|
| 1 | +/* |
| 2 | + * In 9ce77d75c5a (>= 13) struct Var was changed, which caused the output |
| 3 | + * of get_partition_cooked_key to change. |
| 4 | + */ |
| 5 | +\set VERBOSITY terse |
| 6 | +SET search_path = 'public'; |
| 7 | +CREATE EXTENSION pg_pathman; |
| 8 | +CREATE SCHEMA test_column_type; |
| 9 | +/* |
| 10 | + * RANGE partitioning. |
| 11 | + */ |
| 12 | +/* create new table (val int) */ |
| 13 | +CREATE TABLE test_column_type.test(val INT4 NOT NULL); |
| 14 | +SELECT create_range_partitions('test_column_type.test', 'val', 1, 10, 10); |
| 15 | + create_range_partitions |
| 16 | +------------------------- |
| 17 | + 10 |
| 18 | +(1 row) |
| 19 | + |
| 20 | +/* make sure that bounds and dispatch info has been cached */ |
| 21 | +SELECT * FROM test_column_type.test; |
| 22 | + val |
| 23 | +----- |
| 24 | +(0 rows) |
| 25 | + |
| 26 | +SELECT context, entries FROM pathman_cache_stats |
| 27 | + WHERE context != 'partition status cache' ORDER BY context; |
| 28 | + context | entries |
| 29 | +-------------------------+--------- |
| 30 | + maintenance | 0 |
| 31 | + partition bounds cache | 10 |
| 32 | + partition parents cache | 10 |
| 33 | +(3 rows) |
| 34 | + |
| 35 | +/* |
| 36 | + * Get parsed and analyzed expression. |
| 37 | + */ |
| 38 | +CREATE FUNCTION get_cached_partition_cooked_key(REGCLASS) |
| 39 | +RETURNS TEXT AS 'pg_pathman', 'get_cached_partition_cooked_key_pl' |
| 40 | +LANGUAGE C STRICT; |
| 41 | +SELECT get_partition_cooked_key('test_column_type.test'::REGCLASS); |
| 42 | + get_partition_cooked_key |
| 43 | +--------------------------------------------------------------------------------------------------------------------------------------------- |
| 44 | + {VAR :varno 1 :varattno 1 :vartype 23 :vartypmod -1 :varcollid 0 :varnullingrels (b) :varlevelsup 0 :varnosyn 1 :varattnosyn 1 :location 8} |
| 45 | +(1 row) |
| 46 | + |
| 47 | +SELECT get_cached_partition_cooked_key('test_column_type.test'::REGCLASS); |
| 48 | + get_cached_partition_cooked_key |
| 49 | +--------------------------------------------------------------------------------------------------------------------------------------------- |
| 50 | + {VAR :varno 1 :varattno 1 :vartype 23 :vartypmod -1 :varcollid 0 :varnullingrels (b) :varlevelsup 0 :varnosyn 1 :varattnosyn 1 :location 8} |
| 51 | +(1 row) |
| 52 | + |
| 53 | +SELECT get_partition_key_type('test_column_type.test'::REGCLASS); |
| 54 | + get_partition_key_type |
| 55 | +------------------------ |
| 56 | + integer |
| 57 | +(1 row) |
| 58 | + |
| 59 | +/* change column's type (should also flush caches) */ |
| 60 | +ALTER TABLE test_column_type.test ALTER val TYPE NUMERIC; |
| 61 | +/* check that correct expression has been built */ |
| 62 | +SELECT get_partition_key_type('test_column_type.test'::REGCLASS); |
| 63 | + get_partition_key_type |
| 64 | +------------------------ |
| 65 | + numeric |
| 66 | +(1 row) |
| 67 | + |
| 68 | +SELECT get_partition_cooked_key('test_column_type.test'::REGCLASS); |
| 69 | + get_partition_cooked_key |
| 70 | +----------------------------------------------------------------------------------------------------------------------------------------------- |
| 71 | + {VAR :varno 1 :varattno 1 :vartype 1700 :vartypmod -1 :varcollid 0 :varnullingrels (b) :varlevelsup 0 :varnosyn 1 :varattnosyn 1 :location 8} |
| 72 | +(1 row) |
| 73 | + |
| 74 | +SELECT get_cached_partition_cooked_key('test_column_type.test'::REGCLASS); |
| 75 | + get_cached_partition_cooked_key |
| 76 | +----------------------------------------------------------------------------------------------------------------------------------------------- |
| 77 | + {VAR :varno 1 :varattno 1 :vartype 1700 :vartypmod -1 :varcollid 0 :varnullingrels (b) :varlevelsup 0 :varnosyn 1 :varattnosyn 1 :location 8} |
| 78 | +(1 row) |
| 79 | + |
| 80 | +DROP FUNCTION get_cached_partition_cooked_key(REGCLASS); |
| 81 | +/* make sure that everything works properly */ |
| 82 | +SELECT * FROM test_column_type.test; |
| 83 | + val |
| 84 | +----- |
| 85 | +(0 rows) |
| 86 | + |
| 87 | +SELECT context, entries FROM pathman_cache_stats |
| 88 | + WHERE context != 'partition status cache' ORDER BY context; |
| 89 | + context | entries |
| 90 | +-------------------------+--------- |
| 91 | + maintenance | 0 |
| 92 | + partition bounds cache | 10 |
| 93 | + partition parents cache | 10 |
| 94 | +(3 rows) |
| 95 | + |
| 96 | +/* check insert dispatching */ |
| 97 | +INSERT INTO test_column_type.test VALUES (1); |
| 98 | +SELECT tableoid::regclass, * FROM test_column_type.test; |
| 99 | + tableoid | val |
| 100 | +-------------------------+----- |
| 101 | + test_column_type.test_1 | 1 |
| 102 | +(1 row) |
| 103 | + |
| 104 | +SELECT drop_partitions('test_column_type.test'); |
| 105 | +NOTICE: 1 rows copied from test_column_type.test_1 |
| 106 | +NOTICE: 0 rows copied from test_column_type.test_2 |
| 107 | +NOTICE: 0 rows copied from test_column_type.test_3 |
| 108 | +NOTICE: 0 rows copied from test_column_type.test_4 |
| 109 | +NOTICE: 0 rows copied from test_column_type.test_5 |
| 110 | +NOTICE: 0 rows copied from test_column_type.test_6 |
| 111 | +NOTICE: 0 rows copied from test_column_type.test_7 |
| 112 | +NOTICE: 0 rows copied from test_column_type.test_8 |
| 113 | +NOTICE: 0 rows copied from test_column_type.test_9 |
| 114 | +NOTICE: 0 rows copied from test_column_type.test_10 |
| 115 | + drop_partitions |
| 116 | +----------------- |
| 117 | + 10 |
| 118 | +(1 row) |
| 119 | + |
| 120 | +DROP TABLE test_column_type.test CASCADE; |
| 121 | +/* |
| 122 | + * HASH partitioning. |
| 123 | + */ |
| 124 | +/* create new table (id int, val int) */ |
| 125 | +CREATE TABLE test_column_type.test(id INT4 NOT NULL, val INT4); |
| 126 | +SELECT create_hash_partitions('test_column_type.test', 'id', 5); |
| 127 | + create_hash_partitions |
| 128 | +------------------------ |
| 129 | + 5 |
| 130 | +(1 row) |
| 131 | + |
| 132 | +/* make sure that bounds and dispatch info has been cached */ |
| 133 | +SELECT * FROM test_column_type.test; |
| 134 | + id | val |
| 135 | +----+----- |
| 136 | +(0 rows) |
| 137 | + |
| 138 | +SELECT context, entries FROM pathman_cache_stats |
| 139 | + WHERE context != 'partition status cache' ORDER BY context; |
| 140 | + context | entries |
| 141 | +-------------------------+--------- |
| 142 | + maintenance | 0 |
| 143 | + partition bounds cache | 5 |
| 144 | + partition parents cache | 5 |
| 145 | +(3 rows) |
| 146 | + |
| 147 | +/* change column's type (should NOT work) */ |
| 148 | +ALTER TABLE test_column_type.test ALTER id TYPE NUMERIC; |
| 149 | +ERROR: cannot change type of column "id" of table "test" partitioned by HASH |
| 150 | +/* make sure that everything works properly */ |
| 151 | +SELECT * FROM test_column_type.test; |
| 152 | + id | val |
| 153 | +----+----- |
| 154 | +(0 rows) |
| 155 | + |
| 156 | +SELECT context, entries FROM pathman_cache_stats |
| 157 | + WHERE context != 'partition status cache' ORDER BY context; |
| 158 | + context | entries |
| 159 | +-------------------------+--------- |
| 160 | + maintenance | 0 |
| 161 | + partition bounds cache | 5 |
| 162 | + partition parents cache | 5 |
| 163 | +(3 rows) |
| 164 | + |
| 165 | +/* change column's type (should flush caches) */ |
| 166 | +ALTER TABLE test_column_type.test ALTER val TYPE NUMERIC; |
| 167 | +/* make sure that everything works properly */ |
| 168 | +SELECT * FROM test_column_type.test; |
| 169 | + id | val |
| 170 | +----+----- |
| 171 | +(0 rows) |
| 172 | + |
| 173 | +SELECT context, entries FROM pathman_cache_stats |
| 174 | + WHERE context != 'partition status cache' ORDER BY context; |
| 175 | + context | entries |
| 176 | +-------------------------+--------- |
| 177 | + maintenance | 0 |
| 178 | + partition bounds cache | 5 |
| 179 | + partition parents cache | 5 |
| 180 | +(3 rows) |
| 181 | + |
| 182 | +/* check insert dispatching */ |
| 183 | +INSERT INTO test_column_type.test VALUES (1); |
| 184 | +SELECT tableoid::regclass, * FROM test_column_type.test; |
| 185 | + tableoid | id | val |
| 186 | +-------------------------+----+----- |
| 187 | + test_column_type.test_0 | 1 | |
| 188 | +(1 row) |
| 189 | + |
| 190 | +SELECT drop_partitions('test_column_type.test'); |
| 191 | +NOTICE: 1 rows copied from test_column_type.test_0 |
| 192 | +NOTICE: 0 rows copied from test_column_type.test_1 |
| 193 | +NOTICE: 0 rows copied from test_column_type.test_2 |
| 194 | +NOTICE: 0 rows copied from test_column_type.test_3 |
| 195 | +NOTICE: 0 rows copied from test_column_type.test_4 |
| 196 | + drop_partitions |
| 197 | +----------------- |
| 198 | + 5 |
| 199 | +(1 row) |
| 200 | + |
| 201 | +DROP TABLE test_column_type.test CASCADE; |
| 202 | +DROP SCHEMA test_column_type; |
| 203 | +DROP EXTENSION pg_pathman; |