pg.ddx.io pgsql-committers@postgresql.org mailing list archive
help / color / mirror / Atom feedpgsql: Fix CommandCounterIncrement in partition-related DDL
6+ messages / 2 participants
[nested] [flat]
Commits from this thread:
2018-03-21 56163004b8 Fix relcache handling of the 'default' partition
* pgsql: Fix CommandCounterIncrement in partition-related DDL
@ 2018-03-20 14:37 Alvaro Herrera <alvherre@alvh.no-ip.org>
2018-03-20 14:54 ` Re: pgsql: Fix CommandCounterIncrement in partition-related DDL Alvaro Herrera <alvherre@alvh.no-ip.org>
0 siblings, 1 reply; 6+ messages in thread
From: Alvaro Herrera @ 2018-03-20 14:37 UTC (permalink / raw)
To: pgsql-committers@lists.postgresql.org
Fix CommandCounterIncrement in partition-related DDL
It makes sense to do the CCIs in the places that do catalog updates,
rather than before the places that error out because the former ones
fail to do it. In particular, it looks like StorePartitionBound() and
IndexSetParentIndex() ought to make their own CCIs.
Per review comments from Peter Eisentraut for row-level triggers on
partitioned tables.
Discussion: https://postgr.es/m/20171229225319.ajltgss2ojkfd3kp@alvherre.pgsql
Branch
------
master
Details
-------
https://git.postgresql.org/pg/commitdiff/4dba331cb3dc1b5ffb0680ed8efae847de216796
Modified Files
--------------
src/backend/catalog/heap.c | 3 +++
src/backend/commands/indexcmds.c | 3 +++
src/backend/commands/tablecmds.c | 9 ---------
3 files changed, 6 insertions(+), 9 deletions(-)
^ permalink raw reply [nested|flat] 6+ messages in thread
* Re: pgsql: Fix CommandCounterIncrement in partition-related DDL
2018-03-20 14:37 pgsql: Fix CommandCounterIncrement in partition-related DDL Alvaro Herrera <alvherre@alvh.no-ip.org>
@ 2018-03-20 14:54 ` Alvaro Herrera <alvherre@alvh.no-ip.org>
2018-03-20 18:26 ` Re: pgsql: Fix CommandCounterIncrement in partition-related DDL Alvaro Herrera <alvherre@alvh.no-ip.org>
0 siblings, 1 reply; 6+ messages in thread
From: Alvaro Herrera @ 2018-03-20 14:54 UTC (permalink / raw)
To: pgsql-committers@lists.postgresql.org
Alvaro Herrera wrote:
> Fix CommandCounterIncrement in partition-related DDL
Hmm, Prion seems unhappy about this. Looking
--
Álvaro Herrera https://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services
^ permalink raw reply [nested|flat] 6+ messages in thread
* Re: pgsql: Fix CommandCounterIncrement in partition-related DDL
2018-03-20 14:37 pgsql: Fix CommandCounterIncrement in partition-related DDL Alvaro Herrera <alvherre@alvh.no-ip.org>
2018-03-20 14:54 ` Re: pgsql: Fix CommandCounterIncrement in partition-related DDL Alvaro Herrera <alvherre@alvh.no-ip.org>
@ 2018-03-20 18:26 ` Alvaro Herrera <alvherre@alvh.no-ip.org>
2018-03-20 18:37 ` Re: pgsql: Fix CommandCounterIncrement in partition-related DDL Tom Lane <tgl@sss.pgh.pa.us>
2018-03-21 15:07 ` Re: pgsql: Fix CommandCounterIncrement in partition-related DDL Alvaro Herrera <alvherre@alvh.no-ip.org>
0 siblings, 2 replies; 6+ messages in thread
From: Alvaro Herrera @ 2018-03-20 18:26 UTC (permalink / raw)
To: pgsql-hackers@lists.postgresql.org; +Cc: Jeevan Ladhe <jeevan.ladhe@enterprisedb.com>; Robert Haas <robertmhaas@gmail.com>
Alvaro Herrera wrote:
> Alvaro Herrera wrote:
> > Fix CommandCounterIncrement in partition-related DDL
>
> Hmm, Prion seems unhappy about this. Looking
Here's a patch that seems to fix the problem, and generally looks sane
to me.
The previous arrangements to avoid CCI seem brittle: apparently we were
forced to do StorePartitionBounds() and immediately
update_default_partition_oid() without CCI in between, or various things
went nuts ("unexpected partdefid"). With this patch, what we do is we
call update_default_partition_oid *within* StorePartitionBounds without
an intervening CCI, which seems to achieve the same result -- namely
that when the relcache entry is rebuilt, it doesn't end up incomplete.
The two places that previously called update_default_partition_oid with
a non-zero default partition OID no longer call it, since they were
storing bounds. The only places that remain outside of
StorePartitionBounds call it with InvalidOid (during relation drop, and
during partition detach).
I also remove a crock in RelationBuildPartitionDesc to return empty when
"key is null" (i.e. pg_class entry was there but not
pg_partitioned_table), which makes no sense -- except if you're building
the cache untimely, which apparently is what was happening. If you make
sure the pg_partitioned_table entry is present before making the
pg_class entry visible, then this should not be necessary.
heap_drop_with_catalog contains a copy-paste failure, fixed also in this
patch.
I wonder about adding a syscache callback so that when an item in
pg_partitioned_table is invalidated, the relcache entry for partrelid
entry in pg_class is invalidated also. I can't find any precedent for
anything similar, though, and there doesn't seem to be any convenient
place to do it, either.
--
Álvaro Herrera https://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services
Attachments:
0001-Fix-relcache-handling-of-the-default-partition.patch (text/plain, 3.4K) download
diff --git a/src/backend/catalog/heap.c b/src/backend/catalog/heap.c
index 0497332e9d..a049234390 100644
--- a/src/backend/catalog/heap.c
+++ b/src/backend/catalog/heap.c
@@ -1769,7 +1769,8 @@ heap_drop_with_catalog(Oid relid)
* could attempt to access the just-dropped relation as its partition. We
* must therefore take a table lock strong enough to prevent all queries
* on the table from proceeding until we commit and send out a
- * shared-cache-inval notice that will make them update their index lists.
+ * shared-cache-inval notice that will make them update their partition
+ * descriptors.
*/
tuple = SearchSysCache1(RELOID, ObjectIdGetDatum(relid));
if (!HeapTupleIsValid(tuple))
@@ -3247,6 +3248,9 @@ RemovePartitionKeyByRelId(Oid relid)
* Update pg_class tuple of rel to store the partition bound and set
* relispartition to true
*
+ * If this is the default partition, also update the default partition OID in
+ * pg_partitioned_table.
+ *
* Also, invalidate the parent's relcache, so that the next rebuild will load
* the new partition's info into its partition descriptor. If there is a
* default partition, we must invalidate its relcache entry as well.
@@ -3298,7 +3302,17 @@ StorePartitionBound(Relation rel, Relation parent, PartitionBoundSpec *bound)
heap_freetuple(newtuple);
heap_close(classRel, RowExclusiveLock);
- /* Make update visible */
+ /*
+ * If we're storing bounds for the default partition, update
+ * pg_partitioned_table too. This must happen before CCI, to avoid risk
+ * of constructing a partition descriptor lacking the default partition
+ * OID.
+ */
+ if (bound->is_default)
+ update_default_partition_oid(RelationGetRelid(parent),
+ RelationGetRelid(rel));
+
+ /* Make these updates visible */
CommandCounterIncrement();
/*
diff --git a/src/backend/catalog/partition.c b/src/backend/catalog/partition.c
index 786c05df73..53855f5088 100644
--- a/src/backend/catalog/partition.c
+++ b/src/backend/catalog/partition.c
@@ -227,13 +227,6 @@ RelationBuildPartitionDesc(Relation rel)
/* Range partitioning specific */
PartitionRangeBound **rbounds = NULL;
- /*
- * The following could happen in situations where rel has a pg_class entry
- * but not the pg_partitioned_table entry yet.
- */
- if (key == NULL)
- return;
-
/* Get partition oids from pg_inherits */
inhoids = find_inheritance_children(RelationGetRelid(rel), NoLock);
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 8f83aa4675..c4cf0abadc 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -859,10 +859,6 @@ DefineRelation(CreateStmt *stmt, char relkind, Oid ownerId,
/* Update the pg_class entry. */
StorePartitionBound(rel, parent, bound);
- /* Update the default partition oid */
- if (bound->is_default)
- update_default_partition_oid(RelationGetRelid(parent), relationId);
-
heap_close(parent, NoLock);
}
@@ -14020,11 +14016,6 @@ ATExecAttachPartition(List **wqueue, Relation rel, PartitionCmd *cmd)
/* OK to create inheritance. Rest of the checks performed there */
CreateInheritance(attachrel, rel);
- /* Update the default partition oid */
- if (cmd->bound->is_default)
- update_default_partition_oid(RelationGetRelid(rel),
- RelationGetRelid(attachrel));
-
/*
* Check that the new partition's bound is valid and does not overlap any
* of existing partitions of the parent - note that it does not return on
--
2.11.0
^ permalink raw reply [nested|flat] 6+ messages in thread
* Re: pgsql: Fix CommandCounterIncrement in partition-related DDL
2018-03-20 14:37 pgsql: Fix CommandCounterIncrement in partition-related DDL Alvaro Herrera <alvherre@alvh.no-ip.org>
2018-03-20 14:54 ` Re: pgsql: Fix CommandCounterIncrement in partition-related DDL Alvaro Herrera <alvherre@alvh.no-ip.org>
2018-03-20 18:26 ` Re: pgsql: Fix CommandCounterIncrement in partition-related DDL Alvaro Herrera <alvherre@alvh.no-ip.org>
@ 2018-03-20 18:37 ` Tom Lane <tgl@sss.pgh.pa.us>
2018-03-20 18:55 ` Re: pgsql: Fix CommandCounterIncrement in partition-related DDL Alvaro Herrera <alvherre@alvh.no-ip.org>
1 sibling, 1 reply; 6+ messages in thread
From: Tom Lane @ 2018-03-20 18:37 UTC (permalink / raw)
To: Alvaro Herrera <alvherre@alvh.no-ip.org>; +Cc: pgsql-hackers@lists.postgresql.org, Jeevan Ladhe <jeevan.ladhe@enterprisedb.com>; Robert Haas <robertmhaas@gmail.com>
Alvaro Herrera <alvherre@alvh.no-ip.org> writes:
> I wonder about adding a syscache callback so that when an item in
> pg_partitioned_table is invalidated, the relcache entry for partrelid
> entry in pg_class is invalidated also. I can't find any precedent for
> anything similar, though, and there doesn't seem to be any convenient
> place to do it, either.
In principle you could do it by adding logic to CacheInvalidateHeapTuple
in inval.c, similar to the existing logic for pg_class, pg_attribute
and pg_index entries. Not sure it's worthwhile though. That's very
ancient code; of late our practice has been to insist that the code
modifying other catalogs that feed into relcache entries should issue
a relcache inval explicitly. If there's a reason why it's not convenient
to do that, then maybe making CacheInvalidateHeapTuple do it is a
good way.
regards, tom lane
^ permalink raw reply [nested|flat] 6+ messages in thread
* Re: pgsql: Fix CommandCounterIncrement in partition-related DDL
2018-03-20 14:37 pgsql: Fix CommandCounterIncrement in partition-related DDL Alvaro Herrera <alvherre@alvh.no-ip.org>
2018-03-20 14:54 ` Re: pgsql: Fix CommandCounterIncrement in partition-related DDL Alvaro Herrera <alvherre@alvh.no-ip.org>
2018-03-20 18:26 ` Re: pgsql: Fix CommandCounterIncrement in partition-related DDL Alvaro Herrera <alvherre@alvh.no-ip.org>
2018-03-20 18:37 ` Re: pgsql: Fix CommandCounterIncrement in partition-related DDL Tom Lane <tgl@sss.pgh.pa.us>
@ 2018-03-20 18:55 ` Alvaro Herrera <alvherre@alvh.no-ip.org>
0 siblings, 0 replies; 6+ messages in thread
From: Alvaro Herrera @ 2018-03-20 18:55 UTC (permalink / raw)
To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: pgsql-hackers@lists.postgresql.org, Jeevan Ladhe <jeevan.ladhe@enterprisedb.com>; Robert Haas <robertmhaas@gmail.com>
Tom Lane wrote:
> Alvaro Herrera <alvherre@alvh.no-ip.org> writes:
> > I wonder about adding a syscache callback so that when an item in
> > pg_partitioned_table is invalidated, the relcache entry for partrelid
> > entry in pg_class is invalidated also. I can't find any precedent for
> > anything similar, though, and there doesn't seem to be any convenient
> > place to do it, either.
>
> In principle you could do it by adding logic to CacheInvalidateHeapTuple
> in inval.c, similar to the existing logic for pg_class, pg_attribute
> and pg_index entries. Not sure it's worthwhile though. That's very
> ancient code; of late our practice has been to insist that the code
> modifying other catalogs that feed into relcache entries should issue
> a relcache inval explicitly. If there's a reason why it's not convenient
> to do that, then maybe making CacheInvalidateHeapTuple do it is a
> good way.
Actually, the current code uses CacheInvalidateRelcache() already and it
seems to work; I was looking for a better way that did not require us to
remember it for every update in that catalog, but it seems there isn't
one.
--
Álvaro Herrera https://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services
^ permalink raw reply [nested|flat] 6+ messages in thread
* Re: pgsql: Fix CommandCounterIncrement in partition-related DDL
2018-03-20 14:37 pgsql: Fix CommandCounterIncrement in partition-related DDL Alvaro Herrera <alvherre@alvh.no-ip.org>
2018-03-20 14:54 ` Re: pgsql: Fix CommandCounterIncrement in partition-related DDL Alvaro Herrera <alvherre@alvh.no-ip.org>
2018-03-20 18:26 ` Re: pgsql: Fix CommandCounterIncrement in partition-related DDL Alvaro Herrera <alvherre@alvh.no-ip.org>
@ 2018-03-21 15:07 ` Alvaro Herrera <alvherre@alvh.no-ip.org>
1 sibling, 0 replies; 6+ messages in thread
From: Alvaro Herrera @ 2018-03-21 15:07 UTC (permalink / raw)
To: pgsql-hackers@lists.postgresql.org; +Cc: Jeevan Ladhe <jeevan.ladhe@enterprisedb.com>; Robert Haas <robertmhaas@gmail.com>
Alvaro Herrera wrote:
> Alvaro Herrera wrote:
> > Alvaro Herrera wrote:
> > > Fix CommandCounterIncrement in partition-related DDL
> >
> > Hmm, Prion seems unhappy about this. Looking
>
> Here's a patch that seems to fix the problem, and generally looks sane
> to me.
Pushed, after editing a couple of other comments here and there.
--
Álvaro Herrera https://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services
^ permalink raw reply [nested|flat] 6+ messages in thread
end of thread, other threads:[~2018-03-21 15:07 UTC | newest]
Thread overview: 6+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2018-03-20 14:37 pgsql: Fix CommandCounterIncrement in partition-related DDL Alvaro Herrera <alvherre@alvh.no-ip.org>
2018-03-20 14:54 ` Alvaro Herrera <alvherre@alvh.no-ip.org>
2018-03-20 18:26 ` Alvaro Herrera <alvherre@alvh.no-ip.org>
2018-03-20 18:37 ` Tom Lane <tgl@sss.pgh.pa.us>
2018-03-20 18:55 ` Alvaro Herrera <alvherre@alvh.no-ip.org>
2018-03-21 15:07 ` Alvaro Herrera <alvherre@alvh.no-ip.org>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox