作业帮 > 综合 > 作业

sql语句性能问题(1)select b.x_Client_Satisfaction from siebel.s_srv

来源:学生作业帮 编辑:百度作业网作业帮 分类:综合作业 时间:2024/07/07 20:20:17
sql语句性能问题
(1)select b.x_Client_Satisfaction from siebel.s_srv_req
a,siebel.s_Srv_Req_x b
where a.row_id = b.par_row_id
and a.created > to_date('2013-11-20
00:00:00','yyyy-mm-dd hh24:mi:ss')-8/24
and b.x_Client_Satisfaction is not null;
(2)select b.x_Client_Satisfaction from siebel.s_srv_req
a,siebel.s_Srv_Req_x b
where a.row_id = b.par_row_id
and a.created > to_date(to_char(sysdate,'yyyy-mm-dd')||'00:00:00','yyyy-mm-dd
hh24:mi:ss')-8/24
and b.x_Client_Satisfaction is not null;
这两个语句中加了限制时间的条,数据量很大时第二个语句跑不动,第一个还行,这是为什么?
sql语句性能问题(1)select b.x_Client_Satisfaction from siebel.s_srv
这里的主要区别就是第二个语句用了sysdate函数取系统时间,这里看来是将这个值作为变量处理了.
第一个语句优化器是将 to_date('2013-11-20 00:00:00','yyyy-mm-dd hh24:mi:ss')-8/24直接处理好后作为常量执行语句,所以索引等都能够使用
第二个语句优化器to_date(to_char(sysdate,'yyyy-mm-dd')||'00:00:00','yyyy-mm-dd hh24:mi:ss')-8/24作为变量处理的话,就不会走created的索引,所以变成表扫描的话就会比较慢.