pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Rob Sargent <robjsargent@gmail.com>
To: pgsql-general@postgresql.org <pgsql-general@postgresql.org>
Subject: Surprised by index choice for count(*)
Date: Tue, 1 May 2018 09:46:51 -0600
Message-ID: <38fc1d14-1207-cbca-18e0-b2e6f269565b@gmail.com> (raw)

Should I be?  I would have thought the pk would have been chosen v. 
function index?

explain analyse select count(*) from bc.segment s;
QUERY PLAN
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------
  Finalize Aggregate  (cost=4428009.24..4428009.25 rows=1 width=8) 
(actual time=14786.395..14786.395 rows=1 loops=1)
    ->  Gather  (cost=4428009.03..4428009.24 rows=2 width=8) (actual 
time=14786.358..14786.386 rows=3 loops=1)
          Workers Planned: 2
          Workers Launched: 2
          ->  Partial Aggregate  (cost=4427009.03..4427009.04 rows=1 
width=8) (actual time=14782.167..14782.167 rows=1 loops=3)
                ->  Parallel Index Only Scan using fpv on segment s  
(cost=0.57..4210177.14 rows=86732753 width=0) (actual 
time=0.061..11352.855 rows=69386204 loops=3)
                      Heap Fetches: 1780
  Planning time: 0.221 ms
  Execution time: 14815.939 ms
(9 rows)

\d bc.segment
               Table "bc.segment"
      Column     |  Type   |     Modifiers
----------------+---------+--------------------
  id             | uuid    | not null
  chrom          | integer | not null
  markerset_id   | uuid    | not null
  probandset_id  | uuid    | not null
  startbase      | integer | not null
  endbase        | integer | not null
  firstmarker    | integer | not null
  lastmarker     | integer | not null
  events_less    | bigint  | not null default 0
  events_equal   | bigint  | not null default 0
  events_greater | bigint  | not null default 0
Indexes:
     "segment_pkey" PRIMARY KEY, btree (id)
     "useg" UNIQUE, btree (probandset_id, chrom, startbase, endbase)
     "fpv" btree (pv(events_less, events_equal, events_greater, 0))
     "segment_markerset_id_probandset_id_idx" btree (markerset_id, 
probandset_id)

create or replace function public.pv(l bigint, e bigint, g bigint, o int)
returns float
as
$$
select 1.0*(g+e+o)/(l+e+g+o)::float;
$$
language sql
;






view thread (4+ messages)  latest in thread

Message-ID: <38fc1d14-1207-cbca-18e0-b2e6f269565b@gmail.com>
Permalink:  ../38fc1d14-1207-cbca-18e0-b2e6f269565b@gmail.com/
Also on:    postgresql.org/message-id/38fc1d14-1207-cbca-18e0-b2e6f269565b@gmail.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-general@postgresql.org
  Cc: robjsargent@gmail.com
  Subject: Re: Surprised by index choice for count(*)
  In-Reply-To: <38fc1d14-1207-cbca-18e0-b2e6f269565b@gmail.com>
  References: <38fc1d14-1207-cbca-18e0-b2e6f269565b@gmail.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