Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1UXig6-0001Cv-80 for pgsql-performance@arkaria.postgresql.org; Thu, 02 May 2013 01:51:22 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.72) (envelope-from ) id 1UXig5-0004TA-EB for pgsql-performance@arkaria.postgresql.org; Thu, 02 May 2013 01:51:21 +0000 Received: from makus.postgresql.org ([2001:4800:7903:4::125]) by malur.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1UXig3-0004T2-D8 for pgsql-performance@postgresql.org; Thu, 02 May 2013 01:51:19 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1UXig1-0002vU-Il for pgsql-performance@postgresql.org; Thu, 02 May 2013 01:51:18 +0000 Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.5/8.14.5) with ESMTP id r421pGbC009393; Wed, 1 May 2013 21:51:16 -0400 (EDT) From: Tom Lane To: Craig James cc: "pgsql-performance@postgresql.org" Subject: Re: 100x slowdown for nearly identical tables In-reply-to: References: <7768.1367453912@sss.pgh.pa.us> Comments: In-reply-to Craig James message dated "Wed, 01 May 2013 17:45:11 -0700" Date: Wed, 01 May 2013 21:51:16 -0400 Message-ID: <9392.1367459476@sss.pgh.pa.us> X-Pg-Spam-Score: -4.5 (----) 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 Craig James writes: > On Wed, May 1, 2013 at 5:18 PM, Tom Lane wrote: >> It looks like old_str_conntab is more or less clustered by "id", >> and str_conntab not so much. You could try EXPLAIN (ANALYZE, BUFFERS) >> (on newer PG versions) to verify how many distinct pages are getting >> touched during the indexscan. > Yeah, now that you say it, it's obvious. The original table was built with > ID from a sequence, so it's going to be naturally clustered by ID. The new > table was built by reloading the data in alphabetical order by supplier > name, so it would have scattered the IDs all over the place. > I guess I could actually cluster the new table, but since that one table > holds about 90% of the total data in the database, that would be a chore. > Probably better to find a more efficient way to do the query. Just out of curiosity, you could try forcing a bitmap indexscan to see how much that helps. The planner evidently thinks "not at all", but it's been wrong before ;-) regards, tom lane -- Sent via pgsql-performance mailing list (pgsql-performance@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-performance