From c748ed6c858873812e7a5bc7d9a846bb2c2673ac Mon Sep 17 00:00:00 2001 From: Yuya Watari Date: Fri, 10 Mar 2023 15:01:26 +0900 Subject: [PATCH v18 5/5] Reduce bms_is_empty_internal() function call Originally, we checked whether the result was empty or not by calling bms_is_empty_internal() function at the end of bms_int_members(). However, this leads to redundant looping over the bitmapset. This commit reduces this call and improves the performance. --- src/backend/nodes/bitmapset.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/backend/nodes/bitmapset.c b/src/backend/nodes/bitmapset.c index af87da15fb..b8f4f85361 100644 --- a/src/backend/nodes/bitmapset.c +++ b/src/backend/nodes/bitmapset.c @@ -929,6 +929,7 @@ bms_int_members(Bitmapset *a, const Bitmapset *b) { int shortlen; int i; + bool result_is_empty = true; /* Handle cases where either input is NULL */ if (a == NULL) @@ -941,7 +942,12 @@ bms_int_members(Bitmapset *a, const Bitmapset *b) /* Intersect b into a; we need never copy */ shortlen = Min(a->nwords, b->nwords); for (i = 0; i < shortlen; i++) - a->words[i] &= b->words[i]; + { + bitmapword w = (a->words[i] &= b->words[i]); + + if (w != 0) + result_is_empty = false; + } /* * We simply shorten the left input to both remove the need to zero the @@ -953,7 +959,7 @@ bms_int_members(Bitmapset *a, const Bitmapset *b) a->nwords = shortlen; /* If we computed an empty result, we must return NULL */ - if (bms_is_empty_internal(a)) + if (result_is_empty) { pfree(a); return NULL; -- 2.39.2.windows.1