From ac38a245ef2bd62a6d7dd1966b6cca349ab6173b Mon Sep 17 00:00:00 2001 From: Pierre GIRAUD Date: Fri, 26 Jun 2020 15:23:41 +0200 Subject: [PATCH] Don't try to parse plans without analyze nor costs Nodes should always have parenthesis Avoids extra infos to be parsed as nodes --- .../__tests__/08-plan-without-cost.spec.ts | 4 +-- .../1-parse-error-line-break.spec.ts | 5 +++- src/services/__tests__/plan-service.spec.ts | 25 +++++++++++++++++++ src/services/plan-service.ts | 2 +- 4 files changed, 32 insertions(+), 4 deletions(-) diff --git a/src/services/__tests__/08-plan-without-cost.spec.ts b/src/services/__tests__/08-plan-without-cost.spec.ts index c589cbbc..2ae5ec7c 100644 --- a/src/services/__tests__/08-plan-without-cost.spec.ts +++ b/src/services/__tests__/08-plan-without-cost.spec.ts @@ -16,7 +16,7 @@ Seq Scan on pg_class (actual time=0.013..0.181 rows=645 loops=1) describe('PlanService', () => { - test('Can parse plan without analyze nor costs', () => { + test('Cannot parse plan without analyze nor costs', () => { const planService = new PlanService(); const source = ` Bitmap Heap Scan on a @@ -27,6 +27,6 @@ Bitmap Heap Scan on a -> Bitmap Index Scan on a_pkey Index Cond: (id = 4711) `; - const r: any = planService.fromSource(source); + expect(() => { planService.fromText(source); }).toThrow(); }); }); diff --git a/src/services/__tests__/1-parse-error-line-break.spec.ts b/src/services/__tests__/1-parse-error-line-break.spec.ts index e6fee4bc..4114de13 100644 --- a/src/services/__tests__/1-parse-error-line-break.spec.ts +++ b/src/services/__tests__/1-parse-error-line-break.spec.ts @@ -1,4 +1,5 @@ import { PlanService } from '@/services/plan-service'; +import { IPlan } from '@/iplan'; describe('PlanService', () => { test('Can`t parse plan with line break', () => { @@ -18,7 +19,9 @@ Nested Loop Left Join (cost=11.95..28.52 rows=5 width=157) (actual time=0.010.. here is a line break Planning Time: 1.110 ms Execution Time: 0.170 ms`; - expect(() => { planService.fromText(source); }).toThrow(); + const r: any = planService.fromSource(source); + const plan: IPlan = planService.createPlan('', r, ''); + expect(plan.content['Planning Time']).toBe(1.11); }); }); diff --git a/src/services/__tests__/plan-service.spec.ts b/src/services/__tests__/plan-service.spec.ts index abd9bd42..3ace5202 100644 --- a/src/services/__tests__/plan-service.spec.ts +++ b/src/services/__tests__/plan-service.spec.ts @@ -229,4 +229,29 @@ Result (cost=0.31..0.32 rows=1 width=4) expect(r.Plan.Plans[0]['Shared Hit Blocks']).toEqual(16230); expect(r.Plan.Plans[0]['Shared Read Blocks']).toEqual(67104); }); + + test('doesn\'t parse delete target tables as nodes', () => { + const planService = new PlanService(); + const source = ` +Delete on stock (cost=1748.14..26203.41 rows=1159930 width=12) (actual time=19.228..19.228 rows=0 loops=1) + Delete on stock_2001 + Delete on stock_2002 + -> Merge Join (cost=1748.14..5240.68 rows=231986 width=12) (actual time=6.337..6.337 rows=0 loops=1) + Merge Cond: (tannee.annee = stock_2001.annee) + -> Sort (cost=179.78..186.16 rows=2550 width=10) (actual time=0.032..0.032 rows=1 loops=1) + Sort Key: tannee.annee + Sort Method: quicksort Memory: 25kB + -> Seq Scan on tannee (cost=0.00..35.50 rows=2550 width=10) (actual time=0.020..0.021 rows=1 loops=1) + -> Sort (cost=1568.36..1613.85 rows=18195 width=10) (actual time=6.301..6.301 rows=1 loops=1) + Sort Key: stock_2001.annee + Sort Method: quicksort Memory: 1621kB + -> Seq Scan on stock_2001 (cost=0.00..280.95 rows=18195 width=10) (actual time=0.015..3.241 rows=18195 loops=1) + -> Merge Join (cost=1748.14..5240.68 rows=231986 width=12) (actual time=3.002..3.003 rows=0 loops=1) + Merge Cond: (tannee.annee = stock_2002.annee) +Planning Time: 0.550 ms +Execution Time: 19.475 ms +`; + const r: any = planService.fromSource(source); + expect(r.Plan.Plans[1]['Node Type']).toBe('Merge Join'); + }); }); diff --git a/src/services/plan-service.ts b/src/services/plan-service.ts index 1e4c42ce..d81cff87 100644 --- a/src/services/plan-service.ts +++ b/src/services/plan-service.ts @@ -423,7 +423,7 @@ export class PlanService { nonCapturingGroupOpen + estimationRegex + nonCapturingGroupClose + '|' + nonCapturingGroupOpen + openParenthesisRegex + actualRegex + closeParenthesisRegex + nonCapturingGroupClose + - nonCapturingGroupClose + '*' + + nonCapturingGroupClose + '\\s*$', 'gm', );