BRIN: Block Range Indexes
BRIN is a new index access method intended to accelerate scans of very
large tables, without the maintenance overhead of btrees or other
traditional indexes. They work by maintaining "summary" data about
block ranges. Bitmap index scans work by reading each summary tuple and
comparing them with the query quals; all pages in the range are returned
in a lossy TID bitmap if the quals are consistent with the values in the
summary tuple, otherwise not. Normal index scans are not supported
because these indexes do not store TIDs.
As new tuples are added into the index, the summary information is
updated (if the block range in which the tuple is added is already
summarized) or not; in the latter case, a subsequent pass of VACUUM or
the brin_summarize_new_values() function will create the summary
information.
For data types with natural 1-D sort orders, the summary info consists
of the maximum and the minimum values of each indexed column within each
page range. This type of operator class we call "Minmax", and we
supply a bunch of them for most data types with B-tree opclasses.
Since the BRIN code is generalized, other approaches are possible for
things such as arrays, geometric types, ranges, etc; even for things
such as enum types we could do something different than minmax with
better results. In this commit I only include minmax.
Catalog version bumped due to new builtin catalog entries.
There's more that could be done here, but this is a good step forwards.
Loosely based on ideas from Simon Riggs; code mostly by Álvaro Herrera,
with contribution by Heikki Linnakangas.
Patch reviewed by: Amit Kapila, Heikki Linnakangas, Robert Haas.
Testing help from Jeff Janes, Erik Rijkers, Emanuel Calvo.
PS:
The research leading to these results has received funding from the
European Union's Seventh Framework Programme (FP7/2007-2013) under
grant agreement n° 318633.
2014-11-08 03:38:14 +08:00
|
|
|
/* contrib/pageinspect/pageinspect--1.2--1.3.sql */
|
|
|
|
|
|
|
|
-- complain if script is sourced in psql, rather than via ALTER EXTENSION
|
|
|
|
\echo Use "ALTER EXTENSION pageinspect UPDATE TO '1.3'" to load this file. \quit
|
|
|
|
|
|
|
|
--
|
|
|
|
-- brin_page_type()
|
|
|
|
--
|
|
|
|
CREATE FUNCTION brin_page_type(IN page bytea)
|
|
|
|
RETURNS text
|
|
|
|
AS 'MODULE_PATHNAME', 'brin_page_type'
|
|
|
|
LANGUAGE C STRICT;
|
|
|
|
|
|
|
|
--
|
|
|
|
-- brin_metapage_info()
|
|
|
|
--
|
|
|
|
CREATE FUNCTION brin_metapage_info(IN page bytea, OUT magic text,
|
|
|
|
OUT version integer, OUT pagesperrange integer, OUT lastrevmappage bigint)
|
|
|
|
AS 'MODULE_PATHNAME', 'brin_metapage_info'
|
|
|
|
LANGUAGE C STRICT;
|
|
|
|
|
|
|
|
--
|
|
|
|
-- brin_revmap_data()
|
2014-12-02 23:20:50 +08:00
|
|
|
--
|
BRIN: Block Range Indexes
BRIN is a new index access method intended to accelerate scans of very
large tables, without the maintenance overhead of btrees or other
traditional indexes. They work by maintaining "summary" data about
block ranges. Bitmap index scans work by reading each summary tuple and
comparing them with the query quals; all pages in the range are returned
in a lossy TID bitmap if the quals are consistent with the values in the
summary tuple, otherwise not. Normal index scans are not supported
because these indexes do not store TIDs.
As new tuples are added into the index, the summary information is
updated (if the block range in which the tuple is added is already
summarized) or not; in the latter case, a subsequent pass of VACUUM or
the brin_summarize_new_values() function will create the summary
information.
For data types with natural 1-D sort orders, the summary info consists
of the maximum and the minimum values of each indexed column within each
page range. This type of operator class we call "Minmax", and we
supply a bunch of them for most data types with B-tree opclasses.
Since the BRIN code is generalized, other approaches are possible for
things such as arrays, geometric types, ranges, etc; even for things
such as enum types we could do something different than minmax with
better results. In this commit I only include minmax.
Catalog version bumped due to new builtin catalog entries.
There's more that could be done here, but this is a good step forwards.
Loosely based on ideas from Simon Riggs; code mostly by Álvaro Herrera,
with contribution by Heikki Linnakangas.
Patch reviewed by: Amit Kapila, Heikki Linnakangas, Robert Haas.
Testing help from Jeff Janes, Erik Rijkers, Emanuel Calvo.
PS:
The research leading to these results has received funding from the
European Union's Seventh Framework Programme (FP7/2007-2013) under
grant agreement n° 318633.
2014-11-08 03:38:14 +08:00
|
|
|
CREATE FUNCTION brin_revmap_data(IN page bytea,
|
|
|
|
OUT pages tid)
|
|
|
|
RETURNS SETOF tid
|
|
|
|
AS 'MODULE_PATHNAME', 'brin_revmap_data'
|
|
|
|
LANGUAGE C STRICT;
|
|
|
|
|
|
|
|
--
|
|
|
|
-- brin_page_items()
|
|
|
|
--
|
|
|
|
CREATE FUNCTION brin_page_items(IN page bytea, IN index_oid regclass,
|
|
|
|
OUT itemoffset int,
|
|
|
|
OUT blknum int,
|
|
|
|
OUT attnum int,
|
|
|
|
OUT allnulls bool,
|
|
|
|
OUT hasnulls bool,
|
|
|
|
OUT placeholder bool,
|
|
|
|
OUT value text)
|
|
|
|
RETURNS SETOF record
|
|
|
|
AS 'MODULE_PATHNAME', 'brin_page_items'
|
|
|
|
LANGUAGE C STRICT;
|
2014-11-21 17:46:50 +08:00
|
|
|
|
|
|
|
--
|
|
|
|
-- gin_metapage_info()
|
|
|
|
--
|
|
|
|
CREATE FUNCTION gin_metapage_info(IN page bytea,
|
|
|
|
OUT pending_head bigint,
|
|
|
|
OUT pending_tail bigint,
|
|
|
|
OUT tail_free_size int4,
|
|
|
|
OUT n_pending_pages bigint,
|
|
|
|
OUT n_pending_tuples bigint,
|
|
|
|
OUT n_total_pages bigint,
|
|
|
|
OUT n_entry_pages bigint,
|
|
|
|
OUT n_data_pages bigint,
|
|
|
|
OUT n_entries bigint,
|
|
|
|
OUT version int4)
|
|
|
|
AS 'MODULE_PATHNAME', 'gin_metapage_info'
|
|
|
|
LANGUAGE C STRICT;
|
|
|
|
|
|
|
|
--
|
|
|
|
-- gin_page_opaque_info()
|
|
|
|
--
|
|
|
|
CREATE FUNCTION gin_page_opaque_info(IN page bytea,
|
|
|
|
OUT rightlink bigint,
|
|
|
|
OUT maxoff int4,
|
|
|
|
OUT flags text[])
|
|
|
|
AS 'MODULE_PATHNAME', 'gin_page_opaque_info'
|
|
|
|
LANGUAGE C STRICT;
|
|
|
|
|
|
|
|
--
|
|
|
|
-- gin_leafpage_items()
|
|
|
|
--
|
|
|
|
CREATE FUNCTION gin_leafpage_items(IN page bytea,
|
|
|
|
OUT first_tid tid,
|
|
|
|
OUT nbytes int2,
|
|
|
|
OUT tids tid[])
|
|
|
|
RETURNS SETOF record
|
|
|
|
AS 'MODULE_PATHNAME', 'gin_leafpage_items'
|
|
|
|
LANGUAGE C STRICT;
|