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

Commite5691cc

Browse files
committed
Don't use_physical_tlist for an IOS with non-returnable columns.
createplan.c tries to save a runtime projection step by specifyinga scan plan node's output as being exactly the table's columns, orindex's columns in the case of an index-only scan, if there is not areason to do otherwise. This logic did not previously pay attentionto whether an index's columns are returnable. That worked, sort ofaccidentally, until commit9a3ddeb taught setrefs.c to reject plansthat try to read a non-returnable column. I have no desire to loosensetrefs.c's new check, so instead adjust use_physical_tlist() to nottry to optimize this way when there are non-returnable column(s).Per report from Ryan Kelly. Like the previous patch, back-patchto all supported branches.Discussion:https://postgr.es/m/CAHUie24ddN+pDNw7fkhNrjrwAX=fXXfGZZEHhRuofV_N_ftaSg@mail.gmail.com
1 parent549ec20 commite5691cc

File tree

3 files changed

+37
-0
lines changed

3 files changed

+37
-0
lines changed

‎src/backend/optimizer/plan/createplan.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -914,6 +914,22 @@ use_physical_tlist(PlannerInfo *root, Path *path, int flags)
914914
return false;
915915
}
916916

917+
/*
918+
* For an index-only scan, the "physical tlist" is the index's indextlist.
919+
* We can only return that without a projection if all the index's columns
920+
* are returnable.
921+
*/
922+
if (path->pathtype==T_IndexOnlyScan)
923+
{
924+
IndexOptInfo*indexinfo= ((IndexPath*)path)->indexinfo;
925+
926+
for (i=0;i<indexinfo->ncolumns;i++)
927+
{
928+
if (!indexinfo->canreturn[i])
929+
return false;
930+
}
931+
}
932+
917933
/*
918934
* Also, can't do it if CP_LABEL_TLIST is specified and path is requested
919935
* to emit any sort/group columns that are not simple Vars. (If they are

‎src/test/regress/expected/gist.out

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,22 @@ select p from gist_tbl where circle(p,1) @> circle(point(0,0),0.95);
357357
(0,0)
358358
(1 row)
359359

360+
-- Also check that use_physical_tlist doesn't trigger in such cases.
361+
explain (verbose, costs off)
362+
select count(*) from gist_tbl;
363+
QUERY PLAN
364+
---------------------------------------------------------------------
365+
Aggregate
366+
Output: count(*)
367+
-> Index Only Scan using gist_tbl_multi_index on public.gist_tbl
368+
(3 rows)
369+
370+
select count(*) from gist_tbl;
371+
count
372+
-------
373+
10001
374+
(1 row)
375+
360376
-- This case isn't supported, but it should at least EXPLAIN correctly.
361377
explain (verbose, costs off)
362378
select p from gist_tbl order by circle(p,1) <-> point(0,0) limit 1;

‎src/test/regress/sql/gist.sql

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,11 @@ explain (verbose, costs off)
159159
select pfrom gist_tblwherecircle(p,1) @>circle(point(0,0),0.95);
160160
select pfrom gist_tblwherecircle(p,1) @>circle(point(0,0),0.95);
161161

162+
-- Also check that use_physical_tlist doesn't trigger in such cases.
163+
explain (verbose, costs off)
164+
selectcount(*)from gist_tbl;
165+
selectcount(*)from gist_tbl;
166+
162167
-- This case isn't supported, but it should at least EXPLAIN correctly.
163168
explain (verbose, costs off)
164169
select pfrom gist_tblorder bycircle(p,1)<->point(0,0)limit1;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp