Re: Alias collision in `refresh materialized view concurrently`
Bernd Helmle <mailings@oopsware.de>
From: Bernd Helmle <mailings@oopsware.de>
To: Bharath Rupireddy <bharath.rupireddyforpostgres@gmail.com>, Mathis
Rudolf <mathis.rudolf@credativ.de>
Cc: PostgreSQL-development <pgsql-hackers@postgresql.org>
Date: 2021-05-20T14:21:57Z
Lists: pgsql-hackers
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 patch does this change for the aliases `mv`, `newdata` > > and > > `newdata2`. > > I think it's better to have some random name, see below. We could > either use "OIDNewHeap" or "MyBackendId" to make those column names > unique and almost unguessable. So, something like "pg_temp1_XXXX", > "pg_temp2_XXXX" or "pg_temp3_XXXX" and so on would be better IMO. > > snprintf(NewHeapName, sizeof(NewHeapName), "pg_temp_%u", > OIDOldHeap); > snprintf(namespaceName, sizeof(namespaceName), "pg_temp_%d", > MyBackendId); Hmm, it's an idea, but this can also lead to pretty random failures if you have an unlucky user who had the same idea in its generating query tool than the backend, no? Not sure if that's really better. With the current implementation of REFRESH MATERIALIZED VIEW CONCURRENTLY we always have the problem of possible collisions here, you'd never get out of this area without analyzing the whole query for such collisions. "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 already myself). So the risk here for such a collision looks very high. We can try to lower this risk by choosing an alias name, which is not so common. With a static alias however you get a static error condition, not something that fails here and then. -- Thanks, Bernd
Commits
-
Really fix the ambiguity in REFRESH MATERIALIZED VIEW CONCURRENTLY.
- d33fc411000e 11.13 landed
- c08b3a9eb6cc 9.6.23 landed
- ba9f665a4413 13.4 landed
- ac818984a222 10.18 landed
- 9179a82d7af3 15.0 landed
- 2c915905e3e8 14.0 landed
- 1ff1e4a60646 12.8 landed
-
Reduce risks of conflicts in internal queries of REFRESH MATVIEW CONCURRENTLY
- d9525c46c89d 9.6.23 landed
- 20f70f558172 10.18 landed
- dbc9dbba5652 11.13 landed
- 4ceaa760bd8c 12.8 landed
- 75d66d10e0e3 13.4 landed
- 187682c32173 14.0 landed