← Back to team overview

maria-discuss team mailing list archive

Re: Bug in MAX() function?

 

Hello Benoit,

It might be useful to supply your table definitions. I did the following test and I can't find a problem. I am using 10.0.19-MariaDB.


CREATE TABLE t1
( 
	col1 INT, # have also tried defined as VARCHAR. No problem either.
	col2 INT
);

INSERT INTO `t1` (`col1`, `col2`) VALUES('8','58');
INSERT INTO `t1` (`col1`, `col2`) VALUES('8','48');
INSERT INTO `t1` (`col1`, `col2`) VALUES('4','63');
INSERT INTO `t1` (`col1`, `col2`) VALUES('9','53');
INSERT INTO `t1` (`col1`, `col2`) VALUES('2','36');
INSERT INTO `t1` (`col1`, `col2`) VALUES('0','12');
INSERT INTO `t1` (`col1`, `col2`) VALUES('3','2');
INSERT INTO `t1` (`col1`, `col2`) VALUES('0','2');
INSERT INTO `t1` (`col1`, `col2`) VALUES('0','6');
INSERT INTO `t1` (`col1`, `col2`) VALUES('0','2');
INSERT INTO `t1` (`col1`, `col2`) VALUES('0','9');
INSERT INTO `t1` (`col1`, `col2`) VALUES('0','44');
INSERT INTO `t1` (`col1`, `col2`) VALUES('14','63');
INSERT INTO `t1` (`col1`, `col2`) VALUES('0','96');
INSERT INTO `t1` (`col1`, `col2`) VALUES('7','43');
INSERT INTO `t1` (`col1`, `col2`) VALUES('4','66');
INSERT INTO `t1` (`col1`, `col2`) VALUES('2','43');
INSERT INTO `t1` (`col1`, `col2`) VALUES('2','66');
INSERT INTO `t1` (`col1`, `col2`) VALUES('0','63');
INSERT INTO `t1` (`col1`, `col2`) VALUES('6','48');
INSERT INTO `t1` (`col1`, `col2`) VALUES('2','52');


SELECT col1, col2, col1 + col2
FROM t1;

# Correctly returns 96
SELECT MAX(col1 + col2)
FROM  t1;


Cheers,

Rhys

-----Original Message-----
From: Maria-discuss [mailto:maria-discuss-bounces+rhys.campbell=tradingscreen.com@xxxxxxxxxxxxxxxxxxx] On Behalf Of Benoit Panizzon
Sent: 19 June 2015 09:59
To: maria-discuss@xxxxxxxxxxxxxxxxxxx
Subject: [Maria-discuss] Bug in MAX() function?

Hi all

I stumbled over that problem, while trying to graph mail traffic..

I have two different counters for emails sent with authentication and without. 
Aggregated per hour.

I would like to total the both values per row, to create a graph of outgoing emails per hour.

MariaDB [maildb]> select mail_out_anon,mail_out_auth from domaincounters;

+---------------+---------------+
| mail_out_anon | mail_out_auth |
+---------------+---------------+
|             8 |            58 |
|             8 |            48 |
|             4 |            63 |
|             9 |            53 |
|             2 |            36 |
|             0 |            12 |
|             3 |             2 |
|             0 |             2 |
|             0 |             6 |
|             0 |             2 |
|             0 |             9 |
|             0 |            44 |
|            14 |            63 |
|             0 |            96 |
|             7 |            43 |
|             4 |            61 |
|             2 |            43 |
|             2 |            66 |
|             0 |            86 |
|             6 |            77 |
|             6 |            55 |
|             0 |            63 |
|             6 |            48 |
|             2 |            52 |
+---------------+---------------+

> select mail_out_anon+mail_out_auth as mail_out_total from 
> domaincounters;

+-----------------------------+
| mail_out_anon+mail_out_auth |
+-----------------------------+
|                          70 |
|                          56 |
|                          67 |
|                          62 |
|                          38 |
|                          12 |
|                           5 |
|                           2 |
|                           6 |
|                           2 |
|                           9 |
|                          44 |
|                          77 |
|                          96 |
|                          50 |
|                          65 |
|                          45 |
|                          68 |
|                          86 |
|                          83 |
|                          61 |
|                          63 |
|                          54 |
|                          54 |
+-----------------------------+

Now I need the max value of that addition to auto-scale the graph.

MariaDB [maildb]> select MAX(mail_out_anon+mail_out_auth)
+----------------------------------+
| MAX(mail_out_anon+mail_out_auth) |
+----------------------------------+
|                              187 |
+----------------------------------+

What did MariaDB count here? I was expecting a value 96 which is the largest value of all the additions.

Also trying various ways of first using GREATEST() always returns a way to high value.

Is it a bug, or did I do something wrong?

Mit freundlichen Grüssen

Benoit Panizzon
-- 
I m p r o W a r e   A G    -    
______________________________________________________

Zurlindenstrasse 29             Tel  +41 61 826 93 07
CH-4133 Pratteln                Fax  +41 61 826 93 02
Schweiz                         Web  http://www.imp.ch
______________________________________________________

_______________________________________________
Mailing list: https://launchpad.net/~maria-discuss
Post to     : maria-discuss@xxxxxxxxxxxxxxxxxxx
Unsubscribe : https://launchpad.net/~maria-discuss
More help   : https://help.launchpad.net/ListHelp


References