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