# Select count return null instead of 0 when using reflection

**URL:** https://community.dremio.com/t/select-count-return-null-instead-of-0-when-using-reflection/10616
**Category:** Uncategorized
**Created:** [May 16, 2023, 9:40am UTC](https://community.dremio.com/t/select-count-return-null-instead-of-0-when-using-reflection/10616 "2023-05-16T09:40:44Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![tempestj](https://avatars.discourse-cdn.com/v4/letter/t/4491bb/32.png) [@tempestj](https://community.dremio.com/u/tempestj)
#### Post date: [May 16, 2023, 9:40am UTC](https://community.dremio.com/t/select-count-return-null-instead-of-0-when-using-reflection/10616/1 "2023-05-16T09:40:44Z")

</div>

Helllo, I am using dremio cloud in 22.1.4 version and I observe an error with reflection  
When I execute a query of that pattern  
SELECT count(\*) FROM a\_table WHERE a\_condition\_filtering\_all\_rows  
=\> without reflection, it returns 0  
=\> with reflection, it returns null

If I execute the same query replacing star char by a column name, then the result is OK  
Is it a known problem ? Is there a workaround to use star char ?

---

<div class="post-metadata">

### Author: ![balaji.ramaswamy](https://sea2.discourse-cdn.com/flex020/user_avatar/community.dremio.com/balaji.ramaswamy/32/843_2.png) [@balaji.ramaswamy](https://community.dremio.com/u/balaji.ramaswamy)
#### Post date: [May 17, 2023, 1:08am UTC](https://community.dremio.com/t/select-count-return-null-instead-of-0-when-using-reflection/10616/2 "2023-05-17T01:08:07Z")

</div>

@tempestj Are you able to send the 2 job profiles?

> **[How To Share A Query Profile](https://www.dremio.com/resources/tutorials/share-query-profile-dremio/#)**
>
> In this tutorial we’ll show you how to share a Dremio query profile. Query profiles store important metadata about queries that you run in Dremio, and can make it easier to help Dremio’s engineers debug any issues you encounter. You will require...

---

<div class="post-metadata">

### Author: ![Benny\_Chow](https://sea2.discourse-cdn.com/flex020/user_avatar/community.dremio.com/benny_chow/32/5527_2.png) [@Benny\_Chow](https://community.dremio.com/u/Benny_Chow)
#### Post date: [May 20, 2023, 12:03am UTC](https://community.dremio.com/t/select-count-return-null-instead-of-0-when-using-reflection/10616/3 "2023-05-20T00:03:38Z")

</div>

count(\*) should always return a type of BIGINT NOT NULL even if there are no records.

---

<div class="post-metadata">

### Author: ![tempestj](https://avatars.discourse-cdn.com/v4/letter/t/4491bb/32.png) [@tempestj](https://community.dremio.com/u/tempestj)
#### Post date: [May 22, 2023, 8:46am UTC](https://community.dremio.com/t/select-count-return-null-instead-of-0-when-using-reflection/10616/4 "2023-05-22T08:46:34Z")

</div>

Here is an illustration

 ![image](https://us1.discourse-cdn.com/flex020/uploads/dremio/original/2X/c/ce6a5a7be4086db395e68f6e2a43002849329ba2.png)

- the profile  
[3f2fcdf7-8f16-402b-8208-75dfeee5dde1.zip](https://community.dremio.com/uploads/short-url/gpze3KEGuguWVFOqaSlUb2Bxja5.zip) (31.6 KB)

If I disable the reflection the query answer is ok, here is the successful profile

- without reflection  
[84bb41b3-895a-4888-890c-ea407f10e2cd.zip](https://community.dremio.com/uploads/short-url/ruCZf4UHiGg2JP5aUfp7unCu2AK.zip) (33.3 KB)

---

<div class="post-metadata">

### Author: ![Benny\_Chow](https://sea2.discourse-cdn.com/flex020/user_avatar/community.dremio.com/benny_chow/32/5527_2.png) [@Benny\_Chow](https://community.dremio.com/u/Benny_Chow)
#### Post date: [May 23, 2023, 4:45am UTC](https://community.dremio.com/t/select-count-return-null-instead-of-0-when-using-reflection/10616/5 "2023-05-23T04:45:41Z")

</div>

Thanks… looks like a bug with sum0. In the profile without the reflection, I can see 9 rows (from the 9 threads from phase 1) entering sum0 and it returns 0 as expected. However, with the reflection, no rows enter sum0 and it returns null. That seems like a bug. Usually, if the reflection had more data, we would have parallelized the scan and then this would have worked around the bug because the physical plan would have looked more like the working case with exchanges.
