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: Avoid O(N^2) cost in ExecFindRowMark().
Date: Mon, 08 Oct 2018 14:41:39 +0000
Message-ID: <E1g9Wj5-0002Xc-S4@gemulon.postgresql.org> (raw)

Avoid O(N^2) cost in ExecFindRowMark().

If there are many ExecRowMark structs, we spent O(N^2) time in
ExecFindRowMark during executor startup.  Once upon a time this was
not of great concern, but the addition of native partitioning has
squeezed out enough other costs that this can become the dominant
overhead in some use-cases for tables with many partitions.

To fix, simply replace that List data structure with an array.

This adds a little bit of cost to execCurrentOf(), but not much,
and anyway that code path is neither of large importance nor very
efficient now.  If we ever decide it is a bottleneck, constructing a
hash table for lookup-by-tableoid would likely be the thing to do.

Per complaint from Amit Langote, though this is different from
his fix proposal.

Discussion: https://postgr.es/m/468c85d9-540e-66a2-1dde-fec2b741e688@lab.ntt.co.jp

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/f9eb7c14b08d2cc5eda62ffaf37a356c05e89b93

Modified Files
--------------
src/backend/executor/execCurrent.c |  11 ++--
src/backend/executor/execMain.c    | 116 +++++++++++++++++++------------------
src/backend/executor/execUtils.c   |   9 ++-
src/include/nodes/execnodes.h      |  13 +++--
4 files changed, 82 insertions(+), 67 deletions(-)



Message-ID: <E1g9Wj5-0002Xc-S4@gemulon.postgresql.org>
Permalink:  ../E1g9Wj5-0002Xc-S4@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1g9Wj5-0002Xc-S4@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: Avoid O(N^2) cost in ExecFindRowMark().
  In-Reply-To: <E1g9Wj5-0002Xc-S4@gemulon.postgresql.org>
  References: <E1g9Wj5-0002Xc-S4@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