[Bug] Wrong results: GROUP BY a constant expression returns one row for empty input
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 48/100
Direzione di ricerca
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.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
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.
- Lingua principale
- C
- Stelle
- 1.4k
- Fork
- 248
- Merge medio
- 4g 10h
- PR unite (30g)
- 40
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di apache/cloudberry
-
type: Bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
apache/cloudberry#1885 · 2 reazioni ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 86/100
apache/cloudberry#1825 ·
-
type: Bug
Difficoltà 3/5 1-2 giorni Idoneità per principianti 65/100
apache/cloudberry#2048 · 1 reazione ·
-
type: Bug
Difficoltà 4/5 3-5 giorni Idoneità per principianti 40/100
apache/cloudberry#2047 ·
-
type: Bug
Difficoltà 4/5 3-5 giorni Idoneità per principianti 45/100
apache/cloudberry#2046 · 1 commento ·
Tutte le issue di apache/cloudberry
Issue simili
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
bradcypert/plum#53 ·
-
Component: GLib
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
-
Status: Opened
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
nextbsd/nextbsd-userland#285 ·