From 11a1a5c9add714704405d65104e0d5b057e915c6 Mon Sep 17 00:00:00 2001 From: ganyang Date: Tue, 26 Apr 2022 19:15:23 +0800 Subject: [PATCH 1/2] fix partition error --- src/gausskernel/optimizer/commands/tablecmds.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/gausskernel/optimizer/commands/tablecmds.cpp b/src/gausskernel/optimizer/commands/tablecmds.cpp index dc6ccc59c..eebee65e2 100644 --- a/src/gausskernel/optimizer/commands/tablecmds.cpp +++ b/src/gausskernel/optimizer/commands/tablecmds.cpp @@ -24797,7 +24797,8 @@ static Oid AddTemporaryPartitionForAlterPartitions(const AlterTableCmd* cmd, Rel destPartOid = AddTemporaryHashPartitionForAlterPartitions(cmd, partTableRel, partSeq, renameTargetPart); break; } - case PART_TYPE_RANGE: { + case PART_TYPE_RANGE: + case PART_TYPE_INTERVAL: { destPartOid = AddTemporaryRangePartitionForAlterPartitions(cmd, partTableRel, partSeq, renameTargetPart); break; } From 4898f04a3c8a00231b014d1bcb77ed337f486ce1 Mon Sep 17 00:00:00 2001 From: kidhasdream Date: Tue, 26 Apr 2022 20:03:04 +0800 Subject: [PATCH 2/2] change fastcheck --- src/test/regress/expected/truncate_gpi.out | 67 ++++++++++++++++++++++ src/test/regress/sql/truncate_gpi.sql | 42 +++++++++++++- 2 files changed, 108 insertions(+), 1 deletion(-) diff --git a/src/test/regress/expected/truncate_gpi.out b/src/test/regress/expected/truncate_gpi.out index d1d1ce427..10bf91558 100644 --- a/src/test/regress/expected/truncate_gpi.out +++ b/src/test/regress/expected/truncate_gpi.out @@ -1062,6 +1062,73 @@ select /*+ indexscan(tg_hash i_tg_hash_local_a) */ * from tg_hash where a < 9; (81 rows) drop table tg_hash; +drop table if exists test_ugi_045; +NOTICE: table "test_ugi_045" does not exist, skipping +create table test_ugi_045 +( + c_id integer not null, + c_date DATE, + c_info varchar(20) not null +) +partition by range(c_date) +interval('2 day') +( + partition p1 values less than ('2021-06-01 00:00:00'), + partition p2 values less than ('2021-06-03 00:00:00'), + partition p3 values less than ('2021-06-05 00:00:00'), + partition p4 values less than ('2021-06-07 00:00:00'), + partition p5 values less than ('2021-06-09 00:00:00') +); +insert into test_ugi_045(c_id, c_date, c_info) values(1, '2021-05-30 00:00:00', '1-1'); +insert into test_ugi_045(c_id, c_date, c_info) values(2, '2021-05-31 00:00:00', '1-1'); +insert into test_ugi_045(c_id, c_date, c_info) values(3, '2021-06-01 00:00:00', '1-1'); +insert into test_ugi_045(c_id, c_date, c_info) values(4, '2021-06-02 00:00:00', '1-2'); +insert into test_ugi_045(c_id, c_date, c_info) values(5, '2021-06-03 00:00:00', '1-2'); +insert into test_ugi_045(c_id, c_date, c_info) values(6, '2021-06-04 00:00:00', '1-3'); +insert into test_ugi_045(c_id, c_date, c_info) values(7, '2021-06-05 00:00:00', '1-3'); +insert into test_ugi_045(c_id, c_date, c_info) values(8, '2021-06-06 00:00:00', '1-4'); +insert into test_ugi_045(c_id, c_date, c_info) values(9, '2021-06-07 00:00:00', '1-4'); +insert into test_ugi_045(c_id, c_date, c_info) values(10, '2021-06-08 00:00:00', '1-5'); +create index global_index_id_045 on test_ugi_045(c_date) global; +create index global_index_info_045 on test_ugi_045(c_info) global; +select *from test_ugi_045; + c_id | c_date | c_info +------+---------------------+-------- + 1 | 2021-05-30 00:00:00 | 1-1 + 2 | 2021-05-31 00:00:00 | 1-1 + 3 | 2021-06-01 00:00:00 | 1-1 + 4 | 2021-06-02 00:00:00 | 1-2 + 5 | 2021-06-03 00:00:00 | 1-2 + 6 | 2021-06-04 00:00:00 | 1-3 + 7 | 2021-06-05 00:00:00 | 1-3 + 8 | 2021-06-06 00:00:00 | 1-4 + 9 | 2021-06-07 00:00:00 | 1-4 + 10 | 2021-06-08 00:00:00 | 1-5 +(10 rows) + +alter table test_ugi_045 truncate partition p3 update global index; +set enable_seqscan = off; +set enable_bitmapscan = off; +select *from test_ugi_045; + c_id | c_date | c_info +------+---------------------+-------- + 1 | 2021-05-30 00:00:00 | 1-1 + 2 | 2021-05-31 00:00:00 | 1-1 + 3 | 2021-06-01 00:00:00 | 1-1 + 4 | 2021-06-02 00:00:00 | 1-2 + 7 | 2021-06-05 00:00:00 | 1-3 + 8 | 2021-06-06 00:00:00 | 1-4 + 9 | 2021-06-07 00:00:00 | 1-4 + 10 | 2021-06-08 00:00:00 | 1-5 +(8 rows) + +select *from test_ugi_045 where c_info = '1-2'; + c_id | c_date | c_info +------+---------------------+-------- + 4 | 2021-06-02 00:00:00 | 1-2 +(1 row) + +drop table if exists test_ugi_045; -- 清理过程 drop view check_truncate_results; drop materialized view pg_partition_before_truncate; diff --git a/src/test/regress/sql/truncate_gpi.sql b/src/test/regress/sql/truncate_gpi.sql index a9e61ed26..ed2ba6374 100644 --- a/src/test/regress/sql/truncate_gpi.sql +++ b/src/test/regress/sql/truncate_gpi.sql @@ -192,6 +192,46 @@ explain(costs off) select /*+ indexscan(tg_hash i_tg_hash_local_a) */ * from tg_ select /*+ indexscan(tg_hash i_tg_hash_local_a) */ * from tg_hash where a < 9; drop table tg_hash; + +drop table if exists test_ugi_045; +create table test_ugi_045 +( + c_id integer not null, + c_date DATE, + c_info varchar(20) not null +) +partition by range(c_date) +interval('2 day') +( + partition p1 values less than ('2021-06-01 00:00:00'), + partition p2 values less than ('2021-06-03 00:00:00'), + partition p3 values less than ('2021-06-05 00:00:00'), + partition p4 values less than ('2021-06-07 00:00:00'), + partition p5 values less than ('2021-06-09 00:00:00') +); + +insert into test_ugi_045(c_id, c_date, c_info) values(1, '2021-05-30 00:00:00', '1-1'); +insert into test_ugi_045(c_id, c_date, c_info) values(2, '2021-05-31 00:00:00', '1-1'); +insert into test_ugi_045(c_id, c_date, c_info) values(3, '2021-06-01 00:00:00', '1-1'); +insert into test_ugi_045(c_id, c_date, c_info) values(4, '2021-06-02 00:00:00', '1-2'); +insert into test_ugi_045(c_id, c_date, c_info) values(5, '2021-06-03 00:00:00', '1-2'); +insert into test_ugi_045(c_id, c_date, c_info) values(6, '2021-06-04 00:00:00', '1-3'); +insert into test_ugi_045(c_id, c_date, c_info) values(7, '2021-06-05 00:00:00', '1-3'); +insert into test_ugi_045(c_id, c_date, c_info) values(8, '2021-06-06 00:00:00', '1-4'); +insert into test_ugi_045(c_id, c_date, c_info) values(9, '2021-06-07 00:00:00', '1-4'); +insert into test_ugi_045(c_id, c_date, c_info) values(10, '2021-06-08 00:00:00', '1-5'); + +create index global_index_id_045 on test_ugi_045(c_date) global; +create index global_index_info_045 on test_ugi_045(c_info) global; +select *from test_ugi_045; + +alter table test_ugi_045 truncate partition p3 update global index; +set enable_seqscan = off; +set enable_bitmapscan = off; +select *from test_ugi_045; +select *from test_ugi_045 where c_info = '1-2'; +drop table if exists test_ugi_045; + -- 清理过程 drop view check_truncate_results; -drop materialized view pg_partition_before_truncate; \ No newline at end of file +drop materialized view pg_partition_before_truncate;