Commit a2bdd621 authored by unknown's avatar unknown

Post-review fixes for bug #1790 'BIT_AND() result in GROUP BY different when

 SQL_BIG_RESULT used':
- BIT_AND now returns BIGINT UNSIGNED
- in case there were no matching rows BIT_AND returns 18446744073709551615 
(but not NULL), BIT_OR returns 0 (but not NULL). That's how Monty wants it
and how is described in our docs.




include/my_global.h:
  Added definition for ULONGLONG_MAX.
  This is also a check that ULL type specifier
  can be used on all supported platforms.
mysql-test/r/func_group.result:
  bug #1790, post-review work: test results fixed
sql/item_sum.cc:
  small cleanup
sql/item_sum.h:
  few style fixes.
  BIT_AND and BIT_OR now are both BIGINT UNSIGNED
parent 363c4e8a
...@@ -603,11 +603,25 @@ extern double my_atof(const char*); ...@@ -603,11 +603,25 @@ extern double my_atof(const char*);
#define HAVE_LONG_LONG 1 #define HAVE_LONG_LONG 1
#endif #endif
/*
Some pre-ANSI-C99 systems like AIX 5.1 and Linux/GCC 2.95 define
ULONGLONG_MAX, LONGLONG_MIN, LONGLONG_MAX; we use them if they're defined.
*/
#if defined(HAVE_LONG_LONG) && !defined(LONGLONG_MIN) #if defined(HAVE_LONG_LONG) && !defined(LONGLONG_MIN)
#define LONGLONG_MIN ((long long) 0x8000000000000000LL) #define LONGLONG_MIN ((long long) 0x8000000000000000LL)
#define LONGLONG_MAX ((long long) 0x7FFFFFFFFFFFFFFFLL) #define LONGLONG_MAX ((long long) 0x7FFFFFFFFFFFFFFFLL)
#endif #endif
#if defined(HAVE_LONG_LONG) && !defined(ULONLONG_MAX)
/* First check for ANSI C99 definition: */
#ifdef ULLONG_MAX
#define ULONGLONG_MAX ULLONG_MAX
#else
#define ULONGLONG_MAX ((unsigned long long)(~0ULL))
#endif
#endif /* defined (HAVE_LONG_LONG) && !defined(ULONLONG_MAX)*/
#if SIZEOF_LONG == 4 #if SIZEOF_LONG == 4
#define INT_MIN32 (long) 0x80000000L #define INT_MIN32 (long) 0x80000000L
#define INT_MAX32 (long) 0x7FFFFFFFL #define INT_MAX32 (long) 0x7FFFFFFFL
......
...@@ -47,7 +47,7 @@ sum(all a) count(all a) avg(all a) std(all a) bit_or(all a) bit_and(all a) min(a ...@@ -47,7 +47,7 @@ sum(all a) count(all a) avg(all a) std(all a) bit_or(all a) bit_and(all a) min(a
21 6 3.5000 1.7078 7 0 1 6 E 21 6 3.5000 1.7078 7 0 1 6 E
select grp, sum(a),count(a),avg(a),std(a),bit_or(a),bit_and(a),min(a),max(a),min(c),max(c) from t1 group by grp; select grp, sum(a),count(a),avg(a),std(a),bit_or(a),bit_and(a),min(a),max(a),min(c),max(c) from t1 group by grp;
grp sum(a) count(a) avg(a) std(a) bit_or(a) bit_and(a) min(a) max(a) min(c) max(c) grp sum(a) count(a) avg(a) std(a) bit_or(a) bit_and(a) min(a) max(a) min(c) max(c)
NULL NULL 0 NULL NULL 0 -1 NULL NULL NULL NULL 0 NULL NULL 0 18446744073709551615 NULL NULL
1 1 1 1.0000 0.0000 1 1 1 1 a a 1 1 1 1.0000 0.0000 1 1 1 1 a a
2 5 2 2.5000 0.5000 3 2 2 3 b c 2 5 2 2.5000 0.5000 3 2 2 3 b c
3 15 3 5.0000 0.8165 7 4 4 6 C E 3 15 3 5.0000 0.8165 7 4 4 6 C E
...@@ -218,8 +218,8 @@ insert into t1 values (1,null); ...@@ -218,8 +218,8 @@ insert into t1 values (1,null);
insert into t1 values (2,null); insert into t1 values (2,null);
select a,count(b), sum(b), avg(b), std(b), min(b), max(b), bit_and(b), bit_or(b) from t1 group by a; select a,count(b), sum(b), avg(b), std(b), min(b), max(b), bit_and(b), bit_or(b) from t1 group by a;
a count(b) sum(b) avg(b) std(b) min(b) max(b) bit_and(b) bit_or(b) a count(b) sum(b) avg(b) std(b) min(b) max(b) bit_and(b) bit_or(b)
1 0 NULL NULL NULL NULL NULL -1 0 1 0 NULL NULL NULL NULL NULL 18446744073709551615 0
2 0 NULL NULL NULL NULL NULL -1 0 2 0 NULL NULL NULL NULL NULL 18446744073709551615 0
select SQL_BIG_RESULT a,count(b), sum(b), avg(b), std(b), min(b), max(b), bit_and(b), bit_or(b) from t1 group by a; select SQL_BIG_RESULT a,count(b), sum(b), avg(b), std(b), min(b), max(b), bit_and(b), bit_or(b) from t1 group by a;
a count(b) sum(b) avg(b) std(b) min(b) max(b) bit_and(b) bit_or(b) a count(b) sum(b) avg(b) std(b) min(b) max(b) bit_and(b) bit_or(b)
1 0 NULL NULL NULL NULL NULL -1 0 1 0 NULL NULL NULL NULL NULL -1 0
...@@ -227,7 +227,7 @@ a count(b) sum(b) avg(b) std(b) min(b) max(b) bit_and(b) bit_or(b) ...@@ -227,7 +227,7 @@ a count(b) sum(b) avg(b) std(b) min(b) max(b) bit_and(b) bit_or(b)
insert into t1 values (2,1); insert into t1 values (2,1);
select a,count(b), sum(b), avg(b), std(b), min(b), max(b), bit_and(b), bit_or(b) from t1 group by a; select a,count(b), sum(b), avg(b), std(b), min(b), max(b), bit_and(b), bit_or(b) from t1 group by a;
a count(b) sum(b) avg(b) std(b) min(b) max(b) bit_and(b) bit_or(b) a count(b) sum(b) avg(b) std(b) min(b) max(b) bit_and(b) bit_or(b)
1 0 NULL NULL NULL NULL NULL -1 0 1 0 NULL NULL NULL NULL NULL 18446744073709551615 0
2 1 1 1.0000 0.0000 1 1 1 1 2 1 1 1.0000 0.0000 1 1 1 1
select SQL_BIG_RESULT a,count(b), sum(b), avg(b), std(b), min(b), max(b), bit_and(b), bit_or(b) from t1 group by a; select SQL_BIG_RESULT a,count(b), sum(b), avg(b), std(b), min(b), max(b), bit_and(b), bit_or(b) from t1 group by a;
a count(b) sum(b) avg(b) std(b) min(b) max(b) bit_and(b) bit_or(b) a count(b) sum(b) avg(b) std(b) min(b) max(b) bit_and(b) bit_or(b)
...@@ -236,7 +236,7 @@ a count(b) sum(b) avg(b) std(b) min(b) max(b) bit_and(b) bit_or(b) ...@@ -236,7 +236,7 @@ a count(b) sum(b) avg(b) std(b) min(b) max(b) bit_and(b) bit_or(b)
insert into t1 values (3,1); insert into t1 values (3,1);
select a,count(b), sum(b), avg(b), std(b), min(b), max(b), bit_and(b), bit_or(b) from t1 group by a; select a,count(b), sum(b), avg(b), std(b), min(b), max(b), bit_and(b), bit_or(b) from t1 group by a;
a count(b) sum(b) avg(b) std(b) min(b) max(b) bit_and(b) bit_or(b) a count(b) sum(b) avg(b) std(b) min(b) max(b) bit_and(b) bit_or(b)
1 0 NULL NULL NULL NULL NULL -1 0 1 0 NULL NULL NULL NULL NULL 18446744073709551615 0
2 1 1 1.0000 0.0000 1 1 1 1 2 1 1 1.0000 0.0000 1 1 1 1
3 1 1 1.0000 0.0000 1 1 1 1 3 1 1 1.0000 0.0000 1 1 1 1
select SQL_BIG_RESULT a,count(b), sum(b), avg(b), std(b), min(b), max(b), bit_and(b), bit_or(b) from t1 group by a; select SQL_BIG_RESULT a,count(b), sum(b), avg(b), std(b), min(b), max(b), bit_and(b), bit_or(b) from t1 group by a;
......
...@@ -615,10 +615,8 @@ void Item_sum_avg::reset_field() ...@@ -615,10 +615,8 @@ void Item_sum_avg::reset_field()
void Item_sum_bit::reset_field() void Item_sum_bit::reset_field()
{ {
char *res= result_field->ptr; reset();
bits= reset_bits; int8store(result_field->ptr, bits);
add();
int8store(res, bits);
} }
void Item_sum_bit::update_field() void Item_sum_bit::update_field()
......
...@@ -361,10 +361,10 @@ public: ...@@ -361,10 +361,10 @@ public:
class Item_sum_bit :public Item_sum_int class Item_sum_bit :public Item_sum_int
{ {
protected: protected:
ulonglong reset_bits,bits; ulonglong reset_bits,bits;
public: public:
Item_sum_bit(Item *item_par,ulonglong reset_arg) Item_sum_bit(Item *item_par,ulonglong reset_arg)
:Item_sum_int(item_par),reset_bits(reset_arg),bits(reset_arg) {} :Item_sum_int(item_par),reset_bits(reset_arg),bits(reset_arg) {}
enum Sumfunctype sum_func () const {return SUM_BIT_FUNC;} enum Sumfunctype sum_func () const {return SUM_BIT_FUNC;}
...@@ -373,6 +373,8 @@ class Item_sum_bit :public Item_sum_int ...@@ -373,6 +373,8 @@ class Item_sum_bit :public Item_sum_int
void reset_field(); void reset_field();
void update_field(); void update_field();
unsigned int size_of() { return sizeof(*this);} unsigned int size_of() { return sizeof(*this);}
void fix_length_and_dec()
{ decimals=0; max_length=21; unsigned_flag=1; maybe_null=null_value=0; }
}; };
...@@ -383,20 +385,16 @@ public: ...@@ -383,20 +385,16 @@ public:
bool add(); bool add();
const char *func_name() const { return "bit_or"; } const char *func_name() const { return "bit_or"; }
unsigned int size_of() { return sizeof(*this);} unsigned int size_of() { return sizeof(*this);}
void fix_length_and_dec()
{ decimals=0; max_length=21; unsigned_flag=1; maybe_null=null_value=0; }
}; };
class Item_sum_and :public Item_sum_bit class Item_sum_and :public Item_sum_bit
{ {
public: public:
Item_sum_and(Item *item_par) :Item_sum_bit(item_par, ~(ulonglong) LL(0)) {} Item_sum_and(Item *item_par) :Item_sum_bit(item_par, ULONGLONG_MAX) {}
bool add(); bool add();
const char *func_name() const { return "bit_and"; } const char *func_name() const { return "bit_and"; }
unsigned int size_of() { return sizeof(*this);} unsigned int size_of() { return sizeof(*this);}
void fix_length_and_dec()
{ decimals=0; max_length=21; unsigned_flag=0; maybe_null=null_value=0; }
}; };
/* /*
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment