From: Frédéric Yhuel <frederic.yhuel@dalibo.com>
To: Jerry Brenner <jbrenner@guidewire.com>
To: pgsql-performance@lists.postgresql.org
Subject: Re: Which side of a Merge Join gets executed first? Do both sides always get executed?
Date: Wed, 20 Dec 2023 19:05:40 +0100
Message-ID: <7a5deb77-3607-4252-be85-63ed0093d9fb@dalibo.com> (raw)
In-Reply-To: <CACoKFYQLgfOYnEGKytSZOQ7hrpdcGgk0jn22jRsZCU9aChUnCw@mail.gmail.com>
References: <CACoKFYQLgfOYnEGKytSZOQ7hrpdcGgk0jn22jRsZCU9aChUnCw@mail.gmail.com>
Le 20/12/2023 à 15:40, Jerry Brenner a écrit :
> The attached query plan is from 11.
> We are getting Merge Joins on both sides of the UNION. In both cases,
> the first node under the Merge Join returns 0 rows but the other side of
> the Merge Join (the one being sorted) is executed and that's where all
> of the time is spent.
>
> On the surface, I don't see any way from the attached explain plan to
> determine which side of the Merge Join is executed first. Some questions:
>
> * Which side gets executed first?
> * How would one tell that from the json?
> * Have there been any relevant changes to later releases to make that
> more apparent?
> * Whichever side gets executed first, is the execution of the side
> that would be second get short circuited if 0 rows are returned by
> the first side?
>
> Here's a screenshot from pgMustard.
>
> * Nodes 6 and 14 (the first node under each of the Merge Joins) each
> return 0 rows
> * Nodes 9 and 15 are the expensive sides of the Merge Joins and return
> lots of rows
I think those nodes (9 and 15) are expensive because they have to filter
out 8 millions rows in order to produce their first output row. After
that, they get short circuited.
Best regards,
Frédéric
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-performance@postgresql.org
Cc: frederic.yhuel@dalibo.com, jbrenner@guidewire.com, pgsql-performance@lists.postgresql.org
Subject: Re: Which side of a Merge Join gets executed first? Do both sides always get executed?
In-Reply-To: <7a5deb77-3607-4252-be85-63ed0093d9fb@dalibo.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox