@@ -1835,8 +1835,17 @@ recordDependencyOnSingleRelExpr(const ObjectAddress *depender,
1835
1835
* the datatype. However we do need a type dependency if there is no such
1836
1836
* indirect dependency, as for example in Const and CoerceToDomain nodes.
1837
1837
*
1838
- * Similarly, we don't need to create dependencies on collations except where
1839
- * the collation is being freshly introduced to the expression.
1838
+ * Collations are handled primarily by recording the inputcollid's of node
1839
+ * types that have them, as those are the ones that are semantically
1840
+ * significant during expression evaluation. We also record the collation of
1841
+ * CollateExpr nodes, since those will be needed to print such nodes even if
1842
+ * they don't really affect semantics. Collations of leaf nodes such as Vars
1843
+ * can be ignored on the grounds that if they're not default, they came from
1844
+ * the referenced object (e.g., a table column), so the dependency on that
1845
+ * object is enough. (Note: in a post-const-folding expression tree, a
1846
+ * CollateExpr's collation could have been absorbed into a Const or
1847
+ * RelabelType node. While ruleutils.c prints such collations for clarity,
1848
+ * we may ignore them here as they have no semantic effect.)
1840
1849
*/
1841
1850
static bool
1842
1851
find_expr_references_walker (Node * node ,
@@ -1876,29 +1885,6 @@ find_expr_references_walker(Node *node,
1876
1885
/* If it's a plain relation, reference this column */
1877
1886
add_object_address (OCLASS_CLASS , rte -> relid , var -> varattno ,
1878
1887
context -> addrs );
1879
-
1880
- /* Top-level collation if valid */
1881
- if (OidIsValid (var -> varcollid ))
1882
- add_object_address (OCLASS_COLLATION , var -> varcollid , 0 ,
1883
- context -> addrs );
1884
- /* Otherwise, it may be a type with internal collations */
1885
- else if (var -> vartype >= FirstNormalObjectId )
1886
- {
1887
- List * collations ;
1888
- ListCell * lc ;
1889
-
1890
- collations = GetTypeCollations (var -> vartype );
1891
-
1892
- foreach (lc , collations )
1893
- {
1894
- Oid coll = lfirst_oid (lc );
1895
-
1896
- if (OidIsValid (coll ))
1897
- add_object_address (OCLASS_COLLATION ,
1898
- lfirst_oid (lc ), 0 ,
1899
- context -> addrs );
1900
- }
1901
- }
1902
1888
}
1903
1889
1904
1890
/*
@@ -1920,15 +1906,6 @@ find_expr_references_walker(Node *node,
1920
1906
add_object_address (OCLASS_TYPE , con -> consttype , 0 ,
1921
1907
context -> addrs );
1922
1908
1923
- /*
1924
- * We must also depend on the constant's collation: it could be
1925
- * different from the datatype's, if a CollateExpr was const-folded to
1926
- * a simple constant.
1927
- */
1928
- if (OidIsValid (con -> constcollid ))
1929
- add_object_address (OCLASS_COLLATION , con -> constcollid , 0 ,
1930
- context -> addrs );
1931
-
1932
1909
/*
1933
1910
* If it's a regclass or similar literal referring to an existing
1934
1911
* object, add a reference to that object. (Currently, only the
@@ -2013,17 +1990,16 @@ find_expr_references_walker(Node *node,
2013
1990
/* A parameter must depend on the parameter's datatype */
2014
1991
add_object_address (OCLASS_TYPE , param -> paramtype , 0 ,
2015
1992
context -> addrs );
2016
- /* and its collation, just as for Consts */
2017
- if (OidIsValid (param -> paramcollid ))
2018
- add_object_address (OCLASS_COLLATION , param -> paramcollid , 0 ,
2019
- context -> addrs );
2020
1993
}
2021
1994
else if (IsA (node , FuncExpr ))
2022
1995
{
2023
1996
FuncExpr * funcexpr = (FuncExpr * ) node ;
2024
1997
2025
1998
add_object_address (OCLASS_PROC , funcexpr -> funcid , 0 ,
2026
1999
context -> addrs );
2000
+ if (OidIsValid (funcexpr -> inputcollid ))
2001
+ add_object_address (OCLASS_COLLATION , funcexpr -> inputcollid , 0 ,
2002
+ context -> addrs );
2027
2003
/* fall through to examine arguments */
2028
2004
}
2029
2005
else if (IsA (node , OpExpr ))
@@ -2032,6 +2008,9 @@ find_expr_references_walker(Node *node,
2032
2008
2033
2009
add_object_address (OCLASS_OPERATOR , opexpr -> opno , 0 ,
2034
2010
context -> addrs );
2011
+ if (OidIsValid (opexpr -> inputcollid ))
2012
+ add_object_address (OCLASS_COLLATION , opexpr -> inputcollid , 0 ,
2013
+ context -> addrs );
2035
2014
/* fall through to examine arguments */
2036
2015
}
2037
2016
else if (IsA (node , DistinctExpr ))
@@ -2040,6 +2019,9 @@ find_expr_references_walker(Node *node,
2040
2019
2041
2020
add_object_address (OCLASS_OPERATOR , distinctexpr -> opno , 0 ,
2042
2021
context -> addrs );
2022
+ if (OidIsValid (distinctexpr -> inputcollid ))
2023
+ add_object_address (OCLASS_COLLATION , distinctexpr -> inputcollid , 0 ,
2024
+ context -> addrs );
2043
2025
/* fall through to examine arguments */
2044
2026
}
2045
2027
else if (IsA (node , NullIfExpr ))
@@ -2048,6 +2030,9 @@ find_expr_references_walker(Node *node,
2048
2030
2049
2031
add_object_address (OCLASS_OPERATOR , nullifexpr -> opno , 0 ,
2050
2032
context -> addrs );
2033
+ if (OidIsValid (nullifexpr -> inputcollid ))
2034
+ add_object_address (OCLASS_COLLATION , nullifexpr -> inputcollid , 0 ,
2035
+ context -> addrs );
2051
2036
/* fall through to examine arguments */
2052
2037
}
2053
2038
else if (IsA (node , ScalarArrayOpExpr ))
@@ -2056,6 +2041,9 @@ find_expr_references_walker(Node *node,
2056
2041
2057
2042
add_object_address (OCLASS_OPERATOR , opexpr -> opno , 0 ,
2058
2043
context -> addrs );
2044
+ if (OidIsValid (opexpr -> inputcollid ))
2045
+ add_object_address (OCLASS_COLLATION , opexpr -> inputcollid , 0 ,
2046
+ context -> addrs );
2059
2047
/* fall through to examine arguments */
2060
2048
}
2061
2049
else if (IsA (node , Aggref ))
@@ -2064,6 +2052,9 @@ find_expr_references_walker(Node *node,
2064
2052
2065
2053
add_object_address (OCLASS_PROC , aggref -> aggfnoid , 0 ,
2066
2054
context -> addrs );
2055
+ if (OidIsValid (aggref -> inputcollid ))
2056
+ add_object_address (OCLASS_COLLATION , aggref -> inputcollid , 0 ,
2057
+ context -> addrs );
2067
2058
/* fall through to examine arguments */
2068
2059
}
2069
2060
else if (IsA (node , WindowFunc ))
@@ -2072,6 +2063,9 @@ find_expr_references_walker(Node *node,
2072
2063
2073
2064
add_object_address (OCLASS_PROC , wfunc -> winfnoid , 0 ,
2074
2065
context -> addrs );
2066
+ if (OidIsValid (wfunc -> inputcollid ))
2067
+ add_object_address (OCLASS_COLLATION , wfunc -> inputcollid , 0 ,
2068
+ context -> addrs );
2075
2069
/* fall through to examine arguments */
2076
2070
}
2077
2071
else if (IsA (node , SubscriptingRef ))
@@ -2116,10 +2110,6 @@ find_expr_references_walker(Node *node,
2116
2110
else
2117
2111
add_object_address (OCLASS_TYPE , fselect -> resulttype , 0 ,
2118
2112
context -> addrs );
2119
- /* the collation might not be referenced anywhere else, either */
2120
- if (OidIsValid (fselect -> resultcollid ))
2121
- add_object_address (OCLASS_COLLATION , fselect -> resultcollid , 0 ,
2122
- context -> addrs );
2123
2113
}
2124
2114
else if (IsA (node , FieldStore ))
2125
2115
{
@@ -2146,10 +2136,6 @@ find_expr_references_walker(Node *node,
2146
2136
/* since there is no function dependency, need to depend on type */
2147
2137
add_object_address (OCLASS_TYPE , relab -> resulttype , 0 ,
2148
2138
context -> addrs );
2149
- /* the collation might not be referenced anywhere else, either */
2150
- if (OidIsValid (relab -> resultcollid ))
2151
- add_object_address (OCLASS_COLLATION , relab -> resultcollid , 0 ,
2152
- context -> addrs );
2153
2139
}
2154
2140
else if (IsA (node , CoerceViaIO ))
2155
2141
{
@@ -2158,10 +2144,6 @@ find_expr_references_walker(Node *node,
2158
2144
/* since there is no exposed function, need to depend on type */
2159
2145
add_object_address (OCLASS_TYPE , iocoerce -> resulttype , 0 ,
2160
2146
context -> addrs );
2161
- /* the collation might not be referenced anywhere else, either */
2162
- if (OidIsValid (iocoerce -> resultcollid ))
2163
- add_object_address (OCLASS_COLLATION , iocoerce -> resultcollid , 0 ,
2164
- context -> addrs );
2165
2147
}
2166
2148
else if (IsA (node , ArrayCoerceExpr ))
2167
2149
{
@@ -2170,10 +2152,6 @@ find_expr_references_walker(Node *node,
2170
2152
/* as above, depend on type */
2171
2153
add_object_address (OCLASS_TYPE , acoerce -> resulttype , 0 ,
2172
2154
context -> addrs );
2173
- /* the collation might not be referenced anywhere else, either */
2174
- if (OidIsValid (acoerce -> resultcollid ))
2175
- add_object_address (OCLASS_COLLATION , acoerce -> resultcollid , 0 ,
2176
- context -> addrs );
2177
2155
/* fall through to examine arguments */
2178
2156
}
2179
2157
else if (IsA (node , ConvertRowtypeExpr ))
@@ -2213,6 +2191,24 @@ find_expr_references_walker(Node *node,
2213
2191
add_object_address (OCLASS_OPFAMILY , lfirst_oid (l ), 0 ,
2214
2192
context -> addrs );
2215
2193
}
2194
+ foreach (l , rcexpr -> inputcollids )
2195
+ {
2196
+ Oid inputcollid = lfirst_oid (l );
2197
+
2198
+ if (OidIsValid (inputcollid ))
2199
+ add_object_address (OCLASS_COLLATION , inputcollid , 0 ,
2200
+ context -> addrs );
2201
+ }
2202
+ /* fall through to examine arguments */
2203
+ }
2204
+ else if (IsA (node , MinMaxExpr ))
2205
+ {
2206
+ MinMaxExpr * mmexpr = (MinMaxExpr * ) node ;
2207
+
2208
+ /* minmaxtype will match one of the inputs, so no need to record it */
2209
+ if (OidIsValid (mmexpr -> inputcollid ))
2210
+ add_object_address (OCLASS_COLLATION , mmexpr -> inputcollid , 0 ,
2211
+ context -> addrs );
2216
2212
/* fall through to examine arguments */
2217
2213
}
2218
2214
else if (IsA (node , CoerceToDomain ))
0 commit comments