public inbox for [email protected]
help / color / mirror / Atom feedRe: How to use index in simple select
3+ messages / 2 participants
[nested] [flat]
* Re: How to use index in simple select
@ 2025-11-29 17:27 Adrian Klaver <[email protected]>
0 siblings, 1 reply; 3+ messages in thread
From: Adrian Klaver @ 2025-11-29 17:27 UTC (permalink / raw)
To: Andrus <[email protected]>; pgsql-general
On 11/28/25 14:57, Andrus wrote:
> Hi!
>
> Table has index on name column:
>
> CREATE TABLE firma2.klient
> (
> kood character(12) primary key,
> nimi character(100),
> ...
> );
>
> CREATE INDEX IF NOT EXISTS klient_nimi_idx
> ON firma2.klient USING btree
> (nimi COLLATE pg_catalog."default" ASC NULLS LAST)
> TABLESPACE pg_default;
>
> Database settings have default values:
>
> enable_indexonlyscan on
> enable_indexscan on
> enable_indexonlyscan on
> enable_indexscan on
>
> Query
>
> SELECT * FROM firma2.klient WHERE nimi='John';
>
> Runs slowly.
>
> analyze firma2.klient;
> explain analyze select * from firma2.klient where nimi='John'
>
> Shows that index is not used:
>
> "Seq Scan on klient (cost=0.00..2287976.20 rows=1 width=4002)
> (actual time=12769.987..12769.988 rows=0 loops=1)"
> " Filter: (nimi = 'John'::bpchar)"
> " Rows Removed by Filter: 849971"
> "Planning Time: 4.751 ms"
> "Execution Time: 12770.029 ms"
>
> How to force Postgres to use index? It probably worked long time but
> suddenly stopped working today.
> Re-started whole windows server but problem persists.
>
> Using
>
> PostgreSQL 17.5 on x86_64-windows, compiled by msvc-19.43.34808, 64-bit
>
> in Windows Server 2022 vers 21H2
>
> Andrus.
>
>
> Posted also in
>
> https://stackoverflow.com/questions/79832965/how-to-use-index-in-simple-
> select
>
>
Seems to be already answered:
"It looks like reindex table firma2.klient restored index scan. create
index concurrently was used when lot of transactions using this table
where running"
--
Adrian Klaver
[email protected]
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: How to use index in simple select
@ 2025-11-29 17:47 Andrus <[email protected]>
parent: Adrian Klaver <[email protected]>
0 siblings, 1 reply; 3+ messages in thread
From: Andrus @ 2025-11-29 17:47 UTC (permalink / raw)
To: Adrian Klaver <[email protected]>; pgsql-general
Hi!
> Seems to be already answered:
>
> "It looks like reindex table firma2.klient restored index scan. create
> index concurrently was used when lot of transactions using this table
> where running"
>
Is it possible that reindex changes query from sequential scan to use
index ?
Andrus.
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: How to use index in simple select
@ 2025-11-29 17:56 Adrian Klaver <[email protected]>
parent: Andrus <[email protected]>
0 siblings, 0 replies; 3+ messages in thread
From: Adrian Klaver @ 2025-11-29 17:56 UTC (permalink / raw)
To: Andrus <[email protected]>; pgsql-general
On 11/29/25 09:47, Andrus wrote:
> Hi!
>
>> Seems to be already answered:
>>
>> "It looks like reindex table firma2.klient restored index scan. create
>> index concurrently was used when lot of transactions using this table
>> where running"
>>
> Is it possible that reindex changes query from sequential scan to use
> index ?
More likely it was one of the build index concurrently caveats detailed
here:
https://www.postgresql.org/docs/current/sql-createindex.html#SQL-CREATEINDEX-CONCURRENTLY
>
> Andrus.
>
--
Adrian Klaver
[email protected]
^ permalink raw reply [nested|flat] 3+ messages in thread
end of thread, other threads:[~2025-11-29 17:56 UTC | newest]
Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2025-11-29 17:27 Re: How to use index in simple select Adrian Klaver <[email protected]>
2025-11-29 17:47 ` Andrus <[email protected]>
2025-11-29 17:56 ` Adrian Klaver <[email protected]>
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox