国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 數據庫 > 文庫 > 正文

字段運用函數索引被抑制

2024-09-07 22:12:39
字體:
來源:轉載
供稿:網友

       在索引字段上使用函數,該字段的索引將會被抑制。如下案例:
       查看表結構:
       點擊(此處)折疊或打開
 
mysql> show create table test06 /G
*************************** 1. row ***************************
       Table: test06
Create Table: CREATE TABLE `test06` (
  `id` bigint(11) NOT NULL DEFAULT '0',
  `u_id` bigint(11) NOT NULL,
  `openid` varchar(100) DEFAULT NULL,
  `unionid` varchar(100) DEFAULT NULL,
  `username` varchar(100) NOT NULL,
  `password` varchar(100) NOT NULL,
  `create_time` datetime NOT NULL,
  KEY `idx_test03_id` (`id`),
  KEY `idx_test03_name` (`username`),
  KEY `idx_test06_crea_time` (`create_time`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8
使用函數進行查詢:
點擊(此處)折疊或打開
 
mysql> select count(*) from test06 where date(create_time)=curdate();
+----------+
| count(*) |
+----------+
| 0 |
+----------+
1 row in set (1.00 sec)
不使用函數:
點擊(此處)折疊或打開
 
mysql> select count(*) from test06 where create_time=date_format(curdate(),'%Y-%m-%d');
+----------+
| count(*) |
+----------+
| 0 |
+----------+
1 row in set (0.03 sec)
  可以看出:查詢時間變快很多。
 對比一下執行計劃:
 
點擊(此處)折疊或打開
 
mysql> explain select count(*) from test06 where date(create_time)=curdate();
+----+-------------+--------+-------+---------------+----------------------+---------+------+---------+--------------------------+
| id | select_type | table  | type  | possible_keys | key                  | key_len | ref  | rows    | Extra                    |
+----+-------------+--------+-------+---------------+----------------------+---------+------+---------+--------------------------+
| 1  | SIMPLE      | test06 | index | NULL          | idx_test06_crea_time | 5       | NULL | 2009559 | Using where; Using index |
+----+-------------+--------+-------+---------------+----------------------+---------+------+---------+--------------------------+
1 row in set (0.00 sec)
 
mysql> explain select count(*) from test06 where create_time=date_format(curdate(),'%Y-%m-%d');
+----+-------------+--------+------+----------------------+----------------------+---------+-------+------+-------------+
| id | select_type | table  | type | possible_keys    key | key_len              | ref     | rows  | Extra              |
+----+-------------+--------+------+----------------------+----------------------+---------+-------+------+-------------+
| 1  | SIMP        | test06 | ref  | idx_test06_crea_time | idx_test06_crea_time | 5       | const | 1    | Using index |
+----+-------------+--------+------+----------------------+----------------------+---------+-------+------+-------------+

(編輯:武林網)

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 保康县| 济源市| 通化县| 东源县| 叶城县| 得荣县| 吉木萨尔县| 沭阳县| 云浮市| 嘉义县| 日喀则市| 衡南县| 德清县| 哈尔滨市| 土默特左旗| 烟台市| 平阴县| 望奎县| 南郑县| 曲阜市| 柘城县| 四子王旗| 承德县| 达拉特旗| 光山县| 来宾市| 商水县| 全椒县| 蒲江县| 门源| 宁强县| 汕尾市| 阳春市| 大同市| 霞浦县| 定安县| 长寿区| 历史| 肇州县| 察隅县| 毕节市|