Naked EXISTS vs SELECT EXISTS very different performance.

From: Jimmy A <jimmypsql(at)gmail(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Naked EXISTS vs SELECT EXISTS very different performance.
Date: 2021-11-01 06:10:53
Message-ID: CANU97ysMJjzYUqo2COo7sZ=UcNrF1tHCbRAN40n3mMo-WSt7HQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hi everyone.

Can someone tell me why these two equivalent queries, one involving a
"naked" EXISTS
versus one involving an EXISTS inside a SELECT statement perform so
differently?
I can see that the slow one scans the entire child table while the fast one
only scans children
that have the same parent_id as the parent. The tables have been vacuumed.
I have confirmed both give the same results across the whole table.

Setup is attached.

Cheers and regards.

Slow
https://explain.depesz.com/s/DzcK

Fast
https://explain.depesz.com/s/EftS

Attachment Content-Type Size
exists.sql application/octet-stream 1.2 KB

Browse pgsql-general by date

  From Date Subject
Next Message Florents Tselai 2021-11-01 11:18:46 Lazier alternative to row_to_json ?
Previous Message Laurenz Albe 2021-11-01 04:42:43 Re: Settings for a new machine - some guidance sought.