Commit 2ec43747 authored by Sergey Petrunya's avatar Sergey Petrunya

Merge MWL#121-125 DS-MRR improvements

- Address Monty's review feedback, part 1
parent c635eb33
...@@ -586,7 +586,6 @@ if (`select @@join_cache_level=6`) ...@@ -586,7 +586,6 @@ if (`select @@join_cache_level=6`)
--echo # Not anymore: --echo # Not anymore:
--echo # The following query gives wrong result due to Bug#49129 --echo # The following query gives wrong result due to Bug#49129
} }
select * from t0 where t0.a in select * from t0 where t0.a in
(select t1.a from t1, t2 where t2.a=t0.a and t1.b=t2.b); (select t1.a from t1, t2 where t2.a=t0.a and t1.b=t2.b);
......
...@@ -341,14 +341,14 @@ int Mrr_ordered_index_reader::get_next(char **range_info) ...@@ -341,14 +341,14 @@ int Mrr_ordered_index_reader::get_next(char **range_info)
DBUG_RETURN(HA_ERR_END_OF_FILE); DBUG_RETURN(HA_ERR_END_OF_FILE);
} }
while (1) for(;;)
{ {
bool have_record= FALSE; bool have_record= FALSE;
if (scanning_key_val_iter) if (scanning_key_val_iter)
{ {
if ((res= kv_it.get_next())) if ((res= kv_it.get_next()))
{ {
kv_it.close(); kv_it.close_();
scanning_key_val_iter= FALSE; scanning_key_val_iter= FALSE;
if ((res != HA_ERR_KEY_NOT_FOUND && res != HA_ERR_END_OF_FILE)) if ((res != HA_ERR_KEY_NOT_FOUND && res != HA_ERR_END_OF_FILE))
DBUG_RETURN(res); DBUG_RETURN(res);
...@@ -439,24 +439,22 @@ int Mrr_ordered_index_reader::refill_buffer() ...@@ -439,24 +439,22 @@ int Mrr_ordered_index_reader::refill_buffer()
} }
/* Put key, or {key, range_id} pair into the buffer */ /* Put key, or {key, range_id} pair into the buffer */
if (keypar.use_key_pointers) key_ptr= (keypar.use_key_pointers)? (uchar*)&cur_range.start_key.key :
key_ptr=(uchar*) &cur_range.start_key.key; (uchar*)cur_range.start_key.key;
else
key_ptr=(uchar*) cur_range.start_key.key;
key_buffer->write(); key_buffer->write();
} }
bool no_more_keys= test(res); /* Force get_next() to start with kv_it.init() call: */
scanning_key_val_iter= FALSE; scanning_key_val_iter= FALSE;
if (no_more_keys && (!know_key_tuple_params || key_buffer->is_empty())) if (test(res) && (!know_key_tuple_params || key_buffer->is_empty()))
DBUG_RETURN(HA_ERR_END_OF_FILE); DBUG_RETURN(HA_ERR_END_OF_FILE);
key_buffer->sort((key_buffer->type() == Lifo_buffer::FORWARD)? key_buffer->sort((key_buffer->type() == Lifo_buffer::FORWARD)?
(qsort2_cmp)Mrr_ordered_index_reader::key_tuple_cmp_reverse : (qsort2_cmp)Mrr_ordered_index_reader::key_tuple_cmp_reverse :
(qsort2_cmp)Mrr_ordered_index_reader::key_tuple_cmp, (qsort2_cmp)Mrr_ordered_index_reader::key_tuple_cmp,
(void*)this); this);
DBUG_RETURN(0); DBUG_RETURN(0);
} }
...@@ -558,7 +556,7 @@ int Mrr_ordered_rndpos_reader::refill_buffer() ...@@ -558,7 +556,7 @@ int Mrr_ordered_rndpos_reader::refill_buffer()
if (index_reader_exhausted) if (index_reader_exhausted)
DBUG_RETURN(HA_ERR_END_OF_FILE); DBUG_RETURN(HA_ERR_END_OF_FILE);
while ((res= refill_from_key_buffer() == HA_ERR_END_OF_FILE)) while ((res= refill_from_key_buffer()) == HA_ERR_END_OF_FILE)
{ {
if ((res= index_reader->refill_buffer())) if ((res= index_reader->refill_buffer()))
{ {
...@@ -603,11 +601,16 @@ int Mrr_ordered_rndpos_reader::refill_from_key_buffer() ...@@ -603,11 +601,16 @@ int Mrr_ordered_rndpos_reader::refill_from_key_buffer()
res= index_reader->get_next(&range_info); res= index_reader->get_next(&range_info);
if (res) if (res)
{
if (res != HA_ERR_END_OF_FILE)
DBUG_RETURN(res);
index_reader_exhausted= TRUE;
break; break;
}
/* Put rowid, or {rowid, range_id} pair into the buffer */
index_reader->position(); index_reader->position();
/* Put rowid, or {rowid, range_id} pair into the buffer */
rowid_buffer->write(); rowid_buffer->write();
} }
...@@ -658,7 +661,7 @@ int Mrr_ordered_rndpos_reader::get_next(char **range_info) ...@@ -658,7 +661,7 @@ int Mrr_ordered_rndpos_reader::get_next(char **range_info)
} }
} }
while (1) for(;;)
{ {
last_identical_rowid= NULL; last_identical_rowid= NULL;
...@@ -1052,8 +1055,8 @@ void DsMrr_impl::setup_buffer_sizes(uint key_size_in_keybuf, ...@@ -1052,8 +1055,8 @@ void DsMrr_impl::setup_buffer_sizes(uint key_size_in_keybuf,
Ok if we got here we need to allocate one part of the buffer Ok if we got here we need to allocate one part of the buffer
for keys and another part for rowids. for keys and another part for rowids.
*/ */
uint rowid_buf_elem_size= h->ref_length + ulonglong rowid_buf_elem_size= h->ref_length +
(int)is_mrr_assoc * sizeof(char*); (int)is_mrr_assoc * sizeof(char*);
/* /*
Use rec_per_key statistics as a basis to find out how many rowids Use rec_per_key statistics as a basis to find out how many rowids
...@@ -1070,8 +1073,8 @@ void DsMrr_impl::setup_buffer_sizes(uint key_size_in_keybuf, ...@@ -1070,8 +1073,8 @@ void DsMrr_impl::setup_buffer_sizes(uint key_size_in_keybuf,
} }
double fraction_for_rowids= double fraction_for_rowids=
((double) rowid_buf_elem_size / (ulonglong2double(rowid_buf_elem_size) /
((double)rowid_buf_elem_size + key_buff_elem_size)); (ulonglong2double(rowid_buf_elem_size) + key_buff_elem_size));
size_t bytes_for_rowids= size_t bytes_for_rowids=
round(fraction_for_rowids * (full_buf_end - full_buf)); round(fraction_for_rowids * (full_buf_end - full_buf));
...@@ -1080,7 +1083,7 @@ void DsMrr_impl::setup_buffer_sizes(uint key_size_in_keybuf, ...@@ -1080,7 +1083,7 @@ void DsMrr_impl::setup_buffer_sizes(uint key_size_in_keybuf,
if (bytes_for_keys < key_buff_elem_size + 1) if (bytes_for_keys < key_buff_elem_size + 1)
{ {
uint add= key_buff_elem_size + 1 - bytes_for_keys; ulong add= key_buff_elem_size + 1 - bytes_for_keys;
bytes_for_keys= key_buff_elem_size + 1; bytes_for_keys= key_buff_elem_size + 1;
bytes_for_rowids -= add; bytes_for_rowids -= add;
DBUG_ASSERT(bytes_for_rowids >= rowid_buf_elem_size + 1); DBUG_ASSERT(bytes_for_rowids >= rowid_buf_elem_size + 1);
...@@ -1088,7 +1091,7 @@ void DsMrr_impl::setup_buffer_sizes(uint key_size_in_keybuf, ...@@ -1088,7 +1091,7 @@ void DsMrr_impl::setup_buffer_sizes(uint key_size_in_keybuf,
if (bytes_for_rowids < rowid_buf_elem_size + 1) if (bytes_for_rowids < rowid_buf_elem_size + 1)
{ {
uint add= rowid_buf_elem_size + 1 - bytes_for_rowids; ulong add= rowid_buf_elem_size + 1 - bytes_for_rowids;
bytes_for_rowids= rowid_buf_elem_size + 1; bytes_for_rowids= rowid_buf_elem_size + 1;
bytes_for_keys -= add; bytes_for_keys -= add;
DBUG_ASSERT(bytes_for_keys >= key_buff_elem_size + 1); DBUG_ASSERT(bytes_for_keys >= key_buff_elem_size + 1);
...@@ -1185,7 +1188,7 @@ int Key_value_records_iterator::init(Mrr_ordered_index_reader *owner_arg) ...@@ -1185,7 +1188,7 @@ int Key_value_records_iterator::init(Mrr_ordered_index_reader *owner_arg)
if (res) if (res)
{ {
close(); close_();
return res; return res;
} }
get_next_row= FALSE; get_next_row= FALSE;
...@@ -1223,7 +1226,7 @@ int Key_value_records_iterator::get_next() ...@@ -1223,7 +1226,7 @@ int Key_value_records_iterator::get_next()
} }
void Key_value_records_iterator::close() void Key_value_records_iterator::close_()
{ {
while (!owner->key_buffer->read() && while (!owner->key_buffer->read() &&
(cur_index_tuple != last_identical_key_ptr)) {} (cur_index_tuple != last_identical_key_ptr)) {}
......
...@@ -137,7 +137,7 @@ class Key_value_records_iterator ...@@ -137,7 +137,7 @@ class Key_value_records_iterator
public: public:
int init(Mrr_ordered_index_reader *owner_arg); int init(Mrr_ordered_index_reader *owner_arg);
int get_next(); int get_next();
void close(); void close_();
}; };
......
...@@ -8006,7 +8006,7 @@ QUICK_RANGE_SELECT *get_quick_select_for_ref(THD *thd, TABLE *table, ...@@ -8006,7 +8006,7 @@ QUICK_RANGE_SELECT *get_quick_select_for_ref(THD *thd, TABLE *table,
quick->mrr_buf_size= thd->variables.mrr_buff_size; quick->mrr_buf_size= thd->variables.mrr_buff_size;
if (table->file->multi_range_read_info(quick->index, 1, (uint)records, if (table->file->multi_range_read_info(quick->index, 1, (uint)records,
uint(-1), ~0,
&quick->mrr_buf_size, &quick->mrr_buf_size,
&quick->mrr_flags, &cost)) &quick->mrr_flags, &cost))
goto err; goto err;
......
...@@ -150,7 +150,7 @@ public: ...@@ -150,7 +150,7 @@ public:
enum_direction type() { return FORWARD; } enum_direction type() { return FORWARD; }
size_t used_size() size_t used_size()
{ {
return pos - start; return (size_t)(pos - start);
} }
void reset() void reset()
{ {
...@@ -243,7 +243,7 @@ public: ...@@ -243,7 +243,7 @@ public:
size_t used_size() size_t used_size()
{ {
return end - pos; return (size_t)(end - pos);
} }
void reset() void reset()
{ {
......
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