From 047f400dddae731e25c1f60c8e63382a6c946928 Mon Sep 17 00:00:00 2001 From: wangzhijun2018 Date: Sat, 5 Sep 2020 15:28:28 +0800 Subject: [PATCH] add orientation option restriction for global temp table --- src/gausskernel/optimizer/commands/tablecmds.cpp | 15 ++++++++++++++- src/test/regress/expected/gtt_function.out | 3 +++ src/test/regress/expected/gtt_parallel_1.out | 1 + src/test/regress/parallel_schedule0 | 7 +++++++ src/test/regress/sql/gtt_function.sql | 3 +++ src/test/regress/sql/gtt_parallel_1.sql | 2 ++ 6 files changed, 30 insertions(+), 1 deletion(-) diff --git a/src/gausskernel/optimizer/commands/tablecmds.cpp b/src/gausskernel/optimizer/commands/tablecmds.cpp index 388bf6e2d..006ab17d5 100644 --- a/src/gausskernel/optimizer/commands/tablecmds.cpp +++ b/src/gausskernel/optimizer/commands/tablecmds.cpp @@ -686,6 +686,12 @@ static void CheckCStoreUnsupportedFeature(CreateStmt* stmt) { Assert(stmt); + if (stmt->relation->relpersistence == RELPERSISTENCE_GLOBAL_TEMP) { + ereport(ERROR, + (errcode(ERRCODE_INVALID_TABLE_DEFINITION), + errmsg("global temporary table can only support heap table"))); + } + if (stmt->ofTypename) { ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), @@ -15351,7 +15357,14 @@ void PreCommit_on_commit_actions(void) /* Do nothing (there shouldn't be such entries, actually) */ break; case ONCOMMIT_DELETE_ROWS: - oids_to_truncate = lappend_oid(oids_to_truncate, oc->relid); + /* + * If this transaction hasn't accessed any temporary + * relations, we can skip truncating ON COMMIT DELETE ROWS + * tables, as they must still be empty. + */ + if (t_thrd.xact_cxt.MyXactAccessedTempRel) { + oids_to_truncate = lappend_oid(oids_to_truncate, oc->relid); + } break; case ONCOMMIT_DROP: { ObjectAddress object; diff --git a/src/test/regress/expected/gtt_function.out b/src/test/regress/expected/gtt_function.out index 02863b260..5447d7a86 100644 --- a/src/test/regress/expected/gtt_function.out +++ b/src/test/regress/expected/gtt_function.out @@ -51,6 +51,9 @@ ERROR: must have at least one column alter table foo set (on_commit_delete_rows='true'); ERROR: relation "foo" does not exist -- ERROR +create global temp table cgtt(id int, b text) with (ORIENTATION=column); +ERROR: global temporary table can only support heap table +-- ERROR CREATE global temp TABLE measurement ( logdate date not null, peaktemp int, diff --git a/src/test/regress/expected/gtt_parallel_1.out b/src/test/regress/expected/gtt_parallel_1.out index 0646aaed7..7dc62f644 100644 --- a/src/test/regress/expected/gtt_parallel_1.out +++ b/src/test/regress/expected/gtt_parallel_1.out @@ -1,4 +1,5 @@ set search_path=gtt,sys; +analyze verify fast gtt1; select nextval('gtt_with_seq_c2_seq'); nextval --------- diff --git a/src/test/regress/parallel_schedule0 b/src/test/regress/parallel_schedule0 index 1b6f8ef2c..ab070f293 100644 --- a/src/test/regress/parallel_schedule0 +++ b/src/test/regress/parallel_schedule0 @@ -176,3 +176,10 @@ test: single_node_unsupported_view #test: hw_cstore test: instr_unique_sql + +# global temporary table tests +test: gtt_stats +test: gtt_function +test: gtt_prepare +test: gtt_parallel_1 gtt_parallel_2 +test: gtt_clean diff --git a/src/test/regress/sql/gtt_function.sql b/src/test/regress/sql/gtt_function.sql index 3df1126d5..a1a47ab59 100644 --- a/src/test/regress/sql/gtt_function.sql +++ b/src/test/regress/sql/gtt_function.sql @@ -47,6 +47,9 @@ create global temp table foo(); -- ERROR alter table foo set (on_commit_delete_rows='true'); +-- ERROR +create global temp table cgtt(id int, b text) with (ORIENTATION=column); + -- ERROR CREATE global temp TABLE measurement ( logdate date not null, diff --git a/src/test/regress/sql/gtt_parallel_1.sql b/src/test/regress/sql/gtt_parallel_1.sql index 10a0c0552..35b75421c 100644 --- a/src/test/regress/sql/gtt_parallel_1.sql +++ b/src/test/regress/sql/gtt_parallel_1.sql @@ -1,6 +1,8 @@ set search_path=gtt,sys; +analyze verify fast gtt1; + select nextval('gtt_with_seq_c2_seq'); insert into gtt1 values(1, 'test1');