今天發(fā)現(xiàn)一個問題,where條件的列上明明有索引,但是執(zhí)行計劃還是走全表掃描
創(chuàng)新互聯(lián)科技有限公司專業(yè)互聯(lián)網(wǎng)基礎(chǔ)服務(wù)商,為您提供綿陽主機托管,高防主機,成都IDC機房托管,成都主機托管等互聯(lián)網(wǎng)服務(wù)。
MySQL> explain select task_id FROM mostop_xiaodai_collection_call_auto WHERE task_id = 433423882127424 AND task_data_id = 27739131157286912; +----+-------------+-------------------------------------+------------+------+------------------------------+------+---------+------+---------+----------+-------------+ | id | select_type | table | partitions | type | possible_keys | key | key_len | ref | rows | filtered | Extra | +----+-------------+-------------------------------------+------------+------+------------------------------+------+---------+------+---------+----------+-------------+ | 1 | SIMPLE | mostop_xiaodai_collection_call_auto | NULL | ALL | IDX_task_id,IDX_task_data_id | NULL | NULL | NULL | 3101134 | 1.00 | Using where | +----+-------------+-------------------------------------+------------+------+------------------------------+------+---------+------+---------+----------+-------------+ 1 row in set, 5 warnings (0.00 sec)
查看表結(jié)構(gòu)
mysql> show create table mostop_xiaodai_collection_call_auto\G *************************** 1. row *************************** Table: mostop_xiaodai_collection_call_auto Create Table: CREATE TABLE `mostop_xiaodai_collection_call_auto` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT '編號', `agentid` int(10) unsigned NOT NULL COMMENT '渠道 ID', `loan_id` bigint(20) unsigned NOT NULL DEFAULT '0' COMMENT '借款 ID', `user_id` bigint(20) unsigned NOT NULL COMMENT '借款人 ID', `call_mobile` varchar(20) NOT NULL COMMENT '手機號', `call_name` varchar(20) NOT NULL COMMENT '名稱', `call_sex` varchar(20) NOT NULL COMMENT '性別', `call_due_date` date NOT NULL COMMENT '應(yīng)還日期', `call_overdue_day` int(10) NOT NULL COMMENT '逾期天數(shù)(負(fù)數(shù)為貸前催告的天數(shù))', `call_talking_type` varchar(50) NOT NULL COMMENT '話術(shù) (A:貸前7天的提醒話術(shù) B:貸前3天的話術(shù) C:貸前3天的話術(shù) D:貸前1天的話術(shù) Ps:若話術(shù)為空,則使用的是大唐的話術(shù),其余類似due_one之類的均已廢棄)', `call_platform_name` varchar(100) NOT NULL COMMENT '平臺名稱', `third_party_system` tinyint(3) unsigned NOT NULL COMMENT '第三方IVR系統(tǒng),1 = 百可錄(暫停使用),2 = 大唐,3 = 云電幫(暫停使用), 4 = 科大訊飛, 5 = 基立訊,99 = 決策引擎測試', `send_time` datetime DEFAULT NULL COMMENT '發(fā)送時間', `send_status` tinyint(3) unsigned NOT NULL DEFAULT '0' COMMENT '發(fā)送狀態(tài),0 = 未發(fā)送,1 = 發(fā)送成功,2 = 發(fā)送失敗', `send_result` tinyint(3) DEFAULT '0' COMMENT 'IVR結(jié)果( 0 = 代表無效接聽,或者未接聽,1 = 有效接聽,已通知用戶)', `talking_time` int(10) NOT NULL DEFAULT '0' COMMENT '通話時長', `task_id` varchar(32) NOT NULL DEFAULT '0' COMMENT '外呼任務(wù)ID (只為科大訊飛服務(wù))', `task_data_id` varchar(32) NOT NULL DEFAULT '0' COMMENT '外呼任務(wù)二級ID (只為科大訊飛服務(wù))', `resend_num` tinyint(3) unsigned NOT NULL DEFAULT '0' COMMENT '重發(fā)次數(shù)', `receive_time` datetime DEFAULT NULL COMMENT '接收時間', `receive_content` text COMMENT '接收內(nèi)容', `unique_tab` varchar(100) DEFAULT NULL COMMENT '唯一標(biāo)識', `created_at` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '創(chuàng)建時間', `updated_at` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '更新時間', PRIMARY KEY (`id`), KEY `loan_id` (`agentid`,`loan_id`), KEY `send_result` (`call_mobile`,`send_time`), KEY `receive_time` (`receive_time`), KEY `IDX_task_id` (`task_id`), KEY `IDX_task_data_id` (`task_data_id`) ) ENGINE=InnoDB AUTO_INCREMENT=5292233 DEFAULT CHARSET=utf8 COMMENT='催收自動通話表' 1 row in set (0.00 sec)
查看warnings
因為這兩列為字符串類型 ,但是SQL中并沒有加引號?。?/p>
`task_id` varchar(32) `task_data_id` varchar(32)
加上引號后查看執(zhí)行計劃
mysql> explain select task_id FROM mostop_xiaodai_collection_call_auto WHERE task_id = '433423882127424' AND task_data_id =' 27739131157286912'; +----+-------------+-------------------------------------+------------+------+------------------------------+------------------+---------+-------+------+----------+-------------+ | id | select_type | table | partitions | type | possible_keys | key | key_len | ref | rows | filtered | Extra | +----+-------------+-------------------------------------+------------+------+------------------------------+------------------+---------+-------+------+----------+-------------+ | 1 | SIMPLE | mostop_xiaodai_collection_call_auto | NULL | ref | IDX_task_id,IDX_task_data_id | IDX_task_data_id | 98 | const | 1 | 5.00 | Using where | +----+-------------+-------------------------------------+------------+------+------------------------------+------------------+---------+-------+------+----------+-------------+ 1 row in set, 1 warning (0.00 sec)