public inbox for [email protected]  
help / color / mirror / Atom feed
From: Laurenz Albe <[email protected]>
To: yudhi s <[email protected]>
Cc: Ron Johnson <[email protected]>
Cc: Adrian Klaver <[email protected]>
Cc: Nisarg Patel <[email protected]>
Cc: pgsql-general <[email protected]>
Subject: Re: Question on execution plan and suitable index
Date: Mon, 16 Feb 2026 15:38:05 +0100
Message-ID: <[email protected]> (raw)
In-Reply-To: <CAEzWdqe6WwgRX4-GQHeePTUCdzHQ5-nMU0hHd9eGWV8ZS3kq0w@mail.gmail.com>
References: <CAEzWdqeGj9FcubNXegJ8PGTnXNahUhgc6T+yNFW7O12EkKR9yA@mail.gmail.com>
	<[email protected]>
	<CAEzWdqfxtEzxO10Rnr0Yw+tPJMtCuu2c2e1mr6bEzuYL1U1BvA@mail.gmail.com>
	<[email protected]>
	<CAEzWdqdo14MgxC_XO+ah_7r-cyEJwfenSAyve1tAeLaE+nwLZA@mail.gmail.com>
	<[email protected]>
	<CAEzWdqe6WwgRX4-GQHeePTUCdzHQ5-nMU0hHd9eGWV8ZS3kq0w@mail.gmail.com>

On Mon, 2026-02-16 at 17:52 +0530, yudhi s wrote:
> Regarding the composite index on (request_id, event_comment_text, created_at) for
> table event_audit_log, is there any advice, which we should follow for keeping
> "date column"(like column "Created_at" here) in the indexing order (apart from
> the frequency of usage in the query)?

The rule is to first have all columns that are compared with equality, then the
others, starting with the most selective one.  Based on the condition, I guessed
that that wouldn't be your "date" column, but if it is, put it second.

> And to help the table scan of the ORDER table, should we also have "entity_id"
> added to the index along with "due_date" i.e. a composite index on (entity_id,due_date)?

I don't know; you'd have to test it on your test system.
The current execution plan has no use for such an index, but adding additional
columns could

1. lead to an efficient index-only scan

2. make PostgreSQL pick an altogether different, better plan

Yours,
Laurenz Albe






view thread (7+ messages)

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], [email protected], [email protected], [email protected]
  Subject: Re: Question on execution plan and suitable 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