[Bug] Wrong results: GROUP BY a constant expression returns one row for empty input
Maintainers usually reply within 2 days
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 48/100
Research direction
Start by reproducing the two queries with optimizer = off and inspecting the provided EXPLAIN output, then trace how the PostgreSQL planner handles constant GROUP BY keys and multiphase aggregation. Done means empty input produces zero rows in both cases, without regressing non-empty inputs or the GPORCA path.
Written by the indexing model from the issue text.
Description
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
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), orSET 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
- I agree to follow this project's Code of Conduct.
- Dominant language
- C
- Stars
- 1.4k
- Forks
- 256
- Avg merge
- 4d 17h
- Merged PRs (30d)
- 40
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from apache/cloudberry
-
type: Bug
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
apache/cloudberry#1885 · 2 reactions ·
Maintainers usually reply within 2 days
-
Difficulty 2/5 1-3 hours Newbie friendliness 86/100
apache/cloudberry#1825 ·
Maintainers usually reply within 2 days
-
[Bug] UPDATE of the distribution key fails with "can't split update for inherit table" after the child table is droppedPossibly taken @aryan9948 claimed this 4 days ago. Opentype: Bug
Difficulty 3/5 1-2 days Newbie friendliness 65/100
apache/cloudberry#2048 · 5 comments · 1 reaction · 1 assignee ·
Maintainers usually reply within 2 days
-
[Bug] Wrong results: GPORCA evaluates a window function in a correlated aggregate subquery over all groupsPossibly taken @andr-sokolov claimed this 4 days ago. Opentype: Bug
Difficulty 4/5 3-5 days Newbie friendliness 40/100
apache/cloudberry#2047 · 1 assignee ·
Maintainers usually reply within 2 days
-
[Bug] Wrong results: GPORCA returns NULL instead of the empty-input value for correlated aggregate subqueries other than countPossibly taken @Alena0704 claimed this 4 days ago. Opentype: Bug
Difficulty 4/5 3-5 days Newbie friendliness 45/100
apache/cloudberry#2046 · 1 comment · 1 assignee ·
Maintainers usually reply within 2 days
All issues in apache/cloudberry
Similar issues
-
feature request
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
BasedHardware/omi#20271 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 86/100
ImageMagick/ImageMagick#8994 ·
Maintainers usually reply within 1 day
-
area/ysql kind/bug priority/medium
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
yugabyte/yugabyte-db#34552 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
flux-framework/flux-coral2#509 ·