Commit 8d07c16a authored by Sergey Petrunya's avatar Sergey Petrunya

Do dynamic buffer growing/shrinking.

parent 8dc81f47
...@@ -792,7 +792,7 @@ void DsMrr_impl::setup_buffer_sizes(key_range *sample_key) ...@@ -792,7 +792,7 @@ void DsMrr_impl::setup_buffer_sizes(key_range *sample_key)
((double) rowid_buf_elem_size / ((double) rowid_buf_elem_size /
((double)rowid_buf_elem_size + key_buff_elem_size)); ((double)rowid_buf_elem_size + key_buff_elem_size));
uint 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));
uint bytes_for_keys= (full_buf_end - full_buf) - bytes_for_rowids; uint bytes_for_keys= (full_buf_end - full_buf) - bytes_for_rowids;
...@@ -805,10 +805,10 @@ void DsMrr_impl::setup_buffer_sizes(key_range *sample_key) ...@@ -805,10 +805,10 @@ void DsMrr_impl::setup_buffer_sizes(key_range *sample_key)
(h->ref_length + (int)is_mrr_assoc * sizeof(char*) + 1)); (h->ref_length + (int)is_mrr_assoc * sizeof(char*) + 1));
} }
//rowid_buffer.set_buffer_space(full_buf, full_buf + bytes_for_rowids, 1); rowid_buffer_end= full_buf + bytes_for_rowids;
//key_buffer.set_buffer_space(full_buf + bytes_for_rowids, full_buf_end, 1); rowid_buffer.set_buffer_space(full_buf, rowid_buffer_end, 1);
rowid_buffer.set_buffer_space(full_buf, full_buf + bytes_for_rowids, 1); key_buffer.set_buffer_space(rowid_buffer_end, full_buf_end, -1);
key_buffer.set_buffer_space(full_buf + bytes_for_rowids, full_buf_end, -1);
index_ranges_unique= test(key_info->flags & HA_NOSAME && index_ranges_unique= test(key_info->flags & HA_NOSAME &&
key_info->key_parts == key_info->key_parts ==
...@@ -838,7 +838,15 @@ void DsMrr_impl::dsmrr_fill_key_buffer() ...@@ -838,7 +838,15 @@ void DsMrr_impl::dsmrr_fill_key_buffer()
// reset the buffer for writing. // reset the buffer for writing.
if (key_tuple_length) if (key_tuple_length)
{
if (do_rowid_fetch)
{
/* Restore original buffer sizes */
rowid_buffer.set_buffer_space(full_buf, rowid_buffer_end, 1);
key_buffer.set_buffer_space(rowid_buffer_end, full_buf_end, -1);
}
key_buffer.reset_for_writing(); key_buffer.reset_for_writing();
}
while ((key_tuple_length == 0 || while ((key_tuple_length == 0 ||
key_buffer.have_space_for(key_buff_elem_size)) && key_buffer.have_space_for(key_buff_elem_size)) &&
...@@ -912,7 +920,6 @@ int DsMrr_impl::dsmrr_next_from_index(char **range_info_arg) ...@@ -912,7 +920,6 @@ int DsMrr_impl::dsmrr_next_from_index(char **range_info_arg)
while (in_identical_keys_range) while (in_identical_keys_range)
{ {
//read_and_check:
/* Read record/key pointer from the buffer */ /* Read record/key pointer from the buffer */
key_in_buf= identical_key_it.get_next(key_size_in_keybuf); key_in_buf= identical_key_it.get_next(key_size_in_keybuf);
if (is_mrr_assoc) if (is_mrr_assoc)
...@@ -980,6 +987,11 @@ check_record: ...@@ -980,6 +987,11 @@ check_record:
} }
/* First, make sure we have a range at start of the buffer */ /* First, make sure we have a range at start of the buffer */
//psergey-todo: why would we re-fill it here in the case when
// we're doing rowid retrieval?
// - need to check if this is really happening.
if (!key_buffer.have_data(key_buff_elem_size)) if (!key_buffer.have_data(key_buff_elem_size))
{ {
if (dsmrr_eof) if (dsmrr_eof)
...@@ -995,6 +1007,18 @@ check_record: ...@@ -995,6 +1007,18 @@ check_record:
} }
} }
if (do_rowid_fetch)
{
/*
At this point we're not using anything beyond what we've read from key
buffer. Shrik the key buffer and grow the rowid buffer.
*/
uchar *unused_start;
uchar *unused_end;
key_buffer.remove_unused_space(&unused_start, &unused_end);
rowid_buffer.grow(unused_start, unused_end);
}
/* Get the next range to scan*/ /* Get the next range to scan*/
cur_index_tuple= key_in_buf= key_buffer.read(key_size_in_keybuf); cur_index_tuple= key_in_buf= key_buffer.read(key_size_in_keybuf);
if (use_key_pointers) if (use_key_pointers)
...@@ -1002,7 +1026,8 @@ check_record: ...@@ -1002,7 +1026,8 @@ check_record:
if (is_mrr_assoc) if (is_mrr_assoc)
cur_range_info= (char*)key_buffer.read(sizeof(void*)); cur_range_info= (char*)key_buffer.read(sizeof(void*));
/* Do index lookup */ /* Do index lookup */
if ((res= file->ha_index_read_map(table->record[0], cur_index_tuple, if ((res= file->ha_index_read_map(table->record[0], cur_index_tuple,
key_tuple_map, HA_READ_KEY_EXACT))) key_tuple_map, HA_READ_KEY_EXACT)))
......
...@@ -91,6 +91,46 @@ public: ...@@ -91,6 +91,46 @@ public:
direction= direction_arg; direction= direction_arg;
reset_for_writing(); reset_for_writing();
} }
/*
Stop/return the unneded space (the one that we have wrote to and have read
from.
*/
void remove_unused_space(uchar **unused_start, uchar **unused_end)
{
if (direction == 1)
{
*unused_start= start;
*unused_end= read_pos;
}
else
{
*unused_start=read_pos;
*unused_end=end;
}
}
void grow(uchar *unused_start, uchar *unused_end)
{
/*
Passed memory area can be meaningfully used for growing the buffer if:
- it is adjacent to buffer space we're using
- it is on the end towards which we grow.
*/
if (direction == 1 && end == unused_start)
{
end= unused_end;
}
else if (direction == -1 && start == unused_end)
{
start= unused_start;
}
else
DBUG_ASSERT(0); /* Attempt to grow buffer in wrong direction */
}
/* */
void grow();
friend class PeekIterator; friend class PeekIterator;
class PeekIterator class PeekIterator
...@@ -202,6 +242,9 @@ private: ...@@ -202,6 +242,9 @@ private:
uchar *full_buf; uchar *full_buf;
uchar *full_buf_end; uchar *full_buf_end;
/* Valid when using both rowid and key buffer: the original bound between them */
uchar *rowid_buffer_end;
/* Buffer to store rowids, or (rowid, range_id) pairs */ /* Buffer to store rowids, or (rowid, range_id) pairs */
SimpleBuffer rowid_buffer; SimpleBuffer rowid_buffer;
...@@ -248,7 +291,7 @@ private: ...@@ -248,7 +291,7 @@ private:
/* = h->ref_length [ + sizeof(range_assoc_info) ] */ /* = h->ref_length [ + sizeof(range_assoc_info) ] */
uint rowid_buff_elem_size; uint rowid_buff_elem_size;
/* /*
TRUE <=> We're scanning on a full primary key (and not on prefix), and so TRUE <=> We're scanning on a full primary key (and not on prefix), and so
can get max. one match for each key can get max. one match for each key
......
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