From: Tom Lane <tgl@sss.pgh.pa.us>
To: arun chirappurath <arunsnmimt@gmail.com>
Cc: pgsql-general@lists.postgresql.org
Subject: Re: Seq scan vs index scan
Date: Sat, 23 Mar 2024 00:13:16 -0400
Message-ID: <1242761.1711167196@sss.pgh.pa.us> (raw)
In-Reply-To: <CAA23SdtXY94TGASWxVAV9ffx0H3GXBR7fuQnT_Ba20GZsbkZ=w@mail.gmail.com>
References: <CAA23SdtXY94TGASWxVAV9ffx0H3GXBR7fuQnT_Ba20GZsbkZ=w@mail.gmail.com>
arun chirappurath <arunsnmimt@gmail.com> writes:
> I have a table named users with index on user name.
> ...
> When I try to do below select query it's taking seq scan and query returns
> in 5ms.
5ms is an okay runtime, I would think. Is the table empty?
> I am trying to force query to use indexes using query hints.
The way to force it would be enable_seqscan = off. I would not
be surprised to hear that that makes it slower, though. The
planner will prefer not to use an index if it thinks that will
be slower, and in this case it sounds like that could be right.
(Don't ever assume that what the planner does with a small table
is what it will do with a large table.)
regards, tom lane
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: tgl@sss.pgh.pa.us, arunsnmimt@gmail.com
Subject: Re: Seq scan vs index scan
In-Reply-To: <1242761.1711167196@sss.pgh.pa.us>
References: <CAA23SdtXY94TGASWxVAV9ffx0H3GXBR7fuQnT_Ba20GZsbkZ=w@mail.gmail.com> <1242761.1711167196@sss.pgh.pa.us>
* 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