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
bf4d0dcf
Commit
bf4d0dcf
authored
Jul 30, 2021
by
Michael Okoko
Committed by
Sergei Petrunia
Jan 19, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
implement parse and serialize for histogram json
parent
9bba5955
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
32 additions
and
10 deletions
+32
-10
sql/sql_statistics.cc
sql/sql_statistics.cc
+28
-8
sql/sql_statistics.h
sql/sql_statistics.h
+4
-2
No files found.
sql/sql_statistics.cc
View file @
bf4d0dcf
...
...
@@ -1261,12 +1261,6 @@ bool Histogram_binary::parse(MEM_ROOT *mem_root, Histogram_type type_arg, const
*/
void
Histogram_binary
::
serialize
(
Field
*
field
)
{
if
(
get_type
()
==
JSON
)
{
field
->
store
((
char
*
)
get_values
(),
strlen
((
char
*
)
get_values
()),
&
my_charset_bin
);
}
else
field
->
store
((
char
*
)
get_values
(),
get_width
(),
&
my_charset_bin
);
}
...
...
@@ -1287,6 +1281,32 @@ void Histogram_json::init_for_collection(MEM_ROOT *mem_root, Histogram_type htyp
size
=
(
uint8
)
size_arg
;
}
bool
Histogram_json
::
parse
(
MEM_ROOT
*
mem_root
,
Histogram_type
type_arg
,
const
uchar
*
ptr
,
uint
size_arg
)
{
size
=
(
uint8
)
size_arg
;
type
=
type_arg
;
// I think we could use memcpy here, but not sure about how to get the right size
// since we can't depend on size_arg (it's zero for json histograms)
// also, does it make sense to cast here? or we can modify json_get_array_items
// to accept uchar*
const
char
*
json
=
(
char
*
)
ptr
;
int
vt
;
bool
result
=
json_get_array_items
(
json
,
json
+
strlen
(
json
),
&
vt
,
hist_buckets
);
fprintf
(
stderr
,
"==============
\n
"
);
fprintf
(
stderr
,
"histogram: %s
\n
"
,
json
);
fprintf
(
stderr
,
"json_get_array_items() returned %s
\n
"
,
result
?
"true"
:
"false"
);
fprintf
(
stderr
,
"value type after json_get_array_items() is %d
\n
"
,
vt
);
fprintf
(
stderr
,
" JSV_BAD_JSON=%d, JSON_VALUE_ARRAY=%d
\n
"
,
(
int
)
JSV_BAD_JSON
,
(
int
)
JSON_VALUE_ARRAY
);
fprintf
(
stderr
,
"hist_buckets.size()=%zu
\n
"
,
hist_buckets
.
size
());
return
false
;
}
void
Histogram_json
::
serialize
(
Field
*
field
)
{
field
->
store
((
char
*
)
get_values
(),
strlen
((
char
*
)
get_values
()),
&
my_charset_bin
);
}
/*
An object of the class Index_stat is created to read statistical
data on tables from the statistical table table_stat, to update
...
...
@@ -1987,9 +2007,9 @@ class Count_distinct_field: public Sql_alloc
@brief
Get the pointer to the histogram built for table_field
*/
Histogram_b
inary
*
get_histogram
()
Histogram_b
ase
*
get_histogram
()
{
return
dynamic_cast
<
Histogram_binary
*>
(
table_field
->
collected_stats
->
histogram_
)
;
return
table_field
->
collected_stats
->
histogram_
;
}
};
...
...
sql/sql_statistics.h
View file @
bf4d0dcf
...
...
@@ -16,6 +16,7 @@
#ifndef SQL_STATISTICS_H
#define SQL_STATISTICS_H
#include <vector>
/*
For COMPLEMENTARY_FOR_QUERIES and PREFERABLY_FOR_QUERIES they are
similar to the COMPLEMENTARY and PREFERABLY respectively except that
...
...
@@ -341,11 +342,12 @@ class Histogram_json : public Histogram_base
Histogram_type
type
;
uint8
size
;
/* Number of elements in the histogram*/
uchar
*
values
;
std
::
vector
<
std
::
string
>
hist_buckets
;
public:
bool
parse
(
MEM_ROOT
*
mem_root
,
Histogram_type
type_arg
,
const
uchar
*
ptr
,
uint
size
)
override
{
return
false
;}
bool
parse
(
MEM_ROOT
*
mem_root
,
Histogram_type
type_arg
,
const
uchar
*
ptr
,
uint
size
)
override
;
void
serialize
(
Field
*
to_field
)
override
{}
void
serialize
(
Field
*
field
)
override
;
// returns number of buckets in the histogram
uint
get_width
()
override
...
...
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