Query speed difference using range vs. exact match
Posted in 1994
Hi All; While working on a project, I noticed that some queries were taking longer to complete than others. Specifically, queries that search for an exact date match were taking much longer than those that used a range, even though the range was only 1 day. I was wondering if: a.) have others seen this or is it only me ( I hope not ); b.) there is an explaination for this seemingly backwards operation ( I'd expect a range to take longer ). The SQL statement and timing info follows. Thanks, Jon. jon@hpoemg.sj.hp.com Jon Dallara Systems Engineer Hewlett-Packard Optoelectronics Division 370 W. Trimble Rd. San Jose, CA 95131 time: UNIX system time utility range: mnsum with range in select clause. data_equals: mnsum with exact range inselect clause NOTE: 108% difference ---------- > time range 10/27/93 entity, source >> oed,wfab Product, test number >> 1BF4, 1 Product, test number >> SELECT RK.*, RT.* FROM results_keys RK, results_table RT WHERE (( RK.key4 >= DATE("10/27/1993") AND RK.key4 <= DATE("10/27/1993")) AND ( RK.key1 = "1BF4" AND RT.param1 = 1 AND RK.pointer = RT.pointer )) ; Result: 15 1BF4 found real 0m23.41s user 0m0.00s sys 0m0.02s > time date_equals 10/27/93 entity, source >> oed,wfab Product, test number >> 1BF4, 1 Product, test number >> SELECT RK.*, RT.* FROM results_keys RK, results_table RT WHERE ( RK.key4 = DATE("10/27/1993") AND ( RK.key1 = "1BF4" AND RT.param1 = 1 AND RK.pointer = RT.pointer )) ; Result: 15 1BF4 found real 4m13.07s user 0m0.01s sys 0m0.03s