19
Execution Plan Compiler Brionne Godby Rachel Leeman-Munk Ryan Marcus

EP to SQL Compiler

Embed Size (px)

Citation preview

Page 1: EP to SQL Compiler

Execution Plan Compiler

Brionne Godby Rachel Leeman-Munk

Ryan Marcus

Page 2: EP to SQL Compiler

Motivation

● DevelOPs lets optimizers build execution plans

Page 3: EP to SQL Compiler

Motivation

● DevelOPs lets optimizers build physical plans

● … but there’s no way of testing those plans!

Page 4: EP to SQL Compiler

Motivation

● DevelOPs lets optimizers build physical plans

● … but there’s no way of testing those plans!

● Enter: EPtoSQL!

Page 5: EP to SQL Compiler

SQL Server

● Microsoft SQL Server lets you force join order○ OPTION(FORCE ORDER)

● And join types…○ SELECT * FROM t1 MERGE JOIN t2 ON ...

Page 6: EP to SQL Compiler

DevelOPs Physical Plans

Merge Join

Loop Join

table1 table2

table3

Page 7: EP to SQL Compiler

DevelOPs Physical Plans

Merge Join

Loop Join

table1 table2

table3

PMJOIN(attr1 = attr2, PNLJOIN(a3 = a4, PTABLE(table1), PTABLE(table2) ), PTABLE(table3))

Page 8: EP to SQL Compiler

Translating Physical PlansPMJOIN(attr1 = attr2, PNLJOIN(a3 = a4, PTABLE(table1), PTABLE(table2) ), PTABLE(table3))

SELECT * FROM table2INNER LOOP JOIN table1 ON a3 = a4 INNER MERGE JOIN table3 ON attr1 = attr2 OPTION(FORCE ORDER);

Page 9: EP to SQL Compiler

Translating Physical PlansPMJOIN(attr1 = attr2, PNLJOIN(a3 = a4, PTABLE(table1), PTABLE(table2) ), PTABLE(table3))

SELECT * FROM table2INNER LOOP JOIN table1 ON a3 = a4 INNER MERGE JOIN table3 ON attr1 = attr2 OPTION(FORCE ORDER);

Page 10: EP to SQL Compiler

Translating Physical PlansPMJOIN(attr1 = attr2, PNLJOIN(a3 = a4, PTABLE(table1), PTABLE(table2) ), PTABLE(table3))

SELECT * FROM table2INNER LOOP JOIN table1 ON a3 = a4 INNER MERGE JOIN table3 ON attr1 = attr2 OPTION(FORCE ORDER);

Page 11: EP to SQL Compiler

Translating Physical Plans

● Some complications○ Selection over join with same attributes○ Join over selection with same attributes

Page 12: EP to SQL Compiler

Translating Physical Plans

● Some complications○ Selection over join with same attributes○ Join over selection with same attributes

● Subexpression elimination

Page 13: EP to SQL Compiler

Subexpression Elimination

Merge Join

Loop Join

table1 table2

table3

Page 14: EP to SQL Compiler

Subexpression Elimination

Merge Join

Loop Join

table1 table2

table3

Merge Join

table3

#T1

Page 15: EP to SQL Compiler

General Procedure

Page 16: EP to SQL Compiler

General Procedure

Semantics after IR?

Page 17: EP to SQL Compiler

General Procedure

Subexpression elimination

Semantics after IR?

Page 18: EP to SQL Compiler

General Procedure

Subexpression elimination

Everything valid if each subexpression

valid

Page 19: EP to SQL Compiler

GPL’d!

● Code on GitHub○ https://github.com/RyanMarcus/DevelOPSToSQLServerCompiler