mirror of
https://github.com/postgres/postgres.git
synced 2025-11-21 00:42:43 +03:00
Teach ANALYZE to clear pg_class.relhassubclass when appropriate.
In the past, relhassubclass always remained true if a relation had ever had
child relations, even if the last subclass was long gone. While this had
only marginal performance implications in most cases, it was annoying, and
I'm now considering some planner changes that would raise the cost of a
false positive. It was previously impractical to fix this because of race
condition concerns. However, given the recent change that made tablecmds.c
take ShareExclusiveLock on relations that are gaining a child (commit
fbcf4b92aa), we can now allow ANALYZE to
clear the flag when it's no longer relevant. There is no additional
locking cost to do so, since ANALYZE takes ShareExclusiveLock anyway.
This commit is contained in:
@@ -228,11 +228,12 @@ find_all_inheritors(Oid parentrelId, LOCKMODE lockmode, List **numparents)
|
||||
* In the current implementation, has_subclass returns whether a
|
||||
* particular class *might* have a subclass. It will not return the
|
||||
* correct result if a class had a subclass which was later dropped.
|
||||
* This is because relhassubclass in pg_class is not updated when a
|
||||
* subclass is dropped, primarily because of concurrency concerns.
|
||||
* This is because relhassubclass in pg_class is not updated immediately
|
||||
* when a subclass is dropped, primarily because of concurrency concerns.
|
||||
*
|
||||
* Currently has_subclass is only used as an efficiency hack to skip
|
||||
* unnecessary inheritance searches, so this is OK.
|
||||
* unnecessary inheritance searches, so this is OK. Note that ANALYZE
|
||||
* on a childless table will clean up the obsolete relhassubclass flag.
|
||||
*
|
||||
* Although this doesn't actually touch pg_inherits, it seems reasonable
|
||||
* to keep it here since it's normally used with the other routines here.
|
||||
|
||||
Reference in New Issue
Block a user