MCPcopy Create free account
hub / github.com/apache/cloudberry / make_pathkey_from_sortinfo

Function make_pathkey_from_sortinfo

src/backend/optimizer/path/pathkeys.c:505–555  ·  view source on GitHub ↗

* make_pathkey_from_sortinfo * Given an expression and sort-order information, create a PathKey. * The result is always a "canonical" PathKey, but it might be redundant. * * expr is the expression, and nullable_relids is the set of base relids * that are potentially nullable below it. * * If the PathKey is being generated from a SortGroupClause, sortref should be * the SortGroupClause'

Source from the content-addressed store, hash-verified

503 * sort key isn't already present in any EquivalenceClass.
504 */
505static PathKey *
506make_pathkey_from_sortinfo(PlannerInfo *root,
507 Expr *expr,
508 Relids nullable_relids,
509 Oid opfamily,
510 Oid opcintype,
511 Oid collation,
512 bool reverse_sort,
513 bool nulls_first,
514 Index sortref,
515 Relids rel,
516 bool create_it)
517{
518 int16 strategy;
519 Oid equality_op;
520 List *opfamilies;
521 EquivalenceClass *eclass;
522
523 strategy = reverse_sort ? BTGreaterStrategyNumber : BTLessStrategyNumber;
524
525 /*
526 * EquivalenceClasses need to contain opfamily lists based on the family
527 * membership of mergejoinable equality operators, which could belong to
528 * more than one opfamily. So we have to look up the opfamily's equality
529 * operator and get its membership.
530 */
531 equality_op = get_opfamily_member(opfamily,
532 opcintype,
533 opcintype,
534 BTEqualStrategyNumber);
535 if (!OidIsValid(equality_op)) /* shouldn't happen */
536 elog(ERROR, "missing operator %d(%u,%u) in opfamily %u",
537 BTEqualStrategyNumber, opcintype, opcintype, opfamily);
538 opfamilies = get_mergejoin_opfamilies(equality_op);
539 if (!opfamilies) /* certainly should find some */
540 elog(ERROR, "could not find opfamilies for equality operator %u",
541 equality_op);
542
543 /* Now find or (optionally) create a matching EquivalenceClass */
544 eclass = get_eclass_for_sort_expr(root, expr, nullable_relids,
545 opfamilies, opcintype, collation,
546 sortref, rel, create_it);
547
548 /* Fail if no EC and !create_it */
549 if (!eclass)
550 return NULL;
551
552 /* And finally we can find or create a PathKey node */
553 return make_canonical_pathkey(root, eclass, opfamily,
554 strategy, nulls_first);
555}
556
557/*
558 * make_pathkey_from_sortop

Callers 4

make_pathkey_from_sortopFunction · 0.85
build_index_pathkeysFunction · 0.85
build_partition_pathkeysFunction · 0.85
build_expression_pathkeyFunction · 0.85

Calls 4

get_opfamily_memberFunction · 0.85
get_mergejoin_opfamiliesFunction · 0.85
get_eclass_for_sort_exprFunction · 0.85
make_canonical_pathkeyFunction · 0.85

Tested by

no test coverage detected