summaryrefslogtreecommitdiff
path: root/sql/field.h
diff options
context:
space:
mode:
authorAlexander Barkov <bar@mariadb.com>2020-07-24 08:07:04 +0400
committerAlexander Barkov <bar@mariadb.com>2020-08-14 10:07:03 +0400
commitc55f24cd99f3c6f001c210bc83f1f6b5b106bf83 (patch)
treef5848cc23228279559ba86c7e4bd2c48b0373d7d /sql/field.h
parentf1a9700fec8312bdce3e7a7145389adede1722b2 (diff)
downloadmariadb-git-c55f24cd99f3c6f001c210bc83f1f6b5b106bf83.tar.gz
MDEV-23162 Improve Protocol performance for numeric data
An alternative implementation (replacing the one based on repertoire). This implementation makes Field send itself to Protocol_text using data type specific Protocol methods rather than field->val_str() followed by protocol_text->store_str(). As now Field sends itself in the same way to all protocol types (e.g. Protocol_binary, Protocol_text, Protocol_local), the method Field::send_binary() was renamed just to Field::send(). Note, this change introduces symmetry between Field and Item, because Items also send themself using a single method Item::send(), which is used for *all* protocol types. Performance improvement is achieved by the fact that Protocol_text implements these data type specific methods using store_numeric_string_aux() rather than store_string_aux(). The conversion now happens only when character_set_results is not ASCII compatible character sets (e.g. UCS2, UTF16, UTF32). In the old code (before any MDEV-23162 work, e.g. as of 10.5.4), Protocol_text::store(Field*) used val_str() for all data types. So the execution went through the character set conversion routines even for numeric and temporal data types. Benchmarking summary (see details in MDEV-23478): The new approach stably demonstrates additional improvement comparing to the previous implementation (the smaller time - the better): Original - the commit before MDEV-23162 be98036f25ac8cfb34fa5bb5066975d79f595aec 1m9.336s 1m9.290s 1m9.300s MDEV-23162 - the repertoire optimization 1m6.101s 1m5.988s 1m6.264s MDEV-23478 - this commit 1m2.150s 1m2.079s 1m2.099s
Diffstat (limited to 'sql/field.h')
-rw-r--r--sql/field.h56
1 files changed, 40 insertions, 16 deletions
diff --git a/sql/field.h b/sql/field.h
index 0f531564116..2c73fed708b 100644
--- a/sql/field.h
+++ b/sql/field.h
@@ -37,6 +37,7 @@
class Send_field;
class Copy_field;
class Protocol;
+class Protocol_text;
class Create_field;
class Relay_log_info;
class Field;
@@ -1576,7 +1577,7 @@ public:
ptr= old_ptr;
return str;
}
- virtual bool send_binary(Protocol *protocol);
+ virtual bool send(Protocol *protocol);
virtual uchar *pack(uchar *to, const uchar *from, uint max_length);
/**
@@ -2005,6 +2006,9 @@ protected:
return (flags & UNSIGNED_FLAG) ? Binlog_type_info::SIGN_UNSIGNED :
Binlog_type_info::SIGN_SIGNED;
}
+ bool send_numeric_zerofill_str(Protocol_text *protocol,
+ protocol_send_type_t send_type);
+
public:
const uint8 dec;
bool zerofill,unsigned_flag; // Purify cannot handle bit fields
@@ -2194,6 +2198,7 @@ public:
int store_decimal(const my_decimal *d) override;
uint32 max_data_length() const override;
void make_send_field(Send_field *) override;
+ bool send(Protocol *protocol) override;
bool is_varchar_and_in_write_set() const override
{
@@ -2520,7 +2525,7 @@ public:
double val_real() override;
longlong val_int() override;
String *val_str(String *, String *) override;
- bool send_binary(Protocol *protocol) override;
+ bool send(Protocol *protocol) override;
int cmp(const uchar *,const uchar *) const override;
void sort_string(uchar *buff,uint length) override;
uint32 pack_length() const override { return 1; }
@@ -2583,7 +2588,7 @@ public:
double val_real() override;
longlong val_int() override;
String *val_str(String *, String *) override;
- bool send_binary(Protocol *protocol) override;
+ bool send(Protocol *protocol) override;
int cmp(const uchar *,const uchar *) const override;
void sort_string(uchar *buff,uint length) override;
uint32 pack_length() const override { return 2; }
@@ -2630,7 +2635,7 @@ public:
double val_real() override;
longlong val_int() override;
String *val_str(String *, String *) override;
- bool send_binary(Protocol *protocol) override;
+ bool send(Protocol *protocol) override;
int cmp(const uchar *,const uchar *) const override;
void sort_string(uchar *buff,uint length) override;
uint32 pack_length() const override { return 3; }
@@ -2681,7 +2686,7 @@ public:
int reset() override { ptr[0]=ptr[1]=ptr[2]=ptr[3]=0; return 0; }
double val_real() override;
longlong val_int() override;
- bool send_binary(Protocol *protocol) override;
+ bool send(Protocol *protocol) override;
String *val_str(String *, String *) override;
int cmp(const uchar *,const uchar *) const override;
void sort_string(uchar *buff,uint length) override;
@@ -2743,7 +2748,7 @@ public:
double val_real() override;
longlong val_int() override;
String *val_str(String *, String *) override;
- bool send_binary(Protocol *protocol) override;
+ bool send(Protocol *protocol) override;
int cmp(const uchar *,const uchar *) const override;
void sort_string(uchar *buff,uint length) override;
uint32 pack_length() const override { return 8; }
@@ -2843,7 +2848,7 @@ public:
double val_real() override;
longlong val_int() override;
String *val_str(String *, String *) override;
- bool send_binary(Protocol *protocol) override;
+ bool send(Protocol *protocol) override;
int cmp(const uchar *,const uchar *) const override;
void sort_string(uchar *buff, uint length) override;
uint32 pack_length() const override { return sizeof(float); }
@@ -2907,7 +2912,7 @@ public:
longlong val_int() override final { return val_int_from_real(false); }
ulonglong val_uint() override final { return (ulonglong) val_int_from_real(true); }
String *val_str(String *, String *) override final;
- bool send_binary(Protocol *protocol) override final;
+ bool send(Protocol *protocol) override;
int cmp(const uchar *,const uchar *) const override final;
void sort_string(uchar *buff, uint length) override final;
uint32 pack_length() const override final { return sizeof(double); }
@@ -3210,7 +3215,7 @@ public:
{
return (double) Field_timestamp0::val_int();
}
- bool send_binary(Protocol *protocol) override;
+ bool send(Protocol *protocol) override;
int cmp(const uchar *,const uchar *) const override;
void sort_string(uchar *buff,uint length) override;
uint32 pack_length() const override { return 4; }
@@ -3265,7 +3270,7 @@ public:
DBUG_ASSERT(length == pack_length());
memcpy(to, ptr, length);
}
- bool send_binary(Protocol *protocol) override;
+ bool send(Protocol *protocol) override;
double val_real() override;
my_decimal* val_decimal(my_decimal*) override;
int set_time() override;
@@ -3403,7 +3408,7 @@ public:
longlong val_int() override;
String *val_str(String *, String *) override;
bool get_date(MYSQL_TIME *ltime, date_mode_t fuzzydate) override;
- bool send_binary(Protocol *protocol) override;
+ bool send(Protocol *protocol) override;
Information_schema_numeric_attributes
information_schema_numeric_attributes() const override
{
@@ -3462,7 +3467,7 @@ public:
double val_real() override;
longlong val_int() override;
String *val_str(String *, String *) override;
- bool send_binary(Protocol *protocol) override;
+ bool send(Protocol *protocol) override;
int cmp(const uchar *,const uchar *) const override;
void sort_string(uchar *buff,uint length) override;
uint32 pack_length() const override { return 4; }
@@ -3501,7 +3506,7 @@ public:
double val_real() override;
longlong val_int() override;
String *val_str(String *, String *) override;
- bool send_binary(Protocol *protocol) override;
+ bool send(Protocol *protocol) override;
int cmp(const uchar *,const uchar *) const override;
void sort_string(uchar *buff,uint length) override;
uint32 pack_length() const override { return 3; }
@@ -3561,7 +3566,7 @@ public:
int store(longlong nr, bool unsigned_val) override;
int store_decimal(const my_decimal *) override;
String *val_str(String *, String *) override;
- bool send_binary(Protocol *protocol) override;
+ bool send(Protocol *protocol) override;
void set_curdays(THD *thd);
Field *new_key_field(MEM_ROOT *root, TABLE *new_table,
uchar *new_ptr, uint32 length,
@@ -3775,7 +3780,7 @@ public:
}
longlong val_int() override;
String *val_str(String *, String *) override;
- bool send_binary(Protocol *protocol) override;
+ bool send(Protocol *protocol) override;
int cmp(const uchar *,const uchar *) const override;
void sort_string(uchar *buff,uint length) override;
uint32 pack_length() const override { return 8; }
@@ -3815,7 +3820,7 @@ public:
uint decimals() const override final { return dec; }
enum ha_base_keytype key_type() const override final { return HA_KEYTYPE_BINARY; }
void make_send_field(Send_field *field) override final;
- bool send_binary(Protocol *protocol) override final;
+ bool send(Protocol *protocol) override final;
uchar *pack(uchar *to, const uchar *from, uint max_length) override final
{ return Field::pack(to, from, max_length); }
const uchar *unpack(uchar* to, const uchar *from, const uchar *from_end,
@@ -4153,6 +4158,7 @@ public:
longlong val_int() override;
String *val_str(String *, String *) override;
my_decimal *val_decimal(my_decimal *) override;
+ bool send(Protocol *protocol) override;
int cmp(const uchar *a,const uchar *b) const override;
int cmp_prefix(const uchar *a, const uchar *b, size_t prefix_len) const
override;
@@ -4217,6 +4223,15 @@ private:
double val_real() override;
longlong val_int() override;
uint size_of() const override { return sizeof *this; }
+ /*
+ We use the default Field::send() implementation,
+ because the derived optimized version (from Field_longstr)
+ is not suitable for compressed fields.
+ */
+ bool send(Protocol *protocol) override
+ {
+ return Field::send(protocol);
+ }
enum_field_types binlog_type() const override
{ return MYSQL_TYPE_VARCHAR_COMPRESSED; }
void sql_type(String &str) const override
@@ -4614,6 +4629,15 @@ private:
String *val_str(String *, String *) override;
double val_real() override;
longlong val_int() override;
+ /*
+ We use the default Field::send() implementation,
+ because the derived optimized version (from Field_longstr)
+ is not suitable for compressed fields.
+ */
+ bool send(Protocol *protocol) override
+ {
+ return Field::send(protocol);
+ }
uint size_of() const override { return sizeof *this; }
enum_field_types binlog_type() const override
{ return MYSQL_TYPE_BLOB_COMPRESSED; }