summaryrefslogtreecommitdiff
path: root/src/backend/optimizer/util/plancat.c
diff options
context:
space:
mode:
authorPeter Eisentraut2025-04-06 12:43:51 +0000
committerPeter Eisentraut2025-04-06 12:43:51 +0000
commita8025f544854ad8b865c6b4509030ee84aa8f4a0 (patch)
tree845091557eeb98a01ef6ce7ca0e26315f67e8cfc /src/backend/optimizer/util/plancat.c
parent3a1a7c5a7071c75676c15b26e242c7df17560bd1 (diff)
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 <[email protected]> Co-authored-by: Peter Eisentraut <[email protected]> Discussion: https://www.postgresql.org/message-id/flat/[email protected]
Diffstat (limited to 'src/backend/optimizer/util/plancat.c')
-rw-r--r--src/backend/optimizer/util/plancat.c38
1 files changed, 17 insertions, 21 deletions
diff --git a/src/backend/optimizer/util/plancat.c b/src/backend/optimizer/util/plancat.c
index 441684a72b1..67d879be8b8 100644
--- a/src/backend/optimizer/util/plancat.c
+++ b/src/backend/optimizer/util/plancat.c
@@ -365,14 +365,10 @@ get_relation_info(PlannerInfo *root, Oid relationObjectId, bool inhparent,
* Since "<" uniquely defines the behavior of a sort
* order, this is a sufficient test.
*
- * XXX This method is rather slow and also requires the
- * undesirable assumption that the other index AM numbers
- * its strategies the same as btree. It'd be better to
- * have a way to explicitly declare the corresponding
- * btree opfamily for each opfamily of the other index
- * type. But given the lack of current or foreseeable
- * amcanorder index types, it's not worth expending more
- * effort on now.
+ * XXX This method is rather slow and complicated. It'd
+ * be better to have a way to explicitly declare the
+ * corresponding btree opfamily for each opfamily of the
+ * other index type.
*/
info->sortopfamily = (Oid *) palloc(sizeof(Oid) * nkeycolumns);
info->reverse_sort = (bool *) palloc(sizeof(bool) * nkeycolumns);
@@ -382,27 +378,27 @@ get_relation_info(PlannerInfo *root, Oid relationObjectId, bool inhparent,
{
int16 opt = indexRelation->rd_indoption[i];
Oid ltopr;
- Oid btopfamily;
- Oid btopcintype;
- int16 btstrategy;
+ Oid opfamily;
+ Oid opcintype;
+ CompareType cmptype;
info->reverse_sort[i] = (opt & INDOPTION_DESC) != 0;
info->nulls_first[i] = (opt & INDOPTION_NULLS_FIRST) != 0;
- ltopr = get_opfamily_member(info->opfamily[i],
- info->opcintype[i],
- info->opcintype[i],
- BTLessStrategyNumber);
+ ltopr = get_opfamily_member_for_cmptype(info->opfamily[i],
+ info->opcintype[i],
+ info->opcintype[i],
+ COMPARE_LT);
if (OidIsValid(ltopr) &&
get_ordering_op_properties(ltopr,
- &btopfamily,
- &btopcintype,
- &btstrategy) &&
- btopcintype == info->opcintype[i] &&
- btstrategy == BTLessStrategyNumber)
+ &opfamily,
+ &opcintype,
+ &cmptype) &&
+ opcintype == info->opcintype[i] &&
+ cmptype == COMPARE_LT)
{
/* Successful mapping */
- info->sortopfamily[i] = btopfamily;
+ info->sortopfamily[i] = opfamily;
}
else
{