summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMonty <monty@mariadb.org>2019-11-26 19:52:07 +0200
committerMonty <monty@mariadb.org>2019-11-26 19:52:07 +0200
commitd1851b3009279d91c27a1fa36d2294a3f4fd7959 (patch)
treeec5a5cc2594fee04a33a57991892549a8b29f3e7
parentdc75f3e06d3ff3c521207321e3548a83786092eb (diff)
downloadmariadb-git-d1851b3009279d91c27a1fa36d2294a3f4fd7959.tar.gz
Code cleanups
- Replace "class Repeat_count" with function call. There is no reason for this class to exists. More complex and more code than doing a function! In addition the code didn't match what the val() function was doing. Other things: - Fixed compiler failure in print_cached_tables_callback()
-rw-r--r--sql/item_strfunc.cc38
-rw-r--r--sql/sql_test.cc3
2 files changed, 18 insertions, 23 deletions
diff --git a/sql/item_strfunc.cc b/sql/item_strfunc.cc
index 78c29ac8e33..a9ee0f83b0a 100644
--- a/sql/item_strfunc.cc
+++ b/sql/item_strfunc.cc
@@ -58,25 +58,21 @@ C_MODE_END
size_t username_char_length= 80;
+/*
+ Calculate max length of string from length argument to LEFT and RIGHT
+*/
-class Repeat_count
+static uint32 max_length_for_string(Item *item)
{
- ulonglong m_count;
-public:
- Repeat_count(Item *item)
- :m_count(0)
+ ulonglong length= item->val_int();
+ /* Note that if value is NULL, val_int() returned 0 */
+ if (length > (ulonglong) INT_MAX32)
{
- Longlong_hybrid nr= item->to_longlong_hybrid();
- if (!item->null_value && !nr.neg())
- {
- // Assume that the maximum length of a String is < INT_MAX32
- m_count= (ulonglong) nr.value();
- if (m_count > (ulonglong) INT_MAX32)
- m_count= (ulonglong) INT_MAX32;
- }
+ /* Limit string length to maxium string length in MariaDB (2G) */
+ length= item->unsigned_flag ? (ulonglong) INT_MAX32 : 0;
}
- ulonglong count() const { return m_count; }
-};
+ return (uint32) length;
+}
/*
@@ -1656,8 +1652,8 @@ void Item_str_func::left_right_max_length()
uint32 char_length= args[0]->max_char_length();
if (args[1]->const_item() && !args[1]->is_expensive())
{
- Repeat_count tmp(args[1]);
- set_if_smaller(char_length, (uint) tmp.count());
+ uint32 length= max_length_for_string(args[1]);
+ set_if_smaller(char_length, length);
}
fix_char_length(char_length);
}
@@ -3025,8 +3021,8 @@ bool Item_func_repeat::fix_length_and_dec()
DBUG_ASSERT(collation.collation != NULL);
if (args[1]->const_item() && !args[1]->is_expensive())
{
- Repeat_count tmp(args[1]);
- ulonglong char_length= (ulonglong) args[0]->max_char_length() * tmp.count();
+ uint32 length= max_length_for_string(args[1]);
+ ulonglong char_length= (ulonglong) args[0]->max_char_length() * length;
fix_char_length_ulonglong(char_length);
return false;
}
@@ -3099,7 +3095,7 @@ bool Item_func_space::fix_length_and_dec()
collation.set(default_charset(), DERIVATION_COERCIBLE, MY_REPERTOIRE_ASCII);
if (args[0]->const_item() && !args[0]->is_expensive())
{
- fix_char_length_ulonglong(Repeat_count(args[0]).count());
+ fix_char_length_ulonglong(max_length_for_string(args[0]));
return false;
}
max_length= MAX_BLOB_WIDTH;
@@ -3218,7 +3214,7 @@ bool Item_func_pad::fix_length_and_dec()
DBUG_ASSERT(collation.collation->mbmaxlen > 0);
if (args[1]->const_item() && !args[1]->is_expensive())
{
- fix_char_length_ulonglong(Repeat_count(args[1]).count());
+ fix_char_length_ulonglong(max_length_for_string(args[1]));
return false;
}
max_length= MAX_BLOB_WIDTH;
diff --git a/sql/sql_test.cc b/sql/sql_test.cc
index c5d8b336e38..07e2d5e084e 100644
--- a/sql/sql_test.cc
+++ b/sql/sql_test.cc
@@ -88,9 +88,8 @@ static my_bool print_cached_tables_callback(TDC_element *element,
while ((entry= it++))
{
THD *in_use= entry->in_use;
- printf("%-14.14s %-32s%6lu%8ld%6d %s\n",
+ printf("%-14.14s %-32s%8ld%6d %s\n",
entry->s->db.str, entry->s->table_name.str,
- (ulong) element->version,
in_use ? (long) in_use->thread_id : (long) 0,
entry->db_stat ? 1 : 0,
in_use ? lock_descriptions[(int)entry->reginfo.lock_type] :