Exemple #1
0
        public void ExecuteExplainPlan(SqlObfuscator obfuscator)
        {
            // Don't re-run an explain plan if one already exists
            if (_explainPlan != null)
            {
                return;
            }

            try
            {
                // Using invoke for thread safety, DoExplainPlanCondition is nullable
                if (DoExplainPlanCondition?.Invoke() == true)
                {
                    var explainPlan = GenerateExplainPlan?.Invoke(_explainPlanResources);
                    if (explainPlan != null)
                    {
                        foreach (var data in explainPlan.ExplainPlanDatas)
                        {
                            foreach (var index in explainPlan.ObfuscatedHeaders)
                            {
                                data[index] = obfuscator.GetObfuscatedSql(data[index].ToString(), DatastoreVendorName);
                            }
                        }

                        _explainPlan = new ExplainPlan(explainPlan.ExplainPlanHeaders, explainPlan.ExplainPlanDatas, explainPlan.ObfuscatedHeaders);
                    }
                }
            }
            catch (Exception exception)
            {
                Log.DebugFormat("Unable to execute explain plan: {0}", exception);
            }
        }
Exemple #2
0
        internal override IEnumerable <KeyValuePair <string, object> > Finish()
        {
            if (GetExplainPlanResources == null)
            {
                return(null);
            }

            // Ensures we aren't running explain plan twice
            if (_explainPlanResources != null)
            {
                return(null);
            }

            try
            {
                // Using invoke for thread safety, DoExplainPlanCondition is nullable
                if (DoExplainPlanCondition?.Invoke() == true)
                {
                    _explainPlanResources = GetExplainPlanResources();
                }
                else
                {
                    GetExplainPlanResources = null;
                    GenerateExplainPlan     = null;
                }
            }
            catch (Exception exception)
            {
                Log.DebugFormat("Unable to retrieve resources for explain plan: {0}", exception);
            }
            return(null);
        }