Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1goiup-0001BX-NO for pgsql-general@arkaria.postgresql.org; Wed, 30 Jan 2019 06:00:03 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1goitp-0004xP-MQ for pgsql-general@arkaria.postgresql.org; Wed, 30 Jan 2019 05:59:01 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1goitp-0004xI-Bp for pgsql-general@lists.postgresql.org; Wed, 30 Jan 2019 05:59:01 +0000 Received: from mail-oi1-x22b.google.com ([2607:f8b0:4864:20::22b]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1goitn-0002a7-7U for pgsql-general@lists.postgresql.org; Wed, 30 Jan 2019 05:59:00 +0000 Received: by mail-oi1-x22b.google.com with SMTP id y23so18307676oia.4 for ; Tue, 29 Jan 2019 21:58:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-language; bh=eGZ97+gpvfUp2XnVWpNBrhexNZYL2oUynckooV2m0xE=; b=ej+GQcCHfLhDC3W9u2NiwFiAgvhLSxFSPivvSGqTxHTUxUhakhzTEmFCCc2y0LSZyc fnZNVlH0kRTjTbGlOMV/Em9y2P1yLJlvOcG/7k/9eWX05lCNDBvMCAW2EBIg3Pg4R6qV cSl3aaNs6c3eaI/uobYMOAjs/6OzhAhiSKUMfSqj1JN/NZ3IQUiRRr7vJJwxMLkn2p5v SKkYBebGD/NJ/5WdOiDkU8PiPasyvwbYVhPEZeAoVeA00Nj2bRRIPwoPWYU6jUPlFyiv yaqfq6v/3EZ23qTt2nXtgQ4S1RolNaTgH1OQ931dI+z/SRjjBI9Y1AT0kn7fIDJjtdq4 r3XA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language; bh=eGZ97+gpvfUp2XnVWpNBrhexNZYL2oUynckooV2m0xE=; b=KvGm6+kxJRJDcvH7FWB6byQ3ThPya5hNuUcSLneUT/4Xhk2SnVDz1yK2d32Xvj4lh+ gfUvmckmb+ZwQLe7/4tWZXkXdpPHy/J8Y4gRyRO6SXy94Hg5OWtua2Dg3Ol3fEAAeKcG WT50u/KQ99CVWa95bSbYboYbLhnvGSg94JQN+IuHJGxM+qfZAEJLK8ygvxbvvhBoBIT6 446YoCtJJ0g1MifdJ5llUui/JG7laoUrBHALseXrUcEUqEAGr8la/lt2g/0EGzzdmFeY 6EjGLKlBzSzv671c0ICP+2CAmRg2QmRMaayHkbuVt06PUblTdXLlD3FhzNxR3qLSWZum HFKg== X-Gm-Message-State: AJcUukc9NbsDttWjiG0/FRU7BQhqmsPwfdIpsXsWH4zyEbZaesGbLXiI tuPssUWMV2vvEudfKqQJ0kECIHgF X-Google-Smtp-Source: AHgI3IbQECv1KpSIsCPUzKD14/eg0mzAL4M9vb8xX/kWSxgbUfbvr+6Kuo0TeaC1binZLUfVG/uVJA== X-Received: by 2002:aca:490c:: with SMTP id w12mr11747989oia.8.1548827934943; Tue, 29 Jan 2019 21:58:54 -0800 (PST) Received: from [192.168.1.10] (ip70-171-116-89.no.no.cox.net. [70.171.116.89]) by smtp.googlemail.com with ESMTPSA id a201sm290408oii.27.2019.01.29.21.58.53 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 29 Jan 2019 21:58:54 -0800 (PST) Subject: Re: Querying w/ join slow for large/many child tables To: pgsql-general@lists.postgresql.org References: From: Ron Message-ID: <91a008bf-180b-f60b-b8e1-39c32537baee@gmail.com> Date: Tue, 29 Jan 2019 23:58:53 -0600 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.4.0 MIME-Version: 1.0 In-Reply-To: Content-Type: multipart/alternative; boundary="------------D4E4D6D41A4047B9C1AE6DF1" Content-Language: en-US List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk This is a multi-part message in MIME format. --------------D4E4D6D41A4047B9C1AE6DF1 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit 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. --------------D4E4D6D41A4047B9C1AE6DF1 Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: 8bit 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.
--------------D4E4D6D41A4047B9C1AE6DF1--