Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

[Bug] GPORCA: “could not find MotionState” for correlated EXISTS with LIMIT and a scalar subquery

Đang mở
#2,221 0 bình luận 0 reaction 1 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 2 ngày

@Alena0704 đang làm issue này rồi.

Từ ngày 29/10/2026.

  • #2223 của @Alena0704 — đang mở

Đánh giá

Issue này chưa được đánh giá.

Mô tả

type: Bug
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
Ngôn ngữ chính
C
Star
1.4k
Fork
265
Merge trung bình
3 ngày 17 giờ
Pull request đã merge (30 ngày)
68

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của apache/cloudberry

Tất cả issue của apache/cloudberry

Issue tương tự

Thêm issue về C

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.