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

Commit922a1dd

Browse files
committed
Merge branch 'callback_fix' into rel_1_2_beta
2 parentsc3e8ed8 +9295350 commit922a1dd

13 files changed

+311
-57
lines changed

‎Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ MODULE_big = pg_pathman
44
OBJS = src/init.o src/relation_info.o src/utils.o src/partition_filter.o\
55
src/runtimeappend.o src/runtime_merge_append.o src/pg_pathman.o src/rangeset.o\
66
src/pl_funcs.o src/pl_range_funcs.o src/pl_hash_funcs.o src/pathman_workers.o\
7-
src/hooks.o src/nodes_common.o src/xact_handling.o src/copy_stmt_hooking.o\
7+
src/hooks.o src/nodes_common.o src/xact_handling.o src/utility_stmt_hooking.o\
88
src/planner_tree_modification.o src/debug_print.o src/pg_compat.o\
99
src/partition_creation.o$(WIN32RES)
1010

@@ -21,7 +21,7 @@ REGRESS = pathman_basic \
2121
pathman_foreign_keys\
2222
pathman_permissions\
2323
pathman_rowmarks\
24-
pathman_copy_stmt_hooking\
24+
pathman_utility_stmt_hooking\
2525
pathman_calamity
2626
EXTRA_REGRESS_OPTS=--temp-config=$(top_srcdir)/$(subdir)/conf.add
2727
EXTRA_CLEAN = pg_pathman--$(EXTVERSION).sql ./isolation_output

‎expected/pathman_basic.out

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2193,31 +2193,31 @@ NOTICE: sequence "index_on_childs_seq" does not exist, skipping
21932193
0
21942194
(1 row)
21952195

2196-
SELECT add_range_partition('test.index_on_childs', 1, 1000, 'test.index_on_childs_1_1K');
2196+
SELECT add_range_partition('test.index_on_childs', 1, 1000, 'test.index_on_childs_1_1k');
21972197
add_range_partition
21982198
---------------------------
21992199
test.index_on_childs_1_1k
22002200
(1 row)
22012201

2202-
SELECT append_range_partition('test.index_on_childs', 'test.index_on_childs_1K_2K');
2202+
SELECT append_range_partition('test.index_on_childs', 'test.index_on_childs_1k_2k');
22032203
append_range_partition
22042204
----------------------------
22052205
test.index_on_childs_1k_2k
22062206
(1 row)
22072207

2208-
SELECT append_range_partition('test.index_on_childs', 'test.index_on_childs_2K_3K');
2208+
SELECT append_range_partition('test.index_on_childs', 'test.index_on_childs_2k_3k');
22092209
append_range_partition
22102210
----------------------------
22112211
test.index_on_childs_2k_3k
22122212
(1 row)
22132213

2214-
SELECT append_range_partition('test.index_on_childs', 'test.index_on_childs_3K_4K');
2214+
SELECT append_range_partition('test.index_on_childs', 'test.index_on_childs_3k_4k');
22152215
append_range_partition
22162216
----------------------------
22172217
test.index_on_childs_3k_4k
22182218
(1 row)
22192219

2220-
SELECT append_range_partition('test.index_on_childs', 'test.index_on_childs_4K_5K');
2220+
SELECT append_range_partition('test.index_on_childs', 'test.index_on_childs_4k_5k');
22212221
append_range_partition
22222222
----------------------------
22232223
test.index_on_childs_4k_5k

‎expected/pathman_copy_stmt_hooking.outrenamed to‎expected/pathman_utility_stmt_hooking.out

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
\set VERBOSITY terse
22
CREATE EXTENSION pg_pathman;
3+
/*
4+
* Test COPY
5+
*/
36
CREATE SCHEMA copy_stmt_hooking;
47
CREATE TABLE copy_stmt_hooking.test(
58
val int not null,
@@ -190,4 +193,92 @@ SELECT * FROM copy_stmt_hooking.test ORDER BY val;
190193

191194
DROP SCHEMA copy_stmt_hooking CASCADE;
192195
NOTICE: drop cascades to 7 other objects
196+
/*
197+
* Test auto check constraint renaming
198+
*/
199+
CREATE SCHEMA rename;
200+
CREATE TABLE rename.test(a serial, b int);
201+
SELECT create_hash_partitions('rename.test', 'a', 3);
202+
create_hash_partitions
203+
------------------------
204+
3
205+
(1 row)
206+
207+
ALTER TABLE rename.test_0 RENAME TO test_one;
208+
/* We expect to find check constraint renamed as well */
209+
\d+ rename.test_one
210+
Table "rename.test_one"
211+
Column | Type | Modifiers | Storage | Stats target | Description
212+
--------+---------+---------------------------------------------------------+---------+--------------+-------------
213+
a | integer | not null default nextval('rename.test_a_seq'::regclass) | plain | |
214+
b | integer | | plain | |
215+
Check constraints:
216+
"pathman_test_one_1_check" CHECK (get_hash_part_idx(hashint4(a), 3) = 0)
217+
Inherits: rename.test
218+
219+
/* Generates check constraint for relation */
220+
CREATE OR REPLACE FUNCTION add_constraint(rel regclass, att text)
221+
RETURNS VOID AS $$
222+
declare
223+
constraint_name text := build_check_constraint_name(rel, 'a');
224+
BEGIN
225+
EXECUTE format('ALTER TABLE %s ADD CONSTRAINT %s CHECK (a < 100);',
226+
rel, constraint_name);
227+
END
228+
$$
229+
LANGUAGE plpgsql;
230+
/*
231+
* Check that it doesn't affect regular inherited
232+
* tables that aren't managed by pg_pathman
233+
*/
234+
CREATE TABLE rename.test_inh (LIKE rename.test INCLUDING ALL);
235+
CREATE TABLE rename.test_inh_1 (LIKE rename.test INCLUDING ALL);
236+
ALTER TABLE rename.test_inh_1 INHERIT rename.test_inh;
237+
SELECT add_constraint('rename.test_inh_1', 'a');
238+
add_constraint
239+
----------------
240+
241+
(1 row)
242+
243+
ALTER TABLE rename.test_inh_1 RENAME TO test_inh_one;
244+
\d+ rename.test_inh_one
245+
Table "rename.test_inh_one"
246+
Column | Type | Modifiers | Storage | Stats target | Description
247+
--------+---------+---------------------------------------------------------+---------+--------------+-------------
248+
a | integer | not null default nextval('rename.test_a_seq'::regclass) | plain | |
249+
b | integer | | plain | |
250+
Check constraints:
251+
"pathman_test_inh_1_1_check" CHECK (a < 100)
252+
Inherits: rename.test_inh
253+
254+
/* Check that plain tables are not affected too */
255+
CREATE TABLE rename.plain_test(a serial, b int);
256+
ALTER TABLE rename.plain_test RENAME TO plain_test_renamed;
257+
SELECT add_constraint('rename.plain_test_renamed', 'a');
258+
add_constraint
259+
----------------
260+
261+
(1 row)
262+
263+
\d+ rename.plain_test_renamed
264+
Table "rename.plain_test_renamed"
265+
Column | Type | Modifiers | Storage | Stats target | Description
266+
--------+---------+---------------------------------------------------------------+---------+--------------+-------------
267+
a | integer | not null default nextval('rename.plain_test_a_seq'::regclass) | plain | |
268+
b | integer | | plain | |
269+
Check constraints:
270+
"pathman_plain_test_renamed_1_check" CHECK (a < 100)
271+
272+
ALTER TABLE rename.plain_test_renamed RENAME TO plain_test;
273+
\d+ rename.plain_test
274+
Table "rename.plain_test"
275+
Column | Type | Modifiers | Storage | Stats target | Description
276+
--------+---------+---------------------------------------------------------------+---------+--------------+-------------
277+
a | integer | not null default nextval('rename.plain_test_a_seq'::regclass) | plain | |
278+
b | integer | | plain | |
279+
Check constraints:
280+
"pathman_plain_test_renamed_1_check" CHECK (a < 100)
281+
282+
DROP SCHEMA rename CASCADE;
283+
NOTICE: drop cascades to 7 other objects
193284
DROP EXTENSION pg_pathman;

‎sql/pathman_basic.sql

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -630,11 +630,11 @@ CREATE TABLE test.index_on_childs(c1 integer not null, c2 integer);
630630
CREATEINDEXONtest.index_on_childs(c2);
631631
INSERT INTOtest.index_on_childsSELECT i, (random()*10000)::integerFROM generate_series(1,10000) i;
632632
SELECT create_range_partitions('test.index_on_childs','c1',1,1000,0, false);
633-
SELECT add_range_partition('test.index_on_childs',1,1000,'test.index_on_childs_1_1K');
634-
SELECT append_range_partition('test.index_on_childs','test.index_on_childs_1K_2K');
635-
SELECT append_range_partition('test.index_on_childs','test.index_on_childs_2K_3K');
636-
SELECT append_range_partition('test.index_on_childs','test.index_on_childs_3K_4K');
637-
SELECT append_range_partition('test.index_on_childs','test.index_on_childs_4K_5K');
633+
SELECT add_range_partition('test.index_on_childs',1,1000,'test.index_on_childs_1_1k');
634+
SELECT append_range_partition('test.index_on_childs','test.index_on_childs_1k_2k');
635+
SELECT append_range_partition('test.index_on_childs','test.index_on_childs_2k_3k');
636+
SELECT append_range_partition('test.index_on_childs','test.index_on_childs_3k_4k');
637+
SELECT append_range_partition('test.index_on_childs','test.index_on_childs_4k_5k');
638638
SELECT set_enable_parent('test.index_on_childs', true);
639639
VACUUM ANALYZEtest.index_on_childs;
640640
EXPLAIN (COSTS OFF)SELECT*FROMtest.index_on_childsWHERE c1>100AND c1<2500AND c2=500;

‎sql/pathman_copy_stmt_hooking.sqlrenamed to‎sql/pathman_utility_stmt_hooking.sql

Lines changed: 50 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
\set VERBOSITY terse
22

33
CREATE EXTENSION pg_pathman;
4-
CREATESCHEMAcopy_stmt_hooking;
5-
64

5+
/*
6+
* Test COPY
7+
*/
8+
CREATESCHEMAcopy_stmt_hooking;
79
CREATETABLEcopy_stmt_hooking.test(
810
valintnot null,
911
commenttext,
@@ -89,6 +91,51 @@ COPY copy_stmt_hooking.test FROM stdin;
8991
SELECTcount(*)FROM ONLYcopy_stmt_hooking.test;
9092
SELECT*FROMcopy_stmt_hooking.testORDER BY val;
9193

92-
9394
DROPSCHEMA copy_stmt_hooking CASCADE;
95+
96+
97+
/*
98+
* Test auto check constraint renaming
99+
*/
100+
CREATESCHEMArename;
101+
102+
CREATETABLErename.test(aserial, bint);
103+
SELECT create_hash_partitions('rename.test','a',3);
104+
ALTERTABLErename.test_0 RENAME TO test_one;
105+
/* We expect to find check constraint renamed as well*/
106+
\d+rename.test_one
107+
108+
/* Generates check constraint for relation*/
109+
CREATE OR REPLACEFUNCTIONadd_constraint(rel regclass, atttext)
110+
RETURNS VOIDAS $$
111+
declare
112+
constraint_nametext := build_check_constraint_name(rel,'a');
113+
BEGIN
114+
EXECUTE format('ALTER TABLE %s ADD CONSTRAINT %s CHECK (a < 100);',
115+
rel, constraint_name);
116+
END
117+
$$
118+
LANGUAGE plpgsql;
119+
120+
/*
121+
* Check that it doesn't affect regular inherited
122+
* tables that aren't managed by pg_pathman
123+
*/
124+
CREATETABLErename.test_inh (LIKErename.test INCLUDING ALL);
125+
CREATETABLErename.test_inh_1 (LIKErename.test INCLUDING ALL);
126+
ALTERTABLErename.test_inh_1 INHERITrename.test_inh;
127+
SELECT add_constraint('rename.test_inh_1','a');
128+
ALTERTABLErename.test_inh_1 RENAME TO test_inh_one;
129+
\d+rename.test_inh_one
130+
131+
/* Check that plain tables are not affected too*/
132+
CREATETABLErename.plain_test(aserial, bint);
133+
ALTERTABLErename.plain_test RENAME TO plain_test_renamed;
134+
SELECT add_constraint('rename.plain_test_renamed','a');
135+
\d+rename.plain_test_renamed
136+
ALTERTABLErename.plain_test_renamed RENAME TO plain_test;
137+
\d+rename.plain_test
138+
139+
DROPSCHEMA rename CASCADE;
140+
94141
DROP EXTENSION pg_pathman;

‎src/hooks.c

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* ------------------------------------------------------------------------
99
*/
1010

11-
#include"copy_stmt_hooking.h"
11+
#include"utility_stmt_hooking.h"
1212
#include"hooks.h"
1313
#include"init.h"
1414
#include"partition_filter.h"
@@ -24,6 +24,7 @@
2424
#include"optimizer/cost.h"
2525
#include"optimizer/restrictinfo.h"
2626
#include"utils/typcache.h"
27+
#include"utils/lsyscache.h"
2728

2829

2930
set_join_pathlist_hook_typeset_join_pathlist_next=NULL;
@@ -650,18 +651,32 @@ pathman_process_utility_hook(Node *parsetree,
650651
DestReceiver*dest,
651652
char*completionTag)
652653
{
653-
/* Override standard COPY statement if needed */
654-
if (IsPathmanReady()&&is_pathman_related_copy(parsetree))
654+
if (IsPathmanReady())
655655
{
656-
uint64processed;
656+
Oidpartition_relid;
657+
AttrNumberpartitioned_col;
658+
659+
/* Override standard COPY statement if needed */
660+
if (is_pathman_related_copy(parsetree))
661+
{
662+
uint64processed;
657663

658-
/* Handle our COPY case (and show a special cmd name) */
659-
PathmanDoCopy((CopyStmt*)parsetree,queryString,&processed);
660-
if (completionTag)
661-
snprintf(completionTag,COMPLETION_TAG_BUFSIZE,
662-
"PATHMAN COPY "UINT64_FORMAT,processed);
664+
/* Handle our COPY case (and show a special cmd name) */
665+
PathmanDoCopy((CopyStmt*)parsetree,queryString,&processed);
666+
if (completionTag)
667+
snprintf(completionTag,COMPLETION_TAG_BUFSIZE,
668+
"PATHMAN COPY "UINT64_FORMAT,processed);
669+
670+
return;/* don't call standard_ProcessUtility() or hooks */
671+
}
663672

664-
return;/* don't call standard_ProcessUtility() or hooks */
673+
/* Override standard RENAME statement if needed */
674+
if (is_pathman_related_table_rename(parsetree,
675+
&partition_relid,
676+
&partitioned_col))
677+
PathmanRenameConstraint(partition_relid,
678+
partitioned_col,
679+
(constRenameStmt*)parsetree);
665680
}
666681

667682
/* Call hooks set by other extensions if needed */

‎src/init.c

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -593,12 +593,18 @@ find_inheritance_children_array(Oid parentrelId,
593593
/*
594594
* Generate check constraint name for a partition.
595595
*
596-
*This function does not perform sanity checks at all.
596+
*These functions does not perform sanity checks at all.
597597
*/
598598
char*
599-
build_check_constraint_name_internal(Oidrelid,AttrNumberattno)
599+
build_check_constraint_name_relid_internal(Oidrelid,AttrNumberattno)
600+
{
601+
returnbuild_check_constraint_name_relname_internal(get_rel_name(relid),attno);
602+
}
603+
604+
char*
605+
build_check_constraint_name_relname_internal(constchar*relname,AttrNumberattno)
600606
{
601-
returnpsprintf("pathman_%s_%u_check",get_rel_name(relid),attno);
607+
returnpsprintf("pathman_%s_%u_check",relname,attno);
602608
}
603609

604610
/*
@@ -818,7 +824,7 @@ get_partition_constraint_expr(Oid partition, AttrNumber part_attno)
818824
boolconbin_isnull;
819825
Expr*expr;/* expression tree for constraint */
820826

821-
conname=build_check_constraint_name_internal(partition,part_attno);
827+
conname=build_check_constraint_name_relid_internal(partition,part_attno);
822828
conid=get_relation_constraint_oid(partition,conname, true);
823829
if (conid==InvalidOid)
824830
{

‎src/init.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,11 @@ find_children_status find_inheritance_children_array(Oid parentrelId,
123123
uint32*children_size,
124124
Oid**children);
125125

126-
char*build_check_constraint_name_internal(Oidrelid,
127-
AttrNumberattno);
126+
char*build_check_constraint_name_relid_internal(Oidrelid,
127+
AttrNumberattno);
128+
129+
char*build_check_constraint_name_relname_internal(constchar*relname,
130+
AttrNumberattno);
128131

129132
char*build_sequence_name_internal(Oidrelid);
130133

‎src/partition_creation.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -901,7 +901,8 @@ build_range_check_constraint(Oid child_relid,
901901

902902
/* Build a correct name for this constraint */
903903
attnum=get_attnum(child_relid,attname);
904-
range_constr_name=build_check_constraint_name_internal(child_relid,attnum);
904+
range_constr_name=build_check_constraint_name_relid_internal(child_relid,
905+
attnum);
905906

906907
/* Initialize basic properties of a CHECK constraint */
907908
hash_constr=make_constraint_common(range_constr_name,

‎src/pl_funcs.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -505,7 +505,7 @@ build_check_constraint_name_attnum(PG_FUNCTION_ARGS)
505505
elog(ERROR,"Cannot build check constraint name: "
506506
"invalid attribute number %i",attnum);
507507

508-
result=build_check_constraint_name_internal(relid,attnum);
508+
result=build_check_constraint_name_relid_internal(relid,attnum);
509509

510510
PG_RETURN_TEXT_P(cstring_to_text(quote_identifier(result)));
511511
}
@@ -525,7 +525,7 @@ build_check_constraint_name_attname(PG_FUNCTION_ARGS)
525525
elog(ERROR,"relation \"%s\" has no column \"%s\"",
526526
get_rel_name_or_relid(relid),text_to_cstring(attname));
527527

528-
result=build_check_constraint_name_internal(relid,attnum);
528+
result=build_check_constraint_name_relid_internal(relid,attnum);
529529

530530
PG_RETURN_TEXT_P(cstring_to_text(quote_identifier(result)));
531531
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp