Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Fixup some misusages of bms_num_members()
authorDavid Rowley <drowley@postgresql.org>
Tue, 25 Aug 2020 22:51:36 +0000 (10:51 +1200)
committerDavid Rowley <drowley@postgresql.org>
Tue, 25 Aug 2020 22:51:36 +0000 (10:51 +1200)
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
src/backend/optimizer/path/clausesel.c
src/backend/statistics/dependencies.c

index a3ebe10592d0e2392532722c51d10c3672b11014..37a735b06bba649fe301a2ad33eff04b169ef25a 100644 (file)
@@ -164,8 +164,7 @@ clauselist_selectivity_simple(PlannerInfo *root,
     * directly to clause_selectivity(). None of what we might do below is
     * relevant.
     */
-   if ((list_length(clauses) == 1) &&
-       bms_num_members(estimatedclauses) == 0)
+   if (list_length(clauses) == 1 && bms_is_empty(estimatedclauses))
        return clause_selectivity(root, (Node *) linitial(clauses),
                                  varRelid, jointype, sjinfo);
 
index 3e37e2758ca0c1f88c29fdf30f5f36035e839416..4e30abb674378c4389effcf34db5b757e9720c00 100644 (file)
@@ -1246,7 +1246,7 @@ dependencies_clauselist_selectivity(PlannerInfo *root,
     * of clauses. We must return 1.0 so the calling function's selectivity is
     * unaffected.
     */
-   if (bms_num_members(clauses_attnums) < 2)
+   if (bms_membership(clauses_attnums) != BMS_MULTIPLE)
    {
        bms_free(clauses_attnums);
        pfree(list_attnums);
@@ -1273,18 +1273,18 @@ dependencies_clauselist_selectivity(PlannerInfo *root,
    {
        StatisticExtInfo *stat = (StatisticExtInfo *) lfirst(l);
        Bitmapset  *matched;
-       int         num_matched;
+       BMS_Membership membership;
 
        /* skip statistics that are not of the correct type */
        if (stat->kind != STATS_EXT_DEPENDENCIES)
            continue;
 
        matched = bms_intersect(clauses_attnums, stat->keys);
-       num_matched = bms_num_members(matched);
+       membership = bms_membership(matched);
        bms_free(matched);
 
        /* skip objects matching fewer than two attributes from clauses */
-       if (num_matched < 2)
+       if (membership != BMS_MULTIPLE)
            continue;
 
        func_dependencies[nfunc_dependencies]