MySQL隐式类型转换导致索引失效-创新互联
今天发现一个问题,where条件的列上明明有索引,但是执行计划还是走全表扫描
成都创新互联公司坚持“要么做到,要么别承诺”的工作理念,服务领域包括:做网站、成都网站建设、企业官网、英文网站、手机端网站、网站推广等服务,满足客户于互联网时代的钟祥网站设计、移动媒体设计的需求,帮助企业找到有效的互联网解决方案。努力成为您成熟可靠的网络建设合作伙伴!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)查看表结构
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 '应还日期', `call_overdue_day` int(10) NOT NULL COMMENT '逾期天数(负数为贷前催告的天数)', `call_talking_type` varchar(50) NOT NULL COMMENT '话术 (A:贷前7天的提醒话术 B:贷前3天的话术 C:贷前3天的话术 D:贷前1天的话术 Ps:若话术为空,则使用的是大唐的话术,其余类似due_one之类的均已废弃)', `call_platform_name` varchar(100) NOT NULL COMMENT '平台名称', `third_party_system` tinyint(3) unsigned NOT NULL COMMENT '第三方IVR系统,1 = 百可录(暂停使用),2 = 大唐,3 = 云电帮(暂停使用), 4 = 科大讯飞, 5 = 基立讯,99 = 决策引擎测试', `send_time` datetime DEFAULT NULL COMMENT '发送时间', `send_status` tinyint(3) unsigned NOT NULL DEFAULT '0' COMMENT '发送状态,0 = 未发送,1 = 发送成功,2 = 发送失败', `send_result` tinyint(3) DEFAULT '0' COMMENT 'IVR结果( 0 = 代表无效接听,或者未接听,1 = 有效接听,已通知用户)', `talking_time` int(10) NOT NULL DEFAULT '0' COMMENT '通话时长', `task_id` varchar(32) NOT NULL DEFAULT '0' COMMENT '外呼任务ID (只为科大讯飞服务)', `task_data_id` varchar(32) NOT NULL DEFAULT '0' COMMENT '外呼任务二级ID (只为科大讯飞服务)', `resend_num` tinyint(3) unsigned NOT NULL DEFAULT '0' COMMENT '重发次数', `receive_time` datetime DEFAULT NULL COMMENT '接收时间', `receive_content` text COMMENT '接收内容', `unique_tab` varchar(100) DEFAULT NULL COMMENT '唯一标识', `created_at` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '创建时间', `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中并没有加引号!!
`task_id` varchar(32) `task_data_id` varchar(32)加上引号后查看执行计划
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)另外有需要云服务器可以了解下创新互联cdcxhl.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。
网站题目:MySQL隐式类型转换导致索引失效-创新互联
标题来源:http://hbruida.cn/article/ddjhso.html