From: Tomas Vondra <tomas.vondra@2ndquadrant.com>
To: Greg Stark <stark@mit.edu>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: Dilyan Palauzov <dilyan.palauzov@aegee.org>
Cc: PostgreSQL Bugs <pgsql-bugs@postgresql.org>
Subject: Re: Query planner skipping index depending on DISTINCT parameter order (2)
Date: Mon, 2 Oct 2017 00:03:29 +0200
Message-ID: <eaee8428-8d38-9ee6-b129-a29eeb8a80c2@2ndquadrant.com> (raw)
In-Reply-To: <CAM-w4HPhUKkB6uA5vSOxZRUenACj-qAbSrcEBdmB1x1PyJ7hYA@mail.gmail.com>
References: <3c651d99-a943-4e21-4ec9-604b142c85e0@aegee.org>
<57ccc03b-279a-63f7-19c6-6fe3b2d0e1be@aegee.org>
<cd89d79f-96df-1a1e-5821-ef111950eccf@2ndquadrant.com>
<a68737c6-601f-6846-2ba0-3795c942c81f@aegee.org>
<271e4961-abfa-06ef-a502-cf00a31b236a@2ndquadrant.com>
<12044.1505668534@sss.pgh.pa.us>
<CAM-w4HPhUKkB6uA5vSOxZRUenACj-qAbSrcEBdmB1x1PyJ7hYA@mail.gmail.com>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-bugs>
On 09/25/2017 12:43 PM, Greg Stark wrote:
> On 17 September 2017 at 18:15, Tom Lane <tgl@sss.pgh.pa.us> wrote:
>
>> 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.
>
> I don't follow this part. Are you saying a simple "select distinct a,b
> from table" is unlikely to find a matching index on <b,a>? Don't we
> already do exactly this for "select a,b from table group by a,b"?
FWIW we don't do that:
create table t (a int, b int);
insert into t select mod(i, 1000), mod(i, 1000)
from generate_series(1,1000000) S(i);
create index on t (a,b);
vacuum analyze t;
explain (costs off) select a, b, count(*) from t group by a , b;
QUERY PLAN
--------------------------------------------
GroupAggregate
Group Key: a, b
-> Index Only Scan using t_a_b_idx on t
(3 rows)
explain (costs off) select a, b, count(*) from t group by b , a;
QUERY PLAN
---------------------------
GroupAggregate
Group Key: b, a
-> Sort
Sort Key: b, a
-> Seq Scan on t
(5 rows)
But yeah, fixing this is probably more worthwhile than the original
DISTINCT ON issue ...
regards
--
Tomas Vondra http://www.2ndQuadrant.com
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services
--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-bugs@postgresql.org
Cc: tomas.vondra@2ndquadrant.com, stark@mit.edu, tgl@sss.pgh.pa.us, dilyan.palauzov@aegee.org
Subject: Re: Query planner skipping index depending on DISTINCT parameter order (2)
In-Reply-To: <eaee8428-8d38-9ee6-b129-a29eeb8a80c2@2ndquadrant.com>
References: <3c651d99-a943-4e21-4ec9-604b142c85e0@aegee.org> <57ccc03b-279a-63f7-19c6-6fe3b2d0e1be@aegee.org> <cd89d79f-96df-1a1e-5821-ef111950eccf@2ndquadrant.com> <a68737c6-601f-6846-2ba0-3795c942c81f@aegee.org> <271e4961-abfa-06ef-a502-cf00a31b236a@2ndquadrant.com> <12044.1505668534@sss.pgh.pa.us> <CAM-w4HPhUKkB6uA5vSOxZRUenACj-qAbSrcEBdmB1x1PyJ7hYA@mail.gmail.com> <eaee8428-8d38-9ee6-b129-a29eeb8a80c2@2ndquadrant.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox