NAYA Technologies




COMMON ERRORS THAT SLOW
      THE SERVER
TYPE OF ERRORS

  1. Misunderstanding parameter sniffing
  2. Using batches instead of procedures
  3. Using wrong temporary objects
  4. Using to long columns
WHAT IS PARAMETER SNIFING?
 • When SQL Server creates a query plan for a
   procedure, it uses the parameters’ values
   to create the proper query plan
MISUNDERSTANDING PARAMETER SNIFING
 • This behavior can lead to the fallowing
   problems:
   – Sometimes different values need different
     plans
   – The query plan is according to the values that
     were passed and not according to the values
     during runtime
Demo 1
 • Parameter sniffing
   – Working with procedures that different value
     should use different plans.
   – Avoiding modifying procedure’s parameters
     during runtime.
Using batch instead of procedures
BATCH VS. PROCEDURE

  • Batch might have a different and none optimal
    query plan then a stored procedure.
  • Batches might bloat the cache memory.
DEMO 2

• Demo 2
  – Difference in query plan between batch and stored procedure

  – Procedure cache and stored procedures and batches
USING WRONG TEMPORARY OBJECTS
 • SQL Server has 2 types of objects that store
   temporary data:
   – Temporary tables
   – Table variables
 • The myth that table variable is better then
   temporary table because it exists only in
   memory and never written to the disk is
   not true
TABLE VARIABLE VS. TEMPORARY TABLE
   • Some of the differences between table
     variable and temporary table are:
     – Temporary tables have statistics. Table
       variables don't. The server will always treat
       the table variable as if it has exactly 1 row
     – Inserting data into temporary tables cause
       recompilation. Inserting data into table
       variables doesn’t cause recompilation.
Demo 3
  • Table variables, temporary tables and query
    plans
Using to long columns
  • SQL Server can use varying length columns
  • For columns with varying length, the server
    users the actual data length + 2 extra bytes
Using to long columns
  • Many times DBA are using to big size
    limitations on varying size columns
  • Using to big maximum size for a column can
    lead to memory problems and sometimes
    to different query plans
Demo 4
  • Influence of column’s maximum size on
    memory consumption and query plans

עדי

  • 1.
    NAYA Technologies COMMON ERRORSTHAT SLOW THE SERVER
  • 2.
    TYPE OF ERRORS 1. Misunderstanding parameter sniffing 2. Using batches instead of procedures 3. Using wrong temporary objects 4. Using to long columns
  • 3.
    WHAT IS PARAMETERSNIFING? • When SQL Server creates a query plan for a procedure, it uses the parameters’ values to create the proper query plan
  • 4.
    MISUNDERSTANDING PARAMETER SNIFING • This behavior can lead to the fallowing problems: – Sometimes different values need different plans – The query plan is according to the values that were passed and not according to the values during runtime
  • 5.
    Demo 1 •Parameter sniffing – Working with procedures that different value should use different plans. – Avoiding modifying procedure’s parameters during runtime.
  • 6.
    Using batch insteadof procedures
  • 7.
    BATCH VS. PROCEDURE • Batch might have a different and none optimal query plan then a stored procedure. • Batches might bloat the cache memory.
  • 8.
    DEMO 2 • Demo2 – Difference in query plan between batch and stored procedure – Procedure cache and stored procedures and batches
  • 9.
    USING WRONG TEMPORARYOBJECTS • SQL Server has 2 types of objects that store temporary data: – Temporary tables – Table variables • The myth that table variable is better then temporary table because it exists only in memory and never written to the disk is not true
  • 10.
    TABLE VARIABLE VS.TEMPORARY TABLE • Some of the differences between table variable and temporary table are: – Temporary tables have statistics. Table variables don't. The server will always treat the table variable as if it has exactly 1 row – Inserting data into temporary tables cause recompilation. Inserting data into table variables doesn’t cause recompilation.
  • 11.
    Demo 3 • Table variables, temporary tables and query plans
  • 12.
    Using to longcolumns • SQL Server can use varying length columns • For columns with varying length, the server users the actual data length + 2 extra bytes
  • 13.
    Using to longcolumns • Many times DBA are using to big size limitations on varying size columns • Using to big maximum size for a column can lead to memory problems and sometimes to different query plans
  • 14.
    Demo 4 • Influence of column’s maximum size on memory consumption and query plans