[Bug] ORCA returns wrong system column values through a partially pruned CTE consumer
Maintainer antworten meist innerhalb von 2 Tagen
Bewertung
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Anfängerfreundlichkeit
- 48/100
Rechercherichtung
Start by tracing CPhysicalCTEConsumer's fallback when the producer has no used mask, then inspect how the producer's Shared Scan output columns are ordered. The reproduction SQL and EXPLAIN (verbose, costs off) in the issue show the mismatch: the consumer requests gp_segment_id but reads ctid by position. Done when ORCA returns the same system column values as the Postgres planner for the supplied queries.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Beschreibung
Bug reported with the assistance of Claude Code
Apache Cloudberry version
main (reproduced at e8113db9679)
What happened
With ORCA on, selecting a system column (gp_segment_id, tableoid, ...) through a CTE consumer that keeps only some of its producer's columns returns wrong values. One way to hit it is the full join expansion (optimizer_expand_fulljoin = on): wa.gp_segment_id comes back as 0 on every row, wa.tableoid::regclass as -, and when wa.ctid is selected too, gp_segment_id becomes garbage such as 939.
EXPLAIN VERBOSE labels the consumer's output as share0_ref2.ctid although the query asked for gp_segment_id:
-> Shared Scan (share slice:id 1:0)
Output: share0_ref1.a, share0_ref1.ctid, share0_ref1.xmin, share0_ref1.cmin, share0_ref1.xmax, share0_ref1.cmax, share0_ref1.tableoid, share0_ref1.gp_segment_id, share0_ref1.gp_foreign_server
-> Seq Scan on public.wa
...
-> Hash Left Join
Output: share0_ref2.a, share0_ref2.ctid, share1_ref2.b
-> Shared Scan (share slice:id 1:0)
Output: share0_ref2.a, share0_ref2.ctid
What you think should happen instead
ORCA should return the same values as the Postgres planner:
a | b | gp_segment_id
----+----+---------------
-1 | -1 | 2
0 | 0 | 1
1 | 1 | 1
| 2 |
(ORCA currently returns 0 for the first three rows.)
Cause: a CTE created by an xform such as the full join expansion is not pruned, so its producer has no used mask and its Shared Scan emits every column of the scan, system columns included. In CPhysicalCTEConsumer, the fallback for a producer without a used mask keeps only the consumer's used columns (a, gp_segment_id). ShareInputScan does not project; it reads the shared tuple by position. So the consumer's second column is the producer's second column, ctid, not gp_segment_id.
How to reproduce
On a 3-segment demo cluster:
create table wa (a int, x int, y text) distributed by (a);
create table wb (b int, z int, w text) distributed by (b);
insert into wa select i, i, 'x' from generate_series(-1,1) i;
insert into wb select i, i, 'y' from generate_series(-1,2) i;
analyze wa; analyze wb;
set optimizer = on;
set optimizer_expand_fulljoin = on;
select disable_xform('CXformFullOuterJoin2HashJoin');
select disable_xform('CXformImplementFullOuterMergeJoin');
SELECT a, b, wa.gp_segment_id FROM wa FULL JOIN wb ON a = b order by 1,2; -- ORCA: 0,0,0; planner: 2,1,1
SELECT a, b, wa.tableoid::regclass FROM wa FULL JOIN wb ON a = b order by 1,2; -- ORCA: '-'; planner: wa
SELECT a, b, wa.gp_segment_id, wa.ctid FROM wa FULL JOIN wb ON a = b order by 1,2; -- gp_segment_id is garbage
EXPLAIN (verbose, costs off) SELECT a, b, wa.gp_segment_id FROM wa FULL JOIN wb ON a = b order by 1,2;
Compare with set optimizer = off.
Operating System
Rocky Linux 9 (apache/incubator-cloudberry:cbdb-build-rocky9-latest)
Anything else
Happens every time. Queries that only use a leading prefix of the producer's columns are not affected, which is the common case, so it only surfaces when a system column (or any non-prefix subset) is referenced through such a consumer.
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.
- Vorherrschende Sprache
- C
- Sterne
- 1.5k
- Forks
- 280
- Ø Merge
- 5 T. 35 Min.
- Gemergte PRs (30 T.)
- 128
Entwicklungsumgebung
- Kein Dockerfile und keine Docker-Compose-Datei
- Hat eine Pull-Request-Vorlage
- Beitragsleitfaden lesen
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus apache/cloudberry
-
type: Bug
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
apache/cloudberry#2459 · 1 Kommentar ·
Maintainer antworten meist innerhalb von 2 Tagen
-
psql tab completion broken for storage servers, tags, profiles and resource groups (pre-PG15 query format)Evtl. vergeben @allenvox hat das vor 18 Tagen übernommen. Offen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 72/100
apache/cloudberry#2316 ·
Maintainer antworten meist innerhalb von 2 Tagen
-
gpexpand first stage fails: 'SyncPackages' object has no attribute 'ret' (extension sync never runs; regression)Evtl. vergeben @talmacschen-arch hat das vor 166 Tagen übernommen. Offen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 86/100
apache/cloudberry#1825 ·
Maintainer antworten meist innerhalb von 2 Tagen
-
[Bug] Window Sort above ROLLUP gets a larger memory quota and runs slower after "Reserve memory for one partition at a time"Evtl. vergeben @Alena0704 hat das vor 1 Tag übernommen. Offentype: Bug
Schwierigkeit 4/5 3-5 Tage Anfängerfreundlichkeit 52/100
apache/cloudberry#2446 · 1 zugewiesene Person ·
Maintainer antworten meist innerhalb von 2 Tagen
-
type: Bug
Schwierigkeit 4/5 3-5 Tage Anfängerfreundlichkeit 56/100
apache/cloudberry#2429 ·
Maintainer antworten meist innerhalb von 2 Tagen
Alle Issues in apache/cloudberry
Ähnliche Issues
-
HXsetdir strdup leakOffen
Schwierigkeit 1/5 1-3 Stunden Anfängerfreundlichkeit 82/100
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 90/100
ly05010419/MacNativeGames#2459 ·
Maintainer antworten meist innerhalb von 1 Tag
-
2024.2 Backport Required 2025.2 Backport Required 2026.1 Backport Required 2026.2 Backport Required area/build-framework kind/enhancement priority/medium
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 74/100
yugabyte/yugabyte-db#39930 ·
Maintainer antworten meist innerhalb von 1 Tag
-
RecompLauncher supportOffen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 68/100
shinyquagsire23/OpenJKDF2#540 ·
Maintainer antworten meist innerhalb von 12 Tagen
-
Prison work hall: laundry and kitchen stations stand at bare walls, the hatch has no counter or signOffen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
Life-Framework/Life-Framework#5939 ·
Maintainer antworten meist innerhalb von 1 Tag