Skip to content
  • Roy Lyseng's avatar
    7205512e
    Bug#16325175: Function ifnull ignored when used with some others selects · 7205512e
    Roy Lyseng authored
    The problem statement has an aggregated, non-grouped outer query with
    an aggregated, non-grouped subquery in the SELECT list.
    
    The outer query has no rows, so in end_send_group() it calls
    no_rows_in_result() for all items in the SELECT list. For a scalar
    subquery, this causes "no_rows" to be set true, which later prevents
    the subquery from being evaluated when sending the result row for the
    outer query. This behavior was introduced with the fix for 13742712,
    where the inner subquery was dependent upon the outer, and evaluating
    the inner subquery caused references to unassigned columns in the outer
    query, when the outer query has no rows.
    
    However, in this bug case, the inner query is not dependent upon the
    outer query, and thus should be evaluated when sending data. The bug
    fix is to check whether the inner query is dependent upon the outer in
    Item_singlerow_subselect::no_rows_in_result(), and setting "no_rows"
    for this case only.
    
    Notice however that the case of dependent inner query is invalid
    according to standard SQL: setting sql_mode only_full_group_by rejects
    a query with dependent inner query with error 1140.
    
    Another problem with setting "no_rows" for such queries is that a COUNT
    function may return NULL, even though the function is specified to
    always return a non-negative integer. However, as this is an invalid
    query according toe the SQL standard, we will not worry about that
    problem for now.
    
    sql/item_subselect.cc
      In Item_singlerow_subselect::no_rows_in_result(), set no_rows true
      only when subquery is dependent on the outer query.
    7205512e
    Bug#16325175: Function ifnull ignored when used with some others selects
    Roy Lyseng authored
    The problem statement has an aggregated, non-grouped outer query with
    an aggregated, non-grouped subquery in the SELECT list.
    
    The outer query has no rows, so in end_send_group() it calls
    no_rows_in_result() for all items in the SELECT list. For a scalar
    subquery, this causes "no_rows" to be set true, which later prevents
    the subquery from being evaluated when sending the result row for the
    outer query. This behavior was introduced with the fix for 13742712,
    where the inner subquery was dependent upon the outer, and evaluating
    the inner subquery caused references to unassigned columns in the outer
    query, when the outer query has no rows.
    
    However, in this bug case, the inner query is not dependent upon the
    outer query, and thus should be evaluated when sending data. The bug
    fix is to check whether the inner query is dependent upon the outer in
    Item_singlerow_subselect::no_rows_in_result(), and setting "no_rows"
    for this case only.
    
    Notice however that the case of dependent inner query is invalid
    according to standard SQL: setting sql_mode only_full_group_by rejects
    a query with dependent inner query with error 1140.
    
    Another problem with setting "no_rows" for such queries is that a COUNT
    function may return NULL, even though the function is specified to
    always return a non-negative integer. However, as this is an invalid
    query according toe the SQL standard, we will not worry about that
    problem for now.
    
    sql/item_subselect.cc
      In Item_singlerow_subselect::no_rows_in_result(), set no_rows true
      only when subquery is dependent on the outer query.
Loading