Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
Postgres FD Implementation
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Abuhujair Javed
Postgres FD Implementation
Commits
0eb5ab82
Commit
0eb5ab82
authored
Mar 02, 2000
by
Tom Lane
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Apply a MATERIAL node to the result of an uncorrelated subplan, if it
looks like it will save computation to do so.
parent
9f198423
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
71 additions
and
5 deletions
+71
-5
src/backend/optimizer/plan/subselect.c
src/backend/optimizer/plan/subselect.c
+71
-5
No files found.
src/backend/optimizer/plan/subselect.c
View file @
0eb5ab82
...
...
@@ -7,7 +7,7 @@
* Portions Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/optimizer/plan/subselect.c,v 1.2
8 2000/02/15 20:49:18
tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/optimizer/plan/subselect.c,v 1.2
9 2000/03/02 04:08:16
tgl Exp $
*
*-------------------------------------------------------------------------
*/
...
...
@@ -18,6 +18,8 @@
#include "nodes/makefuncs.h"
#include "nodes/nodeFuncs.h"
#include "optimizer/clauses.h"
#include "optimizer/cost.h"
#include "optimizer/planmain.h"
#include "optimizer/planner.h"
#include "optimizer/subselect.h"
#include "parser/parse_expr.h"
...
...
@@ -123,6 +125,7 @@ static Node *
make_subplan
(
SubLink
*
slink
)
{
SubPlan
*
node
=
makeNode
(
SubPlan
);
Query
*
subquery
=
(
Query
*
)
(
slink
->
subselect
);
double
tuple_fraction
;
Plan
*
plan
;
List
*
lst
;
...
...
@@ -151,8 +154,7 @@ make_subplan(SubLink *slink)
else
tuple_fraction
=
0
.
5
;
/* 50% */
node
->
plan
=
plan
=
union_planner
((
Query
*
)
slink
->
subselect
,
tuple_fraction
);
node
->
plan
=
plan
=
union_planner
(
subquery
,
tuple_fraction
);
/*
* Assign subPlan, extParam and locParam to plan nodes. At the moment,
...
...
@@ -179,7 +181,7 @@ make_subplan(SubLink *slink)
PlannerQueryLevel
--
;
node
->
plan_id
=
PlannerPlanId
++
;
node
->
rtable
=
((
Query
*
)
slink
->
subselect
)
->
rtable
;
node
->
rtable
=
subquery
->
rtable
;
node
->
sublink
=
slink
;
slink
->
subselect
=
NULL
;
/* cool ?! */
...
...
@@ -287,12 +289,76 @@ make_subplan(SubLink *slink)
}
else
{
/* make expression of SUBPLAN type */
Expr
*
expr
=
makeNode
(
Expr
);
List
*
args
=
NIL
;
List
*
newoper
=
NIL
;
int
i
=
0
;
/*
* We can't convert subplans of ALL_SUBLINK or ANY_SUBLINK types to
* initPlans, even when they are uncorrelated or undirect correlated,
* because we need to scan the output of the subplan for each outer
* tuple. However, we have the option to tack a MATERIAL node onto
* the top of an uncorrelated/undirect correlated subplan, which lets
* us do the work of evaluating the subplan only once. We do this
* if the subplan's top plan node is anything more complicated than
* a sequential or index scan, and we do it even for those plan types
* if the qual appears selective enough to eliminate many tuples.
*/
if
(
node
->
parParam
==
NIL
)
{
bool
use_material
;
switch
(
nodeTag
(
plan
))
{
case
T_SeqScan
:
{
Selectivity
qualsel
;
qualsel
=
clauselist_selectivity
(
subquery
,
plan
->
qual
,
0
);
/* Is 10% selectivity a good threshold?? */
use_material
=
qualsel
<
0
.
10
;
break
;
}
case
T_IndexScan
:
{
List
*
indxqual
=
((
IndexScan
*
)
plan
)
->
indxqualorig
;
Selectivity
qualsel
;
qualsel
=
clauselist_selectivity
(
subquery
,
plan
->
qual
,
0
);
qualsel
*=
clauselist_selectivity
(
subquery
,
indxqual
,
0
);
/* Note: if index is lossy, we just double-counted the
* index selectivity. Worth fixing?
*/
/* Is 10% selectivity a good threshold?? */
use_material
=
qualsel
<
0
.
10
;
break
;
}
case
T_Material
:
case
T_Sort
:
/* Don't add another Material node if there's one already,
* nor if the top node is a Sort, since Sort materializes
* its output anyway. (I doubt either case can happen in
* practice for a subplan, but...)
*/
use_material
=
false
;
break
;
default:
use_material
=
true
;
break
;
}
if
(
use_material
)
{
plan
=
(
Plan
*
)
make_noname
(
plan
->
targetlist
,
NIL
,
plan
);
node
->
plan
=
plan
;
}
}
/*
* Make expression of SUBPLAN type
*/
expr
->
typeOid
=
BOOLOID
;
/* bogus, but we don't really care */
expr
->
opType
=
SUBPLAN_EXPR
;
expr
->
oper
=
(
Node
*
)
node
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment