public inbox for [email protected]  
help / color / mirror / Atom feed
From: Ilia Evdokimov <[email protected]>
To: pgsql-hackers <[email protected]>
Subject: Remove redundant NULL check in clause_selectivity_ext() function
Date: Mon, 19 Aug 2024 12:38:05 +0300
Message-ID: <[email protected]> (raw)

Hi everyone,


In the `clause_selectivity_ext()` function, there’s a comment regarding 
a NULL clause check that asks, "can this still happen?". I decided to 
investigate whether this scenario is still valid.

Here’s what I found after reviewing the relevant cases:

- approx_tuple_count(): The function iterates over a loop of other clauses.
- get_foreign_key_join_selectivity(): The function is invoked within an 
`if (clause)` condition.
- consider_new_or_clause(): The clause is generated by 
`make_restrictinfo()`, which never returns NULL.
- clauselist_selectivity_ext(): This function either checks 
`list_length(clauses) == 1` before being called, or it is called within 
a loop of clauses.

In other cases, the function is called recursively from 
`clause_selectivity_ext()`.

If you are aware of any situations where a NULL clause could be passed 
or if I’ve missed anything, please let me know. I’m also open to any 
other suggestions.

-- 
Regards,
Ilia Evdokimov,
Tantor Labs LCC.


Attachments:

  [text/x-patch] v1-0001-Remove-redundant-NULL-check-for-clause-during-select.patch (1.1K, ../[email protected]/2-v1-0001-Remove-redundant-NULL-check-for-clause-during-select.patch)
  download | inline diff:
From fab0575ef1350cb700b6fc079230397ecb5ca19d Mon Sep 17 00:00:00 2001
From: Ilia Evdokimov <[email protected]>
Date: Mon, 19 Aug 2024 12:08:53 +0300
Subject: [PATCH] Remove redundant NULL check for clause during selectivity
 calculation

The function clause_selectivity_ext() takes a Node *clause parameter,
which is either iterated over in a loop with other clauses or passed
as a RestrictInfo from other functions.
Since these functions guarantee that clause cannot be NULL,
the NULL check is unnecessary and has been removed.
---
 src/backend/optimizer/path/clausesel.c | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/src/backend/optimizer/path/clausesel.c b/src/backend/optimizer/path/clausesel.c
index 0ab021c1e8..5992f96ed2 100644
--- a/src/backend/optimizer/path/clausesel.c
+++ b/src/backend/optimizer/path/clausesel.c
@@ -692,9 +692,6 @@ clause_selectivity_ext(PlannerInfo *root,
 	RestrictInfo *rinfo = NULL;
 	bool		cacheable = false;
 
-	if (clause == NULL)			/* can this still happen? */
-		return s1;
-
 	if (IsA(clause, RestrictInfo))
 	{
 		rinfo = (RestrictInfo *) clause;
-- 
2.34.1



view thread (2+ messages)

reply

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: [email protected]
  Cc: [email protected]
  Subject: Re: Remove redundant NULL check in clause_selectivity_ext() function
  In-Reply-To: <[email protected]>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox