pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: PG Bug reporting form <noreply@postgresql.org>
To: pgsql-bugs@lists.postgresql.org
Cc: imchifan@163.com
Subject: BUG #19883: Partition pruning errors on SubPlan inside = ANY array
Date: Wed, 11 Nov 2026 14:04:19 +0000
Message-ID: <19883-5fe20b9d0ae341dc@postgresql.org> (raw)

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.








view thread (2+ messages)  latest in thread

Message-ID: <19883-5fe20b9d0ae341dc@postgresql.org>
Permalink:  ../19883-5fe20b9d0ae341dc@postgresql.org/
Also on:    postgresql.org/message-id/19883-5fe20b9d0ae341dc@postgresql.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-bugs@postgresql.org
  Cc: noreply@postgresql.org, imchifan@163.com
  Subject: Re: BUG #19883: Partition pruning errors on SubPlan inside = ANY array
  In-Reply-To: <19883-5fe20b9d0ae341dc@postgresql.org>
  References: <19883-5fe20b9d0ae341dc@postgresql.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox