Received: from malur.postgresql.org ([2a02:16a8:dc51::56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1g5nWW-0007Tj-Bw for pgsql-general@arkaria.postgresql.org; Fri, 28 Sep 2018 07:49:16 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1g5nWU-0004Tn-Bm for pgsql-general@arkaria.postgresql.org; Fri, 28 Sep 2018 07:49:14 +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 1g5nWT-0004Tg-NZ for pgsql-general@lists.postgresql.org; Fri, 28 Sep 2018 07:49:14 +0000 Received: from mail-pg1-x541.google.com ([2607:f8b0:4864:20::541]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1g5nWL-0007ZY-FA for pgsql-general@lists.postgresql.org; Fri, 28 Sep 2018 07:49:12 +0000 Received: by mail-pg1-x541.google.com with SMTP id d19-v6so3869198pgv.1 for ; Fri, 28 Sep 2018 00:49:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=zeit-io.20150623.gappssmtp.com; s=20150623; h=from:mime-version:subject:date:references:to:in-reply-to:message-id; bh=byKyCplUD3jcrTR4KfsRf2/4MrHcC4d5yf8MzbtJjfs=; b=JEnnFbiUdv3m0zHxiajXlcvXFCcwTLNt1nXyg1Gfi/jXHwnROekwIZAcoOru4sd18X Q4kiOC25LXoAIxR8HcRSUsGslKCPLhco4X/o4AWuEbSmpsS4obOmv5G4yjR4F+9cFnXH OyvKWlNxmDC7KQFdKfzdxTNfZt/6KCjsI5pLyW/T0Gz/Dh815jueSzfdJzs/mGnevlAK gFrpFXM0yLfamHffISoHcyXqkbGzxJ3HLa1MBaNUl6B/Ih+RyFbYa90YouASRcwsxWfR e8EifI9+V/hqV85fI9FE20w3tM6nN+78H7bBneBWnxo0mQlWbXAEzTtbrqXK+MvKWQ6G 3gyg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:mime-version:subject:date:references:to :in-reply-to:message-id; bh=byKyCplUD3jcrTR4KfsRf2/4MrHcC4d5yf8MzbtJjfs=; b=TYqCJAx7FAu2dCckASolJjOStt0k2iAhKWBpKaBKSc6JUWJ6J2baNqNB1Q236wbEFz PCJLogNCLF08woxML+J/9uaf1Fkem28h0qCNbtSZswsO9ab6LRInHWXfEOMHIw0590Zh g1pdX99XrUyy6xU4NuEWpKZG264Y3fI2WaprsABeM+/9qzJSTWMhNW6HaugNopPqme8f m4W8D0fTNOxCIMBcWUDPOTe5JMEkwa2rVNtBNzInTZZrRBNwGPhUvxr0veg5WbQSVCO7 0u4cI8qH8U0Y/CdGYFrtBimrljhneuE279AsTUooxV53LyAsOwR5lMNbwxbUG0V4jiY8 33hw== X-Gm-Message-State: ABuFfojo/igQNyduq3UJN7IPfUZ4P+DdjBmAlyaFllzeGk+yEcqXS6PE xZTWyK9jDFdgWYvV9gvHnvJ53Pr4Euo= X-Google-Smtp-Source: ACcGV61izF+I9f95ibRYfIB/iVH0PG29bHOLKN4paFeuqcl2++xQqnUSVkfQTuQHDneiux33duo1BA== X-Received: by 2002:a63:ac11:: with SMTP id v17-v6mr13832288pge.196.1538120943763; Fri, 28 Sep 2018 00:49:03 -0700 (PDT) Received: from [192.168.0.100] ([45.123.160.163]) by smtp.gmail.com with ESMTPSA id v83-v6sm9755987pfa.103.2018.09.28.00.49.02 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 28 Sep 2018 00:49:03 -0700 (PDT) From: Arup Rakshit Content-Type: multipart/alternative; boundary="Apple-Mail=_80B5E259-A5E9-49CB-B6CD-74FE9D293FE9" Mime-Version: 1.0 (Mac OS X Mail 11.5 \(3445.9.1\)) Subject: Re: Help to understand Actual Rows vs Plan Rows from the query planner output Date: Fri, 28 Sep 2018 13:18:59 +0530 References: <409f074d-56f5-3dbb-b4e1-6c0b69f27952@2ndquadrant.com> <6B4B7F74-8148-43CC-9AA0-6C0F4B769216@zeit.io> To: pgsql-general@lists.postgresql.org In-Reply-To: Message-Id: <41F082EC-2F24-4607-B6F2-5A5E7AD3FCF9@zeit.io> X-Mailer: Apple Mail (2.3445.9.1) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk --Apple-Mail=_80B5E259-A5E9-49CB-B6CD-74FE9D293FE9 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 Hi, > This is a broad topic, and I can only give you some hints. Yes when I am reading this = https://www.postgresql.org/docs/10/static/using-explain.html = I found = the doc said like =E2=80=9C...Plan-reading is an art that requires some = experience to master, but this section attempts to cover the basics..=E2=80= =9D Lets see how can I get there. :) I probably need to ask a lot of = questions. Thanks for sharing those points. I made a note about them. Thanks, Arup Rakshit ar@zeit.io > On 25-Sep-2018, at 11:45 AM, Laurenz Albe = wrote: >=20 > 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. >=20 > That is true; a truth that many developers unfortunately ignore. >=20 >> 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=E2=80=99t 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. >=20 > 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. >=20 > 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. >=20 > 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. >=20 >> Also what are the best resources to learn GIST, GIN indexes =E2=80=94 = something which >> teaches it from the ground up?=20 >=20 > The documentation, and for what goes beyond that, the source. >=20 > Yours, > Laurenz Albe > --=20 > Cybertec | https://www.cybertec-postgresql.com >=20 --Apple-Mail=_80B5E259-A5E9-49CB-B6CD-74FE9D293FE9 Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=utf-8
Hi,

> This is a broad topic, and I can only give you some = hints.







On 25-Sep-2018, at 11:45 AM, Laurenz Albe <laurenz.albe@cybertec.at> wrote:

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=E2=80=99t 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 =E2=80=94 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


= --Apple-Mail=_80B5E259-A5E9-49CB-B6CD-74FE9D293FE9--