From: Christophe Pettus <xof@thebuild.com>
To: arun chirappurath <arunsnmimt@gmail.com>
Cc: pgsql-general@lists.postgresql.org
Subject: Re: Seq scan vs index scan
Date: Fri, 22 Mar 2024 21:02:18 -0700
Message-ID: <5FE1E177-BFDB-4386-8DDC-02A652E71C86@thebuild.com> (raw)
In-Reply-To: <CAA23SdtXY94TGASWxVAV9ffx0H3GXBR7fuQnT_Ba20GZsbkZ=w@mail.gmail.com>
References: <CAA23SdtXY94TGASWxVAV9ffx0H3GXBR7fuQnT_Ba20GZsbkZ=w@mail.gmail.com>
> On Mar 22, 2024, at 20:55, arun chirappurath <arunsnmimt@gmail.com> 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 = 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 = 'example_username';
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: xof@thebuild.com, arunsnmimt@gmail.com
Subject: Re: Seq scan vs index scan
In-Reply-To: <5FE1E177-BFDB-4386-8DDC-02A652E71C86@thebuild.com>
References: <CAA23SdtXY94TGASWxVAV9ffx0H3GXBR7fuQnT_Ba20GZsbkZ=w@mail.gmail.com> <5FE1E177-BFDB-4386-8DDC-02A652E71C86@thebuild.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