Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gS6Y0-0006Pj-GV for pgsql-general@arkaria.postgresql.org; Wed, 28 Nov 2018 20:35:00 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1gS6Xz-0002jm-0b for pgsql-general@arkaria.postgresql.org; Wed, 28 Nov 2018 20:34:59 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gS6Xx-0002jY-Tt for pgsql-general@lists.postgresql.org; Wed, 28 Nov 2018 20:34:58 +0000 Received: from out4-smtp.messagingengine.com ([66.111.4.28]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gS6Xu-0002Xz-Or for pgsql-general@postgresql.org; Wed, 28 Nov 2018 20:34:56 +0000 Received: from compute6.internal (compute6.nyi.internal [10.202.2.46]) by mailout.nyi.internal (Postfix) with ESMTP id 1BD2722276; Wed, 28 Nov 2018 15:34:54 -0500 (EST) Received: from mailfrontend1 ([10.202.2.162]) by compute6.internal (MEProxy); Wed, 28 Nov 2018 15:34:54 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aklaver.com; h= subject:to:references:from:message-id:date:mime-version :in-reply-to:content-type:content-transfer-encoding; s=fm1; bh=C UI9Zy5RpTcHu1ZPlJ4z3SS2s0eL4wV2FQ6Yv3/tdAA=; b=T8po6V7pAg/zyIRw3 EK77Ab3pswxMOL6fo3/QHGNUJT2yj0zEZyVeMVk1Yyf1CQ4JHbVOedqoCpjqXVqp I4tzjc6rRvTWpjQXeTIGvA8kb0IOE+9sncXcrdiF6TgW8XwMJ2uNAVVLpxLacsKG UFYqjz+PpmtSLZE/lq9n3OSejScSthK66tk6jTt7fNPo4OCQOYjIWYLTRUa8lc0H lc6t6XzTaPoxlgY5bozBwbFGhu5plh16YAVyJe+OR+GsivGD4lpQC9FpGbOrtYW7 kMBRB4u7/yenJipXdmL5h/gMeSWa4NQTBGQSGD3ALviJalQnW4P7AW1j5lPHMAgf KNWVw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm1; bh=CUI9Zy5RpTcHu1ZPlJ4z3SS2s0eL4wV2FQ6Yv3/td AA=; b=juEo4NA8xUAgfMd5f6ycxp2K/MUUtzYaGDIYl8mWf8UnMIx+Onw6lOYz2 polRugUvR7GPx9l/rOlRPzzuWpZ8L3qLALE4gxQNnbXx3+tSpjZbQsGDkOdcYfak ohSx4e1ZaYH4uyGUaqlHZ/Mo6x7m13SL/UQcAqnKF4Sl+yo33G5Oa4kKjet7goc3 61AozyhcZu6EZ6S+KzamVod6/cwMQvegpKs0mXiyIBNeA7d2jkH8ffTvocFNN8Cv IUp71MMttAwyUaHcu1s+4ApuQuCIw2tLgBIeZwiLw3lhbo1TVD5mAkE/ir4bUVn4 nevZqPB3iXtMhXzHrzZZOjbsWff2Q== X-ME-Sender: X-ME-Proxy: Received: from [192.168.1.3] (unknown [71.212.134.3]) by mail.messagingengine.com (Postfix) with ESMTPA id E1B94E4125; Wed, 28 Nov 2018 15:34:52 -0500 (EST) Subject: Re: Primary Key index with Include To: PegoraroF10 , pgsql-general@postgresql.org References: <1543434917462-0.post@n3.nabble.com> From: Adrian Klaver Message-ID: Date: Wed, 28 Nov 2018 12:34:52 -0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.3.0 MIME-Version: 1.0 In-Reply-To: <1543434917462-0.post@n3.nabble.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk 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