pg.ddx.io  pgsql-performance@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Alexis Lê-Quôc <alq@datadoghq.com>
Cc: pgsql-performance@postgresql.org
Subject: Re: Better performance possible for a pathological query?
Date: Wed, 07 Aug 2013 12:07:37 -0400
Message-ID: <6581.1375891657@sss.pgh.pa.us> (raw)
In-Reply-To: <CAAGz8TOnHrOJyHwr8Zo2U6smY_UE3GO=aYcyjkgLeTKfM3K41g@mail.gmail.com>
References: <CAAGz8TOnHrOJyHwr8Zo2U6smY_UE3GO=aYcyjkgLeTKfM3K41g@mail.gmail.com>
List-Unsubscribe:  <mailto:majordomo@postgresql.org?body=unsub%20pgsql-performance>

=?UTF-8?B?QWxleGlzIEzDqi1RdcO0Yw==?= <alq@datadoghq.com> writes:
> The query itself is very simple: a primary key lookup on a 1.5x10^7 rows.
> The issue is that we are looking up over 11,000 primary keys at once,
> causing the db to consume a lot of CPU.

It looks like most of the runtime is probably going into checking the
c.key = ANY (ARRAY[...]) construct.  PG isn't especially smart about that
if it fails to optimize the construct into an index operation --- I think
it's just searching the array linearly for each row meeting the other
restrictions on c.

You could try writing the test like this:
    c.key = ANY (VALUES (1), (17), (42), ...)
to see if the sub-select code path gives better results than the array
code path.  In a quick check it looked like this might produce a hash
join, which seemed promising anyway.

			regards, tom lane


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



view thread (3+ messages)  latest in thread

Message-ID: <6581.1375891657@sss.pgh.pa.us>
Permalink:  ../6581.1375891657@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/6581.1375891657@sss.pgh.pa.us

 · 

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 using the --to and --cc options:
  reply via email

  To: pgsql-performance@postgresql.org
  Cc: tgl@sss.pgh.pa.us, alq@datadoghq.com
  Subject: Re: Better performance possible for a pathological query?
  In-Reply-To: <6581.1375891657@sss.pgh.pa.us>

* 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