Commit d9a8dd22 authored by Sergey Petrunya's avatar Sergey Petrunya

DS-MRR/CPK improvements: correct buffer exhaustion handling

parent 8e4c627e
...@@ -484,7 +484,7 @@ int Mrr_ordered_index_reader::refill_buffer() ...@@ -484,7 +484,7 @@ int Mrr_ordered_index_reader::refill_buffer()
scanning_key_val_iter= FALSE; scanning_key_val_iter= FALSE;
index_scan_eof= FALSE; index_scan_eof= FALSE;
DBUG_RETURN(0); DBUG_RETURN((no_more_keys && key_buffer->is_empty())? HA_ERR_END_OF_FILE:0);
} }
...@@ -521,8 +521,11 @@ int Mrr_ordered_rndpos_reader::init(handler *h_arg, ...@@ -521,8 +521,11 @@ int Mrr_ordered_rndpos_reader::init(handler *h_arg,
//rowid_buff_elem_size= h->ref_length; //rowid_buff_elem_size= h->ref_length;
//if (!(mode & HA_MRR_NO_ASSOCIATION)) //if (!(mode & HA_MRR_NO_ASSOCIATION))
// rowid_buff_elem_size += sizeof(char*); // rowid_buff_elem_size += sizeof(char*);
return index_reader->refill_buffer(); int res= index_reader->refill_buffer();
if (res && res!=HA_ERR_END_OF_FILE)
return res;
return 0;
} }
...@@ -561,7 +564,7 @@ int Mrr_ordered_rndpos_reader::refill_buffer() ...@@ -561,7 +564,7 @@ int Mrr_ordered_rndpos_reader::refill_buffer()
last_identical_rowid= NULL; last_identical_rowid= NULL;
if (index_reader->eof()) if (index_reader->eof())
DBUG_RETURN(0); DBUG_RETURN(HA_ERR_END_OF_FILE);
while (rowid_buffer->can_write()) while (rowid_buffer->can_write())
{ {
...@@ -584,9 +587,9 @@ int Mrr_ordered_rndpos_reader::refill_buffer() ...@@ -584,9 +587,9 @@ int Mrr_ordered_rndpos_reader::refill_buffer()
rowid_buffer->sort((qsort2_cmp)rowid_cmp_reverse, (void*)h); rowid_buffer->sort((qsort2_cmp)rowid_cmp_reverse, (void*)h);
rowid_buffer->setup_reading(&rowid, h->ref_length, rowid_buffer->setup_reading(&rowid, h->ref_length,
is_mrr_assoc? (uchar**)&rowids_range_id: NULL, is_mrr_assoc? (uchar**)&rowids_range_id: NULL,
sizeof(void*)); sizeof(void*));
DBUG_RETURN(0); DBUG_RETURN((rowid_buffer->is_empty() && res) ? HA_ERR_END_OF_FILE : 0);
} }
...@@ -632,8 +635,9 @@ int Mrr_ordered_rndpos_reader::get_next(char **range_info) ...@@ -632,8 +635,9 @@ int Mrr_ordered_rndpos_reader::get_next(char **range_info)
/* First, finish off the sorted keys we have */ /* First, finish off the sorted keys we have */
if (!index_reader->eof()) if (!index_reader->eof())
{ {
if ((res= refill_buffer())) res= refill_buffer();
return res; /* for fatal errors */ if (res && res != HA_ERR_END_OF_FILE)
return res;
} }
if (rowid_buffer->is_empty()) if (rowid_buffer->is_empty())
...@@ -821,8 +825,9 @@ int DsMrr_impl::dsmrr_init(handler *h_arg, RANGE_SEQ_IF *seq_funcs, ...@@ -821,8 +825,9 @@ int DsMrr_impl::dsmrr_init(handler *h_arg, RANGE_SEQ_IF *seq_funcs,
goto error; goto error;
} }
} }
if (strategy->refill_buffer()) res= strategy->refill_buffer();
if (res && res != HA_ERR_END_OF_FILE)
goto error; goto error;
/* /*
......
...@@ -126,8 +126,16 @@ class Buffer_manager ...@@ -126,8 +126,16 @@ class Buffer_manager
index tuple or a table record. index tuple or a table record.
Getting HA_ERR_END_OF_FILE from get_next() means that the source should be Getting HA_ERR_END_OF_FILE from get_next() means that the source should be
re-filled. if eof() returns true after refill attempt, then the end of re-filled.
Was:
if eof() returns true after refill attempt, then the end of
stream has been reached and get_next() must not be called anymore. stream has been reached and get_next() must not be called anymore.
Now:
if refill_buffer() returns HA_ERR_END_OF_FILE that means the stream is
really exhausted.
*/ */
class Mrr_reader class Mrr_reader
...@@ -168,7 +176,7 @@ class Mrr_simple_index_reader : public Mrr_index_reader ...@@ -168,7 +176,7 @@ class Mrr_simple_index_reader : public Mrr_index_reader
void *seq_init_param, uint n_ranges, void *seq_init_param, uint n_ranges,
uint mode, Buffer_manager *buf_manager_arg); uint mode, Buffer_manager *buf_manager_arg);
int get_next(char **range_info); int get_next(char **range_info);
int refill_buffer() { return 0; } int refill_buffer() { return HA_ERR_END_OF_FILE; }
bool eof() { return test(res); } bool eof() { return test(res); }
uchar *get_rowid_ptr() { return h->ref; } uchar *get_rowid_ptr() { return h->ref; }
bool skip_record(char *range_id, uchar *rowid) bool skip_record(char *range_id, uchar *rowid)
......
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