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

Function cdb_make_distkey_for_expr

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

* cdb_make_distkey_for_expr * Returns a DistributionKey which represents an equivalence class of * expressions that must be equal to the given expression. * * The 'opfamily' argument specifies a hash operator family, which * determines the hash function used. The = operator for the expression's * datatype is used to look up a compatible btree operator family, which * is recorded

Source from the content-addressed store, hash-verified

1445 * distribution key.
1446 */
1447DistributionKey *
1448cdb_make_distkey_for_expr(PlannerInfo *root,
1449 RelOptInfo *rel,
1450 Node *expr,
1451 Oid opfamily /* hash opfamily */,
1452 int sortref)
1453{
1454 Oid typeoid;
1455 Oid eqopoid;
1456 DistributionKey *dk;
1457 List *mergeopfamilies;
1458 EquivalenceClass *eclass;
1459 Oid lefttype;
1460 Oid righttype;
1461
1462 Assert(OidIsValid(opfamily));
1463
1464 /* Get the expr's data type. */
1465 typeoid = exprType(expr);
1466
1467 /* If it's a domain, look at the base type instead */
1468 typeoid = getBaseType(typeoid);
1469
1470 eqopoid = cdb_eqop_in_hash_opfamily(opfamily, typeoid);
1471
1472 /*
1473 * Get Oid of the sort operator that would be used for a sort-merge
1474 * equijoin on a pair of exprs of the same type.
1475 */
1476 if (!op_mergejoinable(eqopoid, typeoid))
1477 elog(ERROR, "could not find mergejoinable = operator for type %u", typeoid);
1478
1479 mergeopfamilies = get_mergejoin_opfamilies(eqopoid);
1480
1481 /*
1482 * Get the equality operator's operand type. It might be different from the
1483 * original datatype, if the datatype itself doesn't have an equivalence
1484 * operator, but relies on casts. For example with two varchars, "a = b" uses
1485 * the text equals operator, i.e. "a::text = b::text".
1486 */
1487 op_input_types(eqopoid, &lefttype, &righttype);
1488 Assert(lefttype == righttype);
1489
1490 /* If this type is a domain type, get its base type. */
1491 if (get_typtype(lefttype) == 'd')
1492 lefttype = getBaseType(lefttype);
1493
1494 /*
1495 * It should be OK to set nullable_relids = NULL, since this eclass is only
1496 * used for DistributionKey, so it would not participate in qual deduction.
1497 */
1498 eclass = get_eclass_for_sort_expr(root, (Expr *) expr,
1499 NULL,
1500 mergeopfamilies,
1501 lefttype,
1502 exprCollation(expr),
1503 sortref,
1504 rel->relids,

Callers 1

cdbpathlocus_from_exprsFunction · 0.85

Calls 9

exprTypeFunction · 0.85
getBaseTypeFunction · 0.85
op_mergejoinableFunction · 0.85
get_mergejoin_opfamiliesFunction · 0.85
op_input_typesFunction · 0.85
get_typtypeFunction · 0.85
get_eclass_for_sort_exprFunction · 0.85
exprCollationFunction · 0.85

Tested by

no test coverage detected