tbm_intersect(result, subresult);
tbm_free(subresult);
}
+
+ /*
+ * If at any stage we have a completely empty bitmap, we can fall
+ * out without evaluating the remaining subplans, since ANDing them
+ * can no longer change the result. (Note: the fact that indxpath.c
+ * orders the subplans by selectivity should make this case more
+ * likely to occur.)
+ */
+ if (tbm_is_empty(result))
+ break;
}
if (result == NULL)
}
}
+/*
+ * tbm_is_empty - is a TIDBitmap completely empty?
+ */
+bool
+tbm_is_empty(const TIDBitmap *tbm)
+{
+ return (tbm->nentries == 0);
+}
+
/*
* tbm_begin_iterate - prepare to iterate through a TIDBitmap
*
* cases, the partial index will sort before competing non-partial
* indexes and so it makes the right choice, but perhaps we need to
* work harder.
+ *
+ * Note: outputting the selected sub-paths in selectivity order is a good
+ * thing even if we weren't using that as part of the selection method,
+ * because it makes the short-circuit case in MultiExecBitmapAnd() more
+ * likely to apply.
*/
/* Convert list to array so we can apply qsort */
extern void tbm_union(TIDBitmap *a, const TIDBitmap *b);
extern void tbm_intersect(TIDBitmap *a, const TIDBitmap *b);
+extern bool tbm_is_empty(const TIDBitmap *tbm);
+
extern void tbm_begin_iterate(TIDBitmap *tbm);
extern TBMIterateResult *tbm_iterate(TIDBitmap *tbm);