show creat..."/>
溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

字符類型數(shù)據(jù)缺失引號(hào)索引被抑制

發(fā)布時(shí)間:2020-08-11 01:42:30 來(lái)源:ITPUB博客 閱讀:144 作者:StevenBeijing 欄目:MySQL數(shù)據(jù)庫(kù)
 字符類型的數(shù)據(jù)沒(méi)有使用引號(hào),索引將被抑制,下邊看一個(gè)案例:
 查看表結(jié)構(gòu):

點(diǎn)擊(此處)折疊或打開(kāi)

  1. mysql> show create table test06 \G
  2. *************************** 1. row ***************************
  3.        Table: test06
  4. Create Table: CREATE TABLE `test06` (
  5.   `id` bigint(11) NOT NULL DEFAULT '0',
  6.   `u_id` bigint(11) NOT NULL,
  7.   `openid` varchar(100) DEFAULT NULL,
  8.   `unionid` varchar(100) DEFAULT NULL,
  9.   `username` varchar(100) NOT NULL,
  10.   `password` varchar(100) NOT NULL,
  11.   `create_time` datetime NOT NULL,
  12.   KEY `idx_test03_id` (`id`),
  13.   KEY `idx_test03_name` (`username`),
  14.   KEY `idx_test06_crea_time` (`create_time`)
  15. ) ENGINE=InnoDB DEFAULT CHARSET=utf8
  16. 1 row in set (0.00 sec)
username字段不加引號(hào):

點(diǎn)擊(此處)折疊或打開(kāi)

  1. mysql> select * from test06 where username=13499770088;
  2. Empty set, 8208 warnings (5.77 sec)

  3. mysql> explain select * from test06 where username=13499770088;
  4. +----+-------------+--------+------+-----------------+------+---------+------+---------+-------------+
  5. | id | select_type | table  | type | possible_keys   | key  | key_len | ref  | rows    | Extra       |
  6. +----+-------------+--------+------+-----------------+------+---------+------+---------+-------------+
  7. | 1  | SIMPLE      | test06 | ALL  | idx_test03_name | NULL | NULL    | NULL | 2009559 | Using where |
  8. +----+-------------+--------+------+-----------------+------+---------+------+---------+-------------+
username字段加引號(hào):

點(diǎn)擊(此處)折疊或打開(kāi)

  1. mysql> select * from test06 where username='13499770088';
  2. Empty set (0.07 sec)

  3. mysql> explain select * from test06 where username='13499770088';
  4. +----+-------------+--------+------+-----------------+-----------------+---------+-------+------+-----------------------+
  5. | id | select_type | table  | type | possible_keys   | key             | key_len | ref   | rows | Extra                 |
  6. +----+-------------+--------+------+-----------------+-----------------+---------+-------+------+-----------------------+
  7. | 1  | SIMPLE      | test06 | ref  | idx_test03_name | idx_test03_name | 302     | const | 1    | Using index condition |
  8. +----+-------------+--------+------+-----------------+-----------------+---------+-------+------+-----------------------+
查詢速度明顯變快,執(zhí)行計(jì)劃走了索引,這樣是正常的寫法。
向AI問(wèn)一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI