2016-09-29 12:00:00 -04:00
|
|
|
CREATE EXTENSION pageinspect;
|
|
|
|
|
2022-11-21 10:50:50 -05:00
|
|
|
-- Use a temp table so that effects of VACUUM are predictable
|
|
|
|
CREATE TEMP TABLE test1 (a int, b int);
|
2019-05-07 09:30:24 +05:30
|
|
|
INSERT INTO test1 VALUES (16777217, 131584);
|
2016-09-29 12:00:00 -04:00
|
|
|
|
2021-01-20 11:49:29 -05:00
|
|
|
VACUUM (DISABLE_PAGE_SKIPPING) test1; -- set up FSM
|
2016-09-29 12:00:00 -04:00
|
|
|
|
|
|
|
-- The page contents can vary, so just test that it can be read
|
|
|
|
-- successfully, but don't keep the output.
|
|
|
|
|
2019-05-07 09:30:24 +05:30
|
|
|
SELECT octet_length(get_raw_page('test1', 'main', 0)) AS main_0;
|
|
|
|
SELECT octet_length(get_raw_page('test1', 'main', 1)) AS main_1;
|
2016-09-29 12:00:00 -04:00
|
|
|
|
2019-05-07 09:30:24 +05:30
|
|
|
SELECT octet_length(get_raw_page('test1', 'fsm', 0)) AS fsm_0;
|
|
|
|
SELECT octet_length(get_raw_page('test1', 'fsm', 1)) AS fsm_1;
|
2016-09-29 12:00:00 -04:00
|
|
|
|
2019-05-07 09:30:24 +05:30
|
|
|
SELECT octet_length(get_raw_page('test1', 'vm', 0)) AS vm_0;
|
|
|
|
SELECT octet_length(get_raw_page('test1', 'vm', 1)) AS vm_1;
|
2016-09-29 12:00:00 -04:00
|
|
|
|
2021-01-19 10:28:05 +01:00
|
|
|
SELECT octet_length(get_raw_page('test1', 'main', -1));
|
2016-09-29 12:00:00 -04:00
|
|
|
SELECT octet_length(get_raw_page('xxx', 'main', 0));
|
2019-05-07 09:30:24 +05:30
|
|
|
SELECT octet_length(get_raw_page('test1', 'xxx', 0));
|
2016-09-29 12:00:00 -04:00
|
|
|
|
2019-05-07 09:30:24 +05:30
|
|
|
SELECT get_raw_page('test1', 0) = get_raw_page('test1', 'main', 0);
|
2016-09-29 12:00:00 -04:00
|
|
|
|
2017-03-17 09:23:39 -04:00
|
|
|
SELECT pagesize, version FROM page_header(get_raw_page('test1', 0));
|
|
|
|
|
2017-03-17 09:49:10 -04:00
|
|
|
SELECT page_checksum(get_raw_page('test1', 0), 0) IS NOT NULL AS silly_checksum_test;
|
2021-01-19 10:28:05 +01:00
|
|
|
SELECT page_checksum(get_raw_page('test1', 0), -1);
|
2017-03-17 09:49:10 -04:00
|
|
|
|
2016-09-29 12:00:00 -04:00
|
|
|
SELECT tuple_data_split('test1'::regclass, t_data, t_infomask, t_infomask2, t_bits)
|
|
|
|
FROM heap_page_items(get_raw_page('test1', 0));
|
|
|
|
|
2019-05-07 09:30:24 +05:30
|
|
|
SELECT * FROM fsm_page_contents(get_raw_page('test1', 'fsm', 0));
|
|
|
|
|
Add to pageinspect function to make t_infomask/t_infomask2 human-readable
Flags of t_infomask and t_infomask2 for each tuple are already included
in the information returned by heap_page_items as integers, and we
lacked a way to make that information human-readable.
Per discussion, the function includes an option which controls if
combined flags should be decomposed or not. The default is false, to
not decompose combined flags.
The module is bumped to version 1.8.
Author: Craig Ringer, Sawada Masahiko
Reviewed-by: Peter Geoghegan, Robert Haas, Álvaro Herrera, Moon Insung,
Amit Kapila, Michael Paquier, Tomas Vondra
Discussion: https://postgr.es/m/CAMsr+YEY7jeaXOb+oX+RhDyOFuTMdmHjGsBxL=igCm03J0go9Q@mail.gmail.com
2019-09-12 15:06:00 +09:00
|
|
|
-- If we freeze the only tuple on test1, the infomask should
|
2021-01-20 11:49:29 -05:00
|
|
|
-- always be the same in all test runs.
|
|
|
|
VACUUM (FREEZE, DISABLE_PAGE_SKIPPING) test1;
|
Add to pageinspect function to make t_infomask/t_infomask2 human-readable
Flags of t_infomask and t_infomask2 for each tuple are already included
in the information returned by heap_page_items as integers, and we
lacked a way to make that information human-readable.
Per discussion, the function includes an option which controls if
combined flags should be decomposed or not. The default is false, to
not decompose combined flags.
The module is bumped to version 1.8.
Author: Craig Ringer, Sawada Masahiko
Reviewed-by: Peter Geoghegan, Robert Haas, Álvaro Herrera, Moon Insung,
Amit Kapila, Michael Paquier, Tomas Vondra
Discussion: https://postgr.es/m/CAMsr+YEY7jeaXOb+oX+RhDyOFuTMdmHjGsBxL=igCm03J0go9Q@mail.gmail.com
2019-09-12 15:06:00 +09:00
|
|
|
|
2019-09-19 11:01:52 +09:00
|
|
|
SELECT t_infomask, t_infomask2, raw_flags, combined_flags
|
Add to pageinspect function to make t_infomask/t_infomask2 human-readable
Flags of t_infomask and t_infomask2 for each tuple are already included
in the information returned by heap_page_items as integers, and we
lacked a way to make that information human-readable.
Per discussion, the function includes an option which controls if
combined flags should be decomposed or not. The default is false, to
not decompose combined flags.
The module is bumped to version 1.8.
Author: Craig Ringer, Sawada Masahiko
Reviewed-by: Peter Geoghegan, Robert Haas, Álvaro Herrera, Moon Insung,
Amit Kapila, Michael Paquier, Tomas Vondra
Discussion: https://postgr.es/m/CAMsr+YEY7jeaXOb+oX+RhDyOFuTMdmHjGsBxL=igCm03J0go9Q@mail.gmail.com
2019-09-12 15:06:00 +09:00
|
|
|
FROM heap_page_items(get_raw_page('test1', 0)),
|
2019-09-19 11:01:52 +09:00
|
|
|
LATERAL heap_tuple_infomask_flags(t_infomask, t_infomask2);
|
Add to pageinspect function to make t_infomask/t_infomask2 human-readable
Flags of t_infomask and t_infomask2 for each tuple are already included
in the information returned by heap_page_items as integers, and we
lacked a way to make that information human-readable.
Per discussion, the function includes an option which controls if
combined flags should be decomposed or not. The default is false, to
not decompose combined flags.
The module is bumped to version 1.8.
Author: Craig Ringer, Sawada Masahiko
Reviewed-by: Peter Geoghegan, Robert Haas, Álvaro Herrera, Moon Insung,
Amit Kapila, Michael Paquier, Tomas Vondra
Discussion: https://postgr.es/m/CAMsr+YEY7jeaXOb+oX+RhDyOFuTMdmHjGsBxL=igCm03J0go9Q@mail.gmail.com
2019-09-12 15:06:00 +09:00
|
|
|
|
|
|
|
-- tests for decoding of combined flags
|
|
|
|
-- HEAP_XMAX_SHR_LOCK = (HEAP_XMAX_EXCL_LOCK | HEAP_XMAX_KEYSHR_LOCK)
|
2019-09-19 11:01:52 +09:00
|
|
|
SELECT * FROM heap_tuple_infomask_flags(x'0050'::int, 0);
|
Add to pageinspect function to make t_infomask/t_infomask2 human-readable
Flags of t_infomask and t_infomask2 for each tuple are already included
in the information returned by heap_page_items as integers, and we
lacked a way to make that information human-readable.
Per discussion, the function includes an option which controls if
combined flags should be decomposed or not. The default is false, to
not decompose combined flags.
The module is bumped to version 1.8.
Author: Craig Ringer, Sawada Masahiko
Reviewed-by: Peter Geoghegan, Robert Haas, Álvaro Herrera, Moon Insung,
Amit Kapila, Michael Paquier, Tomas Vondra
Discussion: https://postgr.es/m/CAMsr+YEY7jeaXOb+oX+RhDyOFuTMdmHjGsBxL=igCm03J0go9Q@mail.gmail.com
2019-09-12 15:06:00 +09:00
|
|
|
-- HEAP_XMIN_FROZEN = (HEAP_XMIN_COMMITTED | HEAP_XMIN_INVALID)
|
2019-09-19 11:01:52 +09:00
|
|
|
SELECT * FROM heap_tuple_infomask_flags(x'0300'::int, 0);
|
Add to pageinspect function to make t_infomask/t_infomask2 human-readable
Flags of t_infomask and t_infomask2 for each tuple are already included
in the information returned by heap_page_items as integers, and we
lacked a way to make that information human-readable.
Per discussion, the function includes an option which controls if
combined flags should be decomposed or not. The default is false, to
not decompose combined flags.
The module is bumped to version 1.8.
Author: Craig Ringer, Sawada Masahiko
Reviewed-by: Peter Geoghegan, Robert Haas, Álvaro Herrera, Moon Insung,
Amit Kapila, Michael Paquier, Tomas Vondra
Discussion: https://postgr.es/m/CAMsr+YEY7jeaXOb+oX+RhDyOFuTMdmHjGsBxL=igCm03J0go9Q@mail.gmail.com
2019-09-12 15:06:00 +09:00
|
|
|
-- HEAP_MOVED = (HEAP_MOVED_IN | HEAP_MOVED_OFF)
|
2019-09-19 11:01:52 +09:00
|
|
|
SELECT * FROM heap_tuple_infomask_flags(x'C000'::int, 0);
|
|
|
|
SELECT * FROM heap_tuple_infomask_flags(x'C000'::int, 0);
|
Add to pageinspect function to make t_infomask/t_infomask2 human-readable
Flags of t_infomask and t_infomask2 for each tuple are already included
in the information returned by heap_page_items as integers, and we
lacked a way to make that information human-readable.
Per discussion, the function includes an option which controls if
combined flags should be decomposed or not. The default is false, to
not decompose combined flags.
The module is bumped to version 1.8.
Author: Craig Ringer, Sawada Masahiko
Reviewed-by: Peter Geoghegan, Robert Haas, Álvaro Herrera, Moon Insung,
Amit Kapila, Michael Paquier, Tomas Vondra
Discussion: https://postgr.es/m/CAMsr+YEY7jeaXOb+oX+RhDyOFuTMdmHjGsBxL=igCm03J0go9Q@mail.gmail.com
2019-09-12 15:06:00 +09:00
|
|
|
|
|
|
|
-- test all flags of t_infomask and t_infomask2
|
2019-09-19 11:01:52 +09:00
|
|
|
SELECT unnest(raw_flags)
|
|
|
|
FROM heap_tuple_infomask_flags(x'FFFF'::int, x'FFFF'::int) ORDER BY 1;
|
|
|
|
SELECT unnest(combined_flags)
|
|
|
|
FROM heap_tuple_infomask_flags(x'FFFF'::int, x'FFFF'::int) ORDER BY 1;
|
|
|
|
|
|
|
|
-- no flags at all
|
|
|
|
SELECT * FROM heap_tuple_infomask_flags(0, 0);
|
|
|
|
-- no combined flags
|
|
|
|
SELECT * FROM heap_tuple_infomask_flags(x'0010'::int, 0);
|
Add to pageinspect function to make t_infomask/t_infomask2 human-readable
Flags of t_infomask and t_infomask2 for each tuple are already included
in the information returned by heap_page_items as integers, and we
lacked a way to make that information human-readable.
Per discussion, the function includes an option which controls if
combined flags should be decomposed or not. The default is false, to
not decompose combined flags.
The module is bumped to version 1.8.
Author: Craig Ringer, Sawada Masahiko
Reviewed-by: Peter Geoghegan, Robert Haas, Álvaro Herrera, Moon Insung,
Amit Kapila, Michael Paquier, Tomas Vondra
Discussion: https://postgr.es/m/CAMsr+YEY7jeaXOb+oX+RhDyOFuTMdmHjGsBxL=igCm03J0go9Q@mail.gmail.com
2019-09-12 15:06:00 +09:00
|
|
|
|
2016-09-29 12:00:00 -04:00
|
|
|
DROP TABLE test1;
|
2017-03-09 16:34:25 -05:00
|
|
|
|
2018-05-09 14:03:43 -03:00
|
|
|
-- check that using any of these functions with a partitioned table or index
|
|
|
|
-- would fail
|
2017-03-09 16:34:25 -05:00
|
|
|
create table test_partitioned (a int) partition by range (a);
|
2018-05-09 14:03:43 -03:00
|
|
|
create index test_partitioned_index on test_partitioned (a);
|
2017-03-09 16:34:25 -05:00
|
|
|
select get_raw_page('test_partitioned', 0); -- error about partitioned table
|
2018-05-09 14:03:43 -03:00
|
|
|
select get_raw_page('test_partitioned_index', 0); -- error about partitioned index
|
2017-03-09 16:34:25 -05:00
|
|
|
|
|
|
|
-- a regular table which is a member of a partition set should work though
|
|
|
|
create table test_part1 partition of test_partitioned for values from ( 1 ) to (100);
|
|
|
|
select get_raw_page('test_part1', 0); -- get farther and error about empty table
|
|
|
|
drop table test_partitioned;
|
2018-01-04 14:59:00 -05:00
|
|
|
|
|
|
|
-- check null bitmap alignment for table whose number of attributes is multiple of 8
|
|
|
|
create table test8 (f1 int, f2 int, f3 int, f4 int, f5 int, f6 int, f7 int, f8 int);
|
2018-01-04 15:59:29 -05:00
|
|
|
insert into test8(f1, f8) values (x'7f00007f'::int, 0);
|
2018-01-04 14:59:00 -05:00
|
|
|
select t_bits, t_data from heap_page_items(get_raw_page('test8', 0));
|
|
|
|
select tuple_data_split('test8'::regclass, t_data, t_infomask, t_infomask2, t_bits)
|
|
|
|
from heap_page_items(get_raw_page('test8', 0));
|
|
|
|
drop table test8;
|
pageinspect: Fix handling of page sizes and AM types
This commit fixes a set of issues related to the use of the SQL
functions in this module when the caller is able to pass down raw page
data as input argument:
- The page size check was fuzzy in a couple of places, sometimes
looking after only a sub-range, but what we are looking for is an exact
match on BLCKSZ. After considering a few options here, I have settled
down to do a generalization of get_page_from_raw(). Most of the SQL
functions already used that, and this is not strictly required if not
accessing an 8-byte-wide value from a raw page, but this feels safer in
the long run for alignment-picky environment, particularly if a code
path begins to access such values. This also reduces the number of
strings that need to be translated.
- The BRIN function brin_page_items() uses a Relation but it did not
check the access method of the opened index, potentially leading to
crashes. All the other functions in need of a Relation already did
that.
- Some code paths could fail on elog(), but we should to use ereport()
for failures that can be triggered by the user.
Tests are added to stress all the cases that are fixed as of this
commit, with some junk raw pages (\set VERBOSITY ensures that this works
across all page sizes) and unexpected index types when functions open
relations.
Author: Michael Paquier, Justin Prysby
Discussion: https://postgr.es/m/20220218030020.GA1137@telsasoft.com
Backpatch-through: 10
2022-03-16 11:19:39 +09:00
|
|
|
|
Virtual generated columns
This adds a new variant of generated columns that are computed on read
(like a view, unlike the existing stored generated columns, which are
computed on write, like a materialized view).
The syntax for the column definition is
... GENERATED ALWAYS AS (...) VIRTUAL
and VIRTUAL is also optional. VIRTUAL is the default rather than
STORED to match various other SQL products. (The SQL standard makes
no specification about this, but it also doesn't know about VIRTUAL or
STORED.) (Also, virtual views are the default, rather than
materialized views.)
Virtual generated columns are stored in tuples as null values. (A
very early version of this patch had the ambition to not store them at
all. But so much stuff breaks or gets confused if you have tuples
where a column in the middle is completely missing. This is a
compromise, and it still saves space over being forced to use stored
generated columns. If we ever find a way to improve this, a bit of
pg_upgrade cleverness could allow for upgrades to a newer scheme.)
The capabilities and restrictions of virtual generated columns are
mostly the same as for stored generated columns. In some cases, this
patch keeps virtual generated columns more restricted than they might
technically need to be, to keep the two kinds consistent. Some of
that could maybe be relaxed later after separate careful
considerations.
Some functionality that is currently not supported, but could possibly
be added as incremental features, some easier than others:
- index on or using a virtual column
- hence also no unique constraints on virtual columns
- extended statistics on virtual columns
- foreign-key constraints on virtual columns
- not-null constraints on virtual columns (check constraints are supported)
- ALTER TABLE / DROP EXPRESSION
- virtual column cannot have domain type
- virtual columns are not supported in logical replication
The tests in generated_virtual.sql have been copied over from
generated_stored.sql with the keyword replaced. This way we can make
sure the behavior is mostly aligned, and the differences can be
visible. Some tests for currently not supported features are
currently commented out.
Reviewed-by: Jian He <jian.universality@gmail.com>
Reviewed-by: Dean Rasheed <dean.a.rasheed@gmail.com>
Tested-by: Shlok Kyal <shlok.kyal.oss@gmail.com>
Discussion: https://www.postgresql.org/message-id/flat/a368248e-69e4-40be-9c07-6c3b5880b0a6@eisentraut.org
2025-02-07 09:09:34 +01:00
|
|
|
-- check storage of generated columns
|
|
|
|
-- stored
|
|
|
|
create table test9s (a int not null, b int generated always as (a * 2) stored);
|
|
|
|
insert into test9s values (131584);
|
|
|
|
select raw_flags, t_bits, t_data
|
|
|
|
from heap_page_items(get_raw_page('test9s', 0)), lateral heap_tuple_infomask_flags(t_infomask, t_infomask2);
|
|
|
|
select tuple_data_split('test9s'::regclass, t_data, t_infomask, t_infomask2, t_bits)
|
|
|
|
from heap_page_items(get_raw_page('test9s', 0));
|
|
|
|
drop table test9s;
|
|
|
|
|
|
|
|
-- virtual
|
|
|
|
create table test9v (a int not null, b int generated always as (a * 2) virtual);
|
|
|
|
insert into test9v values (131584);
|
|
|
|
select raw_flags, t_bits, t_data
|
|
|
|
from heap_page_items(get_raw_page('test9v', 0)), lateral heap_tuple_infomask_flags(t_infomask, t_infomask2);
|
|
|
|
select tuple_data_split('test9v'::regclass, t_data, t_infomask, t_infomask2, t_bits)
|
|
|
|
from heap_page_items(get_raw_page('test9v', 0));
|
|
|
|
drop table test9v;
|
|
|
|
|
pageinspect: Fix handling of page sizes and AM types
This commit fixes a set of issues related to the use of the SQL
functions in this module when the caller is able to pass down raw page
data as input argument:
- The page size check was fuzzy in a couple of places, sometimes
looking after only a sub-range, but what we are looking for is an exact
match on BLCKSZ. After considering a few options here, I have settled
down to do a generalization of get_page_from_raw(). Most of the SQL
functions already used that, and this is not strictly required if not
accessing an 8-byte-wide value from a raw page, but this feels safer in
the long run for alignment-picky environment, particularly if a code
path begins to access such values. This also reduces the number of
strings that need to be translated.
- The BRIN function brin_page_items() uses a Relation but it did not
check the access method of the opened index, potentially leading to
crashes. All the other functions in need of a Relation already did
that.
- Some code paths could fail on elog(), but we should to use ereport()
for failures that can be triggered by the user.
Tests are added to stress all the cases that are fixed as of this
commit, with some junk raw pages (\set VERBOSITY ensures that this works
across all page sizes) and unexpected index types when functions open
relations.
Author: Michael Paquier, Justin Prysby
Discussion: https://postgr.es/m/20220218030020.GA1137@telsasoft.com
Backpatch-through: 10
2022-03-16 11:19:39 +09:00
|
|
|
-- Failure with incorrect page size
|
|
|
|
-- Suppress the DETAIL message, to allow the tests to work across various
|
|
|
|
-- page sizes.
|
|
|
|
\set VERBOSITY terse
|
|
|
|
SELECT fsm_page_contents('aaa'::bytea);
|
|
|
|
SELECT page_checksum('bbb'::bytea, 0);
|
|
|
|
SELECT page_header('ccc'::bytea);
|
|
|
|
\set VERBOSITY default
|
pageinspect: Fix handling of all-zero pages
Getting from get_raw_page() an all-zero page is considered as a valid
case by the buffer manager and it can happen for example when finding a
corrupted page with zero_damaged_pages enabled (using zero_damaged_pages
to look at corrupted pages happens), or after a crash when a relation
file is extended before any WAL for its new data is generated (before a
vacuum or autovacuum job comes in to do some cleanup).
However, all the functions of pageinspect, as of the index AMs (except
hash that has its own idea of new pages), heap, the FSM or the page
header have never worked with all-zero pages, causing various crashes
when going through the page internals.
This commit changes all the pageinspect functions to be compliant with
all-zero pages, where the choice is made to return NULL or no rows for
SRFs when finding a new page. get_raw_page() still works the same way,
returning a batch of zeros in the bytea of the page retrieved. A hard
error could be used but NULL, while more invasive, is useful when
scanning relation files in full to get a batch of results for a single
relation in one query. Tests are added for all the code paths
impacted.
Reported-by: Daria Lepikhova
Author: Michael Paquier
Discussion: https://postgr.es/m/561e187b-3549-c8d5-03f5-525c14e65bd0@postgrespro.ru
Backpatch-through: 10
2022-04-14 15:08:03 +09:00
|
|
|
|
|
|
|
-- Tests with all-zero pages.
|
|
|
|
SHOW block_size \gset
|
|
|
|
SELECT fsm_page_contents(decode(repeat('00', :block_size), 'hex'));
|
|
|
|
SELECT page_header(decode(repeat('00', :block_size), 'hex'));
|
|
|
|
SELECT page_checksum(decode(repeat('00', :block_size), 'hex'), 1);
|
2024-09-12 16:31:29 -05:00
|
|
|
|
|
|
|
-- tests for sequences
|
2024-09-13 10:16:40 -05:00
|
|
|
create sequence test_sequence start 72057594037927937;
|
2024-09-12 16:31:29 -05:00
|
|
|
select tuple_data_split('test_sequence'::regclass, t_data, t_infomask, t_infomask2, t_bits)
|
|
|
|
from heap_page_items(get_raw_page('test_sequence', 0));
|
2024-09-13 10:16:40 -05:00
|
|
|
drop sequence test_sequence;
|