limits of max, min optimization

From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: limits of max, min optimization
Date: 2022-07-18 13:24:02
Message-ID: CAFj8pRCTq7-UDKyVbh=rGY4UtJV2csqQuum0e2u7C+XcmqLXuA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi

I am trying to fix one slow query, and found that optimization of min, max
functions is possible only when there is no JOIN in the query.

Is it true?

I need to do manual transformation of query

select max(insert_date) from foo join boo on foo.boo_id = boo.id
where foo.item_id = 100 and boo.is_ok

to

select insert_date from foo join boo on foo.boo_id = boo.id
where foo.item_id = 100 and boo.is_ok order by insert_date desc limit 1;

Regards

Pavel

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2022-07-18 13:48:16 Re: Proposal to introduce a shuffle function to intarray extension
Previous Message Justin Pryzby 2022-07-18 13:20:00 Re: MERGE and parsing with prepared statements