1
0
mirror of https://github.com/postgres/postgres.git synced 2025-06-27 23:21:58 +03:00

Relax ordering-related hardcoded btree requirements in planning

There were several places in ordering-related planning where a
requirement for btree was hardcoded but an amcanorder index could
suffice.  This fixes that.  We just need to do the necessary mapping
between strategy numbers and compare types and adjust some related
APIs so that this works independent of btree strategy numbers.  For
instance, non-btree amcanorder indexes can now be used to support
sorting and merge joins.  Also, predtest.c works independent of btree
strategy numbers now.

To avoid performance regressions, some details on btree and other
built-in index types are still hardcoded as shortcuts, but other index
types now have access to the same features by providing the required
flags and callbacks.

Author: Mark Dilger <mark.dilger@enterprisedb.com>
Co-authored-by: Peter Eisentraut <peter@eisentraut.org>
Discussion: https://www.postgresql.org/message-id/flat/E72EAA49-354D-4C2E-8EB9-255197F55330@enterprisedb.com
This commit is contained in:
Peter Eisentraut
2025-04-06 14:43:51 +02:00
parent 3a1a7c5a70
commit a8025f5448
16 changed files with 298 additions and 226 deletions

View File

@ -2832,7 +2832,7 @@ make_row_comparison_op(ParseState *pstate, List *opname,
ListCell *l,
*r;
List **opinfo_lists;
Bitmapset *strats;
Bitmapset *cmptypes;
int nopers;
int i;
@ -2897,45 +2897,45 @@ make_row_comparison_op(ParseState *pstate, List *opname,
/*
* Now we must determine which row comparison semantics (= <> < <= > >=)
* apply to this set of operators. We look for btree opfamilies
* containing the operators, and see which interpretations (strategy
* numbers) exist for each operator.
* apply to this set of operators. We look for opfamilies containing the
* operators, and see which interpretations (cmptypes) exist for each
* operator.
*/
opinfo_lists = (List **) palloc(nopers * sizeof(List *));
strats = NULL;
cmptypes = NULL;
i = 0;
foreach(l, opexprs)
{
Oid opno = ((OpExpr *) lfirst(l))->opno;
Bitmapset *this_strats;
Bitmapset *this_cmptypes;
ListCell *j;
opinfo_lists[i] = get_op_btree_interpretation(opno);
opinfo_lists[i] = get_op_index_interpretation(opno);
/*
* convert strategy numbers into a Bitmapset to make the intersection
* convert comparison types into a Bitmapset to make the intersection
* calculation easy.
*/
this_strats = NULL;
this_cmptypes = NULL;
foreach(j, opinfo_lists[i])
{
OpBtreeInterpretation *opinfo = lfirst(j);
OpIndexInterpretation *opinfo = lfirst(j);
this_strats = bms_add_member(this_strats, opinfo->strategy);
this_cmptypes = bms_add_member(this_cmptypes, opinfo->cmptype);
}
if (i == 0)
strats = this_strats;
cmptypes = this_cmptypes;
else
strats = bms_int_members(strats, this_strats);
cmptypes = bms_int_members(cmptypes, this_cmptypes);
i++;
}
/*
* If there are multiple common interpretations, we may use any one of
* them ... this coding arbitrarily picks the lowest btree strategy
* them ... this coding arbitrarily picks the lowest comparison type
* number.
*/
i = bms_next_member(strats, -1);
i = bms_next_member(cmptypes, -1);
if (i < 0)
{
/* No common interpretation, so fail */
@ -2969,9 +2969,9 @@ make_row_comparison_op(ParseState *pstate, List *opname,
foreach(j, opinfo_lists[i])
{
OpBtreeInterpretation *opinfo = lfirst(j);
OpIndexInterpretation *opinfo = lfirst(j);
if (opinfo->strategy == cmptype)
if (opinfo->cmptype == cmptype)
{
opfamily = opinfo->opfamily_id;
break;