pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Ron <ronljohnsonjr@gmail.com>
To: pgsql-general@lists.postgresql.org
Subject: Re: Querying w/ join slow for large/many child tables
Date: Tue, 29 Jan 2019 23:58:53 -0600
Message-ID: <91a008bf-180b-f60b-b8e1-39c32537baee@gmail.com> (raw)
In-Reply-To: <CAOC+FBVMRLnbKCwMKpHYu3buHe2h2sztxS2fk7r_rBq=05nMFg@mail.gmail.com>
References: <CAOC+FBVMRLnbKCwMKpHYu3buHe2h2sztxS2fk7r_rBq=05nMFg@mail.gmail.com>

On 1/29/19 8:49 PM, Wells Oliver wrote:
> I have a primary parent table with a child table per week of the year for 
> each week back through 2015. There are a lot of child tables. Each week's 
> child table has maybe 80-110m rows.

A *partititioned* table?

>
> When I join to the parent table on a column, it's very slow, but when I 
> manually specify the specific week's child table, it's quite fast, e.g.
>
> Slow:
> select * from foo
> join schema.mytable on foo.col = mytable.col
>
> vs. fast:
> select * from foo
> join schema.mytable_2015_wk33 as mytable on foo.col = mytable.col
>
> What's the resolution to make querying the table faster in terms of it 
> finding the appropriate child table? Is it putting an index on `col` on 
> each child table? Some other thing?

If it's a partitioned table, then yes, putting the appropriate indexes on 
each child table as well as the empty parent table is what we do.

-- 
Angular momentum makes the world go 'round.

view thread (3+ messages)

Message-ID: <91a008bf-180b-f60b-b8e1-39c32537baee@gmail.com>
Permalink:  ../91a008bf-180b-f60b-b8e1-39c32537baee@gmail.com/
Also on:    postgresql.org/message-id/91a008bf-180b-f60b-b8e1-39c32537baee@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-general@postgresql.org
  Cc: ronljohnsonjr@gmail.com
  Subject: Re: Querying w/ join slow for large/many child tables
  In-Reply-To: <91a008bf-180b-f60b-b8e1-39c32537baee@gmail.com>
  References: <CAOC+FBVMRLnbKCwMKpHYu3buHe2h2sztxS2fk7r_rBq=05nMFg@mail.gmail.com> <91a008bf-180b-f60b-b8e1-39c32537baee@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