ORDER BY and LIMIT not propagated on inherited tables / UNIONs - Mailing list pgsql-performance

From Matteo Beccati
Subject ORDER BY and LIMIT not propagated on inherited tables / UNIONs
Date
Msg-id 43182789.4070307@beccati.com
Whole thread Raw
Responses Re: ORDER BY and LIMIT not propagated on inherited  (Simon Riggs <simon@2ndquadrant.com>)
Re: ORDER BY and LIMIT not propagated on inherited  (Simon Riggs <simon@2ndquadrant.com>)
List pgsql-performance
Hi,

I'm using inherited tables to partition some data which can grow very
large. Recently I discovered that a simple query that on a regular table
would use an index was instead using seq scans (70s vs a guessed 2s).
The well known query is:

SELECT foo FROM bar ORDER BY foo DESC LIMIT 1

(The same applies for SELECT MIN(foo) FROM bar using 8.1)


The query plan generated when running the query on a table which has
inheritance forces the planner to choose a seq_scan for each table.
Wouldn't be a good thing to also promote ORDER BYs and LIMITs to each
subscan (like WHERE does)?

I needed a quick solution, so I wrote a function which looks each
inherited table separately and my problem is partially solved, but I
think that a (hopefully) little change in the optimizer could be advisable.

Attached are some EXPLAIN ANALYZE outputs of my suggestion.


Best regards
--
Matteo Beccati
http://phpadsnew.com
http://phppgads.com

Attachment

pgsql-performance by date:

Previous
From: Richard Huxton
Date:
Subject: Re: Update is more affected( taking more time) than Select
Next
From: Alex Stapleton
Date:
Subject: Re: Avoid using swap in a cluster