mirror of
https://github.com/postgres/postgres.git
synced 2025-06-22 02:52:08 +03:00
Implement operator class parameters
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
This commit is contained in:
@ -90,6 +90,7 @@ static void RangeVarCallbackForReindexIndex(const RangeVar *relation,
|
||||
static bool ReindexRelationConcurrently(Oid relationOid, int options);
|
||||
static void ReindexPartitionedIndex(Relation parentIdx);
|
||||
static void update_relispartition(Oid relationId, bool newval);
|
||||
static bool CompareOpclassOptions(Datum *opts1, Datum *opts2, int natts);
|
||||
|
||||
/*
|
||||
* callback argument type for RangeVarCallbackForReindexIndex()
|
||||
@ -268,6 +269,18 @@ CheckIndexCompatible(Oid oldId,
|
||||
}
|
||||
}
|
||||
|
||||
/* Any change in opclass options break compatibility. */
|
||||
if (ret)
|
||||
{
|
||||
Datum *opclassOptions = RelationGetIndexRawAttOptions(irel);
|
||||
|
||||
ret = CompareOpclassOptions(opclassOptions,
|
||||
indexInfo->ii_OpclassOptions, old_natts);
|
||||
|
||||
if (opclassOptions)
|
||||
pfree(opclassOptions);
|
||||
}
|
||||
|
||||
/* Any change in exclusion operator selections breaks compatibility. */
|
||||
if (ret && indexInfo->ii_ExclusionOps != NULL)
|
||||
{
|
||||
@ -302,6 +315,42 @@ CheckIndexCompatible(Oid oldId,
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*
|
||||
* CompareOpclassOptions
|
||||
*
|
||||
* Compare per-column opclass options which are represented by arrays of text[]
|
||||
* datums. Both elements of arrays and array themselves can be NULL.
|
||||
*/
|
||||
static bool
|
||||
CompareOpclassOptions(Datum *opts1, Datum *opts2, int natts)
|
||||
{
|
||||
int i;
|
||||
|
||||
if (!opts1 && !opts2)
|
||||
return true;
|
||||
|
||||
for (i = 0; i < natts; i++)
|
||||
{
|
||||
Datum opt1 = opts1 ? opts1[i] : (Datum) 0;
|
||||
Datum opt2 = opts2 ? opts2[i] : (Datum) 0;
|
||||
|
||||
if (opt1 == (Datum) 0)
|
||||
{
|
||||
if (opt2 == (Datum) 0)
|
||||
continue;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
else if (opt2 == (Datum) 0)
|
||||
return false;
|
||||
|
||||
/* Compare non-NULL text[] datums. */
|
||||
if (!DatumGetBool(DirectFunctionCall2(array_eq, opt1, opt2)))
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
* WaitForOlderSnapshots
|
||||
@ -1528,7 +1577,7 @@ CheckPredicate(Expr *predicate)
|
||||
|
||||
/*
|
||||
* Compute per-index-column information, including indexed column numbers
|
||||
* or index expressions, opclasses, and indoptions. Note, all output vectors
|
||||
* or index expressions, opclasses and their options. Note, all output vectors
|
||||
* should be allocated for all columns, including "including" ones.
|
||||
*/
|
||||
static void
|
||||
@ -1829,6 +1878,20 @@ ComputeIndexAttrs(IndexInfo *indexInfo,
|
||||
accessMethodName)));
|
||||
}
|
||||
|
||||
/* Set up the per-column opclass options (attoptions field). */
|
||||
if (attribute->opclassopts)
|
||||
{
|
||||
Assert(attn < nkeycols);
|
||||
|
||||
if (!indexInfo->ii_OpclassOptions)
|
||||
indexInfo->ii_OpclassOptions =
|
||||
palloc0(sizeof(Datum) * indexInfo->ii_NumIndexAttrs);
|
||||
|
||||
indexInfo->ii_OpclassOptions[attn] =
|
||||
transformRelOptions((Datum) 0, attribute->opclassopts,
|
||||
NULL, NULL, false, false);
|
||||
}
|
||||
|
||||
attn++;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user