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@postgresql.org
Subject: pgsql: Micro-optimize some slower queries in the opr_sanity regression
Date: Sun, 30 Apr 2017 00:15:40 +0000
Message-ID: <E1d4cWa-0005uD-HT@gemulon.postgresql.org> (raw)
List-Unsubscribe:  <mailto:majordomo@postgresql.org?body=unsub%20pgsql-committers>

Micro-optimize some slower queries in the opr_sanity regression test.

Convert the binary_coercible() and physically_coercible() functions from
SQL to plpgsql.  It's not that plpgsql is inherently better at doing
queries; if you simply convert the previous single SQL query into one
RETURN expression, it's no faster.  The problem with the existing code
is that it fools the plancache into deciding that it's worth re-planning
the query every time, since constant-folding with a concrete value for $2
allows elimination of at least one sub-SELECT.  In reality that's using the
planner to do the equivalent of a few runtime boolean tests, causing the
function to run much slower than it should.  Splitting the AND/OR logic
into separate plpgsql statements allows each if-expression to acquire a
static plan.

Also, get rid of some uses of obj_description() in favor of explicitly
joining to pg_description, allowing the joins to be optimized better.
(Someday we might improve the SQL-function-inlining logic enough that
this happens automatically, but today is not that day.)

Together, these changes reduce the runtime of the opr_sanity regression
test by about a factor of two on one of my slower machines.  They don't
seem to help as much on a fast machine, but this should at least benefit
the buildfarm.

Branch
------
master

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

Modified Files
--------------
src/test/regress/expected/opr_sanity.out | 76 +++++++++++++++++++++-----------
src/test/regress/sql/opr_sanity.sql      | 76 +++++++++++++++++++++-----------
2 files changed, 100 insertions(+), 52 deletions(-)


-- 
Sent via pgsql-committers mailing list (pgsql-committers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-committers


Message-ID: <E1d4cWa-0005uD-HT@gemulon.postgresql.org>
Permalink:  ../E1d4cWa-0005uD-HT@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1d4cWa-0005uD-HT@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: Micro-optimize some slower queries in the opr_sanity regression
  In-Reply-To: <E1d4cWa-0005uD-HT@gemulon.postgresql.org>
  References: <E1d4cWa-0005uD-HT@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