Re: [PATCH] Lockable views

From: Tatsuo Ishii <ishii(at)sraoss(dot)co(dot)jp>
To: nagata(at)sraoss(dot)co(dot)jp
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: [PATCH] Lockable views
Date: 2017-10-12 04:11:45
Message-ID: 20171012.131145.747993212681315233.t-ishii@sraoss.co.jp
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

>> test=# CREATE VIEW v3 AS SELECT count(*) FROM v1;
>> CREATE VIEW
>> test=# BEGIN;
>> BEGIN
>> test=# LOCK TABLE v3;
>> ERROR: cannot lock view "v3"
>> DETAIL: Views that return aggregate functions are not automatically updatable.
>
> It would be nice if the message would be something like:
>
> DETAIL: Views that return aggregate functions are not lockable
>
>> test=# END;
>> ROLLBACK
>>
>> test=# CREATE FUNCTION fnc() RETURNS trigger AS $$ BEGIN RETURN NEW; END; $$ LANGUAGE plpgsql;
>> CREATE FUNCTION
>> test=# CREATE TRIGGER trg INSTEAD OF INSERT ON v1 FOR EACH ROW EXECUTE PROCEDURE fnc();
>> CREATE TRIGGER
>> test=# BEGIN;
>> BEGIN
>> test=# LOCK TABLE v1;
>> ERROR: cannot lock view "v1"
>> DETAIL: views that have an INSTEAD OF trigger are not lockable
>> test=# END;
>> ROLLBACK
>
> I wonder if we should lock tables in a subquery as well. For example,
>
> create view v1 as select * from t1 where i in (select i from t2);
>
> In this case should we lock t2 as well?

Current the patch ignores t2 in the case above.

So we have options below:

- Leave as it is (ignore tables appearing in a subquery)

- Lock all tables including in a subquery

- Check subquery in the view definition. If there are some tables
involved, emit an error and abort.

The first one might be different from what users expect. There may be
a risk that the second one could cause deadlock. So it seems the third
one seems to be the safest IMO.

Best regards,
--
Tatsuo Ishii
SRA OSS, Inc. Japan
English: http://www.sraoss.co.jp/index_en.php
Japanese:http://www.sraoss.co.jp

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Dilip Kumar 2017-10-12 04:28:25 Re: Proposal: Improve bitmap costing for lossy pages
Previous Message Thomas Munro 2017-10-12 03:04:57 Continuous integration on Windows?