QUERY_EVENT

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

This event is written into the binary log file for:

  • STATEMENT based replication (updating statements)
  • DDLs
  • COMMIT related to non transactional engines (MyISAM, BLACKHOLE etc)
  • Event Type = 0x02

Fields

Fixed data part:

  • uint<4> The ID of the thread that issued this statement on the master.
  • uint<4> The time in seconds that the statement took to execute.
  • uint<1> The length of the name of the database which was the default database when the statement was executed. This name appears later, in the variable data part. It is necessary for statements such as INSERT INTO t VALUES(1) that don't specify the database and rely on the default database previously selected by USE.
  • uint<2> The error code resulting from execution of the statement on the master.
  • uint<2> The length of the status variable block.

Variable data part:

  • byte<n> Zero or more status variables. Each status variable consists of one byte code identifying the variable stored, followed by the value of the variable. The format of the value is variable-specific.
    The number of bytes 'n' is the length of the status variable block (read in fixed data part)
  • string<NUL> The default database name (null-terminated).
  • string<EOF> The SQL statement. By subtraction the size of the statement can be known.

Example With CRC32

71 17 28 5a 02 8c 27 00  00 55 00 00 00 01 09 00  q.(Z..'..U......
00 00 00 66 01 00 00 00  00 00 00 00 00 00 1a 00  ...f............
00 00 00 00 00 01 00 00  00 50 00 00 00 00 06 03  .........P......
73 74 64 04 08 00 08 00  08 00 00 54 52 55 4e 43  std........TRUNC
41 54 45 20 54 41 42 4c  45 20 74 65 73 74 2e 74  ATE TABLE test.t
34 4a 69 9e ed                                    4Ji..

Header, 19 Bytes

  • Event Time[4] = 71 17 28 5a ===> 1512576881
  • Event Type[1] = 2
  • Server_id[4] = 8c 27 00 00 ===> 10124
  • Event Size = 55 00 00 00 ===> 85
  • Next Pos = 01 09 00 00 ===> 2305
  • Flags = 00 00 => 0

Content, Variable Data

  • Thread ID[4] = 66 01 00 00 ===> 358
  • Execution Time[4] = 00 00 00 00 => 0 seconds
  • Statement default database name len[1] = 00 => 0 (no default db)
  • Error code[2] = 00 00 => 0 (no errors)
  • Status variable block len[2] = 1a 00 => 26
  • Status variables[n] = 00 ... 08 00
  • The default database[string<NUL>] = 00 = 0 (no default db)
  • The SQL statement[string<EOF>] = TRUNCATE TABLE test.t4

CRC32, 4 Bytes

  • 4a 69 9e ed

Example With Default db and CRC32

MariaDB []> use test;
Database changed
MariaDB [test]> TRUNCATE TABLE t4;
...

ce 22 28 5a 02 8c 27 00  00 54 00 00 00 87 0c 00  ."(Z..'..T......
00 00 00 66 01 00 00 01  00 00 00 04 00 00 1a 00  ...f............
00 00 00 00 00 01 00 00  00 50 00 00 00 00 06 03  .........P......
73 74 64 04 08 00 08 00  08 00 74 65 73 74 00 54  std.......test.T
52 55 4e 43 41 54 45 20  54 41 42 4c 45 20 74 34  RUNCATE TABLE t4
08 f1 09 16                                       ....

Content, Variable Data

  • Thread ID[4] = 66 01 00 00 ===> 358
  • Execution Time[4] = 10 00 00 00 => 1 second
  • Statement default database name len[1] = 04 => 4 (default db is "test")
  • Error code[2] = 00 00 => 0 (no errors)
  • Status variable block len[2] = 1a 00 => 26
  • Status variables[n] = 00 ... 08 00
  • The default database[string<NUL>] = 74 65 73 74 00 =>test
  • The SQL statement[string<EOF>] = TRUNCATE TABLE test.t4

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.