为了账号安全,请及时绑定邮箱和手机立即绑定

MySQL 请问这两条语句谁更快一点?

MySQL 请问这两条语句谁更快一点?

莫回无 2019-02-07 11:07:40
select * from qs_exam_info where TRANS_DATE LIKE '2018-08-18%'select * from qs_exam_info where date(TRANS_DATE) = '20180818'数据库里面TRANS_DATE是按2018-10-16 00:14:17这样的格式存储的
查看完整描述

2 回答

?
繁星coding

TA贡献1797条经验 获得超4个赞

如果 TRANS_DATE 为 varchar/char 类型,且该字段有索引,那么大部分情况下第一句比第二句更快

如果 TRANS_DATE 为 timestamp/datetime 类型,两句都用不到索引,全表扫描,所以效率差不多


查看完整回答
反对 回复 2019-03-13
?
跃然一笑

TA贡献1826条经验 获得超6个赞

mysql> select count(*) from table where date like '2018-08-18%';

+----------+

| count(*) |

+----------+

|     2128 |

+----------+

1 row in set (0.98 sec)


mysql> select count(*) from table where date(date) = '2018-08-18';

+----------+

| count(*) |

+----------+

|     2128 |

+----------+

1 row in set (1.21 sec)


mysql> select count(*) from table where date(date) = '2018-08-18';

+----------+

| count(*) |

+----------+

|     2128 |

+----------+

1 row in set (1.21 sec)


mysql> select count(*) from table where date like '2018-08-18%';

+----------+

| count(*) |

+----------+

|     2128 |

+----------+

1 row in set (0.98 sec)


mysql> select count(*) from table;

+----------+

| count(*) |

+----------+

|  2066946 |

+----------+

1 row in set (0.66 sec)


mysql> 


查看完整回答
反对 回复 2019-03-13
  • 2 回答
  • 0 关注
  • 553 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信