Bug #1749 Prepared statements within transaction
Submitted: 4 Nov 2003 12:54 Modified: 20 Jan 2004 22:13
Reporter: [ name withheld ] Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server Severity:S2 (Serious)
Version:4.1 alpha OS:Windows (win 2k)
Assigned to: Alexey Botchkov CPU Architecture:Any

[4 Nov 2003 12:54] [ name withheld ]
Description:
It seems there is a problem with prepared statements, or they have some strange behavior that is not documented.
 What I do is:

( I`m using innodb tables )

1) create 3 different prepared statements
2) call mysql_query("BEGIN")
3) call 1st,2nd and 3rd prepared statement
4) call mysql_query("COMMIT")

What exactly does the queries do:
 first two update rows of the same table  ( different rows )
 third does update another table

What happens:
 sometime are only 1st two queries processed, sometimes only 3rd query. I think it never happend that all of them succeded ( maybe it did, but really in rare cases ).
 
 I didn`t test it separately out of my program, but when I change prepared statements of my program to normal mysql_query calls, everything works perfectly fine..

( when I`m doing lot of inserts on lot of different tables during one transaction, using both prepared statements and normal statements, everything works fine. )

 Maybe differnet issue is, that sometimes ( quite often ) server does completely crash during prepared statement queries ( and they do not have to be in a transaction ).. even if it would be inrepeatable on another computer, it is unfortunately fact.. ( I didn`t have any stability problems on my computer with any previous release )
 After that crash it cannot be recovered without computer reboot ( which I have to do right now after another db crash.. )
 ( I`m using mysqld-max.exe )

How to repeat:
Do what I wrote above. In addition it might be affected with the fact, that I`m connected with mysql_client_multiqueries parameter.

my queris are realy simple:
just like 
"UPDATE tableA SET param = param + ? WHERE ID = ?"
"UPDATE tableA SET param = param - ? WHERE ID = ?"
"UPDATE tableB SET param2 = ? WHERE ID = ?"

it never returns any error..
[4 Nov 2003 13:56] Heikki Tuuri
Hi!

Yes, prepare/execute with InnoDB is badly broken in 4.1.0, because MySQL changes thd->query_id differently from field->query_id in execute() (or was it in prepare()?).

The rule is that InnoDB should fetch those fields where thd->query_id == field->query_id. But the current MySQL code fails to keep the id's right.

Regards,

Heikki
[20 Jan 2004 22:13] Alexey Botchkov
Thank you for your bug report. This issue has been committed to our
source repository of that product and will be incorporated into the
next release.

If necessary, you can access the source repository and build the latest
available version, including the bugfix, yourself. More information 
about accessing the source trees is available at
    http://www.mysql.com/doc/en/Installing_source_tree.html

Additional info:

Fixed with the big cleanup()-related patch