Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dtdCm-0005SM-8N for pgsql-bugs@arkaria.postgresql.org; Sun, 17 Sep 2017 17:18:04 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1dtdCl-0003e7-Nl for pgsql-bugs@arkaria.postgresql.org; Sun, 17 Sep 2017 17:18:03 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1dtdCk-0003dg-6S for pgsql-bugs@postgresql.org; Sun, 17 Sep 2017 17:18:02 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1dtdCc-00085Q-UB for pgsql-bugs@postgresql.org; Sun, 17 Sep 2017 17:18:01 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id v8HHFYgH012045; Sun, 17 Sep 2017 13:15:34 -0400 From: Tom Lane To: Tomas Vondra cc: Dilyan Palauzov , pgsql-bugs@postgresql.org Subject: Re: Query planner skipping index depending on DISTINCT parameter order (2) In-reply-to: <271e4961-abfa-06ef-a502-cf00a31b236a@2ndquadrant.com> References: <3c651d99-a943-4e21-4ec9-604b142c85e0@aegee.org> <57ccc03b-279a-63f7-19c6-6fe3b2d0e1be@aegee.org> <271e4961-abfa-06ef-a502-cf00a31b236a@2ndquadrant.com> Comments: In-reply-to Tomas Vondra message dated "Sun, 17 Sep 2017 18:39:27 +0200" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <12043.1505668534.1@sss.pgh.pa.us> Date: Sun, 17 Sep 2017 13:15:34 -0400 Message-ID: <12044.1505668534@sss.pgh.pa.us> 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 Tomas Vondra writes: > On 09/17/2017 02:30 AM, Dilyan Palauzov wrote: >> The behaviour behind DISTINCT and indexes surprises me, as the >> query planner does reorder the columns for SELECT to determine the >> most suitable index. > Well, I agree it's somewhat reasonable optimization. The thing is, the > planner/optimizer does not start with all features on day 1, it gets > improved over time. And no one implemented this bit yet. For the DISTINCT ON case, the user-visible semantics are actually pretty tightly tied to ORDER BY, so that it would not be very reasonable to consider any other orderings than the given column order anyway. For plain DISTINCT, yeah we could consider other orderings ... but we're rather unlikely to find an index that matches all the output columns, regardless of what order they're in. So it's just not that exciting. IOW, somebody might get around to this someday, but don't hold your breath; there's lots of higher-value fruit to be reaching for. 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