From 9619fdca106149d9e7bae5db3977435f8ce5f0c2 Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Wed, 24 Oct 2012 14:54:07 -0400 Subject: Prevent parser from believing that views have system columns. Views should not have any pg_attribute entries for system columns. However, we forgot to remove such entries when converting a table to a view. This could lead to crashes later on, if someone attempted to reference such a column, as reported by Kohei KaiGai. This problem is corrected properly in HEAD (by removing the pg_attribute entries during conversion), but in the back branches we need to defend against existing mis-converted views. This fix costs us an extra syscache lookup per system column reference, which is annoying but probably not really measurable in the big scheme of things. --- src/backend/parser/parse_relation.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'src/backend/parser/parse_relation.c') diff --git a/src/backend/parser/parse_relation.c b/src/backend/parser/parse_relation.c index 1d0fc82bba2..101637cec6c 100644 --- a/src/backend/parser/parse_relation.c +++ b/src/backend/parser/parse_relation.c @@ -501,10 +501,17 @@ scanRTEForColumn(ParseState *pstate, RangeTblEntry *rte, char *colname, attnum = specialAttNum(colname); if (attnum != InvalidAttrNumber) { - /* now check to see if column actually is defined */ + /* + * Now check to see if column actually is defined. Because of + * an ancient oversight in DefineQueryRewrite, it's possible that + * pg_attribute contains entries for system columns for a view, + * even though views should not have such --- so we also check + * the relkind. This kluge will not be needed in 9.3 and later. + */ if (SearchSysCacheExists2(ATTNUM, ObjectIdGetDatum(rte->relid), - Int16GetDatum(attnum))) + Int16GetDatum(attnum)) && + get_rel_relkind(rte->relid) != RELKIND_VIEW) { var = make_var(pstate, rte, attnum, location); /* Require read access to the column */ -- cgit v1.2.3