Skip to content

Commit 4586e55

Browse files
committed
Merge branch 'rel_1_2_beta' into rel_1_2_infinite
2 parents 5531ce0 + 5d11c16 commit 4586e55

26 files changed

+1986
-937
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: 119 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ INSERT INTO test.hash_rel VALUES (1, 1);
1010
INSERT INTO test.hash_rel VALUES (2, 2);
1111
INSERT INTO test.hash_rel VALUES (3, 3);
1212
SELECT pathman.create_hash_partitions('test.hash_rel', 'value', 3);
13-
ERROR: partitioning key 'value' must be NOT NULL
13+
ERROR: partitioning key "value" must be NOT NULL
1414
ALTER TABLE test.hash_rel ALTER COLUMN value SET NOT NULL;
1515
SELECT pathman.create_hash_partitions('test.hash_rel', 'value', 3, partition_data:=false);
1616
create_hash_partitions
@@ -131,10 +131,10 @@ CREATE INDEX ON test.range_rel (dt);
131131
INSERT INTO test.range_rel (dt, txt)
132132
SELECT g, md5(g::TEXT) FROM generate_series('2015-01-01', '2015-04-30', '1 day'::interval) as g;
133133
SELECT pathman.create_range_partitions('test.range_rel', 'dt', '2015-01-01'::DATE, '1 month'::INTERVAL, 2);
134-
ERROR: partitioning key 'dt' must be NOT NULL
134+
ERROR: partitioning key "dt" must be NOT NULL
135135
ALTER TABLE test.range_rel ALTER COLUMN dt SET NOT NULL;
136136
SELECT pathman.create_range_partitions('test.range_rel', 'dt', '2015-01-01'::DATE, '1 month'::INTERVAL, 2);
137-
ERROR: not enough partitions to fit all values of 'dt'
137+
ERROR: not enough partitions to fit all values of "dt"
138138
SELECT pathman.create_range_partitions('test.range_rel', 'DT', '2015-01-01'::DATE, '1 month'::INTERVAL);
139139
NOTICE: sequence "range_rel_seq" does not exist, skipping
140140
create_range_partitions
@@ -1080,6 +1080,64 @@ WHERE j1.dt < '2015-03-01' AND j2.dt >= '2015-02-01' ORDER BY j2.dt;
10801080
-> Index Scan using range_rel_2_pkey on range_rel_2 j1_1
10811081
(20 rows)
10821082

1083+
/*
1084+
* Test inlined SQL functions
1085+
*/
1086+
CREATE TABLE test.sql_inline (id INT NOT NULL);
1087+
SELECT pathman.create_hash_partitions('test.sql_inline', 'id', 3);
1088+
create_hash_partitions
1089+
------------------------
1090+
3
1091+
(1 row)
1092+
1093+
CREATE OR REPLACE FUNCTION test.sql_inline_func(i_id int) RETURNS SETOF INT AS $$
1094+
select * from test.sql_inline where id = i_id limit 1;
1095+
$$ LANGUAGE sql STABLE;
1096+
EXPLAIN (COSTS OFF) SELECT * FROM test.sql_inline_func(5);
1097+
QUERY PLAN
1098+
--------------------------------------
1099+
Limit
1100+
-> Append
1101+
-> Seq Scan on sql_inline_0
1102+
Filter: (id = 5)
1103+
(4 rows)
1104+
1105+
EXPLAIN (COSTS OFF) SELECT * FROM test.sql_inline_func(1);
1106+
QUERY PLAN
1107+
--------------------------------------
1108+
Limit
1109+
-> Append
1110+
-> Seq Scan on sql_inline_2
1111+
Filter: (id = 1)
1112+
(4 rows)
1113+
1114+
DROP FUNCTION test.sql_inline_func(int);
1115+
DROP TABLE test.sql_inline CASCADE;
1116+
NOTICE: drop cascades to 3 other objects
1117+
/*
1118+
* Test by @baiyinqiqi (issue #60)
1119+
*/
1120+
CREATE TABLE test.hash_varchar(val VARCHAR(40) NOT NULL);
1121+
INSERT INTO test.hash_varchar SELECT generate_series(1, 20);
1122+
SELECT pathman.create_hash_partitions('test.hash_varchar', 'val', 4);
1123+
create_hash_partitions
1124+
------------------------
1125+
4
1126+
(1 row)
1127+
1128+
SELECT * FROM test.hash_varchar WHERE val = 'a';
1129+
val
1130+
-----
1131+
(0 rows)
1132+
1133+
SELECT * FROM test.hash_varchar WHERE val = '12'::TEXT;
1134+
val
1135+
-----
1136+
12
1137+
(1 row)
1138+
1139+
DROP TABLE test.hash_varchar CASCADE;
1140+
NOTICE: drop cascades to 4 other objects
10831141
/*
10841142
* Test CTE query
10851143
*/
@@ -1563,14 +1621,64 @@ SELECT * FROM test.hash_rel WHERE id = 123;
15631621
123 | 456 | 789
15641622
(1 row)
15651623

1624+
/* Test replacing hash partition */
1625+
CREATE TABLE test.hash_rel_extern (LIKE test.hash_rel INCLUDING ALL);
1626+
SELECT pathman.replace_hash_partition('test.hash_rel_0', 'test.hash_rel_extern');
1627+
replace_hash_partition
1628+
------------------------
1629+
test.hash_rel_extern
1630+
(1 row)
1631+
1632+
\d+ test.hash_rel_0
1633+
Table "test.hash_rel_0"
1634+
Column | Type | Modifiers | Storage | Stats target | Description
1635+
--------+---------+------------------------------------------------------------+---------+--------------+-------------
1636+
id | integer | not null default nextval('test.hash_rel_id_seq'::regclass) | plain | |
1637+
value | integer | not null | plain | |
1638+
abc | integer | | plain | |
1639+
Indexes:
1640+
"hash_rel_0_pkey" PRIMARY KEY, btree (id)
1641+
Triggers:
1642+
hash_rel_upd_trig BEFORE UPDATE ON test.hash_rel_0 FOR EACH ROW EXECUTE PROCEDURE test.hash_rel_upd_trig_func()
1643+
1644+
\d+ test.hash_rel_extern
1645+
Table "test.hash_rel_extern"
1646+
Column | Type | Modifiers | Storage | Stats target | Description
1647+
--------+---------+------------------------------------------------------------+---------+--------------+-------------
1648+
id | integer | not null default nextval('test.hash_rel_id_seq'::regclass) | plain | |
1649+
value | integer | not null | plain | |
1650+
abc | integer | | plain | |
1651+
Indexes:
1652+
"hash_rel_extern_pkey" PRIMARY KEY, btree (id)
1653+
Check constraints:
1654+
"pathman_hash_rel_extern_2_check" CHECK (pathman.get_hash_part_idx(hashint4(value), 3) = 0)
1655+
Inherits: test.hash_rel
1656+
1657+
INSERT INTO test.hash_rel SELECT * FROM test.hash_rel_0;
1658+
DROP TABLE test.hash_rel_0;
1659+
/* Table with which we are replacing partition must have exact same structure */
1660+
CREATE TABLE test.hash_rel_wrong(
1661+
id INTEGER NOT NULL,
1662+
value INTEGER);
1663+
SELECT pathman.replace_hash_partition('test.hash_rel_1', 'test.hash_rel_wrong');
1664+
ERROR: partition must have the exact same structure as parent
1665+
EXPLAIN (COSTS OFF) SELECT * FROM test.hash_rel;
1666+
QUERY PLAN
1667+
-----------------------------------
1668+
Append
1669+
-> Seq Scan on hash_rel_extern
1670+
-> Seq Scan on hash_rel_1
1671+
-> Seq Scan on hash_rel_2
1672+
(4 rows)
1673+
15661674
/*
15671675
* Clean up
15681676
*/
15691677
SELECT pathman.drop_partitions('test.hash_rel');
1570-
NOTICE: drop cascades to 3 other objects
1571-
NOTICE: 2 rows copied from test.hash_rel_0
1678+
NOTICE: drop cascades to 2 other objects
15721679
NOTICE: 3 rows copied from test.hash_rel_1
15731680
NOTICE: 2 rows copied from test.hash_rel_2
1681+
NOTICE: 2 rows copied from test.hash_rel_extern
15741682
drop_partitions
15751683
-----------------
15761684
3
@@ -2191,31 +2299,31 @@ NOTICE: sequence "index_on_childs_seq" does not exist, skipping
21912299
0
21922300
(1 row)
21932301

2194-
SELECT add_range_partition('test.index_on_childs', 1, 1000, 'test.index_on_childs_1_1K');
2302+
SELECT add_range_partition('test.index_on_childs', 1, 1000, 'test.index_on_childs_1_1k');
21952303
add_range_partition
21962304
---------------------------
21972305
test.index_on_childs_1_1k
21982306
(1 row)
21992307

2200-
SELECT append_range_partition('test.index_on_childs', 'test.index_on_childs_1K_2K');
2308+
SELECT append_range_partition('test.index_on_childs', 'test.index_on_childs_1k_2k');
22012309
append_range_partition
22022310
----------------------------
22032311
test.index_on_childs_1k_2k
22042312
(1 row)
22052313

2206-
SELECT append_range_partition('test.index_on_childs', 'test.index_on_childs_2K_3K');
2314+
SELECT append_range_partition('test.index_on_childs', 'test.index_on_childs_2k_3k');
22072315
append_range_partition
22082316
----------------------------
22092317
test.index_on_childs_2k_3k
22102318
(1 row)
22112319

2212-
SELECT append_range_partition('test.index_on_childs', 'test.index_on_childs_3K_4K');
2320+
SELECT append_range_partition('test.index_on_childs', 'test.index_on_childs_3k_4k');
22132321
append_range_partition
22142322
----------------------------
22152323
test.index_on_childs_3k_4k
22162324
(1 row)
22172325

2218-
SELECT append_range_partition('test.index_on_childs', 'test.index_on_childs_4K_5K');
2326+
SELECT append_range_partition('test.index_on_childs', 'test.index_on_childs_4k_5k');
22192327
append_range_partition
22202328
----------------------------
22212329
test.index_on_childs_4k_5k
@@ -2246,6 +2354,6 @@ EXPLAIN (COSTS OFF) SELECT * FROM test.index_on_childs WHERE c1 > 100 AND c1 < 2
22462354
(12 rows)
22472355

22482356
DROP SCHEMA test CASCADE;
2249-
NOTICE: drop cascades to 50 other objects
2357+
NOTICE: drop cascades to 51 other objects
22502358
DROP EXTENSION pg_pathman CASCADE;
22512359
DROP SCHEMA pathman CASCADE;

expected/pathman_calamity.out

Lines changed: 66 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,28 @@ set client_min_messages = NOTICE;
1414
CREATE TABLE calamity.part_test(val serial);
1515
/* check function validate_relname() */
1616
SELECT validate_relname('calamity.part_test');
17-
validate_relname
18-
--------------------
19-
calamity.part_test
17+
validate_relname
18+
------------------
19+
20+
(1 row)
21+
22+
SELECT validate_relname(1::REGCLASS);
23+
ERROR: relation "1" does not exist
24+
SELECT validate_relname(NULL);
25+
ERROR: relation should not be NULL
26+
/* check function get_number_of_partitions() */
27+
SELECT get_number_of_partitions('calamity.part_test');
28+
get_number_of_partitions
29+
--------------------------
30+
0
31+
(1 row)
32+
33+
SELECT get_number_of_partitions(NULL) IS NULL;
34+
?column?
35+
----------
36+
t
2037
(1 row)
2138

22-
/* SELECT validate_relname(NULL); -- FIXME: %s */
2339
/* check function get_parent_of_partition() */
2440
SELECT get_parent_of_partition('calamity.part_test');
2541
ERROR: "part_test" is not a partition
@@ -277,6 +293,51 @@ SHOW pg_pathman.enable;
277293
on
278294
(1 row)
279295

296+
/* check function create_hash_partitions_internal() (called for the 2nd time) */
297+
CREATE TABLE calamity.hash_two_times(val serial);
298+
SELECT create_hash_partitions_internal('calamity.hash_two_times', 'val', 2);
299+
ERROR: table "hash_two_times" is not partitioned
300+
SELECT create_hash_partitions('calamity.hash_two_times', 'val', 2);
301+
create_hash_partitions
302+
------------------------
303+
2
304+
(1 row)
305+
306+
SELECT create_hash_partitions_internal('calamity.hash_two_times', 'val', 2);
307+
ERROR: cannot add new HASH partitions
308+
/* check function disable_pathman_for() */
309+
CREATE TABLE calamity.to_be_disabled(val INT NOT NULL);
310+
SELECT create_hash_partitions('calamity.to_be_disabled', 'val', 3); /* add row to main config */
311+
create_hash_partitions
312+
------------------------
313+
3
314+
(1 row)
315+
316+
SELECT set_enable_parent('calamity.to_be_disabled', true); /* add row to params */
317+
set_enable_parent
318+
-------------------
319+
320+
(1 row)
321+
322+
SELECT disable_pathman_for('calamity.to_be_disabled'); /* should delete both rows */
323+
NOTICE: function calamity.to_be_disabled_upd_trig_func() does not exist, skipping
324+
disable_pathman_for
325+
---------------------
326+
327+
(1 row)
328+
329+
SELECT count(*) FROM pathman_config WHERE partrel = 'calamity.to_be_disabled'::REGCLASS;
330+
count
331+
-------
332+
0
333+
(1 row)
334+
335+
SELECT count(*) FROM pathman_config_params WHERE partrel = 'calamity.to_be_disabled'::REGCLASS;
336+
count
337+
-------
338+
0
339+
(1 row)
340+
280341
DROP SCHEMA calamity CASCADE;
281-
NOTICE: drop cascades to 8 other objects
342+
NOTICE: drop cascades to 15 other objects
282343
DROP EXTENSION pg_pathman;

0 commit comments

Comments
 (0)