diff options
author | Alvaro Herrera <alvherre@alvh.no-ip.org> | 2019-02-01 12:50:32 -0300 |
---|---|---|
committer | Alvaro Herrera <alvherre@alvh.no-ip.org> | 2019-02-01 12:50:32 -0300 |
commit | 558d77f20e4e9ed18101d5d057b770ae22ece855 (patch) | |
tree | c65b6dff674f7f6a46a391683e281a51839162c1 /src/backend/utils/adt/ruleutils.c | |
parent | f831d4accda00b9144bc647ede2e2f848b59f39d (diff) | |
download | postgresql-558d77f20e4e9ed18101d5d057b770ae22ece855.tar.gz postgresql-558d77f20e4e9ed18101d5d057b770ae22ece855.zip |
Renaming for new subscripting mechanism
Over at patch https://commitfest.postgresql.org/21/1062/ Dmitry wants to
introduce a more generic subscription mechanism, which allows
subscripting not only arrays but also other object types such as JSONB.
That functionality is introduced in a largish invasive patch, out of
which this internal renaming patch was extracted.
Author: Dmitry Dolgov
Reviewed-by: Tom Lane, Arthur Zakirov
Discussion: https://postgr.es/m/CA+q6zcUK4EqPAu7XRRO5CCjMwhz5zvg+rfWuLzVoxp_5sKS6=w@mail.gmail.com
Diffstat (limited to 'src/backend/utils/adt/ruleutils.c')
-rw-r--r-- | src/backend/utils/adt/ruleutils.c | 88 |
1 files changed, 46 insertions, 42 deletions
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c index 51e4c275ab0..17a28c26517 100644 --- a/src/backend/utils/adt/ruleutils.c +++ b/src/backend/utils/adt/ruleutils.c @@ -456,7 +456,7 @@ static void get_tablesample_def(TableSampleClause *tablesample, static void get_opclass_name(Oid opclass, Oid actual_datatype, StringInfo buf); static Node *processIndirection(Node *node, deparse_context *context); -static void printSubscripts(ArrayRef *aref, deparse_context *context); +static void printSubscripts(SubscriptingRef *sbsref, deparse_context *context); static char *get_relation_name(Oid relid); static char *generate_relation_name(Oid relid, List *namespaces); static char *generate_qualified_relation_name(Oid relid); @@ -6400,12 +6400,12 @@ get_update_query_targetlist_def(Query *query, List *targetList, { /* * We must dig down into the expr to see if it's a PARAM_MULTIEXPR - * Param. That could be buried under FieldStores and ArrayRefs - * and CoerceToDomains (cf processIndirection()), and underneath - * those there could be an implicit type coercion. Because we - * would ignore implicit type coercions anyway, we don't need to - * be as careful as processIndirection() is about descending past - * implicit CoerceToDomains. + * Param. That could be buried under FieldStores and + * SubscriptingRefs and CoerceToDomains (cf processIndirection()), + * and underneath those there could be an implicit type coercion. + * Because we would ignore implicit type coercions anyway, we + * don't need to be as careful as processIndirection() is about + * descending past implicit CoerceToDomains. */ expr = (Node *) tle->expr; while (expr) @@ -6416,13 +6416,14 @@ get_update_query_targetlist_def(Query *query, List *targetList, expr = (Node *) linitial(fstore->newvals); } - else if (IsA(expr, ArrayRef)) + else if (IsA(expr, SubscriptingRef)) { - ArrayRef *aref = (ArrayRef *) expr; + SubscriptingRef *sbsref = (SubscriptingRef *) expr; - if (aref->refassgnexpr == NULL) + if (sbsref->refassgnexpr == NULL) break; - expr = (Node *) aref->refassgnexpr; + + expr = (Node *) sbsref->refassgnexpr; } else if (IsA(expr, CoerceToDomain)) { @@ -7456,7 +7457,7 @@ isSimpleNode(Node *node, Node *parentNode, int prettyFlags) /* single words: always simple */ return true; - case T_ArrayRef: + case T_SubscriptingRef: case T_ArrayExpr: case T_RowExpr: case T_CoalesceExpr: @@ -7574,7 +7575,7 @@ isSimpleNode(Node *node, Node *parentNode, int prettyFlags) return true; /* own parentheses */ } case T_BoolExpr: /* lower precedence */ - case T_ArrayRef: /* other separators */ + case T_SubscriptingRef: /* other separators */ case T_ArrayExpr: /* other separators */ case T_RowExpr: /* other separators */ case T_CoalesceExpr: /* own parentheses */ @@ -7624,7 +7625,7 @@ isSimpleNode(Node *node, Node *parentNode, int prettyFlags) return false; return true; /* own parentheses */ } - case T_ArrayRef: /* other separators */ + case T_SubscriptingRef: /* other separators */ case T_ArrayExpr: /* other separators */ case T_RowExpr: /* other separators */ case T_CoalesceExpr: /* own parentheses */ @@ -7810,9 +7811,9 @@ get_rule_expr(Node *node, deparse_context *context, get_windowfunc_expr((WindowFunc *) node, context); break; - case T_ArrayRef: + case T_SubscriptingRef: { - ArrayRef *aref = (ArrayRef *) node; + SubscriptingRef *sbsref = (SubscriptingRef *) node; bool need_parens; /* @@ -7823,37 +7824,38 @@ get_rule_expr(Node *node, deparse_context *context, * here too, and display only the assignment source * expression. */ - if (IsA(aref->refexpr, CaseTestExpr)) + if (IsA(sbsref->refexpr, CaseTestExpr)) { - Assert(aref->refassgnexpr); - get_rule_expr((Node *) aref->refassgnexpr, + Assert(sbsref->refassgnexpr); + get_rule_expr((Node *) sbsref->refassgnexpr, context, showimplicit); break; } /* * Parenthesize the argument unless it's a simple Var or a - * FieldSelect. (In particular, if it's another ArrayRef, we - * *must* parenthesize to avoid confusion.) + * FieldSelect. (In particular, if it's another + * SubscriptingRef, we *must* parenthesize to avoid + * confusion.) */ - need_parens = !IsA(aref->refexpr, Var) && - !IsA(aref->refexpr, FieldSelect); + need_parens = !IsA(sbsref->refexpr, Var) && + !IsA(sbsref->refexpr, FieldSelect); if (need_parens) appendStringInfoChar(buf, '('); - get_rule_expr((Node *) aref->refexpr, context, showimplicit); + get_rule_expr((Node *) sbsref->refexpr, context, showimplicit); if (need_parens) appendStringInfoChar(buf, ')'); /* * If there's a refassgnexpr, we want to print the node in the - * format "array[subscripts] := refassgnexpr". This is not - * legal SQL, so decompilation of INSERT or UPDATE statements - * should always use processIndirection as part of the - * statement-level syntax. We should only see this when + * format "container[subscripts] := refassgnexpr". This is + * not legal SQL, so decompilation of INSERT or UPDATE + * statements should always use processIndirection as part of + * the statement-level syntax. We should only see this when * EXPLAIN tries to print the targetlist of a plan resulting * from such a statement. */ - if (aref->refassgnexpr) + if (sbsref->refassgnexpr) { Node *refassgnexpr; @@ -7869,8 +7871,8 @@ get_rule_expr(Node *node, deparse_context *context, } else { - /* Just an ordinary array fetch, so print subscripts */ - printSubscripts(aref, context); + /* Just an ordinary container fetch, so print subscripts */ + printSubscripts(sbsref, context); } } break; @@ -8068,12 +8070,13 @@ get_rule_expr(Node *node, deparse_context *context, bool need_parens; /* - * Parenthesize the argument unless it's an ArrayRef or + * Parenthesize the argument unless it's an SubscriptingRef or * another FieldSelect. Note in particular that it would be * WRONG to not parenthesize a Var argument; simplicity is not * the issue here, having the right number of names is. */ - need_parens = !IsA(arg, ArrayRef) &&!IsA(arg, FieldSelect); + need_parens = !IsA(arg, SubscriptingRef) && + !IsA(arg, FieldSelect); if (need_parens) appendStringInfoChar(buf, '('); get_rule_expr(arg, context, true); @@ -10437,7 +10440,7 @@ get_opclass_name(Oid opclass, Oid actual_datatype, /* * processIndirection - take care of array and subfield assignment * - * We strip any top-level FieldStore or assignment ArrayRef nodes that + * We strip any top-level FieldStore or assignment SubscriptingRef nodes that * appear in the input, printing them as decoration for the base column * name (which we assume the caller just printed). We might also need to * strip CoerceToDomain nodes, but only ones that appear above assignment @@ -10483,19 +10486,20 @@ processIndirection(Node *node, deparse_context *context) */ node = (Node *) linitial(fstore->newvals); } - else if (IsA(node, ArrayRef)) + else if (IsA(node, SubscriptingRef)) { - ArrayRef *aref = (ArrayRef *) node; + SubscriptingRef *sbsref = (SubscriptingRef *) node; - if (aref->refassgnexpr == NULL) + if (sbsref->refassgnexpr == NULL) break; - printSubscripts(aref, context); + + printSubscripts(sbsref, context); /* * We ignore refexpr since it should be an uninteresting reference * to the target column or subcolumn. */ - node = (Node *) aref->refassgnexpr; + node = (Node *) sbsref->refassgnexpr; } else if (IsA(node, CoerceToDomain)) { @@ -10523,14 +10527,14 @@ processIndirection(Node *node, deparse_context *context) } static void -printSubscripts(ArrayRef *aref, deparse_context *context) +printSubscripts(SubscriptingRef *sbsref, deparse_context *context) { StringInfo buf = context->buf; ListCell *lowlist_item; ListCell *uplist_item; - lowlist_item = list_head(aref->reflowerindexpr); /* could be NULL */ - foreach(uplist_item, aref->refupperindexpr) + lowlist_item = list_head(sbsref->reflowerindexpr); /* could be NULL */ + foreach(uplist_item, sbsref->refupperindexpr) { appendStringInfoChar(buf, '['); if (lowlist_item) |