Re: EXPLAIN/EXPLAIN ANALYZE REFRESH MATERIALIZED VIEW

From: Bharath Rupireddy <bharath(dot)rupireddyforpostgres(at)gmail(dot)com>
To: japin <japinli(at)hotmail(dot)com>
Cc: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: EXPLAIN/EXPLAIN ANALYZE REFRESH MATERIALIZED VIEW
Date: 2021-01-08 09:24:50
Message-ID: CALj2ACW0VaFsp2Z1V52J2JwHHeh+nTQRRHz+dWigBMLp1GXecA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Fri, Jan 8, 2021 at 1:50 PM japin <japinli(at)hotmail(dot)com> wrote:
> Thanks for updating the patch!
>
> + /* Get the data generating query. */
> + dataQuery = get_matview_query(stmt, &matviewRel, &matviewOid);
>
> - /*
> - * Check for active uses of the relation in the current transaction, such
> - * as open scans.
> - *
> - * NB: We count on this to protect us against problems with refreshing the
> - * data using TABLE_INSERT_FROZEN.
> - */
> - CheckTableNotInUse(matviewRel, "REFRESH MATERIALIZED VIEW");
> + relowner = matviewRel->rd_rel->relowner;
>
> After apply the patch, there is a duplicate
>
> relowner = matviewRel->rd_rel->relowner;

Corrected that.

> + else if(matviewInfo)
> + dest = CreateTransientRelDestReceiver(matviewInfo->OIDNewHeap);
>
> If the `matviewInfo->OIDNewHeap` is invalid, IMO we don't need create
> DestReceiver, isn't it? And we should add a space after `if`.

Yes, we can skip creating the dest receiver when OIDNewHeap is
invalid, this can happen for plain explain refresh mat view case.

if (explainInfo && !explainInfo->es->analyze)
OIDNewHeap = InvalidOid;
else
OIDNewHeap = get_new_heap_oid(stmt, matviewRel, matviewOid,
&relpersistence);

Since we don't call ExecutorRun for plain explain, we can skip the
dest receiver creation. I modified the code as below in explain.c.

if (into)
dest = CreateIntoRelDestReceiver(into);
else if (matviewInfo && OidIsValid(matviewInfo->OIDNewHeap))
dest = CreateTransientRelDestReceiver(matviewInfo->OIDNewHeap);
else
dest = None_Receiver;

Thanks for taking a look at the patches.

Attaching v3 patches, please consider these for further review.

With Regards,
Bharath Rupireddy.
EnterpriseDB: http://www.enterprisedb.com

Attachment Content-Type Size
v3-0001-Rearrange-Refresh-Mat-View-Code.patch application/x-patch 18.1 KB
v3-0002-EXPLAIN-EXPLAIN-ANALYZE-REFRESH-MATERIALIZED-VIEW.patch application/x-patch 16.3 KB

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message vignesh C 2021-01-08 09:24:56 Re: Parallel INSERT (INTO ... SELECT ...)
Previous Message Peter Eisentraut 2021-01-08 09:21:15 Re: Improper use about DatumGetInt32