From: Дилян Палаузов <dilyan.palauzov@aegee.org>
To: Greg Stark <stark@mit.edu>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: Tomas Vondra <tomas.vondra@2ndquadrant.com>
Cc: PostgreSQL Bugs <pgsql-bugs@postgresql.org>
Subject: Re: Query planner skipping index depending on DISTINCT parameter order (2)
Date: Mon, 25 Sep 2017 20:10:57 +0200
Message-ID: <6e8b3a9b-9b3d-e655-4456-f91a1ea3292b@aegee.org> (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>
Hello,
for the record, in this table
spamassassin=> \d bayes_token
Table "public.bayes_token"
Column Type Modifiers
────────── ─────── ────────────────────────────
id integer not null default 0
token bytea not null default '\x'::bytea
spam_count integer not null default 0
ham_count integer not null default 0
atime integer not null default 0
Indexes:
"bayes_token_pkey" PRIMARY KEY, btree (id, token)
"bayes_token_idx1" btree (token)
"SELECT id, token FROM bayes_token" and "SELECT id, token FROM bayes_token WHERE id > 0" do Seq Scan and need 35-50 Sec.
But "SELECT id, token FROM bayes_token WHERE id > 1" uses Index Only Scan and 0.04 seconds on pg 9.6.5 .
Greetings
Dilian
On 09/25/17 12:43, 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"? I
> would have expected the two equivalent SQL statements to use exactly
> the same infrastructure and thought it was only a matter of historical
> legacy that they didn't.
>
--
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: dilyan.palauzov@aegee.org, stark@mit.edu, tgl@sss.pgh.pa.us, tomas.vondra@2ndquadrant.com
Subject: Re: Query planner skipping index depending on DISTINCT parameter order (2)
In-Reply-To: <6e8b3a9b-9b3d-e655-4456-f91a1ea3292b@aegee.org>
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> <6e8b3a9b-9b3d-e655-4456-f91a1ea3292b@aegee.org>
* 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