Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fDXUc-0004rC-Tk for pgsql-general@arkaria.postgresql.org; Tue, 01 May 2018 15:47:03 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1fDXUb-0006qL-Tj for pgsql-general@arkaria.postgresql.org; Tue, 01 May 2018 15:47:01 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fDXUb-0006qA-Fw for pgsql-general@lists.postgresql.org; Tue, 01 May 2018 15:47:01 +0000 Received: from mail-pf0-x244.google.com ([2607:f8b0:400e:c00::244]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1fDXUU-00005u-U3 for pgsql-general@postgresql.org; Tue, 01 May 2018 15:47:00 +0000 Received: by mail-pf0-x244.google.com with SMTP id a14so9380900pfi.1 for ; Tue, 01 May 2018 08:46:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=to:from:subject:message-id:date:user-agent:mime-version :content-transfer-encoding:content-language; bh=Um/F42mY3ehvjGdeiakGU+z52LTVy1GUQpUubw4C3d8=; b=LcRnpLuG+XE0LZfEz5bOoei+faulh5v5QJZxtaNqYlCh4xJZGsVhvLG3EcJQ1ZFIap eBL3wadVtWx1/TIfvymKnoiESO9fZy58oXu8de06sVfV+03OwGtPjw++qnHVP+hbBOs9 NfiWLPGGnOKXbKqEqshhHcKUehrudSksyW94CBmaTufxsJba0Ynehr9wRta96zZDnp5R Nlf2/vYkswDu4LkSPVLQ+5FpauFKY2QO3LCS8VXYvjZR9BiKzhgGIR1aqnO+NaVfYiJ7 F7Cj+9aHjsjfXQj2QKMoe9EDYua2Ceu7syj3tNnFkQMadojS6eUilLEY2QhGq1Aff7lv 5lzw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:to:from:subject:message-id:date:user-agent :mime-version:content-transfer-encoding:content-language; bh=Um/F42mY3ehvjGdeiakGU+z52LTVy1GUQpUubw4C3d8=; b=PXmZEUiRqpVK9J1mSdvtR8kZgpHk3NO2UIW1cOdIybTWMCKedlXLHY7MDpFiMwaVaP Jq0r3pAsrwM9u5T7gi/GkeGTM/VubaRvXSJ/VpuWM4NLhTZYhVs9uLHM/tOI3VCoVHRS pqlqzeZnaTGPpcQefY/gMaRLX+K1WNVn4SHLnrE3c/3AqDnOzMIY38728x+U3Tzw59bf qljicCm8z1BDwMBeZtFSF9oYCyRUScfWlNZXgMY4DTknbpgOHkxvoYeb7jAhwcbUnoqN eh6GRouMGfeGOIxMg/TZDmLlkRxFGGo0OHroP837dE3rnqHqI7QrbjGMJCPKXjwpvHdN p4aA== X-Gm-Message-State: ALQs6tBsI19wMN/IR5uW8JxluULjEF3/NDzp4rWzKipleCotPl7OszmN X5I1X8Czuj2BCCbvD2rwUB2d8HmZ X-Google-Smtp-Source: AB8JxZofFe1trkFLedvdu/vb3zun7bLL0lBesP+8FSth0BMYnzCp2ZCykeAeZF27e3ky2k9EaZxBBw== X-Received: by 10.98.194.199 with SMTP id w68mr15989005pfk.174.1525189613227; Tue, 01 May 2018 08:46:53 -0700 (PDT) Received: from [10.104.134.14] ([155.100.47.6]) by smtp.gmail.com with ESMTPSA id v187sm20049420pfv.21.2018.05.01.08.46.52 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 01 May 2018 08:46:52 -0700 (PDT) To: "pgsql-general@postgresql.org" From: Rob Sargent Subject: Surprised by index choice for count(*) Message-ID: <38fc1d14-1207-cbca-18e0-b2e6f269565b@gmail.com> Date: Tue, 1 May 2018 09:46:51 -0600 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.7.0 MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-US List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk 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 ;