|
| 1 | +-- ########## ID 10 TESTS ########## |
| 2 | +-- Additional tests: |
| 3 | + -- Partition col is primary key with generated identity |
| 4 | + -- Populate initial data from source table |
| 5 | + -- Since this is id partitioning, we can use the partition key for primary key, so that should work from parent |
| 6 | + |
| 7 | +\set ON_ERROR_ROLLBACK 1 |
| 8 | +\set ON_ERROR_STOP true |
| 9 | + |
| 10 | +BEGIN; |
| 11 | +SELECT set_config('search_path','partman, public',false); |
| 12 | + |
| 13 | +SELECT plan(51); |
| 14 | +CREATE SCHEMA partman_test; |
| 15 | +CREATE SCHEMA partman_source; |
| 16 | + |
| 17 | +CREATE TABLE partman_test.id_taptest_table |
| 18 | + (col1 bigint PRIMARY KEY NOT NULL GENERATED ALWAYS AS IDENTITY |
| 19 | + , col2 text not null default 'stuff' |
| 20 | + , col3 timestamptz DEFAULT now() |
| 21 | + , col4 text) |
| 22 | + PARTITION BY RANGE (col1); |
| 23 | +CREATE TABLE partman_test.undo_taptest (LIKE partman_test.id_taptest_table INCLUDING ALL); |
| 24 | + |
| 25 | +CREATE TABLE partman_source.id_taptest_table_source (LIKE partman_test.id_taptest_table INCLUDING ALL); |
| 26 | + |
| 27 | +INSERT INTO partman_source.id_taptest_table_source (col4) VALUES ('stuff'||generate_series(3000000001,3000000009)); |
| 28 | + |
| 29 | +SELECT results_eq('SELECT count(*)::int FROM partman_source.id_taptest_table_source', ARRAY[9], 'Ensure source has expected row count'); |
| 30 | + |
| 31 | +SELECT create_parent('partman_test.id_taptest_table', 'col1', '10'); |
| 32 | + |
| 33 | +SELECT has_table('partman_test', 'id_taptest_table_p0', 'Check id_taptest_table_p0 exists'); |
| 34 | +SELECT has_table('partman_test', 'id_taptest_table_p10', 'Check id_taptest_table_p10 exists'); |
| 35 | +SELECT has_table('partman_test', 'id_taptest_table_p20', 'Check id_taptest_table_p20 exists'); |
| 36 | +SELECT has_table('partman_test', 'id_taptest_table_p30', 'Check id_taptest_table_p30 exists'); |
| 37 | +SELECT has_table('partman_test', 'id_taptest_table_p40', 'Check id_taptest_table_p40 exists'); |
| 38 | +SELECT has_table('partman_test', 'id_taptest_table_default', 'Check id_taptest_table_default exists'); |
| 39 | +SELECT hasnt_table('partman_test', 'id_taptest_table_p50', 'Check id_taptest_table_p50 doesn''t exists yet'); |
| 40 | +SELECT col_is_pk('partman_test', 'id_taptest_table_p0', ARRAY['col1'], 'Check for primary key in id_taptest_table_p0'); |
| 41 | +SELECT col_is_pk('partman_test', 'id_taptest_table_p10', ARRAY['col1'], 'Check for primary key in id_taptest_table_p10'); |
| 42 | +SELECT col_is_pk('partman_test', 'id_taptest_table_p20', ARRAY['col1'], 'Check for primary key in id_taptest_table_p20'); |
| 43 | +SELECT col_is_pk('partman_test', 'id_taptest_table_p30', ARRAY['col1'], 'Check for primary key in id_taptest_table_p30'); |
| 44 | +SELECT col_is_pk('partman_test', 'id_taptest_table_p40', ARRAY['col1'], 'Check for primary key in id_taptest_table_p40'); |
| 45 | +SELECT col_is_pk('partman_test', 'id_taptest_table_default', ARRAY['col1'], 'Check for primary key in id_taptest_table_default'); |
| 46 | + |
| 47 | +SELECT results_eq('SELECT partman.partition_data_id(''partman_test.id_taptest_table'', ''20'', p_source_table := ''partman_source.id_taptest_table_source'', p_ignored_columns := ARRAY[''col1''])::int', ARRAY[9], 'Move data out of source table into partitioned table'); |
| 48 | + |
| 49 | +SELECT is_empty('SELECT * FROM ONLY partman_test.id_taptest_table_default', 'Check that default table has no data'); |
| 50 | +SELECT results_eq('SELECT count(*)::int FROM partman_test.id_taptest_table', ARRAY[9], 'Check count from parent table'); |
| 51 | +SELECT results_eq('SELECT count(*)::int FROM partman_test.id_taptest_table_p0', ARRAY[9], 'Check count from id_taptest_table_p0'); |
| 52 | + |
| 53 | +INSERT INTO partman_test.id_taptest_table (col4) VALUES ('stuff'||generate_series(3000000010,3000000025)); |
| 54 | +-- Run again to make new partition based on latest data |
| 55 | +SELECT run_maintenance(); |
| 56 | + |
| 57 | +SELECT is_empty('SELECT * FROM ONLY partman_test.id_taptest_table', 'Check that parent table has had no data inserted to it'); |
| 58 | +SELECT results_eq('SELECT count(*)::int FROM partman_test.id_taptest_table_p10', ARRAY[10], 'Check count from id_taptest_table_p10'); |
| 59 | +SELECT results_eq('SELECT count(*)::int FROM partman_test.id_taptest_table_p20', ARRAY[6], 'Check count from id_taptest_table_p20'); |
| 60 | + |
| 61 | +SELECT has_table('partman_test', 'id_taptest_table_p50', 'Check id_taptest_table_p50 exists'); |
| 62 | +SELECT has_table('partman_test', 'id_taptest_table_p60', 'Check id_taptest_table_p60 exists yet'); |
| 63 | +SELECT hasnt_table('partman_test', 'id_taptest_table_p70', 'Check id_taptest_table_p70 doesn''t exists yet'); |
| 64 | +SELECT col_is_pk('partman_test', 'id_taptest_table_p50', ARRAY['col1'], 'Check for primary key in id_taptest_table_p50'); |
| 65 | + |
| 66 | +INSERT INTO partman_test.id_taptest_table (col4) VALUES ('stuff'||generate_series(3000000026,3000000038)); |
| 67 | + |
| 68 | +SELECT run_maintenance(); |
| 69 | + |
| 70 | +SELECT is_empty('SELECT * FROM ONLY partman_test.id_taptest_table', 'Check that parent table has had no data inserted to it'); |
| 71 | +SELECT results_eq('SELECT count(*)::int FROM partman_test.id_taptest_table', ARRAY[38], 'Check count from id_taptest_table'); |
| 72 | +SELECT results_eq('SELECT count(*)::int FROM partman_test.id_taptest_table_p20', ARRAY[10], 'Check count from id_taptest_table_p20'); |
| 73 | +SELECT results_eq('SELECT count(*)::int FROM partman_test.id_taptest_table_p30', ARRAY[9], 'Check count from id_taptest_table_p30'); |
| 74 | + |
| 75 | +SELECT has_table('partman_test', 'id_taptest_table_p70', 'Check id_taptest_table_p70 exists'); |
| 76 | +SELECT hasnt_table('partman_test', 'id_taptest_table_p80', 'Check id_taptest_table_p80 doesn''t exists yet'); |
| 77 | +SELECT col_is_pk('partman_test', 'id_taptest_table_p60', ARRAY['col1'], 'Check for primary key in id_taptest_table_p60'); |
| 78 | +SELECT col_is_pk('partman_test', 'id_taptest_table_p70', ARRAY['col1'], 'Check for primary key in id_taptest_table_p70'); |
| 79 | + |
| 80 | +-- Max value is 38 above |
| 81 | +SELECT drop_partition_id('partman_test.id_taptest_table', '20', p_keep_table := false); |
| 82 | +SELECT hasnt_table('partman_test', 'id_taptest_table_p0', 'Check id_taptest_table_p0 doesn''t exists anymore'); |
| 83 | +SELECT has_table('partman_test', 'id_taptest_table_p10', 'Check id_taptest_table_p10 exists'); |
| 84 | + |
| 85 | +UPDATE part_config SET retention = '10' WHERE parent_table = 'partman_test.id_taptest_table'; |
| 86 | +SELECT drop_partition_id('partman_test.id_taptest_table', p_keep_table := false); |
| 87 | +SELECT hasnt_table('partman_test', 'id_taptest_table_p10', 'Check id_taptest_table_p10 doesn''t exists anymore'); |
| 88 | +SELECT has_table('partman_test', 'id_taptest_table_p20', 'Check id_taptest_table_p20 exists'); |
| 89 | + |
| 90 | +SELECT undo_partition('partman_test.id_taptest_table', 'partman_test.undo_taptest', p_keep_table := false, p_ignored_columns := ARRAY['col1']); |
| 91 | +SELECT hasnt_table('partman_test', 'id_taptest_table_p20', 'Check id_taptest_table_p20 does not exist'); |
| 92 | +SELECT has_table('partman_test', 'id_taptest_table_p30', 'Check id_taptest_table_p30 exists'); |
| 93 | + |
| 94 | +-- Test keeping the rest of the tables |
| 95 | +SELECT undo_partition('partman_test.id_taptest_table', 'partman_test.undo_taptest', 10, p_ignored_columns := ARRAY['col1']); |
| 96 | +SELECT results_eq('SELECT count(*)::int FROM ONLY partman_test.undo_taptest', ARRAY[19], 'Check count from undo table after undo'); |
| 97 | +SELECT has_table('partman_test', 'id_taptest_table_p30', 'Check id_taptest_table_p30 still exists'); |
| 98 | +SELECT is_empty('SELECT * FROM partman_test.id_taptest_table_p30', 'Check child table had its data removed id_taptest_table_p30'); |
| 99 | +SELECT has_table('partman_test', 'id_taptest_table_p40', 'Check id_taptest_table_p40 still exists'); |
| 100 | +SELECT is_empty('SELECT * FROM partman_test.id_taptest_table_p40', 'Check child table had its data removed id_taptest_table_p40'); |
| 101 | +SELECT has_table('partman_test', 'id_taptest_table_p50', 'Check id_taptest_table_p50 still exists'); |
| 102 | +SELECT is_empty('SELECT * FROM partman_test.id_taptest_table_p50', 'Check child table had its data removed id_taptest_table_p50'); |
| 103 | +SELECT has_table('partman_test', 'id_taptest_table_p60', 'Check id_taptest_table_p60 still exists'); |
| 104 | +SELECT is_empty('SELECT * FROM partman_test.id_taptest_table_p60', 'Check child table had its data removed id_taptest_table_p60'); |
| 105 | +SELECT has_table('partman_test', 'id_taptest_table_p70', 'Check id_taptest_table_p70 still exists'); |
| 106 | +SELECT is_empty('SELECT * FROM partman_test.id_taptest_table_p70', 'Check child table had its data removed id_taptest_table_p70'); |
| 107 | + |
| 108 | +SELECT hasnt_table('partman_test', 'template_id_taptest_table', 'Check that template table was dropped'); |
| 109 | + |
| 110 | +SELECT * FROM finish(); |
| 111 | +ROLLBACK; |
0 commit comments