Re: Index Skip Scan

From: Alexander Kuzmenkov <a(dot)kuzmenkov(at)postgrespro(dot)ru>
To: Dmitry Dolgov <9erthalion6(at)gmail(dot)com>, Jesper Pedersen <jesper(dot)pedersen(at)redhat(dot)com>
Cc: pg(at)bowt(dot)ie, Thomas Munro <thomas(dot)munro(at)enterprisedb(dot)com>, Bhushan Uparkar <bhushan(dot)uparkar(at)gmail(dot)com>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>, Alexander Korotkov <a(dot)korotkov(at)postgrespro(dot)ru>, jtc331(at)gmail(dot)com
Subject: Re: Index Skip Scan
Date: 2018-11-21 15:38:55
Message-ID: b360894b-b436-b3aa-e839-97f1c0413713@postgrespro.ru
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On 11/18/18 02:27, Dmitry Dolgov wrote:
>
> [0001-Index-skip-scan-v4.patch]

I ran a couple of tests on this, please see the cases below. As before,
I'm setting total_cost = 1 for index skip scan so that it is chosen.
Case 1 breaks because we determine the high key incorrectly, it is the
second tuple on page or something like that, not the last tuple. Case 2
is backwards scan, I don't understand how it is supposed to work. We
call _bt_search(nextKey = ScanDirectionIsForward), so it seems that it
just fetches the previous tuple like the regular scan does.

case 1:
# create table t as select generate_series(1, 1000000) a;
# create index ta on t(a);
# explain select count(*) from (select distinct a from t) d;
                               QUERY PLAN
-------------------------------------------------------------------------
 Aggregate  (cost=3.50..3.51 rows=1 width=8)
   ->  Index Only Scan using ta on t  (cost=0.42..1.00 rows=200 width=4)
         Scan mode: Skip scan
(3 rows)

postgres=# select count(*) from (select distinct a from t) d;
 count
--------
 500000 -- should be 1kk
(1 row)

case 2:
# create table t as select generate_series(1, 1000000) / 2 a;
# create index ta on t(a);
# explain select count(*) from (select distinct a from t order by a desc) d;
                                     QUERY PLAN
-------------------------------------------------------------------------------------
 Aggregate  (cost=5980.81..5980.82 rows=1 width=8)
   ->  Index Only Scan Backward using ta on t  (cost=0.42..1.00
rows=478385 width=4)
         Scan mode: Skip scan
(3 rows)

# select count(*) from (select distinct a from t order by a desc) d;
 count
--------
 502733 -- should be 500k

(1 row)

--

Alexander Kuzmenkov
Postgres Professional: http://www.postgrespro.com
The Russian Postgres Company

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Andreas Karlsson 2018-11-21 15:40:27 Re: Need of maintaining unsupported release notes in HEAD?
Previous Message Pavel Stehule 2018-11-21 15:36:05 Re: ToDo: show size of partitioned table