Re: Fail Fast In CTAS/CMV If Relation Already Exists To Avoid Unnecessary Rewrite, Planning Costs

2020-12-30 Thread Michael Paquier
On Thu, Dec 24, 2020 at 01:23:40PM +0900, Michael Paquier wrote: > Please note that I have added an entry in the CF app for the moment so > as we don't lose track of it: > https://commitfest.postgresql.org/31/2892/ I have been able to look at that again today, and applied it. I have tweaked a

Re: Fail Fast In CTAS/CMV If Relation Already Exists To Avoid Unnecessary Rewrite, Planning Costs

2020-12-23 Thread Michael Paquier
On Thu, Dec 24, 2020 at 09:10:22AM +0530, Bharath Rupireddy wrote: > Since I tested that with all the formats manually here and it works, > so I don't want to make the test cases complicated with adding > explain_filter() function into matview.sql and select_into.sql and all > that. I'm okay

Re: Fail Fast In CTAS/CMV If Relation Already Exists To Avoid Unnecessary Rewrite, Planning Costs

2020-12-23 Thread Bharath Rupireddy
On Thu, Dec 24, 2020 at 7:40 AM Michael Paquier wrote: > > On Wed, Dec 23, 2020 at 07:13:33PM +0530, Bharath Rupireddy wrote: > > +1. Shall we add some test cases(with xml, yaml, json formats as is > > currently being done in explain.sql) to cover that? We can have the > > explain_filter()

Re: Fail Fast In CTAS/CMV If Relation Already Exists To Avoid Unnecessary Rewrite, Planning Costs

2020-12-23 Thread Michael Paquier
On Wed, Dec 23, 2020 at 07:13:33PM +0530, Bharath Rupireddy wrote: > +1. Shall we add some test cases(with xml, yaml, json formats as is > currently being done in explain.sql) to cover that? We can have the > explain_filter() function to remove the unstable parts in the output, > it looks

Re: Fail Fast In CTAS/CMV If Relation Already Exists To Avoid Unnecessary Rewrite, Planning Costs

2020-12-23 Thread Bharath Rupireddy
On Wed, Dec 23, 2020 at 6:01 PM Michael Paquier wrote: > On Tue, Dec 22, 2020 at 03:12:15PM +0530, Bharath Rupireddy wrote: > > On Tue, Dec 22, 2020 at 2:07 PM Michael Paquier wrote: > >> Note: I'd like to think that we could choose a better name for > >> CheckRelExistenceInCTAS(). > > > > I

Re: Fail Fast In CTAS/CMV If Relation Already Exists To Avoid Unnecessary Rewrite, Planning Costs

2020-12-23 Thread Michael Paquier
On Tue, Dec 22, 2020 at 03:12:15PM +0530, Bharath Rupireddy wrote: > On Tue, Dec 22, 2020 at 2:07 PM Michael Paquier wrote: >> Note: I'd like to think that we could choose a better name for >> CheckRelExistenceInCTAS(). > > I changed it to IsCTASRelCreationAllowed() and attached a v5 patch. >

Re: Fail Fast In CTAS/CMV If Relation Already Exists To Avoid Unnecessary Rewrite, Planning Costs

2020-12-22 Thread Bharath Rupireddy
On Tue, Dec 22, 2020 at 2:07 PM Michael Paquier wrote: > I was looking at your patch today, and I actually found the conclusion > to output an empty plan while issuing a NOTICE to be quite intuitive > if the caller uses IF NOT EXISTS with EXPLAIN. Thanks! > Thanks for adding some test cases!

Re: Fail Fast In CTAS/CMV If Relation Already Exists To Avoid Unnecessary Rewrite, Planning Costs

2020-12-22 Thread Michael Paquier
On Mon, Dec 21, 2020 at 12:01:38PM +0530, Bharath Rupireddy wrote: > On Fri, Dec 18, 2020 at 8:15 AM Bharath Rupireddy >> I tried to make it consistent by issuing NOTICE (not an error) even >> for EXPLAIN/EXPLAIN ANALYZE IF NOT EXISTS case. If issue notice and >> exit from the ExplainOneUtility,

Re: Fail Fast In CTAS/CMV If Relation Already Exists To Avoid Unnecessary Rewrite, Planning Costs

2020-12-20 Thread Bharath Rupireddy
On Fri, Dec 18, 2020 at 8:15 AM Bharath Rupireddy wrote: > On Fri, Dec 18, 2020 at 7:18 AM Michael Paquier wrote: > > On Thu, Dec 17, 2020 at 03:06:59PM +0530, Bharath Rupireddy wrote: > > > The behavior of the ctas/cmv, in case the relation already exists is as > > > shown in [1]. The things

Re: Fail Fast In CTAS/CMV If Relation Already Exists To Avoid Unnecessary Rewrite, Planning Costs

2020-12-17 Thread Bharath Rupireddy
On Fri, Dec 18, 2020 at 7:18 AM Michael Paquier wrote: > On Thu, Dec 17, 2020 at 03:06:59PM +0530, Bharath Rupireddy wrote: > > The behavior of the ctas/cmv, in case the relation already exists is as > > shown in [1]. The things that have been changed with the patch are: 1) In > > any case we do

Re: Fail Fast In CTAS/CMV If Relation Already Exists To Avoid Unnecessary Rewrite, Planning Costs

2020-12-17 Thread Michael Paquier
On Thu, Dec 17, 2020 at 03:06:59PM +0530, Bharath Rupireddy wrote: > The behavior of the ctas/cmv, in case the relation already exists is as > shown in [1]. The things that have been changed with the patch are: 1) In > any case we do not rewrite or plan the select part if the relation already >

Re: Fail Fast In CTAS/CMV If Relation Already Exists To Avoid Unnecessary Rewrite, Planning Costs

2020-12-17 Thread Bharath Rupireddy
On Mon, Dec 14, 2020 at 1:54 PM Bharath Rupireddy wrote: > On Mon, Dec 14, 2020 at 11:52 AM Michael Paquier wrote: > > On Mon, Dec 14, 2020 at 03:15:12PM +0900, Michael Paquier wrote: > > > Please note that this case fails with your patch, but the presence of > > > IF NOT EXISTS should ensure

Re: Fail Fast In CTAS/CMV If Relation Already Exists To Avoid Unnecessary Rewrite, Planning Costs

2020-12-14 Thread Bharath Rupireddy
On Mon, Dec 14, 2020 at 11:52 AM Michael Paquier wrote: > On Mon, Dec 14, 2020 at 03:15:12PM +0900, Michael Paquier wrote: > > Please note that this case fails with your patch, but the presence of > > IF NOT EXISTS should ensure that we don't fail and issue a NOTICE > > instead, no? Thanks for

Re: Fail Fast In CTAS/CMV If Relation Already Exists To Avoid Unnecessary Rewrite, Planning Costs

2020-12-13 Thread Michael Paquier
On Mon, Dec 14, 2020 at 03:15:12PM +0900, Michael Paquier wrote: > Please note that this case fails with your patch, but the presence of > IF NOT EXISTS should ensure that we don't fail and issue a NOTICE > instead, no? Taking this case specifically (OK, I am playing with > the rules a bit to

Re: Fail Fast In CTAS/CMV If Relation Already Exists To Avoid Unnecessary Rewrite, Planning Costs

2020-12-13 Thread Michael Paquier
On Fri, Dec 11, 2020 at 03:03:46PM +0530, Bharath Rupireddy wrote: > I may not have got your above scenario correctly(it will be good if > you can provide the use case in case I want to check something there). It is possible to have DML queries in WITH clauses, as long as they use RETURNING to

Re: Fail Fast In CTAS/CMV If Relation Already Exists To Avoid Unnecessary Rewrite, Planning Costs

2020-12-11 Thread Bharath Rupireddy
On Fri, Dec 11, 2020 at 1:40 PM Michael Paquier wrote: > On Fri, Dec 11, 2020 at 12:48:49PM +0530, Bharath Rupireddy wrote: > > I'm not quite sure how other databases behave. If I go by the main > > intention of EXPLAIN without ANALYZE, that should do the planning, > > show it in the output and

Re: Fail Fast In CTAS/CMV If Relation Already Exists To Avoid Unnecessary Rewrite, Planning Costs

2020-12-11 Thread Michael Paquier
On Fri, Dec 11, 2020 at 12:48:49PM +0530, Bharath Rupireddy wrote: > I'm not quite sure how other databases behave. If I go by the main > intention of EXPLAIN without ANALYZE, that should do the planning, > show it in the output and no execution of the query should happen. For > EXPLAIN CTAS/CMV,

Re: Fail Fast In CTAS/CMV If Relation Already Exists To Avoid Unnecessary Rewrite, Planning Costs

2020-12-10 Thread Bharath Rupireddy
On Fri, Dec 11, 2020 at 12:13 PM Hou, Zhijie wrote: > > IMO, let's not change the 1) behaviour to 3) with the patch. If agreed, > > > I can do the following way in ExplainOneUtility and will add a comment on > > > why we are doing this. > > > if (es->analyze) > > > (void)

RE: Fail Fast In CTAS/CMV If Relation Already Exists To Avoid Unnecessary Rewrite, Planning Costs

2020-12-10 Thread Hou, Zhijie
> IMO, let's not change the 1) behaviour to 3) with the patch. If agreed, > I can do the following way in ExplainOneUtility and will add a comment on > why we are doing this. > > if (es->analyze) > (void) CheckRelExistenceInCTAS(ctas, true); > > Thoughts? Agreed. Just in case, I took

Re: Fail Fast In CTAS/CMV If Relation Already Exists To Avoid Unnecessary Rewrite, Planning Costs

2020-12-10 Thread Bharath Rupireddy
Thanks for taking a look at this. On Fri, Dec 11, 2020 at 6:33 AM Hou, Zhijie wrote: > > > Currently, for CTAS or CREATE MATERIALIZED VIEW(CMV) without if-not-exists > > clause, the existence of the relation gets checked during the execution > > of the select part and an error is thrown there. >

RE: Fail Fast In CTAS/CMV If Relation Already Exists To Avoid Unnecessary Rewrite, Planning Costs

2020-12-10 Thread Hou, Zhijie
> Currently, for CTAS or CREATE MATERIALIZED VIEW(CMV) without if-not-exists > clause, the existence of the relation gets checked during the execution > of the select part and an error is thrown there. > All the unnecessary rewrite and planning for the select part would have > happened just to

Fail Fast In CTAS/CMV If Relation Already Exists To Avoid Unnecessary Rewrite, Planning Costs

2020-12-10 Thread Bharath Rupireddy
Hi, Currently, for CTAS or CREATE MATERIALIZED VIEW(CMV) without if-not-exists clause, the existence of the relation gets checked during the execution of the select part and an error is thrown there. All the unnecessary rewrite and planning for the select part would have happened just to fail