diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2012-06-30 16:43:58 -0400 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2012-06-30 16:45:27 -0400 |
commit | 52336a47024e8212be619fcfe28d384777ed7b72 (patch) | |
tree | cdcbfdabab860e907ad11556f4fa9a08b4a9b01c /src/include | |
parent | 31fff64ef522abeda9c26c0be7ffee32d27a1b3c (diff) | |
download | postgresql-52336a47024e8212be619fcfe28d384777ed7b72.tar.gz postgresql-52336a47024e8212be619fcfe28d384777ed7b72.zip |
Prevent CREATE TABLE LIKE/INHERITS from (mis) copying whole-row Vars.
If a CHECK constraint or index definition contained a whole-row Var (that
is, "table.*"), an attempt to copy that definition via CREATE TABLE LIKE or
table inheritance produced incorrect results: the copied Var still claimed
to have the rowtype of the source table, rather than the created table.
For the LIKE case, it seems reasonable to just throw error for this
situation, since the point of LIKE is that the new table is not permanently
coupled to the old, so there's no reason to assume its rowtype will stay
compatible. In the inheritance case, we should ideally allow such
constraints, but doing so will require nontrivial refactoring of CREATE
TABLE processing (because we'd need to know the OID of the new table's
rowtype before we adjust inherited CHECK constraints). In view of the lack
of previous complaints, that doesn't seem worth the risk in a back-patched
bug fix, so just make it throw error for the inheritance case as well.
Along the way, replace change_varattnos_of_a_node() with a more robust
function map_variable_attnos(), which is capable of being extended to
handle insertion of ConvertRowtypeExpr whenever we get around to fixing
the inheritance case nicely, and in the meantime it returns a failure
indication to the caller so that a helpful message with some context can be
thrown. Also, this code will do the right thing with subselects (if we
ever allow them in CHECK or indexes), and it range-checks varattnos before
using them to index into the map array.
Per report from Sergey Konoplev. Back-patch to all supported branches.
Diffstat (limited to 'src/include')
-rw-r--r-- | src/include/commands/tablecmds.h | 4 | ||||
-rw-r--r-- | src/include/rewrite/rewriteManip.h | 5 |
2 files changed, 5 insertions, 4 deletions
diff --git a/src/include/commands/tablecmds.h b/src/include/commands/tablecmds.h index 9ceb086f681..15d4713cec1 100644 --- a/src/include/commands/tablecmds.h +++ b/src/include/commands/tablecmds.h @@ -61,10 +61,6 @@ extern void find_composite_type_dependencies(Oid typeOid, extern void check_of_type(HeapTuple typetuple); -extern AttrNumber *varattnos_map(TupleDesc olddesc, TupleDesc newdesc); -extern AttrNumber *varattnos_map_schema(TupleDesc old, List *schema); -extern void change_varattnos_of_a_node(Node *node, const AttrNumber *newattno); - extern void register_on_commit_action(Oid relid, OnCommitAction action); extern void remove_on_commit_action(Oid relid); diff --git a/src/include/rewrite/rewriteManip.h b/src/include/rewrite/rewriteManip.h index 72261878492..6f57b37b814 100644 --- a/src/include/rewrite/rewriteManip.h +++ b/src/include/rewrite/rewriteManip.h @@ -65,6 +65,11 @@ extern Node *replace_rte_variables(Node *node, extern Node *replace_rte_variables_mutator(Node *node, replace_rte_variables_context *context); +extern Node *map_variable_attnos(Node *node, + int target_varno, int sublevels_up, + const AttrNumber *attno_map, int map_length, + bool *found_whole_row); + extern Node *ResolveNew(Node *node, int target_varno, int sublevels_up, RangeTblEntry *target_rte, List *targetlist, int event, int update_varno, |