cockroach
cockroach copied to clipboard
sql: txn status becomes incorrect after executed "commit;begin"
txn status becomes incorrect after executed "commit;begin"
root@:26257> commit;begin;
Now adding input for a multi-line SQL transaction client-side.
Press Enter two times to send the SQL text collected so far to the server, or Ctrl+C to cancel.
->
pq: there is no transaction in progress
root@:26257> select 1;
+---+
| 1 |
+---+
| 1 |
+---+
(1 row)
root@:26257> select b;
pq: column name "b" not found
root@:26257> select 1;
+---+
| 1 |
+---+
| 1 |
+---+
(1 row)
root@:26257> commit;
pq: there is no transaction in progress
@yznming I have troubleshooted this and I think there is no issue, everything works as intended. Perhaps we are not doing a good job at reporting the transaction status (see #10290) but I believe there is no error. Let me explain:
- initially, there is no transaction.
- you enter
commit; begin. The CLI shell starts a multi-line editor. The two statementscommit;beginare not sent to the server yet! there is still no transaction. - you press the "enter" key two times. This causes the shell to send
commit;beginto the server. They are sent as one string/statement! So the server seescommit;beginarriving in one string. - the server processes
commit;first. This fails, because there is no transaction. So the server produces an error. - because the server has produced an error, the server does not look further into the string it has received. In other words, because of the error in
commit, the server does not processbeginthat was just afterwards. - the commit error is reported to the client:
there is no transaction in progress. At this point, because there was an error andbeginwas skipped, there is still no transaction in progress on the server. - you enter "select 1". This is sent to the server and processed in a spontaneous, single-statement transaction. After this completes and produces a result, there is still no transaction in progress on the server.
- you enter "select b". This is sent to the server, again processed in a spontaneous single-statement transaction. After this completes and produces an error, there is still no transaction in progress on the server.
- you enter "select 1", same happens as step 7 above.
- you enter "commit". The server receives this, but there is no transaction in progress, so
commitfails again withthere is no transaction in progress.
The situation would have been different if you had placed commit and begin on different lines at the beginning.
Does this clarify?
it's clear now. thank you :)
You're welcome! Thanks for asking.