Skip to main content

Posts

Showing posts with the label protocol

The Potential of Query Attributes in MySQL

Introduction Query Attributes are a relatively new feature of the MySQL Protocol. This is availble since MySQL 8.0.23. Before Query Attributes were introduced there already was already another similar feature: Connetion Attributes, which provides per-connection metadata in the form of key/value pairs. This is what connection attributes look like: mysql > SELECT ATTR_NAME, ATTR_VALUE -> FROM performance_schema.session_connect_attrs -> WHERE PROCESSLIST_ID = 64 ; +------------------+---------------------+ | ATTR_NAME | ATTR_VALUE | +------------------+---------------------+ | _platform | amd64 | | _runtime_version | go1.23.4 | | _client_version | (devel) | | _client_role | binary_log_listener | | _client_name | go-mysql | | _os | linux | +------------------+---------------------+ 6 rows in set (0.00 sec) Connection attributes are set by connectors (wi...

MySQL Protocol: Collations

This story starts with a pull request for go-mysql to allow setting the collation in auth handshake that I was reviewing. The reason why the author wanted to do this is to speedup the connection setup as he has a latency sensitive application and a lot of connection setups and tear downs. While looking at this I noticed that the collation would be stored in a single byte. However the list of supported collations shows collations with an ID that’s more than 255. mysql> SELECT MIN(ID),MAX(ID) FROM information_schema.collations; +---------+---------+ | MIN(ID) | MAX(ID) | +---------+---------+ | 1 | 323 | +---------+---------+ 1 row in set (0.00 sec) The protocol documentation for Protocol::HandshakeResponse41 says that the value sent here is only the lower 8-bits. So I was wondering how do other connectors send this to the server? Are the other 8-bits sent elsewhere in the protocol? So I used MySQL Connector/Python to try this out. import mysql.connector c = mysq...

Notes on Compression in the MySQL Protocol

The MySQL Protocol is the network protocol that is used between a MySQL server and a client. This is called the “classic” protocol as there is now a newer protobuf based protocol called X Protocol . However the “classic” protocol is used by many database drivers, applications, etc. and also by MySQL Replication. The MySQL Protocol has the option to compress network traffic. Most client libraries don’t enable this by default as this increases CPU usage. Some history Initially this was added in MySQL 3.22 (based on historical release notes) and was based on zlib . Then in MySQL 8.0.18 a second compression algorithm, Zstandard , was added based on a contribution by Facebook . So zlib has been there basically forever and Zstandard support is new-ish (8.0.18 was released in October 2019). Why you might want to use compression. There are multiple usecases that are often mentioned when talking about the compressed protocol. The first one is slow connections. This could, for example, ...