例如,具有以下内容的表:
我的理解是,对于具有lastName IS NULL的行,无论firstName是多少,都不会进行约束检查。(因为NULL不被视为彼此相等。)但我想问的是,这些值是否真的记录在磁盘上,进入索引。例如,如果我想选择firstName为“Mary”的所有行,是否可以使用索引而不是全文行条目来回答此查询?
lastName IS NULL
firstName
NULL
djmepvbi1#
是,索引中有空值。
MySQL [bbodb_test]> create table test_index(c1 int null, c2 int null, unique(c1, c2)); Query OK, 0 rows affected (0.007 sec) MySQL [bbodb_test]> insert into test_index values (null, null); Query OK, 1 row affected (0.002 sec) MySQL [bbodb_test]> insert into test_index values (null, null); Query OK, 1 row affected (0.001 sec) MySQL [bbodb_test]> explain select * from test_index where c1 is null; +----+-------------+------------+------------+------+---------------+------+---------+-------+------+----------+--------------------------+ | id | select_type | table | partitions | type | possible_keys | key | key_len | ref | rows | filtered | Extra | +----+-------------+------------+------------+------+---------------+------+---------+-------+------+----------+--------------------------+ | 1 | SIMPLE | test_index | NULL | ref | c1 | c1 | 5 | const | 2 | 100.00 | Using where; Using index | +----+-------------+------------+------------+------+---------------+------+---------+-------+------+----------+--------------------------+ 1 row in set, 1 warning (0.001 sec)
正如你所看到的,它使用索引来满足WHERE c1 is null。
WHERE c1 is null
1条答案
按热度按时间djmepvbi1#
是,索引中有空值。
正如你所看到的,它使用索引来满足
WHERE c1 is null
。