Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit6d154fd

Browse files
committed
fix partition creation for tables with dropped columns
1 parent001166a commit6d154fd

File tree

7 files changed

+148
-17
lines changed

7 files changed

+148
-17
lines changed

‎Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ REGRESS = pathman_array_qual \
3737
pathman_column_type\
3838
pathman_cte\
3939
pathman_domains\
40+
pathman_dropped_cols\
4041
pathman_expressions\
4142
pathman_foreign_keys\
4243
pathman_gaps\

‎expected/pathman_dropped_cols.out

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
\set VERBOSITY terse
2+
SET search_path = 'public';
3+
CREATE EXTENSION pg_pathman;
4+
CREATE SCHEMA dropped_cols;
5+
/*
6+
* we should be able to manage tables with dropped columns
7+
*/
8+
create table test_range(a int, b int, key int not null);
9+
alter table test_range drop column a;
10+
select create_range_partitions('test_range', 'key', 1, 10, 2);
11+
create_range_partitions
12+
-------------------------
13+
2
14+
(1 row)
15+
16+
alter table test_range drop column b;
17+
select prepend_range_partition('test_range');
18+
prepend_range_partition
19+
-------------------------
20+
test_range_3
21+
(1 row)
22+
23+
select * from pathman_partition_list order by parent, partition;
24+
parent | partition | parttype | expr | range_min | range_max
25+
------------+--------------+----------+------+-----------+-----------
26+
test_range | test_range_1 | 2 | key | 1 | 11
27+
test_range | test_range_2 | 2 | key | 11 | 21
28+
test_range | test_range_3 | 2 | key | -9 | 1
29+
(3 rows)
30+
31+
select pg_get_constraintdef(oid, true) from pg_constraint where conname = 'pathman_test_range_1_check';
32+
pg_get_constraintdef
33+
-------------------------------
34+
CHECK (key >= 1 AND key < 11)
35+
(1 row)
36+
37+
select pg_get_constraintdef(oid, true) from pg_constraint where conname = 'pathman_test_range_3_check';
38+
pg_get_constraintdef
39+
------------------------------------------
40+
CHECK (key >= '-9'::integer AND key < 1)
41+
(1 row)
42+
43+
drop table test_range cascade;
44+
NOTICE: drop cascades to 4 other objects
45+
create table test_hash(a int, b int, key int not null);
46+
alter table test_hash drop column a;
47+
select create_hash_partitions('test_hash', 'key', 3);
48+
create_hash_partitions
49+
------------------------
50+
3
51+
(1 row)
52+
53+
alter table test_hash drop column b;
54+
create table test_dummy (like test_hash);
55+
select replace_hash_partition('test_hash_2', 'test_dummy', true);
56+
replace_hash_partition
57+
------------------------
58+
test_dummy
59+
(1 row)
60+
61+
select * from pathman_partition_list order by parent, partition;
62+
parent | partition | parttype | expr | range_min | range_max
63+
-----------+-------------+----------+------+-----------+-----------
64+
test_hash | test_hash_0 | 1 | key | |
65+
test_hash | test_hash_1 | 1 | key | |
66+
test_hash | test_dummy | 1 | key | |
67+
(3 rows)
68+
69+
select pg_get_constraintdef(oid, true) from pg_constraint where conname = 'pathman_test_hash_1_check';
70+
pg_get_constraintdef
71+
-------------------------------------------------
72+
CHECK (get_hash_part_idx(hashint4(key), 3) = 1)
73+
(1 row)
74+
75+
select pg_get_constraintdef(oid, true) from pg_constraint where conname = 'pathman_test_dummy_check';
76+
pg_get_constraintdef
77+
-------------------------------------------------
78+
CHECK (get_hash_part_idx(hashint4(key), 3) = 2)
79+
(1 row)
80+
81+
drop table test_hash cascade;
82+
NOTICE: drop cascades to 3 other objects
83+
DROP SCHEMA dropped_cols CASCADE;
84+
DROP EXTENSION pg_pathman;

‎sql/pathman_dropped_cols.sql

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
\set VERBOSITY terse
2+
3+
SET search_path='public';
4+
CREATE EXTENSION pg_pathman;
5+
CREATESCHEMAdropped_cols;
6+
7+
8+
/*
9+
* we should be able to manage tables with dropped columns
10+
*/
11+
12+
createtabletest_range(aint, bint, keyintnot null);
13+
14+
altertable test_range drop column a;
15+
select create_range_partitions('test_range','key',1,10,2);
16+
17+
altertable test_range drop column b;
18+
select prepend_range_partition('test_range');
19+
20+
select*from pathman_partition_listorder by parent, partition;
21+
select pg_get_constraintdef(oid, true)from pg_constraintwhere conname='pathman_test_range_1_check';
22+
select pg_get_constraintdef(oid, true)from pg_constraintwhere conname='pathman_test_range_3_check';
23+
24+
droptable test_range cascade;
25+
26+
27+
createtabletest_hash(aint, bint, keyintnot null);
28+
29+
altertable test_hash drop column a;
30+
select create_hash_partitions('test_hash','key',3);
31+
32+
altertable test_hash drop column b;
33+
createtabletest_dummy (like test_hash);
34+
select replace_hash_partition('test_hash_2','test_dummy', true);
35+
36+
select*from pathman_partition_listorder by parent, partition;
37+
select pg_get_constraintdef(oid, true)from pg_constraintwhere conname='pathman_test_hash_1_check';
38+
select pg_get_constraintdef(oid, true)from pg_constraintwhere conname='pathman_test_dummy_check';
39+
droptable test_hash cascade;
40+
41+
42+
DROPSCHEMA dropped_cols CASCADE;
43+
DROP EXTENSION pg_pathman;

‎src/include/utils.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
boolclause_contains_params(Node*clause);
2525
boolis_date_type_internal(Oidtypid);
2626
boolcheck_security_policy_internal(Oidrelid,Oidrole);
27-
boolmatch_expr_to_operand(Node*expr,Node*operand);
27+
boolmatch_expr_to_operand(constNode*expr,constNode*operand);
2828

2929
/*
3030
* Misc.

‎src/init.c

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1165,7 +1165,6 @@ validate_hash_constraint(const Expr *expr,
11651165
Node*first=linitial(get_hash_expr->args);/* arg #1: TYPE_HASH_PROC(EXPRESSION) */
11661166
Node*second=lsecond(get_hash_expr->args);/* arg #2: PARTITIONS_COUNT */
11671167
Const*cur_partition_idx;/* hash value for this partition */
1168-
Node*hash_arg;
11691168

11701169
if (!IsA(first,FuncExpr)|| !IsA(second,Const))
11711170
return false;
@@ -1180,13 +1179,6 @@ validate_hash_constraint(const Expr *expr,
11801179
if (list_length(type_hash_proc_expr->args)!=1)
11811180
return false;
11821181

1183-
/* Extract arg of TYPE_HASH_PROC() */
1184-
hash_arg= (Node*)linitial(type_hash_proc_expr->args);
1185-
1186-
/* Check arg of TYPE_HASH_PROC() */
1187-
if (!match_expr_to_operand(prel->expr,hash_arg))
1188-
return false;
1189-
11901182
/* Check that PARTITIONS_COUNT is equal to total amount of partitions */
11911183
if (DatumGetUInt32(((Const*)second)->constvalue)!=PrelChildrenCount(prel))
11921184
return false;

‎src/relation_info.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -976,7 +976,7 @@ delay_invalidation_vague_rel(Oid vague_rel)
976976
/* Finish all pending invalidation jobs if possible */
977977
void
978978
finish_delayed_invalidation(void)
979-
{
979+
{
980980
/* Exit early if there's nothing to do */
981981
if (delayed_invalidation_whole_cache== false&&
982982
delayed_invalidation_parent_rels==NIL&&

‎src/utils.c

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,21 @@
3737
#include"utils/regproc.h"
3838
#endif
3939

40+
staticconstNode*
41+
drop_irrelevant_expr_wrappers(constNode*expr)
42+
{
43+
switch (nodeTag(expr))
44+
{
45+
/* Strip relabeling */
46+
caseT_RelabelType:
47+
return (constNode*) ((constRelabelType*)expr)->arg;
48+
49+
/* no special actions required */
50+
default:
51+
returnexpr;
52+
}
53+
}
54+
4055
staticbool
4156
clause_contains_params_walker(Node*node,void*context)
4257
{
@@ -110,14 +125,10 @@ check_security_policy_internal(Oid relid, Oid role)
110125

111126
/* Compare clause operand with expression */
112127
bool
113-
match_expr_to_operand(Node*expr,Node*operand)
128+
match_expr_to_operand(constNode*expr,constNode*operand)
114129
{
115-
/* Strip relabeling for both operand and expr */
116-
if (operand&&IsA(operand,RelabelType))
117-
operand= (Node*) ((RelabelType*)operand)->arg;
118-
119-
if (expr&&IsA(expr,RelabelType))
120-
expr= (Node*) ((RelabelType*)expr)->arg;
130+
expr=drop_irrelevant_expr_wrappers(expr);
131+
operand=drop_irrelevant_expr_wrappers(operand);
121132

122133
/* compare expressions and return result right away */
123134
returnequal(expr,operand);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp