Re: Query run in 27s with 15.2 vs 37ms with 14.6

From: Stephen Frost <sfrost(at)snowman(dot)net>
To: Charles <peacech(at)gmail(dot)com>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, pgsql-bugs(at)lists(dot)postgresql(dot)org
Subject: Re: Query run in 27s with 15.2 vs 37ms with 14.6
Date: 2023-02-20 20:58:36
Message-ID: Y/Pe/Ed7HNBKUN0q@tamriel.snowman.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

Greetings,

* Charles (peacech(at)gmail(dot)com) wrote:
> Wrapping the query with a select * from (...) t where length(code) = 4 puts
> the execution time back to 27 seconds.
>
> This is a bit unexpected since I expect that the result from the inner
> query to be executed first and then filtered.

It's really not- PG will (correctly) attempt to pull in such subselects
into the overall optimization, which is generally better for everyone.
If you want to force it, you can use a WITH MATERIALIZED CTE, or throw
in an 'OFFSET 0' as a hack into your sub-select, but really it's a much
better idea to generate extended stats on what you're filtering as has
been suggested, or come up with a better data representation where
you're not doing a search on a 'length()' as you are.

Thanks,

Stephen

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Tom Lane 2023-02-20 21:59:24 Re: BUG #17795: Erroneous parsing of floating-poing components in DecodeISO8601Interval()
Previous Message Jeff Janes 2023-02-20 19:25:39 Re: Query run in 27s with 15.2 vs 37ms with 14.6