Bug #67326 in_trans doesn't track implicit commit when new transaction is begun
Submitted: 22 Oct 2012 15:00 Modified: 22 Oct 2012 17:25
Reporter: Tobi Nisgod Email Updates:
Status: Not a Bug Impact on me:
None 
Category:MySQL Proxy Severity:S3 (Non-critical)
Version:0.8.3 OS:Linux (CentOS5.6)
Assigned to: CPU Architecture:Any
Tags: transactions

[22 Oct 2012 15:00] Tobi Nisgod
Description:
On read_query_result(inj) inj.resultset.flags.in_trans doesn't track implicit commit when new transaction is begun.

How to repeat:
In active-transactions.lua, comment out all of read_query_result but,

for thread_id, statements in pairs(proxy.global.trxs) do
 for stmt_id, statement in ipairs(statements) do
  print(("  [%d].%d: %s"):format(thread_id, stmt_id, statement))
 end
end

if not flags.in_trans then
 proxy.global.trxs[proxy.connection.server.thread_id] = nil
end

Pass in:
begin;
begin;
commit;
begin;

Results:
[1232804].1: begin
[1232804].2: begin
[1232804].3: commit
[1232804].1: begin

Note that the statement counter doesn't reset after the second begin but does after the first commit.
[22 Oct 2012 17:25] Jan Kneschke
BEGIN; COMMIT; is a no-op.

In the case of InnoDB the transaction is opened by the first statement hitting a innodb table, not the BEGIN/START TRANSACTION.

The protocol level (and its in_trans flag) reflects that.