2016-11-01 17:00:00 +01:00
|
|
|
CREATE TABLE test1 (a int8, b text);
|
|
|
|
INSERT INTO test1 VALUES (72057594037927937, 'text');
|
2016-09-29 18:00:00 +02:00
|
|
|
CREATE INDEX test1_a_idx ON test1 USING btree (a);
|
|
|
|
\x
|
|
|
|
SELECT * FROM bt_metap('test1_a_idx');
|
Skip full index scan during cleanup of B-tree indexes when possible
Vacuum of index consists from two stages: multiple (zero of more) ambulkdelete
calls and one amvacuumcleanup call. When workload on particular table
is append-only, then autovacuum isn't intended to touch this table. However,
user may run vacuum manually in order to fill visibility map and get benefits
of index-only scans. Then ambulkdelete wouldn't be called for indexes
of such table (because no heap tuples were deleted), only amvacuumcleanup would
be called In this case, amvacuumcleanup would perform full index scan for
two objectives: put recyclable pages into free space map and update index
statistics.
This patch allows btvacuumclanup to skip full index scan when two conditions
are satisfied: no pages are going to be put into free space map and index
statistics isn't stalled. In order to check first condition, we store
oldest btpo_xact in the meta-page. When it's precedes RecentGlobalXmin, then
there are some recyclable pages. In order to check second condition we store
number of heap tuples observed during previous full index scan by cleanup.
If fraction of newly inserted tuples is less than
vacuum_cleanup_index_scale_factor, then statistics isn't considered to be
stalled. vacuum_cleanup_index_scale_factor can be defined as both reloption and GUC (default).
This patch bumps B-tree meta-page version. Upgrade of meta-page is performed
"on the fly": during VACUUM meta-page is rewritten with new version. No special
handling in pg_upgrade is required.
Author: Masahiko Sawada, Alexander Korotkov
Review by: Peter Geoghegan, Kyotaro Horiguchi, Alexander Korotkov, Yura Sokolov
Discussion: https://www.postgresql.org/message-id/flat/CAD21AoAX+d2oD_nrd9O2YkpzHaFr=uQeGr9s1rKC3O4ENc568g@mail.gmail.com
2018-04-04 18:29:00 +02:00
|
|
|
-[ RECORD 1 ]-----------+-------
|
|
|
|
magic | 340322
|
Make heap TID a tiebreaker nbtree index column.
Make nbtree treat all index tuples as having a heap TID attribute.
Index searches can distinguish duplicates by heap TID, since heap TID is
always guaranteed to be unique. This general approach has numerous
benefits for performance, and is prerequisite to teaching VACUUM to
perform "retail index tuple deletion".
Naively adding a new attribute to every pivot tuple has unacceptable
overhead (it bloats internal pages), so suffix truncation of pivot
tuples is added. This will usually truncate away the "extra" heap TID
attribute from pivot tuples during a leaf page split, and may also
truncate away additional user attributes. This can increase fan-out,
especially in a multi-column index. Truncation can only occur at the
attribute granularity, which isn't particularly effective, but works
well enough for now. A future patch may add support for truncating
"within" text attributes by generating truncated key values using new
opclass infrastructure.
Only new indexes (BTREE_VERSION 4 indexes) will have insertions that
treat heap TID as a tiebreaker attribute, or will have pivot tuples
undergo suffix truncation during a leaf page split (on-disk
compatibility with versions 2 and 3 is preserved). Upgrades to version
4 cannot be performed on-the-fly, unlike upgrades from version 2 to
version 3. contrib/amcheck continues to work with version 2 and 3
indexes, while also enforcing stricter invariants when verifying version
4 indexes. These stricter invariants are the same invariants described
by "3.1.12 Sequencing" from the Lehman and Yao paper.
A later patch will enhance the logic used by nbtree to pick a split
point. This patch is likely to negatively impact performance without
smarter choices around the precise point to split leaf pages at. Making
these two mostly-distinct sets of enhancements into distinct commits
seems like it might clarify their design, even though neither commit is
particularly useful on its own.
The maximum allowed size of new tuples is reduced by an amount equal to
the space required to store an extra MAXALIGN()'d TID in a new high key
during leaf page splits. The user-facing definition of the "1/3 of a
page" restriction is already imprecise, and so does not need to be
revised. However, there should be a compatibility note in the v12
release notes.
Author: Peter Geoghegan
Reviewed-By: Heikki Linnakangas, Alexander Korotkov
Discussion: https://postgr.es/m/CAH2-WzkVb0Kom=R+88fDFb=JSxZMFvbHVC6Mn9LJ2n=X=kS-Uw@mail.gmail.com
2019-03-20 18:04:01 +01:00
|
|
|
version | 4
|
Skip full index scan during cleanup of B-tree indexes when possible
Vacuum of index consists from two stages: multiple (zero of more) ambulkdelete
calls and one amvacuumcleanup call. When workload on particular table
is append-only, then autovacuum isn't intended to touch this table. However,
user may run vacuum manually in order to fill visibility map and get benefits
of index-only scans. Then ambulkdelete wouldn't be called for indexes
of such table (because no heap tuples were deleted), only amvacuumcleanup would
be called In this case, amvacuumcleanup would perform full index scan for
two objectives: put recyclable pages into free space map and update index
statistics.
This patch allows btvacuumclanup to skip full index scan when two conditions
are satisfied: no pages are going to be put into free space map and index
statistics isn't stalled. In order to check first condition, we store
oldest btpo_xact in the meta-page. When it's precedes RecentGlobalXmin, then
there are some recyclable pages. In order to check second condition we store
number of heap tuples observed during previous full index scan by cleanup.
If fraction of newly inserted tuples is less than
vacuum_cleanup_index_scale_factor, then statistics isn't considered to be
stalled. vacuum_cleanup_index_scale_factor can be defined as both reloption and GUC (default).
This patch bumps B-tree meta-page version. Upgrade of meta-page is performed
"on the fly": during VACUUM meta-page is rewritten with new version. No special
handling in pg_upgrade is required.
Author: Masahiko Sawada, Alexander Korotkov
Review by: Peter Geoghegan, Kyotaro Horiguchi, Alexander Korotkov, Yura Sokolov
Discussion: https://www.postgresql.org/message-id/flat/CAD21AoAX+d2oD_nrd9O2YkpzHaFr=uQeGr9s1rKC3O4ENc568g@mail.gmail.com
2018-04-04 18:29:00 +02:00
|
|
|
root | 1
|
|
|
|
level | 0
|
|
|
|
fastroot | 1
|
|
|
|
fastlevel | 0
|
|
|
|
oldest_xact | 0
|
|
|
|
last_cleanup_num_tuples | -1
|
2020-02-29 21:10:17 +01:00
|
|
|
allequalimage | t
|
2016-09-29 18:00:00 +02:00
|
|
|
|
|
|
|
SELECT * FROM bt_page_stats('test1_a_idx', 0);
|
|
|
|
ERROR: block 0 is a meta page
|
|
|
|
SELECT * FROM bt_page_stats('test1_a_idx', 1);
|
|
|
|
-[ RECORD 1 ]-+-----
|
|
|
|
blkno | 1
|
|
|
|
type | l
|
|
|
|
live_items | 1
|
|
|
|
dead_items | 0
|
|
|
|
avg_item_size | 16
|
|
|
|
page_size | 8192
|
|
|
|
free_size | 8128
|
|
|
|
btpo_prev | 0
|
|
|
|
btpo_next | 0
|
|
|
|
btpo | 0
|
|
|
|
btpo_flags | 3
|
|
|
|
|
|
|
|
SELECT * FROM bt_page_stats('test1_a_idx', 2);
|
|
|
|
ERROR: block number out of range
|
|
|
|
SELECT * FROM bt_page_items('test1_a_idx', 0);
|
|
|
|
ERROR: block 0 is a meta page
|
|
|
|
SELECT * FROM bt_page_items('test1_a_idx', 1);
|
|
|
|
-[ RECORD 1 ]-----------------------
|
|
|
|
itemoffset | 1
|
|
|
|
ctid | (0,1)
|
|
|
|
itemlen | 16
|
|
|
|
nulls | f
|
|
|
|
vars | f
|
2016-11-01 17:00:00 +01:00
|
|
|
data | 01 00 00 00 00 00 00 01
|
2020-02-29 21:10:17 +01:00
|
|
|
dead | f
|
|
|
|
htid | (0,1)
|
|
|
|
tids |
|
2016-09-29 18:00:00 +02:00
|
|
|
|
|
|
|
SELECT * FROM bt_page_items('test1_a_idx', 2);
|
|
|
|
ERROR: block number out of range
|
2017-04-05 05:48:49 +02:00
|
|
|
SELECT * FROM bt_page_items(get_raw_page('test1_a_idx', 0));
|
|
|
|
ERROR: block is a meta page
|
|
|
|
SELECT * FROM bt_page_items(get_raw_page('test1_a_idx', 1));
|
|
|
|
-[ RECORD 1 ]-----------------------
|
|
|
|
itemoffset | 1
|
|
|
|
ctid | (0,1)
|
|
|
|
itemlen | 16
|
|
|
|
nulls | f
|
|
|
|
vars | f
|
|
|
|
data | 01 00 00 00 00 00 00 01
|
2020-02-29 21:10:17 +01:00
|
|
|
dead | f
|
|
|
|
htid | (0,1)
|
|
|
|
tids |
|
2017-04-05 05:48:49 +02:00
|
|
|
|
|
|
|
SELECT * FROM bt_page_items(get_raw_page('test1_a_idx', 2));
|
|
|
|
ERROR: block number 2 is out of range for relation "test1_a_idx"
|
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 03:20:51 +01:00
|
|
|
-- Failure when using a non-btree index.
|
|
|
|
CREATE INDEX test1_a_hash ON test1 USING hash(a);
|
|
|
|
SELECT bt_metap('test1_a_hash');
|
|
|
|
ERROR: "test1_a_hash" is not a btree index
|
|
|
|
SELECT bt_page_stats('test1_a_hash', 0);
|
|
|
|
ERROR: "test1_a_hash" is not a btree index
|
|
|
|
SELECT bt_page_items('test1_a_hash', 0);
|
|
|
|
ERROR: "test1_a_hash" is not a btree index
|
|
|
|
-- Failure with incorrect page size
|
|
|
|
-- Suppress the DETAIL message, to allow the tests to work across various
|
|
|
|
-- page sizes.
|
|
|
|
\set VERBOSITY terse
|
|
|
|
SELECT bt_page_items('aaa'::bytea);
|
|
|
|
ERROR: invalid page size
|
|
|
|
\set VERBOSITY default
|
2016-09-29 18:00:00 +02:00
|
|
|
DROP TABLE test1;
|