pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Robert Haas <rhaas@postgresql.org>
To: pgsql-committers@postgresql.org
Subject: pgsql: Use abbreviated keys for faster sorting of text datums.
Date: Mon, 19 Jan 2015 20:28:37 +0000
Message-ID: <E1YDIw9-0001Ol-3r@gemulon.postgresql.org> (raw)
List-Unsubscribe:  <mailto:majordomo@postgresql.org?body=unsub%20pgsql-committers>

Use abbreviated keys for faster sorting of text datums.

This commit extends the SortSupport infrastructure to allow operator
classes the option to provide abbreviated representations of Datums;
in the case of text, we abbreviate by taking the first few characters
of the strxfrm() blob.  If the abbreviated comparison is insufficent
to resolve the comparison, we fall back on the normal comparator.
This can be much faster than the old way of doing sorting if the
first few bytes of the string are usually sufficient to resolve the
comparison.

There is the potential for a performance regression if all of the
strings to be sorted are identical for the first 8+ characters and
differ only in later positions; therefore, the SortSupport machinery
now provides an infrastructure to abort the use of abbreviation if
it appears that abbreviation is producing comparatively few distinct
keys.  HyperLogLog, a streaming cardinality estimator, is included in
this commit and used to make that determination for text.

Peter Geoghegan, reviewed by me.

Branch
------
master

Details
-------
http://git.postgresql.org/pg/commitdiff/4ea51cdfe85ceef8afabceb03c446574daa0ac23

Modified Files
--------------
src/backend/access/nbtree/nbtsort.c    |    2 +
src/backend/commands/analyze.c         |    6 +
src/backend/executor/nodeAgg.c         |    4 +
src/backend/executor/nodeMergeAppend.c |    9 +
src/backend/executor/nodeMergejoin.c   |    8 +
src/backend/lib/Makefile               |    2 +-
src/backend/lib/hyperloglog.c          |  228 ++++++++++++++++++
src/backend/utils/adt/orderedsetaggs.c |    8 +-
src/backend/utils/adt/varlena.c        |  330 +++++++++++++++++++++++--
src/backend/utils/sort/tuplesort.c     |  413 ++++++++++++++++++++++++++++----
src/include/lib/hyperloglog.h          |   67 ++++++
src/include/pg_config_manual.h         |   14 +-
src/include/utils/sortsupport.h        |  134 ++++++++++-
13 files changed, 1149 insertions(+), 76 deletions(-)


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


view thread (2+ messages)  latest in thread

Message-ID: <E1YDIw9-0001Ol-3r@gemulon.postgresql.org>
Permalink:  ../E1YDIw9-0001Ol-3r@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1YDIw9-0001Ol-3r@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: rhaas@postgresql.org
  Subject: Re: pgsql: Use abbreviated keys for faster sorting of text datums.
  In-Reply-To: <E1YDIw9-0001Ol-3r@gemulon.postgresql.org>
  References: <E1YDIw9-0001Ol-3r@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