[Bug] GPORCA: “could not find MotionState” for correlated EXISTS with LIMIT and a scalar subquery
Les mainteneurs répondent en général sous 2 jours
Évaluation
Cette issue n'a pas encore été évaluée.
Description
Apache Cloudberry version
ANY
What happened
A valid SELECT fails with SQLSTATE XX000 when using GPORCA. The same query succeeds and returns zero rows with the Postgres optimizer.
The query combines a cross join, a correlated EXISTS ... LIMIT 1, and a scalar aggregate subquery in the EXISTS target list. The reproducer requires only one distributed table containing one row.
What you think should happen instead
No response
How to reproduce
CREATE TEMP TABLE motion_repro (id integer) DISTRIBUTED BY (id);
INSERT INTO motion_repro VALUES (1);
ANALYZE motion_repro;
SET optimizer = on;
SELECT y.id
FROM motion_repro x CROSS JOIN motion_repro y
WHERE EXISTS (
SELECT (SELECT count(*) FROM motion_repro)
FROM motion_repro z
WHERE y.id IS NULL
LIMIT 1
);
Expected results: Zero rows: the only value of y.id is 1, so the correlated predicate is false.
Actual result:
ERROR: XX000: could not find MotionState for slice 4 in executor tree
(execUtils.c:2310)
LOCATION: getMotionState, execUtils.c:2310
With optimizer=off, the query returns zero rows successfully. Replacing the EXISTS target list with SELECT 1 also returns zero rows successfully with GPORCA.
full sql reproduction:
\set ON_ERROR_STOP on
\set VERBOSITY verbose
SET statement_timeout = '10s';
CREATE TEMP TABLE motion_repro (id integer) DISTRIBUTED BY (id);
INSERT INTO motion_repro VALUES (1);
ANALYZE motion_repro;
SET optimizer = off;
EXPLAIN (COSTS OFF)
SELECT y.id FROM motion_repro x CROSS JOIN motion_repro y
WHERE EXISTS (SELECT (SELECT count(*) FROM motion_repro)
FROM motion_repro z WHERE y.id IS NULL LIMIT 1);
SELECT y.id FROM motion_repro x CROSS JOIN motion_repro y
WHERE EXISTS (SELECT (SELECT count(*) FROM motion_repro)
FROM motion_repro z WHERE y.id IS NULL LIMIT 1);
SET optimizer = on;
EXPLAIN (COSTS OFF)
SELECT y.id FROM motion_repro x CROSS JOIN motion_repro y
WHERE EXISTS (SELECT (SELECT count(*) FROM motion_repro)
FROM motion_repro z WHERE y.id IS NULL LIMIT 1);
\set ON_ERROR_STOP off
SELECT y.id FROM motion_repro x CROSS JOIN motion_repro y
WHERE EXISTS (SELECT (SELECT count(*) FROM motion_repro)
FROM motion_repro z WHERE y.id IS NULL LIMIT 1);
\echo SQLSTATE=:SQLSTATE
-- Equivalent control: an EXISTS target list does not affect existence.
\set ON_ERROR_STOP on
SELECT y.id FROM motion_repro x CROSS JOIN motion_repro y
WHERE EXISTS (SELECT 1
FROM motion_repro z WHERE y.id IS NULL LIMIT 1);
DROP TABLE motion_repro;
output:
SET
CREATE TABLE
INSERT 0 1
ANALYZE
SET
QUERY PLAN
---------------------------------------------------------------
Gather Motion 3:1 (slice1; segments: 3)
-> Nested Loop Semi Join
-> Nested Loop
-> Broadcast Motion 3:3 (slice2; segments: 3)
-> Seq Scan on motion_repro x
-> Seq Scan on motion_repro y
Filter: (id IS NULL)
-> Materialize
-> Broadcast Motion 3:3 (slice3; segments: 3)
-> Seq Scan on motion_repro z
Optimizer: Postgres query optimizer
(11 rows)
id
----
(0 rows)
SET
QUERY PLAN
-----------------------------------------------------------------------------------------
Gather Motion 3:1 (slice1; segments: 3)
-> Nested Loop
Join Filter: true
-> Seq Scan on motion_repro y
Filter: ((id IS NULL) AND (SubPlan 2))
SubPlan 2
-> Result
-> Limit
-> Result
One-Time Filter: (y.id IS NULL)
-> Materialize
-> Broadcast Motion 3:3 (slice3; segments: 3)
-> Seq Scan on motion_repro z
-> Materialize
-> Broadcast Motion 3:3 (slice2; segments: 3)
-> Seq Scan on motion_repro x
Optimizer: GPORCA
(17 rows)
SQLSTATE=XX000
psql:/home/alena/rel2-fuzz-20261029/triage-20261029/repro.sql:25: ERROR: XX000: could not find MotionState for slice 4 in executor tree (execUtils.c:2310) (entry db 127.0.0.1:25460 pid=71013) (execUtils.c:2310)
LOCATION: getMotionState, execUtils.c:2310
id
----
(0 rows)
DROP TABLE
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.
- Langage dominant
- C
- Étoiles
- 1.4k
- Forks
- 265
- Merge moyen
- 3 j 17 h
- PR mergées (30 j)
- 68
Préparer son environnement
- Aucun Dockerfile ni fichier Docker Compose
- Propose un modèle de pull request
- Lire le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Autres issues de apache/cloudberry
-
[Bug] Expand fails to recognize user-defined tablespacesPeut-être pris @nix-oss l’a pris il y a 73 jours. Ouvertetype: Bug
Difficulté 2/5 1-3 heures Accessibilité débutants 76/100
apache/cloudberry#1885 · 2 réactions ·
Les mainteneurs répondent en général sous 2 jours
-
gpexpand first stage fails: 'SyncPackages' object has no attribute 'ret' (extension sync never runs; regression)Peut-être pris @talmacschen-arch l’a pris il y a 134 jours. Ouverte
Difficulté 2/5 1-3 heures Accessibilité débutants 86/100
apache/cloudberry#1825 ·
Les mainteneurs répondent en général sous 2 jours
-
Difficulté 4/5 3-5 jours Accessibilité débutants 42/100
apache/cloudberry#2214 · 1 commentaire ·
Les mainteneurs répondent en général sous 2 jours
-
Difficulté 4/5 3-5 jours Accessibilité débutants 35/100
apache/cloudberry#2213 · 4 commentaires ·
Les mainteneurs répondent en général sous 2 jours
-
type: Bug
Difficulté 4/5 3-5 jours Accessibilité débutants 48/100
apache/cloudberry#2202 ·
Les mainteneurs répondent en général sous 2 jours
Toutes les issues de apache/cloudberry
Issues similaires
-
Difficulté 2/5 1-3 heures Accessibilité débutants 72/100
ly05010419/MacNativeGames#1420 ·
Les mainteneurs répondent en général sous 1 jour
-
GPU-UNLOCK RTX 4070 (2786) Gigabyte 1458:416C: cold boot AND warm reboot unlock, Ubuntu 26.04Ouverte
Difficulté 2/5 1-3 heures Accessibilité débutants 62/100
JustAResearcher/gpu-unlock-ada#124 ·
Les mainteneurs répondent en général sous 1 jour
-
Difficulté 2/5 1-3 heures Accessibilité débutants 74/100
swoole/swoole-cli#1092 ·
-
Difficulté 2/5 1-3 heures Accessibilité débutants 62/100
-
inflate: total_in uses plain += on c_ulong (32-bit on Windows), panics in debug for streams > 4 GiBOuverte
Difficulté 1/5 Moins d'une heure Accessibilité débutants 85/100
trifectatechfoundation/zlib-rs#570 · 1 commentaire ·