Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
a741e6d5
提交
a741e6d5
authored
9月 06, 2018
作者:
Evgenij Ryazanov
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Optimize ST_EXTENT
上级
de7f02e0
隐藏空白字符变更
内嵌
并排
正在显示
5 个修改的文件
包含
158 行增加
和
29 行删除
+158
-29
Aggregate.java
h2/src/main/org/h2/expression/aggregate/Aggregate.java
+2
-1
AggregateDataST_Extent.java
...n/org/h2/expression/aggregate/AggregateDataST_Extent.java
+0
-28
MVSpatialIndex.java
h2/src/main/org/h2/mvstore/db/MVSpatialIndex.java
+101
-0
st_extent.sql
...est/org/h2/test/scripts/functions/aggregate/st_extent.sql
+53
-0
dictionary.txt
h2/src/tools/org/h2/build/doc/dictionary.txt
+2
-0
没有找到文件。
h2/src/main/org/h2/expression/aggregate/Aggregate.java
浏览文件 @
a741e6d5
...
...
@@ -19,6 +19,7 @@ import org.h2.expression.ExpressionVisitor;
import
org.h2.index.Cursor
;
import
org.h2.index.Index
;
import
org.h2.message.DbException
;
import
org.h2.mvstore.db.MVSpatialIndex
;
import
org.h2.result.SearchRow
;
import
org.h2.result.SortOrder
;
import
org.h2.table.Column
;
...
...
@@ -378,7 +379,7 @@ public class Aggregate extends Expression {
case
MEDIAN:
return
AggregateDataMedian
.
getResultFromIndex
(
session
,
on
,
dataType
);
case
ST_EXTENT:
return
AggregateDataST_Extent
.
getResultFromIndex
(
session
,
on
);
return
((
MVSpatialIndex
)
AggregateDataST_Extent
.
getGeometryColumnIndex
(
on
)).
getBounds
(
sessi
on
);
default
:
DbException
.
throwInternalError
(
"type="
+
type
);
}
...
...
h2/src/main/org/h2/expression/aggregate/AggregateDataST_Extent.java
浏览文件 @
a741e6d5
...
...
@@ -8,12 +8,10 @@ package org.h2.expression.aggregate;
import
java.util.ArrayList
;
import
org.h2.engine.Database
;
import
org.h2.engine.Session
;
import
org.h2.expression.Expression
;
import
org.h2.expression.ExpressionColumn
;
import
org.h2.index.Index
;
import
org.h2.mvstore.db.MVSpatialIndex
;
import
org.h2.mvstore.rtree.SpatialKey
;
import
org.h2.table.Column
;
import
org.h2.table.TableFilter
;
import
org.h2.value.Value
;
...
...
@@ -59,32 +57,6 @@ class AggregateDataST_Extent extends AggregateData {
return
null
;
}
/**
* Get the result from the index.
*
* @param session
* the session
* @param on
* the expression
* @return the result
*/
static
Value
getResultFromIndex
(
Session
session
,
Expression
on
)
{
MVSpatialIndex
index
=
(
MVSpatialIndex
)
getGeometryColumnIndex
(
on
);
MVSpatialIndex
.
MVStoreCursor
cursor
=
(
MVSpatialIndex
.
MVStoreCursor
)
index
.
find
(
session
,
null
,
null
);
Envelope
envelope
=
new
Envelope
();
while
(
cursor
.
next
())
{
SpatialKey
key
=
cursor
.
getKey
();
if
(!
key
.
isNull
())
{
envelope
.
expandToInclude
(
key
.
min
(
0
),
key
.
min
(
1
));
envelope
.
expandToInclude
(
key
.
max
(
0
),
key
.
max
(
1
));
}
}
if
(
envelope
.
isNull
())
{
return
ValueNull
.
INSTANCE
;
}
return
ValueGeometry
.
getFromGeometry
(
new
GeometryFactory
().
toGeometry
(
envelope
));
}
@Override
void
add
(
Database
database
,
int
dataType
,
boolean
distinct
,
Value
v
)
{
if
(
v
==
ValueNull
.
INSTANCE
)
{
...
...
h2/src/main/org/h2/mvstore/db/MVSpatialIndex.java
浏览文件 @
a741e6d5
...
...
@@ -17,6 +17,7 @@ import org.h2.index.IndexType;
import
org.h2.index.SpatialIndex
;
import
org.h2.index.SpatialTreeIndex
;
import
org.h2.message.DbException
;
import
org.h2.mvstore.Page
;
import
org.h2.mvstore.rtree.MVRTreeMap
;
import
org.h2.mvstore.rtree.MVRTreeMap.RTreeCursor
;
import
org.h2.mvstore.rtree.SpatialKey
;
...
...
@@ -33,6 +34,7 @@ import org.h2.value.ValueGeometry;
import
org.h2.value.ValueLong
;
import
org.h2.value.ValueNull
;
import
org.locationtech.jts.geom.Envelope
;
import
org.locationtech.jts.geom.GeometryFactory
;
/**
* This is an index based on a MVRTreeMap.
...
...
@@ -217,6 +219,21 @@ public class MVSpatialIndex extends BaseIndex implements SpatialIndex, MVIndex {
return
new
MVStoreCursor
(
session
,
it
,
mvTable
);
}
/**
* Returns the minimum bounding box that encloses all keys.
*
* @param session the session
* @return the minimum bounding box that encloses all keys, or null
*/
public
Value
getBounds
(
Session
session
)
{
FindBoundsCursor
cursor
=
new
FindBoundsCursor
(
spatialMap
.
getRootPage
(),
new
SpatialKey
(
0
),
session
,
getMap
(
session
),
columnIds
[
0
]);
while
(
cursor
.
hasNext
())
{
cursor
.
next
();
}
return
cursor
.
getBounds
();
}
private
SpatialKey
getKey
(
SearchRow
row
)
{
Value
v
=
row
.
getValue
(
columnIds
[
0
]);
if
(
v
==
ValueNull
.
INSTANCE
)
{
...
...
@@ -381,5 +398,89 @@ public class MVSpatialIndex extends BaseIndex implements SpatialIndex, MVIndex {
}
}
/**
* A cursor for getBounds() method.
*/
private
final
class
FindBoundsCursor
extends
RTreeCursor
{
private
final
Session
session
;
private
final
TransactionMap
<
SpatialKey
,
Value
>
map
;
private
final
int
columnId
;
private
boolean
hasBounds
;
private
float
bminxf
,
bmaxxf
,
bminyf
,
bmaxyf
;
private
double
bminxd
,
bmaxxd
,
bminyd
,
bmaxyd
;
FindBoundsCursor
(
Page
root
,
SpatialKey
filter
,
Session
session
,
TransactionMap
<
SpatialKey
,
Value
>
map
,
int
columnId
)
{
super
(
root
,
filter
);
this
.
session
=
session
;
this
.
map
=
map
;
this
.
columnId
=
columnId
;
}
@Override
protected
boolean
check
(
boolean
leaf
,
SpatialKey
key
,
SpatialKey
test
)
{
float
minxf
=
key
.
min
(
0
),
maxxf
=
key
.
max
(
0
),
minyf
=
key
.
min
(
1
),
maxyf
=
key
.
max
(
1
);
if
(
leaf
)
{
if
(
hasBounds
)
{
if
((
minxf
<=
bminxf
||
maxxf
>=
bmaxxf
||
minyf
<=
bminyf
||
maxyf
>=
bmaxyf
)
&&
map
.
containsKey
(
key
))
{
Envelope
env
=
((
ValueGeometry
)
mvTable
.
getRow
(
session
,
key
.
getId
()).
getValue
(
columnId
))
.
getEnvelopeNoCopy
();
double
minxd
=
env
.
getMinX
(),
maxxd
=
env
.
getMaxX
(),
minyd
=
env
.
getMinY
(),
maxyd
=
env
.
getMaxY
();
if
(
minxd
<
bminxd
)
{
bminxf
=
minxf
;
bminxd
=
minxd
;
}
if
(
maxxd
>
bmaxxd
)
{
bmaxxf
=
maxxf
;
bmaxxd
=
maxxd
;
}
if
(
minyd
<
bminyd
)
{
bminyf
=
minyf
;
bminyd
=
minyd
;
}
if
(
maxyd
>
bmaxyd
)
{
bmaxyf
=
maxyf
;
bmaxyd
=
maxyd
;
}
}
}
else
if
(
map
.
containsKey
(
key
))
{
hasBounds
=
true
;
Envelope
env
=
((
ValueGeometry
)
mvTable
.
getRow
(
session
,
key
.
getId
()).
getValue
(
columnId
))
.
getEnvelopeNoCopy
();
bminxf
=
minxf
;
bminxd
=
env
.
getMinX
();
bmaxxf
=
maxxf
;
bmaxxd
=
env
.
getMaxX
();
bminyf
=
minyf
;
bminyd
=
env
.
getMinY
();
bmaxyf
=
maxyf
;
bmaxyd
=
env
.
getMaxY
();
}
}
else
if
(
hasBounds
)
{
if
(
minxf
<=
bminxf
||
maxxf
>=
bmaxxf
||
minyf
<=
bminyf
||
maxyf
>=
bmaxyf
)
{
return
true
;
}
}
else
{
return
true
;
}
return
false
;
}
Value
getBounds
()
{
return
hasBounds
?
ValueGeometry
.
getFromGeometry
(
new
GeometryFactory
().
toGeometry
(
new
Envelope
(
bminxd
,
bmaxxd
,
bminyd
,
bmaxyd
)))
:
ValueNull
.
INSTANCE
;
}
}
}
h2/src/test/org/h2/test/scripts/functions/aggregate/st_extent.sql
浏览文件 @
a741e6d5
...
...
@@ -28,22 +28,75 @@ SELECT ST_EXTENT(V), ST_EXTENT(V) FILTER (WHERE V <> 'POINT(3 1)') FILTERED1,
CREATE
SPATIAL
INDEX
IDX
ON
TEST
(
V
);
>
ok
-- Without index
SELECT
ST_EXTENT
(
N
)
FROM
(
SELECT
V
AS
N
FROM
TEST
);
>>
POLYGON
((
1
1
,
1
2
,
3
2
,
3
1
,
1
1
))
-- With index
SELECT
ST_EXTENT
(
V
)
FROM
TEST
;
>>
POLYGON
((
1
1
,
1
2
,
3
2
,
3
1
,
1
1
))
-- Without index
SELECT
ST_EXTENT
(
V
)
FILTER
(
WHERE
V
<>
'POINT(3 1)'
)
FILTERED
FROM
TEST
;
>>
LINESTRING
(
1
1
,
1
2
)
-- Without index
SELECT
ST_EXTENT
(
V
)
FROM
TEST
WHERE
V
<>
'POINT(3 1)'
;
>>
LINESTRING
(
1
1
,
1
2
)
INSERT
INTO
TEST
VALUES
(
'POINT(-1.0000000001 1)'
);
>
update
count
:
1
-- Without index
SELECT
ST_EXTENT
(
N
)
FROM
(
SELECT
V
AS
N
FROM
TEST
);
>>
POLYGON
((
-
1
.
0000000001
1
,
-
1
.
0000000001
2
,
3
2
,
3
1
,
-
1
.
0000000001
1
))
-- With index
SELECT
ST_EXTENT
(
V
)
FROM
TEST
;
>>
POLYGON
((
-
1
.
0000000001
1
,
-
1
.
0000000001
2
,
3
2
,
3
1
,
-
1
.
0000000001
1
))
TRUNCATE
TABLE
TEST
;
>
ok
-- Without index
SELECT
ST_EXTENT
(
N
)
FROM
(
SELECT
V
AS
N
FROM
TEST
);
>>
null
-- With index
SELECT
ST_EXTENT
(
V
)
FROM
TEST
;
>>
null
SELECT
RAND
(
1000
)
*
0
;
>>
0
.
0
INSERT
INTO
TEST
SELECT
CAST
(
'POINT('
||
CAST
(
RAND
()
*
100000
AS
INT
)
||
' '
||
CAST
(
RAND
()
*
100000
AS
INT
)
||
')'
AS
GEOMETRY
)
FROM
SYSTEM_RANGE
(
1
,
1000
);
>
update
count
:
1000
-- Without index
SELECT
ST_EXTENT
(
N
)
FROM
(
SELECT
V
AS
N
FROM
TEST
);
>>
POLYGON
((
68
78
,
68
99951
,
99903
99951
,
99903
78
,
68
78
))
-- With index
SELECT
ST_EXTENT
(
V
)
FROM
TEST
;
>>
POLYGON
((
68
78
,
68
99951
,
99903
99951
,
99903
78
,
68
78
))
TRUNCATE
TABLE
TEST
;
>
ok
SELECT
RAND
(
1000
)
*
0
;
>>
0
.
0
INSERT
INTO
TEST
SELECT
CAST
(
'POINT('
||
(
CAST
(
RAND
()
*
100000
AS
INT
)
*
0
.
000000001
+
1
)
||
' '
||
(
CAST
(
RAND
()
*
100000
AS
INT
)
*
0
.
000000001
+
1
)
||
')'
AS
GEOMETRY
)
FROM
SYSTEM_RANGE
(
1
,
1000
);
>
update
count
:
1000
-- Without index
SELECT
ST_EXTENT
(
N
)
FROM
(
SELECT
V
AS
N
FROM
TEST
);
>>
POLYGON
((
1
.
000000068
1
.
000000078
,
1
.
000000068
1
.
000099951
,
1
.
000099903
1
.
000099951
,
1
.
000099903
1
.
000000078
,
1
.
000000068
1
.
000000078
))
-- With index
SELECT
ST_EXTENT
(
V
)
FROM
TEST
;
>>
POLYGON
((
1
.
000000068
1
.
000000078
,
1
.
000000068
1
.
000099951
,
1
.
000099903
1
.
000099951
,
1
.
000099903
1
.
000000078
,
1
.
000000068
1
.
000000078
))
DROP
TABLE
TEST
;
>
ok
h2/src/tools/org/h2/build/doc/dictionary.txt
浏览文件 @
a741e6d5
...
...
@@ -790,3 +790,5 @@ tied ties
launched unavailable smallmoney erroneously multiplier newid pan streamline unmap preview unexpectedly presumably
converging smth rng curs casts unmapping unmapper
immediate hhmmss scheduled hhmm prematurely postponed arranges subexpression subexpressions encloses plane
minxf maxxf minyf maxyf bminxf bmaxxf bminyf bmaxyf
minxd maxxd minyd maxyd bminxd bmaxxd bminyd bmaxyd
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论