Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mPjKP-0004i5-Qs for pgsql-bugs@arkaria.postgresql.org; Mon, 13 Sep 2021 10:36:46 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1mPjKN-00075A-EH for pgsql-bugs@arkaria.postgresql.org; Mon, 13 Sep 2021 10:36:43 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mPjKN-000752-6d for pgsql-bugs@lists.postgresql.org; Mon, 13 Sep 2021 10:36:43 +0000 Received: from lana.depesz.com ([88.198.49.178] helo=depesz.com) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mPjKF-00025t-TD for pgsql-bugs@lists.postgresql.org; Mon, 13 Sep 2021 10:36:42 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=depesz.com; s=20170201; h=In-Reply-To:Content-Type:MIME-Version:References:Reply-To: Message-ID:Subject:To:Sender:From:Date:Cc:Content-Transfer-Encoding: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=uxww+iyF/XWPvEHrprCVVCSWC6EtqJyEmKBPRknyIFM=; b=VcicPOtZ5xVSD/wGDRPkaeh6uQ ZyQOcukRLMxoKwR4e3BXYkas+A2Tfw2kjMoilkCicrSQId5xAxZH/2ADHkfvrZlDkF+gpASwlAcO8 h0X7LRTemRlc2B7T3NYqsTiKVu20F+Z9yFBPj3o7ujniE2m7fxVJS1y6Ih/yZ6zSSYNw=; Received: from lana.depesz.com ([88.198.49.178] helo=depesz.com) by depesz.com with esmtpa (Exim 4.92) (envelope-from ) id 1mPjKC-0004Gd-3S; Mon, 13 Sep 2021 12:36:32 +0200 Date: Mon, 13 Sep 2021 12:36:31 +0200 From: hubert depesz lubaczewski Sender: depesz@depesz.com To: puneet.orcl@gmail.com, pgsql-bugs@lists.postgresql.org Subject: Re: BUG #17189: Index not created when primary key created Message-ID: <20210913103631.GB23362@depesz.com> Reply-To: depesz@depesz.com References: <17189-521a1b29d9727929@postgresql.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <17189-521a1b29d9727929@postgresql.org> User-Agent: Mutt/1.10.1 (2018-07-13) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Mon, Sep 13, 2021 at 05:27:00AM +0000, PG Bug reporting form wrote: > I have created the composite primary key which is created successfully but i > am not getting the index against the primary key. That's rather impossible. Please show create table statement, and output of `\d table_name` after creation. > When i created a select query and includes the primary key column it is > going with full table scan. Even i am creating an index on the columns it is > also going with full table scan. Index will be used only when it makes sense. If you'd do: select * from table; - that is select all rows - there is no point in using index, as it will be slower than getting seq scan. Plus - your table can be too small to effectively use index. Consider reading: https://www.depesz.com/2010/09/09/why-is-my-index-not-being-used/ Best regards, depesz