mariadb/mysql-test/suite/innodb_plugin/r
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
..
innodb-analyze.result Move the InnoDB Plugin tests from storage/innodb_plugin/mysql-test/ where 2010-04-09 15:56:51 +03:00
innodb-autoinc-44030.result Fix a failure of innodb_plugin.innodb-autoinc-44030 now that 2010-04-09 16:29:13 +03:00
innodb-autoinc-optimize.result Copy built-in InnoDB tests to mysql-test/suite/innodb_plugin. 2010-06-03 12:48:59 +03:00
innodb-autoinc.result Bug#39828 : Autoinc wraps around when offset and increment > 1 2010-12-13 14:48:12 +03:00
innodb-consistent.result Move the InnoDB Plugin tests from storage/innodb_plugin/mysql-test/ where 2010-04-09 15:56:51 +03:00
innodb-create-options.result In this patch, existing tests innodb_bug54679.test and innodb_bug56632.test are 2010-11-02 17:28:34 -05:00
innodb-index.result Move the InnoDB Plugin tests from storage/innodb_plugin/mysql-test/ where 2010-04-09 15:56:51 +03:00
innodb-index_ucs2.result Move the InnoDB Plugin tests from storage/innodb_plugin/mysql-test/ where 2010-04-09 15:56:51 +03:00
innodb-lock.result Move the InnoDB Plugin tests from storage/innodb_plugin/mysql-test/ where 2010-04-09 15:56:51 +03:00
innodb-replace.result Move the InnoDB Plugin tests from storage/innodb_plugin/mysql-test/ where 2010-04-09 15:56:51 +03:00
innodb-semi-consistent.result Move the InnoDB Plugin tests from storage/innodb_plugin/mysql-test/ where 2010-04-09 15:56:51 +03:00
innodb-timeout.result Move the InnoDB Plugin tests from storage/innodb_plugin/mysql-test/ where 2010-04-09 15:56:51 +03:00
innodb-ucs2.result Copy built-in InnoDB tests to mysql-test/suite/innodb_plugin. 2010-06-03 12:48:59 +03:00
innodb-use-sys-malloc.result Move the InnoDB Plugin tests from storage/innodb_plugin/mysql-test/ where 2010-04-09 15:56:51 +03:00
innodb-zip.result In this patch, existing tests innodb_bug54679.test and innodb_bug56632.test are 2010-11-02 17:28:34 -05:00
innodb.result Factor out innodb_multi_update.test from innodb.test 2010-05-05 13:44:25 +03:00
innodb_autoinc_lock_mode_zero.result Copy built-in InnoDB tests to mysql-test/suite/innodb_plugin. 2010-06-03 12:48:59 +03:00
innodb_bug21704.result Move the InnoDB Plugin tests from storage/innodb_plugin/mysql-test/ where 2010-04-09 15:56:51 +03:00
innodb_bug30919.result Copy built-in InnoDB tests to mysql-test/suite/innodb_plugin. 2010-06-03 12:48:59 +03:00
innodb_bug34053.result Move the InnoDB Plugin tests from storage/innodb_plugin/mysql-test/ where 2010-04-09 15:56:51 +03:00
innodb_bug34300.result Move the InnoDB Plugin tests from storage/innodb_plugin/mysql-test/ where 2010-04-09 15:56:51 +03:00
innodb_bug35220.result Move the InnoDB Plugin tests from storage/innodb_plugin/mysql-test/ where 2010-04-09 15:56:51 +03:00
innodb_bug36169.result Move the InnoDB Plugin tests from storage/innodb_plugin/mysql-test/ where 2010-04-09 15:56:51 +03:00
innodb_bug36172.result Move the InnoDB Plugin tests from storage/innodb_plugin/mysql-test/ where 2010-04-09 15:56:51 +03:00
innodb_bug38231.result Move the InnoDB Plugin tests from storage/innodb_plugin/mysql-test/ where 2010-04-09 15:56:51 +03:00
innodb_bug39438.result Move the InnoDB Plugin tests from storage/innodb_plugin/mysql-test/ where 2010-04-09 15:56:51 +03:00
innodb_bug40360.result Move the InnoDB Plugin tests from storage/innodb_plugin/mysql-test/ where 2010-04-09 15:56:51 +03:00
innodb_bug40565.result Move the InnoDB Plugin tests from storage/innodb_plugin/mysql-test/ where 2010-04-09 15:56:51 +03:00
innodb_bug41904.result Move the InnoDB Plugin tests from storage/innodb_plugin/mysql-test/ where 2010-04-09 15:56:51 +03:00
innodb_bug42101-nonzero.result Move the InnoDB Plugin tests from storage/innodb_plugin/mysql-test/ where 2010-04-09 15:56:51 +03:00
innodb_bug42101.result Move the InnoDB Plugin tests from storage/innodb_plugin/mysql-test/ where 2010-04-09 15:56:51 +03:00
innodb_bug42419.result Copy built-in InnoDB tests to mysql-test/suite/innodb_plugin. 2010-06-03 12:48:59 +03:00
innodb_bug44032.result Move the InnoDB Plugin tests from storage/innodb_plugin/mysql-test/ where 2010-04-09 15:56:51 +03:00
innodb_bug44369.result Move the InnoDB Plugin tests from storage/innodb_plugin/mysql-test/ where 2010-04-09 15:56:51 +03:00
innodb_bug44571.result Move the InnoDB Plugin tests from storage/innodb_plugin/mysql-test/ where 2010-04-09 15:56:51 +03:00
innodb_bug45357.result Move the InnoDB Plugin tests from storage/innodb_plugin/mysql-test/ where 2010-04-09 15:56:51 +03:00
innodb_bug46000.result Move the InnoDB Plugin tests from storage/innodb_plugin/mysql-test/ where 2010-04-09 15:56:51 +03:00
innodb_bug46676.result Move the InnoDB Plugin tests from storage/innodb_plugin/mysql-test/ where 2010-04-09 15:56:51 +03:00
innodb_bug47167.result Move the InnoDB Plugin tests from storage/innodb_plugin/mysql-test/ where 2010-04-09 15:56:51 +03:00
innodb_bug47621.result Move the InnoDB Plugin tests from storage/innodb_plugin/mysql-test/ where 2010-04-09 15:56:51 +03:00
innodb_bug47622.result Move the InnoDB Plugin tests from storage/innodb_plugin/mysql-test/ where 2010-04-09 15:56:51 +03:00
innodb_bug47777.result Move the InnoDB Plugin tests from storage/innodb_plugin/mysql-test/ where 2010-04-09 15:56:51 +03:00
innodb_bug48024.result Make the InnoDB FOREIGN KEY parser understand multi-statements. (Bug #48024) 2010-05-14 16:08:15 +03:00
innodb_bug49164.result Add an innodb_plugin test case for Bug #49164. 2010-05-10 13:38:25 +02:00
innodb_bug51378.result Move the InnoDB Plugin tests from storage/innodb_plugin/mysql-test/ where 2010-04-09 15:56:51 +03:00
innodb_bug51920.result mysql-5.1-innodb: add error codes to innodb_bug51920.test 2010-04-22 14:16:14 -05:00
innodb_bug52663.result row_search_for_mysql(): Never try semi-consistent read in unique searches. 2010-04-26 13:27:25 +03:00
innodb_bug52745.result Add a test case for Bug #52745. 2010-04-26 14:08:56 +03:00
innodb_bug53046.result Fix Bug#53046 dict_update_statistics_low can still be run concurrently on same table 2010-11-02 18:57:20 +02:00
innodb_bug53290.result Merge a contribution from Ryan Mack at Facebook: 2010-05-05 15:39:01 +03:00
innodb_bug53591.result ha_innobase::add_index(): Reset trx->error_state in error handling. 2010-05-12 13:42:12 +03:00
innodb_bug53592.result Fix Bug #53592 in plugin code, "crash replacing duplicates into table 2010-05-25 22:31:27 -07:00
innodb_bug53674.result Bug#53674: InnoDB: Error: unlock row could not find a 4 mode lock on the record 2010-06-02 13:37:14 +03:00
innodb_bug53756.result Port fix for bug #53756 from 5.1 built-in to 5.1 plugin. 2010-09-06 22:41:37 -07:00
innodb_bug54044.result Change the table name in innodb_bug54044 to lower case to avoid 2010-06-29 00:13:18 -07:00
innodb_bug54453.result Bug#54453: Failing assertion: trx->active_trans when renaming a 2010-07-20 14:36:15 -03:00
innodb_bug56143.result Fix Bug#56143 too many foreign keys causes output of show create table to become invalid 2010-10-14 12:28:25 +03:00
innodb_bug56680.result Bug #56680 wrong InnoDB results from a case-insensitive covering index 2010-10-19 09:04:15 +03:00
innodb_bug56716.result Bug#56716 InnoDB locks a record gap without locking the table 2010-10-04 13:06:41 +03:00
innodb_bug56947.result Bug #56947 InnoDB leaks memory when failing to create a table 2010-10-11 11:18:00 +03:00
innodb_bug57252.result Fix Bug#57252 disabling innobase_stats_on_metadata disables ANALYZE 2010-10-18 14:20:16 +03:00
innodb_bug57255.result Fix Bug #57255 Cascade Delete results in "Got error -1 from storage engine". 2010-10-06 03:41:26 -07:00
innodb_file_format.result Move the InnoDB Plugin tests from storage/innodb_plugin/mysql-test/ where 2010-04-09 15:56:51 +03:00
innodb_gis.result Copy built-in InnoDB tests to mysql-test/suite/innodb_plugin. 2010-06-03 12:48:59 +03:00
innodb_information_schema.result Move the InnoDB Plugin tests from storage/innodb_plugin/mysql-test/ where 2010-04-09 15:56:51 +03:00
innodb_lock_wait_timeout_1.result Copy built-in InnoDB tests to mysql-test/suite/innodb_plugin. 2010-06-03 12:48:59 +03:00
innodb_multi_update.result Fixed following problems: 2010-12-14 12:33:03 +03:00
innodb_mysql.result Bug#56862 Execution of a query that uses index merge returns a wrong result 2010-11-23 13:18:47 +03:00
innodb_mysql_rbk.result Copy built-in InnoDB tests to mysql-test/suite/innodb_plugin. 2010-06-03 12:48:59 +03:00
innodb_notembedded.result Copy built-in InnoDB tests to mysql-test/suite/innodb_plugin. 2010-06-03 12:48:59 +03:00
innodb_timeout_rollback.result Copy built-in InnoDB tests to mysql-test/suite/innodb_plugin. 2010-06-03 12:48:59 +03:00
innodb_trx_weight.result Move the InnoDB Plugin tests from storage/innodb_plugin/mysql-test/ where 2010-04-09 15:56:51 +03:00