Commit graph

499 commits

Author SHA1 Message Date
Igor Babaev
34aa69564d Merge 5.3->5.5 2013-08-27 22:19:14 -07:00
Igor Babaev
901737c978 Fixed bug mdev-4944.
The patch to fix mdev-4418 turned out to be incorrect.
At the substitution of single row tables in make_join_statistics()
the used multiple equalities may change and references to the new multiple
equalities must be updated. The function remove_eq_conds() takes care of it and
it should be called right after the substitution of single row tables.
Calling it after the call of make_join_statistics was a mistake.
2013-08-26 12:55:58 -07:00
Sergey Petrunya
9651a6f574 mdev-4173: Wrong result (extra row) with semijoin=on, joins in outer query, LEFT JOIN in the subquery
Apply the patch from Patryk Pomykalski:
- create_internal_tmp_table_from_heap() will now return information whether
  the last row that we tried to write was a duplicate row.
(mysql-5.6 also has this change)
2013-07-16 09:22:17 +04:00
Sergey Petrunya
716a49a19e MDEV-4536, MDEV-4042
- Make JOIN::cleanup(true) also work correctly when the query is KILLed
  after join optimization was started but before a query plan was produced
2013-07-15 18:51:52 +04:00
Michael Widenius
bef95a4bbe -Run test suite with smaller aria keybuffer size (to make it possible to run more tests in parallel)
-Added test and extra code to ensure we don't leave keyread on for a handler table.
-Create on disk temporary files always with long data pointers if SQL_SMALL_RESULT is not used. This ensures that we can handle temporary files bigger than 4G.

mysql-test/include/default_mysqld.cnf:
  Run test suite with smaller aria keybuffer size
mysql-test/suite/maria/maria3.result:
  Run test suite with smaller aria keybuffer size
mysql-test/suite/sys_vars/r/aria_pagecache_buffer_size_basic.result:
  Run test suite with smaller aria keybuffer size
sql/handler.cc:
  Disable key read (extra safety if something went wrong)
sql/multi_range_read.cc:
  Ensure we have don't leave keyread on for secondary_file
sql/opt_range.cc:
  Simplify code with mark_columns_used_by_index_no_reset()
  Ensure that read_keys_and_merge() disableds keyread if it enables it
sql/opt_subselect.cc:
  Remove not anymore used argument for create_internal_tmp_table()
sql/sql_derived.cc:
  Remove not anymore used argument for create_internal_tmp_table()
sql/sql_select.cc:
  Use 'enable_keyread()' instead of calling HA_EXTRA_RESET. (Makes debugging easier)
  Create on disk temporary files always with long data pointers if SQL_SMALL_RESULT is not used. This ensures that we can handle temporary files bigger than 4G.
  Remove not anymore used argument for create_internal_tmp_table()
  More DBUG
sql/sql_select.h:
  Remove not anymore used argument for create_internal_tmp_table()
2013-06-05 23:53:35 +03:00
Sergei Golubchik
213f1c76a0 5.3->5.5 merge 2013-02-28 22:47:29 +01:00
Sergei Golubchik
8161c6772d merge with mysql-5.5.30 minus few incorrect or not applicable changesets 2013-02-28 18:42:49 +01:00
Igor Babaev
48aee45957 Fixed bug mdev-3995.
This bug happened because the executor tried to use a wrong
TABLE REF object when building access keys. It constructed
keys from fields of a materialized table from a ref object
created to construct keys from the fields of the underlying
base table. This could happen only when materialized table
was created for a non-correlated IN subquery and only
when the materialized table used for lookups.
In this case we are guaranteed to be able to construct the
keys from the fields of tables that would be outer tables
for the tables of the IN subquery.
The patch makes sure that no ref objects constructed from
fields of materialized lookup tables are to be used.
2013-02-07 21:46:02 -08:00
Olav Sandstaa
e7ad5e36d4 Fix for Bug#14636211 WRONG RESULT (EXTRA ROW) ON A FROM SUBQUERY
WITH A VARIABLE AND ORDER BY
        Bug#16035412 MYSQL SERVER 5.5.29 WRONG SORTING USING COMPLEX INDEX
            
This is a fix for a regression introduced by Bug#12667154:
Bug#12667154 attempted to fix a performance problem with subqueries
that did filesort. For doing filesort, the optimizer creates a quick
select object to use when building the sort index. This quick select
object was deleted after the first call to create_sort_index(). Thus,
for queries where the subquery was executed multiple times, the quick
object was only used for the first execution. For all later executions
of the subquery, filesort used a complete table scan for building the
sort index. The fix for Bug#12667154 tried to fix this by not deleting
the quick object after the first execution of create_sort_index() so
that it would be re-used for building the sort index by the following
executions of the subquery.

This regression introduced in Bug#12667154 is that due to not deleting
the quick select object after building the sort index, the quick
object could in some cases be used also during the second phase of the
execution of the subquery instead of using the created sort
index. This caused wrong results to be returned.

The fix for this issue is to delete the reference to the select object
after it has been used in create_sort_index(). In this way the select 
and quick objects will not be available when doing the second phase
of the execution of the select operation. To ensure that the select
object can be re-used for the following executions of the subquery
we make a copy of the select pointer. This is used for restoring the
select object after the select operation is completed.


mysql-test/suite/innodb/r/innodb_mysql.result:
  Changed explain output: The explain now contains "Using where" since we
  have restored the select pointer after doing the filesort operation.
sql/sql_select.cc:
  Change create_sort_index() so that it always sets the pointer to
  the select object to NULL. This is done in order to avoid that the
  select->quick object can be used when execution the main part of
  the select operation.
sql/sql_select.h:
  New member in JOIN_TAB: saved_select. Used by create_sort_index to
  make a backup copy of the select pointer.
2013-01-15 08:52:38 +01:00
unknown
b8b875cb79 Fix of MDEV-3874: Server crashes in Item_field::print on a SELECT from a MERGE view with materialization+semijoin, subquery, ORDER BY.
The problem was that in debugging binaries it try to print item to assign human readable name to the item.
But subquery item was already freed (join_free/cleanup with full cleanup) so Item_field refers to temporary
table which memory had been already freed.
2012-11-26 21:22:44 +02:00
Sergey Petrunya
39e7072d64 MDEV-536: LP:1050806 - different result for a query using subquery, and
MDEV-567: Wrong result from a query with correlated subquery if ICP is allowed:

backport the fix developed for SHOW EXPLAIN: 

revision-id: psergey@askmonty.org-20120719115219-212cxmm6qvf0wlrb
branch nick: 5.5-show-explain-r21
timestamp: Thu 2012-07-19 15:52:19 +0400
  BUG#992942 & MDEV-325: Pre-liminary commit for testing

and adjust it so that it handles DS-MRR scans correctly.
2012-11-04 19:09:46 +04:00
unknown
974abc7ad8 MDEV-3812
This patch undoes the removal of enum store_key_result by the previous patch for mdev-3812.
2012-10-27 00:56:14 +03:00
unknown
97a1c53c81 MDEV-3812: Remove unneeded extra call to engine->exec() in Item_subselect::exec, remove enum store_key_result
This task fixes an ineffeciency that is a remainder from MySQL 5.0/5.1. There, subqueries
were optimized in a lazy manner, when executed for the first time. During this lazy optimization
it may happen that the server finds a more efficient subquery engine, and substitute the current
engine of the query being executed with the new engine. This required re-execution of the engine.

MariaDB 5.3 pre-optimizes subqueries in almost all cases, and the engine is chosen in most cases,
except when subquery materialization found that it must use partial matching. In this case, the
current code was performing one extra re-execution although it was not needed at all. The patch
performs the re-execution only if the engine was changed while executing.

In addition the patch performs small cleanup by removing "enum store_key_result" because it is
essentially a boolean, and the code that uses it already maps it to a boolean.
2012-10-25 15:50:10 +03:00
Sergei Golubchik
a1fd37b1fd MDEV-414 Depending on indexes or execution plans, a warning on incorrect or out of range values in WHERE condition is sometimes produced and sometimes not
use the same method that disables warnings in all relevant places, remove redundant function
2012-08-31 13:03:41 +02:00
unknown
80b3f74705 Fix bug mdev-447: Wrong output from the EXPLAIN command of the test case for lp bug #714999
The fix backports from MWL#182: Explain running statements the logic that
saves the original JOIN_TAB array of a query plan after optimization. This
array is later used during EXPLAIN to iterate over the original JOIN plan
nodes in the cases when this plan could be changed by early subquery
execution during the optimization phase of the outer query.
2012-08-21 15:24:43 +03:00
unknown
c2677de7ac Merge the fix for lp:944706, mdev-193 2012-06-06 22:26:40 +03:00
unknown
da5214831d Fix for bug lp:944706, task MDEV-193
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.
2012-05-17 13:46:05 +03:00
Sergei Golubchik
1185420da0 5.3 merge 2012-05-21 20:54:41 +02:00
unknown
fe0a0bdb14 Fix compiler warnings. 2012-05-08 20:58:41 +03:00
unknown
4e2926d927 Addition to the fix to LP bug#994275.
It is problem of constant propagated to ref* access method (the problem was hiden by using debug binaries for testing).
2012-05-08 19:13:26 +03:00
Sergei Golubchik
44cf9ee5f7 5.3 merge 2012-05-04 07:16:38 +02:00
unknown
c04786d3e3 Fix bug lp:985667, MDEV-229
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.
2012-04-27 12:59:17 +03:00
Sergei Golubchik
5701d53190 MDEV-207 Install headers required to build external storage plugins
install all private headers in mysql/private/
2012-04-23 09:45:27 +02:00
unknown
335de5db18 Merge mariadb 5.3->mariadb 5.5 2012-03-24 18:21:22 +01:00
Michael Widenius
8e825a2249 Fixes lp:941889 "JOIN constructors takes a long time in 5.3"
- Remove all references of MAX_TABLES from JOIN struct and make these dynamic
- Updated Join_plan_state to allocate just as many elements as it's needed


sql/opt_subselect.cc:
  Optimized version of Join_plan_state
sql/sql_select.cc:
  Set join->positions and join->best_positions dynamicly
  Don't call update_virtual_fields() if table->vfield is not set.
sql/sql_select.h:
  Remove all references of MAX_TABLES from JOIN struct and Join_plan_state and make these dynamic
2012-03-23 18:18:16 +02:00
Sergei Golubchik
25609313ff 5.3.4 merge 2012-02-15 18:08:08 +01:00
Vladislav Vaintroub
24e7faa54f Various fixes for Solaris compiler.
Also, restrict symbol visibility in statically
built plugins, to minimize the chance for symbol 
name clashes with dynamic plugins.
2012-02-03 11:46:40 +01:00
Igor Babaev
7b79d8a33f Merge 5.2->5.3 in preparation for the release of mariadb-5.3.4-rc. 2012-02-01 15:48:02 -08:00
Sergey Petrunya
424f56b3ba BUG#920713: Wrong result (missing rows) with firstmatch+BNL, IN subquery, ...
- Disable use of join cache when we're using FirstMatch strategy, and the join
  order is such that subquery's inner tables are interleaved with outer.  Join 
  buffering code is incapable of handling such join orders.

- The testcase requires use of @@debug_optimizer_prefer_join_prefix to hit the bug, 
  but I'm pushing it anyway (including the mention of the variable in .test file), 
  so that it can be found and enabled when/if we get something comparable in the 
  main tree.
2012-01-25 22:05:20 +04:00
Sergey Petrunya
73cc529b51 BUG#920255: Wrong result (extra rows) with loosescan and IN subquery
The problem was that LooseScan execution code assumed that tab->key holds 
the index used for looseScan. This is only true when range or full index
scan are used. In case of ref access, the index is in tab->ref.key (and 
tab->index==0 which explains how LooseScan passed tests with ref access: they 
used one index)

Fixed by setting/using loosescan_key, which always the correct index#.
2012-01-25 18:33:57 +04:00
Igor Babaev
bb4053afc3 Fixed LP bug #919427.
The function subselect_uniquesubquery_engine::copy_ref_key has to take into
account that when EXPLAIN is processed the array of store_key object created
for any TABLE_REF may contain elements for constant items. These items should
be ignored by thefunction.
2012-01-20 23:54:43 -08:00
Sergei Golubchik
4f435bddfd 5.3 merge 2012-01-13 15:50:02 +01:00
unknown
cf31ccc33c Fix for LP BUG#908269 Wrong result with subquery in select list, EXISTS, constant MyISAM/Aria table.
Problem: When building the condition for JOIN::outer_ref_cond the optimizer forgot to take into account
that this condition could depend on constant tables as well.
2012-01-10 23:26:00 +02:00
Sergey Petrunya
263ee55318 Remove garbage comments 2011-12-19 18:07:19 +04:00
Sergey Petrunya
04e9004fa3 BUG#901399: Wrong result (extra row) with semijoin=ON, materialization=OFF, optimizer_prune_level=0
- Correctly handle plan refinement stage for LooseScan plans: run create_ref_for_key() if LooseScan 
  plan includes a ref access, and if we don't have any fixed key components, switch to a full index scan.
2011-12-16 03:44:25 +04:00
Igor Babaev
9b4cd1b0ae Merge 2011-12-11 14:38:14 -08:00
Igor Babaev
fa29f18ffb Fixed LP bug #901478.
If the duplicate elimination strategy is used for a semi-join and potentially
one of the block-based join algorithms can be employed to join the inner
tables of the semi-join then sorting of the head (first non-constant) table
for a query with ORDER BY / GROUP BY cannot be used.
2011-12-11 12:56:06 -08:00
Michael Widenius
24e452a208 Merge with 5.1 & fixes to IGNORE handling 2011-12-11 19:28:05 +02:00
Michael Widenius
6d4224a31c Merge with 5.2.
no_error handling for select (used by INSERT ... SELECT) still needs to be fixed, but I will do that in a separate commit
2011-12-11 11:34:44 +02:00
Igor Babaev
7414a0b6d6 Fixed LP bug #900469.
The execution plan cannot use sorting on the first table from the
sequence of the joined tables if it plans to employ the block-based
hash join algorithm.
2011-12-06 13:42:18 -08:00
Igor Babaev
7d1f41265c Fixed LP bug #899777.
KEYUSE elements for a possible hash join key are not sorted by field
numbers of the second table T of the hash join operation. Besides
some of these KEYUSE elements cannot be used to build any key as their
key expressions depend on the tables that are planned to be accessed
after the table T. 
The code before the patch did not take this into account and, as a result,
execition of a query the employing block-based hash join algorithm could
cause a crash or return a wrong result set.
2011-12-05 09:50:24 -08:00
Sergey Petrunya
3a9edc5f77 Merge 2011-11-25 14:28:43 +04:00
Sergey Petrunya
f84dbf4b20 Semi-join optimizations code cleanup part 2:
- Make EXPLAIN display "Start temporary" at the start of the fanout (it used to display
  at the first table whose rowid gets into temp. table which is not that useful for
  the user)
- Updated test results (all checked)
2011-11-25 05:56:58 +04:00
Sergey Petrunya
694ce95557 Semi-join optimizations code cleanup:
- Break down POSITION/advance_sj_state() into four classes 
  representing potential semi-join strategies.

- Treat all strategies uniformly (before, DuplicateWeedout 
  was special as it was the catch-all strategy. Now, we're 
  still relying on it to be the catch-all, but are able to 
  function,e.g. with firstmatch=on,duplicate_weedout=off.

- Update test results (checked)
2011-11-23 04:25:52 +04:00
Sergei Golubchik
d2755a2c9c 5.3->5.5 merge 2011-11-22 18:04:38 +01:00
Michael Widenius
a8d03ab235 Initail merge with MySQL 5.1 (XtraDB still needs to be merged)
Fixed up copyright messages.
2011-11-21 19:13:14 +02:00
Igor Babaev
b4b7d941fe Fixed LP bug #889750.
If the optimizer switch 'semijoin_with_cache' is set to 'off' then 
join cache cannot be used to join inner tables of a semijoin.

Also fixed a bug in the function check_join_cache_usage() that led
to wrong output of the EXPLAIN commands for some test cases.
2011-11-15 13:03:00 -08:00
Sergey Petrunya
7c7611d728 BUG#887026: Wrong result with ICP, outer join, subquery in maria-5.3-icp
- Do not push index condition if we're using a triggered ref access.
2011-11-07 23:30:03 +04:00
Sergei Golubchik
0e007344ea mysql-5.5.18 merge 2011-11-03 19:17:05 +01:00
Sergei Golubchik
76f0b94bb0 merge with 5.3
sql/sql_insert.cc:
  CREATE ... IF NOT EXISTS may do nothing, but
  it is still not a failure. don't forget to my_ok it.
  ******
  CREATE ... IF NOT EXISTS may do nothing, but
  it is still not a failure. don't forget to my_ok it.
sql/sql_table.cc:
  small cleanup
  ******
  small cleanup
2011-10-19 21:45:18 +02:00