+ -
当前位置:首页 → 问答吧 → mysqldumpslow找到的sql,查询不明白?

mysqldumpslow找到的sql,查询不明白?

时间:2011-09-15

来源:互联网

rt
偶是oracle dba,刚管理mysql,学习中。。。
mysqldumpslow -s c -t 20 host-slow.log  按执行次序

Count: 270  Time=14.71s (3971s)  Lock=0.00s (0s)  Rows=1.0 (270), fan[fan]@3hosts
  SELECT count(*) AS count_all FROM `tuan_coupons` WHERE (operator_id in (N) and consume = N)


我在数据库里
SELECT * FROM `tuan_coupons` WHERE (operator_id IN ('N') AND consume = 'N')
可以查询,需要在N 加上单引号

结果operator_id  的值为0

不明白 WHERE (operator_id IN ('N') AND consume = 'N') 是神马意思

SELECT * FROM tuan_coupons t limit 10 查询operator_id为NULL或都有数值

数据类型
`operator_id` int(11) DEFAULT NULL
`consume` smallint(6) DEFAULT '0'

如果做优化,因为只有一个值,可以把 in 换成 = ?

作者: saup007   发布时间: 2011-09-15



QUOTE:原帖由 saup007 于 2011-9-15 14:33 发表
rt
偶是oracle dba,刚管理mysql,学习中。。。
mysqldumpslow -s c -t 20 host-slow.log  按执行次序

Count: 270  Time=14.71s (3971s)  Lock=0.00s (0s)  Rows=1.0 (270), fan[fan]@3hosts
  SELECT count(*) AS count_all FROM `tuan_coupons` WHERE (operator_id in (N) and consume = N)


我在数据库里
SELECT * FROM `tuan_coupons` WHERE (operator_id IN ('N') AND consume = 'N')
可以查询,需要在N 加上单引号

结果operator_id  的值为0

不明白 WHERE (operator_id IN ('N') AND consume = 'N') 是神马意思

SELECT * FROM tuan_coupons t limit 10 查询operator_id为NULL或都有数值

数据类型
`operator_id` int(11) DEFAULT NULL
`consume` smallint(6) DEFAULT '0'

如果做优化,因为只有一个值,可以把 in 换成 = ?

WHERE (operator_id IN ('N') AND consume = 'N')
这是mysqldumpslow为统计而抽象出来的,把其真实值用N代替掉......要是用mysqlsla工具,会给出归纳的SQL语句,类似你这所贴出来的,同时会列出一个真实的例子.....


IN的内容 其实在优化器那边会做优化的,最后转换成范围 或OR 操作...

作者: jinguanding   发布时间: 2011-09-15

谢谢,我再使用mysqlsla,做一次吧,其实抽象的就可以了。主要反馈给开发。

如果一个值还是用=吧
如果多个值使用in吧,优化器来判断使用 rang 或 or操作。

作者: saup007   发布时间: 2011-09-15