1. A method comprising: calculating a hit percentage of an expected affinity for a first query, wherein the expected affinity comprises a first address range in a query plan cache; calculating a hit percentage of a candidate affinity for the first query, wherein the candidate affinity comprises a second address range in the query plan cache; comparing the hit percentage of the expected affinity for the first query and the hit percentage of the candidate affinity for the first query; and swapping, based on the hit percentage of the candidate affinity being greater than the hit percentage of the expected affinity by more than a threshold amount, query plans in the candidate affinity with query plans in the expected affinity.