Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
d902164b
提交
d902164b
authored
1月 13, 2019
作者:
Evgenij Ryazanov
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Optimize window aggregates with AND UNBOUNDED FOLLOWING and no exclusions
上级
fe26f354
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
69 行增加
和
14 行删除
+69
-14
AbstractAggregate.java
...c/main/org/h2/expression/aggregate/AbstractAggregate.java
+36
-7
WindowFrame.java
h2/src/main/org/h2/expression/analysis/WindowFrame.java
+26
-0
array-agg.sql
...est/org/h2/test/scripts/functions/aggregate/array-agg.sql
+7
-7
没有找到文件。
h2/src/main/org/h2/expression/aggregate/AbstractAggregate.java
浏览文件 @
d902164b
...
...
@@ -98,15 +98,22 @@ public abstract class AbstractAggregate extends DataAnalysisOperation {
aggregateFastPartition
(
session
,
result
,
ordered
,
rowIdColumn
,
grouped
);
return
;
}
if
(
frame
.
getStarting
().
getType
()
==
WindowFrameBoundType
.
UNBOUNDED_PRECEDING
&&
frame
.
getExclusion
()
==
WindowFrameExclusion
.
EXCLUDE_NO_OTHERS
)
{
if
(
frame
.
getExclusion
()
==
WindowFrameExclusion
.
EXCLUDE_NO_OTHERS
)
{
WindowFrameBound
following
=
frame
.
getFollowing
();
if
(
following
!=
null
&&
following
.
getType
()
==
WindowFrameBoundType
.
UNBOUNDED_FOLLOWING
)
{
aggregateWholePartition
(
session
,
result
,
ordered
,
rowIdColumn
);
}
else
{
aggregateFastPartition
(
session
,
result
,
ordered
,
rowIdColumn
,
grouped
);
boolean
unboundedFollowing
=
following
!=
null
&&
following
.
getType
()
==
WindowFrameBoundType
.
UNBOUNDED_FOLLOWING
;
if
(
frame
.
getStarting
().
getType
()
==
WindowFrameBoundType
.
UNBOUNDED_PRECEDING
)
{
if
(
unboundedFollowing
)
{
aggregateWholePartition
(
session
,
result
,
ordered
,
rowIdColumn
);
}
else
{
aggregateFastPartition
(
session
,
result
,
ordered
,
rowIdColumn
,
grouped
);
}
return
;
}
if
(
unboundedFollowing
)
{
aggregateFastPartitionInReverse
(
session
,
result
,
ordered
,
rowIdColumn
,
grouped
);
return
;
}
return
;
}
// All other types of frames (slow)
int
size
=
ordered
.
size
();
...
...
@@ -138,6 +145,28 @@ public abstract class AbstractAggregate extends DataAnalysisOperation {
}
}
private
void
aggregateFastPartitionInReverse
(
Session
session
,
HashMap
<
Integer
,
Value
>
result
,
ArrayList
<
Value
[]>
ordered
,
int
rowIdColumn
,
boolean
grouped
)
{
Object
aggregateData
=
createAggregateData
();
int
firstIncludedRow
=
ordered
.
size
();
for
(
int
i
=
firstIncludedRow
-
1
;
i
>=
0
;)
{
int
newLast
=
over
.
getWindowFrame
().
getStartIndex
(
session
,
ordered
,
getOverOrderBySort
(),
i
);
assert
newLast
<=
firstIncludedRow
;
if
(
newLast
<
firstIncludedRow
)
{
for
(
int
j
=
firstIncludedRow
-
1
;
j
>=
newLast
;
j
--)
{
updateFromExpressions
(
session
,
aggregateData
,
ordered
.
get
(
j
));
}
firstIncludedRow
=
newLast
;
}
Value
[]
lastRowInGroup
=
ordered
.
get
(
i
),
currentRowInGroup
=
lastRowInGroup
;
Value
r
=
getAggregatedValue
(
session
,
aggregateData
);
do
{
result
.
put
(
currentRowInGroup
[
rowIdColumn
].
getInt
(),
r
);
}
while
(--
i
>=
0
&&
grouped
&&
overOrderBySort
.
compare
(
lastRowInGroup
,
currentRowInGroup
=
ordered
.
get
(
i
))
==
0
);
}
}
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
;
...
...
h2/src/main/org/h2/expression/analysis/WindowFrame.java
浏览文件 @
d902164b
...
...
@@ -424,6 +424,32 @@ public final class WindowFrame {
:
plainIterator
(
orderedRows
,
startIndex
,
endIndex
,
reverse
);
}
/**
* Returns start index of this frame,
*
* @param session
* the session
* @param orderedRows
* ordered rows
* @param sortOrder
* sort order
* @param currentRow
* index of the current row
* @return start index
* @throws UnsupportedOperationException
* if exclusion clause is not EXCLUDE NO OTHERS
*/
public
int
getStartIndex
(
Session
session
,
ArrayList
<
Value
[]>
orderedRows
,
SortOrder
sortOrder
,
int
currentRow
)
{
if
(
exclusion
!=
WindowFrameExclusion
.
EXCLUDE_NO_OTHERS
)
{
throw
new
UnsupportedOperationException
();
}
int
startIndex
=
getIndex
(
session
,
orderedRows
,
sortOrder
,
currentRow
,
starting
,
false
);
if
(
startIndex
<
0
)
{
startIndex
=
0
;
}
return
startIndex
;
}
/**
* Returns end index of this frame,
*
...
...
h2/src/test/org/h2/test/scripts/functions/aggregate/array-agg.sql
浏览文件 @
d902164b
...
...
@@ -371,7 +371,7 @@ SELECT *,
ARRAY_AGG
(
ID
)
OVER
(
ORDER
BY
VALUE
GROUPS
BETWEEN
UNBOUNDED
PRECEDING
AND
1
PRECEDING
)
U_P
,
ARRAY_AGG
(
ID
)
OVER
(
ORDER
BY
VALUE
GROUPS
BETWEEN
2
PRECEDING
AND
1
PRECEDING
)
P
,
ARRAY_AGG
(
ID
)
OVER
(
ORDER
BY
VALUE
GROUPS
BETWEEN
1
FOLLOWING
AND
2
FOLLOWING
)
F
,
ARRAY_AGG
(
ID
)
OVER
(
ORDER
BY
VALUE
GROUPS
BETWEEN
1
FOLLOWING
AND
UNBOUNDED
FOLLOWING
)
U_F
ARRAY_AGG
(
ID
ORDER
BY
ID
)
OVER
(
ORDER
BY
VALUE
GROUPS
BETWEEN
1
FOLLOWING
AND
UNBOUNDED
FOLLOWING
)
U_F
FROM
TEST
;
>
ID
VALUE
U_P
P
F
U_F
>
-- ----- ------------------ ------------ --------------- ------------------
...
...
@@ -451,11 +451,11 @@ SELECT ID, VALUE, ARRAY_AGG(ID) OVER (ORDER BY VALUE RANGE BETWEEN 2 PRECEDING A
SELECT
ID
,
VALUE
,
ARRAY_AGG
(
ID
)
OVER
(
ORDER
BY
VALUE
ROWS
BETWEEN
UNBOUNDED
PRECEDING
AND
CURRENT
ROW
)
CP
,
ARRAY_AGG
(
ID
)
OVER
(
ORDER
BY
VALUE
ROWS
BETWEEN
CURRENT
ROW
AND
UNBOUNDED
FOLLOWING
)
CF
,
ARRAY_AGG
(
ID
ORDER
BY
ID
)
OVER
(
ORDER
BY
VALUE
ROWS
BETWEEN
CURRENT
ROW
AND
UNBOUNDED
FOLLOWING
)
CF
,
ARRAY_AGG
(
ID
)
OVER
(
ORDER
BY
VALUE
RANGE
BETWEEN
UNBOUNDED
PRECEDING
AND
CURRENT
ROW
)
RP
,
ARRAY_AGG
(
ID
)
OVER
(
ORDER
BY
VALUE
RANGE
BETWEEN
CURRENT
ROW
AND
UNBOUNDED
FOLLOWING
)
RF
,
ARRAY_AGG
(
ID
ORDER
BY
ID
)
OVER
(
ORDER
BY
VALUE
RANGE
BETWEEN
CURRENT
ROW
AND
UNBOUNDED
FOLLOWING
)
RF
,
ARRAY_AGG
(
ID
)
OVER
(
ORDER
BY
VALUE
GROUPS
BETWEEN
UNBOUNDED
PRECEDING
AND
CURRENT
ROW
)
GP
,
ARRAY_AGG
(
ID
)
OVER
(
ORDER
BY
VALUE
GROUPS
BETWEEN
CURRENT
ROW
AND
UNBOUNDED
FOLLOWING
)
GF
ARRAY_AGG
(
ID
ORDER
BY
ID
)
OVER
(
ORDER
BY
VALUE
GROUPS
BETWEEN
CURRENT
ROW
AND
UNBOUNDED
FOLLOWING
)
GF
FROM
TEST
;
>
ID
VALUE
CP
CF
RP
RF
GP
GF
>
-- ----- ------------------------ ------------------------ ------------------------ ------------------------ ------------------------ ------------------------
...
...
@@ -545,11 +545,11 @@ SELECT ID, VALUE, ARRAY_AGG(ID) OVER (ORDER BY VALUE RANGE BETWEEN 1 FOLLOWING A
SELECT
ID
,
VALUE
,
ARRAY_AGG
(
ID
)
OVER
(
ORDER
BY
VALUE
ROWS
BETWEEN
UNBOUNDED
PRECEDING
AND
CURRENT
ROW
)
CP
,
ARRAY_AGG
(
ID
)
OVER
(
ORDER
BY
VALUE
ROWS
BETWEEN
CURRENT
ROW
AND
UNBOUNDED
FOLLOWING
)
CF
,
ARRAY_AGG
(
ID
ORDER
BY
ID
)
OVER
(
ORDER
BY
VALUE
ROWS
BETWEEN
CURRENT
ROW
AND
UNBOUNDED
FOLLOWING
)
CF
,
ARRAY_AGG
(
ID
)
OVER
(
ORDER
BY
VALUE
RANGE
BETWEEN
UNBOUNDED
PRECEDING
AND
CURRENT
ROW
)
RP
,
ARRAY_AGG
(
ID
)
OVER
(
ORDER
BY
VALUE
RANGE
BETWEEN
CURRENT
ROW
AND
UNBOUNDED
FOLLOWING
)
RF
,
ARRAY_AGG
(
ID
ORDER
BY
ID
)
OVER
(
ORDER
BY
VALUE
RANGE
BETWEEN
CURRENT
ROW
AND
UNBOUNDED
FOLLOWING
)
RF
,
ARRAY_AGG
(
ID
)
OVER
(
ORDER
BY
VALUE
GROUPS
BETWEEN
UNBOUNDED
PRECEDING
AND
CURRENT
ROW
)
GP
,
ARRAY_AGG
(
ID
)
OVER
(
ORDER
BY
VALUE
GROUPS
BETWEEN
CURRENT
ROW
AND
UNBOUNDED
FOLLOWING
)
GF
ARRAY_AGG
(
ID
ORDER
BY
ID
)
OVER
(
ORDER
BY
VALUE
GROUPS
BETWEEN
CURRENT
ROW
AND
UNBOUNDED
FOLLOWING
)
GF
FROM
TEST
;
>
ID
VALUE
CP
CF
RP
RF
GP
GF
>
-- ----- ------------------------ ------------------------ ------------------------ ------------------------ ------------------------ ------------------------
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论