pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Querying w/ join slow for large/many child tables
3+ messages / 3 participants
[nested] [flat]

* Querying w/ join slow for large/many child tables
@ 2019-01-30 02:49 Wells Oliver <wells.oliver@gmail.com>
  2019-01-30 03:30 ` Re: Querying w/ join slow for large/many child tables Adrian Klaver <adrian.klaver@aklaver.com>
  2019-01-30 05:58 ` Re: Querying w/ join slow for large/many child tables Ron <ronljohnsonjr@gmail.com>
  0 siblings, 2 replies; 3+ messages in thread

From: Wells Oliver @ 2019-01-30 02:49 UTC (permalink / raw)
  To: pgsql-general@lists.postgresql.org

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.

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?

Thank you.

-- 
Wells Oliver
wells.oliver@gmail.com <wellsoliver@gmail.com>

^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: Querying w/ join slow for large/many child tables
  2019-01-30 02:49 Querying w/ join slow for large/many child tables Wells Oliver <wells.oliver@gmail.com>
@ 2019-01-30 03:30 ` Adrian Klaver <adrian.klaver@aklaver.com>
  1 sibling, 0 replies; 3+ messages in thread

From: Adrian Klaver @ 2019-01-30 03:30 UTC (permalink / raw)
  To: Wells Oliver <wells.oliver@gmail.com>; pgsql-general@lists.postgresql.org

On 1/29/19 6: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.
> 
> 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?

https://wiki.postgresql.org/wiki/Slow_Query_Questions

> 
> Thank you.
> 
> -- 
> Wells Oliver
> wells.oliver@gmail.com <mailto:wellsoliver@gmail.com>


-- 
Adrian Klaver
adrian.klaver@aklaver.com




^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: Querying w/ join slow for large/many child tables
  2019-01-30 02:49 Querying w/ join slow for large/many child tables Wells Oliver <wells.oliver@gmail.com>
@ 2019-01-30 05:58 ` Ron <ronljohnsonjr@gmail.com>
  1 sibling, 0 replies; 3+ messages in thread

From: Ron @ 2019-01-30 05:58 UTC (permalink / raw)
  To: pgsql-general@lists.postgresql.org

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.

^ permalink  raw  reply  [nested|flat] 3+ messages in thread


end of thread, other threads:[~2019-01-30 05:58 UTC | newest]

Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2019-01-30 02:49 Querying w/ join slow for large/many child tables Wells Oliver <wells.oliver@gmail.com>
2019-01-30 03:30 ` Adrian Klaver <adrian.klaver@aklaver.com>
2019-01-30 05:58 ` Ron <ronljohnsonjr@gmail.com>

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