MySQL 8.4.2
Source Code Documentation
statement_events.h
Go to the documentation of this file.
1/* Copyright (c) 2014, 2024, Oracle and/or its affiliates.
2
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License, version 2.0,
5 as published by the Free Software Foundation.
6
7 This program is designed to work with certain software (including
8 but not limited to OpenSSL) that is licensed under separate terms,
9 as designated in a particular file or component or in included license
10 documentation. The authors of MySQL hereby grant you an additional
11 permission to link the program and your derivative works with the
12 separately licensed software that they have either included with
13 the program or referenced in the documentation.
14
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License, version 2.0, for more details.
19
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
23
24/**
25 @file statement_events.h
26
27 @brief Contains the classes representing statement events occurring in the
28 replication stream. Each event is represented as a byte sequence with logical
29 divisions as event header, event specific data and event footer. The header
30 and footer are common to all the events and are represented as two different
31 subclasses.
32*/
33
34#ifndef MYSQL_BINLOG_EVENT_STATEMENT_EVENTS_H
35#define MYSQL_BINLOG_EVENT_STATEMENT_EVENTS_H
36
39
40/// @addtogroup GroupLibsMysqlBinlogEvent
41/// @{
42
43namespace mysql::binlog::event {
44/**
45 The following constant represents the maximum of MYSQL_XID domain.
46 The maximum XID value practically is never supposed to grow beyond UINT64
47 range.
48*/
49const uint64_t INVALID_XID = 0xffffffffffffffffULL;
50
51/**
52 @class Query_event
53
54 A @c Query_event is created for each query that modifies the
55 database, unless the query is logged row-based.
56
57 @section Query_event_binary_format Binary format
58
59 See @ref Binary_log_event_binary_format "Binary format for log events" for
60 a general discussion and introduction to the binary format of binlog
61 events.
62
63 The Post-Header has five components:
64
65 <table>
66 <caption>Post-Header for Query_event</caption>
67
68 <tr>
69 <th>Name</th>
70 <th>Format</th>
71 <th>Description</th>
72 </tr>
73
74 <tr>
75 <td>thread_id</td>
76 <td>4 byte unsigned integer</td>
77 <td>The ID of the thread that issued this statement. It is needed for
78 temporary tables.</td>
79 </tr>
80
81 <tr>
82 <td>query_exec_time</td>
83 <td>4 byte unsigned integer</td>
84 <td>The time from when the query started to when it was logged in
85 the binlog, in seconds.</td>
86 </tr>
87
88 <tr>
89 <td>db_len</td>
90 <td>1 byte integer</td>
91 <td>The length of the name of the currently selected database.</td>
92 </tr>
93
94 <tr>
95 <td>error_code</td>
96 <td>2 byte unsigned integer</td>
97 <td>Error code generated by the master. If the master fails, the
98 slave will fail with the same error code.
99 </td>
100 </tr>
101
102 <tr>
103 <td>status_vars_len</td>
104 <td>2 byte unsigned integer</td>
105 <td>The length of the status_vars block of the Body, in bytes. This is not
106 present for binlog version 1 and 3. See
107 @ref Query_event_status_vars "below".
108 </td>
109 </tr>
110 </table>
111
112 The Body has the following components:
113
114 <table>
115 <caption>Body for Query_event</caption>
116
117 <tr>
118 <th>Name</th>
119 <th>Format</th>
120 <th>Description</th>
121 </tr>
122
123 <tr>
124 <td>@anchor Query_event_status_vars status_vars</td>
125 <td>status_vars_len bytes</td>
126 <td>Zero or more status variables. Each status variable consists
127 of one byte identifying the variable stored, followed by the value
128 of the variable. The possible variables are listed separately in
129 the table @ref Table_query_event_status_vars "below". MySQL
130 always writes events in the order defined below; however, it is
131 capable of reading them in any order. </td>
132 </tr>
133
134 <tr>
135 <td>m_db</td>
136 <td>db_len + 1</td>
137 <td>The currently selected database, as a null-terminated string.
138
139 (The trailing zero is redundant since the length is already known;
140 it is db_len from Post-Header.)
141 </td>
142 </tr>
143
144 <tr>
145 <td>m_query</td>
146 <td>variable length string without trailing zero, extending to the
147 end of the event (determined by the length field of the
148 Common-Header)
149 </td>
150 <td>The SQL query.</td>
151 </tr>
152 </table>
153
154 The following table lists the status variables that may appear in
155 the status_vars field.
156
157 @anchor Table_query_event_status_vars
158 <table>
159 <caption>Status variables for Query_event</caption>
160
161 <tr>
162 <th>Status variable</th>
163 <th>1 byte identifier</th>
164 <th>Format</th>
165 <th>Description</th>
166 </tr>
167
168 <tr>
169 <td>flags2</td>
170 <td>Q_FLAGS2_CODE == 0</td>
171 <td>4 byte bitfield</td>
172 <td>The flags in @c thd->options, binary AND-ed with @c
173 OPTIONS_WRITTEN_TO_BIN_LOG. The @c thd->options bitfield contains
174 options for "SELECT". @c OPTIONS_WRITTEN identifies those options
175 that need to be written to the binlog (not all do). Specifically,
176 @c OPTIONS_WRITTEN_TO_BIN_LOG equals (@c OPTION_AUTO_IS_NULL | @c
177 OPTION_NO_FOREIGN_KEY_CHECKS | @c OPTION_RELAXED_UNIQUE_CHECKS |
178 @c OPTION_NOT_AUTOCOMMIT), or 0x0c084000 in hex.
179
180 These flags correspond to the SQL variables SQL_AUTO_IS_NULL,
181 FOREIGN_KEY_CHECKS, UNIQUE_CHECKS, and AUTOCOMMIT, documented in
182 the "SET Syntax" section of the MySQL Manual.
183
184 This field is always written to the binlog in version >= 5.0, and
185 never written in version < 5.0.
186 </td>
187 </tr>
188
189 <tr>
190 <td>sql_mode</td>
191 <td>Q_SQL_MODE_CODE == 1</td>
192 <td>8 byte bitfield</td>
193 <td>The @c sql_mode variable. See the section "SQL Modes" in the
194 MySQL manual, and see sql_class.h for a list of the possible
195 flags. Currently (2007-10-04), the following flags are available:
196 <pre>
197 MODE_REAL_AS_FLOAT==0x1
198 MODE_PIPES_AS_CONCAT==0x2
199 MODE_ANSI_QUOTES==0x4
200 MODE_IGNORE_SPACE==0x8
201 MODE_NOT_USED==0x10
202 MODE_ONLY_FULL_GROUP_BY==0x20
203 MODE_NO_UNSIGNED_SUBTRACTION==0x40
204 MODE_NO_DIR_IN_CREATE==0x80
205 MODE_ANSI==0x80000
206 MODE_NO_AUTO_VALUE_ON_ZERO==0x100000
207 MODE_NO_BACKSLASH_ESCAPES==0x200000
208 MODE_STRICT_TRANS_TABLES==0x400000
209 MODE_STRICT_ALL_TABLES==0x800000
210 MODE_NO_ZERO_IN_DATE==0x1000000
211 MODE_NO_ZERO_DATE==0x2000000
212 MODE_INVALID_DATES==0x4000000
213 MODE_ERROR_FOR_DIVISION_BY_ZERO==0x8000000
214 MODE_TRADITIONAL==0x10000000
215 MODE_HIGH_NOT_PRECEDENCE==0x40000000
216 MODE_PAD_CHAR_TO_FULL_LENGTH==0x80000000
217 MODE_TIME_TRUNCATE_FRACTIONAL==0x100000000
218 </pre>
219 All these flags are replicated from the server. However, all
220 flags except @c MODE_NO_DIR_IN_CREATE are honored by the slave;
221 the slave always preserves its old value of @c
222 MODE_NO_DIR_IN_CREATE.
223
224 This field is always written to the binlog.
225 </td>
226 </tr>
227
228 <tr>
229 <td>catalog</td>
230 <td>Q_CATALOG_NZ_CODE == 6</td>
231 <td>Variable-length string: the length in bytes (1 byte) followed
232 by the characters (at most 255 bytes)
233 </td>
234 <td>Stores the client's current catalog. Every database belongs
235 to a catalog, the same way that every table belongs to a
236 database. Currently, there is only one catalog, "std".
237
238 This field is written if the length of the catalog is > 0;
239 otherwise it is not written.
240 </td>
241 </tr>
242
243 <tr>
244 <td>auto_increment</td>
245 <td>Q_AUTO_INCREMENT == 3</td>
246 <td>two 2 byte unsigned integers, totally 2+2=4 bytes</td>
247
248 <td>The two variables auto_increment_increment and
249 auto_increment_offset, in that order. For more information, see
250 "System variables" in the MySQL manual.
251
252 This field is written if auto_increment > 1. Otherwise, it is not
253 written.
254 </td>
255 </tr>
256
257 <tr>
258 <td>charset</td>
259 <td>Q_CHARSET_CODE == 4</td>
260 <td>three 2 byte unsigned integers, totally 2+2+2=6 bytes</td>
261 <td>The three variables character_set_client,
262 collation_connection, and collation_server, in that order.
263 character_set_client is a code identifying the character set and
264 collation used by the client to encode the query.
265 collation_connection identifies the character set and collation
266 that the master converts the query to when it receives it; this is
267 useful when comparing literal strings. collation_server is the
268 default character set and collation used when a new database is
269 created.
270
271 See also "Connection Character Sets and Collations" in the MySQL
272 5.1 manual.
273
274 All three variables are codes identifying a (character set,
275 collation) pair. To see which codes map to which pairs, run the
276 query "SELECT id, character_set_name, collation_name FROM
277 COLLATIONS".
278
279 Cf. Q_CHARSET_DATABASE_CODE below.
280
281 This field is always written.
282 </td>
283 </tr>
284
285 <tr>
286 <td>time_zone</td>
287 <td>Q_TIME_ZONE_CODE == 5</td>
288 <td>Variable-length string: the length in bytes (1 byte) followed
289 by the characters (at most 255 bytes).
290 <td>The time_zone of the master.
291
292 See also "System Variables" and "MySQL Server Time Zone Support"
293 in the MySQL manual.
294
295 This field is written if the length of the time zone string is >
296 0; otherwise, it is not written.
297 </td>
298 </tr>
299
300 <tr>
301 <td>lc_time_names_number</td>
302 <td>Q_LC_TIME_NAMES_CODE == 7</td>
303 <td>2 byte integer</td>
304 <td>A code identifying a table of month and day names. The
305 mapping from codes to languages is defined in @c sql_locale.cc.
306
307 This field is written if it is not 0, i.e., if the locale is not
308 en_US.
309 </td>
310 </tr>
311
312 <tr>
313 <td>charset_database_number</td>
314 <td>Q_CHARSET_DATABASE_CODE == 8</td>
315 <td>2 byte integer</td>
316
317 <td>The value of the collation_database system variable (in the
318 source code stored in @c thd->variables.collation_database), which
319 holds the code for a (character set, collation) pair as described
320 above (see Q_CHARSET_CODE).
321
322 collation_database was used in old versions (???WHEN). Its value
323 was loaded when issuing a "use db" query and could be changed by
324 issuing a "SET collation_database=xxx" query. It used to affect
325 the "LOAD DATA INFILE" and "CREATE TABLE" commands.
326
327 In newer versions, "CREATE TABLE" has been changed to take the
328 character set from the database of the created table, rather than
329 the character set of the current database. This makes a
330 difference when creating a table in another database than the
331 current one. "LOAD DATA INFILE" has not yet changed to do this,
332 but there are plans to eventually do it, and to make
333 collation_database read-only.
334
335 This field is written if it is not 0.
336 </td>
337 </tr>
338 <tr>
339 <td>table_map_for_update</td>
340 <td>Q_TABLE_MAP_FOR_UPDATE_CODE == 9</td>
341 <td>8 byte integer</td>
342
343 <td>The value of the table map that is to be updated by the
344 multi-table update query statement. Every bit of this variable
345 represents a table, and is set to 1 if the corresponding table is
346 to be updated by this statement.
347
348 The value of this variable is set when executing a multi-table update
349 statement and used by slave to apply filter rules without opening
350 all the tables on slave. This is required because some tables may
351 not exist on slave because of the filter rules.
352 </td>
353 </tr>
354 <tr>
355 <td>master_data_written</td>
356 <td>Q_MASTER_DATA_WRITTEN_CODE == 10</td>
357 <td>4 byte bitfield</td>
358
359 <td>The value of the original length of a Query_event that comes from a
360 master. Master's event is relay-logged with storing the original size of
361 event in this field by the IO thread. The size is to be restored by reading
362 Q_MASTER_DATA_WRITTEN_CODE-marked event from the relay log.
363
364 This field is not written to slave's server binlog by the SQL thread.
365 This field only exists in relay logs where master has binlog_version<4 i.e.
366 server_version < 5.0 and the slave has binlog_version=4.
367 </td>
368 </tr>
369 <tr>
370 <td>binlog_invoker</td>
371 <td>Q_INVOKER == 11</td>
372 <td>2 Variable-length strings: the length in bytes (1 byte) followed
373 by characters (user), again followed by length in bytes (1 byte) followed
374 by characters(host)</td>
375
376 <td>The value of boolean variable m_binlog_invoker is set TRUE if
377 CURRENT_USER() is called in account management statements. SQL thread
378 uses it as a default definer in CREATE/ALTER SP, SF, Event, TRIGGER or
379 VIEW statements.
380
381 The field Q_INVOKER has length of user stored in 1 byte followed by the
382 user string which is assigned to 'user' and the length of host stored in
383 1 byte followed by host string which is assigned to 'host'.
384 </td>
385 </tr>
386 <tr>
387 <td>mts_accessed_dbs</td>
388 <td>Q_UPDATED_DB_NAMES == 12</td>
389 <td>1 byte character, and a 2-D array</td>
390 <td>The total number and the names to of the databases accessed is stored,
391 to be propagated to the slave in order to facilitate the parallel
392 applying of the Query events.
393 </td>
394 </tr>
395 <tr>
396 <td>explicit_defaults_ts</td>
397 <td>Q_EXPLICIT_DEFAULTS_FOR_TIMESTAMP</td>
398 <td>1 byte boolean</td>
399 <td>Stores master connection @@session.explicit_defaults_for_timestamp when
400 CREATE and ALTER operate on a table with a TIMESTAMP column. </td>
401 </tr>
402 <tr>
403 <td>ddl_xid</td>
404 <td>Q_DDL_LOGGED_WITH_XID</td>
405 <td>8 byte integer</td>
406 <td>Stores variable carrying xid info of 2pc-aware (recoverable) DDL
407 queries. </td>
408 </tr>
409 <tr>
410 <td>default_collation_for_utf8mb4_number</td>
411 <td>Q_DEFAULT_COLLATION_FOR_UTF8MB4</td>
412 <td>2 byte integer</td>
413 <td>Stores variable carrying the the default collation for the utf8mb4
414 character set. Mainly used to support replication 5.7- master to a 8.0+
415 slave.
416 </td>
417 </tr>
418 <tr>
419 <td>sql_require_primary_key</td>
420 <td>Q_SQL_REQUIRE_PRIMARY_KEY</td>
421 <td>2 byte integer</td>
422 <td>Value of the config variable sql_require_primary_key</td>
423 </tr>
424 <tr>
425 <td>default_table_encryption</td>
426 <td>Q_DEFAULT_TABLE_ENCRYPTION</td>
427 <td>2 byte integer</td>
428 <td>Value of the config variable default_table_encryption</td>
429 </tr>
430 </table>
431
432 @subsection Query_event_notes_on_previous_versions Notes on Previous Versions
433
434 * Status vars were introduced in version 5.0. To read earlier
435 versions correctly, check the length of the Post-Header.
436
437 * The status variable Q_CATALOG_CODE == 2 existed in MySQL 5.0.x,
438 where 0<=x<=3. It was identical to Q_CATALOG_CODE, except that the
439 string had a trailing '\0'. The '\0' was removed in 5.0.4 since it
440 was redundant (the string length is stored before the string). The
441 Q_CATALOG_CODE will never be written by a new master, but can still
442 be understood by a new slave.
443
444 * See Q_CHARSET_DATABASE_CODE in the table above.
445
446 * When adding new status vars, please don't forget to update the
447 MAX_SIZE_LOG_EVENT_STATUS.
448
449*/
450
452 public:
453 /** query event post-header */
461 };
462
463 /* these are codes, not offsets; not more than 256 values (1 byte). */
467 /*
468 Q_CATALOG_CODE is catalog with end zero stored; it is used only by MySQL
469 5.0.x where 0<=x<=3. We have to keep it to be able to replicate these
470 old masters.
471 */
476 /*
477 Q_CATALOG_NZ_CODE is catalog withOUT end zero stored; it is used by MySQL
478 5.0.x where x>=4. Saves one byte in every Query_event in binlog,
479 compared to Q_CATALOG_CODE. The reason we didn't simply re-use
480 Q_CATALOG_CODE is that then a 5.0.3 slave of this 5.0.x (x>=4)
481 master would crash (segfault etc) because it would expect a 0 when there
482 is none.
483 */
488 /* It is just a placeholder after 8.0.2*/
491 /*
492 Q_UPDATED_DB_NAMES status variable collects information of accessed
493 databases i.e. the total number and the names to be propagated to the
494 slave in order to facilitate the parallel applying of the Query events.
495 */
498 /*
499 A old (unused now) code for Query_log_event status similar to G_COMMIT_TS.
500 */
502 /*
503 An old (unused after migration to Gtid_event) code for
504 Query_log_event status, similar to G_COMMIT_TS2.
505 */
507 /*
508 The master connection @@session.explicit_defaults_for_timestamp which
509 is recorded for queries, CREATE and ALTER table that is defined with
510 a TIMESTAMP column, that are dependent on that feature.
511 For pre-WL6292 master's the associated with this code value is zero.
512 */
514 /*
515 The variable carries xid info of 2pc-aware (recoverable) DDL queries.
516 */
518 /*
519 This variable stores the default collation for the utf8mb4 character set.
520 Used to support cross-version replication.
521 */
523
524 /*
525 Replicate sql_require_primary_key.
526 */
528
529 /*
530 Replicate default_table_encryption.
531 */
533 };
534 const char *query;
535 const char *db;
536 const char *catalog;
537 const char *time_zone_str;
538
539 protected:
540 const char *user;
541 size_t user_len;
542 const char *host;
543 size_t host_len;
544
545 /* Required by the MySQL server class Log_event::Query_event */
546 unsigned long data_len;
547 /*
548 Copies data into the buffer in the following fashion
549 +--------+-----------+------+------+---------+----+-------+----+
550 | catlog | time_zone | user | host | db name | \0 | Query | \0 |
551 +--------+-----------+------+------+---------+----+-------+----+
552 */
553 int fill_data_buf(unsigned char *dest, unsigned long len);
554
555 public:
556 /* data members defined in order they are packed and written into the log */
557 uint32_t thread_id;
559 size_t db_len;
560 uint16_t error_code;
561 /*
562 We want to be able to store a variable number of N-bit status vars:
563 (generally N=32; but N=64 for SQL_MODE) a user may want to log the number
564 of affected rows (for debugging) while another does not want to lose 4
565 bytes in this.
566 The storage on disk is the following:
567 status_vars_len is part of the post-header,
568 status_vars are in the variable-length part, after the post-header, before
569 the db & query.
570 status_vars on disk is a sequence of pairs (code, value) where 'code' means
571 'sql_mode', 'affected' etc. Sometimes 'value' must be a short string, so
572 its first byte is its length. For now the order of status vars is:
573 flags2 - sql_mode - catalog - autoinc - charset
574 We should add the same thing to Load_event, but in fact
575 LOAD DATA INFILE is going to be logged with a new type of event (logging of
576 the plain text query), so Load_event would be frozen, so no need. The
577 new way of logging LOAD DATA INFILE would use a derived class of
578 Query_event, so automatically benefit from the work already done for
579 status variables in Query_event.
580 */
582 /*
583 If we already know the length of the query string
584 we pass it with q_len, so we would not have to call strlen()
585 otherwise, set it to 0, in which case, we compute it with strlen()
586 */
587 size_t q_len;
588
589 /* The members below represent the status variable block */
590
591 /*
592 'flags2' is a second set of flags (on top of those in Log_event), for
593 session variables. These are thd->options which is & against a mask
594 (OPTIONS_WRITTEN_TO_BIN_LOG).
595 flags2_inited helps make a difference between flags2==0 (3.23 or 4.x
596 master, we don't know flags2, so use the slave server's global options) and
597 flags2==0 (5.0 master, we know this has a meaning of flags all down which
598 must influence the query).
599 */
603
604 uint32_t flags2;
605 /* In connections sql_mode is 32 bits now but will be 64 bits soon */
606 uint64_t sql_mode;
608 char charset[6];
609 size_t time_zone_len; /* 0 means uninited */
610 /*
611 Binlog format 3 and 4 start to differ (as far as class members are
612 concerned) from here.
613 */
614 size_t catalog_len; // <= 255 char; 0 means uninited
615 uint16_t lc_time_names_number; /* 0 means en_US */
617 /*
618 map for tables that will be updated for a multi-table update query
619 statement, for other query statements, this will be zero.
620 */
622 /*
623 The following member gets set to OFF or ON value when the
624 Query-log-event is marked as dependent on
625 @@explicit_defaults_for_timestamp. That is the member is relevant
626 to queries that declare TIMESTAMP column attribute, like CREATE
627 and ALTER.
628 The value is set to @c TERNARY_OFF when @@explicit_defaults_for_timestamp
629 encoded value is zero, otherwise TERNARY_ON.
630 */
636 /*
637 number of updated databases by the query and their names. This info
638 is requested by both Coordinator and Worker.
639 */
640 unsigned char mts_accessed_dbs;
642 /* XID value when the event is a 2pc-capable DDL */
643 uint64_t ddl_xid;
644 /* Default collation for the utf8mb4 set. Used in cross-version replication */
647
649
650 /**
651 The constructor will be used while creating a Query_event, to be
652 written to the binary log.
653 */
654 Query_event(const char *query_arg, const char *catalog_arg,
655 const char *db_arg, uint32_t query_length,
656 unsigned long thread_id_arg, unsigned long long sql_mode_arg,
657 unsigned long auto_increment_increment_arg,
658 unsigned long auto_increment_offset_arg, unsigned int number,
659 unsigned long long table_map_for_update_arg, int errcode);
660
661 /**
662 The constructor receives a buffer and instantiates a Query_event filled in
663 with the data from the buffer
664
665 <pre>
666 The fixed event data part buffer layout is as follows:
667 +---------------------------------------------------------------------+
668 | thread_id | query_exec_time | db_len | error_code | status_vars_len |
669 +---------------------------------------------------------------------+
670 </pre>
671
672 <pre>
673 The fixed event data part buffer layout is as follows:
674 +--------------------------------------------+
675 | Zero or more status variables | db | query |
676 +--------------------------------------------+
677 </pre>
678
679 @param buf Contains the serialized event.
680 @param fde An FDE event (see Rotate_event constructor for more info).
681 @param event_type Required to determine whether the event type is
682 QUERY_EVENT or EXECUTE_LOAD_QUERY_EVENT
683 */
684 Query_event(const char *buf, const Format_description_event *fde,
685 Log_event_type event_type);
686 /**
687 The simplest constructor that could possibly work. This is used for
688 creating static objects that have a special meaning and are invisible
689 to the log.
690 */
692 ~Query_event() override = default;
693
694#ifndef HAVE_MYSYS
695 void print_event_info(std::ostream &info) override;
696 void print_long_info(std::ostream &info) override;
697#endif
698};
699
700/*
701 Check how many bytes are available on buffer.
702
703 @param buf_start Pointer to buffer start.
704 @param buf_current Pointer to the current position on buffer.
705 @param buf_len Buffer length.
706
707 @return Number of bytes available on event buffer.
708*/
709template <class T>
710T available_buffer(const char *buf_start, const char *buf_current, T buf_len) {
711 /* Sanity check */
712 if (buf_current < buf_start ||
713 buf_len < static_cast<T>(buf_current - buf_start))
714 return static_cast<T>(0);
715
716 return static_cast<T>(buf_len - (buf_current - buf_start));
717}
718
719/**
720 Check if jump value is within buffer limits.
721
722 @param jump Number of positions we want to advance.
723 @param buf_start Pointer to buffer start
724 @param buf_current Pointer to the current position on buffer.
725 @param buf_len Buffer length.
726
727 @retval True If jump value is within buffer limits.
728 @retval False Otherwise.
729*/
730template <class T>
731bool valid_buffer_range(T jump, const char *buf_start, const char *buf_current,
732 T buf_len) {
733 return (jump <= available_buffer(buf_start, buf_current, buf_len));
734}
735
736/**
737 @class User_var_event
738
739 Written every time a statement uses a user variable; precedes other
740 events for the statement. Indicates the value to use for the user
741 variable in the next statement. This is written only before a QUERY_EVENT
742 and is not used with row-based logging
743
744 The Post-Header has following components:
745
746 <table>
747 <caption>Post-Header for Format_description_event</caption>
748
749 <tr>
750 <th>Name</th>
751 <th>Format</th>
752 <th>Description</th>
753 </tr>
754
755 <tr>
756 <td>Value_type</td>
757 <td>enum</td>
758 <td>The user variable type.</td>
759 </tr>
760 <tr>
761 <td>User_var_event_data</td>
762 <td>enum</td>
763 <td>User_var event data</td>
764 </tr>
765 <tr>
766 <td>name</td>
767 <td>const char pointer</td>
768 <td>User variable name.</td>
769 </tr>
770 <tr>
771 <td>name_len</td>
772 <td>unsigned int</td>
773 <td>Length of the user variable name</td>
774 </tr>
775 <tr>
776 <td>val</td>
777 <td>char pointer</td>
778 <td>value of the user variable.</td>
779 </tr>
780 <tr>
781 <td>val_len</td>
782 <td>unsigned long</td>
783 <td>Length of the value of the user variable</td>
784 </tr>
785 <tr>
786 <td>type</td>
787 <td>enum Value_type</td>
788 <td>Type of the user variable</td>
789 </tr>
790 <tr>
791 <td>charset_number</td>
792 <td>unsigned int</td>
793 <td>The number of the character set for the user variable (needed for a
794 string variable). The character set number is really a collation
795 number that indicates a character set/collation pair.</td>
796 </tr>
797 <tr>
798 <td>is_null</td>
799 <td>bool</td>
800 <td>Non-zero if the variable value is the SQL NULL value, 0 otherwise.</td>
801 </tr>
802 </table>
803*/
805 public:
814 };
815
816 /**
817 This constructor will initialize the instance variables and the type_code,
818 it will be used only by the server code.
819 */
820 User_var_event(const char *name_arg, unsigned int name_len_arg, char *val_arg,
821 unsigned long val_len_arg, Value_type type_arg,
822 unsigned int charset_number_arg, unsigned char flags_arg)
824 name(bapi_strndup(name_arg, name_len_arg)),
825 name_len(name_len_arg),
826 val(val_arg),
827 val_len(val_len_arg),
828 type(type_arg),
829 charset_number(charset_number_arg),
830 is_null(!val),
831 flags(flags_arg) {}
832
833 /**
834 The constructor receives a buffer and instantiates a User_var_event filled
835 in with the data from the buffer
836 Written every time a statement uses a user variable, precedes other
837 events for the statement. Indicates the value to use for the
838 user variable in the next statement. This is written only before a
839 QUERY_EVENT and is not used with row-based logging.
840
841 The buffer layout for variable data part is as follows:
842 <pre>
843 +-------------------------------------------------------------------+
844 | name_len | name | is_null | type | charset_number | val_len | val |
845 +-------------------------------------------------------------------+
846 </pre>
847
848 @param buf Contains the serialized event.
849 @param fde An FDE event (see Rotate_event constructor for more info).
850 */
851 User_var_event(const char *buf, const Format_description_event *fde);
852 ~User_var_event() override;
853 const char *name;
854 unsigned int name_len;
855 char *val;
856 uint32_t val_len;
858 unsigned int charset_number;
860 unsigned char flags;
861#ifndef HAVE_MYSYS
862 void print_event_info(std::ostream &info) override;
863 void print_long_info(std::ostream &info) override;
864 const char *get_value_type_string(Value_type type_arg) const {
865 switch (type_arg) {
866 case STRING_RESULT:
867 return "String";
868 case REAL_RESULT:
869 return "Real";
870 case INT_RESULT:
871 return "Integer";
872 case ROW_RESULT:
873 return "Row";
874 case DECIMAL_RESULT:
875 return "Decimal";
876 default:
877 return "Unknown";
878 }
879 }
880#endif
881};
882
883/**
884 @class Intvar_event
885
886 An Intvar_event will be created just before a Query_event,
887 if the query uses one of the variables LAST_INSERT_ID or INSERT_ID.
888 Each Intvar_event holds the value of one of these variables.
889
890 @section Intvar_event_binary_format Binary Format
891
892 The Post-Header for this event type is empty. The Body has two
893 components:
894
895 <table>
896 <caption>Body for Intvar_event</caption>
897
898 <tr>
899 <th>Name</th>
900 <th>Format</th>
901 <th>Description</th>
902 </tr>
903
904 <tr>
905 <td>type</td>
906 <td>1 byte enumeration</td>
907 <td>One byte identifying the type of variable stored. Currently,
908 two identifiers are supported: LAST_INSERT_ID_EVENT == 1 and
909 INSERT_ID_EVENT == 2.
910 </td>
911 </tr>
912
913 <tr>
914 <td>val</td>
915 <td>8 byte unsigned integer</td>
916 <td>The value of the variable.</td>
917 </tr>
918
919 </table>
920*/
922 public:
923 uint8_t type;
924 uint64_t val;
925
926 /*
927 The enum recognizes the type of variables that can occur in an
928 INTVAR_EVENT. The two types supported are LAST_INSERT_ID and
929 INSERT_ID, in accordance to the SQL query using LAST_INSERT_ID
930 or INSERT_ID.
931 */
936 };
937
938 /**
939 moving from pre processor symbols from global scope in log_event.h
940 to an enum inside the class, since these are used only by
941 members of this class itself.
942 */
944
945 /**
946 This method returns the string representing the type of the variable
947 used in the event. Changed the definition to be similar to that
948 previously defined in log_event.cc.
949 */
950 std::string get_var_type_string() const {
951 switch (type) {
953 return "INVALID_INT";
955 return "LAST_INSERT_ID";
956 case INSERT_ID_EVENT:
957 return "INSERT_ID";
958 default: /* impossible */
959 return "UNKNOWN";
960 }
961 }
962
963 /**
964 Constructor receives a packet from the MySQL master or the binary
965 log and decodes it to create an Intvar_event.
966
967 The post header for the event is empty. Buffer layout for the variable
968 data part is as follows:
969 <pre>
970 +--------------------------------+
971 | type (4 bytes) | val (8 bytes) |
972 +--------------------------------+
973 </pre>
974
975 @param buf Contains the serialized event.
976 @param fde An FDE event (see Rotate_event constructor for more info).
977 */
978 Intvar_event(const char *buf, const Format_description_event *fde);
979 /**
980 The minimal constructor for Intvar_event it initializes the instance
981 variables type & val and set the type_code as INTVAR_EVENT in the header
982 object in Binary_log_event
983 */
984 Intvar_event(uint8_t type_arg, uint64_t val_arg)
985 : Binary_log_event(INTVAR_EVENT), type(type_arg), val(val_arg) {}
986
987 ~Intvar_event() override = default;
988
989#ifndef HAVE_MYSYS
990 void print_event_info(std::ostream &info) override;
991 void print_long_info(std::ostream &info) override;
992#endif
993};
994
995/**
996 @class Rand_event
997
998 Logs random seed used by the next RAND(), and by PASSWORD() in 4.1.0.
999 4.1.1 does not need it (it's repeatable again) so this event needn't be
1000 written in 4.1.1 for PASSWORD() (but the fact that it is written is just a
1001 waste, it does not cause bugs).
1002
1003 The state of the random number generation consists of 128 bits,
1004 which are stored internally as two 64-bit numbers.
1005
1006 @section Rand_event_binary_format Binary Format
1007
1008 The Post-Header for this event type is empty. The Body has two
1009 components:
1010
1011 <table>
1012 <caption>Body for Rand_event</caption>
1013
1014 <tr>
1015 <th>Name</th>
1016 <th>Format</th>
1017 <th>Description</th>
1018 </tr>
1019
1020 <tr>
1021 <td>seed1</td>
1022 <td>8 byte unsigned integer</td>
1023 <td>64 bit random seed1.</td>
1024 </tr>
1025
1026 <tr>
1027 <td>seed2</td>
1028 <td>8 byte unsigned integer</td>
1029 <td>64 bit random seed2.</td>
1030 </tr>
1031 </table>
1032*/
1034 public:
1035 unsigned long long seed1;
1036 unsigned long long seed2;
1038
1039 /**
1040 This will initialize the instance variables seed1 & seed2, and set the
1041type_code as RAND_EVENT in the header object in Binary_log_event
1042 */
1043 Rand_event(unsigned long long seed1_arg, unsigned long long seed2_arg)
1045 seed1 = seed1_arg;
1046 seed2 = seed2_arg;
1047 }
1048
1049 /**
1050 Written every time a statement uses the RAND() function; precedes other
1051 events for the statement. Indicates the seed values to use for generating a
1052 random number with RAND() in the next statement. This is written only before
1053 a QUERY_EVENT and is not used with row-based logging
1054
1055 <pre>
1056 The buffer layout for variable part is as follows:
1057 +----------------------------------------------+
1058 | value for first seed | value for second seed |
1059 +----------------------------------------------+
1060 </pre>
1061
1062 @param buf Contains the serialized event.
1063 @param fde An FDE event (see Rotate_event constructor for more info).
1064 */
1065 Rand_event(const char *buf, const Format_description_event *fde);
1066#ifndef HAVE_MYSYS
1067 void print_event_info(std::ostream &info) override;
1068 void print_long_info(std::ostream &info) override;
1069#endif
1070};
1071} // end namespace mysql::binlog::event
1072
1073/// @}
1074
1075#endif // MYSQL_BINLOG_EVENT_STATEMENT_EVENTS_H
This is the abstract base class for binary log events.
Definition: binlog_event.h:859
@ QUERY_HEADER_LEN
Definition: binlog_event.h:876
For binlog version 4.
Definition: control_events.h:239
An Intvar_event will be created just before a Query_event, if the query uses one of the variables LAS...
Definition: statement_events.h:921
Intvar_event(const char *buf, const Format_description_event *fde)
Constructor receives a packet from the MySQL master or the binary log and decodes it to create an Int...
Definition: statement_events.cpp:483
uint64_t val
Definition: statement_events.h:924
std::string get_var_type_string() const
This method returns the string representing the type of the variable used in the event.
Definition: statement_events.h:950
Intvar_event(uint8_t type_arg, uint64_t val_arg)
The minimal constructor for Intvar_event it initializes the instance variables type & val and set the...
Definition: statement_events.h:984
Int_event_type
Definition: statement_events.h:932
@ LAST_INSERT_ID_EVENT
Definition: statement_events.h:934
@ INVALID_INT_EVENT
Definition: statement_events.h:933
@ INSERT_ID_EVENT
Definition: statement_events.h:935
uint8_t type
Definition: statement_events.h:923
Intvar_event_offset
moving from pre processor symbols from global scope in log_event.h to an enum inside the class,...
Definition: statement_events.h:943
@ I_TYPE_OFFSET
Definition: statement_events.h:943
@ I_VAL_OFFSET
Definition: statement_events.h:943
A Query_event is created for each query that modifies the database, unless the query is logged row-ba...
Definition: statement_events.h:451
uint16_t error_code
Definition: statement_events.h:560
size_t host_len
Definition: statement_events.h:543
uint8_t default_table_encryption
Definition: statement_events.h:648
Query_event(const char *query_arg, const char *catalog_arg, const char *db_arg, uint32_t query_length, unsigned long thread_id_arg, unsigned long long sql_mode_arg, unsigned long auto_increment_increment_arg, unsigned long auto_increment_offset_arg, unsigned int number, unsigned long long table_map_for_update_arg, int errcode)
The constructor will be used while creating a Query_event, to be written to the binary log.
Definition: statement_events.cpp:53
const char * host
Definition: statement_events.h:542
uint64_t table_map_for_update
Definition: statement_events.h:621
uint16_t auto_increment_increment
Definition: statement_events.h:607
const char * db
Definition: statement_events.h:535
const char * user
Definition: statement_events.h:540
uint64_t sql_mode
Definition: statement_events.h:606
const char * query
Definition: statement_events.h:534
char charset[6]
Definition: statement_events.h:608
uint64_t ddl_xid
Definition: statement_events.h:643
enum mysql::binlog::event::Query_event::enum_ternary explicit_defaults_ts
bool charset_inited
Definition: statement_events.h:602
unsigned char mts_accessed_dbs
Definition: statement_events.h:640
const char * catalog
Definition: statement_events.h:536
uint16_t default_collation_for_utf8mb4_number
Definition: statement_events.h:645
size_t db_len
Definition: statement_events.h:559
const char * time_zone_str
Definition: statement_events.h:537
bool sql_mode_inited
Definition: statement_events.h:601
enum_ternary
Definition: statement_events.h:631
@ TERNARY_OFF
Definition: statement_events.h:633
@ TERNARY_UNSET
Definition: statement_events.h:632
@ TERNARY_ON
Definition: statement_events.h:634
char mts_accessed_db_names[MAX_DBS_IN_EVENT_MTS][NAME_LEN]
Definition: statement_events.h:641
int fill_data_buf(unsigned char *dest, unsigned long len)
Layout for the data buffer is as follows.
Definition: statement_events.cpp:366
uint8_t sql_require_primary_key
Definition: statement_events.h:646
uint32_t flags2
Definition: statement_events.h:604
size_t catalog_len
Definition: statement_events.h:614
Query_event_status_vars
Definition: statement_events.h:464
@ Q_COMMIT_TS2
Definition: statement_events.h:506
@ Q_LC_TIME_NAMES_CODE
Definition: statement_events.h:485
@ Q_COMMIT_TS
Definition: statement_events.h:501
@ Q_CHARSET_CODE
Definition: statement_events.h:474
@ Q_CHARSET_DATABASE_CODE
Definition: statement_events.h:486
@ Q_UPDATED_DB_NAMES
Definition: statement_events.h:496
@ Q_CATALOG_NZ_CODE
Definition: statement_events.h:484
@ Q_TABLE_MAP_FOR_UPDATE_CODE
Definition: statement_events.h:487
@ Q_MICROSECONDS
Definition: statement_events.h:497
@ Q_EXPLICIT_DEFAULTS_FOR_TIMESTAMP
Definition: statement_events.h:513
@ Q_DDL_LOGGED_WITH_XID
Definition: statement_events.h:517
@ Q_INVOKER
Definition: statement_events.h:490
@ Q_DEFAULT_TABLE_ENCRYPTION
Definition: statement_events.h:532
@ Q_SQL_REQUIRE_PRIMARY_KEY
Definition: statement_events.h:527
@ Q_FLAGS2_CODE
Definition: statement_events.h:465
@ Q_SQL_MODE_CODE
Definition: statement_events.h:466
@ Q_AUTO_INCREMENT
Definition: statement_events.h:473
@ Q_TIME_ZONE_CODE
Definition: statement_events.h:475
@ Q_MASTER_DATA_WRITTEN_CODE
Definition: statement_events.h:489
@ Q_CATALOG_CODE
Definition: statement_events.h:472
@ Q_DEFAULT_COLLATION_FOR_UTF8MB4
Definition: statement_events.h:522
uint32_t query_exec_time
Definition: statement_events.h:558
unsigned long data_len
Definition: statement_events.h:546
uint16_t status_vars_len
Definition: statement_events.h:581
size_t user_len
Definition: statement_events.h:541
uint16_t auto_increment_offset
Definition: statement_events.h:607
uint16_t charset_database_number
Definition: statement_events.h:616
uint32_t thread_id
Definition: statement_events.h:557
uint16_t lc_time_names_number
Definition: statement_events.h:615
bool flags2_inited
Definition: statement_events.h:600
Query_event_post_header_offset
query event post-header
Definition: statement_events.h:454
@ Q_DATA_OFFSET
Definition: statement_events.h:460
@ Q_EXEC_TIME_OFFSET
Definition: statement_events.h:456
@ Q_STATUS_VARS_LEN_OFFSET
Definition: statement_events.h:459
@ Q_THREAD_ID_OFFSET
Definition: statement_events.h:455
@ Q_ERR_CODE_OFFSET
Definition: statement_events.h:458
@ Q_DB_LEN_OFFSET
Definition: statement_events.h:457
size_t time_zone_len
Definition: statement_events.h:609
size_t q_len
Definition: statement_events.h:587
Logs random seed used by the next RAND(), and by PASSWORD() in 4.1.0.
Definition: statement_events.h:1033
Rand_event(unsigned long long seed1_arg, unsigned long long seed2_arg)
Definition: statement_events.h:1043
unsigned long long seed1
Definition: statement_events.h:1035
unsigned long long seed2
Definition: statement_events.h:1036
Rand_event_data
Definition: statement_events.h:1037
@ RAND_SEED2_OFFSET
Definition: statement_events.h:1037
@ RAND_SEED1_OFFSET
Definition: statement_events.h:1037
Written every time a statement uses a user variable; precedes other events for the statement.
Definition: statement_events.h:804
const char * name
Definition: statement_events.h:853
uint32_t val_len
Definition: statement_events.h:856
@ UNSIGNED_F
Definition: statement_events.h:807
@ UNDEF_F
Definition: statement_events.h:807
Value_type type
Definition: statement_events.h:857
char * val
Definition: statement_events.h:855
bool is_null
Definition: statement_events.h:859
unsigned int charset_number
Definition: statement_events.h:858
User_var_event_data
Definition: statement_events.h:808
@ UV_VAL_LEN_SIZE
Definition: statement_events.h:809
@ UV_VAL_IS_NULL
Definition: statement_events.h:810
@ UV_CHARSET_NUMBER_SIZE
Definition: statement_events.h:813
@ UV_VAL_TYPE_SIZE
Definition: statement_events.h:811
@ UV_NAME_LEN_SIZE
Definition: statement_events.h:812
~User_var_event() override
Definition: statement_events.cpp:467
User_var_event(const char *name_arg, unsigned int name_len_arg, char *val_arg, unsigned long val_len_arg, Value_type type_arg, unsigned int charset_number_arg, unsigned char flags_arg)
This constructor will initialize the instance variables and the type_code, it will be used only by th...
Definition: statement_events.h:820
unsigned char flags
Definition: statement_events.h:860
unsigned int name_len
Definition: statement_events.h:854
Contains the classes representing events operating in the replication stream properties.
#define MAX_DBS_IN_EVENT_MTS
The maximum number of updated databases that a status of Query-log-event can carry.
Definition: binlog_event.h:117
#define NAME_LEN
Definition: mysql_com.h:67
Definition: buf0block_hint.cc:30
The namespace contains classes representing events that can occur in a replication stream.
Definition: binlog_event.cpp:36
Log_event_type
Enumeration type for the different types of log events.
Definition: binlog_event.h:286
@ QUERY_EVENT
Definition: binlog_event.h:300
@ RAND_EVENT
Definition: binlog_event.h:310
@ INTVAR_EVENT
Definition: binlog_event.h:303
@ USER_VAR_EVENT
Definition: binlog_event.h:311
T available_buffer(const char *buf_start, const char *buf_current, T buf_len)
Definition: statement_events.h:710
bool valid_buffer_range(T jump, const char *buf_start, const char *buf_current, T buf_len)
Check if jump value is within buffer limits.
Definition: statement_events.h:731
const uint64_t INVALID_XID
The following constant represents the maximum of MYSQL_XID domain.
Definition: statement_events.h:49
const char * bapi_strndup(const char *destination, size_t n)
This is a wrapper function, and returns a pointer to a new string which is a duplicate of the input s...
Definition: wrapper_functions.h:150
Item_result
Type of the user defined function return slot and arguments.
Definition: udf_registration_types.h:39
@ STRING_RESULT
not valid for UDFs
Definition: udf_registration_types.h:41
@ DECIMAL_RESULT
not valid for UDFs
Definition: udf_registration_types.h:45
@ REAL_RESULT
char *
Definition: udf_registration_types.h:42
@ INT_RESULT
double
Definition: udf_registration_types.h:43
@ ROW_RESULT
long long
Definition: udf_registration_types.h:44