Unusual variation in elapsed times on a SQL

Today we had users complaining that a query would run fast the first time and then fail to complete the second time. The SQL used bind parameters and we (DBAs) suspected that the issue was caused by the user changing the bind parameters. However, when we ran the SQL ourselves with hard coded values we also experienced the same behavior. The first execution completed in < 5 seconds and the second execution was killed at > 400 seconds of elapsed time. After some searching on the web I ran across an excellent explanation at the web site:

http://orcasoracle.squarespace.com/oracle-rdbms/2012/12/18/when-a-query-runs-slower-on-second-execution-a-possible-side.html

We added

/*+ OPT_PARAM('_OPTIMIZER_USE_FEEDBACK' 'FALSE') */

and the SQL began to perform consistently every time.

This was experienced on Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 – 64bit Production.

Author: Dean Capps

Database consultant at Amazon Web Services.