Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
6ef85054
提交
6ef85054
authored
6月 17, 2016
作者:
Noel Grandin
提交者:
GitHub
6月 17, 2016
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #267 from nicolas-f/fix/spatial_index_update_issue266
Fix issue, update key on MVMAP update about #266
上级
705718b2
ca4e29e7
显示空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
129 行增加
和
8 行删除
+129
-8
SpatialTreeIndex.java
h2/src/main/org/h2/index/SpatialTreeIndex.java
+6
-7
MVRTreeMap.java
h2/src/main/org/h2/mvstore/rtree/MVRTreeMap.java
+1
-0
TestSpatial.java
h2/src/test/org/h2/test/db/TestSpatial.java
+122
-1
没有找到文件。
h2/src/main/org/h2/index/SpatialTreeIndex.java
浏览文件 @
6ef85054
...
@@ -186,19 +186,18 @@ public class SpatialTreeIndex extends BaseIndex implements SpatialIndex {
...
@@ -186,19 +186,18 @@ public class SpatialTreeIndex extends BaseIndex implements SpatialIndex {
* @return Index cost hint
* @return Index cost hint
*/
*/
public
static
long
getCostRangeIndex
(
int
[]
masks
,
long
rowCount
,
Column
[]
columns
)
{
public
static
long
getCostRangeIndex
(
int
[]
masks
,
long
rowCount
,
Column
[]
columns
)
{
rowCount
+=
Constants
.
COST_ROW_OFFSET
;
// Never use spatial tree index without spatial filter
long
cost
=
rowCount
;
if
(
columns
.
length
==
0
)
{
if
(
masks
==
null
)
{
return
Long
.
MAX_VALUE
;
return
cost
;
}
}
for
(
Column
column
:
columns
)
{
for
(
Column
column
:
columns
)
{
int
index
=
column
.
getColumnId
();
int
index
=
column
.
getColumnId
();
int
mask
=
masks
[
index
];
int
mask
=
masks
[
index
];
if
((
mask
&
IndexCondition
.
SPATIAL_INTERSECTS
)
!=
0
)
{
if
((
mask
&
IndexCondition
.
SPATIAL_INTERSECTS
)
!=
IndexCondition
.
SPATIAL_INTERSECTS
)
{
cost
=
3
+
rowCount
/
4
;
return
Long
.
MAX_VALUE
;
}
}
}
}
return
10
*
cost
;
return
2
;
}
}
@Override
@Override
...
...
h2/src/main/org/h2/mvstore/rtree/MVRTreeMap.java
浏览文件 @
6ef85054
...
@@ -237,6 +237,7 @@ public class MVRTreeMap<V> extends MVMap<SpatialKey, V> {
...
@@ -237,6 +237,7 @@ public class MVRTreeMap<V> extends MVMap<SpatialKey, V> {
if
(
p
.
isLeaf
())
{
if
(
p
.
isLeaf
())
{
for
(
int
i
=
0
;
i
<
p
.
getKeyCount
();
i
++)
{
for
(
int
i
=
0
;
i
<
p
.
getKeyCount
();
i
++)
{
if
(
keyType
.
equals
(
p
.
getKey
(
i
),
key
))
{
if
(
keyType
.
equals
(
p
.
getKey
(
i
),
key
))
{
p
.
setKey
(
i
,
key
);
return
p
.
setValue
(
i
,
value
);
return
p
.
setValue
(
i
,
value
);
}
}
}
}
...
...
h2/src/test/org/h2/test/db/TestSpatial.java
浏览文件 @
6ef85054
...
@@ -93,6 +93,8 @@ public class TestSpatial extends TestBase {
...
@@ -93,6 +93,8 @@ public class TestSpatial extends TestBase {
testNullableGeometryDelete
();
testNullableGeometryDelete
();
testNullableGeometryInsert
();
testNullableGeometryInsert
();
testNullableGeometryUpdate
();
testNullableGeometryUpdate
();
testIndexUpdateNullGeometry
();
testInsertNull
();
}
}
private
void
testBug1
()
throws
SQLException
{
private
void
testBug1
()
throws
SQLException
{
...
@@ -879,7 +881,8 @@ public class TestSpatial extends TestBase {
...
@@ -879,7 +881,8 @@ public class TestSpatial extends TestBase {
stat
.
execute
(
"create spatial index spatial on test(the_geom)"
);
stat
.
execute
(
"create spatial index spatial on test(the_geom)"
);
ResultSet
rs
=
stat
.
executeQuery
(
"explain select * from test where _ROWID_ = 5"
);
ResultSet
rs
=
stat
.
executeQuery
(
"explain select * from test where _ROWID_ = 5"
);
assertTrue
(
rs
.
next
());
assertTrue
(
rs
.
next
());
assertContains
(
rs
.
getString
(
1
),
"/* PUBLIC.SPATIAL: _ROWID_ = 5 */"
);
assertFalse
(
rs
.
getString
(
1
).
contains
(
"/* PUBLIC.SPATIAL: _ROWID_ = "
+
"5 */"
));
}
finally
{
}
finally
{
// Close the database
// Close the database
conn
.
close
();
conn
.
close
();
...
@@ -1076,4 +1079,122 @@ public class TestSpatial extends TestBase {
...
@@ -1076,4 +1079,122 @@ public class TestSpatial extends TestBase {
deleteDb
(
"spatial"
);
deleteDb
(
"spatial"
);
}
}
public
void
testIndexUpdateNullGeometry
()
throws
SQLException
{
deleteDb
(
"spatial"
);
Connection
conn
=
getConnection
(
URL
);
Statement
stat
=
conn
.
createStatement
();
stat
.
execute
(
"drop table if exists DUMMY_11;"
);
stat
.
execute
(
"CREATE TABLE PUBLIC.DUMMY_11 (fid serial, GEOM GEOMETRY);"
);
stat
.
execute
(
"CREATE SPATIAL INDEX PUBLIC_DUMMY_11_SPATIAL_INDEX on"
+
" PUBLIC.DUMMY_11(GEOM);"
);
stat
.
execute
(
"insert into PUBLIC.DUMMY_11(geom) values(null);"
);
stat
.
execute
(
"update PUBLIC.DUMMY_11 set geom ="
+
" 'POLYGON ((1 1, 5 1, 5 5, 1 5, 1 1))';"
);
ResultSet
rs
=
stat
.
executeQuery
(
"select fid, GEOM from DUMMY_11 "
+
"where GEOM && "
+
"'POLYGON"
+
"((1 1,5 1,5 5,1 5,1 1))';"
);
try
{
assertTrue
(
rs
.
next
());
assertEquals
(
"POLYGON ((1 1, 5 1, 5 5, 1 5, 1 1))"
,
rs
.
getString
(
2
));
}
finally
{
rs
.
close
();
}
// Update again the geometry elsewhere
stat
.
execute
(
"update PUBLIC.DUMMY_11 set geom ="
+
" 'POLYGON ((10 10, 50 10, 50 50, 10 50, 10 10))';"
);
rs
=
stat
.
executeQuery
(
"select fid, GEOM from DUMMY_11 "
+
"where GEOM && "
+
"'POLYGON ((10 10, 50 10, 50 50, 10 50, 10 10))';"
);
try
{
assertTrue
(
rs
.
next
());
assertEquals
(
"POLYGON ((10 10, 50 10, 50 50, 10 50, 10 10))"
,
rs
.
getString
(
2
));
}
finally
{
rs
.
close
();
}
conn
.
close
();
deleteDb
(
"spatial"
);
}
public
void
testInsertNull
()
throws
SQLException
{
deleteDb
(
"spatial"
);
Connection
conn
=
getConnection
(
URL
);
Statement
stat
=
conn
.
createStatement
();
stat
.
execute
(
"\n"
+
"drop table if exists PUBLIC.DUMMY_12;\n"
+
"CREATE TABLE PUBLIC.DUMMY_12 (\n"
+
" \"fid\" serial,\n"
+
" Z_ID INTEGER,\n"
+
" GEOM GEOMETRY,\n"
+
" CONSTRAINT CONSTRAINT_DUMMY_12 PRIMARY KEY (\"fid\")\n"
+
");\n"
+
"CREATE INDEX PRIMARY_KEY_DUMMY_12 ON PUBLIC.DUMMY_12 (\"fid\");\n"
+
"CREATE spatial INDEX PUBLIC_DUMMY_12_SPATIAL_INDEX_ ON PUBLIC.DUMMY_12 (GEOM);\n"
+
"INSERT INTO PUBLIC.DUMMY_12 (\"fid\",Z_ID,GEOM) VALUES (123,3125163,NULL);\n"
+
"INSERT INTO PUBLIC.DUMMY_12 (\"fid\",Z_ID,GEOM) VALUES (124,3125164,NULL);\n"
+
"INSERT INTO PUBLIC.DUMMY_12 (\"fid\",Z_ID,GEOM) VALUES (125,3125173,NULL);\n"
+
"INSERT INTO PUBLIC.DUMMY_12 (\"fid\",Z_ID,GEOM) VALUES (126,3125174,NULL);\n"
+
"INSERT INTO PUBLIC.DUMMY_12 (\"fid\",Z_ID,GEOM) VALUES (127,3125175,NULL);\n"
+
"INSERT INTO PUBLIC.DUMMY_12 (\"fid\",Z_ID,GEOM) VALUES (128,3125176,NULL);\n"
+
"INSERT INTO PUBLIC.DUMMY_12 (\"fid\",Z_ID,GEOM) VALUES (129,3125177,NULL);\n"
+
"INSERT INTO PUBLIC.DUMMY_12 (\"fid\",Z_ID,GEOM) VALUES (130,3125178,NULL);\n"
+
"INSERT INTO PUBLIC.DUMMY_12 (\"fid\",Z_ID,GEOM) VALUES (131,3125179,NULL);\n"
+
"INSERT INTO PUBLIC.DUMMY_12 (\"fid\",Z_ID,GEOM) VALUES (132,3125180,NULL);\n"
+
"INSERT INTO PUBLIC.DUMMY_12 (\"fid\",Z_ID,GEOM) VALUES (133,3125335,NULL);\n"
+
"INSERT INTO PUBLIC.DUMMY_12 (\"fid\",Z_ID,GEOM) VALUES (134,3125336,NULL);\n"
+
"INSERT INTO PUBLIC.DUMMY_12 (\"fid\",Z_ID,GEOM) VALUES (135,3125165,NULL);\n"
+
"INSERT INTO PUBLIC.DUMMY_12 (\"fid\",Z_ID,GEOM) VALUES (136,3125337,NULL);\n"
+
"INSERT INTO PUBLIC.DUMMY_12 (\"fid\",Z_ID,GEOM) VALUES (137,3125338,NULL);\n"
+
"INSERT INTO PUBLIC.DUMMY_12 (\"fid\",Z_ID,GEOM) VALUES (138,3125339,NULL);\n"
+
"INSERT INTO PUBLIC.DUMMY_12 (\"fid\",Z_ID,GEOM) VALUES (139,3125340,NULL);\n"
+
"INSERT INTO PUBLIC.DUMMY_12 (\"fid\",Z_ID,GEOM) VALUES (140,3125341,NULL);\n"
+
"INSERT INTO PUBLIC.DUMMY_12 (\"fid\",Z_ID,GEOM) VALUES (141,3125342,NULL);\n"
+
"INSERT INTO PUBLIC.DUMMY_12 (\"fid\",Z_ID,GEOM) VALUES (142,3125343,NULL);\n"
+
"INSERT INTO PUBLIC.DUMMY_12 (\"fid\",Z_ID,GEOM) VALUES (143,3125344,NULL);\n"
+
"INSERT INTO PUBLIC.DUMMY_12 (\"fid\",Z_ID,GEOM) VALUES (144,3125345,NULL);\n"
+
"INSERT INTO PUBLIC.DUMMY_12 (\"fid\",Z_ID,GEOM) VALUES (145,3125346,NULL);\n"
+
"INSERT INTO PUBLIC.DUMMY_12 (\"fid\",Z_ID,GEOM) VALUES (146,3125166,NULL);\n"
+
"INSERT INTO PUBLIC.DUMMY_12 (\"fid\",Z_ID,GEOM) VALUES (147,3125347,NULL);\n"
+
"INSERT INTO PUBLIC.DUMMY_12 (\"fid\",Z_ID,GEOM) VALUES (148,3125348,NULL);\n"
+
"INSERT INTO PUBLIC.DUMMY_12 (\"fid\",Z_ID,GEOM) VALUES (149,3125349,NULL);\n"
+
"INSERT INTO PUBLIC.DUMMY_12 (\"fid\",Z_ID,GEOM) VALUES (150,3125350,NULL);\n"
+
"INSERT INTO PUBLIC.DUMMY_12 (\"fid\",Z_ID,GEOM) VALUES (151,3125351,NULL);\n"
+
"INSERT INTO PUBLIC.DUMMY_12 (\"fid\",Z_ID,GEOM) VALUES (152,3125352,NULL);\n"
+
"INSERT INTO PUBLIC.DUMMY_12 (\"fid\",Z_ID,GEOM) VALUES (153,3125353,NULL);\n"
+
"INSERT INTO PUBLIC.DUMMY_12 (\"fid\",Z_ID,GEOM) VALUES (154,3125354,NULL);\n"
+
"INSERT INTO PUBLIC.DUMMY_12 (\"fid\",Z_ID,GEOM) VALUES (155,3125355,NULL);\n"
+
"INSERT INTO PUBLIC.DUMMY_12 (\"fid\",Z_ID,GEOM) VALUES (156,3125356,NULL);\n"
+
"INSERT INTO PUBLIC.DUMMY_12 (\"fid\",Z_ID,GEOM) VALUES (157,3125167,NULL);\n"
+
"INSERT INTO PUBLIC.DUMMY_12 (\"fid\",Z_ID,GEOM) VALUES (158,3125357,NULL);\n"
+
"INSERT INTO PUBLIC.DUMMY_12 (\"fid\",Z_ID,GEOM) VALUES (159,3125358,NULL);\n"
+
"INSERT INTO PUBLIC.DUMMY_12 (\"fid\",Z_ID,GEOM) VALUES (160,3125359,NULL);\n"
+
"INSERT INTO PUBLIC.DUMMY_12 (\"fid\",Z_ID,GEOM) VALUES (161,3125360,NULL);\n"
+
"INSERT INTO PUBLIC.DUMMY_12 (\"fid\",Z_ID,GEOM) VALUES (162,3125361,NULL);\n"
+
"INSERT INTO PUBLIC.DUMMY_12 (\"fid\",Z_ID,GEOM) VALUES (163,3125362,NULL);\n"
+
"INSERT INTO PUBLIC.DUMMY_12 (\"fid\",Z_ID,GEOM) VALUES (164,3125363,NULL);\n"
+
"INSERT INTO PUBLIC.DUMMY_12 (\"fid\",Z_ID,GEOM) VALUES (165,3125364,NULL);\n"
+
"INSERT INTO PUBLIC.DUMMY_12 (\"fid\",Z_ID,GEOM) VALUES (166,3125365,NULL);\n"
+
"INSERT INTO PUBLIC.DUMMY_12 (\"fid\",Z_ID,GEOM) VALUES (167,3125366,NULL);\n"
+
"INSERT INTO PUBLIC.DUMMY_12 (\"fid\",Z_ID,GEOM) VALUES (168,3125168,NULL);\n"
+
"INSERT INTO PUBLIC.DUMMY_12 (\"fid\",Z_ID,GEOM) VALUES (169,3125367,NULL);\n"
+
"INSERT INTO PUBLIC.DUMMY_12 (\"fid\",Z_ID,GEOM) VALUES (170,3125368,NULL);\n"
+
"INSERT INTO PUBLIC.DUMMY_12 (\"fid\",Z_ID,GEOM) VALUES (171,3125369,NULL);\n"
+
"INSERT INTO PUBLIC.DUMMY_12 (\"fid\",Z_ID,GEOM) VALUES (172,3125370,NULL);\n"
+
"INSERT INTO PUBLIC.DUMMY_12 (\"fid\",Z_ID,GEOM) VALUES (173,3125169,NULL);\n"
+
"INSERT INTO PUBLIC.DUMMY_12 (\"fid\",Z_ID,GEOM) VALUES (174,3125170,NULL);\n"
+
"INSERT INTO PUBLIC.DUMMY_12 (\"fid\",Z_ID,GEOM) VALUES (175,3125171,NULL);\n"
+
"INSERT INTO PUBLIC.DUMMY_12 (\"fid\",Z_ID,GEOM) VALUES (176,3125172,NULL);\n"
+
"INSERT INTO PUBLIC.DUMMY_12 (\"fid\",Z_ID,GEOM) VALUES (177,-2,NULL);\n"
+
"INSERT INTO PUBLIC.DUMMY_12 (\"fid\",Z_ID,GEOM) VALUES (178,-1,NULL);\n"
+
"INSERT INTO PUBLIC.DUMMY_12 (\"fid\",Z_ID,GEOM) VALUES (179,"
+
"-1,NULL);"
);
ResultSet
rs
=
stat
.
executeQuery
(
"select * from DUMMY_12"
);
try
{
assertTrue
(
rs
.
next
());
}
finally
{
rs
.
close
();
}
}
}
}
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论