From c5a0d43b52d084f512e67d82c6c9804f36cc5524 Mon Sep 17 00:00:00 2001 From: Georgy Shelkovy Date: Wed, 3 Jun 2026 13:05:33 +0500 Subject: [PATCH 1/3] Fix OID dispatching during index inheritance. Commit 5028981 refactored index inheritance during table creation, although the earlier commit 19cd1cf had already disabled OID dispatching during this process. --- src/backend/commands/indexcmds.c | 7 ------- 1 file changed, 7 deletions(-) diff --git a/src/backend/commands/indexcmds.c b/src/backend/commands/indexcmds.c index 1b68706cc7c9..e7e0e8212604 100644 --- a/src/backend/commands/indexcmds.c +++ b/src/backend/commands/indexcmds.c @@ -653,13 +653,6 @@ DefineIndex(Oid relationId, shouldDispatch = false; } - /* - * Also don't dispatch this if it's part of an ALTER TABLE. We will dispatch - * the whole ALTER TABLE command later. - */ - if (is_alter_table) - shouldDispatch = false; - /* * Some callers need us to run with an empty default_tablespace; this is a * necessary hack to be able to reproduce catalog state accurately when From 9944097f8f0c75de227ea6f0266a91b5c4971874 Mon Sep 17 00:00:00 2001 From: Georgy Shelkovy Date: Wed, 3 Jun 2026 15:54:04 +0500 Subject: [PATCH 2/3] rework --- src/backend/commands/indexcmds.c | 8 ++++++++ src/backend/tcop/utility.c | 26 +++++++++++++++++++++++++- 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/src/backend/commands/indexcmds.c b/src/backend/commands/indexcmds.c index e7e0e8212604..9d7580fe8c3e 100644 --- a/src/backend/commands/indexcmds.c +++ b/src/backend/commands/indexcmds.c @@ -653,6 +653,14 @@ DefineIndex(Oid relationId, shouldDispatch = false; } + + /* + * Also don't dispatch this if it's part of an ALTER TABLE. We will dispatch + * the whole ALTER TABLE command later. + */ + if (is_alter_table) + shouldDispatch = false; + /* * Some callers need us to run with an empty default_tablespace; this is a * necessary hack to be able to reproduce catalog state accurately when diff --git a/src/backend/tcop/utility.c b/src/backend/tcop/utility.c index e8dec6cbb16c..b78c558428ab 100644 --- a/src/backend/tcop/utility.c +++ b/src/backend/tcop/utility.c @@ -1779,7 +1779,7 @@ ProcessUtilitySlow(ParseState *pstate, IndexStmt *stmt = (IndexStmt *) parsetree; Oid relid; LOCKMODE lockmode; - bool is_alter_table; + bool is_alter_table = false; // see below if (stmt->concurrent) PreventInTransactionBlock(isTopLevel, @@ -1849,6 +1849,29 @@ ProcessUtilitySlow(ParseState *pstate, list_free(inheritors); } + /* + * Greengage specific behavior: + * Postgres will pass false for is_alter_table for DefineIndex. + * This argument is only used at two places in DefineIndex (in original postgres code): + * 1. the function index_check_primary_key + * 2. print a debug log on what the statement is + * + * In fact when calling DefineIndex here, we can always pass + * false for is_alter_table when it actually comes from expandTableLikeClause: + * for 1, we are sure relationHasPrimaryKey check will pass because we are + * building a new relation with index here. + * for 2, I do not think it will mislead the user if we print it as CreateStmt. + * + * But for Greengage, is_alter_table matters a lot and has to be set false here: + * DefineIndex need to dispatch, and if it is_alter_table is true, Greengage will + * take this as a sub command of AlterTable stmt, thus it will not dispatch and + * lead to errors. Thus, we comment off the following code and pass false for + * is_alter_table for DefineIndex here. + * + * See following discussion for details: + * https://www.postgresql.org/message-id/CANerzActdrdFO1r4RSqK0M2d0Xtwu5t5bH%3DZOoLsAQ%3DHhZrB%3Dg%40mail.gmail.com + */ +#if 0 /* * If the IndexStmt is already transformed, it must have * come from generateClonedIndexStmt, which in current @@ -1859,6 +1882,7 @@ ProcessUtilitySlow(ParseState *pstate, * worth adding a separate bool field for the purpose.) */ is_alter_table = stmt->transformed; +#endif /* Run parse analysis ... */ stmt = transformIndexStmt(relid, stmt, queryString); From fa863537b8f335e0d409d317bed7548e480b7716 Mon Sep 17 00:00:00 2001 From: Georgy Shelkovy Date: Wed, 3 Jun 2026 15:54:50 +0500 Subject: [PATCH 3/3] rm --- src/backend/commands/indexcmds.c | 1 - 1 file changed, 1 deletion(-) diff --git a/src/backend/commands/indexcmds.c b/src/backend/commands/indexcmds.c index 9d7580fe8c3e..1b68706cc7c9 100644 --- a/src/backend/commands/indexcmds.c +++ b/src/backend/commands/indexcmds.c @@ -653,7 +653,6 @@ DefineIndex(Oid relationId, shouldDispatch = false; } - /* * Also don't dispatch this if it's part of an ALTER TABLE. We will dispatch * the whole ALTER TABLE command later.