[Commits] 20fc80d: C

Oleksandr Byelkin sanja at mariadb.com
Mon Sep 26 19:15:11 EEST 2016


revision-id: 20fc80dfbd4ed1a993d07810a4f7066bfbab42ea (mariadb-5.5.52-6-g20fc80d)
parent(s): c91fdb66dbd26d832073e7b99075bfd0b5b9da11
committer: Oleksandr Byelkin
timestamp: 2016-09-26 18:15:11 +0200
message:

C

---
 sql/item_strfunc.cc | 14 +++++++++++++-
 sql/item_strfunc.h  | 28 +++++++++++++---------------
 2 files changed, 26 insertions(+), 16 deletions(-)

diff --git a/sql/item_strfunc.cc b/sql/item_strfunc.cc
index 94370d4..acbb9b1 100644
--- a/sql/item_strfunc.cc
+++ b/sql/item_strfunc.cc
@@ -2951,7 +2951,19 @@ String *Item_func_conv::val_str(String *str)
 String *Item_func_conv_charset::val_str(String *str)
 {
   DBUG_ASSERT(fixed == 1);
-  if (use_cached_value)
+  if (cached_value == CONST_WILL_BE_CACHED)
+  {
+    uint errors= 0;
+    String tmp, *str= args[0]->val_str(&tmp);
+    if (!str || str_value.copy(str->ptr(), str->length(),
+                               str->charset(), conv_charset, &errors))
+      null_value= 1;
+    cached_value= CACHED;
+    str_value.mark_as_const();
+    safe= (errors == 0);
+    expensive= FALSE;
+  }
+  if (cached_value == CACHED)
     return null_value ? 0 : &str_value;
   String *arg= args[0]->val_str(str);
   uint dummy_errors;
diff --git a/sql/item_strfunc.h b/sql/item_strfunc.h
index 7606c28..a13fe7f 100644
--- a/sql/item_strfunc.h
+++ b/sql/item_strfunc.h
@@ -817,31 +817,27 @@ class Item_func_quote :public Item_str_func
 
 class Item_func_conv_charset :public Item_str_func
 {
-  bool use_cached_value;
   String tmp_value;
+  bool expensive;
+  enum state_of_cache { NOT_CONST, CONST_WILL_BE_CACHED, CACHED };
+  enum state_of_cache cached_value;
 public:
   bool safe;
   CHARSET_INFO *conv_charset; // keep it public
-  Item_func_conv_charset(Item *a, CHARSET_INFO *cs) :Item_str_func(a) 
-  { conv_charset= cs; use_cached_value= 0; safe= 0; }
+  Item_func_conv_charset(Item *a, CHARSET_INFO *cs) :Item_str_func(a),
+    expensive(TRUE), cached_value(NOT_CONST), safe(0), conv_charset(cs)
+  {}
   Item_func_conv_charset(Item *a, CHARSET_INFO *cs, bool cache_if_const) 
-    :Item_str_func(a) 
+    :Item_str_func(a), expensive(TRUE), conv_charset(cs)
   {
-    conv_charset= cs;
-    if (cache_if_const && args[0]->const_item() && !args[0]->is_expensive())
+    if (cache_if_const && args[0]->const_item())
     {
-      uint errors= 0;
-      String tmp, *str= args[0]->val_str(&tmp);
-      if (!str || str_value.copy(str->ptr(), str->length(),
-                                 str->charset(), conv_charset, &errors))
-        null_value= 1;
-      use_cached_value= 1;
-      str_value.mark_as_const();
-      safe= (errors == 0);
+      expensive= args[0]->is_expensive();
+      cached_value= CONST_WILL_BE_CACHED;
     }
     else
     {
-      use_cached_value= 0;
+      cached_value= NOT_CONST;
       /*
         Conversion from and to "binary" is safe.
         Conversion to Unicode is safe.
@@ -892,6 +888,8 @@ class Item_func_conv_charset :public Item_str_func
   void fix_length_and_dec();
   const char *func_name() const { return "convert"; }
   virtual void print(String *str, enum_query_type query_type);
+  bool is_expensive() { return expensive; }
+  virtual bool const_item() const { return cached_value != NOT_CONST; }
 };
 
 class Item_func_set_collation :public Item_str_func


More information about the commits mailing list