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
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nexedi
MariaDB
Commits
23bd5607
Commit
23bd5607
authored
Dec 01, 2020
by
Varun Gupta
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Working on descriptors for variable sized keys
parent
1e9b0a4e
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
140 additions
and
26 deletions
+140
-26
sql/field.cc
sql/field.cc
+26
-0
sql/field.h
sql/field.h
+5
-0
sql/filesort.cc
sql/filesort.cc
+23
-1
sql/item_sum.cc
sql/item_sum.cc
+5
-5
sql/sql_class.h
sql/sql_class.h
+2
-0
sql/sql_statistics.cc
sql/sql_statistics.cc
+3
-3
sql/uniques.cc
sql/uniques.cc
+29
-13
sql/uniques.h
sql/uniques.h
+47
-4
No files found.
sql/field.cc
View file @
23bd5607
...
@@ -1064,6 +1064,32 @@ Field::make_packed_sort_key_part(uchar *buff,
...
@@ -1064,6 +1064,32 @@ Field::make_packed_sort_key_part(uchar *buff,
}
}
uint
Field
::
make_packed_key_part
(
uchar
*
buff
,
const
SORT_FIELD_ATTR
*
sort_field
)
{
if
(
maybe_null
())
{
if
(
is_null
())
{
*
buff
++=
0
;
return
0
;
// For NULL values don't write any data
}
*
buff
++=
1
;
}
memcpy
(
buff
,
ptr
,
sort_field
->
original_length
);
return
sort_field
->
original_length
;
}
uint
Field_longstr
::
make_packed_key_part
(
uchar
*
buff
,
const
SORT_FIELD_ATTR
*
sort_field
)
{
return
make_packed_sort_key_part
(
buff
,
sort_field
);
}
uint
uint
Field_longstr
::
make_packed_sort_key_part
(
uchar
*
buff
,
Field_longstr
::
make_packed_sort_key_part
(
uchar
*
buff
,
const
SORT_FIELD_ATTR
*
sort_field
)
const
SORT_FIELD_ATTR
*
sort_field
)
...
...
sql/field.h
View file @
23bd5607
...
@@ -1468,6 +1468,9 @@ class Field: public Value_source
...
@@ -1468,6 +1468,9 @@ class Field: public Value_source
virtual
uint
make_packed_sort_key_part
(
uchar
*
buff
,
virtual
uint
make_packed_sort_key_part
(
uchar
*
buff
,
const
SORT_FIELD_ATTR
*
sort_field
);
const
SORT_FIELD_ATTR
*
sort_field
);
virtual
uint
make_packed_key_part
(
uchar
*
buff
,
const
SORT_FIELD_ATTR
*
sort_field
);
virtual
void
make_send_field
(
Send_field
*
);
virtual
void
make_send_field
(
Send_field
*
);
/*
/*
...
@@ -2213,6 +2216,8 @@ class Field_longstr :public Field_str
...
@@ -2213,6 +2216,8 @@ class Field_longstr :public Field_str
bool
is_packable
()
const
override
{
return
true
;
}
bool
is_packable
()
const
override
{
return
true
;
}
uint
make_packed_sort_key_part
(
uchar
*
buff
,
uint
make_packed_sort_key_part
(
uchar
*
buff
,
const
SORT_FIELD_ATTR
*
sort_field
)
override
;
const
SORT_FIELD_ATTR
*
sort_field
)
override
;
uint
make_packed_key_part
(
uchar
*
buff
,
const
SORT_FIELD_ATTR
*
sort_field
)
override
;
uchar
*
pack_sort_string
(
uchar
*
to
,
const
SORT_FIELD_ATTR
*
sort_field
);
uchar
*
pack_sort_string
(
uchar
*
to
,
const
SORT_FIELD_ATTR
*
sort_field
);
};
};
...
...
sql/filesort.cc
View file @
23bd5607
...
@@ -2587,7 +2587,7 @@ uint32 Sort_param::get_record_length_for_unique(uchar *to,
...
@@ -2587,7 +2587,7 @@ uint32 Sort_param::get_record_length_for_unique(uchar *to,
{
{
if
(
!
using_packed_sortkeys
())
if
(
!
using_packed_sortkeys
())
return
rec_length
;
return
rec_length
;
return
Variable_size_
keys_descriptor
::
read_packed_length
(
to
)
+
return
Variable_size_
composite_key_desc
::
read_packed_length
(
to
)
+
size_of_dupl_count
;
size_of_dupl_count
;
}
}
...
@@ -3018,6 +3018,28 @@ int SORT_FIELD_ATTR::compare_packed_fixed_size_vals(uchar *a, size_t *a_len,
...
@@ -3018,6 +3018,28 @@ int SORT_FIELD_ATTR::compare_packed_fixed_size_vals(uchar *a, size_t *a_len,
}
}
int
SORT_FIELD
::
compare_fixed_size_vals
(
uchar
*
a
,
size_t
*
a_len
,
uchar
*
b
,
size_t
*
b_len
)
{
if
(
maybe_null
)
{
*
a_len
=
1
;
*
b_len
=
1
;
int
cmp_val
;
if
((
cmp_val
=
compare_nullability
(
a
,
b
))
||
*
a
==
0
)
return
cmp_val
;
a
++
;
b
++
;
}
else
*
a_len
=
*
b_len
=
0
;
*
a_len
+=
length
;
*
b_len
+=
length
;
return
field
->
cmp
(
a
,
b
);
}
/*
/*
@brief
@brief
Comparison function to compare two packed sort keys
Comparison function to compare two packed sort keys
...
...
sql/item_sum.cc
View file @
23bd5607
...
@@ -974,7 +974,7 @@ void Aggregator_distinct::clear()
...
@@ -974,7 +974,7 @@ void Aggregator_distinct::clear()
@retval
@retval
-1 NULL value, record rejected
-1 NULL value, record rejected
0 record succesfully inserted into the tree
0 record succes
s
fully inserted into the tree
1 error
1 error
*/
*/
int
Aggregator_distinct
::
insert_record_to_unique
()
int
Aggregator_distinct
::
insert_record_to_unique
()
...
@@ -3921,7 +3921,7 @@ Item_func_group_concat::dump_leaf_variable_sized_key(void *key_arg,
...
@@ -3921,7 +3921,7 @@ Item_func_group_concat::dump_leaf_variable_sized_key(void *key_arg,
pos
=
item
->
unique_filter
->
get_descriptor
()
->
get_sortorder
();
pos
=
item
->
unique_filter
->
get_descriptor
()
->
get_sortorder
();
key_end
=
key
+
item
->
unique_filter
->
get_full_size
();
key_end
=
key
+
item
->
unique_filter
->
get_full_size
();
key
+=
Variable_size_
keys_descriptor
::
size_of_length_field
;
key
+=
Variable_size_
composite_key_desc
::
size_of_length_field
;
ulonglong
*
offset_limit
=
&
item
->
copy_offset_limit
;
ulonglong
*
offset_limit
=
&
item
->
copy_offset_limit
;
ulonglong
*
row_limit
=
&
item
->
copy_row_limit
;
ulonglong
*
row_limit
=
&
item
->
copy_row_limit
;
...
@@ -4794,7 +4794,7 @@ bool Item_sum::is_packing_allowed(TABLE *table, uint* total_length)
...
@@ -4794,7 +4794,7 @@ bool Item_sum::is_packing_allowed(TABLE *table, uint* total_length)
Unique::size_of_lengt_field is the length bytes to store the packed length
Unique::size_of_lengt_field is the length bytes to store the packed length
for each record inserted in the Unique tree
for each record inserted in the Unique tree
*/
*/
(
*
total_length
)
+=
Variable_size_
keys_descriptor
::
size_of_length_field
+
(
*
total_length
)
+=
Variable_size_
composite_key_desc
::
size_of_length_field
+
size_of_packable_fields
;
size_of_packable_fields
;
return
true
;
return
true
;
}
}
...
@@ -4817,7 +4817,7 @@ Item_sum::get_unique(qsort_cmp2 comp_func, void *comp_func_fixed_arg,
...
@@ -4817,7 +4817,7 @@ Item_sum::get_unique(qsort_cmp2 comp_func, void *comp_func_fixed_arg,
if
(
number_of_args
==
1
)
if
(
number_of_args
==
1
)
desc
=
new
Variable_size_keys_simple
(
size_arg
);
desc
=
new
Variable_size_keys_simple
(
size_arg
);
else
else
desc
=
new
Variable_size_
keys_descriptor
(
size_arg
);
desc
=
new
Variable_size_
composite_key_desc
(
size_arg
);
}
}
else
else
{
{
...
@@ -4850,7 +4850,7 @@ Item_func_group_concat::get_unique(qsort_cmp2 comp_func,
...
@@ -4850,7 +4850,7 @@ Item_func_group_concat::get_unique(qsort_cmp2 comp_func,
if
(
number_of_args
==
1
)
if
(
number_of_args
==
1
)
desc
=
new
Variable_size_keys_simple
(
size_arg
);
desc
=
new
Variable_size_keys_simple
(
size_arg
);
else
else
desc
=
new
Variable_size_
keys_descriptor
(
size_arg
);
desc
=
new
Variable_size_
composite_key_desc
(
size_arg
);
}
}
else
else
{
{
...
...
sql/sql_class.h
View file @
23bd5607
...
@@ -6461,6 +6461,8 @@ struct SORT_FIELD: public SORT_FIELD_ATTR
...
@@ -6461,6 +6461,8 @@ struct SORT_FIELD: public SORT_FIELD_ATTR
void
setup
(
Field
*
fld
,
bool
with_suffix
);
void
setup
(
Field
*
fld
,
bool
with_suffix
);
void
setup
(
Item
*
item
,
bool
with_suffix
);
void
setup
(
Item
*
item
,
bool
with_suffix
);
void
setup_for_fixed_size_keys
(
Field
*
fld
);
void
setup_for_fixed_size_keys
(
Field
*
fld
);
int
compare_fixed_size_vals
(
uchar
*
a
,
size_t
*
a_len
,
uchar
*
b
,
size_t
*
b_len
);
};
};
...
...
sql/sql_statistics.cc
View file @
23bd5607
...
@@ -1527,7 +1527,7 @@ class Stat_table_write_iter
...
@@ -1527,7 +1527,7 @@ class Stat_table_write_iter
*/
*/
uint
get_offset_to_value
(
Field
*
field
)
uint
get_offset_to_value
(
Field
*
field
)
{
{
return
Variable_size_
keys_descriptor
::
size_of_length_field
+
return
Variable_size_
composite_key_desc
::
size_of_length_field
+
MY_TEST
(
field
->
maybe_null
());
MY_TEST
(
field
->
maybe_null
());
}
}
...
@@ -1538,7 +1538,7 @@ uint get_offset_to_value(Field *field)
...
@@ -1538,7 +1538,7 @@ uint get_offset_to_value(Field *field)
*/
*/
uchar
*
get_buffer_end
(
Field
*
field
,
uchar
*
to
)
uchar
*
get_buffer_end
(
Field
*
field
,
uchar
*
to
)
{
{
return
to
+
Variable_size_
keys_descriptor
::
read_packed_length
(
to
);
return
to
+
Variable_size_
composite_key_desc
::
read_packed_length
(
to
);
}
}
...
@@ -1719,7 +1719,7 @@ class Count_distinct_field: public Sql_alloc
...
@@ -1719,7 +1719,7 @@ class Count_distinct_field: public Sql_alloc
tree_key_length
=
table_field
->
tree_key_length
=
table_field
->
max_packed_col_length
(
table_field
->
pack_length
());
max_packed_col_length
(
table_field
->
pack_length
());
tree_key_length
+=
Variable_size_
keys_descriptor
::
size_of_length_field
;
tree_key_length
+=
Variable_size_
composite_key_desc
::
size_of_length_field
;
tree_key_length
+=
MY_TEST
(
table_field
->
maybe_null
());
tree_key_length
+=
MY_TEST
(
table_field
->
maybe_null
());
desc
=
new
Variable_size_keys_simple
(
tree_key_length
);
desc
=
new
Variable_size_keys_simple
(
tree_key_length
);
...
...
sql/uniques.cc
View file @
23bd5607
...
@@ -876,7 +876,7 @@ int Unique_impl::write_record_to_file(uchar *key)
...
@@ -876,7 +876,7 @@ int Unique_impl::write_record_to_file(uchar *key)
}
}
Variable_size_
keys_descriptor
::
Variable_size_keys_descriptor
(
uint
length
)
Variable_size_
composite_key_desc
::
Variable_size_composite_key_desc
(
uint
length
)
{
{
max_length
=
length
;
max_length
=
length
;
flags
=
(
1
<<
VARIABLE_SIZED_KEYS_WITH_ORIGINAL_VALUES
);
flags
=
(
1
<<
VARIABLE_SIZED_KEYS_WITH_ORIGINAL_VALUES
);
...
@@ -889,7 +889,7 @@ Variable_size_keys_descriptor::Variable_size_keys_descriptor(uint length)
...
@@ -889,7 +889,7 @@ Variable_size_keys_descriptor::Variable_size_keys_descriptor(uint length)
}
}
Variable_size_
keys_descriptor
::~
Variable_size_keys_descriptor
()
Variable_size_
composite_key_desc
::~
Variable_size_composite_key_desc
()
{
{
my_free
(
packed_rec_ptr
);
my_free
(
packed_rec_ptr
);
}
}
...
@@ -903,7 +903,7 @@ Variable_size_keys_descriptor::~Variable_size_keys_descriptor()
...
@@ -903,7 +903,7 @@ Variable_size_keys_descriptor::~Variable_size_keys_descriptor()
0 NULL value
0 NULL value
>0 length of the packed record
>0 length of the packed record
*/
*/
uint
Variable_size_
keys_descriptor
::
make_packed_record
(
bool
exclude_nulls
)
uint
Variable_size_
composite_key_desc
::
make_packed_record
(
bool
exclude_nulls
)
{
{
Field
*
field
;
Field
*
field
;
SORT_FIELD
*
sort_field
;
SORT_FIELD
*
sort_field
;
...
@@ -920,7 +920,7 @@ uint Variable_size_keys_descriptor::make_packed_record(bool exclude_nulls)
...
@@ -920,7 +920,7 @@ uint Variable_size_keys_descriptor::make_packed_record(bool exclude_nulls)
if
((
field
=
sort_field
->
field
))
if
((
field
=
sort_field
->
field
))
{
{
// Field
// Field
length
=
field
->
make_packed_
sort_
key_part
(
to
,
sort_field
);
length
=
field
->
make_packed_key_part
(
to
,
sort_field
);
}
}
else
else
{
// Item
{
// Item
...
@@ -939,7 +939,7 @@ uint Variable_size_keys_descriptor::make_packed_record(bool exclude_nulls)
...
@@ -939,7 +939,7 @@ uint Variable_size_keys_descriptor::make_packed_record(bool exclude_nulls)
to
+=
length
;
to
+=
length
;
}
}
length
=
static_cast
<
int
>
(
to
-
orig_to
);
length
=
static_cast
<
u
int
>
(
to
-
orig_to
);
store_packed_length
(
orig_to
,
length
);
store_packed_length
(
orig_to
,
length
);
return
length
;
return
length
;
}
}
...
@@ -964,8 +964,8 @@ uint Variable_size_keys_descriptor::make_packed_record(bool exclude_nulls)
...
@@ -964,8 +964,8 @@ uint Variable_size_keys_descriptor::make_packed_record(bool exclude_nulls)
*/
*/
bool
bool
Variable_size_
keys_descriptor
::
setup
(
THD
*
thd
,
Item_sum
*
item
,
Variable_size_
composite_key_desc
::
setup
(
THD
*
thd
,
Item_sum
*
item
,
uint
non_const_args
,
uint
arg_count
)
uint
non_const_args
,
uint
arg_count
)
{
{
SORT_FIELD
*
sort
,
*
pos
;
SORT_FIELD
*
sort
,
*
pos
;
if
(
sortorder
)
if
(
sortorder
)
...
@@ -1010,7 +1010,7 @@ Variable_size_keys_descriptor::setup(THD *thd, Item_sum *item,
...
@@ -1010,7 +1010,7 @@ Variable_size_keys_descriptor::setup(THD *thd, Item_sum *item,
FALSE setup successful
FALSE setup successful
*/
*/
bool
Variable_size_
keys_descriptor
::
setup
(
THD
*
thd
,
Field
*
field
)
bool
Variable_size_
composite_key_desc
::
setup
(
THD
*
thd
,
Field
*
field
)
{
{
SORT_FIELD
*
sort
,
*
pos
;
SORT_FIELD
*
sort
,
*
pos
;
if
(
sortorder
)
if
(
sortorder
)
...
@@ -1044,11 +1044,27 @@ bool Variable_size_keys_descriptor::setup(THD *thd, Field *field)
...
@@ -1044,11 +1044,27 @@ bool Variable_size_keys_descriptor::setup(THD *thd, Field *field)
*/
*/
int
Variable_size_
keys_descriptor
::
compare_keys
(
uchar
*
a_ptr
,
int
Variable_size_
composite_key_desc
::
compare_keys
(
uchar
*
a_ptr
,
uchar
*
b_ptr
)
uchar
*
b_ptr
)
{
{
return
sort_keys
->
compare_keys
(
a_ptr
+
size_of_length_field
,
uchar
*
a
=
a_ptr
+
Variable_size_composite_key_desc
::
size_of_length_field
;
b_ptr
+
size_of_length_field
);
uchar
*
b
=
b_ptr
+
Variable_size_composite_key_desc
::
size_of_length_field
;
int
retval
=
0
;
size_t
a_len
,
b_len
;
for
(
SORT_FIELD
*
sort_field
=
sort_keys
->
begin
();
sort_field
!=
sort_keys
->
end
();
sort_field
++
)
{
retval
=
sort_field
->
is_variable_sized
()
?
sort_field
->
compare_packed_varstrings
(
a
,
&
a_len
,
b
,
&
b_len
)
:
sort_field
->
compare_packed_fixed_size_vals
(
a
,
&
a_len
,
b
,
&
b_len
);
if
(
retval
)
return
sort_field
->
reverse
?
-
retval
:
retval
;
a
+=
a_len
;
b
+=
b_len
;
}
return
retval
;
}
}
...
@@ -1060,7 +1076,7 @@ int Variable_size_keys_simple::compare_keys(uchar *a, uchar *b)
...
@@ -1060,7 +1076,7 @@ int Variable_size_keys_simple::compare_keys(uchar *a, uchar *b)
Variable_size_keys_simple
::
Variable_size_keys_simple
(
uint
length
)
Variable_size_keys_simple
::
Variable_size_keys_simple
(
uint
length
)
:
Variable_size_
keys_descriptor
(
length
)
:
Variable_size_
composite_key_desc
(
length
)
{}
{}
...
...
sql/uniques.h
View file @
23bd5607
...
@@ -161,10 +161,53 @@ class Fixed_size_composite_keys_descriptor : public Fixed_size_keys_descriptor
...
@@ -161,10 +161,53 @@ class Fixed_size_composite_keys_descriptor : public Fixed_size_keys_descriptor
};
};
class
Encode_record
:
public
Sql_alloc
{
private:
/*
Packed record ptr for a record of the table, the packed value in this
record is added to the unique tree
*/
uchar
*
rec_ptr
;
String
tmp_buffer
;
public:
Encode_record
()
{
rec_ptr
=
NULL
;
}
virtual
~
Encode_record
()
{}
virtual
uint
make_record
()
{
return
0
;
}
uchar
*
get_packed_rec_ptr
()
{
return
rec_ptr
;
}
};
class
Encode_record_for_count_distinct
:
public
Encode_record
{
public:
Encode_record_for_count_distinct
()
:
Encode_record
()
{}
~
Encode_record_for_count_distinct
()
{}
uint
make_record
()
override
{
return
0
;
}
};
class
Encode_record_for_group_concat
:
public
Encode_record
{
public:
Encode_record_for_group_concat
()
:
Encode_record
()
{}
~
Encode_record_for_group_concat
()
{}
uint
make_record
()
override
{
return
0
;
}
};
/*
/*
Descriptor for variable size keys
Descriptor for variable size keys
*/
*/
class
Variable_size_
keys_descriptor
:
public
Descriptor
class
Variable_size_
composite_key_desc
:
public
Descriptor
{
{
protected:
protected:
/*
/*
...
@@ -176,8 +219,8 @@ class Variable_size_keys_descriptor : public Descriptor
...
@@ -176,8 +219,8 @@ class Variable_size_keys_descriptor : public Descriptor
String
tmp_buffer
;
String
tmp_buffer
;
public:
public:
Variable_size_
keys_descriptor
(
uint
length
);
Variable_size_
composite_key_desc
(
uint
length
);
virtual
~
Variable_size_
keys_descriptor
();
virtual
~
Variable_size_
composite_key_desc
();
Sort_keys
*
get_keys
()
{
return
sort_keys
;
}
Sort_keys
*
get_keys
()
{
return
sort_keys
;
}
SORT_FIELD
*
get_sortorder
()
{
return
sortorder
;
}
SORT_FIELD
*
get_sortorder
()
{
return
sortorder
;
}
...
@@ -209,7 +252,7 @@ class Variable_size_keys_descriptor : public Descriptor
...
@@ -209,7 +252,7 @@ class Variable_size_keys_descriptor : public Descriptor
/* Descriptor for variable size keys with only one component */
/* Descriptor for variable size keys with only one component */
class
Variable_size_keys_simple
:
public
Variable_size_
keys_descriptor
class
Variable_size_keys_simple
:
public
Variable_size_
composite_key_desc
{
{
public:
public:
Variable_size_keys_simple
(
uint
length
);
Variable_size_keys_simple
(
uint
length
);
...
...
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