From: Laurenz Albe <laurenz.albe@cybertec.at>
To: Arup Rakshit <ar@zeit.io>
To: pgsql-general@postgresql.org
Subject: Re: Why my query not doing index only scan
Date: Mon, 10 Sep 2018 15:12:10 +0200
Message-ID: <e498902f3df994d43055baa489ebad291b591172.camel@cybertec.at> (raw)
In-Reply-To: <C7195132-E8C4-4914-B96D-F9A2F166C18A@zeit.io>
References: <C7195132-E8C4-4914-B96D-F9A2F166C18A@zeit.io>
Arup Rakshit wrote:
> I am learning at this point how index works in DBMS. So I am looking for a very broad explanation to clear my basics.
>
> I have an index defined "inspector_tool_idx4_1" UNIQUE, btree (company_id, item_code, deleted_at).
> Now I am using the *company_id* column in the where clause, and the selecting just the *item_code* field for all matching rows.
> I expected here the planner will do a index only scans. But it is doing bitmap index scan. Any idea what it is not doing what I expected it to do.
>
>
> inspection_development=# explain analyze select item_code from inspector_tool_components where company_id = '7881ff2e-0557-4734-9da8-2d33072ff1ef';
> QUERY PLAN
> -------------------------------------------------------------------------------------------------------------------------------------
> Bitmap Heap Scan on inspector_tool_components (cost=45.92..1360.48 rows=1226 width=8) (actual time=0.382..1.202 rows=1232 loops=1)
> Recheck Cond: (company_id = '7881ff2e-0557-4734-9da8-2d33072ff1ef'::uuid)
> Heap Blocks: exact=81
> -> Bitmap Index Scan on inspector_tool_idx4_1 (cost=0.00..45.61 rows=1226 width=0) (actual time=0.347..0.347 rows=1232 loops=1)
> Index Cond: (company_id = '7881ff2e-0557-4734-9da8-2d33072ff1ef'::uuid)
> Planning time: 0.207 ms
> Execution time: 1.358 ms
> (7 rows)
Try to "VACUUM (ANALYZE) inspector_tool_components", that will set the
visibility mape and get the statistics right, maybe than you get an
index only scan.
How many rows does the table contain?
Yours,
Laurenz Albe
--
Cybertec | https://www.cybertec-postgresql.com
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
Subject: Re: Why my query not doing index only scan
In-Reply-To: <e498902f3df994d43055baa489ebad291b591172.camel@cybertec.at>
References: <C7195132-E8C4-4914-B96D-F9A2F166C18A@zeit.io> <e498902f3df994d43055baa489ebad291b591172.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