资讯专栏INFORMATION COLUMN

MySQL内核技术之"线程操作"

xuweijian / 1117人阅读

摘要:开始用创建,最后用销毁。中间是对进行赋值。和当前线程有关的是。然后把需要的内容取出来并赋值给主要是对三个变量赋值,,。因为是,所以其本身对执行并没有影响,我们可以把子线程的设置为。

预处理

当一个新的连接进来时,MySQL会创建对应的thread(pfs.cc):

/**
  Implementation of the thread instrumentation interface.
  @sa PSI_v1::spawn_thread.
*/
int pfs_spawn_thread_v1(PSI_thread_key key,
                        my_thread_handle *thread, const my_thread_attr_t *attr,
                        void *(*start_routine)(void*), void *arg)
{
  PFS_spawn_thread_arg *psi_arg;
  PFS_thread *parent;

  /* psi_arg can not be global, and can not be a local variable. */
  psi_arg= (PFS_spawn_thread_arg*) my_malloc(PSI_NOT_INSTRUMENTED,
                                             sizeof(PFS_spawn_thread_arg),
                                             MYF(MY_WME));
  if (unlikely(psi_arg == NULL))
    return EAGAIN;

  psi_arg->m_child_key= key;
  psi_arg->m_child_identity= (arg ? arg : thread);
  psi_arg->m_user_start_routine= start_routine;
  psi_arg->m_user_arg= arg;

  parent= my_thread_get_THR_PFS();
  if (parent != NULL)
  {
    /*
      Make a copy of the parent attributes.
      This is required, because instrumentation for this thread (the parent)
      may be destroyed before the child thread instrumentation is created.
    */
    psi_arg->m_thread_internal_id= parent->m_thread_internal_id;

    memcpy(psi_arg->m_username, parent->m_username, sizeof(psi_arg->m_username));
    psi_arg->m_username_length= parent->m_username_length;

    memcpy(psi_arg->m_hostname, parent->m_hostname, sizeof(psi_arg->m_hostname));
    psi_arg->m_hostname_length= parent->m_hostname_length;
  }
  else
  {
    psi_arg->m_thread_internal_id= 0;
    psi_arg->m_username_length= 0;
    psi_arg->m_hostname_length= 0;
  }

  int result= my_thread_create(thread, attr, pfs_spawn_thread, psi_arg);
  if (unlikely(result != 0))
    my_free(psi_arg);
  return result;
}

注意上面代码中最后的位置: my_thread_create(thread, attr, pfs_spawn_thread, psi_arg);这个函数直接调用pthread_create(&thread->thread, attr, func, arg)创建pthead。

这里最重要的事情是把当前thread的执行环境传到新的thread。所以上面代码前半部分都是在做这个事情。让我们看一下都需要传入哪些上下文。参数psi_arg就是要传入的上下文。开始用my_malloc创建,最后用my_free销毁。中间是对psi_arg进行赋值。

和当前线程有关的是parent= my_thread_get_THR_PFS()。然后把需要的parent内容取出来并赋值给psi_arg

/*
  Make a copy of the parent attributes.
  This is required, because instrumentation for this thread (the parent)
  may be destroyed before the child thread instrumentation is created.
*/
psi_arg->m_thread_internal_id= parent->m_thread_internal_id;

memcpy(psi_arg->m_username, parent->m_username, sizeof(psi_arg->m_username));
psi_arg->m_username_length= parent->m_username_length;

memcpy(psi_arg->m_hostname, parent->m_hostname, sizeof(psi_arg->m_hostname));
psi_arg->m_hostname_length= parent->m_hostname_length;

主要是对三个变量赋值:m_thread_internal_idm_usernamem_hostname

生成PFS_thread

从上面可以看到,生成的thread具体执行的pfs_spawn_thread函数,其内容如下:

extern "C" void* pfs_spawn_thread(void *arg)
{
  PFS_spawn_thread_arg *typed_arg= (PFS_spawn_thread_arg*) arg;
  void *user_arg;
  void *(*user_start_routine)(void*);

  PFS_thread *pfs;

  /* First, attach instrumentation to this newly created pthread. */
  PFS_thread_class *klass= find_thread_class(typed_arg->m_child_key);
  if (likely(klass != NULL))
  {
    pfs= create_thread(klass, typed_arg->m_child_identity, 0);
    if (likely(pfs != NULL))
    {
      pfs->m_thread_os_id= my_thread_os_id();
      clear_thread_account(pfs);

      pfs->m_parent_thread_internal_id= typed_arg->m_thread_internal_id;

      memcpy(pfs->m_username, typed_arg->m_username, sizeof(pfs->m_username));
      pfs->m_username_length= typed_arg->m_username_length;

      memcpy(pfs->m_hostname, typed_arg->m_hostname, sizeof(pfs->m_hostname));
      pfs->m_hostname_length= typed_arg->m_hostname_length;

      set_thread_account(pfs);
    }
  }
  else
  {
    pfs= NULL;
  }
  std::cout << "my_thread_set_THR_PFS in pfs_spawn_thread, value: " << pfs << std::endl;
  my_thread_set_THR_PFS(pfs);

  /*
    Secondly, free the memory allocated in spawn_thread_v1().
    It is preferable to do this before invoking the user
    routine, to avoid memory leaks at shutdown, in case
    the server exits without waiting for this thread.
  */
  user_start_routine= typed_arg->m_user_start_routine;
  user_arg= typed_arg->m_user_arg;
  my_free(typed_arg);

  /* Then, execute the user code for this thread. */
  (*user_start_routine)(user_arg);

  return NULL;
}
代码改动

由于开发原因,我加入了一个boost线程池,那么从原始线程产生任务塞入boost线程池中的时候,需要做类似的操作,即要传入一个psi_arg参数。因为PSI是performance schema,所以其本身对执行并没有影响,我们可以把子线程的PSI设置为NULL。在psi.h中,我们可以看到:

/**
  Instrumented thread key.
  To instrument a thread, a thread key must be obtained
  using @c register_thread.
  Using a zero key always disable the instrumentation.
*/
typedef unsigned int PSI_thread_key;

获取当前的pfs:

/**
  Implementation of the thread instrumentation interface.
  @sa PSI_v1::get_thread_id.
*/
PSI_thread*
pfs_get_thread_v1(void)
{
  PFS_thread *pfs= my_thread_get_THR_PFS();
  return reinterpret_cast (pfs);
}

注意,不能直接用my_thread_get_THR_PFS()获取,因为其为static函数,只能用于本文件使用。同理设置pfs:

/**
  Implementation of the thread instrumentation interface.
  @sa PSI_v1::set_thread.
*/
void pfs_set_thread_v1(PSI_thread* thread)
{
  PFS_thread *pfs= reinterpret_cast (thread);
  my_thread_set_THR_PFS(pfs);
  std::cout << "my_thread_set_THR_PFS in pfs_set_thread_v1, value: "<< pfs << std::endl;
}

附录:
定义的PSI结构(psi.h):

/**
  Performance Schema Interface, version 1.
  @since PSI_VERSION_1
*/
struct PSI_v1
{
  /** @sa register_mutex_v1_t. */
  register_mutex_v1_t register_mutex;
  /** @sa register_rwlock_v1_t. */
  register_rwlock_v1_t register_rwlock;
  /** @sa register_cond_v1_t. */
  register_cond_v1_t register_cond;
  /** @sa register_thread_v1_t. */
  register_thread_v1_t register_thread;
  /** @sa register_file_v1_t. */
  register_file_v1_t register_file;
  /** @sa register_stage_v1_t. */
  register_stage_v1_t register_stage;
  /** @sa register_statement_v1_t. */
  register_statement_v1_t register_statement;
  /** @sa register_socket_v1_t. */
  register_socket_v1_t register_socket;
  /** @sa init_mutex_v1_t. */
  init_mutex_v1_t init_mutex;
  /** @sa destroy_mutex_v1_t. */
  destroy_mutex_v1_t destroy_mutex;
  /** @sa init_rwlock_v1_t. */
  init_rwlock_v1_t init_rwlock;
  /** @sa destroy_rwlock_v1_t. */
  destroy_rwlock_v1_t destroy_rwlock;
  /** @sa init_cond_v1_t. */
  init_cond_v1_t init_cond;
  /** @sa destroy_cond_v1_t. */
  destroy_cond_v1_t destroy_cond;
  /** @sa init_socket_v1_t. */
  init_socket_v1_t init_socket;
  /** @sa destroy_socket_v1_t. */
  destroy_socket_v1_t destroy_socket;

  /** @sa get_table_share_v1_t. */
  get_table_share_v1_t get_table_share;
  /** @sa release_table_share_v1_t. */
  release_table_share_v1_t release_table_share;
  /** @sa drop_table_share_v1_t. */
  drop_table_share_v1_t drop_table_share;
  /** @sa open_table_v1_t. */
  open_table_v1_t open_table;
  /** @sa unbind_table_v1_t. */
  unbind_table_v1_t unbind_table;
  /** @sa rebind_table_v1_t. */
  rebind_table_v1_t rebind_table;
  /** @sa close_table_v1_t. */
  close_table_v1_t close_table;
  /** @sa create_file_v1_t. */
  create_file_v1_t create_file;
  /** @sa spawn_thread_v1_t. */
  spawn_thread_v1_t spawn_thread;
  /** @sa new_thread_v1_t. */
  new_thread_v1_t new_thread;
  /** @sa set_thread_id_v1_t. */
  set_thread_id_v1_t set_thread_id;
  /** @sa set_thread_THD_v1_t. */
  set_thread_THD_v1_t set_thread_THD;
  /** @sa set_thread_os_id_v1_t. */
  set_thread_os_id_v1_t set_thread_os_id;
  /** @sa get_thread_v1_t. */
  get_thread_v1_t get_thread;
  /** @sa set_thread_user_v1_t. */
  set_thread_user_v1_t set_thread_user;
  /** @sa set_thread_account_v1_t. */
  set_thread_account_v1_t set_thread_account;
  /** @sa set_thread_db_v1_t. */
  set_thread_db_v1_t set_thread_db;
  /** @sa set_thread_command_v1_t. */
  set_thread_command_v1_t set_thread_command;
  /** @sa set_connection_type_v1_t. */
  set_connection_type_v1_t set_connection_type;
  /** @sa set_thread_start_time_v1_t. */
  set_thread_start_time_v1_t set_thread_start_time;
  /** @sa set_thread_state_v1_t. */
  set_thread_state_v1_t set_thread_state;
  /** @sa set_thread_info_v1_t. */
  set_thread_info_v1_t set_thread_info;
  /** @sa set_thread_v1_t. */
  set_thread_v1_t set_thread;
  /** @sa delete_current_thread_v1_t. */
  delete_current_thread_v1_t delete_current_thread;
  /** @sa delete_thread_v1_t. */
  delete_thread_v1_t delete_thread;
  /** @sa get_thread_file_name_locker_v1_t. */
  get_thread_file_name_locker_v1_t get_thread_file_name_locker;
  /** @sa get_thread_file_stream_locker_v1_t. */
  get_thread_file_stream_locker_v1_t get_thread_file_stream_locker;
  /** @sa get_thread_file_descriptor_locker_v1_t. */
  get_thread_file_descriptor_locker_v1_t get_thread_file_descriptor_locker;
  /** @sa unlock_mutex_v1_t. */
  unlock_mutex_v1_t unlock_mutex;
  /** @sa unlock_rwlock_v1_t. */
  unlock_rwlock_v1_t unlock_rwlock;
  /** @sa signal_cond_v1_t. */
  signal_cond_v1_t signal_cond;
  /** @sa broadcast_cond_v1_t. */
  broadcast_cond_v1_t broadcast_cond;
  /** @sa start_idle_wait_v1_t. */
  start_idle_wait_v1_t start_idle_wait;
  /** @sa end_idle_wait_v1_t. */
  end_idle_wait_v1_t end_idle_wait;
  /** @sa start_mutex_wait_v1_t. */
  start_mutex_wait_v1_t start_mutex_wait;
  /** @sa end_mutex_wait_v1_t. */
  end_mutex_wait_v1_t end_mutex_wait;
  /** @sa start_rwlock_rdwait_v1_t. */
  start_rwlock_rdwait_v1_t start_rwlock_rdwait;
  /** @sa end_rwlock_rdwait_v1_t. */
  end_rwlock_rdwait_v1_t end_rwlock_rdwait;
  /** @sa start_rwlock_wrwait_v1_t. */
  start_rwlock_wrwait_v1_t start_rwlock_wrwait;
  /** @sa end_rwlock_wrwait_v1_t. */
  end_rwlock_wrwait_v1_t end_rwlock_wrwait;
  /** @sa start_cond_wait_v1_t. */
  start_cond_wait_v1_t start_cond_wait;
  /** @sa end_cond_wait_v1_t. */
  end_cond_wait_v1_t end_cond_wait;
  /** @sa start_table_io_wait_v1_t. */
  start_table_io_wait_v1_t start_table_io_wait;
  /** @sa end_table_io_wait_v1_t. */
  end_table_io_wait_v1_t end_table_io_wait;
  /** @sa start_table_lock_wait_v1_t. */
  start_table_lock_wait_v1_t start_table_lock_wait;
  /** @sa end_table_lock_wait_v1_t. */
  end_table_lock_wait_v1_t end_table_lock_wait;
  /** @sa start_file_open_wait_v1_t. */
  start_file_open_wait_v1_t start_file_open_wait;
  /** @sa end_file_open_wait_v1_t. */
  end_file_open_wait_v1_t end_file_open_wait;
  /** @sa end_file_open_wait_and_bind_to_descriptor_v1_t. */
  end_file_open_wait_and_bind_to_descriptor_v1_t
    end_file_open_wait_and_bind_to_descriptor;
  /** @sa end_temp_file_open_wait_and_bind_to_descriptor_v1_t. */
  end_temp_file_open_wait_and_bind_to_descriptor_v1_t
    end_temp_file_open_wait_and_bind_to_descriptor;
  /** @sa start_file_wait_v1_t. */
  start_file_wait_v1_t start_file_wait;
  /** @sa end_file_wait_v1_t. */
  end_file_wait_v1_t end_file_wait;
  /** @sa start_file_close_wait_v1_t. */
  start_file_close_wait_v1_t start_file_close_wait;
  /** @sa end_file_close_wait_v1_t. */
  end_file_close_wait_v1_t end_file_close_wait;
  /** @sa start_stage_v1_t. */
  start_stage_v1_t start_stage;
  /** @sa get_current_stage_progress_v1_t. */
  get_current_stage_progress_v1_t get_current_stage_progress;
  /** @sa end_stage_v1_t. */
  end_stage_v1_t end_stage;
  /** @sa get_thread_statement_locker_v1_t. */
  get_thread_statement_locker_v1_t get_thread_statement_locker;
  /** @sa refine_statement_v1_t. */
  refine_statement_v1_t refine_statement;
  /** @sa start_statement_v1_t. */
  start_statement_v1_t start_statement;
  /** @sa set_statement_text_v1_t. */
  set_statement_text_v1_t set_statement_text;
  /** @sa set_statement_lock_time_t. */
  set_statement_lock_time_t set_statement_lock_time;
  /** @sa set_statement_rows_sent_t. */
  set_statement_rows_sent_t set_statement_rows_sent;
  /** @sa set_statement_rows_examined_t. */
  set_statement_rows_examined_t set_statement_rows_examined;
  /** @sa inc_statement_created_tmp_disk_tables. */
  inc_statement_created_tmp_disk_tables_t inc_statement_created_tmp_disk_tables;
  /** @sa inc_statement_created_tmp_tables. */
  inc_statement_created_tmp_tables_t inc_statement_created_tmp_tables;
  /** @sa inc_statement_select_full_join. */
  inc_statement_select_full_join_t inc_statement_select_full_join;
  /** @sa inc_statement_select_full_range_join. */
  inc_statement_select_full_range_join_t inc_statement_select_full_range_join;
  /** @sa inc_statement_select_range. */
  inc_statement_select_range_t inc_statement_select_range;
  /** @sa inc_statement_select_range_check. */
  inc_statement_select_range_check_t inc_statement_select_range_check;
  /** @sa inc_statement_select_scan. */
  inc_statement_select_scan_t inc_statement_select_scan;
  /** @sa inc_statement_sort_merge_passes. */
  inc_statement_sort_merge_passes_t inc_statement_sort_merge_passes;
  /** @sa inc_statement_sort_range. */
  inc_statement_sort_range_t inc_statement_sort_range;
  /** @sa inc_statement_sort_rows. */
  inc_statement_sort_rows_t inc_statement_sort_rows;
  /** @sa inc_statement_sort_scan. */
  inc_statement_sort_scan_t inc_statement_sort_scan;
  /** @sa set_statement_no_index_used. */
  set_statement_no_index_used_t set_statement_no_index_used;
  /** @sa set_statement_no_good_index_used. */
  set_statement_no_good_index_used_t set_statement_no_good_index_used;
  /** @sa end_statement_v1_t. */
  end_statement_v1_t end_statement;
  /** @sa get_thread_transaction_locker_v1_t. */
  get_thread_transaction_locker_v1_t get_thread_transaction_locker;
  /** @sa start_transaction_v1_t. */
  start_transaction_v1_t start_transaction;
  /** @sa set_transaction_xid_v1_t. */
  set_transaction_xid_v1_t set_transaction_xid;
  /** @sa set_transaction_xa_state_v1_t. */
  set_transaction_xa_state_v1_t set_transaction_xa_state;
  /** @sa set_transaction_gtid_v1_t. */
  set_transaction_gtid_v1_t set_transaction_gtid;
  /** @sa set_transaction_trxid_v1_t. */
  set_transaction_trxid_v1_t set_transaction_trxid;
  /** @sa inc_transaction_savepoints_v1_t. */
  inc_transaction_savepoints_v1_t inc_transaction_savepoints;
  /** @sa inc_transaction_rollback_to_savepoint_v1_t. */
  inc_transaction_rollback_to_savepoint_v1_t inc_transaction_rollback_to_savepoint;
  /** @sa inc_transaction_release_savepoint_v1_t. */
  inc_transaction_release_savepoint_v1_t inc_transaction_release_savepoint;
  /** @sa end_transaction_v1_t. */
  end_transaction_v1_t end_transaction;
  /** @sa start_socket_wait_v1_t. */
  start_socket_wait_v1_t start_socket_wait;
  /** @sa end_socket_wait_v1_t. */
  end_socket_wait_v1_t end_socket_wait;
  /** @sa set_socket_state_v1_t. */
  set_socket_state_v1_t set_socket_state;
  /** @sa set_socket_info_v1_t. */
  set_socket_info_v1_t set_socket_info;
  /** @sa set_socket_thread_owner_v1_t. */
  set_socket_thread_owner_v1_t set_socket_thread_owner;
  /** @sa create_prepared_stmt_v1_t. */
  create_prepared_stmt_v1_t create_prepared_stmt;
  /** @sa destroy_prepared_stmt_v1_t. */
  destroy_prepared_stmt_v1_t destroy_prepared_stmt;
  /** @sa reprepare_prepared_stmt_v1_t. */
  reprepare_prepared_stmt_v1_t reprepare_prepared_stmt;
  /** @sa execute_prepared_stmt_v1_t. */
  execute_prepared_stmt_v1_t execute_prepared_stmt;
  /** @sa digest_start_v1_t. */
  digest_start_v1_t digest_start;
  /** @sa digest_end_v1_t. */
  digest_end_v1_t digest_end;
  /** @sa set_thread_connect_attrs_v1_t. */
  set_thread_connect_attrs_v1_t set_thread_connect_attrs;
  /** @sa start_sp_v1_t. */
  start_sp_v1_t start_sp;
  /** @sa start_sp_v1_t. */
  end_sp_v1_t end_sp;
  /** @sa drop_sp_v1_t. */
  drop_sp_v1_t drop_sp;
  /** @sa get_sp_share_v1_t. */
  get_sp_share_v1_t get_sp_share;
  /** @sa release_sp_share_v1_t. */
  release_sp_share_v1_t release_sp_share;
  /** @sa register_memory_v1_t. */
  register_memory_v1_t register_memory;
  /** @sa memory_alloc_v1_t. */
  memory_alloc_v1_t memory_alloc;
  /** @sa memory_realloc_v1_t. */
  memory_realloc_v1_t memory_realloc;
  /** @sa memory_claim_v1_t. */
  memory_claim_v1_t memory_claim;
  /** @sa memory_free_v1_t. */
  memory_free_v1_t memory_free;

  unlock_table_v1_t unlock_table;

  create_metadata_lock_v1_t create_metadata_lock;
  set_metadata_lock_status_v1_t set_metadata_lock_status;
  destroy_metadata_lock_v1_t destroy_metadata_lock;

  start_metadata_wait_v1_t start_metadata_wait;
  end_metadata_wait_v1_t end_metadata_wait;
};

该结构在psi.cc被赋值:

/**
  Implementation of the instrumentation interface.
  @sa PSI_v1.
*/
PSI_v1 PFS_v1=
{
  pfs_register_mutex_v1,
  pfs_register_rwlock_v1,
  pfs_register_cond_v1,
  pfs_register_thread_v1,
  pfs_register_file_v1,
  pfs_register_stage_v1,
  pfs_register_statement_v1,
  pfs_register_socket_v1,
  pfs_init_mutex_v1,
  pfs_destroy_mutex_v1,
  pfs_init_rwlock_v1,
  pfs_destroy_rwlock_v1,
  pfs_init_cond_v1,
  pfs_destroy_cond_v1,
  pfs_init_socket_v1,
  pfs_destroy_socket_v1,
  pfs_get_table_share_v1,
  pfs_release_table_share_v1,
  pfs_drop_table_share_v1,
  pfs_open_table_v1,
  pfs_unbind_table_v1,
  pfs_rebind_table_v1,
  pfs_close_table_v1,
  pfs_create_file_v1,
  pfs_spawn_thread_v1,
  pfs_new_thread_v1,
  pfs_set_thread_id_v1,
  pfs_set_thread_THD_v1,
  pfs_set_thread_os_id_v1,
  pfs_get_thread_v1,
  pfs_set_thread_user_v1,
  pfs_set_thread_account_v1,
  pfs_set_thread_db_v1,
  pfs_set_thread_command_v1,
  pfs_set_connection_type_v1,
  pfs_set_thread_start_time_v1,
  pfs_set_thread_state_v1,
  pfs_set_thread_info_v1,
  pfs_set_thread_v1,
  pfs_delete_current_thread_v1,
  pfs_delete_thread_v1,
  pfs_get_thread_file_name_locker_v1,
  pfs_get_thread_file_stream_locker_v1,
  pfs_get_thread_file_descriptor_locker_v1,
  pfs_unlock_mutex_v1,
  pfs_unlock_rwlock_v1,
  pfs_signal_cond_v1,
  pfs_broadcast_cond_v1,
  pfs_start_idle_wait_v1,
  pfs_end_idle_wait_v1,
  pfs_start_mutex_wait_v1,
  pfs_end_mutex_wait_v1,
  pfs_start_rwlock_rdwait_v1,
  pfs_end_rwlock_rdwait_v1,
  pfs_start_rwlock_wrwait_v1,
  pfs_end_rwlock_wrwait_v1,
  pfs_start_cond_wait_v1,
  pfs_end_cond_wait_v1,
  pfs_start_table_io_wait_v1,
  pfs_end_table_io_wait_v1,
  pfs_start_table_lock_wait_v1,
  pfs_end_table_lock_wait_v1,
  pfs_start_file_open_wait_v1,
  pfs_end_file_open_wait_v1,
  pfs_end_file_open_wait_and_bind_to_descriptor_v1,
  pfs_end_temp_file_open_wait_and_bind_to_descriptor_v1,
  pfs_start_file_wait_v1,
  pfs_end_file_wait_v1,
  pfs_start_file_close_wait_v1,
  pfs_end_file_close_wait_v1,
  pfs_start_stage_v1,
  pfs_get_current_stage_progress_v1,
  pfs_end_stage_v1,
  pfs_get_thread_statement_locker_v1,
  pfs_refine_statement_v1,
  pfs_start_statement_v1,
  pfs_set_statement_text_v1,
  pfs_set_statement_lock_time_v1,
  pfs_set_statement_rows_sent_v1,
  pfs_set_statement_rows_examined_v1,
  pfs_inc_statement_created_tmp_disk_tables_v1,
  pfs_inc_statement_created_tmp_tables_v1,
  pfs_inc_statement_select_full_join_v1,
  pfs_inc_statement_select_full_range_join_v1,
  pfs_inc_statement_select_range_v1,
  pfs_inc_statement_select_range_check_v1,
  pfs_inc_statement_select_scan_v1,
  pfs_inc_statement_sort_merge_passes_v1,
  pfs_inc_statement_sort_range_v1,
  pfs_inc_statement_sort_rows_v1,
  pfs_inc_statement_sort_scan_v1,
  pfs_set_statement_no_index_used_v1,
  pfs_set_statement_no_good_index_used_v1,
  pfs_end_statement_v1,
  pfs_get_thread_transaction_locker_v1,
  pfs_start_transaction_v1,
  pfs_set_transaction_xid_v1,
  pfs_set_transaction_xa_state_v1,
  pfs_set_transaction_gtid_v1,
  pfs_set_transaction_trxid_v1,
  pfs_inc_transaction_savepoints_v1,
  pfs_inc_transaction_rollback_to_savepoint_v1,
  pfs_inc_transaction_release_savepoint_v1,
  pfs_end_transaction_v1,
  pfs_start_socket_wait_v1,
  pfs_end_socket_wait_v1,
  pfs_set_socket_state_v1,
  pfs_set_socket_info_v1,
  pfs_set_socket_thread_owner_v1,
  pfs_create_prepared_stmt_v1,
  pfs_destroy_prepared_stmt_v1,
  pfs_reprepare_prepared_stmt_v1,
  pfs_execute_prepared_stmt_v1,
  pfs_digest_start_v1,
  pfs_digest_end_v1,
  pfs_set_thread_connect_attrs_v1,
  pfs_start_sp_v1,
  pfs_end_sp_v1,
  pfs_drop_sp_v1,
  pfs_get_sp_share_v1,
  pfs_release_sp_share_v1,
  pfs_register_memory_v1,
  pfs_memory_alloc_v1,
  pfs_memory_realloc_v1,
  pfs_memory_claim_v1,
  pfs_memory_free_v1,
  pfs_unlock_table_v1,
  pfs_create_metadata_lock_v1,
  pfs_set_metadata_lock_status_v1,
  pfs_destroy_metadata_lock_v1,
  pfs_start_metadata_wait_v1,
  pfs_end_metadata_wait_v1
}; 

每一个值都是一个函数。感兴趣的可以去看对应实现。

文章版权归作者所有,未经允许请勿转载,若此文章存在违规行为,您可以联系管理员删除。

转载请注明本文地址:https://www.ucloud.cn/yun/47283.html

相关文章

  • MySQL内核技术&quot;LIKE&quot;和&quot;IN&quot;

    摘要:在中,像这些操作符都属于类型在中,这些都是。先说,它对应的类为位于中。进行的时候实际上是在中进行折半查找。因此如果想做并发执行,多线程就共用了该变量。解决办法和上面类似,独立出一个数组,来对应不同线程即可。 在MySQL中,像LIKE、IN、>、= 这些操作符都属于Item类型(在Postgres中,这些都是expression)。本节中,我们详细说说LIKE和IN是怎么实现的。 先说...

    edagarli 评论0 收藏0
  • MySQL内核技术&quot;线程操作&quot;

    摘要:开始用创建,最后用销毁。中间是对进行赋值。和当前线程有关的是。然后把需要的内容取出来并赋值给主要是对三个变量赋值,,。因为是,所以其本身对执行并没有影响,我们可以把子线程的设置为。 预处理 当一个新的连接进来时,MySQL会创建对应的thread(pfs.cc): /** Implementation of the thread instrumentation interface....

    hover_lew 评论0 收藏0
  • MySQL内核技术&quot;线程操作&quot;

    摘要:开始用创建,最后用销毁。中间是对进行赋值。和当前线程有关的是。然后把需要的内容取出来并赋值给主要是对三个变量赋值,,。因为是,所以其本身对执行并没有影响,我们可以把子线程的设置为。 预处理 当一个新的连接进来时,MySQL会创建对应的thread(pfs.cc): /** Implementation of the thread instrumentation interface....

    XiNGRZ 评论0 收藏0
  • MySQL内核技术&quot;查询流程&quot;

    摘要:本节讨论是如何进行数据查询和读取的。首先看一下调用过程实际上是或实际上是是从派生出来的,用来做实际查询的。里面的重要结构有这里面最重要的是结构,其中比较重要的几项是由调用的,常用的方式是,这里的实际上就是。 本节讨论MySQL是如何进行数据查询和读取的。首先看一下调用过程: JOIN::exec()--> do_select()--> sub_select()--> read_reco...

    dinfer 评论0 收藏0
  • 如何&quot;有计划,高效率,优简历&quot;应对面试

    摘要:虽然有了十全的计划,但如何高效率去记住上面那么多东西是一个大问题,看看我是怎么做的。 前言 前一篇文章讲述了我在三月份毫无准备就去面试的后果,一开始心态真的爆炸,但是又不服气,一想到每次回来后家人朋友问我面试结果的期待脸,越觉得必须付出的行动来证明自己了。 面经传送门:一个1年工作经验的PHP程序员是如何被面试官虐的? 下面是我花费两个星期做的准备,主要分三部分: 有计划——计划好...

    gyl_coder 评论0 收藏0

发表评论

0条评论

xuweijian

|高级讲师

TA的文章

阅读更多
最新活动
阅读需要支付1元查看
<