Re: Alias collision in `refresh materialized view concurrently`

2021-08-06 Thread Tom Lane
Michael Paquier writes: > On Fri, Aug 06, 2021 at 10:48:40AM -0400, Tom Lane wrote: >> Given that it took this long to notice the problem at all, maybe >> this is not a fix to cram in on the weekend before the release wrap. >> But I don't see why we need to settle for "mostly works" when >> "alway

Re: Alias collision in `refresh materialized view concurrently`

2021-08-06 Thread Michael Paquier
On Fri, Aug 06, 2021 at 10:48:40AM -0400, Tom Lane wrote: > AFAICT that works and generates the identical parse tree to the original > coding. The only place touched by the patch where it's a bit difficult to > make the syntax unambiguous this way is > > "CREATE TEMP TABLE %s

Re: Alias collision in `refresh materialized view concurrently`

2021-08-06 Thread Tom Lane
I wrote: > I just came across this issue while preparing the release notes. > ISTM that people have expended a great deal of effort on a fundamentally > unreliable solution, when a reliable one is easily available. Concretely, I propose the attached. regards, tom lane dif

Re: Alias collision in `refresh materialized view concurrently`

2021-08-06 Thread Tom Lane
Michael Paquier writes: > On Wed, Jun 02, 2021 at 03:44:45PM +0530, Bharath Rupireddy wrote: >> Thanks.The changes with that approach are very minimal. PSA v5 and let >> me know if any more changes are needed. > Simple enough, so applied and back-patched. I just came across this issue while prep

Re: Alias collision in `refresh materialized view concurrently`

2021-06-02 Thread Michael Paquier
On Wed, Jun 02, 2021 at 03:44:45PM +0530, Bharath Rupireddy wrote: > Thanks.The changes with that approach are very minimal. PSA v5 and let > me know if any more changes are needed. Simple enough, so applied and back-patched. It took 8 years for somebody to complain about the current aliases, so

Re: Alias collision in `refresh materialized view concurrently`

2021-06-02 Thread Bharath Rupireddy
On Wed, Jun 2, 2021 at 1:27 PM Michael Paquier wrote: > > On Wed, Jun 02, 2021 at 10:53:22AM +0530, Bharath Rupireddy wrote: > > Thanks. PSA v4. > > Thanks for the new version. > > +MyProcPid, tempname, MyProcPid, MyProcPid, > +tempname, MyProcPid, MyProcPid

Re: Alias collision in `refresh materialized view concurrently`

2021-06-02 Thread Michael Paquier
On Wed, Jun 02, 2021 at 10:53:22AM +0530, Bharath Rupireddy wrote: > Thanks. PSA v4. Thanks for the new version. +MyProcPid, tempname, MyProcPid, MyProcPid, +tempname, MyProcPid, MyProcPid, MyProcPid, +MyProcPid, MyProcPid, MyProcPid); T

Re: Alias collision in `refresh materialized view concurrently`

2021-06-01 Thread Bharath Rupireddy
On Wed, Jun 2, 2021 at 6:33 AM Michael Paquier wrote: > > On Wed, Jun 02, 2021 at 12:30:55PM +1200, Thomas Munro wrote: > > I wondered if we could find a way to make identifiers that regular > > queries are prohibited from using, at least by documentation. You > > could take advantage of the vari

Re: Alias collision in `refresh materialized view concurrently`

2021-06-01 Thread Michael Paquier
On Wed, Jun 02, 2021 at 12:30:55PM +1200, Thomas Munro wrote: > I wondered if we could find a way to make identifiers that regular > queries are prohibited from using, at least by documentation. You > could take advantage of the various constraints on unquoted > identifiers in the standard (for ex

Re: Alias collision in `refresh materialized view concurrently`

2021-06-01 Thread Thomas Munro
On Wed, Jun 2, 2021 at 2:02 AM Bharath Rupireddy wrote: > PSA v3 patch. I added a commit message and made some cosmetic adjustments. Reminds me of this fun topic in Lisp: https://en.wikipedia.org/wiki/Hygienic_macro#Strategies_used_in_languages_that_lack_hygienic_macros I wondered if we could f

Re: Alias collision in `refresh materialized view concurrently`

2021-06-01 Thread Bharath Rupireddy
On Tue, Jun 1, 2021 at 5:24 PM Bernd Helmle wrote: > > Am Dienstag, dem 01.06.2021 um 13:13 +0530 schrieb Bharath Rupireddy: > > I used MyProcPid which seems more random than MyBackendId (which is > > just a number like 1,2,3...). Even with this, someone could argue > > that > > they can look at t

Re: Alias collision in `refresh materialized view concurrently`

2021-06-01 Thread Bernd Helmle
Am Dienstag, dem 01.06.2021 um 13:13 +0530 schrieb Bharath Rupireddy: > I used MyProcPid which seems more random than MyBackendId (which is > just a number like 1,2,3...). Even with this, someone could argue > that > they can look at the backend PID, use it in the materialized view > names just to

Re: Alias collision in `refresh materialized view concurrently`

2021-06-01 Thread Bharath Rupireddy
On Tue, Jun 1, 2021 at 7:11 AM Michael Paquier wrote: > > On Fri, May 21, 2021 at 03:56:31PM +0530, Bharath Rupireddy wrote: > > On Fri, May 21, 2021 at 6:08 AM Michael Paquier wrote: > >> I am not sure that I see the point of using a random() number here > >> while the backend ID, or just the PI

Re: Alias collision in `refresh materialized view concurrently`

2021-05-31 Thread Michael Paquier
On Fri, May 21, 2021 at 03:56:31PM +0530, Bharath Rupireddy wrote: > On Fri, May 21, 2021 at 6:08 AM Michael Paquier wrote: >> I am not sure that I see the point of using a random() number here >> while the backend ID, or just the PID, would easily provide enough >> entropy for this internal alias

Re: Alias collision in `refresh materialized view concurrently`

2021-05-21 Thread Bharath Rupireddy
On Fri, May 21, 2021 at 6:08 AM Michael Paquier wrote: > > On Thu, May 20, 2021 at 09:14:45PM +0530, Bharath Rupireddy wrote: > > On Thu, May 20, 2021 at 7:52 PM Bernd Helmle wrote: > >> "mv" looks like a very common alias (i use it all over the time when > >> testing or playing around with mater

Re: Alias collision in `refresh materialized view concurrently`

2021-05-20 Thread Michael Paquier
On Thu, May 20, 2021 at 09:14:45PM +0530, Bharath Rupireddy wrote: > On Thu, May 20, 2021 at 7:52 PM Bernd Helmle wrote: >> "mv" looks like a very common alias (i use it all over the time when >> testing or playing around with materialized views, so i'm wondering why >> i didn't see this issue al

Re: Alias collision in `refresh materialized view concurrently`

2021-05-20 Thread Bharath Rupireddy
On Thu, May 20, 2021 at 7:52 PM Bernd Helmle wrote: > > Am Mittwoch, dem 19.05.2021 um 18:06 +0530 schrieb Bharath Rupireddy: > > > The corresponding Code is in `matview.c` in function > > > `refresh_by_match_merge`. With adding a prefix like `_pg_internal_` > > > we > > > could make collisions pr

Re: Alias collision in `refresh materialized view concurrently`

2021-05-20 Thread Bernd Helmle
Am Mittwoch, dem 19.05.2021 um 18:06 +0530 schrieb Bharath Rupireddy: > > The corresponding Code is in `matview.c` in function > > `refresh_by_match_merge`. With adding a prefix like `_pg_internal_` > > we > > could make collisions pretty unlikely, without intrusive changes. > > > > The appended p

Re: Alias collision in `refresh materialized view concurrently`

2021-05-19 Thread Bharath Rupireddy
On Wed, May 19, 2021 at 5:33 PM Mathis Rudolf wrote: > > Hello, > > we had a Customer-Report in which `refresh materialized view > CONCURRENTLY` failed with: `ERROR: column reference "mv" is ambiguous` > > They're using `mv` as an alias for one column and this is causing a > collision with an inte

Alias collision in `refresh materialized view concurrently`

2021-05-19 Thread Mathis Rudolf
Hello, we had a Customer-Report in which `refresh materialized view CONCURRENTLY` failed with: `ERROR: column reference "mv" is ambiguous` They're using `mv` as an alias for one column and this is causing a collision with an internal alias. They also made it reproducible like this: ``` creat