[MDEV-19237] Skip sending metadata when possible for binary protocol Created: 2019-04-11 Updated: 2021-07-29 Resolved: 2020-11-23 |
|
| Status: | Closed |
| Project: | MariaDB Server |
| Component/s: | Prepared Statements |
| Fix Version/s: | 10.6.0 |
| Type: | Task | Priority: | Critical |
| Reporter: | Diego Dupin | Assignee: | Vladislav Vaintroub |
| Resolution: | Fixed | Votes: | 1 |
| Labels: | None | ||
| Issue Links: |
|
||||||||||||||||||||||||||||||||||||||||||||
| Description |
|
This task goal is to permit not sending metadata every time What MySQL has done in version 8MySQL has changed the protocol to permit skipping metadata for version 8. In description MySQL task indicate some big improvement:
MySQL implementation send metadata (or not) according to resultset_metadata variable. When resultset_metadata = 0 (NONE) no metadata is send for COM_STMT_PREPARE/COM_STMT_EXECUTE/COM_QUERY Exchange format changeColumn count packetThere is a "new metadata_follows flag"
When metadata_follows = 0x00, protocol skip column informations packet (continuing by an EOF_packet if CLIENT_DEPRECATE_EOF capability is not set or rows if CLIENT_DEPRECATE_EOF is set). COM_PREPARE response
if metadata is set to 0x00, column definition packet that decribe each parameter and each column are skipped. Requirement:Connectors need metadata to parse resultset. What do connectors need: For first execute of a prepared statement:
For next execute:
There are two issues with not sending metadata each time:
COM_STMT_PREPARE still need to have the possibility to ask for metadata (at least java need that possibility to have metadata (example) without any COM_STMT_EXECUTE execution) For production environment where DDL never change an option can be set on client level to use that same functionality for COM_QUERY. MySQL doesn't permits modularity, so client request have to add this information.
|
| Comments |
| Comment by Vladislav Vaintroub [ 2019-04-17 ] |
|
I think EOF packet is not needed after column count 0xFC0000. It is not easy to imagine any of the existing clients would be able to cope with 0 metadata packets |
| Comment by Sergei Golubchik [ 2020-07-21 ] |
|
An approach that won't need need new COM commands and no application side changes could be:
Practically it'll mean that metadata will only be sent on COM_STMT_PREPARE. Connector will need to cache the metadata and update the cache every time metadata is received. Note: multiple result sets. A connector should be able to cache multiple metadata sets per one prepared statement. This approach will work automatically for any application as soon as the connector and the server are upgraded. One can reduce the transferred data even more with application-aware changes. Meaning, application tells the server "don't send any metadata, I know it already or don't care". I would suggest to move this application-aware optimization into a separate MDEV. |
| Comment by Vladislav Vaintroub [ 2020-10-06 ] |
|
I think with multiple result sets, it is rather peculiar. A prepared statement can produce multiple result sets. It happens (only) if it is a prepared CALL, However CALL can also have a single designated result set, which might be OK to cache on the client - output parameters set. With this, I think client should only be able to cache a single result set, and the server can have at most one "skip-metadata" result set per COM_STMT_EXECUTE. Note : semicolon-batch can't be prepared, and the protocol has no provision to report multiple results sets during COM_STMT_PREPARE. |
| Comment by Vladislav Vaintroub [ 2020-10-29 ] |
|
sanja, could you please review ? Currently the detection of change is always based checksumming fields to be sent, but when MDEV-23913 is fixed, and MDEV_23913_FIXED is removed, it will be more efficient. Then change of the metadata will be almost always derived from whether reprepare ran, and fallbacks to checksumming will only be in degenerate cases, like SELECT ? or SELECT @user_var, or SELECT GREATEST(@a,@b) basically, when the type or the length/decimals etc of the result depends on user variables or a parameter |
| Comment by Vladislav Vaintroub [ 2020-11-23 ] |
|
Address Review comments, add vertical space and doxygenize function comments |