27 #include <my_global.h>
31 #include <mysql_version.h>
32 #include <mysql/plugin.h>
34 #include "my_pthread.h"
37 #include "sql_plugin.h"
39 #include "sql_class.h"
43 #include "transaction.h"
44 #include "sql_handler.h"
53 extern int write_bin_log(THD *thd,
bool clear_error,
54 char const *
query, ulong query_length,
55 bool is_trans=
false);
62 const uchar *before_record,
63 const uchar *after_record,
77 fprintf(stderr,
" InnoDB_Memcached: MySQL server"
78 " binlog not enabled\n");
90 thd->variables.pseudo_thread_id = thread_id++;
91 thd->thread_id = thd->variables.pseudo_thread_id;
92 thd->thread_stack =
reinterpret_cast<char*
>(&thd);
96 thd->binlog_setup_trx_data();
99 thd->set_current_stmt_binlog_format_row();
114 THD* thd =
static_cast<THD*
>(my_thd);
117 *original_thd = my_pthread_getspecific(THD*, THR_THD);
118 assert(thd->mysys_var);
121 my_pthread_setspecific_ptr(THR_THD, thd);
122 my_pthread_setspecific_ptr(THR_MALLOC, &thd->mem_root);
123 set_mysys_var(thd->mysys_var);
138 THD* thd =
static_cast<THD*
>(my_thd);
140 thr_lock_type lock_mode;
147 strlen(table_name), table_name, lock_mode);
149 tables.mdl_request.
init(MDL_key::TABLE, db_name, table_name,
150 (lock_mode > TL_READ)
152 : MDL_SHARED_READ, MDL_TRANSACTION);
156 table->use_all_columns();
173 THD* thd =
static_cast<THD*
>(my_thd);
176 if (thd->get_binlog_table_maps() == 0) {
178 thd->binlog_write_table_map(
179 static_cast<TABLE*>(my_table), 1, 0);
185 assert(table->record[1]);
186 log_func = Update_rows_log_event::binlog_row_logging_function;
191 log_func = Write_rows_log_event::binlog_row_logging_function;
195 log_func = Delete_rows_log_event::binlog_row_logging_function;
211 THD* thd =
static_cast<THD*
>(my_thd);
214 tc_log->
commit(thd,
true);
216 trans_commit_stmt(thd);
227 THD* thd =
static_cast<THD*
>(my_thd);
236 trans_rollback_stmt(thd);
247 THD* thd = (THD*) my_thd;
248 char query_str[MAX_FULL_NAME_LEN + 16];
251 memset(query_str, 0,
sizeof(query_str));
253 assert(strlen(table_name) < MAX_FULL_NAME_LEN);
255 snprintf(query_str, MAX_FULL_NAME_LEN + 16,
"%s %s",
256 "truncate table", table_name);
258 len = strlen(query_str);
260 write_bin_log(thd, 1, query_str, len);
270 empty_record(static_cast<TABLE*>(my_table));
286 fld = table->field[field_id];
291 fld->store(str, len, &my_charset_bin);
312 fld = table->field[field_id];
318 fld->store(value, unsigned_flag);
337 fld = table->field[field_id];
343 fld->store(value, unsigned_flag);
354 store_record(static_cast<TABLE*>(my_table),
record[1]);
364 THD* thd =
static_cast<THD*
>(my_thd);
369 thd->release_resources();
373 my_pthread_setspecific_ptr(THR_THD, 0);
387 THD* thd =
static_cast<THD*
>(my_thd);
389 thr_lock_type lock_mode;
391 lock_mode = (mode &
HDL_READ) ? TL_READ : TL_WRITE;
393 if (lock_mode == TL_WRITE) {
394 query_cache_invalidate3(thd, table, 1);
395 table->file->ha_release_auto_increment();
398 result = trans_commit_stmt(thd);
401 mysql_unlock_tables(thd, thd->lock);
415 #ifdef HANDLER_API_MEMCACHED
423 field_arg_t* srch_args,
426 KEY* key_info = &my_table->key_info[0];
427 uchar* srch_buf =
new uchar[key_info->
key_length];
428 size_t total_key_len = 0;
429 key_part_map part_map;
431 handler* handle = my_table->file;
433 assert(srch_args->num_arg <= key_info->key_parts);
435 for (
unsigned int i = 0;
i < key_info->key_parts;
i++) {
438 key_part = &key_info->key_part[
i];
440 if (i < srch_args->num_arg) {
441 int srch_len = srch_args->len[
i];
443 assert(srch_len >= 0);
446 key_part->field->set_null();
448 char* srch_value = srch_args->value[
i];
449 key_part->field->set_notnull();
450 key_part->field->store(srch_value,
453 total_key_len += key_part->store_length;
456 key_part->field->set_null();
460 assert(key_info->
key_length >= total_key_len);
462 key_copy(srch_buf, my_table->record[0], key_info, total_key_len);
463 my_table->read_set = &my_table->s->all_set;
466 assert(srch_args->num_arg <= 4096);
468 part_map = (1 << srch_args->num_arg) - 1;
470 handle->ha_index_or_rnd_end();
474 part_map, HA_READ_KEY_EXACT);
479 return(my_table->record[0]);
492 field_arg_t* store_args)
495 KEY* key_info = &(
table->key_info[0]);
496 handler* handle = my_table->file;
498 empty_record(my_table);
500 assert(
table->reginfo.lock_type > TL_READ
501 &&
table->reginfo.lock_type <= TL_WRITE_ONLY);
503 insert_buf = my_table->record[0];
504 memset(insert_buf, 0, my_table->s->null_bytes);
506 assert(store_args->num_arg == key_info->key_parts);
508 for (
unsigned int i = 0;
i < key_info->key_parts;
i++) {
512 if (store_args->len[
i]) {
513 fld->store(store_args->value[
i],
514 store_args->len[
i], &my_charset_bin);
521 return(handle->ha_write_row((uchar *)my_table->record[0]));
531 field_arg_t* store_args)
533 uchar*
buf = my_table->record[0];
534 handler* handle = my_table->file;
535 KEY* key_info = &my_table->key_info[0];
537 store_record(my_table,
record[1]);
539 for (
unsigned int i = 0;
i < key_info->key_parts;
i++) {
542 fld = my_table->field[
i];
543 fld->store(store_args->value[
i],
544 store_args->len[
i], &my_charset_bin);
548 return(handle->ha_update_row(my_table->record[1], buf));
559 return(my_table->file->ha_delete_row(my_table->record[0]));
570 thr_lock_type lock_mode)
573 my_table->reginfo.lock_type = lock_mode;
576 return(my_thd->lock);