12

My first question is, will these update statements work as intended? Very likely, but not certain. SQL Server guarantees it will honour the semantics of the query, and the level of ACID compliance determined by the effective isolation level. Beyond that, all is implementation detail (including what type(s) of locks are taken, when, and for how long they ...


8

Since we've established that no other transaction holds any of the locks the current one holds, it logically follows that no other transaction would be attempting to update or lock any of the records with those same object ids in the personal inventory table. You should know that this: no other transaction holds any of the locks the current one ...


6

(Updated February 2019) This is an old post, that said I've finally managed to convince Microsoft that the very fact this happens is indeed a defect. Update: MS Confirmed the defect and assigned it a bug # of 12628722. I had seen this post this past November 2018 when we to began to suffer much the same after we'd upgraded from Sql Server 2005 to Sql ...


5

You've got two different indexes that can satisfy that query. So two queries, running two different plans could each lock a key on a different index. Try forcing the index in the query.


5

Getting the same row from different indexes As David mentions in his answer, you can get the same row from multiple sessions if you happen to access that row via different indexes. The UPDLOCK hint only applies to the specific access method. Having a nonclustered index row U locked does not prevent another query acquiring a U lock on a different index (...


4

The given schedule S is: T1 T2 ---- ----- R(X) W(X) W(X) To be view serializable W2(X) must move before R1(X) or after W1(X). However, the first would violate the "initial read" rule and the second would violate the "last write" rule. T2 starts after T1 so has a higher timestamp. When T1 comes to write X it sees that T2's timestamp on it. By ...


4

A lesson to learn about indexing. INDEX(a,b,c) is not optimal for WHERE a=1 AND c=2. This is because only the leftmost column(s) of an index will be used; there cannot be any skipping over columns (b, in this example). Back to your question. INDEX(slack_channel_id, message_id) is needed, and INDEX(`slack_id`,`slack_channel_id `,`message_id`) is not ...


3

The problem is that the HOLDLOCK is creating the "Shared" lock (the Mode: S locks) on that resource for the duration of the transaction. This does not prevent other processes (such as the same proc executed in another session) from placing their own "Shared" lock on the same resource. But then both sessions get to the UPDATE statement which is trying to ...


3

One way to avoid the "lost update" problem, where changes are overwritten silently and the last one wins, is with an optimistic concurrency technique. This can be accomplished using a rowversion column and comparing the original and current value during each update. The update can be rejected if any of the row values changed or the row deleted. CREATE ...


2

Maybe I'm totally wrong, but it seems to me that if a customer has one and only one default credit card, I'll add that as a column in the customers tables : CREATE TABLE customers ( acc_num text PRIMARY KEY, name text, default_credit_card integer NOT NULL ); CREATE TABLE customers_credit_cards ( id serial primary key, acc_num text references ...


2

The tables are being locked due to the trigger: [iduSalesOrderDetail] on [Sales].[SalesOrderDetail] The trigger launches if any of these actions occur: IF UPDATE([ProductID]) OR UPDATE([OrderQty]) OR UPDATE([UnitPrice]) OR UPDATE([UnitPriceDiscount]) And UPDATE([OrderQty]) is one of these actions. This trigger will then update Person.Person two times. ...


2

Not sure if that's the best approach, but it seems to be a quick and reliable as long as application[s] consistently uses it. Create a new table, access_attempt (user_id integer not null primary key). Modify you workflow : begin ; insert into attempt_access (user_id) values (:user_id); -- do you verification, raise an error if needed insert into access (...


1

For SQL Server: But what's about single statements? In SQL Server, there is 4 transaction isolation levels (in pessimistic locking model). Default transaction isolation level is Read Committed, and locks are placed on a statement level. If you have a transaction that has 2 statements inside it that retrieve same data, and in the middle of that ...


1

If there are multiple queries in a batch then these queries will be executed in the order they appear in the batch. After the execution of Query 1 is finished then the update query will be executed. You can run debugger to see the sequential execution.


1

Option 1: Use COPY from a valid dump of the tables in order to avoid any foreign key conflict (Copy is the fastest way i've found to load bulk data) Option 2: Create the schema without foreign keys, load the dumps, and recreate the foreign keys after that: ALTER TABLE table2 DROP CONSTRAINT fkey; ALTER TABLE table2 ADD CONSTRAINT fkey; FOREIGN KEY (...


1

Serializable means that there is some order the transactions can be run in without overlapping and we'll end up with the same answers and the same state of the data base as we get by running the transactions in parallel with serializable isolation level. Given two transactions, A and B, the only valid states of the system are All of A followed by all of B, ...


1

I am answering your comment For now I'm always inserting single rows, but in the future it will likely be necessary/desirable to insert a whole set at once I don't know how you store a player has joined a team or not. So i will call them "newplayer" If you have a lot of "newplayers" waiting for joining a team, I would suggest this kind of query to now ...


1

Combining the comment from @Rory and info in @Zaytsev Dmitry's answer: The CREATE INDEX CONCURRENTLY will not return until the index has finished building. So you know the index is done when your query returns. However if you're building a large index you may wonder if it is 'really' still running. You can use the query for 'invalid' indexes: SELECT * ...


1

You can get list of invalid indexes. SELECT * FROM pg_class, pg_index WHERE pg_index.indisvalid = false AND pg_index.indexrelid = pg_class.oid; If you see your index in this query it means the index won't work and you have to recreate index. Don't do REINDEX. It won’t re-create the index concurrently, it will lock the table for writes while the index is ...


Only top voted, non community-wiki answers of a minimum length are eligible