pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Heikki Linnakangas <heikki.linnakangas@iki.fi>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Improve performance of tuple conversion map generation
Date: Fri, 13 Jul 2018 16:57:01 +0000
Message-ID: <E1fe1NN-0003Kg-Hy@gemulon.postgresql.org> (raw)

Improve performance of tuple conversion map generation

Previously convert_tuples_by_name_map naively performed a search of each
outdesc column starting at the first column in indesc and searched each
indesc column until a match was found.  When partitioned tables had many
columns this could result in slow generation of the tuple conversion maps.
For INSERT and UPDATE statements that touched few rows, this could mean a
very large overhead indeed.

We can do a bit better with this loop.  It's quite likely that the columns
in partitioned tables and their partitions are in the same order, so it
makes sense to start searching for each column outer column at the inner
column position 1 after where the previous match was found (per idea from
Alexander Kuzmenkov). This makes the best case search O(N) instead of
O(N^2).  The worst case is still O(N^2), but it seems unlikely that would
happen.

Likewise, in the planner, make_inh_translation_list's search for the
matching column could often end up falling back on an O(N^2) type search.
This commit also improves that by first checking the column that follows
the previous match, instead of the column with the same attnum.  If we
fail to match here we fallback on the syscache's hashtable lookup.

Author: David Rowley
Reviewed-by: Alexander Kuzmenkov
Discussion: https://www.postgresql.org/message-id/CAKJS1f9-wijVgMdRp6_qDMEQDJJ%2BA_n%3DxzZuTmLx5Fz6cwf%2B8A%40ma...

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/42f70cd9c3dbfcdfbeea4e24d5921173d0eaab66

Modified Files
--------------
src/backend/access/common/tupconvert.c | 36 ++++++++++++++++++++++++-------
src/backend/optimizer/prep/prepunion.c | 39 +++++++++++++++++-----------------
2 files changed, 47 insertions(+), 28 deletions(-)



Message-ID: <E1fe1NN-0003Kg-Hy@gemulon.postgresql.org>
Permalink:  ../E1fe1NN-0003Kg-Hy@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1fe1NN-0003Kg-Hy@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: heikki.linnakangas@iki.fi
  Subject: Re: pgsql: Improve performance of tuple conversion map generation
  In-Reply-To: <E1fe1NN-0003Kg-Hy@gemulon.postgresql.org>
  References: <E1fe1NN-0003Kg-Hy@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