diff options
author | Varun Gupta <varun.gupta@mariadb.com> | 2020-03-28 12:31:22 +0530 |
---|---|---|
committer | Varun Gupta <varun.gupta@mariadb.com> | 2020-06-29 14:04:07 +0530 |
commit | 077b71e4e5e5ad4aa2b4a7f6a1b49d457f5ceb55 (patch) | |
tree | c4a09ebb32e662a1243c23601ab6bd65a321668f /sql/item_jsonfunc.cc | |
parent | ead98fe5d34912578445d42e620c8ed95df4c433 (diff) | |
download | mariadb-git-10.5-varun2.tar.gz |
MDEV-21829: Use packed sort keys in Unique objects10.5-varun2
The task deals with packing the values stored in the Unique tree for each record.
The changes brought by this feature is:
1) Unique tree can have dynamic length keys
2) Format of keys looks like
<key_length> <packed_value1> <packed_value2> ....... <packed_valueN>
Unique class is currently used in
1) agg_func(DISTINCT col)
Here most aggregate functions like SUM, AVG accept only fixed size arguments
so it is not beneficial to use packing for these. Packing is done for
COUNT and GROUP_CONCAT (or JSON_ARRAYAGG) aggregate function as these are meaningful
2) index-merge stores row-ids
index merge stores row-ids which are of fixed size, so packing is not required
3) Engine Independent Table statistics
Packing is done here for variable length data types
This task is an extension to MDEV-21580.
Diffstat (limited to 'sql/item_jsonfunc.cc')
-rw-r--r-- | sql/item_jsonfunc.cc | 82 |
1 files changed, 81 insertions, 1 deletions
diff --git a/sql/item_jsonfunc.cc b/sql/item_jsonfunc.cc index b9a84775311..48075106206 100644 --- a/sql/item_jsonfunc.cc +++ b/sql/item_jsonfunc.cc @@ -1452,7 +1452,7 @@ append_null: } -static int append_json_value_from_field(String *str, +static bool append_json_value_from_field(String *str, Item *i, Field *f, const uchar *key, size_t offset, String *tmp_val) { if (i->type_handler()->is_bool_type()) @@ -1498,6 +1498,73 @@ append_null: } +/* + @brief + Append the value of a field in JSON format + + @param + str buffer to write the value + item JSON_ARRAYAGG item + field field whose value needs to be appended + tmp_val temp buffer + + @note + Use this function when the field has the value in its ptr. + This is currently used when packing is done for JSON_ARRAYAGG function. + In the case of packing, we have to unpack the value to Field::ptr. + + @retval + FALSE value appended in JSON format + TRUE error +*/ + +static bool append_json_value_from_field(String *str, Item *item, Field *field, + String *tmp_val) +{ + if (item->type_handler()->is_bool_type()) + { + if (field->is_null()) + goto append_null; + + longlong v_int= field->val_int(); + const char *t_f; + int t_f_len; + + if (v_int) + { + t_f= "true"; + t_f_len= 4; + } + else + { + t_f= "false"; + t_f_len= 5; + } + + return str->append(t_f, t_f_len); + } + { + if (field->is_null()) + goto append_null; + String *sv= field->val_str(tmp_val); + + if (item->is_json_type()) + return str->append(sv->ptr(), sv->length()); + + if (item->result_type() == STRING_RESULT) + { + return str->append("\"", 1) || + st_append_escaped(str, sv) || + str->append("\"", 1); + } + return st_append_escaped(str, sv); + } + +append_null: + return str->append("null", 4); +} + + static int append_json_keyname(String *str, Item *item, String *tmp_val) { String *sv= item->val_str(tmp_val); @@ -3689,6 +3756,19 @@ String *Item_func_json_arrayagg::get_str_from_field(Item *i,Field *f, } +String *Item_func_json_arrayagg::get_str_from_field(Item *i,Field *f, + String *tmp) +{ + m_tmp_json.length(0); + + if (append_json_value_from_field(&m_tmp_json, i, f, tmp)) + return NULL; + + return &m_tmp_json; + +} + + void Item_func_json_arrayagg::cut_max_length(String *result, uint old_length, uint max_length) const { |