Assuming the MySQL client process is killed

Note:
This topic has been translated from a Chinese forum by GPT and might contain errors.

Original topic: 假设mysql客户端进程被杀

| username: vincentLi

【TiDB Usage Environment】Production Environment
【TiDB Version】6.5.3
【Reproduction Path】Suppose you find that the client is performing an operation that takes more than 1 hour to complete. You don’t want to wait, so you directly kill the process on the client side. What will the TiDB server do after it stops receiving data packets from the client?
If a complex query is being executed, will the query automatically exit?
If a large transaction is being executed, will the transaction rollback? Will the locks be automatically released?

| username: 人如其名 | Original post link

In versions prior to 7.5, if the client process is killed directly, the database will continue to complete the statement. If a large transaction is being executed, it will succeed if it is auto-commit; if it is not auto-commit, the transaction will roll back and the lock will be automatically released.

In version 7.5, if the client process is killed, the database will terminate immediately, the statement will be killed immediately, the transaction will roll back, and the lock will be released.

| username: Kongdom | Original post link

:flushed: I always thought that after killing, the data execution would terminate and roll back. It turns out that before version 7.5, it wouldn’t roll back.

| username: 人如其名 | Original post link

There is no problem using the kill command in the database server, but directly terminating the program on the client side doesn’t work. This requirement was mentioned before, but it was finally implemented in version 7.5.

| username: vincentLi | Original post link

Good improvement.

| username: Kongdom | Original post link

Oh, so killing is normal, and if you just close the client, it won’t take effect. This is actually expected.

| username: zhaokede | Original post link

Got it. Previously, I understood that after the client stops, the system will continue to execute until it detects that the session is disconnected, at which point it will automatically roll back and release the lock, but it is quite slow.

| username: tidb菜鸟一只 | Original post link

If you use PL/SQL Developer with Oracle, clicking “Interrupt” will cause a rollback, but if you directly kill PL/SQL Developer, it will continue to execute.

| username: zhaokede | Original post link

PL/SQL Developer does not automatically commit transactions by default, meaning that if you execute a transaction, it will lock the data.

| username: TiDBer_QKDdYGfz | Original post link

Master, may I ask how the TiDB server senses that the client has disconnected? Is this related to TCP long connections?

| username: zhaokede | Original post link

Mainly relies on heartbeat messages or the KeepAlive mechanism of the TCP protocol.

| username: TiDBer_ZxWlj6A1 | Original post link

The client actually sent the command to the server for execution, so if the client is killed, it will not roll back previously.

| username: chenhanneu | Original post link

Learned.

| username: tidb菜鸟一只 | Original post link

Isn’t that an issue with your settings? Regardless of whether you submit it or not, the SQL statement you executed needs to be completed.

| username: 我是吉米哥 | Original post link

This bug had a significant impact, and the fix is very well done.

| username: TiDBer_QKDdYGfz | Original post link

Is there a heartbeat between the client and the server?

| username: zhaokede | Original post link

The KeepAlive mechanism of the TCP protocol

| username: TiDBer_QKDdYGfz | Original post link

Got it, thanks for the explanation.

| username: TiDBer_LM | Original post link

Got it. Thanks for the explanation, expert.

| username: lemonade010 | Original post link

The client in version 6.5 restarted, but TiDB continued to execute and could only be killed manually. Thumbs up for the new features in version 7.5.