• Alexander Barkov's avatar
    MDEV-34085 Server crash ASAN used-after-poison upon 2nd execution of PS with... · 0e8e1575
    Alexander Barkov authored
    MDEV-34085 Server crash ASAN used-after-poison upon 2nd execution of PS with erroneous timestamp conversion
    
    The optimization code replacing DATETIME comparison to TIMESTAMP comparison
    in conditions like:
    - WHERE timestamp_col=const_expr
    - WHERE const_expr IN (SELECT timestamp_column FROM t1)
    worked as follows:
    
    - Install an internal condition handler (suppressing and counting warnings).
    - Convert const_expr from its data type to TIMESTAMP
    - Check the warning count collected by the internal condition handler:
      * If any warnings happened during the constant conversion,
        then continue with DATETIME comparison.
      * Otherwise, go to the next stage of switching to TIMESTAMP comparison.
    
    This scenario did not take into account that in some cases warnings
    are escalated to errors. Errors were not caught by the internal handler,
    so Type_handler_datetime_common::convert_item_for_comparison()
    returned with an SQL error in the diagnostics area.
    The calling code did not expect this.
    
    Fixing the code to suppress and count both errors and warnings, to make sure
    Type_handler_datetime_common::convert_item_for_comparison() returns without
    adding any errors to DA if the conversion to TIMESTAMP fails and it decides
    to go with DATETIME comparison.
    0e8e1575
sql_type.cc 299 KB