pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Peter J. Holzer <hjp-pgsql@hjp.at>
To: pgsql-general@lists.postgresql.org
Subject: Re: Questions about btree_gin vs btree_gist for low cardinality columns
Date: Sun, 2 Jun 2019 09:37:32 +0200
Message-ID: <20190602073732.kvan34sfotdlyc7s@hjp.at> (raw)
In-Reply-To: <CAKqncch73a0rff1sUb17eFCivLMV+sWhzxc2Bx2o_q1p3H4jGA@mail.gmail.com>
References: <CAMa1XUiRZsg7Y5OBvau=orfVv=w=Rq19RDHQRySnF6RS=-+y2g@mail.gmail.com>
	<CAKqnccjrdoNne5D48-REhgNgRghc_2o453x1SWEoa8EYh792EQ@mail.gmail.com>
	<CAKqncciUyxY04GagOWYALE7+zOeF9a+AD=gYWV8PvJROw_YN7Q@mail.gmail.com>
	<20190601135313.z4pnwxcmbpeuzrq2@hjp.at>
	<CAKqncch73a0rff1sUb17eFCivLMV+sWhzxc2Bx2o_q1p3H4jGA@mail.gmail.com>

On 2019-06-02 09:10:25 +1000, Morris de Oryx wrote:
> Peter, thanks a lot for picking up on what I started, improving it, and
> reporting back. I thought I was providing timing estimates from the EXPLAIN
> cost dumps. Seems not. Well, there's another thing that I've learned.

The cost is how long the optimizer thinks it will take (in arbitrary
units). But it's just an estimate, and estimates can be off - sometimes
quite dramatically.

To get the real timings with explain, use explain (analyze). I often
combine this with buffers to get I/O stats as well:

wdsah=> explain (analyze, buffers) select min(date) from facttable_stat_fta4 where partnerregion = 'USA' and sitcr4 = '7522'; 
╔══════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════╗
║                                                                                  QUERY PLAN                                                                                  ║
╟──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╢
║ Aggregate  (cost=694.23..694.24 rows=1 width=4) (actual time=7.568..7.568 rows=1 loops=1)                                                                                    ║
║   Buffers: shared hit=3 read=148 dirtied=114                                                                                                                                 ║
║   ->  Index Scan using facttable_stat_fta4_sitcr4_partnerregion_idx on facttable_stat_fta4  (cost=0.57..693.09 rows=455 width=4) (actual time=0.515..7.493 rows=624 loops=1) ║
║         Index Cond: (((sitcr4)::text = '7522'::text) AND ((partnerregion)::text = 'USA'::text))                                                                              ║
║         Buffers: shared hit=3 read=148 dirtied=114                                                                                                                           ║
║ Planning time: 0.744 ms                                                                                                                                                      ║
║ Execution time: 7.613 ms                                                                                                                                                     ║
╚══════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════╝
(7 rows)

And when you don't need the costs, you can turn them off:

wdsah=> explain (analyze, buffers, costs off) select min(date) from facttable_stat_fta4 where partnerregion = 'USA' and sitcr4 = '7522'; 
╔════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════╗
║                                                               QUERY PLAN                                                               ║
╟────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╢
║ Aggregate (actual time=0.598..0.598 rows=1 loops=1)                                                                                    ║
║   Buffers: shared hit=140                                                                                                              ║
║   ->  Index Scan using facttable_stat_fta4_sitcr4_partnerregion_idx on facttable_stat_fta4 (actual time=0.054..0.444 rows=624 loops=1) ║
║         Index Cond: (((sitcr4)::text = '7522'::text) AND ((partnerregion)::text = 'USA'::text))                                        ║
║         Buffers: shared hit=140                                                                                                        ║
║ Planning time: 0.749 ms                                                                                                                ║
║ Execution time: 0.647 ms                                                                                                               ║
╚════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════╝
(7 rows)

See https://www.postgresql.org/docs/current/sql-explain.html for details.

> Can you tell me how you get timing results into state_test_times?

In this case I just entered them manually (cut and paste from psql
\timing output). If I wanted to repeat that test on another database, I
would write a Python script (I'm sure you can do that in pgsql, too, but
I feel more comfortable in Python). I don't think there is a way to get
time timings in plain SQL.

        hp

-- 
   _  | Peter J. Holzer    | we build much bigger, better disasters now
|_|_) |                    | because we have much more sophisticated
| |   | hjp@hjp.at         | management tools.
__/   | http://www.hjp.at/ | -- Ross Anderson <https://www.edge.org/;

Attachments:

  signature.asc (application/pgp-signature, 832B) download

view thread (24+ messages)  latest in thread

Message-ID: <20190602073732.kvan34sfotdlyc7s@hjp.at>
Permalink:  ../20190602073732.kvan34sfotdlyc7s@hjp.at/
Also on:    postgresql.org/message-id/20190602073732.kvan34sfotdlyc7s@hjp.at

 · 

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: hjp-pgsql@hjp.at
  Subject: Re: Questions about btree_gin vs btree_gist for low cardinality columns
  In-Reply-To: <20190602073732.kvan34sfotdlyc7s@hjp.at>
  References: <CAMa1XUiRZsg7Y5OBvau=orfVv=w=Rq19RDHQRySnF6RS=-+y2g@mail.gmail.com> <CAKqnccjrdoNne5D48-REhgNgRghc_2o453x1SWEoa8EYh792EQ@mail.gmail.com> <CAKqncciUyxY04GagOWYALE7+zOeF9a+AD=gYWV8PvJROw_YN7Q@mail.gmail.com> <20190601135313.z4pnwxcmbpeuzrq2@hjp.at> <CAKqncch73a0rff1sUb17eFCivLMV+sWhzxc2Bx2o_q1p3H4jGA@mail.gmail.com> <20190602073732.kvan34sfotdlyc7s@hjp.at>

* 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