What will happen if connection is lost during long operation?
For example there is a select statement that takes several minutes to complete and connection is lost during its execution. Will it continue execution or will be stopped?
For a delete statement: will it be executed to its finish or interrupted when client disconnects? What will happen to the data: will it be committed or rolled back, how soon?
For a ddl operation: I have a long running alter table tbl_name move operation, what will happen to it when client loses connection? Will continue execution or will be interrupted?
I’m assuming that we’re talking about something akin to the client application crashing or the network connection getting dropped rather than a situation where the application is doing a clean disconnect since you cannot do a clean disconnect while a transaction is open let alone while a statement is running.
In general, the statement will run to completion on the server (where “completion” for a
SELECTis the point at which it can return the first set of rows the client requested which may or may not require executing the statement in its entirety). The server will then attempt to communicate the fact that the result is ready back to the client. When it doesn’t get a response back (it may take a few minutes to time out waiting for theACKpacket), it knows that the client process is dead and begins the process of rolling back the uncommitted transaction (which releases all the locks held by the transaction). If you have made changes to the database as part of your transaction (i.e. you have done inserts, updates, and/or deletes), it can take as long to roll back the changes as it took to generate the changes in the first place.