mariadb/sql/init.cc
unknown faad73550c fix for bug #19690: ORDER BY eliminates rows from the result
Depending on the queries we use different data processing methods
and can lose some data in case of double (and decimal in 4.1) fields.

The fix consists of two parts:
1. double comparison changed, now double a is equal to double b 
if (a-b) is less than 5*0.1^(1 + max(a->decimals, b->decimals)). 
For example, if a->decimals==1, b->decimals==2, a==b if (a-b)<0.005
2. if we use a temporary table, store double values there as is 
to avoid any data conversion (rounding).


mysql-test/r/type_float.result:
  fix for bug #19690: ORDER BY eliminates rows from the result
    - test result
mysql-test/t/type_float.test:
  fix for bug #19690: ORDER BY eliminates rows from the result
    - test case
sql/field.cc:
  fix for bug #19690: ORDER BY eliminates rows from the result
    - use not_fixed flag instead of dec to check bounds.
sql/field.h:
  fix for bug #19690: ORDER BY eliminates rows from the result
    - Field_Double::not_fixed flag introduced, which is set if dec == NOT_FIXED_DEC
      and is used in the ::store() to check bounds. 
    - new constructor introduced (with not_fixed_arg parameter).
sql/init.cc:
  fix for bug #19690: ORDER BY eliminates rows from the result
    - fill log_01[] array with 0.1 powers.
sql/item_cmpfunc.cc:
  fix for bug #19690: ORDER BY eliminates rows from the result
    - compare_real_fixed() and compare_e_real_fixed() introduced,
      they consider double a == double b if a-b is less than 'precision',
      'precision' is set to 5*0.1^(1 + max(a->decimals, b->decimals)), 
      for example, if a->decimals==1, b->decimals==2, 'precision' is 0.005
    - use the above functions if both arguments are fixed.
sql/item_cmpfunc.h:
  fix for bug #19690: ORDER BY eliminates rows from the result
    - Arg_comparator::presision introduced.
    - Arg_comparator::compare_real_fixed(), Arg_comparator::compare_e_real_fixed() introduced.
sql/mysql_priv.h:
  fix for bug #19690: ORDER BY eliminates rows from the result
    - log_01 array of 0.1 powers added.
sql/mysqld.cc:
  fix for bug #19690: ORDER BY eliminates rows from the result
    - log_01 array of 0.1 powers added.
sql/sql_select.cc:
  fix for bug #19690: ORDER BY eliminates rows from the result
    - if we create double field in a temporary table, set not_fixed flag
      (use proper constructor) to avoid data conversion 
      in the Field_double::store(). Otherwise we can lose some data.
2007-01-31 09:51:05 +04:00

56 lines
1.8 KiB
C++

/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
/* Init and dummy functions for interface with unireg */
#include "mysql_priv.h"
#include <m_ctype.h>
void unireg_init(ulong options)
{
uint i;
double nr;
DBUG_ENTER("unireg_init");
MYSYS_PROGRAM_DONT_USE_CURSES();
abort_loop=0;
my_disable_async_io=1; /* aioread is only in shared library */
wild_many='%'; wild_one='_'; wild_prefix='\\'; /* Change to sql syntax */
current_pid=(ulong) getpid(); /* Save for later ref */
init_time(); /* Init time-functions (read zone) */
#ifndef EMBEDDED_LIBRARY
my_abort_hook=unireg_abort; /* Abort with close of databases */
#endif
VOID(strmov(reg_ext,".frm"));
specialflag=SPECIAL_SAME_DB_NAME;
/* Make a tab of powers of 10 */
for (i=0,nr=1.0; i < array_elements(log_10) ; i++)
{ /* It's used by filesort... */
log_10[i]= nr ; nr*= 10.0;
}
/* Make a tab of powers of 0.1 */
for (i= 0, nr= 0.1; i < array_elements(log_01); i++)
{
log_01[i]= nr;
nr*= 0.1;
}
specialflag|=options; /* Set options from argv */
DBUG_VOID_RETURN;
}