You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudberry.apache.org by "roseduan (via GitHub)" <gi...@apache.org> on 2026/09/17 07:03:59 UTC
[I] [Bug] Wrong results: GROUP BY a constant expression returns one row for empty input [cloudberry]
roseduan opened a new issue, #2025:
URL: https://github.com/apache/cloudberry/issues/2025
### Apache Cloudberry version
main branch
### What happened
With the Postgres planner (`optimizer = off`), a query that groups by a constant expression returns one row when the input table is empty. A `GROUP BY` over zero input rows has zero groups, so the
correct answer is no rows.
GPORCA (`optimizer = on`) is not affected. Non-empty inputs are not affected — the extra row only appears when the input is empty.
### What you think should happen instead
_No response_
### How to reproduce
```sql
CREATE TABLE g(c0 boolean) DISTRIBUTED BY (c0); -- left EMPTY
SET optimizer = off;
SELECT count(*) FROM g GROUP BY 'x'::text;
-- count
-- -------
-- 0 <-- WRONG, expected 0 rows
SELECT 1 FROM g GROUP BY (0.25)::MONEY HAVING count(*) = 0;
-- ?column?
-- ----------
-- 1 <-- WRONG, expected 0 rows
```
Expected in both cases: `(0 rows)`.
The plan shows the grouping key disappearing and the final aggregate becoming a plain `Aggregate`, which always emits one row:
```
EXPLAIN (VERBOSE, COSTS OFF) SELECT count(*) FROM g GROUP BY 'x'::text;
Finalize Aggregate
Output: count(*), 'x'::text
-> Gather Motion 3:1 (slice1; segments: 3)
Output: (PARTIAL count(*))
-> Partial GroupAggregate
Output: PARTIAL count(*)
-> Seq Scan on public.g
```
**Workarounds**
- `SET optimizer = on;` (GPORCA), or
- `SET gp_enable_multiphase_agg = off;`
### Operating System
any
### Anything else
_No response_
### Are you willing to submit PR?
- [ ] Yes, I am willing to submit a PR!
### Code of Conduct
- [x] I agree to follow this project's [Code of Conduct](https://github.com/apache/cloudberry/blob/main/CODE_OF_CONDUCT.md).
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@cloudberry.apache.org.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cloudberry.apache.org
For additional commands, e-mail: commits-help@cloudberry.apache.org
Re: [I] [Bug] Wrong results: GROUP BY a constant expression returns one row for empty input [cloudberry]
Posted by "Alena0704 (via GitHub)" <gi...@apache.org>.
Alena0704 commented on issue #2025:
URL: https://github.com/apache/cloudberry/issues/2025#issuecomment-5801209929
Maybe useful: the same reproduction returns an incorrect result (0):
```
set optimizer = off;
create table t(c0 int);
select 1 from t group by (0.5)::numeric;
```
Building with `--enable-cassert` causes `FATAL ... ("false", File: "cdbgroupingpaths.c", Line: 1124)`.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@cloudberry.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cloudberry.apache.org
For additional commands, e-mail: commits-help@cloudberry.apache.org
Re: [I] [Bug] Wrong results: GROUP BY a constant expression returns one row for empty input [cloudberry]
Posted by "tuhaihe (via GitHub)" <gi...@apache.org>.
tuhaihe closed issue #2025: [Bug] Wrong results: GROUP BY a constant expression returns one row for empty input
URL: https://github.com/apache/cloudberry/issues/2025
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@cloudberry.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cloudberry.apache.org
For additional commands, e-mail: commits-help@cloudberry.apache.org