1. 01 Jun, 2012 1 commit
    • unknown's avatar
      Fixed bug MDEV-288 · 7ddd5418
      unknown authored
      CHEAP SQ: Valgrind warnings "Memory lost" with IN and EXISTS nested subquery, materialization+semijoin
      
      Analysis:
      The memory leak was a result of the interaction of semi-join optimization
      with early optimization of constant subqueries. The function:
      setup_jtbm_semi_joins() created a dummy temporary table "dummy_table"
      in order to make some JOIN_TAB objects complete. Normally, such temporary
      tables are freed inside JOIN_TAB::cleanup.
      
      However, the inner-most subquery is pre-optimized, which allows the
      optimization fo the MAX subquery to determine that its WHERE is TRUE,
      and thus to compute the result of the MAX during optimization. This
      ultimately allows the optimize phase of the outer query to find that
      it WHERE clause is FALSE. Once JOIN::optimize finds that the result
      set is empty, it sets zero_result_cause, and returns *before* it ever
      reached make_join_statistics(). As a result the query plan has no
      JOIN_TABs at all. Since the temporary table is supposed to be cleanup
      via JOIN_TAB::cleanup, this never happens because there is no JOIN_TAB
      for this table. Hence we get a memory leak.
      
      Solution:
      Whenever there are no JOIN_TABs, iterate over all table reference in
      JOIN::join_list, and free the ones that contain semi-join temporary
      tables.
      7ddd5418
  2. 29 May, 2012 1 commit
    • unknown's avatar
      Patch for mdev-287: CHEAP SQ: A query with subquery in SELECT list, EXISTS,... · 941018f8
      unknown authored
      Patch for mdev-287: CHEAP SQ: A query with subquery in SELECT list, EXISTS, inner joins takes hundreds times longer
      
      Analysis:
      
      The fix for lp:944706 introduces early subquery optimization.
      While a subquery is being optimized some of its predicates may be
      removed. In the test case, the EXISTS subquery is constant, and is
      evaluated to TRUE. As a result the whole OR is TRUE, and thus the
      correlated condition "b = alias1.b" is optimized away. The subquery
      becomes non-correlated.
      
      The subquery cache is designed to work only for correlated subqueries.
      If constant subquery optimization is disallowed, then the constant
      subquery is not evaluated, the subquery remains correlated, and its
      execution is cached. As a result execution is fast.
      
      However, when the constant subquery was optimized away, it was neither
      cached by the subquery cache, nor it was cached by the internal subquery
      caching. The latter was due to the fact that the subquery still appeared
      as correlated to the subselect_XYZ_engine::exec methods, and they
      re-executed the subquery on each call to Item_subselect::exec.
      
      Solution:
      
      The solution is to update the correlated status of the subquery after it has
      been optimized. This status consists of:
      - st_select_lex::is_correlated
      - Item_subselect::is_correlated
      - SELECT_LEX::uncacheable
      - SELECT_LEX_UNIT::uncacheable
      The status is updated by st_select_lex::update_correlated_cache(), and its
      caller st_select_lex::optimize_unflattened_subqueries. The solution relies
      on the fact that the optimizer already called
      st_select_lex::update_used_tables() for each subquery. This allows to
      efficiently update the correlated status of each subquery without walking
      the whole subquery tree.
      
      Notice that his patch is an improvement over MySQL 5.6 and older, where
      subqueries are not pre-optimized, and the above analysis is not possible.
      941018f8
  3. 24 May, 2012 1 commit
    • unknown's avatar
      Test case for bug lp:1001117, MySQL BUG#12330344 · 4fa89b5f
      unknown authored
      Analysis:
      The problem in the original MySQL bug is that the range optimizer
      performs its analysis in a separate MEM_ROOT object that is freed
      after the range optimzier is done. During range analysis get_mm_tree
      calls Item_func_like::select_optimize, which in turn evaluates its
      right argument. In the test case the right argument is a subquery.
      
      In MySQL, subqueries are optimized lazyly, thus the call to val_str
      triggers optimization for the subquery. All objects needed by the
      subquery plan end up in the temporary MEM_ROOT used by the range
      optimizer. When execution ends, the JOIN::cleanup process tries to
      cleanup objects of the subquery plan, but all these objects are gone
      with the temporary MEM_ROOT. The solution for MySQL is to switch the
      mem_root.
      
      In MariaDB with the patch for bug lp:944706, all constant subqueries
      that may be used by the optimization process are preoptimized. Therefore
      Item_func_like::select_optimize only triggers subquery execution, and
      the above problem is not present.
      
      The patch however adds a test whether the evaluated right argument of
      the LIKE predicate is expensive. This is consistent with our approach
      not to evaluate expensive expressions during optimization.
      4fa89b5f
  4. 18 May, 2012 1 commit
    • unknown's avatar
      Fixed bug mdev-277 as part of the fix for lp:944706 · e5bca74b
      unknown authored
      The cause for this bug is that the method JOIN::get_examined_rows iterates over all
      JOIN_TABs of the join assuming they are just a sequence. In the query above, the
      innermost subquery is merged into its parent query. When we call
      JOIN::get_examined_rows for the second-level subquery, the iteration that
      assumes sequential order of join tabs goes outside the join_tab array and calls
      the method JOIN_TAB::get_examined_rows on uninitialized memory. 
      
      The fix is to iterate over JOIN_TABs in a way that takes into account the nested
      semi-join structure of JOIN_TABs. In particular iterate as select_describe.
      e5bca74b
  5. 17 May, 2012 1 commit
    • unknown's avatar
      Fix for bug lp:944706, task MDEV-193 · da521483
      unknown authored
      The patch enables back constant subquery execution during
      query optimization after it was disabled during the development
      of MWL#89 (cost-based choice of IN-TO-EXISTS vs MATERIALIZATION).
      
      The main idea is that constant subqueries are allowed to be executed
      during optimization if their execution is not expensive.
      
      The approach is as follows:
      - Constant subqueries are recursively optimized in the beginning of
        JOIN::optimize of the outer query. This is done by the new method
        JOIN::optimize_constant_subqueries(). This is done so that the cost
        of executing these queries can be estimated.
      - Optimization of the outer query proceeds normally. During this phase
        the optimizer may request execution of non-expensive constant subqueries.
        Each place where the optimizer may potentially execute an expensive
        expression is guarded with the predicate Item::is_expensive().
      - The implementation of Item_subselect::is_expensive has been extended
        to use the number of examined rows (estimated by the optimizer) as a
        way to determine whether the subquery is expensive or not.
      - The new system variable "expensive_subquery_limit" controls how many
        examined rows are considered to be not expensive. The default is 100.
      
      In addition, multiple changes were needed to make this solution work
      in the light of the changes made by MWL#89. These changes were needed
      to fix various crashes and wrong results, and legacy bugs discovered
      during development.
      da521483
  6. 08 May, 2012 1 commit
  7. 07 May, 2012 2 commits
  8. 05 May, 2012 4 commits
  9. 04 May, 2012 5 commits
  10. 03 May, 2012 3 commits
  11. 02 May, 2012 1 commit
  12. 03 May, 2012 1 commit
  13. 02 May, 2012 8 commits
  14. 29 Apr, 2012 1 commit
    • Alexey Botchkov's avatar
      bug #977021 ST_BUFFER fails with the negative D. · af084bcd
      Alexey Botchkov authored
        Points and lines should disappear if we got negative D.
        To make it work properly inside the GEOMETRYCOLLECTION,
        we add the empty operation there.
      
      bug #986977 Assertion `!cur_p->event' failed in Gcalc_scan_iterator::arrange_event(int, int).
        The double->inernal coord conversion produced -0 (minus zero) on some data.
        That minus-zero produces invalid comparison results when compared agains plus-zero.
        So we fixed the gcalc_set_double() to avoid it.
      
      per-file comments:
        mysql-test/r/gis-precise.result
              result updated.
        mysql-test/t/gis-precise.test
              tests for #977021 and #986977 added.
        sql/gcalc_slicescan.cc
              bug #986977. The gcalc_set_double fixed to not produce minus-zero.
        sql/item_geofunc.cc
              bug #977021. Add the NOOP for the disappearing features.
      af084bcd
  15. 26 Apr, 2012 1 commit
  16. 27 Apr, 2012 1 commit
    • unknown's avatar
      Fix bug lp:985667, MDEV-229 · c04786d3
      unknown authored
      Analysis:
      
      The reason for the wrong result is the interaction between constant
      optimization (in this case 1-row table) and subquery optimization.
      
      - First the outer query is optimized, and 'make_join_statistics' finds that
      table t2 has one row, reads that row, and marks the whole table as constant.
      This also means that all fields of t2 are constant.
      
      - Next, we optimize the subquery in the end of the outer 'make_join_statistics'.
      The field 'f2' is considered constant, with value '3'. The subquery predicate
      is rewritten as the constant TRUE.
      
      - The outer query execution detects early that the whole query result is empty
      and calls 'return_zero_rows'. Since the query is with implicit grouping, we
      have to produce one row with special values for the aggregates (depending on
      each aggregate function), and NULL values for all non-aggregate fields.  This
      function calls 'no_rows_in_result' to set each aggregate function to the
      default value when it aggregates over an empty result, and then calls
      'send_data', which in turn evaluates each Item in the SELECT list.
      
      - When evaluation reaches the subquery predicate, it executes the subquery
      with field 'f2' having a constant value '3', and the subquery produces the
      incorrect result '7'.
      
      Solution:
      
      Implement Item::no_rows_in_result for all subquery predicates. In order to
      make this work, it is also needed to make all val_* methods of all subquery
      predicates respect the Item_subselect::forced_const flag. Otherwise subqueries
      are executed anyways, and override the default value set by no_rows_in_result
      with whatever result is produced from the subquery evaluation.
      c04786d3
  17. 25 Apr, 2012 1 commit
  18. 24 Apr, 2012 1 commit
  19. 23 Apr, 2012 2 commits
  20. 20 Apr, 2012 1 commit
    • Vladislav Vaintroub's avatar
      LPBUG#983285 - incompatibility in frm in case of VIEWs with non-default ALGORITHM option. · 97aa8e8c
      Vladislav Vaintroub authored
      As part of derived tables redesign, values for VIEW_ALGORITHM_MERGE and VIEW_ALGORITHM_TMPTABLE have changed from (former values 1 rsp 2 , new values 5 rsp 9).
      
      This lead to the problem that views, created with version 5.2  or earlier would not work in all situations  (e.g "SHOW CREATE VIEW"), or with mysqldump.
      
      The fix is to restore backward compatibility for the from file, and convert algorithm={1,2} in the frm to {5,9} when reading .frm from disk, and store backward compatible values when writing from to disk. 
      
      Also allow processing correct processing for "invalid" .frms created with MariaDB 5.3/5.5 GA releases (where algorithm stored in memory matched the one stored in frm).
      97aa8e8c
  21. 19 Apr, 2012 1 commit
  22. 29 Apr, 2012 1 commit
    • Alexey Botchkov's avatar
      bug #977021 ST_BUFFER fails with the negative D. · d16ea779
      Alexey Botchkov authored
        Points and lines should disappear if we got negative D.
        To make it work properly inside the GEOMETRYCOLLECTION,
        we add the empty operation there.
      
      bug #986977 Assertion `!cur_p->event' failed in Gcalc_scan_iterator::arrange_event(int, int).
        The double->inernal coord conversion produced -0 (minus zero) on some data.
        That minus-zero produces invalid comparison results when compared agains plus-zero.
        So we fixed the gcalc_set_double() to avoid it.
      
      per-file comments:
        mysql-test/r/gis-precise.result
              result updated.
        mysql-test/t/gis-precise.test
              tests for #977021 and #986977 added.
        sql/gcalc_slicescan.cc
              bug #986977. The gcalc_set_double fixed to not produce minus-zero.
        sql/item_geofunc.cc
              bug #977021. Add the NOOP for the disappearing features.
      d16ea779