• unknown's avatar
    Bug#33143: Incorrect ORDER BY for ROUND()/TRUNCATE() result · f9440588
    unknown authored
    The ROUND(X, D) function would change the Item::decimals field during
    execution to achieve the effect of a dynamic number of decimal digits.
    This caused a series of bugs:
    Bug #30617:Round() function not working under some circumstances in InnoDB
    Bug #33402:ROUND with decimal and non-constant cannot round to 0 decimal places
    Bug #30889:filesort and order by with float/numeric crashes server
    Fixed by never changing the number of shown digits for DECIMAL when
    used with a nonconstant number of decimal digits.
    
    
    mysql-test/r/type_decimal.result:
      Bug#33143: Test result
    mysql-test/t/type_decimal.test:
      Bug#33143: Test case
    sql/item_func.cc:
      Bug#33143: 
      - Moved the DECIMAL_MAX_SCALE limitation to fix_length_and_dec.
      - Removed resetting of Item::decimals field.
      - set the frac field of the output value to current scale.
    strings/decimal.c:
      Bug#33143: It is necessary to set all digits in the buffer following the 
      rounded one to zero, as they may now be displayed.
    f9440588
decimal.c 85.5 KB