From cd2af1466b1c23f81c13af61fa550475f82e0227 Mon Sep 17 00:00:00 2001 From: Alex Tatiyants Date: Sat, 5 Mar 2016 11:58:52 -0800 Subject: better handle CTE scans, including correct duration calculations. fix #15 --- app/services/help-service.ts | 5 ++++- app/services/plan-service.ts | 13 +++++++++++-- 2 files changed, 15 insertions(+), 3 deletions(-) (limited to 'app/services') diff --git a/app/services/help-service.ts b/app/services/help-service.ts index 6067b05..532d694 100644 --- a/app/services/help-service.ts +++ b/app/services/help-service.ts @@ -26,5 +26,8 @@ export var NODE_DESCRIPTIONS = { from the index and do not read from the corresponding table.`, 'BITMAP HEAP SCAN': 'searches through the pages returned by the Bitmap Index Scan for relevant rows.', 'BITMAP INDEX SCAN': `uses a Bitmap Index (index which uses 1 bit per page) to find all relevant pages. - Results of this node are fed to the Bitmap Heap Scan.` + Results of this node are fed to the Bitmap Heap Scan.`, + 'CTE SCAN': `performs a sequential scan of Common Table Expression (CTE) query results. Note that + results of a CTE are materialized (calculated and temporarily stored).` + }; diff --git a/app/services/plan-service.ts b/app/services/plan-service.ts index e634f64..c34a52a 100644 --- a/app/services/plan-service.ts +++ b/app/services/plan-service.ts @@ -36,6 +36,9 @@ export class PlanService { PLANNER_ESTIMATE_FACTOR: string = '*Planner Row Estimate Factor'; PLANNER_ESIMATE_DIRECTION: string = '*Planner Row Estimate Direction'; + CTE_SCAN_PROP = 'CTE Scan'; + CTE_NAME_PROP = 'CTE Name'; + ARRAY_INDEX_KEY: string = 'arrayIndex'; PEV_PLAN_TAG: string = 'plan_'; @@ -159,9 +162,15 @@ export class PlanService { node[this.ACTUAL_DURATION_PROP] = node[this.ACTUAL_TOTAL_TIME_PROP]; node[this.ACTUAL_COST_PROP] = node[this.TOTAL_COST_PROP]; + console.log (node); _.each(node.Plans, subPlan => { - node[this.ACTUAL_DURATION_PROP] = node[this.ACTUAL_DURATION_PROP] - subPlan[this.ACTUAL_TOTAL_TIME_PROP]; - node[this.ACTUAL_COST_PROP] = node[this.ACTUAL_COST_PROP] - subPlan[this.TOTAL_COST_PROP]; + console.log('processing chldren', subPlan) + // since CTE scan duration is already included in its subnodes, it should be be + // subtracted from the duration of this node + if (subPlan[this.NODE_TYPE_PROP] !== this.CTE_SCAN_PROP) { + node[this.ACTUAL_DURATION_PROP] = node[this.ACTUAL_DURATION_PROP] - subPlan[this.ACTUAL_TOTAL_TIME_PROP]; + node[this.ACTUAL_COST_PROP] = node[this.ACTUAL_COST_PROP] - subPlan[this.TOTAL_COST_PROP]; + } }); if (node[this.ACTUAL_COST_PROP] < 0) { -- cgit v1.2.3