Below is the list of changes that have just been committed into a local
4.0 repository of gluh. When gluh 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://www.mysql.com/doc/I/n/Installing_source_tree.html
ChangeSet
1.2004 04/09/04 11:35:57 gluh@stripped +4 -0
Fix for bug #4388: Aggregate Functions Return Wrong Column Type
sql/item_sum.h
1.27 04/09/04 11:35:54 gluh@stripped +3 -1
Fix for bug #4388: Aggregate Functions Return Wrong Column Type
sql/item_sum.cc
1.39 04/09/04 11:35:54 gluh@stripped +53 -13
Fix for bug #4388: Aggregate Functions Return Wrong Column Type
mysql-test/t/func_group.test
1.10 04/09/04 11:35:54 gluh@stripped +9 -0
Fix for bug #4388: Aggregate Functions Return Wrong Column Type
mysql-test/r/func_group.result
1.14 04/09/04 11:35:54 gluh@stripped +8 -0
Fix for bug #4388: Aggregate Functions Return Wrong Column Type
# 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: gluh
# Host: gluh.mysql.r18.ru
# Root: /home/gluh/MySQL-BUGS/mysql-4.0
--- 1.38/sql/item_sum.cc Wed Dec 10 22:26:29 2003
+++ 1.39/sql/item_sum.cc Sat Sep 4 11:35:54 2004
@@ -143,6 +143,20 @@
}
+void Item_sum_sum::fix_length_and_dec()
+{
+ maybe_null=null_value=1;
+ hybrid_type= args[0]->result_type() == INT_RESULT ? INT_RESULT : REAL_RESULT;
+ if (hybrid_type == INT_RESULT)
+ {
+ decimals=0;
+ max_length=21;
+ }
+ else
+ max_length=float_length(decimals);
+}
+
+
bool
Item_sum_hybrid::fix_fields(THD *thd,TABLE_LIST *tables)
{
@@ -572,12 +586,24 @@
void Item_sum_sum::reset_field()
{
- double nr=args[0]->val(); // Nulls also return 0
- float8store(result_field->ptr,nr);
- if (args[0]->null_value)
- result_field->set_null();
+ if (hybrid_type == INT_RESULT)
+ {
+ longlong nr=args[0]->val_int(); // Nulls also return 0
+ int8store(result_field->ptr,nr);
+ if (args[0]->null_value)
+ result_field->set_null();
+ else
+ result_field->set_notnull();
+ }
else
- result_field->set_notnull();
+ {
+ double nr=args[0]->val(); // Nulls also return 0
+ float8store(result_field->ptr,nr);
+ if (args[0]->null_value)
+ result_field->set_null();
+ else
+ result_field->set_notnull();
+ }
}
@@ -634,17 +660,31 @@
void Item_sum_sum::update_field()
{
- double old_nr,nr;
char *res=result_field->ptr;
-
- float8get(old_nr,res);
- nr=args[0]->val();
- if (!args[0]->null_value)
+ if (hybrid_type == INT_RESULT)
{
- old_nr+=nr;
- result_field->set_notnull();
+ longlong old_nr,nr;
+ old_nr= uint8korr(res);
+ nr=args[0]->val_int();
+ if (!args[0]->null_value)
+ {
+ old_nr+=nr;
+ result_field->set_notnull();
+ }
+ int8store(res,old_nr);
+ }
+ else
+ {
+ double old_nr,nr;
+ float8get(old_nr,res);
+ nr=args[0]->val();
+ if (!args[0]->null_value)
+ {
+ old_nr+=nr;
+ result_field->set_notnull();
+ }
+ float8store(res,old_nr);
}
- float8store(res,old_nr);
}
--- 1.26/sql/item_sum.h Sun Aug 1 00:39:08 2004
+++ 1.27/sql/item_sum.h Sat Sep 4 11:35:54 2004
@@ -118,11 +118,13 @@
class Item_sum_sum :public Item_sum_num
{
double sum;
- void fix_length_and_dec() { maybe_null=null_value=1; }
+ Item_result hybrid_type;
+ void fix_length_and_dec();
public:
Item_sum_sum(Item *item_par) :Item_sum_num(item_par),sum(0.0) {}
enum Sumfunctype sum_func () const {return SUM_FUNC;}
+ enum Item_result result_type () const { return hybrid_type; };
void reset();
bool add();
double val();
--- 1.13/mysql-test/r/func_group.result Fri Apr 9 18:07:21 2004
+++ 1.14/mysql-test/r/func_group.result Sat Sep 4 11:35:54 2004
@@ -261,3 +261,11 @@
avg(2)
NULL
drop table t1;
+create table t1(a int, b float);
+insert into t1 values (1, 0.5),(2, 0.7);
+create table t2 select sum(a), sum(b) from t1;
+describe t2;
+Field Type Null Key Default Extra
+sum(a) bigint(21) YES NULL
+sum(b) double YES NULL
+drop table t1,t2;
--- 1.9/mysql-test/t/func_group.test Fri Apr 9 18:07:21 2004
+++ 1.10/mysql-test/t/func_group.test Sat Sep 4 11:35:54 2004
@@ -163,3 +163,12 @@
create table t1 (a int);
select avg(2) from t1;
drop table t1;
+
+#
+# Bug #4388: Aggregate Functions Return Wrong Column Type
+#
+create table t1(a int, b float);
+insert into t1 values (1, 0.5),(2, 0.7);
+create table t2 select sum(a), sum(b) from t1;
+describe t2;
+drop table t1,t2;
| Thread |
|---|
| • bk commit into 4.0 tree (gluh:1.2004) | gluh | 4 Sep |