From 46a0eee3006b11a15b73426c8146ed5ab32e1d62 Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Sun, 28 Aug 2005 22:47:20 +0000 Subject: Tweak nodeBitmapAnd to stop evaluating sub-plan scans if it finds it's got an empty bitmap after any step; the remaining subplans can no longer affect the result. Per a suggestion from Ilia Kantor. --- src/backend/executor/nodeBitmapAnd.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'src/backend/executor') diff --git a/src/backend/executor/nodeBitmapAnd.c b/src/backend/executor/nodeBitmapAnd.c index 1d5d94fc3f8..939062d4d6c 100644 --- a/src/backend/executor/nodeBitmapAnd.c +++ b/src/backend/executor/nodeBitmapAnd.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/executor/nodeBitmapAnd.c,v 1.2 2005/04/20 15:48:36 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/executor/nodeBitmapAnd.c,v 1.3 2005/08/28 22:47:20 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -143,6 +143,16 @@ MultiExecBitmapAnd(BitmapAndState *node) 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) -- cgit v1.2.3