Skip to content
  • Chaithra Gopalareddy's avatar
    37fab57b
    Bug#11760197:INCORRECT RESULTS WITH COUNT DISTINCT AND BIG_TABLES · 37fab57b
    Chaithra Gopalareddy authored
    Problem:
    When big_tables is enabled, COUNT DISTINCT on simple join with
    constant equality condition gives wrong result.
    
    Analysis:-
    In case of count distinct with sql_big_tables enable, optimizer
    saves data in myisam file instead of heap unique tree.
    When a constant equality condition is present, it does not
    detect duplicate field values when inserting the records into the
    temporary table.
    
    Original solution:
    While creating temporary table, allow creations of fields for constant
    items. When we have distinct query, this will make sure the duplicate
    value filtered out when inserting rows in the temporary table.
    
    Side Effects:
    Bug#17555462 - SELECT DISTINCT OF VIEW WITH CONSTANT STRING
                   RETURNS WRONG RESULT
    Problem:
    In a temporary table if a field is created for a const ref_item,
    and if this ref_item is a reference over a constant string and not
    on a field results are not as expected.
    
    Analysis:
    This is a regression from the patch for Bug#11760197. Post
    this bugfix, a field gets created in temporary table
    even for const_item's. If the const_item is of type Item_ref,
    while creating the temporary field, item->result_field
    is made to point to the newly created field.
    While the original item would hold the constant's value,
    the new field created while changing ref's to use temporary
    fields, will not be having the value.
    As a result we loose the value when fetching the results.
    
    In similar lines:
    Bug #17607155: ASSERTION FAILED: ((ITEM_RESULT_FIELD*)ITEM)->RESULT_FIELD
    Bug #17957913: ASSERTION `((ITEM_RESULT_FIELD*)ITEM)->RESULT_FIELD' FAILS
                   IN CREATE_TMP_FIELD
    Problem:
    Query having a GROUP BY CLAUSE with ROLLUP modifier and a
    GROUP_CONCAT/COUNT(DISTINCT) function with constant expression,
    causes an assert.
    
    Analysis:
    The GROUP_CONCAT/COUNT(DISTINCT) uses its own temporary table.
    When ROLLUP is present it creates the second copy of temporary
    table.
    This copy receives the same list of arguments that original
    group_concat/count(distinct) does which will help to copy
    the content of the result_field for the function under
    GROUP_CONCAT/COUNT from  the first temporary table to the second
    temporary table.
    
    In the case, when constant item is present, result_field will carry
    null value. After the fix for Bug#11760197, while creating field
    for second temporary table as result_field for the constant
    expression is not set, it asserts.
    
    Bug#17634335: SELECT DISTINCT...GROUP BY RETURNS WRONG RESULTS
    IN SOME CASES
    
    Query creating temporary table to find the distinct value and has
    constant value in projected list doesn't give correct result.
    
    Analysis:
    After the fix for Bug#11760197 const_items also were created as
    part of temporary tables. In the call to remove_duplicates() an
    assumption against the same was made which resulted in the above bug.
    
    All the above bugs were side effects of the fix made for Bug#11760197.
    
    Current solution:
    Distinct of a constant value will always be the constant value and
    count distinct of the same will always be one. Based on this,
    a new variable const_distinct is introduced. If enabled, temporary
    table is not created and aggregation is also avoided as the result
    will always be one.
    
    Works in similar lines to always_null.
    37fab57b
    Bug#11760197:INCORRECT RESULTS WITH COUNT DISTINCT AND BIG_TABLES
    Chaithra Gopalareddy authored
    Problem:
    When big_tables is enabled, COUNT DISTINCT on simple join with
    constant equality condition gives wrong result.
    
    Analysis:-
    In case of count distinct with sql_big_tables enable, optimizer
    saves data in myisam file instead of heap unique tree.
    When a constant equality condition is present, it does not
    detect duplicate field values when inserting the records into the
    temporary table.
    
    Original solution:
    While creating temporary table, allow creations of fields for constant
    items. When we have distinct query, this will make sure the duplicate
    value filtered out when inserting rows in the temporary table.
    
    Side Effects:
    Bug#17555462 - SELECT DISTINCT OF VIEW WITH CONSTANT STRING
                   RETURNS WRONG RESULT
    Problem:
    In a temporary table if a field is created for a const ref_item,
    and if this ref_item is a reference over a constant string and not
    on a field results are not as expected.
    
    Analysis:
    This is a regression from the patch for Bug#11760197. Post
    this bugfix, a field gets created in temporary table
    even for const_item's. If the const_item is of type Item_ref,
    while creating the temporary field, item->result_field
    is made to point to the newly created field.
    While the original item would hold the constant's value,
    the new field created while changing ref's to use temporary
    fields, will not be having the value.
    As a result we loose the value when fetching the results.
    
    In similar lines:
    Bug #17607155: ASSERTION FAILED: ((ITEM_RESULT_FIELD*)ITEM)->RESULT_FIELD
    Bug #17957913: ASSERTION `((ITEM_RESULT_FIELD*)ITEM)->RESULT_FIELD' FAILS
                   IN CREATE_TMP_FIELD
    Problem:
    Query having a GROUP BY CLAUSE with ROLLUP modifier and a
    GROUP_CONCAT/COUNT(DISTINCT) function with constant expression,
    causes an assert.
    
    Analysis:
    The GROUP_CONCAT/COUNT(DISTINCT) uses its own temporary table.
    When ROLLUP is present it creates the second copy of temporary
    table.
    This copy receives the same list of arguments that original
    group_concat/count(distinct) does which will help to copy
    the content of the result_field for the function under
    GROUP_CONCAT/COUNT from  the first temporary table to the second
    temporary table.
    
    In the case, when constant item is present, result_field will carry
    null value. After the fix for Bug#11760197, while creating field
    for second temporary table as result_field for the constant
    expression is not set, it asserts.
    
    Bug#17634335: SELECT DISTINCT...GROUP BY RETURNS WRONG RESULTS
    IN SOME CASES
    
    Query creating temporary table to find the distinct value and has
    constant value in projected list doesn't give correct result.
    
    Analysis:
    After the fix for Bug#11760197 const_items also were created as
    part of temporary tables. In the call to remove_duplicates() an
    assumption against the same was made which resulted in the above bug.
    
    All the above bugs were side effects of the fix made for Bug#11760197.
    
    Current solution:
    Distinct of a constant value will always be the constant value and
    count distinct of the same will always be one. Based on this,
    a new variable const_distinct is introduced. If enabled, temporary
    table is not created and aggregation is also avoided as the result
    will always be one.
    
    Works in similar lines to always_null.
Loading