From f51e22501d1b26b4ca33b5619965f9214bc60f9c 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 | 13 +++++++++++++ src/services/plan-service.ts | 2 +- 3 files changed, 15 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() + 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] }