Hi,

While I debug hashjoin codes,  in estimate_multivariate_bucketsize(), I
find that
the list_copy(hashclauses) below is unnecessary if we have a single join
clause.

List       *clauses = list_copy(hashclauses);
...

I adjust the place of list_copy() call as the attached patch.
This can save some overhead of function calls and memory copies.

Any thoughts?

-- 
Thanks, Tender Wang
From d4a29af25ef276a145b46ecc16d631909fb1891a Mon Sep 17 00:00:00 2001
From: Tender Wang <tndrw...@gmail.com>
Date: Mon, 14 Apr 2025 13:53:15 +0800
Subject: [PATCH] Adjust the place of list_copy() in
 estimate_multivariate_bucketsize.

If we have a single hashclause, list_copy(hashclauses) is unnecessary.
This adjustment can save the overhead of function calls and memory
copies.
---
 src/backend/utils/adt/selfuncs.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/src/backend/utils/adt/selfuncs.c b/src/backend/utils/adt/selfuncs.c
index 588d991fa57..786fea16bc5 100644
--- a/src/backend/utils/adt/selfuncs.c
+++ b/src/backend/utils/adt/selfuncs.c
@@ -3799,18 +3799,18 @@ estimate_multivariate_bucketsize(PlannerInfo *root, 
RelOptInfo *inner,
                                                                 List 
*hashclauses,
                                                                 Selectivity 
*innerbucketsize)
 {
-       List       *clauses = list_copy(hashclauses);
+       List       *clauses = NIL;
        List       *otherclauses = NIL;
        double          ndistinct = 1.0;
 
+       /*
+        * Nothing to do for a single clause.  Could we employ univariate
+        * extended stat here?
+        */
        if (list_length(hashclauses) <= 1)
-
-               /*
-                * Nothing to do for a single clause.  Could we employ 
univariate
-                * extended stat here?
-                */
                return hashclauses;
 
+       clauses = list_copy(hashclauses);
        while (clauses != NIL)
        {
                ListCell   *lc;
-- 
2.34.1

Reply via email to