Skip to content

[MYSQL] logging of prepared statement parameters #4861#4895

Merged
renecannao merged 13 commits intov3.0from
v3.0-4861-mysql-logging_prepared_statement_parameters
Apr 14, 2025
Merged

[MYSQL] logging of prepared statement parameters #4861#4895
renecannao merged 13 commits intov3.0from
v3.0-4861-mysql-logging_prepared_statement_parameters

Conversation

@renecannao
Copy link
Contributor

For MySQL queries, two logging formats are supported:

  • Binary Format (Format 1) via write_query_format_1()
  • JSON Format (Format 2) via write_query_format_2_json()

For prepared statements (i.e. COM_STMT_EXECUTE events), the logging functions now log extra parameter details.
Both formats encode the number of parameters and, for each parameter, log its type and a human-readable string value, with special handling for NULL values.

Adding session
Addin a placeholder for extractStmtExecuteMetadataToJson()
Added:
* bufferTypeInfoMap : to map mysql type to typename and function to convert to JSON
* extractStmtExecuteMetadataToJson() : function to generate a JSON with parameters

Modified write_query_format_1() to write parameters.

This is still a WIP
Added inline documentation in write_query_format_1() related to the logging
of parameters when COM_STMT_EXECUTE is logged
Added detailed documentation for Logging of prepared statements parameters
When logging COM_STMT_EXECUTE parameters, we check stored parameters.
In the unexpected event (it should never happen) that either `session`
or `session->CurrentQuery.stmt_meta` are `nullptr` , we log 0 parameters
to ensure a deterministic format in the query logging file.
@renecannao renecannao requested a review from Copilot March 31, 2025 17:22
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR introduces documentation updates that describe enhanced logging for prepared statement parameters in MySQL queries using both binary and JSON formats.

  • Adds a comprehensive markdown guide explaining how prepared statement parameters are logged, including details on parameter counts, null bitmaps, and value encoding.
  • Provides a detailed JSON example to illustrate the expected output for parameter logging.
Files not reviewed (1)
  • include/MySQL_Logger.hpp: Language not supported
Comments suppressed due to low confidence (1)

doc/internal/MySQL_Logging_Prepared_Statements_Parameters.md:56

  • The JSON example appears to be missing a comma after the 'starttime' field, which results in invalid JSON format. Please insert the missing comma to ensure the example is syntactically correct.
    "starttime": "2021-03-31 12:32:00.000000"

eventlog_reader_to_json.cpp is the first iteration of a tool able to read an
eventlog in binary format and generate a JSON
Still not completed.
We still need an automatic way to verify the generated files.
In write_query_format_1() :
* write the number of parameters (previously erroneously skipped)
* write null_bitmap only if there are parameters
* write the parameters values (this was previously erroneously skipped)

In test_ps_logging-t.cpp :
* verify that query logging is configured to file

In eventlog_reader_to_json.cpp :
* added verbose logging
* added enum `log_event_type` for properly identifying event type
* parse all events in the input file
Extending test_ps_logging-t with more data types
@renecannao renecannao merged commit 77247a1 into v3.0 Apr 14, 2025
30 of 162 checks passed
@renecannao renecannao deleted the v3.0-4861-mysql-logging_prepared_statement_parameters branch March 7, 2026 20:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants