Esempio n. 1
0
        /// <summary>
        /// Report the given result.
        /// </summary>
        /// <param name="result">
        /// The result.
        /// </param>
        /// <param name="type">
        /// The record type.
        /// </param>
        /// <param name="listIndexLookups">
        /// The list of lookup ids.
        /// </param>
        /// <param name="fReportPartition">
        /// Indicates whether or not to report partitions.
        /// </param>
        /// <returns>
        /// A report for the given result.
        /// </returns>
        protected static string ReportResult(IPartialResult result,
                                             QueryRecorder.RecordType type,
                                             IList listIndexLookups,
                                             bool fReportPartition)
        {
            StringBuilder sb = new StringBuilder();

            if (type == QueryRecorder.RecordType.Trace)
            {
                sb.Append(String.Format(REPORT_TRACE_HEADER_FORMAT,
                                        "Name", "Index", "Effectiveness", "Duration"));
            }
            else
            {
                sb.Append(String.Format(REPORT_EXPLAIN_HEADER_FORMAT,
                                        "Name", "Index", "Cost"));
            }

            sb.Append(String.Format(REPORT_DIVIDER));


            foreach (IStep childStep in result.Steps)
            {
                sb.Append(ReportStep(childStep, type, listIndexLookups, 0));
                sb.Append(String.Format("\n"));
            }

            sb.Append(String.Format("\n"));

            if (fReportPartition)
            {
                sb.Append(String.Format(REPORT_PARTITION_FORMAT,
                                        result.Partitions.ToString()));
            }

            return(sb.ToString());
        }
Esempio n. 2
0
        /// <summary>
        /// Report the given step.
        /// </summary>
        /// <param name="step">
        /// The step.
        /// </param>
        /// <param name="type">
        /// The record type.
        /// </param>
        /// <param name="listIndexLookups">
        /// The list of lookup ids.
        /// </param>
        /// <param name="nLevel">
        /// The indent level.
        /// </param>
        /// <returns>
        /// A report line for the given step.
        /// </returns>
        protected static string ReportStep(IStep step,
                                           QueryRecorder.RecordType type,
                                           IList listIndexLookups,
                                           int nLevel)
        {
            StringBuilder sbName = new StringBuilder();

            for (int i = 0; i < nLevel; ++i)
            {
                sbName.Append("  ");
            }
            sbName.Append(step.FilterDescription);

            string sCost     = step.Efficiency >= 0 ? step.Efficiency.ToString() : REPORT_NA;
            string sSizeIn   = step.PreFilterKeySetSize >= 0 ? step.PreFilterKeySetSize.ToString() : REPORT_NA;
            string sSizeOut  = step.PostFilterKeySetSize >= 0 ? step.PostFilterKeySetSize.ToString() : REPORT_NA;
            string sDuration = step.Duration >= 0 ? step.Duration.ToString() : REPORT_NA;

            StringBuilder sbIndex = new StringBuilder();

            foreach (IIndexLookupRecord record in step.IndexLookupRecords)
            {
                int nIndex = listIndexLookups.IndexOf(record);
                if (nIndex == -1)
                {
                    nIndex = listIndexLookups.Count;

                    listIndexLookups.Add(record);
                }
                sbIndex.Append(sbIndex.Length > 0 ? "," : "" + nIndex);
            }

            StringBuilder sbStep = new StringBuilder();

            if (type == QueryRecorder.RecordType.Trace)
            {
                int nEff = step.PreFilterKeySetSize == 0 ? 0 :
                           (step.PreFilterKeySetSize - step.PostFilterKeySetSize) * 100 / step.PreFilterKeySetSize;

                String sEff = sSizeIn + "|" + sSizeOut + "(" + nEff + "%)";

                sbStep.Append(String.Format(REPORT_TRACE_STEP_FORMAT,
                                            sbName,
                                            sbIndex.Length > 0 ? sbIndex.ToString() : REPORT_NA,
                                            sEff, sDuration));
            }
            else
            {
                sbStep.Append(String.Format(REPORT_EXPLAIN_STEP_FORMAT,
                                            sbName,
                                            sbIndex.Length > 0 ? sbIndex.ToString() : REPORT_NA,
                                            sCost));
            }

            foreach (IStep stepChild in step.Steps)
            {
                sbStep.Append(String.Format("\n")).Append(ReportStep(stepChild,
                                                                     type, listIndexLookups, nLevel + 1));
            }

            return(sbStep.ToString());
        }
 /// <summary>
 /// Construct a <b>SimpleQueryRecord</b> from the given collection of partial
 /// results.
 /// </summary>
 /// <param name="type">
 /// The record type.
 /// </param>
 /// <param name="colResults">
 /// The collection of partial results.
 /// </param>
 public SimpleQueryRecord(QueryRecorder.RecordType type, ICollection colResults)
 {
     m_type = type;
     MergeResults(colResults);
 }