List:Internals« Previous MessageNext Message »
From:holyfoot Date:April 13 2005 7:35am
Subject:bk commit into 5.0 tree (hf:1.1820)
View as plain text  
Below is the list of changes that have just been committed into a local
5.0 repository of hf. When hf does a push these changes will
be propagated to the main repository and, within 24 hours after the
push, to the public repository.
For information on how to access the public repository
see http://dev.mysql.com/doc/mysql/en/installing-source-tree.html

ChangeSet
  1.1820 05/04/13 12:35:03 hf@deer.(none) +32 -0
  Merging

  sql/sql_show.cc
    1.236 05/04/13 12:34:58 hf@deer.(none) +1 -4
    merging

  sql/item.cc
    1.109 05/04/13 12:34:58 hf@deer.(none) +0 -9
    merging

  mysql-test/r/union.result
    1.71 05/04/13 12:34:58 hf@deer.(none) +0 -1
    test result fixed

  mysql-test/r/sum_distinct.result
    1.5 05/04/13 12:34:58 hf@deer.(none) +93 -0
    test result fixed

  strings/decimal.c
    1.45 05/04/13 12:06:52 hf@deer.(none) +0 -0
    Auto merged

  sql/sql_select.cc
    1.315 05/04/13 12:06:52 hf@deer.(none) +0 -0
    Auto merged

  sql/sql_parse.cc
    1.441 05/04/13 12:06:51 hf@deer.(none) +0 -0
    Auto merged

  sql/sql_class.h
    1.232 05/04/13 12:06:51 hf@deer.(none) +0 -0
    Auto merged

  sql/set_var.cc
    1.104 05/04/13 12:06:51 hf@deer.(none) +0 -0
    Auto merged

  sql/mysqld.cc
    1.453 05/04/13 12:06:51 hf@deer.(none) +0 -0
    Auto merged

  sql/my_decimal.cc
    1.9 05/04/13 12:06:50 hf@deer.(none) +0 -0
    Auto merged

  sql/item_timefunc.cc
    1.80 05/04/13 12:06:50 hf@deer.(none) +0 -0
    Auto merged

  sql/item_sum.h
    1.83 05/04/13 12:06:50 hf@deer.(none) +0 -0
    Auto merged

  sql/item_sum.cc
    1.139 05/04/13 12:06:50 hf@deer.(none) +0 -0
    Auto merged

  sql/item_func.h
    1.105 05/04/13 12:06:50 hf@deer.(none) +0 -0
    Auto merged

  sql/item_cmpfunc.cc
    1.144 05/04/13 12:06:50 hf@deer.(none) +0 -0
    Auto merged

  sql/item.h
    1.114 05/04/13 12:06:50 hf@deer.(none) +0 -0
    Auto merged

  sql/field.h
    1.153 05/04/13 12:06:50 hf@deer.(none) +0 -0
    Auto merged

  sql/field.cc
    1.256 05/04/13 12:06:50 hf@deer.(none) +0 -0
    Auto merged

  mysql-test/r/view.result
    1.76 05/04/13 12:06:49 hf@deer.(none) +0 -0
    Auto merged

  mysql-test/r/variables.result
    1.61 05/04/13 12:06:49 hf@deer.(none) +0 -0
    Auto merged

  mysql-test/r/type_newdecimal.result
    1.6 05/04/13 12:06:49 hf@deer.(none) +0 -0
    Auto merged

  mysql-test/r/select.result
    1.56 05/04/13 12:06:49 hf@deer.(none) +0 -0
    Auto merged

  mysql-test/r/ps_6bdb.result
    1.26 05/04/13 12:06:49 hf@deer.(none) +0 -0
    Auto merged

  mysql-test/r/ps_5merge.result
    1.25 05/04/13 12:06:49 hf@deer.(none) +0 -0
    Auto merged

  mysql-test/r/ps_4heap.result
    1.24 05/04/13 12:06:49 hf@deer.(none) +0 -0
    Auto merged

  mysql-test/r/ps_3innodb.result
    1.28 05/04/13 12:06:49 hf@deer.(none) +0 -0
    Auto merged

  mysql-test/r/ps_2myisam.result
    1.25 05/04/13 12:06:49 hf@deer.(none) +0 -0
    Auto merged

  mysql-test/r/metadata.result
    1.11 05/04/13 12:06:48 hf@deer.(none) +0 -0
    Auto merged

  mysql-test/r/group_by.result
    1.48 05/04/13 12:06:48 hf@deer.(none) +0 -0
    Auto merged

  mysql-test/r/func_group.result
    1.44 05/04/13 12:06:48 hf@deer.(none) +0 -0
    Auto merged

  mysql-test/r/create.result
    1.85 05/04/13 12:06:48 hf@deer.(none) +0 -0
    Auto merged

# This is a BitKeeper patch.  What follows are the unified diffs for the
# set of deltas contained in the patch.  The rest of the patch, the part
# that BitKeeper cares about, is below these diffs.
# User:	hf
# Host:	deer.(none)
# Root:	/home/hf/work/mysql-5.0.8425/RESYNC

--- 1.255/sql/field.cc	Tue Apr 12 19:36:04 2005
+++ 1.256/sql/field.cc	Wed Apr 13 12:06:50 2005
@@ -2229,12 +2229,6 @@
 ** Field_new_decimal
 ****************************************************************************/
 
-/*
-  Constructors of new decimal field. In case of using NOT_FIXED_DEC it try
-  to use maximally allowed length (DECIMAL_MAX_LENGTH) and number of digits
-  after decimal point maximally close to half of this range
-  (min(DECIMAL_MAX_LENGTH/2, NOT_FIXED_DEC-1))
-*/
 Field_new_decimal::Field_new_decimal(char *ptr_arg,
                                      uint32 len_arg, uchar *null_ptr_arg,
                                      uchar null_bit_arg,
@@ -2243,17 +2237,15 @@
                                      struct st_table *table_arg,
                                      uint8 dec_arg,bool zero_arg,
                                      bool unsigned_arg)
-  :Field_num(ptr_arg,
-             (dec_arg == NOT_FIXED_DEC || len_arg > DECIMAL_MAX_LENGTH ?
-              DECIMAL_MAX_LENGTH : len_arg),
+  :Field_num(ptr_arg, len_arg,
              null_ptr_arg, null_bit_arg,
              unireg_check_arg, field_name_arg, table_arg,
-             (dec_arg == NOT_FIXED_DEC ?
-              min(DECIMAL_MAX_LENGTH / 2, NOT_FIXED_DEC - 1) :
-              dec_arg),
-             zero_arg, unsigned_arg)
+             dec_arg, zero_arg, unsigned_arg)
 {
-  bin_size= my_decimal_get_binary_size(field_length, dec);
+  precision= my_decimal_length2precision(len_arg, dec_arg);
+  DBUG_ASSERT((precision <= DECIMAL_MAX_PRECISION) &&
+              (dec <= DECIMAL_MAX_SCALE));
+  bin_size= my_decimal_get_binary_size(precision, dec);
 }
 
 
@@ -2262,17 +2254,16 @@
                                      const char *name,
                                      struct st_table *t_arg,
                                      uint8 dec_arg)
-  :Field_num((char*) 0,
-             (dec_arg == NOT_FIXED_DEC|| len_arg > DECIMAL_MAX_LENGTH ?
-              DECIMAL_MAX_LENGTH : len_arg),
+  :Field_num((char*) 0, len_arg,
              maybe_null ? (uchar*) "": 0, 0,
              NONE, name, t_arg,
-             (dec_arg == NOT_FIXED_DEC ?
-              min(DECIMAL_MAX_LENGTH / 2, NOT_FIXED_DEC - 1) :
-              dec_arg),
+             dec_arg,
              0, 0)
 {
-  bin_size= my_decimal_get_binary_size(field_length, dec);
+  precision= my_decimal_length2precision(len_arg, dec_arg);
+  DBUG_ASSERT((precision <= DECIMAL_MAX_PRECISION) &&
+              (dec <= DECIMAL_MAX_SCALE));
+  bin_size= my_decimal_get_binary_size(precision, dec);
 }
 
 
@@ -2295,7 +2286,7 @@
                                               bool sign)
 {
   DBUG_ENTER("Field_new_decimal::set_value_on_overflow");
-  max_my_decimal(decimal_value, field_length, decimals());
+  max_my_decimal(decimal_value, precision, decimals());
   if (sign)
   {
     if (unsigned_flag)
@@ -2326,10 +2317,9 @@
 
 bool Field_new_decimal::store_value(const my_decimal *decimal_value)
 {
-  my_decimal *dec= (my_decimal*)decimal_value;
   int error= 0;
   DBUG_ENTER("Field_new_decimal::store_value");
-  dbug_print_decimal("enter", "value: %s", dec);
+  dbug_print_decimal("enter", "value: %s", decimal_value);
 
   /* check that we do not try to write negative value in unsigned field */
   if (unsigned_flag && decimal_value->sign())
@@ -2337,25 +2327,22 @@
     DBUG_PRINT("info", ("unsigned overflow"));
     set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
     error= 1;
-    dec= &decimal_zero;
+    decimal_value= &decimal_zero;
   }
   DBUG_PRINT("info", ("saving with precision %d, scale: %d",
-                      (int)field_length, (int)decimals()));
-  dbug_print_decimal("info", "value: %s", dec);
+                      (int)precision, (int)dec));
+  dbug_print_decimal("info", "value: %s", decimal_value);
 
-  if (warn_if_overflow(my_decimal2binary(E_DEC_FATAL_ERROR &
-                                         ~E_DEC_OVERFLOW,
-                                         dec, ptr,
-                                         field_length,
-                                         decimals())))
+  if (warn_if_overflow(my_decimal2binary(E_DEC_FATAL_ERROR & ~E_DEC_OVERFLOW,
+                                         decimal_value, ptr, precision, dec)))
   {
     my_decimal buff;
     DBUG_PRINT("info", ("overflow"));
-    set_value_on_overflow(&buff, dec->sign());
-    my_decimal2binary(E_DEC_FATAL_ERROR, &buff, ptr, field_length, decimals());
+    set_value_on_overflow(&buff, decimal_value->sign());
+    my_decimal2binary(E_DEC_FATAL_ERROR, &buff, ptr, precision, dec);
     error= 1;
   }
-  DBUG_EXECUTE("info", print_decimal_buff(dec, (byte *) ptr, bin_size););
+  DBUG_EXECUTE("info", print_decimal_buff(decimal_value, (byte *) ptr, bin_size););
   DBUG_RETURN(error);
 }
 
@@ -2477,8 +2464,7 @@
 {
   DBUG_ENTER("Field_new_decimal::val_decimal");
   binary2my_decimal(E_DEC_FATAL_ERROR, ptr, decimal_value,
-                    field_length,
-                    decimals());
+                    precision, dec);
   DBUG_EXECUTE("info", print_decimal_buff(decimal_value, (byte *) ptr,
                                           bin_size););
   DBUG_RETURN(decimal_value);
@@ -2489,12 +2475,9 @@
                                    String *val_ptr __attribute__((unused)))
 {
   my_decimal decimal_value;
-  int fixed_precision= (zerofill ?
-                        (field_length + (decimals() ? 1 : 0)) :
-                        0);
+  int fixed_precision= zerofill ? precision : 0;
   my_decimal2string(E_DEC_FATAL_ERROR, val_decimal(&decimal_value),
-                    fixed_precision, decimals(), '0',
-                    val_buffer);
+                    fixed_precision, dec, '0', val_buffer);
   return val_buffer;
 }
 
@@ -2516,7 +2499,7 @@
 {
   CHARSET_INFO *cs= str.charset();
   str.length(cs->cset->snprintf(cs, (char*) str.ptr(), str.alloced_length(),
-                                "decimal(%d,%d)", field_length, (int)dec));
+                                "decimal(%d,%d)", precision, (int)dec));
   add_zerofill_and_unsigned(str);
 }
 

--- 1.152/sql/field.h	Tue Apr 12 23:11:55 2005
+++ 1.153/sql/field.h	Wed Apr 13 12:06:50 2005
@@ -299,8 +299,6 @@
   int warn_if_overflow(int op_result);
   /* maximum possible display length */
   virtual uint32 max_length()= 0;
-  /* length of field value symbolic representation (in bytes) */
-  virtual uint32 representation_length() { return field_length; }
   /* convert decimal to longlong with overflow check */
   longlong convert_decimal2longlong(const my_decimal *val, bool unsigned_flag,
                                     int *err);
@@ -437,6 +435,7 @@
 /* New decimal/numeric field which use fixed point arithmetic */
 class Field_new_decimal :public Field_num {
 public:
+  uint precision;
   uint bin_size;
   Field_new_decimal(char *ptr_arg, uint32 len_arg, uchar *null_ptr_arg,
                     uchar null_bit_arg,
@@ -464,10 +463,7 @@
   void sort_string(char *buff, uint length);
   bool zero_pack() const { return 0; }
   void sql_type(String &str) const;
-  uint32 max_length()
-  { return field_length + 1 + (dec ? 1 : 0) + (field_length == dec ? 1 : 0); }
-  uint32 representation_length()
-  { return field_length + 1 + (dec ? 1 : 0) + (field_length == dec ? 1 : 0); };
+  uint32 max_length() { return field_length; }
   uint size_of() const { return sizeof(*this); } 
   uint32 pack_length() const { return (uint32) bin_size; }
 };

--- 1.108/sql/item.cc	Mon Apr 11 15:08:58 2005
+++ 1.109/sql/item.cc	Wed Apr 13 12:34:58 2005
@@ -80,7 +80,7 @@
 {
   item->decimals= arg->decimals;
   item->max_length= min(arg->max_length + DECIMAL_LONGLONG_DIGITS,
-                        DECIMAL_MAX_LENGTH);
+                        DECIMAL_MAX_STR_LENGTH);
 }
 
 
@@ -303,7 +303,7 @@
 {
   marker= 0;
   maybe_null=null_value=with_sum_func=unsigned_flag=0;
-  decimals= 0; max_length= 0;
+  decimals= 0; max_length= 0; precision= 0;
 
   /* Put item in free list so that we can free all items at end */
   THD *thd= current_thd;
@@ -336,6 +336,7 @@
   max_length(item->max_length),
   marker(item->marker),
   decimals(item->decimals),
+  precision(item->precision),
   maybe_null(item->maybe_null),
   null_value(item->null_value),
   unsigned_flag(item->unsigned_flag),
@@ -748,6 +749,7 @@
   DBUG_ASSERT(it->fixed);
   max_length= it->max_length;
   decimals= it->decimals;
+  precision= it->precision;
   fixed= 1;
   return FALSE;
 }
@@ -1020,12 +1022,16 @@
   field=result_field=field_par;			// for easy coding with fields
   maybe_null=field->maybe_null();
   decimals= field->decimals();
-  max_length= field_par->representation_length();
+  max_length= field_par->field_length;
+  precision= (field->type() == FIELD_TYPE_NEWDECIMAL) ?
+    ((Field_new_decimal *)field)->precision : max_length;
   table_name= *field_par->table_name;
   field_name= field_par->field_name;
   db_name= field_par->table->s->db;
   alias_name_used= field_par->table->alias_name_used;
   unsigned_flag=test(field_par->flags & UNSIGNED_FLAG);
+  if ((field->result_type() == INT_RESULT) && !unsigned_flag)
+    max_length++;
   collation.set(field_par->charset(), DERIVATION_IMPLICIT);
   fixed= 1;
 }
@@ -1358,6 +1364,7 @@
   str2my_decimal(E_DEC_FATAL_ERROR, str_arg, length, charset, &decimal_value);
   name= (char*) str_arg;
   decimals= (uint8) decimal_value.frac;
+  precision= decimal_value.intg + decimal_value.frac;
   max_length= my_decimal_max_length(&decimal_value);
   fixed= 1;
   unsigned_flag= !decimal_value.sign();
@@ -1367,6 +1374,7 @@
 {
   int2my_decimal(E_DEC_FATAL_ERROR, val, unsig, &decimal_value);
   decimals= (uint8) decimal_value.frac;
+  precision= decimal_value.intg + decimal_value.frac;
   max_length= my_decimal_max_length(&decimal_value);
   fixed= 1;
   unsigned_flag= !decimal_value.sign();
@@ -1377,6 +1385,7 @@
 {
   double2my_decimal(E_DEC_FATAL_ERROR, val, &decimal_value);
   decimals= (uint8) decimal_value.frac;
+  precision= decimal_value.intg + decimal_value.frac;
   max_length= my_decimal_max_length(&decimal_value);
   fixed= 1;
   unsigned_flag= !decimal_value.sign();
@@ -1390,6 +1399,7 @@
   name= (char*) str;
   decimals= (uint8) decimal_par;
   max_length= length;
+  precision= my_decimal_length2precision(length, decimals);
   fixed= 1;
   unsigned_flag= !decimal_value.sign();
 }
@@ -1399,16 +1409,19 @@
 {
   my_decimal2decimal(value_par, &decimal_value);
   decimals= (uint8) decimal_value.frac;
+  precision= decimal_value.intg + decimal_value.frac;
   max_length= my_decimal_max_length(value_par);
   fixed= 1;
   unsigned_flag= !decimal_value.sign();
 }
 
 
-Item_decimal::Item_decimal(const char *bin, int precision, int scale)
+Item_decimal::Item_decimal(const char *bin, int precision_arg, int scale)
 {
-  binary2my_decimal(E_DEC_FATAL_ERROR, bin, &decimal_value, precision, scale);
+  binary2my_decimal(E_DEC_FATAL_ERROR, bin,
+                    &decimal_value, precision_arg, scale);
   decimals= (uint8) decimal_value.frac;
+  precision= precision_arg;
   max_length= my_decimal_max_length(&decimal_value);
   fixed= 1;
   unsigned_flag= !decimal_value.sign();
@@ -1621,6 +1634,7 @@
   */
   max_length= 0;
   decimals= 0;
+  precision= 0;
   state= NULL_VALUE;
   DBUG_VOID_RETURN;
 }
@@ -1632,6 +1646,7 @@
   state= INT_VALUE;
   max_length= max_length_arg;
   decimals= 0;
+  precision= max_length_arg;
   maybe_null= 0;
   DBUG_VOID_RETURN;
 }
@@ -1643,6 +1658,7 @@
   state= REAL_VALUE;
   max_length= DBL_DIG + 8;
   decimals= NOT_FIXED_DEC;
+  precision= DBL_DIG;
   maybe_null= 0;
   DBUG_VOID_RETURN;
 }
@@ -1671,7 +1687,8 @@
   str2my_decimal(E_DEC_FATAL_ERROR, str, &decimal_value, &end);
   state= DECIMAL_VALUE;
   decimals= decimal_value.frac;
-  max_length= decimal_value.intg + decimals + 2;
+  precision= decimal_value.intg + decimal_value.frac;
+  max_length= my_decimal_string_length(&decimal_value);
   maybe_null= 0;
   DBUG_VOID_RETURN;
 }
@@ -1714,6 +1731,7 @@
   maybe_null= 0;
   max_length= max_length_arg;
   decimals= 0;
+  precision= max_length_arg;
   DBUG_VOID_RETURN;
 }
 
@@ -1822,7 +1840,8 @@
       my_decimal2decimal(ent_value, &decimal_value);
       state= DECIMAL_VALUE;
       decimals= ent_value->frac;
-      max_length= ent_value->intg + decimals + 2;
+      precision= ent_value->frac + ent_value->intg;
+      max_length= my_decimal_string_length(ent_value);
       break;
     }
     default:
@@ -2155,6 +2174,7 @@
 
     max_length= str_value.length();
     decimals= 0;
+    precision= max_length;
     /*
       str_value_ptr is returned from val_str(). It must be not alloced
       to prevent it's modification by val_str() invoker.
@@ -3110,25 +3130,22 @@
 
   switch (field_type()) {
   case MYSQL_TYPE_DECIMAL:
-    return new Field_decimal((char*) 0, max_length, null_ptr, 0, Field::NONE,
-			     name, table, decimals, 0, unsigned_flag);
   case MYSQL_TYPE_NEWDECIMAL:
-    return new Field_new_decimal((char*) 0, max_length - (decimals?1:0),
-                                 null_ptr, 0,
+    return new Field_new_decimal((char*) 0, max_length, null_ptr, 0,
                                  Field::NONE, name, table, decimals, 0,
                                  unsigned_flag);
   case MYSQL_TYPE_TINY:
-    return new Field_tiny((char*) 0, max_length, null_ptr, 0, Field::NONE,
+    return new Field_tiny((char*) 0, precision, null_ptr, 0, Field::NONE,
 			  name, table, 0, unsigned_flag);
   case MYSQL_TYPE_SHORT:
-    return new Field_short((char*) 0, max_length, null_ptr, 0, Field::NONE,
+    return new Field_short((char*) 0, precision, null_ptr, 0, Field::NONE,
 			   name, table, 0, unsigned_flag);
   case MYSQL_TYPE_LONG:
-    return new Field_long((char*) 0, max_length, null_ptr, 0, Field::NONE,
+    return new Field_long((char*) 0, precision, null_ptr, 0, Field::NONE,
 			  name, table, 0, unsigned_flag);
 #ifdef HAVE_LONG_LONG
   case MYSQL_TYPE_LONGLONG:
-    return new Field_longlong((char*) 0, max_length, null_ptr, 0, Field::NONE,
+    return new Field_longlong((char*) 0, precision, null_ptr, 0, Field::NONE,
 			      name, table, 0, unsigned_flag);
 #endif
   case MYSQL_TYPE_FLOAT:
@@ -3141,7 +3158,7 @@
     return new Field_null((char*) 0, max_length, Field::NONE,
 			  name, table, &my_charset_bin);
   case MYSQL_TYPE_INT24:
-    return new Field_medium((char*) 0, max_length, null_ptr, 0, Field::NONE,
+    return new Field_medium((char*) 0, precision, null_ptr, 0, Field::NONE,
 			    name, table, 0, unsigned_flag);
   case MYSQL_TYPE_NEWDATE:
   case MYSQL_TYPE_DATE:
@@ -3402,6 +3419,7 @@
   presentation= name=(char*) str_arg;
   decimals=(uint8) nr_of_decimals(str_arg, str_arg+length);
   max_length=length;
+  precision= max_length;
   fixed= 1;
 }
 
@@ -3937,6 +3955,7 @@
   max_length= (*ref)->max_length;
   maybe_null= (*ref)->maybe_null;
   decimals=   (*ref)->decimals;
+  precision=  (*ref)->precision;
   collation.set((*ref)->collation);
   /*
     We have to remember if we refer to a sum function, to ensure that

--- 1.113/sql/item.h	Wed Apr  6 07:45:08 2005
+++ 1.114/sql/item.h	Wed Apr 13 12:06:50 2005
@@ -258,7 +258,8 @@
   Item *next;
   uint32 max_length;
   uint name_length;                     /* Length of name */
-  uint8 marker,decimals;
+  uint8 marker, decimals;
+  uint precision;
   my_bool maybe_null;			/* If item may be null */
   my_bool null_value;			/* if item is null */
   my_bool unsigned_flag;
@@ -925,13 +926,13 @@
 public:
   longlong value;
   Item_int(int32 i,uint length=11) :value((longlong) i)
-    { max_length=length; fixed= 1; }
+    { max_length=length; fixed= 1; precision= max_length;}
 #ifdef HAVE_LONG_LONG
   Item_int(longlong i,uint length=21) :value(i)
-    { max_length=length; fixed= 1;}
+    { max_length=length; fixed= 1; precision= max_length;}
 #endif
   Item_int(const char *str_arg,longlong i,uint length) :value(i)
-    { max_length=length; name=(char*) str_arg; fixed= 1; }
+    { max_length=length; precision=max_length; name=(char*) str_arg; fixed= 1; }
   Item_int(const char *str_arg, uint length=64);
   enum Type type() const { return INT_ITEM; }
   enum Item_result result_type () const { return INT_RESULT; }
@@ -1028,6 +1029,7 @@
     presentation= name=(char*) str;
     decimals=(uint8) decimal_par;
     max_length=length;
+    precision=max_length;
     fixed= 1;
   }
   Item_float(double value_par) :presentation(0), value(value_par) { fixed= 1; }
@@ -1083,6 +1085,7 @@
     max_length= str_value.numchars()*cs->mbmaxlen;
     set_name(str, length, cs);
     decimals=NOT_FIXED_DEC;
+    precision=max_length;
     // it is constant => can be used without fix_fields (and frequently used)
     fixed= 1;
   }
@@ -1094,6 +1097,7 @@
     max_length= str_value.numchars()*cs->mbmaxlen;
     set_name(name_par,0,cs);
     decimals=NOT_FIXED_DEC;
+    precision=max_length;
     // it is constant => can be used without fix_fields (and frequently used)
     fixed= 1;
   }
@@ -1397,6 +1401,7 @@
     null_value=maybe_null=item->maybe_null;
     decimals=item->decimals;
     max_length=item->max_length;
+    precision=item->precision;
     name=item->name;
     cached_field_type= item->field_type();
   }
@@ -1616,6 +1621,7 @@
     example= item;
     max_length= item->max_length;
     decimals= item->decimals;
+    precision= item->precision;
     collation.set(item->collation);
     return 0;
   };

--- 1.143/sql/item_cmpfunc.cc	Fri Apr  1 13:07:51 2005
+++ 1.144/sql/item_cmpfunc.cc	Wed Apr 13 12:06:50 2005
@@ -201,6 +201,7 @@
 void Item_bool_func2::fix_length_and_dec()
 {
   max_length= 1;				     // Function returns 0 or 1
+  precision= 1;
   THD *thd= current_thd;
 
   /*
@@ -874,6 +875,7 @@
   }
   maybe_null= 0;
   max_length= 2;
+  precision= max_length;
   used_tables_cache|= row->used_tables();
   not_null_tables_cache= row->not_null_tables();
   with_sum_func= with_sum_func || row->with_sum_func;
@@ -970,6 +972,7 @@
 void Item_func_between::fix_length_and_dec()
 {
    max_length= 1;
+   precision= 1;
    THD *thd= current_thd;
 
   /*
@@ -1111,15 +1114,15 @@
 {
   maybe_null=args[1]->maybe_null;
   decimals= max(args[0]->decimals, args[1]->decimals);
-  max_length= (max(args[0]->max_length - args[0]->decimals,
-                   args[1]->max_length - args[1]->decimals) +
-               decimals);
+  max_length= max(args[0]->max_length, args[1]->max_length);
+  precision= max(args[0]->precision, args[1]->precision);
   agg_result_type(&cached_result_type, args, 2);
   switch (cached_result_type) {
   case STRING_RESULT:
     agg_arg_charsets(collation, args, arg_count, MY_COLL_CMP_CONV);
     break;
   case DECIMAL_RESULT:
+    break;
   case REAL_RESULT:
     break;
   case INT_RESULT:
@@ -1217,9 +1220,6 @@
 {
   maybe_null=args[1]->maybe_null || args[2]->maybe_null;
   decimals= max(args[1]->decimals, args[2]->decimals);
-  max_length= (max(args[1]->max_length - args[1]->decimals,
-                   args[2]->max_length - args[2]->decimals) +
-               decimals);
   enum Item_result arg1_type=args[1]->result_type();
   enum Item_result arg2_type=args[2]->result_type();
   bool null1=args[1]->const_item() && args[1]->null_value;
@@ -1248,6 +1248,21 @@
       collation.set(&my_charset_bin);	// Number
     }
   }
+  if (cached_result_type == DECIMAL_RESULT)
+  {
+    precision= (max(args[1]->precision - args[1]->decimals,
+                    args[2]->precision - args[2]->decimals) +
+                decimals);
+    set_if_smaller(precision, DECIMAL_MAX_PRECISION);
+    max_length= my_decimal_precision2length(precision, decimals);
+  }
+  else
+  {
+    max_length= (max(args[1]->max_length - args[1]->decimals,
+                     args[2]->max_length - args[2]->decimals) +
+                 decimals);
+    precision= min(max_length, DECIMAL_MAX_PRECISION);
+  }
 }
 
 
@@ -1304,7 +1319,8 @@
   {
     max_length=args[0]->max_length;
     decimals=args[0]->decimals;
-    agg_result_type(&cached_result_type, args, 2);
+    precision=args[0]->precision;
+    cached_result_type= args[0]->result_type();
     if (cached_result_type == STRING_RESULT &&
         agg_arg_charsets(collation, args, arg_count, MY_COLL_CMP_CONV))
       return;
@@ -1603,15 +1619,18 @@
   
   max_length=0;
   decimals=0;
+  precision=0;
   for (uint i=0 ; i < ncases ; i+=2)
   {
     set_if_bigger(max_length,args[i+1]->max_length);
     set_if_bigger(decimals,args[i+1]->decimals);
+    set_if_bigger(precision, args[i+1]->precision);
   }
   if (else_expr_num != -1) 
   {
     set_if_bigger(max_length,args[else_expr_num]->max_length);
     set_if_bigger(decimals,args[else_expr_num]->decimals);
+    set_if_bigger(precision, args[else_expr_num]->precision);
   }
 }
 
@@ -2789,6 +2808,7 @@
     return TRUE;				/* purecov: inspected */
   with_sum_func=args[0]->with_sum_func || args[1]->with_sum_func;
   max_length= 1;
+  precision=max_length;
   decimals= 0;
 
   if (agg_arg_charsets(cmp_collation, args, 2, MY_COLL_CMP_CONV))

--- 1.104/sql/item_func.h	Fri Apr  1 04:13:23 2005
+++ 1.105/sql/item_func.h	Wed Apr 13 12:06:50 2005
@@ -237,7 +237,7 @@
 class Item_int_func :public Item_func
 {
 public:
-  Item_int_func() :Item_func() { max_length= 21; }
+  Item_int_func() :Item_func() { max_length= 21; precision= 21; }
   Item_int_func(Item *a) :Item_func(a) { max_length= 21; }
   Item_int_func(Item *a,Item *b) :Item_func(a,b) { max_length= 21; }
   Item_int_func(Item *a,Item *b,Item *c) :Item_func(a,b,c)
@@ -268,8 +268,7 @@
     null_value= args[0]->null_value; 
     return tmp;
   }
-  void fix_length_and_dec()
-  { max_length=args[0]->max_length; unsigned_flag=0; }
+  void fix_length_and_dec();
   void print(String *str);
 };
 
@@ -279,8 +278,7 @@
 public:
   Item_func_unsigned(Item *a) :Item_func_signed(a) {}
   const char *func_name() const { return "cast_as_unsigned"; }
-  void fix_length_and_dec()
-  { max_length=args[0]->max_length; unsigned_flag=1; }
+  void fix_length_and_dec();
   void print(String *str);
 };
 
@@ -293,13 +291,14 @@
   {
     max_length= len + 2;
     decimals= dec;
+    precision= len;
   }
   String *val_str(String *str);
   double val_real();
   longlong val_int();
   my_decimal *val_decimal(my_decimal*);
   enum Item_result result_type () const { return DECIMAL_RESULT; }
-  enum_field_types field_type() const { return MYSQL_TYPE_DECIMAL; }
+  enum_field_types field_type() const { return MYSQL_TYPE_NEWDECIMAL; }
   void fix_length_and_dec() {};
 };
 
@@ -349,6 +348,7 @@
 class Item_func_div :public Item_num_op
 {
 public:
+  uint prec_increment;
   Item_func_div(Item *a,Item *b) :Item_num_op(a,b) {}
   longlong int_op() { DBUG_ASSERT(0); return 0; }
   double real_op();

--- 1.138/sql/item_sum.cc	Sat Apr  9 06:00:34 2005
+++ 1.139/sql/item_sum.cc	Wed Apr 13 12:06:50 2005
@@ -99,8 +99,12 @@
 void Item_sum::fix_num_length_and_dec()
 {
   decimals=0;
+  precision=0;
   for (uint i=0 ; i < arg_count ; i++)
+  {
     set_if_bigger(decimals,args[i]->decimals);
+    set_if_bigger(precision,args[i]->precision);
+  }
   max_length=float_length(decimals);
 }
 
@@ -156,8 +160,7 @@
                                  collation.collation);
     return make_string_field(table);
   case DECIMAL_RESULT:
-    return new Field_new_decimal(max_length - (decimals?1:0),
-                                 maybe_null, name, table, decimals);
+    return new Field_new_decimal(max_length, maybe_null, name, table, decimals);
   case ROW_RESULT:
   default:
     // This case should never be choosen
@@ -206,12 +209,14 @@
   }
   thd->allow_sum_func=0;			// No included group funcs
   decimals=0;
+  precision=0;
   maybe_null=0;
   for (uint i=0 ; i < arg_count ; i++)
   {
     if (args[i]->fix_fields(thd, tables, args + i) || args[i]->check_cols(1))
       return TRUE;
     set_if_bigger(decimals, args[i]->decimals);
+    set_if_bigger(precision, args[i]->precision);
     maybe_null |= args[i]->maybe_null;
   }
   result_field=0;
@@ -267,6 +272,7 @@
       (item= args[0])->check_cols(1))
     return TRUE;
   decimals=item->decimals;
+  precision=item->precision;
 
   switch (hybrid_type= item->result_type()) {
   case INT_RESULT:
@@ -364,6 +370,7 @@
   DBUG_ENTER("Item_sum_sum::fix_length_and_dec");
   maybe_null=null_value=1;
   decimals= args[0]->decimals;
+  precision= args[0]->precision;
   switch (args[0]->result_type()) {
   case REAL_RESULT:
   case STRING_RESULT:
@@ -373,8 +380,9 @@
   case INT_RESULT:
   case DECIMAL_RESULT:
     /* SUM result can't be longer than length(arg) + length(MAX_ROWS) */
-    max_length= min(args[0]->max_length + DECIMAL_LONGLONG_DIGITS,
-                    DECIMAL_MAX_LENGTH);
+    precision=  min(args[0]->precision + DECIMAL_LONGLONG_DIGITS,
+                    DECIMAL_MAX_PRECISION);
+    max_length= my_decimal_precision2length(precision, decimals);
     curr_dec_buff= 0;
     hybrid_type= DECIMAL_RESULT;
     my_decimal_set_zero(dec_buffs);
@@ -723,11 +731,12 @@
 Item_sum_avg_distinct::fix_length_and_dec()
 {
   Item_sum_distinct::fix_length_and_dec();
+  prec_increment= current_thd->variables.div_precincrement;
   /*
     AVG() will divide val by count. We need to reserve digits
     after decimal point as the result can be fractional.
   */
-  decimals= min(decimals + 4, NOT_FIXED_DEC);
+  decimals= min(decimals + prec_increment, NOT_FIXED_DEC);
 }
 
 
@@ -788,14 +797,18 @@
 {
   Item_sum_sum::fix_length_and_dec();
   maybe_null=null_value=1;
-  decimals= min(args[0]->decimals + 4, NOT_FIXED_DEC);
+  prec_increment= current_thd->variables.div_precincrement;
   if (hybrid_type == DECIMAL_RESULT)
   {
-    f_scale= args[0]->decimals;
-    max_length= DECIMAL_MAX_LENGTH + (f_scale ? 1 : 0);
-    f_precision= DECIMAL_MAX_LENGTH;
+    decimals= min(args[0]->decimals + prec_increment, DECIMAL_MAX_SCALE);
+    precision= min(args[0]->precision + prec_increment, DECIMAL_MAX_PRECISION);
+    max_length= my_decimal_precision2length(precision, decimals);
+    f_precision= min(precision+DECIMAL_LONGLONG_DIGITS, DECIMAL_MAX_PRECISION);
+    f_scale=  args[0]->decimals;
     dec_bin_size= my_decimal_get_binary_size(f_precision, f_scale);
   }
+  else
+    decimals= min(args[0]->decimals + 4, NOT_FIXED_DEC);
 }
 
 
@@ -815,13 +828,13 @@
       The easyest way is to do this is to store both value in a string
       and unpack on access.
     */
-    return new Field_string(((hybrid_type == DECIMAL_RESULT) ?
-                             dec_bin_size : sizeof(double)) + sizeof(longlong),
-                            0, name, table, &my_charset_bin);
+    return
+      new Field_string(((hybrid_type == DECIMAL_RESULT) ?
+                        dec_bin_size : sizeof(double)) + sizeof(longlong),
+                       0, name, table, &my_charset_bin);
   }
   if (hybrid_type == DECIMAL_RESULT)
-    return new Field_new_decimal(f_precision,
-                                 maybe_null, name, table, f_scale);
+    return new Field_new_decimal(max_length, maybe_null, name, table, decimals);
   return new Field_double(max_length, maybe_null, name, table, decimals);
 }
 
@@ -866,7 +879,7 @@
   }
   sum_dec= Item_sum_sum::val_decimal(&sum);
   int2my_decimal(E_DEC_FATAL_ERROR, count, 0, &cnt);
-  my_decimal_div(E_DEC_FATAL_ERROR, val, sum_dec, &cnt, 4);
+  my_decimal_div(E_DEC_FATAL_ERROR, val, sum_dec, &cnt, prec_increment);
   return val;
 }
 
@@ -903,7 +916,8 @@
 
 Item_sum_variance::Item_sum_variance(THD *thd, Item_sum_variance *item):
   Item_sum_num(thd, item), hybrid_type(item->hybrid_type),
-    cur_dec(item->cur_dec), count(item->count), sample(item->sample)
+    cur_dec(item->cur_dec), count(item->count), sample(item->sample),
+    prec_increment(item->prec_increment)
 {
   if (hybrid_type == DECIMAL_RESULT)
   {
@@ -927,20 +941,20 @@
 {
   DBUG_ENTER("Item_sum_variance::fix_length_and_dec");
   maybe_null= null_value= 1;
-  decimals= min(args[0]->decimals + 4, NOT_FIXED_DEC);
+  prec_increment= current_thd->variables.div_precincrement;
   switch (args[0]->result_type()) {
   case REAL_RESULT:
   case STRING_RESULT:
+    decimals= min(args[0]->decimals + prec_increment, NOT_FIXED_DEC);
+    precision= max_length;
     hybrid_type= REAL_RESULT;
     sum= 0.0;
     break;
   case INT_RESULT:
   case DECIMAL_RESULT:
-    /*
-      SUM result can't be longer than length(arg)*2 +
-      digits_after_the_point_to_add
-    */
-    max_length= args[0]->max_length*2 + 4;
+    decimals= min(args[0]->decimals + prec_increment, DECIMAL_MAX_SCALE);
+    precision= min(args[0]->precision + prec_increment, DECIMAL_MAX_PRECISION);
+    max_length= my_decimal_precision2length(precision, decimals);
     cur_dec= 0;
     hybrid_type= DECIMAL_RESULT;
     my_decimal_set_zero(dec_sum);
@@ -952,9 +966,11 @@
       column_value * column_value
     */
     f_scale0= args[0]->decimals;
-    f_precision0= DECIMAL_MAX_LENGTH / 2;
-    f_scale1= min(f_scale0 * 2, NOT_FIXED_DEC - 1);
-    f_precision1= DECIMAL_MAX_LENGTH;
+    f_precision0= min(args[0]->precision + DECIMAL_LONGLONG_DIGITS,
+                      DECIMAL_MAX_PRECISION);
+    f_scale1= min(args[0]->decimals * 2, DECIMAL_MAX_SCALE);
+    f_precision1= min(args[0]->precision * 2 + DECIMAL_LONGLONG_DIGITS,
+                      DECIMAL_MAX_PRECISION);
     dec_bin_size0= my_decimal_get_binary_size(f_precision0, f_scale0);
     dec_bin_size1= my_decimal_get_binary_size(f_precision1, f_scale1);
     break;
@@ -995,8 +1011,7 @@
                             0, name, table, &my_charset_bin);
   }
   if (hybrid_type == DECIMAL_RESULT)
-    return new Field_new_decimal(DECIMAL_MAX_LENGTH,
-                                 maybe_null, name, table, f_scale1 + 4);
+    return new Field_new_decimal(max_length, maybe_null, name, table, decimals);
   return new Field_double(max_length, maybe_null,name,table,decimals);
 }
 
@@ -1081,9 +1096,11 @@
   int2my_decimal(E_DEC_FATAL_ERROR, count-sample, 0, &count1_buf);
   my_decimal_mul(E_DEC_FATAL_ERROR, &sum_sqr_buf,
                  dec_sum+cur_dec, dec_sum+cur_dec);
-  my_decimal_div(E_DEC_FATAL_ERROR, dec_buf, &sum_sqr_buf, &count_buf, 2);
+  my_decimal_div(E_DEC_FATAL_ERROR, dec_buf,
+                 &sum_sqr_buf, &count_buf, prec_increment);
   my_decimal_sub(E_DEC_FATAL_ERROR, &sum_sqr_buf, dec_sqr+cur_dec, dec_buf);
-  my_decimal_div(E_DEC_FATAL_ERROR, dec_buf, &sum_sqr_buf, &count1_buf, 2);
+  my_decimal_div(E_DEC_FATAL_ERROR, dec_buf,
+                 &sum_sqr_buf, &count1_buf, prec_increment);
   return dec_buf;
 }
 
@@ -1927,19 +1944,20 @@
 {
   name=item->name;
   decimals=item->decimals;
-  max_length=item->max_length;
+  precision= item->precision;
+  max_length= item->max_length;
   field=item->result_field;
   maybe_null=1;
   hybrid_type= res_type;
+  prec_increment= item->prec_increment;
   if (hybrid_type == DECIMAL_RESULT)
   {
-    f_scale= item->f_scale;
     f_precision= item->f_precision;
+    f_scale= item->f_scale;
     dec_bin_size= item->dec_bin_size;
   }
 }
 
-
 double Item_avg_field::val_real()
 {
   // fix_fields() never calls for this Item
@@ -1980,7 +1998,8 @@
   binary2my_decimal(E_DEC_FATAL_ERROR,
                     field->ptr, &dec_field, f_precision, f_scale);
   int2my_decimal(E_DEC_FATAL_ERROR, count, 0, &dec_count);
-  my_decimal_div(E_DEC_FATAL_ERROR, dec_buf, &dec_field, &dec_count, 4);
+  my_decimal_div(E_DEC_FATAL_ERROR, dec_buf,
+                 &dec_field, &dec_count, prec_increment);
   return dec_buf;
 }
 
@@ -2051,10 +2070,12 @@
 {
   name=item->name;
   decimals=item->decimals;
+  precision= item->precision;
   max_length=item->max_length;
   field=item->result_field;
   maybe_null=1;
   sample= item->sample;
+  prec_increment= item->prec_increment;
   if ((hybrid_type= item->hybrid_type) == DECIMAL_RESULT)
   {
     f_scale0= item->f_scale0;
@@ -2114,9 +2135,10 @@
   binary2my_decimal(E_DEC_FATAL_ERROR, field->ptr+dec_bin_size0,
                     &dec_sqr, f_precision1, f_scale1);
   my_decimal_mul(E_DEC_FATAL_ERROR, &tmp, &dec_sum, &dec_sum);
-  my_decimal_div(E_DEC_FATAL_ERROR, dec_buf, &tmp, &dec_count, 2);
+  my_decimal_div(E_DEC_FATAL_ERROR, dec_buf, &tmp, &dec_count, prec_increment);
   my_decimal_sub(E_DEC_FATAL_ERROR, &dec_sum, &dec_sqr, dec_buf);
-  my_decimal_div(E_DEC_FATAL_ERROR, dec_buf, &dec_sum, &dec1_count, 2);
+  my_decimal_div(E_DEC_FATAL_ERROR, dec_buf,
+                 &dec_sum, &dec1_count, prec_increment);
   return dec_buf;
 }
 

--- 1.82/sql/item_sum.h	Mon Apr  4 03:49:52 2005
+++ 1.83/sql/item_sum.h	Wed Apr 13 12:06:50 2005
@@ -237,6 +237,7 @@
   Item_sum_avg_distinct(THD *thd, Item_sum_avg_distinct *original)
     :Item_sum_distinct(thd, original) {}
 public:
+  uint prec_increment;
   Item_sum_avg_distinct(Item *item_arg) : Item_sum_distinct(item_arg) {}
 
   void fix_length_and_dec();
@@ -343,8 +344,8 @@
 public:
   Field *field;
   Item_result hybrid_type;
-  uint f_precision, f_scale;
-  uint dec_bin_size;
+  uint f_precision, f_scale, dec_bin_size;
+  uint prec_increment;
   Item_avg_field(Item_result res_type, Item_sum_avg *item);
   enum Type type() const { return FIELD_AVG_ITEM; }
   double val_real();
@@ -366,12 +367,14 @@
 {
 public:
   ulonglong count;
-  uint f_precision, f_scale;
-  uint dec_bin_size;
+  uint prec_increment;
+  uint f_precision, f_scale, dec_bin_size;
 
   Item_sum_avg(Item *item_par) :Item_sum_sum(item_par), count(0) {}
   Item_sum_avg(THD *thd, Item_sum_avg *item)
-    :Item_sum_sum(thd, item), count(item->count) {}
+    :Item_sum_sum(thd, item), count(item->count),
+    prec_increment(item->prec_increment) {}
+
   void fix_length_and_dec();
   enum Sumfunctype sum_func () const {return AVG_FUNC;}
   void clear();
@@ -402,6 +405,7 @@
   uint f_precision1, f_scale1;
   uint dec_bin_size0, dec_bin_size1;
   uint sample;
+  uint prec_increment;
   Item_variance_field(Item_sum_variance *item);
   enum Type type() const {return FIELD_VARIANCE_ITEM; }
   double val_real();
@@ -446,6 +450,7 @@
   uint f_precision1, f_scale1;
   uint dec_bin_size0, dec_bin_size1;
   uint sample;
+  uint prec_increment;
 
   Item_sum_variance(Item *item_par, uint sample_arg) :Item_sum_num(item_par),
     hybrid_type(REAL_RESULT), cur_dec(0), count(0), sample(sample_arg)

--- 1.79/sql/item_timefunc.cc	Tue Apr  5 03:19:44 2005
+++ 1.80/sql/item_timefunc.cc	Wed Apr 13 12:06:50 2005
@@ -1248,6 +1248,7 @@
   collation.set(&my_charset_bin);
   decimals=0; 
   max_length=MAX_DATE_WIDTH*MY_CHARSET_BIN_MB_MAXLEN;
+  precision=max_length;
 
   store_now_in_TIME(&ltime);
   
@@ -1323,6 +1324,7 @@
   value= TIME_to_ulonglong_time(&ltime);
   buff_length= (uint) my_time_to_str(&ltime, buff);
   max_length= buff_length;
+  precision=max_length;
 }
 
 
@@ -1372,6 +1374,7 @@
 
   buff_length= (uint) my_datetime_to_str(&ltime, buff);
   max_length= buff_length;
+  precision=max_length;
 }
 
 
@@ -1487,6 +1490,7 @@
     set_if_smaller(max_length,MAX_BLOB_WIDTH);
   }
   maybe_null=1;					// If wrong date
+  precision=max_length;
 }
 
 
@@ -1619,6 +1623,7 @@
   max_length=MAX_DATETIME_WIDTH*MY_CHARSET_BIN_MB_MAXLEN;
   maybe_null= 1;
   thd->time_zone_used= 1;
+  precision=max_length;
 }
 
 
@@ -1677,6 +1682,7 @@
   decimals= 0;
   max_length= MAX_DATETIME_WIDTH*MY_CHARSET_BIN_MB_MAXLEN;
   maybe_null= 1;
+  precision=max_length;
 }
 
 
@@ -2337,6 +2343,7 @@
   enum_field_types arg0_field_type;
   decimals=0;
   max_length=MAX_DATETIME_FULL_WIDTH*MY_CHARSET_BIN_MB_MAXLEN;
+  precision=max_length;
 
   /*
     The field type for the result of an Item_func_add_time function is defined
@@ -2951,6 +2958,7 @@
   decimals=0;
   cached_field_type= MYSQL_TYPE_STRING;
   max_length= MAX_DATETIME_FULL_WIDTH*MY_CHARSET_BIN_MB_MAXLEN;
+  precision=max_length;
   cached_timestamp_type= MYSQL_TIMESTAMP_NONE;
   if ((const_item= args[1]->const_item()))
   {

--- 1.452/sql/mysqld.cc	Mon Apr 11 19:29:43 2005
+++ 1.453/sql/mysqld.cc	Wed Apr 13 12:06:51 2005
@@ -4214,7 +4214,8 @@
   OPT_PRELOAD_BUFFER_SIZE,
   OPT_QUERY_CACHE_LIMIT, OPT_QUERY_CACHE_MIN_RES_UNIT, OPT_QUERY_CACHE_SIZE,
   OPT_QUERY_CACHE_TYPE, OPT_QUERY_CACHE_WLOCK_INVALIDATE, OPT_RECORD_BUFFER,
-  OPT_RECORD_RND_BUFFER, OPT_RELAY_LOG_SPACE_LIMIT, OPT_RELAY_LOG_PURGE,
+  OPT_RECORD_RND_BUFFER, OPT_DIV_PRECINCREMENT, OPT_RELAY_LOG_SPACE_LIMIT,
+  OPT_RELAY_LOG_PURGE,
   OPT_SLAVE_NET_TIMEOUT, OPT_SLAVE_COMPRESSED_PROTOCOL, OPT_SLOW_LAUNCH_TIME,
   OPT_SLAVE_TRANS_RETRIES, OPT_READONLY, OPT_DEBUGGING,
   OPT_SORT_BUFFER, OPT_TABLE_CACHE,
@@ -5419,6 +5420,11 @@
    (gptr*) &max_system_variables.read_rnd_buff_size, 0,
    GET_ULONG, REQUIRED_ARG, 256*1024L, IO_SIZE*2+MALLOC_OVERHEAD,
    ~0L, MALLOC_OVERHEAD, IO_SIZE, 0},
+  {"div_precision_increment", OPT_DIV_PRECINCREMENT,
+   "Precision of the result of '/' operator will be increased on that value.",
+   (gptr*) &global_system_variables.div_precincrement,
+   (gptr*) &max_system_variables.div_precincrement, 0, GET_ULONG,
+   REQUIRED_ARG, 4, 0, DECIMAL_MAX_SCALE, 0, 0, 0},
   {"record_buffer", OPT_RECORD_BUFFER,
    "Alias for read_buffer_size",
    (gptr*) &global_system_variables.read_buff_size,

--- 1.231/sql/sql_class.h	Tue Apr  5 16:22:05 2005
+++ 1.232/sql/sql_class.h	Wed Apr 13 12:06:51 2005
@@ -523,6 +523,7 @@
   ulong query_cache_type;
   ulong read_buff_size;
   ulong read_rnd_buff_size;
+  ulong div_precincrement;
   ulong sortbuff_size;
   ulong table_type;
   ulong tmp_table_size;

--- 1.440/sql/sql_parse.cc	Wed Apr 13 02:12:14 2005
+++ 1.441/sql/sql_parse.cc	Wed Apr 13 12:06:51 2005
@@ -5400,9 +5400,13 @@
     }
     new_field->pack_length=
       my_decimal_get_binary_size(new_field->length, new_field->decimals);
-    if (new_field->length <= DECIMAL_MAX_LENGTH &&
+    if (new_field->length <= DECIMAL_MAX_PRECISION &&
         new_field->length >= new_field->decimals)
+    {
+      new_field->length= my_decimal_precision2length(new_field->length,
+                                                     new_field->decimals);
       break;
+    }
     my_error(ER_WRONG_FIELD_SPEC, MYF(0), field_name);
     DBUG_RETURN(NULL);
   case MYSQL_TYPE_VARCHAR:

--- 1.314/sql/sql_select.cc	Mon Apr 11 13:22:28 2005
+++ 1.315/sql/sql_select.cc	Wed Apr 13 12:06:52 2005
@@ -7828,8 +7828,7 @@
       new_field= item->make_string_field(table);
     break;
   case DECIMAL_RESULT:
-    new_field= new Field_new_decimal(item->max_length - (item->decimals?1:0),
-                                     maybe_null,
+    new_field= new Field_new_decimal(item->max_length, maybe_null,
                                      item->name, table, item->decimals);
     break;
   case ROW_RESULT:

--- 1.235/sql/sql_show.cc	Wed Apr  6 21:43:28 2005
+++ 1.236/sql/sql_show.cc	Wed Apr 13 12:34:58 2005
@@ -2360,7 +2360,7 @@
                              strlen((const char*) pos), cs);
       if (field->has_charset())
       {
-        table->field[8]->store((longlong) field->representation_length()/
+        table->field[8]->store((longlong) field->field_length/
                                field->charset()->mbmaxlen);
         table->field[8]->set_notnull();
         table->field[9]->store((longlong) field->representation_length());
@@ -2371,7 +2371,8 @@
         uint dec =field->decimals();
         switch (field->type()) {
         case FIELD_TYPE_NEWDECIMAL:
-          table->field[10]->store((longlong) field->field_length);
+          table->field[10]->store((longlong)
+                                  ((Field_new_decimal*)field)->precision);
           table->field[10]->set_notnull();
           table->field[11]->store((longlong) field->decimals());
           table->field[11]->set_notnull();

--- 1.70/mysql-test/r/union.result	Mon Apr 11 15:08:58 2005
+++ 1.71/mysql-test/r/union.result	Wed Apr 13 12:34:58 2005
@@ -565,7 +565,7 @@
 show create table t1;
 Table	Create Table
 t1	CREATE TABLE `t1` (
-  `a` decimal(19,1) NOT NULL default '0.0'
+  `a` decimal(3,1) NOT NULL default '0.0'
 ) ENGINE=MyISAM DEFAULT CHARSET=latin1
 drop table t1;
 create table t2 (it1 tinyint, it2 tinyint not null, i int not null, ib bigint, f float, d double, y year, da date, dt datetime, sc char(10), sv varchar(10), b blob, tx text);
@@ -792,7 +792,7 @@
 show create table t3;
 Table	Create Table
 t3	CREATE TABLE `t3` (
-  `d` decimal(19,9) default NULL
+  `d` decimal(18,9) default NULL
 ) ENGINE=MyISAM DEFAULT CHARSET=latin1
 drop table t1,t2,t3;
 create table t1 select 1 union select -1;

--- 1.75/mysql-test/r/view.result	Tue Apr  5 00:43:54 2005
+++ 1.76/mysql-test/r/view.result	Wed Apr 13 12:06:49 2005
@@ -306,7 +306,7 @@
 create table t2 select * from v1;
 show columns from t2;
 Field	Type	Null	Key	Default	Extra
-a+1	bigint(12)	YES		NULL	
+a+1	bigint(13)	YES		NULL	
 select * from t2;
 a+1
 2

--- 1.24/mysql-test/r/ps_2myisam.result	Wed Mar 30 17:31:22 2005
+++ 1.25/mysql-test/r/ps_2myisam.result	Wed Apr 13 12:06:49 2005
@@ -59,8 +59,8 @@
 def	test	t9	t9	c8	c8	5	22	1	Y	32768	31	63
 def	test	t9	t9	c9	c9	5	22	1	Y	32768	31	63
 def	test	t9	t9	c10	c10	5	22	1	Y	32768	31	63
-def	test	t9	t9	c11	c11	246	7	6	Y	0	4	63
-def	test	t9	t9	c12	c12	246	8	6	Y	0	4	63
+def	test	t9	t9	c11	c11	246	9	6	Y	0	4	63
+def	test	t9	t9	c12	c12	246	10	6	Y	0	4	63
 def	test	t9	t9	c13	c13	10	10	10	Y	128	0	63
 def	test	t9	t9	c14	c14	12	19	19	Y	128	0	63
 def	test	t9	t9	c15	c15	7	19	19	N	1249	0	63
@@ -1776,8 +1776,8 @@
 t5	CREATE TABLE `t5` (
   `const01` bigint(1) NOT NULL default '0',
   `param01` bigint(20) default NULL,
-  `const02` decimal(3,1) NOT NULL default '0.0',
-  `param02` decimal(64,30) default NULL,
+  `const02` decimal(2,1) NOT NULL default '0.0',
+  `param02` decimal(65,31) default NULL,
   `const03` double NOT NULL default '0',
   `param03` double default NULL,
   `const04` varchar(3) NOT NULL default '',
@@ -1798,7 +1798,7 @@
   `param11` bigint(20) default NULL,
   `const12` binary(0) default NULL,
   `param12` bigint(20) default NULL,
-  `param13` decimal(64,30) default NULL,
+  `param13` decimal(65,31) default NULL,
   `param14` longtext,
   `param15` longblob
 ) ENGINE=MyISAM DEFAULT CHARSET=latin1
@@ -1806,8 +1806,8 @@
 Catalog	Database	Table	Table_alias	Column	Column_alias	Type	Length	Max length	Is_null	Flags	Decimals	Charsetnr
 def	test	t5	t5	const01	const01	8	1	1	N	32769	0	63
 def	test	t5	t5	param01	param01	8	20	1	Y	32768	0	63
-def	test	t5	t5	const02	const02	246	3	3	N	1	1	63
-def	test	t5	t5	param02	param02	246	64	32	Y	0	30	63
+def	test	t5	t5	const02	const02	246	4	3	N	1	1	63
+def	test	t5	t5	param02	param02	246	67	33	Y	0	31	63
 def	test	t5	t5	const03	const03	5	17	1	N	32769	31	63
 def	test	t5	t5	param03	param03	5	20	1	Y	32768	31	63
 def	test	t5	t5	const04	const04	253	3	3	N	1	0	8
@@ -1828,13 +1828,13 @@
 def	test	t5	t5	param11	param11	8	20	4	Y	32768	0	63
 def	test	t5	t5	const12	const12	254	0	0	Y	128	0	63
 def	test	t5	t5	param12	param12	8	20	0	Y	32768	0	63
-def	test	t5	t5	param13	param13	246	64	0	Y	0	30	63
+def	test	t5	t5	param13	param13	246	67	0	Y	0	31	63
 def	test	t5	t5	param14	param14	252	16777215	0	Y	16	0	8
 def	test	t5	t5	param15	param15	252	16777215	0	Y	144	0	63
 const01	8
 param01	8
 const02	8.0
-param02	8.000000000000000000000000000000
+param02	8.0000000000000000000000000000000
 const03	8
 param03	8
 const04	abc
@@ -1926,8 +1926,8 @@
 def					@arg08	253	20	1	Y	128	31	63
 def					@arg09	253	20	1	Y	128	31	63
 def					@arg10	253	20	1	Y	128	31	63
-def					@arg11	253	64	6	Y	128	30	63
-def					@arg12	253	64	6	Y	128	30	63
+def					@arg11	253	67	6	Y	128	31	63
+def					@arg12	253	67	6	Y	128	31	63
 def					@arg13	253	8192	10	Y	128	31	63
 def					@arg14	253	8192	19	Y	128	31	63
 def					@arg15	253	8192	19	Y	128	31	63
@@ -1973,8 +1973,8 @@
 def					@arg08	253	20	0	Y	128	31	63
 def					@arg09	253	20	0	Y	128	31	63
 def					@arg10	253	20	0	Y	128	31	63
-def					@arg11	253	64	0	Y	128	30	63
-def					@arg12	253	64	0	Y	128	30	63
+def					@arg11	253	67	0	Y	128	31	63
+def					@arg12	253	67	0	Y	128	31	63
 def					@arg13	253	8192	0	Y	128	31	63
 def					@arg14	253	8192	0	Y	128	31	63
 def					@arg15	253	8192	19	Y	128	31	63
@@ -2023,8 +2023,8 @@
 def					@arg08	253	20	1	Y	128	31	63
 def					@arg09	253	20	1	Y	128	31	63
 def					@arg10	253	20	1	Y	128	31	63
-def					@arg11	253	64	6	Y	128	30	63
-def					@arg12	253	64	6	Y	128	30	63
+def					@arg11	253	67	6	Y	128	31	63
+def					@arg12	253	67	6	Y	128	31	63
 def					@arg13	253	8192	10	Y	128	31	63
 def					@arg14	253	8192	19	Y	128	31	63
 def					@arg15	253	8192	19	Y	128	31	63
@@ -2063,8 +2063,8 @@
 def					@arg08	253	20	0	Y	128	31	63
 def					@arg09	253	20	0	Y	128	31	63
 def					@arg10	253	20	0	Y	128	31	63
-def					@arg11	253	64	0	Y	128	30	63
-def					@arg12	253	64	0	Y	128	30	63
+def					@arg11	253	67	0	Y	128	31	63
+def					@arg12	253	67	0	Y	128	31	63
 def					@arg13	253	8192	0	Y	128	31	63
 def					@arg14	253	8192	0	Y	128	31	63
 def					@arg15	253	8192	19	Y	128	31	63
@@ -2111,8 +2111,8 @@
 def					@arg08	253	20	1	Y	128	31	63
 def					@arg09	253	20	1	Y	128	31	63
 def					@arg10	253	20	1	Y	128	31	63
-def					@arg11	253	64	6	Y	128	30	63
-def					@arg12	253	64	6	Y	128	30	63
+def					@arg11	253	67	6	Y	128	31	63
+def					@arg12	253	67	6	Y	128	31	63
 def					@arg13	253	8192	10	Y	128	31	63
 def					@arg14	253	8192	19	Y	128	31	63
 def					@arg15	253	8192	19	Y	128	31	63
@@ -2155,8 +2155,8 @@
 def					@arg08	253	20	0	Y	128	31	63
 def					@arg09	253	20	0	Y	128	31	63
 def					@arg10	253	20	0	Y	128	31	63
-def					@arg11	253	64	0	Y	128	30	63
-def					@arg12	253	64	0	Y	128	30	63
+def					@arg11	253	67	0	Y	128	31	63
+def					@arg12	253	67	0	Y	128	31	63
 def					@arg13	253	8192	0	Y	128	31	63
 def					@arg14	253	8192	0	Y	128	31	63
 def					@arg15	253	8192	19	Y	128	31	63
@@ -2201,8 +2201,8 @@
 def					@arg08	253	20	1	Y	128	31	63
 def					@arg09	253	20	1	Y	128	31	63
 def					@arg10	253	20	1	Y	128	31	63
-def					@arg11	253	64	6	Y	128	30	63
-def					@arg12	253	64	6	Y	128	30	63
+def					@arg11	253	67	6	Y	128	31	63
+def					@arg12	253	67	6	Y	128	31	63
 def					@arg13	253	8192	10	Y	128	31	63
 def					@arg14	253	8192	19	Y	128	31	63
 def					@arg15	253	8192	19	Y	128	31	63
@@ -2239,8 +2239,8 @@
 def					@arg08	253	20	0	Y	128	31	63
 def					@arg09	253	20	0	Y	128	31	63
 def					@arg10	253	20	0	Y	128	31	63
-def					@arg11	253	64	0	Y	128	30	63
-def					@arg12	253	64	0	Y	128	30	63
+def					@arg11	253	67	0	Y	128	31	63
+def					@arg12	253	67	0	Y	128	31	63
 def					@arg13	253	8192	0	Y	128	31	63
 def					@arg14	253	8192	0	Y	128	31	63
 def					@arg15	253	8192	19	Y	128	31	63

--- 1.27/mysql-test/r/ps_3innodb.result	Wed Mar 30 17:31:22 2005
+++ 1.28/mysql-test/r/ps_3innodb.result	Wed Apr 13 12:06:49 2005
@@ -59,8 +59,8 @@
 def	test	t9	t9	c8	c8	5	22	1	Y	32768	31	63
 def	test	t9	t9	c9	c9	5	22	1	Y	32768	31	63
 def	test	t9	t9	c10	c10	5	22	1	Y	32768	31	63
-def	test	t9	t9	c11	c11	246	7	6	Y	0	4	63
-def	test	t9	t9	c12	c12	246	8	6	Y	0	4	63
+def	test	t9	t9	c11	c11	246	9	6	Y	0	4	63
+def	test	t9	t9	c12	c12	246	10	6	Y	0	4	63
 def	test	t9	t9	c13	c13	10	10	10	Y	128	0	63
 def	test	t9	t9	c14	c14	12	19	19	Y	128	0	63
 def	test	t9	t9	c15	c15	7	19	19	N	1249	0	63
@@ -1759,8 +1759,8 @@
 t5	CREATE TABLE `t5` (
   `const01` bigint(1) NOT NULL default '0',
   `param01` bigint(20) default NULL,
-  `const02` decimal(3,1) NOT NULL default '0.0',
-  `param02` decimal(64,30) default NULL,
+  `const02` decimal(2,1) NOT NULL default '0.0',
+  `param02` decimal(65,31) default NULL,
   `const03` double NOT NULL default '0',
   `param03` double default NULL,
   `const04` varchar(3) NOT NULL default '',
@@ -1781,7 +1781,7 @@
   `param11` bigint(20) default NULL,
   `const12` binary(0) default NULL,
   `param12` bigint(20) default NULL,
-  `param13` decimal(64,30) default NULL,
+  `param13` decimal(65,31) default NULL,
   `param14` longtext,
   `param15` longblob
 ) ENGINE=MyISAM DEFAULT CHARSET=latin1
@@ -1789,8 +1789,8 @@
 Catalog	Database	Table	Table_alias	Column	Column_alias	Type	Length	Max length	Is_null	Flags	Decimals	Charsetnr
 def	test	t5	t5	const01	const01	8	1	1	N	32769	0	63
 def	test	t5	t5	param01	param01	8	20	1	Y	32768	0	63
-def	test	t5	t5	const02	const02	246	3	3	N	1	1	63
-def	test	t5	t5	param02	param02	246	64	32	Y	0	30	63
+def	test	t5	t5	const02	const02	246	4	3	N	1	1	63
+def	test	t5	t5	param02	param02	246	67	33	Y	0	31	63
 def	test	t5	t5	const03	const03	5	17	1	N	32769	31	63
 def	test	t5	t5	param03	param03	5	20	1	Y	32768	31	63
 def	test	t5	t5	const04	const04	253	3	3	N	1	0	8
@@ -1811,13 +1811,13 @@
 def	test	t5	t5	param11	param11	8	20	4	Y	32768	0	63
 def	test	t5	t5	const12	const12	254	0	0	Y	128	0	63
 def	test	t5	t5	param12	param12	8	20	0	Y	32768	0	63
-def	test	t5	t5	param13	param13	246	64	0	Y	0	30	63
+def	test	t5	t5	param13	param13	246	67	0	Y	0	31	63
 def	test	t5	t5	param14	param14	252	16777215	0	Y	16	0	8
 def	test	t5	t5	param15	param15	252	16777215	0	Y	144	0	63
 const01	8
 param01	8
 const02	8.0
-param02	8.000000000000000000000000000000
+param02	8.0000000000000000000000000000000
 const03	8
 param03	8
 const04	abc
@@ -1909,8 +1909,8 @@
 def					@arg08	253	20	1	Y	128	31	63
 def					@arg09	253	20	1	Y	128	31	63
 def					@arg10	253	20	1	Y	128	31	63
-def					@arg11	253	64	6	Y	128	30	63
-def					@arg12	253	64	6	Y	128	30	63
+def					@arg11	253	67	6	Y	128	31	63
+def					@arg12	253	67	6	Y	128	31	63
 def					@arg13	253	8192	10	Y	128	31	63
 def					@arg14	253	8192	19	Y	128	31	63
 def					@arg15	253	8192	19	Y	128	31	63
@@ -1956,8 +1956,8 @@
 def					@arg08	253	20	0	Y	128	31	63
 def					@arg09	253	20	0	Y	128	31	63
 def					@arg10	253	20	0	Y	128	31	63
-def					@arg11	253	64	0	Y	128	30	63
-def					@arg12	253	64	0	Y	128	30	63
+def					@arg11	253	67	0	Y	128	31	63
+def					@arg12	253	67	0	Y	128	31	63
 def					@arg13	253	8192	0	Y	128	31	63
 def					@arg14	253	8192	0	Y	128	31	63
 def					@arg15	253	8192	19	Y	128	31	63
@@ -2006,8 +2006,8 @@
 def					@arg08	253	20	1	Y	128	31	63
 def					@arg09	253	20	1	Y	128	31	63
 def					@arg10	253	20	1	Y	128	31	63
-def					@arg11	253	64	6	Y	128	30	63
-def					@arg12	253	64	6	Y	128	30	63
+def					@arg11	253	67	6	Y	128	31	63
+def					@arg12	253	67	6	Y	128	31	63
 def					@arg13	253	8192	10	Y	128	31	63
 def					@arg14	253	8192	19	Y	128	31	63
 def					@arg15	253	8192	19	Y	128	31	63
@@ -2046,8 +2046,8 @@
 def					@arg08	253	20	0	Y	128	31	63
 def					@arg09	253	20	0	Y	128	31	63
 def					@arg10	253	20	0	Y	128	31	63
-def					@arg11	253	64	0	Y	128	30	63
-def					@arg12	253	64	0	Y	128	30	63
+def					@arg11	253	67	0	Y	128	31	63
+def					@arg12	253	67	0	Y	128	31	63
 def					@arg13	253	8192	0	Y	128	31	63
 def					@arg14	253	8192	0	Y	128	31	63
 def					@arg15	253	8192	19	Y	128	31	63
@@ -2094,8 +2094,8 @@
 def					@arg08	253	20	1	Y	128	31	63
 def					@arg09	253	20	1	Y	128	31	63
 def					@arg10	253	20	1	Y	128	31	63
-def					@arg11	253	64	6	Y	128	30	63
-def					@arg12	253	64	6	Y	128	30	63
+def					@arg11	253	67	6	Y	128	31	63
+def					@arg12	253	67	6	Y	128	31	63
 def					@arg13	253	8192	10	Y	128	31	63
 def					@arg14	253	8192	19	Y	128	31	63
 def					@arg15	253	8192	19	Y	128	31	63
@@ -2138,8 +2138,8 @@
 def					@arg08	253	20	0	Y	128	31	63
 def					@arg09	253	20	0	Y	128	31	63
 def					@arg10	253	20	0	Y	128	31	63
-def					@arg11	253	64	0	Y	128	30	63
-def					@arg12	253	64	0	Y	128	30	63
+def					@arg11	253	67	0	Y	128	31	63
+def					@arg12	253	67	0	Y	128	31	63
 def					@arg13	253	8192	0	Y	128	31	63
 def					@arg14	253	8192	0	Y	128	31	63
 def					@arg15	253	8192	19	Y	128	31	63
@@ -2184,8 +2184,8 @@
 def					@arg08	253	20	1	Y	128	31	63
 def					@arg09	253	20	1	Y	128	31	63
 def					@arg10	253	20	1	Y	128	31	63
-def					@arg11	253	64	6	Y	128	30	63
-def					@arg12	253	64	6	Y	128	30	63
+def					@arg11	253	67	6	Y	128	31	63
+def					@arg12	253	67	6	Y	128	31	63
 def					@arg13	253	8192	10	Y	128	31	63
 def					@arg14	253	8192	19	Y	128	31	63
 def					@arg15	253	8192	19	Y	128	31	63
@@ -2222,8 +2222,8 @@
 def					@arg08	253	20	0	Y	128	31	63
 def					@arg09	253	20	0	Y	128	31	63
 def					@arg10	253	20	0	Y	128	31	63
-def					@arg11	253	64	0	Y	128	30	63
-def					@arg12	253	64	0	Y	128	30	63
+def					@arg11	253	67	0	Y	128	31	63
+def					@arg12	253	67	0	Y	128	31	63
 def					@arg13	253	8192	0	Y	128	31	63
 def					@arg14	253	8192	0	Y	128	31	63
 def					@arg15	253	8192	19	Y	128	31	63

--- 1.23/mysql-test/r/ps_4heap.result	Wed Mar 30 17:31:22 2005
+++ 1.24/mysql-test/r/ps_4heap.result	Wed Apr 13 12:06:49 2005
@@ -60,8 +60,8 @@
 def	test	t9	t9	c8	c8	5	22	1	Y	32768	31	63
 def	test	t9	t9	c9	c9	5	22	1	Y	32768	31	63
 def	test	t9	t9	c10	c10	5	22	1	Y	32768	31	63
-def	test	t9	t9	c11	c11	246	7	6	Y	0	4	63
-def	test	t9	t9	c12	c12	246	8	6	Y	0	4	63
+def	test	t9	t9	c11	c11	246	9	6	Y	0	4	63
+def	test	t9	t9	c12	c12	246	10	6	Y	0	4	63
 def	test	t9	t9	c13	c13	10	10	10	Y	128	0	63
 def	test	t9	t9	c14	c14	12	19	19	Y	128	0	63
 def	test	t9	t9	c15	c15	7	19	19	N	1249	0	63
@@ -1760,8 +1760,8 @@
 t5	CREATE TABLE `t5` (
   `const01` bigint(1) NOT NULL default '0',
   `param01` bigint(20) default NULL,
-  `const02` decimal(3,1) NOT NULL default '0.0',
-  `param02` decimal(64,30) default NULL,
+  `const02` decimal(2,1) NOT NULL default '0.0',
+  `param02` decimal(65,31) default NULL,
   `const03` double NOT NULL default '0',
   `param03` double default NULL,
   `const04` varchar(3) NOT NULL default '',
@@ -1782,7 +1782,7 @@
   `param11` bigint(20) default NULL,
   `const12` binary(0) default NULL,
   `param12` bigint(20) default NULL,
-  `param13` decimal(64,30) default NULL,
+  `param13` decimal(65,31) default NULL,
   `param14` longtext,
   `param15` longblob
 ) ENGINE=MyISAM DEFAULT CHARSET=latin1
@@ -1790,8 +1790,8 @@
 Catalog	Database	Table	Table_alias	Column	Column_alias	Type	Length	Max length	Is_null	Flags	Decimals	Charsetnr
 def	test	t5	t5	const01	const01	8	1	1	N	32769	0	63
 def	test	t5	t5	param01	param01	8	20	1	Y	32768	0	63
-def	test	t5	t5	const02	const02	246	3	3	N	1	1	63
-def	test	t5	t5	param02	param02	246	64	32	Y	0	30	63
+def	test	t5	t5	const02	const02	246	4	3	N	1	1	63
+def	test	t5	t5	param02	param02	246	67	33	Y	0	31	63
 def	test	t5	t5	const03	const03	5	17	1	N	32769	31	63
 def	test	t5	t5	param03	param03	5	20	1	Y	32768	31	63
 def	test	t5	t5	const04	const04	253	3	3	N	1	0	8
@@ -1812,13 +1812,13 @@
 def	test	t5	t5	param11	param11	8	20	4	Y	32768	0	63
 def	test	t5	t5	const12	const12	254	0	0	Y	128	0	63
 def	test	t5	t5	param12	param12	8	20	0	Y	32768	0	63
-def	test	t5	t5	param13	param13	246	64	0	Y	0	30	63
+def	test	t5	t5	param13	param13	246	67	0	Y	0	31	63
 def	test	t5	t5	param14	param14	252	16777215	0	Y	16	0	8
 def	test	t5	t5	param15	param15	252	16777215	0	Y	144	0	63
 const01	8
 param01	8
 const02	8.0
-param02	8.000000000000000000000000000000
+param02	8.0000000000000000000000000000000
 const03	8
 param03	8
 const04	abc
@@ -1910,8 +1910,8 @@
 def					@arg08	253	20	1	Y	128	31	63
 def					@arg09	253	20	1	Y	128	31	63
 def					@arg10	253	20	1	Y	128	31	63
-def					@arg11	253	64	6	Y	128	30	63
-def					@arg12	253	64	6	Y	128	30	63
+def					@arg11	253	67	6	Y	128	31	63
+def					@arg12	253	67	6	Y	128	31	63
 def					@arg13	253	8192	10	Y	128	31	63
 def					@arg14	253	8192	19	Y	128	31	63
 def					@arg15	253	8192	19	Y	128	31	63
@@ -1957,8 +1957,8 @@
 def					@arg08	253	20	0	Y	128	31	63
 def					@arg09	253	20	0	Y	128	31	63
 def					@arg10	253	20	0	Y	128	31	63
-def					@arg11	253	64	0	Y	128	30	63
-def					@arg12	253	64	0	Y	128	30	63
+def					@arg11	253	67	0	Y	128	31	63
+def					@arg12	253	67	0	Y	128	31	63
 def					@arg13	253	8192	0	Y	128	31	63
 def					@arg14	253	8192	0	Y	128	31	63
 def					@arg15	253	8192	19	Y	128	31	63
@@ -2007,8 +2007,8 @@
 def					@arg08	253	20	1	Y	128	31	63
 def					@arg09	253	20	1	Y	128	31	63
 def					@arg10	253	20	1	Y	128	31	63
-def					@arg11	253	64	6	Y	128	30	63
-def					@arg12	253	64	6	Y	128	30	63
+def					@arg11	253	67	6	Y	128	31	63
+def					@arg12	253	67	6	Y	128	31	63
 def					@arg13	253	8192	10	Y	128	31	63
 def					@arg14	253	8192	19	Y	128	31	63
 def					@arg15	253	8192	19	Y	128	31	63
@@ -2047,8 +2047,8 @@
 def					@arg08	253	20	0	Y	128	31	63
 def					@arg09	253	20	0	Y	128	31	63
 def					@arg10	253	20	0	Y	128	31	63
-def					@arg11	253	64	0	Y	128	30	63
-def					@arg12	253	64	0	Y	128	30	63
+def					@arg11	253	67	0	Y	128	31	63
+def					@arg12	253	67	0	Y	128	31	63
 def					@arg13	253	8192	0	Y	128	31	63
 def					@arg14	253	8192	0	Y	128	31	63
 def					@arg15	253	8192	19	Y	128	31	63
@@ -2095,8 +2095,8 @@
 def					@arg08	253	20	1	Y	128	31	63
 def					@arg09	253	20	1	Y	128	31	63
 def					@arg10	253	20	1	Y	128	31	63
-def					@arg11	253	64	6	Y	128	30	63
-def					@arg12	253	64	6	Y	128	30	63
+def					@arg11	253	67	6	Y	128	31	63
+def					@arg12	253	67	6	Y	128	31	63
 def					@arg13	253	8192	10	Y	128	31	63
 def					@arg14	253	8192	19	Y	128	31	63
 def					@arg15	253	8192	19	Y	128	31	63
@@ -2139,8 +2139,8 @@
 def					@arg08	253	20	0	Y	128	31	63
 def					@arg09	253	20	0	Y	128	31	63
 def					@arg10	253	20	0	Y	128	31	63
-def					@arg11	253	64	0	Y	128	30	63
-def					@arg12	253	64	0	Y	128	30	63
+def					@arg11	253	67	0	Y	128	31	63
+def					@arg12	253	67	0	Y	128	31	63
 def					@arg13	253	8192	0	Y	128	31	63
 def					@arg14	253	8192	0	Y	128	31	63
 def					@arg15	253	8192	19	Y	128	31	63
@@ -2185,8 +2185,8 @@
 def					@arg08	253	20	1	Y	128	31	63
 def					@arg09	253	20	1	Y	128	31	63
 def					@arg10	253	20	1	Y	128	31	63
-def					@arg11	253	64	6	Y	128	30	63
-def					@arg12	253	64	6	Y	128	30	63
+def					@arg11	253	67	6	Y	128	31	63
+def					@arg12	253	67	6	Y	128	31	63
 def					@arg13	253	8192	10	Y	128	31	63
 def					@arg14	253	8192	19	Y	128	31	63
 def					@arg15	253	8192	19	Y	128	31	63
@@ -2223,8 +2223,8 @@
 def					@arg08	253	20	0	Y	128	31	63
 def					@arg09	253	20	0	Y	128	31	63
 def					@arg10	253	20	0	Y	128	31	63
-def					@arg11	253	64	0	Y	128	30	63
-def					@arg12	253	64	0	Y	128	30	63
+def					@arg11	253	67	0	Y	128	31	63
+def					@arg12	253	67	0	Y	128	31	63
 def					@arg13	253	8192	0	Y	128	31	63
 def					@arg14	253	8192	0	Y	128	31	63
 def					@arg15	253	8192	19	Y	128	31	63

--- 1.24/mysql-test/r/ps_5merge.result	Wed Mar 30 17:31:22 2005
+++ 1.25/mysql-test/r/ps_5merge.result	Wed Apr 13 12:06:49 2005
@@ -102,8 +102,8 @@
 def	test	t9	t9	c8	c8	5	22	1	Y	32768	31	63
 def	test	t9	t9	c9	c9	5	22	1	Y	32768	31	63
 def	test	t9	t9	c10	c10	5	22	1	Y	32768	31	63
-def	test	t9	t9	c11	c11	246	7	6	Y	0	4	63
-def	test	t9	t9	c12	c12	246	8	6	Y	0	4	63
+def	test	t9	t9	c11	c11	246	9	6	Y	0	4	63
+def	test	t9	t9	c12	c12	246	10	6	Y	0	4	63
 def	test	t9	t9	c13	c13	10	10	10	Y	128	0	63
 def	test	t9	t9	c14	c14	12	19	19	Y	128	0	63
 def	test	t9	t9	c15	c15	7	19	19	N	1249	0	63
@@ -1696,8 +1696,8 @@
 t5	CREATE TABLE `t5` (
   `const01` bigint(1) NOT NULL default '0',
   `param01` bigint(20) default NULL,
-  `const02` decimal(3,1) NOT NULL default '0.0',
-  `param02` decimal(64,30) default NULL,
+  `const02` decimal(2,1) NOT NULL default '0.0',
+  `param02` decimal(65,31) default NULL,
   `const03` double NOT NULL default '0',
   `param03` double default NULL,
   `const04` varchar(3) NOT NULL default '',
@@ -1718,7 +1718,7 @@
   `param11` bigint(20) default NULL,
   `const12` binary(0) default NULL,
   `param12` bigint(20) default NULL,
-  `param13` decimal(64,30) default NULL,
+  `param13` decimal(65,31) default NULL,
   `param14` longtext,
   `param15` longblob
 ) ENGINE=MyISAM DEFAULT CHARSET=latin1
@@ -1726,8 +1726,8 @@
 Catalog	Database	Table	Table_alias	Column	Column_alias	Type	Length	Max length	Is_null	Flags	Decimals	Charsetnr
 def	test	t5	t5	const01	const01	8	1	1	N	32769	0	63
 def	test	t5	t5	param01	param01	8	20	1	Y	32768	0	63
-def	test	t5	t5	const02	const02	246	3	3	N	1	1	63
-def	test	t5	t5	param02	param02	246	64	32	Y	0	30	63
+def	test	t5	t5	const02	const02	246	4	3	N	1	1	63
+def	test	t5	t5	param02	param02	246	67	33	Y	0	31	63
 def	test	t5	t5	const03	const03	5	17	1	N	32769	31	63
 def	test	t5	t5	param03	param03	5	20	1	Y	32768	31	63
 def	test	t5	t5	const04	const04	253	3	3	N	1	0	8
@@ -1748,13 +1748,13 @@
 def	test	t5	t5	param11	param11	8	20	4	Y	32768	0	63
 def	test	t5	t5	const12	const12	254	0	0	Y	128	0	63
 def	test	t5	t5	param12	param12	8	20	0	Y	32768	0	63
-def	test	t5	t5	param13	param13	246	64	0	Y	0	30	63
+def	test	t5	t5	param13	param13	246	67	0	Y	0	31	63
 def	test	t5	t5	param14	param14	252	16777215	0	Y	16	0	8
 def	test	t5	t5	param15	param15	252	16777215	0	Y	144	0	63
 const01	8
 param01	8
 const02	8.0
-param02	8.000000000000000000000000000000
+param02	8.0000000000000000000000000000000
 const03	8
 param03	8
 const04	abc
@@ -1846,8 +1846,8 @@
 def					@arg08	253	20	1	Y	128	31	63
 def					@arg09	253	20	1	Y	128	31	63
 def					@arg10	253	20	1	Y	128	31	63
-def					@arg11	253	64	6	Y	128	30	63
-def					@arg12	253	64	6	Y	128	30	63
+def					@arg11	253	67	6	Y	128	31	63
+def					@arg12	253	67	6	Y	128	31	63
 def					@arg13	253	8192	10	Y	128	31	63
 def					@arg14	253	8192	19	Y	128	31	63
 def					@arg15	253	8192	19	Y	128	31	63
@@ -1893,8 +1893,8 @@
 def					@arg08	253	20	0	Y	128	31	63
 def					@arg09	253	20	0	Y	128	31	63
 def					@arg10	253	20	0	Y	128	31	63
-def					@arg11	253	64	0	Y	128	30	63
-def					@arg12	253	64	0	Y	128	30	63
+def					@arg11	253	67	0	Y	128	31	63
+def					@arg12	253	67	0	Y	128	31	63
 def					@arg13	253	8192	0	Y	128	31	63
 def					@arg14	253	8192	0	Y	128	31	63
 def					@arg15	253	8192	19	Y	128	31	63
@@ -1943,8 +1943,8 @@
 def					@arg08	253	20	1	Y	128	31	63
 def					@arg09	253	20	1	Y	128	31	63
 def					@arg10	253	20	1	Y	128	31	63
-def					@arg11	253	64	6	Y	128	30	63
-def					@arg12	253	64	6	Y	128	30	63
+def					@arg11	253	67	6	Y	128	31	63
+def					@arg12	253	67	6	Y	128	31	63
 def					@arg13	253	8192	10	Y	128	31	63
 def					@arg14	253	8192	19	Y	128	31	63
 def					@arg15	253	8192	19	Y	128	31	63
@@ -1983,8 +1983,8 @@
 def					@arg08	253	20	0	Y	128	31	63
 def					@arg09	253	20	0	Y	128	31	63
 def					@arg10	253	20	0	Y	128	31	63
-def					@arg11	253	64	0	Y	128	30	63
-def					@arg12	253	64	0	Y	128	30	63
+def					@arg11	253	67	0	Y	128	31	63
+def					@arg12	253	67	0	Y	128	31	63
 def					@arg13	253	8192	0	Y	128	31	63
 def					@arg14	253	8192	0	Y	128	31	63
 def					@arg15	253	8192	19	Y	128	31	63
@@ -2031,8 +2031,8 @@
 def					@arg08	253	20	1	Y	128	31	63
 def					@arg09	253	20	1	Y	128	31	63
 def					@arg10	253	20	1	Y	128	31	63
-def					@arg11	253	64	6	Y	128	30	63
-def					@arg12	253	64	6	Y	128	30	63
+def					@arg11	253	67	6	Y	128	31	63
+def					@arg12	253	67	6	Y	128	31	63
 def					@arg13	253	8192	10	Y	128	31	63
 def					@arg14	253	8192	19	Y	128	31	63
 def					@arg15	253	8192	19	Y	128	31	63
@@ -2075,8 +2075,8 @@
 def					@arg08	253	20	0	Y	128	31	63
 def					@arg09	253	20	0	Y	128	31	63
 def					@arg10	253	20	0	Y	128	31	63
-def					@arg11	253	64	0	Y	128	30	63
-def					@arg12	253	64	0	Y	128	30	63
+def					@arg11	253	67	0	Y	128	31	63
+def					@arg12	253	67	0	Y	128	31	63
 def					@arg13	253	8192	0	Y	128	31	63
 def					@arg14	253	8192	0	Y	128	31	63
 def					@arg15	253	8192	19	Y	128	31	63
@@ -2121,8 +2121,8 @@
 def					@arg08	253	20	1	Y	128	31	63
 def					@arg09	253	20	1	Y	128	31	63
 def					@arg10	253	20	1	Y	128	31	63
-def					@arg11	253	64	6	Y	128	30	63
-def					@arg12	253	64	6	Y	128	30	63
+def					@arg11	253	67	6	Y	128	31	63
+def					@arg12	253	67	6	Y	128	31	63
 def					@arg13	253	8192	10	Y	128	31	63
 def					@arg14	253	8192	19	Y	128	31	63
 def					@arg15	253	8192	19	Y	128	31	63
@@ -2159,8 +2159,8 @@
 def					@arg08	253	20	0	Y	128	31	63
 def					@arg09	253	20	0	Y	128	31	63
 def					@arg10	253	20	0	Y	128	31	63
-def					@arg11	253	64	0	Y	128	30	63
-def					@arg12	253	64	0	Y	128	30	63
+def					@arg11	253	67	0	Y	128	31	63
+def					@arg12	253	67	0	Y	128	31	63
 def					@arg13	253	8192	0	Y	128	31	63
 def					@arg14	253	8192	0	Y	128	31	63
 def					@arg15	253	8192	19	Y	128	31	63
@@ -3115,8 +3115,8 @@
 def	test	t9	t9	c8	c8	5	22	1	Y	32768	31	63
 def	test	t9	t9	c9	c9	5	22	1	Y	32768	31	63
 def	test	t9	t9	c10	c10	5	22	1	Y	32768	31	63
-def	test	t9	t9	c11	c11	246	7	6	Y	0	4	63
-def	test	t9	t9	c12	c12	246	8	6	Y	0	4	63
+def	test	t9	t9	c11	c11	246	9	6	Y	0	4	63
+def	test	t9	t9	c12	c12	246	10	6	Y	0	4	63
 def	test	t9	t9	c13	c13	10	10	10	Y	128	0	63
 def	test	t9	t9	c14	c14	12	19	19	Y	128	0	63
 def	test	t9	t9	c15	c15	7	19	19	N	1249	0	63
@@ -4709,8 +4709,8 @@
 t5	CREATE TABLE `t5` (
   `const01` bigint(1) NOT NULL default '0',
   `param01` bigint(20) default NULL,
-  `const02` decimal(3,1) NOT NULL default '0.0',
-  `param02` decimal(64,30) default NULL,
+  `const02` decimal(2,1) NOT NULL default '0.0',
+  `param02` decimal(65,31) default NULL,
   `const03` double NOT NULL default '0',
   `param03` double default NULL,
   `const04` varchar(3) NOT NULL default '',
@@ -4731,7 +4731,7 @@
   `param11` bigint(20) default NULL,
   `const12` binary(0) default NULL,
   `param12` bigint(20) default NULL,
-  `param13` decimal(64,30) default NULL,
+  `param13` decimal(65,31) default NULL,
   `param14` longtext,
   `param15` longblob
 ) ENGINE=MyISAM DEFAULT CHARSET=latin1
@@ -4739,8 +4739,8 @@
 Catalog	Database	Table	Table_alias	Column	Column_alias	Type	Length	Max length	Is_null	Flags	Decimals	Charsetnr
 def	test	t5	t5	const01	const01	8	1	1	N	32769	0	63
 def	test	t5	t5	param01	param01	8	20	1	Y	32768	0	63
-def	test	t5	t5	const02	const02	246	3	3	N	1	1	63
-def	test	t5	t5	param02	param02	246	64	32	Y	0	30	63
+def	test	t5	t5	const02	const02	246	4	3	N	1	1	63
+def	test	t5	t5	param02	param02	246	67	33	Y	0	31	63
 def	test	t5	t5	const03	const03	5	17	1	N	32769	31	63
 def	test	t5	t5	param03	param03	5	20	1	Y	32768	31	63
 def	test	t5	t5	const04	const04	253	3	3	N	1	0	8
@@ -4761,13 +4761,13 @@
 def	test	t5	t5	param11	param11	8	20	4	Y	32768	0	63
 def	test	t5	t5	const12	const12	254	0	0	Y	128	0	63
 def	test	t5	t5	param12	param12	8	20	0	Y	32768	0	63
-def	test	t5	t5	param13	param13	246	64	0	Y	0	30	63
+def	test	t5	t5	param13	param13	246	67	0	Y	0	31	63
 def	test	t5	t5	param14	param14	252	16777215	0	Y	16	0	8
 def	test	t5	t5	param15	param15	252	16777215	0	Y	144	0	63
 const01	8
 param01	8
 const02	8.0
-param02	8.000000000000000000000000000000
+param02	8.0000000000000000000000000000000
 const03	8
 param03	8
 const04	abc
@@ -4859,8 +4859,8 @@
 def					@arg08	253	20	1	Y	128	31	63
 def					@arg09	253	20	1	Y	128	31	63
 def					@arg10	253	20	1	Y	128	31	63
-def					@arg11	253	64	6	Y	128	30	63
-def					@arg12	253	64	6	Y	128	30	63
+def					@arg11	253	67	6	Y	128	31	63
+def					@arg12	253	67	6	Y	128	31	63
 def					@arg13	253	8192	10	Y	128	31	63
 def					@arg14	253	8192	19	Y	128	31	63
 def					@arg15	253	8192	19	Y	128	31	63
@@ -4906,8 +4906,8 @@
 def					@arg08	253	20	0	Y	128	31	63
 def					@arg09	253	20	0	Y	128	31	63
 def					@arg10	253	20	0	Y	128	31	63
-def					@arg11	253	64	0	Y	128	30	63
-def					@arg12	253	64	0	Y	128	30	63
+def					@arg11	253	67	0	Y	128	31	63
+def					@arg12	253	67	0	Y	128	31	63
 def					@arg13	253	8192	0	Y	128	31	63
 def					@arg14	253	8192	0	Y	128	31	63
 def					@arg15	253	8192	19	Y	128	31	63
@@ -4956,8 +4956,8 @@
 def					@arg08	253	20	1	Y	128	31	63
 def					@arg09	253	20	1	Y	128	31	63
 def					@arg10	253	20	1	Y	128	31	63
-def					@arg11	253	64	6	Y	128	30	63
-def					@arg12	253	64	6	Y	128	30	63
+def					@arg11	253	67	6	Y	128	31	63
+def					@arg12	253	67	6	Y	128	31	63
 def					@arg13	253	8192	10	Y	128	31	63
 def					@arg14	253	8192	19	Y	128	31	63
 def					@arg15	253	8192	19	Y	128	31	63
@@ -4996,8 +4996,8 @@
 def					@arg08	253	20	0	Y	128	31	63
 def					@arg09	253	20	0	Y	128	31	63
 def					@arg10	253	20	0	Y	128	31	63
-def					@arg11	253	64	0	Y	128	30	63
-def					@arg12	253	64	0	Y	128	30	63
+def					@arg11	253	67	0	Y	128	31	63
+def					@arg12	253	67	0	Y	128	31	63
 def					@arg13	253	8192	0	Y	128	31	63
 def					@arg14	253	8192	0	Y	128	31	63
 def					@arg15	253	8192	19	Y	128	31	63
@@ -5044,8 +5044,8 @@
 def					@arg08	253	20	1	Y	128	31	63
 def					@arg09	253	20	1	Y	128	31	63
 def					@arg10	253	20	1	Y	128	31	63
-def					@arg11	253	64	6	Y	128	30	63
-def					@arg12	253	64	6	Y	128	30	63
+def					@arg11	253	67	6	Y	128	31	63
+def					@arg12	253	67	6	Y	128	31	63
 def					@arg13	253	8192	10	Y	128	31	63
 def					@arg14	253	8192	19	Y	128	31	63
 def					@arg15	253	8192	19	Y	128	31	63
@@ -5088,8 +5088,8 @@
 def					@arg08	253	20	0	Y	128	31	63
 def					@arg09	253	20	0	Y	128	31	63
 def					@arg10	253	20	0	Y	128	31	63
-def					@arg11	253	64	0	Y	128	30	63
-def					@arg12	253	64	0	Y	128	30	63
+def					@arg11	253	67	0	Y	128	31	63
+def					@arg12	253	67	0	Y	128	31	63
 def					@arg13	253	8192	0	Y	128	31	63
 def					@arg14	253	8192	0	Y	128	31	63
 def					@arg15	253	8192	19	Y	128	31	63
@@ -5134,8 +5134,8 @@
 def					@arg08	253	20	1	Y	128	31	63
 def					@arg09	253	20	1	Y	128	31	63
 def					@arg10	253	20	1	Y	128	31	63
-def					@arg11	253	64	6	Y	128	30	63
-def					@arg12	253	64	6	Y	128	30	63
+def					@arg11	253	67	6	Y	128	31	63
+def					@arg12	253	67	6	Y	128	31	63
 def					@arg13	253	8192	10	Y	128	31	63
 def					@arg14	253	8192	19	Y	128	31	63
 def					@arg15	253	8192	19	Y	128	31	63
@@ -5172,8 +5172,8 @@
 def					@arg08	253	20	0	Y	128	31	63
 def					@arg09	253	20	0	Y	128	31	63
 def					@arg10	253	20	0	Y	128	31	63
-def					@arg11	253	64	0	Y	128	30	63
-def					@arg12	253	64	0	Y	128	30	63
+def					@arg11	253	67	0	Y	128	31	63
+def					@arg12	253	67	0	Y	128	31	63
 def					@arg13	253	8192	0	Y	128	31	63
 def					@arg14	253	8192	0	Y	128	31	63
 def					@arg15	253	8192	19	Y	128	31	63

--- 1.25/mysql-test/r/ps_6bdb.result	Wed Mar 30 17:31:22 2005
+++ 1.26/mysql-test/r/ps_6bdb.result	Wed Apr 13 12:06:49 2005
@@ -59,8 +59,8 @@
 def	test	t9	t9	c8	c8	5	22	1	Y	32768	31	63
 def	test	t9	t9	c9	c9	5	22	1	Y	32768	31	63
 def	test	t9	t9	c10	c10	5	22	1	Y	32768	31	63
-def	test	t9	t9	c11	c11	246	7	6	Y	0	4	63
-def	test	t9	t9	c12	c12	246	8	6	Y	0	4	63
+def	test	t9	t9	c11	c11	246	9	6	Y	0	4	63
+def	test	t9	t9	c12	c12	246	10	6	Y	0	4	63
 def	test	t9	t9	c13	c13	10	10	10	Y	128	0	63
 def	test	t9	t9	c14	c14	12	19	19	Y	128	0	63
 def	test	t9	t9	c15	c15	7	19	19	N	1249	0	63
@@ -1759,8 +1759,8 @@
 t5	CREATE TABLE `t5` (
   `const01` bigint(1) NOT NULL default '0',
   `param01` bigint(20) default NULL,
-  `const02` decimal(3,1) NOT NULL default '0.0',
-  `param02` decimal(64,30) default NULL,
+  `const02` decimal(2,1) NOT NULL default '0.0',
+  `param02` decimal(65,31) default NULL,
   `const03` double NOT NULL default '0',
   `param03` double default NULL,
   `const04` varchar(3) NOT NULL default '',
@@ -1781,7 +1781,7 @@
   `param11` bigint(20) default NULL,
   `const12` binary(0) default NULL,
   `param12` bigint(20) default NULL,
-  `param13` decimal(64,30) default NULL,
+  `param13` decimal(65,31) default NULL,
   `param14` longtext,
   `param15` longblob
 ) ENGINE=MyISAM DEFAULT CHARSET=latin1
@@ -1789,8 +1789,8 @@
 Catalog	Database	Table	Table_alias	Column	Column_alias	Type	Length	Max length	Is_null	Flags	Decimals	Charsetnr
 def	test	t5	t5	const01	const01	8	1	1	N	32769	0	63
 def	test	t5	t5	param01	param01	8	20	1	Y	32768	0	63
-def	test	t5	t5	const02	const02	246	3	3	N	1	1	63
-def	test	t5	t5	param02	param02	246	64	32	Y	0	30	63
+def	test	t5	t5	const02	const02	246	4	3	N	1	1	63
+def	test	t5	t5	param02	param02	246	67	33	Y	0	31	63
 def	test	t5	t5	const03	const03	5	17	1	N	32769	31	63
 def	test	t5	t5	param03	param03	5	20	1	Y	32768	31	63
 def	test	t5	t5	const04	const04	253	3	3	N	1	0	8
@@ -1811,13 +1811,13 @@
 def	test	t5	t5	param11	param11	8	20	4	Y	32768	0	63
 def	test	t5	t5	const12	const12	254	0	0	Y	128	0	63
 def	test	t5	t5	param12	param12	8	20	0	Y	32768	0	63
-def	test	t5	t5	param13	param13	246	64	0	Y	0	30	63
+def	test	t5	t5	param13	param13	246	67	0	Y	0	31	63
 def	test	t5	t5	param14	param14	252	16777215	0	Y	16	0	8
 def	test	t5	t5	param15	param15	252	16777215	0	Y	144	0	63
 const01	8
 param01	8
 const02	8.0
-param02	8.000000000000000000000000000000
+param02	8.0000000000000000000000000000000
 const03	8
 param03	8
 const04	abc
@@ -1909,8 +1909,8 @@
 def					@arg08	253	20	1	Y	128	31	63
 def					@arg09	253	20	1	Y	128	31	63
 def					@arg10	253	20	1	Y	128	31	63
-def					@arg11	253	64	6	Y	128	30	63
-def					@arg12	253	64	6	Y	128	30	63
+def					@arg11	253	67	6	Y	128	31	63
+def					@arg12	253	67	6	Y	128	31	63
 def					@arg13	253	8192	10	Y	128	31	63
 def					@arg14	253	8192	19	Y	128	31	63
 def					@arg15	253	8192	19	Y	128	31	63
@@ -1956,8 +1956,8 @@
 def					@arg08	253	20	0	Y	128	31	63
 def					@arg09	253	20	0	Y	128	31	63
 def					@arg10	253	20	0	Y	128	31	63
-def					@arg11	253	64	0	Y	128	30	63
-def					@arg12	253	64	0	Y	128	30	63
+def					@arg11	253	67	0	Y	128	31	63
+def					@arg12	253	67	0	Y	128	31	63
 def					@arg13	253	8192	0	Y	128	31	63
 def					@arg14	253	8192	0	Y	128	31	63
 def					@arg15	253	8192	19	Y	128	31	63
@@ -2006,8 +2006,8 @@
 def					@arg08	253	20	1	Y	128	31	63
 def					@arg09	253	20	1	Y	128	31	63
 def					@arg10	253	20	1	Y	128	31	63
-def					@arg11	253	64	6	Y	128	30	63
-def					@arg12	253	64	6	Y	128	30	63
+def					@arg11	253	67	6	Y	128	31	63
+def					@arg12	253	67	6	Y	128	31	63
 def					@arg13	253	8192	10	Y	128	31	63
 def					@arg14	253	8192	19	Y	128	31	63
 def					@arg15	253	8192	19	Y	128	31	63
@@ -2046,8 +2046,8 @@
 def					@arg08	253	20	0	Y	128	31	63
 def					@arg09	253	20	0	Y	128	31	63
 def					@arg10	253	20	0	Y	128	31	63
-def					@arg11	253	64	0	Y	128	30	63
-def					@arg12	253	64	0	Y	128	30	63
+def					@arg11	253	67	0	Y	128	31	63
+def					@arg12	253	67	0	Y	128	31	63
 def					@arg13	253	8192	0	Y	128	31	63
 def					@arg14	253	8192	0	Y	128	31	63
 def					@arg15	253	8192	19	Y	128	31	63
@@ -2094,8 +2094,8 @@
 def					@arg08	253	20	1	Y	128	31	63
 def					@arg09	253	20	1	Y	128	31	63
 def					@arg10	253	20	1	Y	128	31	63
-def					@arg11	253	64	6	Y	128	30	63
-def					@arg12	253	64	6	Y	128	30	63
+def					@arg11	253	67	6	Y	128	31	63
+def					@arg12	253	67	6	Y	128	31	63
 def					@arg13	253	8192	10	Y	128	31	63
 def					@arg14	253	8192	19	Y	128	31	63
 def					@arg15	253	8192	19	Y	128	31	63
@@ -2138,8 +2138,8 @@
 def					@arg08	253	20	0	Y	128	31	63
 def					@arg09	253	20	0	Y	128	31	63
 def					@arg10	253	20	0	Y	128	31	63
-def					@arg11	253	64	0	Y	128	30	63
-def					@arg12	253	64	0	Y	128	30	63
+def					@arg11	253	67	0	Y	128	31	63
+def					@arg12	253	67	0	Y	128	31	63
 def					@arg13	253	8192	0	Y	128	31	63
 def					@arg14	253	8192	0	Y	128	31	63
 def					@arg15	253	8192	19	Y	128	31	63
@@ -2184,8 +2184,8 @@
 def					@arg08	253	20	1	Y	128	31	63
 def					@arg09	253	20	1	Y	128	31	63
 def					@arg10	253	20	1	Y	128	31	63
-def					@arg11	253	64	6	Y	128	30	63
-def					@arg12	253	64	6	Y	128	30	63
+def					@arg11	253	67	6	Y	128	31	63
+def					@arg12	253	67	6	Y	128	31	63
 def					@arg13	253	8192	10	Y	128	31	63
 def					@arg14	253	8192	19	Y	128	31	63
 def					@arg15	253	8192	19	Y	128	31	63
@@ -2222,8 +2222,8 @@
 def					@arg08	253	20	0	Y	128	31	63
 def					@arg09	253	20	0	Y	128	31	63
 def					@arg10	253	20	0	Y	128	31	63
-def					@arg11	253	64	0	Y	128	30	63
-def					@arg12	253	64	0	Y	128	30	63
+def					@arg11	253	67	0	Y	128	31	63
+def					@arg12	253	67	0	Y	128	31	63
 def					@arg13	253	8192	0	Y	128	31	63
 def					@arg14	253	8192	0	Y	128	31	63
 def					@arg15	253	8192	19	Y	128	31	63

--- 1.5/mysql-test/r/type_newdecimal.result	Thu Mar 31 20:46:27 2005
+++ 1.6/mysql-test/r/type_newdecimal.result	Wed Apr 13 12:06:49 2005
@@ -52,13 +52,13 @@
 show create table t1;
 Table	Create Table
 t1	CREATE TABLE `t1` (
-  `if(1, 1.1, 1.2)` decimal(5,1) NOT NULL default '0.0',
-  `if(0, 1.1, 1.2)` decimal(5,1) NOT NULL default '0.0',
-  `if(0.1, 1.1, 1.2)` decimal(5,1) NOT NULL default '0.0',
-  `if(0, 1, 1.1)` decimal(5,1) NOT NULL default '0.0',
-  `if(0, NULL, 1.2)` decimal(5,1) default NULL,
+  `if(1, 1.1, 1.2)` decimal(2,1) NOT NULL default '0.0',
+  `if(0, 1.1, 1.2)` decimal(2,1) NOT NULL default '0.0',
+  `if(0.1, 1.1, 1.2)` decimal(2,1) NOT NULL default '0.0',
+  `if(0, 1, 1.1)` decimal(2,1) NOT NULL default '0.0',
+  `if(0, NULL, 1.2)` decimal(2,1) default NULL,
   `if(1, 0.22e1, 1.1)` double NOT NULL default '0',
-  `if(1E0, 1.1, 1.2)` decimal(5,1) NOT NULL default '0.0'
+  `if(1E0, 1.1, 1.2)` decimal(2,1) NOT NULL default '0.0'
 ) ENGINE=MyISAM DEFAULT CHARSET=latin1
 drop table t1;
 create table t1 select nullif(1.1, 1.1), nullif(1.1, 1.2), nullif(1.1, 0.11e1), nullif(1.0, 1), nullif(1, 1.0), nullif(1, 1.1);
@@ -68,12 +68,12 @@
 show create table t1;
 Table	Create Table
 t1	CREATE TABLE `t1` (
-  `nullif(1.1, 1.1)` decimal(5,1) default NULL,
-  `nullif(1.1, 1.2)` decimal(5,1) default NULL,
-  `nullif(1.1, 0.11e1)` double(4,1) default NULL,
-  `nullif(1.0, 1)` decimal(5,1) default NULL,
-  `nullif(1, 1.0)` decimal(1,0) default NULL,
-  `nullif(1, 1.1)` decimal(1,0) default NULL
+  `nullif(1.1, 1.1)` decimal(2,1) default NULL,
+  `nullif(1.1, 1.2)` decimal(2,1) default NULL,
+  `nullif(1.1, 0.11e1)` decimal(2,1) default NULL,
+  `nullif(1.0, 1)` decimal(2,1) default NULL,
+  `nullif(1, 1.0)` int(1) default NULL,
+  `nullif(1, 1.1)` int(1) default NULL
 ) ENGINE=MyISAM DEFAULT CHARSET=latin1
 drop table t1;
 create table t1 (a decimal(4,2));
@@ -174,10 +174,10 @@
 show create table t1;
 Table	Create Table
 t1	CREATE TABLE `t1` (
-  `round(15.4,-1)` decimal(5,0) NOT NULL default '0',
-  `truncate(-5678.123451,-3)` decimal(13,0) NOT NULL default '0',
-  `abs(-1.1)` decimal(6,1) NOT NULL default '0.0',
-  `-(-1.1)` decimal(7,1) NOT NULL default '0.0'
+  `round(15.4,-1)` decimal(4,0) NOT NULL default '0',
+  `truncate(-5678.123451,-3)` decimal(7,0) NOT NULL default '0',
+  `abs(-1.1)` decimal(3,1) NOT NULL default '0.0',
+  `-(-1.1)` decimal(4,1) NOT NULL default '0.0'
 ) ENGINE=MyISAM DEFAULT CHARSET=latin1
 drop table t1;
 set session sql_mode='traditional';
@@ -375,7 +375,7 @@
 drop table wl1612;
 select 1/3;
 1/3
-0.33333
+0.3333
 select 0.8=0.7+0.1;
 0.8=0.7+0.1
 1
@@ -398,7 +398,7 @@
 0.0049
 select 0.07/0.07 from wl1612_1;
 0.07/0.07
-1.000000000
+1.000000
 drop table wl1612_1;
 create table wl1612_2 (col1 decimal(10,2), col2 numeric(10,2));
 insert into wl1612_2 values(1,1);
@@ -626,16 +626,16 @@
 insert into wl1612_4 values(1,0.0123456789012345678912345,0.0123456789012345678912345);
 select col2/9999999999 from wl1612_4 where col1=1;
 col2/9999999999
-0.0000000000012345678902469135781481410000000000000000000
+0.00000000000123456789024691358
 select col3/9999999999 from wl1612_4 where col1=1;
 col3/9999999999
-0.0000000000012345678902469135781481410000000000000000000
+0.00000000000123456789024691358
 select 9999999999/col2 from wl1612_4 where col1=1;
 9999999999/col2
-810000007209.00007
+810000007209.0001
 select 9999999999/col3 from wl1612_4 where col1=1;
 9999999999/col3
-810000007209.00007
+810000007209.0001
 select col2*9999999999 from wl1612_4 where col1=1;
 col2*9999999999
 123456789.0000000000111104321087655
@@ -645,16 +645,16 @@
 insert into wl1612_4 values(2,55555.0123456789012345678912345,55555.0123456789012345678912345);
 select col2/9999999999 from wl1612_4 where col1=2;
 col2/9999999999
-0.0000055555012351234402469691331481460000000000000000000
+0.00000555550123512344024696913
 select col3/9999999999 from wl1612_4 where col1=2;
 col3/9999999999
-0.0000055555012351234402469691331481460000000000000000000
+0.00000555550123512344024696913
 select 9999999999/col2 from wl1612_4 where col1=2;
 9999999999/col2
-180001.76000
+180001.7600
 select 9999999999/col3 from wl1612_4 where col1=2;
 9999999999/col3
-180001.76000
+180001.7600
 select col2*9999999999 from wl1612_4 where col1=2;
 col2*9999999999
 555550123401234.0000000000111104321087655
@@ -712,7 +712,7 @@
 1000000000000000000;
 .7777777777777777777777777777777777777 *
 1000000000000000000
-777777777777777777.7777777777777777777000000000000000000
+777777777777777777.7777777777777777777000000000000
 select .7777777777777777777777777777777777777 - 0.1;
 .7777777777777777777777777777777777777 - 0.1
 0.6777777777777777777777777777777777777
@@ -772,7 +772,7 @@
 -99999999999999999.999
 select truncate(99999999999999999999999999999999999999,31);
 truncate(99999999999999999999999999999999999999,31)
-99999999999999999999999999999999999999.000000000000000000000000000
+99999999999999999999999999999999999999.0000000000000000000000000000000
 select truncate(99.999999999999999999999999999999999999,31);
 truncate(99.999999999999999999999999999999999999,31)
 99.9999999999999999999999999999999
@@ -783,7 +783,7 @@
 show create table t1;
 Table	Create Table
 t1	CREATE TABLE `t1` (
-  `0.5` decimal(3,1) NOT NULL default '0.0'
+  `0.5` decimal(2,1) NOT NULL default '0.0'
 ) ENGINE=MyISAM DEFAULT CHARSET=latin1
 drop table t1;
 select round(1.5),round(2.5);

--- 1.8/sql/my_decimal.cc	Fri Apr  1 17:04:44 2005
+++ 1.9/sql/my_decimal.cc	Wed Apr 13 12:06:50 2005
@@ -123,7 +123,7 @@
   int err1= E_DEC_OK, err2;
   my_decimal rounded;
   my_decimal2decimal(d, &rounded);
-  decimal_optimize_fraction(&rounded);
+  rounded.frac= decimal_actual_fraction(&rounded);
   if (scale < rounded.frac)
   {
     err1= E_DEC_TRUNCATED;
@@ -220,7 +220,8 @@
 }
 
 
-void dbug_print_decimal(const char *tag, const char *format, my_decimal *val)
+void dbug_print_decimal(const char *tag,
+                        const char *format, const my_decimal *val)
 {
   char buff[DECIMAL_MAX_STR_LENGTH];
   String str(buff, sizeof(buff), &my_charset_bin);

--- 1.4/mysql-test/r/sum_distinct.result	Thu Apr  7 21:24:08 2005
+++ 1.5/mysql-test/r/sum_distinct.result	Wed Apr 13 12:34:58 2005
@@ -95,3 +95,109 @@
 SUM(DISTINCT id % 11)
 55
 DROP TABLE t1;
+CREATE TABLE t1 (id INTEGER);
+CREATE TABLE t2 (id INTEGER);
+INSERT INTO t1 (id) VALUES (1), (1), (1),(1);
+INSERT INTO t1 (id) SELECT id FROM t1;
+/* 8 */
+INSERT INTO t1 (id) SELECT id FROM t1;
+/* 12 */
+INSERT INTO t1 (id) SELECT id FROM t1;
+/* 16 */
+INSERT INTO t1 (id) SELECT id FROM t1;
+/* 20 */
+INSERT INTO t1 (id) SELECT id FROM t1;
+/* 24 */
+INSERT INTO t1 SELECT id+1 FROM t1;
+INSERT INTO t1 SELECT id+2 FROM t1;
+INSERT INTO t1 SELECT id+4 FROM t1;
+INSERT INTO t1 SELECT id+8 FROM t1;
+INSERT INTO t1 SELECT id+16 FROM t1;
+INSERT INTO t1 SELECT id+32 FROM t1;
+INSERT INTO t1 SELECT id+64 FROM t1;
+INSERT INTO t1 SELECT id+128 FROM t1;
+INSERT INTO t1 SELECT id+256 FROM t1;
+INSERT INTO t1 SELECT id+512 FROM t1;
+SELECT AVG(DISTINCT id) FROM t1 GROUP BY id % 13;
+AVG(DISTINCT id)
+513.5000
+508.0000
+509.0000
+510.0000
+511.0000
+512.0000
+513.0000
+514.0000
+515.0000
+516.0000
+517.0000
+511.5000
+512.5000
+SELECT SUM(DISTINCT id)/COUNT(DISTINCT id) FROM t1 GROUP BY id % 13;
+SUM(DISTINCT id)/COUNT(DISTINCT id)
+513.5000
+508.0000
+509.0000
+510.0000
+511.0000
+512.0000
+513.0000
+514.0000
+515.0000
+516.0000
+517.0000
+511.5000
+512.5000
+INSERT INTO t1 SELECT id+1024 FROM t1;
+INSERT INTO t1 SELECT id+2048 FROM t1;
+INSERT INTO t1 SELECT id+4096 FROM t1;
+INSERT INTO t1 SELECT id+8192 FROM t1;
+INSERT INTO t2 SELECT id FROM t1 ORDER BY id*rand();
+SELECT SUM(DISTINCT id) sm FROM t1;
+sm
+134225920
+SELECT SUM(DISTINCT id) sm FROM t2;
+sm
+134225920
+SELECT SUM(DISTINCT id) sm FROM t1 group by id % 13;
+sm
+10327590
+10328851
+10330112
+10331373
+10332634
+10317510
+10318770
+10320030
+10321290
+10322550
+10323810
+10325070
+10326330
+SET max_heap_table_size=16384;
+SHOW variables LIKE 'max_heap_table_size';
+Variable_name	Value
+max_heap_table_size	16384
+SELECT SUM(DISTINCT id) sm FROM t1;
+sm
+134225920
+SELECT SUM(DISTINCT id) sm FROM t2;
+sm
+134225920
+SELECT SUM(DISTINCT id) sm FROM t1 GROUP BY id % 13;
+sm
+10327590
+10328851
+10330112
+10331373
+10332634
+10317510
+10318770
+10320030
+10321290
+10322550
+10323810
+10325070
+10326330
+DROP TABLE t1;
+DROP TABLE t2;

--- 1.84/mysql-test/r/create.result	Wed Apr  6 07:45:07 2005
+++ 1.85/mysql-test/r/create.result	Wed Apr 13 12:06:48 2005
@@ -116,7 +116,7 @@
 b	time	NO		00:00:00	
 c	date	NO		0000-00-00	
 d	int(2)	NO		0	
-e	decimal(6,1)	NO		0.0	
+e	decimal(3,1)	NO		0.0	
 f	bigint(18)	NO		0	
 drop table t2;
 create table t2 select CAST("2001-12-29" AS DATE) as d, CAST("20:45:11" AS TIME) as t, CAST("2001-12-29  20:45:11" AS DATETIME) as dt;
@@ -434,7 +434,7 @@
 e	varchar(1)	NO			
 f	datetime	YES		NULL	
 g	time	YES		NULL	
-h	varbinary(23)	NO			
+h	longblob	NO			
 dd	time	YES		NULL	
 select * from t2;
 a	b	c	d	e	f	g	h	dd
@@ -453,7 +453,7 @@
   `ifnull(e,e)` bigint(20) default NULL,
   `ifnull(f,f)` float(3,2) default NULL,
   `ifnull(g,g)` double(4,3) default NULL,
-  `ifnull(h,h)` decimal(6,4) default NULL,
+  `ifnull(h,h)` decimal(5,4) default NULL,
   `ifnull(i,i)` year(4) default NULL,
   `ifnull(j,j)` date default NULL,
   `ifnull(k,k)` datetime NOT NULL default '0000-00-00 00:00:00',

--- 1.43/mysql-test/r/func_group.result	Thu Mar 31 12:39:42 2005
+++ 1.44/mysql-test/r/func_group.result	Wed Apr 13 12:06:48 2005
@@ -901,42 +901,42 @@
 (3,3,1), (3,3,2), (3,3,3);
 SELECT b/c as v, a FROM t1 ORDER BY v;
 v	a
-0.33333	3
-0.33333	1
-0.33333	2
-0.50000	1
-0.50000	2
-0.50000	3
-0.66667	2
-0.66667	1
-0.66667	3
-1.00000	3
-1.00000	2
-1.00000	3
-1.00000	1
-1.00000	2
-1.00000	3
-1.00000	2
-1.00000	1
-1.00000	1
-1.50000	3
-1.50000	2
-1.50000	1
-2.00000	1
-2.00000	3
-2.00000	2
-3.00000	3
-3.00000	2
-3.00000	1
+0.3333	3
+0.3333	1
+0.3333	2
+0.5000	1
+0.5000	2
+0.5000	3
+0.6667	2
+0.6667	1
+0.6667	3
+1.0000	3
+1.0000	2
+1.0000	3
+1.0000	1
+1.0000	2
+1.0000	3
+1.0000	2
+1.0000	1
+1.0000	1
+1.5000	3
+1.5000	2
+1.5000	1
+2.0000	1
+2.0000	3
+2.0000	2
+3.0000	3
+3.0000	2
+3.0000	1
 SELECT b/c as v, SUM(a) FROM t1 GROUP BY v;
 v	SUM(a)
-0.33333	6
-0.50000	6
-0.66667	6
-1.00000	18
-1.50000	6
-2.00000	6
-3.00000	6
+0.3333	6
+0.5000	6
+0.6667	6
+1.0000	18
+1.5000	6
+2.0000	6
+3.0000	6
 SELECT SUM(a) FROM t1 GROUP BY b/c;
 SUM(a)
 6

--- 1.47/mysql-test/r/group_by.result	Fri Apr  1 13:00:28 2005
+++ 1.48/mysql-test/r/group_by.result	Wed Apr 13 12:06:48 2005
@@ -440,12 +440,15 @@
 insert into t2 values (1, '2002-06-09'),(2, '2002-06-09'),(1, '2002-06-09'),(3, '2002-06-09'),(4, '2002-06-09'),(4, '2002-06-09');
 select u.gender as gender, count(distinct  u.id) as dist_count, (count(distinct u.id)/5*100) as percentage from t1 u, t2 l where l.user_id = u.id group by u.gender;
 gender	dist_count	percentage
-F	3	60.00000
-M	1	20.00000
+F	3	60.0000
+M	1	20.0000
 select u.gender as  gender, count(distinct  u.id) as dist_count, (count(distinct u.id)/5*100) as percentage from t1 u, t2 l where l.user_id = u.id group by u.gender  order by percentage;
 gender	dist_count	percentage
-M	1	20.00000
-F	3	60.00000
+F	3	60.0000
+M	1	20.0000
+Warnings:
+Error	1264	Out of range value adjusted for column '' at row -1
+Error	1264	Out of range value adjusted for column '' at row -1
 drop table t1,t2;
 CREATE TABLE t1 (ID1 int, ID2 int, ID int NOT NULL AUTO_INCREMENT,PRIMARY KEY(ID
 ));

--- 1.55/mysql-test/r/select.result	Sat Apr  2 08:17:13 2005
+++ 1.56/mysql-test/r/select.result	Wed Apr 13 12:06:49 2005
@@ -1672,7 +1672,7 @@
 158402	4181
 select sum(Period)/count(*) from t1;
 sum(Period)/count(*)
-9410.00000
+9410.0000
 select companynr,count(price) as "count",sum(price) as "sum" ,abs(sum(price)/count(price)-avg(price)) as "diff",(0+count(price))*companynr as func from t3 group by companynr;
 companynr	count	sum	diff	func
 37	12543	309394878010	0.0000	464091
@@ -1684,7 +1684,7 @@
 512	4181	3288532102	0.0000	2140672
 select companynr,sum(price)/count(price) as avg from t3 group by companynr having avg > 70000000 order by avg;
 companynr	avg
-154	983543950.00
+154	983543950.0000
 select companynr,count(*) from t2 group by companynr order by 2 desc;
 companynr	count(*)
 37	588

--- 1.60/mysql-test/r/variables.result	Sat Apr  2 08:02:07 2005
+++ 1.61/mysql-test/r/variables.result	Wed Apr 13 12:06:49 2005
@@ -504,7 +504,7 @@
 Table	Create Table
 t1	CREATE TABLE `t1` (
   `c1` bigint(20) default NULL,
-  `c2` decimal(64,30) default NULL,
+  `c2` decimal(65,31) default NULL,
   `c3` longtext,
   `c4` double default NULL
 ) ENGINE=MyISAM DEFAULT CHARSET=latin1

--- 1.103/sql/set_var.cc	Tue Apr  5 16:17:40 2005
+++ 1.104/sql/set_var.cc	Wed Apr 13 12:06:51 2005
@@ -295,6 +295,8 @@
 sys_var_bool_ptr	sys_readonly("read_only", &opt_readonly);
 sys_var_thd_ulong	sys_read_rnd_buff_size("read_rnd_buffer_size",
 					       &SV::read_rnd_buff_size);
+sys_var_thd_ulong	sys_div_precincrement("div_precision_increment",
+                                              &SV::div_precincrement);
 #ifdef HAVE_REPLICATION
 sys_var_bool_ptr	sys_relay_log_purge("relay_log_purge",
                                             &relay_log_purge);
@@ -565,6 +567,7 @@
   &sys_connect_timeout,
   &sys_date_format,
   &sys_datetime_format,
+  &sys_div_precincrement,
   &sys_default_week_format,
   &sys_delay_key_write,
   &sys_delayed_insert_limit,
@@ -751,6 +754,7 @@
   {"datadir",                 mysql_real_data_home,                 SHOW_CHAR},
   {sys_date_format.name,      (char*) &sys_date_format,		    SHOW_SYS},
   {sys_datetime_format.name,  (char*) &sys_datetime_format,	    SHOW_SYS},
+  {sys_div_precincrement.name,(char*) &sys_div_precincrement,SHOW_SYS},
   {sys_default_week_format.name, (char*) &sys_default_week_format,  SHOW_SYS},
   {sys_delay_key_write.name,  (char*) &sys_delay_key_write,         SHOW_SYS},
   {sys_delayed_insert_limit.name, (char*) &sys_delayed_insert_limit,SHOW_SYS},

--- 1.10/mysql-test/r/metadata.result	Thu Mar 31 01:31:11 2005
+++ 1.11/mysql-test/r/metadata.result	Wed Apr 13 12:06:48 2005
@@ -18,7 +18,7 @@
 def	test	t1	t1	e	e	8	20	0	Y	32768	0	63
 def	test	t1	t1	f	f	4	3	0	Y	32768	2	63
 def	test	t1	t1	g	g	5	4	0	Y	32768	3	63
-def	test	t1	t1	h	h	246	5	0	Y	0	4	63
+def	test	t1	t1	h	h	246	7	0	Y	0	4	63
 def	test	t1	t1	i	i	13	4	0	Y	32864	0	63
 def	test	t1	t1	j	j	10	10	0	Y	128	0	63
 def	test	t1	t1	k	k	7	19	0	N	1249	0	63

--- 1.44/strings/decimal.c	Wed Apr  6 19:22:16 2005
+++ 1.45/strings/decimal.c	Wed Apr 13 12:06:52 2005
@@ -274,20 +274,20 @@
 
 
 /*
-  Remove ending 0 digits from fraction part
+  Count actual length of fraction part (without ending zeroes)
 
   SYNOPSIS
-    decimal_optimize_fraction()
+    decimal_actual_fraction()
     from    number for processing
 */
 
-void decimal_optimize_fraction(decimal_t *from)
+int decimal_actual_fraction(decimal_t *from)
 {
   int frac= from->frac, i;
   dec1 *buf0= from->buf + ROUND_UP(from->intg) + ROUND_UP(frac) - 1;
 
   if (frac == 0)
-    return;
+    return 0;
 
   i= ((frac - 1) % DIG_PER_DEC1 + 1);
   while (frac > 0 && *buf0 == 0)
@@ -302,7 +302,7 @@
          *buf0 % powers10[i++] == 0;
          frac--);
   }
-  from->frac= frac;
+  return frac;
 }
 
 
@@ -332,7 +332,7 @@
                    int fixed_precision, int fixed_decimals,
                    char filler)
 {
-  int len, intg, frac=from->frac, i, intg_len, frac_len, fill;
+  int len, intg, frac= from->frac, i, intg_len, frac_len, fill;
   /* number digits before decimal point */
   int fixed_intg= (fixed_precision ?
                    (fixed_precision -
@@ -2609,7 +2609,7 @@
   printf("%-40s =>          ", s);
   end= strend(s1);
   string2decimal(s1, &a, &end);
-  decimal_optimize_fraction(&a);
+  a.frac= decimal_actual_fraction(&a);
   print_decimal(&a, orig, 0, 0);
   printf("\n");
 }
@@ -2947,7 +2947,7 @@
   test_sh("123456789.987654321", 0, "123456789.987654321", 0);
   a.len= sizeof(buf1)/sizeof(dec1);
 
-  printf("==== decimal_optimize_fraction ====\n");
+  printf("==== decimal_actual_fraction ====\n");
   test_fr("1.123456789000000000", "1.123456789");
   test_fr("1.12345678000000000", "1.12345678");
   test_fr("1.1234567000000000", "1.1234567");
Thread
bk commit into 5.0 tree (hf:1.1820)holyfoot13 Apr