Invalid SQL statement in multi-statement transaction does not abort the transaction properly #1296
Description
If an invalid SQL statement is issued in a multi-statement transaction, the state of the transaction is set to ResultType::ABORTED and the idea is that the commit/rollback should abort the transaction. The user gets a warning when trying to run other SQL statements in the same transaction saying that the transaction is aborted and they should rollback.
On getting a rollback, the code calls AbortQueryHelper which checks for the state of the transaction and does not call abort if it is already set to ResultType::ABORTED. This results in the transaction with the invalid statement never being actually aborted.
The main reason the code waits for calling abort is that in such cases, we have to return back to the user in the context of the same transaction and hence, we cannot free up transaction context related data structures. We can get rid of the RW set and other stuff so the ideal fix is to release and give the RW set to the garbage collector as soon as one of the statements in the transaction returns failure. We can keep the transaction context till later when the user either rollbacks or commits. In either of those scenarios, we should add the transaction context data structures to the GC as well ensuring the abort of this transaction.