|
| 1 | +\set VERBOSITY terse |
| 2 | +SET search_path = 'public'; |
| 3 | +CREATE EXTENSION pg_pathman; |
| 4 | +CREATE SCHEMA test_column_type; |
| 5 | +/* |
| 6 | + * RANGE partitioning. |
| 7 | + */ |
| 8 | +/* create new table (val int) */ |
| 9 | +CREATE TABLE test_column_type.test(val INT4 NOT NULL); |
| 10 | +SELECT create_range_partitions('test_column_type.test', 'val', 1, 10, 10); |
| 11 | +NOTICE: sequence "test_seq" does not exist, skipping |
| 12 | + create_range_partitions |
| 13 | +------------------------- |
| 14 | + 10 |
| 15 | +(1 row) |
| 16 | + |
| 17 | +/* make sure that bounds and dispatch info has been cached */ |
| 18 | +SELECT * FROM test_column_type.test; |
| 19 | + val |
| 20 | +----- |
| 21 | +(0 rows) |
| 22 | + |
| 23 | +SELECT context, entries FROM pathman_cache_stats ORDER BY context; |
| 24 | + context | entries |
| 25 | +--------------------------+--------- |
| 26 | + maintenance | 0 |
| 27 | + partition bounds cache | 10 |
| 28 | + partition dispatch cache | 1 |
| 29 | + partition parents cache | 10 |
| 30 | +(4 rows) |
| 31 | + |
| 32 | +/* change column's type (should flush caches) */ |
| 33 | +ALTER TABLE test_column_type.test ALTER val TYPE NUMERIC; |
| 34 | +/* make sure that everything works properly */ |
| 35 | +SELECT * FROM test_column_type.test; |
| 36 | + val |
| 37 | +----- |
| 38 | +(0 rows) |
| 39 | + |
| 40 | +SELECT context, entries FROM pathman_cache_stats ORDER BY context; |
| 41 | + context | entries |
| 42 | +--------------------------+--------- |
| 43 | + maintenance | 0 |
| 44 | + partition bounds cache | 10 |
| 45 | + partition dispatch cache | 1 |
| 46 | + partition parents cache | 10 |
| 47 | +(4 rows) |
| 48 | + |
| 49 | +/* check insert dispatching */ |
| 50 | +INSERT INTO test_column_type.test VALUES (1); |
| 51 | +SELECT tableoid::regclass, * FROM test_column_type.test; |
| 52 | + tableoid | val |
| 53 | +-------------------------+----- |
| 54 | + test_column_type.test_1 | 1 |
| 55 | +(1 row) |
| 56 | + |
| 57 | +SELECT drop_partitions('test_column_type.test'); |
| 58 | +NOTICE: function test_column_type.test_upd_trig_func() does not exist, skipping |
| 59 | +NOTICE: 1 rows copied from test_column_type.test_1 |
| 60 | +NOTICE: 0 rows copied from test_column_type.test_2 |
| 61 | +NOTICE: 0 rows copied from test_column_type.test_3 |
| 62 | +NOTICE: 0 rows copied from test_column_type.test_4 |
| 63 | +NOTICE: 0 rows copied from test_column_type.test_5 |
| 64 | +NOTICE: 0 rows copied from test_column_type.test_6 |
| 65 | +NOTICE: 0 rows copied from test_column_type.test_7 |
| 66 | +NOTICE: 0 rows copied from test_column_type.test_8 |
| 67 | +NOTICE: 0 rows copied from test_column_type.test_9 |
| 68 | +NOTICE: 0 rows copied from test_column_type.test_10 |
| 69 | + drop_partitions |
| 70 | +----------------- |
| 71 | + 10 |
| 72 | +(1 row) |
| 73 | + |
| 74 | +DROP TABLE test_column_type.test CASCADE; |
| 75 | +/* |
| 76 | + * HASH partitioning. |
| 77 | + */ |
| 78 | +/* create new table (id int, val int) */ |
| 79 | +CREATE TABLE test_column_type.test(id INT4 NOT NULL, val INT4); |
| 80 | +SELECT create_hash_partitions('test_column_type.test', 'id', 5); |
| 81 | + create_hash_partitions |
| 82 | +------------------------ |
| 83 | + 5 |
| 84 | +(1 row) |
| 85 | + |
| 86 | +/* make sure that bounds and dispatch info has been cached */ |
| 87 | +SELECT * FROM test_column_type.test; |
| 88 | + id | val |
| 89 | +----+----- |
| 90 | +(0 rows) |
| 91 | + |
| 92 | +SELECT context, entries FROM pathman_cache_stats ORDER BY context; |
| 93 | + context | entries |
| 94 | +--------------------------+--------- |
| 95 | + maintenance | 0 |
| 96 | + partition bounds cache | 5 |
| 97 | + partition dispatch cache | 1 |
| 98 | + partition parents cache | 5 |
| 99 | +(4 rows) |
| 100 | + |
| 101 | +/* change column's type (should NOT work) */ |
| 102 | +ALTER TABLE test_column_type.test ALTER id TYPE NUMERIC; |
| 103 | +ERROR: cannot change type of column "id" of table "test" partitioned by HASH |
| 104 | +/* make sure that everything works properly */ |
| 105 | +SELECT * FROM test_column_type.test; |
| 106 | + id | val |
| 107 | +----+----- |
| 108 | +(0 rows) |
| 109 | + |
| 110 | +SELECT context, entries FROM pathman_cache_stats ORDER BY context; |
| 111 | + context | entries |
| 112 | +--------------------------+--------- |
| 113 | + maintenance | 0 |
| 114 | + partition bounds cache | 5 |
| 115 | + partition dispatch cache | 1 |
| 116 | + partition parents cache | 5 |
| 117 | +(4 rows) |
| 118 | + |
| 119 | +/* change column's type (should flush caches) */ |
| 120 | +ALTER TABLE test_column_type.test ALTER val TYPE NUMERIC; |
| 121 | +/* make sure that everything works properly */ |
| 122 | +SELECT * FROM test_column_type.test; |
| 123 | + id | val |
| 124 | +----+----- |
| 125 | +(0 rows) |
| 126 | + |
| 127 | +SELECT context, entries FROM pathman_cache_stats ORDER BY context; |
| 128 | + context | entries |
| 129 | +--------------------------+--------- |
| 130 | + maintenance | 0 |
| 131 | + partition bounds cache | 5 |
| 132 | + partition dispatch cache | 1 |
| 133 | + partition parents cache | 5 |
| 134 | +(4 rows) |
| 135 | + |
| 136 | +/* check insert dispatching */ |
| 137 | +INSERT INTO test_column_type.test VALUES (1); |
| 138 | +SELECT tableoid::regclass, * FROM test_column_type.test; |
| 139 | + tableoid | id | val |
| 140 | +-------------------------+----+----- |
| 141 | + test_column_type.test_0 | 1 | |
| 142 | +(1 row) |
| 143 | + |
| 144 | +SELECT drop_partitions('test_column_type.test'); |
| 145 | +NOTICE: function test_column_type.test_upd_trig_func() does not exist, skipping |
| 146 | +NOTICE: 1 rows copied from test_column_type.test_0 |
| 147 | +NOTICE: 0 rows copied from test_column_type.test_1 |
| 148 | +NOTICE: 0 rows copied from test_column_type.test_2 |
| 149 | +NOTICE: 0 rows copied from test_column_type.test_3 |
| 150 | +NOTICE: 0 rows copied from test_column_type.test_4 |
| 151 | + drop_partitions |
| 152 | +----------------- |
| 153 | + 5 |
| 154 | +(1 row) |
| 155 | + |
| 156 | +DROP TABLE test_column_type.test CASCADE; |
| 157 | +DROP SCHEMA test_column_type CASCADE; |
| 158 | +NOTICE: drop cascades to sequence test_column_type.test_seq |
| 159 | +DROP EXTENSION pg_pathman; |