I am performing some benchmarking tasks using Postgresql 9.1 running on Debian Linux. I would like to benchmark a workload of queries that share a common part. Before running each query I restart the database and execute the following command:
echo 3 > /proc/sys/vm/drop_caches
aiming at dropping both the shared memory and the OS cache. However, I have noticed that if I run the same query workload with a different order I get different query response times. I suspect that somehow either the query optimizer 'remembers' how to efficiently execute the common query parts or reuses some previously cached results.
Do you have any ideas how to workaround this issue? I would like to get roughly the same response times regardless of query ordering. Note, that I am parsing the EXPLAIN output to extract the actual running times.