Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Greenplum
Gpdb
提交
d3441155
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,发现更多精彩内容 >>
提交
d3441155
编写于
3月 31, 2008
作者:
T
Tom Lane
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Apply my original fix for Taiki Yamaguchi's bug report about DISTINCT MAX().
Add some regression tests for plausible failures in this area.
上级
e86237ff
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
96 addition
and
3 deletion
+96
-3
src/backend/optimizer/path/equivclass.c
src/backend/optimizer/path/equivclass.c
+39
-1
src/backend/optimizer/plan/planagg.c
src/backend/optimizer/plan/planagg.c
+13
-1
src/include/optimizer/paths.h
src/include/optimizer/paths.h
+4
-1
src/test/regress/expected/aggregates.out
src/test/regress/expected/aggregates.out
+33
-0
src/test/regress/sql/aggregates.sql
src/test/regress/sql/aggregates.sql
+7
-0
未找到文件。
src/backend/optimizer/path/equivclass.c
浏览文件 @
d3441155
...
...
@@ -10,7 +10,7 @@
* Portions Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/optimizer/path/equivclass.c,v 1.
9 2008/01/09 20:42:27
tgl Exp $
* $PostgreSQL: pgsql/src/backend/optimizer/path/equivclass.c,v 1.
10 2008/03/31 16:59:26
tgl Exp $
*
*-------------------------------------------------------------------------
*/
...
...
@@ -1638,6 +1638,44 @@ add_child_rel_equivalences(PlannerInfo *root,
}
/*
* mutate_eclass_expressions
* Apply an expression tree mutator to all expressions stored in
* equivalence classes.
*
* This is a bit of a hack ... it's currently needed only by planagg.c,
* which needs to do a global search-and-replace of MIN/MAX Aggrefs
* after eclasses are already set up. Without changing the eclasses too,
* subsequent matching of ORDER BY clauses would fail.
*
* Note that we assume the mutation won't affect relation membership or any
* other properties we keep track of (which is a bit bogus, but by the time
* planagg.c runs, it no longer matters). Also we must be called in the
* main planner memory context.
*/
void
mutate_eclass_expressions
(
PlannerInfo
*
root
,
Node
*
(
*
mutator
)
(),
void
*
context
)
{
ListCell
*
lc1
;
foreach
(
lc1
,
root
->
eq_classes
)
{
EquivalenceClass
*
cur_ec
=
(
EquivalenceClass
*
)
lfirst
(
lc1
);
ListCell
*
lc2
;
foreach
(
lc2
,
cur_ec
->
ec_members
)
{
EquivalenceMember
*
cur_em
=
(
EquivalenceMember
*
)
lfirst
(
lc2
);
cur_em
->
em_expr
=
(
Expr
*
)
mutator
((
Node
*
)
cur_em
->
em_expr
,
context
);
}
}
}
/*
* find_eclass_clauses_for_index_join
* Create joinclauses usable for a nestloop-with-inner-indexscan
...
...
src/backend/optimizer/plan/planagg.c
浏览文件 @
d3441155
...
...
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/optimizer/plan/planagg.c,v 1.3
6 2008/01/01 19:45:50 momjian
Exp $
* $PostgreSQL: pgsql/src/backend/optimizer/plan/planagg.c,v 1.3
7 2008/03/31 16:59:26 tgl
Exp $
*
*-------------------------------------------------------------------------
*/
...
...
@@ -187,6 +187,18 @@ optimize_minmax_aggregates(PlannerInfo *root, List *tlist, Path *best_path)
hqual
=
replace_aggs_with_params_mutator
(
parse
->
havingQual
,
&
aggs_list
);
/*
* We have to replace Aggrefs with Params in equivalence classes too,
* else ORDER BY or DISTINCT on an optimized aggregate will fail.
*
* Note: at some point it might become necessary to mutate other
* data structures too, such as the query's sortClause or distinctClause.
* Right now, those won't be examined after this point.
*/
mutate_eclass_expressions
(
root
,
replace_aggs_with_params_mutator
,
&
aggs_list
);
/*
* Generate the output plan --- basically just a Result
*/
...
...
src/include/optimizer/paths.h
浏览文件 @
d3441155
...
...
@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
* $PostgreSQL: pgsql/src/include/optimizer/paths.h,v 1.10
3 2008/01/01 19:45:58 momjian
Exp $
* $PostgreSQL: pgsql/src/include/optimizer/paths.h,v 1.10
4 2008/03/31 16:59:26 tgl
Exp $
*
*-------------------------------------------------------------------------
*/
...
...
@@ -127,6 +127,9 @@ extern void add_child_rel_equivalences(PlannerInfo *root,
AppendRelInfo
*
appinfo
,
RelOptInfo
*
parent_rel
,
RelOptInfo
*
child_rel
);
extern
void
mutate_eclass_expressions
(
PlannerInfo
*
root
,
Node
*
(
*
mutator
)
(),
void
*
context
);
extern
List
*
find_eclass_clauses_for_index_join
(
PlannerInfo
*
root
,
RelOptInfo
*
rel
,
Relids
outer_relids
);
...
...
src/test/regress/expected/aggregates.out
浏览文件 @
d3441155
...
...
@@ -484,3 +484,36 @@ from int4_tbl;
-2147483647 | 0
(5 rows)
-- check some cases that were handled incorrectly in 8.3.0
select distinct max(unique2) from tenk1;
max
------
9999
(1 row)
select max(unique2) from tenk1 order by 1;
max
------
9999
(1 row)
select max(unique2) from tenk1 order by max(unique2);
max
------
9999
(1 row)
select max(unique2) from tenk1 order by max(unique2)+1;
max
------
9999
(1 row)
select max(unique2), generate_series(1,3) as g from tenk1 order by g desc;
max | g
------+---
9999 | 3
9999 | 2
9999 | 1
(3 rows)
src/test/regress/sql/aggregates.sql
浏览文件 @
d3441155
...
...
@@ -217,3 +217,10 @@ select min(tenthous) from tenk1 where thousand = 33;
-- check parameter propagation into an indexscan subquery
select
f1
,
(
select
min
(
unique1
)
from
tenk1
where
unique1
>
f1
)
AS
gt
from
int4_tbl
;
-- check some cases that were handled incorrectly in 8.3.0
select
distinct
max
(
unique2
)
from
tenk1
;
select
max
(
unique2
)
from
tenk1
order
by
1
;
select
max
(
unique2
)
from
tenk1
order
by
max
(
unique2
);
select
max
(
unique2
)
from
tenk1
order
by
max
(
unique2
)
+
1
;
select
max
(
unique2
),
generate_series
(
1
,
3
)
as
g
from
tenk1
order
by
g
desc
;
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录