How to test SQL query performance - realiably?
623917Jan 19 2010 — edited Apr 24 2013I have certain queries and I want to test which one is faster, and how big is the difference.
How can I do this reliably?
The problem is, when I execute the queries, Oracle does it's caching and execution planning and whatnot, and results of the queries are dependent on the order I execute them.
Example: query A and query B, supposed to return same data.
query A, run 1: 587 seconds
query A, run 2: 509 seconds
query B, run 1: 474 seconds
query B, run 2: 451 seconds
It would seem that A is somewhat faster than B, but if I change the order and execute B before A, results are different.
Also I'm running the queries in SQL Developer, and it only returns 100 first lines, how can I remove this effect and simulate real scenario where all lines are fetched?
I can also use EXPLAIN PLANs and look at the costs but I'm not sure how much I can trust those either. I understand they are only estimations and even if cost(a) = 1.5 * cost (b), b could still end up executing faster in practise due to inaccuracies in the cost calculation....right? EDIT: actually event if cost(a) = 5000 * cost(b), b can still execute faster.....seems like query A's cost is 15836 and B's cost is 3 while A seems to be faster in practise.
Edited by: user620914 on 19-Jan-2010 01:42