Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
f36f879f
提交
f36f879f
authored
5月 06, 2015
作者:
Thomas Mueller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
PostgreSQL compatibility: new syntax create index ... using ...
上级
cfb2cc37
显示空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
200 行增加
和
3 行删除
+200
-3
changelog.html
h2/src/docsrc/html/changelog.html
+2
-1
Parser.java
h2/src/main/org/h2/command/Parser.java
+20
-2
TestAll.java
h2/src/test/org/h2/test/TestAll.java
+2
-0
TestUsingIndex.java
h2/src/test/org/h2/test/db/TestUsingIndex.java
+176
-0
没有找到文件。
h2/src/docsrc/html/changelog.html
浏览文件 @
f36f879f
...
@@ -20,7 +20,8 @@ Change Log
...
@@ -20,7 +20,8 @@ Change Log
<h1>
Change Log
</h1>
<h1>
Change Log
</h1>
<h2>
Next Version (unreleased)
</h2>
<h2>
Next Version (unreleased)
</h2>
<ul><li>
There was a bug in DataType.convertToValue when reading a ResultSet from a ResultSet.
<ul><li>
PostgreSQL compatibility: new syntax "create index ... using ...".
</li><li>
There was a bug in DataType.convertToValue when reading a ResultSet from a ResultSet.
</li><li>
Pull request #116: Improved concurrency in the trace system.
</li><li>
Pull request #116: Improved concurrency in the trace system.
</li><li>
Issue 609: the spatial index did not support NULL.
</li><li>
Issue 609: the spatial index did not support NULL.
</li><li>
Granting a schema is now supported.
</li><li>
Granting a schema is now supported.
...
...
h2/src/main/org/h2/command/Parser.java
浏览文件 @
f36f879f
...
@@ -4199,8 +4199,6 @@ public class Parser {
...
@@ -4199,8 +4199,6 @@ public class Parser {
checkSchema
(
oldSchema
);
checkSchema
(
oldSchema
);
CreateIndex
command
=
new
CreateIndex
(
session
,
getSchema
());
CreateIndex
command
=
new
CreateIndex
(
session
,
getSchema
());
command
.
setIfNotExists
(
ifNotExists
);
command
.
setIfNotExists
(
ifNotExists
);
command
.
setHash
(
hash
);
command
.
setSpatial
(
spatial
);
command
.
setPrimaryKey
(
primaryKey
);
command
.
setPrimaryKey
(
primaryKey
);
command
.
setTableName
(
tableName
);
command
.
setTableName
(
tableName
);
command
.
setUnique
(
unique
);
command
.
setUnique
(
unique
);
...
@@ -4208,6 +4206,26 @@ public class Parser {
...
@@ -4208,6 +4206,26 @@ public class Parser {
command
.
setComment
(
readCommentIf
());
command
.
setComment
(
readCommentIf
());
read
(
"("
);
read
(
"("
);
command
.
setIndexColumns
(
parseIndexColumnList
());
command
.
setIndexColumns
(
parseIndexColumnList
());
if
(
readIf
(
"USING"
))
{
if
(
hash
)
{
throw
getSyntaxError
();
}
if
(
spatial
)
{
throw
getSyntaxError
();
}
if
(
readIf
(
"BTREE"
))
{
}
else
if
(
readIf
(
"RTREE"
))
{
spatial
=
true
;
}
else
if
(
readIf
(
"HASH"
))
{
hash
=
true
;
}
else
{
throw
getSyntaxError
();
}
}
command
.
setHash
(
hash
);
command
.
setSpatial
(
spatial
);
return
command
;
return
command
;
}
}
}
}
...
...
h2/src/test/org/h2/test/TestAll.java
浏览文件 @
f36f879f
...
@@ -70,6 +70,7 @@ import org.h2.test.db.TestTransaction;
...
@@ -70,6 +70,7 @@ import org.h2.test.db.TestTransaction;
import
org.h2.test.db.TestTriggersConstraints
;
import
org.h2.test.db.TestTriggersConstraints
;
import
org.h2.test.db.TestTwoPhaseCommit
;
import
org.h2.test.db.TestTwoPhaseCommit
;
import
org.h2.test.db.TestUpgrade
;
import
org.h2.test.db.TestUpgrade
;
import
org.h2.test.db.TestUsingIndex
;
import
org.h2.test.db.TestView
;
import
org.h2.test.db.TestView
;
import
org.h2.test.db.TestViewAlterTable
;
import
org.h2.test.db.TestViewAlterTable
;
import
org.h2.test.db.TestViewDropView
;
import
org.h2.test.db.TestViewDropView
;
...
@@ -831,6 +832,7 @@ kill -9 `jps -l | grep "org.h2.test." | cut -d " " -f 1`
...
@@ -831,6 +832,7 @@ kill -9 `jps -l | grep "org.h2.test." | cut -d " " -f 1`
addTest
(
new
TestStringUtils
());
addTest
(
new
TestStringUtils
());
addTest
(
new
TestTraceSystem
());
addTest
(
new
TestTraceSystem
());
addTest
(
new
TestUpgrade
());
addTest
(
new
TestUpgrade
());
addTest
(
new
TestUsingIndex
());
addTest
(
new
TestUtils
());
addTest
(
new
TestUtils
());
addTest
(
new
TestValue
());
addTest
(
new
TestValue
());
addTest
(
new
TestValueHashMap
());
addTest
(
new
TestValueHashMap
());
...
...
h2/src/test/org/h2/test/db/TestUsingIndex.java
0 → 100644
浏览文件 @
f36f879f
/*
* 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
*/
package
org
.
h2
.
test
.
db
;
import
java.sql.Connection
;
import
java.sql.ResultSet
;
import
java.sql.SQLException
;
import
java.sql.Statement
;
import
org.h2.test.TestBase
;
import
org.h2.value.DataType
;
/**
* Tests the "create index ... using" syntax.
*
* @author Erwan Bocher Atelier SIG, IRSTV FR CNRS 2488
*/
public
class
TestUsingIndex
extends
TestBase
{
private
Connection
conn
;
private
Statement
stat
;
/**
* Run just this test.
*
* @param a ignored
* @throws java.lang.Exception
*/
public
static
void
main
(
String
...
a
)
throws
Exception
{
TestBase
.
createCaller
().
init
().
test
();
}
@Override
public
void
test
()
throws
SQLException
{
deleteDb
(
"using_index"
);
testUsingBadSyntax
();
testUsingGoodSyntax
();
testHashIndex
();
testSpatialIndex
();
testBadSpatialSyntax
();
}
private
void
testHashIndex
()
throws
SQLException
{
conn
=
getConnection
(
"using_index"
);
stat
=
conn
.
createStatement
();
stat
.
execute
(
"create table test(id int)"
);
stat
.
execute
(
"create index idx_name on test(id) using hash"
);
stat
.
execute
(
"insert into test select x from system_range(1, 1000)"
);
ResultSet
rs
=
stat
.
executeQuery
(
"select * from test where id=100"
);
assertTrue
(
rs
.
next
());
assertFalse
(
rs
.
next
());
stat
.
execute
(
"delete from test where id=100"
);
rs
=
stat
.
executeQuery
(
"select * from test where id=100"
);
assertFalse
(
rs
.
next
());
rs
=
stat
.
executeQuery
(
"select min(id), max(id) from test"
);
assertTrue
(
rs
.
next
());
assertEquals
(
1
,
rs
.
getInt
(
1
));
assertEquals
(
1000
,
rs
.
getInt
(
2
));
stat
.
execute
(
"drop table test"
);
conn
.
close
();
deleteDb
(
"using_index"
);
}
private
void
testUsingBadSyntax
()
throws
SQLException
{
conn
=
getConnection
(
"using_index"
);
stat
=
conn
.
createStatement
();
stat
.
execute
(
"create table test(id int)"
);
assertFalse
(
isSupportedSyntax
(
stat
,
"create hash index idx_name_1 on test(id) using hash"
));
assertFalse
(
isSupportedSyntax
(
stat
,
"create hash index idx_name_2 on test(id) using btree"
));
assertFalse
(
isSupportedSyntax
(
stat
,
"create index idx_name_3 on test(id) using hashtree"
));
assertFalse
(
isSupportedSyntax
(
stat
,
"create unique hash index idx_name_4 on test(id) using hash"
));
assertFalse
(
isSupportedSyntax
(
stat
,
"create index idx_name_5 on test(id) using hash table"
));
conn
.
close
();
deleteDb
(
"using_index"
);
}
private
void
testUsingGoodSyntax
()
throws
SQLException
{
conn
=
getConnection
(
"using_index"
);
stat
=
conn
.
createStatement
();
stat
.
execute
(
"create table test(id int)"
);
assertTrue
(
isSupportedSyntax
(
stat
,
"create index idx_name_1 on test(id) using hash"
));
assertTrue
(
isSupportedSyntax
(
stat
,
"create index idx_name_2 on test(id) using btree"
));
assertTrue
(
isSupportedSyntax
(
stat
,
"create unique index idx_name_3 on test(id) using hash"
));
conn
.
close
();
deleteDb
(
"using_index"
);
}
/**
* Return if the syntax is supported otherwise false
*
* @param stat
* @param sql
* @return
*/
private
static
boolean
isSupportedSyntax
(
Statement
stat
,
String
sql
)
{
try
{
stat
.
execute
(
sql
);
return
true
;
}
catch
(
SQLException
ex
)
{
return
false
;
}
}
private
void
testSpatialIndex
()
throws
SQLException
{
if
(!
config
.
mvStore
&&
config
.
mvcc
)
{
return
;
}
if
(
config
.
memory
&&
config
.
mvcc
)
{
return
;
}
if
(
DataType
.
GEOMETRY_CLASS
!=
null
)
{
deleteDb
(
"spatial"
);
conn
=
getConnection
(
"spatial"
);
try
{
stat
=
conn
.
createStatement
();
stat
.
execute
(
"create table test"
+
"(id int primary key, poly geometry)"
);
stat
.
execute
(
"insert into test values(1, "
+
"'POLYGON ((1 1, 1 2, 2 2, 1 1))')"
);
stat
.
execute
(
"insert into test values(2,null)"
);
stat
.
execute
(
"insert into test values(3, "
+
"'POLYGON ((3 1, 3 2, 4 2, 3 1))')"
);
stat
.
execute
(
"insert into test values(4,null)"
);
stat
.
execute
(
"insert into test values(5, "
+
"'POLYGON ((1 3, 1 4, 2 4, 1 3))')"
);
stat
.
execute
(
"create index on test(poly) using rtree"
);
ResultSet
rs
=
stat
.
executeQuery
(
"select * from test "
+
"where poly && 'POINT (1.5 1.5)'::Geometry"
);
assertTrue
(
rs
.
next
());
assertEquals
(
1
,
rs
.
getInt
(
"id"
));
assertFalse
(
rs
.
next
());
rs
.
close
();
}
finally
{
// Close the database
conn
.
close
();
}
deleteDb
(
"spatial"
);
}
}
private
void
testBadSpatialSyntax
()
throws
SQLException
{
if
(!
config
.
mvStore
&&
config
.
mvcc
)
{
return
;
}
if
(
config
.
memory
&&
config
.
mvcc
)
{
return
;
}
if
(
DataType
.
GEOMETRY_CLASS
!=
null
)
{
deleteDb
(
"spatial"
);
conn
=
getConnection
(
"spatial"
);
try
{
stat
=
conn
.
createStatement
();
stat
.
execute
(
"create table test"
+
"(id int primary key, poly geometry)"
);
stat
.
execute
(
"insert into test values(1, "
+
"'POLYGON ((1 1, 1 2, 2 2, 1 1))')"
);
assertFalse
(
isSupportedSyntax
(
stat
,
"create spatial index on test(poly) using rtree"
));
}
finally
{
// Close the database
conn
.
close
();
}
deleteDb
(
"spatial"
);
}
}
}
\ No newline at end of file
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论