pg.ddx.io pgsql-general@postgresql.org mailing list archivehelp / color / mirror / Atom feed
Primary Key index with Include 2+ messages / 2 participants [nested] [flat]
* Primary Key index with Include @ 2018-11-28 19:55 PegoraroF10 <marcos@f10.com.br> 2018-11-28 20:34 ` Re: Primary Key index with Include Adrian Klaver <adrian.klaver@aklaver.com> 0 siblings, 1 reply; 2+ messages in thread From: PegoraroF10 @ 2018-11-28 19:55 UTC (permalink / raw) To: pgsql-general 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 ? 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 ^ permalink raw reply [nested|flat] 2+ messages in thread
* Re: Primary Key index with Include 2018-11-28 19:55 Primary Key index with Include PegoraroF10 <marcos@f10.com.br> @ 2018-11-28 20:34 ` Adrian Klaver <adrian.klaver@aklaver.com> 0 siblings, 0 replies; 2+ messages in thread From: Adrian Klaver @ 2018-11-28 20:34 UTC (permalink / raw) To: PegoraroF10 <marcos@f10.com.br>; pgsql-general 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 ^ permalink raw reply [nested|flat] 2+ messages in thread
end of thread, other threads:[~2018-11-28 20:34 UTC | newest] Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed) -- links below jump to the message on this page -- 2018-11-28 19:55 Primary Key index with Include PegoraroF10 <marcos@f10.com.br> 2018-11-28 20:34 ` Adrian Klaver <adrian.klaver@aklaver.com>
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