public inbox for [email protected]  
help / color / mirror / Atom feed
From: Tom Lane <[email protected]>
To: Manikandan Swaminathan <[email protected]>
Cc: [email protected]
Subject: Re: Postgres Query Plan using wrong index
Date: Tue, 01 Apr 2025 20:30:39 -0400
Message-ID: <[email protected]> (raw)
In-Reply-To: <CAP4RKL8yqrG42oQKFSF4HH3Rpm_cHz4vaaCNTDL--TSLkYNngg@mail.gmail.com>
References: <CAP4RKL8yqrG42oQKFSF4HH3Rpm_cHz4vaaCNTDL--TSLkYNngg@mail.gmail.com>

Manikandan Swaminathan <[email protected]> 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






reply

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 using the --to and --cc options:
  reply via email

  To: [email protected]
  Cc: [email protected], [email protected], [email protected]
  Subject: Re: Postgres Query Plan using wrong index
  In-Reply-To: <[email protected]>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox