pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Laurenz Albe <laurenz.albe@cybertec.at>
To: Arup Rakshit <ar@zeit.io>
To: Tomas Vondra <tomas.vondra@2ndquadrant.com>
Cc: pgsql-general@lists.postgresql.org
Subject: Re: Help to understand Actual Rows vs Plan Rows from the query planner output
Date: Tue, 25 Sep 2018 08:15:35 +0200
Message-ID: <b18107da93f420aca066c60a1512d15d49643e4b.camel@cybertec.at> (raw)
In-Reply-To: <6B4B7F74-8148-43CC-9AA0-6C0F4B769216@zeit.io>
References: <C2837E8C-4392-4D7B-BFF8-CEF557776910@zeit.io>
	<409f074d-56f5-3dbb-b4e1-6c0b69f27952@2ndquadrant.com>
	<6B4B7F74-8148-43CC-9AA0-6C0F4B769216@zeit.io>

Arup Rakshit wrote:
> Thanks for the link. I read the documentation you linked, and part of it
> I understood and rest went above my head. Probably I need to read it multiple
> times to understand what is going on. I am learning how indexing works in DBMS.
> Mostly I understood Btree so far. I am an application developer.
> Being an application developer I think I need to know which column should be
> indexed and what kind of index to apply in which case.

That is true; a truth that many developers unfortunately ignore.

> Most of the time, when
> I see slow query, I saw people ask to run the explain to see the plan.
> And explain statement shows lot of data about the query. So my questions is that:
> Which part I should read from the plan output to figure out reason of slowness
> or what need to be used to improve it. What are basic things I should know about it.
> I think, I don’t need to internal math for this, am I right? The query in
> this post is not a slow query, it is something I ran to see how index merge happens.
> I am asking generally. Can you give me some directions on this, so that I can
> build up some bases on this subject.

This is a broad topic, and I can only give you some hints.
In order to understand EXPLAIN output and to improve your query, you need
to know some of how the database is implemented.

You have to understand index scans, index only scans and bitmap index scans.
You have to understand nested loop, hash and merge joins.
You have to understand table statistics, dead tuples and table bloat.

The first things to look for in EXPLAIN (ANALYZE, BUFFERS) output is in which
nodes the time is spent, and where the estimated number of rows diverges
significantly from the actual number of rows.
The former are the spots where there is room for improvement, and the latter
is often the root cause of a bad plan choice.
Also, watch out for the nodes that touch a lot of blocks.
They can cause intermittent slow-down if the blocks are not in cache.

> Also what are the best resources to learn GIST, GIN indexes — something which
> teaches it from the ground up? 

The documentation, and for what goes beyond that, the source.

Yours,
Laurenz Albe
-- 
Cybertec | https://www.cybertec-postgresql.com





view thread (5+ messages)  latest in thread

Message-ID: <b18107da93f420aca066c60a1512d15d49643e4b.camel@cybertec.at>
Permalink:  ../b18107da93f420aca066c60a1512d15d49643e4b.camel@cybertec.at/
Also on:    postgresql.org/message-id/b18107da93f420aca066c60a1512d15d49643e4b.camel@cybertec.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: laurenz.albe@cybertec.at, ar@zeit.io, tomas.vondra@2ndquadrant.com
  Subject: Re: Help to understand Actual Rows vs Plan Rows from the query planner output
  In-Reply-To: <b18107da93f420aca066c60a1512d15d49643e4b.camel@cybertec.at>
  References: <C2837E8C-4392-4D7B-BFF8-CEF557776910@zeit.io> <409f074d-56f5-3dbb-b4e1-6c0b69f27952@2ndquadrant.com> <6B4B7F74-8148-43CC-9AA0-6C0F4B769216@zeit.io> <b18107da93f420aca066c60a1512d15d49643e4b.camel@cybertec.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