From 5b45b7946a4515229d8e32d3882ac5a00f839d28 Mon Sep 17 00:00:00 2001 From: Maaz Syed Adeeb Date: Thu, 16 Jul 2026 05:08:07 +0000 Subject: [PATCH v1] Apply parse transformation to expressions in INCLUDE columns CREATE INDEX ... INCLUDE ((expr)) failed with an "unrecognized node type error" instead of "expressions are not supported in included columns". This was because we didn't run parse analysis on the included columns, and started walking them as part of change to improve names for expression indexes (181b6185) Now, we transform the INCLUDE expressions just as we do the key-column expressions. This gets rejected downstream with the right error message. --- src/backend/parser/parse_utilcmd.c | 20 +++++++++++++++++++ src/test/regress/expected/index_including.out | 14 +++++++++++++ src/test/regress/sql/index_including.sql | 9 +++++++++ 3 files changed, 43 insertions(+) diff --git a/src/backend/parser/parse_utilcmd.c b/src/backend/parser/parse_utilcmd.c index 58ccc7b..ccf6ee5 100644 --- a/src/backend/parser/parse_utilcmd.c +++ b/src/backend/parser/parse_utilcmd.c @@ -3122,6 +3122,26 @@ transformIndexStmt(Oid relid, IndexStmt *stmt, const char *queryString) } } + /* + * Likewise take care of any expressions in INCLUDING. (At this writing, + * those will be rejected later on, but probably someday we'll wish to + * support them.) + */ + foreach(l, stmt->indexIncludingParams) + { + IndexElem *ielem = (IndexElem *) lfirst(l); + + if (ielem->expr) + { + /* Do parse transformation of the expression */ + ielem->expr = transformExpr(pstate, ielem->expr, + EXPR_KIND_INDEX_EXPRESSION); + + /* We have to fix its collations too */ + assign_expr_collations(pstate, ielem->expr); + } + } + /* * Check that only the base rel is mentioned. (This should be dead code * now that add_missing_from is history.) diff --git a/src/test/regress/expected/index_including.out b/src/test/regress/expected/index_including.out index 4e8fe49..1c0b895 100644 --- a/src/test/regress/expected/index_including.out +++ b/src/test/regress/expected/index_including.out @@ -423,3 +423,17 @@ SELECT c2, c1, c3 FROM nametbl WHERE c2 = 'two' AND c1 = 1; RESET enable_seqscan; DROP TABLE nametbl; +/* + * 11. Expressions are not supported in included columns. Verify that we + * report a "feature not supported" error. + */ +CREATE TABLE tbl (c1 int, c2 int, c3 int); +CREATE INDEX ON tbl (c1) INCLUDE ((c2 + c3)); +ERROR: expressions are not supported in included columns +LINE 1: CREATE INDEX ON tbl (c1) INCLUDE ((c2 + c3)); + ^ +CREATE INDEX ON tbl (c1) INCLUDE ((c2)); +ERROR: expressions are not supported in included columns +LINE 1: CREATE INDEX ON tbl (c1) INCLUDE ((c2)); + ^ +DROP TABLE tbl; diff --git a/src/test/regress/sql/index_including.sql b/src/test/regress/sql/index_including.sql index 43bb6ea..db3c1bc 100644 --- a/src/test/regress/sql/index_including.sql +++ b/src/test/regress/sql/index_including.sql @@ -236,3 +236,12 @@ SELECT c2, c1, c3 FROM nametbl WHERE c2 = 'two' AND c1 = 1; RESET enable_seqscan; DROP TABLE nametbl; + +/* + * 11. Expressions are not supported in included columns. Verify that we + * report a "feature not supported" error. + */ +CREATE TABLE tbl (c1 int, c2 int, c3 int); +CREATE INDEX ON tbl (c1) INCLUDE ((c2 + c3)); +CREATE INDEX ON tbl (c1) INCLUDE ((c2)); +DROP TABLE tbl; -- 2.47.3