CanonicalQuery generates the plan cache key for the underlying query in the CanonicalQuery::init(). This is an expensive operation that is performed unnecessarily for CanonicalQuery objects that never have their plan cache key examined (see example in exec/sort.cpp).
Instead, plan cache key generation should happen lazily on the first call to CanonicalQuery::getPlanCacheKey(). The first call to this method should save the generated cache key in the _cacheKey member variable for later retrieval.
- links to