Re: Updatable view columns

Lists: pgsql-hackers
From: Dean Rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)com>
To: PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Updatable view columns
Date: 2013-08-12 14:27:52
Message-ID: CAEZATCULXejsZVq3PvG8RJReyXwdPoZU_Myr6H2DWW5=ioR=NA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Hi,

Attached is a work-in-progress patch to extend auto-updatable views to
support views containing a mix of updatable and non-updatable columns.
This is basically the "columns" part of SQL Feature T111, "Updatable
joins, unions, and columns".

So specifically, views of the following form will now be auto-updatable:

SELECT <column, expression, sub-query or non-SRF>, ...
FROM <single base table or view>
WHERE <arbitrary quals>
[ORDER BY ...]

with the restriction that no window functions, aggregates or
set-returning functions may appear in the view's targetlist (because
otherwise the rewriting process may move them up into quals of the
top-level query where they are not allowed).

Hopefully this will make auto-updatable views much more useful, since
it covers a much wider class of real-world views.

INSERT and UPDATE are supported provided that they do not attempt to
assign to a non-updatable column (which currently means a column that
is not a simple reference to an updatable column of the base
relation). This also means that the view must have at least 1
updatable column for these operations, which is per-spec.

DELETE on the other hand doesn't actually require any updatable
columns, provided the view satisfies all the other updatability
requirements (single base relation, no distinction, grouping, etc...).
This is actually an extension of the spec, which says that DELETE
should only be supported on updatable views with at least 1 updatable
column, but having played around with the code, it seems it would be
an annoying amount of additional code to enforce this restriction, so
I don't see any reason to not just allow it.

Code-wise, aside from the obvious changes needed to the
xxx_is_updatable() functions, the only other code change needed to
support this is in rewriteTargetListIU(). This had code for UPDATE
which would add new dummy targetlist entries for unassigned-to
attributes in the view, similar to expand_targetlist() in preptlist.c.
It now only does this for trigger-updatable views. For auto-updatable
views, it is definitely the wrong thing to do, since it would assign
targetlist entries for all the non-updatable columns. For
rule-updatable views it was not wrong, but I think it was unnecessary,
since the rule will rewrite the query with a different target
relation, which would then get recursively processed. Basically,
adding these dummy targetlist entries is only necessary if the view
relation remains the target after rewriting. That's consistent with
the fact that this code-block was only added in 9.1 to support
triggers on views.

It still needs more testing and doc updates, but otherwise I hope it
will be in reasonable shape for the next commitfest.

Regards,
Dean

Attachment Content-Type Size
updatable-view-cols.v1.patch application/octet-stream 58.0 KB

From: Peter Eisentraut <peter_e(at)gmx(dot)net>
To: Dean Rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)com>
Cc: PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Updatable view columns
Date: 2013-08-22 00:49:41
Message-ID: 1377132581.11715.5.camel@vanquo.pezone.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Mon, 2013-08-12 at 15:27 +0100, Dean Rasheed wrote:
> Attached is a work-in-progress patch to extend auto-updatable views to
> support views containing a mix of updatable and non-updatable columns.
> This is basically the "columns" part of SQL Feature T111, "Updatable
> joins, unions, and columns".

This patch needs to be rebased.


From: Dean Rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)com>
To: Peter Eisentraut <peter_e(at)gmx(dot)net>
Cc: PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Updatable view columns
Date: 2013-08-22 07:33:46
Message-ID: CAEZATCXGTKo5CM5RfM+eyfpE=SqDJkJ6LABOfFYU3LB6-AXvCg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On 22 August 2013 01:49, Peter Eisentraut <peter_e(at)gmx(dot)net> wrote:
> On Mon, 2013-08-12 at 15:27 +0100, Dean Rasheed wrote:
>> Attached is a work-in-progress patch to extend auto-updatable views to
>> support views containing a mix of updatable and non-updatable columns.
>> This is basically the "columns" part of SQL Feature T111, "Updatable
>> joins, unions, and columns".
>
> This patch needs to be rebased.
>

Here's a rebased version, now with updated docs.

Regards,
Dean

Attachment Content-Type Size
updatable-view-cols.v2.patch application/octet-stream 62.4 KB

From: Marko Tiikkaja <marko(at)joh(dot)to>
To: Dean Rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)com>
Cc: Peter Eisentraut <peter_e(at)gmx(dot)net>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Updatable view columns
Date: 2013-09-16 20:14:47
Message-ID: 523766B7.8040007@joh.to
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Hi Dean,

First of all, thanks for working on this!

The patch compiles and applies fine (though with offsets). The feature
is in the SQL standard, and further improves an existing feature.

Some stuff I've spotted and fixed in the attached patch (hope you don't
mind, thought it'd be easier to just fix these rather than describing
them in email):
- Some typos I've spotted in some of the comments
- Fixed escaping of _ in regression tests

Other than these, the patch looks good to me. Will wait for your
thoughts and an updated patch before marking ready for committer.

Regards,
Marko Tiikkaja

Attachment Content-Type Size
updatable_views_typos.patch text/plain 7.7 KB

From: Dean Rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)com>
To: Marko Tiikkaja <marko(at)joh(dot)to>
Cc: Peter Eisentraut <peter_e(at)gmx(dot)net>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Updatable view columns
Date: 2013-09-17 10:53:45
Message-ID: CAEZATCVwuXbvcok4rS+t8MMCQxX1xfBwBRGyP75ZWxah6U=SEg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On 16 September 2013 21:14, Marko Tiikkaja <marko(at)joh(dot)to> wrote:
> Hi Dean,
>
> First of all, thanks for working on this!
>
> The patch compiles and applies fine (though with offsets). The feature is
> in the SQL standard, and further improves an existing feature.
>
> Some stuff I've spotted and fixed in the attached patch (hope you don't
> mind, thought it'd be easier to just fix these rather than describing them
> in email):
> - Some typos I've spotted in some of the comments
> - Fixed escaping of _ in regression tests
>
> Other than these, the patch looks good to me. Will wait for your thoughts
> and an updated patch before marking ready for committer.
>

Thanks for the review. Those changes all look sensible to me.

Here's an updated patch incorporating all your fixes, and rebased to
apply without offsets.

Regards,
Dean

Attachment Content-Type Size
updatable-view-cols.v3.patch application/octet-stream 65.0 KB

From: Marko Tiikkaja <marko(at)joh(dot)to>
To: Dean Rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)com>
Cc: Peter Eisentraut <peter_e(at)gmx(dot)net>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Updatable view columns
Date: 2013-09-17 22:16:19
Message-ID: 5238D4B3.4010809@joh.to
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On 2013-09-17 12:53, Dean Rasheed wrote:
> Thanks for the review. Those changes all look sensible to me.
>
> Here's an updated patch incorporating all your fixes, and rebased to
> apply without offsets.

Looks good to me. Marking this one ready for committer.

Regards,
Marko Tiikkaja


From: Robert Haas <robertmhaas(at)gmail(dot)com>
To: Marko Tiikkaja <marko(at)joh(dot)to>
Cc: Dean Rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)com>, Peter Eisentraut <peter_e(at)gmx(dot)net>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Updatable view columns
Date: 2013-10-18 14:43:03
Message-ID: CA+TgmoZAk1Jix3D3NJHA5bt5UYMPe0az-auxgrhXouXqAeLivw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Tue, Sep 17, 2013 at 6:16 PM, Marko Tiikkaja <marko(at)joh(dot)to> wrote:
> On 2013-09-17 12:53, Dean Rasheed wrote:
>>
>> Thanks for the review. Those changes all look sensible to me.
>>
>> Here's an updated patch incorporating all your fixes, and rebased to
>> apply without offsets.
>
>
> Looks good to me. Marking this one ready for committer.

Committed.

--
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company


From: Dean Rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)com>
To: Robert Haas <robertmhaas(at)gmail(dot)com>
Cc: Marko Tiikkaja <marko(at)joh(dot)to>, Peter Eisentraut <peter_e(at)gmx(dot)net>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Updatable view columns
Date: 2013-10-19 08:48:50
Message-ID: CAEZATCVVKiPsKR+Hs-EG8kva8zN0pLxZpwNkCU4P5-_Kpx1-yw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On 18 October 2013 15:43, Robert Haas <robertmhaas(at)gmail(dot)com> wrote:
>
> Committed.
>

Excellent. Thank you!
And thank you Marko for your thorough review.

Regards,
Dean