Skip to content

Commit c34605d

Browse files
committed
Fixup some misusages of bms_num_members()
It's a bit inefficient to test if a Bitmapset is empty by counting all the members and seeing if that number is zero. It's much better just to use bms_is_empty(). Likewise for checking if there are at least two members, just use bms_membership(), which does not need to do anything more after finding two members. Discussion: https://postgr.es/m/CAApHDvpvwm_QjbDOb5xga%2BKmX9XkN9xQavNGm3SvDbVnCYOerQ%40mail.gmail.com Reviewed-by: Tomas Vondra
1 parent ff60394 commit c34605d

File tree

2 files changed

+5
-6
lines changed

2 files changed

+5
-6
lines changed

src/backend/optimizer/path/clausesel.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,8 +164,7 @@ clauselist_selectivity_simple(PlannerInfo *root,
164164
* directly to clause_selectivity(). None of what we might do below is
165165
* relevant.
166166
*/
167-
if ((list_length(clauses) == 1) &&
168-
bms_num_members(estimatedclauses) == 0)
167+
if (list_length(clauses) == 1 && bms_is_empty(estimatedclauses))
169168
return clause_selectivity(root, (Node *) linitial(clauses),
170169
varRelid, jointype, sjinfo);
171170

src/backend/statistics/dependencies.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1246,7 +1246,7 @@ dependencies_clauselist_selectivity(PlannerInfo *root,
12461246
* of clauses. We must return 1.0 so the calling function's selectivity is
12471247
* unaffected.
12481248
*/
1249-
if (bms_num_members(clauses_attnums) < 2)
1249+
if (bms_membership(clauses_attnums) != BMS_MULTIPLE)
12501250
{
12511251
bms_free(clauses_attnums);
12521252
pfree(list_attnums);
@@ -1273,18 +1273,18 @@ dependencies_clauselist_selectivity(PlannerInfo *root,
12731273
{
12741274
StatisticExtInfo *stat = (StatisticExtInfo *) lfirst(l);
12751275
Bitmapset *matched;
1276-
int num_matched;
1276+
BMS_Membership membership;
12771277

12781278
/* skip statistics that are not of the correct type */
12791279
if (stat->kind != STATS_EXT_DEPENDENCIES)
12801280
continue;
12811281

12821282
matched = bms_intersect(clauses_attnums, stat->keys);
1283-
num_matched = bms_num_members(matched);
1283+
membership = bms_membership(matched);
12841284
bms_free(matched);
12851285

12861286
/* skip objects matching fewer than two attributes from clauses */
1287-
if (num_matched < 2)
1287+
if (membership != BMS_MULTIPLE)
12881288
continue;
12891289

12901290
func_dependencies[nfunc_dependencies]

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy