Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1X0AJE-0004RU-Td for pgsql-performance@arkaria.postgresql.org; Thu, 26 Jun 2014 14:05:53 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1X0AJE-0000HL-9N for pgsql-performance@arkaria.postgresql.org; Thu, 26 Jun 2014 14:05:52 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1X0AJD-0000HE-2G for pgsql-performance@postgresql.org; Thu, 26 Jun 2014 14:05:51 +0000 Received: from smtp.optionshouse.com ([38.98.137.6] helo=smtp.peak6.com) by makus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1X0AJ5-0006zn-1A for pgsql-performance@postgresql.org; Thu, 26 Jun 2014 14:05:49 +0000 X-AuditID: 0a64cb20-f79426d000005a0a-94-53ac28b4d443 Message-ID: <53AC28AF.1060500@optionshouse.com> Date: Thu, 26 Jun 2014 09:05:35 -0500 From: Shaun Thomas User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.5.0 MIME-Version: 1.0 To: AJ Weber , "pgsql-performance@postgresql.org" Subject: Re: how to improve perf of 131MM row table? References: <53AB2CB1.8080201@comcast.net> <53AB35CC.10202@optionshouse.com> <1801a5d4-c3f1-4c0c-9c2c-ffb9d7f723a3@email.android.com> <53AB4551.4070207@optionshouse.com> <53AC1F6E.4000700@comcast.net> In-Reply-To: <53AC1F6E.4000700@comcast.net> Content-Type: text/plain; charset="windows-1252"; format=flowed content-transfer-encoding: 7bit X-Originating-IP: [10.10.220.56] X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFjrPIsWRmVeSWpSXmKPExsXClcIrprtFY02wwY0PRhZ3199jt7g+8xyz A5PH5MdzGD0u7JvGHsAU1cBok5iXl1+SWJKqkJJanGyr5F9QkpmfV+yRX1qcquCSWZyck5iZ m1qkpJCZYqtkrKRQkJOYnJqbmldiq5RYUJCal6Jkx6WAAWyAyjLzFFLzkvNTMvPSbZU8g/11 LSxMLXUNlezikUFCJ0vGpusb2Qqa+SrOdx5hbGDs4O5i5OCQEDCR6DnN1MXICWSKSVy4t54N xOYV0Je4u/Q6I4jNIqAqcWPVGzCbTUBXYlL/CrAaUYEwiY9H10HVC0qcnPmEBcQWEciS2Dhl PzuILSxgJzHn5kGgOBeHkMAJRonN55vAEpwC2hKr5vxhBbmBWcBe4sHWMpAws4C8xPa3c5hB bCGgvSuaJ7JBnKkAdFvqBEb+WUi2zUJonoWkeQEj8ypG8eKyxOSMTNOC4tySAiO9gtTEbDO9 vNSSTYzgWDutsIPxe6fVIUYBDkYlHl4BhtXBQqyJZcWVuYcYJTiYlUR4j0mtCRbiTUmsrEot yo8vKs1JLT7E6AMMjYnMUqLJ+cA0kFcSb2hsamBqaWpoam5qaIRDWEmc90hLXLCQQDow+rNT UwtSi2DGMXFwSjUwKp+8GZz4oGHKqS2r//uf70qd7a/JxHFq4d2qCUfi/KdwcgsWt8UuEGoX duc+t6riWfkrjSfP+S4Y2IrMsMq1E1juz/Enc+41U0fJXa/m/P675sKNnrd//P+JendHOM3k cBVju3y/0KuaY/MxyRvvtzPvVL+c42e33UnQNKxQWvWC1Dff08VcSizFGYmGWsxFxYkADequ jeICAAA= X-Pg-Spam-Score: -1.9 (-) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-performance Precedence: bulk Sender: pgsql-performance-owner@postgresql.org On 06/26/2014 08:26 AM, AJ Weber wrote: > The "master table" definition is attached as "table1.sql". > The "detail table" definition is attached as "table2.sql". I'm not sure what you think a primary key is, but neither of these tables have one. Primary keys are declared one of two ways: CREATE TABLE foo ( id BIGINT PRIMARY KEY, col1 VARCHAR, col2 INT ); Or this: CREATE TABLE foo ( id BIGINT, col1 VARCHAR, col2 INT ); ALTER TABLE foo ADD constraint pk_foo PRIMARY KEY (id); On your alf_node_properties table, you only have an index on node_id because you created one. If you look at your alf_node table, there is no index on the id column at all. This is confirmed by the explain output you attached: Seq Scan on alf_node node (cost=0.00..227265.29 rows=5733429 width=16) (actual time=0.013..2029.649 rows=5733888 loops=1) Since it has no index, the database is reading the entire table to find your matching values. Then it's using the index on node_id in the other table to find the 'detail' matches, as seen here: Bitmap Index Scan on fk_alf_nprop_n (cost=0.00..1240.00 rows=52790 width=0) (actual time=0.552..0.552 rows=1071 loops=1) Add an actual primary key to your alf_node table, and your query performance should improve substantially. But I also strongly suggest you spend some time learning how to read an EXPLAIN plan, as that would have made your problem obvious immediately. Here's a link for your version: http://www.postgresql.org/docs/9.0/static/sql-explain.html You should still consider upgrading to the latest release of 9.0 too. -- Shaun Thomas OptionsHouse, LLC | 141 W. Jackson Blvd. | Suite 800 | Chicago IL, 60604 312-676-8870 sthomas@optionshouse.com ______________________________________________ See http://www.peak6.com/email_disclaimer/ for terms and conditions related to this email -- Sent via pgsql-performance mailing list (pgsql-performance@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-performance