public bool ReleaseCachedPlan(ServerProcess process, ServerPlan plan) { if (_sessionInfo.UsePlanCache && (Server.PlanCacheSize > 0) && (plan.Header != null) && (!plan.Header.IsInvalidPlan) && !HasNonGeneratedSessionObjects()) { return(Server.PlanCache.Release(process, plan)); } return(false); }
private void DisposeCachedPlan(ServerProcess process, ServerPlan plan) { try { plan.BindToProcess(process.ServerSession.Server._systemProcess); plan.Dispose(); } catch { // ignore disposal exceptions } }
/// <summary>Gets a cached plan for the given statement, if available.</summary> /// <remarks> /// If a plan is found, it is referenced for the LRU, and disowned by the cache. /// The client must call Release to return the plan to the cache. /// If no plan is found, null is returned and the cache is unaffected. /// </remarks> public ServerPlan Get(ServerProcess process, string statement, int contextHashCode) { ServerPlan plan = null; CachedPlanHeader header = GetPlanHeader(process, statement, contextHashCode); CachedPlans bumped = null; lock (this) { if (_plans != null) { CachedPlans plans; if (_plans.TryGetValue(header, out plans)) { for (int planIndex = plans.Count - 1; planIndex >= 0; planIndex--) { plan = plans[planIndex]; plans.RemoveAt(planIndex); if (process.Catalog.PlanCacheTimeStamp > plan.PlanCacheTimeStamp) { DisposeCachedPlan(process, plan); plan = null; } else { bumped = _plans.Reference(header, plans); break; } } } } } if (bumped != null) { DisposeCachedPlans(process, bumped); } if (plan != null) { plan.BindToProcess(process); } return(plan); }
/// <summary>Releases the given plan and returns whether or not it was returned to the cache.</summary> /// <remarks> /// If the plan is returned to the cache, the client is no longer responsible for the plan, it is owned by the cache. /// If the plan is not returned to the cache, the cache client is responsible for disposing the plan. /// </remarks> public bool Release(ServerProcess process, ServerPlan plan) { CachedPlanHeader header = plan.Header; lock (this) { if (_plans != null) { CachedPlans plans; if (_plans.TryGetValue(header, out plans)) { plan.UnbindFromProcess(); plans.Add(plan); return(true); } } return(false); } }
protected internal RemoteServerPlan(RemoteServerProcess process, ServerPlan serverPlan) { _process = process; _serverPlan = serverPlan; AttachServerPlan(); }
/// <summary>Adds the given plan to the plan cache.</summary> /// <remarks> /// The plan is not contained within the cache after this call, it is assumed in use by the client. /// This call simply reserves storage and marks the plan as referenced for the LRU. /// </remarks> public void Add(ServerProcess process, string statement, int contextHashCode, ServerPlan plan) { CachedPlans bumped = null; CachedPlanHeader header = GetPlanHeader(process, statement, contextHashCode); plan.Header = header; plan.PlanCacheTimeStamp = process.Catalog.PlanCacheTimeStamp; lock (this) { if (_plans != null) { CachedPlans plans; if (!_plans.TryGetValue(header, out plans)) { plans = new CachedPlans(); } bumped = _plans.Reference(header, plans); } } if (bumped != null) { DisposeCachedPlans(process, bumped); } }
// Plan Cache public void AddCachedPlan(ServerProcess process, string statement, int contextHashCode, ServerPlan plan) { if (_sessionInfo.UsePlanCache && (Server.PlanCacheSize > 0) && !HasNonGeneratedSessionObjects()) { plan.Program.IsCached = true; Server.PlanCache.Add(process, statement, contextHashCode, plan); } }