/* * get_proposed_default_constraint * * This function returns the negation of new_part_constraints, which * would be an integral part of the default partition constraints after * addition of the partition to which the new_part_constraints belongs. */ List * get_proposed_default_constraint(List *new_part_constraints) { Expr *defPartConstraint; defPartConstraint = make_ands_explicit(new_part_constraints); /* * Derive the partition constraints of default partition by negating the * given partition constraints. The partition constraint never evaluates * to NULL, so negating it like this is safe. */ defPartConstraint = makeBoolExpr(NOT_EXPR, list_make1(defPartConstraint), -1); /* Simplify, to put the negated expression into canonical form */ defPartConstraint = (Expr *) eval_const_expressions(NULL, (Node *) defPartConstraint); defPartConstraint = canonicalize_qual(defPartConstraint, true); return make_ands_implicit(defPartConstraint); }
Datum gp_get_physical_index_relid(PG_FUNCTION_ARGS) { Oid rootOid = PG_GETARG_OID(0); Oid partOid = PG_GETARG_OID(1); LogicalIndexInfo logicalIndexInfo; Oid resultOid; int2vector *indexKeys; text *inText; Relation rel; logicalIndexInfo.nColumns = 0; logicalIndexInfo.indexKeys = NULL; logicalIndexInfo.indPred = NIL; logicalIndexInfo.indExprs = NIL; if (!PG_ARGISNULL(2)) { indexKeys = (int2vector *)PG_GETARG_POINTER(2); logicalIndexInfo.nColumns = indexKeys->dim1; logicalIndexInfo.indexKeys = (AttrNumber *)palloc0(indexKeys->dim1 * sizeof(AttrNumber)); for (int i = 0; i < indexKeys->dim1; i++) logicalIndexInfo.indexKeys[i] = indexKeys->values[i]; } if (!PG_ARGISNULL(3)) { Node *indPred; inText = PG_GETARG_TEXT_P(3); indPred = stringToNode(text_to_cstring(inText)); /* Perform the same normalization as relcache.c does. */ indPred = eval_const_expressions(NULL, indPred); indPred = (Node *) canonicalize_qual((Expr *) indPred); set_coercionform_dontcare(indPred); indPred = (Node *) make_ands_implicit((Expr *) indPred); fix_opfuncids(indPred); logicalIndexInfo.indPred = (List *) indPred; } if (!PG_ARGISNULL(4)) { Node *indExprs; inText = PG_GETARG_TEXT_P(4); indExprs = stringToNode(text_to_cstring(inText)); /* Perform the same normalization as relcache.c does. */ indExprs = eval_const_expressions(NULL, indExprs); set_coercionform_dontcare(indExprs); fix_opfuncids(indExprs); logicalIndexInfo.indExprs = (List *) indExprs; } logicalIndexInfo.indIsUnique = PG_GETARG_BOOL(5); AttrNumber *attMap = IndexScan_GetColumnMapping(rootOid, partOid); rel = heap_open(partOid, AccessShareLock); /* * The varno is hard-coded to 1 as the original getPhysicalIndexRelid was * using a hard-coded 1 for varattno mapping of logicalIndexInfo. */ IndexScan_MapLogicalIndexInfo(&logicalIndexInfo, attMap, 1); /* do the actual work */ resultOid = getPhysicalIndexRelid(rel, &logicalIndexInfo); if (attMap) { pfree(attMap); } heap_close(rel, AccessShareLock); return ObjectIdGetDatum(resultOid); }