Re: Question on execution plan and suitable index

From: Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>
To: yudhi s <learnerdatabase99(at)gmail(dot)com>
Cc: Ron Johnson <ronljohnsonjr(at)gmail(dot)com>, Adrian Klaver <adrian(dot)klaver(at)aklaver(dot)com>, Nisarg Patel <er(dot)nisarg(at)gmail(dot)com>, pgsql-general <pgsql-general(at)lists(dot)postgresql(dot)org>
Subject: Re: Question on execution plan and suitable index
Date: 2026-02-16 14:38:05
Message-ID: c1b5194a0f225d78069f7377b2fbd31dc4f30c40.camel@cybertec.at
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-general

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

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Bruce Momjian 2026-02-16 15:16:56 Re: Support logical replication of DDLs
Previous Message Adrien Obernesser (OBA) 2026-02-16 13:36:59 Re: pgbouncer transaction pool mode issue for prepared statements