Commit graph

124 commits

Author SHA1 Message Date
Sergey Petrunya
05d54b121c BUG#803365: Crash in pull_out_semijoin_tables with outer join + semijoin + derived tables in maria-5.3 with WL#106
- Don't perform table pullout out of semi-join nests that have nested outer joins.
2011-07-05 21:22:13 +04:00
Sergey Petrunya
e2eafc3bd1 Fix buildbot failures:
- 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.
2011-06-30 20:49:11 +04:00
Sergey Petrunya
1aede4d1c8 Merge 2011-06-29 11:52:26 +04:00
Sergey Petrunya
ff960f439e Remove garbage comment 2011-06-28 18:25:02 +04:00
Sergey Petrunya
4493197125 Followup to previous commit:
- Update test results
- Fix a problem with PS: 
   = convert_subq_to_sj() should not save where to prep_where or on_expr to prep_on_expr.
   = After an unmerged subquery predicate has been pulled, it should call fix_after_pullout() for 
     outer_refs.
2011-06-28 17:42:10 +04:00
unknown
78fa331eaa Fixed bug lp:800679
Analysis:
  The failed assert ensured that the choice of subquery strategy
  is performed only for queries with at least one table. If there
  is a LIMIT 0 clause all tables are removed, and the subquery is
  neither optimized, nor executed during actual optimization. However,
  if the query is EXPLAIN-ed, the EXPLAIN execution path doesn't remove
  the query tables if there is a LIMIT 0 clause. As a result, the
  subquery optimization code is called, which violates the ASSERT
  condition.
  
Solution:
  Transform the assert into a condition, and if the outer query
  has no tables assume that there will be at most one subquery
  execution.
  
  There is potentially a better solution by reengineering the
  EXPLAIN/optimize code, so that subquery optimization is not
  done if not needed. Such a solution would be a lot bigger and
  more complex than a bug fix.
2011-06-28 15:48:44 +03:00
Sergey Petrunya
04326c5220 Test: enable semi-join processing for cases of semi-joins and outer joins, except for the case when the
subquery is in the ON clause.
2011-06-28 00:51:26 +04:00
Sergey Petrunya
4480642624 Added TODO comments 2011-06-27 23:38:56 +04:00
Sergey Petrunya
6adddca80e Make semi-joins work with outer joins part #1:
- Make make_outerjoin_info() correctly process semi-join nests
- Make make_join_select() attach conditions to the right places.
2011-06-22 01:57:28 +04:00
unknown
44570d2b12 MWL#89
Automerged with 5.3.
2011-06-21 16:00:41 +03:00
unknown
a02682abcc MWL#89
- 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.
2011-06-21 15:50:07 +03:00
Sergey Petrunya
a0973ba22e Merge fix for BUG#778406. 2011-06-17 17:45:41 +04:00
Igor Babaev
078b59f5bc Merge of mwl #106 into 5.3. 2011-06-15 21:48:38 -07:00
Sergey Petrunya
bce51cebcb BUG#778406: Crash in hp_movelink with Aria engine and subqueries
-In  do_sj_dups_weedout(), set nulls_ptr to point to NULL bytes (and not to length bytes) of the DuplicateWeedout column.
2011-06-15 18:37:01 +04:00
Igor Babaev
059aff15cd Fixed LP bug #784441.
The code that added semi-join transformations missed checking
the state of the fixed flag for the items built with the
and_items function before calls of the fix_fields method.
This could lead to an abort failure when the first argument
of and_items() happened to be NULL.
2011-06-06 15:50:46 -07:00
Igor Babaev
f03a3ee54f Merged the code of mwl 106 into the latest 5.3 with mwl 90 pushed.
Resolved all conflicts and failures.
2011-06-04 19:56:06 -07:00
Sergey Petrunya
ebb130b189 BUG#787299: Valgrind complains on a join query with two IN subqueries
- Don't attempt to construct FirstMatch access method if we've 
  just figured three lines above that it can't be used (because join
  prefix doesn't have the needed tables), and so have set 
    pos->first_firstmatch_table= MAX_TABLES 
  Attempts to analyze join->positions[MAX_TABLES] caused valgrind warnings
2011-06-02 23:48:33 +04:00
Sergey Petrunya
0cf912c23f - Remove compiler warning
- Remove garbage comments
2011-05-30 11:19:40 +04:00
Sergey Petrunya
5cd18326c2 Merge 5.3->main -> 5.3-mwl90 2011-05-29 12:58:44 +04:00
Sergey Petrunya
ded7342daa - Update test results (trivial)
- Code cleanup: remove garbage comments
2011-05-29 01:47:24 +04:00
Sergey Petrunya
77c4c4d8ea post-merge fixes: get MWL#90 code to work with MWL#89's
way of processing prepared statements:
- conversion subquery_predicate -> TABLE_LIST is once per-statement
- However, the code must take into account that materialized temptable
  is dropped and re-created on each execution (the tricky part is that 
  at start of n-th EXECUTE we have TABLE_LIST object but not its TABLE object)
- IN-equality is injected into WHERE on every execution.
2011-05-28 20:34:04 +04:00
Michael Widenius
2894d50e3e automatic merge with 5.3 2011-05-28 05:58:16 +03:00
Michael Widenius
f197991f41 Merge with 5.1-microseconds
A lot of small fixes and new test cases.

client/mysqlbinlog.cc:
  Cast removed
client/mysqltest.cc:
  Added missing DBUG_RETURN
include/my_pthread.h:
  set_timespec_time_nsec() now only takes one argument
mysql-test/t/date_formats.test:
  Remove --disable_ps_protocl as now also ps supports microseconds
mysys/my_uuid.c:
  Changed to use my_interval_timer() instead of my_getsystime()
mysys/waiting_threads.c:
  Changed to use my_hrtime()
sql/field.h:
  Added bool special_const_compare() for fields that may convert values before compare (like year)
sql/field_conv.cc:
  Added test to get optimal copying of identical temporal values.
sql/item.cc:
  Return that item_int is equal if it's positive, even if unsigned flag is different.
  Fixed Item_cache_str::save_in_field() to have identical null check as other similar functions
  Added proper NULL check to Item_cache_int::save_in_field()
sql/item_cmpfunc.cc:
  Don't call convert_constant_item() if there is nothing that is worth converting.
  Simplified test when years should be converted
sql/item_sum.cc:
  Mark cache values in Item_sum_hybrid as not constants to ensure they are not replaced by other cache values in compare_datetime()
sql/item_timefunc.cc:
  Changed sec_to_time() to take a my_decimal argument to ensure we don't loose any sub seconds.
  Added Item_temporal_func::get_time() (This simplifies some things)
sql/mysql_priv.h:
  Added Lazy_string_decimal()
sql/mysqld.cc:
  Added my_decimal constants max_seconds_for_time_type, time_second_part_factor
sql/table.cc:
  Changed expr_arena to be of type CONVENTIONAL_EXECUTION to ensure that we don't loose any items that are created by fix_fields()
sql/tztime.cc:
  TIME_to_gmt_sec() now sets *in_dst_time_gap in case of errors
  This is needed to be able to detect if timestamp is 0
storage/maria/lockman.c:
  Changed from my_getsystime() to set_timespec_time_nsec()
storage/maria/ma_loghandler.c:
  Changed from my_getsystime() to my_hrtime()
storage/maria/ma_recovery.c:
  Changed from my_getsystime() to mmicrosecond_interval_timer()
storage/maria/unittest/trnman-t.c:
  Changed from my_getsystime() to mmicrosecond_interval_timer()
storage/xtradb/handler/ha_innodb.cc:
  Added support for new time,datetime and timestamp
unittest/mysys/thr_template.c:
  my_getsystime() -> my_interval_timer()
unittest/mysys/waiting_threads-t.c:
  my_getsystime() -> my_interval_timer()
2011-05-28 05:11:32 +03:00
Sergey Petrunya
aa551f1b9e Post-merge fixes part#2 2011-05-26 15:01:26 +04:00
Sergey Petrunya
77b3b960b1 Merge MWL#90 with 5.3-main 2011-05-25 19:31:13 +04:00
unknown
8a314700f9 MWL#89 automatic merge with 5.3 2011-05-23 11:54:26 +03:00
unknown
742dfc92a2 MWL#89: Address review feedback (by Sergey Petrunia)
mysql-test/r/subselect4.result:
  Moved test case for LP BUG#718593 into the correct test file subselect_mat_cost_bugs.test.
mysql-test/t/subselect4.test:
  Moved test case for LP BUG#718593 into the correct test file subselect_mat_cost_bugs.test.
2011-05-23 10:56:05 +03:00
Igor Babaev
89cf840cd9 Merge 2011-05-20 12:47:39 -07:00
Sergey Petrunya
23cfe1261d Merge fix for BUG#784723 2011-05-20 10:13:02 +04:00
Sergey Petrunya
d1138283b9 BUG#784723: Wrong result with semijoin + nested subqueries in maria-5.3
- in advance_sj_state(), remember join->cur_dups_producing_tables in 
  pos->prefix_dups_producing_tables *before* we modify it, so that 
  restore_prev_sj_state() restores cur_dups_producing_tables in all cases.
- Updated test results in subselect_sj2[_jcl6].result (the original EXPLAIN
  was invalid there)
2011-05-20 01:05:06 +04:00
unknown
56c0e19ed0 MWL#89 Addressing Sergey's review comments - Part 1.
Address the 'trivial' part of Sergey's review of MWL#89.
2011-05-18 01:23:22 +03:00
Igor Babaev
704f97035f Merged the code of MWL#106 into 5.3
Resolved all conflicts, bad merges and fixed a few minor bugs in the code.
Commented out the queries from multi_update, view, subselect_sj, func_str,
derived_view, view_grant that failed either with crashes in ps-protocol or
with wrong results.
The failures are clear indications of some bugs in the code and these bugs
are to be fixed.
2011-05-16 22:39:43 -07:00
unknown
18d08eeacc Post review fixes of MWL#148 (moving max/min optimization in optimize phase).
sql/item_subselect.cc:
  Cleanup. Comments added.
sql/item_subselect.h:
  Cleanup.
sql/mysql_priv.h:
  Comments added.
sql/opt_subselect.cc:
  The function renamed and turned to method.
  Comments added.
sql/opt_subselect.h:
  The function turned to method of JOIN.
sql/sql_select.cc:
  Comment added. The function turned to method.
sql/sql_select.h:
  The function turned to method.
2011-05-12 00:14:15 +03:00
Sergey Petrunya
f34b421839 Code cleanup, added comments. 2011-05-10 11:31:02 +01:00
Sergey Petrunya
76fd8c1c2f Change "disable semi-joins in presense of outer joins" check to actually
check for outer joins (and not for any "t1 SOME_JOIN t2 ON cond" syntax).
2011-05-09 11:20:51 +01:00
Sergey Petrunya
524e6aad73 MWL#90: Non-merged semi-joins
- Take into account that grouping or aggregates decrease join output cardinality.
  (First code, can't make use of index statistics yet)
2011-05-09 10:35:55 +01:00
Oleksandr Byelkin
7b797fe66d Moving max/min optimization from prepare to optimization phase. MWL#148
mysql-test/r/explain.result:
  fixed results (new item)
mysql-test/r/subselect.result:
  fixed results (new item)
mysql-test/r/subselect_no_mat.result:
  fixed results (new item)
mysql-test/r/subselect_no_opts.result:
  fixed results (new item)
mysql-test/r/subselect_no_semijoin.result:
  Fixed results (new item)
mysql-test/suite/pbxt/r/subselect.result:
  Fixed results (new item)
mysql-test/t/explain.test:
  Fixed results (correct behaviour)
sql/item_cmpfunc.cc:
  Pass through  for max/min
sql/item_subselect.cc:
  moving max/min
sql/item_subselect.h:
  moving max/min
sql/mysql_priv.h:
  new uncacheble flags added
sql/opt_subselect.cc:
  maxmin moved.
sql/opt_subselect.h:
  New function for maxmin.
sql/sql_class.h:
  debug code
sql/sql_lex.cc:
  Fixed flags.
  Limit setting fixed.
sql/sql_lex.h:
  2 new flags.
sql/sql_select.cc:
  Prepare divided on 2 function to be able recollect some info after transformation.
sql/sql_select.h:
  Prepare divided on 2 functions.
2011-05-04 18:08:58 +03:00
unknown
5dc11616b2 MWL#89
Merge with 5.3
2011-05-02 21:59:16 +03:00
Sergey Petrunya
3098c21b8f Merge MWL#90 into 5.3-main 2011-04-30 04:59:05 +04:00
Igor Babaev
24edac2211 Merge 2011-04-26 21:11:06 -07:00
Igor Babaev
8d9dd21d85 Fixed LP bugs #717577, #724942.
Both these two bugs happened due to the following problem.
When a view column is referenced in the query an Item_direct_view_ref
object is created that is refers to the Item_field for the column.
All references to the same view column refer to the same Item_field.
Different references can belong to different AND/OR levels and,
as a result, can be included in different Item_equal object.
These Item_equal objects may include different constant objects.
If these constant objects are substituted for the Item_field created
for a view column we have a conflict situation when the second
substitution annuls the first substitution. This leads to
wrong result sets returned by the query. Bug #724942 demonstrates
such an erroneous behaviour.
Test case of the bug #717577 produces wrong result sets because best
equal fields of the multiple equalities built for different OR levels
of the WHERE condition differs. The subsitution for the best equal field
in the second OR branch overwrites the the substitution made for the
first branch.

To avoid such conflicts we have to substitute for the references
to the view columns rather than for the underlying field items.
To make such substitutions possible we have to include into
multiple equalities references to view columns rather than 
field items created for such columns.

This patch modifies the Item_equal class to include references
to view columns into multiple equality objects. It also performs
a clean up of the class methods and adds more comments. The methods
of the Item_direct_view_ref class that assist substitutions for
references to view columns has been also added by this patch.
2011-04-26 19:58:41 -07:00
Sergey Petrunya
acc161d363 BUG#752992: Wrong results for a subquery with 'semijoin=on'
- Let advance_sj_state() save the value of JOIN::cur_dups_producing_tables
  in POSITION::prefix_dups_producing_tables, and restore_sj_state() restore
  it.
2011-04-08 02:12:03 +04:00
Sergey Petrunya
81c6f73ff2 MWL#90: Address review feedback part #19: More comments 2011-04-05 14:33:15 +04:00
Sergey Petrunya
151207134b MWL#90: Address review feedback part #18 2011-04-05 12:20:03 +04:00
Sergey Petrunya
8fb724281e Merge MWL#90 with main 5.3 tree 2011-04-02 14:09:00 +04:00
unknown
952556b345 MWL#89
Merge 5.3 with 5.3-mwl89.
2011-03-30 10:10:59 +03:00
Sergey Petrunya
dc937fb53b MWL#90: Address review feedback part #16 2011-03-29 14:33:59 +04:00
Sergey Petrunya
4e5199912b Rename JOIN::top_jtrange_tables to top_join_tab_count 2011-03-27 03:54:15 +04:00
Sergey Petrunya
5de770f317 MWL#90: Address review feedback part #14 2011-03-27 03:45:16 +04:00
Sergey Petrunya
432a058723 - Fix valgrind failure introduced in previous push 2011-03-25 12:14:02 +03:00