Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1p8KEo-0005FJ-N1 for pgsql-hackers@arkaria.postgresql.org; Thu, 22 Dec 2022 11:59:51 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1p8KEm-0001Ck-Gz for pgsql-hackers@arkaria.postgresql.org; Thu, 22 Dec 2022 11:59:48 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1p8KEl-0001Cb-LE for pgsql-hackers@lists.postgresql.org; Thu, 22 Dec 2022 11:59:47 +0000 Received: from mail.postgrespro.ru ([93.174.131.139]) by makus.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1p8KEi-0003o3-NV for pgsql-hackers@lists.postgresql.org; Thu, 22 Dec 2022 11:59:46 +0000 Received: from [192.168.28.53] (cyclops.postgrespro.ru [93.174.131.138]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client did not present a certificate) by mail.postgrespro.ru (Postfix) with ESMTPSA id 2884521C2EF3; Thu, 22 Dec 2022 14:59:42 +0300 (MSK) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=postgrespro.ru; s=mail; t=1671710382; bh=DPIK35G7h7LFfb5YPzy/Wpn19GGPhBhkI6iMKzhjTrU=; h=Date:Subject:To:Cc:References:From:In-Reply-To; b=OLNeX0+J62D267oo0wJtGEjRsOxgdVYc+GowMDYlnd0lYKMEwJkDcZDR7x8dFNQbt woDsXfGM0XgMZqenNJMoucBoAgJJDOZf7vKIDdW/ZfKkQ28oQjPPe1J22R77WAlwgD +cLAH5iYdbha4sYn+xAX9zwXqlGt5l7WSglewJ9w= Message-ID: <628db719-9c26-7aa3-540d-9b6d68e68da6@postgrespro.ru> Date: Thu, 22 Dec 2022 16:59:41 +0500 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0) Gecko/20100101 Thunderbird/102.6.0 Subject: Re: Optimization issue of branching UNION ALL Content-Language: en-US To: Tom Lane Cc: PostgreSQL Hackers References: <703c09a2-08f3-d2ec-b33d-dbecd62428b8@postgrespro.ru> <1788831.1671673839@sss.pgh.pa.us> From: Andrey Lepikhov Organization: Postgres Professional In-Reply-To: <1788831.1671673839@sss.pgh.pa.us> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 22/12/2022 06:50, Tom Lane wrote: >> 2. Iterative passes along the append_rel_list for replacing vars in the >> translated_vars field. I can't grasp real necessity of passing all the >> append_rel_list during flattening of an union all leaf subquery. No one >> can reference this leaf, isn't it? > > After thinking about that for awhile, I believe we can go further: > the containing_appendrel is actually the *only* part of the upper > query that needs to be adjusted. So we could do something like > the attached. > > This passes check-world, but I don't have quite enough confidence > in it to just commit it. Thanks, I have written the letter because of some doubts too. But only one weak point I could imagine - if someday sql standard will be changed. Your code looks better, than previous attempt. -- regards, Andrey Lepikhov Postgres Professional