SlideShare a Scribd company logo
Topics
▪ Click to edit Master text styles
• Second level
• Third level
− Fourth level
• Fifth level
Faster Transactions:
Query Tuning
for Data Manipulation
Jeff Iannucci
Topics
▪ Click to edit Master text styles
• Second level
• Third level
− Fourth level
• Fifth level
2
Who in the world is Jeff Iannucci?
I live in Arizona, and I sell used cars!
Senior Database Administrator at DriveTime
SQL Server data professional since 1998
Topics
▪ Click to edit Master text styles
• Second level
• Third level
− Fourth level
• Fifth level
3
Who in the world is Jeff Iannucci?
@desertdba
jeff@desertdba.com
Topics
▪ Click to edit Master text styles
• Second level
• Third level
− Fourth level
• Fifth level
4
Performance tuning for…
UPDATE
INSERT
DELETE
…especially for large amounts of data
What is in this session?
Topics
▪ Click to edit Master text styles
• Second level
• Third level
− Fourth level
• Fifth level
5
Show WHAT commands help performance
Discuss WHEN to use these commands
Explain WHY the performance improves
What are the goals of this session?
Topics
▪ Click to edit Master text styles
• Second level
• Third level
− Fourth level
• Fifth level
6
But first…let’s talk about food!
Topics
▪ Click to edit Master text styles
• Second level
• Third level
− Fourth level
• Fifth level
7
The waiter writes down the order…
…and orders go in the ticket queue
Topics
▪ Click to edit Master text styles
• Second level
• Third level
− Fourth level
• Fifth level
8
The chef assembles the ingredients…
…gets any missing ingredients from pantry
Topics
▪ Click to edit Master text styles
• Second level
• Third level
− Fourth level
• Fifth level
9
The chef holds items while working…
…until your order is ready!
Topics
▪ Click to edit Master text styles
• Second level
• Third level
− Fourth level
• Fifth level
10
“Le SQL Server”
Your new favorite restaurant…
Topics
▪ Click to edit Master text styles
• Second level
• Third level
− Fourth level
• Fifth level
11
Transaction orders at “Le SQL Server”
Log Buffer Cache Transaction Log Buffer Cache Pages
Pages on Disk Lock
Topics
▪ Click to edit Master text styles
• Second level
• Third level
− Fourth level
• Fifth level
12
So…how can transactions go faster?
Read/write less data pages
Create less locks
Create less transaction log entries
Topics
▪ Click to edit Master text styles
• Second level
• Third level
− Fourth level
• Fifth level
13
What’s on the menu today?
Appetizers: Alter the target table
Entrees: Manipulate the transaction
Desserts: Modify the database settings
Topics
▪ Click to edit Master text styles
• Second level
• Third level
− Fourth level
• Fifth level
14
Appetizers: altering the target table
Topics
▪ Click to edit Master text styles
• Second level
• Third level
− Fourth level
• Fifth level
15
Let’s start with…
An INSERT
…into an empty table
…of sorted data
…that has no indexes
…(also known as a heap.)
Topics
▪ Click to edit Master text styles
• Second level
• Third level
− Fourth level
• Fifth level
16
Clustered Index instead of a Heap
Ordered data INSERTs faster than random data
…if the Clustered Index (CI) matches sort order
This works for INSERTs only
Topics
▪ Click to edit Master text styles
• Second level
• Third level
− Fourth level
• Fifth level
17
Clustered Index instead of a Heap
Topics
▪ Click to edit Master text styles
• Second level
• Third level
− Fourth level
• Fifth level
18
Clustered Index instead of a Heap
Should every table have a clustered index?
▪ Unsorted INSERTS are slower with a CI
▪ Only faster when CI matches sort order
▪ …but, temporary tables can have a CI
Topics
▪ Click to edit Master text styles
• Second level
• Third level
− Fourth level
• Fifth level
19
Now let’s try a bit of…
An UPDATE
…that has a clustered index
…to every record of a table
…and non-clustered indexes.
Topics
▪ Click to edit Master text styles
• Second level
• Third level
− Fourth level
• Fifth level
20
Disabling indexes
Reduces data pages manipulated
Disable Non-Clustered Indexes (NCIs) only
This works for INSERTs, UPDATEs, & DELETEs
Disable only NCIs with affected columns
Topics
▪ Click to edit Master text styles
• Second level
• Third level
− Fourth level
• Fifth level
21
Disabling indexes
Topics
▪ Click to edit Master text styles
• Second level
• Third level
− Fourth level
• Fifth level
22
Disabling indexes
Yes…but…
▪ REBUILDs take additional time
▪ NCIs are not used until they are rebuilt
▪ Clustered Index scans (temporarily)
Topics
▪ Click to edit Master text styles
• Second level
• Third level
− Fourth level
• Fifth level
23
Entrees: manipulating the transaction
Topics
▪ Click to edit Master text styles
• Second level
• Third level
− Fourth level
• Fifth level
24
Today let’s have…
A DELETE
…in a table with lots of records
…of a majority of data
…with lots of user connections
…so don’t slow their orders.
Topics
▪ Click to edit Master text styles
• Second level
• Third level
− Fourth level
• Fifth level
25
Batch using WHILE with TOP
Separates one transaction to many smaller ones
Minimal disruption to concurrent users
This works for INSERTs, UPDATEs, & DELETEs
Allows other processes to go faster (less slow)
Topics
▪ Click to edit Master text styles
• Second level
• Third level
− Fourth level
• Fifth level
26
Batch using WHILE with TOP
Topics
▪ Click to edit Master text styles
• Second level
• Third level
− Fourth level
• Fifth level
27
Batch using WHILE with TOP
What could go wrong?
▪ Could result in a slower query for you
▪ Will result in partial “transaction” if stopped
▪ Lock escalation occurs at 5000 locks
Topics
▪ Click to edit Master text styles
• Second level
• Third level
− Fourth level
• Fifth level
28
For RBAR dieters, try…
An UPDATE
…in a table with lots of records
…of much of the data
…but each row is updated
…in a separate transaction.
Topics
▪ Click to edit Master text styles
• Second level
• Third level
− Fourth level
• Fifth level
29
Explicit transaction
Reduces the pain of Row By Agonizing Row
Consolidates many transaction into one
This works for INSERTs, UPDATEs, & DELETEs
Use when concurrency is not a factor
Topics
▪ Click to edit Master text styles
• Second level
• Third level
− Fourth level
• Fifth level
30
Explicit transaction
Topics
▪ Click to edit Master text styles
• Second level
• Third level
− Fourth level
• Fifth level
31
Explicit transaction
The fine print:
▪ Locked resources during transaction
▪ Concurrent users wait for resources
▪ A bit like TABLOCK
Topics
▪ Click to edit Master text styles
• Second level
• Third level
− Fourth level
• Fifth level
32
What you really want is…
An INSERT
…into an empty table
…of sorted or unsorted data
…and make it fast as you can!
Topics
▪ Click to edit Master text styles
• Second level
• Third level
− Fourth level
• Fifth level
33
Minimally logged INSERT
Less records in the Transaction Log
Logging of page allocations, not record inserts
…because this locks the entire INSERT table
Use when no concurrent usage
Topics
▪ Click to edit Master text styles
• Second level
• Third level
− Fourth level
• Fifth level
34
What do you mean by “table lock”?
RECORD
LOCK
PAGE
LOCK
TABLE
LOCK
Topics
▪ Click to edit Master text styles
• Second level
• Third level
− Fourth level
• Fifth level
35
What do you mean by “page allocation”?
RECORD logging (default)
PAGE allocation logging
Topics
▪ Click to edit Master text styles
• Second level
• Third level
− Fourth level
• Fifth level
36
Some minimally-logged transaction rules
Database NOT in FULL recovery model
Table is not replicated
Table is not memory-optimized
Topics
▪ Click to edit Master text styles
• Second level
• Third level
− Fourth level
• Fifth level
37
Some minimally-logged transaction rules
Table has no indexes (is a heap), or…
…if the table has indexes then it must be empty
May require Trace Flag 610
https://docs.microsoft.com/en-us/sql/relational-databases/import-
export/prerequisites-for-minimal-logging-in-bulk-import?view=sql-server-ver15
Topics
▪ Click to edit Master text styles
• Second level
• Third level
− Fourth level
• Fifth level
38
Minimally logged INSERT
Topics
▪ Click to edit Master text styles
• Second level
• Third level
− Fourth level
• Fifth level
39
Minimally logged INSERT
The bad news:
▪ Concurrent users wait for resources
▪ Only uncommitted (“dirty”) reads
▪ Only works for INSERT, although…
Topics
▪ Click to edit Master text styles
• Second level
• Third level
− Fourth level
• Fifth level
40
Next you might enjoy…
A DELETE
…in a table with lots of records
…of a majority of data
…and make it fast
…like minimal logging!
Topics
▪ Click to edit Master text styles
• Second level
• Third level
− Fourth level
• Fifth level
41
Minimally logged DELETE
Wait…what?!?
Utilize minimally logged INSERTs - Twice!
(Not simultaneously, though)
Let’s lock TWO tables
Topics
▪ Click to edit Master text styles
• Second level
• Third level
− Fourth level
• Fifth level
42
Minimally logged DELETE
Topics
▪ Click to edit Master text styles
• Second level
• Third level
− Fourth level
• Fifth level
43
Minimally logged DELETE
So what’s the catch?
▪ Best for removing a majority of the data
▪ DISABLE/re-ENABLE constraints
▪ All the rules for minimal logging apply
Topics
▪ Click to edit Master text styles
• Second level
• Third level
− Fourth level
• Fifth level
44
Desserts: modifying database settings
Topics
▪ Click to edit Master text styles
• Second level
• Third level
− Fourth level
• Fifth level
45
What sounds good is…
An INSERT
…into an empty table
…of sorted or unsorted data
…in a database with FULL recovery model
…and gimme minimal logging!
Topics
▪ Click to edit Master text styles
• Second level
• Third level
− Fourth level
• Fifth level
46
Bulk Logged Recovery Model
Change recovery model to BULK_LOGGED
Utilize minimally-logged transactions
This works for INSERTs (and savvy DELETEs)
Does NOT break the backup chain!
Topics
▪ Click to edit Master text styles
• Second level
• Third level
− Fourth level
• Fifth level
47
Bulk Logged Recovery Model
Topics
▪ Click to edit Master text styles
• Second level
• Third level
− Fourth level
• Fifth level
48
Bulk Logged Recovery Model
Warning:
▪ ALL database transactions affected
▪ No Point-In-Time recovery
▪ Consult with your Database Administrator
Topics
▪ Click to edit Master text styles
• Second level
• Third level
− Fourth level
• Fifth level
49
Let’s boldly finish with…
A DELETE
…in a table with lots of records
…of a bunch of data
…for those on a RBAR diet.
Topics
▪ Click to edit Master text styles
• Second level
• Third level
− Fourth level
• Fifth level
50
Delayed Durability
Delays the hardening of transactions to log
Log Buffer Cache Work with data Then write to T-Log
Topics
▪ Click to edit Master text styles
• Second level
• Third level
− Fourth level
• Fifth level
51
Use with lots of small transactions
Delayed Durability
This works for INSERTs, UPDATEs, & DELETEs
Topics
▪ Click to edit Master text styles
• Second level
• Third level
− Fourth level
• Fifth level
52
Delayed Durability
Topics
▪ Click to edit Master text styles
• Second level
• Third level
− Fourth level
• Fifth level
53
Delayed Durability
Why isn’t everyone using this?
▪ Lost transactions if SQL Server stops
▪ Works best for lots of small transactions
▪ Consult with your Database Administrator
Topics
▪ Click to edit Master text styles
• Second level
• Third level
− Fourth level
• Fifth level
54
Let’s review the menu
Topics
▪ Click to edit Master text styles
• Second level
• Third level
− Fourth level
• Fifth level
55
Appetizers: Alter the target table
Query options INSERT UPDATE DELETE
Clustered index on a heap
Disable indexes
Topics
▪ Click to edit Master text styles
• Second level
• Third level
− Fourth level
• Fifth level
56
Entrees: Transaction manipulation
Query options INSERT UPDATE DELETE
Batching (WHILE with TOP)
Explicit transactions
Minimally logged INSERT
Minimally logged DELETE
Topics
▪ Click to edit Master text styles
• Second level
• Third level
− Fourth level
• Fifth level
57
Desserts: Database settings
Query options INSERT UPDATE DELETE
Bulk Logged recovery model
Delayed durability
Topics
▪ Click to edit Master text styles
• Second level
• Third level
− Fourth level
• Fifth level
58
And NOW…
Here is IDERA’s Rey Rios
with a demo of
SQL Diagnostic Manager…
Topics
▪ Click to edit Master text styles
• Second level
• Third level
− Fourth level
• Fifth level
59
What questions do you have?
Topics
▪ Click to edit Master text styles
• Second level
• Third level
− Fourth level
• Fifth level
60
That’s the end. Thank you!
jeff@desertdba.com
@desertdba

More Related Content

More from IDERA Software

The role of the database administrator (DBA) in 2020: Changes, challenges, an...
The role of the database administrator (DBA) in 2020: Changes, challenges, an...The role of the database administrator (DBA) in 2020: Changes, challenges, an...
The role of the database administrator (DBA) in 2020: Changes, challenges, an...
IDERA Software
 
Problems and solutions for migrating databases to the cloud
Problems and solutions for migrating databases to the cloudProblems and solutions for migrating databases to the cloud
Problems and solutions for migrating databases to the cloud
IDERA Software
 
Public cloud uses and limitations
Public cloud uses and limitationsPublic cloud uses and limitations
Public cloud uses and limitations
IDERA Software
 
Optimize the performance, cost, and value of databases.pptx
Optimize the performance, cost, and value of databases.pptxOptimize the performance, cost, and value of databases.pptx
Optimize the performance, cost, and value of databases.pptx
IDERA Software
 
Monitor cloud database with SQL Diagnostic Manager for SQL Server
Monitor cloud database with SQL Diagnostic Manager for SQL ServerMonitor cloud database with SQL Diagnostic Manager for SQL Server
Monitor cloud database with SQL Diagnostic Manager for SQL Server
IDERA Software
 
Database administrators (dbas) face increasing pressure to monitor databases
Database administrators (dbas) face increasing pressure to monitor databasesDatabase administrators (dbas) face increasing pressure to monitor databases
Database administrators (dbas) face increasing pressure to monitor databases
IDERA Software
 
Six tips for cutting sql server licensing costs
Six tips for cutting sql server licensing costsSix tips for cutting sql server licensing costs
Six tips for cutting sql server licensing costs
IDERA Software
 
Idera live 2021: The Power of Abstraction by Steve Hoberman
Idera live 2021:  The Power of Abstraction by Steve HobermanIdera live 2021:  The Power of Abstraction by Steve Hoberman
Idera live 2021: The Power of Abstraction by Steve Hoberman
IDERA Software
 
Idera live 2021: Why Data Lakes are Critical for AI, ML, and IoT By Brian Flug
Idera live 2021:  Why Data Lakes are Critical for AI, ML, and IoT  By Brian FlugIdera live 2021:  Why Data Lakes are Critical for AI, ML, and IoT  By Brian Flug
Idera live 2021: Why Data Lakes are Critical for AI, ML, and IoT By Brian Flug
IDERA Software
 
Idera live 2021: Will Data Vault add Value to Your Data Warehouse? 3 Signs th...
Idera live 2021: Will Data Vault add Value to Your Data Warehouse? 3 Signs th...Idera live 2021: Will Data Vault add Value to Your Data Warehouse? 3 Signs th...
Idera live 2021: Will Data Vault add Value to Your Data Warehouse? 3 Signs th...
IDERA Software
 
Idera live 2021: Managing Digital Transformation on a Budget by Bert Scalzo
Idera live 2021:  Managing Digital Transformation on a Budget by Bert ScalzoIdera live 2021:  Managing Digital Transformation on a Budget by Bert Scalzo
Idera live 2021: Managing Digital Transformation on a Budget by Bert Scalzo
IDERA Software
 
Idera live 2021: Keynote Presentation The Future of Data is The Data Cloud b...
Idera live 2021:  Keynote Presentation The Future of Data is The Data Cloud b...Idera live 2021:  Keynote Presentation The Future of Data is The Data Cloud b...
Idera live 2021: Keynote Presentation The Future of Data is The Data Cloud b...
IDERA Software
 
Idera live 2021: Managing Databases in the Cloud - the First Step, a Succes...
Idera live 2021:   Managing Databases in the Cloud - the First Step, a Succes...Idera live 2021:   Managing Databases in the Cloud - the First Step, a Succes...
Idera live 2021: Managing Databases in the Cloud - the First Step, a Succes...
IDERA Software
 
Idera live 2021: Database Auditing - on-Premises and in the Cloud by Craig M...
Idera live 2021:  Database Auditing - on-Premises and in the Cloud by Craig M...Idera live 2021:  Database Auditing - on-Premises and in the Cloud by Craig M...
Idera live 2021: Database Auditing - on-Premises and in the Cloud by Craig M...
IDERA Software
 
Idera live 2021: Performance Tuning Azure SQL Database by Monica Rathbun
Idera live 2021:  Performance Tuning Azure SQL Database by Monica RathbunIdera live 2021:  Performance Tuning Azure SQL Database by Monica Rathbun
Idera live 2021: Performance Tuning Azure SQL Database by Monica Rathbun
IDERA Software
 
Geek Sync | How to Be the DBA When You Don't Have a DBA - Eric Cobb | IDERA
Geek Sync | How to Be the DBA When You Don't Have a DBA - Eric Cobb | IDERAGeek Sync | How to Be the DBA When You Don't Have a DBA - Eric Cobb | IDERA
Geek Sync | How to Be the DBA When You Don't Have a DBA - Eric Cobb | IDERA
IDERA Software
 
How Users of a Performance Monitoring Tool Can Benefit from an Inventory Mana...
How Users of a Performance Monitoring Tool Can Benefit from an Inventory Mana...How Users of a Performance Monitoring Tool Can Benefit from an Inventory Mana...
How Users of a Performance Monitoring Tool Can Benefit from an Inventory Mana...
IDERA Software
 
Benefits of Third Party Tools for MySQL | IDERA
Benefits of Third Party Tools for MySQL | IDERABenefits of Third Party Tools for MySQL | IDERA
Benefits of Third Party Tools for MySQL | IDERA
IDERA Software
 
Achieve More with Less Resources | IDERA
Achieve More with Less Resources | IDERAAchieve More with Less Resources | IDERA
Achieve More with Less Resources | IDERA
IDERA Software
 
Benefits of SQL Server 2017 and 2019 | IDERA
Benefits of SQL Server 2017 and 2019 | IDERABenefits of SQL Server 2017 and 2019 | IDERA
Benefits of SQL Server 2017 and 2019 | IDERA
IDERA Software
 

More from IDERA Software (20)

The role of the database administrator (DBA) in 2020: Changes, challenges, an...
The role of the database administrator (DBA) in 2020: Changes, challenges, an...The role of the database administrator (DBA) in 2020: Changes, challenges, an...
The role of the database administrator (DBA) in 2020: Changes, challenges, an...
 
Problems and solutions for migrating databases to the cloud
Problems and solutions for migrating databases to the cloudProblems and solutions for migrating databases to the cloud
Problems and solutions for migrating databases to the cloud
 
Public cloud uses and limitations
Public cloud uses and limitationsPublic cloud uses and limitations
Public cloud uses and limitations
 
Optimize the performance, cost, and value of databases.pptx
Optimize the performance, cost, and value of databases.pptxOptimize the performance, cost, and value of databases.pptx
Optimize the performance, cost, and value of databases.pptx
 
Monitor cloud database with SQL Diagnostic Manager for SQL Server
Monitor cloud database with SQL Diagnostic Manager for SQL ServerMonitor cloud database with SQL Diagnostic Manager for SQL Server
Monitor cloud database with SQL Diagnostic Manager for SQL Server
 
Database administrators (dbas) face increasing pressure to monitor databases
Database administrators (dbas) face increasing pressure to monitor databasesDatabase administrators (dbas) face increasing pressure to monitor databases
Database administrators (dbas) face increasing pressure to monitor databases
 
Six tips for cutting sql server licensing costs
Six tips for cutting sql server licensing costsSix tips for cutting sql server licensing costs
Six tips for cutting sql server licensing costs
 
Idera live 2021: The Power of Abstraction by Steve Hoberman
Idera live 2021:  The Power of Abstraction by Steve HobermanIdera live 2021:  The Power of Abstraction by Steve Hoberman
Idera live 2021: The Power of Abstraction by Steve Hoberman
 
Idera live 2021: Why Data Lakes are Critical for AI, ML, and IoT By Brian Flug
Idera live 2021:  Why Data Lakes are Critical for AI, ML, and IoT  By Brian FlugIdera live 2021:  Why Data Lakes are Critical for AI, ML, and IoT  By Brian Flug
Idera live 2021: Why Data Lakes are Critical for AI, ML, and IoT By Brian Flug
 
Idera live 2021: Will Data Vault add Value to Your Data Warehouse? 3 Signs th...
Idera live 2021: Will Data Vault add Value to Your Data Warehouse? 3 Signs th...Idera live 2021: Will Data Vault add Value to Your Data Warehouse? 3 Signs th...
Idera live 2021: Will Data Vault add Value to Your Data Warehouse? 3 Signs th...
 
Idera live 2021: Managing Digital Transformation on a Budget by Bert Scalzo
Idera live 2021:  Managing Digital Transformation on a Budget by Bert ScalzoIdera live 2021:  Managing Digital Transformation on a Budget by Bert Scalzo
Idera live 2021: Managing Digital Transformation on a Budget by Bert Scalzo
 
Idera live 2021: Keynote Presentation The Future of Data is The Data Cloud b...
Idera live 2021:  Keynote Presentation The Future of Data is The Data Cloud b...Idera live 2021:  Keynote Presentation The Future of Data is The Data Cloud b...
Idera live 2021: Keynote Presentation The Future of Data is The Data Cloud b...
 
Idera live 2021: Managing Databases in the Cloud - the First Step, a Succes...
Idera live 2021:   Managing Databases in the Cloud - the First Step, a Succes...Idera live 2021:   Managing Databases in the Cloud - the First Step, a Succes...
Idera live 2021: Managing Databases in the Cloud - the First Step, a Succes...
 
Idera live 2021: Database Auditing - on-Premises and in the Cloud by Craig M...
Idera live 2021:  Database Auditing - on-Premises and in the Cloud by Craig M...Idera live 2021:  Database Auditing - on-Premises and in the Cloud by Craig M...
Idera live 2021: Database Auditing - on-Premises and in the Cloud by Craig M...
 
Idera live 2021: Performance Tuning Azure SQL Database by Monica Rathbun
Idera live 2021:  Performance Tuning Azure SQL Database by Monica RathbunIdera live 2021:  Performance Tuning Azure SQL Database by Monica Rathbun
Idera live 2021: Performance Tuning Azure SQL Database by Monica Rathbun
 
Geek Sync | How to Be the DBA When You Don't Have a DBA - Eric Cobb | IDERA
Geek Sync | How to Be the DBA When You Don't Have a DBA - Eric Cobb | IDERAGeek Sync | How to Be the DBA When You Don't Have a DBA - Eric Cobb | IDERA
Geek Sync | How to Be the DBA When You Don't Have a DBA - Eric Cobb | IDERA
 
How Users of a Performance Monitoring Tool Can Benefit from an Inventory Mana...
How Users of a Performance Monitoring Tool Can Benefit from an Inventory Mana...How Users of a Performance Monitoring Tool Can Benefit from an Inventory Mana...
How Users of a Performance Monitoring Tool Can Benefit from an Inventory Mana...
 
Benefits of Third Party Tools for MySQL | IDERA
Benefits of Third Party Tools for MySQL | IDERABenefits of Third Party Tools for MySQL | IDERA
Benefits of Third Party Tools for MySQL | IDERA
 
Achieve More with Less Resources | IDERA
Achieve More with Less Resources | IDERAAchieve More with Less Resources | IDERA
Achieve More with Less Resources | IDERA
 
Benefits of SQL Server 2017 and 2019 | IDERA
Benefits of SQL Server 2017 and 2019 | IDERABenefits of SQL Server 2017 and 2019 | IDERA
Benefits of SQL Server 2017 and 2019 | IDERA
 

Recently uploaded

Fueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte WebinarFueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte Webinar
Zilliz
 
Programming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup SlidesProgramming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup Slides
Zilliz
 
GraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracyGraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracy
Tomaz Bratanic
 
Webinar: Designing a schema for a Data Warehouse
Webinar: Designing a schema for a Data WarehouseWebinar: Designing a schema for a Data Warehouse
Webinar: Designing a schema for a Data Warehouse
Federico Razzoli
 
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with SlackLet's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
shyamraj55
 
Ocean lotus Threat actors project by John Sitima 2024 (1).pptx
Ocean lotus Threat actors project by John Sitima 2024 (1).pptxOcean lotus Threat actors project by John Sitima 2024 (1).pptx
Ocean lotus Threat actors project by John Sitima 2024 (1).pptx
SitimaJohn
 
Artificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopmentArtificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopment
Octavian Nadolu
 
Nordic Marketo Engage User Group_June 13_ 2024.pptx
Nordic Marketo Engage User Group_June 13_ 2024.pptxNordic Marketo Engage User Group_June 13_ 2024.pptx
Nordic Marketo Engage User Group_June 13_ 2024.pptx
MichaelKnudsen27
 
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAUHCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
panagenda
 
AI 101: An Introduction to the Basics and Impact of Artificial Intelligence
AI 101: An Introduction to the Basics and Impact of Artificial IntelligenceAI 101: An Introduction to the Basics and Impact of Artificial Intelligence
AI 101: An Introduction to the Basics and Impact of Artificial Intelligence
IndexBug
 
Taking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdfTaking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdf
ssuserfac0301
 
June Patch Tuesday
June Patch TuesdayJune Patch Tuesday
June Patch Tuesday
Ivanti
 
Project Management Semester Long Project - Acuity
Project Management Semester Long Project - AcuityProject Management Semester Long Project - Acuity
Project Management Semester Long Project - Acuity
jpupo2018
 
Building Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and MilvusBuilding Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and Milvus
Zilliz
 
Best 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERPBest 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERP
Pixlogix Infotech
 
Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...
Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...
Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...
Jeffrey Haguewood
 
Presentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of GermanyPresentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of Germany
innovationoecd
 
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development ProvidersYour One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
akankshawande
 
Energy Efficient Video Encoding for Cloud and Edge Computing Instances
Energy Efficient Video Encoding for Cloud and Edge Computing InstancesEnergy Efficient Video Encoding for Cloud and Edge Computing Instances
Energy Efficient Video Encoding for Cloud and Edge Computing Instances
Alpen-Adria-Universität
 
OpenID AuthZEN Interop Read Out - Authorization
OpenID AuthZEN Interop Read Out - AuthorizationOpenID AuthZEN Interop Read Out - Authorization
OpenID AuthZEN Interop Read Out - Authorization
David Brossard
 

Recently uploaded (20)

Fueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte WebinarFueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte Webinar
 
Programming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup SlidesProgramming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup Slides
 
GraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracyGraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracy
 
Webinar: Designing a schema for a Data Warehouse
Webinar: Designing a schema for a Data WarehouseWebinar: Designing a schema for a Data Warehouse
Webinar: Designing a schema for a Data Warehouse
 
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with SlackLet's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
 
Ocean lotus Threat actors project by John Sitima 2024 (1).pptx
Ocean lotus Threat actors project by John Sitima 2024 (1).pptxOcean lotus Threat actors project by John Sitima 2024 (1).pptx
Ocean lotus Threat actors project by John Sitima 2024 (1).pptx
 
Artificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopmentArtificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopment
 
Nordic Marketo Engage User Group_June 13_ 2024.pptx
Nordic Marketo Engage User Group_June 13_ 2024.pptxNordic Marketo Engage User Group_June 13_ 2024.pptx
Nordic Marketo Engage User Group_June 13_ 2024.pptx
 
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAUHCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
 
AI 101: An Introduction to the Basics and Impact of Artificial Intelligence
AI 101: An Introduction to the Basics and Impact of Artificial IntelligenceAI 101: An Introduction to the Basics and Impact of Artificial Intelligence
AI 101: An Introduction to the Basics and Impact of Artificial Intelligence
 
Taking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdfTaking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdf
 
June Patch Tuesday
June Patch TuesdayJune Patch Tuesday
June Patch Tuesday
 
Project Management Semester Long Project - Acuity
Project Management Semester Long Project - AcuityProject Management Semester Long Project - Acuity
Project Management Semester Long Project - Acuity
 
Building Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and MilvusBuilding Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and Milvus
 
Best 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERPBest 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERP
 
Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...
Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...
Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...
 
Presentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of GermanyPresentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of Germany
 
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development ProvidersYour One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
 
Energy Efficient Video Encoding for Cloud and Edge Computing Instances
Energy Efficient Video Encoding for Cloud and Edge Computing InstancesEnergy Efficient Video Encoding for Cloud and Edge Computing Instances
Energy Efficient Video Encoding for Cloud and Edge Computing Instances
 
OpenID AuthZEN Interop Read Out - Authorization
OpenID AuthZEN Interop Read Out - AuthorizationOpenID AuthZEN Interop Read Out - Authorization
OpenID AuthZEN Interop Read Out - Authorization
 

Geek Sync | Faster Transactions: Query Tuning for Data Manipulation

  • 1. Topics ▪ Click to edit Master text styles • Second level • Third level − Fourth level • Fifth level Faster Transactions: Query Tuning for Data Manipulation Jeff Iannucci
  • 2. Topics ▪ Click to edit Master text styles • Second level • Third level − Fourth level • Fifth level 2 Who in the world is Jeff Iannucci? I live in Arizona, and I sell used cars! Senior Database Administrator at DriveTime SQL Server data professional since 1998
  • 3. Topics ▪ Click to edit Master text styles • Second level • Third level − Fourth level • Fifth level 3 Who in the world is Jeff Iannucci? @desertdba jeff@desertdba.com
  • 4. Topics ▪ Click to edit Master text styles • Second level • Third level − Fourth level • Fifth level 4 Performance tuning for… UPDATE INSERT DELETE …especially for large amounts of data What is in this session?
  • 5. Topics ▪ Click to edit Master text styles • Second level • Third level − Fourth level • Fifth level 5 Show WHAT commands help performance Discuss WHEN to use these commands Explain WHY the performance improves What are the goals of this session?
  • 6. Topics ▪ Click to edit Master text styles • Second level • Third level − Fourth level • Fifth level 6 But first…let’s talk about food!
  • 7. Topics ▪ Click to edit Master text styles • Second level • Third level − Fourth level • Fifth level 7 The waiter writes down the order… …and orders go in the ticket queue
  • 8. Topics ▪ Click to edit Master text styles • Second level • Third level − Fourth level • Fifth level 8 The chef assembles the ingredients… …gets any missing ingredients from pantry
  • 9. Topics ▪ Click to edit Master text styles • Second level • Third level − Fourth level • Fifth level 9 The chef holds items while working… …until your order is ready!
  • 10. Topics ▪ Click to edit Master text styles • Second level • Third level − Fourth level • Fifth level 10 “Le SQL Server” Your new favorite restaurant…
  • 11. Topics ▪ Click to edit Master text styles • Second level • Third level − Fourth level • Fifth level 11 Transaction orders at “Le SQL Server” Log Buffer Cache Transaction Log Buffer Cache Pages Pages on Disk Lock
  • 12. Topics ▪ Click to edit Master text styles • Second level • Third level − Fourth level • Fifth level 12 So…how can transactions go faster? Read/write less data pages Create less locks Create less transaction log entries
  • 13. Topics ▪ Click to edit Master text styles • Second level • Third level − Fourth level • Fifth level 13 What’s on the menu today? Appetizers: Alter the target table Entrees: Manipulate the transaction Desserts: Modify the database settings
  • 14. Topics ▪ Click to edit Master text styles • Second level • Third level − Fourth level • Fifth level 14 Appetizers: altering the target table
  • 15. Topics ▪ Click to edit Master text styles • Second level • Third level − Fourth level • Fifth level 15 Let’s start with… An INSERT …into an empty table …of sorted data …that has no indexes …(also known as a heap.)
  • 16. Topics ▪ Click to edit Master text styles • Second level • Third level − Fourth level • Fifth level 16 Clustered Index instead of a Heap Ordered data INSERTs faster than random data …if the Clustered Index (CI) matches sort order This works for INSERTs only
  • 17. Topics ▪ Click to edit Master text styles • Second level • Third level − Fourth level • Fifth level 17 Clustered Index instead of a Heap
  • 18. Topics ▪ Click to edit Master text styles • Second level • Third level − Fourth level • Fifth level 18 Clustered Index instead of a Heap Should every table have a clustered index? ▪ Unsorted INSERTS are slower with a CI ▪ Only faster when CI matches sort order ▪ …but, temporary tables can have a CI
  • 19. Topics ▪ Click to edit Master text styles • Second level • Third level − Fourth level • Fifth level 19 Now let’s try a bit of… An UPDATE …that has a clustered index …to every record of a table …and non-clustered indexes.
  • 20. Topics ▪ Click to edit Master text styles • Second level • Third level − Fourth level • Fifth level 20 Disabling indexes Reduces data pages manipulated Disable Non-Clustered Indexes (NCIs) only This works for INSERTs, UPDATEs, & DELETEs Disable only NCIs with affected columns
  • 21. Topics ▪ Click to edit Master text styles • Second level • Third level − Fourth level • Fifth level 21 Disabling indexes
  • 22. Topics ▪ Click to edit Master text styles • Second level • Third level − Fourth level • Fifth level 22 Disabling indexes Yes…but… ▪ REBUILDs take additional time ▪ NCIs are not used until they are rebuilt ▪ Clustered Index scans (temporarily)
  • 23. Topics ▪ Click to edit Master text styles • Second level • Third level − Fourth level • Fifth level 23 Entrees: manipulating the transaction
  • 24. Topics ▪ Click to edit Master text styles • Second level • Third level − Fourth level • Fifth level 24 Today let’s have… A DELETE …in a table with lots of records …of a majority of data …with lots of user connections …so don’t slow their orders.
  • 25. Topics ▪ Click to edit Master text styles • Second level • Third level − Fourth level • Fifth level 25 Batch using WHILE with TOP Separates one transaction to many smaller ones Minimal disruption to concurrent users This works for INSERTs, UPDATEs, & DELETEs Allows other processes to go faster (less slow)
  • 26. Topics ▪ Click to edit Master text styles • Second level • Third level − Fourth level • Fifth level 26 Batch using WHILE with TOP
  • 27. Topics ▪ Click to edit Master text styles • Second level • Third level − Fourth level • Fifth level 27 Batch using WHILE with TOP What could go wrong? ▪ Could result in a slower query for you ▪ Will result in partial “transaction” if stopped ▪ Lock escalation occurs at 5000 locks
  • 28. Topics ▪ Click to edit Master text styles • Second level • Third level − Fourth level • Fifth level 28 For RBAR dieters, try… An UPDATE …in a table with lots of records …of much of the data …but each row is updated …in a separate transaction.
  • 29. Topics ▪ Click to edit Master text styles • Second level • Third level − Fourth level • Fifth level 29 Explicit transaction Reduces the pain of Row By Agonizing Row Consolidates many transaction into one This works for INSERTs, UPDATEs, & DELETEs Use when concurrency is not a factor
  • 30. Topics ▪ Click to edit Master text styles • Second level • Third level − Fourth level • Fifth level 30 Explicit transaction
  • 31. Topics ▪ Click to edit Master text styles • Second level • Third level − Fourth level • Fifth level 31 Explicit transaction The fine print: ▪ Locked resources during transaction ▪ Concurrent users wait for resources ▪ A bit like TABLOCK
  • 32. Topics ▪ Click to edit Master text styles • Second level • Third level − Fourth level • Fifth level 32 What you really want is… An INSERT …into an empty table …of sorted or unsorted data …and make it fast as you can!
  • 33. Topics ▪ Click to edit Master text styles • Second level • Third level − Fourth level • Fifth level 33 Minimally logged INSERT Less records in the Transaction Log Logging of page allocations, not record inserts …because this locks the entire INSERT table Use when no concurrent usage
  • 34. Topics ▪ Click to edit Master text styles • Second level • Third level − Fourth level • Fifth level 34 What do you mean by “table lock”? RECORD LOCK PAGE LOCK TABLE LOCK
  • 35. Topics ▪ Click to edit Master text styles • Second level • Third level − Fourth level • Fifth level 35 What do you mean by “page allocation”? RECORD logging (default) PAGE allocation logging
  • 36. Topics ▪ Click to edit Master text styles • Second level • Third level − Fourth level • Fifth level 36 Some minimally-logged transaction rules Database NOT in FULL recovery model Table is not replicated Table is not memory-optimized
  • 37. Topics ▪ Click to edit Master text styles • Second level • Third level − Fourth level • Fifth level 37 Some minimally-logged transaction rules Table has no indexes (is a heap), or… …if the table has indexes then it must be empty May require Trace Flag 610 https://docs.microsoft.com/en-us/sql/relational-databases/import- export/prerequisites-for-minimal-logging-in-bulk-import?view=sql-server-ver15
  • 38. Topics ▪ Click to edit Master text styles • Second level • Third level − Fourth level • Fifth level 38 Minimally logged INSERT
  • 39. Topics ▪ Click to edit Master text styles • Second level • Third level − Fourth level • Fifth level 39 Minimally logged INSERT The bad news: ▪ Concurrent users wait for resources ▪ Only uncommitted (“dirty”) reads ▪ Only works for INSERT, although…
  • 40. Topics ▪ Click to edit Master text styles • Second level • Third level − Fourth level • Fifth level 40 Next you might enjoy… A DELETE …in a table with lots of records …of a majority of data …and make it fast …like minimal logging!
  • 41. Topics ▪ Click to edit Master text styles • Second level • Third level − Fourth level • Fifth level 41 Minimally logged DELETE Wait…what?!? Utilize minimally logged INSERTs - Twice! (Not simultaneously, though) Let’s lock TWO tables
  • 42. Topics ▪ Click to edit Master text styles • Second level • Third level − Fourth level • Fifth level 42 Minimally logged DELETE
  • 43. Topics ▪ Click to edit Master text styles • Second level • Third level − Fourth level • Fifth level 43 Minimally logged DELETE So what’s the catch? ▪ Best for removing a majority of the data ▪ DISABLE/re-ENABLE constraints ▪ All the rules for minimal logging apply
  • 44. Topics ▪ Click to edit Master text styles • Second level • Third level − Fourth level • Fifth level 44 Desserts: modifying database settings
  • 45. Topics ▪ Click to edit Master text styles • Second level • Third level − Fourth level • Fifth level 45 What sounds good is… An INSERT …into an empty table …of sorted or unsorted data …in a database with FULL recovery model …and gimme minimal logging!
  • 46. Topics ▪ Click to edit Master text styles • Second level • Third level − Fourth level • Fifth level 46 Bulk Logged Recovery Model Change recovery model to BULK_LOGGED Utilize minimally-logged transactions This works for INSERTs (and savvy DELETEs) Does NOT break the backup chain!
  • 47. Topics ▪ Click to edit Master text styles • Second level • Third level − Fourth level • Fifth level 47 Bulk Logged Recovery Model
  • 48. Topics ▪ Click to edit Master text styles • Second level • Third level − Fourth level • Fifth level 48 Bulk Logged Recovery Model Warning: ▪ ALL database transactions affected ▪ No Point-In-Time recovery ▪ Consult with your Database Administrator
  • 49. Topics ▪ Click to edit Master text styles • Second level • Third level − Fourth level • Fifth level 49 Let’s boldly finish with… A DELETE …in a table with lots of records …of a bunch of data …for those on a RBAR diet.
  • 50. Topics ▪ Click to edit Master text styles • Second level • Third level − Fourth level • Fifth level 50 Delayed Durability Delays the hardening of transactions to log Log Buffer Cache Work with data Then write to T-Log
  • 51. Topics ▪ Click to edit Master text styles • Second level • Third level − Fourth level • Fifth level 51 Use with lots of small transactions Delayed Durability This works for INSERTs, UPDATEs, & DELETEs
  • 52. Topics ▪ Click to edit Master text styles • Second level • Third level − Fourth level • Fifth level 52 Delayed Durability
  • 53. Topics ▪ Click to edit Master text styles • Second level • Third level − Fourth level • Fifth level 53 Delayed Durability Why isn’t everyone using this? ▪ Lost transactions if SQL Server stops ▪ Works best for lots of small transactions ▪ Consult with your Database Administrator
  • 54. Topics ▪ Click to edit Master text styles • Second level • Third level − Fourth level • Fifth level 54 Let’s review the menu
  • 55. Topics ▪ Click to edit Master text styles • Second level • Third level − Fourth level • Fifth level 55 Appetizers: Alter the target table Query options INSERT UPDATE DELETE Clustered index on a heap Disable indexes
  • 56. Topics ▪ Click to edit Master text styles • Second level • Third level − Fourth level • Fifth level 56 Entrees: Transaction manipulation Query options INSERT UPDATE DELETE Batching (WHILE with TOP) Explicit transactions Minimally logged INSERT Minimally logged DELETE
  • 57. Topics ▪ Click to edit Master text styles • Second level • Third level − Fourth level • Fifth level 57 Desserts: Database settings Query options INSERT UPDATE DELETE Bulk Logged recovery model Delayed durability
  • 58. Topics ▪ Click to edit Master text styles • Second level • Third level − Fourth level • Fifth level 58 And NOW… Here is IDERA’s Rey Rios with a demo of SQL Diagnostic Manager…
  • 59. Topics ▪ Click to edit Master text styles • Second level • Third level − Fourth level • Fifth level 59 What questions do you have?
  • 60. Topics ▪ Click to edit Master text styles • Second level • Third level − Fourth level • Fifth level 60 That’s the end. Thank you! jeff@desertdba.com @desertdba