Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
899022c9
提交
899022c9
authored
8 年前
作者:
Noel Grandin
提交者:
GitHub
8 年前
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #443 from alexpaschenko/opt-cmp
Optimized column vs constant comparisons
上级
079c91bf
2604902d
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
33 行增加
和
6 行删除
+33
-6
Comparison.java
h2/src/main/org/h2/expression/Comparison.java
+7
-0
TestOptimizations.java
h2/src/test/org/h2/test/db/TestOptimizations.java
+20
-0
testScript.sql
h2/src/test/org/h2/test/testScript.sql
+6
-6
没有找到文件。
h2/src/main/org/h2/expression/Comparison.java
浏览文件 @
899022c9
...
...
@@ -194,6 +194,13 @@ public class Comparison extends Condition {
return
ValueExpression
.
getNull
();
}
}
int
colType
=
left
.
getType
();
int
constType
=
r
.
getType
();
int
resType
=
Value
.
getHigherOrder
(
colType
,
constType
);
// If not the column values will need to be promoted
// to constant type, but vise versa, then let's do this here once.
if
(
constType
!=
resType
)
right
=
ValueExpression
.
get
(
r
.
convertTo
(
resType
));
}
else
if
(
right
instanceof
Parameter
)
{
((
Parameter
)
right
).
setColumn
(
((
ExpressionColumn
)
left
).
getColumn
());
...
...
This diff is collapsed.
Click to expand it.
h2/src/test/org/h2/test/db/TestOptimizations.java
浏览文件 @
899022c9
...
...
@@ -58,6 +58,7 @@ public class TestOptimizations extends TestBase {
testNestedIn
();
testConstantIn1
();
testConstantIn2
();
testConstantTypeConversionToColumnType
();
testNestedInSelectAndLike
();
testNestedInSelect
();
testInSelectJoin
();
...
...
@@ -463,6 +464,25 @@ public class TestOptimizations extends TestBase {
conn
.
close
();
}
private
void
testConstantTypeConversionToColumnType
()
throws
SQLException
{
deleteDb
(
"optimizations"
);
Connection
conn
=
getConnection
(
"optimizations;IGNORECASE=TRUE"
);
Statement
stat
=
conn
.
createStatement
();
stat
.
executeUpdate
(
"CREATE TABLE test (x int)"
);
ResultSet
resultSet
;
resultSet
=
stat
.
executeQuery
(
"EXPLAIN SELECT x FROM test WHERE x = '5'"
);
assertTrue
(
resultSet
.
next
());
// String constant '5' has been converted to int constant 5 on optimization
assertTrue
(
resultSet
.
getString
(
1
).
endsWith
(
"X = 5"
));
stat
.
execute
(
"drop table test"
);
conn
.
close
();
}
private
void
testNestedInSelect
()
throws
SQLException
{
deleteDb
(
"optimizations"
);
Connection
conn
=
getConnection
(
"optimizations"
);
...
...
This diff is collapsed.
Click to expand it.
h2/src/test/org/h2/test/testScript.sql
浏览文件 @
899022c9
...
...
@@ -8172,9 +8172,9 @@ select * from s;
>
rows
:
1
select
some
(
y
>
10
),
every
(
y
>
10
),
min
(
y
),
max
(
y
)
from
t
;
>
BOOL_OR
(
Y
>
10
)
BOOL_AND
(
Y
>
1
0
)
MIN
(
Y
)
MAX
(
Y
)
>
---------------
---------------- ------ ------
>
null
null
null
null
>
BOOL_OR
(
Y
>
10
.
0
)
BOOL_AND
(
Y
>
10
.
0
)
MIN
(
Y
)
MAX
(
Y
)
>
---------------
-- --
---------------- ------ ------
>
null
null
null
null
>
rows
:
1
insert
into
t
values
(
1000000004
,
4
);
...
...
@@ -8230,9 +8230,9 @@ stddev_pop(distinct y) s_py, stddev_samp(distinct y) s_sy, var_pop(distinct y) v
>
rows
:
1
select
some
(
y
>
10
),
every
(
y
>
10
),
min
(
y
),
max
(
y
)
from
t
;
>
BOOL_OR
(
Y
>
10
)
BOOL_AND
(
Y
>
1
0
)
MIN
(
Y
)
MAX
(
Y
)
>
---------------
---------------- ------ ------
>
TRUE
FALSE
4
.
0
16
.
0
>
BOOL_OR
(
Y
>
10
.
0
)
BOOL_AND
(
Y
>
10
.
0
)
MIN
(
Y
)
MAX
(
Y
)
>
---------------
-- --
---------------- ------ ------
>
TRUE
FALSE
4
.
0
16
.
0
>
rows
:
1
drop
view
s
;
...
...
This diff is collapsed.
Click to expand it.
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论