Skip site navigation (1) Skip section navigation (2)

Re: What is the right way to deal with a table with rows that are not in a random order?

From: Douglas Alan <darkwater42(at)gmail(dot)com>
To: pgsql-general(at)postgresql(dot)org
Cc: Simon Riggs <simon(at)2ndquadrant(dot)com>
Subject: Re: What is the right way to deal with a table with rows that are not in a random order?
Date: 2009-05-28 19:03:32
Message-ID: ce6334d00905281203n10fa5188l7dcaaffe50d26b05@mail.gmail.com (view raw or flat)
Thread:
Lists: pgsql-general
On Thu, May 28, 2009 at 4:14 AM, Simon Riggs <simon(at)2ndquadrant(dot)com> wrote:

> Partition the table, then scan the correct partition.

If I do that, will Postgres figure out the "right thing" to do if the
parent table is queried instead?  Also, what are the performance
implications then for doing queries that span all the partitions,
which will be the norm for our application?

The application in question is a kind of data warehousing thing (of
astronomical stars), and there's an ORM in the middle, so it's not
easy for us to hand-tune how individual queries are specified.
Instead, we have to structure the database and the indexes so that
things generally perform well, without having to tweak specific
queries.

Users can specify fairly arbitrary search criteria.  All of the
queries should perform well.  By "well", I mean within 10 seconds or
so.  Scanning all of the 150 million rows takes much longer than 10
seconds, unfortunately.

Any one of these "solutions" will cause Postgres to do an index scan
in the problematic case where Postgres is deciding to a sequential
scan.  The index scan performs snappily enough:

   - Using "order by" on the query.

   - Changing the search value for the column to a value that occurs
less frequently.

   - Fetching the value to search for via a sub-query so that Postgres
can't determine a priori that the
     value being searched value occurs so commonly.

Unfortunately, as I mentioned, due to the ORM, none of these solutions
really work for us in practice, as opposed to at a psql prompt.

|>ouglas

In response to

Responses

pgsql-general by date

Next:From: Douglas AlanDate: 2009-05-28 19:12:58
Subject: Re: What is the right way to deal with a table with rows that are not in a random order?
Previous:From: Marcelo GiovaneDate: 2009-05-28 18:26:16
Subject: Please remove me from the list!

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group