Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1XsrPS-0007CR-Lj for pgsql-performance@arkaria.postgresql.org; Mon, 24 Nov 2014 11:02:22 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1XsrPR-0006xx-W0 for pgsql-performance@arkaria.postgresql.org; Mon, 24 Nov 2014 11:02:22 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1XsrPQ-0006xq-Tf for pgsql-performance@postgresql.org; Mon, 24 Nov 2014 11:02:20 +0000 Received: from smtp.dc.baikal.ru ([87.103.128.133]) by magus.postgresql.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.80) (envelope-from ) id 1XsrPN-0000Ig-A3 for pgsql-performance@postgresql.org; Mon, 24 Nov 2014 11:02:19 +0000 Received: from [192.168.17.193] (it00.dc-local [192.168.17.193]) (authenticated bits=0) by smtp.dc.baikal.ru (8.13.8/8.13.8) with ESMTP id sAOB2C30027010 for ; Mon, 24 Nov 2014 19:02:12 +0800 Message-ID: <5473103A.5040004@dc.baikal.ru> Date: Mon, 24 Nov 2014 19:02:18 +0800 From: Vlad Arkhipov User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.2.0 MIME-Version: 1.0 To: pgsql-performance Subject: Why don't use index on x when ORDER BY x, y? Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit 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 Hello, I wonder why Postgres does not use index in the query below? It is a quite common use-case when you want to sort records by an arbitrary set of columns but do not want to create a lot of compound indexes for all possible combinations of them. It seems that if, for instance, your query's ORDER BY is x, y, z then any of these indexes could be used to improve the performance: (x); (x, y); (x, y, z). create temp table t as select s as x, s % 10 as y, s % 100 as z from generate_series(1, 1000000) s; analyze t; create index idx1 on t (y); select * from t order by y desc, x limit 10; -- Sent via pgsql-performance mailing list (pgsql-performance@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-performance