explain select task_id FROM mostop_xiaoda..."/>
您好,登錄后才能下訂單哦!
今天發(fā)現(xiàn)一個(gè)問(wèn)題,where條件的列上明明有索引,但是執(zhí)行計(jì)劃還是走全表掃描
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 '編號(hào)', `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 '手機(jī)號(hào)', `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 '平臺(tái)名稱', `third_party_system` tinyint(3) unsigned NOT NULL COMMENT '第三方IVR系統(tǒng),1 = 百可錄(暫停使用),2 = 大唐,3 = 云電幫(暫停使用), 4 = 科大訊飛, 5 = 基立訊,99 = 決策引擎測(cè)試', `send_time` datetime DEFAULT NULL COMMENT '發(fā)送時(shí)間', `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 = 代表無(wú)效接聽(tīng),或者未接聽(tīng),1 = 有效接聽(tīng),已通知用戶)', `talking_time` int(10) NOT NULL DEFAULT '0' COMMENT '通話時(shí)長(zhǎng)', `task_id` varchar(32) NOT NULL DEFAULT '0' COMMENT '外呼任務(wù)ID (只為科大訊飛服務(wù))', `task_data_id` varchar(32) NOT NULL DEFAULT '0' COMMENT '外呼任務(wù)二級(jí)ID (只為科大訊飛服務(wù))', `resend_num` tinyint(3) unsigned NOT NULL DEFAULT '0' COMMENT '重發(fā)次數(shù)', `receive_time` datetime DEFAULT NULL COMMENT '接收時(shí)間', `receive_content` text COMMENT '接收內(nèi)容', `unique_tab` varchar(100) DEFAULT NULL COMMENT '唯一標(biāo)識(shí)', `created_at` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '創(chuàng)建時(shí)間', `updated_at` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '更新時(shí)間', 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='催收自動(dòng)通話表' 1 row in set (0.00 sec)
查看warnings
因?yàn)檫@兩列為字符串類型 ,但是SQL中并沒(méi)有加引號(hào)?。?/p>
`task_id` varchar(32) `task_data_id` varchar(32)
加上引號(hào)后查看執(zhí)行計(jì)劃
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)
免責(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)容。