@
JustLookBy 有点像 online_time 和 offline_time,数据量少的时候可以使用索引。
数据量 100w 时,也是全表扫描。SQL:
```sql
EXPLAIN
select * from online_log where
MBRContains(online_range,ST_GeomFromText('point(1614152940 0)'));
+----+-------------+------------+------------+------+--------------------+------+---------+------+---------+----------+-------------+
| id | select_type | table | partitions | type | possible_keys | key | key_len | ref | rows | filtered | Extra |
+----+-------------+------------+------------+------+--------------------+------+---------+------+---------+----------+-------------+
| 1 | SIMPLE | online_log | NULL | ALL | index_online_range | NULL | NULL | NULL | 1343396 | 31.03 | Using where |
+----+-------------+------------+------------+------+--------------------+------+---------+------+---------+----------+-------------+
1 row in set, 1 warning (0.00 sec)
```
这条 SQL 最后筛选出来的数据大约 100 条。
优化过程:
```
......
"analyzing_range_alternatives": {
"range_scan_alternatives": [
{
"index": "index_online_range",
"ranges": [
"online_range unprintable_geometry_value"
],
"index_dives_for_eq_ranges": true,
"rowid_ordered": false,
"using_mrr": false,
"index_only": false,
"rows": 425368,
"cost": 510443,
"chosen": false,
"cause": "cost"
}
],
"analyzing_roworder_intersect": {
"usable": false,
"cause": "too_few_roworder_scans"
}
}
......
```