I am facing a strange problem with one of my SQL Server 2017 Clusters. I faced a query regression in the past and forced a known good plan for that query_id in query store.
When the planned database failover happens every month for OS patching from HostA to HostB the optimizer generates a different query_id for the same query_text_id.
I found the context_settings_id remains same but the query_hash changes. Because the query_id has changed the forced plan is no longer valid and optimizer generates new plans and performance degrades until I go and force the good plan.
It is not the case of some pressure/limit on the query store to cleanup the old plans. I verified it because when the database again fails back from HostB to HostA after a week which is also a monthly planned activity,the query_id is intact and the plan forcing is intact.
ChatGPT says "you’re running into is fundamentally: failover/cold cache → recompiles → Query Store may capture a “new” query identity (new query_id) even when query_text_id and context_settings_id look the same. Mirroring is just the thing that reliably triggers that cold-start compile pattern in your environment every month."
Is this something anybody experienced, because I dont know what can I check or do here to make sure the query_id remains the same after the mirroring failover other than doing some workaround automation to have a post failover step to find new query_id and force the known goon plan_id