MySQL 9.5.0
Source Code Documentation
statement_events.h
Go to the documentation of this file.
1/* Copyright (c) 2014, 2025, 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
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 system_variables.h for a list of the possible
195 flags. Currently, 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 MODE_INTERPRET_UTF8_AS_UTF8MB4==0x200000000
219 </pre>
220 All these flags are replicated from the server. However, all
221 flags except @c MODE_NO_DIR_IN_CREATE are honored by the slave;
222 the slave always preserves its old value of @c
223 MODE_NO_DIR_IN_CREATE.
224
225 This field is always written to the binlog.
226 </td>
227 </tr>
228
229 <tr>
230 <td>catalog</td>
231 <td>Q_CATALOG_NZ_CODE == 6</td>
232 <td>Variable-length string: the length in bytes (1 byte) followed
233 by the characters (at most 255 bytes)
234 </td>
235 <td>Stores the client's current catalog. Every database belongs
236 to a catalog, the same way that every table belongs to a
237 database. Currently, there is only one catalog, "std".
238
239 This field is written if the length of the catalog is > 0;
240 otherwise it is not written.
241 </td>
242 </tr>
243
244 <tr>
245 <td>auto_increment</td>
246 <td>Q_AUTO_INCREMENT == 3</td>
247 <td>two 2 byte unsigned integers, totally 2+2=4 bytes</td>
248
249 <td>The two variables auto_increment_increment and
250 auto_increment_offset, in that order. For more information, see
251 "System variables" in the MySQL manual.
252
253 This field is written if auto_increment > 1. Otherwise, it is not
254 written.
255 </td>
256 </tr>
257
258 <tr>
259 <td>charset</td>
260 <td>Q_CHARSET_CODE == 4</td>
261 <td>three 2 byte unsigned integers, totally 2+2+2=6 bytes</td>
262 <td>The three variables character_set_client,
263 collation_connection, and collation_server, in that order.
264 character_set_client is a code identifying the character set and
265 collation used by the client to encode the query.
266 collation_connection identifies the character set and collation
267 that the master converts the query to when it receives it; this is
268 useful when comparing literal strings. collation_server is the
269 default character set and collation used when a new database is
270 created.
271
272 See also "Connection Character Sets and Collations" in the MySQL
273 5.1 manual.
274
275 All three variables are codes identifying a (character set,
276 collation) pair. To see which codes map to which pairs, run the
277 query "SELECT id, character_set_name, collation_name FROM
278 COLLATIONS".
279
280 Cf. Q_CHARSET_DATABASE_CODE below.
281
282 This field is always written.
283 </td>
284 </tr>
285
286 <tr>
287 <td>time_zone</td>
288 <td>Q_TIME_ZONE_CODE == 5</td>
289 <td>Variable-length string: the length in bytes (1 byte) followed
290 by the characters (at most 255 bytes).
291 <td>The time_zone of the master.
292
293 See also "System Variables" and "MySQL Server Time Zone Support"
294 in the MySQL manual.
295
296 This field is written if the length of the time zone string is >
297 0; otherwise, it is not written.
298 </td>
299 </tr>
300
301 <tr>
302 <td>lc_time_names_number</td>
303 <td>Q_LC_TIME_NAMES_CODE == 7</td>
304 <td>2 byte integer</td>
305 <td>A code identifying a table of month and day names. The
306 mapping from codes to languages is defined in @c sql_locale.cc.
307
308 This field is written if it is not 0, i.e., if the locale is not
309 en_US.
310 </td>
311 </tr>
312
313 <tr>
314 <td>charset_database_number</td>
315 <td>Q_CHARSET_DATABASE_CODE == 8</td>
316 <td>2 byte integer</td>
317
318 <td>The value of the collation_database system variable (in the
319 source code stored in @c thd->variables.collation_database), which
320 holds the code for a (character set, collation) pair as described
321 above (see Q_CHARSET_CODE).
322
323 collation_database was used in old versions (???WHEN). Its value
324 was loaded when issuing a "use db" query and could be changed by
325 issuing a "SET collation_database=xxx" query. It used to affect
326 the "LOAD DATA INFILE" and "CREATE TABLE" commands.
327
328 In newer versions, "CREATE TABLE" has been changed to take the
329 character set from the database of the created table, rather than
330 the character set of the current database. This makes a
331 difference when creating a table in another database than the
332 current one. "LOAD DATA INFILE" has not yet changed to do this,
333 but there are plans to eventually do it, and to make
334 collation_database read-only.
335
336 This field is written if it is not 0.
337 </td>
338 </tr>
339 <tr>
340 <td>table_map_for_update</td>
341 <td>Q_TABLE_MAP_FOR_UPDATE_CODE == 9</td>
342 <td>8 byte integer</td>
343
344 <td>The value of the table map that is to be updated by the
345 multi-table update query statement. Every bit of this variable
346 represents a table, and is set to 1 if the corresponding table is
347 to be updated by this statement.
348
349 The value of this variable is set when executing a multi-table update
350 statement and used by slave to apply filter rules without opening
351 all the tables on slave. This is required because some tables may
352 not exist on slave because of the filter rules.
353 </td>
354 </tr>
355 <tr>
356 <td>master_data_written</td>
357 <td>Q_MASTER_DATA_WRITTEN_CODE == 10</td>
358 <td>4 byte bitfield</td>
359
360 <td>The value of the original length of a Query_event that comes from a
361 master. Master's event is relay-logged with storing the original size of
362 event in this field by the IO thread. The size is to be restored by reading
363 Q_MASTER_DATA_WRITTEN_CODE-marked event from the relay log.
364
365 This field is not written to slave's server binlog by the SQL thread.
366 This field only exists in relay logs where master has binlog_version<4 i.e.
367 server_version < 5.0 and the slave has binlog_version=4.
368 </td>
369 </tr>
370 <tr>
371 <td>binlog_invoker</td>
372 <td>Q_INVOKER == 11</td>
373 <td>2 Variable-length strings: the length in bytes (1 byte) followed
374 by characters (user), again followed by length in bytes (1 byte) followed
375 by characters(host)</td>
376
377 <td>The value of boolean variable m_binlog_invoker is set TRUE if
378 CURRENT_USER() is called in account management statements. SQL thread
379 uses it as a default definer in CREATE/ALTER SP, SF, Event, TRIGGER or
380 VIEW statements.
381
382 The field Q_INVOKER has length of user stored in 1 byte followed by the
383 user string which is assigned to 'user' and the length of host stored in
384 1 byte followed by host string which is assigned to 'host'.
385 </td>
386 </tr>
387 <tr>
388 <td>mts_accessed_dbs</td>
389 <td>Q_UPDATED_DB_NAMES == 12</td>
390 <td>1 byte character, and a 2-D array</td>
391 <td>The total number and the names to of the databases accessed is stored,
392 to be propagated to the slave in order to facilitate the parallel
393 applying of the Query events.
394 </td>
395 </tr>
396 <tr>
397 <td>explicit_defaults_ts</td>
398 <td>Q_EXPLICIT_DEFAULTS_FOR_TIMESTAMP</td>
399 <td>1 byte boolean</td>
400 <td>Stores master connection @@session.explicit_defaults_for_timestamp when
401 CREATE and ALTER operate on a table with a TIMESTAMP column. </td>
402 </tr>
403 <tr>
404 <td>ddl_xid</td>
405 <td>Q_DDL_LOGGED_WITH_XID</td>
406 <td>8 byte integer</td>
407 <td>Stores variable carrying xid info of 2pc-aware (recoverable) DDL
408 queries. </td>
409 </tr>
410 <tr>
411 <td>default_collation_for_utf8mb4_number</td>
412 <td>Q_DEFAULT_COLLATION_FOR_UTF8MB4</td>
413 <td>2 byte integer</td>
414 <td>Stores variable carrying the the default collation for the utf8mb4
415 character set. Mainly used to support replication 5.7- master to a 8.0+
416 slave.
417 </td>
418 </tr>
419 <tr>
420 <td>sql_require_primary_key</td>
421 <td>Q_SQL_REQUIRE_PRIMARY_KEY</td>
422 <td>2 byte integer</td>
423 <td>Value of the config variable sql_require_primary_key</td>
424 </tr>
425 <tr>
426 <td>default_table_encryption</td>
427 <td>Q_DEFAULT_TABLE_ENCRYPTION</td>
428 <td>2 byte integer</td>
429 <td>Value of the config variable default_table_encryption</td>
430 </tr>
431 </table>
432
433 @subsection Query_event_notes_on_previous_versions Notes on Previous Versions
434
435 * Status vars were introduced in version 5.0. To read earlier
436 versions correctly, check the length of the Post-Header.
437
438 * The status variable Q_CATALOG_CODE == 2 existed in MySQL 5.0.x,
439 where 0<=x<=3. It was identical to Q_CATALOG_CODE, except that the
440 string had a trailing '\0'. The '\0' was removed in 5.0.4 since it
441 was redundant (the string length is stored before the string). The
442 Q_CATALOG_CODE will never be written by a new master, but can still
443 be understood by a new slave.
444
445 * See Q_CHARSET_DATABASE_CODE in the table above.
446
447 * When adding new status vars, please don't forget to update the
448 MAX_SIZE_LOG_EVENT_STATUS.
449
450*/
451
453 public:
454 /** query event post-header */
462 };
463
464 /* these are codes, not offsets; not more than 256 values (1 byte). */
468 /*
469 Q_CATALOG_CODE is catalog with end zero stored; it is used only by MySQL
470 5.0.x where 0<=x<=3. We have to keep it to be able to replicate these
471 old masters.
472 */
477 /*
478 Q_CATALOG_NZ_CODE is catalog withOUT end zero stored; it is used by MySQL
479 5.0.x where x>=4. Saves one byte in every Query_event in binlog,
480 compared to Q_CATALOG_CODE. The reason we didn't simply re-use
481 Q_CATALOG_CODE is that then a 5.0.3 slave of this 5.0.x (x>=4)
482 master would crash (segfault etc) because it would expect a 0 when there
483 is none.
484 */
489 /* It is just a placeholder after 8.0.2*/
492 /*
493 Q_UPDATED_DB_NAMES status variable collects information of accessed
494 databases i.e. the total number and the names to be propagated to the
495 slave in order to facilitate the parallel applying of the Query events.
496 */
499 /*
500 A old (unused now) code for Query_log_event status similar to G_COMMIT_TS.
501 */
503 /*
504 An old (unused after migration to Gtid_event) code for
505 Query_log_event status, similar to G_COMMIT_TS2.
506 */
508 /*
509 The master connection @@session.explicit_defaults_for_timestamp which
510 is recorded for queries, CREATE and ALTER table that is defined with
511 a TIMESTAMP column, that are dependent on that feature.
512 For pre-WL6292 master's the associated with this code value is zero.
513 */
515 /*
516 The variable carries xid info of 2pc-aware (recoverable) DDL queries.
517 */
519 /*
520 This variable stores the default collation for the utf8mb4 character set.
521 Used to support cross-version replication.
522 */
524
525 /*
526 Replicate sql_require_primary_key.
527 */
529
530 /*
531 Replicate default_table_encryption.
532 */
534 };
535 const char *query;
536 const char *db;
537 const char *catalog;
538 const char *time_zone_str;
539
540 protected:
541 const char *user;
542 size_t user_len;
543 const char *host;
544 size_t host_len;
545
546 /* Required by the MySQL server class Log_event::Query_event */
547 unsigned long data_len;
548 /*
549 Copies data into the buffer in the following fashion
550 +--------+-----------+------+------+---------+----+-------+----+
551 | catlog | time_zone | user | host | db name | \0 | Query | \0 |
552 +--------+-----------+------+------+---------+----+-------+----+
553 */
554 int fill_data_buf(unsigned char *dest, unsigned long len);
555
556 public:
557 /* data members defined in order they are packed and written into the log */
558 uint32_t thread_id;
560 size_t db_len;
561 uint16_t error_code;
562 /*
563 We want to be able to store a variable number of N-bit status vars:
564 (generally N=32; but N=64 for SQL_MODE) a user may want to log the number
565 of affected rows (for debugging) while another does not want to lose 4
566 bytes in this.
567 The storage on disk is the following:
568 status_vars_len is part of the post-header,
569 status_vars are in the variable-length part, after the post-header, before
570 the db & query.
571 status_vars on disk is a sequence of pairs (code, value) where 'code' means
572 'sql_mode', 'affected' etc. Sometimes 'value' must be a short string, so
573 its first byte is its length. For now the order of status vars is:
574 flags2 - sql_mode - catalog - autoinc - charset
575 We should add the same thing to Load_event, but in fact
576 LOAD DATA INFILE is going to be logged with a new type of event (logging of
577 the plain text query), so Load_event would be frozen, so no need. The
578 new way of logging LOAD DATA INFILE would use a derived class of
579 Query_event, so automatically benefit from the work already done for
580 status variables in Query_event.
581 */
583 /*
584 If we already know the length of the query string
585 we pass it with q_len, so we would not have to call strlen()
586 otherwise, set it to 0, in which case, we compute it with strlen()
587 */
588 size_t q_len;
589
590 /* The members below represent the status variable block */
591
592 /*
593 'flags2' is a second set of flags (on top of those in Log_event), for
594 session variables. These are thd->options which is & against a mask
595 (OPTIONS_WRITTEN_TO_BIN_LOG).
596 flags2_inited helps make a difference between flags2==0 (3.23 or 4.x
597 master, we don't know flags2, so use the slave server's global options) and
598 flags2==0 (5.0 master, we know this has a meaning of flags all down which
599 must influence the query).
600 */
604
605 uint32_t flags2;
606 /* In connections sql_mode is 32 bits now but will be 64 bits soon */
607 uint64_t sql_mode;
609 char charset[6];
610 size_t time_zone_len; /* 0 means uninited */
611 /*
612 Binlog format 3 and 4 start to differ (as far as class members are
613 concerned) from here.
614 */
615 size_t catalog_len; // <= 255 char; 0 means uninited
616 uint16_t lc_time_names_number; /* 0 means en_US */
618 /*
619 map for tables that will be updated for a multi-table update query
620 statement, for other query statements, this will be zero.
621 */
623 /*
624 The following member gets set to OFF or ON value when the
625 Query-log-event is marked as dependent on
626 @@explicit_defaults_for_timestamp. That is the member is relevant
627 to queries that declare TIMESTAMP column attribute, like CREATE
628 and ALTER.
629 The value is set to @c TERNARY_OFF when @@explicit_defaults_for_timestamp
630 encoded value is zero, otherwise TERNARY_ON.
631 */
637 /*
638 number of updated databases by the query and their names. This info
639 is requested by both Coordinator and Worker.
640 */
641 unsigned char mts_accessed_dbs;
643 /* XID value when the event is a 2pc-capable DDL */
644 uint64_t ddl_xid;
645 /* Default collation for the utf8mb4 set. Used in cross-version replication */
648
650
651 /**
652 The constructor will be used while creating a Query_event, to be
653 written to the binary log.
654 */
655 Query_event(const char *query_arg, const char *catalog_arg,
656 const char *db_arg, uint32_t query_length,
657 unsigned long thread_id_arg, unsigned long long sql_mode_arg,
658 unsigned long auto_increment_increment_arg,
659 unsigned long auto_increment_offset_arg, unsigned int number,
660 unsigned long long table_map_for_update_arg, int errcode);
661
662 /**
663 The constructor receives a buffer and instantiates a Query_event filled in
664 with the data from the buffer
665
666 <pre>
667 The fixed event data part buffer layout is as follows:
668 +---------------------------------------------------------------------+
669 | thread_id | query_exec_time | db_len | error_code | status_vars_len |
670 +---------------------------------------------------------------------+
671 </pre>
672
673 <pre>
674 The fixed event data part buffer layout is as follows:
675 +--------------------------------------------+
676 | Zero or more status variables | db | query |
677 +--------------------------------------------+
678 </pre>
679
680 @param buf Contains the serialized event.
681 @param fde An FDE event (see Rotate_event constructor for more info).
682 @param event_type Required to determine whether the event type is
683 QUERY_EVENT or EXECUTE_LOAD_QUERY_EVENT
684 */
685 Query_event(const char *buf, const Format_description_event *fde,
686 Log_event_type event_type);
687 /**
688 The simplest constructor that could possibly work. This is used for
689 creating static objects that have a special meaning and are invisible
690 to the log.
691 */
693 ~Query_event() override = default;
694
695#ifndef HAVE_MYSYS
696 void print_event_info(std::ostream &info) override;
697 void print_long_info(std::ostream &info) override;
698#endif
699};
700
701/*
702 Check how many bytes are available on buffer.
703
704 @param buf_start Pointer to buffer start.
705 @param buf_current Pointer to the current position on buffer.
706 @param buf_len Buffer length.
707
708 @return Number of bytes available on event buffer.
709*/
710template <class T>
711T available_buffer(const char *buf_start, const char *buf_current, T buf_len) {
712 /* Sanity check */
713 if (buf_current < buf_start ||
714 buf_len < static_cast<T>(buf_current - buf_start))
715 return static_cast<T>(0);
716
717 return static_cast<T>(buf_len - (buf_current - buf_start));
718}
719
720/**
721 Check if jump value is within buffer limits.
722
723 @param jump Number of positions we want to advance.
724 @param buf_start Pointer to buffer start
725 @param buf_current Pointer to the current position on buffer.
726 @param buf_len Buffer length.
727
728 @retval True If jump value is within buffer limits.
729 @retval False Otherwise.
730*/
731template <class T>
732bool valid_buffer_range(T jump, const char *buf_start, const char *buf_current,
733 T buf_len) {
734 return (jump <= available_buffer(buf_start, buf_current, buf_len));
735}
736
737/**
738 @class User_var_event
739
740 Written every time a statement uses a user variable; precedes other
741 events for the statement. Indicates the value to use for the user
742 variable in the next statement. This is written only before a QUERY_EVENT
743 and is not used with row-based logging
744
745 The Post-Header has following components:
746
747 <table>
748 <caption>Post-Header for Format_description_event</caption>
749
750 <tr>
751 <th>Name</th>
752 <th>Format</th>
753 <th>Description</th>
754 </tr>
755
756 <tr>
757 <td>Value_type</td>
758 <td>enum</td>
759 <td>The user variable type.</td>
760 </tr>
761 <tr>
762 <td>User_var_event_data</td>
763 <td>enum</td>
764 <td>User_var event data</td>
765 </tr>
766 <tr>
767 <td>name</td>
768 <td>const char pointer</td>
769 <td>User variable name.</td>
770 </tr>
771 <tr>
772 <td>name_len</td>
773 <td>unsigned int</td>
774 <td>Length of the user variable name</td>
775 </tr>
776 <tr>
777 <td>val</td>
778 <td>char pointer</td>
779 <td>value of the user variable.</td>
780 </tr>
781 <tr>
782 <td>val_len</td>
783 <td>unsigned long</td>
784 <td>Length of the value of the user variable</td>
785 </tr>
786 <tr>
787 <td>type</td>
788 <td>enum Value_type</td>
789 <td>Type of the user variable</td>
790 </tr>
791 <tr>
792 <td>charset_number</td>
793 <td>unsigned int</td>
794 <td>The number of the character set for the user variable (needed for a
795 string variable). The character set number is really a collation
796 number that indicates a character set/collation pair.</td>
797 </tr>
798 <tr>
799 <td>is_null</td>
800 <td>bool</td>
801 <td>Non-zero if the variable value is the SQL NULL value, 0 otherwise.</td>
802 </tr>
803 </table>
804*/
806 public:
815 };
816
817 /**
818 This constructor will initialize the instance variables and the type_code,
819 it will be used only by the server code.
820 */
821 User_var_event(const char *name_arg, unsigned int name_len_arg, char *val_arg,
822 unsigned long val_len_arg, Value_type type_arg,
823 unsigned int charset_number_arg, unsigned char flags_arg)
825 name(bapi_strndup(name_arg, name_len_arg)),
826 name_len(name_len_arg),
827 val(val_arg),
828 val_len(val_len_arg),
829 type(type_arg),
830 charset_number(charset_number_arg),
831 is_null(!val),
832 flags(flags_arg) {}
833
834 /**
835 The constructor receives a buffer and instantiates a User_var_event filled
836 in with the data from the buffer
837 Written every time a statement uses a user variable, precedes other
838 events for the statement. Indicates the value to use for the
839 user variable in the next statement. This is written only before a
840 QUERY_EVENT and is not used with row-based logging.
841
842 The buffer layout for variable data part is as follows:
843 <pre>
844 +-------------------------------------------------------------------+
845 | name_len | name | is_null | type | charset_number | val_len | val |
846 +-------------------------------------------------------------------+
847 </pre>
848
849 @param buf Contains the serialized event.
850 @param fde An FDE event (see Rotate_event constructor for more info).
851 */
852 User_var_event(const char *buf, const Format_description_event *fde);
853 ~User_var_event() override;
854 const char *name;
855 unsigned int name_len;
856 char *val;
857 uint32_t val_len;
859 unsigned int charset_number;
861 unsigned char flags;
862#ifndef HAVE_MYSYS
863 void print_event_info(std::ostream &info) override;
864 void print_long_info(std::ostream &info) override;
865 const char *get_value_type_string(Value_type type_arg) const {
866 switch (type_arg) {
867 case STRING_RESULT:
868 return "String";
869 case REAL_RESULT:
870 return "Real";
871 case INT_RESULT:
872 return "Integer";
873 case ROW_RESULT:
874 return "Row";
875 case DECIMAL_RESULT:
876 return "Decimal";
877 default:
878 return "Unknown";
879 }
880 }
881#endif
882};
883
884/**
885 @class Intvar_event
886
887 An Intvar_event will be created just before a Query_event,
888 if the query uses one of the variables LAST_INSERT_ID or INSERT_ID.
889 Each Intvar_event holds the value of one of these variables.
890
891 @section Intvar_event_binary_format Binary Format
892
893 The Post-Header for this event type is empty. The Body has two
894 components:
895
896 <table>
897 <caption>Body for Intvar_event</caption>
898
899 <tr>
900 <th>Name</th>
901 <th>Format</th>
902 <th>Description</th>
903 </tr>
904
905 <tr>
906 <td>type</td>
907 <td>1 byte enumeration</td>
908 <td>One byte identifying the type of variable stored. Currently,
909 two identifiers are supported: LAST_INSERT_ID_EVENT == 1 and
910 INSERT_ID_EVENT == 2.
911 </td>
912 </tr>
913
914 <tr>
915 <td>val</td>
916 <td>8 byte unsigned integer</td>
917 <td>The value of the variable.</td>
918 </tr>
919
920 </table>
921*/
923 public:
924 uint8_t type;
925 uint64_t val;
926
927 /*
928 The enum recognizes the type of variables that can occur in an
929 INTVAR_EVENT. The two types supported are LAST_INSERT_ID and
930 INSERT_ID, in accordance to the SQL query using LAST_INSERT_ID
931 or INSERT_ID.
932 */
937 };
938
939 /**
940 moving from pre processor symbols from global scope in log_event.h
941 to an enum inside the class, since these are used only by
942 members of this class itself.
943 */
945
946 /**
947 This method returns the string representing the type of the variable
948 used in the event. Changed the definition to be similar to that
949 previously defined in log_event.cc.
950 */
951 std::string get_var_type_string() const {
952 switch (type) {
954 return "INVALID_INT";
956 return "LAST_INSERT_ID";
957 case INSERT_ID_EVENT:
958 return "INSERT_ID";
959 default: /* impossible */
960 return "UNKNOWN";
961 }
962 }
963
964 /**
965 Constructor receives a packet from the MySQL master or the binary
966 log and decodes it to create an Intvar_event.
967
968 The post header for the event is empty. Buffer layout for the variable
969 data part is as follows:
970 <pre>
971 +--------------------------------+
972 | type (4 bytes) | val (8 bytes) |
973 +--------------------------------+
974 </pre>
975
976 @param buf Contains the serialized event.
977 @param fde An FDE event (see Rotate_event constructor for more info).
978 */
979 Intvar_event(const char *buf, const Format_description_event *fde);
980 /**
981 The minimal constructor for Intvar_event it initializes the instance
982 variables type & val and set the type_code as INTVAR_EVENT in the header
983 object in Binary_log_event
984 */
985 Intvar_event(uint8_t type_arg, uint64_t val_arg)
986 : Binary_log_event(INTVAR_EVENT), type(type_arg), val(val_arg) {}
987
988 ~Intvar_event() override = default;
989
990#ifndef HAVE_MYSYS
991 void print_event_info(std::ostream &info) override;
992 void print_long_info(std::ostream &info) override;
993#endif
994};
995
996/**
997 @class Rand_event
998
999 Logs random seed used by the next RAND(), and by PASSWORD() in 4.1.0.
1000 4.1.1 does not need it (it's repeatable again) so this event needn't be
1001 written in 4.1.1 for PASSWORD() (but the fact that it is written is just a
1002 waste, it does not cause bugs).
1003
1004 The state of the random number generation consists of 128 bits,
1005 which are stored internally as two 64-bit numbers.
1006
1007 @section Rand_event_binary_format Binary Format
1008
1009 The Post-Header for this event type is empty. The Body has two
1010 components:
1011
1012 <table>
1013 <caption>Body for Rand_event</caption>
1014
1015 <tr>
1016 <th>Name</th>
1017 <th>Format</th>
1018 <th>Description</th>
1019 </tr>
1020
1021 <tr>
1022 <td>seed1</td>
1023 <td>8 byte unsigned integer</td>
1024 <td>64 bit random seed1.</td>
1025 </tr>
1026
1027 <tr>
1028 <td>seed2</td>
1029 <td>8 byte unsigned integer</td>
1030 <td>64 bit random seed2.</td>
1031 </tr>
1032 </table>
1033*/
1035 public:
1036 unsigned long long seed1;
1037 unsigned long long seed2;
1039
1040 /**
1041 This will initialize the instance variables seed1 & seed2, and set the
1042type_code as RAND_EVENT in the header object in Binary_log_event
1043 */
1044 Rand_event(unsigned long long seed1_arg, unsigned long long seed2_arg)
1046 seed1 = seed1_arg;
1047 seed2 = seed2_arg;
1048 }
1049
1050 /**
1051 Written every time a statement uses the RAND() function; precedes other
1052 events for the statement. Indicates the seed values to use for generating a
1053 random number with RAND() in the next statement. This is written only before
1054 a QUERY_EVENT and is not used with row-based logging
1055
1056 <pre>
1057 The buffer layout for variable part is as follows:
1058 +----------------------------------------------+
1059 | value for first seed | value for second seed |
1060 +----------------------------------------------+
1061 </pre>
1062
1063 @param buf Contains the serialized event.
1064 @param fde An FDE event (see Rotate_event constructor for more info).
1065 */
1066 Rand_event(const char *buf, const Format_description_event *fde);
1067#ifndef HAVE_MYSYS
1068 void print_event_info(std::ostream &info) override;
1069 void print_long_info(std::ostream &info) override;
1070#endif
1071};
1072} // end namespace mysql::binlog::event
1073
1074/// @}
1075
1076#endif // MYSQL_BINLOG_EVENT_STATEMENT_EVENTS_H
This is the abstract base class for binary log events.
Definition: binlog_event.h:851
@ QUERY_HEADER_LEN
Definition: binlog_event.h:868
For binlog version 4.
Definition: control_events.h:240
An Intvar_event will be created just before a Query_event, if the query uses one of the variables LAS...
Definition: statement_events.h:922
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:925
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:951
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:985
Int_event_type
Definition: statement_events.h:933
@ LAST_INSERT_ID_EVENT
Definition: statement_events.h:935
@ INVALID_INT_EVENT
Definition: statement_events.h:934
@ INSERT_ID_EVENT
Definition: statement_events.h:936
uint8_t type
Definition: statement_events.h:924
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:944
@ I_TYPE_OFFSET
Definition: statement_events.h:944
@ I_VAL_OFFSET
Definition: statement_events.h:944
A Query_event is created for each query that modifies the database, unless the query is logged row-ba...
Definition: statement_events.h:452
uint16_t error_code
Definition: statement_events.h:561
size_t host_len
Definition: statement_events.h:544
uint8_t default_table_encryption
Definition: statement_events.h:649
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:543
uint64_t table_map_for_update
Definition: statement_events.h:622
uint16_t auto_increment_increment
Definition: statement_events.h:608
const char * db
Definition: statement_events.h:536
const char * user
Definition: statement_events.h:541
uint64_t sql_mode
Definition: statement_events.h:607
const char * query
Definition: statement_events.h:535
char charset[6]
Definition: statement_events.h:609
uint64_t ddl_xid
Definition: statement_events.h:644
enum mysql::binlog::event::Query_event::enum_ternary explicit_defaults_ts
bool charset_inited
Definition: statement_events.h:603
unsigned char mts_accessed_dbs
Definition: statement_events.h:641
const char * catalog
Definition: statement_events.h:537
uint16_t default_collation_for_utf8mb4_number
Definition: statement_events.h:646
size_t db_len
Definition: statement_events.h:560
const char * time_zone_str
Definition: statement_events.h:538
bool sql_mode_inited
Definition: statement_events.h:602
enum_ternary
Definition: statement_events.h:632
@ TERNARY_OFF
Definition: statement_events.h:634
@ TERNARY_UNSET
Definition: statement_events.h:633
@ TERNARY_ON
Definition: statement_events.h:635
char mts_accessed_db_names[MAX_DBS_IN_EVENT_MTS][NAME_LEN]
Definition: statement_events.h:642
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:647
uint32_t flags2
Definition: statement_events.h:605
size_t catalog_len
Definition: statement_events.h:615
Query_event_status_vars
Definition: statement_events.h:465
@ Q_COMMIT_TS2
Definition: statement_events.h:507
@ Q_LC_TIME_NAMES_CODE
Definition: statement_events.h:486
@ Q_COMMIT_TS
Definition: statement_events.h:502
@ Q_CHARSET_CODE
Definition: statement_events.h:475
@ Q_CHARSET_DATABASE_CODE
Definition: statement_events.h:487
@ Q_UPDATED_DB_NAMES
Definition: statement_events.h:497
@ Q_CATALOG_NZ_CODE
Definition: statement_events.h:485
@ Q_TABLE_MAP_FOR_UPDATE_CODE
Definition: statement_events.h:488
@ Q_MICROSECONDS
Definition: statement_events.h:498
@ Q_EXPLICIT_DEFAULTS_FOR_TIMESTAMP
Definition: statement_events.h:514
@ Q_DDL_LOGGED_WITH_XID
Definition: statement_events.h:518
@ Q_INVOKER
Definition: statement_events.h:491
@ Q_DEFAULT_TABLE_ENCRYPTION
Definition: statement_events.h:533
@ Q_SQL_REQUIRE_PRIMARY_KEY
Definition: statement_events.h:528
@ Q_FLAGS2_CODE
Definition: statement_events.h:466
@ Q_SQL_MODE_CODE
Definition: statement_events.h:467
@ Q_AUTO_INCREMENT
Definition: statement_events.h:474
@ Q_TIME_ZONE_CODE
Definition: statement_events.h:476
@ Q_MASTER_DATA_WRITTEN_CODE
Definition: statement_events.h:490
@ Q_CATALOG_CODE
Definition: statement_events.h:473
@ Q_DEFAULT_COLLATION_FOR_UTF8MB4
Definition: statement_events.h:523
uint32_t query_exec_time
Definition: statement_events.h:559
unsigned long data_len
Definition: statement_events.h:547
uint16_t status_vars_len
Definition: statement_events.h:582
size_t user_len
Definition: statement_events.h:542
uint16_t auto_increment_offset
Definition: statement_events.h:608
uint16_t charset_database_number
Definition: statement_events.h:617
uint32_t thread_id
Definition: statement_events.h:558
uint16_t lc_time_names_number
Definition: statement_events.h:616
bool flags2_inited
Definition: statement_events.h:601
Query_event_post_header_offset
query event post-header
Definition: statement_events.h:455
@ Q_DATA_OFFSET
Definition: statement_events.h:461
@ Q_EXEC_TIME_OFFSET
Definition: statement_events.h:457
@ Q_STATUS_VARS_LEN_OFFSET
Definition: statement_events.h:460
@ Q_THREAD_ID_OFFSET
Definition: statement_events.h:456
@ Q_ERR_CODE_OFFSET
Definition: statement_events.h:459
@ Q_DB_LEN_OFFSET
Definition: statement_events.h:458
size_t time_zone_len
Definition: statement_events.h:610
size_t q_len
Definition: statement_events.h:588
Logs random seed used by the next RAND(), and by PASSWORD() in 4.1.0.
Definition: statement_events.h:1034
Rand_event(unsigned long long seed1_arg, unsigned long long seed2_arg)
Definition: statement_events.h:1044
unsigned long long seed1
Definition: statement_events.h:1036
unsigned long long seed2
Definition: statement_events.h:1037
Rand_event_data
Definition: statement_events.h:1038
@ RAND_SEED2_OFFSET
Definition: statement_events.h:1038
@ RAND_SEED1_OFFSET
Definition: statement_events.h:1038
Written every time a statement uses a user variable; precedes other events for the statement.
Definition: statement_events.h:805
const char * name
Definition: statement_events.h:854
uint32_t val_len
Definition: statement_events.h:857
@ UNSIGNED_F
Definition: statement_events.h:808
@ UNDEF_F
Definition: statement_events.h:808
Value_type type
Definition: statement_events.h:858
char * val
Definition: statement_events.h:856
bool is_null
Definition: statement_events.h:860
unsigned int charset_number
Definition: statement_events.h:859
User_var_event_data
Definition: statement_events.h:809
@ UV_VAL_LEN_SIZE
Definition: statement_events.h:810
@ UV_VAL_IS_NULL
Definition: statement_events.h:811
@ UV_CHARSET_NUMBER_SIZE
Definition: statement_events.h:814
@ UV_VAL_TYPE_SIZE
Definition: statement_events.h:812
@ UV_NAME_LEN_SIZE
Definition: statement_events.h:813
~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:821
unsigned char flags
Definition: statement_events.h:861
unsigned int name_len
Definition: statement_events.h:855
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:109
#define T
Definition: jit_executor_value.cc:373
#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:38
Log_event_type
Enumeration type for the different types of log events.
Definition: binlog_event.h:278
@ QUERY_EVENT
Definition: binlog_event.h:292
@ RAND_EVENT
Definition: binlog_event.h:302
@ INTVAR_EVENT
Definition: binlog_event.h:295
@ USER_VAR_EVENT
Definition: binlog_event.h:303
T available_buffer(const char *buf_start, const char *buf_current, T buf_len)
Definition: statement_events.h:711
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:732
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