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

Commit898eb25

Browse files
committed
Fix best_inner_indexscan to actually enforce that an "inner indexscan" use
at least one join condition as an indexqual. Before bitmap indexscans, thisoversight didn't really cost much except for redundantly considering thesame join paths twice; but as of 8.1 it could result in silly bitmap scansthat would do the same BitmapOr twice and then BitmapAnd these together :-(
1 parentc6e81ae commit898eb25

File tree

1 file changed

+30
-22
lines changed

1 file changed

+30
-22
lines changed

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

Lines changed: 30 additions & 22 deletions
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.202 2006/03/05 15:58:28 momjian Exp $
12+
* $PostgreSQL: pgsql/src/backend/optimizer/path/indxpath.c,v 1.203 2006/04/08 21:32:17 tgl Exp $
1313
*
1414
*-------------------------------------------------------------------------
1515
*/
@@ -253,6 +253,10 @@ find_usable_indexes(PlannerInfo *root, RelOptInfo *rel,
253253
List*all_clauses=NIL;/* not computed till needed */
254254
ListCell*ilist;
255255

256+
/* quick exit if no available clauses */
257+
if (clauses==NIL)
258+
returnNIL;
259+
256260
foreach(ilist,rel->indexlist)
257261
{
258262
IndexOptInfo*index= (IndexOptInfo*)lfirst(ilist);
@@ -1370,16 +1374,20 @@ best_inner_indexscan(PlannerInfo *root, RelOptInfo *rel,
13701374
}
13711375

13721376
/*
1373-
* Find all the relevantrestriction andjoin clauses.
1377+
* Find all the relevant join clauses.
13741378
*/
13751379
clause_list=find_clauses_for_join(root,rel,outer_relids,isouterjoin);
13761380

13771381
/*
13781382
* Find all the index paths that are usable for this join, except for
1379-
* stuff involving OR and ScalarArrayOpExpr clauses.
1383+
* stuff involving OR and ScalarArrayOpExpr clauses. We can use both
1384+
* join and restriction clauses as indexquals, but we insist the path
1385+
* use at least one join clause (else it'd not be an "inner indexscan"
1386+
* but a plain indexscan, and those have already been considered).
13801387
*/
13811388
indexpaths=find_usable_indexes(root,rel,
1382-
clause_list,NIL,
1389+
clause_list,
1390+
rel->baserestrictinfo,
13831391
false, true,
13841392
outer_relids,
13851393
SAOP_FORBID);
@@ -1389,7 +1397,8 @@ best_inner_indexscan(PlannerInfo *root, RelOptInfo *rel,
13891397
* clauses present in the clause list.
13901398
*/
13911399
bitindexpaths=generate_bitmap_or_paths(root,rel,
1392-
clause_list,NIL,
1400+
clause_list,
1401+
rel->baserestrictinfo,
13931402
true,
13941403
outer_relids);
13951404

@@ -1439,13 +1448,12 @@ best_inner_indexscan(PlannerInfo *root, RelOptInfo *rel,
14391448

14401449
/*
14411450
* find_clauses_for_join
1442-
* Generate a list of clauses that are potentially useful for
1451+
* Generate a list ofjoinclauses that are potentially useful for
14431452
* scanning rel as the inner side of a nestloop join.
14441453
*
1445-
* We consider both join and restriction clauses. Any joinclause that uses
1446-
* only otherrels in the specified outer_relids is fair game. But there must
1447-
* be at least one such joinclause in the final list, otherwise we return NIL
1448-
* indicating that there isn't any potential win here.
1454+
* Any joinclause that uses only otherrels in the specified outer_relids is
1455+
* fair game. Note that restriction clauses on rel can also be used in
1456+
* forming index conditions, but we do not include those here.
14491457
*/
14501458
staticList*
14511459
find_clauses_for_join(PlannerInfo*root,RelOptInfo*rel,
@@ -1473,28 +1481,28 @@ find_clauses_for_join(PlannerInfo *root, RelOptInfo *rel,
14731481

14741482
bms_free(join_relids);
14751483

1476-
/* if no join clause was matched then forget it, per comments above */
1484+
/*quick exitif no join clause was matched */
14771485
if (clause_list==NIL)
14781486
returnNIL;
14791487

1480-
/*
1481-
* We can also use any plain restriction clauses for the rel. We put
1482-
* these at the front of the clause list for the convenience of
1483-
* remove_redundant_join_clauses, which can never remove non-join clauses
1484-
* and hence won't be able to get rid of a non-join clause if it appears
1485-
* after a join clause it is redundant with.
1486-
*/
1487-
clause_list=list_concat(list_copy(rel->baserestrictinfo),clause_list);
1488-
14891488
/*
14901489
* We may now have clauses that are known redundant. Get rid of 'em.
14911490
*/
14921491
if (list_length(clause_list)>1)
1493-
{
14941492
clause_list=remove_redundant_join_clauses(root,
14951493
clause_list,
14961494
isouterjoin);
1497-
}
1495+
1496+
/*
1497+
* We might have found join clauses that are known redundant with
1498+
* restriction clauses on rel (due to conclusions drawn by implied
1499+
* equality deduction; without that, this would obviously never happen).
1500+
* Get rid of them too.
1501+
*/
1502+
if (rel->baserestrictinfo!=NIL)
1503+
clause_list=select_nonredundant_join_clauses(root,clause_list,
1504+
rel->baserestrictinfo,
1505+
isouterjoin);
14981506

14991507
returnclause_list;
15001508
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp