mirror of
https://github.com/MariaDB/server.git
synced 2025-09-02 09:41:40 +03:00
Bug#30889: filesort and order by with float/numeric crashes server
There are two problems with ROUND(X, D) on an exact numeric (DECIMAL, NUMERIC type) field of a table: 1) The implementation of the ROUND function would change the number of decimal places regardless of the value decided upon in fix_length_and_dec. When the number of decimal places is not constant, this would cause an inconsistent state where the number of digits was less than the number of decimal places, which crashes filesort. Fixed by not allowing the ROUND operation to add any more decimal places than was decided in fix_length_and_dec. 2) fix_length_and_dec would allow the number of decimals to be greater than the maximium configured value for constant values of D. This led to the same crash as in (1). Fixed by not allowing the above in fix_length_and_dec.
This commit is contained in:
@@ -822,4 +822,71 @@ this must not produce error 1048:
|
||||
select * from t1 where ua_invited_by_id not in (select ua_id from t1);
|
||||
ua_id ua_invited_by_id
|
||||
drop table t1;
|
||||
DROP TABLE IF EXISTS t3;
|
||||
DROP TABLE IF EXISTS t4;
|
||||
CREATE TABLE t1( a NUMERIC, b INT );
|
||||
INSERT INTO t1 VALUES (123456, 40), (123456, 40);
|
||||
SELECT TRUNCATE( a, b ) AS c FROM t1 ORDER BY c;
|
||||
c
|
||||
123456
|
||||
123456
|
||||
SELECT ROUND( a, b ) AS c FROM t1 ORDER BY c;
|
||||
c
|
||||
123456
|
||||
123456
|
||||
SELECT ROUND( a, 100 ) AS c FROM t1 ORDER BY c;
|
||||
c
|
||||
123456.000000000000000000000000000000
|
||||
123456.000000000000000000000000000000
|
||||
CREATE TABLE t2( a NUMERIC, b INT );
|
||||
INSERT INTO t2 VALUES (123456, 100);
|
||||
SELECT TRUNCATE( a, b ) AS c FROM t2 ORDER BY c;
|
||||
c
|
||||
123456
|
||||
SELECT ROUND( a, b ) AS c FROM t2 ORDER BY c;
|
||||
c
|
||||
123456
|
||||
CREATE TABLE t3( a DECIMAL, b INT );
|
||||
INSERT INTO t3 VALUES (123456, 40), (123456, 40);
|
||||
SELECT TRUNCATE( a, b ) AS c FROM t3 ORDER BY c;
|
||||
c
|
||||
123456
|
||||
123456
|
||||
SELECT ROUND( a, b ) AS c FROM t3 ORDER BY c;
|
||||
c
|
||||
123456
|
||||
123456
|
||||
SELECT ROUND( a, 100 ) AS c FROM t3 ORDER BY c;
|
||||
c
|
||||
123456.000000000000000000000000000000
|
||||
123456.000000000000000000000000000000
|
||||
CREATE TABLE t4( a DECIMAL, b INT );
|
||||
INSERT INTO t4 VALUES (123456, 40), (123456, 40);
|
||||
SELECT TRUNCATE( a, b ) AS c FROM t4 ORDER BY c;
|
||||
c
|
||||
123456
|
||||
123456
|
||||
SELECT ROUND( a, b ) AS c FROM t4 ORDER BY c;
|
||||
c
|
||||
123456
|
||||
123456
|
||||
SELECT ROUND( a, 100 ) AS c FROM t4 ORDER BY c;
|
||||
c
|
||||
123456.000000000000000000000000000000
|
||||
123456.000000000000000000000000000000
|
||||
delete from t1;
|
||||
INSERT INTO t1 VALUES (1234567890, 20), (999.99, 5);
|
||||
Warnings:
|
||||
Note 1265 Data truncated for column 'a' at row 2
|
||||
show create table t1;
|
||||
Table Create Table
|
||||
t1 CREATE TABLE `t1` (
|
||||
`a` decimal(10,0) default NULL,
|
||||
`b` int(11) default NULL
|
||||
) ENGINE=MyISAM DEFAULT CHARSET=latin1
|
||||
select round(a,b) as c from t1 order by c;
|
||||
c
|
||||
1000
|
||||
1234567890
|
||||
DROP TABLE t1, t2, t3, t4;
|
||||
End of 5.0 tests
|
||||
|
Reference in New Issue
Block a user