Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eC8I8-0001dB-7j for pgsql-general@arkaria.postgresql.org; Tue, 07 Nov 2017 18:08:04 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1eC8I7-00008t-M5 for pgsql-general@arkaria.postgresql.org; Tue, 07 Nov 2017 18:08:03 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1eC8I7-00008c-14 for pgsql-general@postgresql.org; Tue, 07 Nov 2017 18:08:03 +0000 Received: from hogranch.com ([75.101.82.47]) by magus.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eC8I2-0000yA-C9 for pgsql-general@postgresql.org; Tue, 07 Nov 2017 18:08:02 +0000 Received: from [192.168.0.2] (porker [192.168.0.2]) by hogranch.com (8.11.6/8.11.6) with ESMTP id vA7I7jN15176 for ; Tue, 7 Nov 2017 10:07:48 -0800 Subject: Re: Incremental refresh - Materialized view To: pgsql-general@postgresql.org References: From: John R Pierce Message-ID: <1068317d-dc30-d9bc-1f2f-c8ea841f99dc@hogranch.com> Date: Tue, 7 Nov 2017 10:07:40 -0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.4.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-US X-HawgScanner-Information: Please contact the ISP for more information X-HawgScanner: Found to be clean List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-general Precedence: bulk Sender: pgsql-general-owner@postgresql.org On 11/6/2017 11:34 PM, Krithika Venkatesh wrote: > Materialized view log is one of the feature in oracle. It creates a > log in which the changes made to the table are recorded. This log is > required for an asynchronous materialized view that is refreshed > incrementally. > > I read in the below link about incrementally refreshing the > materialized view in postgresql: > > https://medium.com/@hariprasathnallsamy/postgresql-materialized-view-incremental-refresh-44d1ca742599 > > Can someone let me how to do incremental refresh using Write Ahead Log I note that bloggers sample code on github no longer exists.m   I suspect it was half baked, and ran into intractable problems. to do what you want, you would need to implement logical decoding [1] of the WAL stream,  you would need to 'understand' the views completely so you can tell if a given tuple update affects one of your views or not (relatively simple for a view which is just `select fields from table where simplecondition`, not so easy for a view which is a N way join with complex filtering and/or aggregation, or whatever), then accumulate these updates somewhere so your incremental refresh could replay them and update the table underlying a given materialized view. I'm sure i'm not thinking of major aspects complicating this. [1] https://www.postgresql.org/docs/current/static/logicaldecoding-explanation.html -- john r pierce, recycling bits in santa cruz -- Sent via pgsql-general mailing list (pgsql-general@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-general