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

Commit085c33f

Browse files
committed
Fix tests related with update triggers, build_constraint_name function and others
1 parentbf4ecb8 commit085c33f

File tree

9 files changed

+35
-78
lines changed

9 files changed

+35
-78
lines changed

‎expected/pathman_calamity.out

Lines changed: 3 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -301,51 +301,14 @@ SELECT get_partition_key_type(NULL) IS NULL;
301301
t
302302
(1 row)
303303

304-
/* check functionbuild_check_constraint_name_attnum() */
305-
SELECT build_check_constraint_name('calamity.part_test', 1::int2);
304+
/* check functionbuild_check_constraint_name() */
305+
SELECT build_check_constraint_name('calamity.part_test');
306306
build_check_constraint_name
307307
-----------------------------
308308
pathman_part_test_check
309309
(1 row)
310310

311-
SELECT build_check_constraint_name('calamity.part_test', NULL::int2) IS NULL;
312-
?column?
313-
----------
314-
t
315-
(1 row)
316-
317-
SELECT build_check_constraint_name(NULL, 1::int2) IS NULL;
318-
?column?
319-
----------
320-
t
321-
(1 row)
322-
323-
SELECT build_check_constraint_name(NULL, NULL::int2) IS NULL;
324-
?column?
325-
----------
326-
t
327-
(1 row)
328-
329-
/* check function build_check_constraint_name_attname() */
330-
SELECT build_check_constraint_name('calamity.part_test', 'val');
331-
build_check_constraint_name
332-
-----------------------------
333-
pathman_part_test_check
334-
(1 row)
335-
336-
SELECT build_check_constraint_name('calamity.part_test', NULL::text) IS NULL;
337-
?column?
338-
----------
339-
t
340-
(1 row)
341-
342-
SELECT build_check_constraint_name(NULL, 'val') IS NULL;
343-
?column?
344-
----------
345-
t
346-
(1 row)
347-
348-
SELECT build_check_constraint_name(NULL, NULL::text) IS NULL;
311+
SELECT build_check_constraint_name(NULL) IS NULL;
349312
?column?
350313
----------
351314
t

‎expected/pathman_utility_stmt.out

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -282,10 +282,10 @@ Check constraints:
282282
Inherits: rename.test
283283

284284
/* Generates check constraint for relation */
285-
CREATE OR REPLACE FUNCTION add_constraint(rel regclass, att text)
285+
CREATE OR REPLACE FUNCTION add_constraint(rel regclass)
286286
RETURNS VOID AS $$
287287
declare
288-
constraint_name text := build_check_constraint_name(rel, 'a');
288+
constraint_name text := build_check_constraint_name(rel);
289289
BEGIN
290290
EXECUTE format('ALTER TABLE %s ADD CONSTRAINT %s CHECK (a < 100);',
291291
rel, constraint_name);
@@ -299,7 +299,7 @@ LANGUAGE plpgsql;
299299
CREATE TABLE rename.test_inh (LIKE rename.test INCLUDING ALL);
300300
CREATE TABLE rename.test_inh_1 (LIKE rename.test INCLUDING ALL);
301301
ALTER TABLE rename.test_inh_1 INHERIT rename.test_inh;
302-
SELECT add_constraint('rename.test_inh_1', 'a');
302+
SELECT add_constraint('rename.test_inh_1');
303303
add_constraint
304304
----------------
305305

@@ -319,7 +319,7 @@ Inherits: rename.test_inh
319319
/* Check that plain tables are not affected too */
320320
CREATE TABLE rename.plain_test(a serial, b int);
321321
ALTER TABLE rename.plain_test RENAME TO plain_test_renamed;
322-
SELECT add_constraint('rename.plain_test_renamed', 'a');
322+
SELECT add_constraint('rename.plain_test_renamed');
323323
add_constraint
324324
----------------
325325

‎hash.sql

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -113,15 +113,14 @@ BEGIN
113113
RAISE EXCEPTION'partition must have a compatible tuple format';
114114
END IF;
115115

116-
/* Get partitioningkey*/
116+
/* Get partitioningexpression*/
117117
part_attname := attnameFROM @extschema@.pathman_configWHERE partrel= parent_relid;
118118
IF part_attname ISNULL THEN
119119
RAISE EXCEPTION'table "%" is not partitioned', parent_relid::TEXT;
120120
END IF;
121121

122122
/* Fetch name of old_partition's HASH constraint*/
123-
old_constr_name= @extschema@.build_check_constraint_name(old_partition::REGCLASS,
124-
part_attname);
123+
old_constr_name= @extschema@.build_check_constraint_name(old_partition::REGCLASS);
125124

126125
/* Fetch definition of old_partition's HASH constraint*/
127126
SELECTpg_catalog.pg_get_constraintdef(oid)FROMpg_catalog.pg_constraint
@@ -138,8 +137,7 @@ BEGIN
138137
EXECUTE format('ALTER TABLE %s INHERIT %s', new_partition, parent_relid);
139138
EXECUTE format('ALTER TABLE %s ADD CONSTRAINT %s %s',
140139
new_partition,
141-
@extschema@.build_check_constraint_name(new_partition::REGCLASS,
142-
part_attname),
140+
@extschema@.build_check_constraint_name(new_partition::REGCLASS),
143141
old_constr_def);
144142

145143
/* Fetch init_callback from 'params' table*/

‎init.sql

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -879,13 +879,15 @@ LANGUAGE C STRICT;
879879

880880

881881
/*
882-
* Attach a previously partitioned table.
882+
* Add record to pathman_config. If parttype if not specified then determine
883+
* partitioning type.
883884
*/
884885
CREATEOR REPLACE FUNCTION @extschema@.add_to_pathman_config(
885886
parent_relidREGCLASS,
886887
attnameTEXT,
887888
range_intervalTEXT DEFAULTNULL,
888-
refresh_part_infoBOOL DEFAULT TRUE
889+
refresh_part_infoBOOL DEFAULT TRUE,
890+
parttypeINT4 DEFAULT0
889891
)
890892
RETURNSBOOLEANAS'pg_pathman','add_to_pathman_config'
891893
LANGUAGE C;

‎range.sql

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ $$ LANGUAGE plpgsql;
290290
*/
291291
CREATEOR REPLACE FUNCTION @extschema@.create_range_partitions(
292292
parent_relidREGCLASS,
293-
attributeTEXT,
293+
expressionTEXT,
294294
boundsANYARRAY,
295295
partition_namesTEXT[] DEFAULTNULL,
296296
tablespacesTEXT[] DEFAULTNULL,
@@ -308,17 +308,17 @@ BEGIN
308308
RAISE EXCEPTION'Bounds array must have at least two values';
309309
END IF;
310310

311-
attribute :=lower(attribute);
312-
PERFORM @extschema@.prepare_for_partitioning(parent_relid,attribute, partition_data);
311+
expression :=lower(expression);
312+
PERFORM @extschema@.prepare_for_partitioning(parent_relid,expression, partition_data);
313313

314314
/* Check boundaries*/
315315
PERFORM @extschema@.check_boundaries(parent_relid,
316-
attribute,
316+
expression,
317317
bounds[0],
318318
bounds[array_length(bounds,1)-1]);
319319

320-
INSERT INTO @extschema@.pathman_config (partrel, attname, parttype, range_interval)
321-
VALUES(parent_relid,attribute,2,NULL);
320+
/* Insert new entry to pathman config*/
321+
PERFORM @extschema@.add_to_pathman_config(parent_relid,expression,NULL, false,2);
322322

323323
/* Create sequence for child partitions names*/
324324
PERFORM @extschema@.create_or_replace_sequence(parent_relid)
@@ -548,7 +548,7 @@ BEGIN
548548
/* Alter original partition*/
549549
v_cond := @extschema@.build_range_condition(partition_relid::regclass,
550550
v_attname, p_range[1], split_value);
551-
v_check_name := @extschema@.build_check_constraint_name(partition_relid, v_attname);
551+
v_check_name := @extschema@.build_check_constraint_name(partition_relid);
552552

553553
EXECUTE format('ALTER TABLE %s DROP CONSTRAINT %s',
554554
partition_relid::TEXT,
@@ -959,7 +959,7 @@ BEGIN
959959
/* Set check constraint*/
960960
EXECUTE format('ALTER TABLE %s ADD CONSTRAINT %s CHECK (%s)',
961961
partition_relid::TEXT,
962-
@extschema@.build_check_constraint_name(partition_relid, v_attname),
962+
@extschema@.build_check_constraint_name(partition_relid),
963963
@extschema@.build_range_condition(partition_relid,
964964
v_attname,
965965
start_value,
@@ -1026,7 +1026,7 @@ BEGIN
10261026
/* Remove check constraint*/
10271027
EXECUTE format('ALTER TABLE %s DROP CONSTRAINT %s',
10281028
partition_relid::TEXT,
1029-
@extschema@.build_check_constraint_name(partition_relid, v_attname));
1029+
@extschema@.build_check_constraint_name(partition_relid));
10301030

10311031
/* Remove update trigger*/
10321032
EXECUTE format('DROP TRIGGER IF EXISTS %s ON %s',

‎sql/pathman_calamity.sql

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -137,17 +137,9 @@ SELECT get_partition_key_type('calamity.part_test');
137137
SELECT get_partition_key_type(0::regclass);
138138
SELECT get_partition_key_type(NULL) ISNULL;
139139

140-
/* check function build_check_constraint_name_attnum()*/
141-
SELECT build_check_constraint_name('calamity.part_test',1::int2);
142-
SELECT build_check_constraint_name('calamity.part_test',NULL::int2) ISNULL;
143-
SELECT build_check_constraint_name(NULL,1::int2) ISNULL;
144-
SELECT build_check_constraint_name(NULL,NULL::int2) ISNULL;
145-
146-
/* check function build_check_constraint_name_attname()*/
147-
SELECT build_check_constraint_name('calamity.part_test','val');
148-
SELECT build_check_constraint_name('calamity.part_test',NULL::text) ISNULL;
149-
SELECT build_check_constraint_name(NULL,'val') ISNULL;
150-
SELECT build_check_constraint_name(NULL,NULL::text) ISNULL;
140+
/* check function build_check_constraint_name()*/
141+
SELECT build_check_constraint_name('calamity.part_test');
142+
SELECT build_check_constraint_name(NULL) ISNULL;
151143

152144
/* check function build_update_trigger_name()*/
153145
SELECT build_update_trigger_name('calamity.part_test');

‎sql/pathman_utility_stmt.sql

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -154,10 +154,10 @@ ALTER TABLE rename.test_0 RENAME TO test_one;
154154
\d+rename.test_one
155155

156156
/* Generates check constraint for relation*/
157-
CREATE OR REPLACEFUNCTIONadd_constraint(rel regclass, atttext)
157+
CREATE OR REPLACEFUNCTIONadd_constraint(rel regclass)
158158
RETURNS VOIDAS $$
159159
declare
160-
constraint_nametext := build_check_constraint_name(rel,'a');
160+
constraint_nametext := build_check_constraint_name(rel);
161161
BEGIN
162162
EXECUTE format('ALTER TABLE %s ADD CONSTRAINT %s CHECK (a < 100);',
163163
rel, constraint_name);
@@ -172,14 +172,14 @@ LANGUAGE plpgsql;
172172
CREATETABLErename.test_inh (LIKErename.test INCLUDING ALL);
173173
CREATETABLErename.test_inh_1 (LIKErename.test INCLUDING ALL);
174174
ALTERTABLErename.test_inh_1 INHERITrename.test_inh;
175-
SELECT add_constraint('rename.test_inh_1','a');
175+
SELECT add_constraint('rename.test_inh_1');
176176
ALTERTABLErename.test_inh_1 RENAME TO test_inh_one;
177177
\d+rename.test_inh_one
178178

179179
/* Check that plain tables are not affected too*/
180180
CREATETABLErename.plain_test(aserial, bint);
181181
ALTERTABLErename.plain_test RENAME TO plain_test_renamed;
182-
SELECT add_constraint('rename.plain_test_renamed','a');
182+
SELECT add_constraint('rename.plain_test_renamed');
183183
\d+rename.plain_test_renamed
184184
ALTERTABLErename.plain_test_renamed RENAME TO plain_test;
185185
\d+rename.plain_test

‎src/partition_creation.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1880,7 +1880,7 @@ extract_column_names(Node *node, struct extract_column_names_context *ctx)
18801880
ListCell*lc;
18811881
foreach(lc, ((ColumnRef*)node)->fields)
18821882
if (IsA(lfirst(lc),String))
1883-
ctx->columns=lappend(ctx->columns,strVal(lfirst(lc)));
1883+
ctx->columns=lappend(ctx->columns,lfirst(lc));
18841884
}
18851885

18861886
returnraw_expression_tree_walker(node,extract_column_names,ctx);

‎src/pl_funcs.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -744,8 +744,10 @@ add_to_pathman_config(PG_FUNCTION_ARGS)
744744
get_rel_name_or_relid(relid));
745745
}
746746

747-
/* Select partitioning type using 'range_interval' */
748-
parttype=PG_ARGISNULL(2) ?PT_HASH :PT_RANGE;
747+
/* Select partitioning type */
748+
parttype=PG_GETARG_INT32(4);
749+
if ((parttype!=PT_HASH)&& (parttype!=PT_RANGE))
750+
parttype=PG_ARGISNULL(2) ?PT_HASH :PT_RANGE;
749751

750752
/* Parse and check expression */
751753
expression=TextDatumGetCString(PG_GETARG_TEXT_P(1));

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp