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

Commitac25dbd

Browse files
committed
Add support for FUNCTION RTEs to build_physical_tlist(), so that the
physical-tlist optimization can be applied to FunctionScan nodes as wellas regular tables and SubqueryScans.
1 parent3e8dbc8 commitac25dbd

File tree

2 files changed

+43
-8
lines changed

2 files changed

+43
-8
lines changed

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

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
*
1111
*
1212
* IDENTIFICATION
13-
* $PostgreSQL: pgsql/src/backend/optimizer/plan/createplan.c,v 1.189 2005/05/22 22:30:19 tgl Exp $
13+
* $PostgreSQL: pgsql/src/backend/optimizer/plan/createplan.c,v 1.190 2005/05/30 18:55:49 tgl Exp $
1414
*
1515
*-------------------------------------------------------------------------
1616
*/
@@ -308,13 +308,17 @@ use_physical_tlist(RelOptInfo *rel)
308308
inti;
309309

310310
/*
311-
* OK for subqueryscans, but notfunction scans. (This is mainly
312-
*because build_physical_tlist doesn't support them; worth adding?)
311+
* OK for subqueryandfunction scans; otherwise, can't do it for
312+
*anything except real relations.
313313
*/
314-
if (rel->rtekind==RTE_SUBQUERY)
315-
return true;
316314
if (rel->rtekind!=RTE_RELATION)
315+
{
316+
if (rel->rtekind==RTE_SUBQUERY)
317+
return true;
318+
if (rel->rtekind==RTE_FUNCTION)
319+
return true;
317320
return false;
321+
}
318322

319323
/*
320324
* Can't do it with inheritance cases either (mainly because Append

‎src/backend/optimizer/util/plancat.c

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*
1010
*
1111
* IDENTIFICATION
12-
* $PostgreSQL: pgsql/src/backend/optimizer/util/plancat.c,v 1.108 2005/05/23 03:01:14 tgl Exp $
12+
* $PostgreSQL: pgsql/src/backend/optimizer/util/plancat.c,v 1.109 2005/05/30 18:55:49 tgl Exp $
1313
*
1414
*-------------------------------------------------------------------------
1515
*/
@@ -28,6 +28,7 @@
2828
#include"optimizer/tlist.h"
2929
#include"parser/parsetree.h"
3030
#include"parser/parse_expr.h"
31+
#include"parser/parse_relation.h"
3132
#include"rewrite/rewriteManip.h"
3233
#include"utils/builtins.h"
3334
#include"utils/fmgroids.h"
@@ -373,8 +374,9 @@ estimate_rel_size(Relation rel, int32 *attr_widths,
373374
* For now, we don't apply the physical-tlist optimization when there are
374375
* dropped cols.
375376
*
376-
* We also support building a "physical" tlist for subqueries, since the
377-
* same optimization can occur in SubqueryScan nodes.
377+
* We also support building a "physical" tlist for subqueries and functions,
378+
* since the same optimization can occur in SubqueryScan and FunctionScan
379+
* nodes.
378380
*/
379381
List*
380382
build_physical_tlist(Query*root,RelOptInfo*rel)
@@ -388,6 +390,7 @@ build_physical_tlist(Query *root, RelOptInfo *rel)
388390
ListCell*l;
389391
intattrno,
390392
numattrs;
393+
List*colvars;
391394

392395
switch (rte->rtekind)
393396
{
@@ -429,6 +432,10 @@ build_physical_tlist(Query *root, RelOptInfo *rel)
429432
{
430433
TargetEntry*tle= (TargetEntry*)lfirst(l);
431434

435+
/*
436+
* A resjunk column of the subquery can be reflected as
437+
* resjunk in the physical tlist; we need not punt.
438+
*/
432439
var=makeVar(varno,
433440
tle->resno,
434441
exprType((Node*)tle->expr),
@@ -443,6 +450,30 @@ build_physical_tlist(Query *root, RelOptInfo *rel)
443450
}
444451
break;
445452

453+
caseRTE_FUNCTION:
454+
expandRTE(root->rtable,varno,0, true/* include dropped */,
455+
NULL,&colvars);
456+
foreach(l,colvars)
457+
{
458+
var= (Var*)lfirst(l);
459+
/*
460+
* A non-Var in expandRTE's output means a dropped column;
461+
* must punt.
462+
*/
463+
if (!IsA(var,Var))
464+
{
465+
tlist=NIL;
466+
break;
467+
}
468+
469+
tlist=lappend(tlist,
470+
makeTargetEntry((Expr*)var,
471+
var->varattno,
472+
NULL,
473+
false));
474+
}
475+
break;
476+
446477
default:
447478
/* caller error */
448479
elog(ERROR,"unsupported RTE kind %d in build_physical_tlist",

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp