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

Commit600d320

Browse files
committed
Consider index-only scans even when there is no matching qual or ORDER BY.
By popular demand.
1 parenta018546 commit600d320

File tree

1 file changed

+12
-13
lines changed

1 file changed

+12
-13
lines changed

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

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -317,8 +317,7 @@ find_usable_indexes(PlannerInfo *root, RelOptInfo *rel,
317317
booluseful_predicate;
318318
boolfound_clause;
319319
boolindex_is_ordered;
320-
boolindex_only_scan= false;
321-
boolchecked_index_only= false;
320+
boolindex_only_scan;
322321

323322
/*
324323
* Check that index supports the desired scan type(s)
@@ -436,17 +435,20 @@ find_usable_indexes(PlannerInfo *root, RelOptInfo *rel,
436435
}
437436

438437
/*
439-
* 3. Generate an indexscan path if there are relevant restriction
438+
* 3. Check if an index-only scan is possible.
439+
*/
440+
index_only_scan=check_index_only(rel,index);
441+
442+
/*
443+
* 4. Generate an indexscan path if there are relevant restriction
440444
* clauses in the current clauses, OR the index ordering is
441445
* potentially useful for later merging or final output ordering, OR
442-
* the index has a predicate that was proven by the current clauses.
446+
* the index has a predicate that was proven by the current clauses,
447+
* OR an index-only scan is possible.
443448
*/
444-
if (found_clause||useful_pathkeys!=NIL||useful_predicate)
449+
if (found_clause||useful_pathkeys!=NIL||useful_predicate||
450+
index_only_scan)
445451
{
446-
/* First, detect whether index-only scan is possible */
447-
index_only_scan=check_index_only(rel,index);
448-
checked_index_only= true;
449-
450452
ipath=create_index_path(root,index,
451453
restrictclauses,
452454
orderbyclauses,
@@ -460,7 +462,7 @@ find_usable_indexes(PlannerInfo *root, RelOptInfo *rel,
460462
}
461463

462464
/*
463-
*4. If the index is ordered, a backwards scan might be interesting.
465+
*5. If the index is ordered, a backwards scan might be interesting.
464466
* Again, this is only interesting at top level.
465467
*/
466468
if (index_is_ordered&&possibly_useful_pathkeys&&
@@ -472,9 +474,6 @@ find_usable_indexes(PlannerInfo *root, RelOptInfo *rel,
472474
index_pathkeys);
473475
if (useful_pathkeys!=NIL)
474476
{
475-
if (!checked_index_only)
476-
index_only_scan=check_index_only(rel,index);
477-
478477
ipath=create_index_path(root,index,
479478
restrictclauses,
480479
NIL,

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp