1
- -- ########## NATIVE ID PARENT / TIME SUBPARENT TESTS ##########
1
+ -- ########## ID PARENT / TIME SUBPARENT TESTS ##########
2
2
-- Additional tests: no pg_jobmon
3
3
-- Test using a pre-created template table and passing to create_parent. Should allow indexes to be made for initial children.
4
- -- additional constraint column
4
+ -- additional constraint column (top lvl int)
5
5
6
6
\set ON_ERROR_ROLLBACK 1
7
7
\set ON_ERROR_STOP true
8
8
9
9
BEGIN ;
10
10
SELECT set_config(' search_path' ,' partman, public' ,false);
11
11
12
- SELECT plan(323 );
12
+ SELECT plan(321 );
13
13
CREATE SCHEMA partman_test ;
14
14
15
15
CREATE TABLE partman_test .fk_test_reference (col2 text unique not null );
@@ -31,7 +31,7 @@ ALTER TABLE partman_test.template_id_taptest_table ADD PRIMARY KEY (col1);
31
31
CREATE INDEX ON partman_test .id_taptest_table (col3);
32
32
ALTER TABLE partman_test .id_taptest_table ADD FOREIGN KEY (col2) REFERENCES partman_test .fk_test_reference (col2);
33
33
34
- SELECT create_parent(' partman_test.id_taptest_table' , ' col1' , ' 10' , p_constraint_cols => ' {"col3 "}' , p_jobmon => false, p_template_table => ' partman_test.template_id_taptest_table' );
34
+ SELECT create_parent(' partman_test.id_taptest_table' , ' col1' , ' 10' , p_constraint_cols => ' {"col2 "}' , p_jobmon => false, p_template_table => ' partman_test.template_id_taptest_table' );
35
35
INSERT INTO partman_test .id_taptest_table (col1) VALUES (generate_series(1 ,9 ));
36
36
37
37
SELECT is_partitioned(' partman_test' , ' id_taptest_table' , ' Check that id_taptest_table is natively partitioned' );
@@ -295,6 +295,7 @@ SELECT is_empty('SELECT * FROM partman_test.id_taptest_table_p40', 'Check count
295
295
INSERT INTO partman_test .id_taptest_table (col1, col3) VALUES (generate_series(10 ,20 ), CURRENT_TIMESTAMP + ' 1 day' ::interval);
296
296
297
297
SELECT run_maintenance();
298
+
298
299
SELECT is_empty(' SELECT * FROM ONLY partman_test.id_taptest_table_default' , ' Check that top parent default is empty' );
299
300
SELECT is_empty(' SELECT * FROM ONLY partman_test.id_taptest_table_p0_default' , ' Check that subparent default p0 is empty' );
300
301
SELECT results_eq(' SELECT count(*)::int FROM partman_test.id_taptest_table_p0' , ARRAY[9 ], ' Check count from parent table partman_test.id_taptest_table_p0' );
@@ -387,7 +388,6 @@ SELECT is_empty('SELECT * FROM partman_test.id_taptest_table_p60', 'Check count
387
388
388
389
SELECT hasnt_table(' partman_test' , ' id_taptest_table_p70' , ' Check id_taptest_table_p70 doesn' ' t exists yet' );
389
390
390
- -- Ensure time partitioning works for all sub partitions
391
391
UPDATE part_config SET premake = 5 WHERE parent_table ~ ' partman_test.id_taptest_table_p' ;
392
392
SELECT run_maintenance();
393
393
@@ -448,6 +448,14 @@ SELECT hasnt_table('partman_test', 'id_taptest_table_p50_p'||to_char(CURRENT_TIM
448
448
SELECT hasnt_table(' partman_test' , ' id_taptest_table_p60_p' || to_char(CURRENT_TIMESTAMP + ' 5 days' ::interval, ' YYYYMMDD' ),
449
449
' Check id_taptest_table_p60_p' || to_char(CURRENT_TIMESTAMP + ' 5 days' ::interval, ' YYYYMMDD' )|| ' does not exist' );
450
450
451
+ -- Ensure constraint exclusion for top level. Latest data is in _p5, so optimize_constraint of 4 would be before _p1
452
+ INSERT INTO partman_test .id_taptest_table (col1, col3) VALUES (generate_series(30 ,50 ), CURRENT_TIMESTAMP + ' 1 day' ::interval);
453
+ UPDATE partman .part_config SET optimize_constraint = 4 WHERE parent_table = ' partman_test.id_taptest_table' ;
454
+
455
+ SELECT run_maintenance();
456
+ SELECT col_has_check(' partman_test' , ' id_taptest_table_p0' , ' col2'
457
+ , ' Check for additional constraint on col2 on id_taptest_table_p0' );
458
+
451
459
-- Test dropping without retention set
452
460
SELECT drop_partition_time (' partman_test.id_taptest_table_p0' , ' 2 days' , p_keep_table := false);
453
461
SELECT has_table(' partman_test' , ' id_taptest_table_p0_p' || to_char(CURRENT_TIMESTAMP - ' 2 days' ::interval, ' YYYYMMDD' ),
@@ -462,7 +470,7 @@ SELECT hasnt_table('partman_test', 'id_taptest_table_p0_p'||to_char(CURRENT_TIME
462
470
' Check id_taptest_table_p0_p' || to_char(CURRENT_TIMESTAMP - ' 6 days' ::interval, ' YYYYMMDD' )|| ' does not exist' );
463
471
464
472
465
- UPDATE part_config SET retention = ' 10 ' , retention_keep_table = false WHERE parent_table = ' partman_test.id_taptest_table' ;
473
+ UPDATE part_config SET retention = ' 30 ' , retention_keep_table = false WHERE parent_table = ' partman_test.id_taptest_table' ;
466
474
UPDATE part_config SET retention = ' 2 days' , retention_keep_table = false WHERE parent_table = ' partman_test.id_taptest_table_p0' ;
467
475
UPDATE part_config SET retention = ' 2 days' , retention_keep_table = false WHERE parent_table = ' partman_test.id_taptest_table_p10' ;
468
476
UPDATE part_config SET retention = ' 2 days' , retention_keep_table = false WHERE parent_table = ' partman_test.id_taptest_table_p20' ;
@@ -475,31 +483,19 @@ UPDATE part_config SET retention = '2 days', retention_keep_table = false WHERE
475
483
476
484
SELECT run_maintenance();
477
485
486
+ SELECT hasnt_table(' partman_test' , ' id_taptest_table_p0' ,
487
+ ' Check id_taptest_table_p0 does not exist' );
478
488
SELECT hasnt_table(' partman_test' , ' id_taptest_table_p0_p' || to_char(CURRENT_TIMESTAMP , ' YYYYMMDD' ),
479
489
' Check id_taptest_table_p0_p' || to_char(CURRENT_TIMESTAMP , ' YYYYMMDD' )|| ' does not exist' );
480
490
SELECT hasnt_table(' partman_test' , ' id_taptest_table_p0_p' || to_char(CURRENT_TIMESTAMP + ' 1 day' ::interval, ' YYYYMMDD' ),
481
491
' Check id_taptest_table_p0_p' || to_char(CURRENT_TIMESTAMP + ' 1 day' ::interval, ' YYYYMMDD' )|| ' does not exist' );
482
- SELECT hasnt_table(' partman_test' , ' id_taptest_table_p0_p' || to_char(CURRENT_TIMESTAMP + ' 2 days' ::interval, ' YYYYMMDD' ),
483
- ' Check id_taptest_table_p0_p' || to_char(CURRENT_TIMESTAMP + ' 2 days' ::interval, ' YYYYMMDD' )|| ' does not exist' );
484
- SELECT hasnt_table(' partman_test' , ' id_taptest_table_p0_p' || to_char(CURRENT_TIMESTAMP + ' 3 days' ::interval, ' YYYYMMDD' ),
485
- ' Check id_taptest_table_p0_p' || to_char(CURRENT_TIMESTAMP + ' 3 days' ::interval, ' YYYYMMDD' )|| ' does not exist' );
486
- SELECT hasnt_table(' partman_test' , ' id_taptest_table_p0_p' || to_char(CURRENT_TIMESTAMP + ' 4 days' ::interval, ' YYYYMMDD' ),
487
- ' Check id_taptest_table_p0_p' || to_char(CURRENT_TIMESTAMP + ' 4 days' ::interval, ' YYYYMMDD' )|| ' does not exist' );
488
- SELECT hasnt_table(' partman_test' , ' id_taptest_table_p0_p' || to_char(CURRENT_TIMESTAMP + ' 5 days' ::interval, ' YYYYMMDD' ),
489
- ' Check id_taptest_table_p0_p' || to_char(CURRENT_TIMESTAMP + ' 5 days' ::interval, ' YYYYMMDD' )|| ' does not exist' );
490
- SELECT hasnt_table(' partman_test' , ' id_taptest_table_p0_p' || to_char(CURRENT_TIMESTAMP - ' 1 days' ::interval, ' YYYYMMDD' ),
491
- ' Check id_taptest_table_p0_p' || to_char(CURRENT_TIMESTAMP - ' 1 days' ::interval, ' YYYYMMDD' )|| ' does not exist' );
492
- SELECT hasnt_table(' partman_test' , ' id_taptest_table_p0_p' || to_char(CURRENT_TIMESTAMP - ' 2 days' ::interval, ' YYYYMMDD' ),
493
- ' Check id_taptest_table_p0_p' || to_char(CURRENT_TIMESTAMP - ' 2 days' ::interval, ' YYYYMMDD' )|| ' does not exist' );
494
492
493
+ SELECT hasnt_table(' partman_test' , ' id_taptest_table_p10' ,
494
+ ' Check id_taptest_table_p10 does not exist' );
495
+ SELECT hasnt_table(' partman_test' , ' id_taptest_table_p10_p' || to_char(CURRENT_TIMESTAMP , ' YYYYMMDD' ),
496
+ ' Check id_taptest_table_p10_p' || to_char(CURRENT_TIMESTAMP , ' YYYYMMDD' )|| ' does not exist' );
495
497
SELECT hasnt_table(' partman_test' , ' id_taptest_table_p10_p' || to_char(CURRENT_TIMESTAMP - ' 3 days' ::interval, ' YYYYMMDD' ),
496
498
' Check id_taptest_table_p10_p' || to_char(CURRENT_TIMESTAMP - ' 3 days' ::interval, ' YYYYMMDD' )|| ' does not exist' );
497
- SELECT hasnt_table(' partman_test' , ' id_taptest_table_p10_p' || to_char(CURRENT_TIMESTAMP - ' 4 days' ::interval, ' YYYYMMDD' ),
498
- ' Check id_taptest_table_p10_p' || to_char(CURRENT_TIMESTAMP - ' 4 days' ::interval, ' YYYYMMDD' )|| ' does not exist' );
499
- SELECT hasnt_table(' partman_test' , ' id_taptest_table_p10_p' || to_char(CURRENT_TIMESTAMP - ' 5 days' ::interval, ' YYYYMMDD' ),
500
- ' Check id_taptest_table_p10_p' || to_char(CURRENT_TIMESTAMP - ' 5 days' ::interval, ' YYYYMMDD' )|| ' does not exist' );
501
- SELECT hasnt_table(' partman_test' , ' id_taptest_table_p10_p' || to_char(CURRENT_TIMESTAMP - ' 6 days' ::interval, ' YYYYMMDD' ),
502
- ' Check id_taptest_table_p10_p' || to_char(CURRENT_TIMESTAMP - ' 6 days' ::interval, ' YYYYMMDD' )|| ' does not exist' );
503
499
504
500
SELECT hasnt_table(' partman_test' , ' id_taptest_table_p20_p' || to_char(CURRENT_TIMESTAMP - ' 3 days' ::interval, ' YYYYMMDD' ),
505
501
' Check id_taptest_table_p20_p' || to_char(CURRENT_TIMESTAMP - ' 3 days' ::interval, ' YYYYMMDD' )|| ' does not exist' );
@@ -546,7 +542,6 @@ SELECT hasnt_table('partman_test', 'id_taptest_table_p60_p'||to_char(CURRENT_TIM
546
542
SELECT hasnt_table(' partman_test' , ' id_taptest_table_p60_p' || to_char(CURRENT_TIMESTAMP - ' 6 days' ::interval, ' YYYYMMDD' ),
547
543
' Check id_taptest_table_p60_p' || to_char(CURRENT_TIMESTAMP - ' 6 days' ::interval, ' YYYYMMDD' )|| ' does not exist' );
548
544
549
- SELECT undo_partition(' partman_test.id_taptest_table_p10' , p_target_table := ' partman_test.undo_taptest' , p_loop_count => 20 , p_keep_table := false);
550
545
SELECT has_table(' partman_test' , ' template_id_taptest_table' , ' Check that template table was not removed yet' );
551
546
SELECT undo_partition(' partman_test.id_taptest_table_p20' , p_target_table := ' partman_test.undo_taptest' , p_loop_count => 20 , p_keep_table := false);
552
547
SELECT has_table(' partman_test' , ' template_id_taptest_table' , ' Check that template table was not removed yet' );
@@ -558,9 +553,15 @@ SELECT undo_partition('partman_test.id_taptest_table_p50', p_target_table := 'pa
558
553
SELECT has_table(' partman_test' , ' template_id_taptest_table' , ' Check that template table was not removed yet' );
559
554
SELECT undo_partition(' partman_test.id_taptest_table_p60' , p_target_table := ' partman_test.undo_taptest' , p_loop_count => 20 , p_keep_table := false);
560
555
SELECT has_table(' partman_test' , ' template_id_taptest_table' , ' Check that template table was not removed yet' );
556
+ SELECT undo_partition(' partman_test.id_taptest_table_p70' , p_target_table := ' partman_test.undo_taptest' , p_loop_count => 20 , p_keep_table := false);
557
+ SELECT has_table(' partman_test' , ' template_id_taptest_table' , ' Check that template table was not removed yet' );
558
+ SELECT undo_partition(' partman_test.id_taptest_table_p80' , p_target_table := ' partman_test.undo_taptest' , p_loop_count => 20 , p_keep_table := false);
559
+ SELECT has_table(' partman_test' , ' template_id_taptest_table' , ' Check that template table was not removed yet' );
560
+ SELECT undo_partition(' partman_test.id_taptest_table_p90' , p_target_table := ' partman_test.undo_taptest' , p_loop_count => 20 , p_keep_table := false);
561
+ SELECT has_table(' partman_test' , ' template_id_taptest_table' , ' Check that template table was not removed yet' );
561
562
562
563
563
- SELECT results_eq(' SELECT count(*)::int FROM partman_test.undo_taptest' , ARRAY[11 ], ' Check count from target of undo_partition' );
564
+ SELECT results_eq(' SELECT count(*)::int FROM partman_test.undo_taptest' , ARRAY[22 ], ' Check count from target of undo_partition' );
564
565
565
566
SELECT hasnt_table(' partman_test' , ' id_taptest_table_p10_p' || to_char(CURRENT_TIMESTAMP , ' YYYYMMDD' ),
566
567
' Check id_taptest_table_p10_p' || to_char(CURRENT_TIMESTAMP , ' YYYYMMDD' )|| ' does not exist' );
@@ -698,7 +699,7 @@ SELECT is_empty('SELECT parent_table from part_config where parent_table = ''par
698
699
699
700
SELECT hasnt_table(' partman_test' , ' template_id_taptest_table' , ' Check that template table was removed' );
700
701
701
- SELECT results_eq(' SELECT count(*)::int FROM ONLY partman_test.undo_taptest' , ARRAY[11 ], ' Check count from final unpartitioned target table' );
702
+ SELECT results_eq(' SELECT count(*)::int FROM ONLY partman_test.undo_taptest' , ARRAY[22 ], ' Check count from final unpartitioned target table' );
702
703
703
704
SELECT * FROM finish();
704
705
ROLLBACK ;
0 commit comments