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 1ir6WT-0000Hk-E3 for pgsql-admin@arkaria.postgresql.org; Mon, 13 Jan 2020 20:41:17 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1ir6WR-0003LD-T8 for pgsql-admin@arkaria.postgresql.org; Mon, 13 Jan 2020 20:41:15 +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 1ir6WR-0003L6-Jp for pgsql-admin@lists.postgresql.org; Mon, 13 Jan 2020 20:41:15 +0000 Received: from mout.perfora.net ([74.208.4.197]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1ir6WK-0006v5-VB for pgsql-admin@postgresql.org; Mon, 13 Jan 2020 20:41:15 +0000 Received: from [192.168.1.143] ([98.169.208.73]) by mrelay.perfora.net (mreueus004 [74.208.5.2]) with ESMTPSA (Nemesis) id 1N0WTY-1jcAlg2E2m-00wUQC; Mon, 13 Jan 2020 21:41:04 +0100 Subject: Re: Declarative partitioning, UUIDs, index issues. To: Wells Oliver Cc: pgsql-admin References: From: MichaelDBA Message-ID: <96ab1ca0-c527-8ba9-dedc-5cfe90eecc1e@sqlexec.com> Date: Mon, 13 Jan 2020 15:41:00 -0500 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 PostboxApp/7.0.10 MIME-Version: 1.0 In-Reply-To: Content-Type: multipart/alternative; boundary="------------FEDAAE479BEDAE076FC30DDA" Content-Language: en-US X-Provags-ID: V03:K1:6SHuUcltGGwaHZTT3OsX778u5a9B6LMDICVczkMp4v4nl67ZZm5 wE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vPyY2/5iT6GrfiR/2vAUQgIAXr6I 4UDLCr9wW7PCElKfwya8bl0lnpLo0HElIKgUmtrIg= List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk This is a multi-part message in MIME format. --------------FEDAAE479BEDAE076FC30DDA Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Hi Oliver, I know I am not addressing your immediate concern about why it is not using the index, but I have another question first: You are using a query that is not doing any partition exclusion since you are not providing the date on the where clause, which is the partitioning key, right?  If so, I would expect to see all the partitions in the explain output, but I only see 4 thru 8. Regards, Michael Vitale Wells Oliver wrote on 1/13/2020 12:21 PM: > Hi all. I have a table with 7 columns: uuid, date, smallint, smallint, > real, real, real. > > The PK is the uuid, date, smallint, smallint. > > It has 60 partitions on date, partitioned by month, back to 2015. Each > partition is roughly 40GB, about 350-450m rows. > > Doing a join to this table using the uuid is not using an index, so > it's never completing. So where this table is b: SELECT * FROM a JOIN > b ON A.uuid = B.uuid - I thought it might use the PK as the uuid is > the first column, but we end up with a ton of sequence scans: > >  Hash Join  (cost=113773.34..326420199.08 rows=1187847 width=46) >    Hash Cond: (a.uuid = myt.uuid) >    ->  Append  (cost=0.00..282743385.62 rows=11613643108 width=42) >          ->  Seq Scan on myt_2015_05 myt_4  (cost=0.00..7647300.32 > rows=395295232 width=42) >          ->  Seq Scan on myt_2015_06 myt_5  (cost=0.00..7233480.44 > rows=373904544 width=42) >          ->  Seq Scan on myt_2015_07 myt_6  (cost=0.00..6679997.60 > rows=345294560 width=42) >          ->  Seq Scan on myt_2015_08 myt_7  (cost=0.00..7426294.64 > rows=383871264 width=42) >          ->  Seq Scan on myt_2015_09 myt_8  (cost=0.00..7454691.04 > rows=385339104 width=42) > > Etc, all the way up to present. I then tried adding a btree index on > the uuid itself, same result. > > Selecting directly on the table where the uuid = some value will use > the index, but joining to the table will NOT. > > I ran analyze on the primary table, still a sequence scan. > > This table is useless without an index on the uuid, what might be the > issue? Might my partitions be too large? Something else? > > -- > Wells Oliver > wells.oliver@gmail.com --------------FEDAAE479BEDAE076FC30DDA Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: 8bit Hi Oliver,

I know I am not addressing your immediate concern about why it is not using the index, but I have another question first:

You are using a query that is not doing any partition exclusion since you are not providing the date on the where clause, which is the partitioning key, right?  If so, I would expect to see all the partitions in the explain output, but I only see 4 thru 8.

Regards,
Michael Vitale

Wells Oliver wrote on 1/13/2020 12:21 PM:
Hi all. I have a table with 7 columns: uuid, date, smallint, smallint, real, real, real.

The PK is the uuid, date, smallint, smallint.

It has 60 partitions on date, partitioned by month, back to 2015. Each partition is roughly 40GB, about 350-450m rows.

Doing a join to this table using the uuid is not using an index, so it's never completing. So where this table is b: SELECT * FROM a JOIN b ON A.uuid = B.uuid - I thought it might use the PK as the uuid is the first column, but we end up with a ton of sequence scans:

 Hash Join  (cost=113773.34..326420199.08 rows=1187847 width=46)
   Hash Cond: (a.uuid = myt.uuid)
   ->  Append  (cost=0.00..282743385.62 rows=11613643108 width=42)
         ->  Seq Scan on myt_2015_05 myt_4  (cost=0.00..7647300.32 rows=395295232 width=42)
         ->  Seq Scan on myt_2015_06 myt_5  (cost=0.00..7233480.44 rows=373904544 width=42)
         ->  Seq Scan on myt_2015_07 myt_6  (cost=0.00..6679997.60 rows=345294560 width=42)
         ->  Seq Scan on myt_2015_08 myt_7  (cost=0.00..7426294.64 rows=383871264 width=42)
         ->  Seq Scan on myt_2015_09 myt_8  (cost=0.00..7454691.04 rows=385339104 width=42)

Etc, all the way up to present. I then tried adding a btree index on the uuid itself, same result.

Selecting directly on the table where the uuid = some value will use the index, but joining to the table will NOT.

I ran analyze on the primary table, still a sequence scan.

This table is useless without an index on the uuid, what might be the issue? Might my partitions be too large? Something else?

--

--------------FEDAAE479BEDAE076FC30DDA--