From 7088da8fffd3fb1045f94fccddff4b8a390f2c21 Mon Sep 17 00:00:00 2001 From: Adam Lee Date: Mon, 9 Nov 2020 14:39:04 +0800 Subject: [PATCH] Revert "Provide workaround to reclaim space on truncate cmd in sub-transaction" This reverts commit 6c16abcad31337233aa34f39107d63079374c3bf. After we merged to PostgreSQL 12, plpython has the plpy.commit(), this workaround is not needed then. --- src/backend/commands/tablecmds.c | 15 +---------- src/backend/utils/misc/guc_gp.c | 16 ------------ src/include/utils/guc.h | 1 - src/include/utils/sync_guc_name.h | 1 - src/test/regress/expected/guc_gp.out | 37 ---------------------------- src/test/regress/sql/guc_gp.sql | 31 ----------------------- 6 files changed, 1 insertion(+), 100 deletions(-) diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 5e5f3f0f87..761735193d 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -2159,8 +2159,6 @@ ExecuteTruncateGuts(List *explicit_rels, List *relids, List *relids_logged, foreach(cell, rels) { Relation rel = (Relation) lfirst(cell); - bool inSubTransaction = mySubid != TopSubTransactionId; - bool createdInThisTransactionScope = rel->rd_createSubid != InvalidSubTransactionId; /* Skip partitioned tables as there is nothing to do */ if (rel->rd_rel->relkind == RELKIND_PARTITIONED_TABLE) @@ -2172,20 +2170,9 @@ ExecuteTruncateGuts(List *explicit_rels, List *relids, List *relids_logged, * a new relfilenode in the current (sub)transaction, then we can just * truncate it in-place, because a rollback would cause the whole * table or the current physical file to be thrown away anyway. - * - * GPDB_11_MERGE_FIXME: Remove this guc and related code once we get - * plpy.commit(). - * - * GPDB: Using GUC dev_opt_unsafe_truncate_in_subtransaction can force - * unsafe truncation only if - - * - inside sub-transaction and not in top transaction - * - table was created somewhere within this transaction scope */ if (rel->rd_createSubid == mySubid || - rel->rd_newRelfilenodeSubid == mySubid || - (dev_opt_unsafe_truncate_in_subtransaction && - inSubTransaction && createdInThisTransactionScope)) + rel->rd_newRelfilenodeSubid == mySubid) { /* Immediate, non-rollbackable truncation is OK */ heap_truncate_one_rel(rel); diff --git a/src/backend/utils/misc/guc_gp.c b/src/backend/utils/misc/guc_gp.c index 4dc53b66c5..68fb8fee31 100644 --- a/src/backend/utils/misc/guc_gp.c +++ b/src/backend/utils/misc/guc_gp.c @@ -111,7 +111,6 @@ bool gp_guc_need_restore = false; char *Debug_dtm_action_sql_command_tag; -bool dev_opt_unsafe_truncate_in_subtransaction = false; bool Debug_print_full_dtm = false; bool Debug_print_snapshot_dtm = false; bool Debug_disable_distributed_snapshot = false; @@ -1052,21 +1051,6 @@ struct config_bool ConfigureNamesBool_gp[] = NULL, NULL, NULL }, - { - {"dev_opt_unsafe_truncate_in_subtransaction", PGC_USERSET, DEVELOPER_OPTIONS, - gettext_noop("Pick unsafe truncate instead of safe truncate inside sub-transaction."), - gettext_noop("Usage of this GUC is strongly discouraged and only " - "should be used after understanding the impact of using " - "the same. Setting the GUC comes with cost of losing " - "table data on truncate command despite sub-transaction " - "rollback for table created within transaction."), - GUC_NO_SHOW_ALL | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE | GUC_DISALLOW_IN_AUTO_FILE - }, - &dev_opt_unsafe_truncate_in_subtransaction, - false, - NULL, NULL, NULL - }, - { {"debug_print_full_dtm", PGC_SUSET, LOGGING_WHAT, gettext_noop("Prints full DTM information to server log."), diff --git a/src/include/utils/guc.h b/src/include/utils/guc.h index d35292c953..8980764185 100644 --- a/src/include/utils/guc.h +++ b/src/include/utils/guc.h @@ -270,7 +270,6 @@ extern bool Debug_print_parse; extern bool Debug_print_rewritten; extern bool Debug_pretty_print; -extern bool dev_opt_unsafe_truncate_in_subtransaction; extern bool Debug_print_full_dtm; extern bool Debug_print_snapshot_dtm; extern bool Debug_disable_distributed_snapshot; diff --git a/src/include/utils/sync_guc_name.h b/src/include/utils/sync_guc_name.h index d7a28e03d5..c744be98a7 100644 --- a/src/include/utils/sync_guc_name.h +++ b/src/include/utils/sync_guc_name.h @@ -5,7 +5,6 @@ "DateStyle", "default_table_access_method", "default_tablespace", - "dev_opt_unsafe_truncate_in_subtransaction", "dml_ignore_target_partition_check", "execute_pruned_plan", "explain_memory_verbosity", diff --git a/src/test/regress/expected/guc_gp.out b/src/test/regress/expected/guc_gp.out index da0c1a647b..4ade97cac0 100644 --- a/src/test/regress/expected/guc_gp.out +++ b/src/test/regress/expected/guc_gp.out @@ -299,43 +299,6 @@ NOTICE: command without clusterwide effect HINT: Consider alternatives as DEALLOCATE ALL, or DISCARD TEMP if a clusterwide effect is desired. CREATE TEMP TABLE reset_test ( data text ) ON COMMIT PRESERVE ROWS; ERROR: relation "reset_test" already exists (seg0 127.0.1.1:7002 pid=26153) --- test for guc dev_opt_unsafe_truncate_in_subtransaction --- start_ignore -CREATE LANGUAGE plpython3u; --- end_ignore -CREATE OR REPLACE FUNCTION run_all_in_one() RETURNS VOID AS -$$ - plpy.execute('CREATE TABLE unsafe_truncate(a int, b int) DISTRIBUTED BY (a)') - plpy.execute('INSERT INTO unsafe_truncate SELECT * FROM generate_series(1, 10)') - for i in range(1,4): - plpy.execute('UPDATE unsafe_truncate SET b = b + 1') - plpy.execute('CREATE TABLE foobar AS SELECT * FROM unsafe_truncate DISTRIBUTED BY (a)') - - before_truncate = plpy.execute('SELECT relfilenode FROM gp_dist_random(\'pg_class\') WHERE relname=\'unsafe_truncate\' ORDER BY gp_segment_id') - plpy.execute('truncate unsafe_truncate') - after_truncate = plpy.execute('SELECT relfilenode FROM gp_dist_random(\'pg_class\') WHERE relname=\'unsafe_truncate\' ORDER BY gp_segment_id') - - plpy.execute('DROP TABLE unsafe_truncate') - plpy.execute('ALTER TABLE foobar RENAME TO unsafe_truncate') - - if before_truncate[0]['relfilenode'] == after_truncate[0]['relfilenode']: - plpy.info('iteration:%d unsafe truncate performed' % (i)) - else: - plpy.info('iteration:%d safe truncate performed' % (i)) - - plpy.execute('SET dev_opt_unsafe_truncate_in_subtransaction TO ON') - plpy.execute('DROP TABLE unsafe_truncate') - plpy.execute('RESET dev_opt_unsafe_truncate_in_subtransaction') -$$ language plpython3u; -select run_all_in_one(); -INFO: iteration:1 safe truncate performed -INFO: iteration:2 unsafe truncate performed -INFO: iteration:3 unsafe truncate performed - run_all_in_one ----------------- - -(1 row) - CREATE TABLE guc_gp_t1(i int); NOTICE: Table doesn't have 'DISTRIBUTED BY' clause -- Using column named 'i' as the Greenplum Database data distribution key for this table. HINT: The 'DISTRIBUTED BY' clause determines the distribution of data. Make sure column(s) chosen are the optimal data distribution key to minimize skew. diff --git a/src/test/regress/sql/guc_gp.sql b/src/test/regress/sql/guc_gp.sql index 1eabbfe007..5abd141ee1 100644 --- a/src/test/regress/sql/guc_gp.sql +++ b/src/test/regress/sql/guc_gp.sql @@ -189,37 +189,6 @@ SELECT * FROM reset_test; DISCARD ALL; CREATE TEMP TABLE reset_test ( data text ) ON COMMIT PRESERVE ROWS; --- test for guc dev_opt_unsafe_truncate_in_subtransaction --- start_ignore -CREATE LANGUAGE plpython3u; --- end_ignore -CREATE OR REPLACE FUNCTION run_all_in_one() RETURNS VOID AS -$$ - plpy.execute('CREATE TABLE unsafe_truncate(a int, b int) DISTRIBUTED BY (a)') - plpy.execute('INSERT INTO unsafe_truncate SELECT * FROM generate_series(1, 10)') - for i in range(1,4): - plpy.execute('UPDATE unsafe_truncate SET b = b + 1') - plpy.execute('CREATE TABLE foobar AS SELECT * FROM unsafe_truncate DISTRIBUTED BY (a)') - - before_truncate = plpy.execute('SELECT relfilenode FROM gp_dist_random(\'pg_class\') WHERE relname=\'unsafe_truncate\' ORDER BY gp_segment_id') - plpy.execute('truncate unsafe_truncate') - after_truncate = plpy.execute('SELECT relfilenode FROM gp_dist_random(\'pg_class\') WHERE relname=\'unsafe_truncate\' ORDER BY gp_segment_id') - - plpy.execute('DROP TABLE unsafe_truncate') - plpy.execute('ALTER TABLE foobar RENAME TO unsafe_truncate') - - if before_truncate[0]['relfilenode'] == after_truncate[0]['relfilenode']: - plpy.info('iteration:%d unsafe truncate performed' % (i)) - else: - plpy.info('iteration:%d safe truncate performed' % (i)) - - plpy.execute('SET dev_opt_unsafe_truncate_in_subtransaction TO ON') - plpy.execute('DROP TABLE unsafe_truncate') - plpy.execute('RESET dev_opt_unsafe_truncate_in_subtransaction') -$$ language plpython3u; - -select run_all_in_one(); - CREATE TABLE guc_gp_t1(i int); INSERT INTO guc_gp_t1 VALUES(1),(2); -- GitLab