Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 8962277

Browse files
committed
Add more subpartitions fixes and tests
1 parent 280c26a commit 8962277

6 files changed

+312
-33
lines changed

expected/pathman_basic.out

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ PL/pgSQL function pathman.prepare_for_partitioning(regclass,text,boolean) line 9
147147
SQL statement "SELECT pathman.prepare_for_partitioning(parent_relid,
148148
expression,
149149
partition_data)"
150-
PL/pgSQL function pathman.create_range_partitions(regclass,text,anyelement,interval,integer,boolean) line 12 at PERFORM
150+
PL/pgSQL function pathman.create_range_partitions(regclass,text,anyelement,interval,integer,boolean) line 13 at PERFORM
151151
\set VERBOSITY terse
152152
ALTER TABLE test.range_rel ALTER COLUMN dt SET NOT NULL;
153153
SELECT pathman.create_range_partitions('test.range_rel', 'dt', '2015-01-01'::DATE, '1 month'::INTERVAL, 2);

expected/pathman_expressions.out

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,7 @@ PL/pgSQL function prepare_for_partitioning(regclass,text,boolean) line 9 at PERF
371371
SQL statement "SELECT public.prepare_for_partitioning(parent_relid,
372372
expression,
373373
partition_data)"
374-
PL/pgSQL function create_range_partitions(regclass,text,anyelement,interval,integer,boolean) line 12 at PERFORM
374+
PL/pgSQL function create_range_partitions(regclass,text,anyelement,interval,integer,boolean) line 13 at PERFORM
375375
/* Try using mutable expression */
376376
SELECT create_range_partitions('test_exprs.range_rel', 'RANDOM()',
377377
'15 years'::INTERVAL, '1 year'::INTERVAL, 10);
@@ -382,7 +382,7 @@ PL/pgSQL function prepare_for_partitioning(regclass,text,boolean) line 9 at PERF
382382
SQL statement "SELECT public.prepare_for_partitioning(parent_relid,
383383
expression,
384384
partition_data)"
385-
PL/pgSQL function create_range_partitions(regclass,text,anyelement,interval,integer,boolean) line 12 at PERFORM
385+
PL/pgSQL function create_range_partitions(regclass,text,anyelement,interval,integer,boolean) line 13 at PERFORM
386386
/* Check that 'pathman_hooks_enabled' is true (1 partition in plan) */
387387
EXPLAIN (COSTS OFF) INSERT INTO test_exprs.canary_copy
388388
SELECT * FROM test_exprs.canary WHERE val = 1;

expected/pathman_subpartitions.out

Lines changed: 146 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -224,13 +224,13 @@ SELECT create_range_partitions('subpartitions.abc', 'a', 0, 100, 2);
224224
2
225225
(1 row)
226226

227-
SELECT create_range_partitions('subpartitions.abc_1', 'b', 0, 50, 2);
227+
SELECT create_range_partitions('subpartitions.abc_1', 'b', 0, 50, 2); /* 0 - 100 */
228228
create_range_partitions
229229
-------------------------
230230
2
231231
(1 row)
232232

233-
SELECT create_range_partitions('subpartitions.abc_2', 'b', 0, 50, 2);
233+
SELECT create_range_partitions('subpartitions.abc_2', 'b', 0, 50, 2); /* 100 - 200 */
234234
create_range_partitions
235235
-------------------------
236236
2
@@ -324,7 +324,7 @@ SELECT subpartitions.partitions_tree('subpartitions.abc');
324324
(9 rows)
325325

326326
/* merge_range_partitions */
327-
SELECT append_range_partition('subpartitions.abc', 'subpartitions.abc_3');
327+
SELECT append_range_partition('subpartitions.abc', 'subpartitions.abc_3'); /* 200 - 300 */
328328
append_range_partition
329329
------------------------
330330
subpartitions.abc_3
@@ -340,6 +340,149 @@ select merge_range_partitions('subpartitions.abc_2_1', 'subpartitions.abc_2_2');
340340

341341
DROP TABLE subpartitions.abc CASCADE;
342342
NOTICE: drop cascades to 11 other objects
343+
/* subpartitions on same expressions */
344+
CREATE TABLE subpartitions.abc(a INTEGER NOT NULL);
345+
INSERT INTO subpartitions.abc SELECT i FROM generate_series(1, 200, 20) as i;
346+
SELECT create_range_partitions('subpartitions.abc', 'a', 0, 100, 4);
347+
create_range_partitions
348+
-------------------------
349+
4
350+
(1 row)
351+
352+
SELECT create_range_partitions('subpartitions.abc_1', 'a', 0, 11, 9); /* not multiple */
353+
create_range_partitions
354+
-------------------------
355+
9
356+
(1 row)
357+
358+
SELECT create_range_partitions('subpartitions.abc_2', 'a', 150, 11, 8); /* start_value should be lower */
359+
WARNING: "start_value" was set to 100
360+
create_range_partitions
361+
-------------------------
362+
8
363+
(1 row)
364+
365+
SELECT create_range_partitions('subpartitions.abc_3', 'a', 200, 11, 20); /* too big p_count */
366+
WARNING: "p_interval" is not multiple of range (200, 310)
367+
NOTICE: "p_count" was limited to 10
368+
create_range_partitions
369+
-------------------------
370+
10
371+
(1 row)
372+
373+
SELECT create_range_partitions('subpartitions.abc_4', 'a', ARRAY[301, 350, 400]); /* bounds check */
374+
ERROR: Bounds should start from 300
375+
SELECT create_range_partitions('subpartitions.abc_4', 'a', ARRAY[300, 450, 500]); /* bounds check */
376+
ERROR: Lower bound of rightmost partition should be less than 400
377+
SELECT create_range_partitions('subpartitions.abc_4', 'a', ARRAY[300, 350, 450]); /* bounds check */
378+
create_range_partitions
379+
-------------------------
380+
2
381+
(1 row)
382+
383+
\d+ subpartitions.abc_1
384+
Table "subpartitions.abc_1"
385+
Column | Type | Collation | Nullable | Default | Storage | Stats target | Description
386+
--------+---------+-----------+----------+---------+---------+--------------+-------------
387+
a | integer | | not null | | plain | |
388+
Check constraints:
389+
"pathman_abc_1_check" CHECK (a >= 0 AND a < 100)
390+
Inherits: subpartitions.abc
391+
Child tables: subpartitions.abc_1_1,
392+
subpartitions.abc_1_2,
393+
subpartitions.abc_1_3,
394+
subpartitions.abc_1_4,
395+
subpartitions.abc_1_5,
396+
subpartitions.abc_1_6,
397+
subpartitions.abc_1_7,
398+
subpartitions.abc_1_8,
399+
subpartitions.abc_1_9
400+
401+
SELECT * FROM pathman_partition_list;
402+
parent | partition | parttype | expr | range_min | range_max
403+
---------------------+------------------------+----------+------+-----------+-----------
404+
subpartitions.abc | subpartitions.abc_1 | 2 | a | 0 | 100
405+
subpartitions.abc | subpartitions.abc_2 | 2 | a | 100 | 200
406+
subpartitions.abc | subpartitions.abc_3 | 2 | a | 200 | 300
407+
subpartitions.abc | subpartitions.abc_4 | 2 | a | 300 | 400
408+
subpartitions.abc_1 | subpartitions.abc_1_1 | 2 | a | 0 | 11
409+
subpartitions.abc_1 | subpartitions.abc_1_2 | 2 | a | 11 | 22
410+
subpartitions.abc_1 | subpartitions.abc_1_3 | 2 | a | 22 | 33
411+
subpartitions.abc_1 | subpartitions.abc_1_4 | 2 | a | 33 | 44
412+
subpartitions.abc_1 | subpartitions.abc_1_5 | 2 | a | 44 | 55
413+
subpartitions.abc_1 | subpartitions.abc_1_6 | 2 | a | 55 | 66
414+
subpartitions.abc_1 | subpartitions.abc_1_7 | 2 | a | 66 | 77
415+
subpartitions.abc_1 | subpartitions.abc_1_8 | 2 | a | 77 | 88
416+
subpartitions.abc_1 | subpartitions.abc_1_9 | 2 | a | 88 | 99
417+
subpartitions.abc_2 | subpartitions.abc_2_1 | 2 | a | 100 | 111
418+
subpartitions.abc_2 | subpartitions.abc_2_2 | 2 | a | 111 | 122
419+
subpartitions.abc_2 | subpartitions.abc_2_3 | 2 | a | 122 | 133
420+
subpartitions.abc_2 | subpartitions.abc_2_4 | 2 | a | 133 | 144
421+
subpartitions.abc_2 | subpartitions.abc_2_5 | 2 | a | 144 | 155
422+
subpartitions.abc_2 | subpartitions.abc_2_6 | 2 | a | 155 | 166
423+
subpartitions.abc_2 | subpartitions.abc_2_7 | 2 | a | 166 | 177
424+
subpartitions.abc_2 | subpartitions.abc_2_8 | 2 | a | 177 | 188
425+
subpartitions.abc_3 | subpartitions.abc_3_1 | 2 | a | 200 | 211
426+
subpartitions.abc_3 | subpartitions.abc_3_2 | 2 | a | 211 | 222
427+
subpartitions.abc_3 | subpartitions.abc_3_3 | 2 | a | 222 | 233
428+
subpartitions.abc_3 | subpartitions.abc_3_4 | 2 | a | 233 | 244
429+
subpartitions.abc_3 | subpartitions.abc_3_5 | 2 | a | 244 | 255
430+
subpartitions.abc_3 | subpartitions.abc_3_6 | 2 | a | 255 | 266
431+
subpartitions.abc_3 | subpartitions.abc_3_7 | 2 | a | 266 | 277
432+
subpartitions.abc_3 | subpartitions.abc_3_8 | 2 | a | 277 | 288
433+
subpartitions.abc_3 | subpartitions.abc_3_9 | 2 | a | 288 | 299
434+
subpartitions.abc_3 | subpartitions.abc_3_10 | 2 | a | 299 | 310
435+
subpartitions.abc_4 | subpartitions.abc_4_1 | 2 | a | 300 | 350
436+
subpartitions.abc_4 | subpartitions.abc_4_2 | 2 | a | 350 | 450
437+
(33 rows)
438+
439+
SELECT append_range_partition('subpartitions.abc_1'::regclass);
440+
append_range_partition
441+
------------------------
442+
subpartitions.abc_1_10
443+
(1 row)
444+
445+
SELECT append_range_partition('subpartitions.abc_1'::regclass);
446+
ERROR: reached upper bound in the current level of subpartitions
447+
DROP TABLE subpartitions.abc_1_10;
448+
/* detach_range_partition */
449+
SELECt detach_range_partition('subpartitions.abc_1');
450+
ERROR: could not detach partition if it has children
451+
/* attach_range_partition */
452+
CREATE TABLE subpartitions.abc_c(LIKE subpartitions.abc_1 INCLUDING ALL);
453+
SELECT attach_range_partition('subpartitions.abc_1', 'subpartitions.abc_c', 98, 110); /* fail */
454+
ERROR: specified range [98, 110) overlaps with existing partitions
455+
SELECT attach_range_partition('subpartitions.abc_1', 'subpartitions.abc_c', 100, 110); /* fail */
456+
ERROR: "start value" exceeds upper bound of the current level of subpartitions
457+
SELECT attach_range_partition('subpartitions.abc_1', 'subpartitions.abc_c', 99, 110); /* ok */
458+
attach_range_partition
459+
------------------------
460+
subpartitions.abc_c
461+
(1 row)
462+
463+
DROP TABLE subpartitions.abc CASCADE;
464+
NOTICE: drop cascades to 39 other objects
465+
/* subpartitions on same expression but dates */
466+
CREATE TABLE subpartitions.abc(a DATE NOT NULL);
467+
INSERT INTO subpartitions.abc SELECT current_date + i FROM generate_series(1, 200, 20) as i;
468+
SELECT create_range_partitions('subpartitions.abc', 'a', current_date, '1 month'::INTERVAL);
469+
create_range_partitions
470+
-------------------------
471+
6
472+
(1 row)
473+
474+
SELECT create_range_partitions('subpartitions.abc_1', 'a', current_date + 1,
475+
'32 day'::INTERVAL, 10); /* not multiple, and limited p_count */
476+
WARNING: "start_value" was set to 10-02-2017
477+
WARNING: "p_interval" is not multiple of range (10-02-2017, 11-03-2017)
478+
NOTICE: "p_count" was limited to 1
479+
create_range_partitions
480+
-------------------------
481+
1
482+
(1 row)
483+
484+
DROP TABLE subpartitions.abc CASCADE;
485+
NOTICE: drop cascades to 9 other objects
343486
DROP SCHEMA subpartitions CASCADE;
344487
NOTICE: drop cascades to function subpartitions.partitions_tree(regclass,text)
345488
DROP EXTENSION pg_pathman;

0 commit comments

Comments
 (0)