Re: missing locking in at least INSERT INTO view WITH CHECK

From: Dean Rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)com>
To: Andres Freund <andres(at)2ndquadrant(dot)com>
Cc: PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: missing locking in at least INSERT INTO view WITH CHECK
Date: 2013-10-23 19:51:27
Message-ID: CAEZATCXk1sJoydL3V+BxC8mrTkA5Y3CFjm2t6qrvbnpoa8nvzA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On 23 October 2013 02:18, Andres Freund <andres(at)2ndquadrant(dot)com> wrote:
> Hi,
>
> Using the same debugging hack^Wpatch (0001) as in the matview patch
> (0002) an hour or so ago I noticed that INSERT INTO view WITH CHECK
> doesn't lock the underlying relations properly.
>
> I've attached a sort-of-working (0003) hack but I really doubt it's the
> correct approach, I don't really know enough about that area of the
> code.
> This looks like something that needs to be fixed.
>

Hmm, my first thought is that rewriteTargetView() should be calling
AcquireRewriteLocks() on viewquery, before doing too much with it.
There may be sub-queries in viewquery's quals (and also now in its
targetlist) and I don't think the relations referred to by those
sub-queries are getting locked.

I think that any code that is doing anything significant with a rule
action's query needs to think about locking the query's relations. I
did a quick search and the only suspicious code I found was the
matview and auto-updatable view code.

Regards,
Dean

> Also attached is 0004 which just adds a heap_lock() around a newly
> created temporary table in the matview code which shouldn't be required
> for correctness but gives warm and fuzzy feelings as well as less
> debugging noise.
>
> Wouldn't it be a good idea to tack such WARNINGs (in a proper and clean
> form) to index_open (checking the underlying relation is locked),
> relation_open(..., NoLock) (checking the relation has previously been
> locked) and maybe RelationIdGetRelation() when cassert is enabled? ISTM
> we frequently had bugs around this.
>
> Greetings,
>
> Andres Freund
>
> --
> Andres Freund http://www.2ndQuadrant.com/
> PostgreSQL Development, 24x7 Support, Training & Services
>
>
> --
> Sent via pgsql-hackers mailing list (pgsql-hackers(at)postgresql(dot)org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-hackers

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Jeff Janes 2013-10-23 20:07:51 Re: Add min and max execute statement time in pg_stat_statement
Previous Message Mike Blackwell 2013-10-23 19:19:38 Re: stats for network traffic WIP