Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iAAKH-00065k-NK for pgsql-hackers@arkaria.postgresql.org; Tue, 17 Sep 2019 10:03:13 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1iAAKG-0000qq-L2 for pgsql-hackers@arkaria.postgresql.org; Tue, 17 Sep 2019 10:03:12 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iAAKG-0000qi-9W for pgsql-hackers@lists.postgresql.org; Tue, 17 Sep 2019 10:03:12 +0000 Received: from sraihb2.sra.co.jp ([202.32.10.6]) by makus.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1iAAKD-0004GN-Az for pgsql-hackers@postgresql.org; Tue, 17 Sep 2019 10:03:11 +0000 Received: from srascf.sra.co.jp (srascf [133.137.8.80]) by sraihb2.sra.co.jp (Postfix) with ESMTP id 483A02A15D8 for ; Tue, 17 Sep 2019 19:03:07 +0900 (JST) Received: from srascb.sra.co.jp (unknown [133.137.8.65]) by srascf.sra.co.jp with smtp id 69c7_1a8f_6f395d15_c07b_400c_9364_07f2a7263feb; Tue, 17 Sep 2019 19:03:06 +0900 Received: from sranhm.sra.co.jp (osspc25 [133.137.174.97]) by srascb.sra.co.jp (Postfix) with ESMTP id 2B7902D6942 for ; Tue, 17 Sep 2019 19:03:07 +0900 (JST) Received: from yugon-CFSV7-1 (dhcp-175-183.sra.co.jp [133.137.175.183]) by sranhm.sra.co.jp (Postfix) with SMTP id EAFB5A11D8; Tue, 17 Sep 2019 19:03:06 +0900 (JST) Date: Tue, 17 Sep 2019 19:02:40 +0900 From: Yugo Nagata To: Paul Draper Cc: pgsql-hackers@postgresql.org, kgrittn@gmail.com, thomas.munro@gmail.com Subject: Re: Implementing Incremental View Maintenance Message-Id: <20190917190240.f331029ccca7ba8af6bf08e8@sraoss.co.jp> In-Reply-To: References: X-Mailer: Sylpheed 3.5.1 (GTK+ 2.24.32; x86_64-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Hi Paul, Thank you for your suggestion. On Sun, 15 Sep 2019 11:52:22 -0600 Paul Draper wrote: > As I understand it, the current patch performs immediate IVM using AFTER > STATEMENT trigger transition tables. > > However, multiple tables can be modified *before* AFTER STATEMENT triggers > are fired. > > CREATE TABLE example1 (a int); > CREATE TABLE example2 (a int); > > CREATE INCREMENTAL MATERIALIZED VIEW mv AS > SELECT example1.a, example2.a > FROM example1 JOIN example2 ON a; > > WITH > insert1 AS (INSERT INTO example1 VALUES (1)), > insert2 AS (INSERT INTO example2 VALUES (1)) > SELECT NULL; > > Changes to example1 are visible in an AFTER STATEMENT trigger on example2, > and vice versa. Would this not result in the (1, 1) tuple being > "double-counted"? > > IVM needs to either: > > (1) Evaluate deltas "serially' (e.g. EACH ROW triggers) > > (2) Have simultaneous access to multiple deltas: > delta_mv = example1 x delta_example2 + example2 x delta_example1 - > delta_example1 x delta_example2 > > This latter method is the "logged" approach that has been discussed for > deferred evaluation. > > tl;dr It seems that AFTER STATEMENT triggers required a deferred-like > implementation anyway. You are right, the latest patch doesn't support the situation where multiple tables are modified in a query. I noticed this when working on self-join, which also virtually need to handle multiple table modification. I am now working on this issue and the next patch will enable to handle this situation. I plan to submit the patch during this month. Roughly speaking, in the new implementation, AFTER STATEMENT triggers are used to collect information of modified table and its changes (= transition tables), and then the only last trigger updates the view. This will avoid the double-counting. I think this implementation also would be a base of deferred approach implementation in future where "logs" are used instead of transition tables. Regards, Yugo Nagata -- Yugo Nagata