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 1m0OW8-0003BE-0D for pgsql-hackers@arkaria.postgresql.org; Mon, 05 Jul 2021 13:20:08 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1m0OW6-0005BX-OX for pgsql-hackers@arkaria.postgresql.org; Mon, 05 Jul 2021 13:20:06 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1m0OW6-0005BP-GV for pgsql-hackers@lists.postgresql.org; Mon, 05 Jul 2021 13:20:06 +0000 Received: from mail.postgrespro.ru ([93.174.131.139]) by magus.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1m0OW3-0003bI-PJ for pgsql-hackers@lists.postgresql.org; Mon, 05 Jul 2021 13:20:06 +0000 Received: from Andreys-MacBook-Pro.local (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 55BB921C8AE0; Mon, 5 Jul 2021 16:20:02 +0300 (MSK) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=postgrespro.ru; s=mail; t=1625491202; bh=03F1zwI3QflTowOU1PL0IBNuRmckjhDwgoNEUsfRoAo=; h=Subject:To:Cc:References:From:Date:In-Reply-To; b=fXRwroGNM8I0rdTdS1+aH42vMo8CgNWDbyYVpyZiW2gErymJLdtwbJaiYkCwcFXgV JdSGfEtby2L8wWursW29fPN0xiHijA64CxZUD5E1SLUtIMzNbNQt0JqCAJDIdh2jVt dM1eqDW/6HiCs/sNYqdBomJT0VouhY/5Q3Z449fk= Subject: Re: Removing unneeded self joins To: Hywel Carver Cc: pgsql-hackers@lists.postgresql.org, Konstantin Knizhnik References: <64486b0b-0404-e39e-322d-0801154901f3@postgrespro.ru> <21e15759-dba5-2d2b-dd03-06943ad40378@postgrespro.ru> <161553990603.28624.7702383984090736980.pgcf@coridan.postgresql.org> <2a6e540a-4c9f-9402-2e02-71e35fcd4dd1@postgrespro.ru> From: Andrey Lepikhov Organization: Postgres Professional Message-ID: <4b69ea09-5047-cd8a-a0d7-de1f12120433@postgrespro.ru> Date: Mon, 5 Jul 2021 16:20:01 +0300 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:78.0) Gecko/20100101 Thunderbird/78.11.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 2/7/21 01:56, Hywel Carver wrote: > On Wed, Jun 30, 2021 at 12:21 PM Andrey Lepikhov > > wrote: > I think, here we could ask more general question: do we want to > remove a > 'IS NOT NULL' clause from the clause list if the rest of the list > implicitly implies it? > > > My suggestion was not to remove it, but to avoid adding it in the first > place. When your optimisation has found a join on a group of columns > under a uniqueness constraint, you would do something like this (forgive > the pseudo-code) > > foreach(column, join_clause) { >   if(column.nullable) { // This condition is what I'm suggesting is added >     add_null_test(column, IS_NOT_NULL); >   } > } > > But it may be that that's not possible or practical at this point in the > code. I think, such option will require to implement a new machinery to prove that arbitrary column couldn't produce NULL value. -- regards, Andrey Lepikhov Postgres Professional