1
0
mirror of https://github.com/postgres/postgres.git synced 2025-04-18 13:44:19 +03:00
postgres/contrib/btree_gist/btree_utils_var.h
Heikki Linnakangas e4309f73f6 Add support for sorted gist index builds to btree_gist
This enables sortsupport in the btree_gist extension for faster builds
of gist indexes.

Sorted gist index build strategy is the new default now. Regression
tests are unchanged (except for one small change in the 'enum' test to
add coverage for enum values added later) and are using the sorted
build strategy instead.

One version of this was committed a long time ago already, in commit
9f984ba6d2, but it was quickly reverted because of buildfarm
failures. The failures were presumably caused by some small bugs, but
we never got around to debug and commit it again. This patch was
written from scratch, implementing the same idea, with some fragments
and ideas from the original patch.

Author: Bernd Helmle <mailings@oopsware.de>
Author: Andrey Borodin <x4mmm@yandex-team.ru>
Discussion: https://www.postgresql.org/message-id/64d324ce2a6d535d3f0f3baeeea7b25beff82ce4.camel@oopsware.de
2025-04-03 13:46:35 +03:00

82 lines
2.4 KiB
C

/*
* contrib/btree_gist/btree_utils_var.h
*/
#ifndef __BTREE_UTILS_VAR_H__
#define __BTREE_UTILS_VAR_H__
#include "access/gist.h"
#include "btree_gist.h"
/* Variable length key */
typedef bytea GBT_VARKEY;
/* Better readable key */
typedef struct
{
bytea *lower,
*upper;
} GBT_VARKEY_R;
/*
* type description
*/
typedef struct
{
/* Attribs */
enum gbtree_type t; /* data type */
int32 eml; /* cached pg_database_encoding_max_length (0:
* undefined) */
bool trnc; /* truncate (=compress) key */
/* Methods */
bool (*f_gt) (const void *, const void *, Oid, FmgrInfo *); /* greater than */
bool (*f_ge) (const void *, const void *, Oid, FmgrInfo *); /* greater equal */
bool (*f_eq) (const void *, const void *, Oid, FmgrInfo *); /* equal */
bool (*f_le) (const void *, const void *, Oid, FmgrInfo *); /* less equal */
bool (*f_lt) (const void *, const void *, Oid, FmgrInfo *); /* less than */
int32 (*f_cmp) (const void *, const void *, Oid, FmgrInfo *); /* compare */
GBT_VARKEY *(*f_l2n) (GBT_VARKEY *, FmgrInfo *flinfo); /* convert leaf to node */
} gbtree_vinfo;
/*
* Free ptr1 in case its a copy of ptr2.
*
* This is adapted from varlena's PG_FREE_IF_COPY, though doesn't require
* fcinfo access.
*/
#define GBT_FREE_IF_COPY(ptr1, ptr2) \
do { \
if ((Pointer) (ptr1) != DatumGetPointer(ptr2)) \
pfree(ptr1); \
} while (0)
extern GBT_VARKEY_R gbt_var_key_readable(const GBT_VARKEY *k);
extern GBT_VARKEY *gbt_var_key_copy(const GBT_VARKEY_R *u);
extern GISTENTRY *gbt_var_compress(GISTENTRY *entry, const gbtree_vinfo *tinfo);
extern GBT_VARKEY *gbt_var_union(const GistEntryVector *entryvec, int32 *size,
Oid collation, const gbtree_vinfo *tinfo, FmgrInfo *flinfo);
extern bool gbt_var_same(Datum d1, Datum d2, Oid collation,
const gbtree_vinfo *tinfo, FmgrInfo *flinfo);
extern float *gbt_var_penalty(float *res, const GISTENTRY *o, const GISTENTRY *n,
Oid collation, const gbtree_vinfo *tinfo, FmgrInfo *flinfo);
extern bool gbt_var_consistent(GBT_VARKEY_R *key, const void *query,
StrategyNumber strategy, Oid collation, bool is_leaf,
const gbtree_vinfo *tinfo, FmgrInfo *flinfo);
extern GIST_SPLITVEC *gbt_var_picksplit(const GistEntryVector *entryvec, GIST_SPLITVEC *v,
Oid collation, const gbtree_vinfo *tinfo, FmgrInfo *flinfo);
extern void gbt_var_bin_union(Datum *u, GBT_VARKEY *e, Oid collation,
const gbtree_vinfo *tinfo, FmgrInfo *flinfo);
#endif