tobias ternstrom senior program manager lead sql server engine session code: dat405 itzik ben-gan...

Download Tobias Ternstrom Senior Program Manager Lead SQL Server Engine SESSION CODE: DAT405 Itzik Ben-Gan Mentor and Co-Founder Solid Quality Mentors

If you can't read please download the document

Upload: ellen-richards

Post on 18-Jan-2018

220 views

Category:

Documents


0 download

TRANSCRIPT

Tobias Ternstrom Senior Program Manager Lead SQL Server Engine SESSION CODE: DAT405 Itzik Ben-Gan Mentor and Co-Founder Solid Quality Mentors CREATE FUNCTION AS BIGINT) RETURNS TABLE AS RETURN WITH L0 AS(SELECT 1 AS c UNION ALL SELECT 1), L1 AS(SELECT 1 AS c FROM L0 AS A CROSS JOIN L0 AS B), L2 AS(SELECT 1 AS c FROM L1 AS A CROSS JOIN L1 AS B), L3 AS(SELECT 1 AS c FROM L2 AS A CROSS JOIN L2 AS B), L4 AS(SELECT 1 AS c FROM L3 AS A CROSS JOIN L3 AS B), L5 AS(SELECT 1 AS c FROM L4 AS A CROSS JOIN L4 AS B), Nums AS(SELECT ROW_NUMBER() OVER(ORDER BY (SELECT NULL)) AS n FROM L5) SELECT TOP n FROM Nums ORDER BY n; GO WITH Dates AS ( SELECT DATEADD(day, AS dt+ 1) AS Nums ), Groups AS ( SELECT D.dt, DATEADD(day, -1*DENSE_RANK() OVER(ORDER BY D.dt), D.dt) AS grp FROM dbo.Projects AS P JOIN Dates AS D ON D.dt BETWEEN P.start_date AND P.end_date ) SELECT MIN(dt) AS start_period, MAX(dt) AS end_period FROM Groups GROUP BY grp; Default result set Best possible Default optimization performed by QO is for throughput Cursor using Dynamic plan Not optimized for throughput May use a non-optimal plan Cursor using Static plan Uses the same plan as the Default result set but always adds extra spooling operation at the end decreasing throughput The stability of result sets vary Example: (using default isolation level) CREATE TABLE TestStability (RowNo INT NOT NULL PRIMARY KEY, Value INT NOT NULL); SELECT * FROM MyTable WHERE RowNo BETWEEN 1000 AND 4000 May see changes that occurred after the first row was returned by the query SELECT * FROM TestStability WHERE RowNo BETWEEN 1000 AND 4000 ORDER BY Value Will not be able to see changes that occurred after the first row was returned by the query SELECT Value, COUNT(*) FROM TestStability GROUP BY Value Will not be able to see changes that occurred after the first row was returned by the query Default result set Unpredictable, may or may not be sensitive Because of network buffer Because of stop & go operators in exec. plan Cursor using Dynamic plan Unpredictable, may or may not be sensitive Because of network buffer May degrade to static cursor Cursor using Static plan Stable, always insensitive to data changes (as of full population of temp. table) 3 Required Slide Track PMs will supply the content for this slide, which will be inserted during the final scrub. Sign up for TechEd 2011 and save $500 starting June 8 June 31 stYou can also register at the North America 2011 kiosk located at registration Join us in Atlanta next year