mariadb/mysql-test/t
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
..
1st.test
alias.test
almost_full.test
alter_table-big.test
alter_table.test
analyse.test
analyze.test
ansi.test
archive-big.test
archive.test
archive_bitfield.test
archive_gis.test
auto_increment.test Bug#39828 : Autoinc wraps around when offset and increment > 1 2010-12-13 14:48:12 +03:00
backup-master.sh
backup.test
bench_count_distinct.test
bigint.test
binary.test
bool.test
bootstrap.test
bug39022.test
bug46080-master.opt
bug46080.test
bug46261-master.opt
bug46261.test
bug46760-master.opt
bug46760.test
bug47671-master.opt
bug47671.test
bulk_replace.test
cache_innodb-master.opt
cache_innodb.test
case.test
cast.test
change_user-master.opt
change_user.test Assorted post-merge fixes, clean-up, integration, compat with 5.6. 2010-11-25 03:11:05 +00:00
check.test
client_xml.test
comments.test
commit_1innodb.test
compare.test
compress.test
concurrent_innodb_safelog-master.opt
concurrent_innodb_safelog.test
concurrent_innodb_unsafelog-master.opt
concurrent_innodb_unsafelog.test
connect.test Bug #49752: 2469.126.2 unintentionally breaks authentication against 2010-11-11 07:34:14 +00:00
consistent_snapshot.test
constraints.test
contributors.test
count_distinct.test
count_distinct2-master.opt
count_distinct2.test
count_distinct3.test
crash_commit_before-master.opt
crash_commit_before.test
create-big.test
create.test
create_not_windows.test
create_select_tmp.test
csv.test
csv_alter_table.test
csv_not_null.test
ctype_ascii.test
ctype_big5.test
ctype_collate.test
ctype_cp932_binlog_row.test
ctype_cp932_binlog_stm.test
ctype_cp1250_ch.test
ctype_cp1251.test Bug#56639 Character Euro (0x88) not converted from cp1251 to utf8 2010-11-26 16:58:54 +03:00
ctype_create.test
ctype_eucjpms.test
ctype_euckr.test
ctype_filename.test
ctype_filesystem-master.opt
ctype_filesystem.test
ctype_gb2312.test
ctype_gbk.test
ctype_gbk_binlog.test
ctype_hebrew.test
ctype_latin1.test
ctype_latin1_de-master.opt
ctype_latin1_de.test
ctype_latin2.test
ctype_latin2_ch.test
ctype_ldml-master.opt
ctype_ldml.test
ctype_many.test
ctype_mb.test
ctype_recoding.test
ctype_sjis.test
ctype_tis620.test
ctype_uca.test
ctype_ucs.test
ctype_ucs2_def-master.opt
ctype_ucs2_def.test
ctype_ujis.test
ctype_ujis_ucs2.test
ctype_utf8.test Fix for bug#57272: crash in rpad() when using utf8 2010-10-12 23:25:40 +04:00
date_formats-master.opt
date_formats.test
ddl_i18n_koi8r.test
ddl_i18n_utf8.test
deadlock_innodb.test
debug_sync.test
default.test
delayed.test
delete.test
derived.test Fixed following problems: 2010-12-14 12:33:03 +03:00
dirty_close.test
disabled.def Bug#58197: main.variables-big fails on windows 2010-11-15 16:17:38 +01:00
distinct.test
drop.test
empty_table.test
endspace.test
error_simulation.test
errors.test
events_1.test
events_2.test
events_bugs-master.opt
events_bugs.test
events_embedded.test
events_grant.test
events_logs_tests-master.opt
events_logs_tests.test
events_microsec.test
events_restart-master.opt
events_restart.test
events_scheduling.test
events_stress.test
events_time_zone.test
events_trans.test
events_trans_notembedded.test
exampledb.test
execution_constants.test
explain.test Bug#56814 Explain + subselect + fulltext crashes server 2010-10-18 16:12:27 +04:00
fix_priv_tables.test
flush.test
flush2-master.opt
flush2.test
flush_block_commit.test
flush_block_commit_notembedded.test
flush_read_lock_kill-master.opt
flush_read_lock_kill.test
flush_table.test
foreign_key.test
fulltext.test Bug#54484 explain + prepared statement: crash and Got error -1 from storage engine 2010-10-18 14:47:26 +04:00
fulltext2.test
fulltext3.test
fulltext_cache.test
fulltext_distinct.test
fulltext_left_join.test
fulltext_multi.test
fulltext_order_by.test
fulltext_plugin-master.opt
fulltext_plugin.test
fulltext_update.test
fulltext_var.test
func_compress.test
func_concat.test
func_crypt.test
func_date_add.test
func_default.test
func_des_encrypt.test
func_encrypt-master.opt
func_encrypt.test
func_encrypt_nossl.test
func_equal.test
func_gconcat.test Bug#58396 group_concat and explain extended are still crashy 2010-12-13 13:39:26 +03:00
func_group.test
func_group_innodb.test
func_if.test
func_in.test
func_isnull.test
func_like.test
func_math.test Bug#57477 SIGFPE when dividing a huge number a negative number 2010-10-27 18:12:10 +04:00
func_misc.test Fix for bug#57283: inet_ntoa() crashes 2010-10-12 23:28:03 +04:00
func_op.test
func_regexp.test
func_rollback.test
func_sapdb.test
func_set.test
func_str.test
func_system.test
func_test.test
func_time.test Bug #52160: crash and inconsistent results when grouping 2010-10-31 19:04:38 +03:00
func_timestamp.test
gcc296.test
gis-rtree.test
gis.test
grant.test Fixed bug#36742 - GRANT hostname case handling inconsistent. 2010-10-13 12:28:58 +07:00
grant2.test
grant3-master.opt
grant3.test Follow up for bug#36742. Changed test case for bug#19828 2010-10-18 21:03:53 +07:00
grant_cache_no_prot.test
grant_cache_ps_prot.test
grant_lowercase_fs.test
greedy_optimizer.test
group_by.test Bug#57688 Assertion `!table || (!table->write_set || bitmap_is_set(table->write_set, field 2010-10-29 12:23:06 +04:00
group_min_max.test
group_min_max_innodb.test
handler_innodb.test
handler_myisam.test
having.test
heap.test
heap_auto_increment.test
heap_btree.test
heap_hash.test
help.test
index_merge_innodb.test
index_merge_myisam.test
information_schema.test
information_schema_chmod.test
information_schema_db.test
information_schema_inno.test
information_schema_part.test
init_connect-master.opt
init_connect.test
init_file-master.opt
init_file.test
innodb_ignore_builtin-master.opt
innodb_ignore_builtin.test
innodb_mysql_lock2.test
insert.test
insert_notembedded.test
insert_select.test
insert_update.test
join.test
join_crash.test
join_nested.test
join_outer.test Bug#57688 Assertion `!table || (!table->write_set || bitmap_is_set(table->write_set, field 2010-10-29 12:23:06 +04:00
join_outer_innodb.test
key.test
key_cache-master.opt Bug #57840 MTR: parallel execution breaks with smart ordering of test cases 2010-11-05 15:26:38 +01:00
key_cache.test Assorted post-merge fixes, clean-up, integration, compat with 5.6. 2010-11-25 03:11:05 +00:00
key_diff.test
key_primary.test
keywords.test
kill.test
limit.test
loaddata.test
loaddata_autocom_innodb.test
locale.test
lock.test
lock_multi.test
lock_multi_bug38499.test
lock_multi_bug38691.test
lock_sync.test
lock_tables_lost_commit-master.opt
lock_tables_lost_commit.test
log_state-master.opt
log_state.test
log_tables-big-master.opt
log_tables-big.test
log_tables-master.opt
log_tables.test A fix and a test case for Bug#47924 -main.log_tables times out 2010-11-07 23:42:54 +06:00
log_tables_debug.test
log_tables_upgrade.test
long_tmpdir-master.opt
long_tmpdir-master.sh
long_tmpdir.test
lowercase_fs_off.test
lowercase_mixed_tmpdir-master.opt
lowercase_mixed_tmpdir-master.sh
lowercase_mixed_tmpdir.test
lowercase_mixed_tmpdir_innodb-master.opt
lowercase_mixed_tmpdir_innodb-master.sh
lowercase_mixed_tmpdir_innodb.test
lowercase_table-master.opt
lowercase_table.test
lowercase_table2.test
lowercase_table3-master.opt
lowercase_table3.test
lowercase_table4-master.opt Bug #46941 crash with lower_case_table_names=2 and foreign key 2010-10-19 12:27:09 +02:00
lowercase_table4.test Bug #46941 crash with lower_case_table_names=2 and foreign key 2010-10-19 12:27:09 +02:00
lowercase_table_grant-master.opt
lowercase_table_grant.test
lowercase_table_qcache-master.opt
lowercase_table_qcache.test
lowercase_utf8-master.opt
lowercase_utf8.test
lowercase_view-master.opt
lowercase_view.test
merge-big.test
merge.test
merge_innodb.test
metadata.test
mix2_myisam.test
mix2_myisam_ucs2.test
multi_statement-master.opt
multi_statement.test
multi_update-master.opt
multi_update.test Fixed following problems: 2010-12-14 12:33:03 +03:00
multi_update2-master.opt
multi_update2.test
multi_update_tiny_hash-master.opt
multi_update_tiny_hash.test
myisam-blob-master.opt
myisam-blob.test
myisam-system.test
myisam.test
myisam_crash_before_flush_keys-master.opt
myisam_crash_before_flush_keys.test
myisam_debug.test
myisampack.test
mysql-bug41486.test
mysql-bug45236.test
mysql.test Additional fix for bug#54899 2010-12-01 12:25:31 +05:30
mysql_client_test-master.opt
mysql_client_test.test
mysql_comments.sql
mysql_comments.test
mysql_cp932.test
mysql_delimiter.sql
mysql_delimiter_19799.sql
mysql_delimiter_source.sql
mysql_protocols.test
mysql_upgrade.test
mysqladmin.test
mysqlbinlog-cp932-master.opt
mysqlbinlog-cp932.test
mysqlbinlog-master.opt Bug #57840 MTR: parallel execution breaks with smart ordering of test cases 2010-11-05 15:26:38 +01:00
mysqlbinlog.test
mysqlbinlog2.test
mysqlbinlog_base64.test
mysqlbinlog_row.test
mysqlbinlog_row_big.test
mysqlbinlog_row_innodb.test
mysqlbinlog_row_myisam.test
mysqlbinlog_row_trans.test
mysqlcheck.test
mysqldump-compat.opt
mysqldump-compat.test
mysqldump-max.test
mysqldump-no-binlog-master.opt
mysqldump-no-binlog.test
mysqldump.test
mysqldump_restore.test
mysqlhotcopy_archive.test
mysqlhotcopy_myisam.test
mysqlshow.test
mysqlslap.test
mysqltest.test Bug #58092 Test "rpl_cross_version" has "copy_file" failing 2010-12-01 11:11:16 +01:00
named_pipe-master.opt
named_pipe.test
negation_elimination.test
no-threads-master.opt
no-threads.test
no_binlog.test
not_embedded_server-master.opt
not_embedded_server.test
not_partition.test
null.test
null_key.test
odbc.test
olap.test
openssl_1.test
order_by.test
order_fill_sortbuf-master.opt
order_fill_sortbuf.test
outfile.test
outfile_loaddata.test
overflow.test
packet.test
parser.test
parser_bug21114_innodb.test
parser_not_embedded.test
parser_precedence.test
parser_stack.test
partition-master.opt
partition.test
partition_archive.test
partition_binlog_stmt.test Bug#51851: Server with SBR locks mutex twice on 2010-10-01 13:39:04 +02:00
partition_blackhole.test
partition_bug18198.test
partition_charset.test
partition_csv.test
partition_datatype.test
partition_debug_sync.test
partition_disabled-master.opt
partition_disabled.test
partition_error.test
partition_federated.test
partition_grant.test
partition_hash.test
partition_innodb-master.opt
partition_innodb.test merging. 2010-10-15 20:13:35 +05:00
partition_innodb_builtin.test
partition_innodb_plugin.test
partition_innodb_semi_consistent-master.opt
partition_innodb_semi_consistent.test
partition_innodb_stmt.test
partition_list.test
partition_mgm.test
partition_mgm_err.test
partition_mgm_err2.test
partition_not_blackhole-master.opt
partition_not_blackhole.test
partition_not_embedded.test
partition_not_windows-master.opt
partition_not_windows.test
partition_open_files_limit-master.opt
partition_open_files_limit.test
partition_order.test
partition_pruning.test
partition_range.test
partition_rename_longfilename.test
partition_symlink.test
partition_windows.test
perror-win.test
perror.test
plugin-master.opt
plugin.test
plugin_load-master.opt
plugin_load.test
plugin_not_embedded-master.opt
plugin_not_embedded.test BUG#58246: INSTALL PLUGIN not secure & crashable 2010-12-02 09:13:31 +01:00
preload.test
profiling.test
ps-master.opt
ps.test
ps_1general.test
ps_2myisam.test
ps_3innodb.test
ps_4heap.test
ps_5merge.test
ps_10nestset.test
ps_11bugs.test
ps_ddl.test
ps_ddl1.test
ps_grant.test
ps_not_windows.test
query_cache.test
query_cache_28249.test
query_cache_debug.test
query_cache_merge.test
query_cache_notembedded.test
query_cache_ps_no_prot.test
query_cache_ps_ps_prot.test
query_cache_with_views.test
range.test
read_many_rows_innodb.test
read_only.test
read_only_innodb.test
rename.test
renamedb.test
repair.test
replace.test
rollback.test
round.test
row.test
rowid_order_innodb.test
schema.test
select.test
select_found.test
select_safe.test
shm-master.opt
shm.test
show_check-master.opt
show_check.test
skip_grants-master.opt
skip_grants.test
skip_log_bin-master.opt
skip_log_bin.test
skip_name_resolve-master.opt
skip_name_resolve.test
sp-big.test
sp-bugs.test Fixed bug#54375 - Error in stored procedure leaves connection 2010-11-11 10:52:51 +06:00
sp-code.test
sp-destruct.test
sp-dynamic.test
sp-error.test
sp-fib.test
sp-prelocking.test
sp-security.test
sp-threads.test
sp-ucs2.test
sp-vars.test
sp.test
sp_gis.test
sp_notembedded.test
sp_stress_case.test
sp_sync.test
sp_trans.test
sp_trans_log.test
sql_mode.test
ssl-big.test
ssl.test
ssl_8k_key-master.opt
ssl_8k_key.test
ssl_compress.test
ssl_connect.test
status-master.opt
status.test
status2.test
strict.test
strict_autoinc_1myisam.test
strict_autoinc_2innodb.test
strict_autoinc_3heap.test
subselect.test
subselect2.test
subselect3.test
subselect4.test
subselect_debug.test
subselect_gis.test
subselect_innodb.test
subselect_notembedded.test
sum_distinct-big.test
sum_distinct.test
symlink.test
synchronization.test
sysdate_is_now-master.opt
sysdate_is_now.test
system_mysql_db.test
system_mysql_db_fix30020-master.opt
system_mysql_db_fix30020.test
system_mysql_db_fix40123-master.opt
system_mysql_db_fix40123.test
system_mysql_db_fix50030-master.opt
system_mysql_db_fix50030.test
system_mysql_db_fix50117-master.opt
system_mysql_db_fix50117.test
system_mysql_db_refs.test
tablelock.test
temp_table-master.opt
temp_table.test
timezone-master.opt
timezone.test
timezone2.test
timezone3-master.opt
timezone3.test
timezone4-master.opt
timezone4.test
timezone_grant.test
trigger-compat.test
trigger-trans.test
trigger.test
trigger_notembedded.test
truncate.test
type_binary.test
type_bit.test
type_bit_innodb.test
type_blob.test Bug #52160: crash and inconsistent results when grouping 2010-10-31 19:04:38 +03:00
type_date.test
type_datetime.test
type_decimal.test
type_enum.test
type_float.test
type_nchar.test
type_newdecimal-big.test
type_newdecimal.test
type_ranges.test
type_set.test
type_time.test
type_timestamp.test
type_uint.test
type_varchar.test
type_year.test
udf-master.opt
udf.test
udf_skip_grants-master.opt
udf_skip_grants.test
union-master.opt
union.test
unsafe_binlog_innodb-master.opt
unsafe_binlog_innodb.test
update.test
upgrade.test
user_limits.test
user_var-binlog.test
user_var.test Fix for Bug#56138 "valgrind errors about overlapping memory when double-assigning same variable", 2010-11-22 09:57:59 +01:00
varbinary.test
variables-big.test Bug#58197: main.variables-big fails on windows 2010-11-15 16:17:38 +01:00
variables-notembedded-master.opt
variables-notembedded.test
variables.test Assorted post-merge fixes, clean-up, integration, compat with 5.6. 2010-11-25 03:11:05 +00:00
variables_community.test
variables_debug.test
view.test Fixed following problems: 2010-12-14 12:33:03 +03:00
view_alias.test
view_grant.test
wait_timeout.test Test wait_timeout: do not fail by SQL syntax error, use die 2010-10-19 13:54:28 +02:00
warnings-master.opt
warnings.test
warnings_engine_disabled-master.opt
warnings_engine_disabled.test
windows.test
xa.test
xml.test Bug#57279 updatexml dies with: Assertion failed: str_arg[length] == 0 2010-11-18 16:11:18 +03:00