Re: Hash-based MCV matching for large IN-lists - Mailing list pgsql-hackers

From Matheus Alcantara
Subject Re: Hash-based MCV matching for large IN-lists
Date
Msg-id DGNFXVTPKNX4.2D61JYJY21QJ1@gmail.com
Whole thread Raw
In response to Re: Hash-based MCV matching for large IN-lists  (Ilia Evdokimov <ilya.evdokimov@tantorlabs.com>)
List pgsql-hackers
Hi, thanks for working on this!

On Wed Feb 18, 2026 at 9:48 AM -03, Ilia Evdokimov wrote:
> I've fixed all the comments raised above and updated the v5 patch.
>

Here are some comments regarding v5 patch:

On scalararraysel() we have:

+                ReleaseVariableStats(vardata);
+
+                if (s1 >= 0.0)
+                    return s1;

I'm wondering if we also should call ReleaseVariableStats() on the early
return?

+                    if (!useOr && elem_nulls[i])
+                    {
+                        pfree(elem_values);
+                        pfree(elem_nulls);
+                        pfree(elem_const);
+
+                        return (Selectivity) 0.0;
+                    }

------------------

On scalararray_mcv_hash_match() free_attstatsslot() is called only on
if (have_mcvs && OidIsValid(hashLeft) && OidIsValid(hashRight)),
perhaps it should be moved outside the if condition?

+    if (have_mcvs && OidIsValid(hashLeft) && OidIsValid(hashRight))
+    {
+       ...

+        MCVHashTable_destroy(hashTable);
+        free_attstatsslot(&sslot);
+    }
+
+    return selec;


------------------

typo: "all elements are const"

+ *              array is NULL if all elemnets is const.

------------------

It's worth adding on scalararray_mcv_hash_match() an early return when
num_elems == 0? I imagine that this can happens, e.g "WHERE a =
ANY(array[]::int[]);". In this case the function should still execute
completely?

--
Matheus Alcantara
EDB: https://www.enterprisedb.com



pgsql-hackers by date:

Previous
From: Jacob Champion
Date:
Subject: Re: pgsql: libpq: Grease the protocol by default
Next
From: Mihail Nikalayeu
Date:
Subject: Re: Revisiting {CREATE INDEX, REINDEX} CONCURRENTLY improvements