pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Don't fetch partition check expression during InitResultRelInfo.
Date: Wed, 16 Sep 2020 18:28:39 +0000
Message-ID: <E1kIcAZ-0006Y1-VA@gemulon.postgresql.org> (raw)

Don't fetch partition check expression during InitResultRelInfo.

Since there is only one place that actually needs the partition check
expression, namely ExecPartitionCheck, it's better to fetch it from
the relcache there.  In this way we will never fetch it at all if
the query never has use for it, and we still fetch it just once when
we do need it.

The reason for taking an interest in this is that if the relcache
doesn't already have the check expression cached, fetching it
requires obtaining AccessShareLock on the partition root.  That
means that operations that look like they should only touch the
partition itself will also take a lock on the root.  In particular
we observed that TRUNCATE on a partition may take a lock on the
partition's root, contributing to a deadlock situation in parallel
pg_restore.

As written, this patch does have a small cost, which is that we
are microscopically reducing efficiency for the case where a partition
has an empty check expression.  ExecPartitionCheck will be called,
and will go through the motions of setting up and checking an empty
qual, where before it would not have been called at all.  We could
avoid that by adding a separate boolean flag to track whether there
is a partition expression to test.  However, this case only arises
for a default partition with no siblings, which surely is not an
interesting case in practice.  Hence adding complexity for it
does not seem like a good trade-off.

Amit Langote, per a suggestion by me

Discussion: https://postgr.es/m/VI1PR03MB31670CA1BD9625C3A8C5DD05EB230@VI1PR03MB3167.eurprd03.prod.outlook.com

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/2000b6c10aa6777929f1a8b613f30426bb90f849

Modified Files
--------------
src/backend/commands/copy.c              |  2 +-
src/backend/executor/execMain.c          | 41 ++++++++++++--------------------
src/backend/executor/execPartition.c     |  2 +-
src/backend/executor/execReplication.c   |  4 ++--
src/backend/executor/nodeModifyTable.c   |  4 ++--
src/backend/replication/logical/worker.c |  2 +-
src/include/nodes/execnodes.h            | 11 ++++-----
7 files changed, 26 insertions(+), 40 deletions(-)



Message-ID: <E1kIcAZ-0006Y1-VA@gemulon.postgresql.org>
Permalink:  ../E1kIcAZ-0006Y1-VA@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1kIcAZ-0006Y1-VA@gemulon.postgresql.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-committers@postgresql.org
  Cc: tgl@sss.pgh.pa.us
  Subject: Re: pgsql: Don't fetch partition check expression during InitResultRelInfo.
  In-Reply-To: <E1kIcAZ-0006Y1-VA@gemulon.postgresql.org>
  References: <E1kIcAZ-0006Y1-VA@gemulon.postgresql.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

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