EP to SQL Compiler
-
Upload
ryan-marcus -
Category
Engineering
-
view
34 -
download
4
Transcript of EP to SQL Compiler
![Page 1: EP to SQL Compiler](https://reader030.fdocuments.in/reader030/viewer/2022020218/55a5d3971a28abf4148b45c3/html5/thumbnails/1.jpg)
Execution Plan Compiler
Brionne Godby Rachel Leeman-Munk
Ryan Marcus
![Page 2: EP to SQL Compiler](https://reader030.fdocuments.in/reader030/viewer/2022020218/55a5d3971a28abf4148b45c3/html5/thumbnails/2.jpg)
Motivation
● DevelOPs lets optimizers build execution plans
![Page 3: EP to SQL Compiler](https://reader030.fdocuments.in/reader030/viewer/2022020218/55a5d3971a28abf4148b45c3/html5/thumbnails/3.jpg)
Motivation
● DevelOPs lets optimizers build physical plans
● … but there’s no way of testing those plans!
![Page 4: EP to SQL Compiler](https://reader030.fdocuments.in/reader030/viewer/2022020218/55a5d3971a28abf4148b45c3/html5/thumbnails/4.jpg)
Motivation
● DevelOPs lets optimizers build physical plans
● … but there’s no way of testing those plans!
● Enter: EPtoSQL!
![Page 5: EP to SQL Compiler](https://reader030.fdocuments.in/reader030/viewer/2022020218/55a5d3971a28abf4148b45c3/html5/thumbnails/5.jpg)
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](https://reader030.fdocuments.in/reader030/viewer/2022020218/55a5d3971a28abf4148b45c3/html5/thumbnails/6.jpg)
DevelOPs Physical Plans
Merge Join
Loop Join
table1 table2
table3
![Page 7: EP to SQL Compiler](https://reader030.fdocuments.in/reader030/viewer/2022020218/55a5d3971a28abf4148b45c3/html5/thumbnails/7.jpg)
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](https://reader030.fdocuments.in/reader030/viewer/2022020218/55a5d3971a28abf4148b45c3/html5/thumbnails/8.jpg)
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](https://reader030.fdocuments.in/reader030/viewer/2022020218/55a5d3971a28abf4148b45c3/html5/thumbnails/9.jpg)
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](https://reader030.fdocuments.in/reader030/viewer/2022020218/55a5d3971a28abf4148b45c3/html5/thumbnails/10.jpg)
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](https://reader030.fdocuments.in/reader030/viewer/2022020218/55a5d3971a28abf4148b45c3/html5/thumbnails/11.jpg)
Translating Physical Plans
● Some complications○ Selection over join with same attributes○ Join over selection with same attributes
![Page 12: EP to SQL Compiler](https://reader030.fdocuments.in/reader030/viewer/2022020218/55a5d3971a28abf4148b45c3/html5/thumbnails/12.jpg)
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](https://reader030.fdocuments.in/reader030/viewer/2022020218/55a5d3971a28abf4148b45c3/html5/thumbnails/13.jpg)
Subexpression Elimination
Merge Join
Loop Join
table1 table2
table3
![Page 14: EP to SQL Compiler](https://reader030.fdocuments.in/reader030/viewer/2022020218/55a5d3971a28abf4148b45c3/html5/thumbnails/14.jpg)
Subexpression Elimination
Merge Join
Loop Join
table1 table2
table3
Merge Join
table3
#T1
![Page 15: EP to SQL Compiler](https://reader030.fdocuments.in/reader030/viewer/2022020218/55a5d3971a28abf4148b45c3/html5/thumbnails/15.jpg)
General Procedure
![Page 16: EP to SQL Compiler](https://reader030.fdocuments.in/reader030/viewer/2022020218/55a5d3971a28abf4148b45c3/html5/thumbnails/16.jpg)
General Procedure
Semantics after IR?
![Page 17: EP to SQL Compiler](https://reader030.fdocuments.in/reader030/viewer/2022020218/55a5d3971a28abf4148b45c3/html5/thumbnails/17.jpg)
General Procedure
Subexpression elimination
Semantics after IR?
![Page 18: EP to SQL Compiler](https://reader030.fdocuments.in/reader030/viewer/2022020218/55a5d3971a28abf4148b45c3/html5/thumbnails/18.jpg)
General Procedure
Subexpression elimination
Everything valid if each subexpression
valid
![Page 19: EP to SQL Compiler](https://reader030.fdocuments.in/reader030/viewer/2022020218/55a5d3971a28abf4148b45c3/html5/thumbnails/19.jpg)
GPL’d!
● Code on GitHub○ https://github.com/RyanMarcus/DevelOPSToSQLServerCompiler