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 1rJ1tR-00BPpk-VF for pgsql-hackers@arkaria.postgresql.org; Fri, 29 Dec 2023 01:42:34 +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 1rJ1tQ-0044Br-FP for pgsql-hackers@arkaria.postgresql.org; Fri, 29 Dec 2023 01:42:32 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rJ1tP-0044Bj-H5 for pgsql-hackers@lists.postgresql.org; Fri, 29 Dec 2023 01:42:32 +0000 Received: from m15.mail.163.com ([45.254.50.219]) by magus.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1rJ1tI-00EOZx-65 for pgsql-hackers@lists.postgresql.org; Fri, 29 Dec 2023 01:42:29 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:Subject:Date:Message-ID:MIME-Version: Content-Type; bh=dEwezvP1944D/eGvvmIgZiY2h35V1htlGrNtp1M0/rI=; b=MIDCyXxKeELQEi7IZd06INJoDImLOQxhB9kC8x/34WIfkXgzy7nm2bcz3OxGqW uTcMLgwW4v5Mc3nqC+0ZN86MMiof1+uIn5tQXN0kv6i65kIDrLLkcJXgoGD25oko 7LmG64qkZ6+fo6iVH9u4JQGKcVmx0TNTu7zfaZK9ZjU9I= Received: from b97369165980 (unknown [140.205.118.71]) by zwqz-smtp-mta-g0-1 (Coremail) with SMTP id _____wD337L5I45l32q_Ew--.1499S3; Fri, 29 Dec 2023 09:42:18 +0800 (CST) References: <17540-7aa1855ad5ec18b4@postgresql.org> <2732256.1657163219@sss.pgh.pa.us> <2740652.1657165848@sss.pgh.pa.us> <74a806ed-3b6c-4c45-a67a-27b5f3496ae5@postgrespro.ru> <87bkabri49.fsf@163.com> User-agent: mu4e 1.10.7; emacs 29.1 From: Andy Fan To: Richard Guo Cc: David Rowley , Andrei Lepikhov , Tom Lane , pgsql-hackers@lists.postgresql.org Subject: Re: Removing const-false IS NULL quals and redundant IS NOT NULL quals Date: Fri, 29 Dec 2023 09:25:09 +0800 In-reply-to: Message-ID: <87edf5vl6u.fsf@163.com> MIME-Version: 1.0 Content-Type: text/plain X-CM-TRANSID: _____wD337L5I45l32q_Ew--.1499S3 X-Coremail-Antispam: 1Uf129KBjvdXoW7XFy5Jr43JF1ftr1xAFWUurg_yoWkurb_ua yrtF1UJa10kFW7Jw17Jr4DXFy7A348GFy7Xw4vqrWYyryxJr15C34kZF4xur13W390krn5 Xrn8tryxK39I9jkaLaAFLSUrUUUUUb8apTn2vfkv8UJUUUU8Yxn0WfASr-VFAUDa7-sFnT 9fnUUvcSsGvfC2KfnxnUUI43ZEXa7xRMzuAUUUUUU== X-Originating-IP: [140.205.118.71] X-CM-SenderInfo: x2klx3xlid0iqsrtqiywtou0bp/1tbiVBtVU2VOAuDfOwAAsk List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Richard Guo writes: > > The detection of self-inconsistent restrictions already exists in > planner. > > # set constraint_exclusion to on; > SET > # explain (costs off) select * from a where a > 3 and a is null; > QUERY PLAN > -------------------------- > Result > One-Time Filter: false > (2 rows) It has a different scope and cost from what I suggested. I'd suggest to detect the notnull constraint only with lower cost and it can be used in another user case. the constaint_exclusion can covers more user cases but more expensivly and default off. Apart from the abve topic, I'm thinking if we should think about the case like this: create table t1(a int); create table t2(a int); explain (costs off) select * from t1 join t2 using(a) where a is NULL; QUERY PLAN ----------------------------------- Hash Join Hash Cond: (t2.a = t1.a) -> Seq Scan on t2 -> Hash -> Seq Scan on t1 Filter: (a IS NULL) Here a is nullable at the base relation side, but we know that the query would not return anything at last. IIUC, there is no good place to handle this in our current infrastructure, I still raise this up in case I missed anything. -- Best Regards Andy Fan