-PSP optimization currently compiles and executes each query variant as a new prepared statement, which is one of the reasons that they query variants *lose* their association with any parent modules' `object_id` if the dispatcher plan was based on a module (that is, stored procedure, trigger, function, view, and so on). As a prepared statement, the `object_id` won't be anything that can be mapped to an object in `sys.objects` directly but is essentially a calculated value based on an internal hash of the batch text (see [Table Returned](../system-dynamic-management-views/sys-dm-exec-plan-attributes-transact-sql.md#table-returned) for more information). Query variant plans will be placed in the plan cache object store (CACHESTORE_OBJCP) while dispatcher plans are placed in the SQL Plans cache store (CACHESTORE_SQLCP). The PSP feature will, however, store the `object_id` of a query variant's parent within the ObjectID attribute that is part of the PLAN PER VALUE hint that PSP adds to the ShowPlan XML if the parent query is part of a module and not dynamic or ad-hoc sql. Aggregate performance statistics for cached procedures, functions, and triggers can continue to be used for their respective purposes. More granular execution related statistics such as those found in views similar to the `sys.dm_exec_query_stats` DMV will still contain data for query variants, however, the association between the `object_id` for query variants and objects within the `sys.objects` table won't currently align without additional processing of the ShowPlan XML for each of the query variants in which more granular runtime statistics are required. The runtime and wait statistics information for query variants can be obtained from the Query Store without additional ShowPlan XML parsing techniques if the Query Store is enabled.
0 commit comments