Skip to content

Commit

Permalink
Merge pull request #229 from dalibo/plans-without-analyze-and-cost
Browse files Browse the repository at this point in the history
Don't try to parse plans without analyze nor costs
  • Loading branch information
pgiraud authored Jun 26, 2020
2 parents b0e4ca5 + ac38a24 commit 091932b
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/services/__tests__/08-plan-without-cost.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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();
});
});
5 changes: 4 additions & 1 deletion src/services/__tests__/1-parse-error-line-break.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { PlanService } from '@/services/plan-service';
import { IPlan } from '@/iplan';

describe('PlanService', () => {
test('Can`t parse plan with line break', () => {
Expand All @@ -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);
});

});
25 changes: 25 additions & 0 deletions src/services/__tests__/plan-service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});
});
2 changes: 1 addition & 1 deletion src/services/plan-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,7 @@ export class PlanService {
nonCapturingGroupOpen + estimationRegex + nonCapturingGroupClose +
'|' +
nonCapturingGroupOpen + openParenthesisRegex + actualRegex + closeParenthesisRegex + nonCapturingGroupClose +
nonCapturingGroupClose + '*' +
nonCapturingGroupClose +
'\\s*$',
'gm',
);
Expand Down

0 comments on commit 091932b

Please sign in to comment.