Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rnsaW-00FjVO-Ch for pgsql-general@arkaria.postgresql.org; Sat, 23 Mar 2024 04:02:32 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1rnsaU-008i6V-W4 for pgsql-general@arkaria.postgresql.org; Sat, 23 Mar 2024 04:02:31 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rnsaU-008i6N-LR for pgsql-general@lists.postgresql.org; Sat, 23 Mar 2024 04:02:31 +0000 Received: from smtp75.iad3a.emailsrvr.com ([173.203.187.75]) by magus.postgresql.org with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rnsaO-00615I-4Q for pgsql-general@lists.postgresql.org; Sat, 23 Mar 2024 04:02:30 +0000 X-Auth-ID: xof@thebuild.com Received: by smtp18.relay.iad3a.emailsrvr.com (Authenticated sender: xof-AT-thebuild.com) with ESMTPSA id 1E11120CE1; Sat, 23 Mar 2024 00:02:21 -0400 (EDT) Content-Type: text/plain; charset=us-ascii Mime-Version: 1.0 (Mac OS X Mail 13.4 \(3608.120.23.2.7\)) Subject: Re: Seq scan vs index scan From: Christophe Pettus In-Reply-To: Date: Fri, 22 Mar 2024 21:02:18 -0700 Cc: pgsql-general@lists.postgresql.org Content-Transfer-Encoding: quoted-printable Message-Id: <5FE1E177-BFDB-4386-8DDC-02A652E71C86@thebuild.com> References: To: arun chirappurath X-Mailer: Apple Mail (2.3608.120.23.2.7) X-Classification-ID: 23e5c15a-5393-4a23-8f10-9957ade4ce0f-1-1 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk > On Mar 22, 2024, at 20:55, arun chirappurath = wrote: > I am trying to force query to use indexes using query hints. PostgreSQL does not have query hints. Enabling index scans using = parameters doesn't *disable* other types of query nodes. You can disable sequential scans using: SET enable_seqscan =3D off; ... but more importantly, why do you want to force an index scan? = Generally, PostgreSQL will pick a sequential scan over an index scan if = the table is small, or the number of rows that come back from the query = are a significant percentage of the rows of the table. If you would like a more detailed answer, it would be a good idea to = post an execution plan of the query with: EXPLAIN ANALYZE SELECT * FROM users WHERE username =3D = 'example_username';=