pg.ddx.io  pgsql-performance@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Samuel Gendler <sgendler@ideasculptor.com>
To: Joseph Shraibman <jks@selectacast.net>
Cc: Robert Haas <robertmhaas@gmail.com>
Cc: pgsql-performance@postgresql.org
Subject: Re: index usage on queries on inherited tables
Date: Wed, 27 Apr 2011 17:18:17 -0700
Message-ID: <BANLkTiktd3hKAV9ntLWTxPCdz0Lh7usSUw@mail.gmail.com> (raw)
In-Reply-To: <4DB88690.5050701@selectacast.net>
References: <in36ut$24hs$1@news.hub.org>
	<BANLkTi=g=dA7Bt_P=m0Amknp9r-k6x5-Sw@mail.gmail.com>
	<4DB88690.5050701@selectacast.net>

On Wed, Apr 27, 2011 at 2:11 PM, Joseph Shraibman <jks@selectacast.net>wrote:

> On 04/27/2011 04:32 PM, Robert Haas wrote:
> > In the first case, PostgreSQL evidently thinks that using the indexes
> > will be slower than just ignoring them.  You could find out whether
> > it's right by trying it with enable_seqscan=off.
>
> My point is that this is just a problem with inherited tables.  It
> should be obvious to postgres that few rows are being returned, but in
> the inherited tables case it doesn't use indexes.  This was just an
> example.  In a 52 gig table I have a "select id from table limit 1 order
> by id desc" returns instantly, but as soon as you declare a child table
> it tries to seq scan all the tables.
>
>
If I'm understanding correctly, this kind of obviates the utility of
partitioning if you structure a warehouse in a traditional manner.  Assuming
a fact table partitioned by time, but with foreign keys to a time dimension,
it is now not possible to gain any advantage from the partitioning if
selecting on columns in the time dimension.

"select * from fact_table f join time_dimension t on f.time_id = t.time_id
where t.quarter=3 and t.year = 2010" will scan all partitions of the fact
table despite the fact that all of the rows would come from 3 partitions,
assuming a partitioning schema that uses one partition for each month.

I use a time id that is calculable from the from the timestamp so it doesn't
need to be looked up, and partitioning on time_id directly is easy enough to
handle, but if I'm understanding the problem, it sounds like nothing short
of computing the appropriate time ids before issuing the query and then
including a 'where f.time_id between x and y' clause to the query will
result in the partitions being correctly excluded.  Is that what people are
doing to solve this problem?  The alternative is to leave a timestamp column
in the fact table (something I tend to do since it makes typing ad-hoc
queries in psql much easier) and partition on that column and then always
include a where clause for that column that is at least as large as the
requested row range.  Both result in fairly ugly queries, though I can
certainly see how I might structure my code to always build queries which
adhere to this.

I'm just in the process of designing a star schema for a project and was
intending to use exactly the structure I described at the top of the email.
Is there a postgres best-practices for solving this problem? There's no way
I can get away without partitioning.  I'm looking at a worst case table of
100,000 rows being written every 5 minutes, 24x7 - 29 million rows per day,
a billion rows per month - with most queries running over a single month or
comparing same months from differing years and quarters - so a month based
partitioning.  Normal case is closer to 10K rows per 5 minutes.

Suggestions?

--sam

view thread (6+ messages)  latest in thread

Message-ID: <BANLkTiktd3hKAV9ntLWTxPCdz0Lh7usSUw@mail.gmail.com>
Permalink:  ../BANLkTiktd3hKAV9ntLWTxPCdz0Lh7usSUw@mail.gmail.com/
Also on:    postgresql.org/message-id/BANLkTiktd3hKAV9ntLWTxPCdz0Lh7usSUw@mail.gmail.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 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-performance@postgresql.org
  Cc: sgendler@ideasculptor.com, jks@selectacast.net, robertmhaas@gmail.com
  Subject: Re: index usage on queries on inherited tables
  In-Reply-To: <BANLkTiktd3hKAV9ntLWTxPCdz0Lh7usSUw@mail.gmail.com>
  References: <in36ut$24hs$1@news.hub.org> <BANLkTi=g=dA7Bt_P=m0Amknp9r-k6x5-Sw@mail.gmail.com> <4DB88690.5050701@selectacast.net> <BANLkTiktd3hKAV9ntLWTxPCdz0Lh7usSUw@mail.gmail.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