Skip to content

Commit b346b48

Browse files
committed
Bug#34554865: Hypergraph: Duplicate FLOAT values with SELECT DISTINCT
When SELECT DISTINCT is performed as a "sort with duplicate removal" and the select list contains FLOAT values, duplicates may be returned because Filesort compares the values as DOUBLE and sees differences in insignificant digits. Fixed by truncating the double values to float to remove the insignificant digits before the sort key is created. Change-Id: Iad9c1f2b3fdb69001ef9b68773e45f5c1dde490e
1 parent 9af2fc3 commit b346b48

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

mysql-test/t/distinct.test

+1-1
Original file line numberDiff line numberDiff line change
@@ -984,8 +984,8 @@ INSERT INTO t1 VALUES
984984
(-2007568257), (-2007568260), (-2007570000), (-2007567234), (-2007567230),
985985
(2007568257), (2007568260), (2007570000), (2007567234), (2007567230);
986986

987-
--skip_if_hypergraph # Bug#34119506
988987
SELECT SQL_SMALL_RESULT DISTINCT CAST(v AS FLOAT) FROM t1;
988+
--skip_if_hypergraph # Incorrect results recorded. Bug#34554755.
989989
SELECT SQL_BIG_RESULT DISTINCT CAST(v AS FLOAT) FROM t1;
990990

991991
DROP TABLE t1;

sql/filesort.cc

+6
Original file line numberDiff line numberDiff line change
@@ -1356,6 +1356,12 @@ size_t make_sortkey_from_item(Item *item, Item_result result_type,
13561356
case REAL_RESULT: {
13571357
assert(!is_varlen);
13581358
double value = item->val_real();
1359+
if (item->data_type() == MYSQL_TYPE_FLOAT) {
1360+
// Get rid of extra precision. Otherwise, duplicate removal may make the
1361+
// wrong decision and treat equal values as distinct values due to
1362+
// differences in the insignificant digits.
1363+
value = static_cast<float>(value);
1364+
}
13591365
if (item->null_value) {
13601366
assert(item->is_nullable());
13611367
*null_indicator = 0;

0 commit comments

Comments
 (0)