| 1 |
CREATE EXTENSION pg_visibility; |
| 2 |
-- |
| 3 |
-- recently-dropped table |
| 4 |
-- |
| 5 |
\set VERBOSITY sqlstate |
| 6 |
BEGIN; |
| 7 |
CREATE TABLE droppedtest (c int); |
| 8 |
SELECT 'droppedtest'::regclass::oid AS oid \gset |
| 9 |
SAVEPOINT q; DROP TABLE droppedtest; RELEASE q; |
| 10 |
SAVEPOINT q; SELECT * FROM pg_visibility_map(:oid); ROLLBACK TO q; |
| 11 |
ERROR: XX000 |
| 12 |
-- ERROR: could not open relation with OID 16xxx |
| 13 |
SAVEPOINT q; SELECT 1; ROLLBACK TO q; |
| 14 |
?column? |
| 15 |
---------- |
| 16 |
1 |
| 17 |
(1 row) |
| 18 |
|
| 19 |
SAVEPOINT q; SELECT 1; ROLLBACK TO q; |
| 20 |
?column? |
| 21 |
---------- |
| 22 |
1 |
| 23 |
(1 row) |
| 24 |
|
| 25 |
SELECT pg_relation_size(:oid), pg_relation_filepath(:oid), |
| 26 |
has_table_privilege(:oid, 'SELECT'); |
| 27 |
pg_relation_size | pg_relation_filepath | has_table_privilege |
| 28 |
------------------+----------------------+--------------------- |
| 29 |
| | |
| 30 |
(1 row) |
| 31 |
|
| 32 |
SELECT * FROM pg_visibility_map(:oid); |
| 33 |
ERROR: XX000 |
| 34 |
-- ERROR: could not open relation with OID 16xxx |
| 35 |
ROLLBACK; |
| 36 |
\set VERBOSITY default |
| 37 |
-- |
| 38 |
-- check that using the module's functions with unsupported relations will fail |
| 39 |
-- |
| 40 |
-- partitioned tables (the parent ones) don't have visibility maps |
| 41 |
create table test_partitioned (a int) partition by list (a); |
| 42 |
-- these should all fail |
| 43 |
select pg_visibility('test_partitioned', 0); |
| 44 |
ERROR: relation "test_partitioned" is of wrong relation kind |
| 45 |
DETAIL: This operation is not supported for partitioned tables. |
| 46 |
select pg_visibility_map('test_partitioned'); |
| 47 |
ERROR: relation "test_partitioned" is of wrong relation kind |
| 48 |
DETAIL: This operation is not supported for partitioned tables. |
| 49 |
select pg_visibility_map_summary('test_partitioned'); |
| 50 |
ERROR: relation "test_partitioned" is of wrong relation kind |
| 51 |
DETAIL: This operation is not supported for partitioned tables. |
| 52 |
select pg_check_frozen('test_partitioned'); |
| 53 |
ERROR: relation "test_partitioned" is of wrong relation kind |
| 54 |
DETAIL: This operation is not supported for partitioned tables. |
| 55 |
select pg_truncate_visibility_map('test_partitioned'); |
| 56 |
ERROR: relation "test_partitioned" is of wrong relation kind |
| 57 |
DETAIL: This operation is not supported for partitioned tables. |
| 58 |
create table test_partition partition of test_partitioned for values in (1); |
| 59 |
create index test_index on test_partition (a); |
| 60 |
-- indexes do not, so these all fail |
| 61 |
select pg_visibility('test_index', 0); |
| 62 |
ERROR: relation "test_index" is of wrong relation kind |
| 63 |
DETAIL: This operation is not supported for indexes. |
| 64 |
select pg_visibility_map('test_index'); |
| 65 |
ERROR: relation "test_index" is of wrong relation kind |
| 66 |
DETAIL: This operation is not supported for indexes. |
| 67 |
select pg_visibility_map_summary('test_index'); |
| 68 |
ERROR: relation "test_index" is of wrong relation kind |
| 69 |
DETAIL: This operation is not supported for indexes. |
| 70 |
select pg_check_frozen('test_index'); |
| 71 |
ERROR: relation "test_index" is of wrong relation kind |
| 72 |
DETAIL: This operation is not supported for indexes. |
| 73 |
select pg_truncate_visibility_map('test_index'); |
| 74 |
ERROR: relation "test_index" is of wrong relation kind |
| 75 |
DETAIL: This operation is not supported for indexes. |
| 76 |
create view test_view as select 1; |
| 77 |
-- views do not have VMs, so these all fail |
| 78 |
select pg_visibility('test_view', 0); |
| 79 |
ERROR: relation "test_view" is of wrong relation kind |
| 80 |
DETAIL: This operation is not supported for views. |
| 81 |
select pg_visibility_map('test_view'); |
| 82 |
ERROR: relation "test_view" is of wrong relation kind |
| 83 |
DETAIL: This operation is not supported for views. |
| 84 |
select pg_visibility_map_summary('test_view'); |
| 85 |
ERROR: relation "test_view" is of wrong relation kind |
| 86 |
DETAIL: This operation is not supported for views. |
| 87 |
select pg_check_frozen('test_view'); |
| 88 |
ERROR: relation "test_view" is of wrong relation kind |
| 89 |
DETAIL: This operation is not supported for views. |
| 90 |
select pg_truncate_visibility_map('test_view'); |
| 91 |
ERROR: relation "test_view" is of wrong relation kind |
| 92 |
DETAIL: This operation is not supported for views. |
| 93 |
create sequence test_sequence; |
| 94 |
-- sequences do not have VMs, so these all fail |
| 95 |
select pg_visibility('test_sequence', 0); |
| 96 |
ERROR: relation "test_sequence" is of wrong relation kind |
| 97 |
DETAIL: This operation is not supported for sequences. |
| 98 |
select pg_visibility_map('test_sequence'); |
| 99 |
ERROR: relation "test_sequence" is of wrong relation kind |
| 100 |
DETAIL: This operation is not supported for sequences. |
| 101 |
select pg_visibility_map_summary('test_sequence'); |
| 102 |
ERROR: relation "test_sequence" is of wrong relation kind |
| 103 |
DETAIL: This operation is not supported for sequences. |
| 104 |
select pg_check_frozen('test_sequence'); |
| 105 |
ERROR: relation "test_sequence" is of wrong relation kind |
| 106 |
DETAIL: This operation is not supported for sequences. |
| 107 |
select pg_truncate_visibility_map('test_sequence'); |
| 108 |
ERROR: relation "test_sequence" is of wrong relation kind |
| 109 |
DETAIL: This operation is not supported for sequences. |
| 110 |
create foreign data wrapper dummy; |
| 111 |
create server dummy_server foreign data wrapper dummy; |
| 112 |
create foreign table test_foreign_table () server dummy_server; |
| 113 |
-- foreign tables do not have VMs, so these all fail |
| 114 |
select pg_visibility('test_foreign_table', 0); |
| 115 |
ERROR: relation "test_foreign_table" is of wrong relation kind |
| 116 |
DETAIL: This operation is not supported for foreign tables. |
| 117 |
select pg_visibility_map('test_foreign_table'); |
| 118 |
ERROR: relation "test_foreign_table" is of wrong relation kind |
| 119 |
DETAIL: This operation is not supported for foreign tables. |
| 120 |
select pg_visibility_map_summary('test_foreign_table'); |
| 121 |
ERROR: relation "test_foreign_table" is of wrong relation kind |
| 122 |
DETAIL: This operation is not supported for foreign tables. |
| 123 |
select pg_check_frozen('test_foreign_table'); |
| 124 |
ERROR: relation "test_foreign_table" is of wrong relation kind |
| 125 |
DETAIL: This operation is not supported for foreign tables. |
| 126 |
select pg_truncate_visibility_map('test_foreign_table'); |
| 127 |
ERROR: relation "test_foreign_table" is of wrong relation kind |
| 128 |
DETAIL: This operation is not supported for foreign tables. |
| 129 |
-- check some of the allowed relkinds |
| 130 |
create table regular_table (a int, b text); |
| 131 |
alter table regular_table alter column b set storage external; |
| 132 |
insert into regular_table values (1, repeat('one', 1000)), (2, repeat('two', 1000)); |
| 133 |
vacuum (disable_page_skipping) regular_table; |
| 134 |
select count(*) > 0 from pg_visibility('regular_table'); |
| 135 |
?column? |
| 136 |
---------- |
| 137 |
t |
| 138 |
(1 row) |
| 139 |
|
| 140 |
select count(*) > 0 from pg_visibility((select reltoastrelid from pg_class where relname = 'regular_table')); |
| 141 |
?column? |
| 142 |
---------- |
| 143 |
t |
| 144 |
(1 row) |
| 145 |
|
| 146 |
truncate regular_table; |
| 147 |
select count(*) > 0 from pg_visibility('regular_table'); |
| 148 |
?column? |
| 149 |
---------- |
| 150 |
f |
| 151 |
(1 row) |
| 152 |
|
| 153 |
select count(*) > 0 from pg_visibility((select reltoastrelid from pg_class where relname = 'regular_table')); |
| 154 |
?column? |
| 155 |
---------- |
| 156 |
f |
| 157 |
(1 row) |
| 158 |
|
| 159 |
create materialized view matview_visibility_test as select * from regular_table; |
| 160 |
vacuum (disable_page_skipping) matview_visibility_test; |
| 161 |
select count(*) > 0 from pg_visibility('matview_visibility_test'); |
| 162 |
?column? |
| 163 |
---------- |
| 164 |
f |
| 165 |
(1 row) |
| 166 |
|
| 167 |
insert into regular_table values (1), (2); |
| 168 |
refresh materialized view matview_visibility_test; |
| 169 |
select count(*) > 0 from pg_visibility('matview_visibility_test'); |
| 170 |
?column? |
| 171 |
---------- |
| 172 |
t |
| 173 |
(1 row) |
| 174 |
|
| 175 |
-- regular tables which are part of a partition *do* have visibility maps |
| 176 |
insert into test_partition values (1); |
| 177 |
vacuum (disable_page_skipping) test_partition; |
| 178 |
select count(*) > 0 from pg_visibility('test_partition', 0); |
| 179 |
?column? |
| 180 |
---------- |
| 181 |
t |
| 182 |
(1 row) |
| 183 |
|
| 184 |
select count(*) > 0 from pg_visibility_map('test_partition'); |
| 185 |
?column? |
| 186 |
---------- |
| 187 |
t |
| 188 |
(1 row) |
| 189 |
|
| 190 |
select count(*) > 0 from pg_visibility_map_summary('test_partition'); |
| 191 |
?column? |
| 192 |
---------- |
| 193 |
t |
| 194 |
(1 row) |
| 195 |
|
| 196 |
select * from pg_check_frozen('test_partition'); -- hopefully none |
| 197 |
t_ctid |
| 198 |
-------- |
| 199 |
(0 rows) |
| 200 |
|
| 201 |
select pg_truncate_visibility_map('test_partition'); |
| 202 |
pg_truncate_visibility_map |
| 203 |
---------------------------- |
| 204 |
|
| 205 |
(1 row) |
| 206 |
|
| 207 |
-- test copy freeze |
| 208 |
create table copyfreeze (a int, b char(1500)); |
| 209 |
-- load all rows via COPY FREEZE and ensure that all pages are set all-visible |
| 210 |
-- and all-frozen. |
| 211 |
begin; |
| 212 |
truncate copyfreeze; |
| 213 |
copy copyfreeze from stdin freeze; |
| 214 |
commit; |
| 215 |
select * from pg_visibility_map('copyfreeze'); |
| 216 |
blkno | all_visible | all_frozen |
| 217 |
-------+-------------+------------ |
| 218 |
0 | t | t |
| 219 |
1 | t | t |
| 220 |
(2 rows) |
| 221 |
|
| 222 |
select * from pg_check_frozen('copyfreeze'); |
| 223 |
t_ctid |
| 224 |
-------- |
| 225 |
(0 rows) |
| 226 |
|
| 227 |
-- load half the rows via regular COPY and rest via COPY FREEZE. The pages |
| 228 |
-- which are touched by regular COPY must not be set all-visible/all-frozen. On |
| 229 |
-- the other hand, pages allocated by COPY FREEZE should be marked |
| 230 |
-- all-frozen/all-visible. |
| 231 |
begin; |
| 232 |
truncate copyfreeze; |
| 233 |
copy copyfreeze from stdin; |
| 234 |
copy copyfreeze from stdin freeze; |
| 235 |
commit; |
| 236 |
select * from pg_visibility_map('copyfreeze'); |
| 237 |
blkno | all_visible | all_frozen |
| 238 |
-------+-------------+------------ |
| 239 |
0 | f | f |
| 240 |
1 | f | f |
| 241 |
2 | t | t |
| 242 |
(3 rows) |
| 243 |
|
| 244 |
select * from pg_check_frozen('copyfreeze'); |
| 245 |
t_ctid |
| 246 |
-------- |
| 247 |
(0 rows) |
| 248 |
|
| 249 |
-- Try a mix of regular COPY and COPY FREEZE. |
| 250 |
begin; |
| 251 |
truncate copyfreeze; |
| 252 |
copy copyfreeze from stdin freeze; |
| 253 |
copy copyfreeze from stdin; |
| 254 |
copy copyfreeze from stdin freeze; |
| 255 |
commit; |
| 256 |
select * from pg_visibility_map('copyfreeze'); |
| 257 |
blkno | all_visible | all_frozen |
| 258 |
-------+-------------+------------ |
| 259 |
0 | t | t |
| 260 |
1 | f | f |
| 261 |
2 | t | t |
| 262 |
(3 rows) |
| 263 |
|
| 264 |
select * from pg_check_frozen('copyfreeze'); |
| 265 |
t_ctid |
| 266 |
-------- |
| 267 |
(0 rows) |
| 268 |
|
| 269 |
-- cleanup |
| 270 |
drop table test_partitioned; |
| 271 |
drop view test_view; |
| 272 |
drop sequence test_sequence; |
| 273 |
drop foreign table test_foreign_table; |
| 274 |
drop server dummy_server; |
| 275 |
drop foreign data wrapper dummy; |
| 276 |
drop materialized view matview_visibility_test; |
| 277 |
drop table regular_table; |
| 278 |
drop table copyfreeze; |