CREATE INDEX with an expression in an INCLUDE column fails with XX000 "unrecognized node type" instead of 0A000 on master

Started by Maaz Syed Adeebabout 21 hours ago5 messagesbugs
Jump to latest
#1Maaz Syed Adeeb
maaz.adeeb@gmail.com

PostgreSQL version: 20devel (git master)

On current master, creating an index with an expression in an INCLUDE
(non-key) column fails with an internal error ("unrecognized node
type", SQLSTATE XX000) instead of the user-facing
FEATURE_NOT_SUPPORTED (0A000) "expressions are not supported in
included columns". The statement is still correctly rejected, but with
the wrong error class and a message.

Minimal repro

CREATE TABLE foo (id int PRIMARY KEY, x int, y int);
CREATE INDEX idx_foo ON foo (x) INCLUDE ((x + y));

Actual result on master (20devel):

postgres=# select version();
version
------------------------------------------------------------------------
PostgreSQL 20devel on aarch64-unknown-linux-gnu, compiled by gcc
(GCC) 7.3.1 20180712 (Red Hat 7.3.1-18), 64-bit
(1 row)

postgres=# CREATE TABLE foo (id int PRIMARY KEY, x int, y int);
CREATE TABLE
postgres=# CREATE INDEX idx_foo ON foo (x) INCLUDE ((x + y));
ERROR: unrecognized node type: 74
postgres=# \errverbose
ERROR: XX000: unrecognized node type: 74
LOCATION: expression_tree_walker_impl, nodeFuncs.c:2733

(built from git master, HEAD at the time of testing:
572c3b2ddf8c90303d57bf33add4dcbf1b30b866)

Expected result (behavior on all released majors, e.g. 16.13):

postgres=# CREATE INDEX idx_foo ON foo (x) INCLUDE ((x + y));
ERROR: expressions are not supported in included columns
postgres=# \errverbose
ERROR: 0A000: expressions are not supported in included columns
LOCATION: ComputeIndexAttrs, indexcmds.c:1910

This appears to have been introduced by:

commit 181b6185c79e09e6ac94428189d9afac807244ac
"Improve the names generated for indexes on expressions"
https://git.postgresql.org/gitweb/?p=postgresql.git;a=commit;h=181b6185c79e09e6ac94428189d9afac807244ac

which replaced the previous static "expr" fallback name with a walk of
the expression. Prior to that commit the INCLUDE expression was never
walked at this stage.

The trigger is any parenthesized expression in INCLUDE, not just
arithmetic; e.g. INCLUDE ((x)) fails the same way with "unrecognized
node type: 72"

(CC'ing Tom Lane, author of the patch that I've linked which is likely
causing the issue, and Matthew Ripley, author of a test that led me
down to this discovery when run against master)

Regards,
Maaz Syed Adeeb

#2Tom Lane
tgl@sss.pgh.pa.us
In reply to: Maaz Syed Adeeb (#1)
Re: CREATE INDEX with an expression in an INCLUDE column fails with XX000 "unrecognized node type" instead of 0A000 on master

Maaz Syed Adeeb <maaz.adeeb@gmail.com> writes:

On current master, creating an index with an expression in an INCLUDE
(non-key) column fails with an internal error ("unrecognized node
type", SQLSTATE XX000) instead of the user-facing
FEATURE_NOT_SUPPORTED (0A000) "expressions are not supported in
included columns". The statement is still correctly rejected, but with
the wrong error class and a message.

Thanks for the report! This is evidently happening because we have
not applied parse transformation to the included columns. I think
that the most appropriate way to fix it is to start doing so, even
though the feature will be rejected later. More or less as attached
(but we ought to add a test case too).

regards, tom lane

Attachments:

wip-fix-index-included-expressions.patchtext/x-diff; charset=us-ascii; name=wip-fix-index-included-expressions.patchDownload+20-0
#3Maaz Syed Adeeb
maaz.adeeb@gmail.com
In reply to: Tom Lane (#2)
Re: CREATE INDEX with an expression in an INCLUDE column fails with XX000 "unrecognized node type" instead of 0A000 on master

I'm happy to add a test case to the patch and resubmit it. It'd be my
first contribution to PG, so happy to get my feet wet with setting up
the env, running tests, contribution process, etc. Let me know if
that'd be OK.

Regards,
Maaz Syed Adeeb

Show quoted text

On Wed, Jul 15, 2026 at 11:29 AM Tom Lane <tgl@sss.pgh.pa.us> wrote:

Maaz Syed Adeeb <maaz.adeeb@gmail.com> writes:

On current master, creating an index with an expression in an INCLUDE
(non-key) column fails with an internal error ("unrecognized node
type", SQLSTATE XX000) instead of the user-facing
FEATURE_NOT_SUPPORTED (0A000) "expressions are not supported in
included columns". The statement is still correctly rejected, but with
the wrong error class and a message.

Thanks for the report! This is evidently happening because we have
not applied parse transformation to the included columns. I think
that the most appropriate way to fix it is to start doing so, even
though the feature will be rejected later. More or less as attached
(but we ought to add a test case too).

regards, tom lane

#4Tom Lane
tgl@sss.pgh.pa.us
In reply to: Maaz Syed Adeeb (#3)
Re: CREATE INDEX with an expression in an INCLUDE column fails with XX000 "unrecognized node type" instead of 0A000 on master

Maaz Syed Adeeb <maaz.adeeb@gmail.com> writes:

I'm happy to add a test case to the patch and resubmit it. It'd be my
first contribution to PG, so happy to get my feet wet with setting up
the env, running tests, contribution process, etc. Let me know if
that'd be OK.

Sure, happy to let you take a shot at it.

regards, tom lane

#5Maaz Syed Adeeb
maaz.adeeb@gmail.com
In reply to: Tom Lane (#4)
Re: CREATE INDEX with an expression in an INCLUDE column fails with XX000 "unrecognized node type" instead of 0A000 on master

Attaching a patch with two regress tests. Let me know if I need to
change anything.

Regards,
Maaz Syed Adeeb

Show quoted text

On Wed, Jul 15, 2026 at 12:12 PM Tom Lane <tgl@sss.pgh.pa.us> wrote:

Maaz Syed Adeeb <maaz.adeeb@gmail.com> writes:

I'm happy to add a test case to the patch and resubmit it. It'd be my
first contribution to PG, so happy to get my feet wet with setting up
the env, running tests, contribution process, etc. Let me know if
that'd be OK.

Sure, happy to let you take a shot at it.

regards, tom lane

Attachments:

v1-0001-Apply-parse-transformation-to-expressions-in-INCL.patchapplication/octet-stream; name=v1-0001-Apply-parse-transformation-to-expressions-in-INCL.patchDownload+43-1