diff options
Diffstat (limited to 'sql/field.cc')
-rw-r--r-- | sql/field.cc | 122 |
1 files changed, 95 insertions, 27 deletions
diff --git a/sql/field.cc b/sql/field.cc index 1ce49b0bdfa..460c26fbfd2 100644 --- a/sql/field.cc +++ b/sql/field.cc @@ -1013,8 +1013,15 @@ CPP_UNNAMED_NS_END Static help functions *****************************************************************************/ +/* + @brief + Create a fixed size sort key part + + @param buff buffer where values are written + @param length fixed size of the sort column +*/ -void Field::make_sort_key(uchar *buff,uint length) +void Field::make_sort_key_part(uchar *buff,uint length) { if (maybe_null()) { @@ -1029,6 +1036,62 @@ void Field::make_sort_key(uchar *buff,uint length) } +/* + @brief + Create a packed sort key part + + @param buff buffer where values are written + @param sort_field sort column structure + + @retval + length of the bytes written, does not include the NULL bytes +*/ +uint +Field::make_packed_sort_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; + } + sort_string(buff, sort_field->original_length); + return sort_field->original_length; +} + + +uint +Field_longstr::make_packed_sort_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; + } + uchar *end= pack_sort_string(buff, sort_field); + return static_cast<int>(end-buff); +} + + +uchar* +Field_longstr::pack_sort_string(uchar *to, const SORT_FIELD_ATTR *sort_field) +{ + String buf; + val_str(&buf, &buf); + return to + sort_field->pack_sort_string(to, buf.lex_cstring(), + field_charset()); +} + + /** @brief Determine the relative position of the field value in a numeric interval @@ -5395,29 +5458,6 @@ static longlong read_native(const uchar *from, uint bytes) } #endif -static void store_lowendian(ulonglong num, uchar *to, uint bytes) -{ - switch(bytes) { - case 1: *to= (uchar)num; break; - case 2: int2store(to, num); break; - case 3: int3store(to, num); break; - case 4: int4store(to, num); break; - case 8: int8store(to, num); break; - default: DBUG_ASSERT(0); - } -} - -static longlong read_lowendian(const uchar *from, uint bytes) -{ - switch(bytes) { - case 1: return from[0]; - case 2: return uint2korr(from); - case 3: return uint3korr(from); - case 4: return uint4korr(from); - case 8: return sint8korr(from); - default: DBUG_ASSERT(0); return 0; - } -} void Field_timestamp_hires::store_TIMEVAL(const timeval &tv) { @@ -7030,6 +7070,27 @@ Field_longstr::report_if_important_data(const char *pstr, const char *end, } +/* + This is JSON specific. + We should eventually add Field_json_varchar and Field_json_blob + and move make_send_field() to the new classes. +*/ +void Field_longstr::make_send_field(Send_field *field) +{ + Field_str::make_send_field(field); + if (check_constraint) + { + /* + Append the format that is implicitly implied by the CHECK CONSTRAINT. + For example: + CREATE TABLE t1 (js longtext DEFAULT NULL CHECK (json_valid(a))); + SELECT j FROM t1; + will add "format=json" to the extended type info metadata for t1.js. + */ + check_constraint->expr->set_format_by_check_constraint(field); + } +} + /* Copy a string and fill with space */ int Field_string::store(const char *from, size_t length,CHARSET_INFO *cs) @@ -8013,7 +8074,7 @@ int Field_longstr::compress(char *to, uint to_length, max_length < length) { set_if_smaller(max_length, static_cast<ulonglong>(mbmaxlen()) * length + 1); - if (!(buf= (char*) my_malloc(max_length, MYF(MY_WME)))) + if (!(buf= (char*) my_malloc(PSI_INSTRUMENT_ME, max_length, MYF(MY_WME)))) { *out_length= 0; return -1; @@ -8526,8 +8587,15 @@ Binlog_type_info Field_blob::binlog_type_info() const uint32 Field_blob::sort_length() const { - return (uint32) (get_thd()->variables.max_sort_length + - (field_charset() == &my_charset_bin ? 0 : packlength)); + return packlength == 4 ? + UINT_MAX32 : + (uint32) field_length + sort_suffix_length(); +} + + +uint32 Field_blob::sort_suffix_length() const +{ + return field_charset() == &my_charset_bin ? packlength : 0; } |