Skip to content

Commit e25c4b3

Browse files
committed
Include TableFunc references when computing expression dependencies.
The TableFunc node (i.e., XMLTABLE) includes type and collation OIDs that might not be referenced anywhere else in the expression tree, so they need to be accounted for when extracting dependencies. Fortunately, the practical effects of this are limited, since (a) it's somewhat unlikely that people would be extracting columns of non-builtin types from an XML document, and (b) in many scenarios, the query would contain other references to such types, or functions depending on them. However, it's not hard to construct examples wherein the existing code lets one drop a type used in XMLTABLE and thereby break a view. This is evidently an original oversight in the XMLTABLE patch, so back-patch to v10 where that came in. Discussion: https://postgr.es/m/18427.1573508501@sss.pgh.pa.us
1 parent c443e3c commit e25c4b3

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

src/backend/catalog/dependency.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2027,6 +2027,28 @@ find_expr_references_walker(Node *node,
20272027
context->addrs);
20282028
}
20292029
}
2030+
else if (IsA(node, TableFunc))
2031+
{
2032+
TableFunc *tf = (TableFunc *) node;
2033+
ListCell *ct;
2034+
2035+
/*
2036+
* Add refs for the datatypes and collations used in the TableFunc.
2037+
*/
2038+
foreach(ct, tf->coltypes)
2039+
{
2040+
add_object_address(OCLASS_TYPE, lfirst_oid(ct), 0,
2041+
context->addrs);
2042+
}
2043+
foreach(ct, tf->colcollations)
2044+
{
2045+
Oid collid = lfirst_oid(ct);
2046+
2047+
if (OidIsValid(collid) && collid != DEFAULT_COLLATION_OID)
2048+
add_object_address(OCLASS_COLLATION, collid, 0,
2049+
context->addrs);
2050+
}
2051+
}
20302052
else if (IsA(node, TableSampleClause))
20312053
{
20322054
TableSampleClause *tsc = (TableSampleClause *) node;

0 commit comments

Comments
 (0)