// static Status PlanCacheListQueryShapes::list(const PlanCache& planCache, BSONObjBuilder* bob) { invariant(bob); // Fetch all cached solutions from plan cache. vector<PlanCacheEntry*> solutions = planCache.getAllEntries(); BSONArrayBuilder arrayBuilder(bob->subarrayStart("shapes")); for (vector<PlanCacheEntry*>::const_iterator i = solutions.begin(); i != solutions.end(); i++) { PlanCacheEntry* entry = *i; invariant(entry); BSONObjBuilder shapeBuilder(arrayBuilder.subobjStart()); shapeBuilder.append("query", entry->query); shapeBuilder.append("sort", entry->sort); shapeBuilder.append("projection", entry->projection); shapeBuilder.doneFast(); // Release resources for cached solution after extracting query shape. delete entry; } arrayBuilder.doneFast(); return Status::OK(); }
// static Status PlanCacheListQueryShapes::list(const PlanCache& planCache, BSONObjBuilder* bob) { invariant(bob); // Fetch all cached solutions from plan cache. auto entries = planCache.getAllEntries(); BSONArrayBuilder arrayBuilder(bob->subarrayStart("shapes")); for (auto&& entry : entries) { invariant(entry); BSONObjBuilder shapeBuilder(arrayBuilder.subobjStart()); shapeBuilder.append("query", entry->query); shapeBuilder.append("sort", entry->sort); shapeBuilder.append("projection", entry->projection); if (!entry->collation.isEmpty()) { shapeBuilder.append("collation", entry->collation); } shapeBuilder.append("queryHash", unsignedIntToFixedLengthHex(entry->queryHash)); shapeBuilder.doneFast(); } arrayBuilder.doneFast(); return Status::OK(); }