lock tuning. overview data definition language (ddl) statements are considered harmful ddl is the...
DESCRIPTION
Data definition language (DDL) statements are considered harmful DDL is the language used to access and manipulate catalog or metadata The catalog can easily become a hot spot and therefore a bottleneck The lesson is: avoid updates to the system catalog during heavy system activity, especially if you are using dynamic SQL © Dennis Shasha, Philippe Bonnet 2001TRANSCRIPT
![Page 1: Lock Tuning. Overview Data definition language (DDL) statements are considered harmful DDL is the language used to access and manipulate catalog or metadata](https://reader036.vdocuments.site/reader036/viewer/2022090103/5a4d1bbc7f8b9ab0599d1026/html5/thumbnails/1.jpg)
Lock Tuning
![Page 2: Lock Tuning. Overview Data definition language (DDL) statements are considered harmful DDL is the language used to access and manipulate catalog or metadata](https://reader036.vdocuments.site/reader036/viewer/2022090103/5a4d1bbc7f8b9ab0599d1026/html5/thumbnails/2.jpg)
Overview
![Page 3: Lock Tuning. Overview Data definition language (DDL) statements are considered harmful DDL is the language used to access and manipulate catalog or metadata](https://reader036.vdocuments.site/reader036/viewer/2022090103/5a4d1bbc7f8b9ab0599d1026/html5/thumbnails/3.jpg)
Data definition language (DDL) statements
are considered harmful• DDL is the language used to access and
manipulate catalog or metadata• The catalog can easily become a hot spot
and therefore a bottleneck• The lesson is: avoid updates to the system
catalog during heavy system activity, especially if you are using dynamic SQL
© Dennis Shasha, Philippe Bonnet 2001
![Page 4: Lock Tuning. Overview Data definition language (DDL) statements are considered harmful DDL is the language used to access and manipulate catalog or metadata](https://reader036.vdocuments.site/reader036/viewer/2022090103/5a4d1bbc7f8b9ab0599d1026/html5/thumbnails/4.jpg)
Think about partitioning• Problem: insert a collection records into history file or
security file, or log file– Time dependent insertion– Last page of the file may become a concurrency
bottleneck• Solution: partition insertions to the file across different
pages and possibly different disks– Set up many insertion points and insert into them randomly– Set up a clustering index based on some attribute that is
not correlated with the time of insertion.– Hash the time of insertion and use that as the clustering
key.
© Dennis Shasha, Philippe Bonnet 2001
![Page 5: Lock Tuning. Overview Data definition language (DDL) statements are considered harmful DDL is the language used to access and manipulate catalog or metadata](https://reader036.vdocuments.site/reader036/viewer/2022090103/5a4d1bbc7f8b9ab0599d1026/html5/thumbnails/5.jpg)
Multiple insertion points and page locking
• “sequential” a clustered index defined on an attribute whose value increases (or even decreases) with time
• “Nonsequential” denotes that independent of time
© Dennis Shasha, Philippe Bonnet 2001
![Page 6: Lock Tuning. Overview Data definition language (DDL) statements are considered harmful DDL is the language used to access and manipulate catalog or metadata](https://reader036.vdocuments.site/reader036/viewer/2022090103/5a4d1bbc7f8b9ab0599d1026/html5/thumbnails/6.jpg)
Multiple insertion points and row locking
• Row locking avoids contention between successive insertions
© Dennis Shasha, Philippe Bonnet 2001
![Page 7: Lock Tuning. Overview Data definition language (DDL) statements are considered harmful DDL is the language used to access and manipulate catalog or metadata](https://reader036.vdocuments.site/reader036/viewer/2022090103/5a4d1bbc7f8b9ab0599d1026/html5/thumbnails/7.jpg)
Circumventing hot spots• A hot spot is a piece of data that is accessed by
many transactions and is updated by some.• Hot spots cause bottlenecks because each
updating transaction must complete before any other transaction can obtain a lock on the hot data item.
• Solution– Use partitioning to eliminate it– Access the hot spot as late as possible in the
transaction– Use special database management facilities
© Dennis Shasha, Philippe Bonnet 2001
![Page 8: Lock Tuning. Overview Data definition language (DDL) statements are considered harmful DDL is the language used to access and manipulate catalog or metadata](https://reader036.vdocuments.site/reader036/viewer/2022090103/5a4d1bbc7f8b9ab0599d1026/html5/thumbnails/8.jpg)
2 - Tuning the Guts © Dennis Shasha, Philippe Bonnet 2001 8
Logical Bottleneck: Sequential Key generation
• Consider an application in which one needs a sequential number to act as a key in a table, e.g. invoice numbers for bills.
• Ad hoc approach: a separate table holding the last invoice number. Fetch and update that number on each insert transaction.– The last invoice number becomes a
bottleneck due to two-phase locking• Counter approach: use facility such as
Sequence (Oracle)/Identity(SQL Server).
![Page 9: Lock Tuning. Overview Data definition language (DDL) statements are considered harmful DDL is the language used to access and manipulate catalog or metadata](https://reader036.vdocuments.site/reader036/viewer/2022090103/5a4d1bbc7f8b9ab0599d1026/html5/thumbnails/9.jpg)
© Dennis Shasha, Philippe Bonnet 2001
Latches and Locks• Locks are used for concurrency control
– Is held until commit the transaction– Requests for locks are queued
• Priority queue– Lock data structure
• Locking mode, lock granularity, transaction id.• Lock table
• Latches are used for mutual exclusion – A latch is released immediately after access– Requests for latch succeeds or fails
• Active wait (spinning) on latches on multiple CPU.– Single location in memory
• Test and set for latch manipulation
![Page 10: Lock Tuning. Overview Data definition language (DDL) statements are considered harmful DDL is the language used to access and manipulate catalog or metadata](https://reader036.vdocuments.site/reader036/viewer/2022090103/5a4d1bbc7f8b9ab0599d1026/html5/thumbnails/10.jpg)
© Dennis Shasha, Philippe Bonnet 2001
Counter Facility -- data
Settings:
– default isolation level: READ COMMITTED; Empty tables– Dual Xeon (550MHz,512Kb), 1Gb RAM, Internal RAID controller
from Adaptec (80Mb), 4x18Gb drives (10000RPM), Windows 2000.
accounts( number, branchnum, balance);create clustered index c on accounts(number); counter ( nextkey );insert into counter values (1);
![Page 11: Lock Tuning. Overview Data definition language (DDL) statements are considered harmful DDL is the language used to access and manipulate catalog or metadata](https://reader036.vdocuments.site/reader036/viewer/2022090103/5a4d1bbc7f8b9ab0599d1026/html5/thumbnails/11.jpg)
© Dennis Shasha, Philippe Bonnet 2001
Counter Facility -- transactions
No Concurrent Transactions:– System [100 000 inserts, N threads]
• SQL Server 7 (uses Identity column)insert into accounts values (94496,2789);• Oracle 8iinsert into accounts values (seq.nextval,94496,2789);
– Ad-hoc [100 000 inserts, N threads]begin transaction NextKey:=select nextkey from counter; update counter set nextkey = NextKey+1;commit transactionbegin transaction insert into accounts values(NextKey,?,?);commit transaction
![Page 12: Lock Tuning. Overview Data definition language (DDL) statements are considered harmful DDL is the language used to access and manipulate catalog or metadata](https://reader036.vdocuments.site/reader036/viewer/2022090103/5a4d1bbc7f8b9ab0599d1026/html5/thumbnails/12.jpg)
© Dennis Shasha, Philippe Bonnet 2001
Avoid Bottlenecks: Counters
• System generated counter (system) much better than a counter managed as an attribute value within a table (ad hoc).
• Counters may miss ids, however which is tolerable in many real apps
SQLServer
0 10 20 30 40 50
Number of concurrent insertion threads
Thro
ughp
ut
(sta
tem
ents
/sec
)
systemad-hoc
Oracle
0 10 20 30 40 50
Number of concurrent insertion threads
Thro
ughp
ut
(sta
tem
ents
/sec
)
systemad-hoc
![Page 13: Lock Tuning. Overview Data definition language (DDL) statements are considered harmful DDL is the language used to access and manipulate catalog or metadata](https://reader036.vdocuments.site/reader036/viewer/2022090103/5a4d1bbc7f8b9ab0599d1026/html5/thumbnails/13.jpg)
summary