#include <log_event.h>
Inheritance diagram for Query_log_event:


Definition at line 720 of file log_event.h.
| Query_log_event::Query_log_event | ( | THD * | thd_arg, | |
| const char * | query_arg, | |||
| ulong | query_length, | |||
| bool | using_trans, | |||
| bool | suppress_use | |||
| ) |
Definition at line 1306 of file log_event.cc.
References catalog, catalog_len, charset, db, db_len, DBUG_ASSERT, DBUG_PRINT, end_time, Log_event::exec_time, flags2, int2store, OPTIONS_WRITTEN_TO_BIN_LOG, sql_mode, strlen(), time_zone_len, and time_zone_str.
01309 :Log_event(thd_arg, 01310 ((thd_arg->tmp_table_used ? LOG_EVENT_THREAD_SPECIFIC_F : 0) 01311 | (suppress_use ? LOG_EVENT_SUPPRESS_USE_F : 0)), 01312 using_trans), 01313 data_buf(0), query(query_arg), catalog(thd_arg->catalog), 01314 db(thd_arg->db), q_len((uint32) query_length), 01315 error_code((thd_arg->killed != THD::NOT_KILLED) ? 01316 ((thd_arg->system_thread & SYSTEM_THREAD_DELAYED_INSERT) ? 01317 0 : thd->killed_errno()) : thd_arg->net.last_errno), 01318 thread_id(thd_arg->thread_id), 01319 /* save the original thread id; we already know the server id */ 01320 slave_proxy_id(thd_arg->variables.pseudo_thread_id), 01321 flags2_inited(1), sql_mode_inited(1), charset_inited(1), 01322 sql_mode(thd_arg->variables.sql_mode), 01323 auto_increment_increment(thd_arg->variables.auto_increment_increment), 01324 auto_increment_offset(thd_arg->variables.auto_increment_offset) 01325 { 01326 time_t end_time; 01327 time(&end_time); 01328 exec_time = (ulong) (end_time - thd->start_time); 01329 catalog_len = (catalog) ? (uint32) strlen(catalog) : 0; 01330 /* status_vars_len is set just before writing the event */ 01331 db_len = (db) ? (uint32) strlen(db) : 0; 01332 /* 01333 If we don't use flags2 for anything else than options contained in 01334 thd->options, it would be more efficient to flags2=thd_arg->options 01335 (OPTIONS_WRITTEN_TO_BINLOG would be used only at reading time). 01336 But it's likely that we don't want to use 32 bits for 3 bits; in the future 01337 we will probably want to reclaim the 29 bits. So we need the &. 01338 */ 01339 flags2= (uint32) (thd_arg->options & OPTIONS_WRITTEN_TO_BIN_LOG); 01340 DBUG_ASSERT(thd->variables.character_set_client->number < 256*256); 01341 DBUG_ASSERT(thd->variables.collation_connection->number < 256*256); 01342 DBUG_ASSERT(thd->variables.collation_server->number < 256*256); 01343 int2store(charset, thd_arg->variables.character_set_client->number); 01344 int2store(charset+2, thd_arg->variables.collation_connection->number); 01345 int2store(charset+4, thd_arg->variables.collation_server->number); 01346 if (thd_arg->time_zone_used) 01347 { 01348 /* 01349 Note that our event becomes dependent on the Time_zone object 01350 representing the time zone. Fortunately such objects are never deleted 01351 or changed during mysqld's lifetime. 01352 */ 01353 time_zone_len= thd_arg->variables.time_zone->get_name()->length(); 01354 time_zone_str= thd_arg->variables.time_zone->get_name()->ptr(); 01355 } 01356 else 01357 time_zone_len= 0; 01358 DBUG_PRINT("info",("Query_log_event has flags2=%lu sql_mode=%lu",flags2,sql_mode)); 01359 }
Here is the call graph for this function:

| Query_log_event::Query_log_event | ( | ) |
| Query_log_event::Query_log_event | ( | const char * | buf, | |
| uint | event_len, | |||
| const Format_description_log_event * | description_event, | |||
| Log_event_type | event_type | |||
| ) |
Definition at line 1387 of file log_event.cc.
References auto_increment_increment, auto_increment_offset, catalog, catalog_len, charset, charset_inited, Format_description_log_event::common_header_len, copy_str_and_move(), data_buf, db, db_len, DBUG_ENTER, DBUG_PRINT, DBUG_VOID_RETURN, description_event, error_code, Log_event::exec_time, flags2, flags2_inited, get_str_len_and_pointer(), likely, llstr(), memcpy, my_malloc(), MY_WME, MYF, Format_description_log_event::post_header_len, Q_AUTO_INCREMENT, Q_CATALOG_CODE, Q_CATALOG_NZ_CODE, Q_CHARSET_CODE, Q_DB_LEN_OFFSET, Q_ERR_CODE_OFFSET, Q_EXEC_TIME_OFFSET, Q_FLAGS2_CODE, q_len, Q_SQL_MODE_CODE, Q_STATUS_VARS_LEN_OFFSET, Q_THREAD_ID_OFFSET, Q_TIME_ZONE_CODE, QUERY_HEADER_MINIMAL_LEN, slave_proxy_id, sql_mode, sql_mode_inited, start(), status_vars_len, thread_id, time_zone_len, time_zone_str, uint2korr, uint4korr, and uint8korr.
01390 :Log_event(buf, description_event), data_buf(0), query(NullS), 01391 db(NullS), catalog_len(0), status_vars_len(0), 01392 flags2_inited(0), sql_mode_inited(0), charset_inited(0), 01393 auto_increment_increment(1), auto_increment_offset(1), 01394 time_zone_len(0) 01395 { 01396 ulong data_len; 01397 uint32 tmp; 01398 uint8 common_header_len, post_header_len; 01399 char *start; 01400 const char *end; 01401 bool catalog_nz= 1; 01402 DBUG_ENTER("Query_log_event::Query_log_event(char*,...)"); 01403 01404 common_header_len= description_event->common_header_len; 01405 post_header_len= description_event->post_header_len[event_type-1]; 01406 DBUG_PRINT("info",("event_len=%ld, common_header_len=%d, post_header_len=%d", 01407 event_len, common_header_len, post_header_len)); 01408 01409 /* 01410 We test if the event's length is sensible, and if so we compute data_len. 01411 We cannot rely on QUERY_HEADER_LEN here as it would not be format-tolerant. 01412 We use QUERY_HEADER_MINIMAL_LEN which is the same for 3.23, 4.0 & 5.0. 01413 */ 01414 if (event_len < (uint)(common_header_len + post_header_len)) 01415 DBUG_VOID_RETURN; 01416 data_len = event_len - (common_header_len + post_header_len); 01417 buf+= common_header_len; 01418 01419 slave_proxy_id= thread_id = uint4korr(buf + Q_THREAD_ID_OFFSET); 01420 exec_time = uint4korr(buf + Q_EXEC_TIME_OFFSET); 01421 db_len = (uint)buf[Q_DB_LEN_OFFSET]; // TODO: add a check of all *_len vars 01422 error_code = uint2korr(buf + Q_ERR_CODE_OFFSET); 01423 01424 /* 01425 5.0 format starts here. 01426 Depending on the format, we may or not have affected/warnings etc 01427 The remnent post-header to be parsed has length: 01428 */ 01429 tmp= post_header_len - QUERY_HEADER_MINIMAL_LEN; 01430 if (tmp) 01431 { 01432 status_vars_len= uint2korr(buf + Q_STATUS_VARS_LEN_OFFSET); 01433 data_len-= status_vars_len; 01434 DBUG_PRINT("info", ("Query_log_event has status_vars_len: %u", 01435 (uint) status_vars_len)); 01436 tmp-= 2; 01437 } 01438 /* 01439 We have parsed everything we know in the post header for QUERY_EVENT, 01440 the rest of post header is either comes from older version MySQL or 01441 dedicated to derived events (e.g. Execute_load_query...) 01442 */ 01443 01444 /* variable-part: the status vars; only in MySQL 5.0 */ 01445 01446 start= (char*) (buf+post_header_len); 01447 end= (const char*) (start+status_vars_len); 01448 for (const uchar* pos= (const uchar*) start; pos < (const uchar*) end;) 01449 { 01450 switch (*pos++) { 01451 case Q_FLAGS2_CODE: 01452 flags2_inited= 1; 01453 flags2= uint4korr(pos); 01454 DBUG_PRINT("info",("In Query_log_event, read flags2: %lu", flags2)); 01455 pos+= 4; 01456 break; 01457 case Q_SQL_MODE_CODE: 01458 { 01459 #ifndef DBUG_OFF 01460 char buff[22]; 01461 #endif 01462 sql_mode_inited= 1; 01463 sql_mode= (ulong) uint8korr(pos); // QQ: Fix when sql_mode is ulonglong 01464 DBUG_PRINT("info",("In Query_log_event, read sql_mode: %s", 01465 llstr(sql_mode, buff))); 01466 pos+= 8; 01467 break; 01468 } 01469 case Q_CATALOG_NZ_CODE: 01470 get_str_len_and_pointer(&catalog, (const char **)(&pos), &catalog_len); 01471 break; 01472 case Q_AUTO_INCREMENT: 01473 auto_increment_increment= uint2korr(pos); 01474 auto_increment_offset= uint2korr(pos+2); 01475 pos+= 4; 01476 break; 01477 case Q_CHARSET_CODE: 01478 { 01479 charset_inited= 1; 01480 memcpy(charset, pos, 6); 01481 pos+= 6; 01482 break; 01483 } 01484 case Q_TIME_ZONE_CODE: 01485 { 01486 get_str_len_and_pointer(&time_zone_str, (const char **)(&pos), &time_zone_len); 01487 break; 01488 } 01489 case Q_CATALOG_CODE: /* for 5.0.x where 0<=x<=3 masters */ 01490 if ((catalog_len= *pos)) 01491 catalog= (char*) pos+1; // Will be copied later 01492 pos+= catalog_len+2; // leap over end 0 01493 catalog_nz= 0; // catalog has end 0 in event 01494 break; 01495 default: 01496 /* That's why you must write status vars in growing order of code */ 01497 DBUG_PRINT("info",("Query_log_event has unknown status vars (first has\ 01498 code: %u), skipping the rest of them", (uint) *(pos-1))); 01499 pos= (const uchar*) end; // Break loop 01500 } 01501 } 01502 01503 #if !defined(MYSQL_CLIENT) && defined(HAVE_QUERY_CACHE) 01504 if (!(start= data_buf = (char*) my_malloc(catalog_len + 1 + 01505 time_zone_len + 1 + 01506 data_len + 1 + 01507 QUERY_CACHE_FLAGS_SIZE + 01508 db_len + 1, 01509 MYF(MY_WME)))) 01510 #else 01511 if (!(start= data_buf = (char*) my_malloc(catalog_len + 1 + 01512 time_zone_len + 1 + 01513 data_len + 1, 01514 MYF(MY_WME)))) 01515 #endif 01516 DBUG_VOID_RETURN; 01517 if (catalog_len) // If catalog is given 01518 { 01519 if (likely(catalog_nz)) // true except if event comes from 5.0.0|1|2|3. 01520 copy_str_and_move(&start, &catalog, catalog_len); 01521 else 01522 { 01523 memcpy(start, catalog, catalog_len+1); // copy end 0 01524 catalog= start; 01525 start+= catalog_len+1; 01526 } 01527 } 01528 if (time_zone_len) 01529 copy_str_and_move(&start, &time_zone_str, time_zone_len); 01530 01531 /* A 2nd variable part; this is common to all versions */ 01532 memcpy((char*) start, end, data_len); // Copy db and query 01533 start[data_len]= '\0'; // End query with \0 (For safetly) 01534 db= start; 01535 query= start + db_len + 1; 01536 q_len= data_len - db_len -1; 01537 DBUG_VOID_RETURN; 01538 }
Here is the call graph for this function:

| Query_log_event::~Query_log_event | ( | ) | [inline] |
| Query_log_event::Query_log_event | ( | THD * | thd_arg, | |
| const char * | query_arg, | |||
| ulong | query_length, | |||
| bool | using_trans, | |||
| bool | suppress_use | |||
| ) |
| Query_log_event::Query_log_event | ( | ) |
| Query_log_event::Query_log_event | ( | const char * | buf, | |
| uint | event_len, | |||
| const Format_description_log_event * | description_event, | |||
| Log_event_type | event_type | |||
| ) |
| Query_log_event::~Query_log_event | ( | ) | [inline] |
| const char* Query_log_event::get_db | ( | ) | [inline, virtual] |
Reimplemented from Log_event.
Definition at line 799 of file log_event.h.
References db.
00799 { return db; }
| const char* Query_log_event::get_db | ( | ) | [inline, virtual] |
Reimplemented from Log_event.
Definition at line 799 of file log_event.h.
References db.
00799 { return db; }
| virtual ulong Query_log_event::get_post_header_size_for_derived | ( | ) | [inline, virtual] |
Reimplemented in Execute_load_query_log_event, and Execute_load_query_log_event.
Definition at line 831 of file log_event.h.
| virtual ulong Query_log_event::get_post_header_size_for_derived | ( | ) | [inline, virtual] |
Reimplemented in Execute_load_query_log_event, and Execute_load_query_log_event.
Definition at line 831 of file log_event.h.
Referenced by write().
Here is the caller graph for this function:

| Log_event_type Query_log_event::get_type_code | ( | ) | [inline, virtual] |
Implements Log_event.
Reimplemented in Execute_load_query_log_event, and Execute_load_query_log_event.
Definition at line 820 of file log_event.h.
References QUERY_EVENT.
00820 { return QUERY_EVENT; }
| Log_event_type Query_log_event::get_type_code | ( | ) | [inline, virtual] |
Implements Log_event.
Reimplemented in Execute_load_query_log_event, and Execute_load_query_log_event.
Definition at line 820 of file log_event.h.
References QUERY_EVENT.
00820 { return QUERY_EVENT; }
| bool Query_log_event::is_valid | ( | ) | const [inline, virtual] |
Implements Log_event.
Reimplemented in Execute_load_query_log_event, and Execute_load_query_log_event.
Definition at line 825 of file log_event.h.
00825 { return query != 0; }
| bool Query_log_event::is_valid | ( | ) | const [inline, virtual] |
Implements Log_event.
Reimplemented in Execute_load_query_log_event, and Execute_load_query_log_event.
Definition at line 825 of file log_event.h.
Referenced by Execute_load_query_log_event::Execute_load_query_log_event(), and Execute_load_query_log_event::is_valid().
00825 { return query != 0; }
Here is the caller graph for this function:

Reimplemented from Log_event.
Reimplemented in Muted_query_log_event, and Muted_query_log_event.
Definition at line 1141 of file log_event.cc.
References auto_increment_increment, auto_increment_offset, catalog, catalog_len, charset, charset_inited, db, db_len, DBUG_ASSERT, error_code, Log_event::exec_time, flags2, flags2_inited, FN_REFLEN, get_post_header_size_for_derived(), int2store, int4store, int8store, MAX_TIME_ZONE_NAME_LENGTH, memcpy, my_b_safe_write(), Q_AUTO_INCREMENT, Q_CATALOG_NZ_CODE, Q_CHARSET_CODE, Q_DB_LEN_OFFSET, Q_ERR_CODE_OFFSET, Q_EXEC_TIME_OFFSET, Q_FLAGS2_CODE, q_len, Q_SQL_MODE_CODE, Q_STATUS_VARS_LEN_OFFSET, Q_THREAD_ID_OFFSET, Q_TIME_ZONE_CODE, QUERY_HEADER_LEN, slave_proxy_id, sql_mode, sql_mode_inited, start(), status_vars_len, time_zone_len, time_zone_str, Log_event::write_header(), write_post_header_for_derived(), and write_str_with_code_and_len().
Referenced by MYSQL_BIN_LOG::write().
01142 { 01143 uchar buf[QUERY_HEADER_LEN+ 01144 1+4+ // code of flags2 and flags2 01145 1+8+ // code of sql_mode and sql_mode 01146 1+1+FN_REFLEN+ // code of catalog and catalog length and catalog 01147 1+4+ // code of autoinc and the 2 autoinc variables 01148 1+6+ // code of charset and charset 01149 1+1+MAX_TIME_ZONE_NAME_LENGTH // code of tz and tz length and tz name 01150 ], *start, *start_of_status; 01151 ulong event_length; 01152 01153 if (!query) 01154 return 1; // Something wrong with event 01155 01156 /* 01157 We want to store the thread id: 01158 (- as an information for the user when he reads the binlog) 01159 - if the query uses temporary table: for the slave SQL thread to know to 01160 which master connection the temp table belongs. 01161 Now imagine we (write()) are called by the slave SQL thread (we are 01162 logging a query executed by this thread; the slave runs with 01163 --log-slave-updates). Then this query will be logged with 01164 thread_id=the_thread_id_of_the_SQL_thread. Imagine that 2 temp tables of 01165 the same name were created simultaneously on the master (in the master 01166 binlog you have 01167 CREATE TEMPORARY TABLE t; (thread 1) 01168 CREATE TEMPORARY TABLE t; (thread 2) 01169 ...) 01170 then in the slave's binlog there will be 01171 CREATE TEMPORARY TABLE t; (thread_id_of_the_slave_SQL_thread) 01172 CREATE TEMPORARY TABLE t; (thread_id_of_the_slave_SQL_thread) 01173 which is bad (same thread id!). 01174 01175 To avoid this, we log the thread's thread id EXCEPT for the SQL 01176 slave thread for which we log the original (master's) thread id. 01177 Now this moves the bug: what happens if the thread id on the 01178 master was 10 and when the slave replicates the query, a 01179 connection number 10 is opened by a normal client on the slave, 01180 and updates a temp table of the same name? We get a problem 01181 again. To avoid this, in the handling of temp tables (sql_base.cc) 01182 we use thread_id AND server_id. TODO when this is merged into 01183 4.1: in 4.1, slave_proxy_id has been renamed to pseudo_thread_id 01184 and is a session variable: that's to make mysqlbinlog work with 01185 temp tables. We probably need to introduce 01186 01187 SET PSEUDO_SERVER_ID 01188 for mysqlbinlog in 4.1. mysqlbinlog would print: 01189 SET PSEUDO_SERVER_ID= 01190 SET PSEUDO_THREAD_ID= 01191 for each query using temp tables. 01192 */ 01193 int4store(buf + Q_THREAD_ID_OFFSET, slave_proxy_id); 01194 int4store(buf + Q_EXEC_TIME_OFFSET, exec_time); 01195 buf[Q_DB_LEN_OFFSET] = (char) db_len; 01196 int2store(buf + Q_ERR_CODE_OFFSET, error_code); 01197 01198 /* 01199 You MUST always write status vars in increasing order of code. This 01200 guarantees that a slightly older slave will be able to parse those he 01201 knows. 01202 */ 01203 start_of_status= start= buf+QUERY_HEADER_LEN; 01204 if (flags2_inited) 01205 { 01206 *start++= Q_FLAGS2_CODE; 01207 int4store(start, flags2); 01208 start+= 4; 01209 } 01210 if (sql_mode_inited) 01211 { 01212 *start++= Q_SQL_MODE_CODE; 01213 int8store(start, (ulonglong)sql_mode); 01214 start+= 8; 01215 } 01216 if (catalog_len) // i.e. this var is inited (false for 4.0 events) 01217 { 01218 write_str_with_code_and_len((char **)(&start), 01219 catalog, catalog_len, Q_CATALOG_NZ_CODE); 01220 /* 01221 In 5.0.x where x<4 masters we used to store the end zero here. This was 01222 a waste of one byte so we don't do it in x>=4 masters. We change code to 01223 Q_CATALOG_NZ_CODE, because re-using the old code would make x<4 slaves 01224 of this x>=4 master segfault (expecting a zero when there is 01225 none). Remaining compatibility problems are: the older slave will not 01226 find the catalog; but it is will not crash, and it's not an issue 01227 that it does not find the catalog as catalogs were not used in these 01228 older MySQL versions (we store it in binlog and read it from relay log 01229 but do nothing useful with it). What is an issue is that the older slave 01230 will stop processing the Q_* blocks (and jumps to the db/query) as soon 01231 as it sees unknown Q_CATALOG_NZ_CODE; so it will not be able to read 01232 Q_AUTO_INCREMENT*, Q_CHARSET and so replication will fail silently in 01233 various ways. Documented that you should not mix alpha/beta versions if 01234 they are not exactly the same version, with example of 5.0.3->5.0.2 and 01235 5.0.4->5.0.3. If replication is from older to new, the new will 01236 recognize Q_CATALOG_CODE and have no problem. 01237 */ 01238 } 01239 if (auto_increment_increment != 1) 01240 { 01241 *start++= Q_AUTO_INCREMENT; 01242 int2store(start, auto_increment_increment); 01243 int2store(start+2, auto_increment_offset); 01244 start+= 4; 01245 } 01246 if (charset_inited) 01247 { 01248 *start++= Q_CHARSET_CODE; 01249 memcpy(start, charset, 6); 01250 start+= 6; 01251 } 01252 if (time_zone_len) 01253 { 01254 /* In the TZ sys table, column Name is of length 64 so this should be ok */ 01255 DBUG_ASSERT(time_zone_len <= MAX_TIME_ZONE_NAME_LENGTH); 01256 *start++= Q_TIME_ZONE_CODE; 01257 *start++= time_zone_len; 01258 memcpy(start, time_zone_str, time_zone_len); 01259 start+= time_zone_len; 01260 } 01261 /* 01262 Here there could be code like 01263 if (command-line-option-which-says-"log_this_variable" && inited) 01264 { 01265 *start++= Q_THIS_VARIABLE_CODE; 01266 int4store(start, this_variable); 01267 start+= 4; 01268 } 01269 */ 01270 01271 /* Store length of status variables */ 01272 status_vars_len= (uint) (start-start_of_status); 01273 int2store(buf + Q_STATUS_VARS_LEN_OFFSET, status_vars_len); 01274 01275 /* 01276 Calculate length of whole event 01277 The "1" below is the \0 in the db's length 01278 */ 01279 event_length= (uint) (start-buf) + get_post_header_size_for_derived() + db_len + 1 + q_len; 01280 01281 return (write_header(file, event_length) || 01282 my_b_safe_write(file, (byte*) buf, QUERY_HEADER_LEN) || 01283 write_post_header_for_derived(file) || 01284 my_b_safe_write(file, (byte*) start_of_status, 01285 (uint) (start-start_of_status)) || 01286 my_b_safe_write(file, (db) ? (byte*) db : (byte*)"", db_len + 1) || 01287 my_b_safe_write(file, (byte*) query, q_len)) ? 1 : 0; 01288 }
Here is the call graph for this function:

Here is the caller graph for this function:

Reimplemented in Muted_query_log_event, Execute_load_query_log_event, Muted_query_log_event, and Execute_load_query_log_event.
Definition at line 823 of file log_event.h.
References FALSE.
00823 { return FALSE; }
Reimplemented in Muted_query_log_event, Execute_load_query_log_event, Muted_query_log_event, and Execute_load_query_log_event.
Definition at line 823 of file log_event.h.
References FALSE.
Referenced by write().
00823 { return FALSE; }
Here is the caller graph for this function:

| const char* Query_log_event::catalog |
Definition at line 726 of file log_event.h.
| const char* Query_log_event::catalog |
char* Query_log_event::data_buf [protected] |
Definition at line 723 of file log_event.h.
char* Query_log_event::data_buf [protected] |
Definition at line 723 of file log_event.h.
Referenced by Query_log_event(), and ~Query_log_event().
| const char* Query_log_event::db |
Definition at line 727 of file log_event.h.
| const char* Query_log_event::db |
Definition at line 727 of file log_event.h.
Referenced by get_db(), process_event(), Query_log_event(), write(), and write_to_binlog().
Definition at line 734 of file log_event.h.
Referenced by Query_log_event(), write(), and write_to_binlog().
Definition at line 735 of file log_event.h.
Referenced by binlog_commit(), binlog_rollback(), Query_log_event(), MYSQL_BIN_LOG::write(), write(), and write_to_binlog().
Definition at line 733 of file log_event.h.
Referenced by Execute_load_query_log_event::Execute_load_query_log_event(), Query_log_event(), and write().
| const char* Query_log_event::query |
Definition at line 725 of file log_event.h.
| const char* Query_log_event::query |
| const char* Query_log_event::time_zone_str |
Definition at line 793 of file log_event.h.
| const char* Query_log_event::time_zone_str |
1.4.7

