mirror of
https://github.com/postgres/postgres.git
synced 2026-04-04 08:45:52 -04:00
PostgreSQL provides set of template index access methods, where opclasses have much freedom in the semantics of indexing. These index AMs are GiST, GIN, SP-GiST and BRIN. There opclasses define representation of keys, operations on them and supported search strategies. So, it's natural that opclasses may be faced some tradeoffs, which require user-side decision. This commit implements opclass parameters allowing users to set some values, which tell opclass how to index the particular dataset. This commit doesn't introduce new storage in system catalog. Instead it uses pg_attribute.attoptions, which is used for table column storage options but unused for index attributes. In order to evade changing signature of each opclass support function, we implement unified way to pass options to opclass support functions. Options are set to fn_expr as the constant bytea expression. It's possible due to the fact that opclass support functions are executed outside of expressions, so fn_expr is unused for them. This commit comes with some examples of opclass options usage. We parametrize signature length in GiST. That applies to multiple opclasses: tsvector_ops, gist__intbig_ops, gist_ltree_ops, gist__ltree_ops, gist_trgm_ops and gist_hstore_ops. Also we parametrize maximum number of integer ranges for gist__int_ops. However, the main future usage of this feature is expected to be json, where users would be able to specify which way to index particular json parts. Catversion is bumped. Discussion: https://postgr.es/m/d22c3a18-31c7-1879-fc11-4c1ce2f5e5af%40postgrespro.ru Author: Nikita Glukhov, revised by me Reviwed-by: Nikolay Shaplov, Robert Haas, Tom Lane, Tomas Vondra, Alvaro Herrera
111 lines
3.4 KiB
C
111 lines
3.4 KiB
C
/*
|
|
* brin_internal.h
|
|
* internal declarations for BRIN indexes
|
|
*
|
|
* Portions Copyright (c) 1996-2020, 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 "access/amapi.h"
|
|
#include "storage/bufpage.h"
|
|
#include "utils/typcache.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 cache entries of the stored columns */
|
|
TypeCacheEntry *oi_typcache[FLEXIBLE_ARRAY_MEMBER];
|
|
} BrinOpcInfo;
|
|
|
|
/* the size of a BrinOpcInfo for the given number of columns */
|
|
#define SizeofBrinOpcInfo(ncols) \
|
|
(offsetof(BrinOpcInfo, oi_typcache) + sizeof(TypeCacheEntry *) * 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 can define more function support numbers, which must fall into
|
|
* BRIN_FIRST_OPTIONAL_PROCNUM .. BRIN_LAST_OPTIONAL_PROCNUM.
|
|
*/
|
|
#define BRIN_PROCNUM_OPCINFO 1
|
|
#define BRIN_PROCNUM_ADDVALUE 2
|
|
#define BRIN_PROCNUM_CONSISTENT 3
|
|
#define BRIN_PROCNUM_UNION 4
|
|
#define BRIN_MANDATORY_NPROCS 4
|
|
#define BRIN_PROCNUM_OPTIONS 5 /* optional */
|
|
/* procedure numbers up to 10 are reserved for BRIN future expansion */
|
|
#define BRIN_FIRST_OPTIONAL_PROCNUM 11
|
|
#define BRIN_LAST_OPTIONAL_PROCNUM 15
|
|
|
|
#undef BRIN_DEBUG
|
|
|
|
#ifdef BRIN_DEBUG
|
|
#define BRIN_elog(args) elog args
|
|
#else
|
|
#define BRIN_elog(args) ((void) 0)
|
|
#endif
|
|
|
|
/* brin.c */
|
|
extern BrinDesc *brin_build_desc(Relation rel);
|
|
extern void brin_free_desc(BrinDesc *bdesc);
|
|
extern IndexBuildResult *brinbuild(Relation heap, Relation index,
|
|
struct IndexInfo *indexInfo);
|
|
extern void brinbuildempty(Relation index);
|
|
extern bool brininsert(Relation idxRel, Datum *values, bool *nulls,
|
|
ItemPointer heaptid, Relation heapRel,
|
|
IndexUniqueCheck checkUnique,
|
|
struct IndexInfo *indexInfo);
|
|
extern IndexScanDesc brinbeginscan(Relation r, int nkeys, int norderbys);
|
|
extern int64 bringetbitmap(IndexScanDesc scan, TIDBitmap *tbm);
|
|
extern void brinrescan(IndexScanDesc scan, ScanKey scankey, int nscankeys,
|
|
ScanKey orderbys, int norderbys);
|
|
extern void brinendscan(IndexScanDesc scan);
|
|
extern IndexBulkDeleteResult *brinbulkdelete(IndexVacuumInfo *info,
|
|
IndexBulkDeleteResult *stats,
|
|
IndexBulkDeleteCallback callback,
|
|
void *callback_state);
|
|
extern IndexBulkDeleteResult *brinvacuumcleanup(IndexVacuumInfo *info,
|
|
IndexBulkDeleteResult *stats);
|
|
extern bytea *brinoptions(Datum reloptions, bool validate);
|
|
|
|
/* brin_validate.c */
|
|
extern bool brinvalidate(Oid opclassoid);
|
|
|
|
#endif /* BRIN_INTERNAL_H */
|