Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
ede2d58d
提交
ede2d58d
authored
1月 12, 2019
作者:
Evgenij Ryazanov
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Evaluate window aggregate function only once per each group when possible
上级
7aaa5ff4
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
37 行增加
和
7 行删除
+37
-7
AbstractAggregate.java
...c/main/org/h2/expression/aggregate/AbstractAggregate.java
+26
-7
WindowFrameExclusion.java
...main/org/h2/expression/analysis/WindowFrameExclusion.java
+11
-0
没有找到文件。
h2/src/main/org/h2/expression/aggregate/AbstractAggregate.java
浏览文件 @
ede2d58d
...
@@ -19,6 +19,7 @@ import org.h2.expression.analysis.WindowFrame;
...
@@ -19,6 +19,7 @@ import org.h2.expression.analysis.WindowFrame;
import
org.h2.expression.analysis.WindowFrameBound
;
import
org.h2.expression.analysis.WindowFrameBound
;
import
org.h2.expression.analysis.WindowFrameBoundType
;
import
org.h2.expression.analysis.WindowFrameBoundType
;
import
org.h2.expression.analysis.WindowFrameExclusion
;
import
org.h2.expression.analysis.WindowFrameExclusion
;
import
org.h2.expression.analysis.WindowFrameUnits
;
import
org.h2.table.ColumnResolver
;
import
org.h2.table.ColumnResolver
;
import
org.h2.table.TableFilter
;
import
org.h2.table.TableFilter
;
import
org.h2.value.Value
;
import
org.h2.value.Value
;
...
@@ -86,9 +87,16 @@ public abstract class AbstractAggregate extends DataAnalysisOperation {
...
@@ -86,9 +87,16 @@ public abstract class AbstractAggregate extends DataAnalysisOperation {
protected
void
getOrderedResultLoop
(
Session
session
,
HashMap
<
Integer
,
Value
>
result
,
ArrayList
<
Value
[]>
ordered
,
protected
void
getOrderedResultLoop
(
Session
session
,
HashMap
<
Integer
,
Value
>
result
,
ArrayList
<
Value
[]>
ordered
,
int
rowIdColumn
)
{
int
rowIdColumn
)
{
WindowFrame
frame
=
over
.
getWindowFrame
();
WindowFrame
frame
=
over
.
getWindowFrame
();
/*
* With RANGE (default) or GROUPS units and EXCLUDE GROUP or EXCLUDE NO
* OTHERS (default) exclusion all rows in the group have the same value
* of window aggregate function.
*/
boolean
grouped
=
frame
==
null
||
frame
.
getUnits
()
!=
WindowFrameUnits
.
ROWS
&&
frame
.
getExclusion
().
isGroupOrNoOthers
();
if
(
frame
==
null
)
{
if
(
frame
==
null
)
{
assert
over
.
getOrderBy
()
!=
null
;
assert
over
.
getOrderBy
()
!=
null
;
aggregateFastPartition
(
session
,
result
,
ordered
,
rowIdColumn
);
aggregateFastPartition
(
session
,
result
,
ordered
,
rowIdColumn
,
grouped
);
return
;
return
;
}
}
if
(
frame
.
getStarting
().
getType
()
==
WindowFrameBoundType
.
UNBOUNDED_PRECEDING
if
(
frame
.
getStarting
().
getType
()
==
WindowFrameBoundType
.
UNBOUNDED_PRECEDING
...
@@ -97,28 +105,28 @@ public abstract class AbstractAggregate extends DataAnalysisOperation {
...
@@ -97,28 +105,28 @@ public abstract class AbstractAggregate extends DataAnalysisOperation {
if
(
following
!=
null
&&
following
.
getType
()
==
WindowFrameBoundType
.
UNBOUNDED_FOLLOWING
)
{
if
(
following
!=
null
&&
following
.
getType
()
==
WindowFrameBoundType
.
UNBOUNDED_FOLLOWING
)
{
aggregateWholePartition
(
session
,
result
,
ordered
,
rowIdColumn
);
aggregateWholePartition
(
session
,
result
,
ordered
,
rowIdColumn
);
}
else
{
}
else
{
aggregateFastPartition
(
session
,
result
,
ordered
,
rowIdColumn
);
aggregateFastPartition
(
session
,
result
,
ordered
,
rowIdColumn
,
grouped
);
}
}
return
;
return
;
}
}
// All other types of frames (slow)
// All other types of frames (slow)
int
size
=
ordered
.
size
();
int
size
=
ordered
.
size
();
for
(
int
i
=
0
;
i
<
size
;
i
++
)
{
for
(
int
i
=
0
;
i
<
size
;)
{
Object
aggregateData
=
createAggregateData
();
Object
aggregateData
=
createAggregateData
();
for
(
Iterator
<
Value
[]>
iter
=
WindowFrame
.
iterator
(
over
,
session
,
ordered
,
getOverOrderBySort
(),
i
,
for
(
Iterator
<
Value
[]>
iter
=
WindowFrame
.
iterator
(
over
,
session
,
ordered
,
getOverOrderBySort
(),
i
,
false
);
iter
.
hasNext
();)
{
false
);
iter
.
hasNext
();)
{
updateFromExpressions
(
session
,
aggregateData
,
iter
.
next
());
updateFromExpressions
(
session
,
aggregateData
,
iter
.
next
());
}
}
result
.
put
(
ordered
.
get
(
i
)[
rowIdColumn
].
getInt
(),
getAggregatedValue
(
session
,
aggregateData
)
);
i
=
processGroup
(
session
,
result
,
ordered
,
rowIdColumn
,
i
,
size
,
aggregateData
,
grouped
);
}
}
}
}
private
void
aggregateFastPartition
(
Session
session
,
HashMap
<
Integer
,
Value
>
result
,
ArrayList
<
Value
[]>
ordered
,
private
void
aggregateFastPartition
(
Session
session
,
HashMap
<
Integer
,
Value
>
result
,
ArrayList
<
Value
[]>
ordered
,
int
rowIdColumn
)
{
int
rowIdColumn
,
boolean
grouped
)
{
Object
aggregateData
=
createAggregateData
();
Object
aggregateData
=
createAggregateData
();
int
size
=
ordered
.
size
();
int
size
=
ordered
.
size
();
int
lastIncludedRow
=
-
1
;
int
lastIncludedRow
=
-
1
;
for
(
int
i
=
0
;
i
<
size
;
i
++
)
{
for
(
int
i
=
0
;
i
<
size
;)
{
int
newLast
=
WindowFrame
.
getEndIndex
(
over
,
session
,
ordered
,
getOverOrderBySort
(),
i
);
int
newLast
=
WindowFrame
.
getEndIndex
(
over
,
session
,
ordered
,
getOverOrderBySort
(),
i
);
assert
newLast
>=
lastIncludedRow
;
assert
newLast
>=
lastIncludedRow
;
if
(
newLast
>
lastIncludedRow
)
{
if
(
newLast
>
lastIncludedRow
)
{
...
@@ -127,10 +135,21 @@ public abstract class AbstractAggregate extends DataAnalysisOperation {
...
@@ -127,10 +135,21 @@ public abstract class AbstractAggregate extends DataAnalysisOperation {
}
}
lastIncludedRow
=
newLast
;
lastIncludedRow
=
newLast
;
}
}
result
.
put
(
ordered
.
get
(
i
)[
rowIdColumn
].
getInt
(),
getAggregatedValue
(
session
,
aggregateData
)
);
i
=
processGroup
(
session
,
result
,
ordered
,
rowIdColumn
,
i
,
size
,
aggregateData
,
grouped
);
}
}
}
}
private
int
processGroup
(
Session
session
,
HashMap
<
Integer
,
Value
>
result
,
ArrayList
<
Value
[]>
ordered
,
int
rowIdColumn
,
int
i
,
int
size
,
Object
aggregateData
,
boolean
grouped
)
{
Value
[]
firstRowInGroup
=
ordered
.
get
(
i
),
currentRowInGroup
=
firstRowInGroup
;
Value
r
=
getAggregatedValue
(
session
,
aggregateData
);
do
{
result
.
put
(
currentRowInGroup
[
rowIdColumn
].
getInt
(),
r
);
}
while
(++
i
<
size
&&
grouped
&&
overOrderBySort
.
compare
(
firstRowInGroup
,
currentRowInGroup
=
ordered
.
get
(
i
))
==
0
);
return
i
;
}
private
void
aggregateWholePartition
(
Session
session
,
HashMap
<
Integer
,
Value
>
result
,
ArrayList
<
Value
[]>
ordered
,
private
void
aggregateWholePartition
(
Session
session
,
HashMap
<
Integer
,
Value
>
result
,
ArrayList
<
Value
[]>
ordered
,
int
rowIdColumn
)
{
int
rowIdColumn
)
{
// Aggregate values from the whole partition
// Aggregate values from the whole partition
...
...
h2/src/main/org/h2/expression/analysis/WindowFrameExclusion.java
浏览文件 @
ede2d58d
...
@@ -38,6 +38,17 @@ public enum WindowFrameExclusion {
...
@@ -38,6 +38,17 @@ public enum WindowFrameExclusion {
this
.
sql
=
sql
;
this
.
sql
=
sql
;
}
}
/**
* Returns true if this exclusion clause excludes or includes the whole
* group.
*
* @return true if this exclusion clause is {@link #EXCLUDE_GROUP} or
* {@link #EXCLUDE_NO_OTHERS}
*/
public
boolean
isGroupOrNoOthers
()
{
return
this
==
WindowFrameExclusion
.
EXCLUDE_GROUP
||
this
==
EXCLUDE_NO_OTHERS
;
}
/**
/**
* Returns SQL representation.
* Returns SQL representation.
*
*
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论