Skip to content

Commit 1e86a09

Browse files
authored
docs: spatial index add reculster notes (#3362)
1 parent c4a4108 commit 1e86a09

4 files changed

Lines changed: 25 additions & 10 deletions

File tree

docs/cn/sql-reference/10-sql-commands/00-ddl/07-spatial-index/create-spatial-index.md

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ CREATE [ OR REPLACE ] SPATIAL INDEX [IF NOT EXISTS] <index>
2525
- 空间索引仅支持 Fuse 表。
2626
- 空间索引仅支持 `GEOMETRY` 列,不支持 `GEOGRAPHY` 列。
2727
- 一个空间索引定义中可以包含多个列,这些列都必须是 `GEOMETRY` 类型。
28+
- 为了获得更好的 pruning 效果,建议结合 `CLUSTER BY``ST_HILBERT` 对地理空间数据做物理聚簇,让空间上接近的对象更有机会被写入同一个 block。
2829

2930
## 示例
3031

@@ -35,7 +36,9 @@ CREATE TABLE stores (
3536
store_id INT,
3637
store_name STRING,
3738
location GEOMETRY
38-
) ENGINE = FUSE;
39+
) CLUSTER BY (
40+
ST_HILBERT(location, [-180, -90, 180, 90])
41+
);
3942
```
4043

4144
`location` 列上创建空间索引:
@@ -57,18 +60,20 @@ SHOW CREATE TABLE stores;
5760
│ │ store_name VARCHAR NULL, │
5861
│ │ location GEOMETRY NULL, │
5962
│ │ SYNC SPATIAL INDEX stores_location_idx (location) │
60-
│ │ ) ENGINE=FUSE
63+
│ │ ) ENGINE=FUSE CLUSTER BY linear(st_hilbert(location, [-180, -90, 180, 90]))
6164
└──────────────────────────────────────────────────────────────────────────────────────────────┘
6265
```
6366

64-
插入一些用于空间过滤的示例数据:
67+
插入一些用于空间过滤的示例数据,并执行 RECLUSTER 命令
6568

6669
```sql
6770
INSERT INTO stores VALUES
6871
(1, 'Starbucks', TO_GEOMETRY('POINT(10 10)')),
6972
(2, 'Costa', TO_GEOMETRY('POINT(11 11)')),
7073
(3, 'Gong Cha', TO_GEOMETRY('POINT(20 20)')),
7174
(4, 'Dunkin', TO_GEOMETRY('POINT(-10 -10)'));
75+
76+
ALTER TABLE stores RECLUSTER FINAL;
7277
```
7378

7479
### 使用 `ST_WITHIN``ST_INTERSECTS``ST_CONTAINS` 过滤
@@ -132,7 +137,9 @@ CREATE TABLE districts (
132137
district_id INT,
133138
district_name STRING,
134139
geom GEOMETRY
135-
) ENGINE = FUSE;
140+
) CLUSTER BY (
141+
ST_HILBERT(geom, [-180, -90, 180, 90])
142+
);
136143

137144
INSERT INTO districts VALUES
138145
(1, 'Central', TO_GEOMETRY('POLYGON((8 8, 8 13, 13 13, 13 8, 8 8))')),

docs/cn/sql-reference/10-sql-commands/00-ddl/17-dictionary/show-dictionaries.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,5 +65,5 @@ SHOW DICTIONARIES;
6565
├──────────┼────────────┼───────────────┼──────────────────────────┼────────────────────────────┼─────────────────────────────────┼─────────────────────────────────────────────────────────────────────────────────────────┼─────────────────────────────┤
6666
│ default │ cache │ ["key"] │ ["VARCHAR NULL"] │ ["value"] │ ["VARCHAR NULL"] │ redis(host=127.0.0.1 port=6379) │ cache dictionary from Redis │
6767
│ default │ user_info │ ["user_id"] │ ["BIGINT UNSIGNED NULL"] │ ["user_name","user_email"] │ ["VARCHAR NULL","VARCHAR NULL"] │ mysql(db=app host=127.0.0.1 password=[hidden] port=3306 table=users username=root) │ User dictionary from MySQL │
68-
╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯```
68+
╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
6969
```

docs/en/sql-reference/10-sql-commands/00-ddl/07-spatial-index/create-spatial-index.md

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ CREATE [ OR REPLACE ] SPATIAL INDEX [IF NOT EXISTS] <index>
2525
- Spatial indexes are supported on Fuse tables only.
2626
- Spatial indexes support `GEOMETRY` columns only. `GEOGRAPHY` columns are not supported.
2727
- Multiple columns can be indexed in a single spatial index definition as long as all of them are `GEOMETRY` columns.
28+
- For better pruning, it is recommended to physically cluster geospatial data with `CLUSTER BY` and `ST_HILBERT`, so nearby objects are more likely to be written into the same block.
2829

2930
## Examples
3031

@@ -35,7 +36,9 @@ CREATE TABLE stores (
3536
store_id INT,
3637
store_name STRING,
3738
location GEOMETRY
38-
) ENGINE = FUSE;
39+
) CLUSTER BY (
40+
ST_HILBERT(location, [-180, -90, 180, 90])
41+
);
3942
```
4043

4144
Create a spatial index on the `location` column:
@@ -57,18 +60,20 @@ SHOW CREATE TABLE stores;
5760
│ │ store_name VARCHAR NULL, │
5861
│ │ location GEOMETRY NULL, │
5962
│ │ SYNC SPATIAL INDEX stores_location_idx (location) │
60-
│ │ ) ENGINE=FUSE
63+
│ │ ) ENGINE=FUSE CLUSTER BY linear(st_hilbert(location, [-180, -90, 180, 90]))
6164
└──────────────────────────────────────────────────────────────────────────────────────────────┘
6265
```
6366

64-
Load a slightly richer dataset for spatial filtering:
67+
Load a slightly richer dataset for spatial filtering, and run RECLUSTER command:
6568

6669
```sql
6770
INSERT INTO stores VALUES
6871
(1, 'Starbucks', TO_GEOMETRY('POINT(10 10)')),
6972
(2, 'Costa', TO_GEOMETRY('POINT(11 11)')),
7073
(3, 'Gong Cha', TO_GEOMETRY('POINT(20 20)')),
7174
(4, 'Dunkin', TO_GEOMETRY('POINT(-10 -10)'));
75+
76+
ALTER TABLE stores RECLUSTER FINAL;
7277
```
7378

7479
### Filter with `ST_WITHIN`, `ST_INTERSECTS`, and `ST_CONTAINS`
@@ -132,7 +137,9 @@ CREATE TABLE districts (
132137
district_id INT,
133138
district_name STRING,
134139
geom GEOMETRY
135-
) ENGINE = FUSE;
140+
) CLUSTER BY (
141+
ST_HILBERT(geom, [-180, -90, 180, 90])
142+
);
136143

137144
INSERT INTO districts VALUES
138145
(1, 'Central', TO_GEOMETRY('POLYGON((8 8, 8 13, 13 13, 13 8, 8 8))')),

docs/en/sql-reference/10-sql-commands/00-ddl/17-dictionary/show-dictionaries.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,4 +65,5 @@ SHOW DICTIONARIES;
6565
├──────────┼────────────┼───────────────┼──────────────────────────┼────────────────────────────┼─────────────────────────────────┼─────────────────────────────────────────────────────────────────────────────────────────┼─────────────────────────────┤
6666
│ default │ cache │ ["key"] │ ["VARCHAR NULL"] │ ["value"] │ ["VARCHAR NULL"] │ redis(host=127.0.0.1 port=6379) │ cache dictionary from Redis │
6767
│ default │ user_info │ ["user_id"] │ ["BIGINT UNSIGNED NULL"] │ ["user_name","user_email"] │ ["VARCHAR NULL","VARCHAR NULL"] │ mysql(db=app host=127.0.0.1 password=[hidden] port=3306 table=users username=root) │ User dictionary from MySQL │
68-
╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯```
68+
╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
69+
```

0 commit comments

Comments
 (0)