diff --git a/sql/item_strfunc.cc b/sql/item_strfunc.cc
index 094a0c5631980cd0bf59e998d9676b3cd5d7ed6e..1e1cc123e606ec5c218ffb6e7e9cdb375168a136 100644
--- a/sql/item_strfunc.cc
+++ b/sql/item_strfunc.cc
@@ -2176,6 +2176,9 @@ void Item_func_lpad::fix_length_and_dec()
   {
     ulonglong length= ((ulonglong) args[1]->val_int() *
                        collation.collation->mbmaxlen);
+    /*a comment before (merged) */
+    length= max((ulonglong)args[0]->max_length, length);
+    /*a comment after */
     if (length >= MAX_BLOB_WIDTH)
     {
       length= MAX_BLOB_WIDTH;