Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Greenplum
Gpdb
提交
e2114817
G
Gpdb
项目概览
Greenplum
/
Gpdb
通知
7
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
G
Gpdb
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
e2114817
编写于
1月 22, 2003
作者:
T
Tom Lane
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Implement choice between hash-based and sort-based grouping for doing
DISTINCT processing on the output of an IN sub-select.
上级
a4482f4c
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
105 addition
and
12 deletion
+105
-12
src/backend/optimizer/plan/createplan.c
src/backend/optimizer/plan/createplan.c
+28
-8
src/backend/optimizer/util/pathnode.c
src/backend/optimizer/util/pathnode.c
+77
-4
未找到文件。
src/backend/optimizer/plan/createplan.c
浏览文件 @
e2114817
...
...
@@ -10,12 +10,13 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/optimizer/plan/createplan.c,v 1.13
2 2003/01/20 18:54:52
tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/optimizer/plan/createplan.c,v 1.13
3 2003/01/22 00:07:00
tgl Exp $
*
*-------------------------------------------------------------------------
*/
#include "postgres.h"
#include <limits.h>
#include "nodes/makefuncs.h"
#include "nodes/nodeFuncs.h"
...
...
@@ -418,6 +419,7 @@ create_unique_plan(Query *root, UniquePath *best_path)
Plan
*
plan
;
Plan
*
subplan
;
List
*
sub_targetlist
;
List
*
my_tlist
;
List
*
l
;
subplan
=
create_plan
(
root
,
best_path
->
subpath
);
...
...
@@ -474,21 +476,39 @@ create_unique_plan(Query *root, UniquePath *best_path)
subplan
->
targetlist
=
newtlist
;
}
my_tlist
=
new_unsorted_tlist
(
subplan
->
targetlist
);
if
(
best_path
->
use_hash
)
{
elog
(
ERROR
,
"create_unique_plan: hash case not implemented yet"
);
plan
=
NULL
;
int
numGroupCols
=
length
(
my_tlist
);
long
numGroups
;
AttrNumber
*
groupColIdx
;
int
i
;
numGroups
=
(
long
)
Min
(
best_path
->
rows
,
(
double
)
LONG_MAX
);
groupColIdx
=
(
AttrNumber
*
)
palloc
(
numGroupCols
*
sizeof
(
AttrNumber
));
for
(
i
=
0
;
i
<
numGroupCols
;
i
++
)
groupColIdx
[
i
]
=
i
+
1
;
plan
=
(
Plan
*
)
make_agg
(
root
,
my_tlist
,
NIL
,
AGG_HASHED
,
numGroupCols
,
groupColIdx
,
numGroups
,
0
,
subplan
);
}
else
{
List
*
sort_tlist
;
List
*
sortList
;
sort_tlist
=
new_unsorted_tlist
(
subplan
->
targetlist
);
sortList
=
addAllTargetsToSortList
(
NIL
,
sort_tlist
);
plan
=
(
Plan
*
)
make_sort_from_sortclauses
(
root
,
sort_tlist
,
sortList
=
addAllTargetsToSortList
(
NIL
,
my_tlist
);
plan
=
(
Plan
*
)
make_sort_from_sortclauses
(
root
,
my_tlist
,
subplan
,
sortList
);
plan
=
(
Plan
*
)
make_unique
(
sort
_tlist
,
plan
,
sortList
);
plan
=
(
Plan
*
)
make_unique
(
my
_tlist
,
plan
,
sortList
);
}
plan
->
plan_rows
=
best_path
->
rows
;
...
...
src/backend/optimizer/util/pathnode.c
浏览文件 @
e2114817
...
...
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/optimizer/util/pathnode.c,v 1.8
4 2003/01/20 18:54:56
tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/optimizer/util/pathnode.c,v 1.8
5 2003/01/22 00:07:00
tgl Exp $
*
*-------------------------------------------------------------------------
*/
...
...
@@ -16,14 +16,22 @@
#include <math.h>
#include "catalog/pg_operator.h"
#include "executor/executor.h"
#include "miscadmin.h"
#include "nodes/plannodes.h"
#include "optimizer/cost.h"
#include "optimizer/pathnode.h"
#include "optimizer/paths.h"
#include "optimizer/restrictinfo.h"
#include "parser/parse_expr.h"
#include "parser/parse_oper.h"
#include "utils/memutils.h"
#include "utils/selfuncs.h"
#include "utils/syscache.h"
static
bool
hash_safe_tlist
(
List
*
tlist
);
/*****************************************************************************
...
...
@@ -506,6 +514,7 @@ create_unique_path(Query *root, RelOptInfo *rel, Path *subpath)
{
UniquePath
*
pathnode
;
Path
sort_path
;
/* dummy for result of cost_sort */
Path
agg_path
;
/* dummy for result of cost_agg */
MemoryContext
oldcontext
;
List
*
sub_targetlist
;
List
*
l
;
...
...
@@ -587,16 +596,80 @@ create_unique_path(Query *root, RelOptInfo *rel, Path *subpath)
*/
sort_path
.
total_cost
+=
cpu_operator_cost
*
rel
->
rows
*
numCols
;
pathnode
->
use_hash
=
false
;
/* for now */
/*
* Is it safe to use a hashed implementation? If so, estimate and
* compare costs. We only try this if we know the targetlist for
* sure (else we can't be sure about the datatypes involved).
*/
pathnode
->
use_hash
=
false
;
if
(
enable_hashagg
&&
sub_targetlist
&&
hash_safe_tlist
(
sub_targetlist
))
{
/*
* Estimate the overhead per hashtable entry at 64 bytes (same
* as in planner.c).
*/
int
hashentrysize
=
rel
->
width
+
64
;
pathnode
->
path
.
startup_cost
=
sort_path
.
startup_cost
;
pathnode
->
path
.
total_cost
=
sort_path
.
total_cost
;
if
(
hashentrysize
*
pathnode
->
rows
<=
SortMem
*
1024L
)
{
cost_agg
(
&
agg_path
,
root
,
AGG_HASHED
,
0
,
numCols
,
pathnode
->
rows
,
subpath
->
startup_cost
,
subpath
->
total_cost
,
rel
->
rows
);
if
(
agg_path
.
total_cost
<
sort_path
.
total_cost
)
pathnode
->
use_hash
=
true
;
}
}
if
(
pathnode
->
use_hash
)
{
pathnode
->
path
.
startup_cost
=
agg_path
.
startup_cost
;
pathnode
->
path
.
total_cost
=
agg_path
.
total_cost
;
}
else
{
pathnode
->
path
.
startup_cost
=
sort_path
.
startup_cost
;
pathnode
->
path
.
total_cost
=
sort_path
.
total_cost
;
}
rel
->
cheapest_unique_path
=
(
Path
*
)
pathnode
;
return
pathnode
;
}
/*
* hash_safe_tlist - can datatypes of given tlist be hashed?
*
* We assume hashed aggregation will work if the datatype's equality operator
* is marked hashjoinable.
*
* XXX this probably should be somewhere else. See also hash_safe_grouping
* in plan/planner.c.
*/
static
bool
hash_safe_tlist
(
List
*
tlist
)
{
List
*
tl
;
foreach
(
tl
,
tlist
)
{
Node
*
expr
=
(
Node
*
)
lfirst
(
tl
);
Operator
optup
;
bool
oprcanhash
;
optup
=
equality_oper
(
exprType
(
expr
),
true
);
if
(
!
optup
)
return
false
;
oprcanhash
=
((
Form_pg_operator
)
GETSTRUCT
(
optup
))
->
oprcanhash
;
ReleaseSysCache
(
optup
);
if
(
!
oprcanhash
)
return
false
;
}
return
true
;
}
/*
* create_subqueryscan_path
* Creates a path corresponding to a sequential scan of a subquery,
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录