0 - Packet

You are viewing an old version of this article. View the current version here.

Client - server exchanges are done using the following format :

Standard packet

Standard MySQL/MariaDB Packet have a 4 bytes header + packet body.

Packet length is the length of the packet body. Packet length size cannot be more than 3 bytes length value ( = 16777215). Sequence number indicate exchange number when an exchange demand different exchanges. first seqence is 0.

Example : Sending a COM_PING packet COM_PING body has only one byte (0x10):

01 00 00 00 10

Server will then return an OK_Packet response with a sequence number of 1.

Packet splitting

Server will have a buffer to store the send body with a maximum size corresponding to max_allowed_packet variable.

So if max_allowed_packet value < 16777215, packet length must not never be superior to max_allowed_paclet value. If not, server will close the connection.

If max_allowed_packet >= 16777215, then multiple packet can be send to send the data. Server will read packets until packet length != 0xffffff, data beeing added in server buffer.

Example max_allowed_packet is set to a value > to 40 Mbytes Sending a 40M bytes packet body : standard_packet
First packet will be :

ff ff ff 00 ...

second packet will be

ff ff ff 01 ...

third packet will be

02 00 80 02 ...



Compressed packet

For slow connection, packet can be compressed. this is activate after the handshake-response-packet when Client indicate [[https://mariadb.com/kb/en/mariadb/1-connecting-connecting/#capabilities|COMPRESS] capability with server having this functionnality too.

When activated, packets will be composed of 7 bytes a compress header + data, data being the compressed or uncompressed value of one or many standard packets.

  • int<3> compress packet length
  • int<1> compress sequence number
  • int<3> uncompress packet length
  • byte<n> compress body
    • compress body contain one or many standard packet but can be compressed :

Since compress body can contain many "standard packet", compress sequence number is incremented separatly from sequence number.

For small packet, using compression won't be efficient, so client can choose to send uncompress data.
That is done by setting compress packet length to real length and uncompress packet length to 0. (Data must then be uncompressed).

Example : Sending a COM_PING packet COM_PING body when COMPRESS is enable. This is a 1 byte data, that has then no reason to be compressed. so

01 00 00 00 00 00 00 01 00 00 00 10

Server will then return an OK_Packet response with a compress sequence number of 1, and a sequence number of 1.

Compression packet splitting

server will uncompress data and then must have the same packet than if there was no compression. If data size need splitting, better to separate compress packet.

compress_packet

Comments

Comments loading...
Content reproduced on this site is the property of its respective owners, and this content is not reviewed in advance by MariaDB. The views, information and opinions expressed by this content do not necessarily represent those of MariaDB or any other party.