Session Class Reference

#include <session.h>

Inheritance diagram for Session:

Inheritance graph
[legend]
Collaboration diagram for Session:

Collaboration graph
[legend]

List of all members.

Classes

struct  st_transactions

Public Types

enum  killed_state {
  NOT_KILLED, KILL_BAD_DATA, KILL_CONNECTION, KILL_QUERY,
  KILLED_NO_VALUE
}

Public Member Functions

void * alloc (size_t size)
void * calloc (size_t size)
char * strdup (const char *str)
char * strmake (const char *str, size_t size)
void * memdup (const void *str, size_t size)
void * memdup_w_gap (const void *str, size_t size, uint32_t gap)
void free_items ()
void ** getEngineData (const drizzled::plugin::StorageEngine *engine)
Ha_trx_infogetEngineInfo (const drizzled::plugin::StorageEngine *engine, size_t index=0)
void set_proc_info (const char *info)
const char * get_proc_info () const
query_id_t getQueryId () const
const char * getQueryString () const
size_t getQueryLength () const
uint64_t getSessionId () const
uint32_t getServerId () const
my_xid getTransactionId ()
void record_first_successful_insert_id_in_cur_stmt (uint64_t id_arg)
uint64_t read_first_successful_insert_id_in_prev_stmt (void)
void force_one_auto_inc_interval (uint64_t next_id)
 Session (drizzled::plugin::Client *client_arg)
void cleanup (void)
void cleanup_after_query ()
bool storeGlobals ()
void awake (Session::killed_state state_to_set)
bool initGlobals ()
void prepareForQueries ()
bool executeStatement ()
bool readAndStoreQuery (const char *in_packet, uint32_t in_packet_length)
bool endTransaction (enum enum_mysql_completiontype completion)
bool endActiveTransaction ()
bool startTransaction (start_transaction_option_t opt=START_TRANS_NO_OPTIONS)
bool authenticate ()
void run ()
bool schedule ()
const char * enter_cond (pthread_cond_t *cond, pthread_mutex_t *mutex, const char *msg)
void exit_cond (const char *old_msg)
time_t query_start ()
void set_time ()
void set_current_time ()
void set_time (time_t t)
void set_time_after_lock ()
uint64_t getCurrentTimestamp ()
uint64_t found_rows (void)
bool inTransaction ()
bool fill_derived_tables ()
void * trans_alloc (unsigned int size)
LEX_STRING * make_lex_string (LEX_STRING *lex_str, const char *str, uint32_t length, bool allocate_lex_string)
void add_changed_table (Table *table)
void add_changed_table (const char *key, long key_length)
CHANGED_TableList * changed_table_dup (const char *key, long key_length)
int send_explain_fields (select_result *result)
void clear_error ()
void fatal_error ()
bool is_error () const
const CHARSET_INFO * charset ()
void change_item_tree (Item **place, Item *new_value)
void end_statement ()
int killed_errno () const
void send_kill_message () const
bool really_abort_on_warning ()
void set_status_var_init ()
void reset_n_backup_open_tables_state (Open_tables_state *backup)
void restore_backup_open_tables_state (Open_tables_state *backup)
bool set_db (const NormalisedDatabaseName &new_db)
void clear_db ()
bool copy_db_to (char **p_db, size_t *p_db_length)
void push_internal_handler (Internal_error_handler *handler)
virtual bool handle_error (uint32_t sql_errno, const char *message, DRIZZLE_ERROR::enum_warning_level level)
void pop_internal_handler ()
void reset_for_next_command ()
void disconnect (uint32_t errcode, bool lock)
bool checkUser (const char *passwd, uint32_t passwd_len, const char *db)
uint64_t getConnectMicroseconds () const
drizzled::message::Transaction * getTransactionMessage () const
drizzled::message::Statement * getStatementMessage () const
void setTransactionMessage (drizzled::message::Transaction *in_message)
void setStatementMessage (drizzled::message::Statement *in_message)
void my_ok (ha_rows affected_rows=0, ha_rows found_rows_arg=0, uint64_t passed_id=0, const char *message=NULL)
void my_eof ()
bool add_item_to_list (Item *item)
bool add_value_to_list (Item *value)
bool add_order_to_list (Item *item, bool asc)
bool add_group_to_list (Item *item, bool asc)
void refresh_status ()
user_var_entry * getVariable (LEX_STRING &name, bool create_if_not_exists)
void close_thread_tables ()
void close_old_data_files (bool morph_locks=false, bool send_refresh=false)
void close_open_tables ()
void close_data_files_and_morph_locks (const char *db, const char *table_name)
void close_tables_for_reopen (TableList **tables)
bool openTablesLock (TableList *tables)
bool openTables (TableList *tables, uint32_t flags=0)
int open_tables_from_list (TableList **start, uint32_t *counter, uint32_t flags=0)
TableopenTableLock (TableList *table_list, thr_lock_type lock_type)
TableopenTable (TableList *table_list, bool *refresh, uint32_t flags=0)
void unlink_open_table (Table *find)
void drop_open_table (Table *table, const char *db_name, const char *table_name)
void close_cached_table (Table *table)
Tabletable_cache_insert_placeholder (const char *key, uint32_t key_length)
bool lock_table_name_if_not_cached (const char *db, const char *table_name, Table **table)
Tablefind_temporary_table (TableList *table_list)
Tablefind_temporary_table (const char *db, const char *table_name)
void close_temporary_tables ()
void close_temporary_table (Table *table)
int drop_temporary_table (TableList *table_list)
bool rm_temporary_table (drizzled::plugin::StorageEngine *base, const char *path)
bool rm_temporary_table (drizzled::plugin::StorageEngine *base, drizzled::TableIdentifier &identifier)
Tableopen_temporary_table (drizzled::TableIdentifier &identifier, bool link_in_list=true)
bool reopen_tables (bool get_locks, bool mark_share_as_old)
bool reopen_name_locked_table (TableList *table_list, bool link_in)
bool close_cached_tables (TableList *tables, bool wait_for_refresh, bool wait_for_placeholders)
void wait_for_condition (pthread_mutex_t *mutex, pthread_cond_t *cond)
int setup_conds (TableList *leaves, COND **conds)
int lock_tables (TableList *tables, uint32_t count, bool *need_reopen)
drizzled::plugin::StorageEngine * getDefaultStorageEngine ()
void set_open_tables_state (Open_tables_state *state)
void reset_open_tables_state ()

Static Public Member Functions

static void unlink (Session *session)

Public Attributes

enum enum_mark_columns mark_used_columns
Itemfree_list
drizzled::memory::Root * mem_root
uint32_t id
LEX * lex
char * query
uint32_t query_length
std::string db
drizzled::memory::Root warn_root
drizzled::plugin::Clientclient
drizzled::plugin::Schedulerscheduler
void * scheduler_arg
HASH user_vars
struct system_variables variables
struct system_status_var status_var
struct system_status_varinitial_status_var
THR_LOCK_INFO lock_info
THR_LOCK_OWNER main_lock_id
THR_LOCK_OWNER * lock_id
pthread_mutex_t LOCK_delete
char process_list_info [PROCESS_LIST_WIDTH+1]
char * thread_stack
Security_context security_ctx
const char * where
uint32_t dbug_sentry
struct st_my_thread_var * mysys_var
enum enum_server_command command
uint32_t file_id
uint32_t max_client_packet_length
time_t start_time
time_t user_time
uint64_t thr_create_utime
uint64_t start_utime
uint64_t utime_after_lock
thr_lock_type update_lock_default
void * replication_data
struct Session::st_transactions transaction
Fielddup_field
sigset_t signals
bool arg_of_last_insert_id_function
uint64_t first_successful_insert_id_in_prev_stmt
uint64_t first_successful_insert_id_in_cur_stmt
Discrete_intervals_list auto_inc_intervals_in_cur_stmt_for_binlog
Discrete_intervals_list auto_inc_intervals_forced
uint64_t limit_found_rows
uint64_t options
int64_t row_count_func
ha_rows cuted_fields
ha_rows sent_row_count
ha_rows examined_row_count
table_map used_tables
List< DRIZZLE_ERROR > warn_list
uint32_t warn_count [(uint32_t) DRIZZLE_ERROR::WARN_LEVEL_END]
uint32_t total_warn_count
Diagnostics_area main_da
query_id_t query_id
query_id_t warn_id
ulong col_access
uint32_t statement_id_counter
uint32_t rand_saved_seed1
uint32_t rand_saved_seed2
uint32_t row_count
pthread_t real_id
uint64_t thread_id
uint32_t tmp_table
uint32_t global_read_lock
uint32_t server_status
uint32_t open_options
uint32_t select_number
enum_tx_isolation session_tx_isolation
enum_check_fields count_cuted_fields
killed_state volatile killed
bool some_tables_deleted
bool no_errors
bool password
bool is_fatal_error
bool transaction_rollback_request
bool is_fatal_sub_stmt_error
bool substitute_null_with_insert_id
bool cleanup_done
bool abort_on_warning
bool got_warning
bool no_warnings_for_error
bool derived_tables_processing
bool tablespace_op
union {
   bool   bool_value
   uint32_t   uint32_t_value
   int32_t   int32_t_value
   uint64_t   uint64_t_value
sys_var_tmp
Lex_input_streamm_lip
void * session_marker
Tablecached_table
Tableopen_tables
Tabletemporary_tables
Tablederived_tables
DRIZZLE_LOCK * lock
DRIZZLE_LOCK * extra_lock
uint64_t version
uint32_t current_tablenr
bool backups_available

Static Public Attributes

static const char *const DEFAULT_WHERE = "field list"

Private Member Functions

void mark_used_tables_as_free_for_reuse (Table *table)
void mark_temp_tables_as_free_for_reuse ()
bool free_cached_table ()
void close_temporary (Table *table)

Private Attributes

Ha_data ha_data [MAX_HA]
drizzled::message::Transaction * transaction_message
drizzled::message::Statement * statement_message
uint64_t connect_microseconds
const char * proc_info
Internal_error_handlerm_internal_handler
LEX main_lex
drizzled::memory::Root main_mem_root


Detailed Description

Represents a client connection to the database server.

Contains the client/server protocol object, the current statement being executed, local-to-session variables and status counters, and a host of other information.

Todo:
The Session class should have a vector of Statement object pointers which comprise the statements executed on the Session. Until this architectural change is done, we can forget about parallel operations inside a session.

Todo:
Make member variables private and have inlined accessors and setters. Hide all member variables that are not critical to non-internal operations of the session object.

Definition at line 342 of file session.h.


Member Function Documentation

bool Session::authenticate ( void   ) 

Authenticates users, with error reporting.

Returns true on success, or false on failure.

Definition at line 668 of file session.cc.

References drizzled::plugin::Client::authenticate(), and client.

Referenced by run().

Here is the call graph for this function:

Here is the caller graph for this function:

bool Session::checkUser ( const char *  passwd,
uint32_t  passwd_len,
const char *  db 
)

Check if user exists and the password supplied is correct.

Returns true on success, and false on failure.

Note:
Host, user and passwd may point to communication buffer. Current implementation does not depend on that, but future changes should be done with this in mind;
Parameters:
Scrambled password received from client
Length of scrambled password
Database name to connect to, may be NULL

Definition at line 678 of file session.cc.

References Security_context::ip, my_ok(), security_ctx, Security_context::skip_grants(), and Security_context::user.

Here is the call graph for this function:

void Session::cleanup_after_query (  ) 

Cleans up after query.

This function is used to reset thread data to its default state.

This function is not suitable for setting thread data to some non-default values, as there is only one replication thread, so different master threads may overwrite data of each other on slave.

Definition at line 885 of file session.cc.

References auto_inc_intervals_in_cur_stmt_for_binlog, DEFAULT_WHERE, first_successful_insert_id_in_cur_stmt, first_successful_insert_id_in_prev_stmt, free_items(), substitute_null_with_insert_id, and where.

Referenced by mysql_parse().

Here is the call graph for this function:

Here is the caller graph for this function:

void Session::clear_error (  )  [inline]

Clear the current error, if any. We do not clear is_fatal_error or is_fatal_sub_stmt_error since we assume this is never called if the fatal error is set.

Todo:
: To silence an error, one should use Internal_error_handler mechanism. In future this function will be removed.

Definition at line 1044 of file session.h.

References Diagnostics_area::is_error(), and Diagnostics_area::reset_diagnostics_area().

Referenced by executeStatement(), drizzled::plugin::InfoSchemaMethods::fillTable(), mysql_checksum_table(), and reset_for_next_command().

Here is the call graph for this function:

Here is the caller graph for this function:

void Session::close_tables_for_reopen ( TableList **  tables  ) 

Prepares statement for reopening of tables and recalculation of set of prelocked tables.

Parameters:
Pointer to a pointer to a list of tables which we were trying to open and lock

Definition at line 2104 of file session.cc.

References close_thread_tables(), lex, and TableList::next_global.

Referenced by drizzled::plugin::InfoSchemaMethods::fillTable(), and openTablesLock().

Here is the call graph for this function:

Here is the caller graph for this function:

void Session::close_thread_tables (  ) 

Closes all tables used by the current substatement, or all tables used by this thread if we are on the upper level.

Definition at line 2029 of file session.cc.

References Diagnostics_area::can_overwrite_status, close_open_tables(), Table::free_tmp_table(), is_error(), mark_temp_tables_as_free_for_reuse(), Table::next, and Open_tables_state::open_tables.

Referenced by close_tables_for_reopen(), dispatch_command(), and mysql_checksum_table().

Here is the call graph for this function:

Here is the caller graph for this function:

void Session::disconnect ( uint32_t  errcode,
bool  lock 
)

Disconnects the session from a client connection and updates any status variables necessary.

Parameters:
errcode Error code to print to console
should_lock 1 if we have have to lock LOCK_thread_count
Note:
For the connection that is doing shutdown, this is called twice

Definition at line 1803 of file session.cc.

References client, drizzled::plugin::Client::close(), db, Security_context::ip, Diagnostics_area::is_error(), drizzled::plugin::Client::isConnected(), Diagnostics_area::message(), security_ctx, drizzled::plugin::Client::sendError(), Security_context::user, variables, and drizzled::plugin::Client::wasAborted().

Referenced by SingleThreadScheduler::addSession(), initGlobals(), and run().

Here is the call graph for this function:

Here is the caller graph for this function:

void Session::end_statement (  ) 

Cleanup statement parse state (parse tree, lex) and execution state after execution of a non-prepared SQL statement.

Todo:
Move this to Statement::~Statement

Definition at line 1644 of file session.cc.

References lex.

Referenced by mysql_parse().

Here is the caller graph for this function:

bool Session::endTransaction ( enum enum_mysql_completiontype  completion  ) 

Ends the current transaction and (maybe) begins the next.

Returns true if the transaction completed successfully, otherwise false.

Parameters:
Completion type

Definition at line 780 of file session.cc.

References options.

bool Session::executeStatement (  ) 

Executes a single statement received from the client connection.

Returns true if the statement was successful, or false otherwise.

Note:
For profiling to work, it must never be called recursively.

In MySQL, this used to be the do_command() C function whic accepted a single parameter of the THD pointer.

Definition at line 722 of file session.cc.

References clear_error(), client, command, dispatch_command(), lex, drizzled::plugin::Client::readCommand(), and Diagnostics_area::reset_diagnostics_area().

Referenced by run().

Here is the call graph for this function:

Here is the caller graph for this function:

void Session::fatal_error (  )  [inline]

Mark the current error as fatal. Warning: this does not set any error, it sets a property of the error, so must be followed or prefixed with my_error().

Definition at line 1056 of file session.h.

References Diagnostics_area::is_error(), and is_fatal_error.

Here is the call graph for this function:

void Session::force_one_auto_inc_interval ( uint64_t  next_id  )  [inline]

Used by Intvar_log_event::do_apply_event() and by "SET INSERT_ID=#" (mysqlbinlog). We'll soon add a variant which can take many intervals in argument.

Definition at line 869 of file session.h.

References auto_inc_intervals_forced.

void Session::free_items (  ) 

Frees all items attached to this Statement

Definition at line 282 of file session.cc.

References Item::delete_self(), free_list, and Item::next.

Referenced by cleanup_after_query().

Here is the call graph for this function:

Here is the caller graph for this function:

uint64_t Session::getConnectMicroseconds (  )  const [inline]

Returns the timestamp (in microseconds) of when the Session connected to the server.

Definition at line 1203 of file session.h.

References connect_microseconds.

uint64_t Session::getCurrentTimestamp (  )  [inline]

Returns the current micro-timestamp

Definition at line 1007 of file session.h.

drizzled::plugin::StorageEngine* Session::getDefaultStorageEngine (  )  [inline]

Return the default storage engine

Parameters:
getDefaultStorageEngine() 
Returns:
pointer to plugin::StorageEngine

Definition at line 1456 of file session.h.

References variables.

query_id_t Session::getQueryId (  )  const [inline]

Returns the current query ID

Definition at line 781 of file session.h.

Referenced by innobase_mysql_print_thd().

Here is the caller graph for this function:

size_t Session::getQueryLength (  )  const [inline]

Returns the length of the current query text

Definition at line 793 of file session.h.

References query.

const char* Session::getQueryString (  )  const [inline]

Returns the current query text

Definition at line 787 of file session.h.

References query.

Referenced by innobase_mysql_print_thd().

Here is the caller graph for this function:

uint32_t Session::getServerId (  )  const [inline]

Accessor method returning the server's ID.

Definition at line 808 of file session.h.

uint64_t Session::getSessionId (  )  const [inline]

Accessor method returning the session's ID.

Definition at line 802 of file session.h.

drizzled::message::Statement* Session::getStatementMessage (  )  const [inline]

Returns a pointer to the active Statement message for this Session, or NULL if no active message.

Definition at line 1222 of file session.h.

Referenced by drizzled::ReplicationServices::commitTransaction(), drizzled::ReplicationServices::getDeleteStatement(), drizzled::ReplicationServices::getInsertStatement(), and drizzled::ReplicationServices::getUpdateStatement().

Here is the caller graph for this function:

my_xid Session::getTransactionId (  )  [inline]

Returns the current transaction ID for the session's current statement

Definition at line 815 of file session.h.

drizzled::message::Transaction* Session::getTransactionMessage (  )  const [inline]

Returns a pointer to the active Transaction message for this Session being managed by the ReplicationServices component, or NULL if no active message.

Definition at line 1213 of file session.h.

References transaction_message.

Referenced by drizzled::ReplicationServices::getActiveTransaction().

Here is the caller graph for this function:

bool Session::handle_error ( uint32_t  sql_errno,
const char *  message,
DRIZZLE_ERROR::enum_warning_level  level 
) [virtual]

Handle an error condition.

Parameters:
sql_errno the error number
level the error level
Returns:
true if the error is handled

Definition at line 303 of file session.cc.

References Internal_error_handler::handle_error(), and m_internal_handler.

Here is the call graph for this function:

bool Session::initGlobals (  ) 

Pulls thread-specific variables into Session state.

Returns true most times, or false if there was a problem allocating resources for thread-specific storage.

Kill this. It's not necessary once my_thr_init() is bye bye.

Definition at line 573 of file session.cc.

References disconnect().

Referenced by run().

Here is the call graph for this function:

Here is the caller graph for this function:

bool Session::inTransaction (  )  [inline]

Returns whether the session is currently inside a transaction

Definition at line 1016 of file session.h.

bool Session::is_error (  )  const [inline]

true if there is an error in the error stack.

Please use this method instead of direct access to net.report_error.

If true, the current (sub)-statement should be aborted. The main difference between this member and is_fatal_error is that a fatal error can not be handled by a stored procedure continue handler, whereas a normal error can.

To raise this flag, use my_error().

Definition at line 1074 of file session.h.

References Diagnostics_area::is_error().

Referenced by drizzled::alter_table(), close_thread_tables(), dispatch_command(), drizzled::plugin::InfoSchemaMethods::fillTable(), find_all_keys(), handle_select(), mysql_execute_command(), mysql_parse(), mysql_select(), and parse_sql().

Here is the call graph for this function:

Here is the caller graph for this function:

LEX_STRING * Session::make_lex_string ( LEX_STRING *  lex_str,
const char *  str,
uint32_t  length,
bool  allocate_lex_string 
)

Create a LEX_STRING in this connection.

Parameters:
lex_str pointer to LEX_STRING object to be initialized
str initializer to be copied into lex_str
length length of str, in bytes
allocate_lex_string if true, allocate new LEX_STRING object, instead of using lex_str value
Returns:
NULL on failure, or pointer to the LEX_STRING object

Definition at line 919 of file session.cc.

References mem_root.

Referenced by drizzled::plugin::InfoSchemaMethods::fillTable(), and ha_innobase::get_foreign_key_list().

Here is the caller graph for this function:

void Session::mark_temp_tables_as_free_for_reuse (  )  [private]

Mark all temporary tables which were used by the current statement or substatement as free for reuse, but only if the query_id can be cleared.

Parameters:
session thread context
Remarks:
For temp tables associated with a open SQL HANDLER the query_id is not reset until the HANDLER is closed.

Definition at line 1996 of file session.cc.

References Table::cursor, Cursor::ha_reset(), Table::next, Table::query_id, and Open_tables_state::temporary_tables.

Referenced by close_thread_tables().

Here is the call graph for this function:

Here is the caller graph for this function:

void Session::mark_used_tables_as_free_for_reuse ( Table table  )  [private]

Marks all tables in the list which were used by current substatement as free for reuse.

Parameters:
Head of the list of tables
Note:
The reason we reset query_id is that it's not enough to just test if table->query_id != session->query_id to know if a table is in use.

For example

SELECT f1_that_uses_t1() FROM t1;

In f1_that_uses_t1() we will see one instance of t1 where query_id is set to query_id of original query.

Definition at line 2008 of file session.cc.

References Table::cursor, Cursor::ha_reset(), Table::next, and Table::query_id.

Here is the call graph for this function:

void Session::my_eof (  )  [inline]

A short cut for session->main_da.set_eof_status().

Definition at line 1317 of file session.h.

References Diagnostics_area::set_eof_status().

Referenced by dispatch_command(), and mysql_checksum_table().

Here is the call graph for this function:

Here is the caller graph for this function:

void Session::my_ok ( ha_rows  affected_rows = 0,
ha_rows  found_rows_arg = 0,
uint64_t  passed_id = 0,
const char *  message = NULL 
) [inline]

A short cut for session->main_da.set_ok_status().

Definition at line 1308 of file session.h.

References Diagnostics_area::set_ok_status().

Referenced by drizzled::alter_table(), checkUser(), dispatch_command(), and drizzled::mysql_rm_table().

Here is the call graph for this function:

Here is the caller graph for this function:

bool Session::openTables ( TableList tables,
uint32_t  flags = 0 
)

Open all tables in list and process derived tables

Parameters:
Pointer to a list of tables for open
Bitmap of flags to modify how the tables will be open: DRIZZLE_LOCK_IGNORE_FLUSH - open table even if someone has done a flush or namelock on it.
Return values:
false - ok
true - error
Note:
This is to be used on prepare stage when you don't read any data from the tables.

Definition at line 2142 of file session.cc.

References lex.

Referenced by drizzled::plugin::InfoSchemaMethods::fillTable().

Here is the caller graph for this function:

bool Session::openTablesLock ( TableList tables  ) 

Open all tables in list, locks them (all, including derived)

Parameters:
Pointer to a list of tables for open & locking
Return values:
false - ok
true - error
Note:
The lock will automaticaly be freed by close_thread_tables()

Definition at line 2118 of file session.cc.

References close_tables_for_reopen(), and lex.

Here is the call graph for this function:

void Session::pop_internal_handler (  ) 

Remove the error handler last pushed.

Definition at line 314 of file session.cc.

References m_internal_handler.

void Session::prepareForQueries (  ) 

Initialize memory roots necessary for query processing and (!) pre-allocate memory for it. We can't do that in Session constructor because there are use cases where it's vital to not allocate excessive and not used memory.

Definition at line 553 of file session.cc.

References command, mem_root, options, set_proc_info(), and variables.

Referenced by run().

Here is the call graph for this function:

Here is the caller graph for this function:

void Session::push_internal_handler ( Internal_error_handler handler  ) 

Add an internal error handler to the thread execution context.

Parameters:
handler the exception handler to add

Definition at line 293 of file session.cc.

References m_internal_handler.

bool Session::readAndStoreQuery ( const char *  in_packet,
uint32_t  in_packet_length 
)

Reads a query from packet and stores it.

Returns true if query is read and allocated successfully, false otherwise. On a return of false, Session::fatal_error is set.

Note:
Used in COM_QUERY and COM_STMT_PREPARE.
Sets the following Session variables:
  • query
  • query_length

Parameters:
The packet pointer to read from
The length of the query to read

Definition at line 752 of file session.cc.

References db, query, and query_length.

Referenced by dispatch_command().

Here is the caller graph for this function:

void Session::record_first_successful_insert_id_in_cur_stmt ( uint64_t  id_arg  )  [inline]

There is BUG#19630 where statement-based replication of stored functions/triggers with two auto_increment columns breaks. We however ensure that it works when there is 0 or 1 auto_increment column; our rules are a) on master, while executing a top statement involving substatements, first top- or sub- statement to generate auto_increment values wins the exclusive right to see its values be written to binlog (the write will be done by the statement or its caller), and the losers won't see their values be written to binlog. b) on slave, while replicating a top statement involving substatements, first top- or sub- statement to need to read auto_increment values from the master's binlog wins the exclusive right to read them (so the losers won't read their values from binlog but instead generate on their own). a) implies that we mustn't backup/restore auto_inc_intervals_in_cur_stmt_for_binlog. b) implies that we mustn't backup/restore auto_inc_intervals_forced.

If there are more than 1 auto_increment columns, then intervals for different columns may mix into the auto_inc_intervals_in_cur_stmt_for_binlog list, which is logically wrong, but there is no point in preventing this mixing by preventing intervals from the secondly inserted column to come into the list, as such prevention would be wrong too. What will happen in the case of INSERT INTO t1 (auto_inc) VALUES(NULL); where t1 has a trigger which inserts into an auto_inc column of t2, is that in binlog we'll store the interval of t1 and the interval of t2 (when we store intervals, soon), then in slave, t1 will use both intervals, t2 will use none; if t1 inserts the same number of rows as on master, normally the 2nd interval will not be used by t1, which is fine. t2's values will be wrong if t2's internal auto_increment counter is different from what it was on master (which is likely). In 5.1, in mixed binlogging mode, row-based binlogging is used for such cases where two auto_increment columns are inserted.

Definition at line 855 of file session.h.

References first_successful_insert_id_in_cur_stmt.

void Session::reset_for_next_command (  ) 

Resets Session part responsible for command processing state.

This needs to be called before execution of every statement (prepared or conventional). It is not called by substatements of routines.

Todo:
Make it a method of Session and align its name with the rest of reset/end/start/init methods.

Call it after we use Session for queries, not before.

Definition at line 1844 of file session.cc.

References auto_inc_intervals_in_cur_stmt_for_binlog, clear_error(), examined_row_count, free_list, is_fatal_error, options, Diagnostics_area::reset_diagnostics_area(), select_number, and sent_row_count.

Referenced by mysql_parse().

Here is the call graph for this function:

Here is the caller graph for this function:

void Session::run (  ) 

Run a session.

This will initialize the session and begin the command loop.

Definition at line 584 of file session.cc.

References authenticate(), client, disconnect(), executeStatement(), drizzled::plugin::Client::haveError(), initGlobals(), and prepareForQueries().

Referenced by SingleThreadScheduler::addSession().

Here is the call graph for this function:

Here is the caller graph for this function:

bool Session::schedule (  ) 

Schedule a session to be run on the default scheduler.

Definition at line 603 of file session.cc.

References drizzled::plugin::Scheduler::addSession(), client, scheduler, drizzled::plugin::Client::sendError(), and variables.

Here is the call graph for this function:

bool Session::set_db ( const NormalisedDatabaseName &  new_db  ) 

Set the current database; use deep copy of C-string.

Parameters:
new_db a pointer to the new database name.
new_db_len length of the new database name.
Initialize the current database from a NULL-terminated string with length. If we run out of memory, we free the current database and return true. This way the user will notice the error as there will be no current database selected (in addition to the error message set by malloc).

Note:
This operation just sets {db, db_length}. Switching the current database usually involves other actions, like switching other database attributes including security context. In the future, this operation will be made private and more convenient interface will be provided.
Returns:
Operation status
Return values:
false Success
true Out-of-memory error

Definition at line 1733 of file session.cc.

References db.

void Session::set_proc_info ( const char *  info  )  [inline]

Points to info-string that we show in SHOW PROCESSLIST You are supposed to call Session_SET_PROC_INFO only if you have coded a time-consuming piece that MySQL can get stuck in for a long time.

Set it using the session_proc_info(Session *thread, const char *message) macro/function.

Definition at line 771 of file session.h.

Referenced by drizzled::alter_table(), dispatch_command(), mysql_execute_command(), mysql_parse(), mysql_select(), and prepareForQueries().

Here is the caller graph for this function:

void Session::setStatementMessage ( drizzled::message::Statement *  in_message  )  [inline]

Sets the active statement message used by the ReplicationServices component.

Parameters:
[in] Pointer to the message

Definition at line 1244 of file session.h.

Referenced by drizzled::ReplicationServices::cleanupTransaction(), drizzled::ReplicationServices::getDeleteStatement(), drizzled::ReplicationServices::getInsertStatement(), and drizzled::ReplicationServices::getUpdateStatement().

Here is the caller graph for this function:

void Session::setTransactionMessage ( drizzled::message::Transaction *  in_message  )  [inline]

Sets the active transaction message used by the ReplicationServices component.

Parameters:
[in] Pointer to the message

Definition at line 1233 of file session.h.

References transaction_message.

Referenced by drizzled::ReplicationServices::cleanupTransaction(), and drizzled::ReplicationServices::getActiveTransaction().

Here is the caller graph for this function:


Member Data Documentation

Discrete_intervals_list Session::auto_inc_intervals_forced

Used by replication and SET INSERT_ID

Definition at line 615 of file session.h.

Referenced by force_one_auto_inc_interval().

We follow this logic:

  • when stmt starts, first_successful_insert_id_in_prev_stmt contains the first insert id successfully inserted by the previous stmt.
  • as stmt makes progress, handler::insert_id_for_cur_row changes; every time get_auto_increment() is called, auto_inc_intervals_in_cur_stmt_for_binlog is augmented with the reserved interval (if statement-based binlogging).
  • at first successful insertion of an autogenerated value, first_successful_insert_id_in_cur_stmt is set to handler::insert_id_for_cur_row.
  • when stmt goes to binlog, auto_inc_intervals_in_cur_stmt_for_binlog is binlogged if non-empty.
  • when stmt ends, first_successful_insert_id_in_prev_stmt is set to first_successful_insert_id_in_cur_stmt.

List of auto_increment intervals reserved by the thread so far, for storage in the statement-based binlog. Note that its minimum is not first_successful_insert_id_in_cur_stmt: assuming a table with an autoinc column, and this happens: INSERT INTO ... VALUES(3); SET INSERT_ID=3; INSERT IGNORE ... VALUES (NULL); then the latter INSERT will insert no rows (first_successful_insert_id_in_cur_stmt == 0), but storing "INSERT_ID=3" in the binlog is still needed; the list's minimum will contain 3.

Definition at line 613 of file session.h.

Referenced by cleanup_after_query(), and reset_for_next_command().

Keeps a copy of the previous table around in case we are just slamming on particular table

Definition at line 761 of file session.h.

enum enum_server_command Session::command

Type of current query: COM_STMT_PREPARE, COM_QUERY, etc. Set from first byte of the packet in executeStatement()

Definition at line 507 of file session.h.

Referenced by dispatch_command(), executeStatement(), ProcessListISMethods::fillTable(), and prepareForQueries().

uint64_t Session::connect_microseconds [private]

Microsecond timestamp of when Session connected

Definition at line 1253 of file session.h.

Referenced by getConnectMicroseconds().

Count of "cut" or truncated fields.

Todo:
Kill this friggin thing.

Definition at line 620 of file session.h.

Referenced by drizzled::alter_table(), and store_val_in_field().

std::string Session::db

Name of the current (default) database.

If there is the current (default) database, "db" contains its name. If there is no current (default) database, "db" is NULL and "db_length" is 0. In other words, "db", "db_length" must either be NULL, or contain a valid database name.

Note:
this attribute is set and alloced by the slave SQL thread (for the Session of that thread); that thread is (and must remain, for now) the only responsible for freeing this member.

Definition at line 440 of file session.h.

Referenced by disconnect(), dispatch_command(), ProcessListISMethods::fillTable(), mysql_parse(), drizzled::mysql_rm_table(), readAndStoreQuery(), and set_db().

watch for memory corruption

Definition at line 501 of file session.h.

const char *const Session::DEFAULT_WHERE = "field list" [static]

Constant for Session::where initialization in the beginning of every query.

It's needed because we do not save/restore Session::where normally during primary (non subselect) query execution.

Definition at line 448 of file session.h.

Referenced by cleanup_after_query().

set during loop of derived table processing

Definition at line 736 of file session.h.

Number of rows we read, sent or not, including in create_sort_index()

Definition at line 631 of file session.h.

Referenced by reset_for_next_command().

uint32_t Session::file_id

File ID for LOAD DATA INFILE

Definition at line 508 of file session.h.

This is the first autogenerated insert id which was *successfully* inserted by the current statement. It is maintained only to set first_successful_insert_id_in_prev_stmt when statement ends.

Definition at line 585 of file session.h.

Referenced by cleanup_after_query(), and record_first_successful_insert_id_in_cur_stmt().

This is the first autogenerated insert id which was *successfully* inserted by the previous statement (exactly, if the previous statement didn't successfully insert an autogenerated insert id, then it's the one of the statement before, etc). It can also be set by SET LAST_INSERT_ID=# or SELECT LAST_INSERT_ID(#). It is returned by LAST_INSERT_ID().

Definition at line 579 of file session.h.

Referenced by cleanup_after_query(), and remove_eq_conds().

List of items created in the parser for this query. Every item puts itself to the list on creation (see Item::Item() for details))

Definition at line 393 of file session.h.

Referenced by free_items(), Item::Item(), and reset_for_next_command().

Set on call to push_warning()

Definition at line 733 of file session.h.

uint32_t Session::id

Uniquely identifies each statement object in thread scope; change during statement lifetime.

Todo:
should be const

Definition at line 401 of file session.h.

Set to true if execution of the current compound statement can not continue. In particular, disables activation of CONTINUE or EXIT handlers of stored routines. Reset in the end of processing of the current user request, in

See also:
mysql_reset_session_for_next_command().

Definition at line 709 of file session.h.

Referenced by add_ref_to_table_cond(), change_refs_to_tmp_fields(), fatal_error(), OpenTablesISMethods::fillTable(), find_order_in_list(), parse_sql(), and reset_for_next_command().

true if we are in a sub-statement and the current error can not be safely recovered until we left the sub-statement mode. In particular, disables activation of CONTINUE and EXIT handlers inside sub-statements. E.g. if it is a deadlock error and requires a transaction-wide rollback, this flag is raised (traditionally, MySQL first has to close all the reads via

See also:
handler::ha_index_or_rnd_end() and only then perform the rollback). Reset to false when we leave the sub-statement mode.

Definition at line 727 of file session.h.

pthread_mutex_t Session::LOCK_delete

Locked before session is deleted

Definition at line 461 of file session.h.

Referenced by kill_one_thread().

THR_LOCK_OWNER* Session::lock_id

If not main_lock_id, points to the lock_id of a cursor.

Definition at line 460 of file session.h.

THR_LOCK_INFO Session::lock_info

Locking information for this session

Definition at line 458 of file session.h.

The current internal error handler for this thread, or NULL.

Definition at line 1257 of file session.h.

Referenced by handle_error(), pop_internal_handler(), and push_internal_handler().

Character input stream consumed by the lexical analyser, used during parsing. Note that since the parser is not re-entrant, we keep only one input stream here. This member is valid only when executing code during parsing, and may point to invalid memory after that.

Definition at line 755 of file session.h.

Referenced by check_simple_select(), and parse_sql().

LEX Session::main_lex [private]

The lex to hold the parsed tree of conventional (non-prepared) queries. Whereas for prepared and stored procedure statements we use an own lex instance for each new query, for conventional statements we reuse the same lex. (

See also:
mysql_parse for details).

Definition at line 1264 of file session.h.

THR_LOCK_OWNER Session::main_lock_id

To use for conventional queries

Definition at line 459 of file session.h.

drizzled::memory::Root Session::main_mem_root [private]

This memory root is used for two purposes:

  • for conventional queries, to allocate structures stored in main_lex during parsing, and allocate runtime data (execution plan, etc.) during execution.
  • for prepared queries, only to allocate runtime data. The parsed tree itself is reused between executions and thus is stored elsewhere.

Definition at line 1273 of file session.h.

Maximum number of bytes a client can send in a single packet

Definition at line 510 of file session.h.

drizzled::memory::Root* Session::mem_root

no warnings on call to my_error()

Definition at line 734 of file session.h.

Referenced by drizzled::plugin::InfoSchemaMethods::fillTable().

List of regular tables in use by this thread. Contains temporary and base tables that were opened with

See also:
open_tables().

Definition at line 38 of file open_tables_state.h.

Referenced by close_data_files_and_morph_locks(), close_old_data_files(), close_open_tables(), close_thread_tables(), free_cached_table(), lock_table_name_if_not_cached(), reopen_tables(), and unlink_open_table().

uint64_t Session::options

Bitmap of options

Definition at line 618 of file session.h.

Referenced by endTransaction(), handle_select(), prepareForQueries(), remove_eq_conds(), and reset_for_next_command().

char Session::process_list_info[PROCESS_LIST_WIDTH+1]

A peek into the query string for the session. This is a best effort delivery, there is no guarantee whether the content is meaningful.

Definition at line 467 of file session.h.

Referenced by dispatch_command(), ProcessListISMethods::fillTable(), and mysql_execute_command().

Points to the query associated with this statement. It's const, but we need to declare it char * because all table handlers are written in C and need to point to it.

Note that (A) if we set query = NULL, we must at the same time set query_length = 0, and protect the whole operation with the LOCK_thread_count mutex. And (B) we are ONLY allowed to set query to a non-NULL value if its previous value is NULL. We do not need to protect operation (B) with any mutex. To avoid crashes in races, if we do not know that session->query cannot change at the moment, one should print session->query like this: (1) reserve the LOCK_thread_count mutex; (2) check if session->query is NULL; (3) if not NULL, then print at most session->query_length characters from it. We will see the query_length field as either 0, or the right value for it. Assuming that the write and read of an n-bit memory field in an n-bit computer is atomic, we can avoid races in the above way. This printing is needed at least in SHOW PROCESSLIST and SHOW INNODB STATUS.

Definition at line 425 of file session.h.

Referenced by drizzled::alter_table(), dispatch_command(), getQueryLength(), getQueryString(), handle_select(), mysql_execute_command(), mysql_parse(), drizzled::mysql_prepare_alter_table(), parse_sql(), and readAndStoreQuery().

current query length

Definition at line 426 of file session.h.

Referenced by drizzled::alter_table(), dispatch_command(), mysql_execute_command(), mysql_parse(), and readAndStoreQuery().

pthread_t Session::real_id

For debugging

Definition at line 678 of file session.h.

Row counter, mainly for errors and warnings. Not increased in create_sort_index(); may differ from examined_row_count.

Definition at line 677 of file session.h.

Referenced by drizzled::alter_table().

For the ROW_COUNT() function

Definition at line 619 of file session.h.

Referenced by mysql_execute_command().

Pointer to scheduler object

Definition at line 452 of file session.h.

Referenced by schedule().

Pointer to the optional scheduler argument

Definition at line 453 of file session.h.

Referenced by PoolOfThreadsScheduler::addSession().

Note:
Some members of Session (currently 'Statementdb', 'query') are set and alloced by the slave SQL thread (for the Session of that thread); that thread is (and must remain, for now) the only responsible for freeing these 3 members. If you add members here, and you add code to set them in replication, don't forget to free_them_and_set_them_to_0 in replication properly. For details see the 'err:' label of the handle_slave_sql() in sql/slave.cc.
See also:
handle_slave_sql

Definition at line 487 of file session.h.

Referenced by checkUser(), disconnect(), ProcessListISMethods::fillTable(), and innobase_mysql_print_thd().

number of select (used for EXPLAIN)

Definition at line 684 of file session.h.

Referenced by reset_for_next_command().

Number of rows we actually sent to the client, including "synthetic" rows in ROLLUP etc.

Definition at line 626 of file session.h.

Referenced by reset_for_next_command().

Place to store various things

Definition at line 758 of file session.h.

Referenced by handle_select().

Session-local status counters

Definition at line 456 of file session.h.

Referenced by dispatch_command(), drizzled::statement::ShowStatus::execute(), filesort(), StatusISMethods::fillTable(), and mysql_execute_command().

for IS NULL => = last_insert_id() fix in remove_eq_conds()

Definition at line 729 of file session.h.

Referenced by cleanup_after_query(), and remove_eq_conds().

union { ... } Session::sys_var_tmp

Used by the sys_var class to store temporary values

This is true in DISCARD/IMPORT TABLESPACE

Definition at line 737 of file session.h.

List of temporary tables used by this thread. Contains user-level temporary tables, created with CREATE TEMPORARY TABLE, and internal temporary tables, created, e.g., to resolve a SELECT, or for an intermediate table used in ALTER. XXX Why are internal temporary tables added to this list?

Definition at line 46 of file open_tables_state.h.

Referenced by mark_temp_tables_as_free_for_reuse().

track down slow pthread_create

Definition at line 513 of file session.h.

A pointer to the stack frame of the scheduler thread which is called first in the thread for handling a client

Definition at line 473 of file session.h.

Referenced by SingleThreadScheduler::addSession().

drizzled::message::Transaction* Session::transaction_message [private]

Pointers to memory managed by the ReplicationServices component

Definition at line 1250 of file session.h.

Referenced by getTransactionMessage(), and setTransactionMessage().

Set by a storage engine to request the entire transaction (that possibly spans multiple engines) to rollback. Reset in ha_rollback.

Definition at line 715 of file session.h.

The set of those tables whose fields are referenced in all subqueries of the query.

Todo:
Possibly this it is incorrect to have used tables in Session because with more than one subquery, it is not clear what does the field mean.

Definition at line 642 of file session.h.

Referenced by mysql_select().

Hash of user variables defined during the session's lifetime

Definition at line 454 of file session.h.

struct system_variables Session::variables [read]

List<DRIZZLE_ERROR> Session::warn_list

Todo:
This, and some other variables like 'count_cuted_fields' maybe should be statement/cursor local, that is, moved to Statement class. With current implementation warnings produced in each prepared statement/cursor settle here.

Definition at line 652 of file session.h.

drizzled::memory::Root Session::warn_root

Allocation area for warnings and errors

Definition at line 450 of file session.h.

const char* Session::where

Used in error messages to tell user in what part of MySQL we found an error. E. g. when where= "having clause", if fix_fields() fails, user will know that the error was in having clause.

Definition at line 494 of file session.h.

Referenced by cleanup_after_query(), find_order_in_list(), handle_select(), setup_group(), and setup_order().


The documentation for this class was generated from the following files:

Generated on Tue Jan 5 10:50:45 2010 for drizzle by  doxygen 1.5.8