1. 30 Jul, 2011 1 commit
    • Igor Babaev's avatar
      Fixed LP bug #817360. · 485e5edb
      Igor Babaev authored
      This problem could be observed for queries with nested outer joins
      for which the not_exist optimization were applicable. 
      The problem was caused by the code of the patch for bug #49322
      that erroneously forced the return to the previous nested loop
      level when the join algorithm successfully builds a partial record
      for an embedded outer to which the not_exist optimization could be
      applied.
      Actually the immediate return to the previous nested loops level
      is correct only if this partial record is rejected by a predicate
      pushed down to one of the inner tables of this outer join. Otherwise
      attempts to find extensions of this record must be made.
      485e5edb
  2. 23 Jul, 2011 1 commit
  3. 21 Jul, 2011 2 commits
    • Igor Babaev's avatar
      Fixed LP bug #813447. · 106cd976
      Igor Babaev authored
      Do not make substitution of a single-row table if it is an inner
      table of an outer join with on expression containing an expensive
      subquery.
      106cd976
    • Igor Babaev's avatar
      Fixed LP bug #791761. · 00b5f70a
      Igor Babaev authored
      An aggregating query over an empty set of a join of two tables
      with a rejecting HAVING clause erroneously could return a row.
      It could happen in the cases when the optimizer made a conclusion
      that the aggregating set was empty.
      Wrong results were produced because the server missed initial
      setting for aggregation functions in the mentioned cases.
            
      00b5f70a
  4. 19 Jul, 2011 2 commits
    • Sergey Petrunya's avatar
      BUG##806524: Assertion `join->best_read < 1.7976931348623157e+308 with... · f6494a6d
      Sergey Petrunya authored
      BUG##806524: Assertion `join->best_read < 1.7976931348623157e+308 with table_elimination=on and derived_merge=on 
      reset_nj_counters() used to rely on the fact that join nests have 
      table->table==NULL. This ceased to be true wit new derived table
      optimizations. Use test for table->nested_join!=NULL instead.
      f6494a6d
    • unknown's avatar
      Fixed LP BUG#800696. · 01cf947c
      unknown authored
      The problem was that optimizer removes some outer references (it they are
      constant for example) and the list of outer items built during prepare phase is
      not actual during execution phase when we need it as the cache parameters.
      First solution was use pointer on pointer on outer reference Item and
      initialize temporary table on demand. This solved most problem except case
      when optimiser also reduce Item which contains outer references ('OR' in
      this bug test suite).
      
      The solution is to build the list of outer reference items on execution
      phase (after optimization) on demand (just before temporary table creation)
      by walking Item tree and finding outer references among Item_ident
      (Item_field/Item_ref) and Item_sum items.
      
      Removed depends_on list (because it is not neede any mnore for the cache, in the place where it was used it replaced with upper_refs).
      
      Added processor (collect_outer_ref_processor) and get_cache_parameters() methods to collect outer references (or other expression parameters in future).
      
      mysql-test/r/subselect_cache.result:
        A new test added.
      mysql-test/r/subselect_scache.result:
        Changes in creating the cache and its paremeters order or adding arguments of aggregate function (which is a parameter also, but this has no influence on the result).
      mysql-test/t/subselect_cache.test:
        Added a new test.
      sql/item.cc:
        depends_on removed.
        
        Added processor (collect_outer_ref_processor) and get_cache_parameters() methods to collect outer references.
        
        Item_cache_wrapper collect parameters befor initialization of its cache.
      sql/item.h:
        depends_on removed.
        
        Added processor (collect_outer_ref_processor) and get_cache_parameters() methods to collect outer references.
      sql/item_cmpfunc.cc:
        depends_on removed.
        
        Added processor (collect_outer_ref_processor) to collect outer references.
      sql/item_cmpfunc.h:
        Added processor (collect_outer_ref_processor) to collect outer references.
      sql/item_subselect.cc:
        depends_on removed.
        Added processor get_cache_parameters() method to collect outer references.
      sql/item_subselect.h:
        depends_on removed.
        Added processor get_cache_parameters() method to collect outer references.
      sql/item_sum.cc:
        Added processor (collect_outer_ref_processor) method to collect outer references.
      sql/item_sum.h:
        Added processor (collect_outer_ref_processor) and get_cache_parameters() methods to collect outer references.
      sql/opt_range.cc:
        depends_on removed.
      sql/sql_base.cc:
        depends_on removed.
      sql/sql_class.h:
        New iterator added.
      sql/sql_expression_cache.cc:
        Build of list of items resolved in outer query done just before creating expression cache on the first execution of the subquery which removes influence of optimizer removing items (all optimization already done).
      sql/sql_expression_cache.h:
        Build of list of items resolved in outer query done just before creating expression cache on the first execution of the subquery which removes influence of optimizer removing items (all optimization already done).
      sql/sql_lex.cc:
        depends_on removed.
      sql/sql_lex.h:
        depends_on removed.
      sql/sql_list.h:
        Added add_unique method to add only unique elements to the list.
      sql/sql_select.cc:
        Support of new Item list added.
      sql/sql_select.h:
        Support of new Item list added.
      01cf947c
  5. 18 Jul, 2011 1 commit
    • Igor Babaev's avatar
      Fixed LP bug #793448. · a79de1be
      Igor Babaev authored
      This bug could lead to wrong result sets for a query over a
      materialized derived table or view accessed by a multi-component
      key.
      It happened because the function get_next_field_for_derived_key
      was supposed to update its argument, and it did not do it.
      a79de1be
  6. 17 Jul, 2011 1 commit
    • Igor Babaev's avatar
      Fixed LP bug #794901. · 1eea03cc
      Igor Babaev authored
      Also:
      1. simplified the code of the function mysql_derived_merge_for_insert.
      2. moved merge of views/dt for multi-update/delete to the prepare stage.
      3. the list of the references to the candidates for semi-join now is
         allocated in the statement memory.
      1eea03cc
  7. 14 Jul, 2011 2 commits
    • unknown's avatar
      Fix bug lp:777691 · 79dae88f
      unknown authored
      Analysis:
      
      For some of the re-executions of the correlated subquery the
      where clause is false. In these cases the execution of the
      subquery detects that it must generate a NULL row because of
      implicit grouping. In this case the subquery execution reaches
      the following code in do_select():
      
              while ((table= li++))
                mark_as_null_row(table->table);
      
      This code marks all rows in the table as complete NULL rows.
      In the example, when evaluating the field t2.f10 for the second
      row, all bits of Field::null_ptr[0] are set by the previous call
      to mark_as_null_row(). Then the call to Field::is_null()
      returns true, resulting in a NULL for the MAX function.
      
      Thus the lines above are not suitable for subquery re-execution
      because mark_as_null_row() changes the NULL bits of each table
      field, and there is no logic to restore these fields.
      
      Solution:
      
      The call to mark_as_null_row() was added by the fix for bug
      lp:613029. Therefore removing the fix for lp:613029 corrects
      this wrong result. A...
      79dae88f
    • Igor Babaev's avatar
  8. 13 Jul, 2011 1 commit
    • Igor Babaev's avatar
      Fixed LP bug #809206. · 378063e9
      Igor Babaev authored
      The bitmap of used tables must be evaluated for the select list of every
      materialized derived table / view and saved in a dedicated field.
      This is also applied to materialized subqueries.
      378063e9
  9. 12 Jul, 2011 1 commit
  10. 10 Jul, 2011 1 commit
    • Igor Babaev's avatar
      Fixed LP bug #806097. · 120a95ff
      Igor Babaev authored
      The value of THD::used tables should be re-evaluated after merges
      of views and derived tables into the main query. 
      Now it's done in the function SELECT_LEX::update_used_tables.
      The re-evaluation of the 'used_table' bitmaps for the items
      in HAVING, GROUP BY and ORDER BY clauses has been added as well.
       
      120a95ff
  11. 08 Jul, 2011 1 commit
    • Igor Babaev's avatar
      Fixed LP bug #806510. · 55b0a184
      Igor Babaev authored
      The bug was caused by an incorrect code of the function
      Item_direct_view_ref::replace_equal_field introduced in the
      patch for bugs 717577, 724942. The function erroneously
      returned the wrapped field instead of the Item_direct_view_ref
      object itself in the cases when no replacement happened.
      
      The bug masked two other minor bugs that could result in not
      quite correct output of the EXPLAIN command for some queries.
      They were fixed in the patch as well.
       
      55b0a184
  12. 07 Jul, 2011 1 commit
    • Igor Babaev's avatar
      Fixed LP bug #806431. · 44ca8be7
      Igor Babaev authored
      The function generate_derived_keys_for_table incorrectly handled
      the cases when a materialized view or derived table could be accessed
      by different keys on the same fields if these keys depended on the
      same tables.
        
      44ca8be7
  13. 05 Jul, 2011 1 commit
  14. 04 Jul, 2011 1 commit
    • unknown's avatar
      Fix LP bug lp:802979 · 764e8018
      unknown authored
      Analysis:
      This bug consists of two related problems that are
      result of too early evaluation of single-row subqueries
      during the optimization phase of the outer query.
      
      Several optimizer code paths try to evaluate single-row
      subqueries in order to produce a constant and use that
      constant for further optimzation.
      
      When the execution of the subquery peforms destructive
      changes to the representation of the subquery, and these
      changes are not anticipated by the subsequent optimization
      phases of the outer query, we tipically get a crash or
      failed assert.
      
      Specifically, in this bug the inner-most suqbuery with
      DISTINCT triggers a substitution of the original JOIN
      object by a single-table JOIN object with a temp table
      needed to perform the DISTINCT operation (created by
      JOIN::make_simple_join).
      
      This substitution breaks EXPLAIN because:
      a) in the first example JOIN::cleanup no longer can
      reach the original table of the innermost subquery, and
      close all indexes, and
      b) in this second test query, EXPLAIN attempts to print
      the name of the internal temp table, and crashes because
      the temp table has no name (NULL pointer instead).
      
      Solution:
      a) fully disable subquery evaluation during optimization
      in all cases - both for constant propagation and range
      optimization, and
      b) change JOIN::join_free() to perform cleanup irrespective
      of EXPLAIN or not.
      764e8018
  15. 02 Jul, 2011 1 commit
    • Igor Babaev's avatar
      Fixed LP bug #804515. · ae67700a
      Igor Babaev authored
      If no index is used to access a materialized derived table or view
      then the value of TABLE_REF::key for this table must be (-1).
      ae67700a
  16. 30 Jun, 2011 2 commits
    • Sergey Petrunya's avatar
      Fix buildbot failures: · 91e5eb19
      Sergey Petrunya authored
      - JOIN::prepare would have set JOIN::table_count to incorrect value (bad merge of MWL 106)
      - optimize_keyuse() would use table-bit as table number
        (the change in optimize_keyuse is also the reason for query plan changes. Not 
         expected to have much effect because only handles cases of no index statistics)
      - st_select_lex::register_dependency_item() ignored the fact that some of the 
        selects on the dependency paths could have been merged to their parents (because they 
        were mergeable VIEWs)
      - Undo the incorrect fix in Item_subselect::recalc_used_tables(): do not call 
        fix_after_pullout() for Item_subselect::Ref_to_outside members. 
      91e5eb19
    • Igor Babaev's avatar
      Fixed LP bug #802845. · d4e9da31
      Igor Babaev authored
      If the expression for a derived table contained a clause LIMIT 0
      SELECT from such derived table incorrectly returned a non-empty set.
      
      Fixed by ensuring JOIN::do_send_rows to be updated after the call
      of st_select_lex_unit::set_limit that sets the value of 
      JOIN::unit->select_limit_cnt.
      d4e9da31
  17. 29 Jun, 2011 2 commits
    • Igor Babaev's avatar
      Fixed LP bug #803410. · 3d002a70
      Igor Babaev authored
      Due to this bug in the function generate_derived_keys_for_table some
      key definitions to access materialized derived tables or materialized
      views were constructed with invalid info for their key parts.
      This could make the server crash when it optimized queries using 
      materialized derived tables or materialized views. 
      3d002a70
    • Sergey Petrunya's avatar
      lp:802965: Crash in do_copy_not_null with semijoin=on in maria-5.3 · 4a634961
      Sergey Petrunya authored
      - The crash was because a NOT NULL table column inside the subquery was considered NULLable
        because the code thought it was on the inner side of an outer join nest.
      - Fixed by making correct distinction between tables inside outer join nests and inside semi-join nests.
      4a634961
  18. 27 Jun, 2011 3 commits
    • Sergey Petrunya's avatar
      Added TODO comments · 363bfe6c
      Sergey Petrunya authored
      363bfe6c
    • Michael Widenius's avatar
      New status variables: Rows_tmp_read, Handler_tmp_update and Handler_tmp_write · fd2b7c32
      Michael Widenius authored
      Split status variable Rows_read to Rows_read and Rows_tmp_read so that one can see how much real data is read.
      Same was done with with Handler_update and Handler_write.
      Fixed bug in MEMORY tables where some variables was counted twice.
      Added new internal handler call 'ha_close()' to have one place to gather statistics.
      Fixed bug where thd->open_options was set to wrong value when doing admin_recreate_table()
      
      
      mysql-test/r/status.result:
        Updated test results and added new tests
      mysql-test/r/status_user.result:
        Udated test results
      mysql-test/t/status.test:
        Added new test for temporary table status variables
      sql/ha_partition.cc:
        Changed to call ha_close() instead of close()
      sql/handler.cc:
        Added internal_tmp_table variable for easy checking of temporary tables.
        Added new internal handler call 'ha_close()' to have one place to gather statistics.
        Gather statistics for internal temporary tables.
      sql/handler.h:
        Added handler variables internal_tmp_table, rows_tmp_read.
        Split function update_index_statistics() to two.
        Added ha_update_tmp_row() for faster tmp table handling with more statistics.
      sql/item_sum.cc:
        ha_write_row() -> ha_write_tmp_row()
      sql/multi_range_read.cc:
        close() -> ha_close()
      sql/mysqld.cc:
        New status variables: Rows_tmp_read, Handler_tmp_update and Handler_tmp_write
      sql/opt_range.cc:
        close() -> ha_close()
      sql/sql_base.cc:
        close() -> ha_close()
      sql/sql_class.cc:
        Added handling of rows_tmp_read
      sql/sql_class.h:
        Added new satistics variables.
        rows_read++  ->  update_rows_read() to be able to correctly count reads to internal temp tables.
        Added handler::ha_update_tmp_row()
      sql/sql_connect.cc:
        Added comment
      sql/sql_expression_cache.cc:
        ha_write_row() -> ha_write_tmp_row()
      sql/sql_select.cc:
        close() -> ha_close()
        ha_update_row() -> ha_update_tmp_row()
      sql/sql_show.cc:
        ha_write_row() -> ha_write_tmp_row()
      sql/sql_table.cc:
        Fixed bug where thd->open_options was set to wrong value when doing admin_recreate_table()
      sql/sql_union.cc:
        ha_write_row() -> ha_write_tmp_row()
      sql/sql_update.cc:
        ha_write_row() -> ha_write_tmp_row()
      sql/table.cc:
        close() -> ha_close()
      storage/heap/ha_heap.cc:
        Removed double counting of statistic variables.
        close -> ha_close() to get tmp table statistics.
      storage/maria/ha_maria.cc:
        close -> ha_close() to get tmp table statistics.
      fd2b7c32
    • Igor Babaev's avatar
      Fixed LP bug #801536. · 6312a0a7
      Igor Babaev authored
      Ensured valid calculations of the estimates stored in JOIN_TAB::used_fieldlength.
      
      6312a0a7
  19. 25 Jun, 2011 1 commit
    • Igor Babaev's avatar
      Fixed LP bug #799499. · 413eb2e8
      Igor Babaev authored
      The following were missing in the patch for mwl106:
      - KEY_PART_INFO::fieldnr were not set for generated keys to access
        tmp tables storing the rows of materialized derived tables/views
      - TABLE_SHARE::column_bitmap_size was not set for tmp tables storing
        the rows of materialized derived tables/views.
      These could cause crashes or memory overwrite.
      
      413eb2e8
  20. 24 Jun, 2011 4 commits
    • Igor Babaev's avatar
      Fixed LP bug #798576. · a11b1822
      Igor Babaev authored
      If a view/derived table is non-mergeable then the definition of the tmp table
      to store the rows for it is created at the prepare stage. In this case if the
      view definition uses outer joins and a view column belongs to an inner table
      of one of them then the column should be considered as nullable independently
      on nullability of the underlying column. If the underlying column happens to be
      defined as non-nullable then the function create_tmp_field_from_item rather 
      than the function create_tmp_field_from_field should be employed to create
      the definition of the interesting column in the tmp table.
       
      a11b1822
    • Michael Widenius's avatar
    • Michael Widenius's avatar
      Fix for bug lp:798597 Incorrect "Duplicate entry" error with views and GROUP BY · 71c7be39
      Michael Widenius authored
      mysql-test/r/join.result:
        Test case for LP:798597
      mysql-test/t/join.test:
        Test case for LP:798597
      sql/sql_select.cc:
        In simplify_joins we reset table->maybe_null for outer join tables that can't ever be NULL.
        This caused a conflict between the previously calculated items and the group_buffer against the fields
        in the temporary table that are created as not null thanks to the optimization.
        The fix is to correct the group by items to also be not_null so that they match the used fields and keys.
      71c7be39
    • Igor Babaev's avatar
      Fixed a valgrind problem. · 3c65e0a9
      Igor Babaev authored
      The function setup_tables should handle table_list elements for
      semijoin materialized tables in a special way when executing
      a prepared statement for the second time.
      3c65e0a9
  21. 22 Jun, 2011 3 commits
    • Sergey Petrunya's avatar
      Make semi-joins work with outer joins: · 2d706fd7
      Sergey Petrunya authored
      - evaluate_null_complemented_join_record() should perform FirstMatch checks.
      2d706fd7
    • Sergey Petrunya's avatar
      Make semi-joins work with outer joins part #2: · e9fb13a4
      Sergey Petrunya authored
      - Do make the DuplicateWeedout check for outer joins.
      e9fb13a4
    • Igor Babaev's avatar
      Fixed LP bug #798621. · 03b2a8e0
      Igor Babaev authored
      The patch for bugs 717577 and 724942 has missed to make adjustments for the
      call item_equal->add_const(const_item, orig_field_item) in the function
      check_simple_equality that builds multiple equality for a field and a constant.
      As a result, when this field happens to be a view field and the corresponding
      Item_field object F is wrapped in an Item_direct_view_ref object R the object
      F is placed in the multiple equality instead of the object R.
      A substitution of an equal item for F potentially can cause very serious
      problems and in some cases can lead to crashes of the server.
      03b2a8e0
  22. 21 Jun, 2011 2 commits
    • Sergey Petrunya's avatar
      Make semi-joins work with outer joins part #1: · 1fbbabd0
      Sergey Petrunya authored
      - Make make_outerjoin_info() correctly process semi-join nests
      - Make make_join_select() attach conditions to the right places.
      1fbbabd0
    • unknown's avatar
      MWL#89 · 9895a719
      unknown authored
      - Added regression test with queries over the WORLD database.
      - Discovered and fixed several bugs in the related cost calculation
        functionality both in the semijoin and non-semijon subquery code.
      - Added DBUG printing of the cost variables used to decide between
        IN-EXISTS and MATERIALIZATION.
      9895a719
  23. 13 Jun, 2011 1 commit
  24. 11 Jun, 2011 1 commit
    • Sergey Petrunya's avatar
      In make_join_select(): · 7f765a8c
      Sergey Petrunya authored
      - move attempt to evaluate join->exec_const_cond() out of the "Extract constant part of each ON expression" loop
        (it got there by mistake when merging).
      7f765a8c
  25. 10 Jun, 2011 2 commits
  26. 09 Jun, 2011 1 commit
    • Michael Widenius's avatar
      A bit better fix for tmp-table problem · a49e4635
      Michael Widenius authored
      Fixed reference to not initialized memory detected by valgrind
      
      sql/sql_select.cc:
        A bit better fix for tmp-table problem:
        Use only dynamic_record format for group by and distinct.
      storage/maria/ma_create.c:
        DYNAMIC_RECORD format doesn't pack VARCHAR fields.
        This change fixes a non-fatal uninitialized memory copy.
      a49e4635