Drizzled Public API Documentation

row0sel.h File Reference
#include "univ.i"
#include "data0data.h"
#include "que0types.h"
#include "dict0types.h"
#include "trx0types.h"
#include "row0types.h"
#include "pars0sym.h"
#include "btr0pcur.h"
#include "read0read.h"
#include "row0mysql.h"

Go to the source code of this file.

Classes

struct  sel_buf_struct
 
struct  plan_struct
 
struct  sel_node_struct
 
struct  fetch_node_struct
 
struct  open_node_struct
 
struct  row_printf_node_struct
 

Enumerations

enum  sel_node_state { SEL_NODE_CLOSED, SEL_NODE_OPEN, SEL_NODE_FETCH, SEL_NODE_NO_MORE_ROWS }
 
enum  open_node_op { ROW_SEL_OPEN_CURSOR, ROW_SEL_CLOSE_CURSOR }
 
enum  row_sel_direction { ROW_SEL_NEXT = 1, ROW_SEL_PREV = 2 }
 
enum  row_sel_match_mode { ROW_SEL_EXACT = 1, ROW_SEL_EXACT_PREFIX }
 

Functions

UNIV_INTERN sel_node_tsel_node_create (mem_heap_t *heap)
 
UNIV_INTERN void sel_node_free_private (sel_node_t *node)
 
UNIV_INTERN void sel_col_prefetch_buf_free (sel_buf_t *prefetch_buf)
 
UNIV_INLINE plan_tsel_node_get_nth_plan (sel_node_t *node, ulint i)
 
UNIV_INTERN que_thr_trow_sel_step (que_thr_t *thr)
 
UNIV_INLINE que_thr_topen_step (que_thr_t *thr)
 
UNIV_INTERN que_thr_tfetch_step (que_thr_t *thr)
 
UNIV_INTERN void * row_fetch_print (void *row, void *user_arg)
 
UNIV_INTERN que_thr_trow_printf_step (que_thr_t *thr)
 
UNIV_INTERN void row_sel_convert_mysql_key_to_innobase (dtuple_t *tuple, byte *buf, ulint buf_len, dict_index_t *index, const byte *key_ptr, ulint key_len, trx_t *trx)
 
UNIV_INTERN ulint row_search_for_mysql (byte *buf, ulint mode, row_prebuilt_t *prebuilt, ulint match_mode, ulint direction)
 
UNIV_INTERN ibool row_search_check_if_query_cache_permitted (trx_t *trx, const char *norm_name)
 
UNIV_INTERN ulint row_search_max_autoinc (dict_index_t *index, const char *col_name, ib_uint64_t *value)
 

Detailed Description

Select

Created 12/19/1997 Heikki Tuuri

Definition in file row0sel.h.

Enumeration Type Documentation

Open or close cursor operation type

Enumerator
ROW_SEL_OPEN_CURSOR 

open cursor

ROW_SEL_CLOSE_CURSOR 

close cursor

Definition at line 363 of file row0sel.h.

Search direction for the MySQL interface

Enumerator
ROW_SEL_NEXT 

ascending direction

ROW_SEL_PREV 

descending direction

Definition at line 384 of file row0sel.h.

Match mode for the MySQL interface

Enumerator
ROW_SEL_EXACT 

search using a complete key value

ROW_SEL_EXACT_PREFIX 

search using a key prefix which must match rows: the prefix may contain an incomplete field (the last field in prefix may be just a prefix of a fixed length column)

Definition at line 390 of file row0sel.h.

Select node states

Enumerator
SEL_NODE_CLOSED 

it is a declared cursor which is not currently open

SEL_NODE_OPEN 

intention locks not yet set on tables

SEL_NODE_FETCH 

intention locks have been set

SEL_NODE_NO_MORE_ROWS 

cursor has reached the result set end

Definition at line 280 of file row0sel.h.

Function Documentation

UNIV_INTERN que_thr_t* fetch_step ( que_thr_t thr)

Performs a fetch for a cursor.

Returns
query thread to run next or NULL in: query thread

Performs a fetch for a cursor.

Returns
query thread to run next or NULL
Parameters
thrin: query thread

Definition at line 2118 of file row0sel.cc.

References pars_user_func_struct::arg, sel_node_struct::common, fetch_node_struct::cursor_def, trx_struct::error_state, fetch_step(), fetch_node_struct::func, pars_user_func_struct::func, fetch_node_struct::into_list, que_common_struct::parent, que_thr_struct::prev_node, que_node_get_parent(), que_node_get_type(), que_thr_struct::run_node, SEL_NODE_CLOSED, SEL_NODE_NO_MORE_ROWS, sel_node_struct::state, thr_get_trx(), and ut_ad.

Referenced by fetch_step().

UNIV_INLINE que_thr_t* open_step ( que_thr_t thr)

Performs an execution step of an open or close cursor statement node.

Returns
query thread to run next or NULL in: query thread
UNIV_INTERN void* row_fetch_print ( void *  row,
void *  user_arg 
)

Sample callback function for fetch that prints each row.

Returns
always returns non-NULL in: not used

Sample callback function for fetch that prints each row.

Returns
always returns non-NULL
Parameters
rowin: sel_node_t*
user_argin: not used

Definition at line 2181 of file row0sel.cc.

References dfield_get_len(), que_node_get_next(), que_node_get_val(), row_fetch_print(), sel_node_struct::select_list, UT_NOT_USED, and ut_print_buf().

Referenced by row_fetch_print().

UNIV_INTERN que_thr_t* row_printf_step ( que_thr_t thr)

Prints a row in a select result.

Returns
query thread to run next or NULL in: query thread

Prints a row in a select result.

Returns
query thread to run next or NULL
Parameters
thrin: query thread

Definition at line 2225 of file row0sel.cc.

References que_thr_struct::prev_node, que_node_get_next(), que_node_get_parent(), que_node_get_type(), que_node_get_val(), row_printf_step(), que_thr_struct::run_node, row_printf_node_struct::sel_node, SEL_NODE_FETCH, SEL_NODE_NO_MORE_ROWS, SEL_NODE_OPEN, sel_node_struct::select_list, sel_node_struct::state, and ut_ad.

Referenced by row_printf_step().

UNIV_INTERN ibool row_search_check_if_query_cache_permitted ( trx_t trx,
const char *  norm_name 
)

Checks if MySQL at the moment is allowed for this table to retrieve a consistent read result, or store it to the query cache.

Returns
TRUE if storing or retrieving from the query cache is permitted in: concatenation of database name, '/' char, table name

Checks if MySQL at the moment is allowed for this table to retrieve a consistent read result, or store it to the query cache.

Returns
TRUE if storing or retrieving from the query cache is permitted
Parameters
trxin: transaction object
norm_namein: concatenation of database name, '/' char, table name

Definition at line 4708 of file row0sel.cc.

References trx_struct::id, dict_table_struct::locks, dict_table_struct::query_cache_inv_trx_id, trx_struct::read_view, read_view_open_now(), row_search_check_if_query_cache_permitted(), trx_start_if_not_started_low(), and UT_LIST_GET_LEN.

Referenced by row_search_check_if_query_cache_permitted().

UNIV_INTERN ulint row_search_for_mysql ( byte *  buf,
ulint  mode,
row_prebuilt_t prebuilt,
ulint  match_mode,
ulint  direction 
)

Searches for rows in the database. This is used in the interface to MySQL. This function opens a cursor, and also implements fetch next and fetch prev. NOTE that if we do a search with a full key value from a unique index (ROW_SEL_EXACT), then we will not store the cursor position and fetch next or fetch prev must not be tried to the cursor!

Returns
DB_SUCCESS, DB_RECORD_NOT_FOUND, DB_END_OF_INDEX, DB_DEADLOCK, DB_LOCK_TABLE_FULL, or DB_TOO_BIG_RECORD in: 0 or ROW_SEL_NEXT or ROW_SEL_PREV; NOTE: if this is != 0, then prebuilt must have a pcur with stored position! In opening of a cursor 'direction' should be 0.

Searches for rows in the database. This is used in the interface to MySQL. This function opens a cursor, and also implements fetch next and fetch prev. NOTE that if we do a search with a full key value from a unique index (ROW_SEL_EXACT), then we will not store the cursor position and fetch next or fetch prev must not be tried to the cursor!

Returns
DB_SUCCESS, DB_RECORD_NOT_FOUND, DB_END_OF_INDEX, DB_DEADLOCK, DB_LOCK_TABLE_FULL, DB_CORRUPTION, or DB_TOO_BIG_RECORD
Parameters
bufin/out: buffer for the fetched row in the MySQL format
modein: search mode PAGE_CUR_L, ...
prebuiltin: prebuilt struct for the table handle; this contains the info of search_tuple, index; if search tuple contains 0 fields then we position the cursor at the start or the end of the index, depending on 'mode'
match_modein: 0 or ROW_SEL_EXACT or ROW_SEL_EXACT_PREFIX
directionin: 0 or ROW_SEL_NEXT or ROW_SEL_PREV; NOTE: if this is != 0, then prebuilt must have a pcur with stored position! In opening of a cursor 'direction' should be 0.

Definition at line 3346 of file row0sel.cc.

References btr_cur_get_block(), btr_pcur_move_to_last_on_page(), btr_pcur_move_to_next(), btr_pcur_open_at_index_side(), BTR_SEA_TIMEOUT, btr_search_latch, BTR_SEARCH_LEAF, row_prebuilt_struct::clust_index_was_generated, cmp_dtuple_is_prefix_of_rec(), cmp_dtuple_rec(), trx_struct::conc_state, DB_SUCCESS_LOCKED_REC, dict_index_get_n_unique(), dict_index_is_clust(), dict_index_is_unique(), dict_table_is_comp(), dtuple_contains_null(), dtuple_get_n_fields(), dtuple_get_n_fields_cmp(), trx_struct::error_state, row_prebuilt_struct::fetch_cache_first, row_prebuilt_struct::fetch_direction, dict_table_struct::ibd_file_missing, row_prebuilt_struct::index, row_prebuilt_struct::index_usable, lock_cancel_waiting_and_release(), lock_clust_rec_cons_read_sees(), LOCK_GAP, LOCK_ORDINARY, LOCK_REC_NOT_GAP, lock_sec_rec_cons_read_sees(), que_thr_struct::lock_state, lock_table(), mach_write_to_4(), row_prebuilt_struct::magic_n, mem_analyze_corruption(), mem_heap_free, mtr_commit(), mtr_start(), row_prebuilt_struct::mysql_row_len, trx_struct::mysql_thd, row_prebuilt_struct::n_fetch_cached, row_prebuilt_struct::n_rows_fetched, dict_table_struct::name, row_prebuilt_struct::need_to_access_clustered, row_prebuilt_struct::new_rec_locks, trx_struct::op_info, os_thread_get_curr_id(), page_align(), page_get_page_no(), page_offset(), page_rec_get_next_const(), page_rec_is_comp(), page_rec_is_infimum(), page_rec_is_supremum(), row_prebuilt_struct::pcur, que_fork_get_first_thr(), que_thr_move_to_run_state_for_mysql(), que_thr_stop_for_mysql(), que_thr_stop_for_mysql_no_error(), trx_struct::read_view, rec_get_deleted_flag(), rec_get_next_offs(), rec_offs_extra_size(), rec_offs_size(), rec_offs_validate(), rec_validate(), row_mysql_handle_errors(), row_prebuild_sel_graph(), row_prebuilt_struct::row_read_type, row_search_for_mysql(), ROW_SEL_EXACT, ROW_SEL_EXACT_PREFIX, ROW_SEL_NEXT, row_unlock_for_mysql(), rw_lock_get_writer(), rw_lock_s_lock, btr_pcur_struct::search_mode, row_prebuilt_struct::search_tuple, row_prebuilt_struct::sel_graph, row_prebuilt_struct::select_lock_type, row_prebuilt_struct::sql_stat_start, srv_locks_unsafe_for_binlog, dict_index_struct::table, row_prebuilt_struct::table, row_prebuilt_struct::templ_contains_blob, row_prebuilt_struct::template_type, thd_is_select(), row_prebuilt_struct::trx, trx_assign_read_view(), btr_pcur_struct::trx_if_known, trx_print(), trx_start_if_not_started(), ut_a, ut_ad, ut_error, ut_print_name(), ut_print_timestamp(), and trx_struct::wait_lock.

Referenced by ha_innobase::general_fetch(), ha_innobase::index_read(), row_check_index_for_mysql(), and row_search_for_mysql().

UNIV_INTERN ulint row_search_max_autoinc ( dict_index_t index,
const char *  col_name,
ib_uint64_t *  value 
)

Read the max AUTOINC value from an index.

Returns
DB_SUCCESS if all OK else error code out: AUTOINC value read

Read the max AUTOINC value from an index.

Returns
DB_SUCCESS if all OK else error code, DB_RECORD_NOT_FOUND if column name can't be found in index
Parameters
indexin: index to search
col_namein: name of autoinc column
valueout: AUTOINC value read

Definition at line 4844 of file row0sel.cc.

References btr_pcur_close(), btr_pcur_open_at_index_side(), BTR_SEARCH_LEAF, dict_field_struct::col, dict_index_get_n_ordering_defined_by_user(), mtr_commit(), mtr_start(), dict_col_struct::mtype, dict_field_struct::name, page_get_n_recs(), dict_col_struct::prtype, and row_search_max_autoinc().

Referenced by ha_innobase::innobase_initialize_autoinc(), and row_search_max_autoinc().

UNIV_INTERN void row_sel_convert_mysql_key_to_innobase ( dtuple_t tuple,
byte *  buf,
ulint  buf_len,
dict_index_t index,
const byte *  key_ptr,
ulint  key_len,
trx_t trx 
)

Converts a key value stored in MySQL format to an Innobase dtuple. The last field of the key value may be just a prefix of a fixed length field: hence the parameter key_len. But currently we do not allow search keys where the last field is only a prefix of the full key field len and print a warning if such appears. in: transaction

Converts a key value stored in MySQL format to an Innobase dtuple. The last field of the key value may be just a prefix of a fixed length field: hence the parameter key_len. But currently we do not allow search keys where the last field is only a prefix of the full key field len and print a warning if such appears. A counterpart of this function is ha_innobase::store_key_val_for_row() in ha_innodb.cc.

Parameters
tuplein/out: tuple where to build; NOTE: we assume that the type info in the tuple is already according to index!
bufin: buffer to use in field conversions
buf_lenin: buffer length
indexin: index of the key value
key_ptrin: MySQL key value
key_lenin: MySQL key value length
trxin: transaction

Definition at line 2292 of file row0sel.cc.

References dict_field_struct::col, dfield_get_len(), dfield_set_data(), dfield_set_len(), dfield_set_null(), dict_table_is_comp(), dtype_get_mysql_type(), dict_col_struct::mtype, dict_field_struct::prefix_len, row_mysql_store_col_in_innobase_format(), row_sel_convert_mysql_key_to_innobase(), dict_index_struct::table, ut_a, ut_print_buf(), and ut_print_timestamp().

Referenced by ha_innobase::index_read(), ha_innobase::records_in_range(), and row_sel_convert_mysql_key_to_innobase().

UNIV_INTERN void sel_col_prefetch_buf_free ( sel_buf_t prefetch_buf)

Frees a prefetch buffer for a column, including the dynamically allocated memory for data stored there. in, own: prefetch buffer

Frees a prefetch buffer for a column, including the dynamically allocated memory for data stored there.

Parameters
prefetch_bufin, own: prefetch buffer

Definition at line 505 of file row0sel.cc.

References sel_buf_struct::data, mem_free, sel_col_prefetch_buf_free(), and sel_buf_struct::val_buf_size.

Referenced by sel_col_prefetch_buf_free(), and sym_tab_free_private().

UNIV_INTERN sel_node_t* sel_node_create ( mem_heap_t heap)

Creates a select node struct.

Returns
own: select node struct in: memory heap where created

Creates a select node struct.

Returns
own: select node struct
Parameters
heapin: memory heap where created

Definition at line 255 of file row0sel.cc.

References sel_node_struct::common, mem_heap_alloc(), sel_node_struct::plans, sel_node_create(), SEL_NODE_OPEN, sel_node_struct::state, and que_common_struct::type.

Referenced by pars_select_list(), row_merge_lock_table(), row_prebuild_sel_graph(), and sel_node_create().

UNIV_INTERN void sel_node_free_private ( sel_node_t node)

Frees the memory private to a select node when a query graph is freed, does not free the heap where the node was originally created. in: select node struct

Frees the memory private to a select node when a query graph is freed, does not free the heap where the node was originally created.

Parameters
nodein: select node struct

Definition at line 275 of file row0sel.cc.

References btr_pcur_close(), plan_struct::clust_pcur, mem_heap_free, sel_node_struct::n_tables, plan_struct::old_vers_heap, plan_struct::pcur, sel_node_struct::plans, sel_node_free_private(), and sel_node_get_nth_plan().

Referenced by que_graph_free_recursive(), and sel_node_free_private().

UNIV_INLINE plan_t* sel_node_get_nth_plan ( sel_node_t node,
ulint  i 
)

Gets the plan node for the nth table in a join.

Returns
plan node in: get ith plan node
Parameters
nodein: select node

Referenced by opt_print_query_plan(), pars_update_statement(), row_sel_step(), and sel_node_free_private().