What is the default Escalation Threshold for Microsoft SQL server 2014 - sql-server-2014

What is the default table Escalation Threshold for Microsoft SQL server 2014.
Note: on SQL 2008 and 2012 was 5000 and there is reference, but I cant find any reference for 2014

I guess the MSDN has mentioned at the top itself that this applies to the 2008 and higher versions. So it would be 5000 for 2014 version as well.
Applies to: SQL Server 2008 R2 and higher versions.
From the MSDN
When the Database Engine checks for possible escalations at every 1250
newly acquired locks, a lock escalation will occur if and only if a
Transact-SQL statement has acquired at least 5000 locks on a single
reference of a table. Lock escalation is triggered when a Transact-SQL
statement acquires at least 5,000 locks on a single reference of a
table. For example, lock escalation is not triggered if a statement
acquires 3,000 locks in one index and 3,000 locks in another index of
the same table. Similarly, lock escalation is not triggered if a
statement has a self join on a table, and each reference to the table
only acquires 3,000 locks in the table.

Related

What will be locked when I use mysql transaction?

I'm confused about the mysql transaction. I have a table as follow.
content ip status
aaa null wait
bbb 192.168.21.11 processing
ccc null wait
ddd 192.168.21.11 processing
eee 192.168.21.12 processing
I have two processes running on two different machines to deal with this table. Each of them is doing the following operations.
(1) select a "wait" content from the table
(2) count the contents on each ip and select the ip with fewer contents
(3) update the content status to processing and set the ip column.
I used to use table locks to avoid race conditions, but it causes deadlocks. So now I want to use transactions instead. But I'm confused about the locking scope of the transaction.
I can use "for update" to avoid the race condition when two processes select a wait content from the table and update it to processing. But how should I avoid the race condition from occurring when counting and updating to processing? In the example above, both processes get 1 with 192.168.21.12 and both choose it for the process, then the content on this ip will be 3.
Do all the queries in a transaction execute atomically, so that no race conditions occur? Or mysql just locks the rows between "select ... for update" and "commit"?
In MySQL Innodb, the locks hold by transaction are released when transaction commit or rollback. In above case, the lock granted in step 1, would be hold until transaction complete.
The transaction are not run atomically, they could run concurrently if they do not touch the same records, otherwise, a transaction has to wait another transaction release the locks.
Regarding which kind of locks would be hold by statement, you could refer Locks Set by Different SQL Statements in InnoDB for more details

MySQL concurrent updates

I have small POS system with server side uses PHP and MySql (InnoDB).
When "Sale" is being completed the following query is executed for update stock quantity:
"UPDATE products SET qty=qty-:qty, ustatus=1 WHERE pid=:pid";
Does this statement is "Concurrency Update Secure", meaning do i need any transactions or locking tables.
I just want to be sure, that multiple queries like this, executed in same time
does not make mess with my stock.
If you use innodb, then all sql statements are executed in a transaction, you do not need to explicitly specify that.
Concurrency control is done via locks, not transactions. Transactions may only determine the lifespan of locks.
The update statement places an exclusive lock on the records that it wants to modify, meaning no other statements can modify (sometimes cannot even read) the locked record until the exclusive lock is released. So, your statement is safe from concurrency point of view.

How to apply lock on table level in SQL server

I am using SQL server 2008 R2 edition and want to apply lock on table level while selecting the data from the table.
As applying NO_LOCK can led to DIRTY READ problem so want to apply NO_LOCK on the tables that contains only domain data not the transaction data. i.e. the data which is very less frequent to be changed.
Please suggest any way to apply the LOCK on the domain tables.
You don't need to lock a table while reading (SELECT) since reading always acquires a shared lock on the table or row. WITH(NOLOCK) table hint just allows to read uncommited data as well; that is rows that are yet to be inserted and commited by other session. You can consider, setting TRANSACTION ISOLATION LEVEL to READ COMMITED to make sure that uncommited data is never red.

MySQL innodb select for update concurrency

MySQL documentation says that SELECT FOR UPDATE sets an IX lock. IX lock is intention exclusive lock and when issued it means "Transaction T intends to set X (exclusive) locks on scanned rows". This means that before SELECT FOR UPDATE succeeds it must first get IX and then X. MySQL glossary says this about intention exclusive lock:
intention lock
A kind of lock that applies to the table level, used to indicate what kind of lock the transaction intends to acquire on rows in the table. Different transactions can acquire different kinds of intention locks on the same table, but the first transaction to acquire an intention exclusive (IX) lock on a table prevents other transactions from acquiring any S or X locks on the table. Conversely, the first transaction to acquire an intention shared (IS) lock on a table prevents other transactions from acquiring any X locks on the table. The two-phase process allows the lock requests to be resolved in order, without blocking locks and corresponding operations that are compatible. For more details on this locking mechanism, see Section 14.3.5.3, “InnoDB Lock Modes”.
Also IX and IX are compatible (lock type compatibility matrix) which means that if transaction 1 issues IX and right after another concurrent transaction issues IX it will succeed.
Is there a possibility that two concurrent IX are issued at the exact same moment and MySQL grants/acquires IX for both transactions for the same table. Or MySQL grants at any point only one IX if concurrent IX are issued. I'm thinking that MySQL grants only one of them, even if call is made and triggered at MySQL side at the exact same time.
EDIT: basically if I generalize my question: If two (concurrent) sql statements that lock rows (e.g. update, select for update, select lock in share mode, insert, delete) come to MySQL at the exact same time, I suppose MySQL treats them sequentially. Just want to make sure, that I am thinking right how MySQL works internally.
Locking operations necessarily are serialized. At the nanosecond level in the server's logical workflow there's no such thing as "multiple lock requests at precisely the same moment." Even if there were, the server's logic would arbitrarily place them into some order and grant them one after the other.
A really smart next-generation massively parallel server might be able to figure out that different lock requests were guaranteed never to interfere with each other, and handle them truly in parallel. But for now, there's no such thing as simultaneous.

How to get list of named MySQL locks held by MySQL client connections

For MySQL 5.1, is there a way to get a list of named MySQL "locks" held by MySQL client connections?
I know I can check a specific named lock, if I know the name of the lock. But I want to know how (if possible) to list client connections that are holding (or waiting on) a named lock, and specifically, the name of the lock each client is holding.
I'm asking here about the named locks obtained, released, checked, et al. by the MySQL GET_LOCK, RELEASE_LOCK, IS_FREE_LOCK, and IS_USED_LOCK functions.
http://dev.mysql.com/doc/refman/5.1/en/miscellaneous-functions.html#function_get-lock
(NOTE: I am not asking about table locks acquired by LOCK TABLE statement)
I don't think it's possible to get a list of clients holding locks, but you should be able to get a list of clients who are actively waiting on a lock using a query like this:
select *
from information_schema.PROCESSLIST
where state = 'User lock'