Bug #65800 Add GQL flag for internal prepare/execute of prepared statements
Submitted: 3 Jul 2012 22:27
Reporter: Todd Farmer (OCA) Email Updates:
Status: Verified Impact on me:
Category:MySQL Server: Prepared statements Severity:S4 (Feature request)
Version:5.6.6 OS:Any
Assigned to: CPU Architecture:Any

[3 Jul 2012 22:27] Todd Farmer
MySQL server accepts PREPARE and EXECUTE statements for prepared statements via the COM_QUERY protocol command, and internally transforms them.  This results in the original PREPARE or EXECUTE statement being logged as a "Query" event in the general query log, plus the "Prepare" or "Execute" event generated by the internal transformation.  That information is useful in debugging, as it gives visibility to the generated SQL that was actually executed.  However, it makes it difficult to reconstruct series of SQL statements from the general query log, as one has to account for whether these events are duplicates of events already logged.

How to repeat:
Execute prepared statement against the cli, look at GQL:

6 Query    PREPARE stmt FROM 'SELECT RAND()'
6 Prepare    SELECT RAND()
6 Query    EXECUTE stmt
6 Execute    SELECT RAND()

Execute prepared statement using driver that issues COM_STMT_PREPARE and COM_STMT_EXECUTE (e.g., Connector/J with useServerPrepStmts=true):

14 Prepare    SELECT * FROM t1 WHERE a = ?
14 Execute    SELECT * FROM t1 WHERE a = 2

Suggested fix:
Add some flag to general query log that indicates that a command is a duplicate of already-recorded commands after internal transformation.