pg.ddx.io  pgsql-performance@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Marc Morin <marc@sandvine.com>
To: psql-performance@postgresql.org
Subject: sort/limit across union all
Date: Mon, 14 Nov 2005 08:25:10 -0500
Message-ID: <2BCEB9A37A4D354AA276774EE13FB8C263B0F4@mailserver.sandvine.com> (raw)

We have a large DB with partitioned tables in postgres.   We have had
trouble with a ORDER/LIMIT type query.  The order and limit are not
pushed down to the sub-tables....
 
CREATE TABLE base (
    foo int 
);
 
CREATE TABLE bar_0
    extra int
) INHERITS (base);
ALTER TABLE bar ADD PRIMARY KEY (foo);
 
-- repeated for bar_0... bar_40
 
SELECT foo FROM base ORDER BY foo LIMIT 10;
 
is real slow. What is required to make the query planner generate the
following instead... (code change i know, but how hard would it be?)
 
SELECT
    foo
FROM
(
    SELECT
        *
    FROM bar_0
    ORDER BY foo LIMIT 10
UNION ALL
    SELECT
        *
    FROM bar_1
    ORDER BY foo LIMIT 10
....
) AS base
ORDER BY foo
LIMIT 10;
 
 

Message-ID: <2BCEB9A37A4D354AA276774EE13FB8C263B0F4@mailserver.sandvine.com>
Permalink:  ../2BCEB9A37A4D354AA276774EE13FB8C263B0F4@mailserver.sandvine.com/
Also on:    postgresql.org/message-id/2BCEB9A37A4D354AA276774EE13FB8C263B0F4@mailserver.sandvine.com

 · 

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: marc@sandvine.com, psql-performance@postgresql.org
  Subject: Re: sort/limit across union all
  In-Reply-To: <2BCEB9A37A4D354AA276774EE13FB8C263B0F4@mailserver.sandvine.com>

* 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