Re: How to use index in simple select

From: hubert depesz lubaczewski <depesz(at)depesz(dot)com>
To: Andrus <kobruleht2(at)hot(dot)ee>
Cc: pgsql-general <pgsql-general(at)postgresql(dot)org>
Subject: Re: How to use index in simple select
Date: 2025-12-01 10:10:14
Message-ID: aS1phiFqCNcmroTg@depesz.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Sat, Nov 29, 2025 at 12:57:46AM +0200, 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;

You got your help, hopefully, but please, please, please, for the love
of anything that you care about:

1. read, and apply: https://wiki.postgresql.org/wiki/Don't_Do_This ->
specifically the part about char(n) datatype
since wiki seems to be having problems for some time now, here is
archived version:
https://web.archive.org/web/20251002222437/https://wiki.postgresql.org/wiki/Don't_Do_This

2. Why did you specify so many things in your index? Generally you
should use CONCURRENTLY (which you didn't), but you don't need
tablespace definition, nor collate, nor ordering, nor nulls last.
Unless you know, for a fact, with proof, that you know what you're
doing and it makes sense.
CREATE index concurrently klient_nimi_idx on firma2.klient (nimi);
should be enough.

Best regards,

depesz

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Stuart Campbell 2025-12-01 11:02:00 Re: Check whether a NOT NULL check constraint has been validated
Previous Message Kasper Føns 2025-12-01 09:49:42 Fwd: restore_command on high-throughput cluster never switches to streaming replication