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-07 20:38:14 +01:00
|
|
|
/*
|
|
|
|
* brin_internal.h
|
|
|
|
* internal declarations for BRIN indexes
|
|
|
|
*
|
|
|
|
* Portions Copyright (c) 1996-2014, PostgreSQL Global Development Group
|
|
|
|
* Portions Copyright (c) 1994, Regents of the University of California
|
|
|
|
*
|
|
|
|
* IDENTIFICATION
|
|
|
|
* src/include/access/brin_internal.h
|
|
|
|
*/
|
|
|
|
#ifndef BRIN_INTERNAL_H
|
|
|
|
#define BRIN_INTERNAL_H
|
|
|
|
|
|
|
|
#include "fmgr.h"
|
|
|
|
#include "storage/buf.h"
|
|
|
|
#include "storage/bufpage.h"
|
|
|
|
#include "storage/off.h"
|
|
|
|
#include "utils/relcache.h"
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* A BrinDesc is a struct designed to enable decoding a BRIN tuple from the
|
|
|
|
* on-disk format to an in-memory tuple and vice-versa.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* struct returned by "OpcInfo" amproc */
|
|
|
|
typedef struct BrinOpcInfo
|
|
|
|
{
|
|
|
|
/* Number of columns stored in an index column of this opclass */
|
|
|
|
uint16 oi_nstored;
|
|
|
|
|
|
|
|
/* Opaque pointer for the opclass' private use */
|
|
|
|
void *oi_opaque;
|
|
|
|
|
|
|
|
/* Type IDs of the stored columns */
|
|
|
|
Oid oi_typids[FLEXIBLE_ARRAY_MEMBER];
|
|
|
|
} BrinOpcInfo;
|
|
|
|
|
|
|
|
/* the size of a BrinOpcInfo for the given number of columns */
|
|
|
|
#define SizeofBrinOpcInfo(ncols) \
|
|
|
|
(offsetof(BrinOpcInfo, oi_typids) + sizeof(Oid) * ncols)
|
|
|
|
|
|
|
|
typedef struct BrinDesc
|
|
|
|
{
|
|
|
|
/* Containing memory context */
|
|
|
|
MemoryContext bd_context;
|
|
|
|
|
|
|
|
/* the index relation itself */
|
|
|
|
Relation bd_index;
|
|
|
|
|
|
|
|
/* tuple descriptor of the index relation */
|
|
|
|
TupleDesc bd_tupdesc;
|
|
|
|
|
|
|
|
/* cached copy for on-disk tuples; generated at first use */
|
|
|
|
TupleDesc bd_disktdesc;
|
|
|
|
|
|
|
|
/* total number of Datum entries that are stored on-disk for all columns */
|
|
|
|
int bd_totalstored;
|
|
|
|
|
|
|
|
/* per-column info; bd_tupdesc->natts entries long */
|
|
|
|
BrinOpcInfo *bd_info[FLEXIBLE_ARRAY_MEMBER];
|
|
|
|
} BrinDesc;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Globally-known function support numbers for BRIN indexes. Individual
|
|
|
|
* opclasses define their own function support numbers, which must not collide
|
|
|
|
* with the definitions here.
|
|
|
|
*/
|
|
|
|
#define BRIN_PROCNUM_OPCINFO 1
|
|
|
|
#define BRIN_PROCNUM_ADDVALUE 2
|
|
|
|
#define BRIN_PROCNUM_CONSISTENT 3
|
|
|
|
#define BRIN_PROCNUM_UNION 4
|
|
|
|
/* procedure numbers up to 10 are reserved for BRIN future expansion */
|
|
|
|
|
2014-11-08 04:31:03 +01:00
|
|
|
#undef BRIN_DEBUG
|
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-07 20:38:14 +01:00
|
|
|
|
2014-11-08 04:31:03 +01:00
|
|
|
#ifdef BRIN_DEBUG
|
|
|
|
#define BRIN_elog(args) elog args
|
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-07 20:38:14 +01:00
|
|
|
#else
|
2014-11-08 04:31:03 +01:00
|
|
|
#define BRIN_elog(args) ((void) 0)
|
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-07 20:38:14 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/* brin.c */
|
|
|
|
extern BrinDesc *brin_build_desc(Relation rel);
|
|
|
|
extern void brin_free_desc(BrinDesc *bdesc);
|
2014-12-02 20:07:54 +01:00
|
|
|
extern Datum brin_summarize_new_values(PG_FUNCTION_ARGS);
|
|
|
|
|
|
|
|
/* brin_minmax.c */
|
|
|
|
extern Datum brin_minmax_opcinfo(PG_FUNCTION_ARGS);
|
|
|
|
extern Datum brin_minmax_add_value(PG_FUNCTION_ARGS);
|
|
|
|
extern Datum brin_minmax_consistent(PG_FUNCTION_ARGS);
|
|
|
|
extern Datum brin_minmax_union(PG_FUNCTION_ARGS);
|
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-07 20:38:14 +01:00
|
|
|
|
|
|
|
#endif /* BRIN_INTERNAL_H */
|