1

I am preparing for MCTS 70 - 433 and while reading the dumps I found this question.

"You are tasked to analyze blocking behavior of the following query

SET TRANSACTION ISOLATION LEVEL SERIALIZABLE;

WITH customers
     AS (SELECT *
         FROM   customer),
     salestotal
     AS (SELECT customerid,
                sum(ordertotal) AS Allordertotal
         FROM   salesorder)
SELECT customerid,
       allordertotal
FROM   salestotal
WHERE  allordertotal > 10000.00 

You need to determine if other queries that are using the Customer table will be blocked by this query. You also need to determine if this query will be blocked by the other queries that use the customer table.

A. The other queries will be blocked by the user. This query will be blocked by the other queries.

B. The other queries will be blocked by the user. This query will not be blocked by the other queries.

C. The other queries will not be blocked by the user. This query will be blocked by the other queries.

D. The other queries will not be blocked by the user. This query will not be blocked by the other queries."

The correct answer is given as D.

But when serializable transaction level is used, it issues a lock and stop other transactions rite.??

Please correct me if I am wrong.

4

1 回答 1

2

这是一个技巧问题。该查询仅在 SalesOrder 表上运行。即使在 CTE 定义中使用了客户,但 CTE 永远不会被访问,因此 SQL Server 永远不会锁定。

编辑:如果使用了 CTE,则没有足够的信息来回答这个问题。给定的答案似乎假设了一个表锁——但在大多数情况下,SQL Server 将使用行锁和范围锁。因此,分析阻塞行为的唯一方法是查看所涉及的两个查询。

通常,对于 SERIALIZABLE,任何会修改结果集的查询都将被阻止。这包括引入不可重复读取(例如,对 SELECTed 行的 UPDATE)引入幻像读取(例如,将满足 WHERE 子句的 INSERT)。后一部分是 SERIALIZABLE 对 REPEATABLE READ 提供的额外保证。

于 2013-07-04T03:06:29.027 回答