Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
c58cd967
提交
c58cd967
authored
10月 16, 2009
作者:
christian.peter.io
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Certain queries were not sorted if subselects were involved
上级
6bac611f
隐藏空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
57 行增加
和
3 行删除
+57
-3
changelog.html
h2/src/docsrc/html/changelog.html
+1
-0
Select.java
h2/src/main/org/h2/command/dml/Select.java
+4
-3
TableFilter.java
h2/src/main/org/h2/table/TableFilter.java
+20
-0
TestCases.java
h2/src/test/org/h2/test/db/TestCases.java
+32
-0
没有找到文件。
h2/src/docsrc/html/changelog.html
浏览文件 @
c58cd967
...
...
@@ -22,6 +22,7 @@ Change Log
The diagrams are HTML.
</li><li>
The documentation is no longer available in Japanese because the
translation was too much out of sync. Please use the Google translation instead.
</li><li>
Certain queries were not sorted if subselect queries were involved
</li></ul>
<h2>
Version 1.2.121 (2009-10-11)
</h2>
...
...
h2/src/main/org/h2/command/dml/Select.java
浏览文件 @
c58cd967
...
...
@@ -760,9 +760,10 @@ public class Select extends Query {
Index
current
=
topTableFilter
.
getIndex
();
if
(
index
!=
null
&&
(
current
.
getIndexType
().
isScan
()
||
current
==
index
))
{
topTableFilter
.
setIndex
(
index
);
if
(!
distinct
||
isDistinctQuery
)
{
// sort using index would not work correctly for distinct result sets
// because it would break too early when limit is used
if
((!
distinct
||
isDistinctQuery
)
&&
(!
topTableFilter
.
hasInComparisons
()))
{
// - sort using index would not work correctly for distinct result sets
// because it would break too early when limit is used
// - in(select ...) and in(1,2,3) indices are unsorted
sortUsingIndex
=
true
;
}
}
...
...
h2/src/main/org/h2/table/TableFilter.java
浏览文件 @
c58cd967
...
...
@@ -13,6 +13,7 @@ import org.h2.command.dml.Select;
import
org.h2.constant.SysProperties
;
import
org.h2.engine.Right
;
import
org.h2.engine.Session
;
import
org.h2.expression.Comparison
;
import
org.h2.expression.ConditionAndOr
;
import
org.h2.expression.Expression
;
import
org.h2.expression.ExpressionColumn
;
...
...
@@ -693,4 +694,23 @@ public class TableFilter implements ColumnResolver {
return
hashCode
;
}
/**
* Returns if there are in(...) comparisons involved
*
* @see Comparison.IN_LIST
* @see Comparison.IN_QUERY
*
* @return if there are in(...) comparisons involved
*/
public
boolean
hasInComparisons
()
{
for
(
int
i
=
0
;
i
<
indexConditions
.
size
();
i
++)
{
if
((
indexConditions
.
get
(
i
).
getCompareType
()
==
Comparison
.
IN_QUERY
)
||
(
indexConditions
.
get
(
i
).
getCompareType
()
==
Comparison
.
IN_LIST
))
{
return
true
;
}
}
return
false
;
}
}
h2/src/test/org/h2/test/db/TestCases.java
浏览文件 @
c58cd967
...
...
@@ -10,6 +10,7 @@ import java.io.File;
import
java.io.StringReader
;
import
java.sql.Connection
;
import
java.sql.Date
;
import
java.sql.DriverManager
;
import
java.sql.PreparedStatement
;
import
java.sql.ResultSet
;
import
java.sql.SQLException
;
...
...
@@ -35,6 +36,7 @@ public class TestCases extends TestBase {
}
public
void
test
()
throws
Exception
{
testOrderByWithSubselect
();
testInsertDeleteRollback
();
testLargeRollback
();
testConstraintAlterTable
();
...
...
@@ -880,4 +882,34 @@ public class TestCases extends TestBase {
c0
.
close
();
}
private
void
testOrderByWithSubselect
()
throws
SQLException
{
Connection
c
=
DriverManager
.
getConnection
(
"jdbc:h2:mem:testdb"
);
Statement
s
=
c
.
createStatement
();
s
.
execute
(
"create table master(id number primary key, name varchar2(30));"
);
s
.
execute
(
"create table detail(id number references master(id), location varchar2(30));"
);
s
.
execute
(
"Insert into master values(1,'a');"
);
s
.
execute
(
"Insert into master values(2,'b');"
);
s
.
execute
(
"Insert into master values(3,'c');"
);
s
.
execute
(
"commit;"
);
s
.
execute
(
"Insert into detail values(1,'a');"
);
s
.
execute
(
"Insert into detail values(2,'b');"
);
s
.
execute
(
"Insert into detail values(3,'c');"
);
s
.
execute
(
"commit;"
);
ResultSet
rs
=
s
.
executeQuery
(
"select master.id, master.name "
+
"from master "
+
"where master.id in (select detail.id from detail) "
+
"order by master.id"
);
assertTrue
(
rs
.
next
());
assertEquals
(
1
,
rs
.
getInt
(
1
));
assertTrue
(
rs
.
next
());
assertEquals
(
2
,
rs
.
getInt
(
1
));
assertTrue
(
rs
.
next
());
assertEquals
(
3
,
rs
.
getInt
(
1
));
c
.
close
();
}
}
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论