Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1UWpv0-0005nM-IT for pgsql-bugs@arkaria.postgresql.org; Mon, 29 Apr 2013 15:23:06 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.72) (envelope-from ) id 1UWpuy-0001EI-Ss for pgsql-bugs@arkaria.postgresql.org; Mon, 29 Apr 2013 15:23:04 +0000 Received: from makus.postgresql.org ([2001:4800:7903:4::125]) by malur.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1UWpux-0001E9-Vm for pgsql-bugs@postgresql.org; Mon, 29 Apr 2013 15:23:04 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1UWpuv-0004lb-KP for pgsql-bugs@postgresql.org; Mon, 29 Apr 2013 15:23:03 +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 r3TFMwiL003000; Mon, 29 Apr 2013 11:22:58 -0400 (EDT) From: Tom Lane To: Marc Schablewski cc: pgsql-bugs@postgresql.org Subject: Re: Optimizer problem with multi-column index In-reply-to: <517E5435.9060801@clickware.de> References: <517E5435.9060801@clickware.de> Comments: In-reply-to Marc Schablewski message dated "Mon, 29 Apr 2013 13:06:29 +0200" Date: Mon, 29 Apr 2013 11:22:58 -0400 Message-ID: <2999.1367248978@sss.pgh.pa.us> X-Pg-Spam-Score: -4.3 (----) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org Marc Schablewski writes: > we have an issue concerning multi-column indexes not being used by the planner. I see no particular bug here, just a rational response to an artificial test case. The planner is being discouraged by the random character of the data in your first index column: that means that an indexscan on that index would jump all over the place while accessing the table. In contrast, the other index is *exactly* in heap order and so using it will result in nice sequential touches of the heap. So with default random_page_cost, the cost to use the two-column index comes out quite a bit higher than the cost to use the one-column index. A bitmap scan is less subject to the random-access problem, but it still loses out compared to following an index that's exactly in heap order. Whether this test case corresponds very well to your real use case is hard to say, but it seems a bit extreme from here. BTW, had you vacuumed the table, the planner would've preferred an index-only scan of the two-column index, since with the table marked all-visible the potential for lots of random fetches from the heap goes away. But you didn't. If these plan choices don't correspond to the actual runtimes you're seeing, that probably suggests that you need to lower random_page_cost for your environment. This test case is small enough to fit in RAM on most machines, so you'd have to set random_page_cost to 1 to expect to get accurate predictions for the test case as-is. I don't know how large your real table is ... regards, tom lane -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs