Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rG0x2-00DEu3-5f for pgsql-performance@arkaria.postgresql.org; Wed, 20 Dec 2023 18:05:48 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1rG0x0-00FSXZ-TD for pgsql-performance@arkaria.postgresql.org; Wed, 20 Dec 2023 18:05:46 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rG0x0-00FSXG-HO for pgsql-performance@lists.postgresql.org; Wed, 20 Dec 2023 18:05:46 +0000 Received: from mail1.dalibo.net ([51.159.93.128] helo=mail.dalibo.com) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rG0wy-00BN0w-00 for pgsql-performance@lists.postgresql.org; Wed, 20 Dec 2023 18:05:45 +0000 Received: from [192.168.1.20] (lfbn-ren-1-1137-121.w92-139.abo.wanadoo.fr [92.139.85.121]) by mail.dalibo.com (Postfix) with ESMTPSA id A72381F8EB; Wed, 20 Dec 2023 19:05:40 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=dalibo.com; s=a; t=1703095540; bh=sltefv+92dOQ8lTIWFlHapIoHXH0RRvz1oQv/sX0o+E=; h=Date:Subject:To:References:From:In-Reply-To:From; b=Fa+XfU0wszQExlGyr6NG7uqDMT0NsMyUKofp71x3wc8z83kzOVoljXiqevMVt+VNd hDohe5SfBylcuK55Nk9Zql7v/ygI02dRHDJ8kHcheCzr29kVKWCFLmYIqux93O5aSl NNCDwnQfyLOY00eUWLCtCK2jGOZ5q3mzpGpvajmU= Message-ID: <7a5deb77-3607-4252-be85-63ed0093d9fb@dalibo.com> Date: Wed, 20 Dec 2023 19:05:40 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: Which side of a Merge Join gets executed first? Do both sides always get executed? Content-Language: fr, en-US To: Jerry Brenner , pgsql-performance@lists.postgresql.org References: From: =?UTF-8?Q?Fr=C3=A9d=C3=A9ric_Yhuel?= Autocrypt: addr=frederic.yhuel@dalibo.com; keydata= xjMEXn3bgxYJKwYBBAHaRw8BAQdA6tX5FT/n5ztMWIoBdl6k5avvu65fv6ryfVzIx/aH3V3N JEYuIFlodWVsIDxmcmVkZXJpYy55aHVlbEBkYWxpYm8uY29tPsKWBBMWCAA+FiEEi7OTyf6H ePS+C6n11XGWhN8zGNUFAl6G6CYCGwMFCQeE3WIFCwkIBwIGFQoJCAsCBBYCAwECHgECF4AA CgkQ1XGWhN8zGNWH2wEA/YqoX3f4vTCknwEQgJtqWmcahkMKeusqdddqAB/jclQBAIKj3+N8 fj3S9ZASdfUUz+PoPBvuDSSTdOqwfjX9hZkNzjgEXn3bgxIKKwYBBAGXVQEFAQEHQCuh5cLQ AtEBXHa2Fmtp0kduBu7msM7qO/gaEcdjFUdiAwEIB8J+BBgWCAAmAhsMFiEEi7OTyf6HePS+ C6n11XGWhN8zGNUFAl596uUFCQeE3WIACgkQ1XGWhN8zGNVjGgEA8sKopTosiMWP+pbyf4jF 5WphrhyQf+EBlKIAs0eOpOABAMFDjT7cnlc72KVZd79jT3zmEoVq+IUW5QhcW03LnhoN In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk 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