简体   繁体   English

SQL Server:事务执行总是立即执行?

[英]SQL Server: Transaction execution always immediately?

Does SQL Server (2005/2008/2012) execute BEGIN TRANSACTION as soon as the command arrives? 一旦命令到达,SQL Server(2005/2008/2012)是否执行BEGIN TRANSACTION?

Is it - however (option, network buffering/-delay, distributed database, ..) - possible that a BEGIN TRANSACTION command as well as everything following gets held because eg. 是 - 但是(选项,网络缓冲/ - 延迟,分布式数据库,......) - BEGIN TRANSACTION命令以及随后的所有内容都可能被保留,例如。 something else has to happen first? 别的东西必须先发生?

Further, is there any possibility that - when database/network caused buffering/delay is possible - two transactions will be executed in reverse order? 此外,是否有可能 - 当数据库/网络导致缓冲/延迟时 - 两个事务将以相反的顺序执行?

Yes the transaction will begin as soon as the command arrives and when you do commit or rollback then the operation is done accordingly. 是的,一旦命令到达,事务将立即开始,当您执行提交或回滚时,操作将相应地完成。

The MSDN doc says: MSDN文档说:

During query optimization, SQL Server looks for queries or index operations that might benefit from parallel execution. 在查询优化期间,SQL Server查找可能从并行执行中受益的查询或索引操作。 For these queries, SQL Server inserts exchange operators into the query execution plan to prepare the query for parallel execution. 对于这些查询,SQL Server将交换运算符插入到查询执行计划中,以准备查询并行执行。 An exchange operator is an operator in a query execution plan that provides process management, data redistribution, and flow control. 交换运营商是查询执行计划中的运营商,提供流程管理,数据重新分配和流量控制。 The exchange operator includes the Distribute Streams, Repartition Streams, and Gather Streams logical operators as subtypes, one or more of which can appear in the Showplan output of a query plan for a parallel query. 交换运算符包括Distribute Streams,Repartition Streams和Gather Streams逻辑运算符作为子类型,其中一个或多个可以出现在并行查询的查询计划的Showplan输出中。

You can have parallel execution of the queries but once a query gets started until and unless you are not changing the isolation level or if there is any error then you cannot alter the execution of your query. 您可以并行执行查询,但是一旦查询开始,除非您没有更改隔离级别或者如果有任何错误,那么您无法更改查询的执行。 So in short you cannot make the other query wait for the first query getting executed. 因此,简而言之,您无法让其他查询等待第一个查询执行。

Further, is there any possibility that - when database/network caused buffering/delay is possible - two transactions will be executed in reverse order? 此外,是否有可能 - 当数据库/网络导致缓冲/延迟时 - 两个事务将以相反的顺序执行?

As far as I know you cannot change the order of execution of your query which changing the sequence or making any code/query change. 据我所知,您无法更改查询的执行顺序,即更改序列或更改任何代码/查询。

When the server gets the BEGIN TRAN message, it starts reserving resources and executing the commands. 当服务器获得BEGIN TRAN消息时,它开始保留资源并执行命令。 If another transaction arrives that needs some of the same resources, it will be required to wait until the first transaction releases those resources, usually with a COMMIT. 如果另一个事务到达需要一些相同的资源,则需要等到第一个事务释放这些资源,通常使用COMMIT。

This can be altered somewhat by changing the server isolation levels, but in general transactions executed in the order they are received. 这可以通过更改服务器隔离级别来改变,但通常是按接收顺序执行的事务。

There is a chance that network issues could cause transactions to change order if users are making changes from different locations. 如果用户从不同位置进行更改,网络问题可能会导致事务更改顺序。 But once a transaction reaches the server, there is no reason it would reverse order if they are using the same objects. 但是一旦事务到达服务器,如果它们使用相同的对象,就没有理由它会颠倒顺序。

This behavior is the C in ACID : Consistency. 此行为是ACID中C :一致性。

It is possible that transactions could be executed out of order, but only if they are not accessing the same resources. 事务可能无序执行,但前提是它们不访问相同的资源。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM