BUG #19883: Partition pruning errors on SubPlan inside = ANY array

Started by PG Bug reporting form17 days ago2 messagesbugs

Thread notes

1 note#bug
hackorum-bot#bug
hackorum-bot
2 days ago

@global #bug

#bug
Jump to latest
#1PG Bug reporting form
noreply@postgresql.org

The following bug has been logged on the website:

Bug reference: 19883
Logged by: Qifan Liu
Email address: imchifan@163.com
PostgreSQL version: 18.6
Operating system: Linux/amd64
Description:

On PostgreSQL 18.6 on Linux/amd64, a SELECT against a range-partitioned
table fails with `ERROR: SubPlan found with no parent plan` when an `= ANY`
array element contains an uncorrelated SubPlan whose expression evaluates to
NULL.

The predicate is valid SQL and should return no rows. `NULL::integer IN
(SELECT v ...)` evaluates to NULL, its integer cast remains NULL, and
comparison with the resulting one-element NULL array is not true for either
row. Startup partition pruning should not attempt to evaluate the SubPlan in
a context without a parent PlanState.

How to repeat:

```sql
DROP TABLE IF EXISTS items CASCADE;
DROP TABLE IF EXISTS lookup_values;

CREATE TABLE items (id integer) PARTITION BY RANGE (id);
CREATE TABLE items_low
PARTITION OF items FOR VALUES FROM (MINVALUE) TO (10);
CREATE TABLE items_high
PARTITION OF items FOR VALUES FROM (10) TO (MAXVALUE);
INSERT INTO items VALUES (1), (11);

CREATE TABLE lookup_values (v integer);
INSERT INTO lookup_values VALUES (1);

SELECT id
FROM items
WHERE id = ANY
(ARRAY[(NULL::integer IN
(SELECT v FROM lookup_values))::integer])
ORDER BY id;

DROP TABLE items CASCADE;
DROP TABLE lookup_values;
```

Save this as `reproducer.sql` and run:

```
psql -X -f reproducer.sql
```

The client reports:

```
ERROR: SubPlan found with no parent plan
```

The corresponding server log records the failing statement:

```
ERROR: SubPlan found with no parent plan
STATEMENT: SELECT id
FROM items
WHERE id = ANY
(ARRAY[(NULL::integer IN
(SELECT v FROM lookup_values))::integer])
ORDER BY id;
```

Instead, the SELECT should complete normally and return zero rows. The issue
was reproduced on PostgreSQL 18.6; no other versions were tested. This
occurs when startup partition pruning processes an `= ANY` expression whose
array contains an uncorrelated SubPlan that evaluates to NULL.

#2Andrey Rachitskiy
pl0h0yp1@gmail.com
In reply to: PG Bug reporting form (#1)
Re: BUG #19883: Partition pruning errors on SubPlan inside = ANY array

чт, 12 нояб. 2026 г. в 22:16, PG Bug reporting form <noreply@postgresql.org

:

On PostgreSQL 18.6 on Linux/amd64, a SELECT against a range-partitioned
table fails with `ERROR: SubPlan found with no parent plan` when an `= ANY`
array element contains an uncorrelated SubPlan whose expression evaluates
to
NULL.

Hi Liu,
Fix in master eacee6b6187 (Richard Guo, backpatched to 18). In REL_18_7,
fixed by 70ffc30e12b.
We need to upgrade to 18.7 if possible.

--
Regards,
Rachitskiy Andrey