pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Adrian Klaver <adrian.klaver@aklaver.com>
To: PegoraroF10 <marcos@f10.com.br>
To: pgsql-general@postgresql.org
Subject: Re: Primary Key index with Include
Date: Wed, 28 Nov 2018 12:34:52 -0800
Message-ID: <ce74af6f-6b6d-d4e7-7b5c-82c19c7911e6@aklaver.com> (raw)
In-Reply-To: <1543434917462-0.post@n3.nabble.com>
References: <1543434917462-0.post@n3.nabble.com>

On 11/28/18 11:55 AM, PegoraroF10 wrote:
> As you know version 11 gives us the possibility to include aditional columns
> to an index.
> So, if I recreate all my primary key indexes to contain a description
> column, like ...
> 
> CREATE UNIQUE INDEX CONCURRENTLY Products_pk ON Products(Product_ID)
> INCLUDE(Name);
> ALTER TABLE Products ADD CONSTRAINT Products_pk PRIMARY KEY(Product_ID)
> USING INDEX Products_pk
> 
> Then, when I do
> select Item_ID, Product_ID, Name from Items inner join Products
> using(Product_ID)
> 
> I thought It would do a index scan only for Products table, but it does not,
> why ?

Because an index is overhead and depending on the situation the planner 
may determine it is better not to use it.

Post the results of:

EXPLAIN ANALYZE select Item_ID, Product_ID, Name from Items inner join 
Products using(Product_ID);

That will help understand what the planner is doing.


> What do I need do to use index scan only when searching Product_ID and Name
> on table Products ?
> 
> 
> 
> --
> Sent from: http://www.postgresql-archive.org/PostgreSQL-general-f1843780.html
> 
> 


-- 
Adrian Klaver
adrian.klaver@aklaver.com




view thread (2+ messages)

Message-ID: <ce74af6f-6b6d-d4e7-7b5c-82c19c7911e6@aklaver.com>
Permalink:  ../ce74af6f-6b6d-d4e7-7b5c-82c19c7911e6@aklaver.com/
Also on:    postgresql.org/message-id/ce74af6f-6b6d-d4e7-7b5c-82c19c7911e6@aklaver.com

 · 

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: adrian.klaver@aklaver.com, marcos@f10.com.br
  Subject: Re: Primary Key index with Include
  In-Reply-To: <ce74af6f-6b6d-d4e7-7b5c-82c19c7911e6@aklaver.com>
  References: <1543434917462-0.post@n3.nabble.com> <ce74af6f-6b6d-d4e7-7b5c-82c19c7911e6@aklaver.com>

* 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