Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
820754cf
提交
820754cf
authored
9月 17, 2018
作者:
Evgenij Ryazanov
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Prevent incorrect optimizations for window aggregates too
上级
39ab2054
隐藏空白字符变更
内嵌
并排
正在显示
5 个修改的文件
包含
53 行增加
和
22 行删除
+53
-22
AbstractAggregate.java
...c/main/org/h2/expression/aggregate/AbstractAggregate.java
+25
-0
Aggregate.java
h2/src/main/org/h2/expression/aggregate/Aggregate.java
+3
-0
JavaAggregate.java
h2/src/main/org/h2/expression/aggregate/JavaAggregate.java
+3
-0
WindowFunction.java
h2/src/main/org/h2/expression/aggregate/WindowFunction.java
+0
-22
count.sql
...rc/test/org/h2/test/scripts/functions/aggregate/count.sql
+22
-0
没有找到文件。
h2/src/main/org/h2/expression/aggregate/AbstractAggregate.java
浏览文件 @
820754cf
...
@@ -15,6 +15,7 @@ import org.h2.command.dml.SelectGroups;
...
@@ -15,6 +15,7 @@ import org.h2.command.dml.SelectGroups;
import
org.h2.command.dml.SelectOrderBy
;
import
org.h2.command.dml.SelectOrderBy
;
import
org.h2.engine.Session
;
import
org.h2.engine.Session
;
import
org.h2.expression.Expression
;
import
org.h2.expression.Expression
;
import
org.h2.expression.ExpressionVisitor
;
import
org.h2.message.DbException
;
import
org.h2.message.DbException
;
import
org.h2.result.SortOrder
;
import
org.h2.result.SortOrder
;
import
org.h2.table.ColumnResolver
;
import
org.h2.table.ColumnResolver
;
...
@@ -292,6 +293,30 @@ public abstract class AbstractAggregate extends Expression {
...
@@ -292,6 +293,30 @@ public abstract class AbstractAggregate extends Expression {
protected
abstract
Object
createAggregateData
();
protected
abstract
Object
createAggregateData
();
@Override
public
boolean
isEverything
(
ExpressionVisitor
visitor
)
{
if
(
over
==
null
)
{
return
true
;
}
switch
(
visitor
.
getType
())
{
case
ExpressionVisitor
.
QUERY_COMPARABLE
:
case
ExpressionVisitor
.
OPTIMIZABLE_MIN_MAX_COUNT_ALL
:
case
ExpressionVisitor
.
DETERMINISTIC
:
case
ExpressionVisitor
.
INDEPENDENT
:
return
false
;
case
ExpressionVisitor
.
EVALUATABLE
:
case
ExpressionVisitor
.
READONLY
:
case
ExpressionVisitor
.
NOT_FROM_RESOLVER
:
case
ExpressionVisitor
.
GET_DEPENDENCIES
:
case
ExpressionVisitor
.
SET_MAX_DATA_MODIFICATION_ID
:
case
ExpressionVisitor
.
GET_COLUMNS1
:
case
ExpressionVisitor
.
GET_COLUMNS2
:
return
true
;
default
:
throw
DbException
.
throwInternalError
(
"type="
+
visitor
.
getType
());
}
}
@Override
@Override
public
Value
getValue
(
Session
session
)
{
public
Value
getValue
(
Session
session
)
{
SelectGroups
groupData
=
select
.
getGroupDataIfCurrent
(
over
!=
null
);
SelectGroups
groupData
=
select
.
getGroupDataIfCurrent
(
over
!=
null
);
...
...
h2/src/main/org/h2/expression/aggregate/Aggregate.java
浏览文件 @
820754cf
...
@@ -746,6 +746,9 @@ public class Aggregate extends AbstractAggregate {
...
@@ -746,6 +746,9 @@ public class Aggregate extends AbstractAggregate {
@Override
@Override
public
boolean
isEverything
(
ExpressionVisitor
visitor
)
{
public
boolean
isEverything
(
ExpressionVisitor
visitor
)
{
if
(!
super
.
isEverything
(
visitor
))
{
return
false
;
}
if
(
filterCondition
!=
null
&&
!
filterCondition
.
isEverything
(
visitor
))
{
if
(
filterCondition
!=
null
&&
!
filterCondition
.
isEverything
(
visitor
))
{
return
false
;
return
false
;
}
}
...
...
h2/src/main/org/h2/expression/aggregate/JavaAggregate.java
浏览文件 @
820754cf
...
@@ -91,6 +91,9 @@ public class JavaAggregate extends AbstractAggregate {
...
@@ -91,6 +91,9 @@ public class JavaAggregate extends AbstractAggregate {
@Override
@Override
public
boolean
isEverything
(
ExpressionVisitor
visitor
)
{
public
boolean
isEverything
(
ExpressionVisitor
visitor
)
{
if
(!
super
.
isEverything
(
visitor
))
{
return
false
;
}
switch
(
visitor
.
getType
())
{
switch
(
visitor
.
getType
())
{
case
ExpressionVisitor
.
DETERMINISTIC
:
case
ExpressionVisitor
.
DETERMINISTIC
:
// TODO optimization: some functions are deterministic, but we don't
// TODO optimization: some functions are deterministic, but we don't
...
...
h2/src/main/org/h2/expression/aggregate/WindowFunction.java
浏览文件 @
820754cf
...
@@ -7,7 +7,6 @@ package org.h2.expression.aggregate;
...
@@ -7,7 +7,6 @@ package org.h2.expression.aggregate;
import
org.h2.command.dml.Select
;
import
org.h2.command.dml.Select
;
import
org.h2.engine.Session
;
import
org.h2.engine.Session
;
import
org.h2.expression.ExpressionVisitor
;
import
org.h2.message.DbException
;
import
org.h2.message.DbException
;
import
org.h2.value.Value
;
import
org.h2.value.Value
;
import
org.h2.value.ValueInt
;
import
org.h2.value.ValueInt
;
...
@@ -230,27 +229,6 @@ public class WindowFunction extends AbstractAggregate {
...
@@ -230,27 +229,6 @@ public class WindowFunction extends AbstractAggregate {
return
appendTailConditions
(
builder
).
toString
();
return
appendTailConditions
(
builder
).
toString
();
}
}
@Override
public
boolean
isEverything
(
ExpressionVisitor
visitor
)
{
switch
(
visitor
.
getType
())
{
case
ExpressionVisitor
.
QUERY_COMPARABLE
:
case
ExpressionVisitor
.
OPTIMIZABLE_MIN_MAX_COUNT_ALL
:
case
ExpressionVisitor
.
DETERMINISTIC
:
case
ExpressionVisitor
.
INDEPENDENT
:
return
false
;
case
ExpressionVisitor
.
EVALUATABLE
:
case
ExpressionVisitor
.
READONLY
:
case
ExpressionVisitor
.
NOT_FROM_RESOLVER
:
case
ExpressionVisitor
.
GET_DEPENDENCIES
:
case
ExpressionVisitor
.
SET_MAX_DATA_MODIFICATION_ID
:
case
ExpressionVisitor
.
GET_COLUMNS1
:
case
ExpressionVisitor
.
GET_COLUMNS2
:
return
true
;
default
:
throw
DbException
.
throwInternalError
(
"type="
+
visitor
.
getType
());
}
}
@Override
@Override
public
int
getCost
()
{
public
int
getCost
()
{
int
cost
=
1
;
int
cost
=
1
;
...
...
h2/src/test/org/h2/test/scripts/functions/aggregate/count.sql
浏览文件 @
820754cf
...
@@ -47,3 +47,25 @@ select count(v), count(v) filter (where v >= 4) from test;
...
@@ -47,3 +47,25 @@ select count(v), count(v) filter (where v >= 4) from test;
drop
table
test
;
drop
table
test
;
>
ok
>
ok
CREATE
TABLE
TEST
(
ID
INT
PRIMARY
KEY
,
NAME
VARCHAR
);
>
ok
INSERT
INTO
TEST
VALUES
(
1
,
'b'
),
(
3
,
'a'
);
>
update
count
:
2
SELECT
COUNT
(
ID
)
OVER
(
ORDER
BY
NAME
)
AS
NR
,
A
.
ID
AS
ID
FROM
(
SELECT
ID
,
NAME
FROM
TEST
ORDER
BY
NAME
)
AS
A
;
>
NR
ID
>
-- --
>
1
3
>
2
1
>
rows
(
ordered
):
2
SELECT
NR
FROM
(
SELECT
COUNT
(
ID
)
OVER
(
ORDER
BY
NAME
)
AS
NR
,
A
.
ID
AS
ID
FROM
(
SELECT
ID
,
NAME
FROM
TEST
ORDER
BY
NAME
)
AS
A
)
AS
B
WHERE
B
.
ID
=
1
;
>>
2
DROP
TABLE
TEST
;
>
ok
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论