Re: Convert coalesce to or/and

From: Nicolas Adenis-Lamarre <nicolas(dot)adenis(dot)lamarre(at)gmail(dot)com>
To: pgsql-hackers(at)lists(dot)postgresql(dot)org
Subject: Re: Convert coalesce to or/and
Date: 2026-01-03 15:54:20
Message-ID: CACPGbctvagRdjq0EUvj2kmoZ52c50zz1-gKhb_gexN1tBCuaXQ@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

I attached a patch proposition.

explain analyze
select *
from people p
where coalesce(firstname, lastname) = 'Louis'
-- before: Seq Scan on people p (cost=0.00..4015.04 rows=732
width=321) (actual time=0.019..11.217 rows=3856.00 loops=1)
-- after: Seq Scan on people p (cost=0.00..4015.04 rows=3872
width=177) (actual time=0.026..13.730 rows=3856.00 loops=1)

explain analyze
select *
from people p
where firstname = 'Louis' or (firstname is null and lastname = 'Louis')
-- Seq Scan on people p (cost=0.00..4381.24 rows=3872 width=177)
(actual time=0.016..14.899 rows=3856.00 loops=1)

Nicolas

Attachment Content-Type Size
v1-0001-Estimate-coalesce-returned-rows-as-done-for-or-claus.patch text/x-patch 7.5 KB

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Xuneng Zhou 2026-01-03 16:10:44 Re: Implement waiting for wal lsn replay: reloaded
Previous Message Andreas Karlsson 2026-01-03 15:32:19 Re: pg_dump: Add ExecuteSqlCopy and simplify ExecuteSqlQuery