Re: pgsql: Fix CommandCounterIncrement in partition-related DDL

From: Alvaro Herrera <alvherre(at)alvh(dot)no-ip(dot)org>
To: pgsql-hackers(at)lists(dot)postgresql(dot)org
Cc: Jeevan Ladhe <jeevan(dot)ladhe(at)enterprisedb(dot)com>, Robert Haas <robertmhaas(at)gmail(dot)com>
Subject: Re: pgsql: Fix CommandCounterIncrement in partition-related DDL
Date: 2018-03-20 18:26:59
Message-ID: 20180320182659.nyzn3vqtjbbtfgwq@alvherre.pgsql
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-committers pgsql-hackers

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

Attachment Content-Type Size
0001-Fix-relcache-handling-of-the-default-partition.patch text/plain 3.4 KB

In response to

Responses

Browse pgsql-committers by date

  From Date Subject
Next Message Tom Lane 2018-03-20 18:37:46 Re: pgsql: Fix CommandCounterIncrement in partition-related DDL
Previous Message Robert Haas 2018-03-20 15:38:21 pgsql: Don't pass the grouping target around unnecessarily.

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2018-03-20 18:37:46 Re: pgsql: Fix CommandCounterIncrement in partition-related DDL
Previous Message Tom Lane 2018-03-20 18:04:50 Re: configure's checks for --enable-tap-tests are insufficient