Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
7ec1dbee
提交
7ec1dbee
authored
10月 26, 2017
作者:
Noel Grandin
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Issue #643: H2 doesn't use index when I use IN and EQUAL in one query
上级
89ef8874
显示空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
32 行增加
和
3 行删除
+32
-3
changelog.html
h2/src/docsrc/html/changelog.html
+2
-0
IndexCursor.java
h2/src/main/org/h2/index/IndexCursor.java
+7
-3
TestScript.java
h2/src/test/org/h2/test/scripts/TestScript.java
+1
-0
query-optimisations.sql
h2/src/test/org/h2/test/scripts/query-optimisations.sql
+22
-0
没有找到文件。
h2/src/docsrc/html/changelog.html
浏览文件 @
7ec1dbee
...
...
@@ -21,6 +21,8 @@ Change Log
<h2>
Next Version (unreleased)
</h2>
<ul>
<li>
Issue #643: H2 doesn't use index when I use IN and EQUAL in one query
</li>
<li>
Reset transaction start timestamp on ROLLBACK
</li>
<li>
Issue #632: CREATE OR REPLACE VIEW creates incorrect columns names
...
...
h2/src/main/org/h2/index/IndexCursor.java
浏览文件 @
7ec1dbee
...
...
@@ -131,9 +131,9 @@ public class IndexCursor implements Cursor {
if
(
isIntersects
)
{
intersects
=
getSpatialSearchRow
(
intersects
,
columnId
,
v
);
}
if
(
isStart
||
isEnd
)
{
// an X=? condition will produce less rows than
// an X IN(..) condition
// An X=? condition will produce less rows than
// an X IN(..) condition, unless the X IN condition can use the index.
if
((
isStart
||
isEnd
)
&&
!
canUseIndexFor
(
inColumn
))
{
inColumn
=
null
;
inList
=
null
;
inResult
=
null
;
...
...
@@ -176,6 +176,10 @@ public class IndexCursor implements Cursor {
// only one IN(..) condition can be used at the same time
return
false
;
}
return
canUseIndexFor
(
column
);
}
private
boolean
canUseIndexFor
(
Column
column
)
{
// The first column of the index must match this column,
// or it must be a VIEW index (where the column is null).
// Multiple IN conditions with views are not supported, see
...
...
h2/src/test/org/h2/test/scripts/TestScript.java
浏览文件 @
7ec1dbee
...
...
@@ -80,6 +80,7 @@ public class TestScript extends TestBase {
}
reconnectOften
=
!
config
.
memory
&&
config
.
big
;
testScript
(
"testScript.sql"
);
testScript
(
"query-optimisations.sql"
);
testScript
(
"commands-dml-script.sql"
);
testScript
(
"commands-dml-create-view.sql"
);
for
(
String
s
:
new
String
[]
{
"array"
,
"bigint"
,
"binary"
,
"blob"
,
...
...
h2/src/test/org/h2/test/scripts/query-optimisations.sql
0 → 100644
浏览文件 @
7ec1dbee
-- Copyright 2004-2014 H2 Group. Multiple-Licensed under the MPL 2.0,
-- and the EPL 1.0 (http://h2database.com/html/license.html).
-- Initial Developer: H2 Group
--
create
table
person
(
firstname
varchar
,
lastname
varchar
);
>
ok
create
index
person_1
on
person
(
firstname
,
lastname
);
>
ok
insert
into
person
select
convert
(
x
,
varchar
)
as
firstname
,
(
convert
(
x
,
varchar
)
||
' last'
)
as
lastname
from
system_range
(
1
,
100
);
>
update
count
:
100
-- Issue #643: verify that when using an index, we use the IN part of the query, if that part of the query
-- can directly use the index.
--
explain
analyze
SELECT
*
FROM
person
WHERE
firstname
IN
(
'FirstName1'
,
'FirstName2'
)
AND
lastname
=
'LastName1'
;
>
PLAN
>
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
>
SELECT
PERSON
.
FIRSTNAME
,
PERSON
.
LASTNAME
FROM
PUBLIC
.
PERSON
/* PUBLIC.PERSON_1: FIRSTNAME IN('FirstName1', 'FirstName2') AND LASTNAME = 'LastName1' */
/* scanCount: 1 */
WHERE
(
FIRSTNAME
IN
(
'FirstName1'
,
'FirstName2'
))
AND
(
LASTNAME
=
'LastName1'
)
>
rows
:
1
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论