我对以下 MySQL 查询的理论 Big-O 分析感兴趣:
SELECT id, value FROM MyTable WHERE lat BETWEEN %s AND %s AND lon BETWEEN %s AND %s;
特别是,我想知道 BETWEEN 子句如何影响此查询的复杂性。
MySQL版本是5.1
MyTable 定义:
CREATE TABLE MyTable (
id VARCHAR(255) NOT NULL UNIQUE, \
value DECIMAL(12,9) NOT NULL, \
lat DECIMAL(9,6), \
lon DECIMAL(9,6), \
PRIMARY KEY(id(50)), \
INDEX(lat, lon)) ENGINE=InnoDB;
Describe MyTable;
+----------+---------------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+----------+---------------------+------+-----+---------+-------+
| id | varchar(255) | NO | PRI | NULL | |
| value | decimal(12,9) | NO | | NULL | |
| lat | decimal(9,6) | YES | MUL | NULL | |
| lon | decimal(9,6) | YES | | NULL | |
+----------+---------------------+------+-----+---------+-------+
EXPLAIN EXTENDED SELECT id, value FROM MyTable WHERE lat BETWEEN '40' AND '60' AND lon BETWEEN '-10' AND '10';
+----+-------------+------------+------+---------------+------+---------+------+------+----------+-------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | filtered | Extra |
+----+-------------+------------+------+---------------+------+---------+------+------+----------+-------------+
| 1 | SIMPLE | MyTable | ALL | lat | NULL | NULL | NULL | 7 | 42.86 | Using where |
+----+-------------+------------+------+---------------+------+---------+------+------+----------+-------------+