@@ -125,7 +125,7 @@ static char *deparse_type_name(Oid type_oid, int32 typemod);
125
125
* Functions to construct string representation of a node tree.
126
126
*/
127
127
static void deparseTargetList (StringInfo buf ,
128
- PlannerInfo * root ,
128
+ RangeTblEntry * rte ,
129
129
Index rtindex ,
130
130
Relation rel ,
131
131
bool is_returning ,
@@ -137,13 +137,13 @@ static void deparseExplicitTargetList(List *tlist,
137
137
List * * retrieved_attrs ,
138
138
deparse_expr_cxt * context );
139
139
static void deparseSubqueryTargetList (deparse_expr_cxt * context );
140
- static void deparseReturningList (StringInfo buf , PlannerInfo * root ,
140
+ static void deparseReturningList (StringInfo buf , RangeTblEntry * rte ,
141
141
Index rtindex , Relation rel ,
142
142
bool trig_after_row ,
143
143
List * returningList ,
144
144
List * * retrieved_attrs );
145
145
static void deparseColumnRef (StringInfo buf , int varno , int varattno ,
146
- PlannerInfo * root , bool qualify_col );
146
+ RangeTblEntry * rte , bool qualify_col );
147
147
static void deparseRelation (StringInfo buf , Relation rel );
148
148
static void deparseExpr (Expr * expr , deparse_expr_cxt * context );
149
149
static void deparseVar (Var * node , deparse_expr_cxt * context );
@@ -1050,7 +1050,7 @@ deparseSelectSql(List *tlist, bool is_subquery, List **retrieved_attrs,
1050
1050
*/
1051
1051
Relation rel = heap_open (rte -> relid , NoLock );
1052
1052
1053
- deparseTargetList (buf , root , foreignrel -> relid , rel , false,
1053
+ deparseTargetList (buf , rte , foreignrel -> relid , rel , false,
1054
1054
fpinfo -> attrs_used , false, retrieved_attrs );
1055
1055
heap_close (rel , NoLock );
1056
1056
}
@@ -1099,7 +1099,7 @@ deparseFromExpr(List *quals, deparse_expr_cxt *context)
1099
1099
*/
1100
1100
static void
1101
1101
deparseTargetList (StringInfo buf ,
1102
- PlannerInfo * root ,
1102
+ RangeTblEntry * rte ,
1103
1103
Index rtindex ,
1104
1104
Relation rel ,
1105
1105
bool is_returning ,
@@ -1137,7 +1137,7 @@ deparseTargetList(StringInfo buf,
1137
1137
appendStringInfoString (buf , " RETURNING " );
1138
1138
first = false;
1139
1139
1140
- deparseColumnRef (buf , rtindex , i , root , qualify_col );
1140
+ deparseColumnRef (buf , rtindex , i , rte , qualify_col );
1141
1141
1142
1142
* retrieved_attrs = lappend_int (* retrieved_attrs , i );
1143
1143
}
@@ -1649,7 +1649,7 @@ deparseRangeTblRef(StringInfo buf, PlannerInfo *root, RelOptInfo *foreignrel,
1649
1649
* to *retrieved_attrs.
1650
1650
*/
1651
1651
void
1652
- deparseInsertSql (StringInfo buf , PlannerInfo * root ,
1652
+ deparseInsertSql (StringInfo buf , RangeTblEntry * rte ,
1653
1653
Index rtindex , Relation rel ,
1654
1654
List * targetAttrs , bool doNothing ,
1655
1655
List * returningList , List * * retrieved_attrs )
@@ -1674,7 +1674,7 @@ deparseInsertSql(StringInfo buf, PlannerInfo *root,
1674
1674
appendStringInfoString (buf , ", " );
1675
1675
first = false;
1676
1676
1677
- deparseColumnRef (buf , rtindex , attnum , root , false);
1677
+ deparseColumnRef (buf , rtindex , attnum , rte , false);
1678
1678
}
1679
1679
1680
1680
appendStringInfoString (buf , ") VALUES (" );
@@ -1699,7 +1699,7 @@ deparseInsertSql(StringInfo buf, PlannerInfo *root,
1699
1699
if (doNothing )
1700
1700
appendStringInfoString (buf , " ON CONFLICT DO NOTHING" );
1701
1701
1702
- deparseReturningList (buf , root , rtindex , rel ,
1702
+ deparseReturningList (buf , rte , rtindex , rel ,
1703
1703
rel -> trigdesc && rel -> trigdesc -> trig_insert_after_row ,
1704
1704
returningList , retrieved_attrs );
1705
1705
}
@@ -1712,7 +1712,7 @@ deparseInsertSql(StringInfo buf, PlannerInfo *root,
1712
1712
* to *retrieved_attrs.
1713
1713
*/
1714
1714
void
1715
- deparseUpdateSql (StringInfo buf , PlannerInfo * root ,
1715
+ deparseUpdateSql (StringInfo buf , RangeTblEntry * rte ,
1716
1716
Index rtindex , Relation rel ,
1717
1717
List * targetAttrs , List * returningList ,
1718
1718
List * * retrieved_attrs )
@@ -1735,13 +1735,13 @@ deparseUpdateSql(StringInfo buf, PlannerInfo *root,
1735
1735
appendStringInfoString (buf , ", " );
1736
1736
first = false;
1737
1737
1738
- deparseColumnRef (buf , rtindex , attnum , root , false);
1738
+ deparseColumnRef (buf , rtindex , attnum , rte , false);
1739
1739
appendStringInfo (buf , " = $%d" , pindex );
1740
1740
pindex ++ ;
1741
1741
}
1742
1742
appendStringInfoString (buf , " WHERE ctid = $1" );
1743
1743
1744
- deparseReturningList (buf , root , rtindex , rel ,
1744
+ deparseReturningList (buf , rte , rtindex , rel ,
1745
1745
rel -> trigdesc && rel -> trigdesc -> trig_update_after_row ,
1746
1746
returningList , retrieved_attrs );
1747
1747
}
@@ -1777,6 +1777,7 @@ deparseDirectUpdateSql(StringInfo buf, PlannerInfo *root,
1777
1777
int nestlevel ;
1778
1778
bool first ;
1779
1779
ListCell * lc ;
1780
+ RangeTblEntry * rte = planner_rt_fetch (rtindex , root );
1780
1781
1781
1782
/* Set up context struct for recursion */
1782
1783
context .root = root ;
@@ -1808,7 +1809,7 @@ deparseDirectUpdateSql(StringInfo buf, PlannerInfo *root,
1808
1809
appendStringInfoString (buf , ", " );
1809
1810
first = false;
1810
1811
1811
- deparseColumnRef (buf , rtindex , attnum , root , false);
1812
+ deparseColumnRef (buf , rtindex , attnum , rte , false);
1812
1813
appendStringInfoString (buf , " = " );
1813
1814
deparseExpr ((Expr * ) tle -> expr , & context );
1814
1815
}
@@ -1835,7 +1836,7 @@ deparseDirectUpdateSql(StringInfo buf, PlannerInfo *root,
1835
1836
deparseExplicitTargetList (returningList , true, retrieved_attrs ,
1836
1837
& context );
1837
1838
else
1838
- deparseReturningList (buf , root , rtindex , rel , false,
1839
+ deparseReturningList (buf , rte , rtindex , rel , false,
1839
1840
returningList , retrieved_attrs );
1840
1841
}
1841
1842
@@ -1847,7 +1848,7 @@ deparseDirectUpdateSql(StringInfo buf, PlannerInfo *root,
1847
1848
* to *retrieved_attrs.
1848
1849
*/
1849
1850
void
1850
- deparseDeleteSql (StringInfo buf , PlannerInfo * root ,
1851
+ deparseDeleteSql (StringInfo buf , RangeTblEntry * rte ,
1851
1852
Index rtindex , Relation rel ,
1852
1853
List * returningList ,
1853
1854
List * * retrieved_attrs )
@@ -1856,7 +1857,7 @@ deparseDeleteSql(StringInfo buf, PlannerInfo *root,
1856
1857
deparseRelation (buf , rel );
1857
1858
appendStringInfoString (buf , " WHERE ctid = $1" );
1858
1859
1859
- deparseReturningList (buf , root , rtindex , rel ,
1860
+ deparseReturningList (buf , rte , rtindex , rel ,
1860
1861
rel -> trigdesc && rel -> trigdesc -> trig_delete_after_row ,
1861
1862
returningList , retrieved_attrs );
1862
1863
}
@@ -1918,15 +1919,16 @@ deparseDirectDeleteSql(StringInfo buf, PlannerInfo *root,
1918
1919
deparseExplicitTargetList (returningList , true, retrieved_attrs ,
1919
1920
& context );
1920
1921
else
1921
- deparseReturningList (buf , root , rtindex , rel , false,
1922
+ deparseReturningList (buf , planner_rt_fetch (rtindex , root ),
1923
+ rtindex , rel , false,
1922
1924
returningList , retrieved_attrs );
1923
1925
}
1924
1926
1925
1927
/*
1926
1928
* Add a RETURNING clause, if needed, to an INSERT/UPDATE/DELETE.
1927
1929
*/
1928
1930
static void
1929
- deparseReturningList (StringInfo buf , PlannerInfo * root ,
1931
+ deparseReturningList (StringInfo buf , RangeTblEntry * rte ,
1930
1932
Index rtindex , Relation rel ,
1931
1933
bool trig_after_row ,
1932
1934
List * returningList ,
@@ -1952,7 +1954,7 @@ deparseReturningList(StringInfo buf, PlannerInfo *root,
1952
1954
}
1953
1955
1954
1956
if (attrs_used != NULL )
1955
- deparseTargetList (buf , root , rtindex , rel , true, attrs_used , false,
1957
+ deparseTargetList (buf , rte , rtindex , rel , true, attrs_used , false,
1956
1958
retrieved_attrs );
1957
1959
else
1958
1960
* retrieved_attrs = NIL ;
@@ -2048,11 +2050,9 @@ deparseAnalyzeSql(StringInfo buf, Relation rel, List **retrieved_attrs)
2048
2050
* If qualify_col is true, qualify column name with the alias of relation.
2049
2051
*/
2050
2052
static void
2051
- deparseColumnRef (StringInfo buf , int varno , int varattno , PlannerInfo * root ,
2053
+ deparseColumnRef (StringInfo buf , int varno , int varattno , RangeTblEntry * rte ,
2052
2054
bool qualify_col )
2053
2055
{
2054
- RangeTblEntry * rte ;
2055
-
2056
2056
/* We support fetching the remote side's CTID and OID. */
2057
2057
if (varattno == SelfItemPointerAttributeNumber )
2058
2058
{
@@ -2077,10 +2077,7 @@ deparseColumnRef(StringInfo buf, int varno, int varattno, PlannerInfo *root,
2077
2077
Oid fetchval = 0 ;
2078
2078
2079
2079
if (varattno == TableOidAttributeNumber )
2080
- {
2081
- rte = planner_rt_fetch (varno , root );
2082
2080
fetchval = rte -> relid ;
2083
- }
2084
2081
2085
2082
if (qualify_col )
2086
2083
{
@@ -2100,9 +2097,6 @@ deparseColumnRef(StringInfo buf, int varno, int varattno, PlannerInfo *root,
2100
2097
/* Required only to be passed down to deparseTargetList(). */
2101
2098
List * retrieved_attrs ;
2102
2099
2103
- /* Get RangeTblEntry from array in PlannerInfo. */
2104
- rte = planner_rt_fetch (varno , root );
2105
-
2106
2100
/*
2107
2101
* The lock on the relation will be held by upper callers, so it's
2108
2102
* fine to open it with no lock here.
@@ -2134,7 +2128,7 @@ deparseColumnRef(StringInfo buf, int varno, int varattno, PlannerInfo *root,
2134
2128
}
2135
2129
2136
2130
appendStringInfoString (buf , "ROW(" );
2137
- deparseTargetList (buf , root , varno , rel , false, attrs_used , qualify_col ,
2131
+ deparseTargetList (buf , rte , varno , rel , false, attrs_used , qualify_col ,
2138
2132
& retrieved_attrs );
2139
2133
appendStringInfoChar (buf , ')' );
2140
2134
@@ -2154,9 +2148,6 @@ deparseColumnRef(StringInfo buf, int varno, int varattno, PlannerInfo *root,
2154
2148
/* varno must not be any of OUTER_VAR, INNER_VAR and INDEX_VAR. */
2155
2149
Assert (!IS_SPECIAL_VARNO (varno ));
2156
2150
2157
- /* Get RangeTblEntry from array in PlannerInfo. */
2158
- rte = planner_rt_fetch (varno , root );
2159
-
2160
2151
/*
2161
2152
* If it's a column of a foreign table, and it has the column_name FDW
2162
2153
* option, use that value.
@@ -2354,7 +2345,8 @@ deparseVar(Var *node, deparse_expr_cxt *context)
2354
2345
2355
2346
if (bms_is_member (node -> varno , relids ) && node -> varlevelsup == 0 )
2356
2347
deparseColumnRef (context -> buf , node -> varno , node -> varattno ,
2357
- context -> root , qualify_col );
2348
+ planner_rt_fetch (node -> varno , context -> root ),
2349
+ qualify_col );
2358
2350
else
2359
2351
{
2360
2352
/* Treat like a Param */
0 commit comments