Commit 4f56acb6 authored by Sergey Petrunya's avatar Sergey Petrunya

Better comments, move Lifo_buffer to separate file.

parent 3066c377
...@@ -63,6 +63,7 @@ SET (SQL_SOURCE ...@@ -63,6 +63,7 @@ SET (SQL_SOURCE
sql_cache.cc sql_class.cc sql_client.cc sql_crypt.cc sql_crypt.h sql_cache.cc sql_class.cc sql_client.cc sql_crypt.cc sql_crypt.h
sql_cursor.cc sql_db.cc sql_delete.cc sql_derived.cc sql_do.cc sql_cursor.cc sql_db.cc sql_delete.cc sql_derived.cc sql_do.cc
sql_error.cc sql_handler.cc sql_help.cc sql_insert.cc sql_error.cc sql_handler.cc sql_help.cc sql_insert.cc
sql_lifo_buffer.h
sql_join_cache.cc sql_lex.cc sql_list.cc sql_load.cc sql_manager.cc sql_join_cache.cc sql_lex.cc sql_list.cc sql_load.cc sql_manager.cc
sql_map.cc sql_parse.cc sql_partition.cc sql_plugin.cc sql_map.cc sql_parse.cc sql_partition.cc sql_plugin.cc
sql_prepare.cc sql_rename.cc sql_prepare.cc sql_rename.cc
......
...@@ -66,6 +66,7 @@ noinst_HEADERS = item.h item_func.h item_sum.h item_cmpfunc.h \ ...@@ -66,6 +66,7 @@ noinst_HEADERS = item.h item_func.h item_sum.h item_cmpfunc.h \
log.h log_slow.h sql_show.h rpl_rli.h rpl_mi.h \ log.h log_slow.h sql_show.h rpl_rli.h rpl_mi.h \
sql_select.h structs.h table.h sql_udf.h hash_filo.h \ sql_select.h structs.h table.h sql_udf.h hash_filo.h \
lex.h lex_symbol.h sql_acl.h sql_crypt.h \ lex.h lex_symbol.h sql_acl.h sql_crypt.h \
sql_lifo_buffer.h \
sql_repl.h slave.h rpl_filter.h rpl_injector.h \ sql_repl.h slave.h rpl_filter.h rpl_injector.h \
log_event.h rpl_record.h \ log_event.h rpl_record.h \
log_event_old.h rpl_record_old.h \ log_event_old.h rpl_record_old.h \
......
...@@ -1326,6 +1326,10 @@ void get_sweep_read_cost(TABLE *table, ha_rows nrows, bool interrupted, ...@@ -1326,6 +1326,10 @@ void get_sweep_read_cost(TABLE *table, ha_rows nrows, bool interrupted,
The MRR user has materialized range keys somewhere in the user's buffer. The MRR user has materialized range keys somewhere in the user's buffer.
This can be used for optimization of the procedure that sorts these keys This can be used for optimization of the procedure that sorts these keys
since in this case key values don't have to be copied into the MRR buffer. since in this case key values don't have to be copied into the MRR buffer.
In other words, it is guaranteed that after RANGE_SEQ_IF::next() call the
pointer in range->start_key.key will point to a key value that will remain
there until the end of the MRR scan.
*/ */
#define HA_MRR_MATERIALIZED_KEYS 256 #define HA_MRR_MATERIALIZED_KEYS 256
......
...@@ -332,7 +332,7 @@ int DsMrr_impl::dsmrr_init(handler *h_arg, RANGE_SEQ_IF *seq_funcs, ...@@ -332,7 +332,7 @@ int DsMrr_impl::dsmrr_init(handler *h_arg, RANGE_SEQ_IF *seq_funcs,
is_mrr_assoc= !test(mode & HA_MRR_NO_ASSOCIATION); is_mrr_assoc= !test(mode & HA_MRR_NO_ASSOCIATION);
/* /*
Figure out what steps we'll need to do Determine whether we'll need to do key sorting and/or rnd_pos() scan
*/ */
do_sort_keys= FALSE; do_sort_keys= FALSE;
if ((mode & HA_MRR_SINGLE_POINT) && if ((mode & HA_MRR_SINGLE_POINT) &&
...@@ -362,8 +362,9 @@ int DsMrr_impl::dsmrr_init(handler *h_arg, RANGE_SEQ_IF *seq_funcs, ...@@ -362,8 +362,9 @@ int DsMrr_impl::dsmrr_init(handler *h_arg, RANGE_SEQ_IF *seq_funcs,
status_var_increment(table->in_use->status_var.ha_multi_range_read_init_count); status_var_increment(table->in_use->status_var.ha_multi_range_read_init_count);
/* /*
At start, alloc all of the buffer for rowids. Key sorting code will grab a At start, alloc all of the buffer for rowids. When/if key sorting code
piece if necessary. figures how much buffer space it needs, it will call setup_buffer_sizes()
to re-distribute the buffer space.
*/ */
full_buf= buf->buffer; full_buf= buf->buffer;
full_buf_end= buf->buffer_end; full_buf_end= buf->buffer_end;
...@@ -530,22 +531,19 @@ static int rowid_cmp_reverse(void *h, uchar *a, uchar *b) ...@@ -530,22 +531,19 @@ static int rowid_cmp_reverse(void *h, uchar *a, uchar *b)
/** /**
DS-MRR: Fill and sort the rowid buffer DS-MRR: Fill and sort the rowid buffer
{This is an internal function of DiskSweep MRR implementation}
Scan the MRR ranges and collect ROWIDs (or {ROWID, range_id} pairs) into Scan the MRR ranges and collect ROWIDs (or {ROWID, range_id} pairs) into
buffer. When the buffer is full or scan is completed, sort the buffer by buffer. When the buffer is full or scan is completed, sort the buffer by
rowid and return. rowid and return.
When this function returns, either rowid buffer is not empty, or the source
of lookup keys (i.e. ranges) is exhaused.
dsmrr_eof is set to indicate whether we've exhausted the list of ranges we're dsmrr_eof is set to indicate whether we've exhausted the list of ranges we're
scanning. This function never returns HA_ERR_END_OF_FILE. scanning. This function never returns HA_ERR_END_OF_FILE.
post-condition:
rowid buffer is not empty, or key source is exhausted.
@retval 0 OK, the next portion of rowids is in the buffer, @retval 0 OK, the next portion of rowids is in the buffer,
properly ordered properly ordered
@retval other Error @retval other Error
*/ */
int DsMrr_impl::dsmrr_fill_rowid_buffer() int DsMrr_impl::dsmrr_fill_rowid_buffer()
...@@ -556,15 +554,13 @@ int DsMrr_impl::dsmrr_fill_rowid_buffer() ...@@ -556,15 +554,13 @@ int DsMrr_impl::dsmrr_fill_rowid_buffer()
DBUG_ENTER("DsMrr_impl::dsmrr_fill_rowid_buffer"); DBUG_ENTER("DsMrr_impl::dsmrr_fill_rowid_buffer");
DBUG_ASSERT(rowid_buffer.is_empty()); DBUG_ASSERT(rowid_buffer.is_empty());
rowid_buffer.reset_for_writing(); rowid_buffer.reset();
rowid_buffer.setup_writing(&h2->ref, h2->ref_length, rowid_buffer.setup_writing(&h2->ref, h2->ref_length,
is_mrr_assoc? (uchar**)&range_info_ptr: NULL, sizeof(void*)); is_mrr_assoc? (uchar**)&range_info_ptr: NULL,
sizeof(void*));
last_identical_rowid= NULL; last_identical_rowid= NULL;
//if (do_sort_keys && key_buffer.is_reverse())
// key_buffer.flip();
while (rowid_buffer.can_write()) while (rowid_buffer.can_write())
{ {
if (do_sort_keys) if (do_sort_keys)
...@@ -652,18 +648,21 @@ equals: ...@@ -652,18 +648,21 @@ equals:
return 0; return 0;
} }
int DsMrr_impl::key_tuple_cmp_reverse(void* arg, uchar* key1, uchar* key2) int DsMrr_impl::key_tuple_cmp_reverse(void* arg, uchar* key1, uchar* key2)
{ {
return -key_tuple_cmp(arg, key1, key2); return -key_tuple_cmp(arg, key1, key2);
} }
/*
Setup key/rowid buffer sizes based on sample_key
DESCRIPTION
Setup key/rowid buffer sizes based on sample_key and its length.
This function must be called when all buffer space is empty. /**
Setup key/rowid buffer sizes based on sample_key and its length.
@param
sample_key A lookup key to use as a sample. It is assumed that
all other keys will have the same length/etc.
@note
This function must be called when all buffers are empty
*/ */
void DsMrr_impl::setup_buffer_sizes(key_range *sample_key) void DsMrr_impl::setup_buffer_sizes(key_range *sample_key)
...@@ -737,22 +736,19 @@ void DsMrr_impl::setup_buffer_sizes(key_range *sample_key) ...@@ -737,22 +736,19 @@ void DsMrr_impl::setup_buffer_sizes(key_range *sample_key)
} }
/* /**
DS-MRR/CPK: Fill the buffer with (lookup_tuple, range_id) pairs and sort DS-MRR/CPK: Fill the buffer with (lookup_tuple, range_id) pairs and sort
SYNOPSIS Enumerate the input range (=key) sequence, fill the key buffer with
DsMrr_impl::dsmrr_fill_key_buffer() (lookup_key, range_id) pairs and sort it.
DESCRIPTION
DS-MRR/CPK: Enumerate the input range (=key) sequence, fill the key buffer
(lookup_key, range_id) pairs and sort.
When this function returns, either
- key buffer is non-empty, or
- key buffer is empty and source range sequence is exhausted
@note
dsmrr_eof is set to indicate whether we've exhausted the list of ranges dsmrr_eof is set to indicate whether we've exhausted the list of ranges
we're scanning. we're scanning.
post-condition:
- key buffer is non-empty
- key buffer is empty and source range sequence is exhausted
*/ */
void DsMrr_impl::dsmrr_fill_key_buffer() void DsMrr_impl::dsmrr_fill_key_buffer()
...@@ -778,7 +774,7 @@ void DsMrr_impl::dsmrr_fill_key_buffer() ...@@ -778,7 +774,7 @@ void DsMrr_impl::dsmrr_fill_key_buffer()
identical_key_it= &backward_key_it; identical_key_it= &backward_key_it;
key_buffer->set_buffer_space(rowid_buffer_end, full_buf_end); key_buffer->set_buffer_space(rowid_buffer_end, full_buf_end);
} }
key_buffer->reset_for_writing(); key_buffer->reset();
key_buffer->setup_writing(&key_ptr, key_size_in_keybuf, key_buffer->setup_writing(&key_ptr, key_size_in_keybuf,
is_mrr_assoc? (uchar**)&range_info_ptr : NULL, is_mrr_assoc? (uchar**)&range_info_ptr : NULL,
sizeof(uchar*)); sizeof(uchar*));
...@@ -825,8 +821,8 @@ void DsMrr_impl::dsmrr_fill_key_buffer() ...@@ -825,8 +821,8 @@ void DsMrr_impl::dsmrr_fill_key_buffer()
} }
/* /**
Take unused space from key buffer and give it to rowid buffer. Take unused space from the key buffer and give it to the rowid buffer
*/ */
void DsMrr_impl::reallocate_buffer_space() void DsMrr_impl::reallocate_buffer_space()
...@@ -837,30 +833,25 @@ void DsMrr_impl::reallocate_buffer_space() ...@@ -837,30 +833,25 @@ void DsMrr_impl::reallocate_buffer_space()
} }
/* /**
DS-MRR/CPK: multi_range_read_next() function DS-MRR/CPK: multi_range_read_next() function
DESCRIPTION
DsMrr_impl::dsmrr_next_from_index()
range_info OUT identifier of range that the returned record belongs to
DESCRIPTION
This function walks over key buffer and does index reads, i.e. it produces @param range_info OUT identifier of range that the returned record belongs to
{current_record, range_id} pairs.
@note
This function walks over key buffer and does index reads, i.e. it produces
{current_record, range_id} pairs.
The function has the same call contract like multi_range_read_next()'s. The function has the same call contract like multi_range_read_next()'s.
We actually iterate nested sequences: We actually iterate over nested sequences:
- a disjoint sequence of index ranges
- a disjoint sequence of index ranges - each range has multiple records
- each range has multiple records - each record goes into multiple identical ranges.
- each record goes into multiple identical ranges.
@retval 0 OK, next record was successfully read
RETURN @retval HA_ERR_END_OF_FILE End of records
0 OK, next record was successfully read @retval Other Some other error
HA_ERR_END_OF_FILE End of records
Other Some other error
*/ */
int DsMrr_impl::dsmrr_next_from_index(char **range_info_arg) int DsMrr_impl::dsmrr_next_from_index(char **range_info_arg)
...@@ -1007,7 +998,9 @@ end: ...@@ -1007,7 +998,9 @@ end:
/** /**
DS-MRR implementation: multi_range_read_next() function DS-MRR implementation: multi_range_read_next() function.
Calling convention is like multi_range_read_next() has.
*/ */
int DsMrr_impl::dsmrr_next(char **range_info) int DsMrr_impl::dsmrr_next(char **range_info)
...@@ -1237,17 +1230,12 @@ bool key_uses_partial_cols(TABLE *table, uint keyno) ...@@ -1237,17 +1230,12 @@ bool key_uses_partial_cols(TABLE *table, uint keyno)
/* /*
Check if key/flags allow DS-MRR/CPK strategy to be used Check if key/flags allow DS-MRR/CPK strategy to be used
SYNOPSIS @param thd
DsMrr_impl::check_cpk_scan() @param keyno Index that will be used
keyno Index that will be used @param mrr_flags
mrr_flags
DESCRIPTION @retval TRUE DS-MRR/CPK should be used
Check if key/flags allow DS-MRR/CPK strategy to be used. @retval FALSE Otherwise
RETURN
TRUE DS-MRR/CPK should be used
FALSE Otherwise
*/ */
bool DsMrr_impl::check_cpk_scan(THD *thd, uint keyno, uint mrr_flags) bool DsMrr_impl::check_cpk_scan(THD *thd, uint keyno, uint mrr_flags)
...@@ -1413,17 +1401,14 @@ bool DsMrr_impl::get_disk_sweep_mrr_cost(uint keynr, ha_rows rows, uint flags, ...@@ -1413,17 +1401,14 @@ bool DsMrr_impl::get_disk_sweep_mrr_cost(uint keynr, ha_rows rows, uint flags,
/* /*
Get cost of one sort-and-sweep step Get cost of one sort-and-sweep step
It consists of two parts:
- sort an array of #nrows ROWIDs using qsort
- read #nrows records from table in a sweep.
SYNOPSIS @param table Table being accessed
get_sort_and_sweep_cost() @param nrows Number of rows to be sorted and retrieved
table Table being accessed @param cost OUT The cost of scan
nrows Number of rows to be sorted and retrieved
cost OUT The cost
DESCRIPTION
Get cost of these operations:
- sort an array of #nrows ROWIDs using qsort
- read #nrows records from table in a sweep.
*/ */
static static
......
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment