diff --git a/src/common/backend/parser/parse_utilcmd.cpp b/src/common/backend/parser/parse_utilcmd.cpp index 74612435142d95dfa60ce6c316a794c855d0652d..eb19244b8197b03bb1c3b239174b32f66d598044 100644 --- a/src/common/backend/parser/parse_utilcmd.cpp +++ b/src/common/backend/parser/parse_utilcmd.cpp @@ -1612,8 +1612,7 @@ static void transformTableLikeClause( cxt->reloptions = untransformRelOptions(reloptions); /* remove on_commit_delete_rows option */ - if (cxt->relation->relpersistence != RELPERSISTENCE_TEMP && - cxt->relation->relpersistence != RELPERSISTENCE_GLOBAL_TEMP) { + if (cxt->relation->relpersistence != RELPERSISTENCE_GLOBAL_TEMP) { cxt->reloptions = RemoveRelOption(cxt->reloptions, "on_commit_delete_rows", NULL); } diff --git a/src/gausskernel/optimizer/commands/tablecmds.cpp b/src/gausskernel/optimizer/commands/tablecmds.cpp index 2a812876941a0225e931da466ba157baf97f8262..a4b4e777bf9732a3f1e36370999d30b83aaa5779 100644 --- a/src/gausskernel/optimizer/commands/tablecmds.cpp +++ b/src/gausskernel/optimizer/commands/tablecmds.cpp @@ -1587,13 +1587,12 @@ Oid DefineRelation(CreateStmt* stmt, char relkind, Oid ownerId) OnCommitAction oncommitAction = GttOncommitOption(stmt->options); if (stmt->relation->relpersistence == RELPERSISTENCE_GLOBAL_TEMP && relkind == RELKIND_RELATION) { - if (oncommitAction != ONCOMMIT_NOOP) { - if (stmt->oncommit != ONCOMMIT_NOOP && stmt->oncommit != oncommitAction) { - elog(ERROR, "could not create global temporary table with different on commit parameter and with " - "clause options at same time"); - } + if (oncommitAction != ONCOMMIT_NOOP && stmt->oncommit == ONCOMMIT_NOOP) { stmt->oncommit = oncommitAction; } else { + if (oncommitAction != ONCOMMIT_NOOP && stmt->oncommit != ONCOMMIT_NOOP) { + stmt->options = RemoveRelOption(stmt->options, "on_commit_delete_rows", NULL); + } DefElem *opt = makeNode(DefElem); opt->type = T_DefElem; diff --git a/src/test/regress/expected/gtt_function.out b/src/test/regress/expected/gtt_function.out index 4908d212d9d8b4a87c81da7057411d8e569c284c..2af1b5a3ebbc6ba6c05737518b3c53b3c254c5c4 100644 --- a/src/test/regress/expected/gtt_function.out +++ b/src/test/regress/expected/gtt_function.out @@ -136,9 +136,9 @@ select relname ,relkind, relpersistence, reloptions from pg_class where relname -- ERROR create global temp table gtt3(a int primary key, b text) on commit drop; ERROR: ON COMMIT only support PRESERVE ROWS or DELETE ROWS option --- ERROR -create global temp table gtt4(a int primary key, b text) with(on_commit_delete_rows=true) on commit preserve rows; -ERROR: could not create global temporary table with different on commit parameter and with clause options at same time +-- ok +create global temp table gtt10(a int primary key, b text) with(on_commit_delete_rows=true) on commit preserve rows; +NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "gtt10_pkey" for table "gtt10" -- ok create global temp table gtt4(a int primary key, b text) with(on_commit_delete_rows=true) on commit delete rows; NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "gtt4_pkey" for table "gtt4" @@ -147,9 +147,10 @@ create global temp table gtt5(a int primary key, b text) with(on_commit_delete_r NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "gtt5_pkey" for table "gtt5" -- ok create table tb1 (like gtt2 including reloptions); --- ERROR -create global temp table gtt7 (like gtt2 including reloptions) on commit preserve rows; -ERROR: could not create global temporary table with different on commit parameter and with clause options at same time +-- ok +create temp table ltb1 (like gtt1 including reloptions) on commit delete rows; +-- ok +create global temp table gtt11 (like gtt2 including reloptions) on commit preserve rows; -- ok create global temp table gtt7 (like gtt2 including reloptions) on commit delete rows; -- ok @@ -381,16 +382,18 @@ create global temp table gtt_test11(c1 int) with(on_commit_delete_rows=''); ERROR: parameter "on_commit_delete_rows" requires a Boolean value reset search_path; drop schema gtt_function cascade; -NOTICE: drop cascades to 32 other objects +NOTICE: drop cascades to 34 other objects DETAIL: drop cascades to table gtt_function.gtt1 drop cascades to table gtt_function.gtt2 drop cascades to table gtt_function.gtt3 drop cascades to table gtt_function.gtt6 drop cascades to table gtt_function.tbl_inherits_parent drop cascades to table gtt_function.tbl_inherits_parent_global_temp +drop cascades to table gtt_function.gtt10 drop cascades to table gtt_function.gtt4 drop cascades to table gtt_function.gtt5 drop cascades to table gtt_function.tb1 +drop cascades to table gtt_function.gtt11 drop cascades to table gtt_function.gtt7 drop cascades to table gtt_function.gtt8 drop cascades to table gtt_function.gtt9 diff --git a/src/test/regress/sql/gtt_function.sql b/src/test/regress/sql/gtt_function.sql index 6523c70baf52f63a81eb8397b036b3ab2ae16581..abe6052dacec51ae00f8efd0df74d287427d5063 100644 --- a/src/test/regress/sql/gtt_function.sql +++ b/src/test/regress/sql/gtt_function.sql @@ -131,8 +131,8 @@ select relname ,relkind, relpersistence, reloptions from pg_class where relname -- ERROR create global temp table gtt3(a int primary key, b text) on commit drop; --- ERROR -create global temp table gtt4(a int primary key, b text) with(on_commit_delete_rows=true) on commit preserve rows; +-- ok +create global temp table gtt10(a int primary key, b text) with(on_commit_delete_rows=true) on commit preserve rows; -- ok create global temp table gtt4(a int primary key, b text) with(on_commit_delete_rows=true) on commit delete rows; @@ -143,8 +143,11 @@ create global temp table gtt5(a int primary key, b text) with(on_commit_delete_r -- ok create table tb1 (like gtt2 including reloptions); --- ERROR -create global temp table gtt7 (like gtt2 including reloptions) on commit preserve rows; +-- ok +create temp table ltb1 (like gtt1 including reloptions) on commit delete rows; + +-- ok +create global temp table gtt11 (like gtt2 including reloptions) on commit preserve rows; -- ok create global temp table gtt7 (like gtt2 including reloptions) on commit delete rows;