pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Kevin Grittner <kgrittn@ymail.com>
To: t.katsumata1122@gmail.com <t.katsumata1122@gmail.com>
To: Michael Paquier <michael.paquier@gmail.com>
Cc: pgsql-hackers@postgresql.org <pgsql-hackers@postgresql.org>
Subject: Re: [BUGS] BUG #8542: Materialized View with another column_name does not work?
Date: Mon, 4 Nov 2013 12:53:32 -0800 (PST)
Message-ID: <1383598412.78837.YahooMailNeo@web162901.mail.bf1.yahoo.com> (raw)
In-Reply-To: <1383293807.9149.YahooMailNeo@web162904.mail.bf1.yahoo.com>
References: <E1VYBzB-0004BW-K6@wrigleys.postgresql.org>
	<1383258177.17099.YahooMailNeo@web162903.mail.bf1.yahoo.com>
	<CAB7nPqSaCFY8HqrLhUJgLmGJxfzDuMtP+Kx0SUUraZp5Mrkw8g@mail.gmail.com>
	<1383293807.9149.YahooMailNeo@web162904.mail.bf1.yahoo.com>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-hackers>

Kevin Grittner <kgrittn@ymail.com> wrote:
> Michael Paquier <michael.paquier@gmail.com> wrote:
>
>> I am not sure that adding a boolean flag introducing a concept
>> related to matview inside checkRuleResultList is the best
>> approach to solve that. checkRuleResultList is something related
>> only to rules, and has nothing related to matviews in it yet.
>
> Well, I was tempted to keep that concept in DefineQueryRewrite()
> where the call is made, by calling  the new bool something like
> requireColumnNameMatch and not having checkRuleResultList()
> continue to use isSelect for that purpose at all.
> DefineQueryRewrite() already references RELKIND_RELATION once,
> RELKIND_MATVIEW twice, and RELKIND_VIEW three times, so it would
> hardly be introducing a new concept there.

Upon reflection, that seemed to be cleaner.  Pushed fix that way. 
Not much of a change from the previously posted patch, but attached
here in case anyone wants to argue against this approach.

Thanks for the report!

--
Kevin Grittner
EDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company=

-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

Attachments:

matview-column-names-fix-v2.patch (text/x-diff, 5.2K) download *** a/src/backend/rewrite/rewriteDefine.c --- b/src/backend/rewrite/rewriteDefine.c *************** *** 44,50 **** static void checkRuleResultList(List *targetList, TupleDesc resultDesc, ! bool isSelect); static bool setRuleCheckAsUser_walker(Node *node, Oid *context); static void setRuleCheckAsUser_Query(Query *qry, Oid userid); --- 44,50 ---- static void checkRuleResultList(List *targetList, TupleDesc resultDesc, ! bool isSelect, bool requireColumnNameMatch); static bool setRuleCheckAsUser_walker(Node *node, Oid *context); static void setRuleCheckAsUser_Query(Query *qry, Oid userid); *************** *** 355,361 **** DefineQueryRewrite(char *rulename, */ checkRuleResultList(query->targetList, RelationGetDescr(event_relation), ! true); /* * ... there must not be another ON SELECT rule already ... --- 355,363 ---- */ checkRuleResultList(query->targetList, RelationGetDescr(event_relation), ! true, ! event_relation->rd_rel->relkind != ! RELKIND_MATVIEW); /* * ... there must not be another ON SELECT rule already ... *************** *** 484,490 **** DefineQueryRewrite(char *rulename, errmsg("RETURNING lists are not supported in non-INSTEAD rules"))); checkRuleResultList(query->returningList, RelationGetDescr(event_relation), ! false); } } --- 486,492 ---- errmsg("RETURNING lists are not supported in non-INSTEAD rules"))); checkRuleResultList(query->returningList, RelationGetDescr(event_relation), ! false, false); } } *************** *** 613,627 **** DefineQueryRewrite(char *rulename, * Verify that targetList produces output compatible with a tupledesc * * The targetList might be either a SELECT targetlist, or a RETURNING list; ! * isSelect tells which. (This is mostly used for choosing error messages, ! * but also we don't enforce column name matching for RETURNING.) */ static void ! checkRuleResultList(List *targetList, TupleDesc resultDesc, bool isSelect) { ListCell *tllist; int i; i = 0; foreach(tllist, targetList) { --- 615,634 ---- * Verify that targetList produces output compatible with a tupledesc * * The targetList might be either a SELECT targetlist, or a RETURNING list; ! * isSelect tells which. This is used for choosing error messages. ! * ! * A SELECT targetlist may optionally require that column names match. */ static void ! checkRuleResultList(List *targetList, TupleDesc resultDesc, bool isSelect, ! bool requireColumnNameMatch) { ListCell *tllist; int i; + /* Only a SELECT may require a column name match. */ + Assert(isSelect || !requireColumnNameMatch); + i = 0; foreach(tllist, targetList) { *************** *** 657,663 **** checkRuleResultList(List *targetList, TupleDesc resultDesc, bool isSelect) (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), errmsg("cannot convert relation containing dropped columns to view"))); ! if (isSelect && strcmp(tle->resname, attname) != 0) ereport(ERROR, (errcode(ERRCODE_INVALID_OBJECT_DEFINITION), errmsg("SELECT rule's target entry %d has different column name from \"%s\"", i, attname))); --- 664,670 ---- (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), errmsg("cannot convert relation containing dropped columns to view"))); ! if (requireColumnNameMatch && strcmp(tle->resname, attname) != 0) ereport(ERROR, (errcode(ERRCODE_INVALID_OBJECT_DEFINITION), errmsg("SELECT rule's target entry %d has different column name from \"%s\"", i, attname))); *** a/src/test/regress/expected/matview.out --- b/src/test/regress/expected/matview.out *************** *** 450,452 **** SELECT * FROM boxmv ORDER BY id; --- 450,475 ---- DROP TABLE boxes CASCADE; NOTICE: drop cascades to materialized view boxmv + -- make sure that column names are handled correctly + CREATE TABLE v (i int, j int); + CREATE MATERIALIZED VIEW mv_v (ii) AS SELECT i, j AS jj FROM v; + ALTER TABLE v RENAME COLUMN i TO x; + INSERT INTO v values (1, 2); + CREATE UNIQUE INDEX mv_v_ii ON mv_v (ii); + REFRESH MATERIALIZED VIEW mv_v; + UPDATE v SET j = 3 WHERE x = 1; + REFRESH MATERIALIZED VIEW CONCURRENTLY mv_v; + SELECT * FROM v; + x | j + ---+--- + 1 | 3 + (1 row) + + SELECT * FROM mv_v; + ii | jj + ----+---- + 1 | 3 + (1 row) + + DROP TABLE v CASCADE; + NOTICE: drop cascades to materialized view mv_v *** a/src/test/regress/sql/matview.sql --- b/src/test/regress/sql/matview.sql *************** *** 173,175 **** UPDATE boxes SET b = '(2,2),(1,1)' WHERE id = 2; --- 173,188 ---- REFRESH MATERIALIZED VIEW CONCURRENTLY boxmv; SELECT * FROM boxmv ORDER BY id; DROP TABLE boxes CASCADE; + + -- make sure that column names are handled correctly + CREATE TABLE v (i int, j int); + CREATE MATERIALIZED VIEW mv_v (ii) AS SELECT i, j AS jj FROM v; + ALTER TABLE v RENAME COLUMN i TO x; + INSERT INTO v values (1, 2); + CREATE UNIQUE INDEX mv_v_ii ON mv_v (ii); + REFRESH MATERIALIZED VIEW mv_v; + UPDATE v SET j = 3 WHERE x = 1; + REFRESH MATERIALIZED VIEW CONCURRENTLY mv_v; + SELECT * FROM v; + SELECT * FROM mv_v; + DROP TABLE v CASCADE;

view thread (9+ messages)

Message-ID: <1383598412.78837.YahooMailNeo@web162901.mail.bf1.yahoo.com>
Permalink:  ../1383598412.78837.YahooMailNeo@web162901.mail.bf1.yahoo.com/
Also on:    postgresql.org/message-id/1383598412.78837.YahooMailNeo@web162901.mail.bf1.yahoo.com

 ·  · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-bugs@postgresql.org
  Cc: kgrittn@ymail.com, t.katsumata1122@gmail.com, michael.paquier@gmail.com, pgsql-hackers@postgresql.org
  Subject: Re: [BUGS] BUG #8542: Materialized View with another column_name does not work?
  In-Reply-To: <1383598412.78837.YahooMailNeo@web162901.mail.bf1.yahoo.com>
  References: <E1VYBzB-0004BW-K6@wrigleys.postgresql.org> <1383258177.17099.YahooMailNeo@web162903.mail.bf1.yahoo.com> <CAB7nPqSaCFY8HqrLhUJgLmGJxfzDuMtP+Kx0SUUraZp5Mrkw8g@mail.gmail.com> <1383293807.9149.YahooMailNeo@web162904.mail.bf1.yahoo.com> <1383598412.78837.YahooMailNeo@web162901.mail.bf1.yahoo.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox