Query Attributes in MySQL are a new feature introduced in MySQL Protocol available since version 8.0.23.
They offer per-query metadata in the form of key/value pairs, in contrast to Connection Attributes which provide per-connection metadata.
Connection attributes are set by connectors or applications, aiding in understanding what connects to the server, but have limitations in certain scenarios.
Query Attributes, when the CLIENT_QUERY_ATTRIBUTES flag is set, allow setting key/value pairs on a per-query basis, distinct from connection attributes.
Changes in network packets for COM_STMT_EXECUTE and COM_QUERY commands enable sending parameters and parameter names with queries.
MySQL C API introduces functions like mysql_bind_param() and mysql_stmt_bind_named_param() to send query attributes with regular and prepared statements.
MySQL Connectors like MySQL Connector/Python and MySQL Connector/J have added functions to support query attributes.
MySQL Client now allows setting query attributes using 'query_attributes ' to enhance query metadata.
Query Attributes can be used for sending metadata like Trace ID, user info, page name, etc., improving trace linking, proxying, or web page rendering.
Despite the benefits, query attributes still have limitations, including not being included in binlogs, general log, or slow query log.