Bug #90420 Contribution by Facebook: Query attributes

Submitted: 13 Apr 2018 0:21 Modified: 18 Jan 2021 12:26
Reporter: FBContrib Admin Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: Connection Handling Severity:S4 (Feature request)
Version:8.0.11 OS:Any
Assigned to: CPU Architecture:Any

[13 Apr 2018 0:21] FBContrib Admin
Description:
Background innformation provided by Facebook:

Abstract:

This adds a way to tag COM_QUERY requests.
Currently, queries sent over the network are encoded as follows:
      total packet length
      COM_QUERY
      query string

The length of the query string is implicit from and calculated from the packet length. This change adds a new command called COM_QUERY_ATTRS with the following structure
       total packet length
       COM_QUERY_ATTRS
       total attributes length
       attributes string
       query string

Note that query string length is still implicit. In order to avoid conflicting RPC values with Oracle, COM_QUERY_ATTRS was put at the end of the valid RPC range. Its value is set at 255.

For upstream purposes, COM_QUERY_ATTRS and COM_QUERY can probably be merged, using capability flags to help with the format change.

Repo: https://github.com/mysql/mysql-server
Patch on top of 8.0.4: https://github.com/mysql/mysql-server/commit/577fbcf856cd693434d554545d499559bcdd3695
Facebook commits: https://github.com/facebook/mysql-5.6/commit/a619992

How to repeat:
See description

Suggested fix:
See contribution code attached
[13 Apr 2018 0:21] FBContrib Admin
Query attributes 
(*) This code is contributed under the Facebook agreement

Contribution: fb_patch_43.txt (text/plain), 20.84 KiB.

[1 Oct 2018 22:27] FBContrib Admin
Query attributes for 8.0.11 
(*) This code is contributed under the Facebook agreement

Contribution: fb_patch_83.txt (text/plain), 22.16 KiB.

[18 Jan 2021 8:17] Georgi Kodinov
Implemented as WL#12542 in 8.0.23
[18 Jan 2021 12:26] Paul DuBois
Posted by developer:
 
Fixed in 8.0.23.

For some applications, it may be useful to define metadata on a
per-query basis. Examples include the URL of the page that produced a
query, or extra processing information to be passed with a query for
use by a plugin such as an audit plugin or query rewrite plugin.
MySQL now supports this capability without the use of workarounds
such as specially formatted comments included in query strings:

* On the client side, the mysql_bind_param() C API function enables
  defining query attributes. These attributes apply to the next SQL
  statement sent to the server for execution. Additionally, the mysql and
  mysqltest clients have a query_attributes command that enables defining
  query attributes.

* On the server side, a component service provides access to query
  attributes. A component named query_attributes uses this service to
  implement a mysql_query_attribute_string() user-defined function (UDF)
  that enables obtaining attribute values within SQL statements. The
  query_attributes component is optional but must be installed for the UDF
  to be available.

Thanks to Facebook for suggesting the idea (and for contributing
code, although it was not used).

Portions of this website are copyright © 2001, 2002 The PHP Group

Page generated in 0.042 sec. using MySQL 8.4.7-u6-cloud

Timestamp references displayed by the system are UTC.
Content reproduced on this site is the property of the respective copyright holders.
It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.