From:Steve Adams
Date:20-Feb-2001 01:56
Subject:   Decodes - does the order make a difference?

Yes, there is a saving in the number of comparisons performed, and there may be a saving in the number of expressions evaluated if the candidate values are expressions rather than constants. This is because Oracle considers each candidate in order and stops evaluating the candidate expressions and making comparison as soon as a candidate value has matched.

To keep it simple, consider a decode expression with five candidate values that match say 0%, 10%, 20%, 30% and 40% of subject values respectively. With this ordering, the number of comparisons performed for 100 iterations that match that distribution would be 400 (2*10 + 3*20 + 4*30 + 5*40). Whereas, if the ordering were reversed, then the number of comparisons performed would be 200 (1*40 + 2*30 + 3*20 + 4*10).

If you have a decode statement with more than ten options will the code run faster if the values are in order of common-ness?