Re: Query is taking too long i intermittent

From: Mayank Kandari <mayank(dot)kandari(at)gmail(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Justin Pryzby <pryzby(at)telsasoft(dot)com>, pgsql-performance(at)postgresql(dot)org
Subject: Re: Query is taking too long i intermittent
Date: 2022-06-06 17:13:25
Message-ID: CAArYVwhZsTEELz+PpPGMNTD69PZmZH=xKtZdtVBZH2Byqo-BYA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-performance

Thanks for the tip! I will update my process and monitor it.

On Mon, Jun 6, 2022 at 7:41 PM Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:

> Justin Pryzby <pryzby(at)telsasoft(dot)com> writes:
> > On Mon, Jun 06, 2022 at 03:28:43PM +0530, Mayank Kandari wrote:
> >> SELECT event_id FROM event WHERE (event_sec > time.seconds) OR
> >> ((event_sec=time.seconds) AND (event_usec>=time.useconds) ORDER BY
> >> event_sec, event_usec LIMIT 1
>
> > I think it'd be better if the column was a float storing the fractional
> number
> > of seconds. Currently, it may be hard for the planner to estimate
> rowcounts if
> > the conditions are not independent. I don't know if it's related to this
> > problem, though.
>
> Also, even if you can't change the data representation, there's a more
> idiomatic way to do that in SQL: use a row comparison.
>
> SELECT ...
> WHERE row(event_sec, event_usec) >= row(time.seconds, time.useconds) ...
>
> I doubt this is notably more execution-efficient, but if you're getting a
> bad rowcount estimate it should help with that. It's easier to read too.
>
> regards, tom lane
>

--
regards
Mayank Kandari

In response to

Browse pgsql-performance by date

  From Date Subject
Next Message Paulo Silva 2022-06-08 08:44:08 Strange behavior of limit clause in complex query
Previous Message Tom Lane 2022-06-06 14:11:42 Re: Query is taking too long i intermittent