Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
M
mariadb
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
mariadb
Commits
9b04caff
Commit
9b04caff
authored
Sep 10, 2010
by
Sergey Petrunya
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit for buildbot checks
parent
dbc63bed
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
56 additions
and
41 deletions
+56
-41
sql/multi_range_read.cc
sql/multi_range_read.cc
+37
-27
sql/multi_range_read.h
sql/multi_range_read.h
+19
-14
No files found.
sql/multi_range_read.cc
View file @
9b04caff
...
@@ -283,8 +283,9 @@ scan_it_again:
...
@@ -283,8 +283,9 @@ scan_it_again:
DBUG_RETURN
(
result
);
DBUG_RETURN
(
result
);
}
}
/****************************************************************************
/****************************************************************************
*
DS-MRR implementation
*
SimpleBuffer class implementation (used by DS-MRR code)
***************************************************************************/
***************************************************************************/
void
SimpleBuffer
::
setup_writing
(
uchar
**
data1
,
size_t
len1
,
void
SimpleBuffer
::
setup_writing
(
uchar
**
data1
,
size_t
len1
,
uchar
**
data2
,
size_t
len2
)
uchar
**
data2
,
size_t
len2
)
...
@@ -322,6 +323,13 @@ void SimpleBuffer::write(const uchar *data, size_t bytes)
...
@@ -322,6 +323,13 @@ void SimpleBuffer::write(const uchar *data, size_t bytes)
write_pos
+=
bytes
;
write_pos
+=
bytes
;
}
}
bool
SimpleBuffer
::
can_write
()
{
return
have_space_for
(
write_size1
+
(
write_ptr2
?
write_size2
:
0
));
}
bool
SimpleBuffer
::
have_space_for
(
size_t
bytes
)
bool
SimpleBuffer
::
have_space_for
(
size_t
bytes
)
{
{
if
(
direction
==
1
)
if
(
direction
==
1
)
...
@@ -405,9 +413,12 @@ uchar *SimpleBuffer::end_of_space()
...
@@ -405,9 +413,12 @@ uchar *SimpleBuffer::end_of_space()
return
start
;
return
start
;
else
else
return
end
;
return
end
;
//TODO: check this.
}
}
/****************************************************************************
* DS-MRR implementation
***************************************************************************/
/**
/**
DS-MRR: Initialize and start MRR scan
DS-MRR: Initialize and start MRR scan
...
@@ -472,28 +483,21 @@ int DsMrr_impl::dsmrr_init(handler *h_arg, RANGE_SEQ_IF *seq_funcs,
...
@@ -472,28 +483,21 @@ int DsMrr_impl::dsmrr_init(handler *h_arg, RANGE_SEQ_IF *seq_funcs,
}
}
DBUG_ASSERT
(
do_sort_keys
||
do_rowid_fetch
);
DBUG_ASSERT
(
do_sort_keys
||
do_rowid_fetch
);
full_buf
=
buf
->
buffer
;
full_buf_end
=
buf
->
buffer_end
;
if
(
is_mrr_assoc
)
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. Key sorting code will grab a
piece if necessary.
piece if necessary.
*/
*/
full_buf
=
buf
->
buffer
;
full_buf_end
=
buf
->
buffer_end
;
rowid_buffer
.
set_buffer_space
(
full_buf
,
full_buf_end
,
1
);
rowid_buffer
.
set_buffer_space
(
full_buf
,
full_buf_end
,
1
);
if
(
is_mrr_assoc
)
status_var_increment
(
table
->
in_use
->
status_var
.
ha_multi_range_read_init_count
);
/*
psergey2-todo: for CPK scans:
- use MRR irrespectively of @@mrr_sort_keys setting,
- dont do rowid retrieval.
*/
if
(
do_sort_keys
)
if
(
do_sort_keys
)
{
{
/* It's a DS-MRR/CPK scan */
know_key_tuple_params
=
FALSE
;
key_tuple_length
=
0
;
/* dummy value telling it needs to be inited */
key_buff_elem_size
=
0
;
in_index_range
=
FALSE
;
in_index_range
=
FALSE
;
h
->
mrr_iter
=
seq_funcs
->
init
(
seq_init_param
,
n_ranges
,
mode
);
h
->
mrr_iter
=
seq_funcs
->
init
(
seq_init_param
,
n_ranges
,
mode
);
h
->
mrr_funcs
=
*
seq_funcs
;
h
->
mrr_funcs
=
*
seq_funcs
;
...
@@ -693,7 +697,7 @@ int DsMrr_impl::dsmrr_fill_rowid_buffer()
...
@@ -693,7 +697,7 @@ int DsMrr_impl::dsmrr_fill_rowid_buffer()
if
(
do_sort_keys
&&
key_buffer
.
is_reverse
())
if
(
do_sort_keys
&&
key_buffer
.
is_reverse
())
key_buffer
.
flip
();
key_buffer
.
flip
();
while
(
rowid_buffer
.
have_space_for
(
rowid_buff_elem_size
))
while
(
rowid_buffer
.
can_write
(
))
{
{
if
(
do_sort_keys
)
if
(
do_sort_keys
)
res
=
dsmrr_next_from_index
(
&
range_info
);
res
=
dsmrr_next_from_index
(
&
range_info
);
...
@@ -729,6 +733,7 @@ int DsMrr_impl::dsmrr_fill_rowid_buffer()
...
@@ -729,6 +733,7 @@ int DsMrr_impl::dsmrr_fill_rowid_buffer()
DBUG_RETURN
(
0
);
DBUG_RETURN
(
0
);
}
}
void
SimpleBuffer
::
sort
(
qsort2_cmp
cmp_func
,
void
*
cmp_func_arg
)
void
SimpleBuffer
::
sort
(
qsort2_cmp
cmp_func
,
void
*
cmp_func_arg
)
{
{
uint
elem_size
=
write_size1
+
(
write_ptr2
?
write_size2
:
0
);
uint
elem_size
=
write_size1
+
(
write_ptr2
?
write_size2
:
0
);
...
@@ -736,10 +741,9 @@ void SimpleBuffer::sort(qsort2_cmp cmp_func, void *cmp_func_arg)
...
@@ -736,10 +741,9 @@ void SimpleBuffer::sort(qsort2_cmp cmp_func, void *cmp_func_arg)
my_qsort2
(
used_area
(),
n_elements
,
elem_size
,
cmp_func
,
cmp_func_arg
);
my_qsort2
(
used_area
(),
n_elements
,
elem_size
,
cmp_func
,
cmp_func_arg
);
}
}
/*
/*
my_qsort2-compatible function to compare key tuples
my_qsort2-compatible function to compare key tuples
If dsmrr->use_key_pointers==FALSE
*/
*/
int
DsMrr_impl
::
key_tuple_cmp
(
void
*
arg
,
uchar
*
key1
,
uchar
*
key2
)
int
DsMrr_impl
::
key_tuple_cmp
(
void
*
arg
,
uchar
*
key1
,
uchar
*
key2
)
...
@@ -890,9 +894,10 @@ void DsMrr_impl::dsmrr_fill_key_buffer()
...
@@ -890,9 +894,10 @@ void DsMrr_impl::dsmrr_fill_key_buffer()
uchar
**
range_info_ptr
=
(
uchar
**
)
&
cur_range
.
ptr
;
uchar
**
range_info_ptr
=
(
uchar
**
)
&
cur_range
.
ptr
;
DBUG_ENTER
(
"DsMrr_impl::dsmrr_fill_key_buffer"
);
DBUG_ENTER
(
"DsMrr_impl::dsmrr_fill_key_buffer"
);
DBUG_ASSERT
(
!
k
ey_tuple_length
||
key_buffer
.
is_empty
());
DBUG_ASSERT
(
!
k
now_key_tuple_params
||
key_buffer
.
is_empty
());
if
(
key_tuple_length
)
uchar
*
key_ptr
;
if
(
know_key_tuple_params
)
{
{
if
(
do_rowid_fetch
&&
rowid_buffer
.
is_empty
())
if
(
do_rowid_fetch
&&
rowid_buffer
.
is_empty
())
{
{
...
@@ -904,21 +909,24 @@ void DsMrr_impl::dsmrr_fill_key_buffer()
...
@@ -904,21 +909,24 @@ void DsMrr_impl::dsmrr_fill_key_buffer()
key_buffer
.
set_buffer_space
(
rowid_buffer_end
,
full_buf_end
,
-
1
);
key_buffer
.
set_buffer_space
(
rowid_buffer_end
,
full_buf_end
,
-
1
);
}
}
key_buffer
.
reset_for_writing
();
key_buffer
.
reset_for_writing
();
key_buffer
.
setup_writing
(
&
key_ptr
,
key_size_in_keybuf
,
is_mrr_assoc
?
(
uchar
**
)
&
range_info_ptr
:
NULL
,
sizeof
(
uchar
*
));
}
}
uchar
*
key_ptr
;
while
((
!
know_key_tuple_params
||
key_buffer
.
can_write
())
&&
while
((
key_tuple_length
==
0
||
key_buffer
.
have_space_for
(
key_buff_elem_size
))
&&
!
(
res
=
h
->
mrr_funcs
.
next
(
h
->
mrr_iter
,
&
cur_range
)))
!
(
res
=
h
->
mrr_funcs
.
next
(
h
->
mrr_iter
,
&
cur_range
)))
{
{
DBUG_ASSERT
(
cur_range
.
range_flag
&
EQ_RANGE
);
DBUG_ASSERT
(
cur_range
.
range_flag
&
EQ_RANGE
);
if
(
!
k
ey_tuple_length
)
if
(
!
k
now_key_tuple_params
)
{
{
/* This only happens when we've just started filling the buffer */
/* This only happens when we've just started filling the buffer */
setup_buffer_sizes
(
&
cur_range
.
start_key
);
setup_buffer_sizes
(
&
cur_range
.
start_key
);
know_key_tuple_params
=
TRUE
;
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
*
));
DBUG_ASSERT
(
key_buffer
.
can_write
());
}
}
/* Put key, or {key, range_id} pair into the buffer */
/* Put key, or {key, range_id} pair into the buffer */
...
@@ -934,6 +942,7 @@ void DsMrr_impl::dsmrr_fill_key_buffer()
...
@@ -934,6 +942,7 @@ void DsMrr_impl::dsmrr_fill_key_buffer()
key_buffer
.
sort
((
qsort2_cmp
)
DsMrr_impl
::
key_tuple_cmp
,
(
void
*
)
this
);
key_buffer
.
sort
((
qsort2_cmp
)
DsMrr_impl
::
key_tuple_cmp
,
(
void
*
)
this
);
//psergey4: cur_range_info will point to range-info bytes.
key_buffer
.
setup_reading
(
&
cur_index_tuple
,
key_size_in_keybuf
,
key_buffer
.
setup_reading
(
&
cur_index_tuple
,
key_size_in_keybuf
,
is_mrr_assoc
?
(
uchar
**
)
&
cur_range_info
:
NULL
,
sizeof
(
void
*
));
is_mrr_assoc
?
(
uchar
**
)
&
cur_range_info
:
NULL
,
sizeof
(
void
*
));
...
@@ -995,7 +1004,7 @@ check_record:
...
@@ -995,7 +1004,7 @@ check_record:
{
{
continue
;
continue
;
}
}
memcpy
(
range_info_arg
,
cur_range_info
,
sizeof
(
void
*
));
memcpy
(
range_info_arg
,
cur_range_info
,
sizeof
(
void
*
));
//psergey4: this copyies junk there
return
0
;
return
0
;
}
}
...
@@ -1200,11 +1209,12 @@ int DsMrr_impl::dsmrr_next(char **range_info)
...
@@ -1200,11 +1209,12 @@ int DsMrr_impl::dsmrr_next(char **range_info)
if
(
is_mrr_assoc
)
if
(
is_mrr_assoc
)
{
{
memcpy
(
range_info
,
rowids_range_id
,
sizeof
(
uchar
*
));
memcpy
(
range_info
,
rowids_range_id
,
sizeof
(
uchar
*
));
memcpy
(
&
cur_range_info
,
rowids_range_id
,
sizeof
(
uchar
*
));
//psergey5: memcpy(&cur_range_info, rowids_range_id, sizeof(uchar*)); // psergey: ???
}
}
if
(
h2
->
mrr_funcs
.
skip_record
&&
if
(
h2
->
mrr_funcs
.
skip_record
&&
h2
->
mrr_funcs
.
skip_record
(
h2
->
mrr_iter
,
(
char
*
)
cur_range_info
,
rowid
))
h2
->
mrr_funcs
.
skip_record
(
h2
->
mrr_iter
,
/* psergey5 (char *)
cur_range_info */
*
range_info
,
rowid
))
continue
;
continue
;
res
=
h
->
ha_rnd_pos
(
table
->
record
[
0
],
rowid
);
res
=
h
->
ha_rnd_pos
(
table
->
record
[
0
],
rowid
);
...
...
sql/multi_range_read.h
View file @
9b04caff
...
@@ -76,6 +76,13 @@ class SimpleBuffer
...
@@ -76,6 +76,13 @@ class SimpleBuffer
uchar
**
read_ptr2
;
uchar
**
read_ptr2
;
size_t
read_size2
;
size_t
read_size2
;
bool
have_space_for
(
size_t
bytes
);
uchar
*
used_area
()
{
return
(
direction
==
1
)
?
read_pos
:
write_pos
;
}
size_t
used_size
();
void
write
(
const
uchar
*
data
,
size_t
bytes
);
uchar
*
read
(
size_t
bytes
);
public:
public:
/* Set up writing*/
/* Set up writing*/
void
setup_writing
(
uchar
**
data1
,
size_t
len1
,
void
setup_writing
(
uchar
**
data1
,
size_t
len1
,
...
@@ -86,26 +93,17 @@ public:
...
@@ -86,26 +93,17 @@ public:
/* Write-mode functions */
/* Write-mode functions */
void
reset_for_writing
();
void
reset_for_writing
();
void
write
();
void
write
();
bool
have_space_for
(
size_t
bytes
);
bool
can_write
();
private:
void
write
(
const
uchar
*
data
,
size_t
bytes
);
uchar
*
used_area
()
{
return
(
direction
==
1
)
?
read_pos
:
write_pos
;
}
size_t
used_size
();
public:
bool
is_empty
()
{
return
used_size
()
==
0
;
}
bool
is_empty
()
{
return
used_size
()
==
0
;
}
/* Read-mode functions */
/* Read-mode functions */
void
reset_for_reading
();
void
reset_for_reading
();
// todo: join with setup-writing? (but what for?)
// todo: join with setup-writing?
void
setup_reading
(
uchar
**
data1
,
size_t
len1
,
void
setup_reading
(
uchar
**
data1
,
size_t
len1
,
uchar
**
data2
,
size_t
len2
);
uchar
**
data2
,
size_t
len2
);
bool
read
();
bool
read
();
private:
uchar
*
read
(
size_t
bytes
);
public:
bool
have_data
(
size_t
bytes
);
bool
have_data
(
size_t
bytes
);
uchar
*
end_of_space
();
uchar
*
end_of_space
();
...
@@ -115,6 +113,7 @@ public:
...
@@ -115,6 +113,7 @@ public:
start
=
start_arg
;
start
=
start_arg
;
end
=
end_arg
;
end
=
end_arg
;
direction
=
direction_arg
;
direction
=
direction_arg
;
// TRASH(start, end - start);
reset_for_writing
();
reset_for_writing
();
}
}
...
@@ -166,6 +165,10 @@ public:
...
@@ -166,6 +165,10 @@ public:
DBUG_ASSERT
(
0
);
/* Attempt to grow buffer in wrong direction */
DBUG_ASSERT
(
0
);
/* Attempt to grow buffer in wrong direction */
}
}
/*
An iterator to do look at what we're about to read from the buffer without
actually reading it.
*/
class
PeekIterator
class
PeekIterator
{
{
// if direction==1 : pointer to what to return next
// if direction==1 : pointer to what to return next
...
@@ -342,8 +345,9 @@ private:
...
@@ -342,8 +345,9 @@ private:
bool
doing_cpk_scan
;
/* TRUE <=> DS-MRR/CPK variant is used */
bool
doing_cpk_scan
;
/* TRUE <=> DS-MRR/CPK variant is used */
/** DS-MRR/CPK variables start */
/* Initially FALSE, becomes TRUE when we've set key_tuple_xxx members */
bool
know_key_tuple_params
;
/* Length of lookup tuple being used, in bytes */
/* Length of lookup tuple being used, in bytes */
uint
key_tuple_length
;
uint
key_tuple_length
;
key_part_map
key_tuple_map
;
key_part_map
key_tuple_map
;
...
@@ -368,6 +372,7 @@ private:
...
@@ -368,6 +372,7 @@ private:
/* TRUE<=> we're in a middle of enumerating records from a range */
/* TRUE<=> we're in a middle of enumerating records from a range */
bool
in_index_range
;
bool
in_index_range
;
uchar
*
cur_index_tuple
;
uchar
*
cur_index_tuple
;
/* if in_index_range==TRUE: range_id of the range we're enumerating */
/* if in_index_range==TRUE: range_id of the range we're enumerating */
char
*
cur_range_info
;
char
*
cur_range_info
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment