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

Use reverse/backwards buffer for keys (now works)

- don't allocate space for rowid buffer when we don't really need it.
- fix buffer iterator
parent 0276757d
...@@ -352,14 +352,14 @@ Thimble Smith Happy 3 3 ...@@ -352,14 +352,14 @@ Thimble Smith Happy 3 3
Lilliana Angelovska NULL NULL NULL Lilliana Angelovska NULL NULL NULL
select t1.name, t2.name, t2.id,t3.id from t1 right join t2 on (t1.id = t2.owner) right join t1 as t3 on t3.id=t2.owner; select t1.name, t2.name, t2.id,t3.id from t1 right join t2 on (t1.id = t2.owner) right join t1 as t3 on t3.id=t2.owner;
name name id id name name id id
Antonio Paz El Gato 1 1
Antonio Paz Perrito 2 1 Antonio Paz Perrito 2 1
Antonio Paz El Gato 1 1
Thimble Smith Happy 3 3 Thimble Smith Happy 3 3
NULL NULL NULL 2 NULL NULL NULL 2
select t1.name, t2.name, t2.id, t2.owner, t3.id from t1 left join t2 on (t1.id = t2.owner) right join t1 as t3 on t3.id=t2.owner; select t1.name, t2.name, t2.id, t2.owner, t3.id from t1 left join t2 on (t1.id = t2.owner) right join t1 as t3 on t3.id=t2.owner;
name name id owner id name name id owner id
Antonio Paz El Gato 1 1 1
Antonio Paz Perrito 2 1 1 Antonio Paz Perrito 2 1 1
Antonio Paz El Gato 1 1 1
Thimble Smith Happy 3 3 3 Thimble Smith Happy 3 3 3
NULL NULL NULL NULL 2 NULL NULL NULL NULL 2
drop table t1,t2; drop table t1,t2;
...@@ -413,9 +413,9 @@ insert into t2 values (1, 2, 3),(2, 2, 8), (4,3,9),(3,2,10); ...@@ -413,9 +413,9 @@ insert into t2 values (1, 2, 3),(2, 2, 8), (4,3,9),(3,2,10);
select t1.*, t2.* from t1 left join t2 on t1.n = t2.n and select t1.*, t2.* from t1 left join t2 on t1.n = t2.n and
t1.m = t2.m where t1.n = 1; t1.m = t2.m where t1.n = 1;
n m o n m o n m o n m o
1 2 11 1 2 3
1 2 7 1 2 3
1 2 9 1 2 3 1 2 9 1 2 3
1 2 7 1 2 3
1 2 11 1 2 3
1 3 9 NULL NULL NULL 1 3 9 NULL NULL NULL
select t1.*, t2.* from t1 left join t2 on t1.n = t2.n and select t1.*, t2.* from t1 left join t2 on t1.n = t2.n and
t1.m = t2.m where t1.n = 1 order by t1.o; t1.m = t2.m where t1.n = 1 order by t1.o;
......
...@@ -420,7 +420,8 @@ int DsMrr_impl::dsmrr_init(handler *h_arg, RANGE_SEQ_IF *seq_funcs, ...@@ -420,7 +420,8 @@ int DsMrr_impl::dsmrr_init(handler *h_arg, RANGE_SEQ_IF *seq_funcs,
} }
do_rowid_fetch= FALSE; do_rowid_fetch= FALSE;
doing_cpk_scan= check_cpk_scan(h->active_index, mode); doing_cpk_scan= check_cpk_scan(h->inited == handler::INDEX?
h->active_index: h2->active_index, mode);
if (!doing_cpk_scan /* && !index_only_read */) if (!doing_cpk_scan /* && !index_only_read */)
{ {
/* Will use rowid buffer to store/sort rowids, etc */ /* Will use rowid buffer to store/sort rowids, etc */
...@@ -755,6 +756,20 @@ void DsMrr_impl::setup_buffer_sizes(key_range *sample_key) ...@@ -755,6 +756,20 @@ void DsMrr_impl::setup_buffer_sizes(key_range *sample_key)
key_buff_elem_size= key_size_in_keybuf + key_buff_elem_size= key_size_in_keybuf +
(int)is_mrr_assoc * sizeof(void*); (int)is_mrr_assoc * sizeof(void*);
if (!do_rowid_fetch)
{
/* Give all space to key buffer. */
key_buffer.set_buffer_space(full_buf, full_buf_end, 1);
/* Just in case, tell rowid buffer that it has zero size: */
rowid_buffer.set_buffer_space(full_buf_end, full_buf_end, 1);
return;
}
/*
Ok if we got here we need to allocate one part of the buffer
for keys and another part for rowids.
*/
uint rowid_buf_elem_size= h->ref_length + uint rowid_buf_elem_size= h->ref_length +
(int)is_mrr_assoc * sizeof(char*); (int)is_mrr_assoc * sizeof(char*);
...@@ -790,8 +805,10 @@ void DsMrr_impl::setup_buffer_sizes(key_range *sample_key) ...@@ -790,8 +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);
//key_buffer.set_buffer_space(full_buf + bytes_for_rowids, full_buf_end, 1);
rowid_buffer.set_buffer_space(full_buf, full_buf + bytes_for_rowids, 1); rowid_buffer.set_buffer_space(full_buf, full_buf + bytes_for_rowids, 1);
key_buffer.set_buffer_space(full_buf + bytes_for_rowids, 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 ==
......
...@@ -118,7 +118,7 @@ class SimpleBuffer ...@@ -118,7 +118,7 @@ class SimpleBuffer
} }
else else
{ {
if (pos - nbytes <= sb->write_pos) if (pos - nbytes < sb->write_pos)
return NULL; return NULL;
pos -= nbytes; pos -= nbytes;
return pos; return pos;
......
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