Re: Regarding query optimisation (select for update)

From: Andy Huang <258790519(at)qq(dot)com>
To: Durgamahesh Manne <maheshpostgres9(at)gmail(dot)com>, pgsql-general <pgsql-general(at)lists(dot)postgresql(dot)org>
Subject: Re: Regarding query optimisation (select for update)
Date: 2025-07-15 13:05:52
Message-ID: tencent_964C2D3503B30C723EA33114254BC30E1A07@qq.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-general

Can you try like: ORDER BY betid desc

---Original---
From: "Durgamahesh Manne"<maheshpostgres9(at)gmail(dot)com&gt;
Date: Tue, Jul 15, 2025 18:10 PM
To: "pgsql-general"<pgsql-general(at)lists(dot)postgresql(dot)org&gt;;
Subject: Regarding query optimisation (select for update)

Hi Team,

We are facing issues&nbsp;with slow running query&nbsp;
&nbsp; &nbsp;SELECT betid, versionid, betdata, processed, messagetime, createdat, updatedat FROM praermabetdata where processed = 'false' ORDER BY betid, versionid LIMIT 200 OFFSET 0 FOR UPDATE;&nbsp;&nbsp;

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;QUERY PLAN
--------------------------------------------------------------------------------------------------------------------------------
&nbsp;Limit &nbsp;(cost=0.28..1.89 rows=1 width=78)
&nbsp; &nbsp;-&gt; &nbsp;LockRows &nbsp;(cost=0.28..1.89 rows=1 width=78)
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;-&gt; &nbsp;Index Scan using idx_praermabetdata_processed_betid_versionid on praermabetdata &nbsp;(cost=0.28..1.88 rows=1 width=78)
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Index Cond: (processed = false)

Do we have any alternative way to improve the performance?
Sometimes processed column use true as well as false&nbsp;

Regards,
Durga Mahesh&nbsp;

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Laurenz Albe 2025-07-15 14:06:20 Re: Regarding query optimisation (select for update)
Previous Message Durgamahesh Manne 2025-07-15 12:56:34 Re: Regarding query optimisation (select for update)