Re: Query optimization

From: Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>
To: Durgamahesh Manne <maheshpostgres9(at)gmail(dot)com>, pgsql-general <pgsql-general(at)lists(dot)postgresql(dot)org>
Subject: Re: Query optimization
Date: 2025-03-13 19:34:01
Message-ID: 5b5ba309ccb2a32953f01adc2dcf96260bc9b6c8.camel@cybertec.at
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Fri, 2025-03-14 at 00:42 +0530, Durgamahesh Manne wrote:
> This query takes more time than usual for execution 
>
> How to optimize it in best possible way
>
> Columns used in this query >> composite index eventhough not running optimally 
> SELECT EXISTS (SELECT Key FROM CACHEKEYS WHERE CacheType = $1 AND TrsId = $2 AND
> BrandId = $3 AND SportId = $4 AND CompetitionId = $5 AND
> EventId = $6 AND MarketId = $7 LIMIT ?)

"The best possible way" is hard to say, because an index will have negative
effects on data modification statements.

But for the fastest execution of the query, simply create an index on all the
columns that occur in the WHERE clause. The order doesn't matter.

And remove that useless LIMIT clause.

Yours,
Laurenz Albe

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Renan Alves Fonseca 2025-03-13 21:48:05 Re: psql and regex not like
Previous Message Adrian Klaver 2025-03-13 19:17:23 Re: Query optimization