Presentation is loading. Please wait.

Presentation is loading. Please wait.

Q1 = SELECT [Project9].[ID] AS [ID],[Project9].[C1] AS [C1],[Project9].[C2] AS [C2],[Project9].[ID1] AS [ID1],[Project9].[SalesOrderID] AS [SalesOrderID],

Similar presentations


Presentation on theme: "Q1 = SELECT [Project9].[ID] AS [ID],[Project9].[C1] AS [C1],[Project9].[C2] AS [C2],[Project9].[ID1] AS [ID1],[Project9].[SalesOrderID] AS [SalesOrderID],"— Presentation transcript:

1 Q1 = SELECT [Project9].[ID] AS [ID],[Project9].[C1] AS [C1],[Project9].[C2] AS [C2],[Project9].[ID1] AS [ID1],[Project9].[SalesOrderID] AS [SalesOrderID], [Project9].[TotalDue] AS [TotalDue] FROM ( SELECT [Distinct1].[ID] AS [ID], 1 AS [C1], [Project8].[ID] AS [ID1], [Project8].[SalesOrderID] AS [SalesOrderID], [Project8].[TotalDue] AS [TotalDue], [Project8].[C1] AS [C2] FROM (SELECT DISTINCT [Extent1].[ID] AS [ID] (SELECT DISTINCT [Extent1].[ID] AS [ID] FROM [DBA].[Person] AS [Extent1] FROM [DBA].[Person] AS [Extent1] INNER JOIN [DBA].[Sales] AS [Extent2] INNER JOIN [DBA].[Sales] AS [Extent2] ON EXISTS (SELECT cast(1 as bit) AS [C1] FROM ( SELECT cast(1 as bit) AS X ) AS [SingleRowTable1] FROM ( SELECT cast(1 as bit) AS X ) AS [SingleRowTable1] LEFT OUTER JOIN (SELECT [Extent3].[ID] AS [ID] LEFT OUTER JOIN (SELECT [Extent3].[ID] AS [ID] FROM [DBA].[Person] AS [Extent3] WHERE [Extent2].[ID] = [Extent3].[ID] )AS [Project1] ON cast(1 as bit) = cast(1 as bit) FROM [DBA].[Person] AS [Extent3] WHERE [Extent2].[ID] = [Extent3].[ID] )AS [Project1] ON cast(1 as bit) = cast(1 as bit) LEFT OUTER JOIN (SELECT [Extent4].[ID] AS [ID] LEFT OUTER JOIN (SELECT [Extent4].[ID] AS [ID] FROM [DBA].[Person] AS [Extent4] WHERE [Extent2].[ID] = [Extent4].[ID] ) AS [Project2] ON cast(1 as bit) = cast(1 as bit) FROM [DBA].[Person] AS [Extent4] WHERE [Extent2].[ID] = [Extent4].[ID] ) AS [Project2] ON cast(1 as bit) = cast(1 as bit) WHERE ([Extent1].[ID] = [Project1].[ID]) OR (([Extent1].[ID] IS NULL) AND ([Project2].[ID] IS NULL)) ) WHERE ([Extent1].[ID] = [Project1].[ID]) OR (([Extent1].[ID] IS NULL) AND ([Project2].[ID] IS NULL)) ) ) AS [Distinct1] LEFT OUTER JOIN (SELECT [Extent5].[ID] AS [ID], [Extent6].[SalesOrderID] AS [SalesOrderID], [Extent6].[TotalDue] AS [TotalDue], 1 AS [C1] FROM [DBA].[Person] AS [Extent5] FROM [DBA].[Person] AS [Extent5] INNER JOIN [DBA].[Sales] AS [Extent6] INNER JOIN [DBA].[Sales] AS [Extent6] ON EXISTS (SELECT cast(1 as bit) AS [C1] ON EXISTS (SELECT cast(1 as bit) AS [C1] FROM ( SELECT cast(1 as bit) AS X ) AS [SingleRowTable2] FROM ( SELECT cast(1 as bit) AS X ) AS [SingleRowTable2] LEFT OUTER JOIN (SELECT [Extent9].[ID] AS [ID] LEFT OUTER JOIN (SELECT [Extent9].[ID] AS [ID] FROM [DBA].[Person] AS [Extent9] WHERE [Extent6].[ID] = [Extent9].[ID] )AS [Project5] ON cast(1 as bit) = cast(1 as bit) FROM [DBA].[Person] AS [Extent9] WHERE [Extent6].[ID] = [Extent9].[ID] )AS [Project5] ON cast(1 as bit) = cast(1 as bit) LEFT OUTER JOIN (SELECT [Extent8].[ID] AS [ID] LEFT OUTER JOIN (SELECT [Extent8].[ID] AS [ID] FROM [DBA].[Person] AS [Extent8] WHERE [Extent6].[ID] = [Extent8].[ID] )AS [Project6] ON cast(1 as bit) = cast(1 as bit) FROM [DBA].[Person] AS [Extent8] WHERE [Extent6].[ID] = [Extent8].[ID] )AS [Project6] ON cast(1 as bit) = cast(1 as bit) WHERE ([Extent5].[ID] = [Project5].[ID]) OR (([Extent5].[ID] IS NULL) AND ([Project6].[ID] IS NULL)) WHERE ([Extent5].[ID] = [Project5].[ID]) OR (([Extent5].[ID] IS NULL) AND ([Project6].[ID] IS NULL)) ) ) AS [Project8] ON ([Project8].[ID] = [Distinct1].[ID]) OR (([Project8].[ID] IS NULL) AND ([Distinct1].[ID] IS NULL)) ) AS [Project9] ORDER BY [Project9].[ID] ASC, [Project9].[C2] ASC Generated Queries: Object Relational Mapping (ORM)

2 W = SELECT DISTINCT [Extent1].[ID] AS [ID] W = SELECT DISTINCT [Extent1].[ID] AS [ID] FROM [DBA].[Person] AS [Extent1] FROM [DBA].[Person] AS [Extent1] INNER JOIN [DBA].[Sales] AS [Extent2] INNER JOIN [DBA].[Sales] AS [Extent2] ON EXISTS (SELECT cast(1 as bit) AS [C1] FROM ( SELECT cast(1 as bit) AS X ) AS [SingleRowTable1] FROM ( SELECT cast(1 as bit) AS X ) AS [SingleRowTable1] LEFT OUTER JOIN (SELECT [Extent3].[ID] AS [ID] LEFT OUTER JOIN (SELECT [Extent3].[ID] AS [ID] FROM [DBA].[Person] AS [Extent3] WHERE [Extent2].[ID] = [Extent3].[ID] )AS [Project1] ON cast(1 as bit) = cast(1 as bit) FROM [DBA].[Person] AS [Extent3] WHERE [Extent2].[ID] = [Extent3].[ID] )AS [Project1] ON cast(1 as bit) = cast(1 as bit) LEFT OUTER JOIN (SELECT [Extent4].[ID] AS [ID] LEFT OUTER JOIN (SELECT [Extent4].[ID] AS [ID] FROM [DBA].[Person] AS [Extent4] WHERE [Extent2].[ID] = [Extent4].[ID] ) AS [Project2] ON cast(1 as bit) = cast(1 as bit) FROM [DBA].[Person] AS [Extent4] WHERE [Extent2].[ID] = [Extent4].[ID] ) AS [Project2] ON cast(1 as bit) = cast(1 as bit) WHERE ([Extent1].[ID] = [Project1].[ID]) OR (([Extent1].[ID] IS NULL) AND ([Project2].[ID] IS NULL)) ) WHERE ([Extent1].[ID] = [Project1].[ID]) OR (([Extent1].[ID] IS NULL) AND ([Project2].[ID] IS NULL)) ) Q1 = SELECT [Project9].[ID] AS [ID],[Project9].[C1] AS [C1],[Project9].[C2] AS [C2],[Project9].[ID1] AS [ID1],[Project9].[SalesOrderID] AS [SalesOrderID],[Project9].[TotalDue] AS [TotalDue] FROM ( SELECT [Distinct1].[ID] AS [ID], 1 AS [C1], [Project8].[ID] AS [ID1], [Project8].[SalesOrderID] AS [SalesOrderID], [Project8].[TotalDue] AS [TotalDue], [Project8].[C1] AS [C2] ( FROM ( W ) AS [Distinct1] LEFT OUTER JOIN ( W ) AS [Project8] ON ([Project8].[ID] = [Distinct1].[ID]) OR (([Project8].[ID] IS NULL) AND ([Distinct1].[ID] IS NULL)) ) AS [Project9] ORDER BY [Project9].[ID] ASC, [Project9].[C2] ASC Generated Queries: ORM (cont.)

3 Q1 = select Extent6.ID as, 1 as C1, 1 as C2, Extent6.ID as ID1, Extent6.SalesOrderID as SalesOrderID, Extent6.TotalDue as TotalDue from DBA.Sales as Extent6 order by Extent6.ID as ID asc

4 ORM Very unique features different than human-written SQL queries: EXISTS(subquery) predicates in the ON clause Similar query blocks used in many FROM clauses Cannot change the application to simplify or generate better queries LOJ with exactly 1 row in the preserved side The join condition is inside the correlated derived table ON conditions of the form 1=1 Semantic transformations: 7 new semantic transformations implemented 1 patent select Distinct1.ID as ID as ID, 1 as C1 as C1, 1 as C1 as C2 as C2, Extent6.ID as ID as ID1 as ID1, Extent6.SalesOrderID as SalesOrderID as SalesOrderID as SalesOrderID, Extent6.TotalDue as TotalDue as TotalDue as TotalDue from(select distinct Extent2.ID as ID from DBA.Sales as Extent2) as Distinct1(ID) left outer join DBA.Sales as Extent6, on Extent6.ID as ID = Distinct1.ID order by Distinct1.ID as ID asc

5 Generated Queries: Hibernate Q2 = SELECT DISTINCT Device.ID,Device.Name FROM Device WHERE Device.ID IN (SELECT DISTINCT Device.ID FROM Device WHERE Device.ID IN (SELECT DISTINCT Device.ID FROM Device WHERE Device.ID IN (SELECT DISTINCT Device.ID FROM Device WHERE Device.ID IN (SELECT DISTINCT Device.ID FROM Device WHERE Device.ID IN (SELECT DISTINCT Device.ID FROM Device WHERE Device.ID IN (SELECT DISTINCT Device.ID FROM Device WHERE Device.ID IN (SELECT Device.ID FROM Device,Entry WHERE Device.dbId = Entry.dd AND UPPER(Entry.ss) LIKE '% %') OR Device.ID IN ( ( SELECT ID FROM Device WHERE ( UPPER(Device.sName) LIKE '%SSMC%' ) ) ) ) OR Device.ID IN ( ( SELECT ID FROM Device WHERE ( UPPER(Device.sName) LIKE '%SSTB%' ) ) ) ) OR Device.ID IN ( ( SELECT dcrDeviceId FROM Device WHERE ( UPPER(Device.sName) LIKE '%XHFH%' ) ) ) ) OR Device.ID IN ( ( SELECT ID FROM Device WHERE ( UPPER(Device.Name) LIKE '%SSTB%' ) ) ) ) OR Device.ID IN ( ( SELECT ID FROM Device WHERE ( UPPER(Device.Name) LIKE '%XHFH%' ) ) ) ) OR Device.ID IN ( ( SELECT Device.ID FROM Device,Entry WHERE ( ( Device.dbId = Entry.dd ) ) AND ( UPPER(Entry.ss) LIKE '% %' ) ) ) )

6 sq(c0,c1): select DISTINCT T.X from T where T.X IN (select T.X from T JOIN R where R.Y like c0) or T.X IN (select T.X from T where T.Y like c1) sq(co,c1,…,cn): select DISTINCT T.X from T where T.X IN ( sub(c0,c1,..,c(n-1)) ) or T.X IN (select T.X from T where T.Y like cn) sq('% %, '%SSMC%, '%SSTB%, '%XHFH%, '%SSTB%, '%XHFH%, '% %) Generated Queries: Hibernate (cont.)

7 Q2 = SELECT DISTINCT W0.ID,W0.Name FROM Device W0 WHERE ( W0.ID IS NOT NULL and ( W0.ID IN (SELECT W9.ID FROM Device W9,Entry WHERE W9.dbId = Entry.dd AND UPPER(Entry.ss) LIKE '% %') ) OR ( UPPER(W0.sName) LIKE '%SSMC%' ) OR ( UPPER(W0.sName) LIKE '%SSTB%' ) OR ( UPPER(W0.sName) LIKE '%XHFH%' ) OR (UPPER(W0.Name) LIKE '%SSTB%' ) OR (UPPER(W0.Name) LIKE '%XHFH%' ) OR W0.ID IN ( ( SELECT W12.ID FROM Device W12,Entry WHERE W12.dbId = Entry.dd AND UPPER(Entry.ss) LIKE '% %' ) Generated Queries: Hibernate (cont.)

8 8 New Optimizations WorkloadPlatfor m Comm# StmtsUnique Stmts DB Size Customer 1SolarisjConnect TCP/IP 30K1520 MB Customer 2CEESQL ShMem MB Customer 3Win32ODBC ShMem 13K37165 MB New optimizations cheap queries could be 2-3 times slower Cheap requests doesnt mean simple queries: {cheap, expensive} X {simple, complex}

9 Cardinality estimation errors Errors in cardinality estimation for first joins: ,000,000 rows vs. 1,000 estimated rows 15min vs. 3s

10

11

12 SearchSpaceAnalyzer Anisoara Nica, Daniel S. Brotherston, David W. Hillis Extreme Visualization of Query Optimizer Search Spaces, ACM SIGMOD International Conference on Management of Data, SIGMOD 2009,

13 Anisoara Nica, Daniel S. Brotherston, David W. Hillis Extreme Visualization of Query Optimizer Search Spaces, ACM SIGMOD International Conference on Management of Data, SIGMOD 2009,


Download ppt "Q1 = SELECT [Project9].[ID] AS [ID],[Project9].[C1] AS [C1],[Project9].[C2] AS [C2],[Project9].[ID1] AS [ID1],[Project9].[SalesOrderID] AS [SalesOrderID],"

Similar presentations


Ads by Google