Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit46a0eee

Browse files
committed
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 longeraffect the result. Per a suggestion from Ilia Kantor.
1 parent75e90bb commit46a0eee

File tree

4 files changed

+30
-4
lines changed

4 files changed

+30
-4
lines changed

‎src/backend/executor/nodeBitmapAnd.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/executor/nodeBitmapAnd.c,v 1.2 2005/04/20 15:48:36 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/executor/nodeBitmapAnd.c,v 1.3 2005/08/28 22:47:20 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -143,6 +143,16 @@ MultiExecBitmapAnd(BitmapAndState *node)
143143
tbm_intersect(result,subresult);
144144
tbm_free(subresult);
145145
}
146+
147+
/*
148+
* If at any stage we have a completely empty bitmap, we can fall
149+
* out without evaluating the remaining subplans, since ANDing them
150+
* can no longer change the result. (Note: the fact that indxpath.c
151+
* orders the subplans by selectivity should make this case more
152+
* likely to occur.)
153+
*/
154+
if (tbm_is_empty(result))
155+
break;
146156
}
147157

148158
if (result==NULL)

‎src/backend/nodes/tidbitmap.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
* Copyright (c) 2003-2005, PostgreSQL Global Development Group
2424
*
2525
* IDENTIFICATION
26-
* $PostgreSQL: pgsql/src/backend/nodes/tidbitmap.c,v 1.5 2005/07/24 02:25:26 tgl Exp $
26+
* $PostgreSQL: pgsql/src/backend/nodes/tidbitmap.c,v 1.6 2005/08/28 22:47:20 tgl Exp $
2727
*
2828
*-------------------------------------------------------------------------
2929
*/
@@ -510,6 +510,15 @@ tbm_intersect_page(TIDBitmap *a, PagetableEntry *apage, const TIDBitmap *b)
510510
}
511511
}
512512

513+
/*
514+
* tbm_is_empty - is a TIDBitmap completely empty?
515+
*/
516+
bool
517+
tbm_is_empty(constTIDBitmap*tbm)
518+
{
519+
return (tbm->nentries==0);
520+
}
521+
513522
/*
514523
* tbm_begin_iterate - prepare to iterate through a TIDBitmap
515524
*

‎src/backend/optimizer/path/indxpath.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*
1010
*
1111
* IDENTIFICATION
12-
* $PostgreSQL: pgsql/src/backend/optimizer/path/indxpath.c,v 1.187 2005/07/2820:26:20 tgl Exp $
12+
* $PostgreSQL: pgsql/src/backend/optimizer/path/indxpath.c,v 1.188 2005/08/2822:47:20 tgl Exp $
1313
*
1414
*-------------------------------------------------------------------------
1515
*/
@@ -538,6 +538,11 @@ choose_bitmap_and(PlannerInfo *root, RelOptInfo *rel, List *paths)
538538
* cases, the partial index will sort before competing non-partial
539539
* indexes and so it makes the right choice, but perhaps we need to
540540
* work harder.
541+
*
542+
* Note: outputting the selected sub-paths in selectivity order is a good
543+
* thing even if we weren't using that as part of the selection method,
544+
* because it makes the short-circuit case in MultiExecBitmapAnd() more
545+
* likely to apply.
541546
*/
542547

543548
/* Convert list to array so we can apply qsort */

‎src/include/nodes/tidbitmap.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*
1616
* Copyright (c) 2003-2005, PostgreSQL Global Development Group
1717
*
18-
* $PostgreSQL: pgsql/src/include/nodes/tidbitmap.h,v 1.1 2005/04/17 22:24:02 tgl Exp $
18+
* $PostgreSQL: pgsql/src/include/nodes/tidbitmap.h,v 1.2 2005/08/28 22:47:20 tgl Exp $
1919
*
2020
*-------------------------------------------------------------------------
2121
*/
@@ -49,6 +49,8 @@ extern void tbm_add_tuples(TIDBitmap *tbm, const ItemPointer tids, int ntids);
4949
externvoidtbm_union(TIDBitmap*a,constTIDBitmap*b);
5050
externvoidtbm_intersect(TIDBitmap*a,constTIDBitmap*b);
5151

52+
externbooltbm_is_empty(constTIDBitmap*tbm);
53+
5254
externvoidtbm_begin_iterate(TIDBitmap*tbm);
5355
externTBMIterateResult*tbm_iterate(TIDBitmap*tbm);
5456

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp