Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1UciQ4-0005Jt-U7 for pgsql-performance@arkaria.postgresql.org; Wed, 15 May 2013 20:35:29 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.72) (envelope-from ) id 1UciQ3-0007vZ-Rx for pgsql-performance@arkaria.postgresql.org; Wed, 15 May 2013 20:35:27 +0000 Received: from makus.postgresql.org ([2001:4800:7903:4::125]) by malur.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1UciLw-00073R-OY for pgsql-performance@postgresql.org; Wed, 15 May 2013 20:31:12 +0000 Received: from plane.gmane.org ([80.91.229.3]) by makus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1UciLt-0002xv-JZ for pgsql-performance@postgresql.org; Wed, 15 May 2013 20:31:12 +0000 Received: from list by plane.gmane.org with local (Exim 4.69) (envelope-from ) id 1UciLr-0000au-1i for pgsql-performance@postgresql.org; Wed, 15 May 2013 22:31:07 +0200 Received: from ppp-46-244-182-120.dynamic.mnet-online.de ([46.244.182.120]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Wed, 15 May 2013 22:31:07 +0200 Received: from spam_eater by ppp-46-244-182-120.dynamic.mnet-online.de with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Wed, 15 May 2013 22:31:07 +0200 X-Injected-Via-Gmane: http://gmane.org/ To: pgsql-performance@postgresql.org From: Thomas Kellerer Subject: Re: Thinking About Correlated Columns (again) Date: Wed, 15 May 2013 22:31:46 +0200 Lines: 29 Message-ID: References: <5193AA62.2040700@optionshouse.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Complaints-To: usenet@ger.gmane.org X-Gmane-NNTP-Posting-Host: ppp-46-244-182-120.dynamic.mnet-online.de User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; de; rv:1.8.1.21) Gecko/20090302 Thunderbird/2.0.0.21 Mnenhy/0.7.5.666 In-Reply-To: <5193AA62.2040700@optionshouse.com> X-Pg-Spam-Score: 0.2 (/) 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 Shaun Thomas wrote on 15.05.2013 17:31: > Hi! > > This has been a pain point for quite a while. While we've had several > discussions in the area, it always seems to just kinda trail off and > eventually vanish every time it comes up. > > A really basic example of how bad the planner is here: > > CREATE TABLE foo AS > SELECT a.id, a.id % 1000 AS col_a, a.id % 1000 AS col_b > FROM generate_series(1, 1000000) a(id); > > CREATE INDEX idx_foo_ab ON foo (col_a, col_b); > > Index Scan using idx_foo_ab on foo (cost=0.00..6.35 rows=1 width=12) > (actual time=0.030..3.643 rows=1000 loops=1) > Index Cond: ((col_a = 50) AND (col_b = 50)) > > Hey, look! The row estimate is off by a factor of 1000. This > particular case doesn't suffer terribly from the mis-estimation, but > others do. Boy, do they ever. What happens if you create one index for each column? (instead of one combined index) For your example it does not seem to improve the situation, but maybe things get better with the "bad" queries? -- Sent via pgsql-performance mailing list (pgsql-performance@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-performance