pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tomas Vondra <tomas.vondra@2ndquadrant.com>
To: Дилян Палаузов <dilyan.palauzov@aegee.org>
To: Greg Stark <stark@mit.edu>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: PostgreSQL Bugs <pgsql-bugs@postgresql.org>
Subject: Re: Query planner skipping index depending on DISTINCT parameter order (2)
Date: Mon, 25 Sep 2017 21:26:51 +0200
Message-ID: <200285f5-801c-a53d-3a7d-9828d06947f0@2ndquadrant.com> (raw)
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>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-bugs>



On 09/25/2017 08:10 PM, Дилян Палаузов wrote:
> 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 .
> 

I don't quite see how this is related to the original topic in this
thread, which was discussing DISTINCT ON vs. indexes.

But more importantly, it's really difficult to give you answers without
you showing us EXPLAIN (and ideally EXPLAIN ANALYZE) for the queries.

FWIW, my guess is that there are many rows with (id > 0), and scanning
them using index only scan would be expensive. While there are only very
few rows with (id > 1), so the database uses IOS.

You can try pushing the database towards IOS by disabling sequential and
bitmap scans.

 set enable_seqscan = off;
 set enable_bitmapscan = off;


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



view thread (13+ messages)  latest in thread

Message-ID: <200285f5-801c-a53d-3a7d-9828d06947f0@2ndquadrant.com>
Permalink:  ../200285f5-801c-a53d-3a7d-9828d06947f0@2ndquadrant.com/
Also on:    postgresql.org/message-id/200285f5-801c-a53d-3a7d-9828d06947f0@2ndquadrant.com

 · 

reply

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, dilyan.palauzov@aegee.org, stark@mit.edu, tgl@sss.pgh.pa.us
  Subject: Re: Query planner skipping index depending on DISTINCT parameter order (2)
  In-Reply-To: <200285f5-801c-a53d-3a7d-9828d06947f0@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> <6e8b3a9b-9b3d-e655-4456-f91a1ea3292b@aegee.org> <200285f5-801c-a53d-3a7d-9828d06947f0@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