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

Commita694e8c

Browse files
committed
Merge commit 'c9f9831631070fa702481ebaf00a480d1b5732ad' into PGPRO9_6
2 parents565c81c +c9f9831 commita694e8c

16 files changed

+221
-2098
lines changed

‎contrib/pg_pathman/.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
.deps
22
isolation_output
3-
results/pg_pathman.out
3+
results/*
44
regression.diffs
55
regression.out
66
*.o

‎contrib/pg_pathman/expected/pathman_callbacks.out

Lines changed: 13 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,11 @@
22
CREATE EXTENSION pg_pathman;
33
CREATE SCHEMA callbacks;
44
/* Check callbacks */
5-
CREATE TABLE callbacks.log(id serial, message text);
6-
CREATE OR REPLACE FUNCTION callbacks.abc_on_part_created_range_callback(
5+
CREATE OR REPLACE FUNCTION callbacks.abc_on_part_created_callback(
76
args JSONB)
87
RETURNS VOID AS $$
9-
DECLARE
10-
start_valueTEXT := args->>'start';
11-
end_valueTEXT := args->'end';
128
BEGIN
13-
INSERT INTO callbacks.log(message)
14-
VALUES (start_value || '-' || end_value);
15-
END
16-
$$ language plpgsql;
17-
CREATE OR REPLACE FUNCTION callbacks.abc_on_part_created_hash_callback(
18-
args JSONB)
19-
RETURNS VOID AS $$
20-
BEGIN
21-
RAISE WARNING 'callback: partition %', args->'partition';
9+
RAISE WARNING 'callback arg: %', args::TEXT;
2210
END
2311
$$ language plpgsql;
2412
/* set callback to be called on RANGE partitions */
@@ -31,7 +19,7 @@ NOTICE: sequence "abc_seq" does not exist, skipping
3119
(1 row)
3220

3321
SELECT set_part_init_callback('callbacks.abc',
34-
'callbacks.abc_on_part_created_range_callback');
22+
'callbacks.abc_on_part_created_callback');
3523
set_part_init_callback
3624
------------------------
3725

@@ -40,32 +28,26 @@ SELECT set_part_init_callback('callbacks.abc',
4028
INSERT INTO callbacks.abc VALUES (123, 1);
4129
INSERT INTO callbacks.abc VALUES (223, 1);
4230
SELECT append_range_partition('callbacks.abc');
31+
WARNING: callback arg: {"parent": "abc", "parttype": "2", "partition": "abc_4", "range_max": "401", "range_min": "301"}
4332
append_range_partition
4433
------------------------
4534
callbacks.abc_4
4635
(1 row)
4736

4837
SELECT prepend_range_partition('callbacks.abc');
38+
WARNING: callback arg: {"parent": "abc", "parttype": "2", "partition": "abc_5", "range_max": "1", "range_min": "-99"}
4939
prepend_range_partition
5040
-------------------------
5141
callbacks.abc_5
5242
(1 row)
5343

5444
SELECT add_range_partition('callbacks.abc', 401, 502);
45+
WARNING: callback arg: {"parent": "abc", "parttype": "2", "partition": "abc_6", "range_max": "502", "range_min": "401"}
5546
add_range_partition
5647
---------------------
5748
callbacks.abc_6
5849
(1 row)
5950

60-
SELECT message FROM callbacks.log ORDER BY id;
61-
message
62-
-----------
63-
201-"301"
64-
301-"401"
65-
-99-"1"
66-
401-"502"
67-
(4 rows)
68-
6951
SELECT drop_partitions('callbacks.abc');
7052
NOTICE: function callbacks.abc_upd_trig_func() does not exist, skipping
7153
NOTICE: 0 rows copied from callbacks.abc_1
@@ -81,23 +63,23 @@ NOTICE: 0 rows copied from callbacks.abc_6
8163

8264
/* set callback to be called on HASH partitions */
8365
SELECT set_part_init_callback('callbacks.abc',
84-
'callbacks.abc_on_part_created_hash_callback');
66+
'callbacks.abc_on_part_created_callback');
8567
set_part_init_callback
8668
------------------------
8769

8870
(1 row)
8971

9072
SELECT create_hash_partitions('callbacks.abc', 'a', 5);
91-
WARNING: callback:partition "abc_0"
92-
WARNING: callback:partition "abc_1"
93-
WARNING: callback:partition "abc_2"
94-
WARNING: callback:partition "abc_3"
95-
WARNING: callback:partition "abc_4"
73+
WARNING: callback arg: {"parent": "abc", "parttype": "1", "partition": "abc_0"}
74+
WARNING: callback arg: {"parent": "abc", "parttype": "1", "partition": "abc_1"}
75+
WARNING: callback arg: {"parent": "abc", "parttype": "1", "partition": "abc_2"}
76+
WARNING: callback arg: {"parent": "abc", "parttype": "1", "partition": "abc_3"}
77+
WARNING: callback arg: {"parent": "abc", "parttype": "1", "partition": "abc_4"}
9678
create_hash_partitions
9779
------------------------
9880
5
9981
(1 row)
10082

10183
DROP SCHEMA callbacks CASCADE;
102-
NOTICE: drop cascades to10 other objects
84+
NOTICE: drop cascades to8 other objects
10385
DROP EXTENSION pg_pathman CASCADE;

‎contrib/pg_pathman/init.sql

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -514,6 +514,7 @@ DECLARE
514514
v_rowsINTEGER;
515515
v_part_countINTEGER :=0;
516516
conf_num_delINTEGER;
517+
v_relkindCHAR;
517518

518519
BEGIN
519520
PERFORM @extschema@.validate_relname(parent_relid);
@@ -547,7 +548,20 @@ BEGIN
547548
RAISE NOTICE'% rows copied from %', v_rows,v_rec.tbl;
548549
END IF;
549550

550-
EXECUTE format('DROP TABLE %s',v_rec.tbl);
551+
/*
552+
* Determine the kind of child relation. It can be either regular
553+
* table (r) or foreign table (f). Depending on relkind we use
554+
* DROP TABLE or DROP FOREIGN TABLE
555+
*/
556+
EXECUTE format('SELECT relkind FROM pg_class WHERE oid =''%s''::regclass',v_rec.tbl)
557+
INTO v_relkind;
558+
559+
IF v_relkind='f' THEN
560+
EXECUTE format('DROP FOREIGN TABLE %s',v_rec.tbl);
561+
ELSE
562+
EXECUTE format('DROP TABLE %s',v_rec.tbl);
563+
END IF;
564+
551565
v_part_count := v_part_count+1;
552566
END LOOP;
553567

‎contrib/pg_pathman/range.sql

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ RETURNS INTEGER AS
8989
$$
9090
DECLARE
9191
v_rows_countINTEGER;
92+
v_atttypeREGTYPE;
9293
v_maxp_start_value%TYPE;
9394
v_cur_valuep_start_value%TYPE := p_start_value;
9495
p_end_valuep_start_value%TYPE;
@@ -128,6 +129,8 @@ BEGIN
128129
END LOOP;
129130
END IF;
130131

132+
v_atttype := @extschema@.get_base_type(pg_typeof(p_start_value));
133+
131134
/*
132135
* In case when user doesn't want to automatically create partitions
133136
* and specifies partition count as 0 then do not check boundaries
@@ -146,7 +149,7 @@ BEGIN
146149
p_attribute,
147150
p_start_value,
148151
p_end_value,
149-
@extschema@.get_base_type(pg_typeof(p_start_value))::TEXT);
152+
v_atttype::TEXT);
150153
END IF;
151154

152155
/* Create sequence for child partitions names*/
@@ -162,7 +165,7 @@ BEGIN
162165
LOOP
163166
EXECUTE
164167
format('SELECT @extschema@.create_single_range_partition($1, $2, $3::%s, tablespace:=$4)',
165-
@extschema@.get_base_type(pg_typeof(p_start_value))::TEXT)
168+
v_atttype::TEXT)
166169
USING
167170
parent_relid,
168171
p_start_value,
@@ -831,15 +834,18 @@ RETURNS TEXT AS
831834
$$
832835
DECLARE
833836
v_part_nameTEXT;
837+
v_atttypeREGTYPE;
834838

835839
BEGIN
836840
IF @extschema@.partitions_count(parent_relid)=0 THEN
837841
RAISE EXCEPTION'cannot append to empty partitions set';
838842
END IF;
839843

844+
v_atttype := @extschema@.get_base_type(p_atttype);
845+
840846
/* We have to pass fake NULL casted to column's type*/
841847
EXECUTE format('SELECT @extschema@.get_part_range($1, -1, NULL::%s)',
842-
@extschema@.get_base_type(p_atttype)::TEXT)
848+
v_atttype::TEXT)
843849
USING parent_relid
844850
INTO p_range;
845851

@@ -853,7 +859,7 @@ BEGIN
853859
ELSE
854860
EXECUTE
855861
format('SELECT @extschema@.create_single_range_partition($1, $2, $2 + $3::%s, $4, $5)',
856-
@extschema@.get_base_type(p_atttype)::TEXT)
862+
v_atttype::TEXT)
857863
USING
858864
parent_relid,
859865
p_range[2],
@@ -933,15 +939,18 @@ RETURNS TEXT AS
933939
$$
934940
DECLARE
935941
v_part_nameTEXT;
942+
v_atttypeREGTYPE;
936943

937944
BEGIN
938945
IF @extschema@.partitions_count(parent_relid)=0 THEN
939946
RAISE EXCEPTION'cannot prepend to empty partitions set';
940947
END IF;
941948

949+
v_atttype := @extschema@.get_base_type(p_atttype);
950+
942951
/* We have to pass fake NULL casted to column's type*/
943952
EXECUTE format('SELECT @extschema@.get_part_range($1, 0, NULL::%s)',
944-
@extschema@.get_base_type(p_atttype)::TEXT)
953+
v_atttype::TEXT)
945954
USING parent_relid
946955
INTO p_range;
947956

@@ -955,7 +964,7 @@ BEGIN
955964
ELSE
956965
EXECUTE
957966
format('SELECT @extschema@.create_single_range_partition($1, $2 - $3::%s, $2, $4, $5)',
958-
@extschema@.get_base_type(p_atttype)::TEXT)
967+
v_atttype::TEXT)
959968
USING
960969
parent_relid,
961970
p_range[1],
@@ -1117,7 +1126,7 @@ DECLARE
11171126
parent_relidREGCLASS;
11181127

11191128
BEGIN
1120-
parent_relid= @extschema@.get_parent_of_partition(p_partition);
1129+
parent_relid:= @extschema@.get_parent_of_partition(p_partition);
11211130

11221131
/* Acquire lock on parent*/
11231132
PERFORM @extschema@.lock_partitioned_relation(parent_relid);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp