From 6d828d6761b6a43de9f8d4ee7f9c013babec9155 Mon Sep 17 00:00:00 2001 From: Pierre GIRAUD Date: Wed, 9 Oct 2024 17:07:09 +0200 Subject: [PATCH] Make sure cost is shown even when equaling 0 Fixes #634 --- src/components/PlanNodeDetail.vue | 2 +- src/services/__tests__/17-cost-0.00.spec.ts | 16 ++++++++++++++++ src/services/plan-service.ts | 2 +- 3 files changed, 18 insertions(+), 2 deletions(-) create mode 100644 src/services/__tests__/17-cost-0.00.spec.ts diff --git a/src/components/PlanNodeDetail.vue b/src/components/PlanNodeDetail.vue index ece979f5..857cd2a4 100644 --- a/src/components/PlanNodeDetail.vue +++ b/src/components/PlanNodeDetail.vue @@ -294,7 +294,7 @@ watch(activeTab, () => { }" > -
+
{ + test("Computes exclusive cost correctly", () => { + const planService = new PlanService() + + // tslint:disable:max-line-length + const source = `Seq Scan on atividade_economica ae (cost=0.00..0.00 rows=1 width=36)` + + const r = planService.fromSource(source) as IPlanContent + const plan: IPlan = planService.createPlan("", r, "") + const root = plan.content.Plan + root && expect(root["*Cost (exclusive)"]).toBe(0) + }) +}) diff --git a/src/services/plan-service.ts b/src/services/plan-service.ts index 12e3937f..e505654b 100644 --- a/src/services/plan-service.ts +++ b/src/services/plan-service.ts @@ -233,7 +233,7 @@ export class PlanService { node[NodeProp.EXCLUSIVE_DURATION] = duration > 0 ? duration : 0 } - if (node[NodeProp.TOTAL_COST]) { + if (!_.isUndefined(node[NodeProp.TOTAL_COST])) { node[NodeProp.EXCLUSIVE_COST] = node[NodeProp.TOTAL_COST] }