Skip to content

Commit

Permalink
1
Browse files Browse the repository at this point in the history
  • Loading branch information
lss602726449 committed Mar 14, 2024
1 parent ddf2c7d commit 8fe07ab
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 16 deletions.
5 changes: 1 addition & 4 deletions gpMgmt/bin/gpexpand
Original file line number Diff line number Diff line change
Expand Up @@ -2075,10 +2075,7 @@ class ExecuteSQLStatementsCommand(SQLCommand):
try:
self.conn = dbconn.connect(self.url, utility=True, encoding='UTF8', allowSystemTableMods=True)
for statement in self.sqlCommandList:
if not (statement is None):
dbconn.execSQL(self.conn, statement)
else:
logger.warning(" %s " % self.sqlCommandList)
dbconn.execSQL(self.conn, statement)
except Exception as e:
# traceback.print_exc()
logger.error("Exception in ExecuteSQLStatements. URL = %s" % str(self.url))
Expand Down
34 changes: 22 additions & 12 deletions src/test/regress/expected/shrink_table.out
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ Update t1 set c = gp_segment_id;
Select gp_segment_id, count(*) from t1 group by gp_segment_id;
gp_segment_id | count
---------------+-------
2 | 25
0 | 38
1 | 37
2 | 25
(3 rows)

begin;
Expand Down Expand Up @@ -55,9 +55,9 @@ Update t1 set c = gp_segment_id;
Select gp_segment_id, count(*) from t1 group by gp_segment_id;
gp_segment_id | count
---------------+-------
2 | 37
0 | 33
1 | 30
2 | 37
(3 rows)

begin;
Expand All @@ -72,9 +72,9 @@ abort;
Select gp_segment_id, count(*) from t1 group by gp_segment_id;
gp_segment_id | count
---------------+-------
2 | 37
0 | 33
1 | 30
2 | 37
(3 rows)

Alter table t1 shrink table to 1;
Expand Down Expand Up @@ -105,9 +105,9 @@ insert into t1 values
Select gp_segment_id, count(*) from t1 group by gp_segment_id;
gp_segment_id | count
---------------+-------
0 | 3
1 | 1
2 | 4
0 | 3
(3 rows)

begin;
Expand Down Expand Up @@ -170,8 +170,8 @@ NOTICE: One or more columns in the following table(s) do not have statistics: t
HINT: For non-partitioned tables, run analyze <table_name>(<column_list>). For partitioned tables, run analyze rootpartition <table_name>(<column_list>). See log for columns missing statistics.
gp_segment_id | count
---------------+-------
1 | 37
0 | 38
1 | 37
2 | 25
(3 rows)

Expand Down Expand Up @@ -494,6 +494,7 @@ select gp_segment_id, count(*) from table_with_update_trigger group by 1 order b
1 | 47
(2 rows)

drop table table_with_update_trigger;
--
-- Test shrinking inheritance parent table, parent table has different
-- numsegments with child tables.
Expand Down Expand Up @@ -543,6 +544,10 @@ select count(*) from mix_child_b where gp_segment_id = 2;
0
(1 row)

drop table mix_base_tbl cascade;
NOTICE: drop cascades to 2 other objects
DETAIL: drop cascades to table mix_child_a
drop cascades to table mix_child_b
-- multi-level partition tables
CREATE TABLE part_t1(a int, b int, c int, d int, e int)
DISTRIBUTED BY(a)
Expand All @@ -564,9 +569,9 @@ Update part_t1 set e = gp_segment_id;
Select gp_segment_id, count(*) from part_t1 group by gp_segment_id;
gp_segment_id | count
---------------+-------
2 | 25
0 | 38
1 | 37
2 | 25
(3 rows)

begin;
Expand Down Expand Up @@ -700,11 +705,11 @@ Update part_t1 set e = gp_segment_id;
select gp_segment_id, * from part_t1_1_prt_other_b_2_prt_2_3_prt_others_d;
gp_segment_id | a | b | c | d | e
---------------+----+---+---+---+---
2 | 5 | 2 | 1 | 0 | 2
2 | 9 | 0 | 1 | 4 | 2
0 | 29 | 2 | 1 | 4 | 0
0 | 45 | 0 | 1 | 0 | 0
0 | 65 | 2 | 1 | 0 | 0
2 | 5 | 2 | 1 | 0 | 2
2 | 9 | 0 | 1 | 4 | 2
1 | 69 | 0 | 1 | 4 | 1
1 | 89 | 2 | 1 | 4 | 1
(7 rows)
Expand All @@ -716,13 +721,13 @@ HINT: Call ALTER TABLE SHRINK TABLE on the root table instead
select gp_segment_id, * from part_t1_1_prt_other_b_2_prt_2_3_prt_others_d;
gp_segment_id | a | b | c | d | e
---------------+----+---+---+---+---
0 | 29 | 2 | 1 | 4 | 0
0 | 45 | 0 | 1 | 0 | 0
0 | 65 | 2 | 1 | 0 | 0
2 | 5 | 2 | 1 | 0 | 2
2 | 9 | 0 | 1 | 4 | 2
1 | 69 | 0 | 1 | 4 | 1
1 | 89 | 2 | 1 | 4 | 1
0 | 29 | 2 | 1 | 4 | 0
0 | 45 | 0 | 1 | 0 | 0
0 | 65 | 2 | 1 | 0 | 0
(7 rows)

-- try to shrink root partition, should success
Expand Down Expand Up @@ -807,6 +812,10 @@ ERROR: "shrink_table2" is not a table, materialized view, or foreign table
ALTER TABLE shrink_view shrink TABLE to 2;
ERROR: "shrink_view" is not a table, materialized view, or foreign table
ALTER TABLE shrink_table1 shrink TABLE to 2;
drop table shrink_table1 cascade;
NOTICE: drop cascades to 2 other objects
DETAIL: drop cascades to view shrink_view
drop cascades to view shrink_table2
--
-- Test shrinking a table with a domain type as distribution key.
--
Expand All @@ -817,9 +826,9 @@ update shrink_domain_tab set oldseg = gp_segment_id;
select gp_segment_id, count(*) from shrink_domain_tab group by gp_segment_id;
gp_segment_id | count
---------------+-------
0 | 5
1 | 1
2 | 4
0 | 5
(3 rows)

alter table shrink_domain_tab shrink table to 2;
Expand All @@ -836,6 +845,7 @@ select numsegments from gp_distribution_policy where localoid='shrink_domain_tab
2
(1 row)

drop table shrink_domain_tab;
-- start_ignore
-- We need to do a cluster expansion which will check if there are partial
-- tables, we need to drop the partial tables to keep the cluster expansion
Expand Down
5 changes: 5 additions & 0 deletions src/test/regress/sql/shrink_table.sql
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,8 @@ update table_with_update_trigger set a = a + 1;
-- data expansion should success and not hiting any triggers.
Alter table table_with_update_trigger shrink table to 2;
select gp_segment_id, count(*) from table_with_update_trigger group by 1 order by 1;
drop table table_with_update_trigger;

--
-- Test shrinking inheritance parent table, parent table has different
-- numsegments with child tables.
Expand All @@ -254,6 +256,7 @@ select count(*) from mix_child_b where gp_segment_id = 2;
Alter table mix_base_tbl shrink table to 2;
select count(*) from mix_child_a where gp_segment_id = 2;
select count(*) from mix_child_b where gp_segment_id = 2;
drop table mix_base_tbl cascade;

-- multi-level partition tables
CREATE TABLE part_t1(a int, b int, c int, d int, e int)
Expand Down Expand Up @@ -409,6 +412,7 @@ CREATE rule "_RETURN" AS ON SELECT TO shrink_table2
ALTER TABLE shrink_table2 shrink TABLE to 2;
ALTER TABLE shrink_view shrink TABLE to 2;
ALTER TABLE shrink_table1 shrink TABLE to 2;
drop table shrink_table1 cascade;

--
-- Test shrinking a table with a domain type as distribution key.
Expand All @@ -425,6 +429,7 @@ select gp_segment_id, count(*) from shrink_domain_tab group by gp_segment_id;
alter table shrink_domain_tab shrink table to 2;
select gp_segment_id, count(*) from shrink_domain_tab group by gp_segment_id;
select numsegments from gp_distribution_policy where localoid='shrink_domain_tab'::regclass;
drop table shrink_domain_tab;

-- start_ignore
-- We need to do a cluster expansion which will check if there are partial
Expand Down

0 comments on commit 8fe07ab

Please sign in to comment.