国产探花免费观看_亚洲丰满少妇自慰呻吟_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 |
+----+-------------+--------+------+----------------------+----------------------+---------+-------+------+-------------+

(編輯:武林網)

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 澳门| 友谊县| 黄山市| 台南市| 扬中市| 肇州县| 安龙县| 博湖县| 静宁县| 同德县| 丹江口市| 新干县| 博客| 定日县| 大连市| 句容市| 通化县| 南丰县| 绍兴县| 石景山区| 阳谷县| 嘉鱼县| 汕尾市| 始兴县| 抚顺市| 嘉禾县| 香河县| 曲水县| 游戏| 武鸣县| 静宁县| 甘孜| 台前县| 玉门市| 仙桃市| 乐亭县| 新巴尔虎右旗| 云龙县| 合水县| 广州市| 玉树县|