diff options
author | Sergei Golubchik <serg@mariadb.org> | 2023-03-27 18:50:49 +0200 |
---|---|---|
committer | Sergei Golubchik <serg@mariadb.org> | 2023-03-27 21:27:27 +0200 |
commit | c2b69163934016afa4bb3b274cddaacec92fcb61 (patch) | |
tree | e626bb791fdfb7438e1bdd340da47970926c95b9 /sql | |
parent | d9808f79de992964ed802d27984c9031d72e7b9a (diff) | |
download | mariadb-git-c2b69163934016afa4bb3b274cddaacec92fcb61.tar.gz |
MDEV-19629 post-merge fixesbb-11.0-serg
* it isn't "pfs" function, don't call it Item_func_pfs,
don't use item_pfsfunc.*
* tests don't depend on performance schema, put in the main suite
* inherit from Item_str_ascii_func
* use connection collation, not utf8mb3_general_ci
* set result length in fix_length_and_dec
* do not set maybe_null
* use my_snprintf() where possible
* don't set m_value.ptr on every invocation
* update sys schema to use the format_pico_time()
* len must be size_t (compilation error on Windows)
* the correct function name for double->double is fabs()
* drop volatile hack
Diffstat (limited to 'sql')
-rw-r--r-- | sql/CMakeLists.txt | 2 | ||||
-rw-r--r-- | sql/item.h | 1 | ||||
-rw-r--r-- | sql/item_create.cc | 2 | ||||
-rw-r--r-- | sql/item_pfsfunc.cc | 135 | ||||
-rw-r--r-- | sql/item_pfsfunc.h | 54 | ||||
-rw-r--r-- | sql/item_strfunc.cc | 78 | ||||
-rw-r--r-- | sql/item_strfunc.h | 27 |
7 files changed, 107 insertions, 192 deletions
diff --git a/sql/CMakeLists.txt b/sql/CMakeLists.txt index be0e2d214e0..4938f8da02b 100644 --- a/sql/CMakeLists.txt +++ b/sql/CMakeLists.txt @@ -104,7 +104,7 @@ SET (SQL_SOURCE handler.cc hostname.cc init.cc item.cc item_buff.cc item_cmpfunc.cc item_create.cc item_func.cc item_geofunc.cc item_row.cc - item_strfunc.cc item_subselect.cc item_sum.cc item_timefunc.cc item_pfsfunc.cc + item_strfunc.cc item_subselect.cc item_sum.cc item_timefunc.cc key.cc log.cc lock.cc log_event.cc log_event_server.cc rpl_record.cc rpl_reporting.cc diff --git a/sql/item.h b/sql/item.h index 515a9abb310..5956b810d51 100644 --- a/sql/item.h +++ b/sql/item.h @@ -6371,7 +6371,6 @@ public: #include "item_jsonfunc.h" #include "item_create.h" #include "item_vers.h" -#include "item_pfsfunc.h" #endif /** diff --git a/sql/item_create.cc b/sql/item_create.cc index dc8359346a0..704d86d0ec3 100644 --- a/sql/item_create.cc +++ b/sql/item_create.cc @@ -3588,7 +3588,7 @@ Create_func_format_pico_time Create_func_format_pico_time::s_singleton; Item* Create_func_format_pico_time::create_1_arg(THD *thd, Item *arg1) { - return new (thd->mem_root) Item_func_pfs_format_pico_time(thd, arg1); + return new (thd->mem_root) Item_func_format_pico_time(thd, arg1); } diff --git a/sql/item_pfsfunc.cc b/sql/item_pfsfunc.cc deleted file mode 100644 index 8ac7df50866..00000000000 --- a/sql/item_pfsfunc.cc +++ /dev/null @@ -1,135 +0,0 @@ -/* Copyright (c) 2000, 2023, Oracle and/or its affiliates. - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License, version 2.0, - as published by the Free Software Foundation. - - This program is also distributed with certain software (including - but not limited to OpenSSL) that is licensed under separate terms, - as designated in a particular file or component or in included license - documentation. The authors of MySQL hereby grant you an additional - permission to link the program and your derivative works with the - separately licensed software that they have included with MySQL. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License, version 2.0, for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ - -/** - @file - - @brief - This file defines all performance schema native functions - FORMAT_PICO_TIME() -*/ - -#ifdef USE_PRAGMA_IMPLEMENTATION -#pragma implementation // gcc: Class implementation -#endif - -#include "mariadb.h" // HAVE_* - -/* - It is necessary to include set_var.h instead of item.h because there - are dependencies on include order for set_var.h and item.h. This - will be resolved later. -*/ -#include "set_var.h" - -/** format_pico_time() */ - -bool Item_func_pfs_format_pico_time::fix_length_and_dec(THD *) -{ - set_maybe_null(); - /* Format is 'AAAA.BB UUU' = 11 characters or 'AAA ps' = 6 characters. */ - m_value.set_charset(&my_charset_utf8mb3_general_ci); - return false; -} - - -String *Item_func_pfs_format_pico_time::val_str(String *str __attribute__ ((__unused__))) -{ - /* Evaluate the argument */ - double time_val= args[0]->val_real(); - - /* If argument is null, return null. */ - null_value= args[0]->null_value; - if (null_value) - return 0; - - constexpr uint64_t nano{1000}; - constexpr uint64_t micro{1000 * nano}; - constexpr uint64_t milli{1000 * micro}; - constexpr uint64_t sec{1000 * milli}; - constexpr uint64_t min{60 * sec}; - constexpr uint64_t hour{60 * min}; - constexpr uint64_t day{24 * hour}; - - /* Declaring 'volatile' as workaround for 32-bit optimization bug. */ - volatile double time_abs= abs(time_val); - - uint64_t divisor; - int len; - const char *unit; - - /* SI-approved time units. */ - if (time_abs >= day) - { - divisor= day; - unit= "d"; - } - else if (time_abs >= hour) - { - divisor= hour; - unit= "h"; - } - else if (time_abs >= min) - { - divisor= min; - unit= "min"; - } - else if (time_abs >= sec) - { - divisor= sec; - unit= "s"; - } - else if (time_abs >= milli) - { - divisor= milli; - unit= "ms"; - } - else if (time_abs >= micro) - { - divisor= micro; - unit= "us"; - } - else if (time_abs >= nano) - { - divisor= nano; - unit= "ns"; - } - else - { - divisor= 1; - unit= "ps"; - } - - if (divisor == 1) - len= snprintf(m_value_buffer, sizeof(m_value_buffer), "%3d %s", (int)time_val, unit); - else - { - double value= time_val / divisor; - if (abs(value) >= 100000.0) - len= snprintf(m_value_buffer, sizeof(m_value_buffer), "%4.2e %s", value, unit); - else - len= snprintf(m_value_buffer, sizeof(m_value_buffer), "%4.2f %s", value, unit); - } - - m_value.set(m_value_buffer, len, &my_charset_utf8mb3_general_ci); - return &m_value; -} diff --git a/sql/item_pfsfunc.h b/sql/item_pfsfunc.h deleted file mode 100644 index ee3c111e15c..00000000000 --- a/sql/item_pfsfunc.h +++ /dev/null @@ -1,54 +0,0 @@ -#ifndef ITEM_PFS_FUNC_INCLUDED -#define ITEM_PFS_FUNC_INCLUDED - -/* Copyright (c) 2000, 2023, Oracle and/or its affiliates. - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License, version 2.0, - as published by the Free Software Foundation. - - This program is also distributed with certain software (including - but not limited to OpenSSL) that is licensed under separate terms, - as designated in a particular file or component or in included license - documentation. The authors of MySQL hereby grant you an additional - permission to link the program and your derivative works with the - separately licensed software that they have included with MySQL. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License, version 2.0, for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ - -#ifdef USE_PRAGMA_INTERFACE -#pragma interface /* gcc class implementation */ -#endif - -#include "item_func.h" // Item_str_func, Item_int_func - -/** format_pico_time() */ - -class Item_func_pfs_format_pico_time : public Item_str_func { - String m_value; - char m_value_buffer[12]; - -public: - Item_func_pfs_format_pico_time(THD *thd, Item *a) - : Item_str_func(thd, a){}; - String *val_str(String *str __attribute__ ((__unused__))) override; - LEX_CSTRING func_name_cstring() const override - { - static LEX_CSTRING name= {STRING_WITH_LEN("format_pico_time")}; - return name; - } - bool fix_length_and_dec(THD *thd) override; - Item *get_copy(THD *thd) override - { - return get_item_copy<Item_func_pfs_format_pico_time>(thd, this); - } -}; - -#endif diff --git a/sql/item_strfunc.cc b/sql/item_strfunc.cc index b38d7086548..4b2f1aecf45 100644 --- a/sql/item_strfunc.cc +++ b/sql/item_strfunc.cc @@ -5824,6 +5824,84 @@ bool Item_func_natural_sort_key::check_vcol_func_processor(void *arg) VCOL_NON_DETERMINISTIC); } +String *Item_func_format_pico_time::val_str_ascii(String *) +{ + double time_val= args[0]->val_real(); + + null_value= args[0]->null_value; + if (null_value) + return 0; + + constexpr ulonglong nano{1000}; + constexpr ulonglong micro{1000 * nano}; + constexpr ulonglong milli{1000 * micro}; + constexpr ulonglong sec{1000 * milli}; + constexpr ulonglong min{60 * sec}; + constexpr ulonglong hour{60 * min}; + constexpr ulonglong day{24 * hour}; + + double time_abs= fabs(time_val); + + ulonglong divisor; + size_t len; + const char *unit; + + /* SI-approved time units. */ + if (time_abs >= day) + { + divisor= day; + unit= "d"; + } + else if (time_abs >= hour) + { + divisor= hour; + unit= "h"; + } + else if (time_abs >= min) + { + divisor= min; + unit= "min"; + } + else if (time_abs >= sec) + { + divisor= sec; + unit= "s"; + } + else if (time_abs >= milli) + { + divisor= milli; + unit= "ms"; + } + else if (time_abs >= micro) + { + divisor= micro; + unit= "us"; + } + else if (time_abs >= nano) + { + divisor= nano; + unit= "ns"; + } + else + { + divisor= 1; + unit= "ps"; + } + + if (divisor == 1) + len= my_snprintf(m_value_buffer, sizeof(m_value_buffer), "%3d %s", (int)time_val, unit); + else + { + double value= time_val / divisor; + if (fabs(value) >= 100000.0) + len= snprintf(m_value_buffer, sizeof(m_value_buffer), "%4.2e %s", value, unit); + else + len= my_snprintf(m_value_buffer, sizeof(m_value_buffer), "%4.2f %s", value, unit); + } + m_value.length(len); + return &m_value; +} + #ifdef WITH_WSREP #include "wsrep_mysqld.h" #include "wsrep_server_state.h" diff --git a/sql/item_strfunc.h b/sql/item_strfunc.h index 3a3c53385b0..ad68ceea3f6 100644 --- a/sql/item_strfunc.h +++ b/sql/item_strfunc.h @@ -2220,6 +2220,33 @@ public: Item *get_copy(THD *thd) override { return get_item_copy<Item_temptable_rowid>(thd, this); } }; + +class Item_func_format_pico_time : public Item_str_ascii_func +{ + /* Format is 'AAAA.BB UUU' = 11 characters or 'AAA ps' = 6 characters. */ + char m_value_buffer[12]; + String m_value; + +public: + Item_func_format_pico_time(THD *thd, Item *a): Item_str_ascii_func(thd, a) {} + String *val_str_ascii(String *) override; + LEX_CSTRING func_name_cstring() const override + { + static LEX_CSTRING name= {STRING_WITH_LEN("format_pico_time")}; + return name; + } + bool fix_length_and_dec(THD *thd) override + { + m_value.set(m_value_buffer, sizeof(m_value_buffer), default_charset()); + fix_length_and_charset(sizeof(m_value_buffer), default_charset()); + return false; + } + Item *get_copy(THD *thd) override + { + return get_item_copy<Item_func_format_pico_time>(thd, this); + } +}; + #ifdef WITH_WSREP #include "wsrep_api.h" |