table-locking

How innodb tables are locked when ON INSERT trigger is processed?

核能气质少年 提交于 2019-12-03 04:41:21
I have two innodb tables: articles id | title | sum_votes ------------------------------ 1 | art 1 | 5 2 | art 2 | 8 3 | art 3 | 35 votes id | article_id | vote ------------------------------ 1 | 1 | 1 2 | 1 | 2 3 | 1 | 2 4 | 2 | 10 5 | 2 | -2 6 | 3 | 10 7 | 3 | 15 8 | 3 | 12 9 | 3 | -2 When a new record is inserted into the votes table, I want to update the sum_votes field in articles table by calculating the sum of all votes. The question Which way is more efficient, if the SUM() calculation itself is a very heavy one ( votes table has 700K records). 1. Creating a trigger CREATE TRIGGER

How to explicitly lock a table in Microsoft SQL Server (looking for a hack - uncooperative client)

与世无争的帅哥 提交于 2019-11-30 18:59:16
This was my original question: I am trying to figure out how to enforce EXCLUSIVE table locks in SQL Server. I need to work around uncooperative readers (beyond my control, closed source stuff) which explicitly set their ISOLATION LEVEL to READ UNCOMMITTED. The effect is that no matter how many locks and what kind of isolation I specify while doing an insert/update, a client just needs to set the right isolation and is back to reading my garbage-in-progress. The answer turned out to be quite simple - while there is no way to trigger an explicit lock, any DDL change triggers the lock I was

Why is table-level locking better than row-level locking for large tables?

落花浮王杯 提交于 2019-11-30 10:55:44
问题 According to the MySQL manual: For large tables, table locking is often better than row locking, Why is this? I would presume that row-level locking is better because when you lock on a larger table, you're locking more data. 回答1: from the (pre-edit) link Slower than page-level or table-level locks when used on a large part of the table because you must acquire many more locks use a row level lock if you are only hitting a row or two. If your code hits many or unknown rows, stick with table

Create an index on a huge MySQL production table without table locking

陌路散爱 提交于 2019-11-27 17:02:38
I need to create an index on a ~5M rows MySQL table. It is a production table, and I fear a complete block of everything if I run a CREATE INDEX statement... Is there a way to create that index without blocking inserts and selects? Just wondering I have not to stop, create index and restart my system! [2017] Update: MySQL 5.6 has support for online index updates https://dev.mysql.com/doc/refman/5.6/en/innodb-create-index-overview.html In MySQL 5.6 and higher, the table remains available for read and write operations while the index is being created or dropped. The CREATE INDEX or DROP INDEX

Create an index on a huge MySQL production table without table locking

筅森魡賤 提交于 2019-11-26 22:30:27
问题 I need to create an index on a ~5M rows MySQL table. It is a production table, and I fear a complete block of everything if I run a CREATE INDEX statement... Is there a way to create that index without blocking inserts and selects? Just wondering I have not to stop, create index and restart my system! 回答1: [2017] Update: MySQL 5.6 has support for online index updates https://dev.mysql.com/doc/refman/5.6/en/innodb-create-index-overview.html In MySQL 5.6 and higher, the table remains available