Commit graph

568 commits

Author SHA1 Message Date
unknown
79a04a2c9c Moving LP BUG#794005 to 5.3 + fixing INSERT of multi-table view. 2012-02-03 13:01:05 +02:00
Igor Babaev
40e4d09c53 Merge 2012-01-18 14:19:28 -08:00
Igor Babaev
746dbbe583 Fixed LP bug #917990.
If the expression for a derived table of a query contained a LIMIT
clause the estimate of the number of rows in this derived table
returned by the EXPLAIN command could be badly off since the
optimizer ignored the limit number from the LIMIT clause when
getting the estimate. 
The call of the method SELECT_LEX_UNIT->set_limit added in the code
of mysql_derived_optimize() will be needed also in maria-5.5 where
parameters in the LIMIT clause are supported.
2012-01-18 03:31:20 -08:00
unknown
69327e2987 Adjust test results after Monty's push of the new
handler counter Handler_read_rnd_deleted.
2012-01-18 12:53:50 +02:00
Igor Babaev
f5dac20f38 Made the optimizer switch flags 'outer_join_with_cache', 'semijoin_with_cache'
set to 'on' by default.
2011-12-15 00:21:15 -08:00
unknown
54caeee5d6 Making subquery cache on by default. 2011-10-05 18:18:00 +03:00
Sergey Petrunya
3769841d9e BUG#833600: Wrong result with view + outer join + uncorrelated subquery (non-semijoin)
- The bug was caused by outer join being incorrectly converted into inner because of 
  invalid return values of Item_direct_view_ref::not_null_tables().
- Provided a correct Item_direct_view_ref::not_null_tables() function.
2011-09-08 23:24:47 +04:00
Igor Babaev
8b56830f7b Fixed LP bug #823189.
The method Item_ref::not_null_tables() returned incorrect bitmap
for outer references to view columns. This could cause an invalid
conversion of an outer join into an inner join that could lead
to a wrong result set for a query with a correlated subquery over
an outer join whose where condition had an outer reference to a view.
2011-08-11 20:24:32 -07:00
Igor Babaev
2092436457 Merge. 2011-07-21 15:55:08 -07:00
Igor Babaev
63abf00a62 Made the optimizer switches 'derived_merge' and 'derived_with_keys'
off by default.
2011-07-21 14:23:08 -07:00
unknown
813aaac51d Fix for LP BUG#806071
In case of two views with subqueries it is dificult to decide about order of injected ORDER BY clauses.
A simple solution is just prohibit ORDER BY injection if there is other order by.

mysql-test/r/view.result:
  New test added, old test changed.
mysql-test/t/view.test:
  New test aded.
sql/share/errmsg.txt:
  new warning added.
sql/sql_view.cc:
  Inject ORDER BY only if there is no other one.
  
  Warning about ignoring ORDER BY in this case for EXPLAIN EXTENDED.
2011-07-21 23:37:40 +03:00
unknown
ef2b4b14e1 Merge from 5.2 2011-07-21 15:50:25 +03:00
unknown
ee06e4d65e Removed incorrect fix and its test suite (the test suit is duplicate).
Fixed explains of previous patch.

mysql-test/r/explain.result:
  Fixed explains of previous patch.
mysql-test/r/join_outer.result:
  Fixed explains of previous patch.
mysql-test/r/negation_elimination.result:
  Fixed explains of previous patch.
mysql-test/r/view.result:
  Fixed explains of previous patch.
mysql-test/suite/innodb/r/innodb_mysql.result:
  Removed duplicate test suite.
mysql-test/suite/innodb/t/innodb_mysql.test:
  Removed duplicate test suite.
mysql-test/suite/innodb_plugin/r/innodb_mysql.result:
  Removed duplicate test suite.
mysql-test/suite/innodb_plugin/t/innodb_mysql.test:
  Removed duplicate test suite.
sql/opt_range.h:
  Removed incorrect fix.
sql/records.cc:
  Removed incorrect fix.
2011-07-21 12:29:00 +03:00
unknown
20a2e1d0ac Fix of LP BUG#777809
There are 2 volatile condition constructions AND/OR constructions and fields(references) when first
good supported to be top elements of conditions because it is normal practice
(see copy_andor_structure for example) fields without any expression in the condition is really rare
and mostly useless case however it could lead to problems when optimiser changes/moves them unaware
of other variables referring to them. An easy solution of this problem is just to replace single field
in a condition with equivalent expression well supported by the server (<field> -> <field> != 0).

mysql-test/r/view.result:
  New test added.
mysql-test/t/view.test:
  New test added.
sql/sql_parse.cc:
  <field> -> <field> != 0
sql/sql_yacc.yy:
  <field> -> <field> != 0
2011-07-21 11:20:55 +03:00
Igor Babaev
47aee19827 Fixed LP bug #793386.
Auto-generated names for view field items must be allocated in
the statement memory, not in the execution memory of the statement.
2011-07-11 10:56:48 -07:00
Sergey Petrunya
1492de8563 Set the default to be mrr=off,mrr_sort_keys=off:
- Set the default
- Adjust the testcases so that 'new' tests are run with optimizations turned on.
- Pull out relevant tests from "irrelevant" tests and run them with optimizations on.
- Run range.test and innodb.test with both mrr=on and mrr=off
2011-07-08 18:46:47 +04:00
Igor Babaev
3f7d51d0d8 Fixed LP bug #804686.
The assert conditions in the functions Item_direct_ref_to_ident::transform
and Item_direct_ref_to_ident::compile could be not valid after constant
propagation when fields and field references may be substituted for constants.
Not only these invalid asserts have been removed, but the functions containing
them have been removed as well because now Item_ref::transform and 
Item_ref::compile can be used instead of them.
2011-07-03 14:59:01 -07: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
Igor Babaev
c68020210f Added test cases for LP bug #798625 and LP bug #800085
fixed by the patch for LP bug 798621.
2011-06-24 21:18:20 -07:00
Igor Babaev
fb22eb1391 Fixed LP bug #798576.
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.
2011-06-24 14:38:53 -07:00
Igor Babaev
e7578ac612 Fixed LP bug #798621.
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.
2011-06-21 18:00:58 -07:00
Igor Babaev
7f345153f9 Fixed LP bug #794038.
INSERT/UPDATE/DELETE statement that used a temptable view v1 could lead to
a crash if v1 was defined as a select from a mergeable view v2 that selected
rows from a temptable view v3. 
 
When INSERT/UPDATE/DELETE uses a view that is not updatable then field
translation for the view should be created before the prepare phase.
2011-06-09 00:13:00 -07:00
Oleksandr Byelkin
e89da2e0f1 Return commented out tests. 2011-05-31 15:33:14 +03:00
Igor Babaev
89cf840cd9 Merge 2011-05-20 12:47:39 -07:00
Igor Babaev
8e33aa9aa7 Merged the fix for bug 777745 into 5.3. 2011-05-19 20:01:43 -07:00
Igor Babaev
016a09cb7d Fixed LP bug #777745.
Fields belonging to views in general cannot be substituted for 
equal items, in particular for constants, because all references
to a view field refer to the same Item_field object while they 
could be used in different OR parts of the where condition and
belong to different equivalence classes (to different Item_equals).
That's why substitution for equal items in any context is allowed
only in place of Item_direct_view_ref objects, but not in place of
Item_fields these objects refer to.
Due to some erroneous code in the patch for bug 717577 substitution
for view fields were allowed in some context.This could lead
to wrong results returned by queries using views.

The fix prohibits substitution of view fields for equal items 
in any context.

The patch also changes slightly the compile method for the Item_func
class. Now if the analyze method returns NULL in his parameter the
compile method is not called for the arguments of the function
at all. A similar change was made for the Item_ref class.
2011-05-19 18:28:38 -07:00
Igor Babaev
1018c90107 Fixed LP bug #784281.
When a view is merged into a select all the depended_from fields
pointing to the select of the view should have been corrected to
point to the select where the view is used. It was not done yet.
This could lead to wrong results returned by queries such as
one from the test case for bug 33389.
Correction of outer references required walking through all items
of the proccesed qurery. To avoid this the following solution was
implemented.
Each select now contains a pointer to the select it is merged into
(if there is any). Such pointers allow to get the corrected value
of depended_from on the fly. The function Item_ident::get_depended_from
was introduced for this purpose.
2011-05-17 22:22:33 -07: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
Michael Widenius
f34be18938 Merge with MariaDB 5.2 2011-05-10 18:17:43 +03:00
Michael Widenius
e415ba0fb2 Merge with MySQL 5.1.57/58
Moved some BSD string functions from Unireg
2011-05-02 20:58:45 +03: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
Gleb Shchepa
a77bc59896 Bug #11829681 - 60295: ERROR 1356 ON VIEW THAT EXECUTES FINE AS A QUERY
Select from a view with the underlying HAVING clause failed with a
message: "1356: View '...' references invalid table(s) or column(s)
or function(s) or definer/invoker of view lack rights to use them"

The bug is a regression of the fix for bug 11750328 - 40825 (similar
case, but the HAVING cause references an aliased field).
In the old fix for bug 40825 the Item_field::name_length value has
been used in place of the real length of Item_field::name. However,
in some cases Item_field::name_length is not in sync with the
actual name length (TODO: combine name and name_length into a
solid String field).

The Item_ref::print() method has been modified to calculate actual
name length every time.


mysql-test/r/view.result:
  Test case for bug #11829681
mysql-test/t/view.test:
  Test case for bug #11829681
sql/item.cc:
  Bug #11829681 - 60295: ERROR 1356 ON VIEW THAT EXECUTES FINE AS A QUERY
  
  The Item_ref::print() method has been modified to calculate actual
  name length every time.
sql/item.h:
  Minor commentary.
2011-04-08 12:05:20 +04:00
Michael Widenius
139a2b64bf Merge with 5.2 2011-03-09 15:47:59 +02:00
Michael Widenius
58bb0769bd Merge with MySQL 5.1.55
- Fixed some issues with partitions and connection_string, which also fixed lp:716890 "Pre- and post-recovery crash in Aria"
- Fixed wrong assert in Aria

Now need to merge with latest xtradb before pushing 

sql/ha_partition.cc:
  Ensure that m_ordered_rec_buffer is not freed before close.
sql/mysqld.cc:
  Changed to use opt_stack_trace instead of opt_pstack.
  Removed references to pstack
sql/partition_element.h:
  Ensure that connect_string is initialized
storage/maria/ma_key_recover.c:
  Fixed wrong assert
2011-02-20 18:51:43 +02:00
Igor Babaev
6c7360b540 Merge 2011-02-07 15:19:03 -08:00
Igor Babaev
cbeab25085 Fixed LP bug #702403 that caused a crash on the tree for mwl#128
with the test case added by this patch.
The bug cannot be reproduced with the same test case for the main
5.3 tree because the backported fix for bug 59696 masks the 
problem that causes the crash in the mentioned test case. It's not
clear weather this fix masks this problem in all possible cases. 

Anyway the patch for bug 698882 introduced some inconsistent data
structures that could contain indirect references to deleted object.
It happened when two Item_equal objects were merged and the Item_field
list of the second object was joined to such list of the first object.
This operation required adjustment of the backward pointers in 
Item fields from the joined list. However the adjustment was missing 
and this caused crashes in the tree for mwl#128.

Now the backward pointers are set only when Item_equal items are
completely built and are not changed anymore.
2011-02-05 20:57:03 -08:00
Igor Babaev
8041013fb1 Back-ported the patch for bug #59696 from mysql-5.6 code line.
The patch fixed the following optimizer defect: when performing
substitution for best equal fields into where conditions to be
able to do their evaluations as soon as possible the optimizer 
skipped conditions over views. That could lead to suboptimal 
execution of queries that used views.  
Slightly changed the test case to demonstrate the performance
improvements if this fix.
2011-01-31 19:33:32 -08:00
Sergey Glukhov
fcb83cbf15 Fixed following problems:
--Bug#52157 various crashes and assertions with multi-table update, stored function
--Bug#54475 improper error handling causes cascading crashing failures in innodb/ndb
--Bug#57703 create view cause Assertion failed: 0, file .\item_subselect.cc, line 846
--Bug#57352 valgrind warnings when creating view
--Recently discovered problem when a nested materialized derived table is used
  before being populated and it leads to incorrect result

We have several modes when we should disable subquery evaluation.
The reasons for disabling are different. It could be
uselessness of the evaluation as in case of 'CREATE VIEW'
or 'PREPARE stmt', or we should disable subquery evaluation
if tables are not locked yet as it happens in bug#54475, or
too early evaluation of subqueries can lead to wrong result
as it happened in Bug#19077.
Main problem is that if subquery items are treated as const
they are evaluated in ::fix_fields(), ::fix_length_and_dec()
of the parental items as a lot of these methods have
Item::val_...() calls inside.
We have to make subqueries non-const to prevent unnecessary
subquery evaluation. At the moment we have different methods
for this. Here is a list of these modes:

1. PREPARE stmt;
We use UNCACHEABLE_PREPARE flag.
It is set during parsing in sql_parse.cc, mysql_new_select() for
each SELECT_LEX object and cleared at the end of PREPARE in
sql_prepare.cc, init_stmt_after_parse(). If this flag is set
subquery becomes non-const and evaluation does not happen.

2. CREATE|ALTER VIEW, SHOW CREATE VIEW, I_S tables which
   process FRM files
We use LEX::view_prepare_mode field. We set it before
view preparation and check this flag in
::fix_fields(), ::fix_length_and_dec().
Some bugs are fixed using this approach,
some are not(Bug#57352, Bug#57703). The problem here is
that we have a lot of ::fix_fields(), ::fix_length_and_dec()
where we use Item::val_...() calls for const items.

3. Derived tables with subquery = wrong result(Bug19077)
The reason of this bug is too early subquery evaluation.
It was fixed by adding Item::with_subselect field
The check of this field in appropriate places prevents
const item evaluation if the item have subquery.
The fix for Bug19077 fixes only the problem with
convert_constant_item() function and does not cover
other places(::fix_fields(), ::fix_length_and_dec() again)
where subqueries could be evaluated.

Example:
CREATE TABLE t1 (i INT, j BIGINT);
INSERT INTO t1 VALUES (1, 2), (2, 2), (3, 2);
SELECT * FROM (SELECT MIN(i) FROM t1
WHERE j = SUBSTRING('12', (SELECT * FROM (SELECT MIN(j) FROM t1) t2))) t3;
DROP TABLE t1;

4. Derived tables with subquery where subquery
   is evaluated before table locking(Bug#54475, Bug#52157)

Suggested solution is following:

-Introduce new field LEX::context_analysis_only with the following
 possible flags:
 #define CONTEXT_ANALYSIS_ONLY_PREPARE 1
 #define CONTEXT_ANALYSIS_ONLY_VIEW    2
 #define CONTEXT_ANALYSIS_ONLY_DERIVED 4
-Set/clean these flags when we perform
 context analysis operation
-Item_subselect::const_item() returns
 result depending on LEX::context_analysis_only.
 If context_analysis_only is set then we return
 FALSE that means that subquery is non-const.
 As all subquery types are wrapped by Item_subselect
 it allow as to make subquery non-const when
 it's necessary.


mysql-test/r/derived.result:
  test case
mysql-test/r/multi_update.result:
  test case
mysql-test/r/view.result:
  test case
mysql-test/suite/innodb/r/innodb_multi_update.result:
  test case
mysql-test/suite/innodb/t/innodb_multi_update.test:
  test case
mysql-test/suite/innodb_plugin/r/innodb_multi_update.result:
  test case
mysql-test/suite/innodb_plugin/t/innodb_multi_update.test:
  test case
mysql-test/t/derived.test:
  test case
mysql-test/t/multi_update.test:
  test case
mysql-test/t/view.test:
  test case
sql/item.cc:
  --removed unnecessary code
sql/item_cmpfunc.cc:
  --removed unnecessary checks
  --THD::is_context_analysis_only() is replaced with LEX::is_ps_or_view_context_analysis()
sql/item_func.cc:
  --refactored context analysis checks
sql/item_row.cc:
  --removed unnecessary checks
sql/item_subselect.cc:
  --removed unnecessary code
  --added DBUG_ASSERT into Item_subselect::exec()
    which asserts that subquery execution can not happen
    if LEX::context_analysis_only is set, i.e. at context
    analysis stage.
  --Item_subselect::const_item()
    Return FALSE if LEX::context_analysis_only is set.
    It prevents subquery evaluation in ::fix_fields &
    ::fix_length_and_dec at context analysis stage.
sql/item_subselect.h:
  --removed unnecessary code
sql/mysql_priv.h:
  --Added new set of flags.
sql/sql_class.h:
  --removed unnecessary code
sql/sql_derived.cc:
  --added LEX::context_analysis_only analysis intialization/cleanup
sql/sql_lex.cc:
  --init LEX::context_analysis_only field
sql/sql_lex.h:
  --New LEX::context_analysis_only field
sql/sql_parse.cc:
  --removed unnecessary code
sql/sql_prepare.cc:
  --removed unnecessary code
  --added LEX::context_analysis_only analysis intialization/cleanup
sql/sql_select.cc:
  --refactored context analysis checks
sql/sql_show.cc:
  --added LEX::context_analysis_only analysis intialization/cleanup
sql/sql_view.cc:
  --added LEX::context_analysis_only analysis intialization/cleanup
2010-12-14 12:33:03 +03:00
Christopher Powers
4edea18f8d Bug#35333, "If Federated table can't connect to remote host, can't retrieve
metadata"
            
Improved error handling such that queries against Information_Schema.Tables won't
fail if a federated table can't make a remote connection.

mysql-test/r/merge.result:
  Updated with warnings that were previously masked.
mysql-test/r/show_check.result:
  Updated with warnings that were previously masked.
mysql-test/r/view.result:
  Updated with warnings that were previously masked.
sql/sql_show.cc:
  If get_schema_tables_record() encounters an error, push a warning,
  set the TABLE COMMENT column with the error text, and clear the
  error so that the operation can continue.
2010-11-29 22:46:43 -06:00
Igor Babaev
4f75a8254a Merge 5.3-mwl128 -> 5.3 2010-10-27 16:31:22 -07:00
Igor Babaev
25f5debdc7 MWL#128: Added into EXPLAIN output info about types of the used join buffers and
about the employed join algorithms.
Refactored constructors of the JOIN_CACHE* classes.
2010-10-18 13:33:05 -07:00
Sergey Petrunya
72dd7575cd Merge 5.2->5.3
- Re-commit Monty's merge, partially fixed by Igor and SergeyP, 
  but still broken
2010-10-10 17:18:11 +03:00
Igor Babaev
21b1b5f040 Fixed bug #52636.
Applied the fix for bug #47217 from the mysql-6.0 codebase.
The patch adds not null predicates generated for the left parts
of the equality predicates used for ref accesses. This is done
for such predicates both in where conditions and on conditions.
For the where conditions the not null predicates were generated
but in 5.0/5.1 they actually never were used due to some lame
merge from 4.1 to 5.0. The fix for bug #47217 made these 
predicates to be used in the condition pushed to the tables.
Yet only this patch generates not null predicates for equality
predicated from on conditions of outer joins.
This patch introduces a performance regression that can be
observed on a test case from null_key.test. The regression
will disappear after the fix for bug #57024 from mariadb-5.1
is pulled into mariadb-5.3.
The patch contains many changes in the outputs of the EXPLAIN 
commands since generated not null predicates are considered as
parts of the conditions pushed to join tables and may add
'Usingwhere' in some rows of EXPLAINs where there used
to be no such comments.
2010-09-28 12:39:33 -07:00
Igor Babaev
b969df8bbd Merge of the mwl106 tree into the latest 5.3 tree.
Resolved conflicts. Adjusted some test results
2010-09-23 08:10:53 -07:00
Igor Babaev
577b7345c7 Fixed bug #49600.
The problem could be demonstrated with an outer join of two single-row
tables where the values of the join attributes were null. Any query
with such a join could return a wrong result set if the where
condition of the query was not empty. For queries with empty
where conditions the result sets were correct.
This was the consequence of two bugs in the code:
 - Item_equal objects for on conditions of outer joins were
   not built if the processed query had no where condition
 - the check for null values in the code that evaluated constant 
   Item_equal objects was incorrect.
Fixed both above problems.
Added a test case for the bug and adjusted results for some other
test cases.
2010-09-11 08:20:35 -07:00
Sergey Petrunya
27f9fc063c MariaDB 5.2 -> MariaDB 5.3 merge 2010-06-26 14:05:41 +04:00
Igor Babaev
709a0a1310 MWL#106: Backport optimizations for derived tables and views.
The main consolidated patch.
2010-05-26 13:18:18 -07:00
Michael Widenius
4aa9d903c1 Merge with MySQL 5.1.47
Fixed some bugs introduced in 5.1.47
Disabled some tests until we have merged with latest Xtradb

configure.in:
  Added testing if valgrind/memcheck.h exists
storage/pbxt/src/ha_pbxt.cc:
  LOCK_plugin is not anymore locked in init
2010-05-26 21:55:40 +03:00
unknown
b1e00b6be8 Merge MySQL 5.1.46 into MariaDB.
Still two test failures to be solved: main.myisam and main.subselect.
2010-04-28 14:52:24 +02:00