/* * prune_using_either_value returns the shards for the specified distributed * table after pruning using either of two values provided by the caller (OR). */ Datum prune_using_either_value(PG_FUNCTION_ARGS) { Oid distributedTableId = PG_GETARG_OID(0); text *firstValue = PG_GETARG_TEXT_P(1); text *secondValue = PG_GETARG_TEXT_P(2); Expr *firstQual = MakeTextPartitionExpression(distributedTableId, firstValue); Expr *secondQual = MakeTextPartitionExpression(distributedTableId, secondValue); Expr *orClause = make_orclause(list_make2(firstQual, secondQual)); List *whereClauseList = list_make1(orClause); ArrayType *shardIdArrayType = PrunedShardIdsForTable(distributedTableId, whereClauseList); PG_RETURN_ARRAYTYPE_P(shardIdArrayType); }
/* * Recursively insert sub-RestrictInfo nodes into a boolean expression. * * We put RestrictInfos above simple (non-AND/OR) clauses and above * sub-OR clauses, but not above sub-AND clauses, because there's no need. * This may seem odd but it is closely related to the fact that we use * implicit-AND lists at top level of RestrictInfo lists. Only ORs and * simple clauses are valid RestrictInfos. * * The same is_pushed_down, outerjoin_delayed, and pseudoconstant flag * values can be applied to all RestrictInfo nodes in the result. Likewise * for security_level, outer_relids, and nullable_relids. * * The given required_relids are attached to our top-level output, * but any OR-clause constituents are allowed to default to just the * contained rels. */ static Expr * make_sub_restrictinfos(Expr *clause, bool is_pushed_down, bool outerjoin_delayed, bool pseudoconstant, Index security_level, Relids required_relids, Relids outer_relids, Relids nullable_relids) { if (or_clause((Node *) clause)) { List *orlist = NIL; ListCell *temp; foreach(temp, ((BoolExpr *) clause)->args) orlist = lappend(orlist, make_sub_restrictinfos(lfirst(temp), is_pushed_down, outerjoin_delayed, pseudoconstant, security_level, NULL, outer_relids, nullable_relids)); return (Expr *) make_restrictinfo_internal(clause, make_orclause(orlist), is_pushed_down, outerjoin_delayed, pseudoconstant, security_level, required_relids, outer_relids, nullable_relids); } else if (and_clause((Node *) clause)) { List *andlist = NIL; ListCell *temp; foreach(temp, ((BoolExpr *) clause)->args) andlist = lappend(andlist, make_sub_restrictinfos(lfirst(temp), is_pushed_down, outerjoin_delayed, pseudoconstant, security_level, required_relids, outer_relids, nullable_relids)); return make_andclause(andlist); } else return (Expr *) make_restrictinfo_internal(clause, NULL, is_pushed_down, outerjoin_delayed, pseudoconstant, security_level, required_relids, outer_relids, nullable_relids); }