Why should I care about SQL, if I have ORM?

Slides:



Advertisements
Similar presentations
Object Relational Mapping A to Z. About Me Over A Decade of I.T. Experience Web Developer, DBA, DevOps, Mobile Microsoft Cert. in SQL Server Twitter:
Advertisements

Entity Framework Code First End to End
Eric Nelson (or )
Windows Azure Tour Benjamin Day Benjamin Day Consulting, Inc.
Meta Data Cardinality Explored CSSQLUG User Group - June 2009.
Technology Drill Down: Windows Azure Platform Eric Nelson | ISV Application Architect | Microsoft UK |
How to kill SQL Server Performance Håkan Winther.
What is Data Science and Who is Data Scientist
Deadlocks 3.0. Final Edition. Everything that developer needs to know Denis Reznik Microsoft SQL Server MVP Director of R&D at Intapp Kyiv.
SQL Server Deep Dive Denis Reznik Data Architect at Intapp.
Thank you to our AWESOME sponsors!
SQL Server Performance Tuning
Building Enterprise Applications Using Visual Studio®
Denis Reznik Data Architect, Intapp, Inc. Microsoft Data Platform MVP
Parameter Sniffing in SQL Server Stored Procedures
5/15/2018 © 2014 Microsoft Corporation. All rights reserved. Microsoft, Windows, and other product names are or may be registered trademarks and/or trademarks.
Query Optimization Techniques
Thank You! #sqlsatdnipro Denis
Stored Procedures – Facts and Myths
Data Virtualization Demoette… ADO.NET Client
Power Query Tips & Tricks
T-SQL Coding Techniques Are you playing with fire?
Parameter Sniffing in SQL Server Stored Procedures
Did your feature got in, out or planned?
Building Single Page Applications (SPAs) in SharePoint with JavaScript
Learn. Imagine. Build. .NET Conf
ADO.NET Entity Framework
Query Execution Expectation-Reality Denis Reznik
The Ins and Outs of Indexes
Marcos Freccia Stop everything! Top T-SQL tricks to a developer
The Ins and Outs of Indexes
ORMs and the DBA How to Make Both Happy.
Query Optimization Techniques
It’s Always a Hard Choice
SQL Server Mythconceptions And Mythteries
Entity Framework Core.
Everything you ever wanted to ask but were too shy
SQL Server 2014 Hidden Treasures Denis Reznik Microsoft SQL Server MVP
Hidden Gems of SQL Server 2014
Hidden gems of SQL Server 2016
The Ins and Outs of Indexes
TEMPDB – INTERNALS AND USAGE
New Paradigm for Performance Tuning in SQL Server 2016
Entity Framework from a database perspective
SQL Server Performance Tuning Nowadays
SQL Server Mythconceptions And Mythteries
ORMs and the DBA How to Make Both Happy.
How to Use Parameters Like a Pro
Hidden Gems of SQL Server 2016
Parameter Sniffing: the Good, the Bad, and the Ugly
Hidden Gems of SQL Server 2014
SQL Server Management Studio Tips and Tricks
ORMs and the DBA How to Make Both Happy.
Parameter Sniffing on SQL Server
Parameter Sniffing: the Good, the Bad, and the Ugly
SQL Server Reporting Services 2017 on Steroids!!
Power Query Tips & Tricks
Deadlocks Everything you ever wanted to ask but were too shy
Hidden Gems of SQL Server 2014
The Ins and Outs of Indexes
Hidden Gems of SQL Server 2014
SQL Server Query Design and Optimization Recommendations
A Micro-ORM for the Discerning Developer
Query Optimization Techniques
Data Access in Your Code Thinking Outside the Framework
Denis Reznik SQL Server 2017 Hidden Gems.
Visual Studio 2010 and .NET Framework 4 Training Workshop
.NET Framework V3.5+ & RESTful web services
The Ins and Outs of Indexes
Denis Reznik SQL Server 2017 Hidden Gems.
Presentation transcript:

Why should I care about SQL, if I have ORM? Denis Reznik Why should I care about SQL, if I have ORM?

Thank you to our AWESOME sponsors!

About Me Denis Reznik Kyiv, Ukraine Data Architect at Intapp, Inc. Microsoft Data Platform MVP Co-Founder of Ukrainian Data Community Kyiv (PASS Chapter) PASS Regional Mentor, Central and Eastern Europe Co-author of “SQL Server MVP Deep Dives vol. 2”

Agenda .Net ORM History (how I remember it) Simple Queries Column List Lazy Load Data Types Data Modification Complex Query Parameter Sniffing The Main Thing to Keep in Mind

ORM History which I remember ADO.NET Data Sets (not too bad) LLBL Gen, NHibernate (better than data sets) LINQ to SQL (Awesome!) Entity Framework. Should be even more awesome! Entity Framework is more powerful than L2S Entity Framework Code First Entity Framework is not so good? So what?

Simple Query SELECT * FROM Users WHERE Id = 1

Simple Query Demo

Column List

Column List Demo

Lazy Load

… … Index Seek SELECT * FROM Users WHERE Id = 523 1 .. 1M 2K+1 .. 4K 1M-2K .. 1M … 1 .. 300 301 .. 800 801 .. 1,5K 1,5K+1 .. 2K …

… … Index Range Scan SELECT * FROM Users WHERE Id BETWEEN 700 AND 1700 1 .. 2K 2K+1 .. 4K 1M-2K .. 1M … 1 .. 300 301 .. 800 801 .. 1,5K 1,5K+1 .. 2K …

… … Index Scan SELECT * FROM Users 1 .. 1M 2K+1 .. 4K 1M-2K .. 1M 1 .. 300 301 .. 800 801 .. 1,5K 1,5K+1 .. 2K …

Can Scan Outperform Seek? SELECT user_id FROM Statuses WHERE user_id < 2000 … Leaf-Level Rows: 1059640 Leaf-Level Pages: 2970 Rows on Page (Avg): 356 Index Depth: 3 One Page Seek: 356*3= 1068 1068*3=3204 > 2870 => Row by Row Seek of 3 pages is heavier than full index scan (For this concrete case)

Lazy Load Demo

Data Types

Data Types Demo

Data Modification

Data Modification Demo

Complex Query

What does it mean “Complex Query” ?

What does it mean “Complex Query” ?

Complex Query Demo

Parameter Sniffing

Parameter Sniffing - Stored Procedure Query Processor EXEC ReportSecurityPermissions @UserId = 1 EXEC ReportSecurityPermissions @UserId = 22 SQL Server Cache Procedure cache Procedure cache Query executes using the query plan created for @UserId = 1 Plan created and cached for the @UserId = 1

Parameter Sniffing - Parametrized Query Query Processor sp_executesql N'SELECT * FROM Users WHERE Id = @Id', N'@Id int', 1 SELECT * FROM Users WHERE Id = @Id SELECT * FROM Users WHERE Id = @Id sp_executesql N'SELECT * FROM Users WHERE Id = @Id', N'@Id int', 22 SQL Server Cache Procedure cache Procedure cache Plan created and cached for the @Id = 1 Query executes using the query plan created for @Id = 1

Dynamic SQL – Multiple Plans Query Processor SELECT * FROM Users WHERE Id = 1 SELECT * FROM Users WHERE Id = 22 SQL Server Cache SELECT * FROM Users WHERE Id = 1 Procedure cache Procedure cache Procedure cache Query executed using the query plan, created for the first query. New query plan created and cached. Query executed using newly created plan. New query plan again created and cached. Query executed using newly created plan.

Parameter Sniffing Demo

The Main Thing to Keep in Mind

Life without ORM (Entity Framework) Some Magic Query Result Set 32 |

Life with ORM (Entity Framework) Some Magic Application Code SQL Query Some Magic Result Set 33 |

Life with micro-ORM (Dapper) Some Magic Query Result Set 34 |

Summary ORM is really nice tool But it still requires strong SQL Server background Databases and ORMs are changing very fast Few Advices Sometimes check the generated SQL and its query plan For complex queries consider raw SQL anyway Consider using Dapper Invest your time to learn database internals ORM should not save you from learning SQL and SQL Server

Thank You! Denis Reznik Twitter: @denisreznik Email: denisreznik@gmail.com Blog: http://reznik.uneta.com.ua Facebook: https://www.facebook.com/denis.reznik.5 LinkedIn: http://ua.linkedin.com/pub/denis-reznik/3/502/234