我有两个查询sql,一个查询的速度就很快,而另一个查询的非常慢,所查询出的数据都是大约4万条记录。想了一个上午也没有解决。哪位大哥帮帮我!谢谢
这个是快的
select t.login_user || '--' ||
(select k.user_name from user_t k where k.user_id = t.login_user) login_user,
t.tel,
t.aux_time,
t.aux_times,
t.zd_disconnect,
t.bd_disconnect,
to_char(t.login_time, 'yyyy-mm-dd hh24:mi:ss') login_time,
to_char(t.logout_time, 'yyyy-mm-dd hh24:mi:ss') logout_time,
t.talk_time
from seatstate_count_t t
where 1 = 1
and t.login_user not in ('0001', '0002', '0003')
and t.login_time between
to_date('2009-01-14 00:00', 'yyyy-mm-dd hh24:mi') and
to_date('2010-04-14 23:59', 'yyyy-mm-dd hh24:mi')
order by t.login_user, t.login_user, t.login_user
这个是慢的
select a.event_id,
b.dept deptid,
(select name from d_dept_tree_v t where t.deptid = b.dept) deptname,
a.event_code,
getdeptname(b.dept) receive_dept,
a.receive_user,
a.contact_tele,
a.call_tele,
(select code_value
from d_event_type_v v1
where v1.code_id = a.event_type) event_type,
a.call_owner,
caller,
to_char(a.call_time, 'yyyy-mm-dd hh24:mi') call_time,
a.place,
a.event_content,
v.code_id,
v.code_value,
f.*
from event_t a,
disposal_t b,
(select t.event_id,
nvl(t.other_type, 'other') other_type,
nvl(t.other_type2, 'other1') other_type2
from accident_info_t t) c,
(select * from d_disposal_state_v) v,
(select a.user_name, b.group_name, a.user_id, a.xh
from user_t_history a, user_group_t b
where b.group_code = a.group_code) f
where a.last_disposal_id = b.disposal_id
and a.event_id = c.event_id
and a.event_id = b.event_id
and b.state = v.code_id
and a.receive_user = f.xh
and a.call_time between
to_date('2009-04-01 00:00:00', 'yyyy-mm-dd hh24:mi:ss') and
to_date('2009-04-15 23:59:59', 'yyyy-mm-dd hh24:mi:ss')
and b.dept in
(53, 01, 0102, 0103, 0104, 0106, 02, 0202, 0203, 0204, 0206, 0207, 03, 0302, 0303, 04, 0402, 0403, 05, 0502, 0503, 0504, 0505, 0506, 0507, 0509, 06, 0602, 0603, 0604, 0605, 0607, 07, 0702, 0703, 0704, 0705, 0706, 08, 0802, 09, 0902, 0903, 0904, 10, 11, 12, 1202, 1203, 13, 14, 15, 16, 1602, 1604, 1605, 17, 18, 21, 22, 67, 91)
order by a.call_time,
b.state,
decode(deptid,
'53',
'0001',
'01',
'001',
'0102',
'00102',
'0103',
'00103',
'0104',
'00104',
'0106',
'00106',
'02',
'002',
'0202',
'00202',
'0203',
'00203',
'0204',
'00204',
'0206',
'00206',
'0207',
'00207',
'03',
'003',
'0302',
'00302',
'0303',
'00303',
'04',
'004',
'0402',
'00402',
'0403',
'00403',
'05',
'005',
'0502',
'00502',
'0503',
'00503',
'0504',
'00504',
'0505',
'00505',
'0506',
'00506',
'0507',
'00507',
'0509',
'00509',
'06',
'006',
'0602',
'00602',
'0603',
'00603',
'0604',
'00604',
'0605',
'00605',
'0607',
'00607',
'07',
'007',
'0702',
'00702',
'0703',
'00703',
'0704',
'00704',
'0705',
'00705',
'0706',
'00706',
'08',
'008',
'0802',
'00802',
'09',
'009',
'0902',
'00902',
'0903',
'00903',
'0904',
'00904',
'12',
'01',
'1202',
'0102',
'1203',
'0103',
'16',
'02',
'1602',
'0202',
'1604',
'0204',
'1605',
'0205',
'21',
'03',
'22',
'04',
'13',
'05',
'14',
'06',
'17',
'07',
'18',
'08',
'15',
'09',
'11',
'10',
'10',
'11',
'67',
'2',
'91',
'3')
这个是快的
select t.login_user || '--' ||
(select k.user_name from user_t k where k.user_id = t.login_user) login_user,
t.tel,
t.aux_time,
t.aux_times,
t.zd_disconnect,
t.bd_disconnect,
to_char(t.login_time, 'yyyy-mm-dd hh24:mi:ss') login_time,
to_char(t.logout_time, 'yyyy-mm-dd hh24:mi:ss') logout_time,
t.talk_time
from seatstate_count_t t
where 1 = 1
and t.login_user not in ('0001', '0002', '0003')
and t.login_time between
to_date('2009-01-14 00:00', 'yyyy-mm-dd hh24:mi') and
to_date('2010-04-14 23:59', 'yyyy-mm-dd hh24:mi')
order by t.login_user, t.login_user, t.login_user
这个是慢的
select a.event_id,
b.dept deptid,
(select name from d_dept_tree_v t where t.deptid = b.dept) deptname,
a.event_code,
getdeptname(b.dept) receive_dept,
a.receive_user,
a.contact_tele,
a.call_tele,
(select code_value
from d_event_type_v v1
where v1.code_id = a.event_type) event_type,
a.call_owner,
caller,
to_char(a.call_time, 'yyyy-mm-dd hh24:mi') call_time,
a.place,
a.event_content,
v.code_id,
v.code_value,
f.*
from event_t a,
disposal_t b,
(select t.event_id,
nvl(t.other_type, 'other') other_type,
nvl(t.other_type2, 'other1') other_type2
from accident_info_t t) c,
(select * from d_disposal_state_v) v,
(select a.user_name, b.group_name, a.user_id, a.xh
from user_t_history a, user_group_t b
where b.group_code = a.group_code) f
where a.last_disposal_id = b.disposal_id
and a.event_id = c.event_id
and a.event_id = b.event_id
and b.state = v.code_id
and a.receive_user = f.xh
and a.call_time between
to_date('2009-04-01 00:00:00', 'yyyy-mm-dd hh24:mi:ss') and
to_date('2009-04-15 23:59:59', 'yyyy-mm-dd hh24:mi:ss')
and b.dept in
(53, 01, 0102, 0103, 0104, 0106, 02, 0202, 0203, 0204, 0206, 0207, 03, 0302, 0303, 04, 0402, 0403, 05, 0502, 0503, 0504, 0505, 0506, 0507, 0509, 06, 0602, 0603, 0604, 0605, 0607, 07, 0702, 0703, 0704, 0705, 0706, 08, 0802, 09, 0902, 0903, 0904, 10, 11, 12, 1202, 1203, 13, 14, 15, 16, 1602, 1604, 1605, 17, 18, 21, 22, 67, 91)
order by a.call_time,
b.state,
decode(deptid,
'53',
'0001',
'01',
'001',
'0102',
'00102',
'0103',
'00103',
'0104',
'00104',
'0106',
'00106',
'02',
'002',
'0202',
'00202',
'0203',
'00203',
'0204',
'00204',
'0206',
'00206',
'0207',
'00207',
'03',
'003',
'0302',
'00302',
'0303',
'00303',
'04',
'004',
'0402',
'00402',
'0403',
'00403',
'05',
'005',
'0502',
'00502',
'0503',
'00503',
'0504',
'00504',
'0505',
'00505',
'0506',
'00506',
'0507',
'00507',
'0509',
'00509',
'06',
'006',
'0602',
'00602',
'0603',
'00603',
'0604',
'00604',
'0605',
'00605',
'0607',
'00607',
'07',
'007',
'0702',
'00702',
'0703',
'00703',
'0704',
'00704',
'0705',
'00705',
'0706',
'00706',
'08',
'008',
'0802',
'00802',
'09',
'009',
'0902',
'00902',
'0903',
'00903',
'0904',
'00904',
'12',
'01',
'1202',
'0102',
'1203',
'0103',
'16',
'02',
'1602',
'0202',
'1604',
'0204',
'1605',
'0205',
'21',
'03',
'22',
'04',
'13',
'05',
'14',
'06',
'17',
'07',
'18',
'08',
'15',
'09',
'11',
'10',
'10',
'11',
'67',
'2',
'91',
'3')
选出的数据量较大,第二个语句这么长的decode,还有in列表,
可以将decode中的代码放入字典表中。
我感觉第2条肯定慢,DECODE消耗的语句就占用时间比较长
我改了。