Re: Postgres Query Plan using wrong index

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Manikandan Swaminathan <maniswami23(at)gmail(dot)com>
Cc: pgsql-general(at)lists(dot)postgresql(dot)org
Subject: Re: Postgres Query Plan using wrong index
Date: 2025-04-02 00:30:39
Message-ID: 702947.1743553839@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Manikandan Swaminathan <maniswami23(at)gmail(dot)com> writes:
> 4. When running the following query, I would expect the index "idx_col_b_a"
> to be used: select min(col_b) from test_table where col_a > 4996.
> I have a range-based filter on col_a, and am aggregating the result with
> min(col_b). Both columns are covered by "idx_col_b_a".

They may be covered, but sort order matters, and that index has the
wrong sort order to help with this query. Try

create index on test_table(col_b, col_a);

regards, tom lane

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Adrian Klaver 2025-04-02 15:31:42 Re: Any industry best practise to overcome this specific malware "pg_mem"
Previous Message Manikandan Swaminathan 2025-04-02 00:12:04 Postgres Query Plan using wrong index