110 #define REL_ALIAS_PREFIX "r"
112 #define ADD_REL_QUALIFIER(buf, varno) \
113 appendStringInfo((buf), "%s%d.", REL_ALIAS_PREFIX, (varno))
114 #define SUBQUERY_REL_ALIAS_PREFIX "s"
115 #define SUBQUERY_COL_ALIAS_PREFIX "c"
137 List **retrieved_attrs);
140 List **retrieved_attrs,
146 List *withCheckOptionList,
148 List **retrieved_attrs);
202 int *relno,
int *colno);
204 int *relno,
int *colno);
225 foreach(lc, input_conds)
230 *remote_conds =
lappend(*remote_conds, ri);
232 *local_conds =
lappend(*local_conds, ri);
252 glob_cxt.
root = root;
313 bool check_type =
true;
359 collation = var->varcollid;
365 collation = var->varcollid;
367 collation == DEFAULT_COLLATION_OID)
397 switch (
c->consttype)
400 case REGPROCEDUREOID:
402 ProcedureRelationId, fpinfo))
408 OperatorRelationId, fpinfo))
413 RelationRelationId, fpinfo))
418 TypeRelationId, fpinfo))
421 case REGCOLLATIONOID:
423 CollationRelationId, fpinfo))
437 TSConfigRelationId, fpinfo))
440 case REGDICTIONARYOID:
443 TSDictionaryRelationId, fpinfo))
446 case REGNAMESPACEOID:
448 NamespaceRelationId, fpinfo))
453 AuthIdRelationId, fpinfo))
465 collation =
c->constcollid;
467 collation == DEFAULT_COLLATION_OID)
496 collation = p->paramcollid;
498 collation == DEFAULT_COLLATION_OID)
504 case T_SubscriptingRef:
518 glob_cxt, &inner_cxt, case_arg_cxt))
523 glob_cxt, &inner_cxt, case_arg_cxt))
528 glob_cxt, &inner_cxt, case_arg_cxt))
536 collation = sr->refcollid;
540 collation == inner_cxt.collation)
542 else if (collation == DEFAULT_COLLATION_OID)
564 glob_cxt, &inner_cxt, case_arg_cxt))
574 fe->inputcollid != inner_cxt.collation)
583 collation =
fe->funccollid;
587 collation == inner_cxt.collation)
589 else if (collation == DEFAULT_COLLATION_OID)
612 glob_cxt, &inner_cxt, case_arg_cxt))
622 oe->inputcollid != inner_cxt.collation)
626 collation = oe->opcollid;
630 collation == inner_cxt.collation)
632 else if (collation == DEFAULT_COLLATION_OID)
638 case T_ScalarArrayOpExpr:
652 glob_cxt, &inner_cxt, case_arg_cxt))
662 oe->inputcollid != inner_cxt.collation)
678 glob_cxt, &inner_cxt, case_arg_cxt))
685 collation = r->resultcollid;
689 collation == inner_cxt.collation)
691 else if (collation == DEFAULT_COLLATION_OID)
705 glob_cxt, &inner_cxt, case_arg_cxt))
721 glob_cxt, &inner_cxt, case_arg_cxt))
746 glob_cxt, &arg_cxt, case_arg_cxt))
751 foreach(lc, ce->
args)
774 opArgs = ((
OpExpr *) whenExpr)->args;
789 glob_cxt, &tmp_cxt, &arg_cxt))
794 glob_cxt, &inner_cxt, case_arg_cxt))
800 glob_cxt, &inner_cxt, case_arg_cxt))
811 collation = ce->casecollid;
817 else if (collation == DEFAULT_COLLATION_OID)
836 collation =
c->collation;
842 else if (collation == DEFAULT_COLLATION_OID)
856 glob_cxt, &inner_cxt, case_arg_cxt))
863 collation =
a->array_collid;
867 collation == inner_cxt.collation)
869 else if (collation == DEFAULT_COLLATION_OID)
886 glob_cxt, &inner_cxt, case_arg_cxt))
923 foreach(lc, agg->
args)
936 glob_cxt, &inner_cxt, case_arg_cxt))
969 glob_cxt, &inner_cxt, case_arg_cxt))
988 collation = agg->aggcollid;
994 else if (collation == DEFAULT_COLLATION_OID)
1039 if (outer_cxt->
collation == DEFAULT_COLLATION_OID)
1044 else if (collation != DEFAULT_COLLATION_OID)
1097 relids = baserel->
relids;
1231 bool has_final_sort,
bool has_limit,
bool is_subquery,
1232 List **retrieved_attrs,
List **params_list)
1246 context.
root = root;
1267 quals = remote_conds;
1410 List **retrieved_attrs)
1417 *retrieved_attrs =
NIL;
1424 for (
i = 1;
i <= tupdesc->
natts;
i++)
1429 if (attr->attisdropped)
1432 if (have_wholerow ||
1438 else if (is_returning)
1457 else if (is_returning)
1470 if (first && !is_returning)
1573 bool is_first =
true;
1621 elog(
ERROR,
"unsupported join type %d", jointype);
1642 List **retrieved_attrs,
1649 *retrieved_attrs =
NIL;
1657 else if (is_returning)
1662 *retrieved_attrs =
lappend_int(*retrieved_attrs,
i + 1);
1666 if (
i == 0 && !is_returning)
1718 bool use_alias,
Index ignore_rel,
List **ignore_conds,
1729 bool outerrel_is_target =
false;
1730 bool innerrel_is_target =
false;
1755 if (outerrel->
relid == ignore_rel)
1756 outerrel_is_target =
true;
1757 else if (innerrel->
relid == ignore_rel)
1758 innerrel_is_target =
true;
1762 if (!outerrel_is_target)
1767 ignore_rel, ignore_conds, params_list);
1778 if (innerrel_is_target)
1788 if (!innerrel_is_target)
1793 ignore_rel, ignore_conds, params_list);
1799 if (outerrel_is_target)
1809 Assert(!outerrel_is_target && !innerrel_is_target);
1827 context.
root = root;
1869 bool make_subquery,
Index ignore_rel,
List **ignore_conds,
1882 List *retrieved_attrs;
1890 Assert(ignore_rel == 0 ||
1898 &retrieved_attrs, params_list);
1916 for (
i = 1;
i <= ncols;
i++)
1928 ignore_conds, params_list);
1944 List *targetAttrs,
bool doNothing,
1945 List *withCheckOptionList,
List *returningList,
1946 List **retrieved_attrs,
int *values_end_len)
1961 foreach(lc, targetAttrs)
1976 foreach(lc, targetAttrs)
1985 if (attr->attgenerated)
1998 *values_end_len =
buf->len;
2005 withCheckOptionList, returningList, retrieved_attrs);
2016 char *orig_query,
List *target_attrs,
2017 int values_end_len,
int num_params,
2027 Assert((values_end_len > 0) && (values_end_len <= strlen(orig_query)));
2036 pindex = num_params + 1;
2037 for (
i = 0;
i < num_rows;
i++)
2042 foreach(lc, target_attrs)
2051 if (attr->attgenerated)
2078 List *withCheckOptionList,
List *returningList,
2079 List **retrieved_attrs)
2092 foreach(lc, targetAttrs)
2102 if (attr->attgenerated)
2114 withCheckOptionList, returningList, retrieved_attrs);
2142 List *returningList,
2143 List **retrieved_attrs)
2153 context.
root = root;
2169 forboth(lc, targetlist, lc2, targetAttrs)
2194 &ignore_conds, params_list);
2195 remote_conds =
list_concat(remote_conds, ignore_conds);
2209 NIL, returningList, retrieved_attrs);
2222 List *returningList,
2223 List **retrieved_attrs)
2231 NIL, returningList, retrieved_attrs);
2254 List *returningList,
2255 List **retrieved_attrs)
2260 context.
root = root;
2277 &ignore_conds, params_list);
2278 remote_conds =
list_concat(remote_conds, ignore_conds);
2292 rtindex, rel,
false,
2293 NIL, returningList, retrieved_attrs);
2302 bool trig_after_row,
2303 List *withCheckOptionList,
2304 List *returningList,
2305 List **retrieved_attrs)
2316 if (withCheckOptionList !=
NIL)
2331 if (returningList !=
NIL)
2341 if (attrs_used != NULL)
2345 *retrieved_attrs =
NIL;
2421 List **retrieved_attrs)
2431 *retrieved_attrs =
NIL;
2434 for (
i = 0;
i < tupdesc->
natts;
i++)
2452 if (strcmp(def->
defname,
"column_name") == 0)
2461 *retrieved_attrs =
lappend_int(*retrieved_attrs,
i + 1);
2475 switch (sample_method)
2495 elog(
ERROR,
"unexpected sampling method");
2524 restart_seqs ?
"RESTART" :
"CONTINUE");
2549 else if (varattno < 0)
2560 fetchval = rte->
relid;
2571 else if (varattno == 0)
2578 List *retrieved_attrs;
2624 char *colname = NULL;
2640 if (strcmp(def->
defname,
"column_name") == 0)
2651 if (colname == NULL)
2670 const char *nspname = NULL;
2684 if (strcmp(def->
defname,
"schema_name") == 0)
2686 else if (strcmp(def->
defname,
"table_name") == 0)
2694 if (nspname == NULL)
2717 if (strchr(
val,
'\\') != NULL)
2720 for (valptr =
val; *valptr; valptr++)
2758 case T_SubscriptingRef:
2767 case T_DistinctExpr:
2770 case T_ScalarArrayOpExpr:
2792 elog(
ERROR,
"unsupported expression type for deparse: %d",
2884 bool isfloat =
false;
2885 bool isstring =
false;
2888 if (node->constisnull)
2894 node->consttypmod));
2899 &typoutput, &typIsVarlena);
2916 if (strspn(extval,
"0123456789+-eE.") == strlen(extval))
2918 if (extval[0] ==
'+' || extval[0] ==
'-')
2922 if (strcspn(extval,
"eE.") != strlen(extval))
2934 if (strcmp(extval,
"t") == 0)
2965 needlabel = !isfloat || (node->consttypmod >= 0);
2971 needlabel = !isstring;
2977 if (needlabel || showtype > 0)
2980 node->consttypmod));
3094 Oid rettype = node->funcresulttype;
3095 int32 coercedTypmod;
3107 use_variadic = node->funcvariadic;
3140 bool canSuppressRightConstCast =
false;
3146 elog(
ERROR,
"cache lookup failed for operator %u", node->
opno);
3148 oprkind = form->oprkind;
3165 bool canSuppressLeftConstCast =
false;
3193 if (leftType == rightType)
3201 if (canSuppressLeftConstCast)
3215 if (canSuppressRightConstCast)
3269 opname =
NameStr(opform->oprname);
3272 if (opform->oprnamespace != PG_CATALOG_NAMESPACE)
3274 const char *opnspname;
3321 elog(
ERROR,
"cache lookup failed for operator %u", node->
opno);
3361 node->resulttypmod));
3371 const char *op = NULL;
3392 foreach(lc, node->
args)
3447 if (node->
arg != NULL)
3454 foreach(lc, node->
args)
3460 if (node->
arg == NULL)
3524 use_variadic = node->aggvariadic;
3533 if (AGGKIND_IS_ORDERED_SET(node->aggkind))
3539 Assert(!node->aggvariadic);
3613 foreach(lc, orderList)
3646 if (sortop == typentry->
lt_opr)
3648 else if (sortop == typentry->
gt_opr)
3660 elog(
ERROR,
"cache lookup failed for operator %u", sortop);
3773 const char *delim =
" ";
3780 foreach(lcell, pathkeys)
3808 elog(
ERROR,
"could not find pathkey item to sort");
3822 elog(
ERROR,
"missing operator %d(%u,%u) in opfamily %u",
3882 elog(
ERROR,
"cache lookup failed for function %u", funcid);
3886 if (procform->pronamespace != PG_CATALOG_NAMESPACE)
3888 const char *schemaname;
3933 else if (!expr ||
IsA(expr,
Var))
3943 return (
Node *) expr;
4016 int *relno,
int *colno)
4048 elog(
ERROR,
"unexpected expression in subquery output");
int bms_next_member(const Bitmapset *a, int prevbit)
void bms_free(Bitmapset *a)
bool bms_is_member(int x, const Bitmapset *a)
Bitmapset * bms_make_singleton(int x)
Bitmapset * bms_add_member(Bitmapset *a, int x)
BMS_Membership bms_membership(const Bitmapset *a)
#define FORMAT_TYPE_TYPEMOD_GIVEN
#define FORMAT_TYPE_FORCE_QUALIFY
#define ESCAPE_STRING_SYNTAX
#define SQL_STR_DOUBLE(ch, escape_backslash)
#define OidIsValid(objectId)
bool contain_mutable_functions(Node *clause)
elog(ERROR, "%s: %s", p2, msg)
char * defGetString(DefElem *def)
static void deparseCaseExpr(CaseExpr *node, deparse_expr_cxt *context)
void deparseAnalyzeSizeSql(StringInfo buf, Relation rel)
static void deparseBoolExpr(BoolExpr *node, deparse_expr_cxt *context)
static void appendGroupByClause(List *tlist, deparse_expr_cxt *context)
static void deparseTargetList(StringInfo buf, RangeTblEntry *rte, Index rtindex, Relation rel, bool is_returning, Bitmapset *attrs_used, bool qualify_col, List **retrieved_attrs)
static void deparseRangeTblRef(StringInfo buf, PlannerInfo *root, RelOptInfo *foreignrel, bool make_subquery, Index ignore_rel, List **ignore_conds, List **params_list)
#define SUBQUERY_REL_ALIAS_PREFIX
static void deparseFromExpr(List *quals, deparse_expr_cxt *context)
static Node * deparseSortGroupClause(Index ref, List *tlist, bool force_colno, deparse_expr_cxt *context)
static void deparseLockingClause(deparse_expr_cxt *context)
const char * get_jointype_name(JoinType jointype)
void deparseAnalyzeInfoSql(StringInfo buf, Relation rel)
static void deparseAggref(Aggref *node, deparse_expr_cxt *context)
static void appendOrderBySuffix(Oid sortop, Oid sortcoltype, bool nulls_first, deparse_expr_cxt *context)
void deparseDirectDeleteSql(StringInfo buf, PlannerInfo *root, Index rtindex, Relation rel, RelOptInfo *foreignrel, List *remote_conds, List **params_list, List *returningList, List **retrieved_attrs)
void deparseDirectUpdateSql(StringInfo buf, PlannerInfo *root, Index rtindex, Relation rel, RelOptInfo *foreignrel, List *targetlist, List *targetAttrs, List *remote_conds, List **params_list, List *returningList, List **retrieved_attrs)
struct deparse_expr_cxt deparse_expr_cxt
static void get_relation_column_alias_ids(Var *node, RelOptInfo *foreignrel, int *relno, int *colno)
static void printRemoteParam(int paramindex, Oid paramtype, int32 paramtypmod, deparse_expr_cxt *context)
static bool is_subquery_var(Var *node, RelOptInfo *foreignrel, int *relno, int *colno)
bool is_foreign_param(PlannerInfo *root, RelOptInfo *baserel, Expr *expr)
static void printRemotePlaceholder(Oid paramtype, int32 paramtypmod, deparse_expr_cxt *context)
static void appendOrderByClause(List *pathkeys, bool has_final_sort, deparse_expr_cxt *context)
static bool foreign_expr_walker(Node *node, foreign_glob_cxt *glob_cxt, foreign_loc_cxt *outer_cxt, foreign_loc_cxt *case_arg_cxt)
static void deparseColumnRef(StringInfo buf, int varno, int varattno, RangeTblEntry *rte, bool qualify_col)
static void deparseRelabelType(RelabelType *node, deparse_expr_cxt *context)
static void deparseNullTest(NullTest *node, deparse_expr_cxt *context)
static void deparseOperatorName(StringInfo buf, Form_pg_operator opform)
static void deparseOpExpr(OpExpr *node, deparse_expr_cxt *context)
static void deparseConst(Const *node, deparse_expr_cxt *context, int showtype)
static bool isPlainForeignVar(Expr *node, deparse_expr_cxt *context)
static void deparseDistinctExpr(DistinctExpr *node, deparse_expr_cxt *context)
void deparseSelectStmtForRel(StringInfo buf, PlannerInfo *root, RelOptInfo *rel, List *tlist, List *remote_conds, List *pathkeys, bool has_final_sort, bool has_limit, bool is_subquery, List **retrieved_attrs, List **params_list)
static void deparseFuncExpr(FuncExpr *node, deparse_expr_cxt *context)
void deparseStringLiteral(StringInfo buf, const char *val)
void rebuildInsertSql(StringInfo buf, Relation rel, char *orig_query, List *target_attrs, int values_end_len, int num_params, int num_rows)
struct foreign_glob_cxt foreign_glob_cxt
static void deparseArrayExpr(ArrayExpr *node, deparse_expr_cxt *context)
void deparseInsertSql(StringInfo buf, RangeTblEntry *rte, Index rtindex, Relation rel, List *targetAttrs, bool doNothing, List *withCheckOptionList, List *returningList, List **retrieved_attrs, int *values_end_len)
static void deparseReturningList(StringInfo buf, RangeTblEntry *rte, Index rtindex, Relation rel, bool trig_after_row, List *withCheckOptionList, List *returningList, List **retrieved_attrs)
void deparseUpdateSql(StringInfo buf, RangeTblEntry *rte, Index rtindex, Relation rel, List *targetAttrs, List *withCheckOptionList, List *returningList, List **retrieved_attrs)
static void deparseVar(Var *node, deparse_expr_cxt *context)
static void appendFunctionName(Oid funcid, deparse_expr_cxt *context)
static void appendConditions(List *exprs, deparse_expr_cxt *context)
struct foreign_loc_cxt foreign_loc_cxt
void deparseDeleteSql(StringInfo buf, RangeTblEntry *rte, Index rtindex, Relation rel, List *returningList, List **retrieved_attrs)
void deparseAnalyzeSql(StringInfo buf, Relation rel, PgFdwSamplingMethod sample_method, double sample_frac, List **retrieved_attrs)
static void deparseSubscriptingRef(SubscriptingRef *node, deparse_expr_cxt *context)
static void deparseRelation(StringInfo buf, Relation rel)
static void deparseExplicitTargetList(List *tlist, bool is_returning, List **retrieved_attrs, deparse_expr_cxt *context)
static char * deparse_type_name(Oid type_oid, int32 typemod)
#define ADD_REL_QUALIFIER(buf, varno)
static void appendLimitClause(deparse_expr_cxt *context)
static void deparseExpr(Expr *node, deparse_expr_cxt *context)
bool is_foreign_expr(PlannerInfo *root, RelOptInfo *baserel, Expr *expr)
List * build_tlist_to_deparse(RelOptInfo *foreignrel)
#define SUBQUERY_COL_ALIAS_PREFIX
void classifyConditions(PlannerInfo *root, RelOptInfo *baserel, List *input_conds, List **remote_conds, List **local_conds)
static void deparseScalarArrayOpExpr(ScalarArrayOpExpr *node, deparse_expr_cxt *context)
static void deparseFromExprForRel(StringInfo buf, PlannerInfo *root, RelOptInfo *foreignrel, bool use_alias, Index ignore_rel, List **ignore_conds, List **params_list)
void deparseTruncateSql(StringInfo buf, List *rels, DropBehavior behavior, bool restart_seqs)
static void deparseSubqueryTargetList(deparse_expr_cxt *context)
bool is_foreign_pathkey(PlannerInfo *root, RelOptInfo *baserel, PathKey *pathkey)
static void deparseSelectSql(List *tlist, bool is_subquery, List **retrieved_attrs, deparse_expr_cxt *context)
static void deparseParam(Param *node, deparse_expr_cxt *context)
static void appendAggOrderBy(List *orderList, List *targetList, deparse_expr_cxt *context)
bool equal(const void *a, const void *b)
char * OidOutputFunctionCall(Oid functionId, Datum val)
ForeignTable * GetForeignTable(Oid relid)
List * GetForeignColumnOptions(Oid relid, AttrNumber attnum)
#define HeapTupleIsValid(tuple)
if(TABLE==NULL||TABLE_index==NULL)
Assert(fmt[strlen(fmt) - 1] !='\n')
List * lappend(List *list, void *datum)
List * lappend_int(List *list, int datum)
List * list_concat(List *list1, const List *list2)
bool type_is_rowtype(Oid typid)
char * get_namespace_name(Oid nspid)
void getTypeOutputInfo(Oid type, Oid *typOutput, bool *typIsVarlena)
Oid get_opfamily_member(Oid opfamily, Oid lefttype, Oid righttype, int16 strategy)
char * get_attname(Oid relid, AttrNumber attnum, bool missing_ok)
void pfree(void *pointer)
Oid exprType(const Node *expr)
bool exprIsLengthCoercion(const Node *expr, int32 *coercedTypmod)
Node * strip_implicit_coercions(Node *node)
#define IsA(nodeptr, _type_)
#define castNode(_type_, nodeptr)
#define PVC_RECURSE_PLACEHOLDERS
#define IS_SIMPLE_REL(rel)
#define planner_rt_fetch(rti, root)
#define IS_UPPER_REL(rel)
FormData_pg_attribute * Form_pg_attribute
#define lfirst_node(type, lc)
static int list_length(const List *l)
#define forboth(cell1, list1, cell2, list2)
static ListCell * list_head(const List *l)
static ListCell * lnext(const List *l, const ListCell *c)
FormData_pg_operator * Form_pg_operator
FormData_pg_proc * Form_pg_proc
static Oid DatumGetObjectId(Datum X)
static Datum ObjectIdGetDatum(Oid X)
void reset_transmission_modes(int nestlevel)
int set_transmission_modes(void)
EquivalenceMember * find_em_for_rel(PlannerInfo *root, EquivalenceClass *ec, RelOptInfo *rel)
EquivalenceMember * find_em_for_rel_target(PlannerInfo *root, EquivalenceClass *ec, RelOptInfo *rel)
bool is_shippable(Oid objectId, Oid classId, PgFdwRelationInfo *fpinfo)
bool is_builtin(Oid objectId)
@ ANALYZE_SAMPLE_BERNOULLI
PlanRowMark * get_plan_rowmark(List *rowmarks, Index rtindex)
#define IS_SPECIAL_VARNO(varno)
#define RelationGetRelid(relation)
#define RelationGetDescr(relation)
#define RelationGetRelationName(relation)
#define RelationGetNamespace(relation)
const char * quote_identifier(const char *ident)
void appendStringInfo(StringInfo str, const char *fmt,...)
void appendBinaryStringInfo(StringInfo str, const void *data, int datalen)
void appendStringInfoString(StringInfo str, const char *s)
void appendStringInfoChar(StringInfo str, char ch)
void initStringInfo(StringInfo str)
NullTestType nulltesttype
bool make_outerrel_subquery
Relids lower_subquery_rels
bool make_innerrel_subquery
LockClauseStrength strength
struct PathTarget * reltarget
bool trig_update_after_row
bool trig_insert_after_row
bool trig_delete_after_row
#define FirstLowInvalidHeapAttributeNumber
#define TableOidAttributeNumber
#define SelfItemPointerAttributeNumber
void ReleaseSysCache(HeapTuple tuple)
HeapTuple SearchSysCache1(int cacheId, Datum key1)
void table_close(Relation relation, LOCKMODE lockmode)
Relation table_open(Oid relationId, LOCKMODE lockmode)
TargetEntry * get_sortgroupref_tle(Index sortref, List *targetList)
List * add_to_flat_tlist(List *tlist, List *exprs)
#define FirstNormalObjectId
#define TupleDescAttr(tupdesc, i)
TypeCacheEntry * lookup_type_cache(Oid type_id, int flags)
List * pull_var_clause(Node *node, int flags)
void pull_varattnos(Node *node, Index varno, Bitmapset **varattnos)