pgsql: Don't fetch partition check expression during InitResultRelInfo. - Mailing list pgsql-committers

From Tom Lane
Subject pgsql: Don't fetch partition check expression during InitResultRelInfo.
Date
Msg-id E1kIcAZ-0006Y1-VA@gemulon.postgresql.org
Whole thread Raw
List pgsql-committers
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(-)


pgsql-committers by date:

Previous
From: Peter Geoghegan
Date:
Subject: pgsql: Fix amcheck child check pg_upgrade bug.
Next
From: Tom Lane
Date:
Subject: pgsql: Centralize setup of SIGQUIT handling for postmaster child proces