Skip to content

Commit 8834b71

Browse files
committed
Merge branch 'rel_future_beta' into rel_future_expressions
2 parents e299b75 + 3a60edb commit 8834b71

10 files changed

+97
-140
lines changed

expected/pathman_basic.out

+14
Original file line numberDiff line numberDiff line change
@@ -450,6 +450,13 @@ EXPLAIN (COSTS OFF) SELECT * FROM test.hash_rel;
450450
-> Seq Scan on hash_rel_2
451451
(4 rows)
452452

453+
EXPLAIN (COSTS OFF) SELECT * FROM test.hash_rel WHERE value = NULL;
454+
QUERY PLAN
455+
--------------------------
456+
Result
457+
One-Time Filter: false
458+
(2 rows)
459+
453460
EXPLAIN (COSTS OFF) SELECT * FROM test.hash_rel WHERE value = 2;
454461
QUERY PLAN
455462
------------------------------
@@ -602,6 +609,13 @@ EXPLAIN (COSTS OFF) SELECT * FROM test.hash_rel;
602609
-> Seq Scan on hash_rel_2
603610
(4 rows)
604611

612+
EXPLAIN (COSTS OFF) SELECT * FROM test.hash_rel WHERE value = NULL;
613+
QUERY PLAN
614+
--------------------------
615+
Result
616+
One-Time Filter: false
617+
(2 rows)
618+
605619
EXPLAIN (COSTS OFF) SELECT * FROM test.hash_rel WHERE value = 2;
606620
QUERY PLAN
607621
------------------------------

expected/pathman_utility_stmt.out

+26-1
Original file line numberDiff line numberDiff line change
@@ -256,8 +256,33 @@ SELECT * FROM copy_stmt_hooking.test ORDER BY val;
256256
6 | hash_2 | 0 | 0
257257
(2 rows)
258258

259+
/* Check dropped colums before partitioning */
260+
CREATE TABLE copy_stmt_hooking.test2 (
261+
a varchar(50),
262+
b varchar(50),
263+
t timestamp without time zone not null
264+
);
265+
ALTER TABLE copy_stmt_hooking.test2 DROP COLUMN a;
266+
SELECT create_range_partitions('copy_stmt_hooking.test2',
267+
't',
268+
'2017-01-01 00:00:00'::timestamp,
269+
interval '1 hour', 5, false
270+
);
271+
NOTICE: sequence "test2_seq" does not exist, skipping
272+
create_range_partitions
273+
-------------------------
274+
5
275+
(1 row)
276+
277+
COPY copy_stmt_hooking.test2(t) FROM stdin;
278+
SELECT COUNT(*) FROM copy_stmt_hooking.test2;
279+
count
280+
-------
281+
1
282+
(1 row)
283+
259284
DROP SCHEMA copy_stmt_hooking CASCADE;
260-
NOTICE: drop cascades to 7 other objects
285+
NOTICE: drop cascades to 798 other objects
261286
/*
262287
* Test auto check constraint renaming
263288
*/

hash.sql

-6
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,6 @@ BEGIN
4444
partition_names,
4545
tablespaces);
4646

47-
/* Notify backend about changes */
48-
PERFORM @extschema@.on_create_partitions(parent_relid);
49-
5047
/* Copy data */
5148
IF partition_data = true THEN
5249
PERFORM @extschema@.set_enable_parent(parent_relid, false);
@@ -153,9 +150,6 @@ BEGIN
153150
new_partition,
154151
p_init_callback);
155152

156-
/* Invalidate cache */
157-
PERFORM @extschema@.on_update_partitions(parent_relid);
158-
159153
RETURN new_partition;
160154
END
161155
$$

init.sql

+13-33
Original file line numberDiff line numberDiff line change
@@ -433,9 +433,6 @@ BEGIN
433433

434434
/* Drop triggers on update */
435435
PERFORM @extschema@.drop_triggers(parent_relid);
436-
437-
/* Notify backend about changes */
438-
PERFORM @extschema@.on_remove_partitions(parent_relid);
439436
END
440437
$$
441438
LANGUAGE plpgsql STRICT;
@@ -581,23 +578,22 @@ DECLARE
581578
v_rec RECORD;
582579
v_rows BIGINT;
583580
v_part_count INTEGER := 0;
584-
conf_num_del INTEGER;
581+
conf_num INTEGER;
585582
v_relkind CHAR;
586583

587584
BEGIN
588585
PERFORM @extschema@.validate_relname(parent_relid);
589586

590-
/* Drop trigger first */
587+
/* Acquire data modification lock */
588+
PERFORM @extschema@.prevent_relation_modification(parent_relid);
589+
590+
/* First, drop all triggers */
591591
PERFORM @extschema@.drop_triggers(parent_relid);
592592

593-
WITH config_num_deleted AS (DELETE FROM @extschema@.pathman_config
594-
WHERE partrel = parent_relid
595-
RETURNING *)
596-
SELECT count(*) from config_num_deleted INTO conf_num_del;
593+
SELECT count(*) FROM @extschema@.pathman_config
594+
WHERE partrel = parent_relid INTO conf_num;
597595

598-
DELETE FROM @extschema@.pathman_config_params WHERE partrel = parent_relid;
599-
600-
IF conf_num_del = 0 THEN
596+
IF conf_num = 0 THEN
601597
RAISE EXCEPTION 'relation "%" has no partitions', parent_relid::TEXT;
602598
END IF;
603599

@@ -621,8 +617,8 @@ BEGIN
621617
INTO v_relkind;
622618

623619
/*
624-
* Determine the kind of child relation. It can be either regular
625-
* table (r) or foreign table (f). Depending on relkind we use
620+
* Determine the kind of child relation. It can be either a regular
621+
* table (r) or a foreign table (f). Depending on relkind we use
626622
* DROP TABLE or DROP FOREIGN TABLE.
627623
*/
628624
IF v_relkind = 'f' THEN
@@ -634,8 +630,9 @@ BEGIN
634630
v_part_count := v_part_count + 1;
635631
END LOOP;
636632

637-
/* Notify backend about changes */
638-
PERFORM @extschema@.on_remove_partitions(parent_relid);
633+
/* Finally delete both config entries */
634+
DELETE FROM @extschema@.pathman_config WHERE partrel = parent_relid;
635+
DELETE FROM @extschema@.pathman_config_params WHERE partrel = parent_relid;
639636

640637
RETURN v_part_count;
641638
END
@@ -759,23 +756,6 @@ ON sql_drop
759756
EXECUTE PROCEDURE @extschema@.pathman_ddl_trigger_func();
760757

761758

762-
763-
CREATE OR REPLACE FUNCTION @extschema@.on_create_partitions(
764-
relid REGCLASS)
765-
RETURNS VOID AS 'pg_pathman', 'on_partitions_created'
766-
LANGUAGE C STRICT;
767-
768-
CREATE OR REPLACE FUNCTION @extschema@.on_update_partitions(
769-
relid REGCLASS)
770-
RETURNS VOID AS 'pg_pathman', 'on_partitions_updated'
771-
LANGUAGE C STRICT;
772-
773-
CREATE OR REPLACE FUNCTION @extschema@.on_remove_partitions(
774-
relid REGCLASS)
775-
RETURNS VOID AS 'pg_pathman', 'on_partitions_removed'
776-
LANGUAGE C STRICT;
777-
778-
779759
/*
780760
* Get number of partitions managed by pg_pathman.
781761
*/

range.sql

-32
Original file line numberDiff line numberDiff line change
@@ -170,9 +170,6 @@ BEGIN
170170
NULL);
171171
END IF;
172172

173-
/* Notify backend about changes */
174-
PERFORM @extschema@.on_create_partitions(parent_relid);
175-
176173
/* Relocate data if asked to */
177174
IF partition_data = true THEN
178175
PERFORM @extschema@.set_enable_parent(parent_relid, false);
@@ -268,9 +265,6 @@ BEGIN
268265
NULL);
269266
END IF;
270267

271-
/* Notify backend about changes */
272-
PERFORM @extschema@.on_create_partitions(parent_relid);
273-
274268
/* Relocate data if asked to */
275269
IF partition_data = true THEN
276270
PERFORM @extschema@.set_enable_parent(parent_relid, false);
@@ -327,9 +321,6 @@ BEGIN
327321
partition_names,
328322
tablespaces);
329323

330-
/* Notify backend about changes */
331-
PERFORM @extschema@.on_create_partitions(parent_relid);
332-
333324
/* Relocate data if asked to */
334325
IF partition_data = true THEN
335326
PERFORM @extschema@.set_enable_parent(parent_relid, false);
@@ -387,9 +378,6 @@ BEGIN
387378
part_count := part_count + 1;
388379
END LOOP;
389380

390-
/* Notify backend about changes */
391-
PERFORM @extschema@.on_create_partitions(parent_relid);
392-
393381
/* Relocate data if asked to */
394382
IF partition_data = true THEN
395383
PERFORM @extschema@.set_enable_parent(parent_relid, false);
@@ -450,9 +438,6 @@ BEGIN
450438
part_count := part_count + 1;
451439
END LOOP;
452440

453-
/* Notify backend about changes */
454-
PERFORM @extschema@.on_create_partitions(parent_relid);
455-
456441
/* Relocate data if asked to */
457442
IF partition_data = true THEN
458443
PERFORM @extschema@.set_enable_parent(parent_relid, false);
@@ -553,9 +538,6 @@ BEGIN
553538
partition_relid::TEXT,
554539
v_check_name,
555540
v_cond);
556-
557-
/* Tell backend to reload configuration */
558-
PERFORM @extschema@.on_update_partitions(v_parent);
559541
END
560542
$$
561543
LANGUAGE plpgsql;
@@ -617,8 +599,6 @@ BEGIN
617599
INTO
618600
v_part_name;
619601

620-
/* Invalidate cache */
621-
PERFORM @extschema@.on_update_partitions(parent_relid);
622602
RETURN v_part_name;
623603
END
624604
$$
@@ -727,8 +707,6 @@ BEGIN
727707
INTO
728708
v_part_name;
729709

730-
/* Invalidate cache */
731-
PERFORM @extschema@.on_update_partitions(parent_relid);
732710
RETURN v_part_name;
733711
END
734712
$$
@@ -830,7 +808,6 @@ BEGIN
830808
end_value,
831809
partition_name,
832810
tablespace);
833-
PERFORM @extschema@.on_update_partitions(parent_relid);
834811

835812
RETURN v_part_name;
836813
END
@@ -895,9 +872,6 @@ BEGIN
895872
EXECUTE format('DROP TABLE %s', partition_relid::TEXT);
896873
END IF;
897874

898-
/* Invalidate cache */
899-
PERFORM @extschema@.on_update_partitions(parent_relid);
900-
901875
RETURN part_name;
902876
END
903877
$$
@@ -980,9 +954,6 @@ BEGIN
980954
start_value,
981955
end_value);
982956

983-
/* Invalidate cache */
984-
PERFORM @extschema@.on_update_partitions(parent_relid);
985-
986957
RETURN partition_relid;
987958
END
988959
$$
@@ -1028,9 +999,6 @@ BEGIN
1028999
@extschema@.build_update_trigger_name(parent_relid),
10291000
partition_relid::TEXT);
10301001

1031-
/* Invalidate cache */
1032-
PERFORM @extschema@.on_update_partitions(parent_relid);
1033-
10341002
RETURN partition_relid;
10351003
END
10361004
$$

sql/pathman_basic.sql

+2
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ SET enable_bitmapscan = OFF;
165165
SET enable_seqscan = ON;
166166

167167
EXPLAIN (COSTS OFF) SELECT * FROM test.hash_rel;
168+
EXPLAIN (COSTS OFF) SELECT * FROM test.hash_rel WHERE value = NULL;
168169
EXPLAIN (COSTS OFF) SELECT * FROM test.hash_rel WHERE value = 2;
169170
EXPLAIN (COSTS OFF) SELECT * FROM test.hash_rel WHERE value = 2 OR value = 1;
170171

@@ -188,6 +189,7 @@ SET enable_bitmapscan = OFF;
188189
SET enable_seqscan = OFF;
189190

190191
EXPLAIN (COSTS OFF) SELECT * FROM test.hash_rel;
192+
EXPLAIN (COSTS OFF) SELECT * FROM test.hash_rel WHERE value = NULL;
191193
EXPLAIN (COSTS OFF) SELECT * FROM test.hash_rel WHERE value = 2;
192194
EXPLAIN (COSTS OFF) SELECT * FROM test.hash_rel WHERE value = 2 OR value = 1;
193195
EXPLAIN (COSTS OFF) SELECT * FROM test.hash_rel WHERE value IN (2);

sql/pathman_utility_stmt.sql

+17
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,23 @@ COPY copy_stmt_hooking.test FROM stdin;
139139
SELECT count(*) FROM ONLY copy_stmt_hooking.test;
140140
SELECT * FROM copy_stmt_hooking.test ORDER BY val;
141141

142+
/* Check dropped colums before partitioning */
143+
CREATE TABLE copy_stmt_hooking.test2 (
144+
a varchar(50),
145+
b varchar(50),
146+
t timestamp without time zone not null
147+
);
148+
ALTER TABLE copy_stmt_hooking.test2 DROP COLUMN a;
149+
SELECT create_range_partitions('copy_stmt_hooking.test2',
150+
't',
151+
'2017-01-01 00:00:00'::timestamp,
152+
interval '1 hour', 5, false
153+
);
154+
COPY copy_stmt_hooking.test2(t) FROM stdin;
155+
2017-02-02 20:00:00
156+
\.
157+
SELECT COUNT(*) FROM copy_stmt_hooking.test2;
158+
142159
DROP SCHEMA copy_stmt_hooking CASCADE;
143160

144161

0 commit comments

Comments
 (0)