Re: BUG #15623: Inconsistent use of default for updatable view

From: Amit Langote <Langote_Amit_f8(at)lab(dot)ntt(dot)co(dot)jp>
To: Dean Rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)com>, Amit Langote <amitlangote09(at)gmail(dot)com>
Cc: Roger Curley <rocurley(at)gmail(dot)com>, pgsql-bugs(at)lists(dot)postgresql(dot)org, PG Bug reporting form <noreply(at)postgresql(dot)org>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: BUG #15623: Inconsistent use of default for updatable view
Date: 2019-02-28 07:46:57
Message-ID: a1e31ca8-717a-094e-b701-0502f7cfb9b7@lab.ntt.co.jp
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs pgsql-hackers

On 2019/02/27 18:37, Dean Rasheed wrote:
> On Tue, 12 Feb 2019 at 10:33, Dean Rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)com> wrote:
>> Here's an updated patch ...
>
> So I pushed that. However, ...
>
> Playing around with it some more, I realised that whilst this appeared
> to fix the reported problem, it exposes another issue which is down to
> the interaction between rewriteTargetListIU() and rewriteValuesRTE()
> --- for an INSERT with a VALUES RTE, rewriteTargetListIU() computes a
> list of target attribute numbers (attrno_list) from the targetlist in
> its original order, which rewriteValuesRTE() then relies on being the
> same length (and in the same order) as each of the lists in the VALUES
> RTE. That's OK for the initial invocation of those functions, but it
> breaks down when they're recursively invoked for auto-updatable views.
>> So actually, I think the right way to fix this is to give up trying to
> compute attrno_list in rewriteTargetListIU(), and have
> rewriteValuesRTE() work out the attribute assignments itself for each
> column of the VALUES RTE by examining the rewritten targetlist. That
> looks to be quite straightforward, and results in a cleaner separation
> of logic between the 2 functions, per the attached patch.

+1. Only rewriteValuesRTE needs to use that information, so it's better
to teach it to figure it by itself.

> I think that rewriteValuesRTE() should only ever see DEFAULT items for
> columns that are simple assignments to columns of the target relation,
> so it only needs to work out the target attribute numbers for TLEs
> that contain simple Vars referring to the VALUES RTE. Any DEFAULT seen
> in a column not matching that would be an error, but actually I think
> such a thing ought to be a "can't happen" error because of the prior
> checks during parse analysis, so I've used elog() to report if this
> does happen.

+ if (attrno == 0)
+ elog(ERROR, "Cannot set value in column %d to
DEFAULT", i);

Maybe: s/Cannot/cannot/g

+ Assert(list_length(sublist) == numattrs);

Isn't this Assert useless, because we're setting numattrs to
list_length(<first-sublist>) and transformInsertStmt ensures that all
sublists are same length?

Thanks,
Amit

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Haribabu Kommi 2019-02-28 08:00:12 Re: BUG #15660: pg_dump memory leaks when dumping LOBs
Previous Message Michael Paquier 2019-02-28 02:05:19 Re: BUG #15659: missing comment "change requires restart" in postgresql.conf for parameter "data_sync_retry"

Browse pgsql-hackers by date

  From Date Subject
Next Message Sergei Kornilov 2019-02-28 07:50:28 Re: reloption to prevent VACUUM from truncating empty pages at the end of relation
Previous Message Haribabu Kommi 2019-02-28 07:44:21 Re: Drop type "smgr"?