summaryrefslogtreecommitdiff
path: root/mysql-test/t
diff options
context:
space:
mode:
Diffstat (limited to 'mysql-test/t')
-rw-r--r--mysql-test/t/alter_table.test537
-rw-r--r--mysql-test/t/alter_table_autoinc-5574.test12
-rw-r--r--mysql-test/t/alter_table_mdev539_maria.test7
-rw-r--r--mysql-test/t/alter_table_mdev539_myisam.test7
-rw-r--r--mysql-test/t/alter_table_online.test244
-rw-r--r--mysql-test/t/bad_frm_crash_5029.test3
-rw-r--r--mysql-test/t/blackhole.test9
-rw-r--r--mysql-test/t/blackhole_plugin.test2
-rw-r--r--mysql-test/t/bootstrap.test40
-rw-r--r--mysql-test/t/bug46261-master.opt1
-rw-r--r--mysql-test/t/bug46261.test16
-rw-r--r--mysql-test/t/bug58669.test2
-rw-r--r--mysql-test/t/cast.test13
-rw-r--r--mysql-test/t/change_user_notembedded.test2
-rw-r--r--mysql-test/t/comment_column.test2
-rw-r--r--mysql-test/t/comments.test30
-rw-r--r--mysql-test/t/commit.test361
-rw-r--r--mysql-test/t/connect.test35
-rw-r--r--mysql-test/t/create-big.test13
-rw-r--r--mysql-test/t/create.test48
-rw-r--r--mysql-test/t/create_or_replace-master.opt1
-rw-r--r--mysql-test/t/create_or_replace.test400
-rw-r--r--mysql-test/t/create_or_replace2.test35
-rw-r--r--mysql-test/t/ctype_big5.test102
-rw-r--r--mysql-test/t/ctype_binary.test17
-rw-r--r--mysql-test/t/ctype_collate.test53
-rw-r--r--mysql-test/t/ctype_cp1250_ch.test31
-rw-r--r--mysql-test/t/ctype_cp932_binlog_stm.test36
-rw-r--r--mysql-test/t/ctype_create.test36
-rw-r--r--mysql-test/t/ctype_eucjpms.test46
-rw-r--r--mysql-test/t/ctype_euckr.test23
-rw-r--r--mysql-test/t/ctype_gb2312.test36
-rw-r--r--mysql-test/t/ctype_gbk.test58
-rw-r--r--mysql-test/t/ctype_latin1.test98
-rw-r--r--mysql-test/t/ctype_latin1_de.test37
-rw-r--r--mysql-test/t/ctype_latin2.test24
-rw-r--r--mysql-test/t/ctype_latin2_ch.test210
-rw-r--r--mysql-test/t/ctype_ldml-master.opt2
-rw-r--r--mysql-test/t/ctype_ldml.test218
-rw-r--r--mysql-test/t/ctype_like_range.test32
-rw-r--r--mysql-test/t/ctype_many.test12
-rw-r--r--mysql-test/t/ctype_partitions.test29
-rw-r--r--mysql-test/t/ctype_sjis.test40
-rw-r--r--mysql-test/t/ctype_swe7.test19
-rw-r--r--mysql-test/t/ctype_tis620.test27
-rw-r--r--mysql-test/t/ctype_uca.test333
-rw-r--r--mysql-test/t/ctype_ucs.test163
-rw-r--r--mysql-test/t/ctype_ucs2_def.test2
-rw-r--r--mysql-test/t/ctype_ucs2_query_cache.test2
-rw-r--r--mysql-test/t/ctype_ujis.test48
-rw-r--r--mysql-test/t/ctype_upgrade.test198
-rw-r--r--mysql-test/t/ctype_utf16.test65
-rw-r--r--mysql-test/t/ctype_utf16_def.test1
-rw-r--r--mysql-test/t/ctype_utf16_uca.test213
-rw-r--r--mysql-test/t/ctype_utf16le.test746
-rw-r--r--mysql-test/t/ctype_utf32.test77
-rw-r--r--mysql-test/t/ctype_utf32_uca.test211
-rw-r--r--mysql-test/t/ctype_utf8.test205
-rw-r--r--mysql-test/t/ctype_utf8mb4.test74
-rw-r--r--mysql-test/t/ctype_utf8mb4_uca.test72
-rw-r--r--mysql-test/t/default.test43
-rw-r--r--mysql-test/t/default_storage_engine.test4
-rw-r--r--mysql-test/t/delayed.test4
-rw-r--r--mysql-test/t/delete_returning.test172
-rw-r--r--mysql-test/t/delete_returning_grant.test78
-rw-r--r--mysql-test/t/derived.test35
-rw-r--r--mysql-test/t/drop.test48
-rw-r--r--mysql-test/t/dyncol.test291
-rw-r--r--mysql-test/t/empty_server_name-8224.test4
-rw-r--r--mysql-test/t/engine_error_in_alter-8453.test11
-rw-r--r--mysql-test/t/events_1.test21
-rw-r--r--mysql-test/t/events_bugs.test12
-rw-r--r--mysql-test/t/events_logs_tests.test2
-rw-r--r--mysql-test/t/events_restart.test36
-rw-r--r--mysql-test/t/explain.test16
-rw-r--r--mysql-test/t/explain_non_select.test252
-rw-r--r--mysql-test/t/explain_slowquerylog-master.opt1
-rw-r--r--mysql-test/t/explain_slowquerylog.test63
-rw-r--r--mysql-test/t/ext_key_noPK_6794.test15
-rw-r--r--mysql-test/t/features.test19
-rw-r--r--mysql-test/t/file_contents.test6
-rw-r--r--mysql-test/t/filesort_debug.test2
-rw-r--r--mysql-test/t/flush-innodb-notembedded.test69
-rw-r--r--mysql-test/t/flush-innodb.test471
-rw-r--r--mysql-test/t/flush.test8
-rw-r--r--mysql-test/t/flush_read_lock.test42
-rw-r--r--mysql-test/t/fulltext.test15
-rw-r--r--mysql-test/t/func_concat.test97
-rw-r--r--mysql-test/t/func_crypt.test24
-rw-r--r--mysql-test/t/func_des_encrypt.test2
-rw-r--r--mysql-test/t/func_encrypt.test2
-rw-r--r--mysql-test/t/func_encrypt_nossl.test2
-rw-r--r--mysql-test/t/func_encrypt_ucs2.test2
-rw-r--r--mysql-test/t/func_group_innodb.test7
-rw-r--r--mysql-test/t/func_in.test21
-rw-r--r--mysql-test/t/func_like.test10
-rw-r--r--mysql-test/t/func_math.test18
-rw-r--r--mysql-test/t/func_misc.test515
-rw-r--r--mysql-test/t/func_regexp.test12
-rw-r--r--mysql-test/t/func_regexp_pcre.test451
-rw-r--r--mysql-test/t/func_regexp_pcre_debug.test6
-rw-r--r--mysql-test/t/func_str.test198
-rw-r--r--mysql-test/t/func_system.test6
-rw-r--r--mysql-test/t/func_test.test14
-rw-r--r--mysql-test/t/func_time.test155
-rw-r--r--mysql-test/t/func_weight_string.test113
-rw-r--r--mysql-test/t/function_defaults.test21
-rw-r--r--mysql-test/t/function_defaults_innodb.test24
-rw-r--r--mysql-test/t/function_defaults_notembedded.test18
-rw-r--r--mysql-test/t/get_diagnostics.test851
-rw-r--r--mysql-test/t/gis-alter_table_online.test82
-rw-r--r--mysql-test/t/gis-debug.test6
-rw-r--r--mysql-test/t/gis-precise.test28
-rw-r--r--mysql-test/t/gis-rt-precise.test22
-rw-r--r--mysql-test/t/gis.test54
-rw-r--r--mysql-test/t/grant.test61
-rw-r--r--mysql-test/t/grant2.test364
-rw-r--r--mysql-test/t/grant4.test63
-rw-r--r--mysql-test/t/grant5.test25
-rw-r--r--mysql-test/t/grant_4332.test120
-rw-r--r--mysql-test/t/grant_explain_non_select.test258
-rw-r--r--mysql-test/t/grant_lowercase.test4
-rw-r--r--mysql-test/t/group_by.test65
-rw-r--r--mysql-test/t/group_by_innodb.test69
-rw-r--r--mysql-test/t/group_min_max.test62
-rw-r--r--mysql-test/t/having.test34
-rw-r--r--mysql-test/t/help.test6
-rw-r--r--mysql-test/t/host_cache_size_functionality.test185
-rw-r--r--mysql-test/t/huge_frm-6224.test20
-rw-r--r--mysql-test/t/index_merge_myisam.test2
-rw-r--r--mysql-test/t/information_schema-big.test4
-rw-r--r--mysql-test/t/information_schema.test60
-rw-r--r--mysql-test/t/information_schema_all_engines-master.opt8
-rw-r--r--mysql-test/t/information_schema_all_engines.test3
-rw-r--r--mysql-test/t/information_schema_stats.test46
-rw-r--r--mysql-test/t/init_file.opt (renamed from mysql-test/t/init_file-master.opt)0
-rw-r--r--mysql-test/t/init_file_longline_3816.opt1
-rw-r--r--mysql-test/t/init_file_longline_3816.test5
-rw-r--r--mysql-test/t/init_file_set_password-7656.test26
-rw-r--r--mysql-test/t/innodb_ext_key.test1
-rw-r--r--mysql-test/t/innodb_mrr_cpk.test1
-rw-r--r--mysql-test/t/innodb_mysql_lock-master.opt1
-rw-r--r--mysql-test/t/innodb_mysql_lock.test7
-rw-r--r--mysql-test/t/innodb_mysql_lock2.test55
-rw-r--r--mysql-test/t/innodb_mysql_sync.test516
-rw-r--r--mysql-test/t/insert.test39
-rw-r--r--mysql-test/t/ipv4_and_ipv6.opt1
-rw-r--r--mysql-test/t/ipv4_and_ipv6.test13
-rw-r--r--mysql-test/t/join.test41
-rw-r--r--mysql-test/t/join_cache.test82
-rw-r--r--mysql-test/t/key.test20
-rw-r--r--mysql-test/t/key_cache.test38
-rw-r--r--mysql-test/t/keywords.test2
-rw-r--r--mysql-test/t/kill.test15
-rw-r--r--mysql-test/t/kill_processlist-6619.test23
-rw-r--r--mysql-test/t/kill_query-6728.test14
-rw-r--r--mysql-test/t/limit_rows_examined.test2
-rw-r--r--mysql-test/t/locale.test56
-rw-r--r--mysql-test/t/lock_multi.test2
-rw-r--r--mysql-test/t/lock_sync.test170
-rw-r--r--mysql-test/t/log_errchk.test2
-rw-r--r--mysql-test/t/log_state-master.opt2
-rw-r--r--mysql-test/t/log_state.test83
-rw-r--r--mysql-test/t/log_state_bug33693-master.opt2
-rw-r--r--mysql-test/t/log_tables.test18
-rw-r--r--mysql-test/t/log_tables_upgrade.test9
-rw-r--r--mysql-test/t/lowercase_fs_off.test8
-rw-r--r--mysql-test/t/lowercase_table.test13
-rw-r--r--mysql-test/t/lowercase_table2.test33
-rw-r--r--mysql-test/t/lowercase_table4.test4
-rw-r--r--mysql-test/t/lowercase_table5.test20
-rw-r--r--mysql-test/t/mdev-504.test80
-rw-r--r--mysql-test/t/mdev13607.test60
-rw-r--r--mysql-test/t/mdl_sync.test332
-rw-r--r--mysql-test/t/merge.test85
-rw-r--r--mysql-test/t/multi_update.test50
-rw-r--r--mysql-test/t/myisam-metadata.test59
-rw-r--r--mysql-test/t/myisam-system.test11
-rw-r--r--mysql-test/t/myisam.test2
-rw-r--r--mysql-test/t/myisam_debug.test13
-rw-r--r--mysql-test/t/myisam_explain_non_select_all.test21
-rw-r--r--mysql-test/t/myisam_optimize.test21
-rw-r--r--mysql-test/t/myisampack.test12
-rw-r--r--mysql-test/t/mysql.test10
-rw-r--r--mysql-test/t/mysql5613mysql.test120
-rw-r--r--mysql-test/t/mysql_client_test-master.opt4
-rw-r--r--mysql-test/t/mysql_client_test.test2
-rw-r--r--mysql-test/t/mysql_client_test_comp-master.opt2
-rw-r--r--mysql-test/t/mysql_client_test_comp.test20
-rw-r--r--mysql-test/t/mysql_client_test_nonblock-master.opt3
-rw-r--r--mysql-test/t/mysql_client_test_nonblock.test1
-rw-r--r--mysql-test/t/mysql_upgrade-6984.opt1
-rw-r--r--mysql-test/t/mysql_upgrade-6984.test23
-rw-r--r--mysql-test/t/mysql_upgrade.test61
-rw-r--r--mysql-test/t/mysql_upgrade_no_innodb.test6
-rw-r--r--mysql-test/t/mysql_upgrade_ssl.test1
-rw-r--r--mysql-test/t/mysqlbinlog.test29
-rw-r--r--mysql-test/t/mysqlcheck.test27
-rw-r--r--mysql-test/t/mysqld--help.test15
-rw-r--r--mysql-test/t/mysqldump-max.test2
-rw-r--r--mysql-test/t/mysqldump.test5
-rw-r--r--mysql-test/t/mysqlshow.test2
-rw-r--r--mysql-test/t/mysqltest.test8
-rw-r--r--mysql-test/t/no-threads-master.opt2
-rw-r--r--mysql-test/t/not_embedded_server.test111
-rw-r--r--mysql-test/t/not_partition.test22
-rw-r--r--mysql-test/t/null.test13
-rw-r--r--mysql-test/t/old-mode.test50
-rw-r--r--mysql-test/t/openssl_1.test16
-rw-r--r--mysql-test/t/openssl_6975.test1
-rw-r--r--mysql-test/t/order_by.test213
-rw-r--r--mysql-test/t/order_by_sortkey.test64
-rw-r--r--mysql-test/t/order_by_zerolength-4285.test8
-rw-r--r--mysql-test/t/parser.test2
-rw-r--r--mysql-test/t/parser_not_embedded.test12
-rw-r--r--mysql-test/t/partition.test83
-rw-r--r--mysql-test/t/partition_alter.test66
-rw-r--r--mysql-test/t/partition_binlog.test2
-rw-r--r--mysql-test/t/partition_debug_sync.test71
-rw-r--r--mysql-test/t/partition_disabled.test27
-rw-r--r--mysql-test/t/partition_error.test57
-rw-r--r--mysql-test/t/partition_exchange.test517
-rw-r--r--mysql-test/t/partition_explicit_prune.test860
-rw-r--r--mysql-test/t/partition_innodb.test109
-rw-r--r--mysql-test/t/partition_innodb_plugin.test11
-rw-r--r--mysql-test/t/partition_mgm_err.test2
-rw-r--r--mysql-test/t/partition_myisam.test144
-rw-r--r--mysql-test/t/partition_not_blackhole.test5
-rw-r--r--mysql-test/t/partition_not_windows.test2
-rw-r--r--mysql-test/t/partition_pruning.test20
-rw-r--r--mysql-test/t/partition_symlink.test42
-rw-r--r--mysql-test/t/partition_truncate.test2
-rw-r--r--mysql-test/t/plugin.test51
-rw-r--r--mysql-test/t/plugin_auth.test26
-rw-r--r--mysql-test/t/plugin_auth_qa_1.test26
-rw-r--r--mysql-test/t/plugin_auth_qa_2-master.opt2
-rw-r--r--mysql-test/t/plugin_auth_qa_3-master.opt2
-rw-r--r--mysql-test/t/plugin_load-master.opt2
-rw-r--r--mysql-test/t/plugin_load.opt6
-rw-r--r--mysql-test/t/plugin_load.test14
-rw-r--r--mysql-test/t/plugin_load_option.opt (renamed from mysql-test/t/plugin_load_option-master.opt)2
-rw-r--r--mysql-test/t/ps.test6
-rw-r--r--mysql-test/t/ps_1general.test5
-rw-r--r--mysql-test/t/ps_ddl.test209
-rw-r--r--mysql-test/t/query_cache.test34
-rw-r--r--mysql-test/t/query_cache_ps_no_prot.test7
-rw-r--r--mysql-test/t/range.test68
-rw-r--r--mysql-test/t/range_vs_index_merge.test56
-rw-r--r--mysql-test/t/read_only.test59
-rw-r--r--mysql-test/t/rename.test10
-rw-r--r--mysql-test/t/repair.test27
-rw-r--r--mysql-test/t/rpl_mysqldump_slave.test53
-rw-r--r--mysql-test/t/select.test71
-rw-r--r--mysql-test/t/select_found.test92
-rw-r--r--mysql-test/t/selectivity.test1048
-rw-r--r--mysql-test/t/selectivity_innodb.test143
-rw-r--r--mysql-test/t/selectivity_no_engine.test238
-rw-r--r--mysql-test/t/servers.test8
-rw-r--r--mysql-test/t/show_check-master.opt2
-rw-r--r--mysql-test/t/show_check.test29
-rw-r--r--mysql-test/t/show_explain.test1204
-rw-r--r--mysql-test/t/show_explain_non_select.test78
-rw-r--r--mysql-test/t/show_explain_ps.test51
-rw-r--r--mysql-test/t/show_grants_with_plugin-7985.test161
-rw-r--r--mysql-test/t/shutdown.test32
-rw-r--r--mysql-test/t/sighup-6580.test10
-rw-r--r--mysql-test/t/signal.test11
-rw-r--r--mysql-test/t/skip_grants.test2
-rw-r--r--mysql-test/t/sp-bugs.test9
-rw-r--r--mysql-test/t/sp-bugs2.test29
-rw-r--r--mysql-test/t/sp-destruct.test17
-rw-r--r--mysql-test/t/sp-error.test970
-rw-r--r--mysql-test/t/sp-prelocking.test30
-rw-r--r--mysql-test/t/sp-security.test41
-rw-r--r--mysql-test/t/sp.test124
-rw-r--r--mysql-test/t/sp_notembedded.test31
-rw-r--r--mysql-test/t/sp_trans_log.test12
-rw-r--r--mysql-test/t/ssl.test19
-rw-r--r--mysql-test/t/ssl_8k_key.test3
-rw-r--r--mysql-test/t/ssl_ca.test16
-rw-r--r--mysql-test/t/ssl_cipher.test2
-rw-r--r--mysql-test/t/ssl_compress.test6
-rw-r--r--mysql-test/t/ssl_crl-master.opt4
-rw-r--r--mysql-test/t/ssl_crl.test16
-rw-r--r--mysql-test/t/ssl_crl_clients-master.opt4
-rw-r--r--mysql-test/t/ssl_crl_clients.test41
-rw-r--r--mysql-test/t/ssl_crl_clients_valid-master.opt4
-rw-r--r--mysql-test/t/ssl_crl_clients_valid.test23
-rw-r--r--mysql-test/t/ssl_crl_clrpath-master.opt4
-rw-r--r--mysql-test/t/ssl_crl_clrpath.test16
-rw-r--r--mysql-test/t/ssl_timeout.test20
-rw-r--r--mysql-test/t/stat_tables-enospc.test23
-rw-r--r--mysql-test/t/stat_tables.test308
-rw-r--r--mysql-test/t/stat_tables_disabled.test78
-rw-r--r--mysql-test/t/stat_tables_innodb.test12
-rw-r--r--mysql-test/t/stat_tables_par.test278
-rw-r--r--mysql-test/t/stat_tables_par_innodb.test12
-rw-r--r--mysql-test/t/stat_tables_partition.test17
-rw-r--r--mysql-test/t/stat_tables_rbr.test31
-rw-r--r--mysql-test/t/stat_tables_repl.test58
-rw-r--r--mysql-test/t/statistics.test739
-rw-r--r--mysql-test/t/statistics_index_crash-7362.test30
-rw-r--r--mysql-test/t/str_to_datetime_457.test26
-rw-r--r--mysql-test/t/strict.test20
-rw-r--r--mysql-test/t/subselect.test40
-rw-r--r--mysql-test/t/subselect4.test15
-rw-r--r--mysql-test/t/subselect_cache.test4
-rw-r--r--mysql-test/t/subselect_exists2in.test832
-rw-r--r--mysql-test/t/subselect_exists2in_costmat.test83
-rw-r--r--mysql-test/t/subselect_innodb.test101
-rw-r--r--mysql-test/t/subselect_mat_cost-master.opt2
-rw-r--r--mysql-test/t/subselect_no_exists_to_in.test11
-rw-r--r--mysql-test/t/subselect_sj.test8
-rw-r--r--mysql-test/t/subselect_sj2.test39
-rw-r--r--mysql-test/t/subselect_sj_mat.test113
-rw-r--r--mysql-test/t/symlink-myisam-11902.test4
-rw-r--r--mysql-test/t/system_mysql_db_fix40123.test6
-rw-r--r--mysql-test/t/system_mysql_db_fix50030.test3
-rw-r--r--mysql-test/t/system_mysql_db_fix50117.test6
-rw-r--r--mysql-test/t/table_options-5867.test30
-rw-r--r--mysql-test/t/tc_heuristic_recover.test106
-rw-r--r--mysql-test/t/temp_table.test72
-rw-r--r--mysql-test/t/temporal_literal.test346
-rw-r--r--mysql-test/t/timezone2.test2
-rw-r--r--mysql-test/t/tmp_table_count-7586.test56
-rw-r--r--mysql-test/t/trans_read_only-master.opt1
-rw-r--r--mysql-test/t/trans_read_only.test50
-rw-r--r--mysql-test/t/trigger.test2
-rw-r--r--mysql-test/t/truncate_badse.test15
-rw-r--r--mysql-test/t/truncate_coverage.test4
-rw-r--r--mysql-test/t/type_binary.test26
-rw-r--r--mysql-test/t/type_bit.test4
-rw-r--r--mysql-test/t/type_bit_innodb.test9
-rw-r--r--mysql-test/t/type_blob.test4
-rw-r--r--mysql-test/t/type_date.test11
-rw-r--r--mysql-test/t/type_datetime.test13
-rw-r--r--mysql-test/t/type_enum.test121
-rw-r--r--mysql-test/t/type_float.test54
-rw-r--r--mysql-test/t/type_newdecimal.test41
-rw-r--r--mysql-test/t/type_set.test90
-rw-r--r--mysql-test/t/type_temporal_mysql56.test23
-rw-r--r--mysql-test/t/type_time.test26
-rw-r--r--mysql-test/t/type_time_6065.test200
-rw-r--r--mysql-test/t/type_timestamp.test85
-rw-r--r--mysql-test/t/type_timestamp_hires.test15
-rw-r--r--mysql-test/t/type_uint.test25
-rw-r--r--mysql-test/t/type_varchar.test26
-rw-r--r--mysql-test/t/update.test22
-rw-r--r--mysql-test/t/update_innodb.test13
-rw-r--r--mysql-test/t/upgrade.test10
-rw-r--r--mysql-test/t/user_var.test51
-rw-r--r--mysql-test/t/variables.test30
-rw-r--r--mysql-test/t/view.test302
-rw-r--r--mysql-test/t/view_alias.test9
-rw-r--r--mysql-test/t/view_grant.test162
-rw-r--r--mysql-test/t/xa_binlog.test4
-rw-r--r--mysql-test/t/xml.test67
357 files changed, 24965 insertions, 1670 deletions
diff --git a/mysql-test/t/alter_table.test b/mysql-test/t/alter_table.test
index ee9616e233d..8fcc7d044e5 100644
--- a/mysql-test/t/alter_table.test
+++ b/mysql-test/t/alter_table.test
@@ -1,3 +1,8 @@
+if (`select plugin_auth_version < "5.6.26" from information_schema.plugins where plugin_name='innodb'`)
+{
+ --skip Not fixed in XtraDB below 5.6.26
+}
+--source include/have_innodb.inc
#
# Test of alter table
#
@@ -1215,6 +1220,24 @@ ALTER TABLE db1.t1 ADD baz INT;
DROP DATABASE db1;
+--echo # Additional coverage for refactoring which is made as part
+--echo # of fix for bug #27480 "Extend CREATE TEMPORARY TABLES privilege
+--echo # to allow temp table operations".
+--echo #
+--echo # At some point the below test case failed on assertion.
+
+--disable_warnings
+DROP TABLE IF EXISTS t1;
+--enable_warnings
+
+CREATE TEMPORARY TABLE t1 (i int) ENGINE=MyISAM;
+
+--error ER_ILLEGAL_HA
+ALTER TABLE t1 DISCARD TABLESPACE;
+
+DROP TABLE t1;
+
+
--echo #
--echo # Bug#11938039 RE-EXECUTION OF FRM-ONLY ALTER TABLE WITH RENAME
--echo # CLAUSE FAILS OR ABORTS SERVER.
@@ -1272,3 +1295,517 @@ ALTER COLUMN `consultant_id` DROP DEFAULT,
MODIFY COLUMN `consultant_id` BIGINT;
SHOW CREATE TABLE t1;
DROP TABLE t1;
+
+#
+# Test of ALTER TABLE IF [NOT] EXISTS
+#
+
+CREATE TABLE t1 (
+ id INT(11) NOT NULL,
+ x_param INT(11) DEFAULT NULL,
+ PRIMARY KEY (id)
+) ENGINE=MYISAM;
+
+ALTER TABLE t1 ADD COLUMN IF NOT EXISTS id INT,
+ ADD COLUMN IF NOT EXISTS lol INT AFTER id;
+ALTER TABLE t1 ADD COLUMN IF NOT EXISTS lol INT AFTER id;
+ALTER TABLE t1 DROP COLUMN IF EXISTS lol;
+ALTER TABLE t1 DROP COLUMN IF EXISTS lol;
+
+ALTER TABLE t1 ADD KEY IF NOT EXISTS x_param(x_param);
+ALTER TABLE t1 ADD KEY IF NOT EXISTS x_param(x_param);
+ALTER TABLE t1 MODIFY IF EXISTS lol INT;
+
+DROP INDEX IF EXISTS x_param ON t1;
+DROP INDEX IF EXISTS x_param ON t1;
+CREATE INDEX IF NOT EXISTS x_param1 ON t1(x_param);
+CREATE INDEX IF NOT EXISTS x_param1 ON t1(x_param);
+SHOW CREATE TABLE t1;
+DROP TABLE t1;
+
+CREATE TABLE t1 (
+ id INT(11) NOT NULL,
+ x_param INT(11) DEFAULT NULL,
+ PRIMARY KEY (id)
+) ENGINE=INNODB;
+
+CREATE TABLE t2 (
+ id INT(11) NOT NULL) ENGINE=INNODB;
+
+ALTER TABLE t1 ADD COLUMN IF NOT EXISTS id INT,
+ ADD COLUMN IF NOT EXISTS lol INT AFTER id;
+ALTER TABLE t1 ADD COLUMN IF NOT EXISTS lol INT AFTER id;
+ALTER TABLE t1 DROP COLUMN IF EXISTS lol;
+ALTER TABLE t1 DROP COLUMN IF EXISTS lol;
+
+ALTER TABLE t1 ADD KEY IF NOT EXISTS x_param(x_param);
+ALTER TABLE t1 ADD KEY IF NOT EXISTS x_param(x_param);
+ALTER TABLE t1 MODIFY IF EXISTS lol INT;
+
+DROP INDEX IF EXISTS x_param ON t1;
+DROP INDEX IF EXISTS x_param ON t1;
+CREATE INDEX IF NOT EXISTS x_param1 ON t1(x_param);
+CREATE INDEX IF NOT EXISTS x_param1 ON t1(x_param);
+SHOW CREATE TABLE t1;
+
+ALTER TABLE t2 ADD FOREIGN KEY IF NOT EXISTS fk(id) REFERENCES t1(id);
+ALTER TABLE t2 ADD FOREIGN KEY IF NOT EXISTS fk(id) REFERENCES t1(id);
+ALTER TABLE t2 DROP FOREIGN KEY IF EXISTS fk;
+ALTER TABLE t2 DROP FOREIGN KEY IF EXISTS fk;
+SHOW CREATE TABLE t2;
+ALTER TABLE t2 ADD FOREIGN KEY (id) REFERENCES t1(id);
+ALTER TABLE t2 ADD FOREIGN KEY IF NOT EXISTS t2_ibfk_1(id) REFERENCES t1(id);
+ALTER TABLE t2 DROP FOREIGN KEY IF EXISTS t2_ibfk_1;
+ALTER TABLE t2 DROP FOREIGN KEY IF EXISTS t2_ibfk_1;
+SHOW CREATE TABLE t2;
+
+DROP TABLE t2;
+CREATE TABLE t2 (
+ id INT(11) NOT NULL);
+ALTER TABLE t2 ADD COLUMN a INT, ADD COLUMN IF NOT EXISTS a INT;
+ALTER TABLE t2 ADD KEY k_id(id), ADD KEY IF NOT EXISTS k_id(id);
+SHOW CREATE TABLE t2;
+ALTER TABLE t2 DROP KEY k_id, DROP KEY IF EXISTS k_id;
+ALTER TABLE t2 DROP COLUMN a, DROP COLUMN IF EXISTS a;
+SHOW CREATE TABLE t2;
+
+DROP TABLE t2;
+DROP TABLE t1;
+
+CREATE TABLE t1 (
+ `transaction_id` int(11) NOT NULL DEFAULT '0',
+ KEY `transaction_id` (`transaction_id`));
+ALTER TABLE t1 DROP KEY IF EXISTS transaction_id, ADD PRIMARY KEY IF NOT EXISTS (transaction_id);
+SHOW CREATE TABLE t1;
+
+DROP TABLE t1;
+
+--echo # Bug#11748057 (formerly known as 34972): ALTER TABLE statement doesn't
+--echo # identify correct column name.
+--echo #
+
+CREATE TABLE t1 (c1 int unsigned , c2 char(100) not null default '');
+ALTER TABLE t1 ADD c3 char(16) NOT NULL DEFAULT '' AFTER c2,
+ MODIFY c2 char(100) NOT NULL DEFAULT '' AFTER c1;
+SHOW CREATE TABLE t1;
+DROP TABLE t1;
+
+--echo #
+--echo # WL#5534 Online ALTER, Phase 1
+--echo #
+
+--echo # Single thread tests.
+--echo # See innodb_mysql_sync.test for multi thread tests.
+
+--disable_warnings
+DROP TABLE IF EXISTS t1;
+--enable_warnings
+
+CREATE TABLE t1(a INT PRIMARY KEY, b INT) engine=InnoDB;
+CREATE TABLE m1(a INT PRIMARY KEY, b INT) engine=MyISAM;
+INSERT INTO t1 VALUES (1,1), (2,2);
+INSERT INTO m1 VALUES (1,1), (2,2);
+
+--echo #
+--echo # 1: Test ALGORITHM keyword
+--echo #
+
+--echo # --enable_info allows us to see how many rows were updated
+--echo # by ALTER TABLE. in-place will show 0 rows, while copy > 0.
+
+--enable_info
+ALTER TABLE t1 ADD INDEX i1(b);
+ALTER TABLE t1 ADD INDEX i2(b), ALGORITHM= DEFAULT;
+ALTER TABLE t1 ADD INDEX i3(b), ALGORITHM= COPY;
+ALTER TABLE t1 ADD INDEX i4(b), ALGORITHM= INPLACE;
+--error ER_UNKNOWN_ALTER_ALGORITHM
+ALTER TABLE t1 ADD INDEX i5(b), ALGORITHM= INVALID;
+
+ALTER TABLE m1 ENABLE KEYS;
+ALTER TABLE m1 ENABLE KEYS, ALGORITHM= DEFAULT;
+ALTER TABLE m1 ENABLE KEYS, ALGORITHM= COPY;
+ALTER TABLE m1 ENABLE KEYS, ALGORITHM= INPLACE;
+--disable_info
+
+ALTER TABLE t1 DROP INDEX i1, DROP INDEX i2, DROP INDEX i3, DROP INDEX i4;
+
+--echo #
+--echo # 2: Test ALGORITHM + old_alter_table
+--echo #
+
+--enable_info
+SET SESSION old_alter_table= 1;
+ALTER TABLE t1 ADD INDEX i1(b);
+ALTER TABLE t1 ADD INDEX i2(b), ALGORITHM= DEFAULT;
+ALTER TABLE t1 ADD INDEX i3(b), ALGORITHM= COPY;
+ALTER TABLE t1 ADD INDEX i4(b), ALGORITHM= INPLACE;
+SET SESSION old_alter_table= 0;
+--disable_info
+
+ALTER TABLE t1 DROP INDEX i1, DROP INDEX i2, DROP INDEX i3, DROP INDEX i4;
+
+--echo #
+--echo # 3: Test unsupported in-place operation
+--echo #
+
+ALTER TABLE t1 ADD COLUMN (c1 INT);
+ALTER TABLE t1 ADD COLUMN (c2 INT), ALGORITHM= DEFAULT;
+ALTER TABLE t1 ADD COLUMN (c3 INT), ALGORITHM= COPY;
+ALTER TABLE t1 ADD COLUMN (c4 INT), ALGORITHM= INPLACE;
+
+ALTER TABLE t1 DROP COLUMN c1, DROP COLUMN c2, DROP COLUMN c3, DROP COLUMN c4;
+
+--echo #
+--echo # 4: Test LOCK keyword
+--echo #
+
+--enable_info
+ALTER TABLE t1 ADD INDEX i1(b), LOCK= DEFAULT;
+ALTER TABLE t1 ADD INDEX i2(b), LOCK= NONE;
+ALTER TABLE t1 ADD INDEX i3(b), LOCK= SHARED;
+ALTER TABLE t1 ADD INDEX i4(b), LOCK= EXCLUSIVE;
+--error ER_UNKNOWN_ALTER_LOCK
+ALTER TABLE t1 ADD INDEX i5(b), LOCK= INVALID;
+--disable_info
+
+ALTER TABLE m1 ENABLE KEYS, LOCK= DEFAULT;
+--error ER_ALTER_OPERATION_NOT_SUPPORTED
+ALTER TABLE m1 ENABLE KEYS, LOCK= NONE;
+--error ER_ALTER_OPERATION_NOT_SUPPORTED
+ALTER TABLE m1 ENABLE KEYS, LOCK= SHARED;
+ALTER TABLE m1 ENABLE KEYS, LOCK= EXCLUSIVE;
+
+ALTER TABLE t1 DROP INDEX i1, DROP INDEX i2, DROP INDEX i3, DROP INDEX i4;
+
+--echo #
+--echo # 5: Test ALGORITHM + LOCK
+--echo #
+
+--enable_info
+ALTER TABLE t1 ADD INDEX i1(b), ALGORITHM= INPLACE, LOCK= NONE;
+ALTER TABLE t1 ADD INDEX i2(b), ALGORITHM= INPLACE, LOCK= SHARED;
+ALTER TABLE t1 ADD INDEX i3(b), ALGORITHM= INPLACE, LOCK= EXCLUSIVE;
+--error ER_ALTER_OPERATION_NOT_SUPPORTED_REASON
+ALTER TABLE t1 ADD INDEX i4(b), ALGORITHM= COPY, LOCK= NONE;
+ALTER TABLE t1 ADD INDEX i5(b), ALGORITHM= COPY, LOCK= SHARED;
+ALTER TABLE t1 ADD INDEX i6(b), ALGORITHM= COPY, LOCK= EXCLUSIVE;
+
+--error ER_ALTER_OPERATION_NOT_SUPPORTED
+ALTER TABLE m1 ENABLE KEYS, ALGORITHM= INPLACE, LOCK= NONE;
+--error ER_ALTER_OPERATION_NOT_SUPPORTED
+ALTER TABLE m1 ENABLE KEYS, ALGORITHM= INPLACE, LOCK= SHARED;
+ALTER TABLE m1 ENABLE KEYS, ALGORITHM= INPLACE, LOCK= EXCLUSIVE;
+--error ER_ALTER_OPERATION_NOT_SUPPORTED_REASON
+ALTER TABLE m1 ENABLE KEYS, ALGORITHM= COPY, LOCK= NONE;
+# This works because the lock will be SNW for the copy phase.
+# It will still require exclusive lock for actually enabling keys.
+ALTER TABLE m1 ENABLE KEYS, ALGORITHM= COPY, LOCK= SHARED;
+ALTER TABLE m1 ENABLE KEYS, ALGORITHM= COPY, LOCK= EXCLUSIVE;
+--disable_info
+
+DROP TABLE t1, m1;
+
+--echo #
+--echo # 6: Possible deadlock involving thr_lock.c
+--echo #
+
+CREATE TABLE t1(a INT PRIMARY KEY, b INT);
+INSERT INTO t1 VALUES (1,1), (2,2);
+
+START TRANSACTION;
+INSERT INTO t1 VALUES (3,3);
+
+--echo # Connection con1
+connect (con1, localhost, root);
+--echo # Sending:
+--send ALTER TABLE t1 DISABLE KEYS
+
+--echo # Connection default
+connection default;
+--echo # Waiting until ALTER TABLE is blocked.
+let $wait_condition=
+ SELECT COUNT(*) = 1 FROM information_schema.processlist
+ WHERE state = "Waiting for table metadata lock" AND
+ info = "ALTER TABLE t1 DISABLE KEYS";
+--source include/wait_condition.inc
+UPDATE t1 SET b = 4;
+COMMIT;
+
+--echo # Connection con1
+connection con1;
+--echo # Reaping: ALTER TABLE t1 DISABLE KEYS
+--reap
+disconnect con1;
+--source include/wait_until_disconnected.inc
+
+--echo # Connection default
+connection default;
+DROP TABLE t1;
+
+--echo #
+--echo # 7: Which operations require copy and which can be done in-place?
+--echo #
+--echo # Test which ALTER TABLE operations are done in-place and
+--echo # which operations are done using temporary table copy.
+--echo #
+--echo # --enable_info allows us to see how many rows were updated
+--echo # by ALTER TABLE. in-place will show 0 rows, while copy > 0.
+--echo #
+
+--disable_warnings
+DROP TABLE IF EXISTS ti1, ti2, ti3, tm1, tm2, tm3;
+--enable_warnings
+
+--echo # Single operation tests
+
+CREATE TABLE ti1(a INT NOT NULL, b INT, c INT) engine=InnoDB;
+CREATE TABLE tm1(a INT NOT NULL, b INT, c INT) engine=MyISAM;
+CREATE TABLE ti2(a INT PRIMARY KEY AUTO_INCREMENT, b INT, c INT) engine=InnoDB;
+CREATE TABLE tm2(a INT PRIMARY KEY AUTO_INCREMENT, b INT, c INT) engine=MyISAM;
+INSERT INTO ti1 VALUES (1,1,1), (2,2,2);
+INSERT INTO ti2 VALUES (1,1,1), (2,2,2);
+INSERT INTO tm1 VALUES (1,1,1), (2,2,2);
+INSERT INTO tm2 VALUES (1,1,1), (2,2,2);
+
+--enable_info
+ALTER TABLE ti1;
+ALTER TABLE tm1;
+
+ALTER TABLE ti1 ADD COLUMN d VARCHAR(200);
+ALTER TABLE tm1 ADD COLUMN d VARCHAR(200);
+ALTER TABLE ti1 ADD COLUMN d2 VARCHAR(200);
+ALTER TABLE tm1 ADD COLUMN d2 VARCHAR(200);
+ALTER TABLE ti1 ADD COLUMN e ENUM('a', 'b') FIRST;
+ALTER TABLE tm1 ADD COLUMN e ENUM('a', 'b') FIRST;
+ALTER TABLE ti1 ADD COLUMN f INT AFTER a;
+ALTER TABLE tm1 ADD COLUMN f INT AFTER a;
+
+ALTER TABLE ti1 ADD INDEX ii1(b);
+ALTER TABLE tm1 ADD INDEX im1(b);
+ALTER TABLE ti1 ADD UNIQUE INDEX ii2 (c);
+ALTER TABLE tm1 ADD UNIQUE INDEX im2 (c);
+ALTER TABLE ti1 ADD FULLTEXT INDEX ii3 (d);
+ALTER TABLE tm1 ADD FULLTEXT INDEX im3 (d);
+ALTER TABLE ti1 ADD FULLTEXT INDEX ii4 (d2);
+ALTER TABLE tm1 ADD FULLTEXT INDEX im4 (d2);
+
+# Bug#14140038 INCONSISTENT HANDLING OF FULLTEXT INDEXES IN ALTER TABLE
+--error ER_ALTER_OPERATION_NOT_SUPPORTED_REASON
+ALTER TABLE ti1 ADD PRIMARY KEY(a), ALGORITHM=INPLACE;
+ALTER TABLE ti1 ADD PRIMARY KEY(a);
+ALTER TABLE tm1 ADD PRIMARY KEY(a);
+
+ALTER TABLE ti1 DROP INDEX ii3;
+ALTER TABLE tm1 DROP INDEX im3;
+
+ALTER TABLE ti1 DROP COLUMN d2;
+ALTER TABLE tm1 DROP COLUMN d2;
+
+ALTER TABLE ti1 ADD CONSTRAINT fi1 FOREIGN KEY (b) REFERENCES ti2(a);
+ALTER TABLE tm1 ADD CONSTRAINT fm1 FOREIGN KEY (b) REFERENCES tm2(a);
+
+ALTER TABLE ti1 ALTER COLUMN b SET DEFAULT 1;
+ALTER TABLE tm1 ALTER COLUMN b SET DEFAULT 1;
+ALTER TABLE ti1 ALTER COLUMN b DROP DEFAULT;
+ALTER TABLE tm1 ALTER COLUMN b DROP DEFAULT;
+
+# This will set both ALTER_COLUMN_NAME and COLUMN_DEFAULT_VALUE
+ALTER TABLE ti1 CHANGE COLUMN f g INT;
+ALTER TABLE tm1 CHANGE COLUMN f g INT;
+ALTER TABLE ti1 CHANGE COLUMN g h VARCHAR(20);
+ALTER TABLE tm1 CHANGE COLUMN g h VARCHAR(20);
+ALTER TABLE ti1 MODIFY COLUMN e ENUM('a', 'b', 'c');
+ALTER TABLE tm1 MODIFY COLUMN e ENUM('a', 'b', 'c');
+ALTER TABLE ti1 MODIFY COLUMN e INT;
+ALTER TABLE tm1 MODIFY COLUMN e INT;
+# This will set both ALTER_COLUMN_ORDER and COLUMN_DEFAULT_VALUE
+ALTER TABLE ti1 MODIFY COLUMN e INT AFTER h;
+ALTER TABLE tm1 MODIFY COLUMN e INT AFTER h;
+ALTER TABLE ti1 MODIFY COLUMN e INT FIRST;
+ALTER TABLE tm1 MODIFY COLUMN e INT FIRST;
+# This will set both ALTER_COLUMN_NOT_NULLABLE and COLUMN_DEFAULT_VALUE
+--disable_info
+# NULL -> NOT NULL only allowed INPLACE if strict sql_mode is on.
+SET @orig_sql_mode = @@sql_mode;
+SET @@sql_mode = 'STRICT_TRANS_TABLES';
+--enable_info
+ALTER TABLE ti1 MODIFY COLUMN c INT NOT NULL;
+--disable_info
+SET @@sql_mode = @orig_sql_mode;
+--enable_info
+ALTER TABLE tm1 MODIFY COLUMN c INT NOT NULL;
+# This will set both ALTER_COLUMN_NULLABLE and COLUMN_DEFAULT_VALUE
+ALTER TABLE ti1 MODIFY COLUMN c INT NULL;
+ALTER TABLE tm1 MODIFY COLUMN c INT NULL;
+# This will set both ALTER_COLUMN_EQUAL_PACK_LENGTH and COLUMN_DEFAULT_VALUE
+ALTER TABLE ti1 MODIFY COLUMN h VARCHAR(30);
+ALTER TABLE tm1 MODIFY COLUMN h VARCHAR(30);
+ALTER TABLE ti1 MODIFY COLUMN h VARCHAR(30) AFTER d;
+ALTER TABLE tm1 MODIFY COLUMN h VARCHAR(30) AFTER d;
+
+ALTER TABLE ti1 DROP COLUMN h;
+ALTER TABLE tm1 DROP COLUMN h;
+
+ALTER TABLE ti1 DROP INDEX ii2;
+ALTER TABLE tm1 DROP INDEX im2;
+ALTER TABLE ti1 DROP PRIMARY KEY;
+ALTER TABLE tm1 DROP PRIMARY KEY;
+
+ALTER TABLE ti1 DROP FOREIGN KEY fi1;
+ALTER TABLE tm1 DROP FOREIGN KEY fm1;
+
+ALTER TABLE ti1 RENAME TO ti3;
+ALTER TABLE tm1 RENAME TO tm3;
+ALTER TABLE ti3 RENAME TO ti1;
+ALTER TABLE tm3 RENAME TO tm1;
+
+ALTER TABLE ti1 ORDER BY b;
+ALTER TABLE tm1 ORDER BY b;
+
+ALTER TABLE ti1 CONVERT TO CHARACTER SET utf16;
+ALTER TABLE tm1 CONVERT TO CHARACTER SET utf16;
+ALTER TABLE ti1 DEFAULT CHARACTER SET utf8;
+ALTER TABLE tm1 DEFAULT CHARACTER SET utf8;
+
+ALTER TABLE ti1 FORCE;
+ALTER TABLE tm1 FORCE;
+
+ALTER TABLE ti1 AUTO_INCREMENT 3;
+ALTER TABLE tm1 AUTO_INCREMENT 3;
+ALTER TABLE ti1 AVG_ROW_LENGTH 10;
+ALTER TABLE tm1 AVG_ROW_LENGTH 10;
+ALTER TABLE ti1 CHECKSUM 1;
+ALTER TABLE tm1 CHECKSUM 1;
+ALTER TABLE ti1 COMMENT 'test';
+ALTER TABLE tm1 COMMENT 'test';
+ALTER TABLE ti1 MAX_ROWS 100;
+ALTER TABLE tm1 MAX_ROWS 100;
+ALTER TABLE ti1 MIN_ROWS 1;
+ALTER TABLE tm1 MIN_ROWS 1;
+ALTER TABLE ti1 PACK_KEYS 1;
+ALTER TABLE tm1 PACK_KEYS 1;
+
+--disable_info
+DROP TABLE ti1, ti2, tm1, tm2;
+
+--echo # Tests of >1 operation (InnoDB)
+
+CREATE TABLE ti1(a INT PRIMARY KEY AUTO_INCREMENT, b INT) engine=InnoDB;
+INSERT INTO ti1(b) VALUES (1), (2);
+
+--enable_info
+ALTER TABLE ti1 RENAME TO ti3, ADD INDEX ii1(b);
+
+ALTER TABLE ti3 DROP INDEX ii1, AUTO_INCREMENT 5;
+--disable_info
+INSERT INTO ti3(b) VALUES (5);
+--enable_info
+ALTER TABLE ti3 ADD INDEX ii1(b), AUTO_INCREMENT 7;
+--disable_info
+INSERT INTO ti3(b) VALUES (7);
+SELECT * FROM ti3;
+
+DROP TABLE ti3;
+
+--echo #
+--echo # 8: Scenario in which ALTER TABLE was returning an unwarranted
+--echo # ER_ILLEGAL_HA error at some point during work on this WL.
+--echo #
+
+CREATE TABLE tm1(i INT DEFAULT 1) engine=MyISAM;
+ALTER TABLE tm1 ADD INDEX ii1(i), ALTER COLUMN i DROP DEFAULT;
+DROP TABLE tm1;
+
+#
+# MDEV-4435 Server crashes in my_strcasecmp_utf8 on ADD KEY IF NOT EXISTS with implicit name when the key exists.
+#
+create table if not exists t1 (i int);
+alter table t1 add key (i);
+alter table t1 add key if not exists (i);
+DROP TABLE t1;
+
+#
+# MDEV-4436 CHANGE COLUMN IF EXISTS does not work and throws wrong warning.
+#
+create table t1 (a int);
+alter table t1 change column if exists a b bigint;
+show create table t1;
+DROP TABLE t1;
+
+#
+# MDEV-4437 ALTER TABLE .. ADD UNIQUE INDEX IF NOT EXISTS causes syntax error.
+#
+
+create table t1 (i int);
+alter table t1 add unique index if not exists idx(i);
+alter table t1 add unique index if not exists idx(i);
+show create table t1;
+DROP TABLE t1;
+
+#
+# MDEV-8358 ADD PRIMARY KEY IF NOT EXISTS -> ERROR 1068 (42000): Multiple primary key
+#
+
+CREATE TABLE t1 (
+ `event_id` bigint(20) unsigned NOT NULL DEFAULT '0',
+ `market_id` bigint(20) unsigned NOT NULL DEFAULT '0',
+ PRIMARY KEY (`event_id`,`market_id`)
+ );
+ALTER TABLE t1 ADD PRIMARY KEY IF NOT EXISTS event_id (event_id,market_id);
+DROP TABLE t1;
+
+--echo #
+--echo # MDEV-11126 Crash while altering persistent virtual column
+--echo #
+
+CREATE TABLE `tab1` (
+ `id` bigint(20) NOT NULL AUTO_INCREMENT,
+ `field2` set('option1','option2','option3','option4') NOT NULL,
+ `field3` set('option1','option2','option3','option4','option5') NOT NULL,
+ `field4` set('option1','option2','option3','option4') NOT NULL,
+ `field5` varchar(32) NOT NULL,
+ `field6` varchar(32) NOT NULL,
+ `field7` varchar(32) NOT NULL,
+ `field8` varchar(32) NOT NULL,
+ `field9` int(11) NOT NULL DEFAULT '1',
+ `field10` varchar(16) NOT NULL,
+ `field11` enum('option1','option2','option3') NOT NULL DEFAULT 'option1',
+ `v_col` varchar(128) AS (IF(field11='option1',CONCAT_WS(":","field1",field2,field3,field4,field5,field6,field7,field8,field9,field10), CONCAT_WS(":","field1",field11,field2,field3,field4,field5,field6,field7,field8,field9,field10))) PERSISTENT,
+ PRIMARY KEY (`id`)
+) DEFAULT CHARSET=latin1;
+
+ALTER TABLE `tab1` CHANGE COLUMN v_col `v_col` varchar(128);
+SHOW CREATE TABLE `tab1`;
+ALTER TABLE `tab1` CHANGE COLUMN v_col `v_col` varchar(128) AS (IF(field11='option1',CONCAT_WS(":","field1",field2,field3,field4,field5,field6,field7,field8,field9,field10), CONCAT_WS(":","field1",field11,field2,field3,field4,field5,field6,field7,field8,field9,field10))) PERSISTENT;
+SHOW CREATE TABLE `tab1`;
+DROP TABLE `tab1`;
+
+--echo #
+--echo # MDEV-11548 Reproducible server crash after the 2nd ALTER TABLE ADD FOREIGN KEY IF NOT EXISTS
+--echo #
+
+CREATE TABLE t1 (id INT UNSIGNED NOT NULL PRIMARY KEY);
+CREATE TABLE t2 (id1 INT UNSIGNED NOT NULL);
+
+ALTER TABLE t2
+ADD FOREIGN KEY IF NOT EXISTS (id1)
+ REFERENCES t1 (id);
+
+ALTER TABLE t2
+ADD FOREIGN KEY IF NOT EXISTS (id1)
+REFERENCES t1 (id);
+
+DROP TABLE t2;
+DROP TABLE t1;
+
+
+--echo #
+--echo # MDEV-6390 CONVERT TO CHARACTER SET utf8 doesn't change DEFAULT CHARSET.
+--echo #
+
+CREATE TABLE t1 (id int(11) NOT NULL, a int(11) NOT NULL, b int(11))
+ ENGINE=InnoDB DEFAULT CHARSET=latin1;
+SHOW CREATE TABLE t1;
+ALTER TABLE t1 CONVERT TO CHARACTER SET utf8;
+SHOW CREATE TABLE t1;
+DROP TABLE t1;
diff --git a/mysql-test/t/alter_table_autoinc-5574.test b/mysql-test/t/alter_table_autoinc-5574.test
new file mode 100644
index 00000000000..95c2b8d81bb
--- /dev/null
+++ b/mysql-test/t/alter_table_autoinc-5574.test
@@ -0,0 +1,12 @@
+#
+# MDEV-5574 Set AUTO_INCREMENT below max value of column
+#
+--source include/have_innodb.inc
+create table t1(a int(10)unsigned not null auto_increment primary key,
+b varchar(255) not null) engine=innodb default charset=utf8;
+insert into t1 values(1,'aaa'),(2,'bbb');
+alter table t1 auto_increment=1;
+insert into t1 values(NULL, 'ccc');
+select * from t1;
+drop table t1;
+
diff --git a/mysql-test/t/alter_table_mdev539_maria.test b/mysql-test/t/alter_table_mdev539_maria.test
new file mode 100644
index 00000000000..7e01bc3be84
--- /dev/null
+++ b/mysql-test/t/alter_table_mdev539_maria.test
@@ -0,0 +1,7 @@
+
+--echo #
+set @@storage_engine= Aria;
+
+--source include/alter_table_mdev539.inc
+
+set @@storage_engine= default;
diff --git a/mysql-test/t/alter_table_mdev539_myisam.test b/mysql-test/t/alter_table_mdev539_myisam.test
new file mode 100644
index 00000000000..0a5669088bf
--- /dev/null
+++ b/mysql-test/t/alter_table_mdev539_myisam.test
@@ -0,0 +1,7 @@
+
+--echo #
+set @@storage_engine= MyISAM;
+
+--source include/alter_table_mdev539.inc
+
+set @@storage_engine= default;
diff --git a/mysql-test/t/alter_table_online.test b/mysql-test/t/alter_table_online.test
index 19096efe0fa..9062ecba35a 100644
--- a/mysql-test/t/alter_table_online.test
+++ b/mysql-test/t/alter_table_online.test
@@ -1,11 +1,9 @@
#
-# Test of alter online table
+# Test of ALTER ONLINE TABLE syntax
#
--source include/have_innodb.inc
---disable_warnings
-drop table if exists t1,t2,t3;
---enable_warnings
+--source include/have_partition.inc
#
# Test of things that can be done online
#
@@ -17,30 +15,29 @@ alter online table t1 modify b int default 5;
alter online table t1 change b new_name int;
alter online table t1 modify e enum('a','b','c');
alter online table t1 comment "new comment";
-alter online table t1 rename to t2;
-alter online table t2 rename to t1;
+
+# No OPs
+
+alter online table t1 algorithm=INPLACE, lock=NONE;
+alter online table t1;
+alter table t1 algorithm=INPLACE;
+alter table t1 lock=NONE;
drop table t1;
#
-# temporary tables always require a copy
+# everything with temporary tables is "online", i.e. without locks
#
-
create temporary table t1 (a int not null primary key, b int, c varchar(80), e enum('a','b'));
insert into t1 (a) values (1),(2),(3);
---error ER_CANT_DO_ONLINE
alter online table t1 modify b int default 5;
---error ER_CANT_DO_ONLINE
alter online table t1 change b new_name int;
---error ER_CANT_DO_ONLINE
alter online table t1 modify e enum('a','b','c');
---error ER_CANT_DO_ONLINE
alter online table t1 comment "new comment";
---error ER_CANT_DO_ONLINE
alter online table t1 rename to t2;
-drop table t1;
+drop table t2;
#
# Test of things that is not possible to do online
@@ -49,52 +46,47 @@ drop table t1;
create table t1 (a int not null primary key, b int, c varchar(80), e enum('a','b'));
insert into t1 (a) values (1),(2),(3);
---error ER_CANT_DO_ONLINE
+--error ER_ALTER_OPERATION_NOT_SUPPORTED
alter online table t1 drop column b, add b int;
---error ER_CANT_DO_ONLINE
+--error ER_ALTER_OPERATION_NOT_SUPPORTED
alter online table t1 modify b bigint;
---error ER_CANT_DO_ONLINE
+--error ER_ALTER_OPERATION_NOT_SUPPORTED
alter online table t1 modify e enum('c','a','b');
---error ER_CANT_DO_ONLINE
+--error ER_ALTER_OPERATION_NOT_SUPPORTED
alter online table t1 modify c varchar(50);
---error ER_CANT_DO_ONLINE
+--error ER_ALTER_OPERATION_NOT_SUPPORTED
alter online table t1 modify c varchar(100);
---error ER_CANT_DO_ONLINE
+--error ER_ALTER_OPERATION_NOT_SUPPORTED
alter online table t1 add f int;
---error ER_CANT_DO_ONLINE
+--error ER_ALTER_OPERATION_NOT_SUPPORTED_REASON
alter online table t1 engine=memory;
+--error ER_ALTER_OPERATION_NOT_SUPPORTED
+alter online table t1 rename to t2;
alter table t1 engine=innodb;
alter table t1 add index (b);
---error ER_CANT_DO_ONLINE
alter online table t1 add index c (c);
---error ER_CANT_DO_ONLINE
alter online table t1 drop index b;
+alter online table t1 comment "new comment";
drop table t1;
create temporary table t1 (a int not null primary key, b int, c varchar(80), e enum('a','b'));
insert into t1 (a) values (1),(2),(3);
---error ER_CANT_DO_ONLINE
+#
+# everything with temporary tables is "online", i.e. without locks
+#
alter online table t1 drop column b, add b int;
---error ER_CANT_DO_ONLINE
alter online table t1 modify b bigint;
---error ER_CANT_DO_ONLINE
alter online table t1 modify e enum('c','a','b');
---error ER_CANT_DO_ONLINE
alter online table t1 modify c varchar(50);
---error ER_CANT_DO_ONLINE
alter online table t1 modify c varchar(100);
---error ER_CANT_DO_ONLINE
alter online table t1 add f int;
---error ER_CANT_DO_ONLINE
alter online table t1 engine=memory;
alter table t1 engine=innodb;
alter table t1 add index (b);
---error ER_CANT_DO_ONLINE
alter online table t1 add index c (c);
---error ER_CANT_DO_ONLINE
alter online table t1 drop index b;
drop table t1;
@@ -104,5 +96,193 @@ drop table t1;
create table t1 (a int not null primary key, b int, c varchar(80));
create table t2 (a int not null primary key, b int, c varchar(80));
create table t3 (a int not null primary key, b int, c varchar(80)) engine=merge UNION=(t1);
+--error ER_ALTER_OPERATION_NOT_SUPPORTED
alter online table t3 union=(t1,t2);
drop table t1,t2,t3;
+
+#
+# MDEV-9868 Altering a partitioned table comment does a full copy
+#
+create table t1 (i int) partition by hash(i) partitions 2;
+alter online table t1 comment 'test';
+drop table t1;
+
+#
+# MDEV-9168 altering a column comment does a full copy
+#
+create table t1 (a int);
+alter online table t1 modify a int comment 'test';
+drop table t1;
+
+create table t1 (a int) engine=innodb;
+alter online table t1 modify a int comment 'test';
+drop table t1;
+
+create table t1 (a int) partition by hash(a) partitions 2;
+alter online table t1 modify a int comment 'test';
+drop table t1;
+
+--echo #
+--echo # MDEV-8948 ALTER ... INPLACE does work for BINARY, BLOB
+--echo #
+#
+# ALTER to the same [VAR]BINARY type
+#
+CREATE TABLE t1 (a BINARY(10));
+ALTER TABLE t1 MODIFY a BINARY(10), ALGORITHM=INPLACE;
+DROP TABLE t1;
+
+CREATE TABLE t1 (a VARBINARY(10));
+ALTER TABLE t1 MODIFY a VARBINARY(10), ALGORITHM=INPLACE;
+DROP TABLE t1;
+
+#
+# ALTER to the same BLOB variant
+#
+CREATE TABLE t1 (a TINYBLOB);
+ALTER TABLE t1 MODIFY a TINYBLOB, ALGORITHM=INPLACE;
+DROP TABLE t1;
+
+CREATE TABLE t1 (a MEDIUMBLOB);
+ALTER TABLE t1 MODIFY a MEDIUMBLOB, ALGORITHM=INPLACE;
+DROP TABLE t1;
+
+CREATE TABLE t1 (a BLOB);
+ALTER TABLE t1 MODIFY a BLOB, ALGORITHM=INPLACE;
+DROP TABLE t1;
+
+CREATE TABLE t1 (a LONGBLOB);
+ALTER TABLE t1 MODIFY a LONGBLOB, ALGORITHM=INPLACE;
+DROP TABLE t1;
+
+#
+# ALTER to the same [VAR]CHAR type
+#
+CREATE TABLE t1 (a CHAR(10));
+ALTER TABLE t1 MODIFY a CHAR(10), ALGORITHM=INPLACE;
+DROP TABLE t1;
+
+CREATE TABLE t1 (a VARCHAR(10));
+ALTER TABLE t1 MODIFY a VARCHAR(10), ALGORITHM=INPLACE;
+DROP TABLE t1;
+
+
+#
+# ALTER to the same TEXT variant
+#
+CREATE TABLE t1 (a TINYTEXT);
+ALTER TABLE t1 MODIFY a TINYTEXT, ALGORITHM=INPLACE;
+DROP TABLE t1;
+
+CREATE TABLE t1 (a MEDIUMTEXT);
+ALTER TABLE t1 MODIFY a MEDIUMTEXT, ALGORITHM=INPLACE;
+DROP TABLE t1;
+
+CREATE TABLE t1 (a TEXT);
+ALTER TABLE t1 MODIFY a TEXT, ALGORITHM=INPLACE;
+DROP TABLE t1;
+
+CREATE TABLE t1 (a LONGTEXT);
+ALTER TABLE t1 MODIFY a LONGTEXT, ALGORITHM=INPLACE;
+DROP TABLE t1;
+
+#
+# ALTER from a non-binary to a binary collation
+#
+CREATE TABLE t1 (a CHAR(10));
+--error ER_ALTER_OPERATION_NOT_SUPPORTED
+ALTER TABLE t1 MODIFY a CHAR(10) COLLATE latin1_bin, ALGORITHM=INPLACE;
+DROP TABLE t1;
+
+CREATE TABLE t1 (a VARCHAR(10));
+--error ER_ALTER_OPERATION_NOT_SUPPORTED
+ALTER TABLE t1 MODIFY a VARCHAR(10) COLLATE latin1_bin, ALGORITHM=INPLACE;
+DROP TABLE t1;
+
+CREATE TABLE t1 (a TINYTEXT);
+--error ER_ALTER_OPERATION_NOT_SUPPORTED
+ALTER TABLE t1 MODIFY a TINYTEXT COLLATE latin1_bin, ALGORITHM=INPLACE;
+DROP TABLE t1;
+
+CREATE TABLE t1 (a MEDIUMTEXT);
+--error ER_ALTER_OPERATION_NOT_SUPPORTED
+ALTER TABLE t1 MODIFY a MEDIUMTEXT COLLATE latin1_bin, ALGORITHM=INPLACE;
+DROP TABLE t1;
+
+CREATE TABLE t1 (a TEXT);
+--error ER_ALTER_OPERATION_NOT_SUPPORTED
+ALTER TABLE t1 MODIFY a TEXT COLLATE latin1_bin, ALGORITHM=INPLACE;
+DROP TABLE t1;
+
+CREATE TABLE t1 (a LONGTEXT);
+--error ER_ALTER_OPERATION_NOT_SUPPORTED
+ALTER TABLE t1 MODIFY a LONGTEXT COLLATE latin1_bin, ALGORITHM=INPLACE;
+DROP TABLE t1;
+
+#
+# ALTER from a binary to a non-binary collation
+#
+CREATE TABLE t1 (a CHAR(10) COLLATE latin1_bin);
+--error ER_ALTER_OPERATION_NOT_SUPPORTED
+ALTER TABLE t1 MODIFY a CHAR(10) COLLATE latin1_swedish_ci, ALGORITHM=INPLACE;
+DROP TABLE t1;
+
+CREATE TABLE t1 (a VARCHAR(10) COLLATE latin1_bin);
+--error ER_ALTER_OPERATION_NOT_SUPPORTED
+ALTER TABLE t1 MODIFY a VARCHAR(10) COLLATE latin1_swedish_ci, ALGORITHM=INPLACE;
+DROP TABLE t1;
+
+CREATE TABLE t1 (a TINYTEXT COLLATE latin1_bin);
+--error ER_ALTER_OPERATION_NOT_SUPPORTED
+ALTER TABLE t1 MODIFY a TINYTEXT COLLATE latin1_swedish_ci, ALGORITHM=INPLACE;
+DROP TABLE t1;
+
+CREATE TABLE t1 (a MEDIUMTEXT COLLATE latin1_bin);
+--error ER_ALTER_OPERATION_NOT_SUPPORTED
+ALTER TABLE t1 MODIFY a MEDIUMTEXT COLLATE latin1_swedish_ci, ALGORITHM=INPLACE;
+DROP TABLE t1;
+
+CREATE TABLE t1 (a TEXT COLLATE latin1_bin);
+--error ER_ALTER_OPERATION_NOT_SUPPORTED
+ALTER TABLE t1 MODIFY a TEXT COLLATE latin1_swedish_ci, ALGORITHM=INPLACE;
+DROP TABLE t1;
+
+CREATE TABLE t1 (a LONGTEXT COLLATE latin1_bin);
+--error ER_ALTER_OPERATION_NOT_SUPPORTED
+ALTER TABLE t1 MODIFY a LONGTEXT COLLATE latin1_swedish_ci, ALGORITHM=INPLACE;
+DROP TABLE t1;
+
+#
+# ALTER from a non-binary collation to another non-binary collation
+#
+CREATE TABLE t1 (a CHAR(10) COLLATE latin1_general_ci);
+--error ER_ALTER_OPERATION_NOT_SUPPORTED
+ALTER TABLE t1 MODIFY a CHAR(10) COLLATE latin1_swedish_ci, ALGORITHM=INPLACE;
+DROP TABLE t1;
+
+CREATE TABLE t1 (a VARCHAR(10) COLLATE latin1_general_ci);
+--error ER_ALTER_OPERATION_NOT_SUPPORTED
+ALTER TABLE t1 MODIFY a VARCHAR(10) COLLATE latin1_swedish_ci, ALGORITHM=INPLACE;
+DROP TABLE t1;
+
+CREATE TABLE t1 (a TINYTEXT COLLATE latin1_general_ci);
+--error ER_ALTER_OPERATION_NOT_SUPPORTED
+ALTER TABLE t1 MODIFY a TINYTEXT COLLATE latin1_swedish_ci, ALGORITHM=INPLACE;
+DROP TABLE t1;
+
+CREATE TABLE t1 (a MEDIUMTEXT COLLATE latin1_general_ci);
+--error ER_ALTER_OPERATION_NOT_SUPPORTED
+ALTER TABLE t1 MODIFY a MEDIUMTEXT COLLATE latin1_swedish_ci, ALGORITHM=INPLACE;
+DROP TABLE t1;
+
+CREATE TABLE t1 (a TEXT COLLATE latin1_general_ci);
+--error ER_ALTER_OPERATION_NOT_SUPPORTED
+ALTER TABLE t1 MODIFY a TEXT COLLATE latin1_swedish_ci, ALGORITHM=INPLACE;
+DROP TABLE t1;
+
+CREATE TABLE t1 (a LONGTEXT COLLATE latin1_general_ci);
+--error ER_ALTER_OPERATION_NOT_SUPPORTED
+ALTER TABLE t1 MODIFY a LONGTEXT COLLATE latin1_swedish_ci, ALGORITHM=INPLACE;
+DROP TABLE t1;
+
+# End of 10.0 tests
diff --git a/mysql-test/t/bad_frm_crash_5029.test b/mysql-test/t/bad_frm_crash_5029.test
index dadfc86e28e..858922886ab 100644
--- a/mysql-test/t/bad_frm_crash_5029.test
+++ b/mysql-test/t/bad_frm_crash_5029.test
@@ -18,6 +18,3 @@ copy_file std_data/mdev5029_2.MAI $datadir/test/t1.MAI;
copy_file std_data/mdev5029_2.MAD $datadir/test/t1.MAD;
show create table t1;
drop table t1;
-remove_file $datadir/test/t1.MAI;
-remove_file $datadir/test/t1.MAD;
-
diff --git a/mysql-test/t/blackhole.test b/mysql-test/t/blackhole.test
index ca8ab6deb59..7f394e0f846 100644
--- a/mysql-test/t/blackhole.test
+++ b/mysql-test/t/blackhole.test
@@ -29,3 +29,12 @@ drop temporary table t1;
--echo End of 5.5 tests
+--echo #
+--echo # Bug#13948247 DIVISION BY 0 IN GET_BEST_DISJUNCT_QUICK WITH FORCE INDEX GROUP BY
+--echo #
+
+CREATE TABLE t1(a INT, b INT, c INT, KEY(c), UNIQUE(a)) ENGINE = BLACKHOLE;
+SELECT 0 FROM t1 FORCE INDEX FOR GROUP BY(a) WHERE a = 0 OR b = 0 AND c = 0;
+DROP TABLE t1;
+
+--echo End of 5.6 tests
diff --git a/mysql-test/t/blackhole_plugin.test b/mysql-test/t/blackhole_plugin.test
index 8af8fcc941c..0cc7ae0817c 100644
--- a/mysql-test/t/blackhole_plugin.test
+++ b/mysql-test/t/blackhole_plugin.test
@@ -7,7 +7,7 @@ DROP TABLE t1;
--replace_regex /\.dll/.so/
eval INSTALL PLUGIN blackhole SONAME '$HA_BLACKHOLE_SO';
--replace_regex /\.dll/.so/
---error 1125
+--error ER_PLUGIN_INSTALLED
eval INSTALL PLUGIN BLACKHOLE SONAME '$HA_BLACKHOLE_SO';
UNINSTALL PLUGIN blackhole;
diff --git a/mysql-test/t/bootstrap.test b/mysql-test/t/bootstrap.test
index 2930d936830..5ab736cee15 100644
--- a/mysql-test/t/bootstrap.test
+++ b/mysql-test/t/bootstrap.test
@@ -56,7 +56,6 @@ drop table t1;
--echo #
# need the --skip-innodb option present for the test to succeed
-SHOW VARIABLES LIKE 'have_innodb';
SELECT 'bug' as '' FROM INFORMATION_SCHEMA.ENGINES WHERE engine='innodb'
and SUPPORT='YES';
@@ -67,3 +66,42 @@ SELECT 'bug' as '' FROM INFORMATION_SCHEMA.ENGINES WHERE engine='innodb'
--exec $MYSQLD_BOOTSTRAP_CMD --myisam_recover_options=NONE
--echo End of 5.5 tests
+
+--source include/not_windows_embedded.inc
+--source include/have_example_plugin.inc
+#
+# Check that --bootstrap can install and uninstall plugins
+#
+let $PLUGIN_DIR=`select @@plugin_dir`;
+--write_file $MYSQLTEST_VARDIR/tmp/install_plugin.sql
+install soname 'ha_example';
+uninstall plugin unusable;
+EOF
+--exec $MYSQLD_BOOTSTRAP_CMD --plugin-dir=$PLUGIN_DIR < $MYSQLTEST_VARDIR/tmp/install_plugin.sql >> $MYSQLTEST_VARDIR/tmp/bootstrap.log 2>&1
+--remove_file $MYSQLTEST_VARDIR/tmp/install_plugin.sql
+
+#
+# Check that installed plugins are *not* automatically loaded in --bootstrap
+#
+--write_file $MYSQLTEST_VARDIR/tmp/bootstrap_plugins.sql
+use test;
+create table t1(a int) engine=example charset=latin1;
+EOF
+--exec $MYSQLD_BOOTSTRAP_CMD --plugin-dir=$PLUGIN_DIR < $MYSQLTEST_VARDIR/tmp/bootstrap_plugins.sql >> $MYSQLTEST_VARDIR/tmp/bootstrap.log 2>&1
+--remove_file $MYSQLTEST_VARDIR/tmp/bootstrap_plugins.sql
+flush tables;
+show create table t1;
+drop table t1;
+--replace_result .dll .so
+select * from mysql.plugin;
+truncate table mysql.plugin;
+
+
+#
+# MDEV-9969 mysql_install_db error processing ignore_db_dirs.
+#
+--write_file $MYSQLTEST_VARDIR/tmp/bootstrap_9969.sql
+use test;
+EOF
+--exec $MYSQLD_BOOTSTRAP_CMD --ignore-db-dirs='some_dir' --ignore-db-dirs='some_dir' < $MYSQLTEST_VARDIR/tmp/bootstrap_9969.sql >> $MYSQLTEST_VARDIR/tmp/bootstrap.log 2>&1
+--remove_file $MYSQLTEST_VARDIR/tmp/bootstrap_9969.sql
diff --git a/mysql-test/t/bug46261-master.opt b/mysql-test/t/bug46261-master.opt
deleted file mode 100644
index 5699a3387b8..00000000000
--- a/mysql-test/t/bug46261-master.opt
+++ /dev/null
@@ -1 +0,0 @@
---skip-grant-tables
diff --git a/mysql-test/t/bug46261.test b/mysql-test/t/bug46261.test
deleted file mode 100644
index 9d8eecf3d52..00000000000
--- a/mysql-test/t/bug46261.test
+++ /dev/null
@@ -1,16 +0,0 @@
---source include/not_embedded.inc
---source include/have_example_plugin.inc
-
---echo #
---echo # Bug#46261 Plugins can be installed with --skip-grant-tables
---echo #
-
---replace_regex /\.dll/.so/
---error ER_OPTION_PREVENTS_STATEMENT
-eval INSTALL PLUGIN example SONAME '$HA_EXAMPLE_SO';
-
---replace_regex /\.dll/.so/
---error ER_OPTION_PREVENTS_STATEMENT
-eval UNINSTALL PLUGIN example;
-
---echo End of 5.1 tests
diff --git a/mysql-test/t/bug58669.test b/mysql-test/t/bug58669.test
index 332c104cfea..77827cde5ba 100644
--- a/mysql-test/t/bug58669.test
+++ b/mysql-test/t/bug58669.test
@@ -12,7 +12,7 @@ CREATE TABLE db1.t1(a INT);
connect (con1,localhost,user1,,);
connection con1;
SELECT CURRENT_USER();
-SHOW VARIABLES LIKE "%read_only%";
+SHOW VARIABLES LIKE "read_only%";
--error ER_OPTION_PREVENTS_STATEMENT
INSERT INTO db1.t1 VALUES (1);
diff --git a/mysql-test/t/cast.test b/mysql-test/t/cast.test
index b7630348c93..b6c37cacd8a 100644
--- a/mysql-test/t/cast.test
+++ b/mysql-test/t/cast.test
@@ -2,6 +2,9 @@
# Test of cast function
#
+# For TIME->DATETIME conversion
+SET timestamp=unix_timestamp('2001-02-03 10:20:30');
+
select CAST(1-2 AS UNSIGNED);
select CAST(CAST(1-2 AS UNSIGNED) AS SIGNED INTEGER);
select CAST('10 ' as unsigned integer);
@@ -74,11 +77,11 @@ select 10E+0+'10';
# The following cast creates warnings
-select CONVERT(DATE "2004-01-22 21:45:33" USING latin1);
-select CONVERT(DATE "2004-01-22 21:45:33",CHAR);
-select CONVERT(DATE "2004-01-22 21:45:33",CHAR(4));
-select CONVERT(DATE "2004-01-22 21:45:33",BINARY(4));
-select CAST(DATE "2004-01-22 21:45:33" AS BINARY(4));
+select CONVERT(TIMESTAMP "2004-01-22 21:45:33" USING latin1);
+select CONVERT(TIMESTAMP "2004-01-22 21:45:33",CHAR);
+select CONVERT(TIMESTAMP "2004-01-22 21:45:33",CHAR(4));
+select CONVERT(TIMESTAMP "2004-01-22 21:45:33",BINARY(4));
+select CAST(TIMESTAMP "2004-01-22 21:45:33" AS BINARY(4));
select CAST(0xb3 as signed);
select CAST(0x8fffffffffffffff as signed);
select CAST(0xffffffffffffffff as unsigned);
diff --git a/mysql-test/t/change_user_notembedded.test b/mysql-test/t/change_user_notembedded.test
index bf5d1956cd5..19421c6dd33 100644
--- a/mysql-test/t/change_user_notembedded.test
+++ b/mysql-test/t/change_user_notembedded.test
@@ -22,3 +22,5 @@ change_user;
disconnect test;
connection default;
+--echo that's all
+
diff --git a/mysql-test/t/comment_column.test b/mysql-test/t/comment_column.test
index 90976d143b5..de1c9b8ce47 100644
--- a/mysql-test/t/comment_column.test
+++ b/mysql-test/t/comment_column.test
@@ -125,6 +125,8 @@ ALTER TABLE t1_toupg ADD c3 TIMESTAMP COMMENT 'abcdefghijabcdefghijabcdefghijabc
ALTER TABLE t1_toupg ADD INDEX i1(c1) COMMENT '01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234';
# Add index with comment using CREATE INDEX
CREATE INDEX i2 ON t1_toupg(c2) COMMENT '01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234';
+# Alter the existing table, replace all columns, change comment
+ALTER TABLE t1_toupg drop column c1, drop column c2, drop column c3, add column c4 int, COMMENT='012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012301234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234';
drop table t1_toupg;
diff --git a/mysql-test/t/comments.test b/mysql-test/t/comments.test
index 4d47674650c..6cf69635d1e 100644
--- a/mysql-test/t/comments.test
+++ b/mysql-test/t/comments.test
@@ -8,7 +8,7 @@ multi line comment */;
--error 1065
;
select 1 /*!32301 +1 */;
-select 1 /*!52301 +1 */;
+select 1 /*!952301 +1 */;
select 1--1;
# Note that the following returns 4 while it should return 2
# This is because the mysqld server doesn't parse -- comments
@@ -29,9 +29,31 @@ select 1 /*M!50000 +1 */;
select 1 /*M!50300 +1 */;
select 2 /*M!99999 +1 */;
select 2 /*M!100000 +1 */;
+select 2 /*M!999999 +1 */;
--error ER_PARSE_ERROR
select 2 /*M!0000 +1 */;
+--echo #
+--echo # Testing that MySQL versions >= 5.7.x and < 10.0.0 are ignored (MDEV-5009)
+--echo #
+SELECT 1 /*!50699 +1*/;
+SELECT 1 /*!50700 +1*/;
+SELECT 1 /*!50999 +1*/;
+SELECT 1 /*!99999 +1*/;
+SELECT 1 /*!100000 +1*/;
+SELECT 1 /*!110000 +1*/;
+
+--echo #
+--echo # Tesing that versions >= 5.7.x and < 10.0.0 are not ignored
+--echo # when used with the MariaDB executable comment syntax.
+--echo #
+SELECT 1 /*M!50699 +1*/;
+SELECT 1 /*M!50700 +1*/;
+SELECT 1 /*M!50999 +1*/;
+SELECT 1 /*M!99999 +1*/;
+SELECT 1 /*M!100000 +1*/;
+SELECT 1 /*M!110000 +1*/;
+
#
# Bug#25411 (trigger code truncated)
#
@@ -44,7 +66,7 @@ select 1/*!0000002*/;
select 1/*!999992*/;
-select 1 + /*!00000 2 */ + 3 /*!99999 noise*/ + 4;
+select 1 + /*!00000 2 */ + 3 /*!999999 noise*/ + 4;
#
# Bug#28779 (mysql_query() allows execution of statements with unbalanced
@@ -70,10 +92,10 @@ prepare bar from "DELETE FROM table_28779 WHERE a = 7 OR 1=1/*! AND 2=2;";
prepare bar from "DELETE FROM table_28779 WHERE a = 7 OR 1=1/*! AND 2=2;*";
--error 1064
-prepare bar from "DELETE FROM table_28779 WHERE a = 7 OR 1=1/*!98765' AND b = 'bar';";
+prepare bar from "DELETE FROM table_28779 WHERE a = 7 OR 1=1/*!998765' AND b = 'bar';";
--error 1064
-prepare bar from "DELETE FROM table_28779 WHERE a = 7 OR 1=1/*!98765' AND b = 'bar';*";
+prepare bar from "DELETE FROM table_28779 WHERE a = 7 OR 1=1/*!998765' AND b = 'bar';*";
drop table table_28779;
diff --git a/mysql-test/t/commit.test b/mysql-test/t/commit.test
index 261867bd5cc..c2051358073 100644
--- a/mysql-test/t/commit.test
+++ b/mysql-test/t/commit.test
@@ -28,7 +28,7 @@ COMMIT;
# inside a transaction
#
START TRANSACTION;
---error ER_CANT_CHANGE_TX_ISOLATION
+--error ER_CANT_CHANGE_TX_CHARACTERISTICS
SET TRANSACTION ISOLATION LEVEL SERIALIZABLE;
COMMIT;
@@ -338,7 +338,7 @@ COMMIT AND NO CHAIN;
#
# Cleanup
#
-SET @autocommit=1;
+SET @@autocommit=1;
COMMIT;
disconnect con1;
@@ -348,3 +348,360 @@ DROP TABLE t1;
--echo #
--echo # End of test cases for Bug#20837
--echo #
+
+
+--echo #
+--echo # WL#5968 Implement START TRANSACTION READ (WRITE|ONLY);
+--echo #
+
+--echo #
+--echo # Test 1: Check supported syntax
+
+START TRANSACTION;
+COMMIT;
+
+START TRANSACTION READ ONLY;
+COMMIT;
+
+START TRANSACTION READ WRITE;
+COMMIT;
+
+--error ER_PARSE_ERROR
+START TRANSACTION READ ONLY, READ WRITE;
+
+START TRANSACTION READ ONLY, WITH CONSISTENT SNAPSHOT;
+COMMIT;
+
+START TRANSACTION READ WRITE, WITH CONSISTENT SNAPSHOT;
+COMMIT;
+
+START TRANSACTION WITH CONSISTENT SNAPSHOT, READ ONLY;
+COMMIT;
+
+START TRANSACTION WITH CONSISTENT SNAPSHOT, READ WRITE;
+COMMIT;
+
+--error ER_PARSE_ERROR
+START TRANSACTION READ ONLY, WITH CONSISTENT SNAPSHOT, READ WRITE;
+
+SET TRANSACTION READ ONLY;
+SET TRANSACTION READ WRITE;
+SET TRANSACTION ISOLATION LEVEL SERIALIZABLE, READ ONLY;
+SET TRANSACTION ISOLATION LEVEL SERIALIZABLE, READ WRITE;
+SET TRANSACTION READ ONLY, ISOLATION LEVEL READ COMMITTED;
+SET TRANSACTION READ WRITE, ISOLATION LEVEL READ COMMITTED;
+--error ER_PARSE_ERROR
+SET TRANSACTION READ ONLY, READ WRITE;
+COMMIT;
+
+--echo #
+--echo # Test 2: Check setting of variable.
+
+SET SESSION TRANSACTION READ WRITE;
+SELECT @@tx_read_only;
+
+SET SESSION TRANSACTION READ ONLY;
+SELECT @@tx_read_only;
+
+SET SESSION TRANSACTION ISOLATION LEVEL REPEATABLE READ, READ WRITE;
+SELECT @@tx_read_only;
+
+SET SESSION TRANSACTION READ ONLY, ISOLATION LEVEL REPEATABLE READ;
+SELECT @@tx_read_only;
+
+START TRANSACTION;
+--echo # Not allowed inside a transaction
+--error ER_CANT_CHANGE_TX_CHARACTERISTICS
+SET TRANSACTION READ ONLY;
+--echo # But these are allowed.
+SET SESSION TRANSACTION READ ONLY;
+SET GLOBAL TRANSACTION READ ONLY;
+COMMIT;
+
+# Reset to defaults
+SET SESSION TRANSACTION READ WRITE;
+SET GLOBAL TRANSACTION READ WRITE;
+
+--echo #
+--echo # Test 3: Test that write operations are properly blocked.
+
+CREATE TABLE t1(a INT);
+CREATE TEMPORARY TABLE temp_t2(a INT);
+
+SET SESSION TRANSACTION READ ONLY;
+
+--echo # 1: DDL should be blocked, also on temporary tables.
+--error ER_CANT_EXECUTE_IN_READ_ONLY_TRANSACTION
+CREATE TABLE t3(a INT);
+--error ER_CANT_EXECUTE_IN_READ_ONLY_TRANSACTION
+ALTER TABLE t1 COMMENT "Test";
+--error ER_CANT_EXECUTE_IN_READ_ONLY_TRANSACTION
+DROP TABLE t1;
+--error ER_CANT_EXECUTE_IN_READ_ONLY_TRANSACTION
+CREATE TEMPORARY TABLE temp_t3(a INT);
+--error ER_CANT_EXECUTE_IN_READ_ONLY_TRANSACTION
+ALTER TABLE temp_t2 COMMENT "Test";
+--error ER_CANT_EXECUTE_IN_READ_ONLY_TRANSACTION
+DROP TEMPORARY TABLE temp_t2;
+
+--error ER_CANT_EXECUTE_IN_READ_ONLY_TRANSACTION
+CREATE FUNCTION f1() RETURNS INT RETURN 1;
+--error ER_CANT_EXECUTE_IN_READ_ONLY_TRANSACTION
+DROP FUNCTION f1;
+--error ER_CANT_EXECUTE_IN_READ_ONLY_TRANSACTION
+CREATE PROCEDURE p1() BEGIN END;
+--error ER_CANT_EXECUTE_IN_READ_ONLY_TRANSACTION
+DROP PROCEDURE p1;
+
+--error ER_CANT_EXECUTE_IN_READ_ONLY_TRANSACTION
+CREATE VIEW v1 AS SELECT 1;
+SET SESSION TRANSACTION READ WRITE;
+CREATE VIEW v1 AS SELECT 1;
+SET SESSION TRANSACTION READ ONLY;
+--error ER_CANT_EXECUTE_IN_READ_ONLY_TRANSACTION
+DROP VIEW v1;
+SET SESSION TRANSACTION READ WRITE;
+DROP VIEW v1;
+SET SESSION TRANSACTION READ ONLY;
+
+--error ER_CANT_EXECUTE_IN_READ_ONLY_TRANSACTION
+RENAME TABLE t1 TO t2;
+--error ER_CANT_EXECUTE_IN_READ_ONLY_TRANSACTION
+RENAME TABLE temp_t2 TO temp_t3;
+--error ER_CANT_EXECUTE_IN_READ_ONLY_TRANSACTION
+TRUNCATE TABLE t1;
+
+--error ER_CANT_EXECUTE_IN_READ_ONLY_TRANSACTION
+CREATE DATABASE db1;
+--error ER_CANT_EXECUTE_IN_READ_ONLY_TRANSACTION
+DROP DATABASE db1;
+SET SESSION TRANSACTION READ WRITE;
+
+--echo # 2: DML should be blocked on non-temporary tables.
+START TRANSACTION READ ONLY;
+--error ER_CANT_EXECUTE_IN_READ_ONLY_TRANSACTION
+INSERT INTO t1 VALUES (1), (2);
+--error ER_CANT_EXECUTE_IN_READ_ONLY_TRANSACTION
+UPDATE t1 SET a= 3;
+--error ER_CANT_EXECUTE_IN_READ_ONLY_TRANSACTION
+DELETE FROM t1;
+
+--echo # 3: DML should be allowed on temporary tables.
+INSERT INTO temp_t2 VALUES (1), (2);
+UPDATE temp_t2 SET a= 3;
+DELETE FROM temp_t2;
+
+--echo # 4: Queries should not be blocked.
+SELECT * FROM t1;
+SELECT * FROM temp_t2;
+
+HANDLER t1 OPEN;
+HANDLER t1 READ FIRST;
+HANDLER t1 CLOSE;
+
+HANDLER temp_t2 OPEN;
+HANDLER temp_t2 READ FIRST;
+HANDLER temp_t2 CLOSE;
+
+--echo # 5: Prepared statements
+--error ER_CANT_EXECUTE_IN_READ_ONLY_TRANSACTION
+PREPARE stmt FROM "DELETE FROM t1";
+
+PREPARE stmt FROM "DELETE FROM temp_t2";
+EXECUTE stmt;
+DEALLOCATE PREPARE stmt;
+COMMIT;
+
+--echo # 6: Stored routines
+
+delimiter |;
+CREATE FUNCTION f1() RETURNS INT
+BEGIN
+ DELETE FROM t1;
+ RETURN 1;
+END|
+
+CREATE FUNCTION f2() RETURNS INT
+BEGIN
+ DELETE FROM temp_t2;
+ RETURN 1;
+END|
+delimiter ;|
+
+CREATE PROCEDURE p1() DELETE FROM t1;
+CREATE PROCEDURE p2() DELETE FROM temp_t2;
+
+START TRANSACTION READ ONLY;
+--error ER_CANT_EXECUTE_IN_READ_ONLY_TRANSACTION
+SELECT f1();
+SELECT f2();
+--error ER_CANT_EXECUTE_IN_READ_ONLY_TRANSACTION
+CALL p1();
+CALL p2();
+COMMIT;
+
+DROP FUNCTION f1;
+DROP FUNCTION f2;
+DROP PROCEDURE p1;
+DROP PROCEDURE p2;
+
+--echo # 7: Views
+CREATE VIEW v1 AS SELECT a FROM t1;
+# Not supported for temporary tables.
+
+START TRANSACTION READ ONLY;
+--error ER_CANT_EXECUTE_IN_READ_ONLY_TRANSACTION
+INSERT INTO v1 VALUES (1), (2);
+SELECT * FROM v1;
+COMMIT;
+
+DROP VIEW v1;
+
+--echo # 8: LOCK TABLE
+SET SESSION TRANSACTION READ ONLY;
+--error ER_CANT_EXECUTE_IN_READ_ONLY_TRANSACTION
+LOCK TABLE t1 WRITE;
+
+LOCK TABLE t1 READ;
+UNLOCK TABLES;
+
+# Not supported for temporary tables.
+
+SET SESSION TRANSACTION READ WRITE;
+DROP TABLE temp_t2, t1;
+
+--echo #
+--echo # Test 4: SET TRANSACTION, CHAINing transactions
+
+CREATE TABLE t1(a INT);
+
+SET SESSION TRANSACTION READ ONLY;
+START TRANSACTION;
+--error ER_CANT_EXECUTE_IN_READ_ONLY_TRANSACTION
+DELETE FROM t1;
+COMMIT;
+START TRANSACTION READ WRITE;
+DELETE FROM t1;
+COMMIT;
+
+SET SESSION TRANSACTION READ WRITE;
+SET TRANSACTION READ ONLY;
+START TRANSACTION;
+--error ER_CANT_EXECUTE_IN_READ_ONLY_TRANSACTION
+DELETE FROM t1;
+COMMIT;
+START TRANSACTION READ WRITE;
+DELETE FROM t1;
+COMMIT;
+
+START TRANSACTION READ ONLY;
+SELECT * FROM t1;
+COMMIT AND CHAIN;
+--error ER_CANT_EXECUTE_IN_READ_ONLY_TRANSACTION
+DELETE FROM t1;
+COMMIT;
+
+START TRANSACTION READ ONLY;
+SELECT * FROM t1;
+ROLLBACK AND CHAIN;
+--error ER_CANT_EXECUTE_IN_READ_ONLY_TRANSACTION
+DELETE FROM t1;
+COMMIT;
+
+DROP TABLE t1;
+
+--echo #
+--echo # Test 5: Test that reserved keyword ONLY is still allowed as
+--echo # identifier - both directly and in SPs.
+
+SET @only= 1;
+
+CREATE TABLE t1 (only INT);
+INSERT INTO t1 (only) values (1);
+SELECT only FROM t1 WHERE only = 1;
+DROP TABLE t1;
+
+DELIMITER |;
+CREATE PROCEDURE p1()
+BEGIN
+ DECLARE only INT DEFAULT 1;
+END|
+DELIMITER ;|
+
+CALL p1();
+
+DROP PROCEDURE p1;
+
+--echo #
+--echo # Test 6: Check that XA transactions obey default access mode.
+
+CREATE TABLE t1(a INT);
+
+SET TRANSACTION READ ONLY;
+XA START 'test1';
+--error ER_CANT_EXECUTE_IN_READ_ONLY_TRANSACTION
+INSERT INTO t1 VALUES (1);
+--error ER_CANT_EXECUTE_IN_READ_ONLY_TRANSACTION
+UPDATE t1 SET a=2;
+--error ER_CANT_EXECUTE_IN_READ_ONLY_TRANSACTION
+DELETE FROM t1;
+XA END 'test1';
+XA PREPARE 'test1';
+XA COMMIT 'test1';
+
+DROP TABLE t1;
+
+--echo #
+--echo # Test 7: SET TRANSACTION inside stored routines
+
+CREATE PROCEDURE p1() SET SESSION TRANSACTION READ ONLY;
+CALL p1();
+SELECT @@tx_read_only;
+SET SESSION TRANSACTION READ WRITE;
+DROP PROCEDURE p1;
+
+CREATE PROCEDURE p1() SET SESSION TRANSACTION READ ONLY,
+ ISOLATION LEVEL SERIALIZABLE;
+CALL p1();
+SELECT @@tx_read_only;
+SET SESSION TRANSACTION READ WRITE, ISOLATION LEVEL REPEATABLE READ;
+DROP PROCEDURE p1;
+
+delimiter |;
+CREATE FUNCTION f1() RETURNS INT
+BEGIN
+ SET SESSION TRANSACTION READ ONLY;
+ RETURN 1;
+END|
+delimiter ;|
+
+SELECT f1();
+SELECT @@tx_read_only;
+SET SESSION TRANSACTION READ WRITE;
+DROP FUNCTION f1;
+
+delimiter |;
+CREATE FUNCTION f1() RETURNS INT
+BEGIN
+ SET SESSION TRANSACTION ISOLATION LEVEL SERIALIZABLE, READ ONLY;
+ RETURN 1;
+END|
+delimiter ;|
+
+SELECT f1();
+SELECT @@tx_read_only;
+SET SESSION TRANSACTION ISOLATION LEVEL REPEATABLE READ, READ WRITE;
+DROP FUNCTION f1;
+
+--echo #
+--echo # Test 8: SET TRANSACTION and auto-commit
+
+SELECT @@autocommit;
+CREATE TABLE t1(a INT) engine=InnoDB;
+
+SET TRANSACTION READ ONLY;
+SELECT * FROM t1;
+--echo # This statement should work, since last statement committed.
+INSERT INTO t1 VALUES (1);
+
+DROP TABLE t1;
diff --git a/mysql-test/t/connect.test b/mysql-test/t/connect.test
index cfe4e80fcbd..fca588de8e8 100644
--- a/mysql-test/t/connect.test
+++ b/mysql-test/t/connect.test
@@ -327,17 +327,17 @@ if ($error)
--echo # against MySQL 5.1 server
--echo #
-GRANT ALL ON test.* TO 'Azundris12345678'@'localhost' IDENTIFIED BY 'test123';
+GRANT ALL ON test.* TO 'O1234567890123456789012345678901234567890123456789012345678901234567890123456789'@'localhost' IDENTIFIED BY 'test123';
FLUSH PRIVILEGES;
--replace_result $MASTER_MYSOCK MASTER_SOCKET $MASTER_MYPORT MASTER_PORT
-connect (con1,localhost,Azundris123456789,test123,test);
+connect (con1,localhost,O1234567890123456789012345678901234567890123456789012345678901234567890123456789x,test123,test);
disconnect con1;
connection default;
-DROP USER 'Azundris12345678'@'localhost';
+DROP USER 'O1234567890123456789012345678901234567890123456789012345678901234567890123456789'@'localhost';
FLUSH PRIVILEGES;
@@ -378,8 +378,8 @@ select user(), current_user();
disconnect pcon4;
#
-# lpbug#683112 Maria 5.2 incorrectly reports "(using password: NO)"
-# even when password is specified
+# lp:683112 Maria 5.2 incorrectly reports "(using password: NO)"
+# even when password is specified
#
# test "access denied" error for nonexisting user with and without a password
#
@@ -391,6 +391,31 @@ connect(pcon5,localhost,mysqltest_nouser,newpw,,$MASTER_MYPORT,);
connect(pcon5,localhost,mysqltest_nouser,,,$MASTER_MYPORT,);
connection default;
+
+#
+# MDEV-6253 MySQL Users Break when Migrating from MySQL 5.1 to MariaDB 10.0.10
+#
+# cannot connect when password is set and plugin=mysql_native_password
+#
+update mysql.user set password=authentication_string, authentication_string=''
+ where user like 'mysqltest_up_';
+select user, password, plugin, authentication_string from mysql.user
+ where user like 'mysqltest_up_';
+flush privileges;
+
+--replace_result $MASTER_MYSOCK MASTER_SOCKET $MASTER_MYPORT MASTER_PORT
+connect(pcon6,localhost,mysqltest_up1,bar,,$MASTER_MYPORT,);
+connection pcon6;
+select user(), current_user();
+disconnect pcon6;
+
+--replace_result $MASTER_MYSOCK MASTER_SOCKET $MASTER_MYPORT MASTER_PORT
+connect(pcon7,localhost,mysqltest_up2,oldpw,,$MASTER_MYPORT,);
+connection pcon7;
+select user(), current_user();
+disconnect pcon7;
+connection default;
+
DROP USER mysqltest_up1@'%';
DROP USER mysqltest_up2@'%';
diff --git a/mysql-test/t/create-big.test b/mysql-test/t/create-big.test
index 8d916f8da82..7f20a8b42af 100644
--- a/mysql-test/t/create-big.test
+++ b/mysql-test/t/create-big.test
@@ -420,9 +420,20 @@ set @a:=0;
set debug_sync='create_table_select_before_check_if_exists SIGNAL parked WAIT_FOR go';
--send create table if not exists t1 select 1 as i;
connection addconroot1;
-create trigger t1_bi before insert on t1 for each row set @a:=1;
+set debug_sync='now WAIT_FOR parked';
+--send create trigger t1_bi before insert on t1 for each row set @a:=1;
+connection addconroot2;
+# Wait until the above DROP TABLE is blocked due to CREATE TABLE
+let $wait_condition=
+ select count(*) = 1 from information_schema.processlist
+ where state = "Waiting for table metadata lock" and
+ info like "create trigger%";
+--source include/wait_condition.inc
+set debug_sync='now SIGNAL go';
connection default;
--reap
+connection addconroot1;
+--reap
connection default;
select @a;
select * from t1;
diff --git a/mysql-test/t/create.test b/mysql-test/t/create.test
index 0ffe90a2420..70acf745889 100644
--- a/mysql-test/t/create.test
+++ b/mysql-test/t/create.test
@@ -1,3 +1,4 @@
+call mtr.add_suppression("table or database name 't-1'");
#
# Check some special create statements.
#
@@ -55,10 +56,10 @@ create table a (`aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
#
# Some wrong defaults, so these creates should fail too (Bug #5902)
#
---error 1067
create table t1 (a datetime default now());
---error 1294
+drop table t1;
create table t1 (a datetime on update now());
+drop table t1;
--error 1067
create table t1 (a int default 100 auto_increment);
--error 1067
@@ -1559,29 +1560,26 @@ drop table t1,t2,t3;
--echo # -- End of Bug#45829
#
---echo # new table creation/renaming blocked if old encoded table present
+# new table creation/renaming is NOT blocked if old encoded table present
#
let $MYSQLD_DATADIR= `select @@datadir`;
-create table `t-1` (a int) engine=myisam;
-insert into `t-1` values (1);
-show tables;
-flush tables;
---echo convert table files in mysql 5.0 file name encoding
---copy_file $MYSQLD_DATADIR/test/t@002d1.MYD $MYSQLD_DATADIR/test/t-1.MYD
---copy_file $MYSQLD_DATADIR/test/t@002d1.MYI $MYSQLD_DATADIR/test/t-1.MYI
---copy_file $MYSQLD_DATADIR/test/t@002d1.frm $MYSQLD_DATADIR/test/t-1.frm
---remove_file $MYSQLD_DATADIR/test/t@002d1.MYD
---remove_file $MYSQLD_DATADIR/test/t@002d1.MYI
---remove_file $MYSQLD_DATADIR/test/t@002d1.frm
+create table `#mysql50#t-1` (a int) engine=myisam;
+insert into `#mysql50#t-1` values (1);
show tables;
---error ER_TABLE_EXISTS_ERROR
create table `t-1` (a int);
+show tables;
+# selects can distinguish between the two tables
+select * from `t-1`;
+select * from `#mysql50#t-1`;
+drop table `t-1`;
create table t1 (a int);
---error ER_TABLE_EXISTS_ERROR
alter table t1 rename `t-1`;
---error ER_TABLE_EXISTS_ERROR
+show tables;
+drop table `t-1`;
+create table t1 (a int);
rename table t1 to `t-1`;
-drop table `#mysql50#t-1`, t1;
+show tables;
+drop table `#mysql50#t-1`, `t-1`;
--echo
--echo End of 5.1 tests
@@ -2016,6 +2014,8 @@ create table t1 (a int, b int);
create table t1 (a int, b int) select 2,2;
--error ER_TABLE_EXISTS_ERROR
create table t1 like t2;
+--error ER_LOCK_WAIT_TIMEOUT
+create or replace table t1 (a int, b int) select 2,2;
disconnect user1;
connection default;
select * from t1;
@@ -2234,3 +2234,15 @@ alter table t1 add
drop table t1;
--echo End of 5.5 tests
+
+#
+# MDEV-4880 Attempt to create a table without columns produces ER_ILLEGAL_HA instead of ER_TABLE_MUST_HAVE_COLUMNS
+#
+--error ER_TABLE_MUST_HAVE_COLUMNS
+create table t1;
+
+#
+# MDEV-11231 Server crashes in check_duplicate_key on CREATE TABLE ... SELECT
+#
+create table t1 (i int, j int, key(i), key(i)) as select 1 as i, 2 as j;
+drop table t1;
diff --git a/mysql-test/t/create_or_replace-master.opt b/mysql-test/t/create_or_replace-master.opt
new file mode 100644
index 00000000000..e94228f2f33
--- /dev/null
+++ b/mysql-test/t/create_or_replace-master.opt
@@ -0,0 +1 @@
+--log-output=TABLE,FILE --general-log=1 --slow-query-log=1
diff --git a/mysql-test/t/create_or_replace.test b/mysql-test/t/create_or_replace.test
new file mode 100644
index 00000000000..b37417f39d0
--- /dev/null
+++ b/mysql-test/t/create_or_replace.test
@@ -0,0 +1,400 @@
+#
+# Check CREATE OR REPLACE TABLE
+#
+
+--source include/have_innodb.inc
+--source include/have_metadata_lock_info.inc
+--disable_warnings
+drop table if exists t1,t2,t3;
+--enable_warnings
+
+#
+# Create help table
+#
+
+CREATE TABLE t2 (a int);
+INSERT INTO t2 VALUES(1),(2),(3);
+
+--echo #
+--echo # Check first syntax and wrong usage
+--echo #
+
+--error ER_WRONG_USAGE
+CREATE OR REPLACE TABLE IF NOT EXISTS t1 (a int);
+--error ER_WRONG_USAGE
+create or replace trigger trg before insert on t1 for each row set @a:=1;
+
+# check that we don't try to create a log table in use
+--error ER_BAD_LOG_STATEMENT
+create or replace table mysql.general_log (a int);
+--error ER_BAD_LOG_STATEMENT
+create or replace table mysql.slow_log (a int);
+
+--echo #
+--echo # Usage when table doesn't exist
+--echo #
+
+CREATE OR REPLACE TABLE t1 (a int);
+--error ER_TABLE_EXISTS_ERROR
+CREATE TABLE t1 (a int);
+DROP TABLE t1;
+CREATE OR REPLACE TEMPORARY TABLE t1 (a int);
+--error ER_TABLE_EXISTS_ERROR
+CREATE TEMPORARY TABLE t1 (a int, b int, c int);
+DROP TEMPORARY TABLE t1;
+
+--echo #
+--echo # Testing with temporary tables
+--echo #
+
+CREATE OR REPLACE TABLE t1 (a int);
+CREATE OR REPLACE TEMPORARY TABLE t1 (a int);
+CREATE OR REPLACE TEMPORARY TABLE t1 (a int, b int);
+SHOW CREATE TABLE t1;
+DROP TEMPORARY TABLE t1;
+SHOW CREATE TABLE t1;
+DROP TABLE t1;
+
+# Test also with InnoDB
+create temporary table t1 (i int) engine=InnoDB;
+create or replace temporary table t1 (a int, b int) engine=InnoDB;
+create or replace temporary table t1 (j int);
+show create table t1;
+drop table t1;
+
+# Using lock tables on normal tables with create or replace on temp tables
+CREATE OR REPLACE TABLE t1 (a int);
+LOCK TABLES t1 write;
+CREATE OR REPLACE TEMPORARY TABLE t1 (a int);
+CREATE OR REPLACE TEMPORARY TABLE t1 (a int, b int);
+CREATE OR REPLACE TEMPORARY TABLE t1 (a int, b int) engine= innodb;
+CREATE OR REPLACE TEMPORARY TABLE t1 (a int) engine= innodb;
+CREATE OR REPLACE TEMPORARY TABLE t1 (a int, b int) engine=myisam;
+SHOW CREATE TABLE t1;
+DROP TEMPORARY TABLE t1;
+SHOW CREATE TABLE t1;
+# Verify that table is still locked
+--error ER_TABLE_NOT_LOCKED
+CREATE OR REPLACE TABLE t2 (a int);
+DROP TABLE t1;
+UNLOCK TABLES;
+
+#
+# Using CREATE SELECT
+#
+
+CREATE OR REPLACE TEMPORARY TABLE t1 (a int) SELECT * from t2;
+SELECT * FROM t1;
+CREATE OR REPLACE TEMPORARY TABLE t1 (b int) SELECT * from t2;
+SELECT * FROM t1;
+SHOW CREATE TABLE t1;
+DROP TABLE t1;
+CREATE TEMPORARY TABLE t1 AS SELECT a FROM t2;
+CREATE TEMPORARY TABLE IF NOT EXISTS t1(a int, b int) SELECT 1,2 FROM t2;
+DROP TABLE t1;
+
+CREATE TABLE t1 (a int);
+CREATE OR REPLACE TABLE t1 AS SELECT 1;
+SHOW CREATE TABLE t1;
+DROP TABLE t1;
+
+create table t1 (a int);
+--error ER_UPDATE_TABLE_USED
+create or replace table t1 as select * from t1;
+--error ER_UPDATE_TABLE_USED
+create or replace table t1 as select a from (select a from t1) as t3;
+--error ER_UPDATE_TABLE_USED
+create or replace table t1 as select a from t2 where t2.a in (select a from t1);
+drop table t1;
+
+--echo #
+--echo # Testing with normal tables
+--echo #
+
+CREATE OR REPLACE TABLE t1 (a int);
+CREATE OR REPLACE TABLE t1 (a int, b int);
+SHOW CREATE TABLE t1;
+DROP TABLE t1;
+
+CREATE TABLE t1 (a int) SELECT * from t2;
+SELECT * FROM t1;
+TRUNCATE TABLE t1;
+CREATE TABLE IF NOT EXISTS t1 (a int) SELECT * from t2;
+SELECT * FROM t1;
+DROP TABLE t1;
+
+CREATE TABLE t1 (i int);
+CREATE OR REPLACE TABLE t1 AS SELECT 1;
+SHOW CREATE TABLE t1;
+DROP TABLE t1;
+
+# Using lock tables with CREATE OR REPLACE
+CREATE OR REPLACE TABLE t1 (a int);
+LOCK TABLES t1 write,t2 write;
+CREATE OR REPLACE TABLE t1 (a int, b int);
+# Verify if table is still locked
+SELECT * FROM t1;
+INSERT INTO t1 values(1,1);
+CREATE OR REPLACE TABLE t1 (a int, b int, c int);
+INSERT INTO t1 values(1,1,1);
+--error ER_TABLE_NOT_LOCKED
+CREATE OR REPLACE TABLE t3 (a int);
+UNLOCK TABLES;
+DROP TABLE t1;
+
+# Using lock tables with CREATE OR REPLACE ... SELECT
+CREATE OR REPLACE TABLE t1 (a int);
+LOCK TABLES t1 write,t2 write;
+CREATE OR REPLACE TABLE t1 (a int, b int) select a,1 from t2;
+# Verify if table is still locked
+SELECT * FROM t2;
+SELECT * FROM t1;
+SELECT * FROM t1;
+INSERT INTO t1 values(1,1,1);
+CREATE OR REPLACE TABLE t1 (a int, b int, c int, d int);
+INSERT INTO t1 values(1,1,1,1);
+--error ER_TABLE_NOT_LOCKED
+CREATE OR REPLACE TABLE t3 (a int);
+UNLOCK TABLES;
+DROP TABLE t1;
+
+CREATE OR REPLACE TABLE t1 (a int);
+LOCK TABLES t1 write,t2 write, t1 as t1_read read;
+CREATE OR REPLACE TABLE t1 (a int, b int) select a,1 from t2;
+SELECT * FROM t1;
+SELECT * FROM t2;
+--error ER_TABLE_NOT_LOCKED
+SELECT * FROM t1 as t1_read;
+DROP TABLE t1;
+UNLOCK TABLES;
+
+CREATE OR REPLACE TABLE t1 (a int);
+LOCK TABLE t1 WRITE;
+CREATE OR REPLACE TABLE t1 AS SELECT 1;
+SELECT * from t1;
+--error ER_TABLE_NOT_LOCKED
+SELECT * from t2;
+DROP TABLE t1;
+
+--echo #
+--echo # Test also with InnoDB (transactional engine)
+--echo #
+
+create table t1 (i int) engine=innodb;
+lock table t1 write;
+create or replace table t1 (j int);
+unlock tables;
+show create table t1;
+drop table t1;
+
+create table t1 (i int) engine=InnoDB;
+lock table t1 write, t2 write;
+create or replace table t1 (j int) engine=innodb;
+unlock tables;
+drop table t1;
+
+create table t1 (i int) engine=InnoDB;
+create table t3 (i int) engine=InnoDB;
+insert into t3 values(1),(2),(3);
+create table t4 (i int) engine=InnoDB;
+insert into t4 values(1);
+lock table t1 write, t2 write, t3 write, t4 write;
+create or replace table t1 (a int, i int) engine=innodb select t2.a,t3.i from t2,t3;
+select * from t4;
+unlock tables;
+select * from t1 order by a,i;
+drop table t1,t3,t4;
+
+--echo #
+--echo # Test the meta data locks are freed properly
+--echo #
+
+create database mysqltest2;
+
+drop table if exists test.t1,mysqltest2.t2;
+create table test.t1 (i int);
+create table mysqltest2.t2 like test.t1;
+lock table test.t1 write, mysqltest2.t2 write;
+--replace_column 1 #
+--sorted_result
+select * from information_schema.metadata_lock_info;
+--error ER_TABLE_MUST_HAVE_COLUMNS
+create or replace table test.t1;
+show tables;
+--replace_column 1 #
+--sorted_result
+select * from information_schema.metadata_lock_info;
+--error ER_TABLE_MUST_HAVE_COLUMNS
+create or replace table mysqltest2.t2;
+--replace_column 1 #
+--sorted_result
+select * from information_schema.metadata_lock_info;
+create table t1 (i int);
+drop table t1;
+
+create table test.t1 (i int);
+create table mysqltest2.t2 like test.t1;
+lock table test.t1 write, mysqltest2.t2 write;
+--replace_column 1 #
+--sorted_result
+select * from information_schema.metadata_lock_info;
+--error ER_DUP_FIELDNAME
+create or replace table test.t1 (a int) select 1 as 'a', 2 as 'a';
+show tables;
+--replace_column 1 #
+--sorted_result
+select * from information_schema.metadata_lock_info;
+--error ER_DUP_FIELDNAME
+create or replace table mysqltest2.t2 (a int) select 1 as 'a', 2 as 'a';
+--replace_column 1 #
+--sorted_result
+select * from information_schema.metadata_lock_info;
+create table t1 (i int);
+drop table t1;
+drop database mysqltest2;
+
+--echo #
+--echo # Testing CREATE .. LIKE
+--echo #
+
+create or replace table t1 like t2;
+create or replace table t1 like t2;
+show create table t1;
+drop table t1;
+create table t1 (b int);
+lock tables t1 write, t2 read;
+create or replace table t1 like t2;
+SELECT * FROM t1;
+INSERT INTO t1 values(1);
+CREATE OR REPLACE TABLE t1 like t2;
+INSERT INTO t1 values(2);
+unlock tables;
+show create table t1;
+drop table t1;
+
+create or replace table t1 like t2;
+--error ER_NONUNIQ_TABLE
+create or replace table t1 like t1;
+drop table t1;
+
+CREATE TEMPORARY TABLE t1 like t2;
+--error ER_NONUNIQ_TABLE
+CREATE OR REPLACE TABLE t1 like t1;
+--error ER_NONUNIQ_TABLE
+CREATE OR REPLACE TABLE t1 like t1;
+drop table t1;
+
+CREATE TEMPORARY TABLE t1 like t2;
+CREATE OR REPLACE TEMPORARY TABLE t3 like t1;
+--error ER_NONUNIQ_TABLE
+CREATE OR REPLACE TEMPORARY TABLE t3 like t3;
+drop table t1,t3;
+
+--echo #
+--echo # Test with prepared statements
+--echo #
+
+prepare stmt1 from 'create or replace table t1 select * from t2';
+execute stmt1;
+select * from t1;
+execute stmt1;
+select * from t1;
+drop table t1;
+execute stmt1;
+select * from t1;
+deallocate prepare stmt1;
+drop table t1;
+
+--echo #
+--echo # Test with views
+--echo #
+
+create view t1 as select 1;
+create table if not exists t1 (a int);
+--error ER_IT_IS_A_VIEW
+create or replace table t1 (a int);
+--error ER_IT_IS_A_VIEW
+drop table t1;
+drop view t1;
+
+--echo #
+--echo # MDEV-5602 CREATE OR REPLACE obtains stricter locks than the
+--echo # connection had before
+--echo #
+
+create table t1 (a int);
+lock table t1 write, t2 read;
+--replace_column 1 #
+--sorted_result
+select * from information_schema.metadata_lock_info;
+create or replace table t1 (i int);
+--replace_column 1 #
+--sorted_result
+select * from information_schema.metadata_lock_info;
+create or replace table t1 like t2;
+--replace_column 1 #
+--sorted_result
+select * from information_schema.metadata_lock_info;
+create or replace table t1 select 1 as f1;
+--replace_column 1 #
+--sorted_result
+select * from information_schema.metadata_lock_info;
+drop table t1;
+unlock tables;
+
+--echo #
+--echo # MDEV-6560
+--echo # Assertion `! is_set() ' failed in Diagnostics_area::set_ok_status
+--echo #
+
+CREATE TABLE t1 (col_int_nokey INT) ENGINE=InnoDB;
+
+CREATE OR REPLACE TEMPORARY TABLE tmp LIKE t1;
+LOCK TABLE t1 WRITE;
+
+--connect (con1,localhost,root,,test)
+--let $con_id = `SELECT CONNECTION_ID()`
+--send CREATE OR REPLACE TABLE t1 LIKE tmp
+--connection default
+let $wait_condition= SELECT COUNT(*)=1 FROM information_schema.processlist
+ WHERE state= 'Waiting for table metadata lock';
+--source include/wait_condition.inc
+--replace_result $con_id con_id
+--eval KILL QUERY $con_id
+
+--connection con1
+--error ER_QUERY_INTERRUPTED
+--reap
+--send CREATE OR REPLACE TABLE t1 (a int)
+
+--connection default
+let $wait_condition= SELECT COUNT(*)=1 FROM information_schema.processlist
+ WHERE state= 'Waiting for table metadata lock';
+--source include/wait_condition.inc
+--replace_result $con_id con_id
+--eval KILL QUERY $con_id
+
+--connection con1
+--error ER_QUERY_INTERRUPTED
+--reap
+--disconnect con1
+--connection default
+
+drop table t1;
+
+#
+# Cleanup
+#
+DROP TABLE t2;
+
+--echo #
+--echo # MDEV-10824 - Crash in CREATE OR REPLACE TABLE t1 AS SELECT spfunc()
+--echo #
+CREATE TABLE t1(a INT);
+CREATE FUNCTION f1() RETURNS VARCHAR(16383) RETURN 'test';
+CREATE OR REPLACE TABLE t1 AS SELECT f1();
+LOCK TABLE t1 WRITE;
+CREATE OR REPLACE TABLE t1 AS SELECT f1();
+UNLOCK TABLES;
+DROP FUNCTION f1;
+DROP TABLE t1;
diff --git a/mysql-test/t/create_or_replace2.test b/mysql-test/t/create_or_replace2.test
new file mode 100644
index 00000000000..da451796e12
--- /dev/null
+++ b/mysql-test/t/create_or_replace2.test
@@ -0,0 +1,35 @@
+#
+# Check CREATE OR REPLACE TABLE for test that requires DEBUG
+#
+
+--source include/have_debug.inc
+--source include/have_binlog_format_row.inc
+--source include/have_xtradb.inc
+--source include/master-slave.inc
+
+--disable_warnings
+drop table if exists t1;
+--enable_warnings
+SET @old_debug= @@session.debug;
+
+#
+# MDEV-5854
+# Interrupted CREATE OR REPLACE is written into binlog, and in a wrong format
+#
+
+CREATE TABLE t1 (i INT, KEY(i)) ENGINE=InnoDB;
+CREATE OR REPLACE TEMPORARY TABLE tmp (a int, b int, key(a)) engine=myisam;
+set debug_dbug='+d,send_kill_after_delete';
+CREATE OR REPLACE TABLE t1 LIKE tmp;
+set debug_dbug=@old_debug;
+SHOW TABLES;
+show create table t1;
+--sync_slave_with_master
+SHOW TABLES;
+--connection master
+
+--disable_warnings
+drop temporary table if exists tmp;
+--enable_warnings
+drop table t1;
+--source include/rpl_end.inc
diff --git a/mysql-test/t/ctype_big5.test b/mysql-test/t/ctype_big5.test
index b024420dee3..5c0bdff4633 100644
--- a/mysql-test/t/ctype_big5.test
+++ b/mysql-test/t/ctype_big5.test
@@ -17,6 +17,7 @@ SET collation_connection='big5_chinese_ci';
-- source include/ctype_innodb_like.inc
-- source include/ctype_like_escape.inc
-- source include/ctype_like_range_f1f2.inc
+-- source include/ctype_ascii_order.inc
SET collation_connection='big5_bin';
-- source include/ctype_filesort.inc
-- source include/ctype_innodb_like.inc
@@ -145,3 +146,104 @@ DROP TABLE t1;
--echo #
--echo # End of 5.5 tests
--echo #
+
+
+--echo #
+--echo # Start of 5.6 tests
+--echo #
+
+--echo #
+--echo # WL#3664 WEIGHT_STRING
+--echo #
+
+set names big5;
+--source include/weight_string.inc
+--source include/weight_string_l1.inc
+--source include/weight_string_A1A1.inc
+
+set collation_connection=big5_bin;
+--source include/weight_string.inc
+--source include/weight_string_l1.inc
+--source include/weight_string_A1A1.inc
+
+--echo #
+--echo # End of 5.6 tests
+--echo #
+
+--echo #
+--echo # Start of 10.0 tests
+--echo #
+
+let $ctype_unescape_combinations=selected;
+--source include/ctype_unescape.inc
+
+--character_set big5
+SET NAMES big5;
+--source include/ctype_E05C.inc
+
+
+#
+# Checking unassigned character 0xC840 in an ENUM
+#
+
+SET NAMES big5;
+CREATE TABLE t1 (a ENUM('È@') CHARACTER SET big5);
+SHOW CREATE TABLE t1;
+INSERT INTO t1 VALUES ('È@');
+INSERT INTO t1 VALUES (_big5 0xC840);
+INSERT INTO t1 VALUES (0xC840);
+SELECT HEX(a),a FROM t1;
+DROP TABLE t1;
+
+SET NAMES binary;
+CREATE TABLE t1 (a ENUM('È@') CHARACTER SET big5);
+SHOW CREATE TABLE t1;
+INSERT INTO t1 VALUES ('È@');
+INSERT INTO t1 VALUES (_big5 0xC840);
+INSERT INTO t1 VALUES (0xC840);
+SELECT HEX(a),a FROM t1;
+DROP TABLE t1;
+
+
+#
+# Checking unassigned character in CHAR, VARCHAR, TEXT
+#
+
+SET NAMES big5;
+CREATE TABLE t1 (
+ c1 CHAR(10) CHARACTER SET big5,
+ c2 VARCHAR(10) CHARACTER SET big5,
+ c3 TEXT CHARACTER SET big5
+);
+INSERT INTO t1 VALUES ('È@','È@','È@');
+INSERT INTO t1 VALUES (_big5 0xC840,_big5 0xC840,_big5 0xC840);
+INSERT INTO t1 VALUES (0xC840,0xC840,0xC840);
+SELECT HEX(c1),HEX(c2),HEX(c3) FROM t1;
+DROP TABLE t1;
+
+SET NAMES binary;
+CREATE TABLE t1 (
+ c1 CHAR(10) CHARACTER SET big5,
+ c2 VARCHAR(10) CHARACTER SET big5,
+ c3 TEXT CHARACTER SET big5
+);
+INSERT INTO t1 VALUES ('È@','È@','È@');
+INSERT INTO t1 VALUES (_big5 0xC840,_big5 0xC840,_big5 0xC840);
+INSERT INTO t1 VALUES (0xC840,0xC840,0xC840);
+SELECT HEX(c1),HEX(c2),HEX(c3) FROM t1;
+DROP TABLE t1;
+
+
+#
+# Checking binary->big5 conversion of an unassigned character 0xC840 in optimizer
+#
+SET NAMES binary;
+CREATE TABLE t1 (a VARCHAR(10) CHARACTER SET big5, KEY(a));
+INSERT INTO t1 VALUES (0xC840),(0xC841),(0xC842);
+SELECT HEX(a) FROM t1 WHERE a='È@';
+SELECT HEX(a) FROM t1 IGNORE KEY(a) WHERE a='È@';
+DROP TABLE t1;
+
+--echo #
+--echo # End of 10.0 tests
+--echo #
diff --git a/mysql-test/t/ctype_binary.test b/mysql-test/t/ctype_binary.test
index 8b57854de83..3d3f90b444b 100644
--- a/mysql-test/t/ctype_binary.test
+++ b/mysql-test/t/ctype_binary.test
@@ -10,3 +10,20 @@ set names binary;
--echo #
--echo # End of 5.5 tests
--echo #
+
+
+--echo #
+--echo # Start of 10.0 tests
+--echo #
+
+SET NAMES binary;
+--source include/ctype_like_cond_propagation.inc
+
+--echo #
+--echo # MDEV-7629 Regression: Bit and hex string literals changed column names in 10.0.14
+--echo #
+SELECT _binary 0x7E, _binary X'7E', _binary B'01111110';
+
+--echo #
+--echo # End of 10.0 tests
+--echo #
diff --git a/mysql-test/t/ctype_collate.test b/mysql-test/t/ctype_collate.test
index cb2113277b9..23d34deb981 100644
--- a/mysql-test/t/ctype_collate.test
+++ b/mysql-test/t/ctype_collate.test
@@ -255,3 +255,56 @@ select case _latin1'a' when _latin2'b' then 1 when _latin5'c' collate
latin5_turkish_ci then 2 else 3 end;
select concat(_latin1'a',_latin2'b',_latin5'c' collate latin5_turkish_ci);
+
+
+--echo #
+--echo # Bug#11765016 57926: ILLEGAL MIX OF COLLATIONS FOR OPERATION 'UNION' .. USING CONCAT/FUNCTION/
+--echo # Not a bug: only adding coverage tests
+--echo #
+SET NAMES latin1 COLLATE latin1_german2_ci;
+CREATE DATABASE test1 DEFAULT CHARACTER SET latin1 COLLATE latin1_german2_ci;
+USE test1;
+DELIMITER //;
+--echo #
+--echo # Using "COLLATE latin1_swedish_ci" as the default collation for latin1
+--echo #
+CREATE FUNCTION `getText`() RETURNS varchar(20) CHARSET latin1
+BEGIN
+ RETURN "Testtext";
+END;//
+DELIMITER ;//
+SELECT getText(), CHARSET(getText()), COLLATION(getText()), COERCIBILITY(getText());
+--error ER_CANT_AGGREGATE_NCOLLATIONS
+CREATE TABLE t1 AS SELECT ' - ' AS a UNION SELECT getText();
+DROP FUNCTION getText;
+--echo #
+--echo # Using "CHARACTER SET latin1 COLLATE latin1_german2_ci" as the database defaults
+--echo #
+DELIMITER //;
+CREATE FUNCTION `getText`() RETURNS varchar(20)
+BEGIN
+ RETURN "Testtext";
+END;//
+DELIMITER ;//
+SELECT getText(), CHARSET(getText()), COLLATION(getText()), COERCIBILITY(getText());
+CREATE TABLE t1 AS SELECT ' - ' AS a UNION SELECT getText();
+SHOW CREATE TABLE t1;
+DROP TABLE t1;
+DROP FUNCTION getText;
+--echo #
+--echo # Using explicit "CHARACTER SET latin1 COLLATE latin1_german2_ci"
+--echo #
+DELIMITER //;
+CREATE FUNCTION `getText`() RETURNS varchar(20) CHARACTER SET latin1 COLLATE latin1_german2_ci
+BEGIN
+ RETURN "Testtext";
+END;//
+DELIMITER ;//
+SELECT getText(), CHARSET(getText()), COLLATION(getText()), COERCIBILITY(getText());
+CREATE TABLE t1 AS SELECT ' - ' AS a UNION SELECT getText();
+SHOW CREATE TABLE t1;
+DROP TABLE t1;
+DROP FUNCTION getText;
+DROP DATABASE test1;
+USE test;
+SET NAMES latin1;
diff --git a/mysql-test/t/ctype_cp1250_ch.test b/mysql-test/t/ctype_cp1250_ch.test
index a4c59f494a7..f5c241fb679 100644
--- a/mysql-test/t/ctype_cp1250_ch.test
+++ b/mysql-test/t/ctype_cp1250_ch.test
@@ -71,6 +71,10 @@ insert into t1 values("ááèè");
select a from t1 where a like "abcdefghá";
drop table t1;
+set names cp1250 collate cp1250_czech_cs;
+--source include/ctype_pad_space.inc
+--source include/ctype_filesort.inc
+
# End of 4.1 tests
#
@@ -82,3 +86,30 @@ drop table t1;
--error 1649
set global LC_MESSAGES=convert((@@global.log_bin_trust_function_creators)
using cp1250);
+
+
+--echo #
+--echo # Start of 5.6 tests
+--echo #
+
+--echo #
+--echo # WL#3664 WEIGHT_STRING
+--echo #
+
+--echo #
+--echo # Note:
+--echo # cp1250_czech_cs does not support WEIGHT_STRING in full extent
+--echo #
+
+set names cp1250 collate cp1250_czech_cs;
+--source include/weight_string.inc
+--source include/weight_string_euro.inc
+--source include/weight_string_chde.inc
+--source include/weight_string_l1.inc
+--source include/weight_string_l2.inc
+--source include/weight_string_l12.inc
+
+--echo #
+--echo # End of 5.6 tests
+--echo #
+
diff --git a/mysql-test/t/ctype_cp932_binlog_stm.test b/mysql-test/t/ctype_cp932_binlog_stm.test
index e7b6fe1a014..304c9f5d05c 100644
--- a/mysql-test/t/ctype_cp932_binlog_stm.test
+++ b/mysql-test/t/ctype_cp932_binlog_stm.test
@@ -28,8 +28,8 @@ CALL bug18293("Foo's a Bar", _cp932 0xED40ED41ED42, 47.93)|
SELECT HEX(s1),HEX(s2),d FROM t4|
DROP PROCEDURE bug18293|
DROP TABLE t4|
-source include/show_binlog_events.inc|
delimiter ;|
+source include/show_binlog_events.inc;
--echo End of 5.0 tests
@@ -162,3 +162,37 @@ DROP TABLE t1;
--echo #
--echo # End of 5.5 tests
--echo #
+
+
+--echo #
+--echo # Start of 5.6 tests
+--echo #
+
+--echo #
+--echo # WL#3664 WEIGHT_STRING
+--echo #
+
+set names cp932;
+--source include/weight_string.inc
+--source include/weight_string_l1.inc
+--source include/weight_string_8140.inc
+
+set collation_connection=cp932_bin;
+--source include/weight_string.inc
+--source include/weight_string_l1.inc
+--source include/weight_string_8140.inc
+
+--echo #
+--echo # End of 5.6 tests
+--echo #
+
+
+--echo #
+--echo # Start of 10.0 tests
+--echo #
+SET NAMES cp932;
+--source include/ctype_E05C.inc
+
+--echo #
+--echo # End of 10.0 tests
+--echo #
diff --git a/mysql-test/t/ctype_create.test b/mysql-test/t/ctype_create.test
index 060c09a0459..61fc5292094 100644
--- a/mysql-test/t/ctype_create.test
+++ b/mysql-test/t/ctype_create.test
@@ -105,3 +105,39 @@ ALTER DATABASE DEFAULT CHARACTER SET latin2;
ALTER DATABASE aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa DEFAULT CHARACTER SET latin2;
--error 1102
ALTER DATABASE `` DEFAULT CHARACTER SET latin2;
+USE test;
+
+--echo #
+--echo # Start of 10.0 tests
+--echo #
+
+--echo #
+--echo # MDEV-7387 Alter table xxx CHARACTER SET utf8, CONVERT TO CHARACTER SET latin1 should fail
+--echo #
+--error ER_CONFLICTING_DECLARATIONS
+CREATE TABLE t1 (a VARCHAR(10)) CHARACTER SET DEFAULT, CHARACTER SET utf8;
+--error ER_CONFLICTING_DECLARATIONS
+CREATE TABLE t1 (a VARCHAR(10)) CHARACTER SET utf8, CHARACTER SET DEFAULT;
+CREATE TABLE t1 (a VARCHAR(10)) CHARACTER SET utf8, CHARACTER SET utf8;
+DROP TABLE t1;
+CREATE TABLE t1 (a VARCHAR(10)) CHARACTER SET DEFAULT, CHARACTER SET DEFAULT;
+DROP TABLE t1;
+
+CREATE TABLE t1 (a VARCHAR(10) CHARACTER SET latin1, b VARCHAR(10) CHARACTER SET utf8);
+--error ER_CONFLICTING_DECLARATIONS
+ALTER TABLE t1 CONVERT TO CHARACTER SET utf8, CHARACTER SET latin1;
+--error ER_CONFLICTING_DECLARATIONS
+ALTER TABLE t1 CONVERT TO CHARACTER SET utf8, CHARACTER SET DEFAULT;
+--error ER_CONFLICTING_DECLARATIONS
+ALTER TABLE t1 CONVERT TO CHARACTER SET latin1, CHARACTER SET utf8;
+--error ER_CONFLICTING_DECLARATIONS
+ALTER TABLE t1 CONVERT TO CHARACTER SET latin1, CHARACTER SET DEFAULT;
+--error ER_CONFLICTING_DECLARATIONS
+ALTER TABLE t1 CONVERT TO CHARACTER SET DEFAULT, CHARACTER SET utf8;
+--error ER_CONFLICTING_DECLARATIONS
+ALTER TABLE t1 CONVERT TO CHARACTER SET DEFAULT, CHARACTER SET latin1;
+DROP TABLE t1;
+
+--echo #
+--echo # End of 10.0 tests
+--echo #
diff --git a/mysql-test/t/ctype_eucjpms.test b/mysql-test/t/ctype_eucjpms.test
index fea48061c69..49ca81850ed 100644
--- a/mysql-test/t/ctype_eucjpms.test
+++ b/mysql-test/t/ctype_eucjpms.test
@@ -494,3 +494,49 @@ DROP TABLE t1;
--echo #
--echo # End of 5.5 tests
--echo #
+
+--echo #
+--echo # Start of 5.6 tests
+--echo #
+
+--echo #
+--echo # WL#3664 WEIGHT_STRING
+--echo #
+
+set names eucjpms;
+--source include/weight_string.inc
+--source include/weight_string_l1.inc
+--source include/weight_string_A1A1.inc
+--source include/weight_string_8EA1.inc
+--source include/weight_string_8FA2C3.inc
+
+set collation_connection=eucjpms_bin;
+--source include/weight_string.inc
+--source include/weight_string_l1.inc
+--source include/weight_string_A1A1.inc
+--source include/weight_string_8EA1.inc
+--source include/weight_string_8FA2C3.inc
+
+--echo #
+--echo # End of 5.6 tests
+--echo #
+
+
+--echo #
+--echo # Start of 10.0 tests
+--echo #
+
+--echo #
+--echo # MDEV-6776 ujis and eucjmps erroneously accept 0x8EA0 as a valid byte sequence
+--echo #
+CREATE TABLE t1 (a VARCHAR(10) CHARACTER SET eucjpms);
+INSERT INTO t1 VALUES (0x8EA0);
+SELECT HEX(a), CHAR_LENGTH(a) FROM t1;
+DROP TABLE t1;
+--error ER_INVALID_CHARACTER_STRING
+SELECT _eucjpms 0x8EA0;
+
+
+--echo #
+--echo # End of 10.0 tests
+--echo #
diff --git a/mysql-test/t/ctype_euckr.test b/mysql-test/t/ctype_euckr.test
index 3a88e8ac715..155b8ebed00 100644
--- a/mysql-test/t/ctype_euckr.test
+++ b/mysql-test/t/ctype_euckr.test
@@ -174,3 +174,26 @@ DROP TABLE t1;
--echo #
--echo # End of 5.5 tests
--echo #
+
+
+--echo #
+--echo # Start of 5.6 tests
+--echo #
+
+--echo #
+--echo # WL#3664 WEIGHT_STRING
+--echo #
+set names euckr;
+--source include/weight_string.inc
+--source include/weight_string_l1.inc
+--source include/weight_string_A1A1.inc
+
+set collation_connection=euckr_bin;
+--source include/weight_string.inc
+--source include/weight_string_l1.inc
+--source include/weight_string_A1A1.inc
+
+--echo #
+--echo # End of 5.6 tests
+--echo #
+
diff --git a/mysql-test/t/ctype_gb2312.test b/mysql-test/t/ctype_gb2312.test
index f092a0a501f..e3dd448f54c 100644
--- a/mysql-test/t/ctype_gb2312.test
+++ b/mysql-test/t/ctype_gb2312.test
@@ -17,6 +17,7 @@ SET collation_connection='gb2312_chinese_ci';
-- source include/ctype_innodb_like.inc
-- source include/ctype_like_escape.inc
-- source include/ctype_like_range_f1f2.inc
+-- source include/ctype_ascii_order.inc
SET collation_connection='gb2312_bin';
-- source include/ctype_filesort.inc
-- source include/ctype_innodb_like.inc
@@ -124,3 +125,38 @@ DROP TABLE t1;
--echo #
--echo # End of 5.5 tests
--echo #
+
+
+
+--echo #
+--echo # Start of 5.6 tests
+--echo #
+
+--echo #
+--echo # WL#3664 WEIGHT_STRING
+--echo #
+
+set names gb2312;
+--source include/weight_string.inc
+--source include/weight_string_l1.inc
+--source include/weight_string_A1A1.inc
+
+set collation_connection=gb2312_bin;
+--source include/weight_string.inc
+--source include/weight_string_l1.inc
+--source include/weight_string_A1A1.inc
+
+--echo #
+--echo # End of 5.6 tests
+--echo #
+
+--echo #
+--echo # Start of 10.0 tests
+--echo #
+
+let $ctype_unescape_combinations=selected;
+--source include/ctype_unescape.inc
+
+--echo #
+--echo # End of 10.0 tests
+--echo #
diff --git a/mysql-test/t/ctype_gbk.test b/mysql-test/t/ctype_gbk.test
index b9e25e97a3c..454377d98a7 100644
--- a/mysql-test/t/ctype_gbk.test
+++ b/mysql-test/t/ctype_gbk.test
@@ -17,6 +17,7 @@ SET collation_connection='gbk_chinese_ci';
-- source include/ctype_innodb_like.inc
-- source include/ctype_like_escape.inc
-- source include/ctype_like_range_f1f2.inc
+-- source include/ctype_ascii_order.inc
SET collation_connection='gbk_bin';
-- source include/ctype_filesort.inc
-- source include/ctype_innodb_like.inc
@@ -159,3 +160,60 @@ DROP TABLE t1;
--echo #
--echo # End of 5.5 tests
--echo #
+
+
+--echo #
+--echo # Start of 5.6 tests
+--echo #
+
+--echo #
+--echo # WL#3664 WEIGHT_STRING
+--echo #
+
+set names gbk;
+--source include/weight_string.inc
+--source include/weight_string_l1.inc
+--source include/weight_string_A1A1.inc
+--source include/weight_string_8140.inc
+--source include/weight_string_8EA1.inc
+
+set collation_connection=gbk_bin;
+--source include/weight_string.inc
+--source include/weight_string_l1.inc
+--source include/weight_string_A1A1.inc
+--source include/weight_string_8140.inc
+--source include/weight_string_8EA1.inc
+
+--echo #
+--echo # End of 5.6 tests
+--echo #
+
+--echo #
+--echo # Start of 10.0 tests
+--echo #
+
+let $ctype_unescape_combinations=selected;
+--source include/ctype_unescape.inc
+
+--character_set gbk
+SET NAMES gbk;
+--source include/ctype_E05C.inc
+
+--echo #
+--echo # MDEV-9886 Illegal mix of collations with a view comparing a field to a binary constant
+--echo #
+
+SET NAMES latin1;
+CREATE TABLE t1 (a TEXT CHARACTER SET gbk);
+INSERT INTO t1 VALUES (0xEE5D);
+SELECT a<>0xEE5D AS a FROM t1;
+CREATE VIEW v1 AS SELECT a<>0xEE5D AS a FROM t1;
+SHOW CREATE VIEW v1;
+SELECT * FROM v1;
+DROP VIEW v1;
+DROP TABLE t1;
+
+
+--echo #
+--echo # End of 10.0 tests
+--echo #
diff --git a/mysql-test/t/ctype_latin1.test b/mysql-test/t/ctype_latin1.test
index aa66c8132e3..8a188b71e24 100644
--- a/mysql-test/t/ctype_latin1.test
+++ b/mysql-test/t/ctype_latin1.test
@@ -166,3 +166,101 @@ EXPLAIN EXTENDED SELECT 'abcdó', _latin1'abcdó', _utf8'abcdó';
--echo #
--echo # End of 5.5 tests
--echo #
+
+
+
+--echo #
+--echo # Start of 5.6 tests
+--echo #
+
+--echo #
+--echo # WL#3664 WEIGHT_STRING
+--echo #
+
+set @@collation_connection=latin1_swedish_ci;
+--source include/weight_string.inc
+--source include/weight_string_euro.inc
+--source include/weight_string_l1.inc
+
+set @@collation_connection=latin1_bin;
+--source include/weight_string.inc
+--source include/weight_string_euro.inc
+--source include/weight_string_l1.inc
+
+set @@collation_connection=latin1_general_cs;
+--source include/weight_string.inc
+--source include/weight_string_euro.inc
+--source include/weight_string_l1.inc
+
+set @@collation_connection=binary;
+--source include/weight_string.inc
+--source include/weight_string_euro.inc
+--source include/weight_string_l1.inc
+
+set names latin1;
+
+--echo #
+--echo # End of 5.6 tests
+--echo #
+
+--echo #
+--echo # Start of 10.0 tests
+--echo #
+
+let $ctype_unescape_combinations=selected;
+--source include/ctype_unescape.inc
+
+SET NAMES latin1;
+--source include/ctype_like_cond_propagation.inc
+
+SET NAMES latin1 COLLATE latin1_bin;
+--source include/ctype_like_cond_propagation.inc
+
+
+--echo #
+--echo # MDEV-6752 Trailing incomplete characters are not replaced to question marks on conversion
+--echo #
+SET NAMES utf8, character_set_connection=latin1;
+SELECT 'Â';
+SELECT HEX('Â');
+SELECT HEX(CAST('Â' AS CHAR CHARACTER SET utf8));
+SELECT HEX(CAST('Â' AS CHAR CHARACTER SET latin1));
+SELECT HEX(CONVERT('Â' USING utf8));
+SELECT HEX(CONVERT('Â' USING latin1));
+SELECT 'Âx';
+SELECT HEX('Âx');
+SELECT HEX(CAST('Âx' AS CHAR CHARACTER SET utf8));
+SELECT HEX(CAST('Âx' AS CHAR CHARACTER SET latin1));
+SELECT HEX(CONVERT('Âx' USING utf8));
+SELECT HEX(CONVERT('Âx' USING latin1));
+SET NAMES utf8;
+CREATE TABLE t1 (a VARCHAR(10) CHARACTER SET latin1);
+INSERT INTO t1 VALUES ('Â'),('Â#');
+SHOW WARNINGS;
+SELECT HEX(a),a FROM t1;
+DROP TABLE t1;
+
+--echo #
+--echo # MDEV-7629 Regression: Bit and hex string literals changed column names in 10.0.14
+--echo #
+SELECT _latin1 0x7E, _latin1 X'7E', _latin1 B'01111110';
+
+
+--echo #
+--echo # MDEV-9886 Illegal mix of collations with a view comparing a field to a binary constant
+--echo #
+
+SET NAMES latin1;
+CREATE TABLE t1 (a TEXT CHARACTER SET latin1);
+INSERT INTO t1 VALUES (0xC0);
+SELECT a<>0xEE5D AS a FROM t1;
+CREATE VIEW v1 AS SELECT a<>0xC0 AS a FROM t1;
+SHOW CREATE VIEW v1;
+SELECT * FROM v1;
+DROP VIEW v1;
+DROP TABLE t1;
+
+
+--echo #
+--echo # End of 10.0 tests
+--echo #
diff --git a/mysql-test/t/ctype_latin1_de.test b/mysql-test/t/ctype_latin1_de.test
index 1efbfa4a3ae..29a52c36db6 100644
--- a/mysql-test/t/ctype_latin1_de.test
+++ b/mysql-test/t/ctype_latin1_de.test
@@ -143,3 +143,40 @@ create table t1 (s1 char(5) character set latin1 collate latin1_german2_ci);
insert into t1 values (0xf6) /* this is o-umlaut */;
select * from t1 where length(s1)=1 and s1='oe';
drop table t1;
+
+--echo End of 5.1 tests
+
+
+--echo #
+--echo # Start of 5.6 tests
+--echo #
+
+--echo #
+--echo # WL#3664 WEIGHT_STRING
+--echo #
+
+set @@collation_connection=latin1_german2_ci;
+--source include/weight_string.inc
+--source include/weight_string_euro.inc
+--source include/weight_string_l1.inc
+select hex(weight_string('Ä'));
+select hex(weight_string('ä'));
+select hex(weight_string('Ö'));
+select hex(weight_string('ö'));
+select hex(weight_string('Ü'));
+select hex(weight_string('ü'));
+select hex(weight_string('S'));
+select hex(weight_string('s'));
+select hex(weight_string('ß'));
+select hex(weight_string('ä' as char(1)));
+select hex(weight_string('ö' as char(1)));
+select hex(weight_string('ü' as char(1)));
+select hex(weight_string('ß' as char(1)));
+select hex(weight_string('xä' as char(2)));
+select hex(weight_string('xö' as char(2)));
+select hex(weight_string('xü' as char(2)));
+select hex(weight_string('xß' as char(2)));
+
+--echo #
+--echo # End of 5.6 tests
+--echo #
diff --git a/mysql-test/t/ctype_latin2.test b/mysql-test/t/ctype_latin2.test
index 676b472e7b8..e80515993f2 100644
--- a/mysql-test/t/ctype_latin2.test
+++ b/mysql-test/t/ctype_latin2.test
@@ -50,3 +50,27 @@ SELECT group_concat(a collate latin2_croatian_ci order by binary a) from t1 grou
drop table t1;
# End of 4.1 tests
+
+--echo End of 5.1 tests
+
+
+--echo #
+--echo # Start of 5.6 tests
+--echo #
+
+--echo #
+--echo # WL#3664 WEIGHT_STRING
+--echo #
+
+set names latin2;
+--source include/weight_string.inc
+--source include/weight_string_l1.inc
+--source include/ctype_datetime.inc
+
+set collation_connection=latin2_bin;
+--source include/weight_string.inc
+--source include/weight_string_l1.inc
+
+--echo #
+--echo # End of 5.6 tests
+--echo #
diff --git a/mysql-test/t/ctype_latin2_ch.test b/mysql-test/t/ctype_latin2_ch.test
index 3925d02659d..acd93aad6d6 100644
--- a/mysql-test/t/ctype_latin2_ch.test
+++ b/mysql-test/t/ctype_latin2_ch.test
@@ -27,6 +27,216 @@ select * from t1 where tt like 'AA%';
select * from t1 ignore index (primary) where tt like 'AA%';
select * from t1 where tt like '%AA%';
+drop table t1;
+
# End of 4.1 tests
+set names latin2 collate latin2_czech_cs;
+--source include/ctype_pad_space.inc
+
+# We can not use ctype_filesort.inc because
+# order of SPACE and TAB is not strict
+#--source include/ctype_filesort.inc
+#
+
+#
+# Bug#29459 server died handling latin2 collate latin2_czech_cs
+#
+create table t1 (
+ a varchar(2) character set latin2 collate latin2_czech_cs,
+ primary key(a)
+);
+insert into t1 set a=0x5ff;
+insert into t1 set a=0xff;
+select hex(a) from t1;
+drop table t1;
+
+#
+# Bug#33452 Primary difference between capital and small letters U and O
+#
+create table t1 (
+ ch varchar(1),
+ name varchar(64)
+) character set latin2 collate latin2_czech_cs;
+
+insert into t1 values (0x6F,'LATIN SMALL LETTER O');
+insert into t1 values (0xF3,'LATIN SMALL LETTER O WITH ACUTE');
+insert into t1 values (0xF4,'LATIN SMALL LETTER O WITH CIRCUMFLEX');
+insert into t1 values (0xF6,'LATIN SMALL LETTER O WITH DIAERESIS');
+insert into t1 values (0xF5,'LATIN SMALL LETTER O WITH DOUBLE ACUTE');
+insert into t1 values (0x4F,'LATIN CAPITAL LETTER O');
+insert into t1 values (0xD3,'LATIN CAPITAL LETTER O WITH ACUTE');
+insert into t1 values (0xD4,'LATIN CAPITAL LETTER O WITH CURCUMFLEX');
+insert into t1 values (0xD6,'LATIN CAPITAL LETTER O WITH DIAERESIS');
+insert into t1 values (0xD5,'LATIN CAPITAL LETTER O WITH DOUBLE ACUTE');
+
+insert into t1 values (0x75,'LATIN SMALL LETTER U');
+insert into t1 values (0xFA,'LATIN SMALL LETTER U WITH ACUTE');
+insert into t1 values (0xF9,'LATIN SMALL LETTER U WITH RING ABOVE');
+insert into t1 values (0xFC,'LATIN SMALL LETTER U WITH DIAERESIS');
+insert into t1 values (0xFB,'LATIN SMALL LETTER U WITH DOUBLE ACUTE');
+insert into t1 values (0x55,'LATIN CAPITAL LETTER U');
+insert into t1 values (0xDA,'LATIN CAPITAL LETTER U WITH ACUTE');
+insert into t1 values (0xD9,'LATIN CAPITAL LETTER U WITH RING ABOVE');
+insert into t1 values (0xDC,'LATIN CAPITAL LETTER U WITH DIAERESIS');
+insert into t1 values (0xDB,'LATIN CAPITAL LETTER U WITH DOUBLE ACUTE');
+select
+hex(weight_string(ch level 1)) l1,
+hex(weight_string(ch level 2)) l2,
+hex(weight_string(ch level 3)) l3,
+hex(weight_string(ch level 4)) l4,
+name from t1 order by binary l1, binary l2, binary l3, binary l4;
+drop table t1;
+
+#
+# Bug#33791 Wrong ORDER BY with latin2_czech_cs
+#
+set names utf8;
+create table t1 (
+ch varchar(1),
+name varchar(64)
+) character set latin2 collate latin2_czech_cs;
+insert into t1 values (0x4F,'LATIN CAPITAL LETTER O');
+insert into t1 values (0xD3,'LATIN CAPITAL LETTER O WITH ACUTE');
+insert into t1 values (0xD4,'LATIN CAPITAL LETTER O WITH CURCUMFLEX');
+insert into t1 values (0xD6,'LATIN CAPITAL LETTER O WITH DIAERESIS');
+insert into t1 values (0xD5,'LATIN CAPITAL LETTER O WITH DOUBLE ACUTE');
+insert into t1 values (0x75,'LATIN _SMALL_ LETTER U');
+insert into t1 values (0xFA,'LATIN _SMALL_ LETTER U WITH ACUTE');
+insert into t1 values (0xF9,'LATIN _SMALL_ LETTER U WITH RING ABOVE');
+insert into t1 values (0xFC,'LATIN _SMALL_ LETTER U WITH DIAERESIS');
+insert into t1 values (0xFB,'LATIN _SMALL_ LETTER U WITH DOUBLE ACUTE');
+# Testing order by Field_varchar
+select ch,
+ hex(weight_string(ch level 1)) l1,
+ hex(weight_string(ch level 2)) l2,
+ hex(weight_string(ch level 3)) l3,
+ hex(weight_string(ch level 4)) l4,
+ name from t1 order by ch;
+alter table t1 modify ch char(1), modify name char(64);
+# Testing order by Field_char
+select ch,
+ hex(weight_string(ch level 1)) l1,
+ hex(weight_string(ch level 2)) l2,
+ hex(weight_string(ch level 3)) l3,
+ hex(weight_string(ch level 4)) l4,
+ name from t1 order by ch;
+# Testing order by Item
+select ch,
+ hex(weight_string(ch level 1)) l1,
+ hex(weight_string(ch level 2)) l2,
+ hex(weight_string(ch level 3)) l3,
+ hex(weight_string(ch level 4)) l4,
+ name from t1 order by concat(ch);
drop table t1;
+
+#
+# Bug #30462 Character sets: search failures with case sensitive collations
+#
+SET collation_connection=latin2_czech_cs;
+CREATE TABLE t1 ENGINE=MYISAM AS SELECT repeat('a', 5) AS s1 LIMIT 0;
+INSERT INTO t1 VALUES ('x'),('y'),('z'),('X'),('Y'),('Z');
+SELECT * FROM t1 GROUP BY s1;
+SELECT * FROM t1 ORDER BY s1;
+CREATE INDEX i1 ON t1 (s1);
+SELECT * FROM t1 GROUP BY s1;
+SELECT * FROM t1 ORDER BY s1;
+DROP TABLE t1;
+
+--disable_warnings
+CREATE TABLE t1 ENGINE=INNODB AS SELECT repeat('a', 5) AS s1 LIMIT 0;
+--enable_warnings
+INSERT INTO t1 VALUES ('x'),('y'),('z'),('X'),('Y'),('Z');
+SELECT * FROM t1 GROUP BY s1;
+SELECT * FROM t1 ORDER BY s1;
+CREATE INDEX i1 ON t1 (s1);
+SELECT * FROM t1 GROUP BY s1;
+SELECT * FROM t1 ORDER BY s1;
+DROP TABLE t1;
+
+--disable_warnings
+SET sql_mode='';
+CREATE TABLE t1 ENGINE=FALCON AS SELECT repeat('a', 5) AS s1 LIMIT 0;
+SET sql_mode=DEFAULT;
+--enable_warnings
+INSERT INTO t1 VALUES ('x'),('y'),('z'),('X'),('Y'),('Z');
+SELECT * FROM t1 GROUP BY s1;
+SELECT * FROM t1 ORDER BY s1;
+CREATE INDEX i1 ON t1 (s1);
+SELECT * FROM t1 GROUP BY s1;
+SELECT * FROM t1 ORDER BY s1;
+DROP TABLE t1;
+
+--disable_warnings
+SET sql_mode='';
+CREATE TABLE t1 ENGINE=MARIA AS SELECT repeat('a', 5) AS s1 LIMIT 0;
+SET sql_mode=DEFAULT;
+--enable_warnings
+INSERT INTO t1 VALUES ('x'),('y'),('z'),('X'),('Y'),('Z');
+SELECT * FROM t1 GROUP BY s1;
+SELECT * FROM t1 ORDER BY s1;
+CREATE INDEX i1 ON t1 (s1);
+SELECT * FROM t1 GROUP BY s1;
+SELECT * FROM t1 ORDER BY s1;
+DROP TABLE t1;
+
+SET NAMES latin2;
+
+#
+# Bug#37854 Test fails/aborts for collate latin2_czech_cs used with SET and ENUM datatypes
+#
+CREATE TABLE t2(colours SET('red','blue','yellow'))CHARACTER SET latin2 COLLATE
+latin2_czech_cs;
+CREATE TABLE t1(continent ENUM('Asia', 'Europe','Africa','Antartica'))CHARACTER SET latin2
+COLLATE latin2_czech_cs;
+INSERT INTO t1 VALUES('Asia');
+INSERT INTO t2 VALUES('blue');
+SELECT * FROM t1;
+SELECT * FROM t2;
+DROP TABLE t1, t2;
+
+#
+# Bug#40805 Cannot restore table
+#
+CREATE TABLE `t1` (
+ `ID` smallint(5) unsigned zerofill NOT NULL AUTO_INCREMENT,
+ `Post` enum('','B','O','Z','U') COLLATE latin2_czech_cs DEFAULT NULL,
+ PRIMARY KEY (`ID`)
+) ENGINE=MyISAM AUTO_INCREMENT=135 DEFAULT CHARSET=latin2;
+SHOW CREATE TABLE t1;
+INSERT INTO t1 (ID,Post) VALUES (00041,'');
+SELECT ID, Post, HEX(WEIGHT_STRING(Post)) FROM t1;
+DROP TABLE t1;
+
+
+--echo #
+--echo # Start of 5.6 tests
+--echo #
+
+--echo #
+--echo # WL#3664 WEIGHT_STRING
+--echo #
+
+set names latin2 collate latin2_czech_cs;
+--source include/ctype_pad_space.inc
+# We can not use ctype_filesort.inc because
+# order of SPACE and TAB is not strict
+#--source include/ctype_filesort.inc
+
+--echo #
+--echo # Note:
+--echo # latin2_czech_cs does not support WEIGHT_STRING in full extent
+--echo #
+--source include/weight_string.inc
+--source include/weight_string_chde.inc
+--source include/weight_string_l1.inc
+--source include/weight_string_l2.inc
+--source include/weight_string_l3.inc
+--source include/weight_string_l4.inc
+--source include/weight_string_l12.inc
+--source include/weight_string_l14.inc
+
+--echo #
+--echo # End of 5.6 tests
+--echo #
+
diff --git a/mysql-test/t/ctype_ldml-master.opt b/mysql-test/t/ctype_ldml-master.opt
index a2532d4cfd9..d7ecd9095cb 100644
--- a/mysql-test/t/ctype_ldml-master.opt
+++ b/mysql-test/t/ctype_ldml-master.opt
@@ -1,2 +1,2 @@
--character-sets-dir=$MYSQL_TEST_DIR/std_data/
-
+--log-error=$MYSQLTEST_VARDIR/tmp/ctype_ldml_log.err
diff --git a/mysql-test/t/ctype_ldml.test b/mysql-test/t/ctype_ldml.test
index 4a867d85454..1b9d7c9d4ad 100644
--- a/mysql-test/t/ctype_ldml.test
+++ b/mysql-test/t/ctype_ldml.test
@@ -61,6 +61,27 @@ insert into t1 values ('a');
select * from t1 where c1='b';
drop table t1;
+# make sure utf8_test_ci is Unicode-5.0.0
+SELECT hex(weight_string(_utf8mb4'a' collate utf8mb4_test_ci));
+SELECT hex(weight_string(convert(_utf32 0x10002 using utf8mb4) collate utf8mb4_test_ci));
+SELECT hex(@a:=convert(_utf32 0x10400 using utf8mb4) collate utf8mb4_test_ci), hex(lower(@a));
+SELECT hex(@a:=convert(_utf32 0x10428 using utf8mb4) collate utf8mb4_test_ci), hex(upper(@a));
+SELECT hex(@a:=convert(_utf32 0x2C00 using utf8mb4) collate utf8mb4_test_ci), hex(lower(@a));
+SELECT hex(@a:=convert(_utf32 0x2C30 using utf8mb4) collate utf8mb4_test_ci), hex(upper(@a));
+
+# check that it works with supplementary characters
+SELECT hex(weight_string(convert(_utf32 0x61 using utf8mb4) collate utf8mb4_test_ci));
+SELECT hex(weight_string(convert(_utf32 0x62 using utf8mb4) collate utf8mb4_test_ci));
+SELECT hex(weight_string(convert(_utf32 0x10062 using utf8mb4) collate utf8mb4_test_ci));
+SELECT hex(weight_string(convert(_utf32 0x10400 using utf8mb4) collate utf8mb4_test_ci));
+SELECT hex(weight_string(convert(_utf32 0x100400 using utf8mb4) collate utf8mb4_test_ci));
+
+# check contractions with non-ascii characters
+SELECT hex(weight_string(_utf8mb4 0x64 collate utf8mb4_test_ci));
+SELECT hex(weight_string(convert(_ucs2 0x0064017e using utf8mb4) collate utf8mb4_test_ci));
+SELECT hex(weight_string(convert(_ucs2 0x0044017e using utf8mb4) collate utf8mb4_test_ci));
+SELECT hex(weight_string(convert(_ucs2 0x0044017d using utf8mb4) collate utf8mb4_test_ci));
+
#
# Bug#41084 full-text index added to custom UCA collation not working
@@ -153,7 +174,7 @@ select "foo" = "foo " collate latin1_test;
# The file ../std-data/Index.xml has a number of collations with high IDs.
# Test that the "ID" column in I_S and SHOW queries can handle two bytes
-select * from information_schema.collations where id>256 order by id;
+select * from information_schema.collations where id>256 and is_compiled<>'Yes' order by id;
show collation like '%test%';
# Test that two-byte collation ID is correctly transfered to the client side.
@@ -181,3 +202,198 @@ DROP TABLE t1;
SET NAMES utf8 COLLATE utf8_phone_ci;
SHOW COLLATION LIKE 'utf8_phone_ci';
SET NAMES utf8;
+
+# make sure utf8mb4_test_400_ci is Unicode-4.0.0 based
+SELECT hex(weight_string(_utf8mb4'a' collate utf8mb4_test_400_ci));
+SELECT hex(weight_string(convert(_utf32 0x10002 using utf8mb4) collate utf8mb4_test_400_ci));
+SELECT hex(@a:=convert(_utf32 0x10400 using utf8mb4) collate utf8mb4_test_400_ci), hex(lower(@a));
+SELECT hex(@a:=convert(_utf32 0x10428 using utf8mb4) collate utf8mb4_test_400_ci), hex(upper(@a));
+SELECT hex(@a:=convert(_utf32 0x2C00 using utf8mb4) collate utf8mb4_test_400_ci), hex(lower(@a));
+SELECT hex(@a:=convert(_utf32 0x2C30 using utf8mb4) collate utf8mb4_test_400_ci), hex(upper(@a));
+
+--echo #
+--echo # WL#5624 Collation customization improvements
+--echo #
+SET NAMES utf8 COLLATE utf8_5624_1;
+CREATE TABLE t1 AS SELECT REPEAT(' ', 16) AS a LIMIT 0;
+# Part 1,2,3: long contractions and expansions
+# Part 7: Quarternary difference
+INSERT INTO t1 VALUES ('012345'),('001234'),('000123'),('000012'),('000001');
+INSERT INTO t1 VALUES ('12345'),('01234'),('00123'),('00012'),('00001');
+INSERT INTO t1 VALUES ('1234'),('0123'),('0012'),('0001');
+INSERT INTO t1 VALUES ('123'),('012'),('001');
+INSERT INTO t1 VALUES ('12'),('01');
+INSERT INTO t1 VALUES ('1'),('9');
+INSERT INTO t1 VALUES ('ГÐИ'),('ГИБДД');
+# Part 4: reset before
+# Part 6: characters rather than escape sequences
+INSERT INTO t1 VALUES ('a'),('b'),('c'),('d'),('e');
+INSERT INTO t1 VALUES ('cz'),('ÄŠ'),('Ä‹');
+INSERT INTO t1 VALUES ('f'),('fz'),('g'),('Ä '),('Ä¡');
+INSERT INTO t1 VALUES ('h'),('hz'),('GĦ'),('Għ'),('gĦ'),('għ');
+INSERT INTO t1 VALUES ('i'),('iz'),('Ħ'),('ħ');
+INSERT INTO t1 VALUES ('y'),('yz'),('z'),('Ż'),('ż');
+INSERT INTO t1 VALUES ('Ä'),('Ä€'),('á'),('Ã'),('à'),('À');
+INSERT INTO t1 VALUES ('ē'),('é'),('ě'),('ê'),('Ē'),('É'),('Ě'),('Ê');
+# Part 8: Abbreviated shift syntax
+INSERT INTO t1 VALUES ('a'),('~'),('!'),('@'),('#'),('$'),('%'),('^');
+INSERT INTO t1 VALUES ('('),(')'),('-'),('+'),('|'),('='),(':'),(';');
+INSERT INTO t1 VALUES ('"'),('\''),('?');
+# Part 9: Normal expansion syntax
+INSERT INTO t1 VALUES ('ch'),('k'),('cs'),('ccs'),('cscs');
+# Part 10: Previous context
+INSERT INTO t1 VALUES ('aa-'),('ab-'),('ac-'),('ad-'),('ae-'),('af-'),('az-');
+# Part 12: Logical reset positions
+INSERT INTO t1 VALUES ('lp-fni'),('lp-lni');
+INSERT INTO t1 VALUES ('lp-fpi'),('lp-lpi');
+INSERT INTO t1 VALUES ('lp-fsi'),('lp-lsi');
+INSERT INTO t1 VALUES ('lp-fti'),('lp-lti');
+INSERT INTO t1 VALUES ('lp-ft'),('lp-lt');
+INSERT INTO t1 VALUES ('lp-fv'),('lp-lv');
+# Logical positions with reset before
+INSERT INTO t1 VALUES ('lb-fni'),('lb-lni');
+INSERT INTO t1 VALUES ('lb-fv'),('lb-lv');
+# Part 5: Long tailoring
+INSERT INTO t1 VALUES (_ucs2 0x3106),(_ucs2 0x3110), (_ucs2 0x3111), (_ucs2 0x3112);
+INSERT INTO t1 VALUES (_ucs2 0x32A3), (_ucs2 0x3231);
+INSERT INTO t1 VALUES (_ucs2 0x84D9), (_ucs2 0x98F5), (_ucs2 0x7CF3), (_ucs2 0x5497);
+SELECT a, HEX(WEIGHT_STRING(a)) FROM t1 ORDER BY a, LENGTH(a), BINARY a;
+--echo #
+--echo # WL#5624, the same test with UCS2
+--echo #
+ALTER TABLE t1 CONVERT TO CHARACTER SET ucs2 COLLATE ucs2_5624_1;
+SELECT a, HEX(WEIGHT_STRING(a)) FROM t1 ORDER BY a, LENGTH(a), BINARY(a);
+DROP TABLE t1;
+
+--echo #
+--echo # WL#5624, unsupported features
+--echo #
+# Part 13: More verbosity
+--error ER_UNKNOWN_COLLATION
+SET NAMES utf8 COLLATE utf8_5624_2;
+SHOW WARNINGS;
+
+--error ER_UNKNOWN_COLLATION
+SELECT _utf8'test' COLLATE utf8_5624_2;
+SHOW WARNINGS;
+
+--echo #
+--echo # WL#5624, reset before primary ignorable
+--echo #
+--error ER_UNKNOWN_COLLATION
+SET NAMES utf8 COLLATE utf8_5624_3;
+SHOW WARNINGS;
+
+--echo #
+--echo # WL#5624, \u without hex digits is equal to {'\\', 'u'}
+--echo #
+SET NAMES utf8 COLLATE utf8_5624_4;
+CREATE TABLE t1 AS SELECT REPEAT(' ', 10) AS a LIMIT 0;
+INSERT INTO t1 VALUES ('\\'),('u'),('x'),('X');
+SELECT a, HEX(WEIGHT_STRING(a)) FROM t1 ORDER BY a, LENGTH(a), BINARY(a);
+DROP TABLE t1;
+
+--echo #
+--echo # WL#5624, testing Bengali collations
+--echo #
+SET NAMES utf8, collation_connection=utf8_bengali_standard_ci;
+CREATE TABLE t1 AS SELECT REPEAT (' ', 10) AS a LIMIT 0;
+INSERT INTO t1 VALUES (_ucs2 0x09FA), (_ucs2 0x09F8), (_ucs2 0x09F9), (_ucs2 0x09F2);
+INSERT INTO t1 VALUES (_ucs2 0x09DC), (_ucs2 0x09A109BC);
+INSERT INTO t1 VALUES (_ucs2 0x09A2), (_ucs2 0x09DD), (_ucs2 0x09A209BC);
+INSERT INTO t1 VALUES (_ucs2 0x09A3);
+SELECT HEX(WEIGHT_STRING(a)), HEX(CONVERT(a USING ucs2)), HEX(a)
+FROM t1 ORDER BY a, BINARY a;
+DROP TABLE t1;
+
+SET NAMES utf8, collation_connection=utf8_bengali_traditional_ci;
+CREATE TABLE t1 AS SELECT REPEAT (' ', 10) AS a LIMIT 0;
+INSERT INTO t1 VALUES
+(_ucs2 0x0985),(_ucs2 0x0986),(_ucs2 0x0987),(_ucs2 0x0988),
+(_ucs2 0x0989),(_ucs2 0x098A),(_ucs2 0x098B),(_ucs2 0x09E0),
+(_ucs2 0x098C),(_ucs2 0x09E1),(_ucs2 0x098F),(_ucs2 0x0990),
+(_ucs2 0x0993);
+
+INSERT INTO t1 VALUES
+(_ucs2 0x0994),(_ucs2 0x0982),(_ucs2 0x0983),(_ucs2 0x0981),
+(_ucs2 0x099509CD), (_ucs2 0x099609CD), (_ucs2 0x099709CD), (_ucs2 0x099809CD),
+(_ucs2 0x099909CD), (_ucs2 0x099A09CD), (_ucs2 0x099B09CD), (_ucs2 0x099C09CD),
+(_ucs2 0x099D09CD), (_ucs2 0x099E09CD), (_ucs2 0x099F09CD), (_ucs2 0x09A009CD),
+(_ucs2 0x09A109CD), (_ucs2 0x09A209CD), (_ucs2 0x09A309CD),
+(_ucs2 0x09CE), (_ucs2 0x09A409CD200D), (_ucs2 0x09A409CD),
+(_ucs2 0x09A509CD),(_ucs2 0x09A609CD),
+(_ucs2 0x09A709CD), (_ucs2 0x09A809CD), (_ucs2 0x09AA09CD), (_ucs2 0x09AB09CD),
+(_ucs2 0x09AC09CD), (_ucs2 0x09AD09CD), (_ucs2 0x09AE09CD), (_ucs2 0x09AF09CD),
+(_ucs2 0x09B009CD), (_ucs2 0x09F009CD), (_ucs2 0x09B209CD), (_ucs2 0x09F109CD),
+(_ucs2 0x09B609CD), (_ucs2 0x09B709CD), (_ucs2 0x09B809CD), (_ucs2 0x09B909CD);
+
+INSERT INTO t1 VALUES
+ (_ucs2 0x099509CD0985),(_ucs2 0x0995),
+ (_ucs2 0x099509CD0986),(_ucs2 0x099509BE),
+ (_ucs2 0x099509CD0987),(_ucs2 0x099509BF),
+ (_ucs2 0x099509CD0988),(_ucs2 0x099509C0),
+ (_ucs2 0x099509CD0989),(_ucs2 0x099509C1),
+ (_ucs2 0x099509CD098A),(_ucs2 0x099509C2),
+ (_ucs2 0x099509CD098B),(_ucs2 0x099509C3),
+ (_ucs2 0x099509CD09E0),(_ucs2 0x099509C4),
+ (_ucs2 0x099509CD098C),(_ucs2 0x099509E2),
+ (_ucs2 0x099509CD09E1),(_ucs2 0x099509E3),
+ (_ucs2 0x099509CD098F),(_ucs2 0x099509C7),
+ (_ucs2 0x099509CD0990),(_ucs2 0x099509C8),
+ (_ucs2 0x099509CD0993),(_ucs2 0x099509CB),
+ (_ucs2 0x099509CD0994),(_ucs2 0x099509CC);
+
+SELECT HEX(WEIGHT_STRING(a)), HEX(CONVERT(a USING ucs2)), HEX(a)
+FROM t1 ORDER BY a, BINARY(a);
+SELECT HEX(WEIGHT_STRING(a)) as wa,
+GROUP_CONCAT(HEX(CONVERT(a USING ucs2)) ORDER BY LENGTH(a), BINARY a)
+FROM t1 GROUP BY a ORDER BY a;
+DROP TABLE t1;
+
+--echo #
+--echo # WL#5624, shift after, using expansion
+--echo #
+SET NAMES utf8 COLLATE utf8_5624_5;
+CREATE TABLE t1 AS SELECT REPEAT(' ', 10) AS a LIMIT 0;
+INSERT INTO t1 VALUES ('0'),('1'),('0z'),(_ucs2 0x0030FF9D);
+INSERT INTO t1 VALUES ('a'),('b'),('c'),('d'),('e'),('f'),('g'),('h'),('i');
+INSERT INTO t1 VALUES ('j'),('k'),('l'),('m'),('n'),('o'),('p'),('q'),('r');
+INSERT INTO t1 VALUES ('s'),('t'),('u'),('v'),('w'),('x'),('y'),('z');
+INSERT INTO t1 VALUES ('aa'),('aaa');
+INSERT INTO t1 VALUES ('A'),('B'),('C'),('D'),('E'),('F'),('G'),('H'),('I');
+INSERT INTO t1 VALUES ('J'),('K'),('L'),('M'),('N'),('O'),('P'),('Q'),('R');
+INSERT INTO t1 VALUES ('S'),('T'),('U'),('V'),('W'),('X'),('Y'),('Z');
+INSERT INTO t1 VALUES ('AA'),('AAA');
+INSERT INTO t1 VALUES ('001'),('002');
+
+SELECT a, HEX(WEIGHT_STRING(a)) FROM t1 ORDER BY a, LENGTH(a), BINARY(a);
+DROP TABLE t1;
+
+--error ER_UNKNOWN_COLLATION
+SET NAMES utf8 COLLATE utf8_5624_5_bad;
+SHOW WARNINGS;
+
+--echo #
+--echo # End of WL#5624
+--echo #
+
+
+--echo #
+--echo # Bug#14197426 PARSE ERRORS IN LOADABLE UCA / LDML COLLATIONS ARE SILENTLY IGNORED
+--echo #
+
+--let $out_file= $MYSQLTEST_VARDIR/tmp/ctype_ldml_log.err
+--let OUTF= $out_file
+# Error messages are not seen in error log in embedded version
+--let EMBEDDED=`SELECT IF(version() LIKE '%embedded%',2,0)`
+--echo # Search for occurrences of [ERROR] Syntax error at '[strength tertiary]'
+
+perl;
+ use strict;
+ my $outf= $ENV{'OUTF'} or die "OUTF not set";
+ open(FILE, "$outf") or die("Unable to open $outf: $!\n");
+ my $count_error= grep(/\[ERROR\] Syntax error at '\[strength tertiary\]'/gi,<FILE>);
+ my $count_error= $count_error + $ENV{"EMBEDDED"};
+ print "Occurances : $count_error\n";
+ close(FILE);
+EOF
diff --git a/mysql-test/t/ctype_like_range.test b/mysql-test/t/ctype_like_range.test
index 34a7637222b..02f2f79d168 100644
--- a/mysql-test/t/ctype_like_range.test
+++ b/mysql-test/t/ctype_like_range.test
@@ -2,6 +2,7 @@
--source include/have_ucs2.inc
--source include/have_utf16.inc
--source include/have_utf32.inc
+--source include/have_utf8mb4.inc
--disable_warnings
DROP TABLE IF EXISTS t1;
@@ -20,6 +21,7 @@ INSERT INTO t1 (a) VALUES ('aaa'),('ccc'),('cch');
INSERT INTO t1 (a) VALUES ('aaa_'),('ccc_'),('cch_');
INSERT INTO t1 (a) VALUES ('aaa%'),('ccc%'),('cch%');
INSERT INTO t1 (a) VALUES ('aaaaaaaaaaaaaaaaaaaa');
+INSERT INTO t1 (a) VALUES ('caaaaaaaaaaaaaaaaaaa');
CREATE VIEW v1 AS
SELECT id, 'a' AS name, a AS val FROM t1
@@ -44,9 +46,30 @@ SELECT * FROM v1;
ALTER TABLE t1 MODIFY a VARCHAR(32) CHARACTER SET utf8 COLLATE utf8_czech_ci;
SELECT * FROM v1;
+# Note, 16 bytes is enough for 16/3= 5 characters
+# For the 'aaaaaaaa' value contraction breaks apart
+# For the 'caaaaaaa' value contraction does not break apart
ALTER TABLE t1 MODIFY a VARCHAR(32) CHARACTER SET utf8 COLLATE utf8_danish_ci;
SELECT * FROM v1;
+ALTER TABLE t1 MODIFY a VARCHAR(32) CHARACTER SET utf8mb4;
+SELECT * FROM v1;
+
+ALTER TABLE t1 MODIFY a VARCHAR(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
+SELECT * FROM v1;
+
+ALTER TABLE t1 MODIFY a VARCHAR(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_czech_ci;
+SELECT * FROM v1;
+
+# Note, 16 bytes is enough for 16/4= 4 characters
+# For the 'aaaaaaaa' value contraction does not break apart
+# For the 'caaaaaaa' value contraction breaks apart
+ALTER TABLE t1 MODIFY a VARCHAR(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_danish_ci;
+SELECT * FROM v1;
+
+ALTER TABLE t1 MODIFY a VARCHAR(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_520_ci;
+SELECT * FROM v1;
+
ALTER TABLE t1 MODIFY a VARCHAR(32) CHARACTER SET ucs2;
SELECT * FROM v1;
@@ -68,9 +91,15 @@ SELECT * FROM v1;
ALTER TABLE t1 MODIFY a VARCHAR(32) CHARACTER SET utf16 COLLATE utf16_czech_ci;
SELECT * FROM v1;
+# Note, 16 bytes is enough for 16/3= 5 characters
+# For the 'aaaaaaaa' value contraction does not break apart
+# For the 'caaaaaaa' value contraction breaks apart
ALTER TABLE t1 MODIFY a VARCHAR(32) CHARACTER SET utf16 COLLATE utf16_danish_ci;
SELECT * FROM v1;
+ALTER TABLE t1 MODIFY a VARCHAR(32) CHARACTER SET utf16 COLLATE utf16_unicode_520_ci;
+SELECT * FROM v1;
+
ALTER TABLE t1 MODIFY a VARCHAR(32) CHARACTER SET utf32;
SELECT * FROM v1;
@@ -83,5 +112,8 @@ SELECT * FROM v1;
ALTER TABLE t1 MODIFY a VARCHAR(32) CHARACTER SET utf32 COLLATE utf32_danish_ci;
SELECT * FROM v1;
+ALTER TABLE t1 MODIFY a VARCHAR(32) CHARACTER SET utf32 COLLATE utf32_unicode_520_ci;
+SELECT * FROM v1;
+
DROP VIEW v1;
DROP TABLE t1;
diff --git a/mysql-test/t/ctype_many.test b/mysql-test/t/ctype_many.test
index 060cf9fcf92..11ad942e19c 100644
--- a/mysql-test/t/ctype_many.test
+++ b/mysql-test/t/ctype_many.test
@@ -319,3 +319,15 @@ DROP TABLE t2;
--echo #
--echo # End of 5.5 tests
--echo #
+
+--echo #
+--echo # Bug#11766143 59185: ASSERTION FAILED: (FIXED == 1), FILE
+--echo # ITEM_STRFUNC.CC, LINE 2760
+--echo #
+CREATE TABLE t1 (a CHAR(1) CHARSET UTF8);
+INSERT INTO t1 VALUES ('a'), ('b');
+CREATE TABLE t2 (a BINARY(1));
+--error ER_SUBQUERY_NO_1_ROW
+SELECT * FROM t2 WHERE a=(SELECT a FROM t1) AND a=_LATIN1'x';
+DROP TABLE t2;
+DROP TABLE t1;
diff --git a/mysql-test/t/ctype_partitions.test b/mysql-test/t/ctype_partitions.test
new file mode 100644
index 00000000000..f80a2c98a1b
--- /dev/null
+++ b/mysql-test/t/ctype_partitions.test
@@ -0,0 +1,29 @@
+--source include/have_partition.inc
+
+--echo #
+--echo # MDEV-6255 DUPLICATE KEY Errors on SELECT .. GROUP BY that uses temporary and filesort
+--echo #
+
+# cp1251_ukrainian_ci: 0x20 SPACE is equal to 0x60 GRAVE ACCENT
+CREATE TABLE t1 (a VARCHAR(10) CHARACTER SET cp1251 COLLATE cp1251_ukrainian_ci);
+INSERT INTO t1 VALUES (0x20),(0x60),(0x6060),(0x606060);
+SELECT HEX(a) FROM t1 WHERE a=0x60;
+ALTER TABLE t1 PARTITION BY KEY(a) PARTITIONS 3;
+SELECT HEX(a) FROM t1 WHERE a=0x60;
+DROP TABLE t1;
+
+# koi8u_general_ci: 0x20 SPACE is equal to 0x60 GRAVE ACCENT
+CREATE TABLE t1 (a VARCHAR(10) CHARACTER SET koi8u COLLATE koi8u_general_ci);
+INSERT INTO t1 VALUES (0x20),(0x60),(0x6060),(0x606060);
+SELECT HEX(a) FROM t1 WHERE a=0x60;
+ALTER TABLE t1 PARTITION BY KEY(a) PARTITIONS 3;
+SELECT HEX(a) FROM t1 WHERE a=0x60;
+DROP TABLE t1;
+
+# cp1250_general_ci: 0x20 SPACE is equal to 0xA0 NO-BREAK SPACE
+CREATE TABLE t1 (a VARCHAR(10) CHARACTER SET cp1250 COLLATE cp1250_general_ci);
+INSERT INTO t1 VALUES (0x20),(0xA0),(0xA0A0),(0xA0A0A0);
+SELECT HEX(a) FROM t1 WHERE a=0xA0;
+ALTER TABLE t1 PARTITION BY KEY(a) PARTITIONS 3;
+SELECT HEX(a) FROM t1 WHERE a=0xA0;
+DROP TABLE t1;
diff --git a/mysql-test/t/ctype_sjis.test b/mysql-test/t/ctype_sjis.test
index a988c07ebe0..ae110b20cb2 100644
--- a/mysql-test/t/ctype_sjis.test
+++ b/mysql-test/t/ctype_sjis.test
@@ -191,3 +191,43 @@ DROP TABLE t1;
--echo #
--echo # End of 5.5 tests
--echo #
+
+
+--echo #
+--echo # Start of 5.6 tests
+--echo #
+
+--echo #
+--echo # WL#3664 WEIGHT_STRING
+--echo #
+
+set names sjis;
+--source include/weight_string.inc
+--source include/weight_string_l1.inc
+--source include/weight_string_8140.inc
+
+
+set collation_connection=sjis_bin;
+--source include/weight_string.inc
+--source include/weight_string_l1.inc
+--source include/weight_string_8140.inc
+
+--echo #
+--echo # End of 5.6 tests
+--echo #
+
+--echo #
+--echo # Start of 10.0 tests
+--echo #
+
+let $ctype_unescape_combinations=selected;
+--source include/ctype_unescape.inc
+
+--character_set sjis
+SET NAMES sjis;
+--source include/ctype_E05C.inc
+
+
+--echo #
+--echo # End of 10.0 tests
+--echo #
diff --git a/mysql-test/t/ctype_swe7.test b/mysql-test/t/ctype_swe7.test
new file mode 100644
index 00000000000..7d1ef89b374
--- /dev/null
+++ b/mysql-test/t/ctype_swe7.test
@@ -0,0 +1,19 @@
+--echo #
+--echo # Start of 10.0 tests
+--echo #
+
+SET NAMES swe7;
+
+#
+# Test escape sequences.
+# This also covers:
+# MDEV-6737 Stored routines do now work with swe7: "The table mysql.proc is missing, corrupt, or contains bad data"
+# as uses stored functions actively.
+#
+
+let $ctype_unescape_combinations=selected;
+--source include/ctype_unescape.inc
+
+--echo #
+--echo # End of 10.0 tests
+--echo #
diff --git a/mysql-test/t/ctype_tis620.test b/mysql-test/t/ctype_tis620.test
index c49540de24b..b536a00bec9 100644
--- a/mysql-test/t/ctype_tis620.test
+++ b/mysql-test/t/ctype_tis620.test
@@ -156,8 +156,35 @@ DROP TABLE t1;
SET collation_connection='tis620_thai_ci';
-- source include/ctype_filesort.inc
-- source include/ctype_like_escape.inc
+--source include/ctype_ascii_order.inc
SET collation_connection='tis620_bin';
-- source include/ctype_filesort.inc
-- source include/ctype_like_escape.inc
# End of 4.1 tests
+
+
+--echo #
+--echo # Start of 5.6 tests
+--echo #
+
+--echo #
+--echo # WL#3664 WEIGHT_STRING
+--echo #
+
+set names tis620;
+set collation_connection=tis620_thai_ci;
+--source include/weight_string.inc
+--source include/weight_string_l1.inc
+select hex(weight_string(cast(0xE0A1 as char)));
+select hex(weight_string(cast(0xE0A1 as char) as char(1)));
+
+set collation_connection=tis620_bin;
+--source include/weight_string.inc
+--source include/weight_string_l1.inc
+select hex(weight_string(cast(0xE0A1 as char)));
+select hex(weight_string(cast(0xE0A1 as char) as char(1)));
+
+--echo #
+--echo # End of 5.6 tests
+--echo #
diff --git a/mysql-test/t/ctype_uca.test b/mysql-test/t/ctype_uca.test
index 7170e098d7f..5e8195e4718 100644
--- a/mysql-test/t/ctype_uca.test
+++ b/mysql-test/t/ctype_uca.test
@@ -1,4 +1,5 @@
-- source include/have_ucs2.inc
+-- source include/have_utf8mb4.inc
--disable_warnings
DROP TABLE IF EXISTS t1;
@@ -43,157 +44,7 @@ DROP TABLE t;
create table t1 (c1 char(10) character set utf8 collate utf8_bin);
-#
-# Basic Latin
-#
-insert into t1 values ('A'),('a');
-insert into t1 values ('B'),('b');
-insert into t1 values ('C'),('c');
-insert into t1 values ('D'),('d');
-insert into t1 values ('E'),('e');
-insert into t1 values ('F'),('f');
-insert into t1 values ('G'),('g');
-insert into t1 values ('H'),('h');
-insert into t1 values ('I'),('i');
-insert into t1 values ('J'),('j');
-insert into t1 values ('K'),('k');
-insert into t1 values ('L'),('l');
-insert into t1 values ('M'),('m');
-insert into t1 values ('N'),('n');
-insert into t1 values ('O'),('o');
-insert into t1 values ('P'),('p');
-insert into t1 values ('Q'),('q');
-insert into t1 values ('R'),('r');
-insert into t1 values ('S'),('s');
-insert into t1 values ('T'),('t');
-insert into t1 values ('U'),('u');
-insert into t1 values ('V'),('v');
-insert into t1 values ('W'),('w');
-insert into t1 values ('X'),('x');
-insert into t1 values ('Y'),('y');
-insert into t1 values ('Z'),('z');
-
-#
-# Latin1 suppliment
-#
-insert into t1 values (_ucs2 0x00e0),(_ucs2 0x00c0);
-insert into t1 values (_ucs2 0x00e1),(_ucs2 0x00c1);
-insert into t1 values (_ucs2 0x00e2),(_ucs2 0x00c2);
-insert into t1 values (_ucs2 0x00e3),(_ucs2 0x00c3);
-insert into t1 values (_ucs2 0x00e4),(_ucs2 0x00c4);
-insert into t1 values (_ucs2 0x00e5),(_ucs2 0x00c5);
-insert into t1 values (_ucs2 0x00e6),(_ucs2 0x00c6);
-insert into t1 values (_ucs2 0x00e7),(_ucs2 0x00c7);
-insert into t1 values (_ucs2 0x00e8),(_ucs2 0x00c8);
-insert into t1 values (_ucs2 0x00e9),(_ucs2 0x00c9);
-insert into t1 values (_ucs2 0x00ea),(_ucs2 0x00ca);
-insert into t1 values (_ucs2 0x00eb),(_ucs2 0x00cb);
-insert into t1 values (_ucs2 0x00ec),(_ucs2 0x00cc);
-insert into t1 values (_ucs2 0x00ed),(_ucs2 0x00cd);
-insert into t1 values (_ucs2 0x00ee),(_ucs2 0x00ce);
-insert into t1 values (_ucs2 0x00ef),(_ucs2 0x00cf);
-
-insert into t1 values (_ucs2 0x00f0),(_ucs2 0x00d0);
-insert into t1 values (_ucs2 0x00f1),(_ucs2 0x00d1);
-insert into t1 values (_ucs2 0x00f2),(_ucs2 0x00d2);
-insert into t1 values (_ucs2 0x00f3),(_ucs2 0x00d3);
-insert into t1 values (_ucs2 0x00f4),(_ucs2 0x00d4);
-insert into t1 values (_ucs2 0x00f5),(_ucs2 0x00d5);
-insert into t1 values (_ucs2 0x00f6),(_ucs2 0x00d6);
-insert into t1 values (_ucs2 0x00f7),(_ucs2 0x00d7);
-insert into t1 values (_ucs2 0x00f8),(_ucs2 0x00d8);
-insert into t1 values (_ucs2 0x00f9),(_ucs2 0x00d9);
-insert into t1 values (_ucs2 0x00fa),(_ucs2 0x00da);
-insert into t1 values (_ucs2 0x00fb),(_ucs2 0x00db);
-insert into t1 values (_ucs2 0x00fc),(_ucs2 0x00dc);
-insert into t1 values (_ucs2 0x00fd),(_ucs2 0x00dd);
-insert into t1 values (_ucs2 0x00fe),(_ucs2 0x00de);
-insert into t1 values (_ucs2 0x00ff),(_ucs2 0x00df);
-
-#
-# Latin extended-A, 0100-017F
-#
-insert into t1 values (_ucs2 0x0100),(_ucs2 0x0101),(_ucs2 0x0102),(_ucs2 0x0103);
-insert into t1 values (_ucs2 0x0104),(_ucs2 0x0105),(_ucs2 0x0106),(_ucs2 0x0107);
-insert into t1 values (_ucs2 0x0108),(_ucs2 0x0109),(_ucs2 0x010a),(_ucs2 0x010b);
-insert into t1 values (_ucs2 0x010c),(_ucs2 0x010d),(_ucs2 0x010e),(_ucs2 0x010f);
-insert into t1 values (_ucs2 0x0110),(_ucs2 0x0111),(_ucs2 0x0112),(_ucs2 0x0113);
-insert into t1 values (_ucs2 0x0114),(_ucs2 0x0115),(_ucs2 0x0116),(_ucs2 0x0117);
-insert into t1 values (_ucs2 0x0118),(_ucs2 0x0119),(_ucs2 0x011a),(_ucs2 0x011b);
-insert into t1 values (_ucs2 0x011c),(_ucs2 0x011d),(_ucs2 0x011e),(_ucs2 0x011f);
-insert into t1 values (_ucs2 0x0120),(_ucs2 0x0121),(_ucs2 0x0122),(_ucs2 0x0123);
-insert into t1 values (_ucs2 0x0124),(_ucs2 0x0125),(_ucs2 0x0126),(_ucs2 0x0127);
-insert into t1 values (_ucs2 0x0128),(_ucs2 0x0129),(_ucs2 0x012a),(_ucs2 0x012b);
-insert into t1 values (_ucs2 0x012c),(_ucs2 0x012d),(_ucs2 0x012e),(_ucs2 0x012f);
-insert into t1 values (_ucs2 0x0130),(_ucs2 0x0131),(_ucs2 0x0132),(_ucs2 0x0133);
-insert into t1 values (_ucs2 0x0134),(_ucs2 0x0135),(_ucs2 0x0136),(_ucs2 0x0137);
-insert into t1 values (_ucs2 0x0138),(_ucs2 0x0139),(_ucs2 0x013a),(_ucs2 0x013b);
-insert into t1 values (_ucs2 0x013c),(_ucs2 0x013d),(_ucs2 0x013e),(_ucs2 0x013f);
-insert into t1 values (_ucs2 0x0140),(_ucs2 0x0141),(_ucs2 0x0142),(_ucs2 0x0143);
-insert into t1 values (_ucs2 0x0144),(_ucs2 0x0145),(_ucs2 0x0146),(_ucs2 0x0147);
-insert into t1 values (_ucs2 0x0148),(_ucs2 0x0149),(_ucs2 0x014a),(_ucs2 0x014b);
-insert into t1 values (_ucs2 0x014c),(_ucs2 0x014d),(_ucs2 0x014e),(_ucs2 0x014f);
-insert into t1 values (_ucs2 0x0150),(_ucs2 0x0151),(_ucs2 0x0152),(_ucs2 0x0153);
-insert into t1 values (_ucs2 0x0154),(_ucs2 0x0155),(_ucs2 0x0156),(_ucs2 0x0157);
-insert into t1 values (_ucs2 0x0158),(_ucs2 0x0159),(_ucs2 0x015a),(_ucs2 0x015b);
-insert into t1 values (_ucs2 0x015c),(_ucs2 0x015d),(_ucs2 0x015e),(_ucs2 0x015f);
-insert into t1 values (_ucs2 0x0160),(_ucs2 0x0161),(_ucs2 0x0162),(_ucs2 0x0163);
-insert into t1 values (_ucs2 0x0164),(_ucs2 0x0165),(_ucs2 0x0166),(_ucs2 0x0167);
-insert into t1 values (_ucs2 0x0168),(_ucs2 0x0169),(_ucs2 0x016a),(_ucs2 0x016b);
-insert into t1 values (_ucs2 0x016c),(_ucs2 0x016d),(_ucs2 0x016e),(_ucs2 0x016f);
-insert into t1 values (_ucs2 0x0170),(_ucs2 0x0171),(_ucs2 0x0172),(_ucs2 0x0173);
-insert into t1 values (_ucs2 0x0174),(_ucs2 0x0175),(_ucs2 0x0176),(_ucs2 0x0177);
-insert into t1 values (_ucs2 0x0178),(_ucs2 0x0179),(_ucs2 0x017a),(_ucs2 0x017b);
-insert into t1 values (_ucs2 0x017c),(_ucs2 0x017d),(_ucs2 0x017e),(_ucs2 0x017f);
-
-#
-# Latin extended-B, 0180-024F
-#
-insert into t1 values (_ucs2 0x0180),(_ucs2 0x0181),(_ucs2 0x0182),(_ucs2 0x0183);
-insert into t1 values (_ucs2 0x0184),(_ucs2 0x0185),(_ucs2 0x0186),(_ucs2 0x0187);
-insert into t1 values (_ucs2 0x0188),(_ucs2 0x0189),(_ucs2 0x018a),(_ucs2 0x018b);
-insert into t1 values (_ucs2 0x018c),(_ucs2 0x018d),(_ucs2 0x018e),(_ucs2 0x018f);
-insert into t1 values (_ucs2 0x0190),(_ucs2 0x0191),(_ucs2 0x0192),(_ucs2 0x0193);
-insert into t1 values (_ucs2 0x0194),(_ucs2 0x0195),(_ucs2 0x0196),(_ucs2 0x0197);
-insert into t1 values (_ucs2 0x0198),(_ucs2 0x0199),(_ucs2 0x019a),(_ucs2 0x019b);
-insert into t1 values (_ucs2 0x019c),(_ucs2 0x019d),(_ucs2 0x019e),(_ucs2 0x019f);
-insert into t1 values (_ucs2 0x01a0),(_ucs2 0x01a1),(_ucs2 0x01a2),(_ucs2 0x01a3);
-insert into t1 values (_ucs2 0x01a4),(_ucs2 0x01a5),(_ucs2 0x01a6),(_ucs2 0x01a7);
-insert into t1 values (_ucs2 0x01a8),(_ucs2 0x01a9),(_ucs2 0x01aa),(_ucs2 0x01ab);
-insert into t1 values (_ucs2 0x01ac),(_ucs2 0x01ad),(_ucs2 0x01ae),(_ucs2 0x01af);
-insert into t1 values (_ucs2 0x01b0),(_ucs2 0x01b1),(_ucs2 0x01b2),(_ucs2 0x01b3);
-insert into t1 values (_ucs2 0x01b4),(_ucs2 0x01b5),(_ucs2 0x01b6),(_ucs2 0x01b7);
-insert into t1 values (_ucs2 0x01b8),(_ucs2 0x01b9),(_ucs2 0x01ba),(_ucs2 0x01bb);
-insert into t1 values (_ucs2 0x01bc),(_ucs2 0x01bd),(_ucs2 0x01be),(_ucs2 0x01bf);
-insert into t1 values (_ucs2 0x01c0),(_ucs2 0x01c1),(_ucs2 0x01c2),(_ucs2 0x01c3);
-insert into t1 values (_ucs2 0x01c4),(_ucs2 0x01c5),(_ucs2 0x01c6),(_ucs2 0x01c7);
-insert into t1 values (_ucs2 0x01c8),(_ucs2 0x01c9),(_ucs2 0x01ca),(_ucs2 0x01cb);
-insert into t1 values (_ucs2 0x01cc),(_ucs2 0x01cd),(_ucs2 0x01ce),(_ucs2 0x01cf);
-insert into t1 values (_ucs2 0x01d0),(_ucs2 0x01d1),(_ucs2 0x01d2),(_ucs2 0x01d3);
-insert into t1 values (_ucs2 0x01d4),(_ucs2 0x01d5),(_ucs2 0x01d6),(_ucs2 0x01d7);
-insert into t1 values (_ucs2 0x01d8),(_ucs2 0x01d9),(_ucs2 0x01da),(_ucs2 0x01db);
-insert into t1 values (_ucs2 0x01dc),(_ucs2 0x01dd),(_ucs2 0x01de),(_ucs2 0x01df);
-insert into t1 values (_ucs2 0x01e0),(_ucs2 0x01e1),(_ucs2 0x01e2),(_ucs2 0x01e3);
-insert into t1 values (_ucs2 0x01e4),(_ucs2 0x01e5),(_ucs2 0x01e6),(_ucs2 0x01e7);
-insert into t1 values (_ucs2 0x01e8),(_ucs2 0x01e9),(_ucs2 0x01ea),(_ucs2 0x01eb);
-insert into t1 values (_ucs2 0x01ec),(_ucs2 0x01ed),(_ucs2 0x01ee),(_ucs2 0x01ef);
-insert into t1 values (_ucs2 0x01f0),(_ucs2 0x01f1),(_ucs2 0x01f2),(_ucs2 0x01f3);
-insert into t1 values (_ucs2 0x01f4),(_ucs2 0x01f5),(_ucs2 0x01f6),(_ucs2 0x01f7);
-insert into t1 values (_ucs2 0x01f8),(_ucs2 0x01f9),(_ucs2 0x01fa),(_ucs2 0x01fb);
-insert into t1 values (_ucs2 0x01fc),(_ucs2 0x01fd),(_ucs2 0x01fe),(_ucs2 0x01ff);
-
-
-insert into t1 values ('AA'),('Aa'),('aa'),('aA');
-insert into t1 values ('CH'),('Ch'),('ch'),('cH');
-insert into t1 values ('DZ'),('Dz'),('dz'),('dZ');
-insert into t1 values ('DŽ'),('Dž'),('dž'),('dŽ');
-insert into t1 values ('IJ'),('Ij'),('ij'),('iJ');
-insert into t1 values ('LJ'),('Lj'),('lj'),('lJ');
-insert into t1 values ('LL'),('Ll'),('ll'),('lL');
-insert into t1 values ('NJ'),('Nj'),('nj'),('nJ');
-insert into t1 values ('OE'),('Oe'),('oe'),('oE');
-insert into t1 values ('SS'),('Ss'),('ss'),('sS');
-insert into t1 values ('RR'),('Rr'),('rr'),('rR');
+--source include/ctype_unicode_latin.inc
select group_concat(c1 order by c1) from t1 group by c1 collate utf8_unicode_ci;
select group_concat(c1 order by c1) from t1 group by c1 collate utf8_icelandic_ci;
@@ -214,7 +65,36 @@ select group_concat(c1 order by c1) from t1 group by c1 collate utf8_spanish2_ci
select group_concat(c1 order by c1) from t1 group by c1 collate utf8_roman_ci;
select group_concat(c1 order by c1) from t1 group by c1 collate utf8_esperanto_ci;
select group_concat(c1 order by c1) from t1 group by c1 collate utf8_hungarian_ci;
+select group_concat(c1 order by c1) from t1 group by c1 collate utf8_croatian_mysql561_ci;
select group_concat(c1 order by c1) from t1 group by c1 collate utf8_croatian_ci;
+select group_concat(c1 order by c1) from t1 group by c1 collate utf8_german2_ci;
+select group_concat(c1 order by c1) from t1 group by c1 collate utf8_unicode_520_ci;
+select group_concat(c1 order by c1) from t1 group by c1 collate utf8_vietnamese_ci;
+
+ALTER TABLE t1 CONVERT TO CHARACTER SET ucs2 COLLATE ucs2_bin;
+SELECT GROUP_CONCAT(c1 ORDER BY c1) FROM t1 GROUP BY c1 COLLATE ucs2_unicode_ci;
+SELECT GROUP_CONCAT(c1 ORDER BY c1) FROM t1 GROUP BY c1 COLLATE ucs2_icelandic_ci;
+SELECT GROUP_CONCAT(c1 ORDER BY c1) FROM t1 GROUP BY c1 COLLATE ucs2_latvian_ci;
+SELECT GROUP_CONCAT(c1 ORDER BY c1) FROM t1 GROUP BY c1 COLLATE ucs2_romanian_ci;
+SELECT GROUP_CONCAT(c1 ORDER BY c1) FROM t1 GROUP BY c1 COLLATE ucs2_slovenian_ci;
+SELECT GROUP_CONCAT(c1 ORDER BY c1) FROM t1 GROUP BY c1 COLLATE ucs2_polish_ci;
+SELECT GROUP_CONCAT(c1 ORDER BY c1) FROM t1 GROUP BY c1 COLLATE ucs2_estonian_ci;
+SELECT GROUP_CONCAT(c1 ORDER BY c1) FROM t1 GROUP BY c1 COLLATE ucs2_spanish_ci;
+SELECT GROUP_CONCAT(c1 ORDER BY c1) FROM t1 GROUP BY c1 COLLATE ucs2_swedish_ci;
+SELECT GROUP_CONCAT(c1 ORDER BY c1) FROM t1 GROUP BY c1 COLLATE ucs2_turkish_ci;
+SELECT GROUP_CONCAT(c1 ORDER BY c1) FROM t1 GROUP BY c1 COLLATE ucs2_czech_ci;
+SELECT GROUP_CONCAT(c1 ORDER BY c1) FROM t1 GROUP BY c1 COLLATE ucs2_danish_ci;
+SELECT GROUP_CONCAT(c1 ORDER BY c1) FROM t1 GROUP BY c1 COLLATE ucs2_lithuanian_ci;
+SELECT GROUP_CONCAT(c1 ORDER BY c1) FROM t1 GROUP BY c1 COLLATE ucs2_slovak_ci;
+SELECT GROUP_CONCAT(c1 ORDER BY c1) FROM t1 GROUP BY c1 COLLATE ucs2_spanish2_ci;
+SELECT GROUP_CONCAT(c1 ORDER BY c1) FROM t1 GROUP BY c1 COLLATE ucs2_roman_ci;
+SELECT GROUP_CONCAT(c1 ORDER BY c1) FROM t1 GROUP BY c1 COLLATE ucs2_esperanto_ci;
+SELECT GROUP_CONCAT(c1 ORDER BY c1) FROM t1 GROUP BY c1 COLLATE ucs2_hungarian_ci;
+SELECT GROUP_CONCAT(c1 ORDER BY c1) FROM t1 GROUP BY c1 COLLATE ucs2_croatian_mysql561_ci;
+SELECT GROUP_CONCAT(c1 ORDER BY c1) FROM t1 GROUP BY c1 COLLATE ucs2_croatian_ci;
+SELECT GROUP_CONCAT(c1 ORDER BY c1) FROM t1 GROUP BY c1 COLLATE ucs2_german2_ci;
+SELECT GROUP_CONCAT(c1 ORDER BY c1) FROM t1 GROUP BY c1 COLLATE ucs2_unicode_520_ci;
+SELECT GROUP_CONCAT(c1 ORDER BY c1) FROM t1 GROUP BY c1 COLLATE ucs2_vietnamese_ci;
drop table t1;
@@ -445,6 +325,55 @@ INSERT INTO t1 VALUES (CONVERT(_ucs2 0x06450647064506270646 USING utf8));
SELECT HEX(CONVERT(col1 USING ucs2)) FROM t1 ORDER BY col1 COLLATE utf8_persian_ci, col1 COLLATE utf8_bin;
DROP TABLE t1;
+#
+# Test all characters that appear in utf8_persia_ci tailoring
+#
+CREATE TABLE t1 (
+ a VARCHAR(10) CHARACTER SET utf8 COLLATE utf8_persian_ci,
+ offs INT NOT NULL
+);
+INSERT INTO t1 VALUES
+(_ucs2 0x066D, 1),(_ucs2 0x064E, 2),(_ucs2 0xFE76, 3),(_ucs2 0xFE77, 4),
+(_ucs2 0x0650, 5),(_ucs2 0xFE7A, 6),(_ucs2 0xFE7B, 7),(_ucs2 0x064F, 8),
+(_ucs2 0xFE78, 9),(_ucs2 0xFE79,10),(_ucs2 0x064B,11),(_ucs2 0xFE70,12),
+(_ucs2 0xFE71,13),(_ucs2 0x064D,14),(_ucs2 0xFE74,15),(_ucs2 0x064C,16),
+(_ucs2 0xFE72,17),
+
+(_ucs2 0xFE7F, 1),(_ucs2 0x0653, 2),(_ucs2 0x0654, 3),(_ucs2 0x0655, 4),
+(_ucs2 0x0670, 5),
+
+(_ucs2 0x0669, 1),(_ucs2 0x0622, 2),(_ucs2 0x0627, 3),(_ucs2 0x0671, 4),
+(_ucs2 0x0621, 5),(_ucs2 0x0623, 6),(_ucs2 0x0625, 7),(_ucs2 0x0624, 8),
+(_ucs2 0x0626, 9),
+
+(_ucs2 0x0642, 1),(_ucs2 0x06A9, 2),(_ucs2 0x0643, 3),
+
+(_ucs2 0x0648, 1),(_ucs2 0x0647, 2),(_ucs2 0x0629, 3),(_ucs2 0x06C0, 4),
+(_ucs2 0x06CC, 5),(_ucs2 0x0649, 6),(_ucs2 0x064A, 7),
+
+(_ucs2 0xFE80, 1),(_ucs2 0xFE81, 2),(_ucs2 0xFE82, 3),(_ucs2 0xFE8D, 4),
+(_ucs2 0xFE8E, 5),(_ucs2 0xFB50, 6),(_ucs2 0xFB51, 7),(_ucs2 0xFE80, 8),
+(_ucs2 0xFE83, 9),(_ucs2 0xFE84,10),(_ucs2 0xFE87,11),(_ucs2 0xFE88,12),
+(_ucs2 0xFE85,13),(_ucs2 0xFE86,14),(_ucs2 0x0689,16),(_ucs2 0x068A,17),
+
+(_ucs2 0xFEAE, 1),(_ucs2 0xFDFC, 2),
+
+(_ucs2 0xFED8, 1),(_ucs2 0xFB8E, 2),(_ucs2 0xFB8F, 3),(_ucs2 0xFB90, 4),
+(_ucs2 0xFB91, 5),(_ucs2 0xFED9, 6),(_ucs2 0xFEDA, 7),(_ucs2 0xFEDB, 8),
+(_ucs2 0xFEDC, 9),
+
+(_ucs2 0xFEEE, 1),(_ucs2 0xFEE9, 2),(_ucs2 0xFEEA, 3),(_ucs2 0xFEEB, 4),
+(_ucs2 0xFEEC, 5),(_ucs2 0xFE93, 6),(_ucs2 0xFE94, 7),(_ucs2 0xFBA4, 8),
+(_ucs2 0xFBA5, 9),(_ucs2 0xFBFC,10),(_ucs2 0xFBFD,11),(_ucs2 0xFBFE,12),
+(_ucs2 0xFBFF,13),(_ucs2 0xFEEF,14),(_ucs2 0xFEF0,15),(_ucs2 0xFEF1,16),
+(_ucs2 0xFEF2,17),(_ucs2 0xFEF3,18),(_ucs2 0xFEF4,19),(_ucs2 0xFEF5,20),
+(_ucs2 0xFEF6,21),(_ucs2 0xFEF7,22),(_ucs2 0xFEF8,23),(_ucs2 0xFEF9,24),
+(_ucs2 0xFEFA,25),(_ucs2 0xFEFB,26),(_ucs2 0xFEFC,27);
+
+SELECT HEX(CONVERT(a USING ucs2)), offs, hex(weight_string(a)), a
+FROM t1 ORDER BY a, offs, BINARY a;
+DROP TABLE t1;
+
SET @test_character_set= 'utf8';
SET @test_collation= 'utf8_swedish_ci';
-- source include/ctype_common.inc
@@ -547,6 +476,7 @@ set collation_connection=ucs2_unicode_ci;
set names utf8;
-- echo End for 5.0 tests
+--echo End of 5.1 tests
--echo #
--echo # Start of 5.5 tests
@@ -561,7 +491,7 @@ SET collation_connection=ucs2_czech_ci;
--source include/ctype_czech.inc
--source include/ctype_like_ignorable.inc
-create table t1 (a int, c1 varchar(200) collate utf8_croatian_ci, key (c1));
+create table t1 (a int, c1 varchar(200) collate utf8_croatian_mysql561_ci, key (c1));
insert into t1 values (1,'=> DZ'),(2,'=> Dz'),(3,'=> dz'),(4,'=> dZ');
insert into t1 values (5,'=> DŽ'),(6,'=> Dž'),(7,'=> dž'),(8,'=> dŽ');
insert into t1 values (9,'=> dž'),(10,'=> DŽ');
@@ -591,3 +521,102 @@ SET NAMES utf8 COLLATE utf8_unicode_ci;
--echo #
--echo # End of 5.5 tests
--echo #
+
+
+--echo #
+--echo # Start of 5.6 tests
+--echo #
+
+--echo #
+--echo # WL#3664 WEIGHT_STRING
+--echo #
+
+set collation_connection=ucs2_unicode_ci;
+--source include/weight_string.inc
+--source include/weight_string_euro.inc
+--source include/weight_string_l1.inc
+
+set @@collation_connection=utf8_unicode_ci;
+--source include/weight_string.inc
+--source include/weight_string_euro.inc
+--source include/weight_string_l1.inc
+
+set @@collation_connection=utf8_czech_ci;
+--source include/weight_string_chde.inc
+
+set @@collation_connection=ucs2_czech_ci;
+--source include/weight_string_chde.inc
+
+--echo #
+--echo # Bug#33077 weight of supplementary characters is not 0xfffd
+--echo #
+select hex(weight_string(_utf8mb4 0xF0908080 /* U+10000 */ collate utf8mb4_unicode_ci));
+
+--echo #
+--echo # Bug#53064 garbled data when using utf8_german2_ci collation
+--echo #
+CREATE TABLE t1 (s1 VARCHAR(10) COLLATE utf8_german2_ci);
+INSERT INTO t1 VALUES ('a'),('ae'),('af');
+SELECT s1,hex(s1),hex(weight_string(s1)) FROM t1 ORDER BY s1;
+DROP TABLE t1;
+
+--echo #
+--echo # WL#4013 Unicode german2 collation
+--echo #
+SET collation_connection=utf8_german2_ci;
+--source include/ctype_german.inc
+
+--echo #
+--echo # WL#2673 Unicode Collation Algorithm new version
+--echo #
+SET NAMES utf8mb4 COLLATE utf8mb4_unicode_520_ci;
+--source include/ctype_unicode520.inc
+
+--echo #
+--echo # End of 5.6 tests
+--echo #
+
+
+--echo #
+--echo # Start of MariaDB-10.0 tests
+--echo #
+--echo
+
+SET NAMES utf8 COLLATE utf8_unicode_ci;
+--source include/ctype_like_cond_propagation.inc
+--source include/ctype_like_cond_propagation_utf8_german.inc
+
+SET NAMES utf8 COLLATE utf8_german2_ci;
+--source include/ctype_like_cond_propagation.inc
+--source include/ctype_like_cond_propagation_utf8_german.inc
+
+--echo #
+--echo # MDEV-4929 Myanmar collation
+--echo #
+SET NAMES utf8 COLLATE utf8_myanmar_ci;
+--source include/ctype_myanmar.inc
+SET collation_connection=ucs2_myanmar_ci;
+--source include/ctype_myanmar.inc
+
+--echo #
+--echo # MDEV-7366 SELECT 'a' = BINARY 'A' returns 1 (utf8 charset, utf8_unicode_ci collation)
+--echo #
+SET NAMES utf8 COLLATE utf8_unicode_ci;
+SELECT 'a' = BINARY 'A';
+SELECT BINARY 'A' = 'a';
+
+--echo #
+--echo # Wrong result set for WHERE a='oe' COLLATE utf8_german2_ci AND a='oe'
+--echo #
+SET NAMES utf8 COLLATE utf8_german2_ci;
+CREATE TABLE t1 (a CHAR(10) CHARACTER SET utf8);
+INSERT INTO t1 VALUES ('ö'),('oe');
+SELECT * FROM t1 WHERE a='oe' AND a='oe' COLLATE utf8_german2_ci;
+SELECT * FROM t1 WHERE a='oe' COLLATE utf8_german2_ci AND a='oe';
+EXPLAIN EXTENDED SELECT * FROM t1 WHERE a='oe' AND a='oe' COLLATE utf8_german2_ci;
+EXPLAIN EXTENDED SELECT * FROM t1 WHERE a='oe' COLLATE utf8_german2_ci AND a='oe';
+DROP TABLE t1;
+
+--echo #
+--echo # End of MariaDB-10.0 tests
+--echo #
diff --git a/mysql-test/t/ctype_ucs.test b/mysql-test/t/ctype_ucs.test
index 6f846eae771..d78977a3d1c 100644
--- a/mysql-test/t/ctype_ucs.test
+++ b/mysql-test/t/ctype_ucs.test
@@ -116,49 +116,7 @@ drop table t2;
SET NAMES koi8r;
SET character_set_connection=ucs2;
-
-create table t1 (a varchar(10) character set ucs2, key(a));
-insert into t1 values ("a"),("abc"),("abcd"),("hello"),("test");
-explain select * from t1 where a like 'abc%';
-explain select * from t1 where a like concat('abc','%');
-select * from t1 where a like "abc%";
-select * from t1 where a like concat("abc","%");
-select * from t1 where a like "ABC%";
-select * from t1 where a like "test%";
-select * from t1 where a like "te_t";
-select * from t1 where a like "%a%";
-select * from t1 where a like "%abcd%";
-select * from t1 where a like "%abc\d%";
-drop table t1;
-
-#
-# More LIKE test: bug#2619
-#
-select 'AA' like 'AA';
-select 'AA' like 'A%A';
-select 'AA' like 'A%%A';
-select 'AA' like 'AA%';
-select 'AA' like '%AA%';
-select 'AA' like '%A';
-select 'AA' like '%AA';
-select 'AA' like 'A%A%';
-select 'AA' like '_%_%';
-select 'AA' like '%A%A';
-select 'AAA'like 'A%A%A';
-
-select 'AZ' like 'AZ';
-select 'AZ' like 'A%Z';
-select 'AZ' like 'A%%Z';
-select 'AZ' like 'AZ%';
-select 'AZ' like '%AZ%';
-select 'AZ' like '%Z';
-select 'AZ' like '%AZ';
-select 'AZ' like 'A%Z%';
-select 'AZ' like '_%_%';
-select 'AZ' like '%A%Z';
-select 'AZ' like 'A_';
-select 'AZ' like '_Z';
-select 'AMZ'like 'A%M%Z';
+--source include/ctype_like.inc
CREATE TABLE t1 (a VARCHAR(10) CHARACTER SET ucs2);
INSERT INTO t1 VALUES ('ÆÙ×Á'),('æÙ×Á'),('Æù×Á'),('ÆÙ÷Á'),('ÆÙ×á'),('æù÷á');
@@ -910,3 +868,122 @@ DROP TABLE t1;
--echo #
--echo # End of 5.5 tests
--echo #
+
+
+--echo #
+--echo # Start of 5.6 tests
+--echo #
+
+--echo #
+--echo # WL#3664 WEIGHT_STRING
+--echo #
+
+set collation_connection=ucs2_general_ci;
+--source include/weight_string.inc
+--source include/weight_string_euro.inc
+--source include/weight_string_l1.inc
+
+set collation_connection=ucs2_bin;
+--source include/weight_string.inc
+--source include/weight_string_euro.inc
+--source include/weight_string_l1.inc
+
+--echo #
+--echo # Bug #36418 Character sets: crash if char(256 using utf32)
+--echo #
+select hex(char(0x01 using ucs2));
+select hex(char(0x0102 using ucs2));
+select hex(char(0x010203 using ucs2));
+select hex(char(0x01020304 using ucs2));
+
+--echo #
+--echo # Bug#10094 Displays wrong error message for UNIQUE key index on CHAR(255) Unicode datatype
+--echo #
+CREATE TABLE t1 (f1 CHAR(255) unicode);
+INSERT INTO t1 values ('abc'),('bcd'),('abc');
+--error ER_DUP_ENTRY
+ALTER TABLE t1 ADD UNIQUE Index_1 (f1);
+DROP TABLE t1;
+
+--echo #
+--echo # Test how character set works with date/time
+--echo #
+SET collation_connection=ucs2_general_ci;
+--source include/ctype_datetime.inc
+SET NAMES latin1;
+
+--echo #
+--echo # WL#4013 Unicode german2 collation
+--echo #
+SET collation_connection=ucs2_german2_ci;
+--source include/ctype_german.inc
+
+--echo #
+--echo # Bug#59145 valgrind warnings for uninitialized values in my_strtoll10_mb2
+--echo #
+SET NAMES latin1;
+SELECT CONVERT(CHAR(NULL USING ucs2), UNSIGNED);
+DO IFNULL(CHAR(NULL USING ucs2), '');
+DO CAST(CONVERT('' USING ucs2) AS UNSIGNED);
+
+--echo #
+--echo # Test error message for conversion using different charset
+--echo #
+
+CREATE TABLE t1 (a DECIMAL(2,0));
+
+SET sql_mode='strict_all_tables';
+--error ER_TRUNCATED_WRONG_VALUE_FOR_FIELD
+INSERT INTO t1 VALUES (CONVERT('9e99999999' USING ucs2));
+SET sql_mode=DEFAULT;
+
+INSERT INTO t1 VALUES (CONVERT('aaa' USING ucs2));
+
+DROP TABLE t1;
+
+--echo #
+--echo # End of 5.6 tests
+--echo #
+
+
+--echo #
+--echo # Start of 10.0 tests
+--echo #
+
+SET NAMES latin1, collation_connection=ucs2_bin;
+--source include/ctype_like_cond_propagation.inc
+SET NAMES latin1, collation_connection=ucs2_general_ci;
+--source include/ctype_like_cond_propagation.inc
+SET NAMES latin1;
+
+--echo #
+--echo # MDEV-6661 PI() does not work well in UCS2/UTF16/UTF32 context
+--echo #
+SELECT CONCAT(CONVERT('pi=' USING ucs2),PI()) AS PI;
+
+--echo #
+--echo # MDEV-6695 Bad column name for UCS2 string literals
+--echo #
+SET NAMES utf8, character_set_connection=ucs2;
+SELECT 'a','aa';
+
+
+--echo #
+--echo # MDEV-10306 Wrong results with combination of CONCAT, SUBSTR and CONVERT in subquery
+--echo #
+
+SET NAMES utf8, character_set_connection=ucs2;
+SET @save_optimizer_switch=@@optimizer_switch;
+SET optimizer_switch=_utf8'derived_merge=on';
+CREATE TABLE t1 (t VARCHAR(10) CHARSET latin1);
+INSERT INTO t1 VALUES('abcdefghi');
+SET NAMES utf8, character_set_connection=ucs2;
+SELECT CONCAT(t2,'-',t2) c2 FROM (SELECT HEX(t) t2 FROM t1) sub;
+SELECT CONCAT(t2,'-',t2) c2 FROM (SELECT TO_BASE64(t) t2 FROM t1) sub;
+DROP TABLE t1;
+SET optimizer_switch=@save_optimizer_switch;
+
+
+--echo #
+--echo # End of 10.0 tests
+--echo #
diff --git a/mysql-test/t/ctype_ucs2_def.test b/mysql-test/t/ctype_ucs2_def.test
index b146dc63626..e297fa5ccf1 100644
--- a/mysql-test/t/ctype_ucs2_def.test
+++ b/mysql-test/t/ctype_ucs2_def.test
@@ -1,5 +1,7 @@
-- source include/have_ucs2.inc
+call mtr.add_suppression("'ucs2' can not be used as client character set");
+
#
# MySQL Bug#15276: MySQL ignores collation-server
#
diff --git a/mysql-test/t/ctype_ucs2_query_cache.test b/mysql-test/t/ctype_ucs2_query_cache.test
index 0ac09b2ba4b..ace826aec44 100644
--- a/mysql-test/t/ctype_ucs2_query_cache.test
+++ b/mysql-test/t/ctype_ucs2_query_cache.test
@@ -1,6 +1,8 @@
-- source include/have_query_cache.inc
-- source include/have_ucs2.inc
+call mtr.add_suppression("'ucs2' can not be used as client character set");
+
--echo #
--echo # Start of 5.5 tests
--echo #
diff --git a/mysql-test/t/ctype_ujis.test b/mysql-test/t/ctype_ujis.test
index 4e1ee55e019..48dc0e63058 100644
--- a/mysql-test/t/ctype_ujis.test
+++ b/mysql-test/t/ctype_ujis.test
@@ -1220,6 +1220,7 @@ set names default;
set character_set_database=default;
set character_set_server=default;
+--echo End of 5.1 tests
--echo #
--echo # Start of 5.5 tests
@@ -1321,3 +1322,50 @@ DROP TABLE t1;
--echo #
--echo # End of 5.5 tests
--echo #
+
+
+--echo #
+--echo # Start of 5.6 tests
+--echo #
+
+--echo #
+--echo # WL#3664 WEIGHT_STRING
+--echo #
+
+set names ujis;
+--source include/weight_string.inc
+--source include/weight_string_l1.inc
+--source include/weight_string_A1A1.inc
+--source include/weight_string_8EA1.inc
+--source include/weight_string_8FA2C3.inc
+
+set collation_connection=ujis_bin;
+--source include/weight_string.inc
+--source include/weight_string_l1.inc
+--source include/weight_string_A1A1.inc
+--source include/weight_string_8EA1.inc
+--source include/weight_string_8FA2C3.inc
+
+--echo #
+--echo # End of 5.6 tests
+--echo #
+
+
+--echo #
+--echo # Start of 10.0 tests
+--echo #
+
+--echo #
+--echo # MDEV-6776 ujis and eucjmps erroneously accept 0x8EA0 as a valid byte sequence
+--echo #
+CREATE TABLE t1 (a VARCHAR(10) CHARACTER SET ujis);
+INSERT INTO t1 VALUES (0x8EA0);
+SELECT HEX(a), CHAR_LENGTH(a) FROM t1;
+DROP TABLE t1;
+--error ER_INVALID_CHARACTER_STRING
+SELECT _ujis 0x8EA0;
+
+
+--echo #
+--echo # End of 10.0 tests
+--echo #
diff --git a/mysql-test/t/ctype_upgrade.test b/mysql-test/t/ctype_upgrade.test
new file mode 100644
index 00000000000..cc59d1e4401
--- /dev/null
+++ b/mysql-test/t/ctype_upgrade.test
@@ -0,0 +1,198 @@
+-- source include/mysql_upgrade_preparation.inc
+-- source include/have_innodb.inc
+
+call mtr.add_suppression("Table rebuild required");
+let $MYSQLD_DATADIR= `select @@datadir`;
+
+--echo #
+--echo # Upgrade from Maria-5.3.13:
+--echo # Checking utf8_croatian_ci in a VARCHAR column
+--echo #
+
+--echo # Copying maria050313_utf8_croatian_ci.* to MYSQLD_DATADIR
+--copy_file std_data/ctype_upgrade/maria050313_utf8_croatian_ci.frm $MYSQLD_DATADIR/test/maria050313_utf8_croatian_ci.frm
+--copy_file std_data/ctype_upgrade/maria050313_utf8_croatian_ci.MYD $MYSQLD_DATADIR/test/maria050313_utf8_croatian_ci.MYD
+--copy_file std_data/ctype_upgrade/maria050313_utf8_croatian_ci.MYI $MYSQLD_DATADIR/test/maria050313_utf8_croatian_ci.MYI
+# Following test should show that table is corrupted
+CHECK TABLE maria050313_utf8_croatian_ci FOR UPGRADE;
+--error ER_TABLE_NEEDS_REBUILD
+SHOW CREATE TABLE maria050313_utf8_croatian_ci;
+# Check that REPAIR fixes the table
+REPAIR TABLE maria050313_utf8_croatian_ci;
+CHECK TABLE maria050313_utf8_croatian_ci FOR UPGRADE;
+SHOW CREATE TABLE maria050313_utf8_croatian_ci;
+SELECT count(*) FROM maria050313_utf8_croatian_ci;
+DROP TABLE maria050313_utf8_croatian_ci;
+
+--echo # Copying maria050313_utf8_croatian_ci.* to MYSQLD_DATADIR
+--copy_file std_data/ctype_upgrade/maria050313_utf8_croatian_ci.frm $MYSQLD_DATADIR/test/maria050313_utf8_croatian_ci.frm
+--copy_file std_data/ctype_upgrade/maria050313_utf8_croatian_ci.MYD $MYSQLD_DATADIR/test/maria050313_utf8_croatian_ci.MYD
+--copy_file std_data/ctype_upgrade/maria050313_utf8_croatian_ci.MYI $MYSQLD_DATADIR/test/maria050313_utf8_croatian_ci.MYI
+ALTER TABLE maria050313_utf8_croatian_ci FORCE;
+SHOW CREATE TABLE maria050313_utf8_croatian_ci;
+SELECT GROUP_CONCAT(a ORDER BY BINARY a) FROM maria050313_utf8_croatian_ci GROUP BY a;
+DROP TABLE maria050313_utf8_croatian_ci;
+
+
+--echo #
+--echo # Upgrade from Maria-5.3.13:
+--echo # Checking ucs2_croatian_ci in the table default collation
+--echo #
+
+--echo # Copying maria050313_ucs2_croatian_ci.* to MYSQLD_DATADIR
+--copy_file std_data/ctype_upgrade/maria050313_ucs2_croatian_ci_def.frm $MYSQLD_DATADIR/test/maria050313_ucs2_croatian_ci_def.frm
+--copy_file std_data/ctype_upgrade/maria050313_ucs2_croatian_ci_def.MYD $MYSQLD_DATADIR/test/maria050313_ucs2_croatian_ci_def.MYD
+--copy_file std_data/ctype_upgrade/maria050313_ucs2_croatian_ci_def.MYI $MYSQLD_DATADIR/test/maria050313_ucs2_croatian_ci_def.MYI
+CHECK TABLE maria050313_ucs2_croatian_ci_def FOR UPGRADE;
+--error ER_TABLE_NEEDS_REBUILD
+SELECT count(*) FROM maria050313_ucs2_croatian_ci_def;
+REPAIR TABLE maria050313_ucs2_croatian_ci_def;
+SHOW CREATE TABLE maria050313_ucs2_croatian_ci_def;
+DROP TABLE maria050313_ucs2_croatian_ci_def;
+
+--echo # Copying maria050313_ucs2_croatian_ci.* to MYSQLD_DATADIR
+--copy_file std_data/ctype_upgrade/maria050313_ucs2_croatian_ci_def.frm $MYSQLD_DATADIR/test/maria050313_ucs2_croatian_ci_def.frm
+--copy_file std_data/ctype_upgrade/maria050313_ucs2_croatian_ci_def.MYD $MYSQLD_DATADIR/test/maria050313_ucs2_croatian_ci_def.MYD
+--copy_file std_data/ctype_upgrade/maria050313_ucs2_croatian_ci_def.MYI $MYSQLD_DATADIR/test/maria050313_ucs2_croatian_ci_def.MYI
+CHECK TABLE maria050313_ucs2_croatian_ci_def;
+REPAIR TABLE maria050313_ucs2_croatian_ci_def;
+CHECK TABLE maria050313_ucs2_croatian_ci_def;
+SHOW CREATE TABLE maria050313_ucs2_croatian_ci_def;
+SELECT * FROM maria050313_ucs2_croatian_ci_def ORDER BY a;
+DROP TABLE maria050313_ucs2_croatian_ci_def;
+
+
+
+--echo #
+--echo # Upgrade from Maria-5.5.33
+--echo # Checking utf8_croatian_ci, utf8mb4_croatian_ci, ucs2_croatian_ci,
+--echo # utf16_croatian_ci, utf32_croatian_ci
+--echo #
+
+--echo # Copying maria050533_xxx_croatian_ci.* to MYSQLD_DATADIR
+--copy_file std_data/ctype_upgrade/maria050533_xxx_croatian_ci.frm $MYSQLD_DATADIR/test/maria050533_xxx_croatian_ci.frm
+--copy_file std_data/ctype_upgrade/maria050533_xxx_croatian_ci.MYD $MYSQLD_DATADIR/test/maria050533_xxx_croatian_ci.MYD
+--copy_file std_data/ctype_upgrade/maria050533_xxx_croatian_ci.MYI $MYSQLD_DATADIR/test/maria050533_xxx_croatian_ci.MYI
+CHECK TABLE maria050533_xxx_croatian_ci FOR UPGRADE;
+REPAIR TABLE maria050533_xxx_croatian_ci;
+SHOW CREATE TABLE maria050533_xxx_croatian_ci;
+SELECT count(*) FROM maria050533_xxx_croatian_ci;
+DROP TABLE maria050533_xxx_croatian_ci;
+
+--echo # Copying maria050533_xxx_croatian_ci.* to MYSQLD_DATADIR
+--copy_file std_data/ctype_upgrade/maria050533_xxx_croatian_ci.frm $MYSQLD_DATADIR/test/maria050533_xxx_croatian_ci.frm
+--copy_file std_data/ctype_upgrade/maria050533_xxx_croatian_ci.MYD $MYSQLD_DATADIR/test/maria050533_xxx_croatian_ci.MYD
+--copy_file std_data/ctype_upgrade/maria050533_xxx_croatian_ci.MYI $MYSQLD_DATADIR/test/maria050533_xxx_croatian_ci.MYI
+ALTER TABLE maria050533_xxx_croatian_ci FORCE;
+SHOW CREATE TABLE maria050533_xxx_croatian_ci;
+SELECT GROUP_CONCAT(a ORDER BY BINARY a) FROM maria050533_xxx_croatian_ci GROUP BY a;
+SELECT GROUP_CONCAT(b ORDER BY BINARY b) FROM maria050533_xxx_croatian_ci GROUP BY b;
+SELECT GROUP_CONCAT(c ORDER BY BINARY c) FROM maria050533_xxx_croatian_ci GROUP BY c;
+SELECT GROUP_CONCAT(d ORDER BY BINARY d) FROM maria050533_xxx_croatian_ci GROUP BY d;
+SELECT GROUP_CONCAT(e ORDER BY BINARY e) FROM maria050533_xxx_croatian_ci GROUP BY e;
+DROP TABLE maria050533_xxx_croatian_ci;
+
+
+--echo #
+--echo # Upgrade from Maria-10.0.4
+--echo # Checking utf8_croatian_ci, utf8mb4_croatian_ci, ucs2_croatian_ci,
+--echo # utf16_croatian_ci, utf32_croatian_ci
+--echo #
+
+--echo # Copying maria100004_xxx_croatian_ci.* to MYSQLD_DATADIR
+--copy_file std_data/ctype_upgrade/maria100004_xxx_croatian_ci.frm $MYSQLD_DATADIR/test/maria100004_xxx_croatian_ci.frm
+--copy_file std_data/ctype_upgrade/maria100004_xxx_croatian_ci.MYD $MYSQLD_DATADIR/test/maria100004_xxx_croatian_ci.MYD
+--copy_file std_data/ctype_upgrade/maria100004_xxx_croatian_ci.MYI $MYSQLD_DATADIR/test/maria100004_xxx_croatian_ci.MYI
+CHECK TABLE maria100004_xxx_croatian_ci FOR UPGRADE;
+--error ER_TABLE_NEEDS_REBUILD
+SELECT count(*) FROM maria100004_xxx_croatian_ci;
+REPAIR TABLE maria100004_xxx_croatian_ci;
+SHOW CREATE TABLE maria100004_xxx_croatian_ci;
+DROP TABLE maria100004_xxx_croatian_ci;
+
+--echo # Copying maria100004_xxx_croatian_ci.* to MYSQLD_DATADIR
+--copy_file std_data/ctype_upgrade/maria100004_xxx_croatian_ci.frm $MYSQLD_DATADIR/test/maria100004_xxx_croatian_ci.frm
+--copy_file std_data/ctype_upgrade/maria100004_xxx_croatian_ci.MYD $MYSQLD_DATADIR/test/maria100004_xxx_croatian_ci.MYD
+--copy_file std_data/ctype_upgrade/maria100004_xxx_croatian_ci.MYI $MYSQLD_DATADIR/test/maria100004_xxx_croatian_ci.MYI
+ALTER TABLE maria100004_xxx_croatian_ci FORCE;
+SHOW CREATE TABLE maria100004_xxx_croatian_ci;
+SELECT GROUP_CONCAT(a ORDER BY BINARY a) FROM maria100004_xxx_croatian_ci GROUP BY a;
+SELECT GROUP_CONCAT(b ORDER BY BINARY b) FROM maria100004_xxx_croatian_ci GROUP BY b;
+SELECT GROUP_CONCAT(c ORDER BY BINARY c) FROM maria100004_xxx_croatian_ci GROUP BY c;
+SELECT GROUP_CONCAT(d ORDER BY BINARY d) FROM maria100004_xxx_croatian_ci GROUP BY d;
+SELECT GROUP_CONCAT(e ORDER BY BINARY e) FROM maria100004_xxx_croatian_ci GROUP BY e;
+DROP TABLE maria100004_xxx_croatian_ci;
+
+
+
+--echo #
+--echo # Upgrade from MySQL-5.6.14
+--echo # Checking utf8_croatian_ci, utf8mb4_croatian_ci, ucs2_croatian_ci,
+--echo # utf16_croatian_ci, utf32_croatian_ci
+--echo #
+
+--echo # Copying mysql050614_xxx_croatian_ci.* to MYSQLD_DATADIR
+--copy_file std_data/ctype_upgrade/mysql050614_xxx_croatian_ci.frm $MYSQLD_DATADIR/test/mysql050614_xxx_croatian_ci.frm
+--copy_file std_data/ctype_upgrade/mysql050614_xxx_croatian_ci.MYD $MYSQLD_DATADIR/test/mysql050614_xxx_croatian_ci.MYD
+--copy_file std_data/ctype_upgrade/mysql050614_xxx_croatian_ci.MYI $MYSQLD_DATADIR/test/mysql050614_xxx_croatian_ci.MYI
+CHECK TABLE mysql050614_xxx_croatian_ci FOR UPGRADE;
+SHOW CREATE TABLE mysql050614_xxx_croatian_ci;
+SELECT GROUP_CONCAT(a ORDER BY BINARY a) FROM mysql050614_xxx_croatian_ci GROUP BY a;
+SELECT GROUP_CONCAT(b ORDER BY BINARY b) FROM mysql050614_xxx_croatian_ci GROUP BY b;
+SELECT GROUP_CONCAT(c ORDER BY BINARY c) FROM mysql050614_xxx_croatian_ci GROUP BY c;
+SELECT GROUP_CONCAT(d ORDER BY BINARY d) FROM mysql050614_xxx_croatian_ci GROUP BY d;
+SELECT GROUP_CONCAT(e ORDER BY BINARY e) FROM mysql050614_xxx_croatian_ci GROUP BY e;
+DROP TABLE mysql050614_xxx_croatian_ci;
+
+
+--echo #
+--echo # Checking mysql_upgrade
+--echo #
+--copy_file std_data/ctype_upgrade/maria050313_utf8_croatian_ci.frm $MYSQLD_DATADIR/test/maria050313_utf8_croatian_ci.frm
+--copy_file std_data/ctype_upgrade/maria050313_utf8_croatian_ci.MYD $MYSQLD_DATADIR/test/maria050313_utf8_croatian_ci.MYD
+--copy_file std_data/ctype_upgrade/maria050313_utf8_croatian_ci.MYI $MYSQLD_DATADIR/test/maria050313_utf8_croatian_ci.MYI
+
+--copy_file std_data/ctype_upgrade/maria050313_ucs2_croatian_ci_def.frm $MYSQLD_DATADIR/test/maria050313_ucs2_croatian_ci_def.frm
+--copy_file std_data/ctype_upgrade/maria050313_ucs2_croatian_ci_def.MYD $MYSQLD_DATADIR/test/maria050313_ucs2_croatian_ci_def.MYD
+--copy_file std_data/ctype_upgrade/maria050313_ucs2_croatian_ci_def.MYI $MYSQLD_DATADIR/test/maria050313_ucs2_croatian_ci_def.MYI
+
+--copy_file std_data/ctype_upgrade/maria050533_xxx_croatian_ci.frm $MYSQLD_DATADIR/test/maria050533_xxx_croatian_ci.frm
+--copy_file std_data/ctype_upgrade/maria050533_xxx_croatian_ci.MYD $MYSQLD_DATADIR/test/maria050533_xxx_croatian_ci.MYD
+--copy_file std_data/ctype_upgrade/maria050533_xxx_croatian_ci.MYI $MYSQLD_DATADIR/test/maria050533_xxx_croatian_ci.MYI
+
+--copy_file std_data/ctype_upgrade/maria100004_xxx_croatian_ci.frm $MYSQLD_DATADIR/test/maria100004_xxx_croatian_ci.frm
+--copy_file std_data/ctype_upgrade/maria100004_xxx_croatian_ci.MYD $MYSQLD_DATADIR/test/maria100004_xxx_croatian_ci.MYD
+--copy_file std_data/ctype_upgrade/maria100004_xxx_croatian_ci.MYI $MYSQLD_DATADIR/test/maria100004_xxx_croatian_ci.MYI
+
+--copy_file std_data/ctype_upgrade/mysql050614_xxx_croatian_ci.frm $MYSQLD_DATADIR/test/mysql050614_xxx_croatian_ci.frm
+--copy_file std_data/ctype_upgrade/mysql050614_xxx_croatian_ci.MYD $MYSQLD_DATADIR/test/mysql050614_xxx_croatian_ci.MYD
+--copy_file std_data/ctype_upgrade/mysql050614_xxx_croatian_ci.MYI $MYSQLD_DATADIR/test/mysql050614_xxx_croatian_ci.MYI
+
+--echo # Running mysql_upgrade
+--exec $MYSQL_UPGRADE 2>&1
+
+
+--echo # Running mysql_upgrade for the second time
+--echo # This should report OK for all tables
+--exec $MYSQL_UPGRADE --force 2>&1
+
+SHOW CREATE TABLE maria050313_ucs2_croatian_ci_def;
+SELECT * FROM maria050313_ucs2_croatian_ci_def ORDER BY a;
+
+SHOW CREATE TABLE maria050313_utf8_croatian_ci;
+SELECT GROUP_CONCAT(a ORDER BY BINARY a) FROM maria050313_utf8_croatian_ci GROUP BY a;
+
+SHOW CREATE TABLE maria050533_xxx_croatian_ci;
+SELECT GROUP_CONCAT(a ORDER BY BINARY a) FROM maria050533_xxx_croatian_ci GROUP BY a;
+
+SHOW CREATE TABLE maria100004_xxx_croatian_ci;
+SELECT GROUP_CONCAT(a ORDER BY BINARY a) FROM maria100004_xxx_croatian_ci GROUP BY a;
+
+SHOW CREATE TABLE mysql050614_xxx_croatian_ci;
+SELECT GROUP_CONCAT(a ORDER BY BINARY a) FROM mysql050614_xxx_croatian_ci GROUP BY a;
+
+DROP TABLE maria050313_ucs2_croatian_ci_def;
+DROP TABLE maria050313_utf8_croatian_ci;
+DROP TABLE maria050533_xxx_croatian_ci;
+DROP TABLE maria100004_xxx_croatian_ci;
+DROP TABLE mysql050614_xxx_croatian_ci;
diff --git a/mysql-test/t/ctype_utf16.test b/mysql-test/t/ctype_utf16.test
index ab87c7da0d8..cda85239512 100644
--- a/mysql-test/t/ctype_utf16.test
+++ b/mysql-test/t/ctype_utf16.test
@@ -653,6 +653,7 @@ select 1.1 + '1.2xxx';
# Testing strntoll10_utf16
# Testing cs->cset->strtoll10
select left('aaa','1');
+--source include/ctype_strtoll10.inc
#
# Testing cs->cset->strntoull10rnd
@@ -789,7 +790,9 @@ SELECT 'a' AS id, REPEAT('bla bla', 100) AS body) t1;
--echo #
--echo # MDEV-6865 Merge Bug#18935421 RPAD DIES WITH CERTAIN PADSTR INTPUTS..
--echo #
+--error ER_INVALID_CHARACTER_STRING
DO RPAD(_utf16 0x0061 COLLATE utf16_unicode_ci, 10000, 0x0061DE989999);
+--error ER_INVALID_CHARACTER_STRING
DO LPAD(_utf16 0x0061 COLLATE utf16_unicode_ci, 10000, 0x0061DE989999);
--echo #
@@ -804,3 +807,65 @@ SET NAMES utf8;
--echo #
--echo # End of 5.5 tests
--echo #
+
+
+--echo #
+--echo # Start of 5.6 tests
+--echo #
+
+--echo #
+--echo # WL#3664 WEIGHT_STRING
+--echo #
+
+set collation_connection=utf16_general_ci;
+--source include/weight_string.inc
+--source include/weight_string_euro.inc
+select hex(weight_string(_utf16 0xD800DC00));
+select hex(weight_string(_utf16 0xD800DC01));
+--source include/weight_string_l1.inc
+
+set collation_connection=utf16_bin;
+--source include/weight_string.inc
+--source include/weight_string_euro.inc
+--source include/weight_string_l1.inc
+
+--echo #
+--echo # End of 5.6 tests
+--echo #
+
+--echo #
+--echo # Start of 10.0 tests
+--echo #
+
+--echo #
+--echo # MDEV-6661 PI() does not work well in UCS2/UTF16/UTF32 context
+--echo #
+SELECT CONCAT(CONVERT('pi=' USING utf16),PI()) AS PI;
+
+--echo #
+--echo # MDEV-6666 Malformed result for CONCAT(utf8_column, binary_string)
+--echo #
+
+SET NAMES utf8mb4;
+CREATE TABLE t1 (a VARCHAR(10) CHARACTER SET utf16);
+INSERT INTO t1 VALUES ('a');
+--error ER_INVALID_CHARACTER_STRING
+SELECT CONCAT(a,0xD800) FROM t1;
+SELECT CONCAT(a,0xD800DC00) FROM t1;
+SELECT CONCAT(a,0x00FF) FROM t1;
+DROP TABLE t1;
+--error ER_INVALID_CHARACTER_STRING
+SELECT CONCAT(_utf16'a' COLLATE utf16_unicode_ci, _binary 0xD800);
+PREPARE stmt FROM "SELECT CONCAT(_utf16'a' COLLATE utf16_unicode_ci, ?)";
+SET @arg00=_binary 0xD800;
+--error ER_INVALID_CHARACTER_STRING
+EXECUTE stmt USING @arg00;
+SET @arg00=_binary 0xD800DC00;
+EXECUTE stmt USING @arg00;
+SET @arg00=_binary 0x00FF;
+EXECUTE stmt USING @arg00;
+DEALLOCATE PREPARE stmt;
+
+--echo #
+--echo # End of 10.0 tests
+--echo #
diff --git a/mysql-test/t/ctype_utf16_def.test b/mysql-test/t/ctype_utf16_def.test
index d8ef4a4278b..0829cd53285 100644
--- a/mysql-test/t/ctype_utf16_def.test
+++ b/mysql-test/t/ctype_utf16_def.test
@@ -1,4 +1,5 @@
--source include/have_utf16.inc
+call mtr.add_suppression("'utf16' can not be used as client character set");
#
# Bug #32391 Character sets: crash with --character-set-server
diff --git a/mysql-test/t/ctype_utf16_uca.test b/mysql-test/t/ctype_utf16_uca.test
index a6295c82dec..63799054ae8 100644
--- a/mysql-test/t/ctype_utf16_uca.test
+++ b/mysql-test/t/ctype_utf16_uca.test
@@ -1,3 +1,4 @@
+-- source include/have_ucs2.inc
-- source include/have_utf16.inc
--disable_warnings
@@ -32,156 +33,7 @@ DROP TABLE t;
create table t1 (c1 char(10) character set utf16 collate utf16_bin);
-#
-# Basic Latin
-#
-insert into t1 values ('A'),('a');
-insert into t1 values ('B'),('b');
-insert into t1 values ('C'),('c');
-insert into t1 values ('D'),('d');
-insert into t1 values ('E'),('e');
-insert into t1 values ('F'),('f');
-insert into t1 values ('G'),('g');
-insert into t1 values ('H'),('h');
-insert into t1 values ('I'),('i');
-insert into t1 values ('J'),('j');
-insert into t1 values ('K'),('k');
-insert into t1 values ('L'),('l');
-insert into t1 values ('M'),('m');
-insert into t1 values ('N'),('n');
-insert into t1 values ('O'),('o');
-insert into t1 values ('P'),('p');
-insert into t1 values ('Q'),('q');
-insert into t1 values ('R'),('r');
-insert into t1 values ('S'),('s');
-insert into t1 values ('T'),('t');
-insert into t1 values ('U'),('u');
-insert into t1 values ('V'),('v');
-insert into t1 values ('W'),('w');
-insert into t1 values ('X'),('x');
-insert into t1 values ('Y'),('y');
-insert into t1 values ('Z'),('z');
-
-#
-# Latin1 suppliment
-#
-insert into t1 values (0x00e0),(0x00c0);
-insert into t1 values (0x00e1),(0x00c1);
-insert into t1 values (0x00e2),(0x00c2);
-insert into t1 values (0x00e3),(0x00c3);
-insert into t1 values (0x00e4),(0x00c4);
-insert into t1 values (0x00e5),(0x00c5);
-insert into t1 values (0x00e6),(0x00c6);
-insert into t1 values (0x00e7),(0x00c7);
-insert into t1 values (0x00e8),(0x00c8);
-insert into t1 values (0x00e9),(0x00c9);
-insert into t1 values (0x00ea),(0x00ca);
-insert into t1 values (0x00eb),(0x00cb);
-insert into t1 values (0x00ec),(0x00cc);
-insert into t1 values (0x00ed),(0x00cd);
-insert into t1 values (0x00ee),(0x00ce);
-insert into t1 values (0x00ef),(0x00cf);
-
-insert into t1 values (0x00f0),(0x00d0);
-insert into t1 values (0x00f1),(0x00d1);
-insert into t1 values (0x00f2),(0x00d2);
-insert into t1 values (0x00f3),(0x00d3);
-insert into t1 values (0x00f4),(0x00d4);
-insert into t1 values (0x00f5),(0x00d5);
-insert into t1 values (0x00f6),(0x00d6);
-insert into t1 values (0x00f7),(0x00d7);
-insert into t1 values (0x00f8),(0x00d8);
-insert into t1 values (0x00f9),(0x00d9);
-insert into t1 values (0x00fa),(0x00da);
-insert into t1 values (0x00fb),(0x00db);
-insert into t1 values (0x00fc),(0x00dc);
-insert into t1 values (0x00fd),(0x00dd);
-insert into t1 values (0x00fe),(0x00de);
-insert into t1 values (0x00ff),(0x00df);
-
-#
-# Latin extended-A, 0100-017F
-#
-insert into t1 values (0x0100),(0x0101),(0x0102),(0x0103);
-insert into t1 values (0x0104),(0x0105),(0x0106),(0x0107);
-insert into t1 values (0x0108),(0x0109),(0x010a),(0x010b);
-insert into t1 values (0x010c),(0x010d),(0x010e),(0x010f);
-insert into t1 values (0x0110),(0x0111),(0x0112),(0x0113);
-insert into t1 values (0x0114),(0x0115),(0x0116),(0x0117);
-insert into t1 values (0x0118),(0x0119),(0x011a),(0x011b);
-insert into t1 values (0x011c),(0x011d),(0x011e),(0x011f);
-insert into t1 values (0x0120),(0x0121),(0x0122),(0x0123);
-insert into t1 values (0x0124),(0x0125),(0x0126),(0x0127);
-insert into t1 values (0x0128),(0x0129),(0x012a),(0x012b);
-insert into t1 values (0x012c),(0x012d),(0x012e),(0x012f);
-insert into t1 values (0x0130),(0x0131),(0x0132),(0x0133);
-insert into t1 values (0x0134),(0x0135),(0x0136),(0x0137);
-insert into t1 values (0x0138),(0x0139),(0x013a),(0x013b);
-insert into t1 values (0x013c),(0x013d),(0x013e),(0x013f);
-insert into t1 values (0x0140),(0x0141),(0x0142),(0x0143);
-insert into t1 values (0x0144),(0x0145),(0x0146),(0x0147);
-insert into t1 values (0x0148),(0x0149),(0x014a),(0x014b);
-insert into t1 values (0x014c),(0x014d),(0x014e),(0x014f);
-insert into t1 values (0x0150),(0x0151),(0x0152),(0x0153);
-insert into t1 values (0x0154),(0x0155),(0x0156),(0x0157);
-insert into t1 values (0x0158),(0x0159),(0x015a),(0x015b);
-insert into t1 values (0x015c),(0x015d),(0x015e),(0x015f);
-insert into t1 values (0x0160),(0x0161),(0x0162),(0x0163);
-insert into t1 values (0x0164),(0x0165),(0x0166),(0x0167);
-insert into t1 values (0x0168),(0x0169),(0x016a),(0x016b);
-insert into t1 values (0x016c),(0x016d),(0x016e),(0x016f);
-insert into t1 values (0x0170),(0x0171),(0x0172),(0x0173);
-insert into t1 values (0x0174),(0x0175),(0x0176),(0x0177);
-insert into t1 values (0x0178),(0x0179),(0x017a),(0x017b);
-insert into t1 values (0x017c),(0x017d),(0x017e),(0x017f);
-
-#
-# Latin extended-B, 0180-024F
-#
-insert into t1 values (0x0180),(0x0181),(0x0182),(0x0183);
-insert into t1 values (0x0184),(0x0185),(0x0186),(0x0187);
-insert into t1 values (0x0188),(0x0189),(0x018a),(0x018b);
-insert into t1 values (0x018c),(0x018d),(0x018e),(0x018f);
-insert into t1 values (0x0190),(0x0191),(0x0192),(0x0193);
-insert into t1 values (0x0194),(0x0195),(0x0196),(0x0197);
-insert into t1 values (0x0198),(0x0199),(0x019a),(0x019b);
-insert into t1 values (0x019c),(0x019d),(0x019e),(0x019f);
-insert into t1 values (0x01a0),(0x01a1),(0x01a2),(0x01a3);
-insert into t1 values (0x01a4),(0x01a5),(0x01a6),(0x01a7);
-insert into t1 values (0x01a8),(0x01a9),(0x01aa),(0x01ab);
-insert into t1 values (0x01ac),(0x01ad),(0x01ae),(0x01af);
-insert into t1 values (0x01b0),(0x01b1),(0x01b2),(0x01b3);
-insert into t1 values (0x01b4),(0x01b5),(0x01b6),(0x01b7);
-insert into t1 values (0x01b8),(0x01b9),(0x01ba),(0x01bb);
-insert into t1 values (0x01bc),(0x01bd),(0x01be),(0x01bf);
-insert into t1 values (0x01c0),(0x01c1),(0x01c2),(0x01c3);
-insert into t1 values (0x01c4),(0x01c5),(0x01c6),(0x01c7);
-insert into t1 values (0x01c8),(0x01c9),(0x01ca),(0x01cb);
-insert into t1 values (0x01cc),(0x01cd),(0x01ce),(0x01cf);
-insert into t1 values (0x01d0),(0x01d1),(0x01d2),(0x01d3);
-insert into t1 values (0x01d4),(0x01d5),(0x01d6),(0x01d7);
-insert into t1 values (0x01d8),(0x01d9),(0x01da),(0x01db);
-insert into t1 values (0x01dc),(0x01dd),(0x01de),(0x01df);
-insert into t1 values (0x01e0),(0x01e1),(0x01e2),(0x01e3);
-insert into t1 values (0x01e4),(0x01e5),(0x01e6),(0x01e7);
-insert into t1 values (0x01e8),(0x01e9),(0x01ea),(0x01eb);
-insert into t1 values (0x01ec),(0x01ed),(0x01ee),(0x01ef);
-insert into t1 values (0x01f0),(0x01f1),(0x01f2),(0x01f3);
-insert into t1 values (0x01f4),(0x01f5),(0x01f6),(0x01f7);
-insert into t1 values (0x01f8),(0x01f9),(0x01fa),(0x01fb);
-insert into t1 values (0x01fc),(0x01fd),(0x01fe),(0x01ff);
-
-
-insert into t1 values ('AA'),('Aa'),('aa'),('aA');
-insert into t1 values ('CH'),('Ch'),('ch'),('cH');
-insert into t1 values ('DZ'),('Dz'),('dz'),('dZ');
-insert into t1 values ('IJ'),('Ij'),('ij'),('iJ');
-insert into t1 values ('LJ'),('Lj'),('lj'),('lJ');
-insert into t1 values ('LL'),('Ll'),('ll'),('lL');
-insert into t1 values ('NJ'),('Nj'),('nj'),('nJ');
-insert into t1 values ('OE'),('Oe'),('oe'),('oE');
-insert into t1 values ('SS'),('Ss'),('ss'),('sS');
-insert into t1 values ('RR'),('Rr'),('rr'),('rR');
+--source include/ctype_unicode_latin.inc
select group_concat(c1 order by binary c1 separator '') from t1 group by c1 collate utf16_unicode_ci;
select group_concat(c1 order by binary c1 separator '') from t1 group by c1 collate utf16_icelandic_ci;
@@ -201,6 +53,11 @@ select group_concat(c1 order by binary c1 separator '') from t1 group by c1 coll
select group_concat(c1 order by binary c1 separator '') from t1 group by c1 collate utf16_roman_ci;
select group_concat(c1 order by binary c1 separator '') from t1 group by c1 collate utf16_esperanto_ci;
select group_concat(c1 order by binary c1 separator '') from t1 group by c1 collate utf16_hungarian_ci;
+select group_concat(c1 order by binary c1 separator '') from t1 group by c1 collate utf16_croatian_mysql561_ci;
+select group_concat(c1 order by binary c1 separator '') from t1 group by c1 collate utf16_croatian_ci;
+select group_concat(c1 order by binary c1 separator '') from t1 group by c1 collate utf16_german2_ci;
+select group_concat(c1 order by binary c1 separator '') from t1 group by c1 collate utf16_unicode_520_ci;
+select group_concat(c1 order by binary c1 separator '') from t1 group by c1 collate utf16_vietnamese_ci;
drop table t1;
@@ -249,6 +106,7 @@ SET @test_collation='utf16_swedish_ci';
SET collation_connection='utf16_unicode_ci';
-- source include/ctype_filesort.inc
-- source include/ctype_like_escape.inc
+-- source include/ctype_german.inc
--echo End of 4.1 tests
@@ -295,3 +153,58 @@ SET collation_connection=utf16_czech_ci;
--echo #
--echo # End of 5.5 tests
--echo #
+
+
+
+--echo #
+--echo # Start of 5.6 tests
+--echo #
+
+--echo #
+--echo # WL#3664 WEIGHT_STRING
+--echo #
+
+set collation_connection=utf16_unicode_ci;
+--source include/weight_string.inc
+--source include/weight_string_euro.inc
+select hex(weight_string(_utf16 0xD800DC00 collate utf16_unicode_ci));
+select hex(weight_string(_utf16 0xD800DC01 collate utf16_unicode_ci));
+--source include/weight_string_l1.inc
+
+set @@collation_connection=utf16_czech_ci;
+--source include/weight_string_chde.inc
+
+#
+# WL#4013 Unicode german2 collation
+#
+SET NAMES utf8;
+SET collation_connection=utf16_german2_ci;
+--source include/ctype_german.inc
+
+--echo #
+--echo # WL#2673 Unicode Collation Algorithm new version
+--echo #
+SET NAMES utf8mb4;
+SET collation_connection=utf16_unicode_520_ci;
+--source include/ctype_unicode520.inc
+
+--echo #
+--echo # End of 5.6 tests
+--echo #
+
+
+--echo #
+--echo # Start of MariaDB-10.0 tests
+--echo #
+--echo
+
+--echo #
+--echo # MDEV-4929 Myanmar collation
+--echo #
+SET NAMES utf8;
+SET collation_connection=utf16_myanmar_ci;
+--source include/ctype_myanmar.inc
+
+--echo #
+--echo # End of MariaDB-10.0 tests
+--echo #
diff --git a/mysql-test/t/ctype_utf16le.test b/mysql-test/t/ctype_utf16le.test
new file mode 100644
index 00000000000..a8326900847
--- /dev/null
+++ b/mysql-test/t/ctype_utf16le.test
@@ -0,0 +1,746 @@
+-- source include/have_ucs2.inc
+-- source include/have_utf16.inc
+-- source include/have_utf32.inc
+-- source include/have_utf8mb4.inc
+
+
+SET TIME_ZONE='+03:00';
+
+--disable_warnings
+DROP TABLE IF EXISTS t1;
+--enable_warnings
+
+--echo #
+--echo # Start of 5.6 tests
+--echo #
+
+SET NAMES utf8mb4, collation_connection=utf16le_general_ci;
+SELECT HEX('a'), HEX('a ');
+-- source include/endspace.inc
+
+
+--echo #
+--echo # Check that incomplete utf16le characters in HEX notation
+--echo # are left-padded with zeros
+--echo #
+SELECT HEX(_utf16le 0x44);
+SELECT HEX(_utf16le 0x3344);
+SELECT HEX(_utf16le 0x113344);
+
+--echo #
+--echo # Check that 0x20 is only trimmed when it is
+--echo # a part of real SPACE character, not just a part
+--echo # of a multibyte sequence.
+--echo # Note, CYRILLIC LETTER ER is used as an example, which
+--echo # is stored as 0x0420 in utf16le, thus contains 0x20 in the
+--echo # low byte. The second character is THREE-PER-M, U+2004,
+--echo # which contains 0x20 in the high byte.
+--echo #
+
+CREATE TABLE t1 (word VARCHAR(64), word2 CHAR(64)) CHARACTER SET utf16le;
+INSERT INTO t1 VALUES (_koi8r 0xF2, _koi8r 0xF2), (_ucs2 X'2004',_ucs2 X'2004');
+SELECT HEX(word) FROM t1 ORDER BY word;
+SELECT HEX(word2) FROM t1 ORDER BY word2;
+DELETE FROM t1;
+
+--echo #
+--echo # Check that real spaces are correctly trimmed.
+--echo #
+INSERT INTO t1 VALUES (_ucs2 X'042000200020', _ucs2 X'042000200020');
+INSERT INTO t1 VALUES (_ucs2 X'200400200020', _ucs2 X'200400200020');
+SELECT HEX(word) FROM t1 ORDER BY word;
+SELECT HEX(word2) FROM t1 ORDER BY word2;
+DROP TABLE t1;
+
+
+--echo #
+--echo # Check LPAD/RPAD
+--echo #
+CREATE TABLE t1 (a VARCHAR(10), pad INT, b VARCHAR(10)) CHARACTER SET utf16le;
+INSERT INTO t1 VALUES (_ucs2 X'0420', 10, _ucs2 X'0421');
+INSERT INTO t1 VALUES (_ucs2 X'0420', 10, _ucs2 X'04210422');
+INSERT INTO t1 VALUES (_ucs2 X'0420', 10, _ucs2 X'042104220423');
+INSERT INTO t1 VALUES (_ucs2 X'0420042104220423042404250426042704280429042A042B',10,_ucs2 X'042104220423');
+INSERT INTO t1 VALUES (_utf32 X'010000', 10, _ucs2 X'0421');
+INSERT INTO t1 VALUES (_ucs2 X'0421', 10, _utf32 X'010000');
+SELECT a, pad, b, LPAD(a, pad, b), HEX(LPAD(a, pad, b)) FROM t1;
+DROP TABLE t1;
+
+
+CREATE TABLE t1 SELECT
+LPAD(_utf16le X'2004',10,_utf16le X'2104') l,
+RPAD(_utf16le X'2004',10,_utf16le X'2104') r;
+SHOW CREATE TABLE t1;
+SELECT HEX(l), HEX(r) FROM t1;
+DROP TABLE t1;
+
+CREATE TABLE t1 (f1 CHAR(30));
+INSERT INTO t1 VALUES ("103000"), ("22720000"), ("3401200"), ("78000");
+SELECT LPAD(f1, 12, "-o-/") FROM t1;
+DROP TABLE t1;
+
+--echo #
+--echo # Testing LIKE
+--echo #
+
+SET NAMES utf8, collation_connection=utf16le_general_ci;
+--source include/ctype_like.inc
+
+CREATE TABLE t1 (a VARCHAR(10) CHARACTER SET utf16le);
+INSERT INTO t1 VALUES ('фыва'),('Фыва'),('фЫва'),('фыВа'),('фывÐ'),('ФЫВÐ');
+INSERT INTO t1 VALUES ('фывапролдж'),('Фывапролдж'),('фЫвапролдж'),('фыВапролдж');
+INSERT INTO t1 VALUES ('фывÐпролдж'),('фываПролдж'),('фывапРолдж'),('фывапрОлдж');
+INSERT INTO t1 VALUES ('фывапроЛдж'),('фывапролДж'),('фывапролдЖ'),('ФЫВÐПРОЛДЖ');
+SELECT * FROM t1 WHERE a LIKE '%фЫва%' ORDER BY BINARY a;
+SELECT * FROM t1 WHERE a LIKE '%фЫв%' ORDER BY BINARY a;
+SELECT * FROM t1 WHERE a LIKE 'фЫва%' ORDER BY BINARY a;
+SELECT * FROM t1 WHERE a LIKE 'фЫва%' COLLATE utf16le_bin ORDER BY BINARY a;
+DROP TABLE t1;
+
+CREATE TABLE t1 (word VARCHAR(64) NOT NULL, PRIMARY KEY (word))
+ENGINE=MyISAM CHARACTER SET utf16le;
+INSERT INTO t1 (word) VALUES ("cat");
+SELECT * FROM t1 WHERE word LIKE "c%";
+SELECT * FROM t1 WHERE word LIKE "ca_";
+SELECT * FROM t1 WHERE word LIKE "cat";
+SELECT * FROM t1 WHERE word LIKE _ucs2 x'00630025'; # "c%"
+SELECT * FROM t1 WHERE word LIKE _ucs2 x'00630061005F'; # "ca_"
+DROP TABLE t1;
+
+
+--echo #
+--echo # Check that INSERT() works fine.
+--echo # This invokes charpos() function.
+--echo #
+CREATE TABLE t1 (
+ a VARCHAR(10) CHARACTER SET utf16le,
+ b VARCHAR(10) CHARACTER SET utf16le);
+INSERT INTO t1 VALUES ('abc', 'def');
+SELECT INSERT(a, 10, 2, b) FROM t1;
+SELECT INSERT(a, 1, 2, b) FROM t1;
+DROP TABLE t1;
+
+--echo #
+--echo # Bug#1264
+--echo #
+# Description:
+#
+# When USING a ucs2 TABLE in MySQL,
+# either with ucs2_general_ci or ucs2_bin collation,
+# words are returned in an incorrect order when USING ORDER BY
+# on an _indexed_ CHAR or VARCHAR column. They are sorted with
+# the longest word *first* instead of last. I.E. The word "aardvark"
+# is in the results before the word "a".
+#
+# If there is no index for the column, the problem does not occur.
+#
+# Interestingly, if there is no second column, the words are returned
+# in the correct order.
+#
+# According to EXPLAIN, it looks like when the output includes columns that
+# are not part of the index sorted on, it does a filesort, which fails.
+# Using a straight index yields correct results.
+
+SET NAMES utf8, collation_connection=utf16le_general_ci;
+
+--echo #
+--echo # Two fields, index
+--echo #
+
+CREATE TABLE t1 (
+ word VARCHAR(64),
+ bar INT(11) DEFAULT 0,
+ PRIMARY KEY (word))
+ ENGINE=MyISAM
+ CHARSET utf16le
+ COLLATE utf16le_general_ci ;
+
+INSERT INTO t1 (word) VALUES ("aar");
+INSERT INTO t1 (word) VALUES ("a");
+INSERT INTO t1 (word) VALUES ("aardvar");
+INSERT INTO t1 (word) VALUES ("aardvark");
+INSERT INTO t1 (word) VALUES ("aardvara");
+INSERT INTO t1 (word) VALUES ("aardvarz");
+EXPLAIN SELECT * FROM t1 ORDER BY word;
+SELECT * FROM t1 ORDER BY word;
+EXPLAIN SELECT word FROM t1 ORDER BY word;
+SELECT word FROM t1 ORDER by word;
+DROP TABLE t1;
+
+
+--echo #
+--echo # One field, index
+--echo #
+
+CREATE TABLE t1 (
+ word VARCHAR(64) ,
+ PRIMARY KEY (word))
+ ENGINE=MyISAM
+ CHARSET utf16le
+ COLLATE utf16le_general_ci;
+
+INSERT INTO t1 (word) VALUES ("aar");
+INSERT INTO t1 (word) VALUES ("a");
+INSERT INTO t1 (word) VALUES ("aardvar");
+INSERT INTO t1 (word) VALUES ("aardvark");
+INSERT INTO t1 (word) VALUES ("aardvara");
+INSERT INTO t1 (word) VALUES ("aardvarz");
+EXPLAIN SELECT * FROM t1 ORDER BY WORD;
+SELECT * FROM t1 ORDER BY word;
+DROP TABLE t1;
+
+
+--echo #
+--echo # Two fields, no index
+--echo #
+
+CREATE TABLE t1 (
+ word TEXT,
+ bar INT(11) AUTO_INCREMENT,
+ PRIMARY KEY (bar))
+ ENGINE=MyISAM
+ CHARSET utf16le
+ COLLATE utf16le_general_ci ;
+INSERT INTO t1 (word) VALUES ("aar");
+INSERT INTO t1 (word) VALUES ("a" );
+INSERT INTO t1 (word) VALUES ("aardvar");
+INSERT INTO t1 (word) VALUES ("aardvark");
+INSERT INTO t1 (word) VALUES ("aardvara");
+INSERT INTO t1 (word) VALUES ("aardvarz");
+EXPLAIN SELECT * FROM t1 ORDER BY word;
+SELECT * FROM t1 ORDER BY word;
+EXPLAIN SELECT word FROM t1 ORDER BY word;
+SELECT word FROM t1 ORDER BY word;
+DROP TABLE t1;
+
+--echo #
+--echo # END OF Bug 1264 test
+--echo #
+
+
+--echo #
+--echo # Check alignment for from-binary-conversion with CAST and CONVERT
+--echo #
+SELECT HEX(CAST(0xAA as char CHARACTER SET utf16le));
+SELECT HEX(CONVERT(0xAA USING utf16le));
+
+--echo #
+--echo # Check alignment for string types
+--echo #
+CREATE TABLE t1 (a CHAR(10) CHARACTER SET utf16le);
+INSERT INTO t1 VALUES (0x1),(0x11),(0x111),(0x1111),(0x11111);
+SELECT HEX(a) FROM t1;
+DROP TABLE t1;
+
+CREATE TABLE t1 (a VARCHAR(10) CHARACTER SET utf16le);
+INSERT INTO t1 VALUES (0x1),(0x11),(0x111),(0x1111),(0x11111);
+SELECT HEX(a) FROM t1;
+DROP TABLE t1;
+
+CREATE TABLE t1 (a TEXT CHARACTER SET utf16le);
+INSERT INTO t1 VALUES (0x1),(0x11),(0x111),(0x1111),(0x11111);
+SELECT HEX(a) FROM t1;
+DROP TABLE t1;
+
+CREATE TABLE t1 (a MEDIUMTEXT CHARACTER SET utf16le);
+INSERT INTO t1 VALUES (0x1),(0x11),(0x111),(0x1111),(0x11111);
+SELECT HEX(a) FROM t1;
+DROP TABLE t1;
+
+CREATE TABLE t1 (a LONGTEXT CHARACTER SET utf16le);
+INSERT INTO t1 VALUES (0x1),(0x11),(0x111),(0x1111),(0x11111);
+SELECT HEX(a) FROM t1;
+DROP TABLE t1;
+
+
+--echo #
+--echo # Bug#5081 : UCS2 fields are filled with '0x2020'
+--echo # after extending field length
+--echo #
+
+CREATE TABLE t1(a CHAR(1)) DEFAULT CHARSET utf16le;
+INSERT INTO t1 VALUES ('a'),('b'),('c');
+ALTER TABLE t1 MODIFY a CHAR(5);
+SELECT a, HEX(a) FROM t1;
+DROP TABLE t1;
+
+--echo #
+--echo # Check prepare statement from an UTF16 string
+--echo #
+SET NAMES latin1;
+SET @ivar= 1234;
+SET @str1 = 'SELECT ?';
+SET @str2 = CONVERT(@str1 USING utf16le);
+PREPARE stmt1 FROM @str2;
+EXECUTE stmt1 USING @ivar;
+
+--echo #
+--echo # Check that utf16le works with ENUM and SET type
+--echo #
+SET NAMES utf8, collation_connection=utf16le_general_ci;
+CREATE TABLE t1 (a ENUM('x','y','z') CHARACTER SET utf16le);
+SHOW CREATE TABLE t1;
+INSERT INTO t1 VALUES ('x');
+INSERT INTO t1 VALUES ('y');
+INSERT INTO t1 VALUES ('z');
+SELECT a, HEX(a) FROM t1 ORDER BY a;
+ALTER TABLE t1 CHANGE a a ENUM('x','y','z','d','e','ä','ö','ü') CHARACTER SET utf16le;
+SHOW CREATE TABLE t1;
+INSERT INTO t1 VALUES ('D');
+INSERT INTO t1 VALUES ('E ');
+INSERT INTO t1 VALUES ('ä');
+INSERT INTO t1 VALUES ('ö');
+INSERT INTO t1 VALUES ('ü');
+SELECT a, HEX(a) FROM t1 ORDER BY a;
+DROP TABLE t1;
+
+CREATE TABLE t1 (a set ('x','y','z','ä','ö','ü') CHARACTER SET utf16le);
+SHOW CREATE TABLE t1;
+INSERT INTO t1 VALUES ('x');
+INSERT INTO t1 VALUES ('y');
+INSERT INTO t1 VALUES ('z');
+INSERT INTO t1 VALUES ('x,y');
+INSERT INTO t1 VALUES ('x,y,z,ä,ö,ü');
+SELECT a, HEX(a) FROM t1 ORDER BY a;
+DROP TABLE t1;
+
+--echo #
+--echo # Bug#7302 UCS2 data in ENUM fields get truncated when new column is added
+--echo #
+CREATE TABLE t1(a ENUM('a','b','c')) DEFAULT CHARACTER SET utf16le;
+INSERT INTO t1 VALUES('a'),('b'),('c');
+ALTER TABLE t1 ADD b CHAR(1);
+SHOW WARNINGS;
+SELECT * FROM t1 ORDER BY a;
+DROP TABLE t1;
+
+SET NAMES utf8, collation_connection='utf16le_general_ci';
+-- source include/ctype_filesort.inc
+-- source include/ctype_like_escape.inc
+SET NAMES utf8, collation_connection='utf16le_bin';
+-- source include/ctype_filesort.inc
+-- source include/ctype_filesort2.inc
+-- source include/ctype_like_escape.inc
+
+--echo #
+--echo # Bug#10344 Some string functions fail for UCS2
+--echo #
+CREATE TABLE t1 (a VARCHAR(10) CHARACTER SET utf16le, pos INT);
+INSERT INTO t1 VALUES (_ucs2 0x00e400e50068,1);
+INSERT INTO t1 VALUES (_ucs2 0x00e400e50068,2);
+INSERT INTO t1 VALUES (_ucs2 0x00e400e50068,3);
+INSERT INTO t1 VALUES (_ucs2 0x00e400e50068,-1);
+INSERT INTO t1 VALUES (_ucs2 0x00e400e50068,-2);
+INSERT INTO t1 VALUES (_ucs2 0x00e400e50068,-3);
+INSERT INTO t1 VALUES (_utf32 0x000000e4000000e500010000, 1);
+INSERT INTO t1 VALUES (_utf32 0x000000e4000000e500010000, 2);
+INSERT INTO t1 VALUES (_utf32 0x000000e4000000e500010000, 3);
+INSERT INTO t1 VALUES (_utf32 0x000000e4000000e500010000, -1);
+INSERT INTO t1 VALUES (_utf32 0x000000e4000000e500010000, -2);
+INSERT INTO t1 VALUES (_utf32 0x000000e4000000e500010000, -3);
+SELECT HEX(SUBSTR(a, pos)), SUBSTR(a, pos) FROM t1;
+DROP TABLE t1;
+
+SET NAMES utf8, collation_connection=utf16le_general_ci;
+
+--echo #
+--echo # Bug#9442 Set parameter make query fail if column CHARACTER SET is UCS2
+--echo #
+CREATE TABLE t1 (utext VARCHAR(20) CHARACTER SET utf16le);
+INSERT INTO t1 VALUES ("lily");
+INSERT INTO t1 VALUES ("river");
+PREPARE stmt FROM 'SELECT utext FROM t1 where utext like ?';
+SET @param1='%%';
+EXECUTE stmt USING @param1;
+EXECUTE stmt USING @param1;
+SELECT utext FROM t1 where utext like '%%';
+DROP TABLE t1;
+DEALLOCATE PREPARE stmt;
+
+--echo #
+--echo # Bug#22052 Trailing spaces are not removed FROM UNICODE fields in an index
+--echo #
+CREATE TABLE t1 (
+ a CHAR(10) CHARACTER SET utf16le NOT NULL,
+ INDEX a (a)
+) engine=myisam;
+INSERT INTO t1 VALUES (REPEAT(_ucs2 0x201f, 10));
+INSERT INTO t1 VALUES (REPEAT(_ucs2 0x2020, 10));
+INSERT INTO t1 VALUES (REPEAT(_ucs2 0x2021, 10));
+--echo # make sure "index read" is used
+explain SELECT HEX(a) FROM t1 ORDER BY a;
+SELECT HEX(a) FROM t1 ORDER BY a;
+ALTER TABLE t1 DROP INDEX a;
+SELECT HEX(a) FROM t1 ORDER BY a;
+DROP TABLE t1;
+
+--echo #
+--echo # Bug #20108: corrupted default enum value for a ucs2 field
+--echo #
+CREATE TABLE t1 (
+ status ENUM('active','passive') CHARACTER SET utf16le COLLATE utf16le_general_ci
+ NOT NULL DEFAULT 'passive'
+);
+SHOW CREATE TABLE t1;
+ALTER TABLE t1 ADD a int NOT NULL AFTER status;
+SHOW CREATE TABLE t1;
+DROP TABLE t1;
+
+
+--echo #
+--echo # Conversion FROM an UTF16LE string to a decimal column
+--echo #
+CREATE TABLE t1 (a VARCHAR(64) CHARACTER SET utf16le, b DECIMAL(10,3));
+INSERT INTO t1 VALUES ("1.1", 0), ("2.1", 0);
+UPDATE t1 set b=a;
+SELECT *, HEX(a) FROM t1;
+DROP TABLE t1;
+
+--echo #
+--echo # Bug#9442 Set parameter make query fail if column CHARACTER SET is UCS2
+--echo #
+CREATE TABLE t1 (utext VARCHAR(20) CHARACTER SET utf16le);
+INSERT INTO t1 VALUES ("lily");
+INSERT INTO t1 VALUES ("river");
+PREPARE stmt FROM 'SELECT utext FROM t1 where utext like ?';
+SET @param1='%%';
+EXECUTE stmt USING @param1;
+EXECUTE stmt USING @param1;
+SELECT utext FROM t1 where utext like '%%';
+DROP TABLE t1;
+DEALLOCATE PREPARE stmt;
+
+--echo #
+--echo # Bug#22638 SOUNDEX broken for international characters
+--echo #
+SET NAMES utf8, collation_connection=utf16le_general_ci;
+SELECT SOUNDEX(''),SOUNDEX('he'),SOUNDEX('hello all folks'),SOUNDEX('#3556 in bugdb');
+SELECT HEX(SOUNDEX('')),HEX(SOUNDEX('he')),HEX(SOUNDEX('hello all folks')),HEX(SOUNDEX('#3556 in bugdb'));
+SELECT 'mood' sounds like 'mud';
+--echo # Cyrillic A, BE, VE
+SELECT HEX(SOUNDEX(_utf16le 0x041004110412));
+--echo # Make sure that "U+00BF INVERTED QUESTION MARK" is not considered as letter
+SELECT HEX(SOUNDEX(_utf16le 0x00BF00C0));
+
+--echo #
+--echo # Bug#14290: character_maximum_length for text fields
+--echo #
+CREATE TABLE t1(a BLOB, b TEXT CHARSET utf16le);
+SELECT data_type, character_octet_length, character_maximum_length
+ FROM information_schema.columns where table_name='t1';
+DROP TABLE t1;
+
+
+SET NAMES utf8, collation_connection=utf16le_general_ci;
+
+--echo #
+--echo # Testing cs->coll->instr()
+--echo #
+SELECT POSITION('bb' IN 'abba');
+
+--echo #
+--echo # Testing cs->coll->hash_sort()
+--echo #
+SET NAMES utf8, collation_connection=utf16le_bin;
+--source include/ctype_heap.inc
+SET NAMES utf8, collation_connection=utf16le_general_ci;
+--source include/ctype_heap.inc
+
+--echo #
+--echo # Testing cs->cset->numchars()
+--echo #
+SELECT CHAR_LENGTH('abcd'), OCTET_LENGTH('abcd');
+SELECT CHAR_LENGTH(_utf16le 0x00D800DC), OCTET_LENGTH(_utf16le 0x00D800DC);
+SELECT CHAR_LENGTH(_utf16le 0x7DD8FFDF), OCTET_LENGTH(_utf16le 0x7FD8DDDF);
+
+--echo #
+--echo # Testing cs->cset->charpos()
+--echo #
+SELECT LEFT('abcd',2);
+SELECT HEX(LEFT(_utf16le 0x00D800DC7FD8FFDF, 1));
+SELECT HEX(RIGHT(_utf16le 0x00D800DC7FD8FFDF, 1));
+
+--echo #
+--echo # Testing cs->cset->well_formed_length()
+--echo #
+CREATE TABLE t1 (a VARCHAR(10) CHARACTER SET utf16le);
+--echo # Bad sequences
+--error ER_INVALID_CHARACTER_STRING
+INSERT INTO t1 VALUES (_utf16le 0x00D8);
+--error ER_INVALID_CHARACTER_STRING
+INSERT INTO t1 VALUES (_utf16le 0x00DC);
+--error ER_INVALID_CHARACTER_STRING
+INSERT INTO t1 VALUES (_utf16le 0x00D800D8);
+--error ER_INVALID_CHARACTER_STRING
+INSERT INTO t1 VALUES (_utf16le 0x00D800E8);
+--error ER_INVALID_CHARACTER_STRING
+INSERT INTO t1 VALUES (_utf16le 0x00D80008);
+--echo # Good sequences
+INSERT INTO t1 VALUES (_utf16le 0x00D800DC);
+INSERT INTO t1 VALUES (_utf16le 0x00D8FFDC);
+INSERT INTO t1 VALUES (_utf16le 0xFFDB00DC);
+INSERT INTO t1 VALUES (_utf16le 0xFFDBFFDC);
+SELECT HEX(a) FROM t1;
+DROP TABLE t1;
+
+--echo #
+--echo # Bug#32393 Character sets: illegal characters in utf16le columns
+--echo #
+--echo # Tests that cs->cset->wc_mb() doesn't accept surrogate parts
+--echo #
+--echo # via ALTER
+--echo #
+CREATE TABLE t1 (s1 VARCHAR(50) CHARACTER SET ucs2);
+INSERT INTO t1 VALUES (0xDF84);
+ALTER TABLE t1 MODIFY column s1 VARCHAR(50) CHARACTER SET utf16le;
+SELECT HEX(s1) FROM t1;
+DROP TABLE t1;
+
+--echo #
+--echo # via UPDATE
+--echo #
+CREATE TABLE t1 (s1 VARCHAR(5) CHARACTER SET ucs2, s2 VARCHAR(5) CHARACTER SET utf16le);
+INSERT INTO t1 (s1) VALUES (0xdf84);
+UPDATE t1 set s2 = s1;
+SELECT HEX(s2) FROM t1;
+DROP TABLE t1;
+
+
+--echo #
+--echo # Testing cs->cset->lengthsp()
+--echo #
+CREATE TABLE t1 (a CHAR(10)) CHARACTER SET utf16le;
+INSERT INTO t1 VALUES ('a ');
+SELECT HEX(a) FROM t1;
+DROP TABLE t1;
+
+
+--echo #
+--echo # Testing cs->cset->caseup() and cs->cset->casedn()
+--echo #
+SELECT UPPER('abcd'), LOWER('ABCD');
+
+--echo #
+--echo # Checking str_to_datetime()
+--echo #
+select @@collation_connection;
+CREATE TABLE t1 (a date);
+INSERT INTO t1 VALUES ('2007-09-16');
+SELECT * FROM t1;
+DROP TABLE t1;
+
+
+--echo #
+--echo # Testing cs->cset->ll10tostr
+--echo #
+CREATE TABLE t1 (a VARCHAR(10) CHARACTER SET utf16le);
+INSERT INTO t1 VALUES (123456);
+SELECT a, HEX(a) FROM t1;
+DROP TABLE t1;
+
+--echo #
+--echo # Testing cs->cset->fill
+--echo # SOUNDEX fills strings with DIGIT ZERO up to four characters
+--echo #
+SELECT SOUNDEX('a'), HEX(SOUNDEX('a'));
+
+
+--echo #
+--echo # Testing cs->cset->strntoul
+--echo #
+CREATE TABLE t1 (a enum ('a','b','c')) CHARACTER SET utf16le;
+INSERT INTO t1 VALUES ('1');
+SELECT * FROM t1;
+DROP TABLE t1;
+
+
+--echo #
+--echo # Testing cs->cset->strntoll and cs->cset->strntoull
+--echo #
+SET NAMES latin1;
+SELECT HEX(CONV(CONVERT('123' USING utf16le), -10, 16));
+SELECT HEX(CONV(CONVERT('123' USING utf16le), 10, 16));
+SET NAMES utf8, collation_connection=utf16le_general_ci;
+
+
+--echo #
+--echo # Testing cs->cset->strntod
+--echo #
+SET NAMES utf8, collation_connection=utf16le_general_ci;
+SELECT 1.1 + '1.2';
+SELECT 1.1 + '1.2xxx';
+
+
+--echo #
+--echo # Testing cs->cset->strtoll10
+--echo #
+SELECT LEFT('aaa','1');
+CREATE TABLE t1 AS SELECT REPEAT('abcd', 128) AS a;
+SELECT LEFT(a, '2') FROM t1;
+SELECT LEFT(a, ' \t \t 2') FROM t1;
+SELECT LEFT(a, ' \t \t +2') FROM t1;
+SELECT SUBSTR(a, '-2') FROM t1;
+SELECT SUBSTR(a, ' \t \t -2') FROM t1;
+SELECT LEFT(a, '00002') FROM t1;
+SELECT LEFT(a, ' \t \t 00002') FROM t1;
+SELECT LEFT(a, ' \t \t +00002') FROM t1;
+SELECT SUBSTR(a, '-00002') FROM t1;
+SELECT SUBSTR(a, ' \t \t -00002') FROM t1;
+DROP TABLE t1;
+CREATE TABLE t1 AS SELECT REPEAT('abcd', 128) AS a LIMIT 0;
+INSERT INTO t1 VALUES ('255'), ('65535'),('16777215'),('4294967295'),
+('1099511627775'),('281474976710655'),('72057594037927935'),
+('1844674407370955161'),('18446744073709551614'), ('18446744073709551615');
+SELECT a, CAST(a AS SIGNED), CAST(a AS UNSIGNED) FROM t1;
+UPDATE t1 SET a=CONCAT('-', a);
+SELECT a, CAST(a AS SIGNED) FROM t1;
+DROP TABLE t1;
+
+--source include/ctype_strtoll10.inc
+
+--echo #
+--echo # Testing cs->cset->strntoull10rnd
+--echo #
+CREATE TABLE t1 (a int);
+INSERT INTO t1 VALUES ('-1234.1e2');
+INSERT INTO t1 VALUES ('-1234.1e2xxxx');
+INSERT INTO t1 VALUES ('-1234.1e2 ');
+INSERT INTO t1 VALUES ('123');
+INSERT INTO t1 VALUES ('-124');
+INSERT INTO t1 VALUES ('+125');
+INSERT INTO t1 VALUES (' \t \t 123');
+INSERT INTO t1 VALUES (' \t \t -124');
+INSERT INTO t1 VALUES (' \t \t +125');
+INSERT INTO t1 VALUES (' \t \t 000123');
+INSERT INTO t1 VALUES (' \t \t -000124');
+INSERT INTO t1 VALUES (' \t \t +000125');
+SELECT * FROM t1;
+DROP TABLE t1;
+CREATE TABLE t1 (a BIGINT UNSIGNED);
+INSERT INTO t1 VALUES ('255'), ('65535'),('16777215'),('4294967295'),
+('1099511627775'),('281474976710655'),('72057594037927935'),
+('1844674407370955161'),('18446744073709551614'), ('18446744073709551615');
+SELECT * FROM t1;
+DROP TABLE t1;
+
+
+--echo #
+--echo # Testing cs->cset->scan
+--echo #
+CREATE TABLE t1 (a int);
+INSERT INTO t1 VALUES ('1 ');
+INSERT INTO t1 VALUES ('1 x');
+SELECT * FROM t1;
+DROP TABLE t1;
+
+
+--echo #
+--echo # Testing auto-conversion to TEXT
+--echo #
+CREATE TABLE t1 (a VARCHAR(17000) CHARACTER SET utf16le);
+SHOW CREATE TABLE t1;
+DROP TABLE t1;
+
+
+--echo #
+--echo # Testing that maximim possible key length is 1000 bytes
+--echo #
+CREATE TABLE t1 (a VARCHAR(250) CHARACTER SET utf16le PRIMARY KEY);
+SHOW CREATE TABLE t1;
+DROP TABLE t1;
+--error ER_TOO_LONG_KEY
+CREATE TABLE t1 (a VARCHAR(334) CHARACTER SET utf16le PRIMARY KEY);
+
+
+--echo #
+--echo # Conversion to utf8
+--echo #
+CREATE TABLE t1 (a CHAR(1) CHARACTER SET utf16le);
+INSERT INTO t1 VALUES (0x00D800DC),(0x00D8FFDC),(0x7FDB00DC),(0x7FDBFFDC);
+INSERT INTO t1 VALUES (0xC000), (0xFF00),(0x00E0), (0xFFFF);
+SELECT HEX(a), HEX(@a:=CONVERT(a USING utf8mb4)), HEX(CONVERT(@a USING utf16le)) FROM t1;
+DROP TABLE t1;
+
+
+--echo #
+--echo # Test basic regex functionality
+--echo #
+SET NAMES utf8, collation_connection=utf16le_general_ci;
+--source include/ctype_regex.inc
+
+
+--echo #
+--echo # Test how CHARACTER SET works with date/time
+--echo #
+--source include/ctype_datetime.inc
+
+
+--echo #
+--echo # Bug#33073 Character sets: ordering fails with utf32
+--echo #
+SET NAMES utf8, collation_connection=utf16le_general_ci;
+CREATE TABLE t1 AS SELECT REPEAT('a',2) as s1 LIMIT 0;
+SHOW CREATE TABLE t1;
+INSERT INTO t1 VALUES ('ab'),('AE'),('ab'),('AE');
+SELECT * FROM t1 ORDER BY s1;
+SET max_sort_length=4;
+SELECT * FROM t1 ORDER BY s1;
+DROP TABLE t1;
+SET max_sort_length=DEFAULT;
+
+
+--echo #
+--echo # Bug#52520 Difference in tinytext utf column metadata
+--echo #
+CREATE TABLE t1 (
+ s1 TINYTEXT CHARACTER SET utf16le,
+ s2 TEXT CHARACTER SET utf16le,
+ s3 MEDIUMTEXT CHARACTER SET utf16le,
+ s4 LONGTEXT CHARACTER SET utf16le
+);
+--enable_metadata
+SET NAMES utf8, @@character_set_results=NULL;
+SELECT *, HEX(s1) FROM t1;
+SET NAMES latin1;
+SELECT *, HEX(s1) FROM t1;
+SET NAMES utf8;
+SELECT *, HEX(s1) FROM t1;
+--disable_metadata
+CREATE TABLE t2 AS SELECT CONCAT(s1) FROM t1;
+SHOW CREATE TABLE t2;
+DROP TABLE t1, t2;
+
+--echo #
+--echo # Problem found by Roy during review
+--echo # MY_CS_BINSORT was not set for utf16le_bin,
+--echo # so filesort did not work well
+--echo #
+SET NAMES utf8, @@collation_connection=utf16le_bin;
+CREATE TABLE t1 AS SELECT REPEAT(' ', 10) as c LIMIT 0;
+# the problem in fact reproduced even without the primary key:
+ALTER TABLE t1 ADD PRIMARY KEY(c);
+SHOW CREATE TABLE t1;
+INSERT INTO t1 VALUES ('abc'),('zyx'),('acb');
+SELECT UPPER(c) FROM t1 ORDER BY 1 DESC;
+DROP TABLE t1;
+
+
+--echo #
+--echo # WL#3664 WEIGHT_STRING
+--echo #
+
+SET NAMES utf8, collation_connection=utf16le_general_ci;
+--source include/weight_string.inc
+--source include/weight_string_euro.inc
+SELECT HEX(WEIGHT_STRING(_utf16le 0x00D800DC));
+SELECT HEX(WEIGHT_STRING(_utf16le 0x00D801DC));
+--source include/weight_string_l1.inc
+
+SET NAMES utf8, collation_connection=utf16le_bin;
+--source include/weight_string.inc
+--source include/weight_string_euro.inc
+--source include/weight_string_l1.inc
+
+--echo #
+--echo # End of 5.6 tests
+--echo #
diff --git a/mysql-test/t/ctype_utf32.test b/mysql-test/t/ctype_utf32.test
index fced2838273..c747abb8b08 100644
--- a/mysql-test/t/ctype_utf32.test
+++ b/mysql-test/t/ctype_utf32.test
@@ -1,4 +1,5 @@
-- source include/have_utf32.inc
+-- source include/have_utf8mb4.inc
SET TIME_ZONE = '+03:00';
@@ -692,6 +693,7 @@ select 1.1 + '1.2xxx';
# Testing strntoll10_utf32
# Testing cs->cset->strtoll10
select left('aaa','1');
+--source include/ctype_strtoll10.inc
#
# Testing cs->cset->strntoull10rnd
@@ -813,6 +815,17 @@ SELECT * FROM t1;
DROP TABLE t1;
--echo #
+--echo # Bug#32859 Character sets: no warning with non-fitting chariot wheel
+--echo #
+CREATE TABLE t1 (utf32 CHAR(5) CHARACTER SET utf32, latin1 CHAR(5) CHARACTER SET latin1);
+INSERT INTO t1 (utf32) VALUES (0xc581);
+UPDATE t1 SET latin1 = utf32;
+DELETE FROM t1;
+INSERT INTO t1 (utf32) VALUES (0x100cc);
+UPDATE t1 SET latin1 = utf32;
+DROP TABLE t1;
+
+--echo #
--echo # Bug#55912 FORMAT with locale set fails for numbers < 1000
--echo #
SET collation_connection=utf32_general_ci;
@@ -906,3 +919,67 @@ DROP TABLE t1;
--echo #
--echo # End of 5.5 tests
--echo #
+
+
+--echo #
+--echo # Start of 5.6 tests
+--echo #
+
+--echo #
+--echo # WL#3664 WEIGHT_STRING
+--echo #
+
+set collation_connection=utf32_general_ci;
+--source include/weight_string.inc
+--source include/weight_string_euro.inc
+select hex(weight_string(_utf32 0x10000));
+select hex(weight_string(_utf32 0x10001));
+--source include/weight_string_l1.inc
+
+set collation_connection=utf32_bin;
+--source include/weight_string.inc
+--source include/weight_string_euro.inc
+--source include/weight_string_l1.inc
+
+--echo #
+--echo # End of 5.6 tests
+--echo #
+
+
+--echo #
+--echo # Start of 10.0 tests
+--echo #
+
+--echo #
+--echo # MDEV-6661 PI() does not work well in UCS2/UTF16/UTF32 context
+--echo #
+SELECT CONCAT(CONVERT('pi=' USING utf32),PI()) AS PI;
+
+--echo #
+--echo # MDEV-6666 Malformed result for CONCAT(utf8_column, binary_string)
+--echo #
+
+SET NAMES utf8mb4;
+CREATE TABLE t1 (a VARCHAR(10) CHARACTER SET utf32);
+INSERT INTO t1 VALUES ('a');
+--error ER_INVALID_CHARACTER_STRING
+SELECT CONCAT(a,0x20FFFF) FROM t1;
+SELECT CONCAT(a,0x010000) FROM t1;
+SELECT CONCAT(a,0x00FF) FROM t1;
+DROP TABLE t1;
+--error ER_INVALID_CHARACTER_STRING
+SELECT CONCAT(_utf32'a' COLLATE utf32_unicode_ci, _binary 0x20FFFF);
+PREPARE stmt FROM "SELECT CONCAT(_utf32'a' COLLATE utf32_unicode_ci, ?)";
+SET @arg00=_binary 0x20FFFF;
+--error ER_INVALID_CHARACTER_STRING
+EXECUTE stmt USING @arg00;
+SET @arg00=_binary 0x010000;
+EXECUTE stmt USING @arg00;
+SET @arg00=_binary 0x00FF;
+EXECUTE stmt USING @arg00;
+DEALLOCATE PREPARE stmt;
+
+--echo #
+--echo # End of 10.0 tests
+--echo #
+
diff --git a/mysql-test/t/ctype_utf32_uca.test b/mysql-test/t/ctype_utf32_uca.test
index 1d79fbe1616..6052ea7b334 100644
--- a/mysql-test/t/ctype_utf32_uca.test
+++ b/mysql-test/t/ctype_utf32_uca.test
@@ -33,156 +33,7 @@ DROP TABLE t;
create table t1 (c1 char(10) character set utf32 collate utf32_bin);
-#
-# Basic Latin
-#
-insert into t1 values ('A'),('a');
-insert into t1 values ('B'),('b');
-insert into t1 values ('C'),('c');
-insert into t1 values ('D'),('d');
-insert into t1 values ('E'),('e');
-insert into t1 values ('F'),('f');
-insert into t1 values ('G'),('g');
-insert into t1 values ('H'),('h');
-insert into t1 values ('I'),('i');
-insert into t1 values ('J'),('j');
-insert into t1 values ('K'),('k');
-insert into t1 values ('L'),('l');
-insert into t1 values ('M'),('m');
-insert into t1 values ('N'),('n');
-insert into t1 values ('O'),('o');
-insert into t1 values ('P'),('p');
-insert into t1 values ('Q'),('q');
-insert into t1 values ('R'),('r');
-insert into t1 values ('S'),('s');
-insert into t1 values ('T'),('t');
-insert into t1 values ('U'),('u');
-insert into t1 values ('V'),('v');
-insert into t1 values ('W'),('w');
-insert into t1 values ('X'),('x');
-insert into t1 values ('Y'),('y');
-insert into t1 values ('Z'),('z');
-
-#
-# Latin1 suppliment
-#
-insert into t1 values (_ucs2 0x00e0),(_ucs2 0x00c0);
-insert into t1 values (_ucs2 0x00e1),(_ucs2 0x00c1);
-insert into t1 values (_ucs2 0x00e2),(_ucs2 0x00c2);
-insert into t1 values (_ucs2 0x00e3),(_ucs2 0x00c3);
-insert into t1 values (_ucs2 0x00e4),(_ucs2 0x00c4);
-insert into t1 values (_ucs2 0x00e5),(_ucs2 0x00c5);
-insert into t1 values (_ucs2 0x00e6),(_ucs2 0x00c6);
-insert into t1 values (_ucs2 0x00e7),(_ucs2 0x00c7);
-insert into t1 values (_ucs2 0x00e8),(_ucs2 0x00c8);
-insert into t1 values (_ucs2 0x00e9),(_ucs2 0x00c9);
-insert into t1 values (_ucs2 0x00ea),(_ucs2 0x00ca);
-insert into t1 values (_ucs2 0x00eb),(_ucs2 0x00cb);
-insert into t1 values (_ucs2 0x00ec),(_ucs2 0x00cc);
-insert into t1 values (_ucs2 0x00ed),(_ucs2 0x00cd);
-insert into t1 values (_ucs2 0x00ee),(_ucs2 0x00ce);
-insert into t1 values (_ucs2 0x00ef),(_ucs2 0x00cf);
-
-insert into t1 values (_ucs2 0x00f0),(_ucs2 0x00d0);
-insert into t1 values (_ucs2 0x00f1),(_ucs2 0x00d1);
-insert into t1 values (_ucs2 0x00f2),(_ucs2 0x00d2);
-insert into t1 values (_ucs2 0x00f3),(_ucs2 0x00d3);
-insert into t1 values (_ucs2 0x00f4),(_ucs2 0x00d4);
-insert into t1 values (_ucs2 0x00f5),(_ucs2 0x00d5);
-insert into t1 values (_ucs2 0x00f6),(_ucs2 0x00d6);
-insert into t1 values (_ucs2 0x00f7),(_ucs2 0x00d7);
-insert into t1 values (_ucs2 0x00f8),(_ucs2 0x00d8);
-insert into t1 values (_ucs2 0x00f9),(_ucs2 0x00d9);
-insert into t1 values (_ucs2 0x00fa),(_ucs2 0x00da);
-insert into t1 values (_ucs2 0x00fb),(_ucs2 0x00db);
-insert into t1 values (_ucs2 0x00fc),(_ucs2 0x00dc);
-insert into t1 values (_ucs2 0x00fd),(_ucs2 0x00dd);
-insert into t1 values (_ucs2 0x00fe),(_ucs2 0x00de);
-insert into t1 values (_ucs2 0x00ff),(_ucs2 0x00df);
-
-#
-# Latin extended-A, 0100-017F
-#
-insert into t1 values (_ucs2 0x0100),(_ucs2 0x0101),(_ucs2 0x0102),(_ucs2 0x0103);
-insert into t1 values (_ucs2 0x0104),(_ucs2 0x0105),(_ucs2 0x0106),(_ucs2 0x0107);
-insert into t1 values (_ucs2 0x0108),(_ucs2 0x0109),(_ucs2 0x010a),(_ucs2 0x010b);
-insert into t1 values (_ucs2 0x010c),(_ucs2 0x010d),(_ucs2 0x010e),(_ucs2 0x010f);
-insert into t1 values (_ucs2 0x0110),(_ucs2 0x0111),(_ucs2 0x0112),(_ucs2 0x0113);
-insert into t1 values (_ucs2 0x0114),(_ucs2 0x0115),(_ucs2 0x0116),(_ucs2 0x0117);
-insert into t1 values (_ucs2 0x0118),(_ucs2 0x0119),(_ucs2 0x011a),(_ucs2 0x011b);
-insert into t1 values (_ucs2 0x011c),(_ucs2 0x011d),(_ucs2 0x011e),(_ucs2 0x011f);
-insert into t1 values (_ucs2 0x0120),(_ucs2 0x0121),(_ucs2 0x0122),(_ucs2 0x0123);
-insert into t1 values (_ucs2 0x0124),(_ucs2 0x0125),(_ucs2 0x0126),(_ucs2 0x0127);
-insert into t1 values (_ucs2 0x0128),(_ucs2 0x0129),(_ucs2 0x012a),(_ucs2 0x012b);
-insert into t1 values (_ucs2 0x012c),(_ucs2 0x012d),(_ucs2 0x012e),(_ucs2 0x012f);
-insert into t1 values (_ucs2 0x0130),(_ucs2 0x0131),(_ucs2 0x0132),(_ucs2 0x0133);
-insert into t1 values (_ucs2 0x0134),(_ucs2 0x0135),(_ucs2 0x0136),(_ucs2 0x0137);
-insert into t1 values (_ucs2 0x0138),(_ucs2 0x0139),(_ucs2 0x013a),(_ucs2 0x013b);
-insert into t1 values (_ucs2 0x013c),(_ucs2 0x013d),(_ucs2 0x013e),(_ucs2 0x013f);
-insert into t1 values (_ucs2 0x0140),(_ucs2 0x0141),(_ucs2 0x0142),(_ucs2 0x0143);
-insert into t1 values (_ucs2 0x0144),(_ucs2 0x0145),(_ucs2 0x0146),(_ucs2 0x0147);
-insert into t1 values (_ucs2 0x0148),(_ucs2 0x0149),(_ucs2 0x014a),(_ucs2 0x014b);
-insert into t1 values (_ucs2 0x014c),(_ucs2 0x014d),(_ucs2 0x014e),(_ucs2 0x014f);
-insert into t1 values (_ucs2 0x0150),(_ucs2 0x0151),(_ucs2 0x0152),(_ucs2 0x0153);
-insert into t1 values (_ucs2 0x0154),(_ucs2 0x0155),(_ucs2 0x0156),(_ucs2 0x0157);
-insert into t1 values (_ucs2 0x0158),(_ucs2 0x0159),(_ucs2 0x015a),(_ucs2 0x015b);
-insert into t1 values (_ucs2 0x015c),(_ucs2 0x015d),(_ucs2 0x015e),(_ucs2 0x015f);
-insert into t1 values (_ucs2 0x0160),(_ucs2 0x0161),(_ucs2 0x0162),(_ucs2 0x0163);
-insert into t1 values (_ucs2 0x0164),(_ucs2 0x0165),(_ucs2 0x0166),(_ucs2 0x0167);
-insert into t1 values (_ucs2 0x0168),(_ucs2 0x0169),(_ucs2 0x016a),(_ucs2 0x016b);
-insert into t1 values (_ucs2 0x016c),(_ucs2 0x016d),(_ucs2 0x016e),(_ucs2 0x016f);
-insert into t1 values (_ucs2 0x0170),(_ucs2 0x0171),(_ucs2 0x0172),(_ucs2 0x0173);
-insert into t1 values (_ucs2 0x0174),(_ucs2 0x0175),(_ucs2 0x0176),(_ucs2 0x0177);
-insert into t1 values (_ucs2 0x0178),(_ucs2 0x0179),(_ucs2 0x017a),(_ucs2 0x017b);
-insert into t1 values (_ucs2 0x017c),(_ucs2 0x017d),(_ucs2 0x017e),(_ucs2 0x017f);
-
-#
-# Latin extended-B, 0180-024F
-#
-insert into t1 values (_ucs2 0x0180),(_ucs2 0x0181),(_ucs2 0x0182),(_ucs2 0x0183);
-insert into t1 values (_ucs2 0x0184),(_ucs2 0x0185),(_ucs2 0x0186),(_ucs2 0x0187);
-insert into t1 values (_ucs2 0x0188),(_ucs2 0x0189),(_ucs2 0x018a),(_ucs2 0x018b);
-insert into t1 values (_ucs2 0x018c),(_ucs2 0x018d),(_ucs2 0x018e),(_ucs2 0x018f);
-insert into t1 values (_ucs2 0x0190),(_ucs2 0x0191),(_ucs2 0x0192),(_ucs2 0x0193);
-insert into t1 values (_ucs2 0x0194),(_ucs2 0x0195),(_ucs2 0x0196),(_ucs2 0x0197);
-insert into t1 values (_ucs2 0x0198),(_ucs2 0x0199),(_ucs2 0x019a),(_ucs2 0x019b);
-insert into t1 values (_ucs2 0x019c),(_ucs2 0x019d),(_ucs2 0x019e),(_ucs2 0x019f);
-insert into t1 values (_ucs2 0x01a0),(_ucs2 0x01a1),(_ucs2 0x01a2),(_ucs2 0x01a3);
-insert into t1 values (_ucs2 0x01a4),(_ucs2 0x01a5),(_ucs2 0x01a6),(_ucs2 0x01a7);
-insert into t1 values (_ucs2 0x01a8),(_ucs2 0x01a9),(_ucs2 0x01aa),(_ucs2 0x01ab);
-insert into t1 values (_ucs2 0x01ac),(_ucs2 0x01ad),(_ucs2 0x01ae),(_ucs2 0x01af);
-insert into t1 values (_ucs2 0x01b0),(_ucs2 0x01b1),(_ucs2 0x01b2),(_ucs2 0x01b3);
-insert into t1 values (_ucs2 0x01b4),(_ucs2 0x01b5),(_ucs2 0x01b6),(_ucs2 0x01b7);
-insert into t1 values (_ucs2 0x01b8),(_ucs2 0x01b9),(_ucs2 0x01ba),(_ucs2 0x01bb);
-insert into t1 values (_ucs2 0x01bc),(_ucs2 0x01bd),(_ucs2 0x01be),(_ucs2 0x01bf);
-insert into t1 values (_ucs2 0x01c0),(_ucs2 0x01c1),(_ucs2 0x01c2),(_ucs2 0x01c3);
-insert into t1 values (_ucs2 0x01c4),(_ucs2 0x01c5),(_ucs2 0x01c6),(_ucs2 0x01c7);
-insert into t1 values (_ucs2 0x01c8),(_ucs2 0x01c9),(_ucs2 0x01ca),(_ucs2 0x01cb);
-insert into t1 values (_ucs2 0x01cc),(_ucs2 0x01cd),(_ucs2 0x01ce),(_ucs2 0x01cf);
-insert into t1 values (_ucs2 0x01d0),(_ucs2 0x01d1),(_ucs2 0x01d2),(_ucs2 0x01d3);
-insert into t1 values (_ucs2 0x01d4),(_ucs2 0x01d5),(_ucs2 0x01d6),(_ucs2 0x01d7);
-insert into t1 values (_ucs2 0x01d8),(_ucs2 0x01d9),(_ucs2 0x01da),(_ucs2 0x01db);
-insert into t1 values (_ucs2 0x01dc),(_ucs2 0x01dd),(_ucs2 0x01de),(_ucs2 0x01df);
-insert into t1 values (_ucs2 0x01e0),(_ucs2 0x01e1),(_ucs2 0x01e2),(_ucs2 0x01e3);
-insert into t1 values (_ucs2 0x01e4),(_ucs2 0x01e5),(_ucs2 0x01e6),(_ucs2 0x01e7);
-insert into t1 values (_ucs2 0x01e8),(_ucs2 0x01e9),(_ucs2 0x01ea),(_ucs2 0x01eb);
-insert into t1 values (_ucs2 0x01ec),(_ucs2 0x01ed),(_ucs2 0x01ee),(_ucs2 0x01ef);
-insert into t1 values (_ucs2 0x01f0),(_ucs2 0x01f1),(_ucs2 0x01f2),(_ucs2 0x01f3);
-insert into t1 values (_ucs2 0x01f4),(_ucs2 0x01f5),(_ucs2 0x01f6),(_ucs2 0x01f7);
-insert into t1 values (_ucs2 0x01f8),(_ucs2 0x01f9),(_ucs2 0x01fa),(_ucs2 0x01fb);
-insert into t1 values (_ucs2 0x01fc),(_ucs2 0x01fd),(_ucs2 0x01fe),(_ucs2 0x01ff);
-
-
-insert into t1 values ('AA'),('Aa'),('aa'),('aA');
-insert into t1 values ('CH'),('Ch'),('ch'),('cH');
-insert into t1 values ('DZ'),('Dz'),('dz'),('dZ');
-insert into t1 values ('IJ'),('Ij'),('ij'),('iJ');
-insert into t1 values ('LJ'),('Lj'),('lj'),('lJ');
-insert into t1 values ('LL'),('Ll'),('ll'),('lL');
-insert into t1 values ('NJ'),('Nj'),('nj'),('nJ');
-insert into t1 values ('OE'),('Oe'),('oe'),('oE');
-insert into t1 values ('SS'),('Ss'),('ss'),('sS');
-insert into t1 values ('RR'),('Rr'),('rr'),('rR');
+--source include/ctype_unicode_latin.inc
select group_concat(c1 order by binary c1 separator '') from t1 group by c1 collate utf32_unicode_ci;
select group_concat(c1 order by binary c1 separator '') from t1 group by c1 collate utf32_icelandic_ci;
@@ -202,6 +53,11 @@ select group_concat(c1 order by binary c1 separator '') from t1 group by c1 coll
select group_concat(c1 order by binary c1 separator '') from t1 group by c1 collate utf32_roman_ci;
select group_concat(c1 order by binary c1 separator '') from t1 group by c1 collate utf32_esperanto_ci;
select group_concat(c1 order by binary c1 separator '') from t1 group by c1 collate utf32_hungarian_ci;
+select group_concat(c1 order by binary c1 separator '') from t1 group by c1 collate utf32_croatian_mysql561_ci;
+select group_concat(c1 order by binary c1 separator '') from t1 group by c1 collate utf32_croatian_ci;
+select group_concat(c1 order by binary c1 separator '') from t1 group by c1 collate utf32_german2_ci;
+select group_concat(c1 order by binary c1 separator '') from t1 group by c1 collate utf32_unicode_520_ci;
+select group_concat(c1 order by binary c1 separator '') from t1 group by c1 collate utf32_vietnamese_ci;
drop table t1;
@@ -250,6 +106,7 @@ SET @test_collation='utf32_swedish_ci';
SET collation_connection='utf32_unicode_ci';
-- source include/ctype_filesort.inc
-- source include/ctype_like_escape.inc
+-- source include/ctype_german.inc
--echo End of 4.1 tests
@@ -318,3 +175,57 @@ DROP TABLE t1,t2;
--echo #
--echo # End of 5.5 tests
--echo #
+
+
+--echo #
+--echo # Start of 5.6 tests
+--echo #
+
+--echo #
+--echo # WL#3664 WEIGHT_STRING
+--echo #
+
+set collation_connection=utf32_unicode_ci;
+--source include/weight_string.inc
+--source include/weight_string_euro.inc
+select hex(weight_string(_utf32 0x10000 collate utf32_unicode_ci));
+select hex(weight_string(_utf32 0x10001 collate utf32_unicode_ci));
+--source include/weight_string_l1.inc
+
+set @@collation_connection=utf32_czech_ci;
+--source include/weight_string_chde.inc
+
+#
+# WL#4013 Unicode german2 collation
+#
+SET NAMES utf8;
+SET collation_connection=utf32_german2_ci;
+--source include/ctype_german.inc
+
+--echo #
+--echo # WL#2673 Unicode Collation Algorithm new version
+--echo #
+SET NAMES utf8mb4;
+SET collation_connection=utf32_unicode_520_ci;
+--source include/ctype_unicode520.inc
+
+--echo #
+--echo # End of 5.6 tests
+--echo #
+
+
+--echo #
+--echo # Start of MariaDB-10.0 tests
+--echo #
+--echo
+
+--echo #
+--echo # MDEV-4929 Myanmar collation
+--echo #
+SET NAMES utf8;
+SET collation_connection=utf32_myanmar_ci;
+--source include/ctype_myanmar.inc
+
+--echo #
+--echo # End of MariaDB-10.0 tests
+--echo #
diff --git a/mysql-test/t/ctype_utf8.test b/mysql-test/t/ctype_utf8.test
index 592e3a3b662..2524daffa9e 100644
--- a/mysql-test/t/ctype_utf8.test
+++ b/mysql-test/t/ctype_utf8.test
@@ -199,25 +199,9 @@ drop table t1;
#
# Testing regexp
#
-set collation_connection=utf8_general_ci;
---source include/ctype_regex.inc
-set names utf8;
-
-#
-# Bug #3928 regexp [[:>:]] and UTF-8
-#
set names utf8;
-
-# This should return TRUE
-select 'ваÑÑ' rlike '[[:<:]]ваÑÑ[[:>:]]';
-select 'ваÑÑ ' rlike '[[:<:]]ваÑÑ[[:>:]]';
-select ' ваÑÑ' rlike '[[:<:]]ваÑÑ[[:>:]]';
-select ' ваÑÑ ' rlike '[[:<:]]ваÑÑ[[:>:]]';
-
-# This should return FALSE
-select 'ваÑÑz' rlike '[[:<:]]ваÑÑ[[:>:]]';
-select 'zваÑÑ' rlike '[[:<:]]ваÑÑ[[:>:]]';
-select 'zваÑÑz' rlike '[[:<:]]ваÑÑ[[:>:]]';
+--source include/ctype_regex.inc
+--source include/ctype_regex_utf8.inc
#
# Bug #4555
@@ -1154,6 +1138,11 @@ DROP TABLE t1;
create table t1(a char(200) collate utf8_unicode_ci NOT NULL default '')
default charset=utf8 collate=utf8_unicode_ci;
insert into t1 values (unhex('65')), (unhex('C3A9')), (unhex('65'));
+-- disable_query_log
+-- disable_result_log
+analyze table t1;
+-- enable_result_log
+-- enable_query_log
explain select distinct a from t1;
select distinct a from t1;
explain select a from t1 group by a;
@@ -1166,11 +1155,41 @@ drop table t1;
create table t1(a char(10)) default charset utf8;
insert into t1 values ('123'), ('456');
+-- disable_query_log
+-- disable_result_log
+analyze table t1;
+-- enable_result_log
+-- enable_query_log
explain
select substr(Z.a,-1), Z.a from t1 as Y join t1 as Z on Y.a=Z.a order by 1;
select substr(Z.a,-1), Z.a from t1 as Y join t1 as Z on Y.a=Z.a order by 1;
drop table t1;
+#
+# Bug #34349: Passing invalid parameter to CHAR() in an ORDER BY causes
+# MySQL to hang
+#
+
+SET CHARACTER SET utf8;
+SHOW VARIABLES LIKE 'character\_set\_%';
+CREATE DATABASE crashtest DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;
+USE crashtest;
+CREATE TABLE crashtest (crash char(10)) DEFAULT CHARSET=utf8;
+INSERT INTO crashtest VALUES ('35'), ('36'), ('37');
+SELECT * FROM crashtest ORDER BY CHAR(crash USING utf8);
+INSERT INTO crashtest VALUES ('-1000');
+-- disable_query_log
+-- disable_result_log
+ANALYZE TABLE crashtest;
+-- enable_result_log
+-- enable_query_log
+EXPLAIN SELECT * FROM crashtest ORDER BY CHAR(crash USING utf8);
+SELECT * FROM crashtest ORDER BY CHAR(crash USING utf8);
+DROP TABLE crashtest;
+DROP DATABASE crashtest;
+USE test;
+SET CHARACTER SET default;
+
# End of 4.1 tests
#
@@ -1714,3 +1733,153 @@ DROP TABLE t1;
--echo #
--echo # End of 5.5 tests
--echo #
+
+--echo #
+--echo # Start of 5.6 tests
+--echo #
+
+--echo #
+--echo # WL#3664 WEIGHT_STRING
+--echo #
+
+set names utf8;
+--source include/weight_string.inc
+--source include/weight_string_euro.inc
+--source include/weight_string_l1.inc
+
+set @@collation_connection=utf8_bin;
+--source include/weight_string.inc
+--source include/weight_string_euro.inc
+--source include/weight_string_l1.inc
+
+--echo #
+--echo # Checking strnxfrm() with odd length
+--echo #
+set max_sort_length=5;
+select @@max_sort_length;
+create table t1 (a varchar(128) character set utf8 collate utf8_general_ci);
+insert into t1 values ('a'),('b'),('c');
+select * from t1 order by a;
+alter table t1 modify a varchar(128) character set utf8 collate utf8_bin;
+select * from t1 order by a;
+drop table t1;
+set max_sort_length=default;
+
+--echo #
+--echo # End of 5.6 tests
+--echo #
+
+--echo #
+--echo # Start of 10.0 tests
+--echo #
+
+SET NAMES utf8 COLLATE utf8_bin;
+--source include/ctype_like_cond_propagation.inc
+SET NAMES utf8;
+--source include/ctype_like_cond_propagation.inc
+--source include/ctype_like_cond_propagation_utf8_german.inc
+
+
+--echo #
+--echo # MDEV-6666 Malformed result for CONCAT(utf8_column, binary_string)
+--echo #
+
+CREATE TABLE t1 (a VARCHAR(10) CHARACTER SET utf8);
+INSERT INTO t1 VALUES ('a');
+--error ER_INVALID_CHARACTER_STRING
+SELECT CONCAT(a,0xFF) FROM t1;
+SELECT CONCAT(a,0xC3BF) FROM t1;
+DROP TABLE t1;
+--error ER_INVALID_CHARACTER_STRING
+SELECT CONCAT('a' COLLATE utf8_unicode_ci, _binary 0xFF);
+PREPARE stmt FROM "SELECT CONCAT('a' COLLATE utf8_unicode_ci, ?)";
+SET @arg00=_binary 0xFF;
+--error ER_INVALID_CHARACTER_STRING
+EXECUTE stmt USING @arg00;
+DEALLOCATE PREPARE stmt;
+SET NAMES latin1;
+PREPARE stmt FROM "SELECT CONCAT(_utf8'a' COLLATE utf8_unicode_ci, ?)";
+EXECUTE stmt USING @no_such_var;
+DEALLOCATE PREPARE stmt;
+SET NAMES utf8;
+
+--echo #
+--echo # MDEV-6679 Different optimizer plan for "a BETWEEN 'string' AND ?" and "a BETWEEN ? AND 'string'"
+--echo #
+SET NAMES utf8, collation_connection=utf8_swedish_ci;
+CREATE TABLE t1 (a VARCHAR(10) CHARACTER SET utf8, b INT NOT NULL DEFAULT 0, key(a));
+INSERT INTO t1 (a) VALUES ('a'),('b'),('c'),('d'),('¢');
+SET @arg='¢';
+PREPARE stmt FROM "EXPLAIN SELECT * FROM t1 WHERE a BETWEEN _utf8'¢' and ?";
+EXECUTE stmt USING @arg;
+PREPARE stmt FROM "EXPLAIN SELECT * FROM t1 WHERE a between ? and _utf8'¢'";
+EXECUTE stmt USING @arg;
+DEALLOCATE PREPARE stmt;
+DROP TABLE t1;
+
+-- echo #
+-- echo # MDEV-6683 A parameter and a string literal with the same values are not recognized as equal by the optimizer
+-- echo #
+
+SET NAMES utf8, collation_connection=utf8_swedish_ci;
+CREATE TABLE t1 (a VARCHAR(10) CHARACTER SET latin1, b INT NOT NULL DEFAULT 0, key(a));
+INSERT INTO t1 (a) VALUES ('a'),('b'),('c'),('d'),('¢');
+SET @arg='¢';
+PREPARE stmt FROM "EXPLAIN SELECT * FROM t1 WHERE a BETWEEN _utf8'¢' and ?";
+EXECUTE stmt USING @arg;
+PREPARE stmt FROM "EXPLAIN SELECT * FROM t1 WHERE a between ? and _utf8'¢'";
+EXECUTE stmt USING @arg;
+DEALLOCATE PREPARE stmt;
+DROP TABLE t1;
+
+--echo #
+--echo # MDEV-6688 Illegal mix of collation with bit string B'01100001'
+--echo #
+CREATE TABLE t1 (a VARCHAR(10) CHARACTER SET latin1, b INT);
+INSERT INTO t1 VALUES ('a',1);
+SELECT CONCAT(a, IF(b>10, _utf8 X'61', _utf8 X'61')) FROM t1;
+SELECT CONCAT(a, IF(b>10, _utf8 X'61', _utf8 B'01100001')) FROM t1;
+DROP TABLE t1;
+
+--echo #
+--echo # MDEV-6694 Illegal mix of collation with a PS parameter
+--echo #
+SET NAMES utf8;
+CREATE TABLE t1 (a INT, b VARCHAR(10) CHARACTER SET latin1);
+INSERT INTO t1 VALUES (1,'a');
+SELECT CONCAT(b,IF(a,'b','b')) FROM t1;
+PREPARE stmt FROM "SELECT CONCAT(b,IF(a,?,?)) FROM t1";
+SET @b='b';
+EXECUTE stmt USING @b,@b;
+SET @b='';
+EXECUTE stmt USING @b,@b;
+SET @b='Ñ';
+--error ER_CANT_AGGREGATE_2COLLATIONS
+EXECUTE stmt USING @b,@b;
+DEALLOCATE PREPARE stmt;
+DROP TABLE t1;
+
+--echo #
+--echo # MDEV-7629 Regression: Bit and hex string literals changed column names in 10.0.14
+--echo #
+SELECT _utf8 0x7E, _utf8 X'7E', _utf8 B'01111110';
+
+
+let $ctype_unescape_combinations=selected;
+--source include/ctype_unescape.inc
+
+--echo #
+--echo # MDEV-12681 Wrong VIEW results for CHAR(0xDF USING latin1)
+--echo #
+
+SET NAMES utf8;
+SELECT CHAR(0xDF USING latin1);
+CREATE OR REPLACE VIEW v1 AS SELECT CHAR(0xDF USING latin1) AS c;
+SHOW CREATE VIEW v1;
+SELECT * FROM v1;
+DROP VIEW v1;
+
+
+--echo #
+--echo # End of 10.0 tests
+--echo #
diff --git a/mysql-test/t/ctype_utf8mb4.test b/mysql-test/t/ctype_utf8mb4.test
index 551a570c0fc..f68cfd57e2a 100644
--- a/mysql-test/t/ctype_utf8mb4.test
+++ b/mysql-test/t/ctype_utf8mb4.test
@@ -197,25 +197,9 @@ drop table t1;
#
# Testing regexp
#
-set collation_connection=utf8mb4_general_ci;
---source include/ctype_regex.inc
-set names utf8mb4;
-
-#
-# Bug #3928 regexp [[:>:]] and UTF-8
-#
set names utf8mb4;
-
-# This should return TRUE
-select 'ваÑÑ' rlike '[[:<:]]ваÑÑ[[:>:]]';
-select 'ваÑÑ ' rlike '[[:<:]]ваÑÑ[[:>:]]';
-select ' ваÑÑ' rlike '[[:<:]]ваÑÑ[[:>:]]';
-select ' ваÑÑ ' rlike '[[:<:]]ваÑÑ[[:>:]]';
-
-# This should return FALSE
-select 'ваÑÑz' rlike '[[:<:]]ваÑÑ[[:>:]]';
-select 'zваÑÑ' rlike '[[:<:]]ваÑÑ[[:>:]]';
-select 'zваÑÑz' rlike '[[:<:]]ваÑÑ[[:>:]]';
+--source include/ctype_regex.inc
+--source include/ctype_regex_utf8.inc
#
# Bug #4555
@@ -1812,8 +1796,7 @@ SHOW CREATE TABLE t2;
DROP TABLE t1, t2;
--echo #
---echo # Bug#13581962 HIGH MEMORY USAGE ATTEMPT, THEN CRASH WITH
---echo # LONGTEXT, UNION, USER VARIABLE
+--echo # Bug#13581962 HIGH MEMORY USAGE ATTEMPT, THEN CRASH WITH LONGTEXT, UNION, USER VARIABLE
--echo # Bug#14096619 UNABLE TO RESTORE DATABASE DUMP
--echo #
@@ -1881,6 +1864,57 @@ DROP TABLE t1;
--echo # End of 5.5 tests
--echo #
+
+--echo #
+--echo # WL#3664 WEIGHT_STRING
+--echo #
+
+set names utf8mb4;
+--source include/weight_string.inc
+--source include/weight_string_euro.inc
+--source include/weight_string_l1.inc
+
+set @@collation_connection=utf8mb4_bin;
+--source include/weight_string.inc
+--source include/weight_string_euro.inc
+--source include/weight_string_l1.inc
+
+--echo #
+--echo # End of 5.6 tests
+--echo #
+
+--echo #
+--echo # Start of 10.0 tests
+--echo #
+
+--echo #
+--echo # MDEV-11343 LOAD DATA INFILE fails to load data with an escape character followed by a multi-byte character
+--echo #
+CREATE TABLE t1 (a TEXT CHARACTER SET utf8mb4);
+LOAD DATA INFILE '../../std_data/loaddata/mdev-11343.txt' INTO TABLE t1 CHARACTER SET utf8mb4;
+SELECT HEX(a) FROM t1;
+DROP TABLE t1;
+
+--echo #
+--echo # MDEV-8949: COLUMN_CREATE unicode name breakage
+--echo #
+
+SET NAMES utf8mb4;
+SELECT COLUMN_JSON(COLUMN_CREATE(_utf8mb4 0xF09F988E, 1));
+SELECT COLUMN_LIST(COLUMN_CREATE(_utf8mb4 0xF09F988E, 1));
+SELECT COLUMN_GET(COLUMN_CREATE(_utf8mb4 0xF09F988E, 1), _utf8mb4 0xF09F988E
+as int);
+
+CREATE TABLE t1 AS SELECT
+ COLUMN_LIST(COLUMN_CREATE('a',1)),
+ COLUMN_JSON(COLUMN_CREATE('b',1));
+SHOW CREATE TABLE t1;
+DROP TABLE t1;
+
+SET NAMES default;
+
+--echo # End of 10.0 tests
+
--echo #
--echo # End of tests
--echo #
diff --git a/mysql-test/t/ctype_utf8mb4_uca.test b/mysql-test/t/ctype_utf8mb4_uca.test
new file mode 100644
index 00000000000..a5493e78c47
--- /dev/null
+++ b/mysql-test/t/ctype_utf8mb4_uca.test
@@ -0,0 +1,72 @@
+-- source include/have_ucs2.inc
+-- source include/have_utf8mb4.inc
+
+--disable_warnings
+DROP TABLE IF EXISTS t1;
+--enable_warnings
+
+--echo #
+--echo # Start of 5.5 tests
+--echo #
+
+SET NAMES utf8mb4;
+CREATE TABLE t1 (c1 CHAR(10) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin);
+
+--source include/ctype_unicode_latin.inc
+
+SELECT GROUP_CONCAT(c1 ORDER BY c1 SEPARATOR '') FROM t1 GROUP BY c1 COLLATE utf8mb4_unicode_ci;
+SELECT GROUP_CONCAT(c1 ORDER BY c1 SEPARATOR '') FROM t1 GROUP BY c1 COLLATE utf8mb4_icelandic_ci;
+SELECT GROUP_CONCAT(c1 ORDER BY c1 SEPARATOR '') FROM t1 GROUP BY c1 COLLATE utf8mb4_latvian_ci;
+SELECT GROUP_CONCAT(c1 ORDER BY c1 SEPARATOR '') FROM t1 GROUP BY c1 COLLATE utf8mb4_romanian_ci;
+SELECT GROUP_CONCAT(c1 ORDER BY c1 SEPARATOR '') FROM t1 GROUP BY c1 COLLATE utf8mb4_slovenian_ci;
+SELECT GROUP_CONCAT(c1 ORDER BY c1 SEPARATOR '') FROM t1 GROUP BY c1 COLLATE utf8mb4_polish_ci;
+SELECT GROUP_CONCAT(c1 ORDER BY c1 SEPARATOR '') FROM t1 GROUP BY c1 COLLATE utf8mb4_estonian_ci;
+SELECT GROUP_CONCAT(c1 ORDER BY c1 SEPARATOR '') FROM t1 GROUP BY c1 COLLATE utf8mb4_spanish_ci;
+SELECT GROUP_CONCAT(c1 ORDER BY c1 SEPARATOR '') FROM t1 GROUP BY c1 COLLATE utf8mb4_swedish_ci;
+SELECT GROUP_CONCAT(c1 ORDER BY c1 SEPARATOR '') FROM t1 GROUP BY c1 COLLATE utf8mb4_turkish_ci;
+SELECT GROUP_CONCAT(c1 ORDER BY c1 SEPARATOR '') FROM t1 GROUP BY c1 COLLATE utf8mb4_czech_ci;
+SELECT GROUP_CONCAT(c1 ORDER BY c1 SEPARATOR '') FROM t1 GROUP BY c1 COLLATE utf8mb4_danish_ci;
+SELECT GROUP_CONCAT(c1 ORDER BY c1 SEPARATOR '') FROM t1 GROUP BY c1 COLLATE utf8mb4_lithuanian_ci;
+SELECT GROUP_CONCAT(c1 ORDER BY c1 SEPARATOR '') FROM t1 GROUP BY c1 COLLATE utf8mb4_slovak_ci;
+SELECT GROUP_CONCAT(c1 ORDER BY c1 SEPARATOR '') FROM t1 GROUP BY c1 COLLATE utf8mb4_spanish2_ci;
+SELECT GROUP_CONCAT(c1 ORDER BY c1 SEPARATOR '') FROM t1 GROUP BY c1 COLLATE utf8mb4_roman_ci;
+SELECT GROUP_CONCAT(c1 ORDER BY c1 SEPARATOR '') FROM t1 GROUP BY c1 COLLATE utf8mb4_esperanto_ci;
+SELECT GROUP_CONCAT(c1 ORDER BY c1 SEPARATOR '') FROM t1 GROUP BY c1 COLLATE utf8mb4_hungarian_ci;
+SELECT GROUP_CONCAT(c1 ORDER BY c1 SEPARATOR '') FROM t1 GROUP BY c1 COLLATE utf8mb4_croatian_mysql561_ci;
+SELECT GROUP_CONCAT(c1 ORDER BY c1 SEPARATOR '') FROM t1 GROUP BY c1 COLLATE utf8mb4_croatian_ci;
+SELECT GROUP_CONCAT(c1 ORDER BY c1 SEPARATOR '') FROM t1 GROUP BY c1 COLLATE utf8mb4_german2_ci;
+SELECT GROUP_CONCAT(c1 ORDER BY c1 SEPARATOR '') FROM t1 GROUP BY c1 COLLATE utf8mb4_unicode_520_ci;
+SELECT GROUP_CONCAT(c1 ORDER BY c1 SEPARATOR '') FROM t1 GROUP BY c1 COLLATE utf8mb4_vietnamese_ci;
+
+DROP TABLE t1;
+
+--echo #
+--echo # Start of 5.5 tests
+--echo #
+#
+# Bug#57737 Character sets: search fails with like, contraction, index
+# Test my_like_range and contractions
+#
+SET collation_connection=utf8mb4_czech_ci;
+--source include/ctype_czech.inc
+--source include/ctype_like_ignorable.inc
+
+--echo #
+--echo # End of 5.5 tests
+--echo #
+
+
+--echo #
+--echo # Start of MariaDB-10.0 tests
+--echo #
+--echo
+
+--echo #
+--echo # MDEV-4929 Myanmar collation
+--echo #
+SET NAMES utf8mb4 COLLATE utf8mb4_myanmar_ci;
+--source include/ctype_myanmar.inc
+
+--echo #
+--echo # End of MariaDB-10.0 tests
+--echo #
diff --git a/mysql-test/t/default.test b/mysql-test/t/default.test
index b719cb83448..432df9d4452 100644
--- a/mysql-test/t/default.test
+++ b/mysql-test/t/default.test
@@ -166,3 +166,46 @@ drop table t1, t2;
--echo End of 5.0 tests.
+--echo #
+--echo # Start of 10.0 tests
+--echo #
+
+--echo #
+--echo # MDEV-11265 Access defied when CREATE VIIEW v1 AS SELECT DEFAULT(column) FROM t1
+--echo #
+
+CREATE TABLE t1 (a INT DEFAULT 10);
+INSERT INTO t1 VALUES (11);
+CREATE VIEW v1 AS SELECT a AS a FROM t1;
+CREATE VIEW v2 AS SELECT DEFAULT(a) AS a FROM t1;
+CREATE VIEW v3 AS SELECT VALUES(a) AS a FROM t1;
+SELECT * FROM v1;
+SELECT * FROM v2;
+SELECT * FROM v3;
+--error ER_NONUPDATEABLE_COLUMN
+UPDATE v2 SET a=123;
+--error ER_NONUPDATEABLE_COLUMN
+UPDATE v3 SET a=123;
+DROP VIEW v3;
+DROP VIEW v2;
+DROP VIEW v1;
+DROP TABLE t1;
+
+--echo #
+--echo # MDEV-10780 Server crashes in in create_tmp_table
+--echo #
+
+# Note, the problem was not repeatable with a non-fresh connection.
+--connect (con1,localhost,root,,test)
+CREATE TABLE t1 (pk INT AUTO_INCREMENT PRIMARY KEY) ENGINE=MyISAM;
+INSERT INTO t1 VALUES ();
+INSERT INTO t1 VALUES ();
+SELECT DISTINCT DEFAULT (pk) FROM t1 GROUP BY RAND() WITH ROLLUP;
+--disconnect con1
+--connection default
+DROP TABLE t1;
+
+--echo #
+--echo # End of 10.0 tests
+--echo #
+
diff --git a/mysql-test/t/default_storage_engine.test b/mysql-test/t/default_storage_engine.test
index 4ecfc3b8d44..dd6f4728f47 100644
--- a/mysql-test/t/default_storage_engine.test
+++ b/mysql-test/t/default_storage_engine.test
@@ -3,11 +3,11 @@ if (`SELECT COUNT(*) = 0 FROM INFORMATION_SCHEMA.PLUGINS WHERE PLUGIN_NAME = 'in
--skip Requires built-in InnoDB.
}
-let $cmd=`select replace("$MYSQLD_BOOTSTRAP_CMD", " --default-storage-engine=myisam", "")`;
+let $cmd=`select replace("$MYSQLD_BOOTSTRAP_CMD --skip-innodb", " --default-storage-engine=myisam", "")`;
#
# Now it *must* fail, because if InnoDB is compiled in, it is used as a default
-# storage engine. but $MYSQLD_BOOTSTRAP_CMD includes --skip-innodb
+# storage engine. but $cmd includes --skip-innodb
#
error 1;
exec $cmd;
diff --git a/mysql-test/t/delayed.test b/mysql-test/t/delayed.test
index 1898d1a4691..2886dff8f91 100644
--- a/mysql-test/t/delayed.test
+++ b/mysql-test/t/delayed.test
@@ -457,7 +457,7 @@ SELECT * FROM t1 WHERE a=0;
--echo # Connection con1
connection con1;
--echo # Sending:
---send ALTER TABLE t1 COMMENT 'test'
+--send ALTER TABLE t1 MODIFY a INT UNSIGNED;
--echo # Connection default
connection default;
@@ -465,7 +465,7 @@ connection default;
let $wait_condition=
SELECT COUNT(*) = 1 FROM information_schema.processlist
WHERE state = "Waiting for table metadata lock"
- AND info = "ALTER TABLE t1 COMMENT 'test'";
+ AND info LIKE "ALTER TABLE t1%";
--source include/wait_condition.inc
--error ER_LOCK_DEADLOCK
INSERT DELAYED INTO t1 VALUES (3);
diff --git a/mysql-test/t/delete_returning.test b/mysql-test/t/delete_returning.test
new file mode 100644
index 00000000000..4448a6bcccd
--- /dev/null
+++ b/mysql-test/t/delete_returning.test
@@ -0,0 +1,172 @@
+#
+# Tests for DELETE FROM <table> ... RETURNING <expr>,...
+#
+--disable_warnings
+drop table if exists t1,t2;
+drop view if exists v1;
+drop procedure if exists p1;
+--enable_warnings
+
+CREATE TABLE t1 (a int, b varchar(32));
+INSERT INTO t1 VALUES
+ (7,'ggggggg'), (1,'a'), (3,'ccc'),
+ (4,'dddd'), (1,'A'), (2,'BB'), (4,'DDDD'),
+ (5,'EEEEE'), (7,'GGGGGGG'), (2,'bb');
+
+CREATE TABLE t1c SELECT * FROM t1;
+
+CREATE TABLE t2 (c int);
+INSERT INTO t2 VALUES
+ (4), (5), (7), (1);
+
+CREATE TABLE t2c SELECT * FROM t2;
+
+CREATE VIEW v1 AS SELECT a, UPPER(b) FROM t1;
+
+# DELETE FROM <table> ... RETURNING *
+
+DELETE FROM t1 WHERE a=2 RETURNING * ;
+SELECT * FROM t1;
+
+INSERT INTO t1 VALUES (2,'BB'), (2,'bb');
+
+# DELETE FROM <table> ... RETURNING <col>
+
+DELETE FROM t1 WHERE a=2 RETURNING b;
+SELECT * FROM t1;
+
+# DELETE FROM <table> ... RETURNING <not existing col>
+--error ER_BAD_FIELD_ERROR
+DELETE FROM t1 WHERE a=2 RETURNING c;
+
+INSERT INTO t1 VALUES (2,'BB'), (2,'bb');
+
+# DELETE FROM <table> ... RETURNING <col>, <expr>
+
+DELETE FROM t1 WHERE a=2 RETURNING a, UPPER(b);
+SELECT * FROM t1;
+
+INSERT INTO t1 VALUES (2,'BB'), (2,'bb');
+
+# DELETE FROM <table> ... RETURNING <col> with no rows to be deleted
+
+DELETE FROM t1 WHERE a=6 RETURNING b;
+SELECT * FROM t1;
+
+# DELETE FROM <table> ... RETURNING <expr with aggr function>
+
+--error ER_INVALID_GROUP_FUNC_USE
+DELETE FROM t1 WHERE a=2 RETURNING MAX(b);
+
+# DELETE FROM <table> ... RETURNING <expr with subquery>
+
+DELETE FROM t1 WHERE a < 5 RETURNING a, (SELECT MIN(c) FROM t2 WHERE c=a+1);
+SELECT * FROM t1;
+
+DELETE FROM t1;
+INSERT INTO t1 SELECT * FROM t1c;
+
+DELETE FROM t2 WHERE c < 5
+ RETURNING (SELECT GROUP_CONCAT(b) FROM t1 GROUP BY a HAVING a=c);
+SELECT * FROM t2;
+
+DELETE FROM t2;
+INSERT INTO t2 SELECT * FROM t2c;
+
+# DELETE FROM <table> ... RETURNING <expr with function invocation>
+
+DELIMITER |;
+
+CREATE FUNCTION f(arg INT) RETURNS TEXT
+BEGIN
+ RETURN (SELECT GROUP_CONCAT(b) FROM t1 WHERE a=arg);
+END|
+
+DELIMITER ;|
+
+DELETE FROM t2 WHERE c < 5 RETURNING f(c);
+SELECT * FROM t2;
+
+DELETE FROM t2;
+INSERT INTO t2 SELECT * FROM t2c;
+
+DROP FUNCTION f;
+
+# DELETE FROM <view> ... RETURNING <col>, <col>
+
+DELETE FROM v1 WHERE a < 5 RETURNING * ;
+SELECT * FROM t1;
+
+DELETE FROM t1;
+INSERT INTO t1 SELECT * FROM t1c;
+
+# DELETE FROM <view> ... RETURNING <expr>
+
+CREATE VIEW v11(a,c) AS SELECT a, COUNT(b) FROM t1 GROUP BY a;
+-- error ER_NON_UPDATABLE_TABLE
+DELETE FROM v11 WHERE a < 5 RETURNING * ;
+DROP VIEW v11;
+
+# prepared DELETE FROM <table> ... RETURNING <expr>
+
+PREPARE stmt FROM
+"DELETE FROM t1 WHERE a=2 ORDER BY b LIMIT 1 RETURNING a, UPPER(b)";
+EXECUTE stmt;
+SELECT * FROM t1;
+EXECUTE stmt;
+SELECT * FROM t1;
+DEALLOCATE PREPARE stmt;
+
+# Cleanup
+DROP VIEW v1;
+DROP TABLE t1,t2;
+DROP TABLE t1c,t2c;
+
+--echo #
+--echo # Bug mdev-4918: DELETE ... RETURNING subquery with more than 1 row
+--echo #
+
+CREATE TABLE t1 (i1 int);
+INSERT INTO t1 VALUES (1),(2);
+
+CREATE TABLE t2 (i2 int);
+INSERT INTO t2 VALUES (1),(2);
+
+--error ER_SUBQUERY_NO_1_ROW
+DELETE FROM t1 ORDER BY i1 RETURNING ( SELECT i2 FROM t2 );
+
+DROP TABLE t1,t2;
+
+--echo #
+--echo # MDEV-4919: Packets out of order on a SELECT after calling a procedure with DELETE .. RETURNING
+--echo #
+CREATE TABLE t1 (i INT);
+INSERT INTO t1 VALUES (1),(2);
+--delimiter |
+CREATE PROCEDURE p1 (a INT)
+BEGIN
+ DELETE FROM t1 WHERE i = a RETURNING *;
+ INSERT INTO t1 VALUES (a);
+END |
+--delimiter ;
+
+CALL p1(1);
+SELECT * FROM t1;
+DROP PROCEDURE p1;
+DROP TABLE t1;
+
+--echo #
+--echo # MDEV-13776: DELETE ... RETURNING with sql_mode='ONLY_FULL_GROUP_BY'
+--echo #
+
+set @sql_mode_save= @@sql_mode;
+set sql_mode='ONLY_FULL_GROUP_BY';
+
+CREATE TABLE t1 (id INT);
+INSERT INTO t1 VALUE(1),(2),(3);
+
+DELETE FROM t1 WHERE id > 2 RETURNING *;
+
+set sql_mode=@sql_mode_save;
+
+DROP TABLE t1;
diff --git a/mysql-test/t/delete_returning_grant.test b/mysql-test/t/delete_returning_grant.test
new file mode 100644
index 00000000000..f67a766b936
--- /dev/null
+++ b/mysql-test/t/delete_returning_grant.test
@@ -0,0 +1,78 @@
+#
+# Tests for DELETE FROM <table> ... RETURNING <expr>,...
+#
+--source include/not_embedded.inc
+
+CREATE TABLE t1 (a int(11), b varchar(32));
+INSERT INTO t1 VALUES (7,'ggggggg'),(1,'a'),(3,'ccc'),(4,'dddd'),(1,'A'),
+ (2,'BB'),(4,'DDDD'),(5,'EEEEE'),(7,'GGGGGGG'),(2,'bb');
+CREATE VIEW v1 AS SELECT a, UPPER(b) FROM t1;
+
+# DELETE FROM <table> ... RETURNING ... with checking privileges
+
+connect (root,localhost,root,,test);
+connection root;
+--disable_warnings
+CREATE DATABASE mysqltest;
+--enable_warnings
+
+CREATE TABLE mysqltest.t1 SELECT * FROM t1;
+GRANT DELETE ON mysqltest.* TO mysqltest_1@localhost;
+
+GRANT SELECT(b) ON mysqltest.t1 TO mysqltest_1@localhost;
+
+connect (user1,localhost,mysqltest_1,,test);
+
+connection user1;
+
+--error ER_COLUMNACCESS_DENIED_ERROR
+DELETE FROM mysqltest.t1 WHERE a=2 RETURNING b;
+
+DELETE FROM mysqltest.t1 RETURNING b;
+
+connection root;
+SELECT * FROM mysqltest.t1;
+INSERT INTO mysqltest.t1 SELECT * FROM t1;
+
+GRANT SELECT(a) ON mysqltest.t1 TO mysqltest_1@localhost;
+
+DELETE FROM mysqltest.t1 WHERE a=2 RETURNING b;
+
+SELECT * FROM mysqltest.t1;
+INSERT INTO mysqltest.t1 SELECT * FROM t1;
+
+connection root;
+CREATE VIEW mysqltest.v1(a) AS SELECT a FROM mysqltest.t1;
+GRANT SELECT, INSERT ON mysqltest.t1 TO mysqltest_1@localhost;
+
+connection user1;
+
+DELETE FROM mysqltest.v1;
+SELECT * FROM mysqltest.t1;
+
+INSERT INTO mysqltest.t1 SELECT * FROM t1;
+
+--error ER_COLUMNACCESS_DENIED_ERROR
+DELETE FROM mysqltest.v1 RETURNING a;
+
+connection root;
+GRANT SELECT ON mysqltest.* TO mysqltest_1@localhost;
+
+connection user1;
+DELETE FROM mysqltest.v1 RETURNING a;
+SELECT * FROM mysqltest.t1;
+
+INSERT INTO mysqltest.t1 SELECT * FROM t1;
+
+connection root;
+--disable_warnings
+DROP DATABASE mysqltest;
+--enable_warnings
+
+disconnect user1;
+DROP USER mysqltest_1@localhost;
+
+# Cleanup
+DROP VIEW v1;
+DROP TABLE t1;
+
diff --git a/mysql-test/t/derived.test b/mysql-test/t/derived.test
index c5b792c8d4d..00a88032f72 100644
--- a/mysql-test/t/derived.test
+++ b/mysql-test/t/derived.test
@@ -492,7 +492,38 @@ update t1 set balance=(select sum(balance) from (SELECT balance FROM t1 where ac
set optimizer_switch=@save_derived_optimizer_switch_bug;
drop table t1;
-set optimizer_switch=@save_derived_optimizer_switch;
+--echo #
+--echo # MDEV-6219:Server crashes in Bitmap<64u>::merge
+--echo # (this=0x180, map2=...) on 2nd execution of PS with INSERT .. SELECT,
+--echo # derived_merge
+--echo #
+
+CREATE TABLE t1 (a VARCHAR(8)) ENGINE=MyISAM;
+INSERT INTO t1 VALUES ('foo'),('bar');
+
+create procedure p1()
+ INSERT INTO t1 SELECT * FROM (
+ SELECT * FROM t1
+ ) AS sq
+ WHERE sq.a IN ( SELECT 'baz' FROM DUAL );
+
+call p1();
+call p1();
+drop procedure p1;
+
+PREPARE stmt FROM "
+ INSERT INTO t1 SELECT * FROM (
+ SELECT * FROM t1
+ ) AS sq
+ WHERE sq.a IN ( SELECT 'baz' FROM DUAL )
+";
+
+EXECUTE stmt;
+EXECUTE stmt;
+
+deallocate prepare stmt;
+
+drop table t1;
--echo #
--echo # MDEV-6892: WHERE does not apply
@@ -797,6 +828,8 @@ ORDER BY TOTAL DESC;
DROP TABLES t1,t2;
+set optimizer_switch=@save_derived_optimizer_switch;
+
--echo #
--echo # MDEV-10663: Use of Inline table columns in HAVING clause
--echo # throws 1463 Error
diff --git a/mysql-test/t/drop.test b/mysql-test/t/drop.test
index 079b10cf708..a3e96953bac 100644
--- a/mysql-test/t/drop.test
+++ b/mysql-test/t/drop.test
@@ -1,3 +1,5 @@
+call mtr.add_suppression("table or database name 'abc`def'");
+
# Initialise
--disable_warnings
drop table if exists t1;
@@ -274,3 +276,49 @@ DROP TABLE t1, t1;
UNLOCK TABLES;
DROP TABLE t1;
+
+--echo #
+--echo # BUG#34750: Print database name in Unknown Table error message
+--echo #
+
+--echo
+--echo # Test error message when droping table/view
+
+--error ER_BAD_TABLE_ERROR
+DROP TABLE table1;
+--error ER_BAD_TABLE_ERROR
+DROP TABLE table1,table2;
+--error ER_BAD_TABLE_ERROR
+DROP VIEW view1,view2,view3,view4;
+--echo
+DROP TABLE IF EXISTS table1;
+DROP TABLE IF EXISTS table1,table2;
+DROP VIEW IF EXISTS view1,view2,view3,view4;
+
+--echo
+--echo # Test error message when trigger does not find table
+
+CREATE TABLE table1(a int);
+CREATE TABLE table2(b int);
+
+# Database name is only available (for printing) if specified in
+# the trigger definition
+CREATE TRIGGER trg1 AFTER INSERT ON table1
+FOR EACH ROW
+ INSERT INTO table2 SELECT t.notable.*;
+
+--error ER_BAD_TABLE_ERROR
+INSERT INTO table1 VALUES (1);
+
+DROP TABLE table1,table2;
+
+--echo # End BUG#34750
+
+--echo #
+--echo # MDEV-11105 Table named 'db' has weird side effect.
+--echo #
+
+CREATE DATABASE mysqltest;
+CREATE TABLE mysqltest.db(id INT);
+DROP DATABASE mysqltest;
+
diff --git a/mysql-test/t/dyncol.test b/mysql-test/t/dyncol.test
index f0d9467420a..7807d1a9f9e 100644
--- a/mysql-test/t/dyncol.test
+++ b/mysql-test/t/dyncol.test
@@ -248,8 +248,10 @@ select column_get(column_create(1, "20010203"), 1 as datetime);
select column_get(column_create(1, 0), 1 as datetime);
select column_get(column_create(1, "2001021"), 1 as datetime);
+SET timestamp=unix_timestamp('2001-02-03 10:20:30');
select column_get(column_create(1, "8:46:06.23434" AS time), 1 as datetime);
select column_get(column_create(1, "-808:46:06.23434" AS time), 1 as datetime);
+SET timestamp=DEFAULT;
set @@sql_mode="allow_invalid_dates";
select column_get(column_create(1, "2011-02-30 18:46:06.23434" AS CHAR), 1 as datetime);
@@ -612,6 +614,12 @@ CREATE TABLE t1 (dyn TINYBLOB) ENGINE=MyISAM;
INSERT INTO t1 SET dyn = COLUMN_CREATE( 40, REPEAT('a', 233), 4, REPEAT('b', 322) );
--error ER_DYN_COL_WRONG_FORMAT
SELECT COLUMN_ADD( dyn, 6, REPEAT('x',80), 4, REPEAT('y',215) AS INTEGER ) FROM t1;
+delete from t1;
+--echo #above test with 10.0 format
+INSERT INTO t1 SET dyn = COLUMN_CREATE( 'a', REPEAT('a', 250), 'b', REPEAT('b', 322) );
+--error ER_DYN_COL_WRONG_FORMAT
+SELECT COLUMN_ADD( dyn, 'c', REPEAT('x',80), 'b', REPEAT('y',215) AS INTEGER ) FROM t1;
+
DROP table t1;
@@ -624,6 +632,11 @@ CREATE TABLE t1 (dyncol TINYBLOB) ENGINE=MyISAM;
INSERT INTO t1 SET dyncol = COLUMN_CREATE( 7, REPEAT('k',487), 209, REPEAT('x',464) );
--error 0,ER_DYN_COL_WRONG_FORMAT
SELECT COLUMN_ADD( dyncol, 7, '22:22:22', 8, REPEAT('x',270) AS CHAR ) FROM t1;
+delete from t1;
+INSERT INTO t1 SET dyncol = COLUMN_CREATE( 'a', REPEAT('k',487), 'b', REPEAT('x',464) );
+--error 0,ER_DYN_COL_WRONG_FORMAT
+SELECT COLUMN_ADD( dyncol, 'a', '22:22:22', 'c', REPEAT('x',270) AS CHAR ) FROM t1;
+
DROP table t1;
--echo #
@@ -649,3 +662,281 @@ select column_get(column_create(1, "18446744073709552001" as char), 1 as int);
--echo #
--error ER_TOO_BIG_SCALE
SELECT COLUMN_GET(`x`, 'y' AS DECIMAL(5,34));
+
+--echo #
+--echo # test of symbolic names
+--echo #
+--echo # creation test (names)
+set names utf8;
+select hex(column_create("адын", 1212));
+select hex(column_create("1212", 1212));
+select hex(column_create(1212, 2, "www", 3));
+select hex(column_create("1212", 2, "www", 3));
+select hex(column_create("1212", 2, 3, 3));
+select hex(column_create("1212", 2, "адын", 1, 3, 3));
+set names default;
+
+--echo # fetching column test (names)
+set names utf8;
+select column_get(column_create("адын", 1212), "адын" as int);
+select column_get(column_create("1212", 2, "адын", 1, 3, 3), "адын" as int);
+select column_get(column_create("1212", 2, "адын", 1, 3, 3), 1212 as int);
+select column_get(column_create("1212", 2, "адын", 1, 3, 3), "3" as int);
+select column_get(column_create("1212", 2, "адын", 1, 3, 3), 3 as int);
+select column_get(column_create("1212", 2, "адын", 1, 3, 3), 4 as int);
+select column_get(column_create("1212", 2, "адын", 1, 3, 3), "4" as int);
+set names default;
+
+--echo # column existance test (names)
+set names utf8;
+select column_exists(column_create("адын", 1212), "адын");
+select column_exists(column_create("адын", 1212), "aады");
+select column_exists(column_create("1212", 2, "адын", 1, 3, 3), "адын");
+select column_exists(column_create("1212", 2, "адын", 1, 3, 3), 1212);
+select column_exists(column_create("1212", 2, "адын", 1, 3, 3), "3");
+select column_exists(column_create("1212", 2, "адын", 1, 3, 3), 3);
+select column_exists(column_create("1212", 2, "адын", 1, 3, 3), 4);
+select column_exists(column_create("1212", 2, "адын", 1, 3, 3), "4");
+set names default;
+
+--echo # column changing test (names)
+select hex(column_add(column_create(1, "AAA"), "b", "BBB"));
+select hex(column_add(column_create("1", "AAA"), "b", "BBB"));
+select column_get(column_add(column_create(1, "AAA"), "b", "BBB"), 1 as char);
+select column_get(column_add(column_create(1, "AAA"), "b", "BBB"), "b" as char);
+select hex(column_add(column_create("a", "AAA"), 1, "BBB"));
+select hex(column_add(column_create("a", "AAA"), "1", "BBB"));
+select hex(column_add(column_create("a", 1212 as integer), "b", "1212" as integer));
+select hex(column_add(column_create("a", 1212 as integer), "a", "1212" as integer));
+select hex(column_add(column_create("a", 1212 as integer), "a", NULL as integer));
+select hex(column_add(column_create("a", 1212 as integer), "b", NULL as integer));
+select hex(column_add(column_create("a", 1212 as integer), "b", 1212 as integer, "a", 11 as integer));
+select column_get(column_add(column_create("a", 1212 as integer), "b", 1212 as integer, "a", 11 as integer), "a" as integer);
+select column_get(column_add(column_create("a", 1212 as integer), "b", 1212 as integer, "a", 11 as integer), "b" as integer);
+select hex(column_add(column_create("a", 1212 as integer), "a", 1212 as integer, "b", 11 as integer));
+select hex(column_add(column_create("a", NULL as integer), "a", 1212 as integer, "b", 11 as integer));
+select hex(column_add(column_create("a", 1212 as integer, "b", 1212 as integer), "a", 11 as integer));
+select hex(column_add(column_create("a", 1), "a", null));
+select column_list(column_add(column_create("a", 1), "a", null));
+select column_list(column_add(column_create("a", 1), "a", ""));
+select hex(column_add("", "a", 1));
+
+-- echo # column delete (names)
+select hex(column_delete(column_create("a", 1212 as integer, "b", 1212 as integer), "a"));
+select hex(column_delete(column_create("a", 1 as integer, "b", 2 as integer, "c", 3 as integer), "b"));
+select hex(column_create("a", 1 as integer, "b", 2 as integer, "c", 3 as integer));
+select hex(column_delete(column_create("a", 1 as integer, "b", 2 as integer, "c", 3 as integer), "c"));
+select hex(column_delete(column_create("a", 1 as integer, "b", 2 as integer, "c", 3 as integer), "d"));
+select hex(column_delete(column_create("a", 1 as integer, "b", 2 as integer, "c", 3 as integer), "b", "a"));
+select hex(column_delete(column_create("a", 1 as integer, "b", 2 as integer, "c", 3 as integer), "b", "c"));
+select hex(column_delete(column_create("a", 1 as integer, "b", 2 as integer, "c", 3 as integer), "a", "b", "c"));
+select hex(column_delete(column_create("a", 1 as integer, "b", 2 as integer, "c", 3 as integer), "a", "b", "c", "e"));
+select hex(column_delete(column_create("a", 1), "a"));
+select hex(column_delete("", "a"));
+
+--echo #
+--echo # MDEV-458 DNAMES: Server crashes on using an unquoted string
+--echo # as a dynamic column name
+--echo #
+--error ER_BAD_FIELD_ERROR
+select COLUMN_CREATE(color, "black");
+
+--echo #
+--echo # MDEV-489 Assertion `offset < 0x1f' failed in
+--echo # type_and_offset_store on COLUMN_ADD
+--echo #
+CREATE TABLE t1 (f1 tinyblob);
+
+INSERT INTO t1 VALUES (COLUMN_CREATE('col1', REPEAT('a',30)));
+select column_check(f1) from t1;
+UPDATE t1 SET f1 = COLUMN_ADD( f1, REPEAT('b',211), 'val2' );
+# we can't detect last string cut with 100% probability,
+# because we detect it by string end
+select column_check(f1) from t1;
+UPDATE t1 SET f1 = COLUMN_ADD( f1, REPEAT('c',211), 'val3' );
+select column_check(f1) from t1;
+
+drop table t1;
+
+--echo #
+--echo # MDEV-490/MDEV-491 null as arguments
+--echo #
+SELECT COLUMN_GET( COLUMN_CREATE( 'col', 'val' ), NULL AS CHAR );
+SELECT COLUMN_GET( NULL, 'col' as char );
+SELECT COLUMN_EXISTS( COLUMN_CREATE( 'col', 'val' ), NULL);
+SELECT COLUMN_EXISTS( NULL, 'col');
+SELECT COLUMN_CREATE( NULL, 'val' );
+SELECT COLUMN_ADD( NULL, 'val', 'col');
+
+--echo #
+--echo # MDEV-488: Assertion `column_name->length < 255' failed on a
+--echo # column name with length 255 (precisely)
+--echo #
+SELECT hex(COLUMN_CREATE(REPEAT('a',255),1));
+--error ER_DYN_COL_DATA
+SELECT hex(COLUMN_CREATE(REPEAT('a',65536),1));
+
+--echo #
+--echo # JSON conversion
+--echo #
+select column_json(column_create("int", -1212 as int, "uint", 12334 as unsigned int, "decimal", "23.344" as decimal, "double", 1.23444e50 as double, "string", 'gdgd\\dhdjh"dhdhd' as char, "time", "0:45:49.000001" AS time, "datetime", "2011-04-05 0:45:49.000001" AS datetime, "date", "2011-04-05" AS date));
+select column_json(column_create(1, -1212 as int, 2, 12334 as unsigned int, 3, "23.344" as decimal, 4, 1.23444e50 as double, 5, 'gdgd\\dhdjh"dhdhd' as char, 6, "0:45:49.000001" AS time, 7, "2011-04-05 0:45:49.000001" AS datetime, 8, "2011-04-05" AS date));
+
+--echo #
+--echo # CHECK test
+--echo #
+SELECT COLUMN_CHECK(COLUMN_CREATE(1,'a'));
+SELECT COLUMN_CHECK('abracadabra');
+SELECT COLUMN_CHECK('');
+SELECT COLUMN_CHECK(NULL);
+
+--echo #
+--echo # escaping check
+--echo #
+select column_json(column_create("string", "'\"/\\`.,whatever")),hex(column_create("string", "'\"/\\`.,whatever"));
+
+--echo #
+--echo # embedding test
+--echo #
+select column_json(column_create("val", "val", "emb", column_create("val2", "val2")));
+select column_json(column_create(1, "val", 2, column_create(3, "val2")));
+
+--echo #
+--echo # Time encoding
+--echo #
+select hex(column_create("t", "800:46:06.23434" AS time)) as hex,
+ column_json(column_create("t", "800:46:06.23434" AS time)) as json;
+select hex(column_create(1, "800:46:06.23434" AS time)) as hex,
+ column_json(column_create(1, "800:46:06.23434" AS time)) as json;
+
+select hex(column_create("t", "800:46:06" AS time)) as hex,
+ column_json(column_create("t", "800:46:06" AS time)) as json;
+select hex(column_create(1, "800:46:06" AS time)) as hex,
+ column_json(column_create(1, "800:46:06" AS time)) as json;
+
+select hex(column_create("t", "2012-12-21 10:46:06.23434" AS datetime)) as hex,
+ column_json(column_create("t", "2012-12-21 10:46:06.23434" AS datetime)) as json;
+select hex(column_create(1, "2012-12-21 10:46:06.23434" AS datetime)) as hex,
+ column_json(column_create(1, "2012-12-21 10:46:06.23434" AS datetime)) as json;
+
+select hex(column_create("t", "2012-12-21 10:46:06" AS datetime)) as hex,
+ column_json(column_create("t", "2012-12-21 10:46:06" AS datetime)) as json;
+select hex(column_create(1, "2012-12-21 10:46:06" AS datetime)) as hex,
+ column_json(column_create(1, "2012-12-21 10:46:06" AS datetime)) as json;
+
+--echo #
+--echo # MDEV-4849: Out of memory error and valgrind warnings on COLUMN_ADD
+--echo #
+CREATE TABLE t1 (dyncol tinyblob) ENGINE=MyISAM;
+
+INSERT INTO t1 SET dyncol = COLUMN_CREATE( 3, REPEAT('a',330), 4, 'x' );
+--error ER_DYN_COL_WRONG_FORMAT
+SELECT COLUMN_ADD( COLUMN_ADD( dyncol, 1, REPEAT('b',130) ), 3, 'y' ) FROM t1;
+
+DROP TABLE t1;
+
+--echo #
+--echo #MDEV-5840: group_concat( column_json(dynamic_column )) return empty
+--echo #result
+--echo #
+create table t1 (dyn blob);
+insert into t1 values (column_create('name1','value1','name2','value2'));
+select group_concat(cast(column_json(dyn) as char)) from t1;
+
+drop table t1;
+
+--echo #
+--echo # MDEV-7116: Dynamic column hangs/segfaults
+--echo #
+create table t1 (
+ impressions mediumblob
+);
+
+insert into t1 values ("");
+
+update t1
+set impressions = column_add(impressions,
+ 'total', 12,
+ '2014-10-28 16:00:00', 3,
+ '2014-10-30 15:00:00', 3,
+ '2014-11-04 09:00:00', 6
+ );
+update t1
+set impressions = column_add(impressions,
+ 'total', "a12",
+ '2014-10-28 16:00:00', "a3",
+ '2014-10-30 15:00:00', "a3",
+ '2014-11-04 09:00:00', "a6"
+ );
+
+drop table t1;
+
+--echo #
+--echo # MDEV-8565: COLUMN_CHECK fails on valid data
+--echo #
+
+SELECT COLUMN_CHECK(COLUMN_CREATE('a',0,'b','1'));
+
+SELECT COLUMN_CHECK(COLUMN_CREATE('a',1,'b','1'));
+
+SELECT COLUMN_JSON(COLUMN_CREATE('a',0,'b','1'));
+
+SELECT COLUMN_JSON(COLUMN_CREATE('a',1,'b','1'));
+
+--echo #
+--echo # MDEV-8401: COLUMN_CREATE(name, value as DOUBLE) results in string
+--echo #
+SELECT COLUMN_JSON(
+ COLUMN_CREATE(
+ 'one', 123.456,
+ 'two', 123.456 as DOUBLE
+ )
+);
+
+--echo #
+--echo # MDEV-8521: Drastic loss of precision in COLUMN_JSON() on DOUBLEs
+--echo #
+
+select column_get(column_create('float', 1.23456789012345E+100 as double), 'float' as double);
+select column_json(column_create('float', 1.23456789012345E+100 as double));
+select column_json(column_create('float', 1.23456789012345E+10 as double));
+
+--echo #
+--echo # MDEV-9147: Character set is ignored in Dynamic Column for saved string
+--echo #
+SET NAMES utf8;
+SELECT COLUMN_GET(COLUMN_CREATE(1, 0xC2A2 AS CHAR CHARACTER SET latin1), 1 AS CHAR CHARACTER SET utf8) AS a;
+SELECT COLUMN_GET(COLUMN_CREATE(1, 0xC2A2 AS CHAR CHARACTER SET utf8), 1 AS CHAR CHARACTER SET utf8) AS a;
+
+--echo #
+--echo # MDEV-9167: COLUMN_CHECK fails on valid decimal data
+--echo #
+
+SELECT COLUMN_CHECK(COLUMN_CREATE('a',0 AS DECIMAL,'b',1 AS DECIMAL));
+
+SELECT COLUMN_CHECK(COLUMN_CREATE('a',1 AS DECIMAL,'b',1 AS DECIMAL));
+
+SELECT COLUMN_JSON(COLUMN_CREATE('a',0 AS DECIMAL,'b',1 AS DECIMAL));
+
+SELECT COLUMN_JSON(COLUMN_CREATE('a',1 AS DECIMAL,'b',1 AS DECIMAL));
+
+
+--echo #
+--echo # MDEV-7533: COLUMN_JSON() doesn't escape control characters
+--echo # in string values
+--echo #
+SELECT COLUMN_JSON(COLUMN_CREATE('test','"\\\t\n\Z')) AS json;
+SELECT COLUMN_JSON(COLUMN_CREATE('test','First line\nSecond line')) AS json;
+
+--echo #
+--echo # MDEV-15230: column_json breaks cyrillic in 10.1.31
+--echo #
+set names utf8;
+create table t1 (b blob);
+insert into t1 values (column_create('description',column_create('title','ОпиÑание')));
+select column_json(b) from t1;
+drop table t1;
+
+--echo #
+--echo # end of 10.0 tests
+--echo #
diff --git a/mysql-test/t/empty_server_name-8224.test b/mysql-test/t/empty_server_name-8224.test
index 528bce5dac5..b15e9d82eb8 100644
--- a/mysql-test/t/empty_server_name-8224.test
+++ b/mysql-test/t/empty_server_name-8224.test
@@ -7,3 +7,7 @@ create server '' foreign data wrapper w2 options (host '127.0.0.1');
--shutdown_server 10
--source include/wait_until_disconnected.inc
--exec echo "restart" > $MYSQLTEST_VARDIR/tmp/mysqld.1.expect
+
+-- enable_reconnect
+-- source include/wait_until_connected_again.inc
+drop server '';
diff --git a/mysql-test/t/engine_error_in_alter-8453.test b/mysql-test/t/engine_error_in_alter-8453.test
new file mode 100644
index 00000000000..c4600ec07fe
--- /dev/null
+++ b/mysql-test/t/engine_error_in_alter-8453.test
@@ -0,0 +1,11 @@
+#
+# MDEV-8453 Alter table not returning engine errors
+#
+--source include/have_debug.inc
+
+create table t1 (a int, b int);
+set debug_dbug='+d,external_lock_failure';
+--error ER_GET_ERRMSG
+alter table t1 add column c int;
+set debug_dbug='';
+drop table t1;
diff --git a/mysql-test/t/events_1.test b/mysql-test/t/events_1.test
index 032d5ecd380..250b0d004dc 100644
--- a/mysql-test/t/events_1.test
+++ b/mysql-test/t/events_1.test
@@ -310,10 +310,8 @@ CREATE EVENT intact_check ON SCHEDULE EVERY 10 HOUR DO SELECT "nothing";
--echo expects to see event schema name there
--echo
ALTER TABLE mysql.event ADD dummy INT FIRST;
---error ER_CANNOT_LOAD_FROM_TABLE
--error ER_EVENT_OPEN_TABLE_FAILED
SHOW EVENTS;
---error ER_CANNOT_LOAD_FROM_TABLE
--error ER_EVENT_OPEN_TABLE_FAILED
SELECT event_name FROM INFORMATION_SCHEMA.events;
--error ER_EVENT_OPEN_TABLE_FAILED
@@ -461,6 +459,25 @@ DROP EVENT ev1;
SHOW EVENTS;
+--echo #
+--echo # MDEV-9524 Cannot load from mysql.event when sql_mode is set to PAD_CHAR_TO_FULL_LENGTH
+--echo #
+CREATE TABLE t1 (a INT);
+CREATE EVENT ev1 ON SCHEDULE EVERY 5 SECOND DO DELETE FROM t1;
+--replace_column 8 # 9 #
+SHOW EVENTS;
+SET sql_mode=PAD_CHAR_TO_FULL_LENGTH;
+--replace_column 8 # 9 #
+SHOW EVENTS;
+DROP EVENT ev1;
+CREATE EVENT ev1 ON SCHEDULE EVERY 5 SECOND DO DELETE FROM t1;
+--replace_column 8 # 9 #
+SHOW EVENTS;
+DROP EVENT ev1;
+DROP TABLE t1;
+SET sql_mode=DEFAULT;
+
+
--echo
--echo #
--echo # End of tests
diff --git a/mysql-test/t/events_bugs.test b/mysql-test/t/events_bugs.test
index dc31556998a..c33497f643d 100644
--- a/mysql-test/t/events_bugs.test
+++ b/mysql-test/t/events_bugs.test
@@ -305,7 +305,7 @@ create table events_smode_test(ev_name char(10), a date);
delimiter |;
create event ee_16407_2 on schedule every 60 second do
begin
- select get_lock('ee_16407_2', 60) /*ee_16407_2*/;
+ select get_lock('ee_16407_2', 60); /*ee_16407_2*/
select release_lock('ee_16407_2');
insert into events_test.events_smode_test values('ee_16407_2','1980-19-02');
end|
@@ -314,7 +314,7 @@ insert into events_test.events_smode_test values ('test','1980-19-02')|
--echo "This is ok"
create event ee_16407_3 on schedule every 60 second do
begin
- select get_lock('ee_16407_2', 60) /*ee_16407_3*/;
+ select get_lock('ee_16407_2', 60); /*ee_16407_3*/
select release_lock('ee_16407_2');
insert into events_test.events_smode_test values ('ee_16407_3','1980-02-19');
insert into events_test.events_smode_test values ('ee_16407_3','1980-02-29');
@@ -323,7 +323,7 @@ set sql_mode=""|
--echo "This will insert rows but they will be truncated"
create event ee_16407_4 on schedule every 60 second do
begin
- select get_lock('ee_16407_2', 60) /*ee_16407_4*/;
+ select get_lock('ee_16407_2', 60); /*ee_16407_4*/
select release_lock('ee_16407_2');
insert into events_test.events_smode_test values ('ee_16407_4','10-11-1956');
end|
@@ -411,13 +411,13 @@ create procedure ee_16407_5_pendant() begin insert into events_test.events_smode
create procedure ee_16407_6_pendant() begin insert into events_test.events_smode_test values('ee_16407_6','2004-02-29'); end|
create event ee_16407_5 on schedule every 60 second do
begin
- select get_lock('ee_16407_5', 60) /*ee_16407_5*/;
+ select get_lock('ee_16407_5', 60); /*ee_16407_5*/
select release_lock('ee_16407_5');
call events_test.ee_16407_5_pendant();
end|
create event ee_16407_6 on schedule every 60 second do
begin
- select get_lock('ee_16407_5', 60) /*ee_16407_6*/;
+ select get_lock('ee_16407_5', 60); /*ee_16407_6*/
select release_lock('ee_16407_5');
call events_test.ee_16407_6_pendant();
end|
@@ -943,7 +943,7 @@ DELIMITER ;|
# reasonable time like 4 seconds. Till ~ 2 seconds could pass on a heavy
# loaded testing box before something gets executed).
# Detection of execution is via the records inserted by the event.
---echo Sleep till the first INSERT into events_test.event_log occured
+--echo Sleep till the first INSERT into events_test.event_log occurred
let $wait_timeout= 4;
let $wait_condition=
SELECT COUNT(*) > 0 FROM events_test.event_log;
diff --git a/mysql-test/t/events_logs_tests.test b/mysql-test/t/events_logs_tests.test
index 3240dccbc76..c3bbff90723 100644
--- a/mysql-test/t/events_logs_tests.test
+++ b/mysql-test/t/events_logs_tests.test
@@ -46,7 +46,7 @@ call select_general_log();
--echo Check slow query log
--echo
--echo Ensure that slow logging is on
-show variables like 'log_slow_queries';
+show variables like 'slow_query_log';
--echo
--echo Demonstrate that session value has no effect
--echo
diff --git a/mysql-test/t/events_restart.test b/mysql-test/t/events_restart.test
index 83d28c0812d..7f01859e059 100644
--- a/mysql-test/t/events_restart.test
+++ b/mysql-test/t/events_restart.test
@@ -71,9 +71,9 @@ drop event intact_check_1;
drop event intact_check_2;
--error ER_EVENTS_DB_ERROR
drop event intact_check;
---error ER_EVENTS_DB_ERROR
+--error ER_STARTUP
set global event_scheduler=on;
---error ER_EVENTS_DB_ERROR
+--error ER_STARTUP
set global event_scheduler=off;
show variables like 'event_scheduler';
--echo Make sure that we still can create and drop databases,
@@ -84,6 +84,16 @@ drop database mysqltest_db1;
--echo Restore the original mysql.event table
drop table mysql.event;
rename table event_like to mysql.event;
+
+--echo check that we can now enable events without restart
+set global event_scheduler=original;
+select @@global.event_scheduler;
+set global event_scheduler=on;
+select @@global.event_scheduler;
+--sorted_result
+--replace_column 6 # 9 # 10 #
+show events;
+
--echo Now let's restart the server again
--source include/restart_mysqld.inc
@@ -107,3 +117,25 @@ let $wait_condition=
where db='events_test' and command = 'Connect' and user=current_user();
--source include/wait_condition.inc
+--echo #
+--echo # Test for bug#11748899 -- EVENT SET TO DISABLED AND ON COMPLETION
+--echo # NOT PRESERVE IS DELETED AT SERVER
+--echo #
+SELECT @@event_scheduler;
+USE test;
+--disable_warnings
+DROP EVENT IF EXISTS e1;
+--enable_warnings
+CREATE EVENT e1 ON SCHEDULE EVERY 1 SECOND DISABLE DO SELECT 1;
+--replace_column 6 # 9 # 10 #
+SHOW EVENTS;
+
+--echo "Now we restart the server"
+--source include/restart_mysqld.inc
+USE test;
+SELECT @@event_scheduler;
+--replace_column 6 # 9 # 10 #
+SHOW EVENTS;
+DROP EVENT e1;
+
+--echo # end test for bug#11748899
diff --git a/mysql-test/t/explain.test b/mysql-test/t/explain.test
index 9b9e65d7b51..d5be354c852 100644
--- a/mysql-test/t/explain.test
+++ b/mysql-test/t/explain.test
@@ -317,3 +317,19 @@ SELECT * FROM ( SELECT t1.a FROM t1,t2 WHERE t2.a = t1.a ) AS t;
set optimizer_switch=@tmp_optimizer_switch;
DROP TABLE t1,t2;
+
+--echo #
+--echo # MDEV-7215: EXPLAIN REPLACE produces an error:
+--echo # Column count doesn't match value count
+--echo #
+create table t1 (a int);
+insert into t1 values (1);
+create table t2 (b int, c int);
+
+replace into t2 select 100, (select a from t1);
+explain replace into t2 select 100, (select a from t1);
+#analyze replace into t2 select 100, (select a from t1);
+
+drop table t1, t2;
+
+--echo # End of 10.1 tests
diff --git a/mysql-test/t/explain_non_select.test b/mysql-test/t/explain_non_select.test
new file mode 100644
index 00000000000..d9ff0fb7245
--- /dev/null
+++ b/mysql-test/t/explain_non_select.test
@@ -0,0 +1,252 @@
+#
+# MariaDB tests for EXPLAIN UPDATE/DELETE.
+#
+--source include/have_partition.inc
+
+--disable_warnings
+drop table if exists t0, t1;
+--enable_warnings
+
+create table t0 (a int) engine=myisam;
+insert into t0 values (1),(2),(3),(4),(5),(6),(7),(8);
+
+--echo #
+--echo # Tests for single-table DELETE
+--echo #
+
+explain select * from t0 where a=3;
+explain delete from t0 where a=3;
+
+--echo # DELETE without WHERE is a special case:
+explain delete from t0;
+
+create table t1 (a int, b int, filler char(100), key(a), key(b));
+insert into t1
+select A.a+10*B.a + 10*C.a, A.a+10*B.a + 10*C.a, 'filler'
+from t0 A, t0 B, t0 C;
+
+--echo # This should use an index, possible_keys=NULL because there is no WHERE
+explain delete from t1 order by a limit 2;
+
+--echo # This should use range, possible_keys={a,b}
+explain delete from t1 where a<20 and b < 10;
+
+--echo # This should use ALL + filesort
+explain delete from t1 order by a+1 limit 2;
+
+--echo # This should use range + using filesort
+explain delete from t1 where a<20 order by b limit 2;
+
+--echo # Try some subqueries:
+explain delete from t1 where a < (select max(a) from t0);
+explain delete from t1 where a < (select max(a) from t0 where a < t1.b);
+
+--echo #
+--echo # Tests for multi-table DELETE
+--echo #
+explain delete t1 from t0, t1 where t0.a = t1.a;
+drop table t0, t1;
+
+--echo # ###################################################################
+--echo # ## EXPLAIN UPDATE tests
+--echo # ###################################################################
+create table t0 (a int) engine=myisam;
+insert into t0 values (1),(2),(3),(4),(5),(6),(7),(8);
+
+explain update t0 set a=3 where a=4;
+
+create table t1 (a int, b int, filler char(100), key(a), key(b));
+insert into t1
+select A.a+10*B.a + 10*C.a, A.a+10*B.a + 10*C.a, 'filler'
+from t0 A, t0 B, t0 C;
+
+explain update t1 set a=a+1 where 3>4;
+explain update t1 set a=a+1 where a=3 and a=4;
+
+--echo # This should use an index, possible_keys=NULL because there is no WHERE
+explain update t1 set a=a+1 order by a limit 2;
+
+--echo # This should use range, possible_keys={a,b}
+explain update t1 set filler='fooo' where a<20 and b < 10;
+
+--echo # This should use ALL + filesort
+explain update t1 set filler='fooo' order by a+1 limit 2;
+
+--echo # This should use range + using filesort
+explain update t1 set filler='fooo' where a<20 order by b limit 2;
+
+--echo # Try some subqueries:
+explain update t1 set filler='fooo' where a < (select max(a) from t0);
+explain update t1 set filler='fooo' where a < (select max(a) from t0 where a < t1.b);
+
+--echo #
+--echo # Tests for multi-table UPDATE
+--echo #
+explain update t0, t1 set t1.a=t1.a+1 where t0.a = t1.a;
+
+
+drop table t0, t1;
+
+--echo #
+--echo # Try DELETE ... RETURNING ...
+--echo #
+create table t0 (a int);
+insert into t0 values (1),(2),(3),(4);
+explain delete from t0 where a=1 returning a;
+explain delete from t0 returning a;
+drop table t0;
+
+--echo #
+--echo # MDEV-5070 - EXPLAIN INSERT ... SELECT crashes on 10.0-base-explain-slowquerylog
+--echo #
+create table t0 (a int);
+insert into t0 values (1),(2),(3),(4),(5),(6),(7),(8);
+create table t1 (a int);
+
+explain insert into t1 select * from t0;
+explain replace into t1 select * from t0;
+
+drop table t0, t1;
+
+--echo #
+--echo # MDEV-5067: Valgrind warnings (Invalid read) in QPF_table_access::print_explain
+--echo #
+CREATE TABLE t1 (i INT) ENGINE=MyISAM;
+INSERT INTO t1 VALUES (7),(0),(9);
+
+SELECT * FROM t1 INNER JOIN ( SELECT DISTINCT * FROM t1 ) AS sq ON (sq.i = t1.i);
+
+DROP TABLE t1;
+
+--echo #
+--echo # MDEV-5093, MDEV-5094: EXPLAIN PARTITIONS and EXPLAIN EXTENDED do not
+--echo # work for EXPLAIN UPDATE.
+--echo #
+create table t1 (i int);
+explain partitions update t1 set i = 3;
+
+create table t2 (a int, b int) partition by hash(a) partitions 5;
+insert into t2 values (0,0),(1,1),(2,2),(3,3),(4,4);
+
+explain partitions update t2 set b=3 where a in (3,4);
+explain partitions delete from t2 where a in (3,4);
+
+explain extended update t2 set b=3 where a in (3,4);
+explain extended delete from t2 where a in (3,4);
+
+drop table t1,t2;
+
+--echo #
+--echo # Check the special case where partition pruning removed all partitions
+--echo #
+
+create table t1 (a int, b int)
+partition by range (a) (
+ partition p0 values less than (10),
+ partition p1 values less than (20),
+ partition p2 values less than (30)
+);
+insert into t1 values (9,9), (19,19), (29,29);
+
+explain partitions select * from t1 where a in (32,33);
+
+explain partitions delete from t1 where a in (32,33);
+
+explain partitions update t1 set b=12345 where a in (32,33);
+
+drop table t1;
+
+--echo #
+--echo # Tests for EXPLAIN INSERT ... VALUES
+--echo #
+create table t1 (a int, key(a));
+explain insert into t1 values (1),(2),(3);
+insert into t1 values (1),(2),(3);
+
+create table t2 (a int, b int);
+explain insert into t2 values
+ (10, 1+(select max(a) from t1)),
+ (11, 1+(select max(a+1) from t1));
+
+drop table t1,t2;
+
+--echo #
+--echo # MDEV-5122: "Commands out of sync", "Malformed packet" or client hang up on unique key violation
+--echo #
+drop table if exists t1;
+
+--disable_warnings
+drop function if exists f1;
+--enable_warnings
+
+create table t1 (a int, unique(a));
+
+delimiter |;
+create function f1(x int)
+ returns int
+begin
+ insert into t1 values(x),(x);
+ return 10;
+end|
+delimiter ;|
+
+--error ER_DUP_ENTRY
+select f1(100);
+select 'OK';
+
+drop function f1;
+drop table t1;
+
+--echo #
+--echo # MDEV-7038: Assertion `status_var.memory_used == 0' failed in THD::~THD()
+--echo # on disconnect after executing EXPLAIN for multi-table UPDATE
+--echo #
+
+CREATE TABLE t1 (a INT);
+CREATE VIEW v1 AS SELECT * FROM t1;
+INSERT INTO t1 VALUES (1),(2);
+EXPLAIN UPDATE v1, mysql.user SET v1.a = v1.a + 1;
+DROP TABLE t1;
+DROP VIEW v1;
+
+--echo #
+--echo # MDEV-8299: MyISAM or Aria table gets corrupted after EXPLAIN INSERT and INSERT
+--echo #
+CREATE TABLE t1 (pk INT NOT NULL AUTO_INCREMENT PRIMARY KEY, i INT, KEY(i)) ENGINE=MyISAM;
+INSERT INTO t1 (i) VALUES (100),(200);
+
+CREATE TABLE t2 (j INT) ENGINE=MyISAM;
+INSERT INTO t2 VALUES (10),(20);
+
+EXPLAIN INSERT INTO t1 (i) SELECT j FROM t2;
+INSERT INTO t1 (i) VALUES (300);
+CHECK TABLE t1;
+
+DROP TABLE t1, t2;
+
+--echo #
+--echo # MDEV-8321: Assertion `! is_set()' failed in Diagnostics_area::set_eof_status on EXPLAIN INSERT ... UNION
+--echo #
+
+CREATE TABLE t1 (a INT);
+CREATE TABLE t2 (b INT);
+CREATE TABLE t3 (c INT);
+
+# Data is not necessary, tables can be empty as well
+INSERT INTO t1 VALUES (1),(2);
+INSERT INTO t2 VALUES (3),(4);
+INSERT INTO t3 VALUES (5),(6);
+
+EXPLAIN INSERT INTO t1 SELECT * FROM t2 UNION SELECT * FROM t3;
+drop table t1,t2,t3;
+
+--echo #
+--echo # MDEV-6223: Assertion `! is_set()' fails in Diagnostics_area::set_eof_status on EXPLAIN INSERT executed as a PS
+--echo #
+CREATE TABLE t1 (a INT) ENGINE = MyISAM;
+CREATE TABLE t2 (b INT) ENGINE = MyISAM;
+INSERT INTO t2 VALUES (1),(2);
+PREPARE stmt FROM 'EXPLAIN INSERT INTO t1 SELECT * FROM t2';
+EXECUTE stmt;
+drop table t1,t2;
+
diff --git a/mysql-test/t/explain_slowquerylog-master.opt b/mysql-test/t/explain_slowquerylog-master.opt
new file mode 100644
index 00000000000..0a3ad969e79
--- /dev/null
+++ b/mysql-test/t/explain_slowquerylog-master.opt
@@ -0,0 +1 @@
+--slow-query-log --long-query-time=0.00000 --log-slow-verbosity=query_plan,explain
diff --git a/mysql-test/t/explain_slowquerylog.test b/mysql-test/t/explain_slowquerylog.test
new file mode 100644
index 00000000000..6503a326eb8
--- /dev/null
+++ b/mysql-test/t/explain_slowquerylog.test
@@ -0,0 +1,63 @@
+#
+# This is a test for EXPLAINs being written into slow query log.
+# For now, we just run the queries and hope not to crash.
+#
+#
+--disable_warnings
+drop table if exists t0,t1;
+--enable_warnings
+
+create table t0 (a int);
+insert into t0 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
+
+explain select * from t0 where a < 3;
+
+--echo #
+--echo # MDEV-5045: Server crashes in QPF_query::print_explain with log_slow_verbosity='query_plan,explain'
+--echo #
+set autocommit=1;
+drop table t0;
+
+--echo #
+--echo # MDEV-5047 virtual THD::~THD(): Assertion `status_var.memory_used == 0' fails on disconnect
+--echo #
+--connect (con1,localhost,root,,)
+--error ER_NO_SUCH_TABLE
+ALTER TABLE nonexisting ENABLE KEYS;
+SHOW WARNINGS;
+--disconnect con1
+--connection default
+SELECT 1;
+
+--echo #
+--echo # MDEV-5060 Server crashes on EXPLAIN EXTENDED or EXPLAIN PARTITIONS with explain in slow_log
+--echo #
+EXPLAIN PARTITIONS SELECT 1 ;
+
+
+--echo #
+--echo # MDEV-5106: Server crashes in Explain_union::print_explain on ER_TOO_BIG_SELECT with explain in slow log
+--echo #
+CREATE TABLE t1 (i INT) ENGINE=MyISAM;
+INSERT INTO t1 VALUES
+(1),(2),(3),(4),(5),(6),(7),(8),(9),(10);
+SET max_join_size = 10;
+--error ER_TOO_BIG_SELECT
+( SELECT ta.* FROM t1 ta, t1 tb ) UNION ( SELECT * FROM t1 );
+SELECT 'Server still alive?' as 'Yes';
+
+DROP TABLE t1;
+
+--echo #
+--echo # MDEV-5308 Crash when running with slow_query_log=1
+--echo #
+SET @save1= @@log_slow_rate_limit;
+SET @save2= @@long_query_time;
+
+SET log_slow_rate_limit=1000;
+SET long_query_time=0.000001;
+SELECT 1;
+
+SET log_slow_rate_limit=@save1;
+SET long_query_time=@save2;
+
diff --git a/mysql-test/t/ext_key_noPK_6794.test b/mysql-test/t/ext_key_noPK_6794.test
new file mode 100644
index 00000000000..fc8a2724c22
--- /dev/null
+++ b/mysql-test/t/ext_key_noPK_6794.test
@@ -0,0 +1,15 @@
+#
+# MDEV-6794 XtraDB no longer using UNIQUE as clustered index when PK missing
+#
+
+--source include/have_innodb.inc
+
+create table t1 (c1 int not null, c2 int, unique index(c1), index (c2)) engine=innodb;
+insert into t1 (c1, c2) select 1, round(rand()*100);
+insert into t1 (c1, c2) select (select max(c1) from t1) + c1, c1*93563%100 from t1;
+insert into t1 (c1, c2) select (select max(c1) from t1) + c1, c1*93563%100 from t1;
+insert into t1 (c1, c2) select (select max(c1) from t1) + c1, c1*93563%100 from t1;
+select count(*) from t1;
+--query_vertical explain select * from t1 where c2 = 1 order by c1
+drop table t1;
+
diff --git a/mysql-test/t/features.test b/mysql-test/t/features.test
index cdfc9413da5..f2ac5a5bba6 100644
--- a/mysql-test/t/features.test
+++ b/mysql-test/t/features.test
@@ -6,6 +6,8 @@
drop table if exists t1;
--enable_warnings
+flush status;
+
show status like "feature%";
--echo #
@@ -109,3 +111,20 @@ select updatexml('<div><div><span>1</span><span>2</span></div></div>',
'/','<tr><td>1</td><td>2</td></tr>') as upd1;
--replace_result 4 2
show status like "feature_xml";
+
+
+--echo #
+--echo # Feature delayed_keys
+--echo #
+
+create table t1 (a int, key(a)) engine=myisam delay_key_write=1;
+insert into t1 values(1);
+insert into t1 values(2);
+drop table t1;
+
+create table t1 (a int, key(a)) engine=aria delay_key_write=1;
+insert into t1 values(1);
+insert into t1 values(2);
+drop table t1;
+
+show status like "feature_delay_key_write";
diff --git a/mysql-test/t/file_contents.test b/mysql-test/t/file_contents.test
index 9147727d3e8..186394df4e3 100644
--- a/mysql-test/t/file_contents.test
+++ b/mysql-test/t/file_contents.test
@@ -44,11 +44,11 @@ if ($dir_bin eq '/usr/') {
$dir_docs = "$dir_docs/Docs"; # development tree
}
}
-$found_version = "No line 'MySQL source #.#.#'";
-$found_revision = "No line 'revision-id: .....'";
+$found_version = "No line 'MySQL source #.#.#' in $dir_docs/INFO_SRC";
+$found_revision = "No line 'revision-id: .....' in $dir_docs/INFO_SRC";
open(I_SRC,"<","$dir_docs/INFO_SRC") or print "Cannot open 'INFO_SRC' in '$dir_docs' (starting from bindir '$dir_bin')\n";
while(defined ($line = <I_SRC>)) {
- if ($line =~ m|^MySQL source \d\.\d\.\d+|) {$found_version = "Found MySQL version number";}
+ if ($line =~ m|^MySQL source \d+\.\d\.\d+|) {$found_version = "Found MySQL version number";}
if ($line =~ m|^commit: \w{40}$|) {$found_revision = "Found GIT revision id";}
}
close I_SRC;
diff --git a/mysql-test/t/filesort_debug.test b/mysql-test/t/filesort_debug.test
index f89d46a7bd0..c375334ad29 100644
--- a/mysql-test/t/filesort_debug.test
+++ b/mysql-test/t/filesort_debug.test
@@ -11,7 +11,7 @@ SET @old_debug= @@session.debug;
CREATE TABLE t1(f0 int auto_increment primary key, f1 int);
INSERT INTO t1(f1) VALUES (0),(1),(2),(3),(4),(5);
-SET session debug_dbug= '+d,make_sort_keys_alloc_fail';
+SET session debug_dbug= '+d,alloc_sort_buffer_fail';
CALL mtr.add_suppression("Out of sort memory");
--error ER_OUT_OF_SORTMEMORY
SELECT * FROM t1 ORDER BY f1 ASC, f0;
diff --git a/mysql-test/t/flush-innodb-notembedded.test b/mysql-test/t/flush-innodb-notembedded.test
new file mode 100644
index 00000000000..d08a0647ff5
--- /dev/null
+++ b/mysql-test/t/flush-innodb-notembedded.test
@@ -0,0 +1,69 @@
+--source include/have_innodb.inc
+--source include/not_embedded.inc
+
+--echo # Test 7: Check privileges required.
+--echo #
+
+CREATE DATABASE db1;
+CREATE TABLE db1.t1 (a INT) engine= InnoDB;
+GRANT RELOAD, SELECT, LOCK TABLES ON *.* TO user1@localhost;
+GRANT CREATE, DROP ON *.* TO user2@localhost;
+GRANT RELOAD, SELECT ON *.* TO user3@localhost;
+GRANT SELECT, LOCK TABLES ON *.* TO user4@localhost;
+GRANT RELOAD, LOCK TABLES ON *.* TO user5@localhost;
+
+--echo # Connection con1 as user1
+--connect(con1, localhost, user1)
+FLUSH TABLE db1.t1 FOR EXPORT;
+UNLOCK TABLES;
+--disconnect con1
+--source include/wait_until_disconnected.inc
+
+--echo # Connection default
+--connection default
+
+--echo # Connection con1 as user2
+--connect(con1, localhost, user2)
+--error ER_SPECIFIC_ACCESS_DENIED_ERROR
+FLUSH TABLE db1.t1 FOR EXPORT;
+--disconnect con1
+--source include/wait_until_disconnected.inc
+
+--echo # Connection default
+--connection default
+
+--echo # Connection con1 as user3
+--connect(con1, localhost, user3)
+--error ER_DBACCESS_DENIED_ERROR
+FLUSH TABLE db1.t1 FOR EXPORT;
+--disconnect con1
+--source include/wait_until_disconnected.inc
+
+--echo # Connection default
+--connection default
+
+--echo # Connection con1 as user4
+--connect(con1, localhost, user4)
+--error ER_SPECIFIC_ACCESS_DENIED_ERROR
+FLUSH TABLE db1.t1 FOR EXPORT;
+--disconnect con1
+--source include/wait_until_disconnected.inc
+
+--echo # Connection default
+--connection default
+
+--echo # Connection con1 as user5
+--connect(con1, localhost, user5)
+--error ER_TABLEACCESS_DENIED_ERROR
+FLUSH TABLE db1.t1 FOR EXPORT;
+--disconnect con1
+--source include/wait_until_disconnected.inc
+
+--echo # Connection default
+--connection default
+DROP USER user1@localhost, user2@localhost, user3@localhost,
+ user4@localhost, user5@localhost;
+DROP TABLE db1.t1;
+DROP DATABASE db1;
+
+--echo # End of 5.6 tests
diff --git a/mysql-test/t/flush-innodb.test b/mysql-test/t/flush-innodb.test
index 207032b1acb..acf9493693a 100644
--- a/mysql-test/t/flush-innodb.test
+++ b/mysql-test/t/flush-innodb.test
@@ -4,6 +4,475 @@
FLUSH TABLES WITH READ LOCK AND DISABLE CHECKPOINT;
UNLOCK TABLES;
CREATE TABLE t1 ( m MEDIUMTEXT ) ENGINE=InnoDB;
-INSERT INTO t1 VALUES ( REPEAT('i',1048576) );
+INSERT INTO t1 VALUES ( REPEAT('i',65535) );
DROP TABLE t1;
+
+--echo
+--echo #
+--echo # WL#6168: FLUSH TABLES ... FOR EXPORT -- parser
+--echo #
+--echo
+
+--echo # Requires innodb_file_per_table
+SET @old_innodb_file_per_table= @@GLOBAL.innodb_file_per_table;
+SET GLOBAL innodb_file_per_table= 1;
+
+--echo # new "EXPORT" keyword is a valid user variable name:
+
+SET @export = 10;
+
+--echo # new "EXPORT" keyword is a valid SP parameter name:
+
+CREATE PROCEDURE p1(export INT) BEGIN END;
+DROP PROCEDURE p1;
+
+--echo # new "EXPORT" keyword is a valid local variable name:
+
+DELIMITER |;
+CREATE PROCEDURE p1()
+BEGIN
+ DECLARE export INT;
+END|
+DELIMITER ;|
+DROP PROCEDURE p1;
+
+--echo # new "EXPORT" keyword is a valid SP name:
+
+CREATE PROCEDURE export() BEGIN END;
+DROP PROCEDURE export;
+
+--echo # new FLUSH TABLES ... FOR EXPORT syntax:
+
+--error ER_PARSE_ERROR
+FLUSH TABLES FOR EXPORT;
+--error ER_PARSE_ERROR
+FLUSH TABLES WITH EXPORT;
+
+
+CREATE TABLE t1 (i INT) engine=InnoDB;
+CREATE TABLE t2 LIKE t1;
+
+--error ER_PARSE_ERROR
+FLUSH TABLES t1,t2 WITH EXPORT;
+
+FLUSH TABLES t1, t2 FOR EXPORT;
+UNLOCK TABLES;
+
+--echo # case check
+FLUSH TABLES t1, t2 for ExPoRt;
+UNLOCK TABLES;
+--echo # With LOCAL keyword
+FLUSH LOCAL TABLES t1, t2 FOR EXPORT;
+UNLOCK TABLES;
+--echo # Tables with fully qualified names
+FLUSH LOCAL TABLES test.t1, test.t2 for ExPoRt;
+UNLOCK TABLES;
+
+DROP TABLES t1, t2;
+
+--echo # new "EXPORT" keyword is a valid table name:
+
+CREATE TABLE export (i INT) engine=InnoDB;
+
+--echo # it's ok to lock the "export" table for export:
+
+FLUSH TABLE export FOR EXPORT;
+UNLOCK TABLES;
+
+DROP TABLE export;
+
+
+--echo #
+--echo # WL#6169 FLUSH TABLES ... FOR EXPORT -- runtime
+--echo #
+
+--echo # Test 1: Views, temporary tables, non-existent tables
+--echo #
+
+CREATE VIEW v1 AS SELECT 1;
+CREATE TEMPORARY TABLE t1 (a INT);
+
+--error ER_WRONG_OBJECT
+FLUSH TABLES v1 FOR EXPORT;
+--error ER_NO_SUCH_TABLE
+FLUSH TABLES t1 FOR EXPORT;
+--error ER_NO_SUCH_TABLE
+FLUSH TABLES non_existent FOR EXPORT;
+
+DROP TEMPORARY TABLE t1;
+DROP VIEW v1;
+
+--echo # Test 2: Blocked by update transactions, blocks updates.
+--echo #
+
+CREATE TABLE t1 (a INT PRIMARY KEY, b INT) engine= InnoDB;
+CREATE TABLE t2 (a INT) engine= InnoDB;
+
+--echo # Connection con1
+--connect (con1, localhost, root)
+START TRANSACTION;
+INSERT INTO t1 VALUES (1, 1);
+
+--echo # Connection default
+--connection default
+--echo # Should be blocked
+--echo # Sending:
+--send FLUSH TABLES t1 FOR EXPORT
+
+--echo # Connection con1
+--connection con1
+let $wait_condition=
+ SELECT COUNT(*) = 1 FROM information_schema.processlist
+ WHERE state = "Waiting for table metadata lock" AND
+ info = "FLUSH TABLES t1 FOR EXPORT";
+--source include/wait_condition.inc
+COMMIT;
+
+--echo # Connection default
+--connection default
+--echo # Reaping: FLUSH TABLES t1 FOR EXPORT
+--reap
+
+--echo # Connection con1
+--connection con1
+--echo # Should not be blocked
+INSERT INTO t2 VALUES (1);
+--echo # Should be blocked
+--echo # Sending:
+--send INSERT INTO t1 VALUES (2, 2)
+
+--echo # Connection default
+--connection default
+let $wait_condition=
+ SELECT COUNT(*) = 1 FROM information_schema.processlist
+ WHERE state = "Waiting for table metadata lock" AND
+ info = "INSERT INTO t1 VALUES (2, 2)";
+--source include/wait_condition.inc
+UNLOCK TABLES;
+
+--echo # Connection con1
+--connection con1
+--echo # Reaping: INSERT INTO t1 VALUES (2, 2);
+--reap
+
+--echo # Test 3: Read operations should not be affected.
+--echo #
+
+START TRANSACTION;
+SELECT * FROM t1;
+
+--echo # Connection default
+--connection default
+--echo # Should not be blocked
+FLUSH TABLES t1 FOR EXPORT;
+
+--echo # Connection con1
+--connection con1
+COMMIT;
+--echo # Should not be blocked
+SELECT * FROM t1;
+
+--echo # Connection default
+--connection default
+UNLOCK TABLES;
+
+--echo # Test 4: Blocked by DDL, blocks DDL.
+--echo #
+
+START TRANSACTION;
+SELECT * FROM t1;
+
+--echo # Connection con2
+--connect (con2, localhost, root)
+--echo # Sending:
+--send ALTER TABLE t1 ADD INDEX i1(b)
+
+--echo # Connection con1
+--connection con1
+let $wait_condition=
+ SELECT COUNT(*) = 1 FROM information_schema.processlist
+ WHERE state = "Waiting for table metadata lock" AND
+ info = "ALTER TABLE t1 ADD INDEX i1(b)";
+--source include/wait_condition.inc
+--echo # Should be blocked
+--send FLUSH TABLE t1 FOR EXPORT
+
+--echo # Connection default
+--connection default
+let $wait_condition=
+ SELECT COUNT(*) = 1 FROM information_schema.processlist
+ WHERE state = "Waiting for table metadata lock" AND
+ info = "FLUSH TABLE t1 FOR EXPORT";
+--source include/wait_condition.inc
+COMMIT;
+
+--echo # Connection con2
+--connection con2
+--echo # Reaping ALTER TABLE ...
+--reap
+
+--echo # Connection con1
+--connection con1
+--echo # Reaping FLUSH TABLE t1 FOR EXPORT
+--reap
+UNLOCK TABLES;
+
+--echo # Connection default
+--connection default
+FLUSH TABLE t1 FOR EXPORT;
+
+--echo # Connection con2
+--connection con2
+--echo # Should be blocked
+--send DROP TABLE t1
+
+--echo # Connection default
+--connection default
+let $wait_condition=
+ SELECT COUNT(*) = 1 FROM information_schema.processlist
+ WHERE state = "Waiting for table metadata lock" AND
+ info = "DROP TABLE t1";
+--source include/wait_condition.inc
+UNLOCK TABLES;
+
+--echo # Connection con2
+--connection con2
+--echo # Reaping DROP TABLE t1
+--reap
+--disconnect con2
+--source include/wait_until_disconnected.inc
+
+--echo # Connection default
+--connection default
+DROP TABLE t2;
+
+--echo # Test 5: Compatibilty with FLUSH TABLES WITH READ LOCK
+--echo #
+
+CREATE TABLE t1(a INT) engine= InnoDB;
+FLUSH TABLES WITH READ LOCK;
+
+--echo # Connection con1
+--connection con1
+--echo # This should not block
+FLUSH TABLE t1 FOR EXPORT;
+UNLOCK TABLES;
+
+--echo # Connection default
+--connection default
+UNLOCK TABLES;
+DROP TABLE t1;
+
+--echo # Test 6: Unsupported storage engines.
+--echo #
+
+CREATE TABLE t1(a INT) engine= MEMORY;
+--error ER_ILLEGAL_HA
+FLUSH TABLE t1 FOR EXPORT;
+DROP TABLE t1;
+
+--echo # Connection con1
+--connection con1
+--disconnect con1
+--source include/wait_until_disconnected.inc
+
+--echo # Connection defalt
+--connection default
+
+--echo # Test 7: Check privileges required.
+--echo # in flush-innodb-notembedded.test
+
+--echo # Test 8: FLUSH TABLE <table_list> FOR EXPORT is incompatible
+--echo # with itself (to avoid race conditions in metadata
+--echo # file handling).
+--echo #
+
+CREATE TABLE t1 (a INT) engine= InnoDB;
+CREATE TABLE t2 (a INT) engine= InnoDB;
+
+--echo # Connection con1
+--connect (con1, localhost, root)
+FLUSH TABLE t1 FOR EXPORT;
+
+--echo # Connection default
+--connection default
+--echo # This should not block
+FLUSH TABLE t2 FOR EXPORT;
+UNLOCK TABLES;
+--echo # This should block
+--echo # Sending:
+--send FLUSH TABLE t1 FOR EXPORT
+
+--echo # Connection con1
+--connection con1
+let $wait_condition=
+ SELECT COUNT(*) = 1 FROM information_schema.processlist
+ WHERE state = "Waiting for table metadata lock" AND
+ info = "FLUSH TABLE t1 FOR EXPORT";
+--source include/wait_condition.inc
+UNLOCK TABLES;
+
+--echo # Connection default
+--connection default
+--echo # Reaping: FLUSH TABLE t1 FOR EXPORT
+--reap
+UNLOCK TABLES;
+
+--echo # Test 9: LOCK TABLES ... READ is not affected
+--echo #
+
+LOCK TABLE t1 READ;
+
+--echo # Connection con1
+--connection con1
+--echo # Should not block
+FLUSH TABLE t1 FOR EXPORT;
+UNLOCK TABLES;
+
+--echo # Connection default
+--connection default
+UNLOCK TABLES;
+FLUSH TABLE t1 FOR EXPORT;
+
+--echo # Connection con1
+--connection con1
+--echo # Should not block
+LOCK TABLE t1 READ;
+UNLOCK TABLES;
+
+--echo # Connection default
+--connection default
+UNLOCK TABLES;
+
+--echo # Connection con1
+--connection con1
+--disconnect con1
+--source include/wait_until_disconnected.inc
+
+--echo # Connection default
+--connection default
+DROP TABLE t1, t2;
+
+--echo # Test 10: Lock is released if transaction is started after doing
+--echo # 'flush table..' in same session
+
+CREATE TABLE t1 ( i INT ) ENGINE = Innodb;
+FLUSH TABLE t1 FOR EXPORT;
+--echo # error as active locks already exist
+--error ER_LOCK_OR_ACTIVE_TRANSACTION
+FLUSH TABLE t1 FOR EXPORT;
+--echo # active locks will be released due to start transaction
+START TRANSACTION;
+--echo # passes as start transaction released ealier locks
+FLUSH TABLE t1 FOR EXPORT;
+UNLOCK TABLES;
+DROP TABLE t1;
+
+--echo # Test 11: Test 'flush table with fully qualified table names
+--echo # and with syntax local/NO_WRITE_TO_BINLOG
+
+--echo # Connection con1
+--connect (con1, localhost, root)
+
+--echo # Connection default
+--connection default
+CREATE TABLE t1 ( i INT ) ENGINE = Innodb;
+INSERT INTO t1 VALUES (100),(200);
+FLUSH LOCAL TABLES test.t1 FOR EXPORT;
+--echo # Connection con1
+--connection con1
+--echo # Should be blocked
+--echo # Sending:
+--send FLUSH LOCAL TABLES t1 FOR EXPORT
+
+--echo # Connection default
+--connection default
+let $wait_condition=
+ SELECT COUNT(*) = 1 FROM information_schema.processlist
+ WHERE state = "Waiting for table metadata lock" AND
+ info = "FLUSH LOCAL TABLES t1 FOR EXPORT";
+--source include/wait_condition.inc
+UNLOCK TABLE;
+
+--echo # Connection con1
+--connection con1
+--echo # Reaping: FLUSH LOCAL TABLES t1 FOR EXPORT
+--reap
+SELECT * FROM t1 ORDER BY i;
+
+--echo # Connection default
+--connection default
+--echo # Should be blocked
+--echo # Sending:
+--send FLUSH NO_WRITE_TO_BINLOG TABLES test.t1 FOR EXPORT
+
+--echo # Connection con1
+--connection con1
+let $wait_condition=
+ SELECT COUNT(*) = 1 FROM information_schema.processlist
+ WHERE state = "Waiting for table metadata lock" AND
+ info = "FLUSH NO_WRITE_TO_BINLOG TABLES test.t1 FOR EXPORT";
+--source include/wait_condition.inc
+UNLOCK TABLES;
+
+--echo # Connection default
+--connection default
+--echo # Reaping: FLUSH NO_WRITE_TO_BINLOG TABLES test.t1 FOR EXPORT
+--reap
+SELECT * FROM t1 ORDER BY i;
+UNLOCK TABLE;
+DROP TABLE t1;
+
+--echo # Test 12: Active transaction get committed if user execute
+--echo # "FLUSH TABLE ... FOR EXPORT" or "LOCK TABLE.."
+
+--echo # Connection default
+--connection default
+CREATE TABLE t1 ( i INT ) ENGINE = Innodb;
+INSERT INTO t1 VALUES (100),(200);
+START TRANSACTION;
+INSERT INTO t1 VALUES (300);
+--echo # 'flush table..' commit active transaction from same session
+FLUSH LOCAL TABLES test.t1 FOR EXPORT;
+ROLLBACK;
+SELECT * FROM t1 ORDER BY i;
+START TRANSACTION;
+INSERT INTO t1 VALUES (400);
+--echo # 'lock table ..' commit active transaction from same session
+LOCK TABLES test.t1 READ;
+ROLLBACK;
+SELECT * FROM t1 ORDER BY i;
+UNLOCK TABLES;
+DROP TABLE t1;
+
+--echo # Test 13: Verify "FLUSH TABLE ... FOR EXPORT" and "LOCK TABLE.."
+--echo # in same session
+--echo # Connection default
+
+--connection default
+CREATE TABLE t1 ( i INT ) ENGINE = Innodb;
+--echo # Lock table
+LOCK TABLES test.t1 WRITE;
+--echo # 'lock table ..' completes even if table lock is acquired
+--echo # in same session using 'lock table'. Previous locks are released.
+LOCK TABLES test.t1 READ;
+--echo # 'flush table ..' gives error if table lock is acquired
+--echo # in same session using 'lock table ..'
+--error ER_LOCK_OR_ACTIVE_TRANSACTION
+FLUSH TABLES test.t1 FOR EXPORT;
+--echo # 'lock table ..' completes even if table lock is acquired
+--echo # in same session using 'flush table'. Previous locks are released.
+LOCK TABLES test.t1 WRITE;
+UNLOCK TABLES;
+DROP TABLE t1;
+
+--connection con1
+--disconnect con1
+--source include/wait_until_disconnected.inc
+--connection default
+
+--echo # Reset innodb_file_per_table
+SET GLOBAL innodb_file_per_table= @old_innodb_file_per_table;
+
+--echo # End of 5.6 tests
diff --git a/mysql-test/t/flush.test b/mysql-test/t/flush.test
index 037e2fcaa73..a1df9359d30 100644
--- a/mysql-test/t/flush.test
+++ b/mysql-test/t/flush.test
@@ -701,3 +701,11 @@ disconnect con1;
connection default;
COMMIT;
DROP TABLE t1;
+
+--echo #
+--echo # Test flushing slave or relay logs twice
+--echo #
+--error ER_WRONG_USAGE
+flush relay logs,relay logs;
+--error ER_WRONG_USAGE
+flush slave,slave;
diff --git a/mysql-test/t/flush_read_lock.test b/mysql-test/t/flush_read_lock.test
index 9da93dd40a1..e8ec07392b5 100644
--- a/mysql-test/t/flush_read_lock.test
+++ b/mysql-test/t/flush_read_lock.test
@@ -557,7 +557,7 @@ let $cleanup_stmt= ;
--source include/check_ftwrl_compatible.inc
deallocate prepare stmt1;
-call mtr.add_suppression("Slave SQL.*Can.t execute the query because you have a conflicting read lock., Error_code: 1223");
+call mtr.add_suppression("Slave SQL.*Can.t execute the query because you have a conflicting read lock., error.* 1223");
--echo #
--echo # 9.2.b) EXECUTE for statement which is incompatible with FTWRL
@@ -708,11 +708,10 @@ let $cleanup_stmt1= create table t2_base(j int);
--source include/check_ftwrl_incompatible.inc
--echo # 13.1.b) DROP TABLES which affects only temporary tables
---echo # in theory can be compatible with FTWRL.
---echo # In practice it is not yet.
+--echo # is compatible with FTWRL.
let $statement= drop table t2_temp;
-let $cleanup_stmt1= create temporary table t2_temp(j int);
---source include/check_ftwrl_incompatible.inc
+let $cleanup_stmt= create temporary table t2_temp(j int);
+--source include/check_ftwrl_compatible.inc
--echo #
--echo # 13.1.c) DROP TEMPORARY TABLES should be compatible with FTWRL.
@@ -1902,35 +1901,10 @@ let $statement= analyze table t3_temp_trans;
let $cleanup_stmt= ;
--source include/check_ftwrl_compatible.inc
--echo #
---echo # 39.2.c) Some statements do implicit commit and not
---echo # considered read-only. As result they are
---echo # not compatible with FTWRL.
---echo #
-flush tables with read lock;
---echo # Implicit commits are allowed under FTWRL.
-alter table t3_temp_trans add column c1 int;
-unlock tables;
---echo #
---echo # Switching to connection '$con_aux1'.
-connection $con_aux1;
-flush tables with read lock;
---echo # Switching to connection 'default'.
-connection default;
---send alter table t3_temp_trans drop column c1
---echo # Switching to connection '$con_aux1'.
-connection $con_aux1;
---echo # Check that ALTER TABLE is blocked.
-let $wait_condition=
- select count(*) = 1 from information_schema.processlist
- where state = "Waiting for commit lock" and
- info = "alter table t3_temp_trans drop column c1";
---source include/wait_condition.inc
-unlock tables;
---echo # Switching to connection 'default'.
-connection default;
---echo # Reap ALTER TABLE
---reap
-
+--echo # And ALTER TABLE:
+let $statement= alter table t3_temp_trans add column c1 int;
+let $cleanup_stmt= alter table t3_temp_trans drop column c1;
+--source include/check_ftwrl_compatible.inc
--echo #
--echo # 40) Test effect of implicit commit for DDL which is otherwise
diff --git a/mysql-test/t/fulltext.test b/mysql-test/t/fulltext.test
index 2eb4634e15c..fc7b15c052d 100644
--- a/mysql-test/t/fulltext.test
+++ b/mysql-test/t/fulltext.test
@@ -700,3 +700,18 @@ drop table t1;
--echo #
--echo # End of 5.5 tests
--echo #
+
+#
+# MDEV-318 IF (NOT) EXIST clauses for ALTER TABLE (MWL #252).
+#
+
+CREATE TABLE t1 (
+ id int(11) auto_increment,
+ title varchar(100) default '',
+ PRIMARY KEY (id),
+ KEY ind5 (title)
+) ENGINE=MyISAM;
+
+CREATE FULLTEXT INDEX IF NOT EXISTS ft1 ON t1(title);
+CREATE FULLTEXT INDEX IF NOT EXISTS ft1 ON t1(title);
+DROP TABLE t1;
diff --git a/mysql-test/t/func_concat.test b/mysql-test/t/func_concat.test
index e56d1121808..69dd2c4063e 100644
--- a/mysql-test/t/func_concat.test
+++ b/mysql-test/t/func_concat.test
@@ -145,3 +145,100 @@ CALL p1();
DROP PROCEDURE p1;
--echo # End of 5.1 tests
+
+
+--echo #
+--echo # Start of 10.0 tests
+--echo #
+
+--echo #
+--echo # MDEV-10306 Wrong results with combination of CONCAT, SUBSTR and CONVERT in subquery
+--echo #
+
+SET @save_optimizer_switch=@@optimizer_switch;
+SET optimizer_switch='derived_merge=on';
+
+CREATE TABLE t1 (t VARCHAR(10) CHARSET latin1);
+INSERT INTO t1 VALUES('1234567');
+SELECT CONCAT(SUBSTR(t2, 1, 3), SUBSTR(t2, 5)) c1,
+ CONCAT(SUBSTR(t2,1,3),'---',SUBSTR(t2,5)) c2
+ FROM (SELECT CONVERT(t USING latin1) t2 FROM t1) sub;
+SELECT CONCAT(t2,'-',t2) c2 FROM (SELECT CONVERT(t USING latin1) t2 FROM t1) sub;
+DROP TABLE t1;
+
+# Other functions affected by MDEV-10306
+
+CREATE TABLE t1 (t VARCHAR(10) CHARSET latin1);
+INSERT INTO t1 VALUES('1234567');
+SELECT CONCAT(t2,'-',t2) c2 FROM (SELECT CONVERT(t USING latin1) t2 FROM t1) sub;
+SELECT CONCAT(t2,'-',t2) c2 FROM (SELECT REVERSE(t) t2 FROM t1) sub;
+SELECT CONCAT(t2,'-',t2) c2 FROM (SELECT SOUNDEX(t) t2 FROM t1) sub;
+SELECT CONCAT(t2,'-',t2) c2 FROM (SELECT TO_BASE64(t) t2 FROM t1) sub;
+SELECT CONCAT(t2,'-',t2) c2 FROM (SELECT WEIGHT_STRING(t) t2 FROM t1) sub;
+SELECT CONCAT(t2,'-',t2) c2 FROM (SELECT HEX(t) t2 FROM t1) sub;
+SELECT CONCAT(t2,'-',t2) c2 FROM (SELECT QUOTE(t) t2 FROM t1) sub;
+DROP TABLE t1;
+
+CREATE TABLE t1 (t VARCHAR(32) CHARSET latin1);
+INSERT INTO t1 VALUES(TO_BASE64('abcdefghi'));
+SELECT CONCAT(t2,'-',t2) c2 FROM (SELECT FROM_BASE64(t) t2 FROM t1) sub;
+DROP TABLE t1;
+
+CREATE TABLE t1 (t VARCHAR(32) CHARSET latin1);
+INSERT INTO t1 VALUES(HEX('abcdefghi'));
+SELECT CONCAT(t2,'-',t2) c2 FROM (SELECT UNHEX(t) t2 FROM t1) sub;
+DROP TABLE t1;
+
+CREATE TABLE t1 (t VARCHAR(30) CHARSET latin1);
+INSERT INTO t1 VALUES('test');
+SELECT LENGTH(CONCAT(t2)) c2 FROM (SELECT AES_ENCRYPT(t,'x') t2 FROM t1) sub;
+SELECT LENGTH(CONCAT(t2,'-',t2)) c2 FROM (SELECT AES_ENCRYPT(t,'x') t2 FROM t1) sub;
+SELECT LENGTH(CONCAT(t2,'--',t2)) c2 FROM (SELECT AES_ENCRYPT(t,'x') t2 FROM t1) sub;
+SELECT LENGTH(CONCAT(t2)) c2 FROM (SELECT AES_DECRYPT(AES_ENCRYPT(t,'x'),'x') t2 FROM t1) sub;
+SELECT LENGTH(CONCAT(t2,'-',t2)) c2 FROM (SELECT AES_DECRYPT(AES_ENCRYPT(t,'x'),'x') t2 FROM t1) sub;
+SELECT LENGTH(CONCAT(t2,'--',t2)) c2 FROM (SELECT AES_DECRYPT(AES_ENCRYPT(t,'x'),'x') t2 FROM t1) sub;
+DROP TABLE t1;
+
+
+# Functions not affected by MDEV-10306
+# They only had an unused tmp_value, which was removed.
+
+CREATE TABLE t1 (t VARCHAR(64) CHARSET latin1);
+INSERT INTO t1 VALUES('123456789');
+SELECT CONCAT(t2,'-',t2) c2 FROM (SELECT MD5(t) t2 FROM t1) sub;
+SELECT CONCAT(t2,'-',t2) c2 FROM (SELECT FORMAT(t,2) t2 FROM t1) sub;
+DROP TABLE t1;
+
+# Functions not affected by MDEV-10306
+# They already use tmp_value only for internal purposes and
+# return the result in the String passed to val_str()
+
+CREATE TABLE t1 (t VARCHAR(32) CHARSET latin1);
+INSERT INTO t1 VALUES('abcdefghi');
+SELECT CONCAT(t2,'-',t2) c2 FROM (SELECT INSERT(t,3,4,'xxx') t2 FROM t1) sub;
+DROP TABLE t1;
+
+
+# Functions not affected by MDEV-10306
+# They use this code style:
+# String *res= args[0]->val_str(str);
+# tmp_value.set(*res, start, end);
+# return &tmp_value;
+
+CREATE TABLE t1 (t VARCHAR(10) CHARSET latin1);
+INSERT INTO t1 VALUES('abcdefghi');
+SELECT CONCAT(t2,'-',t2) c2 FROM (SELECT LEFT(t,10) t2 FROM t1) sub;
+SELECT CONCAT(t2,'-',t2) c2 FROM (SELECT RIGHT(t,10) t2 FROM t1) sub;
+SELECT CONCAT(t2,'-',t2) c2 FROM (SELECT SUBSTR(t,1,10) t2 FROM t1) sub;
+SELECT CONCAT(t2,'-',t2) c2 FROM (SELECT LTRIM(t) t2 FROM t1) sub;
+SELECT CONCAT(t2,'-',t2) c2 FROM (SELECT RTRIM(t) t2 FROM t1) sub;
+SELECT CONCAT(t2,'-',t2) c2 FROM (SELECT TRIM(t) t2 FROM t1) sub;
+DROP TABLE t1;
+
+SET optimizer_switch=@save_optimizer_switch;
+
+--echo #
+--echo # MDEV-13790 UNHEX() of a somewhat complicated CONCAT() returns NULL
+--echo #
+
+SELECT UNHEX(CONCAT('414C2', HEX(8 + ROUND(RAND()*7)), SUBSTR(SHA(UUID()),6,33),HEX(2+ROUND(RAND()*8)))) IS NULL AS c1;
diff --git a/mysql-test/t/func_crypt.test b/mysql-test/t/func_crypt.test
index ca6e712f45c..785cc63d3f1 100644
--- a/mysql-test/t/func_crypt.test
+++ b/mysql-test/t/func_crypt.test
@@ -70,3 +70,27 @@ SELECT OLD_PASSWORD(c1), PASSWORD(c1) FROM t1;
DROP TABLE t1;
--echo End of 5.0 tests
+
+
+--echo #
+--echo # Start of 10.0 tests
+--echo #
+
+--echo #
+--echo # MDEV-10306 Wrong results with combination of CONCAT, SUBSTR and CONVERT in subquery
+--echo #
+
+SET @save_optimizer_switch=@@optimizer_switch;
+SET optimizer_switch='derived_merge=on';
+# ENCRYPT() is not affected by MDEV-10306
+# It already uses tmp_value only for internal purposes and
+# returns the result in the String passed to val_str()
+CREATE TABLE t1 (t VARCHAR(32) CHARSET latin1);
+INSERT INTO t1 VALUES('abcdefghi');
+SELECT CONCAT(t2,'-',t2) c2 FROM (SELECT ENCRYPT(t,'aa') t2 FROM t1) sub;
+DROP TABLE t1;
+SET optimizer_switch=@save_optimizer_switch;
+
+--echo #
+--echo # End of 10.0 tests
+--echo #
diff --git a/mysql-test/t/func_des_encrypt.test b/mysql-test/t/func_des_encrypt.test
index e121aedab06..c9661b81cc0 100644
--- a/mysql-test/t/func_des_encrypt.test
+++ b/mysql-test/t/func_des_encrypt.test
@@ -1,4 +1,4 @@
--- source include/have_ssl_crypto_functs.inc
+-- source include/have_des.inc
# This test can't be in func_encrypt.test, because it requires
# --des-key-file to not be set.
diff --git a/mysql-test/t/func_encrypt.test b/mysql-test/t/func_encrypt.test
index 18fb072966b..e24cb80f995 100644
--- a/mysql-test/t/func_encrypt.test
+++ b/mysql-test/t/func_encrypt.test
@@ -1,4 +1,4 @@
--- source include/have_ssl_crypto_functs.inc
+-- source include/have_des.inc
--disable_warnings
drop table if exists t1;
diff --git a/mysql-test/t/func_encrypt_nossl.test b/mysql-test/t/func_encrypt_nossl.test
index 11866db1da7..2dafaa671c4 100644
--- a/mysql-test/t/func_encrypt_nossl.test
+++ b/mysql-test/t/func_encrypt_nossl.test
@@ -1,4 +1,4 @@
--- source include/not_openssl.inc
+-- source include/not_ssl.inc
#
# Test output from des_encrypt and des_decrypt when server is
diff --git a/mysql-test/t/func_encrypt_ucs2.test b/mysql-test/t/func_encrypt_ucs2.test
index 8b4cd44d354..1242c3b9e6a 100644
--- a/mysql-test/t/func_encrypt_ucs2.test
+++ b/mysql-test/t/func_encrypt_ucs2.test
@@ -1,4 +1,4 @@
--- source include/have_ssl_crypto_functs.inc
+-- source include/have_des.inc
-- source include/have_ucs2.inc
--echo #
diff --git a/mysql-test/t/func_group_innodb.test b/mysql-test/t/func_group_innodb.test
index 06405808d79..c62d3d08496 100644
--- a/mysql-test/t/func_group_innodb.test
+++ b/mysql-test/t/func_group_innodb.test
@@ -180,7 +180,12 @@ SET storage_engine=@old_engine;
CREATE TABLE t1(a BLOB, b VARCHAR(255) CHARSET LATIN1, c INT,
KEY(b, c, a(765))) ENGINE=INNODB;
-INSERT INTO t1(a, b, c) VALUES ('', 'a', 0), ('', 'a', null), ('', 'a', 0);
+INSERT INTO t1(a, b, c) VALUES
+('', 'a', 0), ('', 'a', null), ('', 'a', 0), ('', 'a', null), ('', 'a', 0);
+
+-- disable_result_log
+ANALYZE TABLE t1;
+-- enable_result_log
SELECT MIN(c) FROM t1 GROUP BY b;
EXPLAIN SELECT MIN(c) FROM t1 GROUP BY b;
diff --git a/mysql-test/t/func_in.test b/mysql-test/t/func_in.test
index 439f9868ec8..d3b031d4c81 100644
--- a/mysql-test/t/func_in.test
+++ b/mysql-test/t/func_in.test
@@ -614,3 +614,24 @@ create table t1 (a int);
insert t1 values (1),(2),(3);
select * from t1 where 1 in (a, name_const('a', null));
drop table t1;
+
+--echo #
+--echo # Start of 10.0 tests
+--echo #
+
+--echo #
+--echo # MDEV-10020 InnoDB NOT IN Query Crash When One Item Is NULL
+--echo #
+CREATE TABLE t1
+(
+ a INT(11),
+ b VARCHAR(10),
+ KEY (b)
+);
+INSERT INTO t1 VALUES (1,'x'),(2,'y'),(3,'z');
+SELECT * FROM t1 WHERE b NOT IN (NULL, '', 'A');
+DROP TABLE t1;
+
+--echo #
+--echo # End of 10.0 tests
+--echo #
diff --git a/mysql-test/t/func_like.test b/mysql-test/t/func_like.test
index f1fe52274b2..bc64504c742 100644
--- a/mysql-test/t/func_like.test
+++ b/mysql-test/t/func_like.test
@@ -133,3 +133,13 @@ DROP TABLE t1, t2;
SELECT '' LIKE '1' ESCAPE COUNT(1);
--echo End of 5.1 tests
+
+--echo #
+--echo # Start of 10.0 tests
+--echo #
+
+--echo #
+--echo # MDEV-5445 Server crashes in Item_func_like::fix_fields on LIKE ExtractValue(..)
+--echo #
+SELECT 'a' LIKE REPEAT('',0);
+SELECT 'a' LIKE EXTRACTVALUE('bar','qux');
diff --git a/mysql-test/t/func_math.test b/mysql-test/t/func_math.test
index d31b33b5df9..904e8700d26 100644
--- a/mysql-test/t/func_math.test
+++ b/mysql-test/t/func_math.test
@@ -547,6 +547,15 @@ SELECT 1 div null;
select (1.175494351E-37 div 1.7976931348623157E+308);
--echo #
+--echo # Bug#12744991 - DECIMAL_ROUND(X,D) GIVES WRONG RESULTS WHEN D == N*(-9)
+--echo #
+
+select round(999999999, -9);
+select round(999999999.0, -9);
+select round(999999999999999999, -18);
+select round(999999999999999999.0, -18);
+
+--echo #
--echo # Bug#12537160 ASSERTION FAILED:
--echo # STOP0 <= &TO->BUF[TO->LEN] WITH LARGE NUMBER.
--echo #
@@ -579,3 +588,12 @@ DROP TABLE t1;
--echo #
--echo # End of 5.5 tests
--echo #
+
+--echo #
+--echo # MDEV-5781 Item_sum_std::val_real(): Assertion `nr >= 0.0' fails on query with STDDEV_POP, ROUND and variable
+--echo #
+SELECT STDDEV_POP(ROUND(0,@A:=2009)) FROM (SELECT 1 UNION SELECT 2) fake_table;
+
+--echo #
+--echo # End of 10.0 tests
+--echo #
diff --git a/mysql-test/t/func_misc.test b/mysql-test/t/func_misc.test
index c21630c0c7b..271d061b192 100644
--- a/mysql-test/t/func_misc.test
+++ b/mysql-test/t/func_misc.test
@@ -596,6 +596,15 @@ AND 57813X540X1723 = 'Test';
drop table t1;
+#
+# Bug#12735545 - PARSER STACK OVERFLOW WITH NAME_CONST
+# CONTAINING OR EXPRESSION
+#
+--error ER_WRONG_ARGUMENTS
+SELECT NAME_CONST('a', -(1 OR 2)) OR 1;
+--error ER_WRONG_ARGUMENTS
+SELECT NAME_CONST('a', -(1 AND 2)) OR 1;
+SELECT NAME_CONST('a', -(1)) OR 1;
--echo #
--echo # MDEV-15630 uuid() function evaluates at wrong time in query
@@ -612,12 +621,500 @@ DROP TABLE t1;
--echo # End of 5.5 tests
--echo #
-#
-# Bug#12735545 - PARSER STACK OVERFLOW WITH NAME_CONST
-# CONTAINING OR EXPRESSION
-#
---error ER_WRONG_ARGUMENTS
-SELECT NAME_CONST('a', -(1 OR 2)) OR 1;
---error ER_WRONG_ARGUMENTS
-SELECT NAME_CONST('a', -(1 AND 2)) OR 1;
-SELECT NAME_CONST('a', -(1)) OR 1;
+--echo #
+--echo # GET_LOCK, RELEASE_LOCK, IS_USED_LOCK functions test
+--echo #
+
+--echo # IS_USED_LOCK, IS_FREE_LOCK: the lock is not acquired
+--echo # Note: IS_USED_LOCK returns NULL if the lock is unused
+select is_used_lock('test');
+select is_free_lock('test');
+
+--echo # GET_LOCK returns 1 if it manages to acquire a lock
+select get_lock('test', 0);
+
+--echo # IS_USED_LOCK, IS_FREE_LOCK: the lock is acquired
+select is_free_lock('test');
+select is_used_lock('test') = connection_id();
+
+connect (con1,localhost,root,,);
+--echo # -> Switching to connection 'con1'
+connection con1;
+--echo # IS_USED_LOCK, IS_FREE_LOCK: the lock is acquired in another
+--echo # connection
+select is_used_lock('test') = connection_id();
+select is_free_lock('test');
+
+--echo # GET_LOCK returns 0 if it can't acquire a lock (wait timeout)
+select get_lock('test', 0);
+
+--echo # RELEASE_LOCK returns 0 if the lock belongs to another connection
+select release_lock('test');
+
+--echo # -> Switching to connection 'default'
+connection default;
+
+--echo # RELEASE_LOCK returns 1 if it successfully releases a lock
+select release_lock('test');
+--echo # RELEASE_LOCK returns NULL if it doesn't release a lock and there is no such lock
+select release_lock('test');
+
+--echo # Test that get_lock() returns NULL if error.
+select get_lock('test', 0);
+--echo # -> Switching to connection 'con1'
+connection con1;
+create table t1 select connection_id() as id;
+send select get_lock('test', 7200);
+
+--echo # -> Switching to connection 'default'
+connection default;
+let $wait_condition= SELECT count(*) > 0 FROM information_schema.processlist WHERE info LIKE 'select%' AND state='User lock';
+source include/wait_condition.inc;
+select (@id := id) - id from t1;
+kill query @id;
+
+--echo # -> Switching to connection 'con1'
+connection con1;
+reap;
+
+--echo # -> Switching to connection 'default'
+connection default;
+
+--echo # GET_LOCK() works recursively
+select get_lock('test', 0);
+select get_lock('test', 0);
+select get_lock('test', 0);
+
+--echo # RELEASE_LOCK() needs to be called recursively then, too
+select release_lock('test');
+select release_lock('test');
+select release_lock('test');
+
+--echo # Once the last instance of the lock is released,
+--echo # the next call returns NULL
+select release_lock('test');
+
+
+--echo # Multiple locks in the same session are OK
+select get_lock('test1', 0);
+select get_lock('test2', 0);
+select get_lock('test3', 0);
+
+select release_lock('test1');
+select release_lock('test2');
+select release_lock('test3');
+
+--echo # Deadlocks are detected e.g. in case of a mutual wait
+select get_lock('test1', 0);
+
+--echo # -> Switching to connection 'con1'
+connection con1;
+select get_lock('test2', 0);
+send select get_lock('test1', 7200);
+
+--echo # -> Switching to connection 'default'
+connection default;
+let $wait_condition= SELECT count(*) > 0 FROM information_schema.processlist WHERE info LIKE 'select%' AND state='User lock';
+source include/wait_condition.inc;
+--error ER_LOCK_DEADLOCK
+select get_lock('test2', 7200);
+
+select release_lock('test1');
+
+--echo # -> Switching to connection 'con1'
+connection con1;
+reap;
+select release_lock('test2');
+select release_lock('test1');
+
+--echo # -> Switching to connection 'default'
+connection default;
+
+--echo # LOCK/UNLOCK TABLES works fine with a user lock.
+lock table t1 write;
+select get_lock('test', 0);
+unlock tables;
+commit;
+select release_lock('test');
+
+--echo # GLOBAL READ LOCK works with fine with user locks
+select get_lock('test1', 0);
+flush tables with read lock;
+select get_lock('test2', 0);
+unlock tables;
+commit;
+select release_lock('test1');
+select release_lock('test2');
+
+--echo # BEGIN/COMMIT/ROLLBACK don't unlock user locks.
+begin;
+select get_lock('test1', 0);
+select get_lock('test2', 0);
+select count(*) from t1;
+rollback;
+select release_lock('test1');
+select release_lock('test2');
+
+--echo # Deadlocks between user locks and LOCK TABLES locks
+--echo # are detected OK.
+select get_lock('test', 0);
+
+--echo # -> Switching to connection 'con1'
+connection con1;
+lock table t1 write;
+send select get_lock('test', 7200);
+
+--echo # -> Switching to connection 'default'
+connection default;
+let $wait_condition= SELECT count(*) > 0 FROM information_schema.processlist WHERE info LIKE 'select%' AND state = 'User lock';
+source include/wait_condition.inc;
+--error ER_LOCK_DEADLOCK
+lock table t1 read;
+
+select release_lock('test');
+
+--echo # -> Switching to connection 'con1'
+connection con1;
+reap;
+select release_lock('test');
+unlock tables;
+
+--echo # cleanup
+disconnect con1;
+connection default;
+drop table t1;
+
+--echo # check too long identifier names
+select get_lock(repeat('a', 192), 0);
+select is_used_lock(repeat('a', 192)) = connection_id();
+select is_free_lock(repeat('a', 192));
+select release_lock(repeat('a', 192));
+--error ER_TOO_LONG_IDENT
+select get_lock(repeat('a', 193), 0);
+--error ER_TOO_LONG_IDENT
+select is_used_lock(repeat('a', 193));
+--error ER_TOO_LONG_IDENT
+select is_free_lock(repeat('a', 193));
+--error ER_TOO_LONG_IDENT
+select release_lock(repeat('a', 193));
+
+
+--echo
+--echo # --
+--echo # -- WL#5787: IPv6-capable INET_ATON and INET_NTOA functions.
+--echo # --
+
+--echo
+--echo # -- INET6_ATON: checking NULL, invalid types, out-of range values...
+--echo
+
+SELECT INET6_ATON(NULL) IS NULL;
+SELECT INET6_ATON(123) IS NULL;
+SELECT INET6_ATON(123.45) IS NULL;
+SELECT INET6_ATON(NOW()) IS NULL;
+
+SELECT INET6_ATON('1.2.3') IS NULL;
+SELECT INET6_ATON('1.2.3.') IS NULL;
+SELECT INET6_ATON('1..3.4') IS NULL;
+SELECT INET6_ATON('-1.2.3.4') IS NULL;
+SELECT INET6_ATON('1.2.3.256') IS NULL;
+SELECT INET6_ATON('1.2.3.4.5') IS NULL;
+SELECT INET6_ATON('0001.2.3.4') IS NULL;
+SELECT INET6_ATON('0x1.2.3.4') IS NULL;
+SELECT INET6_ATON('a.2.3.4') IS NULL;
+
+SELECT INET6_ATON('1.2.3.4:80') IS NULL;
+SELECT INET6_ATON('1.2.3.4/32') IS NULL;
+
+SELECT INET6_ATON('mysql.com') IS NULL;
+
+SELECT INET6_ATON(':::') IS NULL;
+SELECT INET6_ATON(':1:2:3') IS NULL;
+SELECT INET6_ATON('1:2:3:') IS NULL;
+SELECT INET6_ATON(':1::2:3') IS NULL;
+SELECT INET6_ATON('1::2:3:') IS NULL;
+SELECT INET6_ATON('::00001') IS NULL;
+SELECT INET6_ATON('::00001:2') IS NULL;
+SELECT INET6_ATON('::12345') IS NULL;
+SELECT INET6_ATON('1020::3040::5060') IS NULL;
+SELECT INET6_ATON('::ABCZ') IS NULL;
+
+SELECT INET6_ATON('::0x1.2.3.4') IS NULL;
+SELECT INET6_ATON('::1.0x2.3.4') IS NULL;
+SELECT INET6_ATON('::a.b.c.d') IS NULL;
+
+SELECT INET6_ATON('::FFFF:0x1.2.3.4') IS NULL;
+SELECT INET6_ATON('::FFFF:1.0x2.3.4') IS NULL;
+SELECT INET6_ATON('::FFFF:a.b.c.d') IS NULL;
+
+SELECT INET6_ATON('::1.2.3.4:ABCD') IS NULL;
+
+--echo # NOTE: such addresses are supported because getaddrinfo() supports them.
+--echo # This is just to record the current behaviour.
+SELECT HEX(INET6_ATON('::ABCD:1.2.3.4'));
+
+--echo
+--echo # -- INET6_ATON: checking binary representation...
+--echo
+
+SELECT HEX(INET6_ATON('0.0.0.0'));
+SELECT HEX(INET6_ATON('00.00.00.00'));
+SELECT HEX(INET6_ATON('000.000.000.000'));
+SELECT HEX(INET6_ATON('1.2.3.4'));
+SELECT HEX(INET6_ATON('01.02.03.04'));
+SELECT HEX(INET6_ATON('001.002.003.004'));
+SELECT HEX(INET6_ATON('255.255.255.255'));
+SELECT HEX(INET6_ATON('::'));
+SELECT HEX(INET6_ATON('0::0'));
+SELECT HEX(INET6_ATON('1::2'));
+SELECT HEX(INET6_ATON('0::'));
+SELECT HEX(INET6_ATON('1::'));
+SELECT HEX(INET6_ATON('::0'));
+SELECT HEX(INET6_ATON('::1'));
+SELECT HEX(INET6_ATON('1:2:3:4:5:6:7:8'));
+SELECT HEX(INET6_ATON('::2:3:4:5:6:7:8'));
+SELECT HEX(INET6_ATON('1::3:4:5:6:7:8'));
+SELECT HEX(INET6_ATON('1:2::4:5:6:7:8'));
+SELECT HEX(INET6_ATON('1:2:3::5:6:7:8'));
+SELECT HEX(INET6_ATON('1:2:3:4::6:7:8'));
+SELECT HEX(INET6_ATON('1:2:3:4:5::7:8'));
+SELECT HEX(INET6_ATON('1:2:3:4:5:6::8'));
+SELECT HEX(INET6_ATON('1:2:3:4:5:6:7::'));
+SELECT HEX(INET6_ATON('0000:0000::0000:0001'));
+SELECT HEX(INET6_ATON('1234:5678:9abc:def0:4321:8765:cba9:0fed'));
+SELECT HEX(INET6_ATON('0000:0000:0000:0000:0000:0000:0000:0001'));
+SELECT HEX(INET6_ATON('::C0A8:0102'));
+SELECT HEX(INET6_ATON('::c0a8:0102'));
+SELECT HEX(INET6_ATON('::192.168.1.2'));
+SELECT HEX(INET6_ATON('::FfFf:C0a8:0102'));
+SELECT HEX(INET6_ATON('::ffff:c0a8:0102'));
+SELECT HEX(INET6_ATON('::ffff:192.168.1.2'));
+SELECT HEX(INET6_ATON('::01.2.3.4'));
+SELECT HEX(INET6_ATON('::1.02.3.4'));
+SELECT HEX(INET6_ATON('::1.2.03.4'));
+SELECT HEX(INET6_ATON('::1.2.3.04'));
+SELECT HEX(INET6_ATON('::1.2.3.00'));
+SELECT HEX(INET6_ATON('::FFFF:01.2.3.4'));
+SELECT HEX(INET6_ATON('::FFFF:1.02.3.4'));
+SELECT HEX(INET6_ATON('::FFFF:1.2.03.4'));
+SELECT HEX(INET6_ATON('::FFFF:1.2.3.04'));
+SELECT HEX(INET6_ATON('::FFFF:1.2.3.00'));
+
+--echo
+--echo # -- INET6_ATON: checking the length is either 4 or 16...
+--echo
+
+SELECT LENGTH(INET6_ATON('0.0.0.0'));
+SELECT LENGTH(INET6_ATON('255.255.255.255'));
+SELECT LENGTH(INET6_ATON('::'));
+SELECT LENGTH(INET6_ATON('1020:3040:5060:7080:90A0:B0C0:D0E0:F010'));
+
+--echo
+--echo # -- INET6_NTOA: checking NULL, invalid types, out-of range values...
+--echo
+
+SELECT INET6_NTOA(NULL);
+SELECT INET6_NTOA(123);
+SELECT INET6_NTOA(123.456);
+SELECT INET6_NTOA(NOW());
+SELECT INET6_NTOA(UNHEX('C0A801')); # 3 bytes -> NULL
+SELECT INET6_NTOA(UNHEX('C0A80102')); # 4 bytes -> 192.168.1.2
+SELECT INET6_NTOA(UNHEX('C0A8010203')); # 5 bytes -> NULL
+SELECT INET6_NTOA(UNHEX('0102030405060708090A0B0C0D0E0F')); # 15 bytes -> NULL
+SELECT INET6_NTOA(UNHEX('0102030405060708090A0B0C0D0E0F10')); # 16 bytes -> IP
+SELECT INET6_NTOA(UNHEX('0102030405060708090A0B0C0D0E0F1011')); # 17 bytes -> NULL
+
+SELECT INET6_NTOA('1234'), INET6_NTOA(BINARY('1234'));
+SELECT INET6_NTOA('0123456789abcdef'), INET6_NTOA(BINARY('0123456789abcdef'));
+
+--echo
+--echo # -- Checking double-conversion...
+--echo
+
+SELECT INET6_NTOA(INET6_ATON('::'));
+SELECT INET6_NTOA(INET6_ATON('0::0'));
+SELECT INET6_NTOA(INET6_ATON('1::2'));
+SELECT INET6_NTOA(INET6_ATON('0::'));
+SELECT INET6_NTOA(INET6_ATON('1::'));
+SELECT INET6_NTOA(INET6_ATON('::0'));
+SELECT INET6_NTOA(INET6_ATON('::1'));
+SELECT INET6_NTOA(INET6_ATON('1:2:3:4:5:6:7:8'));
+SELECT INET6_NTOA(INET6_ATON('::2:3:4:5:6:7:8'));
+SELECT INET6_NTOA(INET6_ATON('1::3:4:5:6:7:8'));
+SELECT INET6_NTOA(INET6_ATON('1:2::4:5:6:7:8'));
+SELECT INET6_NTOA(INET6_ATON('1:2:3::5:6:7:8'));
+SELECT INET6_NTOA(INET6_ATON('1:2:3:4::6:7:8'));
+SELECT INET6_NTOA(INET6_ATON('1:2:3:4:5::7:8'));
+SELECT INET6_NTOA(INET6_ATON('1:2:3:4:5:6::8'));
+SELECT INET6_NTOA(INET6_ATON('1:2:3:4:5:6:7::'));
+SELECT INET6_NTOA(INET6_ATON('0000:0000::0000:0001'));
+SELECT INET6_NTOA(INET6_ATON('1234:5678:9abc:def0:4321:8765:cba9:0fed'));
+SELECT INET6_NTOA(INET6_ATON('0000:0000:0000:0000:0000:0000:0000:0001'));
+SELECT INET6_NTOA(INET6_ATON('::C0A8:0102'));
+SELECT INET6_NTOA(INET6_ATON('::c0a8:0102'));
+SELECT INET6_NTOA(INET6_ATON('::192.168.1.2'));
+SELECT INET6_NTOA(INET6_ATON('::FfFf:C0a8:0102'));
+SELECT INET6_NTOA(INET6_ATON('::ffff:c0a8:0102'));
+SELECT INET6_NTOA(INET6_ATON('::ffff:192.168.1.2'));
+SELECT INET6_NTOA(INET6_ATON('::01.2.3.4'));
+SELECT INET6_NTOA(INET6_ATON('::1.02.3.4'));
+SELECT INET6_NTOA(INET6_ATON('::1.2.03.4'));
+SELECT INET6_NTOA(INET6_ATON('::1.2.3.04'));
+SELECT INET6_NTOA(INET6_ATON('::1.2.3.00'));
+SELECT INET6_NTOA(INET6_ATON('::FFFF:01.2.3.4'));
+SELECT INET6_NTOA(INET6_ATON('::FFFF:1.02.3.4'));
+SELECT INET6_NTOA(INET6_ATON('::FFFF:1.2.03.4'));
+SELECT INET6_NTOA(INET6_ATON('::FFFF:1.2.3.04'));
+SELECT INET6_NTOA(INET6_ATON('::FFFF:1.2.3.00'));
+
+--echo
+--echo # -- Comparing INET_ATON() and INET6_ATON()...
+--echo
+
+SELECT HEX(INET_ATON('192.168.1.2'));
+SELECT HEX(INET6_ATON('192.168.1.2'));
+
+SELECT HEX(INET_ATON('255.255.255.255'));
+SELECT HEX(INET6_ATON('255.255.255.255'));
+
+SELECT HEX(INET_ATON('192.168.08.2'));
+SELECT HEX(INET6_ATON('192.168.08.2'));
+
+SELECT HEX(INET_ATON('192.168.0x8.2'));
+SELECT HEX(INET6_ATON('192.168.0x8.2'));
+
+SELECT HEX(INET_ATON('1.2.255'));
+SELECT HEX(INET6_ATON('1.2.255'));
+
+SELECT HEX(INET_ATON('1.2.256'));
+SELECT HEX(INET6_ATON('1.2.256'));
+
+SELECT HEX(INET_ATON('1.0002.3.4'));
+SELECT HEX(INET6_ATON('1.0002.3.4'));
+
+SELECT HEX(INET_ATON('1.2.3.4.5'));
+SELECT HEX(INET6_ATON('1.2.3.4.5'));
+
+--echo
+--echo # -- Checking mix of INET- and INET6- functions...
+--echo
+
+SELECT HEX(INET6_ATON(INET_NTOA(INET_ATON('1.2.3.4')))) AS x;
+
+--echo
+--echo # -- Checking IS_IPV4() / IS_IPV6()...
+--echo
+
+SELECT IS_IPV4(NULL);
+SELECT IS_IPV4(1);
+SELECT IS_IPV4(1.0);
+SELECT IS_IPV4('1.2.3.4');
+SELECT IS_IPV4('001.02.000.255');
+SELECT IS_IPV4('::1.2.0.255');
+SELECT IS_IPV4('::1');
+SELECT IS_IPV4(BINARY('1.2.3.4'));
+
+SELECT IS_IPV6(NULL);
+SELECT IS_IPV6(1);
+SELECT IS_IPV6(1.0);
+SELECT IS_IPV6('1.2.3.4');
+SELECT IS_IPV6('001.02.000.255');
+SELECT IS_IPV6('::001.02.000.255');
+SELECT IS_IPV6('::1.2.0.255');
+SELECT IS_IPV6('::1');
+SELECT IS_IPV6('0000:0000:0000:0000:0000:0000:0000:0001');
+SELECT IS_IPV6(BINARY('0000:0000:0000:0000:0000:0000:0000:0001'));
+
+--echo
+--echo # -- Checking IS_IPV4_MAPPED() and IS_IPV4_COMPAT()...
+--echo
+
+SELECT IS_IPV4_MAPPED(INET6_ATON('1.2.3.4')),
+ IS_IPV4_COMPAT(INET6_ATON('1.2.3.4'));
+SELECT IS_IPV4_MAPPED(INET6_ATON('::1.2.3.4')),
+ IS_IPV4_COMPAT(INET6_ATON('::1.2.3.4'));
+SELECT IS_IPV4_MAPPED(INET6_ATON('::FFFF:1.2.3.4')),
+ IS_IPV4_COMPAT(INET6_ATON('::FFFF:1.2.3.4'));
+SELECT IS_IPV4_MAPPED(INET6_ATON('::ABCD:1.2.3.4')),
+ IS_IPV4_COMPAT(INET6_ATON('::ABCD:1.2.3.4'));
+SELECT IS_IPV4_MAPPED(INET6_ATON('::1')),
+ IS_IPV4_COMPAT(INET6_ATON('::1'));
+SELECT IS_IPV4_MAPPED(INET6_ATON('::')),
+ IS_IPV4_COMPAT(INET6_ATON('::'));
+
+# NOTE: IS_IPV4_COMPAT() / IS_IPV4_MAPPED() could work with "regular strings in
+# binary collation" too, but there is no way to create a "regular string"
+# starting with \0.
+
+--echo
+--echo # -- Checking IS_IPV4_COMPAT()...
+--echo
+
+--echo
+--echo # -- Working with a table...
+--echo
+
+--disable_warnings
+DROP TABLE IF EXISTS t1;
+DROP TABLE IF EXISTS t2;
+--enable_warnings
+
+CREATE TABLE t1(ip INT UNSIGNED);
+CREATE TABLE t2(ip VARBINARY(16));
+
+--echo
+
+INSERT INTO t1 VALUES
+ (INET_ATON('1.2.3.4')), (INET_ATON('255.255.255.255'));
+SELECT INET_NTOA(ip) FROM t1;
+
+--echo
+
+INSERT INTO t2 SELECT INET6_ATON(INET_NTOA(ip)) FROM t1;
+SELECT INET6_NTOA(ip), HEX(ip), LENGTH(ip) FROM t2;
+DELETE FROM t2;
+
+--echo
+
+INSERT INTO t2 VALUES
+ (INET6_ATON('1.2.3.4')), (INET6_ATON('255.255.255.255')),
+ (INET6_ATON('::1.2.3.4')), (INET6_ATON('::ffff:255.255.255.255')),
+ (INET6_ATON('::')), (INET6_ATON('::1')),
+ (INET6_ATON('1020:3040:5060:7080:90A0:B0C0:D0E0:F010'));
+SELECT INET6_NTOA(ip), HEX(ip), LENGTH(ip) FROM t2;
+
+--echo
+
+DROP TABLE t1;
+DROP TABLE t2;
+
+--echo
+--echo # -- Done.
+--echo
+
+
+--echo #
+--echo # MDEV-13685 Can not replay binary log due to Illegal mix of collations (latin1_swedish_ci,IMPLICIT) and (utf8mb4_general_ci,COERCIBLE) for operation 'concat'
+--echo #
+SET NAMES utf8;
+SELECT COERCIBILITY(NAME_CONST('name','test'));
+SELECT COERCIBILITY(NAME_CONST('name',TIME'00:00:00'));
+SELECT COERCIBILITY(NAME_CONST('name',15));
+SELECT CONCAT(NAME_CONST('name',15),'오');
+SET NAMES latin1;
+
+--echo #
+--echo # MDEV-14116 INET6_NTOA output is set as null to varchar(39) variable
+--echo #
+
+DELIMITER $$;
+CREATE PROCEDURE p1()
+BEGIN
+ DECLARE ip_full_addr varchar(39) DEFAULT "";
+ SELECT INET6_NTOA(UNHEX('20000000000000000000000000000000')) into ip_full_addr;
+ SELECT ip_full_addr;
+END;
+$$
+DELIMITER ;$$
+CALL p1();
+DROP PROCEDURE p1;
diff --git a/mysql-test/t/func_regexp.test b/mysql-test/t/func_regexp.test
index 638e0bf08ee..d0ab0cc9044 100644
--- a/mysql-test/t/func_regexp.test
+++ b/mysql-test/t/func_regexp.test
@@ -92,3 +92,15 @@ DROP TABLE t1;
--echo End of 5.1 tests
+
+#
+# MDEV-5820 MySQL Bug #54805 definitions in regex/my_regex.h conflict with /usr/include/regex.h
+# Bug #55427 REGEXP does not recognize '\t' as [:blank:]
+#
+# Test that \t is indeed recognized as [[:blank:]]
+#
+SELECT ' ' REGEXP '[[:blank:]]';
+SELECT '\t' REGEXP '[[:blank:]]';
+
+SELECT ' ' REGEXP '[[:space:]]';
+SELECT '\t' REGEXP '[[:space:]]';
diff --git a/mysql-test/t/func_regexp_pcre.test b/mysql-test/t/func_regexp_pcre.test
new file mode 100644
index 00000000000..8f8273bcecb
--- /dev/null
+++ b/mysql-test/t/func_regexp_pcre.test
@@ -0,0 +1,451 @@
+
+SET NAMES utf8;
+
+--echo #
+--echo # MDEV-4425 REGEXP enhancements
+--echo #
+
+--echo #
+--echo # Checking RLIKE
+--echo #
+
+# Checking that à is a single character
+SELECT 'à' RLIKE '^.$';
+
+# Checking \x{FFFF} syntax and case sensitivity
+SELECT 'à' RLIKE '\\x{00E0}';
+SELECT 'À' RLIKE '\\x{00E0}';
+SELECT 'à' RLIKE '\\x{00C0}';
+SELECT 'À' RLIKE '\\x{00C0}';
+SELECT 'à' RLIKE '\\x{00E0}' COLLATE utf8_bin;
+SELECT 'À' RLIKE '\\x{00E0}' COLLATE utf8_bin;
+SELECT 'à' RLIKE '\\x{00C0}' COLLATE utf8_bin;
+SELECT 'À' RLIKE '\\x{00C0}' COLLATE utf8_bin;
+
+# Checking how (?i) and (?-i) affect case sensitivity
+CREATE TABLE t1 (s VARCHAR(10) CHARACTER SET utf8);
+INSERT INTO t1 VALUES ('a'),('A');
+CREATE TABLE t2 (p VARCHAR(10) CHARACTER SET utf8);
+INSERT INTO t2 VALUES ('a'),('(?i)a'),('(?-i)a'),('A'),('(?i)A'),('(?-i)A');
+SELECT s,p,s RLIKE p, s COLLATE utf8_bin RLIKE p FROM t1,t2 ORDER BY BINARY s, BINARY p;
+DROP TABLE t1,t2;
+
+
+# Checking Unicode character classes
+CREATE TABLE t1 (ch VARCHAR(22)) CHARACTER SET utf8;
+CREATE TABLE t2 (class VARCHAR(32)) CHARACTER SET utf8;
+INSERT INTO t1 VALUES ('Я'),('Σ'),('A'),('À');
+INSERT INTO t1 VALUES ('Ñ'),('σ'),('a'),('à');
+INSERT INTO t1 VALUES ('ã—'),('ê°·'),('ප');
+INSERT INTO t1 VALUES ('1'),('௨');
+INSERT INTO t2 VALUES ('\\p{Cyrillic}'),('\\p{Greek}'),('\\p{Latin}');
+INSERT INTO t2 VALUES ('\\p{Han}'),('\\p{Hangul}');
+INSERT INTO t2 VALUES ('\\p{Sinhala}'), ('\\p{Tamil}');
+INSERT INTO t2 VALUES ('\\p{L}'),('\\p{Ll}'),('\\p{Lu}'),('\\p{L&}');
+INSERT INTO t2 VALUES ('[[:alpha:]]'),('[[:digit:]]');
+SELECT class, ch, ch RLIKE class FROM t1, t2 ORDER BY class, BINARY ch;
+DROP TABLE t1, t2;
+
+# Checking that UCP is disabled by default for binary data
+SELECT 0xFF RLIKE '\\w';
+SELECT 0xFF RLIKE '(*UCP)\\w';
+
+# newline character
+SELECT '\n' RLIKE '(*CR)';
+SELECT '\n' RLIKE '(*LF)';
+SELECT '\n' RLIKE '(*CRLF)';
+SELECT '\n' RLIKE '(*ANYCRLF)';
+SELECT '\n' RLIKE '(*ANY)';
+
+SELECT 'a\nb' RLIKE '(*LF)(?m)^a$';
+SELECT 'a\nb' RLIKE '(*CR)(?m)^a$';
+SELECT 'a\nb' RLIKE '(*CRLF)(?m)^a$';
+SELECT 'a\nb' RLIKE '(*ANYCRLF)(?m)^a$';
+
+SELECT 'a\rb' RLIKE '(*LF)(?m)^a$';
+SELECT 'a\rb' RLIKE '(*CR)(?m)^a$';
+SELECT 'a\rb' RLIKE '(*CRLF)(?m)^a$';
+SELECT 'a\rb' RLIKE '(*ANYCRLF)(?m)^a$';
+
+SELECT 'a\r\nb' RLIKE '(*LF)(?m)^a$';
+SELECT 'a\r\nb' RLIKE '(*CR)(?m)^a$';
+SELECT 'a\r\nb' RLIKE '(*CRLF)(?m)^a$';
+SELECT 'a\r\nb' RLIKE '(*ANYCRLF)(?m)^a$';
+
+#backreference
+SELECT 'aa' RLIKE '(a)\\g1';
+SELECT 'aa bb' RLIKE '(a)\\g1 (b)\\g2';
+
+#repitition
+SELECT 'aaaaa' RLIKE 'a{0,5}';
+SELECT 'aaaaa' RLIKE 'a{1,3}';
+SELECT 'aaaaa' RLIKE 'a{0,}';
+SELECT 'aaaaa' RLIKE 'a{10,20}';
+
+#Recursion
+SELECT 'aabb' RLIKE 'a(?R)?b';
+SELECT 'aabb' RLIKE 'aa(?R)?bb';
+
+#subroutine
+#SELECT 'abbbc' RLIKE '(a(b|(?1))*c)';
+#SELECT 'abca' RLIKE '([abc])(?1){3}';
+
+#Atomic grouping
+SELECT 'abcc' RLIKE 'a(?>bc|b)c';
+SELECT 'abc' RLIKE 'a(?>bc|b)c';
+
+#lookahead - negative
+SELECT 'ab' RLIKE 'a(?!b)';
+SELECT 'ac' RLIKE 'a(?!b)';
+
+#lookahead - positive
+SELECT 'ab' RLIKE 'a(?=b)';
+SELECT 'ac' RLIKE 'a(?=b)';
+
+#lookbehind - negative
+SELECT 'ab' RLIKE '(?<!a)b';
+SELECT 'cb' RLIKE '(?<!a)b';
+
+#lookbehind - positive
+SELECT 'ab' RLIKE '(?<=a)b';
+SELECT 'cb' RLIKE '(?<=a)b';
+
+# named subpatterns
+SELECT 'aa' RLIKE '(?P<pattern>a)(?P=pattern)';
+SELECT 'aba' RLIKE '(?P<pattern>a)b(?P=pattern)';
+
+#comments
+SELECT 'a' RLIKE 'a(?#comment)';
+SELECT 'aa' RLIKE 'a(?#comment)a';
+SELECT 'aba' RLIKE 'a(?#b)a';
+
+#ungreedy maching
+#SELECT 'ddd <ab>cc</ab> eee' RLIKE '<.+?>';
+
+#Extended character classes
+SELECT 'aaa' RLIKE '\\W\\W\\W';
+SELECT '%' RLIKE '\\W';
+SELECT '%a$' RLIKE '\\W.\\W';
+
+SELECT '123' RLIKE '\\d\\d\\d';
+SELECT 'aaa' RLIKE '\\d\\d\\d';
+SELECT '1a3' RLIKE '\\d.\\d';
+SELECT 'a1b' RLIKE '\\d.\\d';
+
+SELECT '8' RLIKE '\\D';
+SELECT 'a' RLIKE '\\D';
+SELECT '%' RLIKE '\\D';
+SELECT 'a1' RLIKE '\\D\\d';
+SELECT 'a1' RLIKE '\\d\\D';
+
+SELECT '\t' RLIKE '\\s';
+SELECT '\r' RLIKE '\\s';
+SELECT '\n' RLIKE '\\s';
+SELECT '\v' RLIKE '\\s';
+
+SELECT 'a' RLIKE '\\S';
+SELECT '1' RLIKE '\\S';
+SELECT '!' RLIKE '\\S';
+SELECT '.' RLIKE '\\S';
+
+# checking 0x00 bytes
+# Bug#70470 REGEXP fails to find matches after NUL character
+SELECT 'abc\0def' REGEXP 'def';
+SELECT 'abc\0def' REGEXP 'abc\\x{00}def';
+SELECT HEX(REGEXP_SUBSTR('abc\0def','abc\\x{00}def'));
+
+
+--echo #
+--echo # Checking REGEXP_REPLACE
+--echo #
+
+# Check data type
+CREATE TABLE t1 AS SELECT REGEXP_REPLACE('abc','b','x');
+SHOW CREATE TABLE t1;
+DROP TABLE t1;
+
+# Check print()
+EXPLAIN EXTENDED SELECT REGEXP_REPLACE('abc','b','x');
+
+# Check decimals
+CREATE TABLE t1 AS SELECT REGEXP_REPLACE('abc','b','x')+0;
+SHOW CREATE TABLE t1;
+DROP TABLE t1;
+
+# Return NULL if any of the arguments are NULL
+SELECT REGEXP_REPLACE(NULL,'b','c');
+SELECT REGEXP_REPLACE('a',NULL,'c');
+SELECT REGEXP_REPLACE('a','b',NULL);
+
+# Return the original string if no match
+SELECT REGEXP_REPLACE('a','x','b');
+
+# Return the original string for an empty pattern
+SELECT REGEXP_REPLACE('a','','b');
+
+# Check that replace stops on the first empty match
+# 'a5b' matches the pattern and '5' is replaced to 'x'
+# then 'ab' matches the pattern, but the match '5*' is empty,
+# so replacing stops here.
+SELECT REGEXP_REPLACE('a5b ab a5b','(?<=a)5*(?=b)','x');
+
+# A modified version of the previous example,
+# to check that all matches are replaced if no empty match is met.
+SELECT REGEXP_REPLACE('a5b a5b a5b','(?<=a)5*(?=b)','x');
+
+
+# Check that case sensitiviry respects the collation
+SELECT REGEXP_REPLACE('A','a','b');
+SELECT REGEXP_REPLACE('a','A','b');
+SELECT REGEXP_REPLACE('A' COLLATE utf8_bin,'a','b');
+SELECT REGEXP_REPLACE('a' COLLATE utf8_bin,'A','b');
+
+# Pattern references in the "replace" string
+SELECT REGEXP_REPLACE('James Bond', '(.*) (.*)', '\\2, \\1 \\2');
+
+# Checking with UTF8
+SELECT REGEXP_REPLACE('абвгд','в','ц');
+
+# Check that it does not treat binary strings as UTF8
+SELECT REGEXP_REPLACE('г',0xB3,0xB4);
+
+# Check that it replaces all matches by default
+SELECT REGEXP_REPLACE('aaaa','a','b');
+
+# Replace all matches except the first letter
+SELECT REGEXP_REPLACE('aaaa','(?<=.)a','b');
+
+# Replace all matches except the last letter
+SELECT REGEXP_REPLACE('aaaa','a(?=.)','b');
+
+# Replace all matches except the first and the last letter
+SELECT REGEXP_REPLACE('aaaa','(?<=.)a(?=.)','b');
+
+# newline character
+SELECT REGEXP_REPLACE('a\nb','(*LF)(?m)^a$','c');
+SELECT REGEXP_REPLACE('a\nb','(*CR)(?m)^a$','c');
+SELECT REGEXP_REPLACE('a\nb','(*CRLF)(?m)^a$','c');
+SELECT REGEXP_REPLACE('a\nb','(*ANYCRLF)(?m)^a$','c');
+
+SELECT REGEXP_REPLACE('a\rb','(*LF)(?m)^a$','c');
+SELECT REGEXP_REPLACE('a\rb','(*CR)(?m)^a$','c');
+SELECT REGEXP_REPLACE('a\rb','(*CRLF)(?m)^a$','c');
+SELECT REGEXP_REPLACE('a\rb','(*ANYCRLF)(?m)^a$','c');
+
+SELECT REGEXP_REPLACE('a\r\nb','(*LF)(?m)^a$','c');
+SELECT REGEXP_REPLACE('a\r\nb','(*CR)(?m)^a$','c');
+SELECT REGEXP_REPLACE('a\r\nb','(*CRLF)(?m)^a$','c');
+SELECT REGEXP_REPLACE('a\r\nb','(*ANYCRLF)(?m)^a$','c');
+
+#backreference
+SELECT REGEXP_REPLACE('aa','(a)\\g1','b');
+SELECT REGEXP_REPLACE('aa bb','(a)\\g1 (b)\\g2','c');
+
+#repitition
+SELECT REGEXP_REPLACE('aaaaa','a{1,3}','b');
+SELECT REGEXP_REPLACE('aaaaa','a{10,20}','b');
+
+#Recursion
+SELECT REGEXP_REPLACE('daabbd','a(?R)?b','c');
+SELECT REGEXP_REPLACE('daabbd','aa(?R)?bb','c');
+
+#Atomic grouping
+SELECT REGEXP_REPLACE('dabccd','a(?>bc|b)c','e');
+SELECT REGEXP_REPLACE('dabcd','a(?>bc|b)c','e');
+
+#lookahead - negative
+SELECT REGEXP_REPLACE('ab','a(?!b)','e');
+SELECT REGEXP_REPLACE('ac','a(?!b)','e');
+
+#lookahead - positive
+SELECT REGEXP_REPLACE('ab','a(?=b)','e');
+SELECT REGEXP_REPLACE('ac','a(?=b)','e');
+
+#lookbehind - negative
+SELECT REGEXP_REPLACE('ab','(?<!a)b','e');
+SELECT REGEXP_REPLACE('cb','(?<!a)b','e');
+
+#lookbehind - positive
+SELECT REGEXP_REPLACE('ab','(?<=a)b','e');
+SELECT REGEXP_REPLACE('cb','(?<=a)b','e');
+
+# named subpatterns
+SELECT REGEXP_REPLACE('aa','(?P<pattern>a)(?P=pattern)','b');
+SELECT REGEXP_REPLACE('aba','(?P<pattern>a)b(?P=pattern)','c');
+
+#comments
+SELECT REGEXP_REPLACE('a','a(?#comment)','e');
+SELECT REGEXP_REPLACE('aa','a(?#comment)a','e');
+SELECT REGEXP_REPLACE('aba','a(?#b)a','e');
+
+#ungreedy maching
+SELECT REGEXP_REPLACE('ddd<ab>cc</ab>eee','<.+?>','*');
+
+#Extended character classes
+SELECT REGEXP_REPLACE('aaa','\\W\\W\\W','e');
+SELECT REGEXP_REPLACE('aaa','\\w\\w\\w','e');
+SELECT REGEXP_REPLACE('%','\\W','e');
+SELECT REGEXP_REPLACE('%a$','\\W.\\W','e');
+SELECT REGEXP_REPLACE('%a$','\\W\\w\\W','e');
+
+SELECT REGEXP_REPLACE('123','\\d\\d\\d\\d\\d\\d','e');
+SELECT REGEXP_REPLACE('123','\\d\\d\\d','e');
+SELECT REGEXP_REPLACE('aaa','\\d\\d\\d','e');
+SELECT REGEXP_REPLACE('1a3','\\d.\\d\\d.\\d','e');
+SELECT REGEXP_REPLACE('1a3','\\d.\\d','e');
+SELECT REGEXP_REPLACE('a1b','\\d.\\d','e');
+
+SELECT REGEXP_REPLACE('8','\\D','e');
+SELECT REGEXP_REPLACE('a','\\D','e');
+SELECT REGEXP_REPLACE('%','\\D','e');
+SELECT REGEXP_REPLACE('a1','\\D\\d','e');
+SELECT REGEXP_REPLACE('a1','\\d\\D','e');
+
+SELECT REGEXP_REPLACE('\t','\\s','e');
+SELECT REGEXP_REPLACE('\r','\\s','e');
+SELECT REGEXP_REPLACE('\n','\\s','e');
+
+SELECT REGEXP_REPLACE('a','\\S','e');
+SELECT REGEXP_REPLACE('1','\\S','e');
+SELECT REGEXP_REPLACE('!','\\S','e');
+SELECT REGEXP_REPLACE('.','\\S','e');
+
+--echo #
+--echo # Checking REGEXP_INSTR
+--echo #
+SELECT REGEXP_INSTR('abcd','X');
+SELECT REGEXP_INSTR('abcd','a');
+SELECT REGEXP_INSTR('abcd','b');
+SELECT REGEXP_INSTR('abcd','c');
+SELECT REGEXP_INSTR('abcd','d');
+SELECT REGEXP_INSTR('aaaa','(?<=a)a');
+
+SELECT REGEXP_INSTR('ваÑÑ','в');
+SELECT REGEXP_INSTR('ваÑÑ','а');
+SELECT REGEXP_INSTR('ваÑÑ','Ñ');
+SELECT REGEXP_INSTR('ваÑÑ','Ñ');
+SELECT REGEXP_INSTR(CONVERT('ваÑÑ' USING koi8r), CONVERT('в' USING koi8r));
+SELECT REGEXP_INSTR(CONVERT('ваÑÑ' USING koi8r), CONVERT('а' USING koi8r));
+SELECT REGEXP_INSTR(CONVERT('ваÑÑ' USING koi8r), CONVERT('Ñ' USING koi8r));
+SELECT REGEXP_INSTR(CONVERT('ваÑÑ' USING koi8r), CONVERT('Ñ' USING koi8r));
+
+
+--echo #
+--echo # Checking REGEXP_SUBSTR
+--echo #
+
+# Check data type
+CREATE TABLE t1 AS SELECT REGEXP_SUBSTR('abc','b');
+SHOW CREATE TABLE t1;
+DROP TABLE t1;
+
+# Check print()
+EXPLAIN EXTENDED SELECT REGEXP_SUBSTR('abc','b');
+
+# Check decimals
+CREATE TABLE t1 AS SELECT REGEXP_SUBSTR('abc','b')+0;
+SHOW CREATE TABLE t1;
+DROP TABLE t1;
+
+
+SELECT REGEXP_SUBSTR('See https://mariadb.org/en/foundation/ for details', 'https?://[^/]*');
+
+
+--echo #
+--echo # MDEV-6027 RLIKE: "." no longer matching new line
+--echo #
+SELECT 'cat and\ndog' RLIKE 'cat.*dog';
+SELECT 'cat and\r\ndog' RLIKE 'cat.*dog';
+SELECT 'a\nb' RLIKE 'a.b';
+SELECT 'a\nb' RLIKE '(?-s)a.b';
+SET default_regex_flags='DOTALL';
+SELECT @@default_regex_flags;
+SELECT 'cat and\ndog' RLIKE 'cat.*dog';
+SELECT 'cat and\r\ndog' RLIKE 'cat.*dog';
+SELECT 'a\nb' RLIKE 'a.b';
+SELECT 'a\nb' RLIKE '(?-s)a.b';
+SET default_regex_flags=DEFAULT;
+
+--error ER_REGEXP_ERROR
+SELECT REGEXP_SUBSTR('Monday Mon','^((?<DN>Mon|Fri|Sun)day|(?<DN>Tue)sday).*(?P=DN)$');
+SET default_regex_flags='DUPNAMES';
+SELECT REGEXP_SUBSTR('Monday Mon','^((?<DN>Mon|Fri|Sun)day|(?<DN>Tue)sday).*(?P=DN)$');
+SELECT REGEXP_SUBSTR('Tuesday Tue','^((?<DN>Mon|Fri|Sun)day|(?<DN>Tue)sday).*(?P=DN)$');
+SET default_regex_flags=DEFAULT;
+
+SELECT 'AB' RLIKE 'A B';
+SELECT 'AB' RLIKE 'A# this is a comment\nB';
+SET default_regex_flags='EXTENDED';
+SELECT 'AB' RLIKE 'A B';
+SELECT 'AB' RLIKE 'A# this is a comment\nB';
+SET default_regex_flags=DEFAULT;
+
+SELECT 'Aq' RLIKE 'A\\q';
+SET default_regex_flags='EXTRA';
+--error ER_REGEXP_ERROR
+SELECT 'Aq' RLIKE 'A\\q';
+SET default_regex_flags=DEFAULT;
+
+SELECT 'a\nb\nc' RLIKE '^b$';
+SET default_regex_flags='MULTILINE';
+SELECT 'a\nb\nc' RLIKE '^b$';
+SET default_regex_flags=DEFAULT;
+
+SELECT REGEXP_SUBSTR('abc','.+');
+SELECT REGEXP_REPLACE('abc','^(.*)(.*)$','\\1/\\2');
+SET default_regex_flags='UNGREEDY';
+SELECT REGEXP_SUBSTR('abc','.+');
+SELECT REGEXP_REPLACE('abc','^(.*)(.*)$','\\1/\\2');
+SET default_regex_flags=DEFAULT;
+
+--echo #
+--echo # MDEV-6965 non-captured group \2 in regexp_replace
+--echo #
+SELECT REGEXP_REPLACE('1 foo and bar', '(\\d+) foo and (\\d+ )?bar', '\\1 this and \\2that');
+
+--echo #
+--echo # MDEV-8102 REGEXP function fails to match hex values when expression is stored as a variable
+--echo #
+
+--echo # Testing a warning
+SET NAMES latin1;
+SET @regCheck= '\\xE0\\x01';
+SELECT 0xE001 REGEXP @regCheck;
+
+--echo # Testing workaround N1: This makes the pattern to be a binary string:
+SET NAMES latin1;
+SET @regCheck= X'E001';
+SELECT 0xE001 REGEXP @regCheck;
+
+--echo # Testing workaround N2: This also makes the pattern to be a binary string, using a different syntax:
+SET NAMES latin1;
+SET @regCheck= _binary '\\xE0\\x01';
+SELECT 0xE001 REGEXP @regCheck;
+
+--echo # Testing workarond N3: This makes derivation of the subject string stronger (IMLICIT instead of COERCIBLE)
+SET NAMES latin1;
+SET @regCheck= '\\xE0\\x01';
+SELECT CAST(0xE001 AS BINARY) REGEXP @regCheck;
+
+--echo # MDEV-12420: Testing recursion overflow
+--replace_regex /[0-9]+ exceeded/NUM exceeded/
+SELECT 1 FROM dual WHERE ('Alpha,Bravo,Charlie,Delta,Echo,Foxtrot,StrataCentral,Golf,Hotel,India,Juliet,Kilo,Lima,Mike,StrataL3,November,Oscar,StrataL2,Sand,P3,P4SwitchTest,Arsys,Poppa,ExtensionMgr,Arp,Quebec,Romeo,StrataApiV2,PtReyes,Sierra,SandAcl,Arrow,Artools,BridgeTest,Tango,SandT,PAlaska,Namespace,Agent,Qos,PatchPanel,ProjectReport,Ark,Gimp,Agent,SliceAgent,Arnet,Bgp,Ale,Tommy,Central,AsicPktTestLib,Hsc,SandL3,Abuild,Pca9555,Standby,ControllerDut,CalSys,SandLib,Sb820,PointV2,BfnLib,Evpn,BfnSdk,Sflow,ManagementActive,AutoTest,GatedTest,Bgp,Sand,xinetd,BfnAgentLib,bf-utils,Hello,BfnState,Eos,Artest,Qos,Scd,ThermoMgr,Uniform,EosUtils,Eb,FanController,Central,BfnL3,BfnL2,tcp_wrappers,Victor,Environment,Route,Failover,Whiskey,Xray,Gimp,BfnFixed,Strata,SoCal,XApi,Msrp,XpProfile,tcpdump,PatchPanel,ArosTest,FhTest,Arbus,XpAcl,MacConc,XpApi,telnet,QosTest,Alpha2,BfnVlan,Stp,VxlanControllerTest,MplsAgent,Bravo2,Lanz,BfnMbb,Intf,XCtrl,Unicast,SandTunnel,L3Unicast,Ipsec,MplsTest,Rsvp,EthIntf,StageMgr,Sol,MplsUtils,Nat,Ira,P4NamespaceDut,Counters,Charlie2,Aqlc,Mlag,Power,OpenFlow,Lag,RestApi,BfdTest,strongs,Sfa,CEosUtils,Adt746,MaintenanceMode,MlagDut,EosImage,IpEth,MultiProtocol,Launcher,Max3179,Snmp,Acl,IpEthTest,PhyEee,bf-syslibs,tacc,XpL2,p4-ar-switch,p4-bf-switch,LdpTest,BfnPhy,Mirroring,Phy6,Ptp' REGEXP '^((?!\b(Strata|StrataApi|StrataApiV2)\b).)*$');
+
+#
+# MDEV-13173 An RLIKE that previously worked on 10.0 now returns "Got error 'pcre_exec: recursion limit of 100 exceeded' from regexp"
+#
+SELECT CONCAT(REPEAT('100,',190),'101') RLIKE '^(([1-9][0-9]*),)*[1-9][0-9]*$';
+--replace_regex /[0-9]+ exceeded/NUM exceeded/
+SELECT CONCAT(REPEAT('100,',600),'101') RLIKE '^(([1-9][0-9]*),)*[1-9][0-9]*$';
+
+SELECT REGEXP_INSTR(CONCAT(REPEAT('100,',190),'101'), '^(([1-9][0-9]*),)*[1-9][0-9]*$');
+--replace_regex /[0-9]+ exceeded/NUM exceeded/
+SELECT REGEXP_INSTR(CONCAT(REPEAT('100,',600),'101'), '^(([1-9][0-9]*),)*[1-9][0-9]*$');
+
+SELECT LENGTH(REGEXP_SUBSTR(CONCAT(REPEAT('100,',190/3),'101'), '^(([1-9][0-9]*),)*[1-9][0-9]*$'));
+--replace_regex /[0-9]+ exceeded/NUM exceeded/
+SELECT LENGTH(REGEXP_SUBSTR(CONCAT(REPEAT('100,',600/3),'101'), '^(([1-9][0-9]*),)*[1-9][0-9]*$'));
+
+SELECT LENGTH(REGEXP_REPLACE(CONCAT(REPEAT('100,',190/3),'101'), '^(([1-9][0-9]*),)*[1-9][0-9]*$', ''));
+--replace_regex /[0-9]+ exceeded/NUM exceeded/
+SELECT LENGTH(REGEXP_REPLACE(CONCAT(REPEAT('100,',600/3),'101'), '^(([1-9][0-9]*),)*[1-9][0-9]*$', ''));
diff --git a/mysql-test/t/func_regexp_pcre_debug.test b/mysql-test/t/func_regexp_pcre_debug.test
new file mode 100644
index 00000000000..c2581fa4110
--- /dev/null
+++ b/mysql-test/t/func_regexp_pcre_debug.test
@@ -0,0 +1,6 @@
+--source include/have_debug.inc
+
+SET debug_dbug='+d,pcre_exec_error_123';
+SELECT 'a' RLIKE 'a';
+SET debug_dbug='';
+SELECT 'a' RLIKE 'a';
diff --git a/mysql-test/t/func_str.test b/mysql-test/t/func_str.test
index 3c3de4240ab..019d17518dd 100644
--- a/mysql-test/t/func_str.test
+++ b/mysql-test/t/func_str.test
@@ -1407,6 +1407,18 @@ insert into t1 values (null),(8);
select group_concat( i ), make_set( i, 'a', 'b' ) field from t1 group by field;
drop table t1;
+--echo #
+--echo # Bug#11766684 59851: UNINITIALISED VALUE IN ITEM_FUNC_LIKE::SELECT_OPTIMIZE WITH SUBQUERY AND
+--echo #
+
+CREATE TABLE t2(a INT, KEY(a));
+INSERT INTO t2 VALUES (1),(2);
+CREATE TABLE t1(b INT, PRIMARY KEY(b));
+INSERT INTO t1 VALUES (0),(254);
+SELECT 1 FROM t2 WHERE a LIKE
+(SELECT EXPORT_SET(1, b, b, b, b) FROM t1 LIMIT 1);
+DROP TABLE t1, t2;
+
--echo End of 5.1 tests
--echo #
@@ -1592,3 +1604,189 @@ select md5(_filename "a"), sha(_filename "a");
--echo # End of 5.5 tests
--echo #
+
+--echo #
+--echo # Start of 5.6 tests
+--echo #
+
+--echo #
+--echo # WL#5510 Functions to_base64 and from_base64
+--echo #
+let $1=64;
+while($1)
+{
+ dec $1;
+ eval CREATE TABLE t1 AS SELECT TO_BASE64(REPEAT('a',$1)) AS to_base64;
+ SHOW CREATE TABLE t1;
+ SELECT to_base64, LENGTH(to_base64) FROM t1;
+ CREATE TABLE t2 AS SELECT from_base64(to_base64) AS from_base64 FROM t1;
+ SHOW CREATE TABLE t2;
+ SELECT from_base64, LENGTH(from_base64) FROM t2;
+ DROP TABLE t2;
+ DROP TABLE t1;
+ --echo
+}
+CREATE TABLE t1 (a VARBINARY(64));
+INSERT INTO t1 VALUES (0x00), (0x0000), (0x000000), (0x00000000);
+INSERT INTO t1 VALUES (0x00010203040506070809);
+SELECT TO_BASE64(a), hex(a) FROM t1 ORDER BY a;
+DROP TABLE t1;
+
+--echo #
+--echo # Test NULL output for NULL input
+--echo #
+SELECT TO_BASE64(NULL);
+SELECT FROM_BASE64(NULL);
+
+--echo #
+--echo # RFC4648 test vectors
+--echo #
+SELECT @b:= TO_BASE64(''), FROM_BASE64(@b); # ""
+SELECT @b:= TO_BASE64('f'), FROM_BASE64(@b); # "Zg=="
+SELECT @b:= TO_BASE64('fo'), FROM_BASE64(@b); # "Zm8="
+SELECT @b:= TO_BASE64('foo'), FROM_BASE64(@b); # "Zm9v"
+SELECT @b:= TO_BASE64('foob'), FROM_BASE64(@b); # "Zm9vYg=="
+SELECT @b:= TO_BASE64('fooba'), FROM_BASE64(@b); # "Zm9vYmE="
+SELECT @b:= TO_BASE64('foobar'), FROM_BASE64(@b); # "Zm9vYmFy"
+
+
+--echo #
+--echo # Invalid characters - return NULL
+--echo #
+SELECT hex(FROM_BASE64('#'));
+SELECT hex(FROM_BASE64('A#'));
+SELECT hex(FROM_BASE64('AB#'));
+SELECT hex(FROM_BASE64('ABC#'));
+SELECT hex(FROM_BASE64('ABCD#'));
+
+--echo #
+--echo # "=" is not valid on the first and second positions of a quadruple
+--echo #
+SELECT hex(FROM_BASE64('='));
+SELECT hex(FROM_BASE64('A='));
+SELECT hex(FROM_BASE64('ABCD='));
+SELECT hex(FROM_BASE64('ABCDE='));
+
+--echo #
+--echo # Incomplete sequences - return NULL
+--echo #
+SELECT hex(FROM_BASE64('A'));
+SELECT hex(FROM_BASE64('AB'));
+SELECT hex(FROM_BASE64('ABC'));
+
+--echo #
+--echo # Unexpected input after pad characters - return NULL
+--echo #
+SELECT hex(FROM_BASE64('AAA=x'));
+SELECT hex(FROM_BASE64('AA==x'));
+
+
+--echo #
+--echo # Delimiters are allowed at any position
+--echo #
+SELECT hex(FROM_BASE64(' A B C D '));
+SELECT hex(FROM_BASE64(' A A = = '));
+SELECT hex(FROM_BASE64(' A A A = '));
+SELECT hex(FROM_BASE64(' A \n B \r C \t D '));
+
+--echo #
+--echo # Testing that to_base64 respects max_allowed_packet
+--echo #
+SELECT LENGTH(TO_BASE64(REPEAT('a', @@max_allowed_packet-10)));
+
+--echo #
+--echo # Testing base64 with various data types
+--echo #
+CREATE TABLE t1 (
+ i1 INT,
+ f1 FLOAT,
+ dc1 DECIMAL(10,5),
+ e1 ENUM('enum11','enum12','enum13'),
+ s1 SET('set1','set2','set3'),
+ t1 TIME,
+ d1 DATE,
+ dt1 DATETIME
+);
+INSERT INTO t1 VALUES
+(-12345, -456.789, 123.45, 'enum13', 'set1,set3',
+'01:02:03', '2010-01-01', '2011-01-01 02:03:04');
+SELECT FROM_BASE64(TO_BASE64(i1)) FROM t1;
+SELECT FROM_BASE64(TO_BASE64(f1)) FROM t1;
+SELECT FROM_BASE64(TO_BASE64(dc1)) FROM t1;
+SELECT FROM_BASE64(TO_BASE64(e1)) FROM t1;
+SELECT FROM_BASE64(TO_BASE64(s1)) FROM t1;
+SELECT FROM_BASE64(TO_BASE64(t1)) FROM t1;
+SELECT FROM_BASE64(TO_BASE64(d1)) FROM t1;
+SELECT FROM_BASE64(TO_BASE64(dt1)) FROM t1;
+DROP TABLE t1;
+
+
+#
+# BUG #12735829: SPACE() FUNCTION WARNING REFERS TO REPEAT() IN ER_WARN_ALLOWED_PACKET_OVERFLOWED
+#
+
+SELECT SPACE(@@global.max_allowed_packet*2);
+
+
+#
+# BUG #11746123-23637: CHARSET AND COLLATION OF THE FUNCTION SPACE()
+#
+
+SET NAMES latin1;
+PREPARE stmt FROM "SELECT COLLATION(space(2))";
+EXECUTE stmt;
+SET NAMES latin2;
+EXECUTE stmt;
+
+
+--echo #
+--echo # End of 5.6 tests
+--echo #
+
+--echo #
+--echo # Start of 10.0 tests
+--echo #
+
+--echo #
+--echo # MDEV-12681 Wrong VIEW results for CHAR(0xDF USING latin1)
+--echo #
+
+EXPLAIN EXTENDED SELECT CHAR(0xDF USING latin1);
+EXPLAIN EXTENDED SELECT CHAR(0xDF USING `binary`);
+EXPLAIN EXTENDED SELECT CHAR(0xDF);
+
+
+--echo #
+--echo # MDEV-15619 using CONVERT() inside AES_ENCRYPT() in an UPDATE corrupts data
+--echo #
+
+CREATE TABLE t1 (
+ id int(11) NOT NULL,
+ session_id varchar(255) DEFAULT NULL,
+ directory mediumtext,
+ checksum int(10) DEFAULT NULL,
+ last_update datetime DEFAULT NULL,
+ PRIMARY KEY (id),
+ KEY lastupdate (last_update)
+) DEFAULT CHARSET=latin1;
+INSERT INTO t1 VALUES (1,'',NULL,38391,'2017-06-24 07:35:28');
+UPDATE t1 SET directory = AES_ENCRYPT(CONVERT('test stringrererejrjerjehrjekhrjkehrjkehrkjehrjkerhkjehrjekrhkjehrkjerhjkehrkjehrkjehrjkehrjkehrjkehrjkerjkehrjkehrjkehrjke rekjhrejrejhrjehgrehjgrhjerjhegrjherejhgrjhegrjehgrjhegrejhrgjehgrjhegrjhegrjhergjhegrjhegrhjegrjerhthkjjkdhjkgdfjkgjkdgdjkfjkhgjkfdhjgjkfdghkjdfghkjfdghfjkdghkdjfghdkjfghfjkdghfkjdghkjfdghfkjdghfkdjghfkjdghfdjkghjkdfhgdfjkghfjkdghfjkdghfjdkghfjkdghkfjdghfkjdghfkjdghkjdfghfjdkghjkfdghkjdfhgjkdfhgjkfdhgkjfdghkfjdhgkjfdgdjkejktjherjthkjrethkjrethjkerthjkerhtjkerhtkjerhtjkerhtjkerhtjkrehtkjerhtkjrehtjkrehtkjrehtkjerhtkjerhtjkrehtkjrehtjkrehtkjrethjkrethkjrehtkjethjkerhtjkrehtjkretkjerhtkjrehtjkerhtjkrehtjrehtkjrekjtrfgdsfgdhjsghjgfdhjsfhjdfgdhjshjdshjfghjdsfgjhsfgjhsdfgjhdsfgjdhsfgsjhfgjhsdfgsdjhfgjdhsfdjshfgdsjhfgjsdhfdjshfgdjhsfgdjshfgjdhsfgjhsdfgjhsdgfjhsdgfjhdsgfjhsgfjhsdgfjhdsgfhjsdehkjthrkjethjkre' USING latin1), '95F5A1F52A554'), last_update= NOW();
+SELECT directory IS NULL FROM t1;
+DROP TABLE t1;
+
+CREATE TABLE t1 (
+ id int(11) NOT NULL PRIMARY KEY,
+ directory mediumtext
+) DEFAULT CHARSET=latin1;
+INSERT INTO t1 VALUES (1,AES_ENCRYPT(CONVERT(REPEAT('a',800) USING latin1),'95F5A1F52A554'));
+SELECT AES_DECRYPT(directory,'95F5A1F52A554') FROM t1;
+DROP TABLE t1;
+
+SET @enc=AES_ENCRYPT(REPEAT(_latin1'a',800),'95F5A1F52A554');
+CREATE TABLE t1 (
+ id int(11) NOT NULL PRIMARY KEY,
+ directory mediumtext
+) DEFAULT CHARSET=latin1;
+INSERT INTO t1 VALUES (1,AES_DECRYPT(CONVERT(@enc USING binary),'95F5A1F52A554'));
+SELECT * FROM t1;
+DROP TABLE t1;
diff --git a/mysql-test/t/func_system.test b/mysql-test/t/func_system.test
index a5041a83623..fa09e81a300 100644
--- a/mysql-test/t/func_system.test
+++ b/mysql-test/t/func_system.test
@@ -13,9 +13,9 @@ select user() like _utf8"%@%";
select user() like _latin1"%@%";
select charset(user());
-select version()>="3.23.29";
-select version()>=_utf8"3.23.29";
-select version()>=_latin1"3.23.29";
+select version()>="03.23.29";
+select version()>=_utf8"03.23.29";
+select version()>=_latin1"03.23.29";
select charset(version());
explain extended select database(), user();
diff --git a/mysql-test/t/func_test.test b/mysql-test/t/func_test.test
index 6a99b975e81..d3703de26c5 100644
--- a/mysql-test/t/func_test.test
+++ b/mysql-test/t/func_test.test
@@ -180,3 +180,17 @@ select * from t1 where not (a+0);
explain extended select * from t1 where not (a+0);
drop table t1;
+
+--echo #
+--echo # Start of 10.0 tests
+--echo #
+
+--echo #
+--echo # MDEV-7001 Bad result for NOT NOT STRCMP('a','b') and NOT NOT NULLIF(2,3)
+--echo #
+SELECT NOT NOT strcmp('a','b');
+EXPLAIN EXTENDED SELECT NOT NOT strcmp('a','b');
+
+--echo #
+--echo # End of 10.0 tests
+--echo #
diff --git a/mysql-test/t/func_time.test b/mysql-test/t/func_time.test
index 8323bd30d2c..1baded9fef7 100644
--- a/mysql-test/t/func_time.test
+++ b/mysql-test/t/func_time.test
@@ -526,7 +526,7 @@ SELECT MAKETIME(0, 0, 4294967296);
SELECT MAKETIME(CAST(-1 AS UNSIGNED), 0, 0);
# check if EXTRACT() handles out-of-range values correctly
-SELECT EXTRACT(HOUR FROM '100000:02:03');
+SELECT EXTRACT(HOUR FROM '10000:02:03');
# check if we get proper warnings if both input string truncation
# and out-of-range value occur
@@ -883,7 +883,9 @@ SELECT STR_TO_DATE(SPACE(2),'1');
--echo #
SET GLOBAL SQL_MODE='';
+--disable_warnings
DO STR_TO_DATE((''), FROM_DAYS(@@GLOBAL.SQL_MODE));
+--enable_warnings
SET GLOBAL SQL_MODE=DEFAULT;
--echo #
@@ -1119,7 +1121,9 @@ drop table t1;
#
# lp:731815 Crash/valgrind warning Item::send with 5.1-micro
#
+SET timestamp=unix_timestamp('2001-02-03 10:20:30');
select convert_tz(timediff('0000-00-00 00:00:00', cast('2008-03-26 07:09:06' as datetime)), 'UTC', 'Europe/Moscow');
+SET timestamp=DEFAULT;
#
# lp:736370 Datetime functions in subquery context cause wrong result and bogus warnings in mysql-5.1-micr
@@ -1140,7 +1144,11 @@ drop table t1;
#
# lp:737092 Assertion `item->null_value' failed in get_datetime_value in 5.1-micro
#
+SET timestamp=UNIX_TIMESTAMP('2014-04-14 10:10:10');
select now() > coalesce(time('21:43:24'), date('2010-05-03'));
+SET timestamp=UNIX_TIMESTAMP('2014-04-14 22:22:22');
+select now() > coalesce(time('21:43:24'), date('2010-05-03'));
+SET timestamp=DEFAULT;
#
# lp:737104 Crash in DTCollation::set in 5.1-micro
@@ -1184,9 +1192,12 @@ insert into t1 values ('0000-00-00 00:00:00');
select cast(f1 AS time) from t1;
drop table t1;
+SET timestamp=UNIX_TIMESTAMP('2014-06-01 10:20:30');
select greatest(cast("0-0-0" as date), cast("10:20:05" as time));
select greatest(cast("0-0-0" as date), cast("10:20:05" as time)) = '0000-00-00';
+select greatest(cast("0-0-0" as date), cast("10:20:05" as time)) = '2014-06-01';
select cast(greatest(cast("0-0-0" as date), cast("10:20:05" as time)) as datetime(6));
+SET timestamp=DEFAULT;
select microsecond('12:00:00.123456'), microsecond('2009-12-31 23:59:59.000010');
@@ -1388,6 +1399,7 @@ DROP TABLE t1;
--echo #
--echo # MDEV-4870 Wrong values of CASE, COALESCE, IFNULL on a combination of different temporal types
--echo #
+SET timestamp=UNIX_TIMESTAMP('2001-01-01 10:20:30');
CREATE TABLE t1 (dt2 DATETIME(2), t3 TIME(3), d DATE);
INSERT INTO t1 VALUES ('2001-01-01 00:00:00.12', '00:00:00.567', '2002-01-01');
SELECT CASE WHEN 0 THEN dt2 ELSE t3 END FROM t1;
@@ -1407,7 +1419,7 @@ SELECT CONCAT(COALESCE(dt2, t3)) FROM t1;
SELECT IFNULL(dt2, t3), CONCAT(IFNULL(dt2, t3)) FROM t1;
SELECT IFNULL(d, t3), CONCAT(IFNULL(d, t3)) FROM t1;
DROP TABLE t1;
-
+SET timestamp=DEFAULT;
--echo #
--echo # MDEV-4724 Some temporal functions do not preserve microseconds
@@ -1521,12 +1533,14 @@ SHOW COLUMNS FROM t1;
SELECT * FROM t1;
DROP TABLE t1;
+SET timestamp=unix_timestamp('2001-02-03 10:20:30');
CREATE TABLE t1 AS SELECT
TIMESTAMP('00:00:00','10:10:10'),
TIMESTAMP(TIME('00:00:00'),'10:10:10');
SHOW COLUMNS FROM t1;
SELECT * FROM t1;
DROP TABLE t1;
+SET timestamp=DEFAULT;
--echo #
--echo # MDEV-4869 Wrong result of MAKETIME(0, 0, -0.1)
@@ -1536,6 +1550,7 @@ SELECT MAKETIME(0, 0, -0.1);
--echo #
--echo # MDEV-4857 Wrong result of HOUR('1 00:00:00')
--echo #
+SET timestamp=unix_timestamp('2001-02-03 10:20:30');
SELECT HOUR('1 02:00:00'), HOUR('26:00:00');
SELECT HOUR(TIME'1 02:00:00'), HOUR(TIME'26:00:00');
SELECT HOUR(TIME('1 02:00:00')), HOUR(TIME('26:00:00'));
@@ -1545,6 +1560,7 @@ SELECT EXTRACT(HOUR FROM '1 02:00:00'), EXTRACT(HOUR FROM '26:00:00');
SELECT EXTRACT(HOUR FROM TIME'1 02:00:00'), EXTRACT(HOUR FROM TIME'26:00:00');
SELECT EXTRACT(HOUR FROM TIME('1 02:00:00')), EXTRACT(HOUR FROM TIME('26:00:00'));
SELECT EXTRACT(DAY FROM TIME('1 02:00:00')), EXTRACT(DAY FROM TIME('26:00:00'));
+SET timestamp=DEFAULT;
--echo #
--echo # MDEV-5458 RQG hits 'sql/tztime.cc:799: my_time_t sec_since_epoch(int, int, int, int, int, int): Assertion `mon > 0 && mon < 13' failed.'
@@ -1557,7 +1573,6 @@ SELECT GREATEST(t, CURRENT_DATE()) FROM t1;
DROP TABLE t1;
SET TIMESTAMP=DEFAULT;
-
--echo #
--echo # MDEV-5504 Server crashes in String::length on SELECT with MONTHNAME, GROUP BY, ROLLUP
--echo #
@@ -1571,6 +1586,61 @@ DROP TABLE t1;
--echo #
SELECT DATE_ADD('2001-01-01 10:20:30',INTERVAL 250000000000.0 SECOND) AS c1, DATE_ADD('2001-01-01 10:20:30',INTERVAL 2000000000000000000.0 SECOND) AS c2;
+--echo #
+--echo # MDEV-4838 Wrong metadata for DATE_ADD('string', INVERVAL)
+--echo #
+--enable_metadata
+SELECT DATE_ADD('2011-01-02 12:13:14', INTERVAL 1 MINUTE);
+--disable_metadata
+
+--echo #
+--echo # MDEV-5450 Assertion `cached_field_ type == MYSQL_TYPE_STRING || ltime.time_type == MYSQL_TIMESTAMP_NONE || mysql_type_to_time_type(cached_field_type) == ltime.time_type' fails with IF, ISNULL, ADDDATE
+--echo #
+
+CREATE TABLE t1 (a DATETIME, b DATE);
+INSERT INTO t1 VALUES (NULL, '2012-12-21');
+SELECT IF(1,ADDDATE(IFNULL(a,b),0),1) FROM t1;
+SELECT CAST(ADDDATE(IFNULL(a,b),0) AS CHAR) FROM t1;
+SELECT CAST(ADDDATE(COALESCE(a,b),0) AS CHAR) FROM t1;
+SELECT CAST(ADDDATE(CASE WHEN 0 THEN a ELSE b END,0) AS CHAR) FROM t1;
+SELECT IF(1,ADDTIME(IFNULL(a,b),0),1) FROM t1;
+SELECT CAST(ADDTIME(IFNULL(a,b),0) AS CHAR) FROM t1;
+SELECT CAST(ADDTIME(COALESCE(a,b),0) AS CHAR) FROM t1;
+SELECT CAST(ADDTIME(CASE WHEN 0 THEN a ELSE b END,0) AS CHAR) FROM t1;
+DROP TABLE t1;
+
+SET timestamp=unix_timestamp('2001-02-03 10:20:30');
+CREATE TABLE t1 (a DATETIME, b TIME);
+INSERT INTO t1 VALUES (NULL, '00:20:12');
+SELECT IF(1,ADDDATE(IFNULL(a,b),0),1) FROM t1;
+SELECT CAST(ADDDATE(IFNULL(a,b),0) AS CHAR) FROM t1;
+SELECT CAST(ADDDATE(COALESCE(a,b),0) AS CHAR) FROM t1;
+SELECT CAST(ADDDATE(CASE WHEN 0 THEN a ELSE b END,0) AS CHAR) FROM t1;
+SELECT IF(1,ADDTIME(IFNULL(a,b),0),1) FROM t1;
+SELECT CAST(ADDTIME(IFNULL(a,b),0) AS CHAR) FROM t1;
+SELECT CAST(ADDTIME(COALESCE(a,b),0) AS CHAR) FROM t1;
+SELECT CAST(ADDTIME(CASE WHEN 0 THEN a ELSE b END,0) AS CHAR) FROM t1;
+DROP TABLE t1;
+SET timestamp=DEFAULT;
+
+
+--echo #
+--echo # MDEV-5870 Assertion `ltime->neg == 0' fails with COALESCE, ADDDATE, MAKEDATE
+--echo #
+CREATE TABLE t1 (dt DATETIME);
+INSERT INTO t1 VALUES ('2003-05-13 19:36:05'), ('2012-12-12 09:20:06');
+SELECT COALESCE(ADDDATE(MAKEDATE(2011,121), dt), '2006-09-12' ) FROM t1;
+DROP TABLE t1;
+
+--echo #
+--echo # MDEV-6101 Hybrid functions do not add CURRENT_DATE when converting TIME to DATETIME
+--echo #
+SET timestamp=UNIX_TIMESTAMP('2014-04-15 01:02:03');
+SELECT IF(1,TIME'10:20:30',DATE'2001-01-01');
+SELECT IFNULL(TIME'10:20:30',DATE'2001-01-01');
+SELECT CASE WHEN 1 THEN TIME'10:20:30' ELSE DATE'2001-01-01' END;
+SELECT COALESCE(TIME'10:20:30',DATE'2001-01-01');
+SET timestamp=DEFAULT;
--echo #
--echo # MDEV-5750 Assertion `ltime->year == 0' fails on a query with EXTRACT DAY_MINUTE and TIME column
@@ -1603,7 +1673,6 @@ DROP TABLE t1;
--echo #
SELECT 1 MOD ADDTIME( '13:58:57', '00:00:01' ) + 2;
-
--echo #
--echo # MDEV-11819 NO_ZERO_IN_DATE: Incorrect generated column value
--echo #
@@ -1626,10 +1695,86 @@ DO TO_DAYS(SEC_TO_TIME(TIME(CEILING(UUID()))));
--enable_warnings
DO TO_DAYS(SEC_TO_TIME(MAKEDATE('',RAND(~('')))));
-SELECT TO_DAYS(SEC_TO_TIME(MAKEDATE(0,RAND(~0))));
SELECT SEC_TO_TIME(MAKEDATE(0,RAND(~0)));
--echo #
--echo # End of 5.5 tests
--echo #
+
+--echo #
+--echo # MDEV-8205 timediff returns null when comparing decimal time to time string value
+--echo #
+
+# 1h difference
+SELECT
+ TIMEDIFF('2014-01-01 00:00:00' , '2014-01-01 01:00:00' ) AS str_str,
+ TIMEDIFF('2014-01-01 00:00:00' , 20140101010000.000 ) AS str_dec,
+ TIMEDIFF(20140101000000.000 , 20140101010000.000 ) AS dec_dec,
+ TIMEDIFF(20140101000000.000 , '2014-01-01 01:00:00' ) AS dec_str;
+
+# 1D1h difference
+SELECT
+ TIMEDIFF('2014-01-01 00:00:00' , '2014-01-02 01:00:00' ) AS str_str,
+ TIMEDIFF('2014-01-01 00:00:00' , 20140102010000.000 ) AS str_dec,
+ TIMEDIFF(20140101000000.000 , 20140102010000.000 ) AS dec_dec,
+ TIMEDIFF(20140101000000.000 , '2014-01-02 01:00:00' ) AS dec_str;
+
+# 1M1D1h difference
+SELECT
+ TIMEDIFF('2014-01-01 00:00:00' , '2014-02-02 01:00:00' ) AS str_str,
+ TIMEDIFF('2014-01-01 00:00:00' , 20140202010000.000 ) AS str_dec,
+ TIMEDIFF(20140101000000.000 , 20140202010000.000 ) AS dec_dec,
+ TIMEDIFF(20140101000000.000 , '2014-02-02 01:00:00' ) AS dec_str;
+
+# 2M1D1h difference
+SELECT
+ TIMEDIFF('2014-01-01 00:00:00' , '2014-03-02 01:00:00' ) AS str_str,
+ TIMEDIFF('2014-01-01 00:00:00' , 20140302010000.000 ) AS str_dec,
+ TIMEDIFF(20140101000000.000 , 20140302010000.000 ) AS dec_dec,
+ TIMEDIFF(20140101000000.000 , '2014-03-02 01:00:00' ) AS dec_str;
+
+
+--echo #
+--echo # MDEV-10787 Assertion `ltime->neg == 0' failed in void date_to_datetime(MYSQL_TIME*)
+--echo #
+CREATE TABLE t1 (d DATE);
+INSERT INTO t1 VALUES ('2005-07-20'),('2012-12-21');
+SELECT REPLACE( ADDDATE( d, INTERVAL 0.6732771076944444 HOUR_SECOND ), '2', 'x' ) FROM t1;
+SELECT REPLACE( ADDDATE( d, INTERVAL '0.6732771076944444' HOUR_SECOND ), '2', 'x' ) FROM t1;
+SELECT CAST(ADDDATE( d, INTERVAL 6732771076944444 SECOND) AS CHAR) FROM t1;
+SELECT CAST(ADDDATE( d, INTERVAL '67327710769444:44' HOUR_SECOND) AS CHAR) FROM t1;
+SELECT CAST(ADDDATE( d, INTERVAL '673277107694:44:44' HOUR_SECOND) AS CHAR) FROM t1;
+DROP TABLE t1;
+
+# Maximum possible DAY_SECOND values in various formats
+SELECT ADDDATE(DATE'0000-01-01', INTERVAL '3652423:23:59:59' DAY_SECOND);
+SELECT ADDDATE(DATE'0000-01-01', INTERVAL '0:87658175:59:59' DAY_SECOND);
+SELECT ADDDATE(DATE'0000-01-01', INTERVAL '0:0:5259490559:59' DAY_SECOND);
+SELECT ADDDATE(DATE'0000-01-01', INTERVAL '0:0:0:315569433599' DAY_SECOND);
+
+# Out-of-range INTERVAL DAY_SECOND values
+SELECT ADDDATE(DATE'0000-01-01', INTERVAL '3652423:0:0:315569433559' DAY_SECOND);
+SELECT ADDDATE(DATE'0000-01-01', INTERVAL '0:87658175:0:315569433559' DAY_SECOND);
+SELECT ADDDATE(DATE'0000-01-01', INTERVAL '0:0:5259490559:315569433599' DAY_SECOND);
+
+--echo #
+--echo # MDEV-13202 Assertion `ltime->neg == 0' failed in date_to_datetime
+--echo #
+
+CREATE TABLE t1 (i INT, d DATE);
+INSERT INTO t1 VALUES (1, '1970-01-01');
+SELECT MAX(NULLIF(i,1)) FROM t1 ORDER BY DATE_SUB(d,INTERVAL 17300000 HOUR);
+DROP TABLE t1;
+
+CREATE TABLE t1 (i INT, d DATE);
+INSERT INTO t1 VALUES (1, '1970-01-01');
+SELECT CONCAT(DATE_SUB(d, INTERVAL 17300000 HOUR)) FROM t1;
+DROP TABLE t1;
+
+SELECT CONCAT(DATE_SUB(TIMESTAMP'1970-01-01 00:00:00', INTERVAL 17300000 HOUR));
+
+
+--echo #
+--echo # End of 10.0 tests
+--echo #
diff --git a/mysql-test/t/func_weight_string.test b/mysql-test/t/func_weight_string.test
new file mode 100644
index 00000000000..6c34ce1e460
--- /dev/null
+++ b/mysql-test/t/func_weight_string.test
@@ -0,0 +1,113 @@
+--disable_warnings
+drop table if exists t1;
+--enable_warnings
+
+set names latin1;
+
+#
+# If it's BLOB or BINARY or VARBINARY, then output = input.
+#
+select hex(weight_string(0x010203));
+
+#
+# "AS CHAR ( int )" causes padding on the right. The pad
+# character is always space, that is, 0x20 or 0x0020.
+# The padding occurs before the conversion to a weight.
+# The value of "int" is the number of characters, not the number of bytes.
+#
+select hex(weight_string('aa' as char(3)));
+
+#
+# The minimum value of 'int' is 1.
+#
+--error 1064
+select hex(weight_string('a' as char(-1)));
+--error 1064
+select hex(weight_string('a' as char(0)));
+select hex(weight_string('a' as char(1)));
+
+#
+# If 'int' is smaller than the length of 'string',
+# truncation will occur with no warning.
+#
+select hex(weight_string('ab' as char(1)));
+
+#
+# If "AS CHAR ( int )" is omitted, there is no padding and no truncation.
+#
+select hex(weight_string('ab'));
+
+#
+# "AS BINARY ( int )" is like CHAR(int) but causes padding of 0x00
+# so one doesn't have to use "CAST(string AS BINARY(int))".
+#
+select hex(weight_string('aa' as binary(3)));
+select hex(weight_string(cast('aa' as binary(3))));
+
+#
+# If and only if one specifies "LEVEL numeric-list" (not "range"),
+# one may follow any "number" with [ASC|DESC][REVERSE]
+#
+--error 1064
+select hex(weight_string('ab' level 1-1 ASC));
+--error 1064
+select hex(weight_string('ab' level 1-1 DESC));
+--error 1064
+select hex(weight_string('ab' level 1-1 REVERSE));
+
+#
+# If one says "DESC", then the weights come out NOTed
+# or negated for that level.
+# If one says "REVERSE", then the weights come out in
+# reverse order for that level, that is, starting with
+# the last character and ending with the first character.
+#
+select hex(weight_string('ab' level 1 ASC));
+select hex(weight_string('ab' level 1 DESC));
+select hex(weight_string('ab' level 1 REVERSE));
+select hex(weight_string('ab' level 1 DESC REVERSE));
+
+#
+# If the result length is less than or equal to the
+# maximum possible length for the VARBINARY data type,
+# then the result data type is VARBINARY. Otherwise
+# the result data type is BLOB.
+#
+create table t1 select weight_string('test') as w;
+show create table t1;
+drop table t1;
+create table t1 select weight_string(repeat('t',66000)) as w;
+show create table t1;
+drop table t1;
+
+#
+# If input is NULL, then output is NULL.
+#
+select weight_string(NULL);
+
+#
+# WEIGHT_STRING and REVERSE will not be a new reserved word.
+#
+select 1 as weight_string, 2 as reverse;
+
+#
+# Check that collation derivation is copied from the argument
+#
+select coercibility(weight_string('test'));
+select coercibility(weight_string('test' collate latin1_swedish_ci));
+
+#
+# Bug#33663 Character sets: weight_string function,
+# varchar column, wrong result
+#
+create table t1 (s1 varchar(5));
+insert into t1 values ('a'),(null);
+select hex(weight_string(s1)) from t1 order by s1;
+drop table t1;
+
+--echo #
+--echo # BUG#11898467 - SERVER CRASHES ON SELECT HEX(WEIGHT_STRING(STR AS [CHAR|BINARY](N))) IF N IS BIG
+--echo #
+SELECT HEX(WEIGHT_STRING('ab' AS CHAR(1000000000000000000)));
+SELECT HEX(WEIGHT_STRING('ab' AS BINARY(1000000000000000000)));
+
diff --git a/mysql-test/t/function_defaults.test b/mysql-test/t/function_defaults.test
new file mode 100644
index 00000000000..f8b23d0eda8
--- /dev/null
+++ b/mysql-test/t/function_defaults.test
@@ -0,0 +1,21 @@
+--echo #
+--echo # Test of function defaults for any server, including embedded.
+--echo #
+
+--echo #
+--echo # Function defaults run 1. No microsecond precision.
+--echo #
+let $current_timestamp=CURRENT_TIMESTAMP;
+let $now=NOW();
+let $timestamp=TIMESTAMP;
+let $datetime=DATETIME;
+source 'include/function_defaults.inc';
+
+--echo #
+--echo # Function defaults run 2. Six digits scale on seconds precision.
+--echo #
+let $current_timestamp=CURRENT_TIMESTAMP(6);
+let $now=NOW(6);
+let $timestamp=TIMESTAMP(6);
+let $datetime=DATETIME(6);
+source 'include/function_defaults.inc';
diff --git a/mysql-test/t/function_defaults_innodb.test b/mysql-test/t/function_defaults_innodb.test
new file mode 100644
index 00000000000..de5a6d34b73
--- /dev/null
+++ b/mysql-test/t/function_defaults_innodb.test
@@ -0,0 +1,24 @@
+--echo #
+--echo # Test of function defaults for any server, including embedded.
+--echo #
+
+--source include/have_innodb.inc
+set default_storage_engine=innodb;
+
+--echo #
+--echo # Function defaults run 1. No microsecond precision.
+--echo #
+let $current_timestamp=CURRENT_TIMESTAMP;
+let $now=NOW();
+let $timestamp=TIMESTAMP;
+let $datetime=DATETIME;
+source 'include/function_defaults.inc';
+
+--echo #
+--echo # Function defaults run 2. Six digits scale on seconds precision.
+--echo #
+let $current_timestamp=CURRENT_TIMESTAMP(6);
+let $now=NOW(6);
+let $timestamp=TIMESTAMP(6);
+let $datetime=DATETIME(6);
+source 'include/function_defaults.inc';
diff --git a/mysql-test/t/function_defaults_notembedded.test b/mysql-test/t/function_defaults_notembedded.test
new file mode 100644
index 00000000000..3d686c4b272
--- /dev/null
+++ b/mysql-test/t/function_defaults_notembedded.test
@@ -0,0 +1,18 @@
+--echo #
+--echo # Test of function defaults for non-embedded server.
+--echo #
+
+--source include/not_embedded.inc
+--source include/have_debug_sync.inc
+
+--echo #
+--echo # Function defaults run 1. No microsecond precision.
+--echo #
+let $timestamp=TIMESTAMP;
+--source include/function_defaults_notembedded.inc
+
+--echo #
+--echo # Function defaults run 2. Six digits scale on seconds precision.
+--echo #
+let $timestamp=TIMESTAMP(6);
+--source include/function_defaults_notembedded.inc
diff --git a/mysql-test/t/get_diagnostics.test b/mysql-test/t/get_diagnostics.test
new file mode 100644
index 00000000000..0b0d8a77087
--- /dev/null
+++ b/mysql-test/t/get_diagnostics.test
@@ -0,0 +1,851 @@
+--echo #
+--echo # WL#2111: GET DIAGNOSTICS tests
+--echo #
+
+--echo #
+--echo # In MariaDB GET is not reserved
+--echo #
+
+CREATE TABLE t1 (get INT);
+DROP TABLE t1;
+
+DELIMITER |;
+CREATE PROCEDURE p1()
+BEGIN
+ DECLARE get INT DEFAULT 1;
+END|
+DELIMITER ;|
+DROP PROCEDURE p1;
+
+# but cannot be used as a label
+
+DELIMITER |;
+--error ER_PARSE_ERROR
+CREATE PROCEDURE p1()
+get:
+BEGIN
+ SELECT 1;
+END get|
+DELIMITER ;|
+
+--echo #
+--echo # Test non-reserved keywords: CURRENT, DIAGNOSTICS, NUMBER, RETURNED_SQLSTATE
+--echo #
+
+CREATE TABLE t1 (current INT, diagnostics INT, number INT, returned_sqlstate INT);
+INSERT INTO t1 (current, diagnostics, number, returned_sqlstate) values (1,2,3,4);
+SELECT current, diagnostics, number, returned_sqlstate FROM t1 WHERE number = 3;
+SELECT `current`, `number` FROM t1 WHERE `current` = 1 AND `number` = 3;
+DROP TABLE t1;
+
+DELIMITER |;
+CREATE PROCEDURE p1()
+BEGIN
+ DECLARE current INT DEFAULT 1;
+ DECLARE diagnostics INT DEFAULT 2;
+ DECLARE number INT DEFAULT 3;
+ DECLARE returned_sqlstate INT DEFAULT 4;
+ SELECT current, diagnostics, number, returned_sqlstate;
+END|
+DELIMITER ;|
+
+CALL p1();
+
+DROP PROCEDURE p1;
+
+--echo #
+--echo # Test GET DIAGNOSTICS syntax
+--echo #
+
+--disable_warnings
+DROP PROCEDURE IF EXISTS p1;
+--enable_warnings
+
+--error ER_PARSE_ERROR
+GET;
+--error ER_PARSE_ERROR
+GET CURRENT;
+--error ER_PARSE_ERROR
+GET DIAGNOSTICS;
+--error ER_PARSE_ERROR
+GET CURRENT DIAGNOSTICS;
+
+--echo
+--echo # Statement information syntax
+--echo
+
+--error ER_PARSE_ERROR
+GET DIAGNOSTICS @var;
+
+--error ER_SP_UNDECLARED_VAR
+GET DIAGNOSTICS var;
+
+DELIMITER |;
+--error ER_SP_UNDECLARED_VAR
+CREATE PROCEDURE p1()
+BEGIN
+ GET DIAGNOSTICS var;
+END|
+DELIMITER ;|
+
+DELIMITER |;
+--error ER_PARSE_ERROR
+CREATE PROCEDURE p1()
+BEGIN
+ DECLARE var INT;
+ GET DIAGNOSTICS var;
+END|
+DELIMITER ;|
+
+--error ER_PARSE_ERROR
+GET DIAGNOSTICS @var =;
+--error ER_PARSE_ERROR
+GET DIAGNOSTICS @var = INVALID;
+--error ER_PARSE_ERROR
+GET DIAGNOSTICS @var = MORE;
+--error ER_PARSE_ERROR
+GET DIAGNOSTICS @var = CLASS_ORIGIN;
+--error ER_PARSE_ERROR
+GET DIAGNOSTICS @var = INVALID,;
+--error ER_PARSE_ERROR
+GET DIAGNOSTICS @var1 = NUMBER, @var2;
+--error ER_PARSE_ERROR
+GET DIAGNOSTICS @var1 = NUMBER, @var2 = INVALID;
+--error ER_PARSE_ERROR
+GET DIAGNOSTICS @@var1 = NUMBER;
+--error ER_PARSE_ERROR
+GET DIAGNOSTICS @var1 = NUMBER, @@var2 = NUMBER;
+
+DELIMITER |;
+--error ER_PARSE_ERROR
+CREATE PROCEDURE p1()
+BEGIN
+ DECLARE var INT;
+ GET DIAGNOSTICS var = INVALID;
+END|
+DELIMITER ;|
+
+DELIMITER |;
+--error ER_SP_UNDECLARED_VAR
+CREATE PROCEDURE p1()
+BEGIN
+ DECLARE var CONDITION FOR SQLSTATE '12345';
+ GET DIAGNOSTICS var = NUMBER;
+END|
+DELIMITER ;|
+
+DELIMITER |;
+--error ER_SP_UNDECLARED_VAR
+CREATE PROCEDURE p1()
+BEGIN
+ DECLARE var INT;
+ GET DIAGNOSTICS var = NUMBER, var1 = ROW_COUNT;
+END|
+DELIMITER ;|
+
+GET DIAGNOSTICS @var = NUMBER;
+GET DIAGNOSTICS @var = ROW_COUNT;
+GET DIAGNOSTICS @var1 = NUMBER, @var2 = ROW_COUNT;
+GET DIAGNOSTICS @var1 = ROW_COUNT, @var2 = NUMBER;
+
+DELIMITER |;
+CREATE PROCEDURE p1()
+BEGIN
+ DECLARE var INT;
+ DECLARE var1 INT;
+ DECLARE var2 INT;
+ GET DIAGNOSTICS var = NUMBER;
+ GET DIAGNOSTICS var = ROW_COUNT;
+ GET DIAGNOSTICS var1 = NUMBER, var2 = ROW_COUNT;
+ GET DIAGNOSTICS var1 = ROW_COUNT, var2 = NUMBER;
+END|
+DELIMITER ;|
+
+DROP PROCEDURE p1;
+
+--echo
+--echo # Condition information syntax
+--echo
+
+--error ER_PARSE_ERROR
+GET DIAGNOSTICS CONDITION;
+--error ER_PARSE_ERROR
+GET DIAGNOSTICS CONDITION a;
+--error ER_PARSE_ERROR
+GET DIAGNOSTICS CONDITION 1;
+
+--error ER_PARSE_ERROR
+GET DIAGNOSTICS CONDITION 1 @var;
+
+--error ER_SP_UNDECLARED_VAR
+GET DIAGNOSTICS CONDITION 1 var;
+
+DELIMITER |;
+--error ER_SP_UNDECLARED_VAR
+CREATE PROCEDURE p1()
+BEGIN
+ GET DIAGNOSTICS CONDITION 1 var;
+END|
+DELIMITER ;|
+
+DELIMITER |;
+--error ER_PARSE_ERROR
+CREATE PROCEDURE p1()
+BEGIN
+ DECLARE var INT;
+ GET DIAGNOSTICS CONDITION 1 var;
+END|
+DELIMITER ;|
+
+--error ER_PARSE_ERROR
+GET DIAGNOSTICS CONDITION 1 @var =;
+--error ER_PARSE_ERROR
+GET DIAGNOSTICS CONDITION 1 @var = INVALID;
+--error ER_PARSE_ERROR
+GET DIAGNOSTICS CONDITION 1 @var = NUMBER;
+--error ER_PARSE_ERROR
+GET DIAGNOSTICS CONDITION 1 @var = INVALID,;
+--error ER_PARSE_ERROR
+GET DIAGNOSTICS CONDITION 1 @var1 = CLASS_ORIGIN, @var2;
+--error ER_PARSE_ERROR
+GET DIAGNOSTICS CONDITION 1 @var1 = CLASS_ORIGIN, @var2 = INVALID;
+--error ER_PARSE_ERROR
+GET DIAGNOSTICS CONDITION 1 @@var1 = CLASS_ORIGIN;
+--error ER_PARSE_ERROR
+GET DIAGNOSTICS CONDITION 1 @var1 = CLASS_ORIGIN, @@var2 = CLASS_ORIGIN;
+
+DELIMITER |;
+--error ER_PARSE_ERROR
+CREATE PROCEDURE p1()
+BEGIN
+ DECLARE var INT;
+ GET DIAGNOSTICS CONDITION 1 var = INVALID;
+END|
+DELIMITER ;|
+
+DELIMITER |;
+--error ER_SP_UNDECLARED_VAR
+CREATE PROCEDURE p1()
+BEGIN
+ DECLARE var CONDITION FOR SQLSTATE '12345';
+ GET DIAGNOSTICS CONDITION 1 var = NUMBER;
+END|
+DELIMITER ;|
+
+DELIMITER |;
+--error ER_SP_UNDECLARED_VAR
+CREATE PROCEDURE p1()
+BEGIN
+ DECLARE var INT;
+ GET DIAGNOSTICS CONDITION 1 var = CLASS_ORIGIN, var1 = SUBCLASS_ORIGIN;
+END|
+DELIMITER ;|
+
+GET DIAGNOSTICS CONDITION 1 @var = CLASS_ORIGIN;
+GET DIAGNOSTICS CONDITION 1 @var = SUBCLASS_ORIGIN;
+GET DIAGNOSTICS CONDITION 1 @var1 = CLASS_ORIGIN, @var2 = SUBCLASS_ORIGIN;
+GET DIAGNOSTICS CONDITION 1 @var1 = SUBCLASS_ORIGIN, @var2 = CLASS_ORIGIN;
+
+DELIMITER |;
+CREATE PROCEDURE p1()
+BEGIN
+ DECLARE var INT;
+ DECLARE var1 INT;
+ DECLARE var2 INT;
+ GET DIAGNOSTICS CONDITION 1 var = CLASS_ORIGIN;
+ GET DIAGNOSTICS CONDITION 1 var = SUBCLASS_ORIGIN;
+ GET DIAGNOSTICS CONDITION 1 var1 = CLASS_ORIGIN, var2 = SUBCLASS_ORIGIN;
+ GET DIAGNOSTICS CONDITION 1 var1 = SUBCLASS_ORIGIN, var2 = CLASS_ORIGIN;
+END|
+DELIMITER ;|
+
+DROP PROCEDURE p1;
+
+--echo # Condition number expression
+
+--error ER_PARSE_ERROR
+GET DIAGNOSTICS CONDITION -1 @var = CLASS_ORIGIN;
+--error ER_PARSE_ERROR
+GET DIAGNOSTICS CONDITION 1+1 @var = CLASS_ORIGIN;
+--error ER_PARSE_ERROR
+GET DIAGNOSTICS CONDITION ? @var = CLASS_ORIGIN;
+--error ER_PARSE_ERROR
+GET DIAGNOSTICS CONDITION (1) @var = CLASS_ORIGIN;
+--error ER_PARSE_ERROR
+GET DIAGNOSTICS CONDITION p1() @var = CLASS_ORIGIN;
+--error ER_PARSE_ERROR
+GET DIAGNOSTICS CONDITION ABS(2) @var = CLASS_ORIGIN;
+
+# Unfortunate side effects...
+GET DIAGNOSTICS CONDITION 1.1 @var = CLASS_ORIGIN;
+GET DIAGNOSTICS CONDITION "1" @var = CLASS_ORIGIN;
+
+# Reset warnings
+SELECT COUNT(max_questions) INTO @var FROM mysql.user;
+
+GET DIAGNOSTICS CONDITION 9999 @var = CLASS_ORIGIN;
+GET DIAGNOSTICS CONDITION NULL @var = CLASS_ORIGIN;
+GET DIAGNOSTICS CONDITION a @var = CLASS_ORIGIN;
+
+# Reset warnings
+SELECT COUNT(max_questions) INTO @var FROM mysql.user;
+
+SET @cond = 1;
+GET DIAGNOSTICS CONDITION @cond @var1 = CLASS_ORIGIN;
+
+SET @cond = "invalid";
+GET DIAGNOSTICS CONDITION @cond @var1 = CLASS_ORIGIN;
+
+# Reset warnings
+SELECT COUNT(max_questions) INTO @var FROM mysql.user;
+
+DELIMITER |;
+CREATE PROCEDURE p1()
+BEGIN
+ DECLARE cond INT DEFAULT 1;
+ DECLARE var INT;
+ GET DIAGNOSTICS CONDITION cond var = CLASS_ORIGIN;
+END|
+DELIMITER ;|
+
+DROP PROCEDURE p1;
+
+DELIMITER |;
+CREATE PROCEDURE p1()
+BEGIN
+ DECLARE cond TEXT;
+ DECLARE var INT;
+ GET DIAGNOSTICS CONDITION cond var = CLASS_ORIGIN;
+END|
+DELIMITER ;|
+
+CALL p1();
+
+DROP PROCEDURE p1;
+
+--echo #
+--echo # Test GET DIAGNOSTICS runtime
+--echo #
+
+--echo
+--echo # GET DIAGNOSTICS cannot be the object of a PREPARE statement.
+--echo
+
+--error ER_UNSUPPORTED_PS
+PREPARE stmt FROM "GET DIAGNOSTICS CONDITION 1 @var = CLASS_ORIGIN";
+--error ER_UNSUPPORTED_PS
+PREPARE stmt FROM "GET DIAGNOSTICS @var = NUMBER";
+
+--echo
+--echo # GET DIAGNOSTICS does not clear the diagnostics area.
+--echo
+
+SELECT CAST(-19999999999999999999 AS SIGNED);
+GET DIAGNOSTICS @var = NUMBER;
+SHOW WARNINGS;
+
+--echo #
+--echo # If GET DIAGNOSTICS itself causes an error, an error message is appended.
+--echo #
+
+SELECT CAST(-19999999999999999999 AS SIGNED);
+GET DIAGNOSTICS CONDITION 99999 @var = CLASS_ORIGIN;
+SHOW WARNINGS;
+
+--echo
+--echo # Statement information runtime
+--echo
+
+SELECT CAST(-19999999999999999999 AS SIGNED),
+ CAST(-19999999999999999999 AS SIGNED);
+GET DIAGNOSTICS @var = NUMBER;
+SELECT @var;
+
+SELECT COUNT(max_questions) INTO @var FROM mysql.user;
+GET DIAGNOSTICS @var = NUMBER;
+SELECT @var;
+
+SELECT 1;
+GET DIAGNOSTICS @var = ROW_COUNT;
+SELECT @var;
+
+CREATE TABLE t1 (a INT);
+INSERT INTO t1 VALUES (1),(2),(3);
+GET DIAGNOSTICS @var = ROW_COUNT;
+SELECT @var;
+DROP TABLE t1;
+
+DELIMITER |;
+CREATE PROCEDURE p1()
+BEGIN
+ DECLARE number INT;
+ DECLARE row_count INT;
+
+ SELECT CAST(-19999999999999999999 AS SIGNED),
+ CAST(-19999999999999999999 AS SIGNED);
+
+ GET DIAGNOSTICS number = NUMBER;
+
+ CREATE TABLE t1 (a INT);
+ INSERT INTO t1 VALUES (1),(2),(3);
+ GET DIAGNOSTICS row_count = ROW_COUNT;
+ DROP TABLE t1;
+
+ SELECT number, row_count;
+
+END|
+DELIMITER ;|
+
+CALL p1();
+
+DROP PROCEDURE p1;
+
+--echo
+--echo # Condition information runtime
+--echo
+
+SELECT CAST(-19999999999999999999 AS SIGNED);
+
+GET DIAGNOSTICS CONDITION 1
+ @class_origin = CLASS_ORIGIN,
+ @subclass_origin = SUBCLASS_ORIGIN,
+ @constraint_catalog = CONSTRAINT_CATALOG,
+ @constraint_schema = CONSTRAINT_SCHEMA,
+ @constraint_name = CONSTRAINT_NAME,
+ @catalog_name = CATALOG_NAME,
+ @schema_name = SCHEMA_NAME,
+ @table_name = TABLE_NAME,
+ @column_name = COLUMN_NAME,
+ @cursor_name = CURSOR_NAME,
+ @message_text = MESSAGE_TEXT,
+ @mysql_errno = MYSQL_ERRNO,
+ @returned_sqlstate = RETURNED_SQLSTATE;
+
+--vertical_results
+SELECT
+ @class_origin,
+ @subclass_origin,
+ @constraint_catalog,
+ @constraint_schema,
+ @constraint_name,
+ @catalog_name,
+ @schema_name,
+ @table_name,
+ @column_name,
+ @cursor_name,
+ @message_text,
+ @mysql_errno,
+ @returned_sqlstate;
+--horizontal_results
+
+DELIMITER |;
+CREATE PROCEDURE p1()
+BEGIN
+ DECLARE class_origin TEXT DEFAULT "a";
+ DECLARE subclass_origin TEXT DEFAULT "a";
+ DECLARE constraint_catalog TEXT DEFAULT "a";
+ DECLARE constraint_schema TEXT DEFAULT "a";
+ DECLARE constraint_name TEXT DEFAULT "a";
+ DECLARE catalog_name TEXT DEFAULT "a";
+ DECLARE schema_name TEXT DEFAULT "a";
+ DECLARE table_name TEXT DEFAULT "a";
+ DECLARE column_name TEXT DEFAULT "a";
+ DECLARE cursor_name TEXT DEFAULT "a";
+ DECLARE message_text TEXT DEFAULT "a";
+ DECLARE mysql_errno INT DEFAULT 1;
+ DECLARE returned_sqlstate TEXT DEFAULT "a";
+
+ SELECT CAST(-19999999999999999999 AS SIGNED);
+
+ GET DIAGNOSTICS CONDITION 1
+ class_origin = CLASS_ORIGIN,
+ subclass_origin = SUBCLASS_ORIGIN,
+ constraint_catalog = CONSTRAINT_CATALOG,
+ constraint_schema = CONSTRAINT_SCHEMA,
+ constraint_name = CONSTRAINT_NAME,
+ catalog_name = CATALOG_NAME,
+ schema_name = SCHEMA_NAME,
+ table_name = TABLE_NAME,
+ column_name = COLUMN_NAME,
+ cursor_name = CURSOR_NAME,
+ message_text = MESSAGE_TEXT,
+ mysql_errno = MYSQL_ERRNO,
+ returned_sqlstate = RETURNED_SQLSTATE;
+
+ SELECT
+ class_origin,
+ subclass_origin,
+ constraint_catalog,
+ constraint_schema,
+ constraint_name,
+ catalog_name,
+ schema_name,
+ table_name,
+ column_name,
+ cursor_name,
+ message_text,
+ mysql_errno,
+ returned_sqlstate;
+END|
+DELIMITER ;|
+
+--vertical_results
+CALL p1();
+--horizontal_results
+
+DROP PROCEDURE p1;
+
+DELIMITER |;
+CREATE PROCEDURE p1()
+BEGIN
+ DECLARE errno1 INT;
+ DECLARE errno2 INT;
+ DECLARE msg1 TEXT;
+ DECLARE msg2 TEXT;
+
+ SELECT CAST(-19999999999999999999 AS SIGNED);
+ GET DIAGNOSTICS CONDITION 99999 msg1 = MESSAGE_TEXT;
+
+ GET DIAGNOSTICS CONDITION 1 errno1 = MYSQL_ERRNO, msg1 = MESSAGE_TEXT;
+ GET DIAGNOSTICS CONDITION 2 errno2 = MYSQL_ERRNO, msg2 = MESSAGE_TEXT;
+
+ SELECT errno1, msg1, errno2, msg2;
+END|
+DELIMITER ;|
+
+--vertical_results
+CALL p1();
+--horizontal_results
+
+DROP PROCEDURE p1;
+
+--echo
+--echo # Interaction with SIGNAL
+--echo
+
+DELIMITER |;
+CREATE PROCEDURE p1()
+BEGIN
+ DECLARE errno INT DEFAULT 0;
+ DECLARE msg TEXT DEFAULT "foo";
+ DECLARE cond CONDITION FOR SQLSTATE "01234";
+ DECLARE CONTINUE HANDLER for 1012
+ BEGIN
+ GET DIAGNOSTICS CONDITION 1 errno = MYSQL_ERRNO, msg = MESSAGE_TEXT;
+ END;
+
+ SIGNAL cond SET MESSAGE_TEXT = "Signal message", MYSQL_ERRNO = 1012;
+
+ SELECT errno, msg;
+END|
+DELIMITER ;|
+
+--vertical_results
+CALL p1();
+--horizontal_results
+
+DROP PROCEDURE p1;
+
+DELIMITER |;
+CREATE PROCEDURE p1()
+BEGIN
+ SIGNAL SQLSTATE '77777' SET MYSQL_ERRNO = 1000, MESSAGE_TEXT='ÃÂÃÅÄ';
+END|
+DELIMITER ;|
+
+--error 1000
+CALL p1();
+
+GET DIAGNOSTICS CONDITION 1
+ @mysql_errno = MYSQL_ERRNO, @message_text = MESSAGE_TEXT,
+ @returned_sqlstate = RETURNED_SQLSTATE, @class_origin = CLASS_ORIGIN;
+
+--vertical_results
+SELECT @mysql_errno, @message_text, @returned_sqlstate, @class_origin;
+--horizontal_results
+
+DROP PROCEDURE p1;
+
+DELIMITER |;
+CREATE PROCEDURE p1()
+BEGIN
+ DECLARE cond CONDITION FOR SQLSTATE '12345';
+ SIGNAL cond SET
+ CLASS_ORIGIN = 'CLASS_ORIGIN text',
+ SUBCLASS_ORIGIN = 'SUBCLASS_ORIGIN text',
+ CONSTRAINT_CATALOG = 'CONSTRAINT_CATALOG text',
+ CONSTRAINT_SCHEMA = 'CONSTRAINT_SCHEMA text',
+ CONSTRAINT_NAME = 'CONSTRAINT_NAME text',
+ CATALOG_NAME = 'CATALOG_NAME text',
+ SCHEMA_NAME = 'SCHEMA_NAME text',
+ TABLE_NAME = 'TABLE_NAME text',
+ COLUMN_NAME = 'COLUMN_NAME text',
+ CURSOR_NAME = 'CURSOR_NAME text',
+ MESSAGE_TEXT = 'MESSAGE_TEXT text',
+ MYSQL_ERRNO = 54321;
+END|
+DELIMITER ;|
+
+--error 54321
+CALL p1();
+
+GET DIAGNOSTICS CONDITION 1
+ @class_origin = CLASS_ORIGIN,
+ @subclass_origin = SUBCLASS_ORIGIN,
+ @constraint_catalog = CONSTRAINT_CATALOG,
+ @constraint_schema = CONSTRAINT_SCHEMA,
+ @constraint_name = CONSTRAINT_NAME,
+ @catalog_name = CATALOG_NAME,
+ @schema_name = SCHEMA_NAME,
+ @table_name = TABLE_NAME,
+ @column_name = COLUMN_NAME,
+ @cursor_name = CURSOR_NAME,
+ @message_text = MESSAGE_TEXT,
+ @mysql_errno = MYSQL_ERRNO,
+ @returned_sqlstate = RETURNED_SQLSTATE;
+
+--vertical_results
+SELECT
+ @class_origin,
+ @subclass_origin,
+ @constraint_catalog,
+ @constraint_schema,
+ @constraint_name,
+ @catalog_name,
+ @schema_name,
+ @table_name,
+ @column_name,
+ @cursor_name,
+ @message_text,
+ @mysql_errno,
+ @returned_sqlstate;
+--horizontal_results
+
+DROP PROCEDURE p1;
+
+--echo #
+--echo # Demonstration
+--echo #
+
+--echo
+--echo # The same statement information item can be used multiple times.
+--echo
+
+DELIMITER |;
+CREATE PROCEDURE p1()
+BEGIN
+ DECLARE var INT;
+ GET DIAGNOSTICS var = NUMBER, @var = NUMBER;
+ SELECT var, @var;
+END|
+DELIMITER ;|
+
+CALL p1();
+
+DROP PROCEDURE p1;
+
+--echo
+--echo # Setting TABLE_NAME is currently not implemented.
+--echo
+
+DELIMITER |;
+CREATE PROCEDURE p1()
+BEGIN
+ DECLARE v VARCHAR(64);
+ DECLARE CONTINUE HANDLER FOR SQLEXCEPTION
+ GET DIAGNOSTICS CONDITION 1 v = TABLE_NAME;
+ DROP TABLE no_such_table;
+ SELECT v;
+END|
+DELIMITER ;|
+
+CALL p1();
+
+DROP PROCEDURE p1;
+
+--echo
+--echo # Message is truncated to fit into target. No truncation warning.
+--echo
+
+DELIMITER |;
+CREATE PROCEDURE p1()
+BEGIN
+ DECLARE v CHAR(1);
+ CREATE TABLE IF NOT EXISTS t1 (a INT);
+ GET DIAGNOSTICS CONDITION 1 v = MESSAGE_TEXT;
+ SELECT v;
+END|
+DELIMITER ;|
+
+CREATE TABLE t1 (a INT);
+CALL p1();
+DROP TABLE t1;
+
+DROP PROCEDURE p1;
+
+--echo
+--echo # Returns number of rows updated by the UPDATE statements.
+--echo
+
+DELIMITER |;
+CREATE PROCEDURE p1(IN param INT)
+LANGUAGE SQL
+BEGIN
+ DECLARE v INT DEFAULT 0;
+ DECLARE rcount_each INT;
+ DECLARE rcount_total INT DEFAULT 0;
+ WHILE v < 5 DO
+ UPDATE t1 SET a = a * 1.1 WHERE b = param;
+ GET DIAGNOSTICS rcount_each = ROW_COUNT;
+ SET rcount_total = rcount_total + rcount_each;
+ SET v = v + 1;
+ END WHILE;
+ SELECT rcount_total;
+END|
+DELIMITER ;|
+
+CREATE TABLE t1 (a REAL, b INT);
+INSERT INTO t1 VALUES (1.1, 1);
+CALL p1(1);
+DROP TABLE t1;
+
+DROP PROCEDURE p1;
+
+--echo
+--echo # GET DIAGNOSTICS doesn't clear the diagnostics area.
+--echo
+
+DELIMITER |;
+CREATE PROCEDURE p1()
+BEGIN
+ DECLARE CONTINUE HANDLER FOR SQLWARNING
+ BEGIN
+ GET CURRENT DIAGNOSTICS CONDITION 1 @x = RETURNED_SQLSTATE;
+ SIGNAL SQLSTATE '01002';
+ GET CURRENT DIAGNOSTICS CONDITION 1 @y = RETURNED_SQLSTATE;
+ END;
+ SIGNAL SQLSTATE '01001';
+ SELECT @x, @y;
+END|
+DELIMITER ;|
+
+CALL p1();
+
+DROP PROCEDURE p1;
+
+--echo
+--echo # Using OUT and INOUT parameters as the target variables.
+--echo
+
+DELIMITER |;
+CREATE PROCEDURE p1(OUT number INT, INOUT message TEXT)
+BEGIN
+ DECLARE warn CONDITION FOR SQLSTATE "01234";
+ DECLARE CONTINUE HANDLER FOR SQLWARNING
+ BEGIN
+ GET DIAGNOSTICS number = NUMBER;
+ GET DIAGNOSTICS CONDITION 1 message = MESSAGE_TEXT;
+ END;
+ SELECT message;
+ SIGNAL warn SET MESSAGE_TEXT = "inout parameter";
+END|
+DELIMITER ;|
+
+SET @var1 = 0;
+SET @var2 = "message text";
+CALL p1(@var1, @var2);
+SELECT @var1, @var2;
+
+DROP PROCEDURE p1;
+
+--echo
+--echo # Using an IN parameter as the target variable.
+--echo
+
+DELIMITER |;
+CREATE PROCEDURE p1(IN number INT)
+BEGIN
+ SELECT number;
+ GET DIAGNOSTICS number = NUMBER;
+ SELECT number;
+END|
+DELIMITER ;|
+
+SET @var1 = 9999;
+CALL p1(@var1);
+SELECT @var1;
+
+DROP PROCEDURE p1;
+
+--echo
+--echo # Using GET DIAGNOSTICS in a stored function.
+--echo
+
+DELIMITER |;
+CREATE FUNCTION f1() RETURNS TEXT
+BEGIN
+ DECLARE message TEXT;
+ DECLARE warn CONDITION FOR SQLSTATE "01234";
+ DECLARE CONTINUE HANDLER FOR SQLWARNING
+ BEGIN
+ GET DIAGNOSTICS CONDITION 1 message = MESSAGE_TEXT;
+ END;
+ SIGNAL warn SET MESSAGE_TEXT = "message text";
+ return message;
+END|
+DELIMITER ;|
+
+SELECT f1();
+
+DROP FUNCTION f1;
+
+--echo
+--echo # Using GET DIAGNOSTICS in a trigger.
+--echo
+
+CREATE TABLE t1 (a INT);
+
+DELIMITER |;
+CREATE TRIGGER trg1 BEFORE INSERT ON t1 FOR EACH ROW
+BEGIN
+ DECLARE var INT DEFAULT row_count();
+ GET DIAGNOSTICS @var1 = ROW_COUNT;
+ SET @var2 = var;
+END|
+DELIMITER ;|
+
+SET @var1 = 9999, @var2 = 9999;
+INSERT INTO t1 VALUES (1), (2);
+SELECT @var1, @var2;
+
+DROP TRIGGER trg1;
+DROP TABLE t1;
+
+--echo
+--echo # GET DIAGNOSTICS does not reset ROW_COUNT
+--echo
+
+CREATE TABLE t1 (a INT);
+INSERT INTO t1 VALUES (1);
+GET DIAGNOSTICS @var1 = ROW_COUNT;
+GET DIAGNOSTICS @var2 = ROW_COUNT;
+SELECT @var1, @var2;
+DROP TABLE t1;
+
+--echo
+--echo # Items are UTF8 (utf8_general_ci default collation)
+--echo
+
+SELECT CAST(-19999999999999999999 AS SIGNED);
+GET DIAGNOSTICS CONDITION 1 @var1 = MESSAGE_TEXT, @var2 = CLASS_ORIGIN;
+SELECT CHARSET(@var1), COLLATION(@var1), COERCIBILITY(@var1);
+SELECT CHARSET(@var2), COLLATION(@var2), COERCIBILITY(@var2);
+
+--echo #
+--echo # Command statistics
+--echo #
+
+FLUSH STATUS;
+SHOW STATUS LIKE 'Com%get_diagnostics';
+GET DIAGNOSTICS @var1 = NUMBER;
+SHOW STATUS LIKE 'Com%get_diagnostics';
diff --git a/mysql-test/t/gis-alter_table_online.test b/mysql-test/t/gis-alter_table_online.test
new file mode 100644
index 00000000000..be6d2137e77
--- /dev/null
+++ b/mysql-test/t/gis-alter_table_online.test
@@ -0,0 +1,82 @@
+--source include/have_innodb.inc
+--source include/have_geometry.inc
+
+--echo #
+--echo # Start of 10.1 tests
+--echo #
+
+--echo #
+--echo # MDEV-8948 ALTER ... INPLACE does work for BINARY, BLOB
+--echo #
+
+#
+# Blob variants to GEOMETRY
+#
+CREATE TABLE t1 (a TINYBLOB);
+--error ER_ALTER_OPERATION_NOT_SUPPORTED
+ALTER TABLE t1 MODIFY a GEOMETRY, ALGORITHM=INPLACE;
+DROP TABLE t1;
+
+CREATE TABLE t1 (a MEDIUMBLOB);
+--error ER_ALTER_OPERATION_NOT_SUPPORTED
+ALTER TABLE t1 MODIFY a GEOMETRY, ALGORITHM=INPLACE;
+DROP TABLE t1;
+
+CREATE TABLE t1 (a BLOB);
+--error ER_ALTER_OPERATION_NOT_SUPPORTED
+ALTER TABLE t1 MODIFY a GEOMETRY, ALGORITHM=INPLACE;
+DROP TABLE t1;
+
+CREATE TABLE t1 (a LONGBLOB);
+--error ER_ALTER_OPERATION_NOT_SUPPORTED
+ALTER TABLE t1 MODIFY a GEOMETRY, ALGORITHM=INPLACE;
+DROP TABLE t1;
+
+#
+# GEOMETRY to BLOB variants
+#
+
+CREATE TABLE t1 (a GEOMETRY);
+--error ER_ALTER_OPERATION_NOT_SUPPORTED
+ALTER TABLE t1 MODIFY a TINYBLOB, ALGORITHM=INPLACE;
+DROP TABLE t1;
+
+CREATE TABLE t1 (a GEOMETRY);
+--error ER_ALTER_OPERATION_NOT_SUPPORTED
+ALTER TABLE t1 MODIFY a MEDIUMBLOB, ALGORITHM=INPLACE;
+DROP TABLE t1;
+
+CREATE TABLE t1 (a GEOMETRY);
+--error ER_ALTER_OPERATION_NOT_SUPPORTED
+ALTER TABLE t1 MODIFY a BLOB, ALGORITHM=INPLACE;
+DROP TABLE t1;
+
+CREATE TABLE t1 (a GEOMETRY);
+--error ER_ALTER_OPERATION_NOT_SUPPORTED
+ALTER TABLE t1 MODIFY a LONGBLOB, ALGORITHM=INPLACE;
+DROP TABLE t1;
+
+#
+# Different GEOMETRY types
+#
+
+# Can't do INPLACE from a supertype to a subtype
+CREATE TABLE t1 (a GEOMETRY);
+--error ER_ALTER_OPERATION_NOT_SUPPORTED
+ALTER TABLE t1 MODIFY a POLYGON, ALGORITHM=INPLACE;
+DROP TABLE t1;
+
+# Ok to do INPLACE from a subtype to a supertype
+CREATE TABLE t1 (a POLYGON);
+ALTER TABLE t1 MODIFY a GEOMETRY, ALGORITHM=INPLACE;
+DROP TABLE t1;
+
+# Ok to do INPLACE for two equal geometry subtypes
+CREATE TABLE t1 (a POLYGON);
+ALTER TABLE t1 MODIFY a POLYGON, ALGORITHM=INPLACE;
+DROP TABLE t1;
+
+
+--echo #
+--echo # End of 10.1 tests
+--echo #
diff --git a/mysql-test/t/gis-debug.test b/mysql-test/t/gis-debug.test
new file mode 100644
index 00000000000..a0647a2c9f4
--- /dev/null
+++ b/mysql-test/t/gis-debug.test
@@ -0,0 +1,6 @@
+--source include/have_geometry.inc
+--source include/have_debug.inc
+
+SET @tmp=ST_GIS_DEBUG(1);
+
+--source include/gis_debug.inc
diff --git a/mysql-test/t/gis-precise.test b/mysql-test/t/gis-precise.test
index b7442a588a2..c6cf42e86e4 100644
--- a/mysql-test/t/gis-precise.test
+++ b/mysql-test/t/gis-precise.test
@@ -111,6 +111,32 @@ SELECT ST_Equals(PolyFromText('POLYGON((67 13, 67 18, 67 18, 59 18, 59 13, 67 13
SELECT ST_Equals(PolyFromText('POLYGON((67 13, 67 18, 67 18, 59 18, 59 13, 67 13) )'),PolyFromText('POLYGON((67 13, 67 18, 59 18, 59 13, 59 13, 67 13) )')) as result;
SELECT ST_Equals(PointFromText('POINT (12 13)'),PointFromText('POINT (12 13)')) as result;
+
+--echo #
+--echo # BUG#11755628/47429: INTERSECTION FUNCTION CRASHED MYSQLD
+--echo # BUG#11759650/51979: UNION/INTERSECTION OF POLYGONS CRASHES MYSQL
+--echo #
+
+SELECT ASTEXT(ST_UNION(GEOMFROMTEXT('POLYGON((525000 183300,525400
+183300,525400 18370, 525000 183700,525000 183300))'),
+geomfromtext('POLYGON((525298.67 183511.53,525296.57
+183510.39,525296.42 183510.31,525289.11 183506.62,525283.17
+183503.47,525280.98 183502.26,525278.63 183500.97,525278.39
+183500.84,525276.79 183500,525260.7 183491.55,525263.95
+183484.75,525265.58 183481.95,525278.97 183488.73,525276.5
+183493.45,525275.5 183495.7,525280.35 183498.2,525282.3
+183499.1,525282.2 183499.3,525283.55 183500,525301.75
+183509.35,525304.45 183504.25,525307.85 183504.95,525304.5
+183510.83,525302.81 183513.8,525298.67 183511.53),(525275.06
+183489.89,525272.06 183488.37,525268.94 183494.51,525271.94
+183496.03,525275.06 183489.89),(525263.26 183491.55,525266.15
+183493.04,525269.88 183485.82,525266.99 183484.33,525263.26
+183491.55))'))) st_u;
+
+SET @a=0x0000000001030000000200000005000000000000000000000000000000000000000000000000002440000000000000000000000000000024400000000000002440000000000000000000000000000024400000000000000000000000000000000000000000000000000000F03F000000000000F03F0000000000000040000000000000F03F00000000000000400000000000000040000000000000F03F0000000000000040000000000000F03F000000000000F03F;
+SELECT ASTEXT(TOUCHES(@a, GEOMFROMTEXT('point(0 0)'))) t;
+
+
# bug #801243 Assertion `(0)' failed in Gis_geometry_collection::init_from_opresult on ST_UNION
SELECT astext(ST_UNION (
@@ -331,3 +357,5 @@ SELECT ST_NUMPOINTS(ST_EXTERIORRING(ST_BUFFER( POLYGONFROMTEXT( 'POLYGON( ( 0.0
# MDEV-5615 crash in Gcalc_function::add_operation
select astext(buffer(st_linestringfromwkb(linestring(point(-1,1), point(-1,-2))),-1));
+--source include/gis_debug.inc
+
diff --git a/mysql-test/t/gis-rt-precise.test b/mysql-test/t/gis-rt-precise.test
index 4cae10a9076..9c26aa05598 100644
--- a/mysql-test/t/gis-rt-precise.test
+++ b/mysql-test/t/gis-rt-precise.test
@@ -62,3 +62,25 @@ SELECT fid, AsText(g) FROM t1 WHERE ST_Within(g,
DROP TABLE t1;
--echo End of 5.5 tests.
+
+#
+# MDEV-12078 Using spatial index changes type from point to geometry.
+#
+CREATE TABLE t1 (
+ coordinate point NOT NULL,
+ SPATIAL KEY coordinate (coordinate)
+) ENGINE=Aria DEFAULT CHARSET=ascii PAGE_CHECKSUM=1;
+
+SHOW COLUMNS FROM t1;
+
+INSERT INTO t1 (coordinate) VALUES(ST_PointFromText("POINT(0 0)"));
+INSERT INTO t1 (coordinate) VALUES(ST_PointFromText("POINT(10 0)"));
+INSERT INTO t1 (coordinate) VALUES(ST_PointFromText("POINT(10 10)"));
+INSERT INTO t1 (coordinate) VALUES(ST_PointFromText("POINT(0 10)"));
+INSERT INTO t1 (coordinate) VALUES(ST_PointFromText("POINT(5 5)"));
+
+SELECT astext(coordinate) FROM t1 WHERE ST_Intersects(ST_LineFromText("LINESTRING(0 0, 10 0, 10 10, 0 10)"), coordinate);
+
+SHOW COLUMNS FROM t1;
+
+DROP TABLE t1;
diff --git a/mysql-test/t/gis.test b/mysql-test/t/gis.test
index 6e41660d598..4192a3284b7 100644
--- a/mysql-test/t/gis.test
+++ b/mysql-test/t/gis.test
@@ -356,15 +356,15 @@ insert into t1 values ('85984',GeomFromText('MULTIPOLYGON(((-115.006363
36.248666,-115.263639 36.247466,-115.263839 36.252766,-115.261439
36.252666,-115.261439 36.247366,-115.247239 36.247066)))'));
-# Expected result is 115.31877315203187, but IA64 returns 115.31877315203188
-# due to fused multiply-add instructions.
---replace_result 115.31877315203188 115.31877315203187
+# Expected results are 115.2970604672862 and 36.23335610879993, but IA64 returns
+# slightly different values due to fused multiply-add instructions.
+--replace_result 115.29706047613604 115.2970604672862 36.23335611157958 36.23335610879993
select object_id, geometrytype(geo), ISSIMPLE(GEO), ASTEXT(centroid(geo)) from
t1 where object_id=85998;
-# Expected result is 36.3310176346905, but IA64 returns 36.3310176346904
+# Expected result is 36.34725218253213, but IA64 returns 36.34725217627852
# due to fused multiply-add instructions.
---replace_result 36.3310176346904 36.3310176346905 -114.87787186923326 -114.87787186923313 36.33101763469053 36.33101763469059 36.33101763469043 36.33101763469059
+--replace_result 36.34725217627852 36.34725218253213 -114.86854470090232 -114.86854472054372
select object_id, geometrytype(geo), ISSIMPLE(GEO), ASTEXT(centroid(geo)) from
t1 where object_id=85984;
@@ -542,6 +542,18 @@ insert into t1 values(default);
drop table t1;
#
+# Bug #27300: create view with geometry functions lost columns types
+#
+CREATE TABLE t1 (a GEOMETRY);
+CREATE VIEW v1 AS SELECT GeomFromwkb(ASBINARY(a)) FROM t1;
+CREATE VIEW v2 AS SELECT a FROM t1;
+DESCRIBE v1;
+DESCRIBE v2;
+
+DROP VIEW v1,v2;
+DROP TABLE t1;
+
+#
# Bug#24563: MBROverlaps does not seem to function propertly
# Bug#54888: MBROverlaps missing in 5.1?
#
@@ -610,9 +622,9 @@ DROP TABLE t1;
#
# Bug#28763: Selecting geometry fields in UNION caused server crash.
#
-create table t1(f1 geometry, f2 point, f3 linestring);
+create table t1(f1 geometry, f2 linestring, f3 linestring);
select f1 from t1 union select f1 from t1;
-insert into t1 (f2,f3) values (GeomFromText('POINT(1 1)'),
+insert into t1 (f2,f3) values (GeomFromText('LINESTRING(1 1, 2 2)'),
GeomFromText('LINESTRING(0 0,1 1,2 2)'));
select AsText(f2),AsText(f3) from t1;
select AsText(a) from (select f2 as a from t1 union select f3 from t1) t;
@@ -1480,3 +1492,31 @@ SELECT ASTEXT(p) FROM v1;
DROP VIEW v1;
# --echo End of 5.5 tests
+
+--echo #
+--echo # Start of 10.0 tests
+--echo #
+
+--echo #
+--echo # MDEV-12495 Conditional jump depends on uninitialised value for: SELECT NULL UNION geom_expression
+--echo #
+SELECT AsText(g) FROM (SELECT NULL AS g UNION SELECT Point(1,1)) AS t1;
+
+--echo #
+--echo # MDEV-10306 Wrong results with combination of CONCAT, SUBSTR and CONVERT in subquery
+--echo #
+
+SET @save_optimizer_switch=@@optimizer_switch;
+SET optimizer_switch='derived_merge=on';
+CREATE TABLE t1 (x INT, y INT);
+INSERT INTO t1 VALUES(0,0);
+SELECT LENGTH(t2) c2 FROM (SELECT ST_BUFFER(POINT(x,y), 0) t2 FROM t1) sub;
+SELECT LENGTH(CONCAT(t2,'-',t2)) c2 FROM (SELECT ST_BUFFER(POINT(x,y), 0) t2 FROM t1) sub;
+SELECT LENGTH(CONCAT(t2,'--',t2)) c2 FROM (SELECT ST_BUFFER(POINT(x,y), 0) t2 FROM t1) sub;
+DROP TABLE t1;
+SET optimizer_switch=@save_optimizer_switch;
+
+
+--echo #
+--echo # End 10.0 tests
+--echo #
diff --git a/mysql-test/t/grant.test b/mysql-test/t/grant.test
index efa79c5b768..0be4c254269 100644
--- a/mysql-test/t/grant.test
+++ b/mysql-test/t/grant.test
@@ -587,7 +587,6 @@ flush privileges;
# Create some users with different hostnames
create user mysqltest_8@'';
-create user mysqltest_8;
create user mysqltest_8@host8;
# Try to create them again
@@ -614,7 +613,6 @@ select * from t1;
disconnect conn3;
connection master;
revoke select on mysqltest.* from mysqltest_8@'';
-revoke select on mysqltest.* from mysqltest_8;
show grants for mysqltest_8@'';
show grants for mysqltest_8;
select * from information_schema.schema_privileges
@@ -642,7 +640,6 @@ select * from t1;
disconnect conn4;
connection master;
revoke update (a) on t1 from mysqltest_8@'';
-revoke update (a) on t1 from mysqltest_8;
show grants for mysqltest_8@'';
show grants for mysqltest_8;
select * from information_schema.column_privileges;
@@ -664,7 +661,6 @@ select * from t1;
disconnect conn5;
connection master;
revoke update on t1 from mysqltest_8@'';
-revoke update on t1 from mysqltest_8;
show grants for mysqltest_8@'';
show grants for mysqltest_8;
select * from information_schema.table_privileges;
@@ -692,10 +688,6 @@ show grants for mysqltest_8;
drop user mysqltest_8@'';
--error ER_NONEXISTING_GRANT
show grants for mysqltest_8@'';
-show grants for mysqltest_8;
-select * from information_schema.user_privileges
-where grantee like "'mysqltest_8'%";
-drop user mysqltest_8;
--replace_result $MASTER_MYSOCK MASTER_SOCKET $MASTER_MYPORT MASTER_PORT
--error ER_ACCESS_DENIED_ERROR
connect (conn6,localhost,mysqltest_8,,);
@@ -823,7 +815,7 @@ disconnect master;
# Bug#10668 CREATE USER does not enforce username length limit
#
--error ER_WRONG_STRING_LENGTH
-create user mysqltest1_thisisreallytoolong;
+create user longer_than_80_456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789;
#
# Test for Bug#16899 Possible buffer overflow in handling of DEFINER-clause.
@@ -913,13 +905,13 @@ USE test;
# Working with database-level privileges.
--error ER_WRONG_STRING_LENGTH
-GRANT CREATE ON mysqltest.* TO 1234567890abcdefGHIKL@localhost;
+GRANT CREATE ON mysqltest.* TO longer_than_80_456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789@localhost;
--error ER_WRONG_STRING_LENGTH
GRANT CREATE ON mysqltest.* TO some_user_name@1234567890abcdefghij1234567890abcdefghij1234567890abcdefghijQWERTY;
--error ER_WRONG_STRING_LENGTH
-REVOKE CREATE ON mysqltest.* FROM 1234567890abcdefGHIKL@localhost;
+REVOKE CREATE ON mysqltest.* FROM longer_than_80_456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789@localhost;
--error ER_WRONG_STRING_LENGTH
REVOKE CREATE ON mysqltest.* FROM some_user_name@1234567890abcdefghij1234567890abcdefghij1234567890abcdefghijQWERTY;
@@ -927,13 +919,13 @@ REVOKE CREATE ON mysqltest.* FROM some_user_name@1234567890abcdefghij1234567890a
# Working with table-level privileges.
--error ER_WRONG_STRING_LENGTH
-GRANT CREATE ON t1 TO 1234567890abcdefGHIKL@localhost;
+GRANT CREATE ON t1 TO longer_than_80_456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789@localhost;
--error ER_WRONG_STRING_LENGTH
GRANT CREATE ON t1 TO some_user_name@1234567890abcdefghij1234567890abcdefghij1234567890abcdefghijQWERTY;
--error ER_WRONG_STRING_LENGTH
-REVOKE CREATE ON t1 FROM 1234567890abcdefGHIKL@localhost;
+REVOKE CREATE ON t1 FROM longer_than_80_456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789@localhost;
--error ER_WRONG_STRING_LENGTH
REVOKE CREATE ON t1 FROM some_user_name@1234567890abcdefghij1234567890abcdefghij1234567890abcdefghijQWERTY;
@@ -941,13 +933,13 @@ REVOKE CREATE ON t1 FROM some_user_name@1234567890abcdefghij1234567890abcdefghij
# Working with routine-level privileges.
--error ER_WRONG_STRING_LENGTH
-GRANT EXECUTE ON PROCEDURE p1 TO 1234567890abcdefGHIKL@localhost;
+GRANT EXECUTE ON PROCEDURE p1 TO longer_than_80_456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789@localhost;
--error ER_WRONG_STRING_LENGTH
GRANT EXECUTE ON PROCEDURE p1 TO some_user_name@1234567890abcdefghij1234567890abcdefghij1234567890abcdefghijQWERTY;
--error ER_WRONG_STRING_LENGTH
-REVOKE EXECUTE ON PROCEDURE p1 FROM 1234567890abcdefGHIKL@localhost;
+REVOKE EXECUTE ON PROCEDURE p1 FROM longer_than_80_456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789@localhost;
--error ER_WRONG_STRING_LENGTH
REVOKE EXECUTE ON PROCEDURE t1 FROM some_user_name@1234567890abcdefghij1234567890abcdefghij1234567890abcdefghijQWERTY;
@@ -1584,7 +1576,7 @@ grant select on test.* to юзер_юзер@localhost;
revoke all on test.* from юзер_юзер@localhost;
drop user юзер_юзер@localhost;
--error ER_WRONG_STRING_LENGTH
-grant select on test.* to очень_длинный_юзер@localhost;
+grant select on test.* to очень_длинный_юзер890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890@localhost;
set names default;
#
@@ -1669,7 +1661,6 @@ use test;
#
--echo FLUSH PRIVILEGES without procs_priv table.
RENAME TABLE mysql.procs_priv TO mysql.procs_gone;
---error ER_NO_SUCH_TABLE
FLUSH PRIVILEGES;
--echo Assigning privileges without procs_priv table.
CREATE DATABASE mysqltest1;
@@ -1862,9 +1853,6 @@ revoke select on Foo.* from myuser@localhost;
delete from mysql.user where User='myuser';
flush privileges;
-# Wait till we reached the initial number of concurrent sessions
---source include/wait_until_count_sessions.inc
-
--echo #########################################################################
--echo #
--echo # Bug#38347: ALTER ROUTINE privilege allows SHOW CREATE TABLE.
@@ -2249,5 +2237,38 @@ DROP USER foo@'127.0.0.1';
--echo # End of Bug#12766319
+
+--echo #
+--echo # Bug#11756966 - 48958: STORED PROCEDURES CAN BE LEVERAGED TO BYPASS
+--echo # DATABASE SECURITY
+--echo #
+
+--disable_warnings
+DROP DATABASE IF EXISTS secret;
+DROP DATABASE IF EXISTS no_such_db;
+--enable_warnings
+
+CREATE DATABASE secret;
+GRANT USAGE ON *.* TO untrusted@localhost;
+
+--echo # Connection con1
+connect (con1, localhost, untrusted);
+SHOW GRANTS;
+SHOW DATABASES;
+
+--echo # Both statements below should fail with the same error.
+--echo # They used to give different errors, thereby
+--echo # hinting that the secret database exists.
+--error ER_DBACCESS_DENIED_ERROR
+CREATE PROCEDURE no_such_db.foo() BEGIN END;
+--error ER_DBACCESS_DENIED_ERROR
+CREATE PROCEDURE secret.peek_at_secret() BEGIN END;
+
+--echo # Connection default
+--connection default
+disconnect con1;
+DROP USER untrusted@localhost;
+DROP DATABASE secret;
+
# Wait till we reached the initial number of concurrent sessions
--source include/wait_until_count_sessions.inc
diff --git a/mysql-test/t/grant2.test b/mysql-test/t/grant2.test
index 6c2ba0dd6fc..8590dccd1d1 100644
--- a/mysql-test/t/grant2.test
+++ b/mysql-test/t/grant2.test
@@ -405,7 +405,7 @@ drop database mysqltest_1;
# But anonymous users can't change their password
connect (n5,localhost,test,,test,$MASTER_MYPORT,$MASTER_MYSOCK);
connection n5;
---error ER_PASSWORD_NO_MATCH
+--error ER_PASSWORD_ANONYMOUS_USER
set password = password("changed");
disconnect n5;
connection default;
@@ -667,5 +667,367 @@ USE test;
--echo End of 5.1 tests
+
+--echo
+--echo # --
+--echo # -- Bug#11746602: 27480 - Extend CREATE TEMPORARY TABLES privilege to
+--echo # -- allow temp table operations
+--echo # --
+--echo # -- Bug#12771903: User with create temporary tables priv only has full
+--echo # -- access to a regular table
+--echo # --
+--echo
+
+--echo ############################################################################
+--echo # Setup environment.
+--echo ###########################################################################
+
+--disable_warnings
+DROP DATABASE IF EXISTS mysqltest_db1;
+DROP DATABASE IF EXISTS mysqltest_db2;
+--enable_warnings
+
+CREATE DATABASE mysqltest_db1;
+CREATE DATABASE mysqltest_db2;
+
+--echo # mysqltest_u1@localhost has CREATE_TMP_ACL, FILE_ACL and EXECUTE_ACL only
+--echo # (EXECUTE_ACL is needed to call p0, and FILE_ACL is needed for SELECT
+--echo # OUTFILE/LOAD DATA INFILE).
+GRANT FILE ON *.* TO mysqltest_u1@localhost;
+GRANT CREATE TEMPORARY TABLES, EXECUTE ON mysqltest_db1.* TO mysqltest_u1@localhost;
+
+--echo # mysqltest_u2@localhost has all privileges but CREATE_TMP_ACL.
+GRANT ALL PRIVILEGES ON mysqltest_db1.* TO mysqltest_u2@localhost;
+REVOKE CREATE TEMPORARY TABLES ON mysqltest_db1.* FROM mysqltest_u2@localhost;
+
+--echo # mysqltest_u3@localhost has CREATE_TMP_ACL & EXECUTE_ACL.
+--echo # This user is required to check SUID-stored-routines.
+GRANT CREATE TEMPORARY TABLES ON mysqltest_db1.* TO mysqltest_u3@localhost;
+GRANT EXECUTE ON mysqltest_db1.* TO mysqltest_u3@localhost;
+
+--echo # mysqltest_u4@localhost has only EXECUTE_ACL.
+--echo # We need this user to check that once created temporary tables
+--echo # are accessible by anyone.
+GRANT EXECUTE ON mysqltest_db1.* TO mysqltest_u4@localhost;
+
+--echo # mysqltest_u5@localhost has CREATE_TMP_ACL and SELECT_ACL, UPDATE_ACL,
+--echo # DELETE_ACL on mysqltest_db1; and only CREATE_TMP_ACL on mysqltest_db2.
+--echo # By means of this user we check privileges required for merge tables.
+GRANT CREATE TEMPORARY TABLES ON mysqltest_db1.* TO mysqltest_u5@localhost;
+GRANT CREATE TEMPORARY TABLES ON mysqltest_db2.* TO mysqltest_u5@localhost;
+GRANT SELECT, UPDATE, DELETE ON mysqltest_db1.* TO mysqltest_u5@localhost;
+
+--echo # Create stored routine to test how privilege checking is done for its
+--echo # arguments.
+CREATE PROCEDURE mysqltest_db1.p0(i INT) SELECT i;
+
+--echo # Create SUID-stored-routines.
+CREATE DEFINER = mysqltest_u3@localhost PROCEDURE mysqltest_db1.p1()
+ CREATE TEMPORARY TABLE t4(x INT);
+
+CREATE DEFINER = mysqltest_u3@localhost PROCEDURE mysqltest_db1.p2()
+ INSERT INTO t4 VALUES (1), (2), (3);
+
+CREATE DEFINER = mysqltest_u3@localhost PROCEDURE mysqltest_db1.p3()
+ SELECT * FROM t4 ORDER BY x;
+
+--echo # We need separate key cache to test CACHE INDEX and LOAD INDEX.
+SET GLOBAL keycache1.key_buffer_size = 128 * 1024;
+
+CREATE TABLE mysqltest_db2.t2_1(a INT);
+
+--echo ###########################################################################
+--echo # Check that CREATE_TMP_ACL is enough to issue almost any supported
+--echo # SQL-statement against temporary tables (loosely follow order in
+--echo # sql_command enum).
+--echo ###########################################################################
+
+--echo
+--echo # -- connect con1, mysqltest_u1@localhost, mysqltest_db1
+--connect (con1,localhost,mysqltest_u1,,mysqltest_db1)
+
+--echo #
+--echo # Variants of CREATE TABLE.
+--echo #
+CREATE TEMPORARY TABLE t1(a INT);
+CREATE TEMPORARY TABLE t2 LIKE t1;
+CREATE TEMPORARY TABLE t3(a INT, b INT, PRIMARY KEY (a));
+CREATE TEMPORARY TABLE t4 SELECT * FROM t1;
+--echo # Check that we do *not* allow creation of MERGE table with underlying
+--echo # temporary table without additional privileges.
+CREATE TEMPORARY TABLE t5(a INT) ENGINE = MyISAM;
+--error ER_TABLEACCESS_DENIED_ERROR
+CREATE TEMPORARY TABLE t6(a INT) ENGINE = MERGE UNION = (t5);
+--echo # Check that we allow creation of MERGE table with no underlying table
+--echo # without additional privileges.
+CREATE TEMPORARY TABLE t6(a INT) ENGINE = MERGE UNION = ();
+
+--echo #
+--echo # SELECT.
+--echo #
+INSERT INTO t1 VALUES (1), (2), (3);
+SELECT * FROM t1 ORDER BY a;
+
+--echo #
+--echo # CREATE/DROP INDEX.
+--echo #
+CREATE INDEX idx1 ON t3(b);
+DROP INDEX idx1 ON t3;
+
+--echo #
+--echo # ALTER TABLE.
+--echo #
+ALTER TABLE t4 ADD COLUMN b INT;
+--echo # Check that we allow altering of MERGE table with no underlying
+--echo # without additional privileges.
+ALTER TABLE t6 UNION = ();
+--echo # Check that we do *not* allow altering of MERGE table with underlying
+--echo # temporary table without additional privileges.
+--error ER_TABLEACCESS_DENIED_ERROR
+ALTER TABLE t6 UNION = (t5);
+
+--echo #
+--echo # Simple INSERT and INSERT ... SELECT.
+--echo #
+INSERT INTO t1 VALUES (4);
+INSERT INTO t2 SELECT a FROM t1;
+SELECT * FROM t1 ORDER BY a;
+SELECT * FROM t2 ORDER BY a;
+
+--echo #
+--echo # UPDATE and multi-UPDATE.
+--echo #
+UPDATE t1 SET a = a * 10;
+UPDATE t1 SET a = 100 WHERE a = 10;
+UPDATE t1, t2 SET t1.a = 200 WHERE t1.a = t2.a * 10 AND t1.a = 20;
+SELECT * FROM t1 ORDER BY a;
+
+--echo #
+--echo # DELETE and multi-DELETE.
+--echo #
+DELETE FROM t1 WHERE a = 100;
+DELETE t1 FROM t1, t2 WHERE t1.a = t2.a * 100 AND t1.a = 200;
+SELECT * FROM t1 ORDER BY a;
+
+--echo #
+--echo # TRUNCATE TABLE.
+--echo #
+TRUNCATE TABLE t1;
+SELECT * FROM t1 ORDER BY a;
+
+--echo #
+--echo # SHOW COLUMNS/DESCRIBE and SHOW KEYS.
+--echo #
+SHOW COLUMNS FROM t1;
+SHOW KEYS FROM t3;
+
+--echo #
+--echo # SHOW CREATE TABLE.
+--echo #
+SHOW CREATE TABLE t1;
+
+--echo #
+--echo # LOAD DATA INFILE (also SELECT INTO OUTFILE).
+--echo #
+INSERT INTO t1 VALUES (1), (2), (3);
+--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
+--eval SELECT a INTO OUTFILE '$MYSQLTEST_VARDIR/tmp/bug27480.txt' FROM t1
+--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
+--eval LOAD DATA INFILE '$MYSQLTEST_VARDIR/tmp/bug27480.txt' INTO TABLE t1
+--remove_file $MYSQLTEST_VARDIR/tmp/bug27480.txt
+SELECT * FROM t1 ORDER BY a;
+
+--echo #
+--echo # SET.
+--echo #
+SET @a := (SELECT COUNT(*) FROM t1);
+SELECT @a;
+
+--echo #
+--echo # LOCK TABLES.
+--echo #
+LOCK TABLES t1 READ;
+UNLOCK TABLES;
+
+--echo #
+--echo # CHECK/REPAIR/ANALYZE/OPTIMIZE and CHECKSUM.
+--echo #
+ANALYZE TABLE t1;
+CHECK TABLE t1;
+OPTIMIZE TABLE t1;
+REPAIR TABLE t1;
+
+--echo #
+--echo # REPLACE and REPLACE ... SELECT.
+--echo #
+INSERT INTO t3 VALUES (1, 111), (2, 222), (3, 333);
+REPLACE INTO t3 VALUES (1, 1111), (4, 444), (0, 001);
+REPLACE INTO t2 SELECT b FROM t3;
+SELECT * FROM t2 ORDER BY a;
+SELECT * FROM t3 ORDER BY a;
+
+--echo #
+--echo # CACHE and LOAD INDEX.
+--echo #
+CACHE INDEX t3 IN keycache1;
+LOAD INDEX INTO CACHE t3;
+
+--echo #
+--echo # RENAME (doesn't work for temporary tables, thus should fail).
+--echo #
+--error ER_TABLEACCESS_DENIED_ERROR
+RENAME TABLE t3 TO t3_1;
+
+--echo #
+--echo # HANDLER OPEN/READ/CLOSE.
+--echo #
+HANDLER t1 OPEN;
+HANDLER t1 READ NEXT;
+HANDLER t1 CLOSE;
+
+--echo #
+--echo # DO.
+--echo #
+DO (SELECT COUNT(*) FROM t1);
+
+--echo #
+--echo # CHECKSUM TABLE.
+--echo #
+DELETE FROM t1;
+CHECKSUM TABLE t1;
+
+--echo #
+--echo # CALL.
+--echo #
+CALL p0((SELECT COUNT(*) FROM t1));
+
+--echo #
+--echo # PREPARE, EXECUTE and DEALLOCATE.
+--echo #
+PREPARE stmt1 FROM 'SELECT * FROM t1 ORDER BY a';
+PREPARE stmt2 FROM 'SELECT * FROM t2 ORDER BY a';
+EXECUTE stmt1;
+EXECUTE stmt2;
+DEALLOCATE PREPARE stmt1;
+DEALLOCATE PREPARE stmt2;
+
+--echo #
+--echo # DROP TABLE and DROP TEMPORARY TABLE.
+--echo #
+DROP TABLE t1;
+
+CREATE TEMPORARY TABLE t1(a INT);
+DROP TEMPORARY TABLE t1;
+
+
+--echo ###########################################################################
+--echo # - Check that even having all privileges but CREATE_TMP_ACL is not enough
+--echo # to create temporary tables.
+--echo # - Check that creation/working with temporary tables is possible via
+--echo # SUID-stored-routines.
+--echo # - Check that even outside of SUID context we can access temporary
+--echo # table once it is created.
+--echo ###########################################################################
+
+--echo
+--echo # -- connect con2, mysqltest_u2@localhost, mysqltest_db1
+--connect (con2,localhost,mysqltest_u2,,mysqltest_db1)
+
+--error ER_DBACCESS_DENIED_ERROR
+CREATE TEMPORARY TABLE t2(a INT);
+
+CALL p1();
+
+CALL p2();
+
+CALL p3();
+
+--echo # Check that once table is created it can be accessed even
+--echo # outside of such a SUID context.
+INSERT INTO t4 VALUES (4);
+UPDATE t4 SET x = 10 WHERE x = 1;
+DELETE FROM t4 WHERE x < 3;
+SELECT * FROM t4 ORDER BY x;
+DROP TEMPORARY TABLE t4;
+
+--echo ###########################################################################
+--echo # - Check that once table is created it can be accessed from within any
+--echo # context, even by user without any privileges on tables.
+--echo ###########################################################################
+
+--echo
+--echo # -- connect con3, mysqltest_u4@localhost, mysqltest_db1
+--connect (con3,localhost,mysqltest_u4,,mysqltest_db1)
+
+CALL p1();
+INSERT INTO t4 VALUES (4);
+UPDATE t4 SET x = 10 WHERE x = 1;
+DELETE FROM t4 WHERE x < 3;
+SELECT * FROM t4 ORDER BY x;
+DROP TEMPORARY TABLE t4;
+
+--echo ###########################################################################
+--echo # Check special case for MERGE-tables:
+--echo # - CREATE_TMP_ACL is required to create a temporary merge table;
+--echo # - SELECT_ACL, UPDATE_ACL and DELETE_ACL are required to include
+--echo # a temporary table into the underlying-table-list.
+--echo ###########################################################################
+
+--echo
+--echo # -- connect con4, mysqltest_u5@localhost, mysqltest_db1
+--connect (con4,localhost,mysqltest_u5,,mysqltest_db1)
+
+CREATE TEMPORARY TABLE t7(a INT);
+CREATE TEMPORARY TABLE t8(a INT);
+CREATE TEMPORARY TABLE t9(a INT);
+CREATE TEMPORARY TABLE t10(a INT) ENGINE = MERGE UNION = (t7, t8);
+
+ALTER TABLE t10 UNION = (t9);
+--error ER_TABLEACCESS_DENIED_ERROR
+ALTER TABLE t10 UNION = (mysqltest_db2.t2_1);
+
+CREATE TEMPORARY TABLE mysqltest_db2.t2_2(a INT) ENGINE = MERGE UNION = (t7, t8);
+
+ALTER TABLE mysqltest_db2.t2_2 UNION = (t9);
+ALTER TABLE mysqltest_db2.t2_2 UNION = ();
+
+DROP TEMPORARY TABLE mysqltest_db2.t2_2;
+DROP TEMPORARY TABLE t10;
+
+DROP TEMPORARY TABLE t7;
+DROP TEMPORARY TABLE t8;
+DROP TEMPORARY TABLE t9;
+
+--echo ###########################################################################
+--echo # That's all. Cleanup.
+--echo ###########################################################################
+
+--echo
+--echo # -- connection: default
+--connection default
+
+--echo # -- disconnect con1
+--echo # All remaining temporary tables are automatically dropped.
+--disconnect con1
+
+--echo # -- disconnect con2
+--disconnect con2
+
+--echo # -- disconnect con3
+--disconnect con3
+
+--echo # -- disconnect con4
+--disconnect con4
+
+SET GLOBAL keycache1.key_buffer_size = 0;
+DROP DATABASE mysqltest_db1;
+DROP DATABASE mysqltest_db2;
+DROP USER mysqltest_u1@localhost;
+DROP USER mysqltest_u2@localhost;
+DROP USER mysqltest_u3@localhost;
+DROP USER mysqltest_u4@localhost;
+DROP USER mysqltest_u5@localhost;
+
+
# Wait till we reached the initial number of concurrent sessions
--source include/wait_until_count_sessions.inc
diff --git a/mysql-test/t/grant4.test b/mysql-test/t/grant4.test
index f3e551cd623..756454237f5 100644
--- a/mysql-test/t/grant4.test
+++ b/mysql-test/t/grant4.test
@@ -104,9 +104,7 @@ connection con1;
use mysqltest_db1;
--echo ** Connect as restricted user mysqltest_u1.
--echo ** SELECT FROM INFORMATION_SCHEMA.STATISTICS will succeed because any privileges will do (authentication is enough).
-#
-# this result is wrong. reported as bug#34104
-#
+--echo ** but will return no rows
SELECT * FROM INFORMATION_SCHEMA.STATISTICS WHERE table_name='t5';
#
# Bug27145 EXTRA_ACL trouble
@@ -144,3 +142,62 @@ connection default;
disconnect con1;
drop database mysqltest_db1;
drop user mysqltest_u1@localhost;
+
+
+--echo #
+--echo # Additional coverage for refactoring which is made as part
+--echo # of fix for bug #27480 "Extend CREATE TEMPORARY TABLES privilege
+--echo # to allow temp table operations".
+--echo #
+--echo # Check that for statements like CHECK/REPAIR and OPTIMIZE TABLE
+--echo # privileges for all tables involved are checked before processing
+--echo # any tables. Doing otherwise, i.e. checking privileges for table
+--echo # right before processing it might result in lost results for tables
+--echo # which were processed by the time when table for which privileges
+--echo # are insufficient are discovered.
+--echo #
+call mtr.add_suppression("Got an error from thread_id=.*ha_myisam.cc:");
+call mtr.add_suppression("MySQL thread id .*, query id .* localhost.*mysqltest_u1 Checking table");
+--disable_warnings
+drop database if exists mysqltest_db1;
+--enable_warnings
+let $MYSQLD_DATADIR = `SELECT @@datadir`;
+create database mysqltest_db1;
+--echo # Create tables which we are going to CHECK/REPAIR.
+create table mysqltest_db1.t1 (a int, key(a)) engine=myisam;
+create table mysqltest_db1.t2 (b int);
+insert into mysqltest_db1.t1 values (1), (2);
+insert into mysqltest_db1.t2 values (1);
+--echo # Create user which will try to do this.
+create user mysqltest_u1@localhost;
+grant insert, select on mysqltest_db1.t1 to mysqltest_u1@localhost;
+connect (con1,localhost,mysqltest_u1,,);
+connection default;
+
+--echo # Corrupt t1 by replacing t1.MYI with a corrupt + unclosed one created
+--echo # by doing: 'create table t1 (a int key(a))'
+--echo # head -c1024 t1.MYI > corrupt_t1.MYI
+flush table mysqltest_db1.t1;
+--remove_file $MYSQLD_DATADIR/mysqltest_db1/t1.MYI
+--copy_file std_data/corrupt_t1.MYI $MYSQLD_DATADIR/mysqltest_db1/t1.MYI
+
+--echo # Switching to connection 'con1'.
+connection con1;
+check table mysqltest_db1.t1;
+--echo # The below statement should fail before repairing t1.
+--echo # Otherwise info about such repair will be missing from its result-set.
+--error ER_TABLEACCESS_DENIED_ERROR
+repair table mysqltest_db1.t1, mysqltest_db1.t2;
+--echo # The same is true for CHECK TABLE statement.
+--error ER_TABLEACCESS_DENIED_ERROR
+check table mysqltest_db1.t1, mysqltest_db1.t2;
+check table mysqltest_db1.t1;
+repair table mysqltest_db1.t1;
+
+--echo # Clean-up.
+disconnect con1;
+--source include/wait_until_disconnected.inc
+--echo # Switching to connection 'default'.
+connection default;
+drop database mysqltest_db1;
+drop user mysqltest_u1@localhost;
diff --git a/mysql-test/t/grant5.test b/mysql-test/t/grant5.test
new file mode 100644
index 00000000000..14f2fd65020
--- /dev/null
+++ b/mysql-test/t/grant5.test
@@ -0,0 +1,25 @@
+-- source include/not_embedded.inc
+
+#
+# MDEV-6625 SHOW GRANTS for current_user_name@wrong_host_name
+#
+--error ER_NONEXISTING_GRANT
+SHOW GRANTS FOR root@invalid_host;
+
+#
+# MDEV-9580 SHOW GRANTS FOR <current_user> fails
+#
+create user test;
+create user foo;
+create role foo;
+grant foo to test;
+--connect (conn_1, localhost, test,,)
+set role foo;
+show grants for test; # user
+show grants for foo; # role
+--error ER_DBACCESS_DENIED_ERROR
+show grants for foo@'%'; # user
+--connection default
+drop user test, foo;
+drop role foo;
+
diff --git a/mysql-test/t/grant_4332.test b/mysql-test/t/grant_4332.test
index 302624e3873..d3c3b2d5652 100644
--- a/mysql-test/t/grant_4332.test
+++ b/mysql-test/t/grant_4332.test
@@ -1,19 +1,31 @@
#
# MDEV-4332 Increase username length from 16 characters
#
-
-# user names here have the pattern
-# <letter><length><more letters>0
-# where '0' at the end is the end-of-name marker
+# test that when ALTER-ing tables to have short usernames,
+# the server switches to short usernames internally too.
+#
--source include/not_embedded.inc
+alter table mysql.user modify User char(16) binary not null default '';
+alter table mysql.db modify User char(16) binary not null default '';
+alter table mysql.tables_priv modify User char(16) binary not null default '';
+alter table mysql.columns_priv modify User char(16) binary not null default '';
+alter table mysql.procs_priv modify User char(16) binary not null default '';
+alter table mysql.proc modify definer char(77) collate utf8_bin not null default '';
+alter table mysql.event modify definer char(77) collate utf8_bin not null default '';
+flush privileges;
+
--enable_metadata
select user();
--disable_metadata
--error ER_WRONG_STRING_LENGTH
create user a17aaaaaaaaaaaaa0@localhost;
+--error ER_WRONG_STRING_LENGTH
+grant usage on *.* to a17aaaaaaaaaaaaa0@lodalhost;
+--error ER_WRONG_STRING_LENGTH
+drop user a17aaaaaaaaaaaaa0@lodalhost;
alter table mysql.user modify User char(80) binary not null default '';
alter table mysql.db modify User char(80) binary not null default '';
@@ -22,106 +34,6 @@ alter table mysql.columns_priv modify User char(80) binary not null default '';
alter table mysql.procs_priv modify User char(80) binary not null default '';
alter table mysql.proc modify definer char(141) collate utf8_bin not null default '';
alter table mysql.event modify definer char(141) collate utf8_bin not null default '';
-
---source include/restart_mysqld.inc
-
-set global event_scheduler = on;
-
---enable_metadata
-select user();
---disable_metadata
-
-create user a17aaaaaaaaaaaaa0@localhost;
-grant usage on *.* to a17aaaaaaaaaaaaa0@localhost;
-grant select on mysql.user to b64bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb0@localhost;
-grant select(User) on mysql.tables_priv to c80cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc0@localhost;
-
-connect (a17,localhost,a17aaaaaaaaaaaaa0,,);
-connect (b64,localhost,b64bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb0,,);
-connect (c80,localhost,c80cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc0,,);
-
-connection a17;
-select user(), current_user();
-show grants;
-
-connection b64;
-select user(), current_user();
-show grants;
-select user,host from mysql.user where user like '%0';
---error ER_TABLEACCESS_DENIED_ERROR
-select user,host from mysql.db;
-
-connection c80;
-select user(), current_user();
-show grants;
-select user from mysql.tables_priv;
---error ER_COLUMNACCESS_DENIED_ERROR
-select user,host from mysql.tables_priv;
-
---error ER_DBACCESS_DENIED_ERROR
-use mtr;
-
---error ER_PROCACCESS_DENIED_ERROR
-drop procedure mtr.add_suppression;
-
-create procedure test.p1() select user(), current_user(), user from mysql.tables_priv;
-
-show create procedure test.p1;
-
-select definer from information_schema.routines;
-
-create table test.t1 (a text);
-create event e1 on schedule every 1 second
- do insert test.t1 values (concat(user(), ' ', current_user()));
-
-select definer from information_schema.events;
-
-create view v1 as select * from t1;
-select definer from information_schema.views;
-drop view v1;
-
-create trigger tr1 before delete on t1 for each row set @a:=1;
-select definer from information_schema.triggers;
-drop trigger tr1;
-
-connection default;
-
---replace_result $MASTER_MYSOCK MASTER_SOCKET $MASTER_MYPORT MASTER_PORT
---error ER_ACCESS_DENIED_ERROR
-connect (c80bad,localhost,c80cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc0,foobar,);
-
-call test.p1();
-
-disconnect a17;
-disconnect b64;
-disconnect c80;
-
-let $wait_timeout= 10;
-let $wait_condition= SELECT 1 from t1;
---source include/wait_condition.inc
-
-select * from t1 limit 1;
---error ER_WRONG_STRING_LENGTH
-grant usage on *.* to d81ddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd0@lodalhost;
-
---error ER_WRONG_STRING_LENGTH
-drop user d81ddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd0@lodalhost;
-drop user c80cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc0@localhost;
-drop user b64bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb0@localhost;
-drop user a17aaaaaaaaaaaaa0@localhost;
-
-set global event_scheduler = off;
-drop event e1;
-drop procedure test.p1;
-drop table t1;
-
-alter table mysql.user modify User char(16) binary not null default '';
-alter table mysql.db modify User char(16) binary not null default '';
-alter table mysql.tables_priv modify User char(16) binary not null default '';
-alter table mysql.columns_priv modify User char(16) binary not null default '';
-alter table mysql.procs_priv modify User char(16) binary not null default '';
-alter table mysql.proc modify definer char(77) collate utf8_bin not null default '';
-alter table mysql.event modify definer char(77) collate utf8_bin not null default '';
flush privileges;
--enable_metadata
diff --git a/mysql-test/t/grant_explain_non_select.test b/mysql-test/t/grant_explain_non_select.test
new file mode 100644
index 00000000000..d59a8f3d8ce
--- /dev/null
+++ b/mysql-test/t/grant_explain_non_select.test
@@ -0,0 +1,258 @@
+#
+# Privilege-specific tests for WL#4897: Add EXPLAIN INSERT/UPDATE/DELETE
+#
+
+# Grant tests not performed with embedded server
+-- source include/not_embedded.inc
+
+# Save the initial number of concurrent sessions
+--source include/count_sessions.inc
+
+CREATE DATABASE privtest_db;
+
+CREATE TABLE privtest_db.t1 (a INT);
+CREATE TABLE privtest_db.t2 (a INT);
+INSERT INTO privtest_db.t2 VALUES (1), (2), (3);
+
+GRANT USAGE ON *.* TO 'privtest'@'localhost';
+GRANT SELECT ON privtest_db.t2 TO 'privtest'@'localhost';
+
+connect(con1,localhost,privtest,,);
+connection con1;
+
+USE privtest_db;
+
+--error ER_TABLEACCESS_DENIED_ERROR
+EXPLAIN INSERT INTO t1 VALUES (10);
+--error ER_TABLEACCESS_DENIED_ERROR
+ INSERT INTO t1 VALUES (10);
+
+--error ER_TABLEACCESS_DENIED_ERROR
+EXPLAIN INSERT INTO t1 SELECT * FROM t2;
+--error ER_TABLEACCESS_DENIED_ERROR
+ INSERT INTO t1 SELECT * FROM t2;
+
+connection default;
+GRANT INSERT ON privtest_db.t1 TO 'privtest'@'localhost';
+connection con1;
+
+EXPLAIN INSERT INTO t1 VALUES (10);
+ INSERT INTO t1 VALUES (10);
+
+EXPLAIN INSERT INTO t1 SELECT * FROM t2;
+ INSERT INTO t1 SELECT * FROM t2;
+
+
+connection default;
+REVOKE ALL PRIVILEGES ON privtest_db.t1 FROM 'privtest'@'localhost';
+connection con1;
+
+--error ER_TABLEACCESS_DENIED_ERROR
+EXPLAIN REPLACE INTO t1 VALUES (10);
+--error ER_TABLEACCESS_DENIED_ERROR
+ REPLACE INTO t1 VALUES (10);
+
+--error ER_TABLEACCESS_DENIED_ERROR
+EXPLAIN REPLACE INTO t1 SELECT * FROM t2;
+--error ER_TABLEACCESS_DENIED_ERROR
+ REPLACE INTO t1 SELECT * FROM t2;
+
+connection default;
+GRANT INSERT ON privtest_db.t1 TO 'privtest'@'localhost';
+connection con1;
+
+--error ER_TABLEACCESS_DENIED_ERROR
+EXPLAIN REPLACE INTO t1 VALUES (10);
+--error ER_TABLEACCESS_DENIED_ERROR
+ REPLACE INTO t1 VALUES (10);
+
+--error ER_TABLEACCESS_DENIED_ERROR
+EXPLAIN REPLACE INTO t1 SELECT * FROM t2;
+--error ER_TABLEACCESS_DENIED_ERROR
+ REPLACE INTO t1 SELECT * FROM t2;
+
+connection default;
+REVOKE INSERT ON privtest_db.t1 FROM 'privtest'@'localhost';
+GRANT DELETE ON privtest_db.t1 TO 'privtest'@'localhost';
+connection con1;
+
+--error ER_TABLEACCESS_DENIED_ERROR
+EXPLAIN REPLACE INTO t1 VALUES (10);
+--error ER_TABLEACCESS_DENIED_ERROR
+ REPLACE INTO t1 VALUES (10);
+
+--error ER_TABLEACCESS_DENIED_ERROR
+EXPLAIN REPLACE INTO t1 SELECT * FROM t2;
+--error ER_TABLEACCESS_DENIED_ERROR
+ REPLACE INTO t1 SELECT * FROM t2;
+
+connection default;
+GRANT INSERT, DELETE ON privtest_db.t1 TO 'privtest'@'localhost';
+connection con1;
+
+EXPLAIN REPLACE INTO t1 VALUES (10);
+ REPLACE INTO t1 VALUES (10);
+
+EXPLAIN REPLACE INTO t1 SELECT * FROM t2;
+ REPLACE INTO t1 SELECT * FROM t2;
+
+connection default;
+REVOKE ALL PRIVILEGES ON privtest_db.t1 FROM 'privtest'@'localhost';
+connection con1;
+
+--error ER_TABLEACCESS_DENIED_ERROR
+EXPLAIN UPDATE t1 SET a = a + 1;
+--error ER_TABLEACCESS_DENIED_ERROR
+ UPDATE t1 SET a = a + 1;
+
+--error ER_TABLEACCESS_DENIED_ERROR
+EXPLAIN UPDATE t1, t2 SET t1.a = t1.a + 1 WHERE t1.a = t2.a;
+--error ER_TABLEACCESS_DENIED_ERROR
+ UPDATE t1, t2 SET t1.a = t1.a + 1 WHERE t1.a = t2.a;
+
+connection default;
+GRANT UPDATE ON privtest_db.t1 TO 'privtest'@'localhost';
+connection con1;
+
+--error ER_COLUMNACCESS_DENIED_ERROR
+EXPLAIN UPDATE t1 SET a = a + 1;
+--error ER_COLUMNACCESS_DENIED_ERROR
+ UPDATE t1 SET a = a + 1;
+
+--error ER_COLUMNACCESS_DENIED_ERROR
+EXPLAIN UPDATE t1, t2 SET t1.a = t1.a + 1 WHERE t1.a = t2.a;
+--error ER_COLUMNACCESS_DENIED_ERROR
+ UPDATE t1, t2 SET t1.a = t1.a + 1 WHERE t1.a = t2.a;
+
+connection default;
+REVOKE UPDATE ON privtest_db.t1 FROM 'privtest'@'localhost';
+GRANT SELECT ON privtest_db.t1 TO 'privtest'@'localhost';
+connection con1;
+
+--error ER_TABLEACCESS_DENIED_ERROR
+EXPLAIN UPDATE t1 SET a = a + 1;
+--error ER_TABLEACCESS_DENIED_ERROR
+ UPDATE t1 SET a = a + 1;
+
+--error ER_TABLEACCESS_DENIED_ERROR
+EXPLAIN UPDATE t1, t2 SET t1.a = t1.a + 1 WHERE t1.a = t2.a;
+--error ER_TABLEACCESS_DENIED_ERROR
+ UPDATE t1, t2 SET t1.a = t1.a + 1 WHERE t1.a = t2.a;
+
+connection default;
+GRANT UPDATE, SELECT ON privtest_db.t1 TO 'privtest'@'localhost';
+connection con1;
+
+EXPLAIN UPDATE t1 SET a = a + 1;
+ UPDATE t1 SET a = a + 1;
+
+EXPLAIN UPDATE t1, t2 SET t1.a = t1.a + 1 WHERE t1.a = t2.a;
+ UPDATE t1, t2 SET t1.a = t1.a + 1 WHERE t1.a = t2.a;
+
+connection default;
+REVOKE ALL PRIVILEGES ON privtest_db.t1 FROM 'privtest'@'localhost';
+connection con1;
+
+--error ER_TABLEACCESS_DENIED_ERROR
+EXPLAIN DELETE FROM t1 WHERE a = 10;
+--error ER_TABLEACCESS_DENIED_ERROR
+ DELETE FROM t1 WHERE a = 10;
+
+--error ER_TABLEACCESS_DENIED_ERROR
+EXPLAIN DELETE FROM t1 USING t1, t2 WHERE t1.a = t2.a;
+--error ER_TABLEACCESS_DENIED_ERROR
+ DELETE FROM t1 USING t1, t2 WHERE t1.a = t2.a;
+
+connection default;
+GRANT DELETE ON privtest_db.t1 TO 'privtest'@'localhost';
+connection con1;
+
+--error ER_COLUMNACCESS_DENIED_ERROR
+EXPLAIN DELETE FROM t1 WHERE a = 10;
+--error ER_COLUMNACCESS_DENIED_ERROR
+ DELETE FROM t1 WHERE a = 10;
+
+--error ER_TABLEACCESS_DENIED_ERROR
+EXPLAIN DELETE FROM t1 USING t1, t2 WHERE t1.a = t2.a;
+--error ER_TABLEACCESS_DENIED_ERROR
+ DELETE FROM t1 USING t1, t2 WHERE t1.a = t2.a;
+
+connection default;
+REVOKE ALL PRIVILEGES ON privtest_db.t1 FROM 'privtest'@'localhost';
+GRANT SELECT ON privtest_db.t1 TO 'privtest'@'localhost';
+connection con1;
+
+--error ER_TABLEACCESS_DENIED_ERROR
+EXPLAIN DELETE FROM t1 WHERE a = 10;
+--error ER_TABLEACCESS_DENIED_ERROR
+ DELETE FROM t1 WHERE a = 10;
+
+--error ER_TABLEACCESS_DENIED_ERROR
+EXPLAIN DELETE FROM t1 USING t1, t2 WHERE t1.a = t2.a;
+--error ER_TABLEACCESS_DENIED_ERROR
+ DELETE FROM t1 USING t1, t2 WHERE t1.a = t2.a;
+
+connection default;
+REVOKE ALL PRIVILEGES ON privtest_db.t1 FROM 'privtest'@'localhost';
+GRANT DELETE, SELECT ON privtest_db.t1 TO 'privtest'@'localhost';
+connection con1;
+
+EXPLAIN DELETE FROM t1 WHERE a = 10;
+ DELETE FROM t1 WHERE a = 10;
+
+EXPLAIN DELETE FROM t1 USING t1, t2 WHERE t1.a = t2.a;
+ DELETE FROM t1 USING t1, t2 WHERE t1.a = t2.a;
+
+# Views
+
+connection default;
+REVOKE ALL PRIVILEGES ON privtest_db.t1 FROM 'privtest'@'localhost';
+CREATE VIEW privtest_db.v1 (a) AS SELECT a FROM privtest_db.t1;
+GRANT SELECT, INSERT, UPDATE, DELETE ON privtest_db.v1 TO 'privtest'@'localhost';
+connection con1;
+
+--error ER_VIEW_NO_EXPLAIN
+EXPLAIN SELECT * FROM v1;
+ SELECT * FROM v1;
+
+--error ER_VIEW_NO_EXPLAIN
+EXPLAIN INSERT INTO v1 VALUES (10);
+ INSERT INTO v1 VALUES (10);
+
+--error ER_VIEW_NO_EXPLAIN
+EXPLAIN INSERT INTO v1 SELECT * FROM t2;
+ INSERT INTO v1 SELECT * FROM t2;
+
+--error ER_VIEW_NO_EXPLAIN
+EXPLAIN REPLACE INTO v1 VALUES (10);
+ REPLACE INTO v1 VALUES (10);
+
+--error ER_VIEW_NO_EXPLAIN
+EXPLAIN REPLACE INTO v1 SELECT * FROM t2;
+ REPLACE INTO v1 SELECT * FROM t2;
+
+--error ER_VIEW_NO_EXPLAIN
+EXPLAIN UPDATE v1 SET a = a + 1;
+ UPDATE v1 SET a = a + 1;
+
+--error ER_VIEW_NO_EXPLAIN
+EXPLAIN UPDATE v1, t2 SET v1.a = v1.a + 1 WHERE v1.a = t2.a;
+ UPDATE v1, t2 SET v1.a = v1.a + 1 WHERE v1.a = t2.a;
+
+--error ER_VIEW_NO_EXPLAIN
+EXPLAIN DELETE FROM v1 WHERE a = 10;
+ DELETE FROM v1 WHERE a = 10;
+
+--error ER_VIEW_NO_EXPLAIN
+EXPLAIN DELETE FROM v1 USING v1, t2 WHERE v1.a = t2.a;
+ DELETE FROM v1 USING v1, t2 WHERE v1.a = t2.a;
+
+connection default;
+disconnect con1;
+
+DROP USER 'privtest'@localhost;
+USE test;
+DROP DATABASE privtest_db;
+
+# Wait till we reached the initial number of concurrent sessions
+--source include/wait_until_count_sessions.inc
diff --git a/mysql-test/t/grant_lowercase.test b/mysql-test/t/grant_lowercase.test
index b07cb88afd6..4fc5facf808 100644
--- a/mysql-test/t/grant_lowercase.test
+++ b/mysql-test/t/grant_lowercase.test
@@ -19,13 +19,13 @@ drop user user1@localhost;
# in acl_load()
call mtr.add_suppression("Incorrect database name");
alter table mysql.host modify Db varchar(200);
-alter table mysql.db modify Db varchar(200);
+alter table mysql.db modify User char(16), modify Db varchar(200);
insert mysql.host set db=concat('=>', repeat(_utf8 'й', 200));
insert mysql.db set db=concat('=>', repeat(_utf8 'й', 200));
flush privileges; # shouldn't crash here
delete from mysql.host where db like '=>%';
delete from mysql.db where db like '=>%';
alter table mysql.host modify Db char(64);
-alter table mysql.db modify Db char(64);
+alter table mysql.db modify Db char(64), modify User char(80);
flush privileges;
diff --git a/mysql-test/t/group_by.test b/mysql-test/t/group_by.test
index 43274532b3e..d941fa22830 100644
--- a/mysql-test/t/group_by.test
+++ b/mysql-test/t/group_by.test
@@ -287,14 +287,14 @@ SELECT a,count(*) FROM t1 GROUP BY binary a;
SELECT binary a FROM t1 GROUP BY 1;
SELECT binary a,count(*) FROM t1 GROUP BY 1;
# Do the same tests with MyISAM temporary tables
-SET SQL_BIG_TABLES=1;
+SET BIG_TABLES=1;
SELECT a FROM t1 GROUP BY a;
SELECT a,count(*) FROM t1 GROUP BY a;
SELECT a FROM t1 GROUP BY binary a;
SELECT a,count(*) FROM t1 GROUP BY binary a;
SELECT binary a FROM t1 GROUP BY 1;
SELECT binary a,count(*) FROM t1 GROUP BY 1;
-SET SQL_BIG_TABLES=0;
+SET BIG_TABLES=0;
drop table t1;
#
@@ -391,7 +391,7 @@ drop table t1,t2,t3;
create table t1 (a blob null);
insert into t1 values (NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(""),(""),(""),("b");
select a,count(*) from t1 group by a;
-set option sql_big_tables=1;
+set big_tables=1;
select a,count(*) from t1 group by a;
drop table t1;
@@ -1310,7 +1310,7 @@ DROP TABLE t1;
--echo # by functions
--echo #
-SET SQL_BIG_TABLES=1;
+SET BIG_TABLES=1;
CREATE TABLE t1(a INT);
INSERT INTO t1 VALUES (0),(0);
SELECT 1 FROM t1 GROUP BY IF(`a`,'','');
@@ -1318,7 +1318,7 @@ SELECT 1 FROM t1 GROUP BY TRIM(LEADING RAND() FROM '');
SELECT 1 FROM t1 GROUP BY SUBSTRING('',SLEEP(0),'');
SELECT 1 FROM t1 GROUP BY SUBSTRING(SYSDATE() FROM 'K' FOR 'jxW<');
DROP TABLE t1;
-SET SQL_BIG_TABLES=0;
+SET BIG_TABLES=0;
--echo #
--echo # MDEV-641 LP:1002108 - Wrong result (or crash) from a query with duplicated field in the group list and a limit clause
@@ -1334,7 +1334,7 @@ INSERT INTO t1 VALUES (1),(2),(3),(4),(5),(6),(7),(8),(9),(10),
(11),(12),(13),(14),(15),(16),(17),(18),(19),(20);
let $query0=SELECT col1 AS field1, col1 AS field2
- FROM t1 GROUP BY field1, field2+0;
+ FROM t1 GROUP BY field1, field2;
# Needs to be range to exercise bug
--eval EXPLAIN $query0;
@@ -1496,8 +1496,7 @@ CREATE TABLE t1 (
b varchar(1),
KEY (b,a)
);
-
-INSERT INTO t1 VALUES (1,NULL),(0,'a');
+INSERT INTO t1 VALUES (1,NULL),(0,'a'),(1,NULL),(0,'a');
let $query=
SELECT SQL_BUFFER_RESULT MIN(a), b FROM t1 WHERE t1.b = 'a' GROUP BY b;
@@ -1770,3 +1769,53 @@ DROP TABLE t1;
#
# End of MariaDB 5.5 tests
#
+
+--echo #
+--echo # Bug #58782
+--echo # Missing rows with SELECT .. WHERE .. IN subquery
+--echo # with full GROUP BY and no aggr
+--echo #
+
+CREATE TABLE t1 (
+ pk INT NOT NULL,
+ col_int_nokey INT,
+ PRIMARY KEY (pk)
+);
+
+INSERT INTO t1 VALUES (10,7);
+INSERT INTO t1 VALUES (11,1);
+INSERT INTO t1 VALUES (12,5);
+INSERT INTO t1 VALUES (13,3);
+
+## original query:
+
+SELECT pk AS field1, col_int_nokey AS field2
+FROM t1
+WHERE col_int_nokey > 0
+GROUP BY field1, field2;
+
+## store query results in a new table:
+
+CREATE TABLE where_subselect
+ SELECT pk AS field1, col_int_nokey AS field2
+ FROM t1
+ WHERE col_int_nokey > 0
+ GROUP BY field1, field2
+;
+
+## query the new table and compare to original using WHERE ... IN():
+
+SELECT *
+FROM where_subselect
+WHERE (field1, field2) IN (
+ SELECT pk AS field1, col_int_nokey AS field2
+ FROM t1
+ WHERE col_int_nokey > 0
+ GROUP BY field1, field2
+);
+
+DROP TABLE t1;
+DROP TABLE where_subselect;
+
+--echo # End of Bug #58782
+
diff --git a/mysql-test/t/group_by_innodb.test b/mysql-test/t/group_by_innodb.test
index df213cc189f..074df222294 100644
--- a/mysql-test/t/group_by_innodb.test
+++ b/mysql-test/t/group_by_innodb.test
@@ -67,3 +67,72 @@ DROP TABLE t1;
--echo End of 5.5 tests
+--echo #
+--echo # MDEV-5719: Wrong result with GROUP BY and LEFT OUTER JOIN
+--echo #
+CREATE TABLE t1 (oidGroup INT, oid INT PRIMARY KEY)ENGINE=INNODB;
+INSERT INTO t1 VALUES (1,1),(1,2),(1,3),(1,4);
+
+CREATE TABLE t2 (oid INT PRIMARY KEY)ENGINE=INNODB;
+INSERT INTO t2 VALUES (3);
+
+# Returns a value
+SELECT a.oidGroup, a.oid, b.oid FROM t1 a LEFT JOIN t2 b ON
+a.oid=b.oid WHERE a.oidGroup=1;
+
+SELECT a.oidGroup, a.oid, b.oid FROM t1 a LEFT JOIN t2 b ON
+a.oid=b.oid WHERE a.oidGroup=1 GROUP BY a.oid;
+
+DROP TABLE t1, t2;
+
+--echo #
+--echo # MDEV-7193: Incorrect Query Result (MySQL Bug 68897) in MariaDB 10.0.14
+--echo # (fixed by MDEV-5719)
+--echo #
+
+CREATE TABLE `t1` (
+ `param` int(11) NOT NULL,
+ `idx` int(11) NOT NULL,
+ `text` varchar(255) default NULL,
+ PRIMARY KEY (`param`,`idx`)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8;
+
+INSERT INTO `t1` (`param`, `idx`, `text`) VALUES
+(1, 0, 'select'),
+(1, 1, 'Kabel mit Stecker 5-polig'),
+(1, 2, 'Kabel ohne Stecker'),
+(2, 0, 'number'),
+(2, 1, '22'),
+(2, 2, '25');
+CREATE TABLE `t2` (
+ `id` int PRIMARY KEY
+);
+
+INSERT INTO t2 VALUES (1),(2),(3),(4);
+SELECT t2.id AS id, T.text AS xtext,GROUP_CONCAT(T3.text) AS optionen
+FROM t2
+LEFT JOIN t1 AS T ON(T.param=t2.id AND T.idx=0 )
+LEFT JOIN t1 AS T3 ON(T3.param=t2.id AND T3.idx>0 )
+GROUP BY t2.id
+ORDER BY id ASC;
+
+SELECT t2.id AS id, T.text AS xtext,GROUP_CONCAT(T3.text) AS optionen
+FROM t2
+LEFT JOIN t1 AS T ON(T.param=t2.id AND T.idx=0 )
+LEFT JOIN t1 AS T3 ON(T3.param=t2.id AND T3.idx>0 )
+GROUP BY t2.id
+ORDER BY id DESC;
+
+DROP TABLE t1, t2;
+
+--echo #
+--echo # MDEV-11162: Assertion `num_records == m_idx_array.size()' failed in Filesort_buffer::alloc_sort_buffer(uint, uint)
+--echo #
+
+CREATE TABLE t1 (i INT) ENGINE=InnoDB;
+SELECT ( SELECT DISTINCT GROUP_CONCAT(SLEEP(0)) FROM t1 GROUP BY i );
+SELECT i FROM t1 order by i LIMIT 1;
+DROP TABLE t1;
+
+--echo # End of tests
+
diff --git a/mysql-test/t/group_min_max.test b/mysql-test/t/group_min_max.test
index 8d5863db176..8c9be0ca8db 100644
--- a/mysql-test/t/group_min_max.test
+++ b/mysql-test/t/group_min_max.test
@@ -15,7 +15,7 @@ drop table if exists t1;
--enable_warnings
create table t1 (
- a1 char(64), a2 char(64), b char(16), c char(16) not null, d char(16), dummy char(64) default ' '
+ a1 char(64), a2 char(64), b char(16), c char(16) not null, d char(16), dummy char(248) default ' '
);
insert into t1 (a1, a2, b, c, d) values
@@ -65,7 +65,7 @@ drop table if exists t2;
--enable_warnings
create table t2 (
- a1 char(64), a2 char(64) not null, b char(16), c char(16), d char(16), dummy char(64) default ' '
+ a1 char(64), a2 char(64) not null, b char(16), c char(16), d char(16), dummy char(248) default ' '
);
insert into t2 select * from t1;
# add few rows with NULL's in the MIN/MAX column
@@ -697,6 +697,19 @@ explain select a1,a2,count(a2) from t1 group by a1,a2,b;
explain extended select a1,a2,count(a2) from t1 where (a1 > 'a') group by a1,a2,b;
explain extended select sum(ord(a1)) from t1 where (a1 > 'a') group by a1,a2,b;
+#
+# MDEV-4120 UNIQUE indexes should not be considered for loose index scan
+#
+
+create table t4 as select distinct a1, a2, b, c from t1;
+alter table t4 add unique index idxt4 (a1, a2, b, c);
+
+--echo # This is "superceded" by MDEV-7118, and Loose Index Scan is again an option:
+explain
+select a1, a2, b, min(c) from t4 group by a1, a2, b;
+select a1, a2, b, min(c) from t4 group by a1, a2, b;
+
+drop table t4;
#
# Bug #16710: select distinct doesn't return all it should
@@ -816,7 +829,7 @@ DROP PROCEDURE a;
# Bug #18068: SELECT DISTINCT
#
-CREATE TABLE t1 (a varchar(64) NOT NULL default '', PRIMARY KEY(a));
+CREATE TABLE t1 (a varchar(64) NOT NULL default '', KEY(a));
INSERT INTO t1 (a) VALUES
(''), ('CENTRAL'), ('EASTERN'), ('GREATER LONDON'),
@@ -879,7 +892,7 @@ DROP TABLE t1,t2,t3,t4,t5,t6;
#
# Bug#22342: No results returned for query using max and group by
#
-CREATE TABLE t1 (a int, b int, PRIMARY KEY (a,b), KEY b (b));
+CREATE TABLE t1 (a int, b int, KEY (a,b), KEY b (b));
INSERT INTO t1 VALUES (1,1),(1,2),(1,0),(1,3);
explain SELECT MAX(b), a FROM t1 WHERE b < 2 AND a = 1 GROUP BY a;
@@ -1003,7 +1016,7 @@ DROP TABLE t1;
# Bug#38195: Incorrect handling of aggregate functions when loose index scan is
# used causes server crash.
#
-create table t1 (a int, b int, primary key (a,b), key `index` (a,b)) engine=MyISAM;
+create table t1 (a int, b int, key (a,b), key `index` (a,b)) engine=MyISAM;
insert into t1 (a,b) values
(0,0),(0,1),(0,2),(0,3),(0,4),(0,5),(0,6),
(0,7),(0,8),(0,9),(0,10),(0,11),(0,12),(0,13),
@@ -1046,6 +1059,7 @@ DROP TABLE t1;
CREATE TABLE t (a INT, b INT, INDEX (a,b));
INSERT INTO t VALUES (2,0), (2,0), (2,1), (2,1);
INSERT INTO t SELECT * FROM t;
+INSERT INTO t SELECT * FROM t;
--echo # test MIN
--echo #should use range with index for group by
@@ -1245,6 +1259,7 @@ drop table t1;
CREATE TABLE t1 (a int, b int, KEY (b, a)) ;
INSERT INTO t1 VALUES (0,99),(9,99),(4,0),(7,0),(99,0),(7,0),(8,0),(99,0),(1,0);
+INSERT INTO t1 VALUES (0,99),(9,99),(4,0),(7,0),(99,0),(7,0),(8,0),(99,0),(1,0);
CREATE TABLE t2 (c int) ;
INSERT INTO t2 VALUES (0),(1);
@@ -1392,7 +1407,7 @@ DROP TABLE t1,t2;
CREATE TABLE t1 (
f1 int(11) NOT NULL DEFAULT '0',
f2 char(1) NOT NULL DEFAULT '',
- PRIMARY KEY (f1,f2)
+ KEY (f1,f2)
) ;
insert into t1 values(1,'A'),(1 , 'B'), (1, 'C'), (2, 'A'),
(3, 'A'), (3, 'B'), (3, 'C'), (3, 'D');
@@ -1474,3 +1489,38 @@ SELECT distinct a, b FROM t1 where a = '3' ORDER BY b;
SELECT distinct a, b FROM t1 where a = '3' ORDER BY b;
drop table t1;
+
+--echo #
+--echo # Start of 10.0 tests
+--echo #
+
+--echo #
+--echo # MDEV-6991 GROUP_MIN_MAX optimization is erroneously applied in some cases
+--echo #
+CREATE TABLE t1 (id INT NOT NULL, a VARCHAR(20)) ENGINE=MyISAM;
+INSERT INTO t1 VALUES (1,'2001-01-01');
+INSERT INTO t1 VALUES (1,'2001-01-02');
+INSERT INTO t1 VALUES (1,'2001-01-03');
+INSERT INTO t1 VALUES (1,' 2001-01-04');
+INSERT INTO t1 VALUES (2,'2001-01-01');
+INSERT INTO t1 VALUES (2,'2001-01-02');
+INSERT INTO t1 VALUES (2,'2001-01-03');
+INSERT INTO t1 VALUES (2,' 2001-01-04');
+INSERT INTO t1 VALUES (3,'2001-01-01');
+INSERT INTO t1 VALUES (3,'2001-01-02');
+INSERT INTO t1 VALUES (3,'2001-01-03');
+INSERT INTO t1 VALUES (3,' 2001-01-04');
+INSERT INTO t1 VALUES (4,'2001-01-01');
+INSERT INTO t1 VALUES (4,'2001-01-02');
+INSERT INTO t1 VALUES (4,'2001-01-03');
+INSERT INTO t1 VALUES (4,' 2001-01-04');
+SELECT id,MIN(a),MAX(a) FROM t1 WHERE a>=DATE'2001-01-04' GROUP BY id;
+ALTER TABLE t1 ADD KEY(id,a);
+SELECT id,MIN(a),MAX(a) FROM t1 WHERE a>=DATE'2001-01-04' GROUP BY id;
+DROP TABLE t1;
+
+
+--echo #
+--echo # End of 10.0 tests
+--echo #
+
diff --git a/mysql-test/t/having.test b/mysql-test/t/having.test
index a470f462d6a..51cf3fb426d 100644
--- a/mysql-test/t/having.test
+++ b/mysql-test/t/having.test
@@ -744,3 +744,37 @@ SELECT a, COUNT(a) as ct FROM t1 GROUP BY a HAVING ct>0;
set sql_mode=@save_sql_mode;
drop table t1;
+
+--echo #
+--echo # Bug mdev-5160: two-way join with HAVING over the second table
+--echo #
+
+CREATE TABLE t1 (c1 varchar(6)) ENGINE=MyISAM;
+INSERT INTO t1 VALUES ('s'), ('t'), ('a'), ('x');
+
+CREATE TABLE t2 (c2 varchar(6)) ENGINE=MyISAM;
+INSERT INTO t2 VALUES ('a'), ('x');
+
+SELECT * FROM t1 JOIN t2 ON c1 = c2 HAVING c2 > 'a' ORDER BY c2 LIMIT 1;
+
+DROP TABLE t1,t2;
+
+--echo #
+--echo # MDEV-6736: Valgrind warnings 'Invalid read' in subselect_engine::calc_const_tables with SQ
+--echo # in WHERE and HAVING, ORDER BY, materialization+semijoin
+--echo #
+
+CREATE TABLE t1 (a INT) ENGINE=MyISAM;
+INSERT INTO t1 VALUES (3),(8);
+
+CREATE TABLE t2 (b INT) ENGINE=MyISAM;
+INSERT INTO t2 VALUES (2),(1);
+
+SELECT a FROM t1
+WHERE 9 IN ( SELECT MIN( a ) FROM t1 )
+HAVING a <> ( SELECT COUNT(*) FROM t2 )
+ORDER BY a;
+
+DROP TABLE t1,t2;
+
+--echo End of 10.0 tests
diff --git a/mysql-test/t/help.test b/mysql-test/t/help.test
index 71821e46771..881299a216c 100644
--- a/mysql-test/t/help.test
+++ b/mysql-test/t/help.test
@@ -61,6 +61,12 @@ help '%function_7';
help '%category_2';
help 'impossible_function_1';
help 'impossible_category_1';
+
+--echo # MDEV-9524 Cannot load from mysql.event when sql_mode is set to PAD_CHAR_TO_FULL_LENGTH
+help 'impossible_function_1';
+SET sql_mode=PAD_CHAR_TO_FULL_LENGTH;
+help 'impossible_function_1';
+SET sql_mode=DEFAULT;
##############
--disable_warnings
diff --git a/mysql-test/t/host_cache_size_functionality.test b/mysql-test/t/host_cache_size_functionality.test
new file mode 100644
index 00000000000..1696c2fcb97
--- /dev/null
+++ b/mysql-test/t/host_cache_size_functionality.test
@@ -0,0 +1,185 @@
+###############################################################################
+# #
+# Variable Name: Host_Cache_Size #
+# Scope: Global #
+# Access Type: Dynamic #
+# Data Type: numeric #
+# #
+# #
+# Creation Date: 2012-08-31 #
+# Author : Tanjot Singh Uppal #
+# #
+# #
+# Description:Test Cases of Dynamic System Variable Host_Cache_Size #
+# that checks the behavior of this variable in the following ways #
+# * Value Check #
+# * Scope Check #
+# * Functionality Check #
+# * Accessability Check #
+# #
+# This test does not perform the crash recovery on this variable #
+# For crash recovery test on default change please run the ibtest #
+###############################################################################
+
+-- source include/have_innodb.inc
+-- source include/not_embedded.inc
+-- source include/have_innodb_16k.inc
+--disable_warnings
+echo '#________________________VAR_06_Host_Cache_Size__________________#'
+echo '##'
+--echo '#---------------------WL6372_VAR_6_01----------------------#'
+####################################################################
+# Checking default value #
+####################################################################
+SELECT COUNT(@@GLOBAL.Host_Cache_Size);
+--echo 1 Expected
+
+#set @Default_host_cache_size=(select if(if(@@global.max_connections<500,128+@@global.max_connections,128+@@global.max_connections+floor((@@global.max_connections-500)/20))>2000,2000,if(@@global.max_connections<500,128+@@global.max_connections,128+@@global.max_connections+floor((@@global.max_connections-500)/20))));
+set @Default_host_cache_size=128;
+
+select @@global.Host_Cache_Size=@Default_host_cache_size;
+--echo 1 Expected
+
+
+--echo '#---------------------WL6372_VAR_6_02----------------------#'
+#################################################################################
+# Checking the Default value post starting the server with other value #
+#################################################################################
+--echo # Restart server with Host_Cache_Size 1
+
+let $restart_file= $MYSQLTEST_VARDIR/tmp/mysqld.1.expect;
+--exec echo "wait" > $restart_file
+--shutdown_server 10
+--source include/wait_until_disconnected.inc
+-- exec echo "restart:--host_cache_size=1 " > $MYSQLTEST_VARDIR/tmp/mysqld.1.expect
+-- enable_reconnect
+-- source include/wait_until_connected_again.inc
+
+--disable_warnings
+
+SELECT @@GLOBAL.Host_Cache_Size;
+--echo 1 Expected
+
+#set @Default_host_cache_size=(select if(if(@@global.max_connections<500,128+@@global.max_connections,128+@@global.max_connections+floor((@@global.max_connections-500)/20))>2000,2000,if(@@global.max_connections<500,128+@@global.max_connections,128+@@global.max_connections+floor((@@global.max_connections-500)/20))));
+set @Default_host_cache_size=128;
+SET @@GLOBAL.Host_Cache_Size=DEFAULT;
+select @@global.Host_Cache_Size=@Default_host_cache_size;
+--echo 1 Expected
+
+
+--echo '#---------------------WL6372_VAR_6_03----------------------#'
+####################################################################
+# Checking Value can be set - Dynamic #
+####################################################################
+--error ER_GLOBAL_VARIABLE
+SET @@local.Host_Cache_Size=1;
+--echo Expected error 'Global variable'
+
+--error ER_GLOBAL_VARIABLE
+SET @@session.Host_Cache_Size=1;
+--echo Expected error 'Global variable'
+
+SET @@GLOBAL.Host_Cache_Size=1;
+SET @@GLOBAL.Host_Cache_Size=DEFAULT;
+
+SELECT COUNT(@@GLOBAL.Host_Cache_Size);
+--echo 1 Expected
+
+select @@global.Host_Cache_Size=@Default_host_cache_size;
+--echo 1 Expected
+
+--echo '#---------------------WL6372_VAR_6_04----------------------#'
+#################################################################
+# Check if the value in GLOBAL Table matches value in variable #
+#################################################################
+SELECT @@GLOBAL.Host_Cache_Size = VARIABLE_VALUE
+FROM INFORMATION_SCHEMA.GLOBAL_VARIABLES
+WHERE VARIABLE_NAME='Host_Cache_Size';
+--echo 1 Expected
+
+SELECT COUNT(@@GLOBAL.Host_Cache_Size);
+--echo 1 Expected
+
+SELECT COUNT(VARIABLE_VALUE)
+FROM INFORMATION_SCHEMA.GLOBAL_VARIABLES
+WHERE VARIABLE_NAME='Host_Cache_Size';
+--echo 1 Expected
+
+--echo '#---------------------WL6372_VAR_6_05----------------------#'
+################################################################################
+# Checking Variable Scope #
+################################################################################
+SELECT @@Host_Cache_Size = @@GLOBAL.Host_Cache_Size;
+--echo 1 Expected
+
+--Error ER_INCORRECT_GLOBAL_LOCAL_VAR
+SELECT COUNT(@@local.Host_Cache_Size);
+--echo Expected error 'Variable is a GLOBAL variable'
+
+--Error ER_INCORRECT_GLOBAL_LOCAL_VAR
+SELECT COUNT(@@SESSION.Host_Cache_Size);
+--echo Expected error 'Variable is a GLOBAL variable'
+
+SELECT COUNT(@@GLOBAL.Host_Cache_Size);
+--echo 1 Expected
+
+--Error ER_BAD_FIELD_ERROR
+SELECT Host_Cache_Size = @@SESSION.Host_Cache_Size;
+--echo Expected error 'Unknown column Host_Cache_Size in field list'
+
+#The below check has been commented out as the IP fetch is different in a P2P connection than BroadBand connection
+#--echo '#---------------------WL6372_VAR_6_06----------------------#'
+###############################################################################
+# Checking the Host cahce functionality #
+###############################################################################
+
+#SET @@GLOBAL.Host_Cache_Size=2;
+#--disable_warnings
+
+#--perl
+#my $ip=`ifconfig | egrep "inet addr|inet" | sed -e 's/^.*inet addr://' -e 's/^.*inet//'| sed 's/ .*\$//'|egrep -i "broadcast|bcast"|head -1|awk '{print $1}'`;
+#open (LOGFH, ">" . $ENV{'MYSQL_TMP_DIR'} . "/bind_ip");
+#print LOGFH "let \$bind_ip = $ip;\n";
+#close LOGFH;
+#EOF
+
+#--source $MYSQL_TMP_DIR/bind_ip
+#--remove_file $MYSQL_TMP_DIR/bind_ip
+
+#let $restart_file= $MYSQLTEST_VARDIR/tmp/mysqld.1.expect;
+#--exec echo "wait" > $restart_file
+#--shutdown_server 10
+#--source include/wait_until_disconnected.inc
+#-- exec echo "restart:--bind-address=$bind_ip " > $MYSQLTEST_VARDIR/tmp/mysqld.1.expect
+#-- enable_reconnect
+#-- source include/wait_until_connected_again.inc
+
+#connection default;
+#--disable_warnings
+
+#create user binduser;
+#grant all on *.* to binduser;
+
+#select count(IP) from performance_schema.host_cache;
+#--echo 0 Expected
+
+#connect (con1,$bind_ip,binduser,,);
+#select count(IP) from performance_schema.host_cache;
+#--echo 1 Expected
+
+#disconnect con1;
+#connection default;
+
+#--disable_warnings
+
+# The below check is hashed until the BUG14689561# is fixed
+#
+#flush hosts;
+
+#connect (con2,$bind_ip,binduser,,);
+#select count(IP) from performance_schema.host_cache;
+#--echo 1 Expected
+
+#disconnect con2;
+
+SET @@GLOBAL.Host_Cache_Size=DEFAULT;
diff --git a/mysql-test/t/huge_frm-6224.test b/mysql-test/t/huge_frm-6224.test
new file mode 100644
index 00000000000..418722a7b51
--- /dev/null
+++ b/mysql-test/t/huge_frm-6224.test
@@ -0,0 +1,20 @@
+#
+# MDEV-6224 Incorrect information in file when *.frm is > 256K
+#
+# verify that huge frms are rejected during creation, not on opening
+#
+--source include/have_partition.inc
+
+let $n=5646;
+let $a=create table t1 (a int) engine=myisam partition by hash(a) partitions $n (;
+dec $n;
+while ($n)
+{
+ let $a=$a partition p01234567890123456789012345678901234567890123456789012345678$n,;
+ dec $n;
+}
+
+--disable_query_log
+--error ER_TABLE_DEFINITION_TOO_BIG
+eval $a partition foo);
+
diff --git a/mysql-test/t/index_merge_myisam.test b/mysql-test/t/index_merge_myisam.test
index 82d0474e28e..d265007431e 100644
--- a/mysql-test/t/index_merge_myisam.test
+++ b/mysql-test/t/index_merge_myisam.test
@@ -117,7 +117,7 @@ set optimizer_switch='default,index_merge_intersection=off';
explain select * from t1 where a=10 and b=10 or c=10;
--echo This will switch to sort-union (intersection will be gone, too,
---echo thats a known limitation:
+--echo that's a known limitation:
set optimizer_switch='default,index_merge_union=off';
explain select * from t1 where a=10 and b=10 or c=10;
diff --git a/mysql-test/t/information_schema-big.test b/mysql-test/t/information_schema-big.test
index 5e73c867143..717c22f8f6a 100644
--- a/mysql-test/t/information_schema-big.test
+++ b/mysql-test/t/information_schema-big.test
@@ -14,9 +14,10 @@ DROP VIEW IF EXISTS v1;
--echo #
---echo # Bug#18925: subqueries with MIN/MAX functions on INFORMARTION_SCHEMA
+--echo # Bug#18925: subqueries with MIN/MAX functions on INFORMATION_SCHEMA
--echo #
+--sorted_result
SELECT t.table_name, c1.column_name
FROM information_schema.tables t
INNER JOIN
@@ -32,6 +33,7 @@ SELECT t.table_name, c1.column_name
c2.column_name LIKE '%SCHEMA%'
)
AND t.table_name NOT LIKE 'innodb%';
+--sorted_result
SELECT t.table_name, c1.column_name
FROM information_schema.tables t
INNER JOIN
diff --git a/mysql-test/t/information_schema.test b/mysql-test/t/information_schema.test
index 943eb8bab8a..2a00ad75a8d 100644
--- a/mysql-test/t/information_schema.test
+++ b/mysql-test/t/information_schema.test
@@ -496,7 +496,7 @@ drop table t_crashme;
#
select table_schema,table_name, column_name from
information_schema.columns
-where data_type = 'longtext';
+where data_type = 'longtext' and table_schema != 'performance_schema';
select table_name, column_name, data_type from information_schema.columns
where data_type = 'datetime' and table_name not like 'innodb_%';
@@ -738,7 +738,7 @@ create temporary table schemata(f1 char(10));
# Bug#10708 SP's can use INFORMATION_SCHEMA as ROUTINE_SCHEMA
#
delimiter |;
---error ER_BAD_DB_ERROR
+--error ER_DBACCESS_DENIED_ERROR
CREATE PROCEDURE p1 ()
BEGIN
SELECT 'foo' FROM DUAL;
@@ -1841,5 +1841,61 @@ SELECT @val1 = @val2;
--echo # End of 5.5 tests
--echo #
+--echo #
+--echo # MDEV-5723: mysqldump -uroot unusable for multi-database operations, checks all databases
+--echo #
+
+--disable_warnings
+drop database if exists db1;
+--enable_warnings
+
+connect (con1,localhost,root,,);
+connection con1;
+
+create database db1;
+use db1;
+create table t1 (a int);
+create table t2 (a int);
+create table t3 (a int);
+
+create database mysqltest;
+use mysqltest;
+create table t1 (a int);
+create table t2 (a int);
+create table t3 (a int);
+
+flush tables;
+flush status;
+
+SELECT
+ LOGFILE_GROUP_NAME, FILE_NAME, TOTAL_EXTENTS, INITIAL_SIZE, ENGINE, EXTRA
+FROM
+ INFORMATION_SCHEMA.FILES
+WHERE
+ FILE_TYPE = 'UNDO LOG' AND FILE_NAME IS NOT NULL AND
+ LOGFILE_GROUP_NAME IN (SELECT DISTINCT LOGFILE_GROUP_NAME
+ FROM INFORMATION_SCHEMA.FILES
+ WHERE
+ FILE_TYPE = 'DATAFILE' AND
+ TABLESPACE_NAME IN (SELECT DISTINCT TABLESPACE_NAME
+ FROM INFORMATION_SCHEMA.PARTITIONS
+ WHERE TABLE_SCHEMA IN ('db1')
+ )
+ )
+GROUP BY
+ LOGFILE_GROUP_NAME, FILE_NAME, ENGINE
+ORDER BY
+ LOGFILE_GROUP_NAME;
+
+--echo # This must have Opened_tables=3, not 6.
+show status like 'Opened_tables';
+
+drop database mysqltest;
+drop database db1;
+
+connection default;
+disconnect con1;
+
# Wait till all disconnects are completed
--source include/wait_until_count_sessions.inc
+
diff --git a/mysql-test/t/information_schema_all_engines-master.opt b/mysql-test/t/information_schema_all_engines-master.opt
index 0a9fa574e49..e37aeaac933 100644
--- a/mysql-test/t/information_schema_all_engines-master.opt
+++ b/mysql-test/t/information_schema_all_engines-master.opt
@@ -1,19 +1,15 @@
--loose-skip-safemalloc --loose-mutex-deadlock-detector=0
---loose-innodb-buffer-pool-pages
---loose-innodb-buffer-pool-pages-blob
---loose-innodb-buffer-pool-pages-index
--loose-innodb-changed-pages
--loose-innodb-cmp
+--loose-innodb-cmp-per-index
--loose-innodb-cmp-reset
+--loose-innodb-cmpmem
--loose-innodb-cmpmem-reset
--loose-innodb-index-stats
--loose-innodb-lock-waits
---loose-innodb-rseg
--loose-innodb-sys-columns
--loose-innodb-sys-fields
--loose-innodb-sys-foreign
--loose-innodb-sys-foreign-cols
---loose-innodb-sys-stats
--loose-innodb-sys-tables
--loose-innodb-sys-tablestats
---loose-innodb-table-stats
diff --git a/mysql-test/t/information_schema_all_engines.test b/mysql-test/t/information_schema_all_engines.test
index 553367d2b9a..9b2a3e68bcd 100644
--- a/mysql-test/t/information_schema_all_engines.test
+++ b/mysql-test/t/information_schema_all_engines.test
@@ -4,6 +4,7 @@
--source include/not_embedded.inc
--source include/have_xtradb.inc
+--source include/have_perfschema.inc
--source include/not_staging.inc
use INFORMATION_SCHEMA;
@@ -49,7 +50,7 @@ SELECT t.table_name, c1.column_name
#
# Bug#24630 Subselect query crashes mysqld
#
-select 1 as f1 from information_schema.tables where "CHARACTER_SETS"=
+select 1 as "must be 1" from information_schema.tables where "ACCOUNTS"=
(select cast(table_name as char) from information_schema.tables
order by table_name limit 1) limit 1;
diff --git a/mysql-test/t/information_schema_stats.test b/mysql-test/t/information_schema_stats.test
new file mode 100644
index 00000000000..c7f39894ce7
--- /dev/null
+++ b/mysql-test/t/information_schema_stats.test
@@ -0,0 +1,46 @@
+#
+# MDEV-8633: information_schema.index_statistics doesn't delete item when drop table indexes or drop table;
+#
+set global userstat=1;
+create table just_a_test(id int,first_name varchar(10),last_name varchar(10),address varchar(100),phone bigint,email varchar(30), state varchar(30));
+insert into just_a_test values(1,'fa','la','china_a',11111111,'fa_la@163.com','California'),
+(2,'fb','lb','china_b',22222222,'fb_lb@163.com','Arizona'),
+(3,'fc','lc','china_c',33333333,'fc_lc@163.com','California'),
+(4,'fd','ld','china_d',44444444,'fd_ld@163.com','Utah'),
+(5,'fe','le','china_e',55555555,'fe_le@163.com','Arizona');
+alter table just_a_test add primary key (id);
+alter table just_a_test add key IND_just_a_test_first_name_last_name(first_name,last_name);
+alter table just_a_test add key IND_just_a_test_state(state);
+select count(*) from just_a_test where first_name='fc' and last_name='lc';
+select count(*) from just_a_test where state = 'California';
+--sorted_result
+select * from information_schema.index_statistics where table_schema='test' and table_name='just_a_test';
+select * from information_schema.table_statistics where table_schema='test' and table_name='just_a_test';
+alter table just_a_test drop key IND_just_a_test_first_name_last_name;
+select * from information_schema.index_statistics where table_schema='test' and table_name='just_a_test';
+select * from information_schema.table_statistics where table_schema='test' and table_name='just_a_test';
+alter table just_a_test drop column state;
+select * from information_schema.index_statistics where table_schema='test' and table_name='just_a_test';
+select * from information_schema.table_statistics where table_schema='test' and table_name='just_a_test';
+drop table just_a_test;
+select * from information_schema.index_statistics where table_schema='test' and table_name='just_a_test';
+select * from information_schema.table_statistics where table_schema='test' and table_name='just_a_test';
+#
+# Test direct drop table
+#
+create table just_a_test(id int not null primary key,first_name varchar(10),last_name varchar(10),address varchar(100),phone bigint,email varchar(30), state varchar(30),key(first_name,last_name),key(state));
+insert into just_a_test values(1,'fa','la','china_a',11111111,'fa_la@163.com','California'),
+(2,'fb','lb','china_b',22222222,'fb_lb@163.com','Arizona'),
+(3,'fc','lc','china_c',33333333,'fc_lc@163.com','California'),
+(4,'fd','ld','china_d',44444444,'fd_ld@163.com','Utah'),
+(5,'fe','le','china_e',55555555,'fe_le@163.com','Arizona');
+select count(*) from just_a_test where first_name='fc' and last_name='lc';
+select count(*) from just_a_test where state = 'California';
+select count(*) from just_a_test where id between 2 and 4;
+--sorted_result
+select * from information_schema.index_statistics where table_schema='test' and table_name='just_a_test';
+select * from information_schema.table_statistics where table_schema='test' and table_name='just_a_test';
+drop table just_a_test;
+select * from information_schema.index_statistics where table_schema='test' and table_name='just_a_test';
+select * from information_schema.table_statistics where table_schema='test' and table_name='just_a_test';
+set global userstat=0;
diff --git a/mysql-test/t/init_file-master.opt b/mysql-test/t/init_file.opt
index 825311dabf2..825311dabf2 100644
--- a/mysql-test/t/init_file-master.opt
+++ b/mysql-test/t/init_file.opt
diff --git a/mysql-test/t/init_file_longline_3816.opt b/mysql-test/t/init_file_longline_3816.opt
new file mode 100644
index 00000000000..9ddb6fa8565
--- /dev/null
+++ b/mysql-test/t/init_file_longline_3816.opt
@@ -0,0 +1 @@
+--init-file=$MYSQL_TEST_DIR/std_data/init_file_longline_3816.sql
diff --git a/mysql-test/t/init_file_longline_3816.test b/mysql-test/t/init_file_longline_3816.test
new file mode 100644
index 00000000000..5db2fcb0c73
--- /dev/null
+++ b/mysql-test/t/init_file_longline_3816.test
@@ -0,0 +1,5 @@
+#
+# MDEV-3816 init-file stops getting executed if a long enough line is encountered; on a debug version, assertion `! is_set() || can_overwrite_status' fails
+#
+select count(*) from t4;
+
diff --git a/mysql-test/t/init_file_set_password-7656.test b/mysql-test/t/init_file_set_password-7656.test
new file mode 100644
index 00000000000..ecee3924355
--- /dev/null
+++ b/mysql-test/t/init_file_set_password-7656.test
@@ -0,0 +1,26 @@
+#
+# MDEV-7656 init_file option does not allow changing passwords
+#
+--source include/not_embedded.inc
+
+create user foo@localhost;
+
+select user,host,password from mysql.user where user='foo';
+
+--write_file $MYSQLTEST_VARDIR/init.file
+grant all on *.* to foo@localhost identified by 'test';
+EOF
+
+--enable_reconnect
+
+--exec echo "wait" > $MYSQLTEST_VARDIR/tmp/mysqld.1.expect
+
+--shutdown_server 10
+--source include/wait_until_disconnected.inc
+
+--exec echo "restart:--init-file=$MYSQLTEST_VARDIR/init.file " > $MYSQLTEST_VARDIR/tmp/mysqld.1.expect
+
+--source include/wait_until_connected_again.inc
+select user,host,password from mysql.user where user='foo';
+
+drop user foo@localhost;
diff --git a/mysql-test/t/innodb_ext_key.test b/mysql-test/t/innodb_ext_key.test
index 6d1890ac1f9..9f3a89ff948 100644
--- a/mysql-test/t/innodb_ext_key.test
+++ b/mysql-test/t/innodb_ext_key.test
@@ -520,6 +520,7 @@ engine=innodb;
insert into t3 select a,a,a,a from t2;
alter table t3 add primary key (pk1, pk2);
alter table t3 add key (col1, col2);
+analyze table t1,t3;
set optimizer_switch='extended_keys=off';
--replace_column 9 #
diff --git a/mysql-test/t/innodb_mrr_cpk.test b/mysql-test/t/innodb_mrr_cpk.test
index b6383f9694c..cb79c238f2b 100644
--- a/mysql-test/t/innodb_mrr_cpk.test
+++ b/mysql-test/t/innodb_mrr_cpk.test
@@ -227,4 +227,3 @@ drop table t0,t1,t2;
set @@join_cache_level= @save_join_cache_level;
set storage_engine=@save_storage_engine;
set optimizer_switch=@innodb_mrr_cpk_tmp;
-
diff --git a/mysql-test/t/innodb_mysql_lock-master.opt b/mysql-test/t/innodb_mysql_lock-master.opt
deleted file mode 100644
index ec82f2755af..00000000000
--- a/mysql-test/t/innodb_mysql_lock-master.opt
+++ /dev/null
@@ -1 +0,0 @@
---loose-innodb_lock_wait_timeout=300
diff --git a/mysql-test/t/innodb_mysql_lock.test b/mysql-test/t/innodb_mysql_lock.test
index 629da27660e..b3c52a1b1cf 100644
--- a/mysql-test/t/innodb_mysql_lock.test
+++ b/mysql-test/t/innodb_mysql_lock.test
@@ -3,6 +3,10 @@
# Save the initial number of concurrent sessions.
--source include/count_sessions.inc
+set @old_innodb_lock_wait_timeout=@@global.innodb_lock_wait_timeout;
+set global innodb_lock_wait_timeout=300;
+set session innodb_lock_wait_timeout=300;
+
--echo #
--echo # Bug #22876 Four-way deadlock
--echo #
@@ -318,3 +322,6 @@ disconnect con1;
# Check that all connections opened by test cases in this file are really
# gone so execution of other tests won't be affected by their presence.
--source include/wait_until_count_sessions.inc
+
+set global innodb_lock_wait_timeout=@old_innodb_lock_wait_timeout;
+
diff --git a/mysql-test/t/innodb_mysql_lock2.test b/mysql-test/t/innodb_mysql_lock2.test
index b7259e771ae..640f9652462 100644
--- a/mysql-test/t/innodb_mysql_lock2.test
+++ b/mysql-test/t/innodb_mysql_lock2.test
@@ -440,15 +440,16 @@ let $wait_statement= $statement;
--echo # 4.1 SELECT/SET with a stored function which does not
--echo # modify data and uses SELECT in its turn.
--echo #
---echo # In theory there is no need to take row locks on the table
+--echo # There is no need to take row locks on the table
--echo # being selected from in SF as the call to such function
---echo # won't get into the binary log. In practice, however, we
---echo # discover that fact too late in the process to be able to
---echo # affect the decision what locks should be taken.
---echo # Hence, strong locks are taken in this case.
+--echo # won't get into the binary log.
+--echo #
+--echo # However in practice innodb takes strong lock on tables
+--echo # being selected from within SF, when SF is called from
+--echo # non SELECT statements like 'set' statement below.
let $statement= select f1();
let $wait_statement= select i from t1 where i = 1 into j;
---source include/check_shared_row_lock.inc
+--source include/check_no_row_lock.inc
let $statement= set @a:= f1();
let $wait_statement= select i from t1 where i = 1 into j;
--source include/check_shared_row_lock.inc
@@ -486,19 +487,21 @@ let $wait_statement= select i from t1 where i = 1 into k;
--echo # modify data and reads a table through subselect
--echo # in a control construct.
--echo #
---echo # Again, in theory a call to this function won't get to the
---echo # binary log and thus no locking is needed. But in practice
---echo # we don't detect this fact early enough (get_lock_type_for_table())
---echo # to avoid taking row locks.
+--echo # Call to this function won't get to the
+--echo # binary log and thus no locking is needed.
+--echo #
+--echo # However in practice innodb takes strong lock on tables
+--echo # being selected from within SF, when SF is called from
+--echo # non SELECT statements like 'set' statement below.
let $statement= select f3();
let $wait_statement= $statement;
---source include/check_shared_row_lock.inc
+--source include/check_no_row_lock.inc
let $statement= set @a:= f3();
let $wait_statement= $statement;
--source include/check_shared_row_lock.inc
let $statement= select f4();
let $wait_statement= $statement;
---source include/check_shared_row_lock.inc
+--source include/check_no_row_lock.inc
let $statement= set @a:= f4();
let $wait_statement= $statement;
--source include/check_shared_row_lock.inc
@@ -539,19 +542,21 @@ let $wait_statement= insert into t2 values ((select i from t1 where i = 1) + 5);
--echo # doesn't modify data and reads tables through
--echo # a view.
--echo #
---echo # Once again, in theory, calls to such functions won't
---echo # get into the binary log and thus don't need row
---echo # locks. But in practice this fact is discovered
---echo # too late to have any effect.
+--echo # Calls to such functions won't get into
+--echo # the binary log and thus don't need row locks.
+--echo #
+--echo # However in practice innodb takes strong lock on tables
+--echo # being selected from within SF, when SF is called from
+--echo # non SELECT statements like 'set' statement below.
let $statement= select f6();
let $wait_statement= select i from v1 where i = 1 into k;
---source include/check_shared_row_lock.inc
+--source include/check_no_row_lock.inc
let $statement= set @a:= f6();
let $wait_statement= select i from v1 where i = 1 into k;
--source include/check_shared_row_lock.inc
let $statement= select f7();
let $wait_statement= select j from v2 where j = 1 into k;
---source include/check_shared_row_lock.inc
+--source include/check_no_row_lock.inc
let $statement= set @a:= f7();
let $wait_statement= select j from v2 where j = 1 into k;
--source include/check_shared_row_lock.inc
@@ -592,12 +597,11 @@ let $wait_statement= update v2 set j=j+10 where j=1;
--echo # data and reads a table indirectly, by calling another
--echo # function.
--echo #
---echo # In theory, calls to such functions won't get into the binary
---echo # log and thus don't need to acquire row locks. But in practice
---echo # this fact is discovered too late to have any effect.
+--echo # Calls to such functions won't get into the binary
+--echo # log and thus don't need to acquire row locks.
let $statement= select f10();
let $wait_statement= select i from t1 where i = 1 into j;
---source include/check_shared_row_lock.inc
+--source include/check_no_row_lock.inc
--echo #
--echo # 4.11 INSERT which uses a stored function which doesn't modify
@@ -676,12 +680,11 @@ let $wait_statement= select i from t1 where i = 1 into p;
--echo # 5.3 SELECT that calls a function that doesn't modify data and
--echo # uses a CALL statement that reads a table via SELECT.
--echo #
---echo # In theory, calls to such functions won't get into the binary
---echo # log and thus don't need to acquire row locks. But in practice
---echo # this fact is discovered too late to have any effect.
+--echo # Calls to such functions won't get into the binary
+--echo # log and thus don't need to acquire row locks.
let $statement= select f15();
let $wait_statement= select i from t1 where i = 1 into p;
---source include/check_shared_row_lock.inc
+--source include/check_no_row_lock.inc
--echo #
--echo # 5.4 INSERT which calls function which doesn't modify data and
diff --git a/mysql-test/t/innodb_mysql_sync.test b/mysql-test/t/innodb_mysql_sync.test
index 2f3bd643837..31365cb8db8 100644
--- a/mysql-test/t/innodb_mysql_sync.test
+++ b/mysql-test/t/innodb_mysql_sync.test
@@ -2,6 +2,7 @@
# Test file for InnoDB tests that require the debug sync facility
#
--source include/have_innodb.inc
+--source include/have_partition.inc
--source include/have_debug.inc
--source include/have_debug_sync.inc
# Save the initial number of concurrent sessions.
@@ -168,7 +169,7 @@ connection default;
CREATE DATABASE db1;
CREATE TABLE db1.t1(id INT NOT NULL AUTO_INCREMENT PRIMARY KEY, value INT) engine=innodb;
INSERT INTO db1.t1(value) VALUES (1), (2);
-SET DEBUG_SYNC= "alter_table_manage_keys SIGNAL manage WAIT_FOR query";
+SET DEBUG_SYNC= "alter_table_inplace_after_lock_downgrade SIGNAL manage WAIT_FOR query";
--echo # Sending:
--send ALTER TABLE db1.t1 ADD INDEX(value)
@@ -186,26 +187,27 @@ connection default;
--reap
DROP DATABASE db1;
---echo # Test 2: Primary index (implicit), should block reads.
+--echo # Test 2: Primary index (implicit), should block writes.
CREATE TABLE t1(a INT NOT NULL, b INT NOT NULL) engine=innodb;
-SET DEBUG_SYNC= "alter_table_manage_keys SIGNAL manage WAIT_FOR query";
+SET DEBUG_SYNC= "alter_table_inplace_after_lock_downgrade SIGNAL manage WAIT_FOR query";
--echo # Sending:
---send ALTER TABLE t1 ADD UNIQUE INDEX(a)
+--send ALTER TABLE t1 ADD UNIQUE INDEX(a), LOCK=SHARED
--echo # Connection con1
connection con1;
SET DEBUG_SYNC= "now WAIT_FOR manage";
USE test;
+SELECT * FROM t1;
--echo # Sending:
---send SELECT * FROM t1
+--send UPDATE t1 SET a=NULL
--echo # Connection con2
connection con2;
--echo # Waiting for SELECT to be blocked by the metadata lock on t1
let $wait_condition= SELECT COUNT(*)= 1 FROM information_schema.processlist
WHERE state= 'Waiting for table metadata lock'
- AND info='SELECT * FROM t1';
+ AND info='UPDATE t1 SET a=NULL';
--source include/wait_condition.inc
SET DEBUG_SYNC= "now SIGNAL query";
@@ -216,30 +218,31 @@ connection default;
--echo # Connection con1
connection con1;
---echo # Reaping: SELECT * FROM t1
+--echo # Reaping: UPDATE t1 SET a=NULL
--reap
---echo # Test 3: Primary index (explicit), should block reads.
+--echo # Test 3: Primary index (explicit), should block writes.
--echo # Connection default
connection default;
ALTER TABLE t1 DROP INDEX a;
-SET DEBUG_SYNC= "alter_table_manage_keys SIGNAL manage WAIT_FOR query";
+SET DEBUG_SYNC= "alter_table_inplace_after_lock_downgrade SIGNAL manage WAIT_FOR query";
--echo # Sending:
---send ALTER TABLE t1 ADD PRIMARY KEY (a)
+--send ALTER TABLE t1 ADD PRIMARY KEY (a), LOCK=SHARED
--echo # Connection con1
connection con1;
SET DEBUG_SYNC= "now WAIT_FOR manage";
+SELECT * FROM t1;
--echo # Sending:
---send SELECT * FROM t1
+--send UPDATE t1 SET a=NULL
--echo # Connection con2
connection con2;
--echo # Waiting for SELECT to be blocked by the metadata lock on t1
let $wait_condition= SELECT COUNT(*)= 1 FROM information_schema.processlist
WHERE state= 'Waiting for table metadata lock'
- AND info='SELECT * FROM t1';
+ AND info='UPDATE t1 SET a=NULL';
--source include/wait_condition.inc
SET DEBUG_SYNC= "now SIGNAL query";
@@ -250,14 +253,14 @@ connection default;
--echo # Connection con1
connection con1;
---echo # Reaping: SELECT * FROM t1
+--echo # Reaping: UPDATE t1 SET a=NULL
--reap
--echo # Test 4: Secondary unique index, should not block reads.
--echo # Connection default
connection default;
-SET DEBUG_SYNC= "alter_table_manage_keys SIGNAL manage WAIT_FOR query";
+SET DEBUG_SYNC= "alter_table_inplace_after_lock_downgrade SIGNAL manage WAIT_FOR query";
--echo # Sending:
--send ALTER TABLE t1 ADD UNIQUE (b)
@@ -304,6 +307,491 @@ DROP TABLE t1;
disconnect con1;
+--echo #
+--echo # Bug#13417754 ASSERT IN ROW_DROP_DATABASE_FOR_MYSQL DURING DROP SCHEMA
+--echo #
+
+--disable_warnings
+DROP TABLE IF EXISTS t1;
+DROP DATABASE IF EXISTS db1;
+--enable_warnings
+
+CREATE TABLE t1(a int) engine=InnoDB;
+CREATE DATABASE db1;
+
+connect(con1, localhost, root);
+connect(con2, localhost, root);
+
+--echo # Connection con1
+connection con1;
+SET DEBUG_SYNC= 'after_innobase_rename_table SIGNAL locked WAIT_FOR continue';
+--echo # Sending:
+--send ALTER TABLE t1 RENAME db1.t1
+
+--echo # Connection con2
+connection con2;
+SET DEBUG_SYNC= 'now WAIT_FOR locked';
+--echo # DROP DATABASE db1 should now be blocked by ALTER TABLE
+--echo # Sending:
+--send DROP DATABASE db1
+
+--echo # Connection default
+connection default;
+--echo # Check that DROP DATABASE is blocked by IX lock on db1
+let $wait_condition=
+ SELECT COUNT(*) = 1 FROM information_schema.processlist
+ WHERE state = "Waiting for schema metadata lock" and
+ info = "DROP DATABASE db1";
+--source include/wait_condition.inc
+--echo # Resume ALTER TABLE
+SET DEBUG_SYNC= 'now SIGNAL continue';
+
+--echo # Connection con1
+connection con1;
+--echo # Reaping: ALTER TABLE t1 RENAME db1.t1;
+--reap
+
+--echo # Connection con2
+connection con2;
+--echo # Reaping: DROP DATABASE db1
+--reap
+
+--echo # Connection default;
+connection default;
+SET DEBUG_SYNC= 'RESET';
+disconnect con1;
+disconnect con2;
+
+
+--echo #
+--echo # WL#5534 Online ALTER, Phase 1
+--echo #
+
+--echo # Multi thread tests.
+--echo # See alter_table.test for single thread tests.
+
+--disable_warnings
+DROP TABLE IF EXISTS t1;
+--enable_warnings
+
+CREATE TABLE t1(a INT PRIMARY KEY, b INT) engine=InnoDB;
+INSERT INTO t1 VALUES (1,1), (2,2);
+SET DEBUG_SYNC= 'RESET';
+connect (con1, localhost, root);
+SET SESSION lock_wait_timeout= 1;
+
+--echo #
+--echo # 1: In-place + writes blocked.
+--echo #
+
+--echo # Connection default
+--connection default
+SET DEBUG_SYNC= 'alter_opened_table SIGNAL opened WAIT_FOR continue1';
+SET DEBUG_SYNC= 'alter_table_inplace_after_lock_upgrade SIGNAL upgraded WAIT_FOR continue2';
+SET DEBUG_SYNC= 'alter_table_inplace_before_commit SIGNAL beforecommit WAIT_FOR continue3';
+SET DEBUG_SYNC= 'alter_table_before_main_binlog SIGNAL binlog WAIT_FOR continue4';
+--echo # Sending:
+--send ALTER TABLE t1 ADD INDEX i1(b), ALGORITHM= INPLACE, LOCK= SHARED
+
+--echo # Connection con1;
+--connection con1
+SET DEBUG_SYNC= 'now WAIT_FOR opened';
+--echo # At this point, neither reads nor writes should be blocked.
+SELECT * FROM t1;
+INSERT INTO t1 VALUES (3,3);
+
+SET DEBUG_SYNC= 'now SIGNAL continue1';
+SET DEBUG_SYNC= 'now WAIT_FOR upgraded';
+--echo # Now both reads and writes should be blocked
+--error ER_LOCK_WAIT_TIMEOUT
+SELECT * FROM t1;
+--error ER_LOCK_WAIT_TIMEOUT
+INSERT INTO t1 VALUES (4,4);
+
+SET DEBUG_SYNC= 'now SIGNAL continue2';
+SET DEBUG_SYNC= 'now WAIT_FOR beforecommit';
+--echo # Still both reads and writes should be blocked.
+--error ER_LOCK_WAIT_TIMEOUT
+SELECT * FROM t1;
+--error ER_LOCK_WAIT_TIMEOUT
+INSERT INTO t1 VALUES (5,5);
+
+SET DEBUG_SYNC= 'now SIGNAL continue3';
+SET DEBUG_SYNC= 'now WAIT_FOR binlog';
+--echo # Same here.
+--error ER_LOCK_WAIT_TIMEOUT
+SELECT * FROM t1;
+--error ER_LOCK_WAIT_TIMEOUT
+INSERT INTO t1 VALUES (6,6);
+
+SET DEBUG_SYNC= 'now SIGNAL continue4';
+--echo # Connection default
+--connection default
+--echo # Reaping ALTER TABLE ...
+--reap
+SET DEBUG_SYNC= 'RESET';
+DELETE FROM t1 WHERE a= 3;
+
+--echo #
+--echo # 2: Copy + writes blocked.
+--echo #
+
+SET DEBUG_SYNC= 'alter_opened_table SIGNAL opened WAIT_FOR continue1';
+SET DEBUG_SYNC= 'alter_table_copy_after_lock_upgrade SIGNAL upgraded WAIT_FOR continue2';
+SET DEBUG_SYNC= 'alter_table_before_main_binlog SIGNAL binlog WAIT_FOR continue3';
+--echo # Sending:
+--send ALTER TABLE t1 ADD INDEX i2(b), ALGORITHM= COPY, LOCK= SHARED
+
+--echo # Connection con1;
+--connection con1
+SET DEBUG_SYNC= 'now WAIT_FOR opened';
+--echo # At this point, neither reads nor writes should be blocked.
+SELECT * FROM t1;
+INSERT INTO t1 VALUES (3,3);
+
+SET DEBUG_SYNC= 'now SIGNAL continue1';
+SET DEBUG_SYNC= 'now WAIT_FOR upgraded';
+--echo # Now writes should be blocked, reads still allowed.
+SELECT * FROM t1;
+--error ER_LOCK_WAIT_TIMEOUT
+INSERT INTO t1 VALUES (4,4);
+
+SET DEBUG_SYNC= 'now SIGNAL continue2';
+SET DEBUG_SYNC= 'now WAIT_FOR binlog';
+--echo # Now both reads and writes should be blocked.
+--error ER_LOCK_WAIT_TIMEOUT
+SELECT * FROM t1 limit 1;
+--error ER_LOCK_WAIT_TIMEOUT
+INSERT INTO t1 VALUES (5,5);
+
+SET DEBUG_SYNC= 'now SIGNAL continue3';
+--echo # Connection default
+--connection default
+--echo # Reaping ALTER TABLE ...
+--reap
+SET DEBUG_SYNC= 'RESET';
+DELETE FROM t1 WHERE a= 3;
+
+--echo #
+--echo # 3: In-place + writes allowed.
+--echo #
+
+--echo # TODO: Enable this test once WL#5526 is pushed
+--disable_parsing
+
+--echo # Connection default
+--connection default
+SET DEBUG_SYNC= 'alter_opened_table SIGNAL opened WAIT_FOR continue1';
+SET DEBUG_SYNC= 'alter_table_inplace_after_lock_upgrade SIGNAL upgraded WAIT_FOR continue2';
+SET DEBUG_SYNC= 'alter_table_inplace_after_lock_downgrade SIGNAL downgraded WAIT_FOR continue3';
+SET DEBUG_SYNC= 'alter_table_inplace_before_commit SIGNAL beforecommit WAIT_FOR continue4';
+SET DEBUG_SYNC= 'alter_table_before_main_binlog SIGNAL binlog WAIT_FOR continue5';
+--echo # Sending:
+--send ALTER TABLE t1 ADD INDEX i3(b), ALGORITHM= INPLACE, LOCK= NONE
+
+--echo # Connection con1;
+--connection con1
+SET DEBUG_SYNC= 'now WAIT_FOR opened';
+--echo # At this point, neither reads nor writes should be blocked.
+SELECT * FROM t1;
+INSERT INTO t1 VALUES (3,3);
+
+SET DEBUG_SYNC= 'now SIGNAL continue1';
+SET DEBUG_SYNC= 'now WAIT_FOR upgraded';
+--echo # Now writes should be blocked, reads still allowed.
+SELECT * FROM t1;
+--error ER_LOCK_WAIT_TIMEOUT
+INSERT INTO t1 VALUES (4,4);
+
+SET DEBUG_SYNC= 'now SIGNAL continue2';
+SET DEBUG_SYNC= 'now WAIT_FOR downgraded';
+--echo # Now writes should be allowed again.
+SELECT * FROM t1;
+INSERT INTO t1 VALUES (5,5);
+
+SET DEBUG_SYNC= 'now SIGNAL continue3';
+SET DEBUG_SYNC= 'now WAIT_FOR beforecommit';
+--echo # Now both reads and writes should be blocked.
+--error ER_LOCK_WAIT_TIMEOUT
+SELECT * FROM t1;
+--error ER_LOCK_WAIT_TIMEOUT
+INSERT INTO t1 VALUES (6,6);
+
+SET DEBUG_SYNC= 'now SIGNAL continue4';
+SET DEBUG_SYNC= 'now WAIT_FOR binlog';
+--echo # Same here.
+--error ER_LOCK_WAIT_TIMEOUT
+SELECT * FROM t1;
+--error ER_LOCK_WAIT_TIMEOUT
+INSERT INTO t1 VALUES (7,7);
+
+SET DEBUG_SYNC= 'now SIGNAL continue5';
+--echo # Connection default
+--connection default
+--echo # Reaping ALTER TABLE ...
+--reap
+SET DEBUG_SYNC= 'RESET';
+DELETE FROM t1 WHERE a= 3 OR a= 4;
+
+--echo # TODO: Enable this test once WL#5526 is pushed
+--enable_parsing
+
+--echo #
+--echo # 4: In-place + reads and writes blocked.
+--echo #
+
+--echo # Connection default
+--connection default
+SET DEBUG_SYNC= 'alter_opened_table SIGNAL opened WAIT_FOR continue1';
+SET DEBUG_SYNC= 'alter_table_inplace_after_lock_upgrade SIGNAL upgraded WAIT_FOR continue2';
+SET DEBUG_SYNC= 'alter_table_inplace_before_commit SIGNAL beforecommit WAIT_FOR continue3';
+SET DEBUG_SYNC= 'alter_table_before_main_binlog SIGNAL binlog WAIT_FOR continue4';
+--echo # Sending:
+--send ALTER TABLE t1 ADD INDEX i4(b), ALGORITHM= INPLACE, LOCK= EXCLUSIVE
+
+--echo # Connection con1;
+--connection con1
+SET DEBUG_SYNC= 'now WAIT_FOR opened';
+--echo # At this point, neither reads nor writes should be blocked.
+SELECT * FROM t1;
+INSERT INTO t1 VALUES (3,3);
+
+SET DEBUG_SYNC= 'now SIGNAL continue1';
+SET DEBUG_SYNC= 'now WAIT_FOR upgraded';
+--echo # Now both reads and writes should be blocked.
+--error ER_LOCK_WAIT_TIMEOUT
+SELECT * FROM t1;
+--error ER_LOCK_WAIT_TIMEOUT
+INSERT INTO t1 VALUES (4,4);
+
+SET DEBUG_SYNC= 'now SIGNAL continue2';
+SET DEBUG_SYNC= 'now WAIT_FOR beforecommit';
+--echo # Same here.
+--error ER_LOCK_WAIT_TIMEOUT
+SELECT * FROM t1;
+--error ER_LOCK_WAIT_TIMEOUT
+INSERT INTO t1 VALUES (5,5);
+
+SET DEBUG_SYNC= 'now SIGNAL continue3';
+SET DEBUG_SYNC= 'now WAIT_FOR binlog';
+--echo # Same here.
+--error ER_LOCK_WAIT_TIMEOUT
+SELECT * FROM t1;
+--error ER_LOCK_WAIT_TIMEOUT
+INSERT INTO t1 VALUES (6,6);
+
+SET DEBUG_SYNC= 'now SIGNAL continue4';
+--echo # Connection default
+--connection default
+--echo # Reaping ALTER TABLE ...
+--reap
+SET DEBUG_SYNC= 'RESET';
+
+--connection default
+--disconnect con1
+DROP TABLE t1;
+SET DEBUG_SYNC= 'RESET';
+
+
+--echo #
+--echo #BUG#13975225:ONLINE OPTIMIZE TABLE FOR INNODB TABLES
+--echo #
+
+SET DEBUG_SYNC= 'alter_table_inplace_after_lock_downgrade SIGNAL downgraded WAIT_FOR continue';
+connect(con1,localhost,root,,);
+
+--echo #Setting up INNODB table.
+CREATE TABLE t1(fld1 INT, fld2 INT, fld3 INT) ENGINE= INNODB;
+INSERT INTO t1 VALUES (155, 45, 55);
+
+--echo #Concurrent INSERT, UPDATE, SELECT and DELETE is supported
+--echo #during OPTIMIZE TABLE operation for INNODB tables.
+--enable_connect_log
+--connection default
+--echo #OPTIMIZE TABLE operation.
+--send OPTIMIZE TABLE t1
+
+--connection con1
+SET DEBUG_SYNC= 'now WAIT_FOR downgraded';
+--echo # With the patch, concurrent DML operation succeeds.
+INSERT INTO t1 VALUES (10, 11, 12);
+UPDATE t1 SET fld1= 20 WHERE fld1= 155;
+DELETE FROM t1 WHERE fld1= 20;
+SELECT * from t1;
+SET DEBUG_SYNC= 'now SIGNAL continue';
+
+--connection default
+--reap
+DROP TABLE t1;
+SET DEBUG_SYNC= 'RESET';
+
+--echo #Concurrent INSERT, UPDATE, SELECT and DELETE is supported
+--echo #during OPTIMIZE TABLE operation for Partitioned table.
+
+SET DEBUG_SYNC= 'alter_table_inplace_after_lock_downgrade SIGNAL downgraded WAIT_FOR continue';
+--echo #Setup PARTITIONED table.
+CREATE TABLE t1(fld1 INT) ENGINE= INNODB PARTITION BY HASH(fld1) PARTITIONS 4;
+INSERT INTO t1 VALUES(10);
+
+--echo #OPTIMIZE TABLE operation.
+--send OPTIMIZE TABLE t1
+
+--connection con1
+SET DEBUG_SYNC= 'now WAIT_FOR downgraded';
+--echo # With the patch, concurrent DML operation succeeds.
+INSERT INTO t1 VALUES (30);
+UPDATE t1 SET fld1= 20 WHERE fld1= 10;
+DELETE FROM t1 WHERE fld1= 20;
+SELECT * from t1;
+SET DEBUG_SYNC= 'now SIGNAL continue';
+
+--connection default
+--reap
+DROP TABLE t1;
+SET DEBUG_SYNC= 'RESET';
+
+--echo #ALTER TABLE FORCE and ALTER TABLE ENGINE uses online rebuild
+--echo #of the table.
+
+CREATE TABLE t1(fld1 INT, fld2 INT) ENGINE=INNODB;
+INSERT INTO t1 VALUES(10, 20);
+
+--enable_info
+ALTER TABLE t1 FORCE;
+ALTER TABLE t1 ENGINE=INNODB;
+
+--echo #ALTER TABLE FORCE, ALTER TABLE ENGINE and OPTIMIZE TABLE uses
+--echo #table copy when the old_alter_table enabled.
+SET SESSION old_alter_table= TRUE;
+ALTER TABLE t1 FORCE;
+ALTER TABLE t1 ENGINE= INNODB;
+
+SET DEBUG_SYNC= 'alter_table_copy_after_lock_upgrade SIGNAL upgraded';
+--echo #OPTIMIZE TABLE operation using table copy.
+--send OPTIMIZE TABLE t1
+
+--connection con1
+SET DEBUG_SYNC= 'now WAIT_FOR upgraded';
+INSERT INTO t1 VALUES(10, 20);
+
+--connection default
+--reap
+SET DEBUG_SYNC= 'RESET';
+SET SESSION old_alter_table= FALSE;
+
+--echo #ALTER TABLE FORCE and ALTER TABLE ENGINE uses table copy
+--echo #when ALGORITHM COPY is used.
+ALTER TABLE t1 FORCE, ALGORITHM= COPY;
+ALTER TABLE t1 ENGINE= INNODB, ALGORITHM= COPY;
+--disable_info
+
+#cleanup
+DROP TABLE t1;
+
+--echo #OPTIMIZE TABLE on a table with FULLTEXT index uses
+--echo #ALTER TABLE FORCE using COPY algorithm here. This
+--echo #test case ensures the COPY table debug sync point is hit.
+
+SET DEBUG_SYNC= 'alter_table_copy_after_lock_upgrade SIGNAL upgraded';
+
+--echo #Setup a table with FULLTEXT index.
+--connection default
+CREATE TABLE t1(fld1 CHAR(10), FULLTEXT(fld1)) ENGINE= INNODB;
+INSERT INTO t1 VALUES("String1");
+
+--echo #OPTIMIZE TABLE operation.
+--send OPTIMIZE TABLE t1
+
+--connection con1
+SET DEBUG_SYNC= 'now WAIT_FOR upgraded';
+INSERT INTO t1 VALUES("String2");
+
+--connection default
+--reap
+SET DEBUG_SYNC= 'RESET';
+DROP TABLE t1;
+
+--echo #Test which demonstrates that ALTER TABLE, OPTIMIZE PARTITION
+--echo #takes OPTIMIZE TABLE code path, hence does an online rebuild
+--echo #of the table with the patch.
+
+--connection default
+SET DEBUG_SYNC= 'alter_table_inplace_after_lock_downgrade SIGNAL downgraded WAIT_FOR continue';
+--echo #Setup PARTITIONED table.
+CREATE TABLE t1(fld1 INT) ENGINE= INNODB PARTITION BY HASH(fld1) PARTITIONS 4;
+INSERT INTO t1 VALUES(10);
+
+--echo #OPTIMIZE ALL PARTITIONS operation.
+--send ALTER TABLE t1 OPTIMIZE PARTITION ALL
+
+--connection con1
+SET DEBUG_SYNC= 'now WAIT_FOR downgraded';
+--echo # With the patch, concurrent DML operation succeeds.
+INSERT INTO t1 VALUES (30);
+UPDATE t1 SET fld1= 20 WHERE fld1= 10;
+DELETE FROM t1 WHERE fld1= 20;
+SELECT * from t1;
+SET DEBUG_SYNC= 'now SIGNAL continue';
+
+--connection default
+--reap
+SET DEBUG_SYNC= 'RESET';
+
+--echo #OPTIMIZE PER PARTITION operation.
+SET DEBUG_SYNC= 'alter_table_inplace_after_lock_downgrade SIGNAL downgraded WAIT_FOR continue';
+--send ALTER TABLE t1 OPTIMIZE PARTITION p0
+
+--connection con1
+SET DEBUG_SYNC= 'now WAIT_FOR downgraded';
+--echo # With the patch, concurrent DML operation succeeds.
+INSERT INTO t1 VALUES (30);
+UPDATE t1 SET fld1= 20 WHERE fld1= 10;
+DELETE FROM t1 WHERE fld1= 20;
+SELECT * from t1;
+SET DEBUG_SYNC= 'now SIGNAL continue';
+
+--connection default
+--reap
+SET DEBUG_SYNC= 'RESET';
+
+--echo # Test case for Bug#11938817 (ALTER BEHAVIOR DIFFERENT THEN DOCUMENTED).
+--enable_info
+--echo # This should not do anything
+ALTER TABLE t1;
+--disable_info
+
+#Note that sync point is activated in the online rebuild code path.
+SET DEBUG_SYNC = 'row_log_table_apply1_before SIGNAL rebuild';
+
+--echo # Check that we rebuild the table
+--send ALTER TABLE t1 engine=innodb
+
+--connection con1
+SET DEBUG_SYNC= 'now WAIT_FOR rebuild';
+
+--connection default
+--reap
+
+SET DEBUG_SYNC= 'RESET';
+
+SET DEBUG_SYNC = 'row_log_table_apply1_before SIGNAL rebuild';
+
+--echo # Check that we rebuild the table
+--send ALTER TABLE t1 FORCE
+
+--connection con1
+SET DEBUG_SYNC= 'now WAIT_FOR rebuild';
+
+--connection default
+--reap
+
+--disable_connect_log
+--disconnect con1
+
+SET DEBUG_SYNC= 'RESET';
+DROP TABLE t1;
+
+
# Check that all connections opened by test cases in this file are really
# gone so execution of other tests won't be affected by their presence.
--source include/wait_until_count_sessions.inc
diff --git a/mysql-test/t/insert.test b/mysql-test/t/insert.test
index ff8396fd7fd..9e84bf3ee5f 100644
--- a/mysql-test/t/insert.test
+++ b/mysql-test/t/insert.test
@@ -573,3 +573,42 @@ insert ignore into t1 values (1,12) on duplicate key update f2=13;
set @@old_mode="";
insert ignore into t1 values (1,12);
DROP TABLE t1;
+
+--echo #
+--echo # MDEV-13290 Assertion Assertion `!is_set() || (m_status == DA_OK_BULK
+--echo # && is_bulk_op())' or `! is_set()' failed
+--echo #
+
+SET @save_mode= @@sql_mode;
+SET sql_mode= 'STRICT_ALL_TABLES';
+CREATE TABLE t1 (f1 INT DEFAULT 0, f2 INT);
+CREATE ALGORITHM = MERGE VIEW v1 AS SELECT f1, f2 FROM t1 WHERE f1 = 'x' WITH CHECK OPTION;
+--error ER_TRUNCATED_WRONG_VALUE
+REPLACE INTO v1 SET f2 = 1;
+SELECT * from t1;
+drop view v1;
+CREATE ALGORITHM = MERGE VIEW v1 AS SELECT f1, f2 FROM t1 WHERE f1 = cast('' as decimal) WITH CHECK OPTION;
+--error ER_TRUNCATED_WRONG_VALUE
+REPLACE INTO v1 SET f2 = 1;
+SELECT * from t1;
+drop view v1;
+SELECT 0,0 INTO OUTFILE 't1.txt';
+CREATE ALGORITHM = MERGE VIEW v1 AS SELECT f1, f2 FROM t1 WHERE f1 = 'x' WITH CHECK OPTION;
+--error ER_TRUNCATED_WRONG_VALUE
+LOAD DATA INFILE 't1.txt' INTO TABLE v1;
+SELECT * from t1;
+let $MYSQLD_DATADIR= `select @@datadir`;
+remove_file $MYSQLD_DATADIR/test/t1.txt;
+drop view v1;
+drop table t1;
+SET @@sql_mode= @save_mode;
+
+#
+# MDEV-13861 Assertion `0' failed in Protocol::end_statement
+#
+CREATE TABLE t1 (f INT);
+CREATE VIEW v1 AS SELECT * FROM t1 WHERE f <=> 'foo' WITH CHECK OPTION;
+--error ER_VIEW_CHECK_FAILED
+REPLACE INTO v1 SET f = NULL;
+DROP VIEW v1;
+DROP TABLE t1;
diff --git a/mysql-test/t/ipv4_and_ipv6.opt b/mysql-test/t/ipv4_and_ipv6.opt
new file mode 100644
index 00000000000..a22a7b100c8
--- /dev/null
+++ b/mysql-test/t/ipv4_and_ipv6.opt
@@ -0,0 +1 @@
+--skip-name-resolve --bind-address=*
diff --git a/mysql-test/t/ipv4_and_ipv6.test b/mysql-test/t/ipv4_and_ipv6.test
new file mode 100644
index 00000000000..19ab4a253cc
--- /dev/null
+++ b/mysql-test/t/ipv4_and_ipv6.test
@@ -0,0 +1,13 @@
+--source include/check_ipv6.inc
+--source include/not_embedded.inc
+
+echo =============Test of '::1' ========================================;
+let $IPv6= ::1;
+--source include/ipv6_clients.inc
+--source include/ipv6.inc
+
+echo =============Test of '127.0.0.1' (IPv4) ===========================;
+let $IPv6= 127.0.0.1;
+--source include/ipv6_clients.inc
+--source include/ipv6.inc
+
diff --git a/mysql-test/t/join.test b/mysql-test/t/join.test
index 203a7d377a5..e07a3665920 100644
--- a/mysql-test/t/join.test
+++ b/mysql-test/t/join.test
@@ -1159,3 +1159,44 @@ DROP VIEW v2;
DROP TABLE t1,t2;
SET optimizer_switch=@save_optimizer_switch;
+
+--echo #
+--echo # Bug #35268: Parser can't handle STRAIGHT_JOIN with USING
+--echo #
+
+CREATE TABLE t1 (a int);
+
+INSERT INTO t1 (a) VALUES (1),(2),(3),(4),(5),(6),(7),(8);
+
+CREATE TABLE t2 (a int);
+
+INSERT INTO t2 (a) VALUES (1),(2),(3),(4);
+
+EXPLAIN
+SELECT t1.a FROM t1 NATURAL INNER JOIN t2 ORDER BY t1.a;
+SELECT t1.a FROM t1 NATURAL INNER JOIN t2 ORDER BY t1.a;
+
+EXPLAIN
+SELECT t1.a FROM t1 STRAIGHT_JOIN t2 USING(a) ORDER BY t1.a;
+SELECT t1.a FROM t1 STRAIGHT_JOIN t2 USING(a) ORDER BY t1.a;
+
+EXPLAIN
+SELECT t1.a FROM t1 NATURAL STRAIGHT_JOIN t2 ORDER BY t1.a;
+SELECT t1.a FROM t1 NATURAL STRAIGHT_JOIN t2 ORDER BY t1.a;
+
+DROP TABLE t1,t2;
+
+--echo #
+--echo # MDEV-5635: join of a const table with non-const tables
+--echo #
+
+CREATE TABLE t1 (a varchar(3) NOT NULL) ENGINE=MyISAM;
+INSERT INTO t1 VALUES ('foo');
+
+CREATE TABLE t2 (b varchar(3), c varchar(3), INDEX(b)) ENGINE=MyISAM;
+INSERT INTO t2 VALUES ('bar', 'bar'),( 'qux', 'qux');
+
+SELECT STRAIGHT_JOIN * FROM t1, t2 AS t2_1, t2 AS t2_2
+ WHERE t2_2.c = t2_1.c AND t2_2.b = t2_1.b AND ( a IS NULL OR t2_1.c = a );
+
+DROP TABLE t1,t2;
diff --git a/mysql-test/t/join_cache.test b/mysql-test/t/join_cache.test
index 58a7b885356..8507d58eecd 100644
--- a/mysql-test/t/join_cache.test
+++ b/mysql-test/t/join_cache.test
@@ -3589,7 +3589,7 @@ DROP TABLE t1,t2,t3;
--echo #
--echo # Bug #1058071: LEFT JOIN using blobs
---echo # (mdev-564) when join buffer size is small
+--echo # (MDEV-564) when join buffer size is small
--echo #
CREATE TABLE t1 (
@@ -3656,8 +3656,7 @@ explain select * from t0,t1 left join t2 on t1.b=t2.b order by t0.a, t1.a;
drop table t0,t1,t2;
---echo #
---echo # mdev-6292: huge performance degradation for a sequence
+--echo # MDEV-6292: huge performance degradation for a sequence
--echo # of LEFT JOIN operations when using join buffer
--echo #
@@ -3836,5 +3835,82 @@ set optimizer_switch=@save_optimizer_switch;
DROP TABLE t1,t4,t5,t2;
+--echo #
+--echo # MDEV-5123 Remove duplicated conditions pushed both to join_tab->select_cond and join_tab->cache_select->cond for blocked joins.
+--echo #
+
+set join_cache_level=default;
+set expensive_subquery_limit=0;
+
+create table t1 (c1 int);
+create table t2 (c2 int);
+create table t3 (c3 int);
+
+insert into t1 values (1), (2);
+insert into t2 values (1), (2);
+insert into t3 values (2);
+
+explain
+select count(*) from t1 straight_join t2
+where c1 = c2-0 and c2 <= (select max(c3) from t3 where c3 = 2 and @counter:=@counter+1);
+
+set @counter=0;
+
+select count(*) from t1 straight_join t2
+where c1 = c2-0 and c2 <= (select max(c3) from t3 where c3 = 2 and @counter:=@counter+1);
+
+select @counter;
+
+explain
+select count(*) from t1 straight_join t2
+where c1 = c2-0 and
+ c2 <= (select max(c3) from t3 where c3 = 2 and @counter:=@counter+1) and
+ c2 / 2 = 1;
+
+set @counter=0;
+
+select count(*) from t1 straight_join t2
+where c1 = c2-0 and
+ c2 <= (select max(c3) from t3 where c3 = 2 and @counter:=@counter+1) and
+ c2 / 2 = 1;
+
+select @counter;
+
+drop table t1,t2,t3;
+set expensive_subquery_limit=default;
+
+--echo #
+--echo # MDEV-6071: EXPLAIN chooses to use join buffer while execution turns it down
+--echo #
+
+create table t1 (a int);
+insert into t1 values
+(7), (9), (1), (4), (2), (3), (5), (8), (11), (6), (10);
+
+explain select count(*) from t1, t1 t2 where t1.a=t2.a;
+
+set join_buffer_space_limit=1024*8;
+select @@join_buffer_space_limit;
+select @@join_buffer_size;
+
+explain select count(*) from t1, t1 t2 where t1.a=t2.a;
+
+set join_buffer_space_limit=default;
+
+drop table t1;
+
+--echo #
+--echo # MDEV-6687: Assertion `0' failed in Protocol::end_statement on query
+--echo #
+SET join_cache_level = 3;
+--echo # The following should have
+--echo # - table order PROFILING,user,
+--echo # - table user accessed with hash_ALL:
+explain
+SELECT * FROM INFORMATION_SCHEMA.PROFILING, mysql.user WHERE password_expired = PAGE_FAULTS_MINOR;
+
+set join_cache_level=default;
+
+# The following command must be the last one the file
# this must be the last command in the file
set @@optimizer_switch=@save_optimizer_switch;
diff --git a/mysql-test/t/key.test b/mysql-test/t/key.test
index 9a4158d8e13..355c5ef53a4 100644
--- a/mysql-test/t/key.test
+++ b/mysql-test/t/key.test
@@ -561,3 +561,23 @@ SELECT 1 as RES FROM t1 AS t1_outer WHERE
(SELECT max(b) FROM t1 GROUP BY a HAVING a < 2) > 12;
DROP TABLE t1;
+
+--echo #
+--echo # Bug#18144: Cost with FORCE/USE index seems incorrect in some cases.
+--echo #
+--echo # We are interested in showing that the cost for the last plan is higher
+--echo # than for the preceding two plans.
+--echo #
+CREATE TABLE t1( a INT, b INT, KEY( a ) );
+INSERT INTO t1 values (1, 2), (1, 3), (2, 3), (2, 4), (3, 4), (3, 5);
+
+EXPLAIN SELECT a, SUM( b ) FROM t1 GROUP BY a;
+SHOW STATUS LIKE 'Last_query_cost';
+
+EXPLAIN SELECT a, SUM( b ) FROM t1 USE INDEX( a ) GROUP BY a;
+SHOW STATUS LIKE 'Last_query_cost';
+
+EXPLAIN SELECT a, SUM( b ) FROM t1 FORCE INDEX( a ) GROUP BY a;
+SHOW STATUS LIKE 'Last_query_cost';
+
+DROP TABLE t1;
diff --git a/mysql-test/t/key_cache.test b/mysql-test/t/key_cache.test
index 9098ca466b7..d28e7c23a4c 100644
--- a/mysql-test/t/key_cache.test
+++ b/mysql-test/t/key_cache.test
@@ -8,6 +8,7 @@ drop table if exists t1, t2, t3;
SET @save_key_buffer_size=@@key_buffer_size;
SET @save_key_cache_block_size=@@key_cache_block_size;
SET @save_key_cache_segments=@@key_cache_segments;
+SET @save_key_cache_file_hash_size=@@key_cache_file_hash_size;
SELECT @@key_buffer_size, @@small.key_buffer_size;
@@ -62,19 +63,19 @@ select @@keycache1.key_buffer_size;
select @@keycache1.key_cache_block_size;
select @@key_buffer_size;
select @@key_cache_block_size;
+select @@key_cache_file_hash_size;
set global keycache1.key_buffer_size=1024*1024;
+let org_key_blocks_unused=`select unused_blocks as unused from information_schema.key_caches where key_cache_name="default"`;
+--disable_query_log
+eval set @org_key_blocks_unused=$org_key_blocks_unused;
+--enable_query_log
+
create table t1 (p int primary key, a char(10)) delay_key_write=1;
create table t2 (p int primary key, i int, a char(10), key k1(i), key k2(a));
-show status like 'key_blocks_used';
-
-# Following results differs on 64 and 32 bit systems because of different
-# pointer sizes, which takes up different amount of space in key cache
-
---replace_result 1812 KEY_BLOCKS_UNUSED 1793 KEY_BLOCKS_UNUSED 1674 KEY_BLOCKS_UNUSED 1818 KEY_BLOCKS_UNUSED 1824 KEY_BLOCKS_UNUSED
-show status like 'key_blocks_unused';
+select @org_key_blocks_unused-unused_blocks as key_blocks_unused, used_blocks as key_blocks_used from information_schema.key_caches where key_cache_name="default";
insert into t1 values (1, 'qqqq'), (11, 'yyyy');
insert into t2 values (1, 1, 'qqqq'), (2, 1, 'pppp'),
@@ -85,9 +86,7 @@ select * from t2;
update t1 set p=2 where p=1;
update t2 set i=2 where i=1;
-show status like 'key_blocks_used';
---replace_result 1808 KEY_BLOCKS_UNUSED 1789 KEY_BLOCKS_UNUSED 1670 KEY_BLOCKS_UNUSED 1814 KEY_BLOCKS_UNUSED 1820 KEY_BLOCKS_UNUSED
-show status like 'key_blocks_unused';
+select @org_key_blocks_unused-unused_blocks as key_blocks_unused, used_blocks as key_blocks_used from information_schema.key_caches where key_cache_name="default";
cache index t1 key (`primary`) in keycache1;
@@ -147,9 +146,7 @@ cache index t3 in keycache2;
cache index t1,t2 in default;
drop table t1,t2,t3;
-show status like 'key_blocks_used';
---replace_result 1812 KEY_BLOCKS_UNUSED 1793 KEY_BLOCKS_UNUSED 1674 KEY_BLOCKS_UNUSED 1818 KEY_BLOCKS_UNUSED 1824 KEY_BLOCKS_UNUSED
-show status like 'key_blocks_unused';
+select @org_key_blocks_unused-unused_blocks as key_blocks_unused, used_blocks as key_blocks_used from information_schema.key_caches where key_cache_name="default";
create table t1 (a int primary key);
cache index t1 in keycache2;
@@ -304,8 +301,8 @@ select * from t2;
update t1 set p=3 where p=1;
update t2 set i=2 where i=1;
---replace_result 1808 KEY_BLOCKS_UNUSED 1670 KEY_BLOCKS_UNUSED 1789 KEY_BLOCKS_UNUSED
-show status like 'key_%';
+select * from information_schema.session_status where variable_name like 'key_%' and variable_name != 'Key_blocks_unused';
+select variable_value into @key_blocks_unused from information_schema.session_status where variable_name = 'Key_blocks_unused';
--replace_column 7 #
select * from information_schema.key_caches where segment_number is null;
@@ -336,8 +333,9 @@ select * from t2;
update t1 set p=3 where p=1;
update t2 set i=2 where i=1;
---replace_result 1808 KEY_BLOCKS_UNUSED 1670 KEY_BLOCKS_UNUSED 1788 KEY_BLOCKS_UNUSED
-show status like 'key_%';
+
+select * from information_schema.session_status where variable_name like 'key_%' and variable_name != 'Key_blocks_unused';
+select variable_value < @key_blocks_unused from information_schema.session_status where variable_name = 'Key_blocks_unused';
--replace_column 7 #
select * from information_schema.key_caches where segment_number is null;
@@ -361,8 +359,8 @@ select * from t2;
update t1 set p=3 where p=1;
update t2 set i=2 where i=1;
---replace_result 1808 KEY_BLOCKS_UNUSED 1670 KEY_BLOCKS_UNUSED 1789 KEY_BLOCKS_UNUSED
-show status like 'key_%';
+select * from information_schema.session_status where variable_name like 'key_%' and variable_name != 'Key_blocks_unused';
+select variable_value = @key_blocks_unused from information_schema.session_status where variable_name = 'Key_blocks_unused';
--replace_column 7 #
select * from information_schema.key_caches where segment_number is null;
@@ -378,6 +376,7 @@ select * from information_schema.key_caches where segment_number is null;
# Switch back to 2 segments
set global key_buffer_size=32*1024;
+set global key_cache_file_hash_size=128;
select @@key_buffer_size;
set global key_cache_segments=2;
select @@key_cache_segments;
@@ -536,5 +535,6 @@ set global keycache2.key_buffer_size=0;
set global key_buffer_size=@save_key_buffer_size;
set global key_cache_segments=@save_key_cache_segments;
+set global key_cache_file_hash_size=@save_key_cache_file_hash_size;
# End of 5.2 tests
diff --git a/mysql-test/t/keywords.test b/mysql-test/t/keywords.test
index 6717cb44fbf..54052e65014 100644
--- a/mysql-test/t/keywords.test
+++ b/mysql-test/t/keywords.test
@@ -169,7 +169,7 @@ DROP TABLE t1;
create table option (option int not null);
drop table option;
---error 1064
+--error 1193
set option=1;
--error 1193
set option option=1;
diff --git a/mysql-test/t/kill.test b/mysql-test/t/kill.test
index 7c6c37ecfc6..06933bcb0b9 100644
--- a/mysql-test/t/kill.test
+++ b/mysql-test/t/kill.test
@@ -632,5 +632,20 @@ connection con4;
select 1;
connection default;
+--echo #
+--echo # MDEV-4911 - add KILL query id, and add query id information to
+--echo # processlist
+--echo #
+send SELECT SLEEP(1000);
+connection con1;
+let $wait_condition= SELECT @id:=QUERY_ID FROM INFORMATION_SCHEMA.PROCESSLIST WHERE INFO='SELECT SLEEP(1000)';
+source include/wait_condition.inc;
+KILL QUERY ID @id;
+connection default;
+reap;
+
+--error ER_NO_SUCH_QUERY
+KILL QUERY ID 0;
+
SET DEBUG_SYNC = 'RESET';
DROP FUNCTION MY_KILL;
diff --git a/mysql-test/t/kill_processlist-6619.test b/mysql-test/t/kill_processlist-6619.test
index 28f98bcbb24..551d36e03fd 100644
--- a/mysql-test/t/kill_processlist-6619.test
+++ b/mysql-test/t/kill_processlist-6619.test
@@ -2,14 +2,33 @@
# MDEV-6619 SHOW PROCESSLIST returns empty result set after KILL QUERY
#
--source include/not_embedded.inc
+--source include/have_debug_sync.inc
+
--enable_connect_log
--connect (con1,localhost,root,,)
--let $con_id = `SELECT CONNECTION_ID()`
+--replace_column 1 # 3 # 6 # 7 #
+SHOW PROCESSLIST;
+SET DEBUG_SYNC='before_execute_sql_command SIGNAL ready WAIT_FOR go';
+send SHOW PROCESSLIST;
--connection default
+# We must wait for the SHOW PROCESSLIST query to have started before sending
+# the kill. Otherwise, the KILL may be lost since it is reset at the start of
+# query execution.
+SET DEBUG_SYNC='now WAIT_FOR ready';
--replace_result $con_id con_id
eval KILL QUERY $con_id;
+SET DEBUG_SYNC='now SIGNAL go';
--connection con1
--error ER_QUERY_INTERRUPTED
-SHOW PROCESSLIST;
---replace_column 1 # 3 # 5 # 6 # 7 # 8 #
+reap;
+SET DEBUG_SYNC='reset';
+
+# Wait until default connection has reset query string
+let $wait_condition=
+ SELECT COUNT(*) = 1 from information_schema.processlist
+ WHERE info is NULL;
+--source include/wait_condition.inc
+
+--replace_column 1 # 3 # 6 # 7 #
SHOW PROCESSLIST;
diff --git a/mysql-test/t/kill_query-6728.test b/mysql-test/t/kill_query-6728.test
new file mode 100644
index 00000000000..485256a65b6
--- /dev/null
+++ b/mysql-test/t/kill_query-6728.test
@@ -0,0 +1,14 @@
+#
+# MDEV-6728 KILL QUERY executed on an idle connection can interrupt the next query
+#
+--enable_connect_log
+--connect (con1,localhost,root,,)
+let $id=`select connection_id()`;
+
+--connection default
+--replace_result $id id
+eval kill query $id;
+
+--connection con1
+select count(*) > 0 from mysql.user;
+
diff --git a/mysql-test/t/limit_rows_examined.test b/mysql-test/t/limit_rows_examined.test
index ef28a37108f..45ee483c7aa 100644
--- a/mysql-test/t/limit_rows_examined.test
+++ b/mysql-test/t/limit_rows_examined.test
@@ -502,7 +502,7 @@ SELECT a AS field1, alias2.d AS field2, alias2.f AS field3, alias2.e AS field4,
FROM t1, t2 AS alias2, t2 AS alias3
WHERE alias3.c IN ( SELECT 1 UNION SELECT 6 )
GROUP BY field1, field2, field3, field4, field5
-LIMIT ROWS EXAMINED 250;
+LIMIT ROWS EXAMINED 124;
SHOW STATUS LIKE 'Handler_read%';
SHOW STATUS LIKE 'Handler_tmp%';
diff --git a/mysql-test/t/locale.test b/mysql-test/t/locale.test
index 4944dc7a228..b1fbc40f0c8 100644
--- a/mysql-test/t/locale.test
+++ b/mysql-test/t/locale.test
@@ -82,3 +82,59 @@ SET NAMES latin1;
SELECT c FROM t1 WHERE DAYNAME(d)<>c;
SELECT c FROM t1 WHERE MONTHNAME(d)<>c;
DROP TABLE t1;
+
+--echo #
+--echo # Start of 5.6 tests
+--echo #
+
+--echo #
+--echo # WL#5303 Romansh locale for DAYNAME, MONTHNAME, DATE_FORMAT
+--echo #
+
+SET NAMES utf8;
+SET @old_50915_lc_time_names := @@lc_time_names;
+SET lc_time_names=en_US;
+SELECT DATE_FORMAT('2001-01-01', '%w %a %W');
+SELECT DATE_FORMAT('2001-03-01', '%c %b %M');
+SET lc_time_names=rm_CH;
+SELECT DATE_FORMAT('2001-01-01', '%w %a %W');
+SELECT DATE_FORMAT('2001-01-02', '%w %a %W');
+SELECT DATE_FORMAT('2001-01-03', '%w %a %W');
+SELECT DATE_FORMAT('2001-01-04', '%w %a %W');
+SELECT DATE_FORMAT('2001-01-05', '%w %a %W');
+SELECT DATE_FORMAT('2001-01-06', '%w %a %W');
+SELECT DATE_FORMAT('2001-01-07', '%w %a %W');
+SELECT DATE_FORMAT('2001-01-01', '%c %b %M');
+SELECT DATE_FORMAT('2001-02-01', '%c %b %M');
+SELECT DATE_FORMAT('2001-03-01', '%c %b %M');
+SELECT DATE_FORMAT('2001-04-01', '%c %b %M');
+SELECT DATE_FORMAT('2001-05-01', '%c %b %M');
+SELECT DATE_FORMAT('2001-06-01', '%c %b %M');
+SELECT DATE_FORMAT('2001-07-01', '%c %b %M');
+SELECT DATE_FORMAT('2001-08-01', '%c %b %M');
+SELECT DATE_FORMAT('2001-09-01', '%c %b %M');
+SELECT DATE_FORMAT('2001-10-01', '%c %b %M');
+SELECT DATE_FORMAT('2001-11-01', '%c %b %M');
+SELECT DATE_FORMAT('2001-12-01', '%c %b %M');
+SET lc_time_names=de_CH;
+SELECT DATE_FORMAT('2001-01-06', '%w %a %W');
+SELECT DATE_FORMAT('2001-09-01', '%c %b %M');
+
+# Checking AM/PM
+SELECT DATE_FORMAT('2010-03-23 11:00:00','%h %p');
+SELECT DATE_FORMAT('2010-03-23 13:00:00','%h %p');
+
+# Checking numeric format
+SELECT format(123456789,2,'rm_CH');
+
+# Checking that error messages point to en_US.
+SET lc_messages=rm_CH;
+--error ER_NO_SUCH_TABLE
+SELECT * FROM non_existent;
+
+SET lc_time_names=@old_50915_lc_time_names;
+
+
+--echo #
+--echo # End of 5.6 tests
+--echo #
diff --git a/mysql-test/t/lock_multi.test b/mysql-test/t/lock_multi.test
index fc507608bdb..753b6bd6379 100644
--- a/mysql-test/t/lock_multi.test
+++ b/mysql-test/t/lock_multi.test
@@ -57,7 +57,7 @@ drop table t1;
connection locker;
create table t1(n int);
-insert into t1 values (1);
+insert into t1 values (1),(2);
connection locker2;
select get_lock("mysqltest_lock", 100);
connection locker;
diff --git a/mysql-test/t/lock_sync.test b/mysql-test/t/lock_sync.test
index bcb78b5b600..ef79cc2c0f4 100644
--- a/mysql-test/t/lock_sync.test
+++ b/mysql-test/t/lock_sync.test
@@ -49,6 +49,7 @@ drop table if exists t0, t1, t2, t3, t4, t5;
drop view if exists v1, v2;
drop procedure if exists p1;
drop procedure if exists p2;
+drop procedure if exists p3;
drop function if exists f1;
drop function if exists f2;
drop function if exists f3;
@@ -64,6 +65,8 @@ drop function if exists f12;
drop function if exists f13;
drop function if exists f14;
drop function if exists f15;
+drop function if exists f16;
+drop function if exists f17;
--enable_warnings
create table t1 (i int primary key);
insert into t1 values (1), (2), (3), (4), (5);
@@ -170,6 +173,26 @@ begin
call p2(k);
return k;
end|
+create function f16() returns int
+begin
+ create temporary table if not exists temp1 (a int);
+ insert into temp1 select * from t1;
+ drop temporary table temp1;
+ return 1;
+end|
+create function f17() returns int
+begin
+ declare j int;
+ select i from t1 where i = 1 into j;
+ call p3;
+ return 1;
+end|
+create procedure p3()
+begin
+ create temporary table if not exists temp1 (a int);
+ insert into temp1 select * from t1;
+ drop temporary table temp1;
+end|
create trigger t4_bi before insert on t4 for each row
begin
declare k int;
@@ -217,6 +240,7 @@ connection con1;
--disable_result_log
show create procedure p1;
show create procedure p2;
+show create procedure p3;
show create function f1;
show create function f2;
show create function f3;
@@ -232,6 +256,8 @@ show create function f12;
show create function f13;
show create function f14;
show create function f15;
+show create function f16;
+show create function f17;
--enable_result_log
--echo # Switch back to connection 'default'.
connection default;
@@ -492,18 +518,15 @@ let $restore_table= t2;
--echo # 4.1 SELECT/SET with a stored function which does not
--echo # modify data and uses SELECT in its turn.
--echo #
---echo # In theory there is no need to take strong locks on the table
+--echo # There is no need to take strong locks on the table
--echo # being selected from in SF as the call to such function
---echo # won't get into the binary log. In practice, however, we
---echo # discover that fact too late in the process to be able to
---echo # affect the decision what locks should be taken.
---echo # Hence, strong locks are taken in this case.
+--echo # won't get into the binary log.
let $statement= select f1();
let $restore_table= ;
---source include/check_no_concurrent_insert.inc
+--source include/check_concurrent_insert.inc
let $statement= set @a:= f1();
let $restore_table= ;
---source include/check_no_concurrent_insert.inc
+--source include/check_concurrent_insert.inc
--echo #
--echo # 4.2 INSERT (or other statement which modifies data) with
@@ -538,22 +561,20 @@ let $restore_table= t2;
--echo # modify data and reads a table through subselect
--echo # in a control construct.
--echo #
---echo # Again, in theory a call to this function won't get to the
---echo # binary log and thus no strong lock is needed. But in practice
---echo # we don't detect this fact early enough (get_lock_type_for_table())
---echo # to avoid taking a strong lock.
+--echo # Call to this function won't get to the
+--echo # binary log and thus no strong lock is needed.
let $statement= select f3();
let $restore_table= ;
---source include/check_no_concurrent_insert.inc
+--source include/check_concurrent_insert.inc
let $statement= set @a:= f3();
let $restore_table= ;
---source include/check_no_concurrent_insert.inc
+--source include/check_concurrent_insert.inc
let $statement= select f4();
let $restore_table= ;
---source include/check_no_concurrent_insert.inc
+--source include/check_concurrent_insert.inc
let $statement= set @a:= f4();
let $restore_table= ;
---source include/check_no_concurrent_insert.inc
+--source include/check_concurrent_insert.inc
--echo #
--echo # 4.5. INSERT (or other statement which modifies data) with
@@ -591,22 +612,21 @@ let $restore_table= t2;
--echo # doesn't modify data and reads tables through
--echo # a view.
--echo #
---echo # Once again, in theory, calls to such functions won't
---echo # get into the binary log and thus don't need strong
---echo # locks. But in practice this fact is discovered
---echo # too late to have any effect.
+--echo # Calls to such functions won't get into
+--echo # the binary log and thus don't need strong
+--echo # locks.
let $statement= select f6();
let $restore_table= t2;
---source include/check_no_concurrent_insert.inc
+--source include/check_concurrent_insert.inc
let $statement= set @a:= f6();
let $restore_table= t2;
---source include/check_no_concurrent_insert.inc
+--source include/check_concurrent_insert.inc
let $statement= select f7();
let $restore_table= t2;
---source include/check_no_concurrent_insert.inc
+--source include/check_concurrent_insert.inc
let $statement= set @a:= f7();
let $restore_table= t2;
---source include/check_no_concurrent_insert.inc
+--source include/check_concurrent_insert.inc
--echo #
--echo # 4.8 INSERT which uses stored function which
@@ -644,12 +664,11 @@ let $restore_table= t2;
--echo # data and reads a table indirectly, by calling another
--echo # function.
--echo #
---echo # In theory, calls to such functions won't get into the binary
---echo # log and thus don't need to acquire strong locks. But in practice
---echo # this fact is discovered too late to have any effect.
+--echo # Calls to such functions won't get into the binary
+--echo # log and thus don't need to acquire strong locks.
let $statement= select f10();
let $restore_table= ;
---source include/check_no_concurrent_insert.inc
+--source include/check_concurrent_insert.inc
--echo #
--echo # 4.11 INSERT which uses a stored function which doesn't modify
@@ -700,6 +719,36 @@ let $statement= insert into t2 values (f13((select i+10 from t1 where i=1)));
let $restore_table= t2;
--source include/check_no_concurrent_insert.inc
+--echo #
+--echo # 4.15 SELECT/SET with a stored function which
+--echo # inserts data into a temporary table using
+--echo # SELECT on t1.
+--echo #
+--echo # Since this statement is written to the binary log it should
+--echo # be serialized with concurrent statements affecting the data it
+--echo # uses. Therefore it should take strong locks on the data it reads.
+let $statement= select f16();
+let $restore_table= ;
+--source include/check_no_concurrent_insert.inc
+let $statement= set @a:= f16();
+let $restore_table= ;
+--source include/check_no_concurrent_insert.inc
+
+--echo #
+--echo # 4.16 SELECT/SET with a stored function which call procedure
+--echo # which inserts data into a temporary table using
+--echo # SELECT on t1.
+--echo #
+--echo # Since this statement is written to the binary log it should
+--echo # be serialized with concurrent statements affecting the data it
+--echo # uses. Therefore it should take strong locks on the data it reads.
+let $statement= select f17();
+let $restore_table= ;
+--source include/check_no_concurrent_insert.inc
+let $statement= set @a:= f17();
+let $restore_table= ;
+--source include/check_no_concurrent_insert.inc
+
--echo #
--echo # 5. Statements that read tables through stored procedures.
@@ -730,12 +779,11 @@ let $restore_table= t2;
--echo # 5.3 SELECT that calls a function that doesn't modify data and
--echo # uses a CALL statement that reads a table via SELECT.
--echo #
---echo # In theory, calls to such functions won't get into the binary
---echo # log and thus don't need to acquire strong locks. But in practice
---echo # this fact is discovered too late to have any effect.
+--echo # Calls to such functions won't get into the binary
+--echo # log and thus don't need to acquire strong locks.
let $statement= select f15();
let $restore_table= ;
---source include/check_no_concurrent_insert.inc
+--source include/check_concurrent_insert.inc
--echo #
--echo # 5.4 INSERT which calls function which doesn't modify data and
@@ -800,7 +848,6 @@ let $statement= update t5 set l= 2 where l = 1;
let $restore_table= t5;
--source include/check_no_concurrent_insert.inc
-
--echo # Clean-up.
drop function f1;
drop function f2;
@@ -817,9 +864,12 @@ drop function f12;
drop function f13;
drop function f14;
drop function f15;
+drop function f16;
+drop function f17;
drop view v1, v2;
drop procedure p1;
drop procedure p2;
+drop procedure p3;
drop table t1, t2, t3, t4, t5;
disconnect con1;
@@ -1136,62 +1186,6 @@ DROP TABLE t1;
disconnect con1;
disconnect con2;
---echo #
---echo # Bug#19070633 - POSSIBLE ACCESS TO FREED MEMORY IN IS_FREE_LOCK() AND IS_USED_LOCK().
---echo #
-
---enable_connect_log
-
---echo # Verifying issue for IS_FREE_LOCK() function.
-SELECT GET_LOCK("lock_19070633", 600);
-
-connect (con1, localhost, root,,);
---echo # Waiting after getting user level lock info and releasing mutex.
-SET DEBUG_SYNC= 'after_getting_user_level_lock_info SIGNAL parked WAIT_FOR go';
---echo # Sending: SELECT IS_FREE_LOCK("lock_19070633");
-send SELECT IS_FREE_LOCK("lock_19070633");
-
-connection default;
-SET DEBUG_SYNC= 'now WAIT_FOR parked';
-SELECT RELEASE_LOCK("lock_19070633");
---echo # Signaling connection con1 after releasing the lock.
---echo # Without fix, accessing user level lock info in con1 would result in
---echo # crash or valgrind issue invalid read is reported.
-SET DEBUG_SYNC= 'now SIGNAL go';
-
-connection con1;
---echo # Reaping: SELECT IS_FREE_LOCK("lock_19070633");
---reap
-
-connection default;
---echo # Verifying issue for IS_USED_LOCK() function.
-SELECT GET_LOCK("lock_19070633", 600);
-
-connection con1;
---echo # Waiting after getting user level lock info and releasing mutex.
-SET DEBUG_SYNC= 'after_getting_user_level_lock_info SIGNAL parked WAIT_FOR go';
---echo # Sending: SELECT IS_USED_LOCK("lock_19070633");
-send SELECT IS_USED_LOCK("lock_19070633");
-
-connection default;
-SET DEBUG_SYNC= 'now WAIT_FOR parked';
-SELECT RELEASE_LOCK("lock_19070633");
---echo # Signaling connection con1 after releasing the lock.
---echo # Without fix, accessing user level lock info in con1 would result in
---echo # crash or valgrind issue invalid read is reported.
-SET DEBUG_SYNC= 'now SIGNAL go';
-
-connection con1;
---echo # Reaping: SELECT IS_USED_LOCK("lock_19070633");
---replace_column 1 #
---reap
-
-connection default;
-SET DEBUG_SYNC= 'RESET';
-disconnect con1;
-
---disable_connect_log
-
# Check that all connections opened by test cases in this file are really
# gone so execution of other tests won't be affected by their presence.
--source include/wait_until_count_sessions.inc
diff --git a/mysql-test/t/log_errchk.test b/mysql-test/t/log_errchk.test
index 4f052b5e2f3..2808458e9f1 100644
--- a/mysql-test/t/log_errchk.test
+++ b/mysql-test/t/log_errchk.test
@@ -40,7 +40,7 @@
# Error 6 is reported, because the other end is closed
call mtr.add_suppression("Could not use .* for logging \\(error 6\\)");
-call mtr.add_suppression("File '.*' not found \\(Errcode: 6\\)");
+call mtr.add_suppression("File '.*' not found \\(Errcode: 6 ");
--perl
my $file= $ENV{'GREP_FILE'};
my $pattern= "for logging \\(error 6\\)\\. Turning logging off for the whole duration";
diff --git a/mysql-test/t/log_state-master.opt b/mysql-test/t/log_state-master.opt
index 445c6223d47..858bf269a7d 100644
--- a/mysql-test/t/log_state-master.opt
+++ b/mysql-test/t/log_state-master.opt
@@ -1 +1 @@
---log-output=TABLE,FILE --log --general-log=0 --log-slow-queries --slow-query-log=0
+--log-output=TABLE,FILE --general-log=0 --slow-query-log=0
diff --git a/mysql-test/t/log_state.test b/mysql-test/t/log_state.test
index e8f0bf8c511..3231769a4bf 100644
--- a/mysql-test/t/log_state.test
+++ b/mysql-test/t/log_state.test
@@ -18,8 +18,7 @@ set global general_log= OFF;
truncate table mysql.general_log;
truncate table mysql.slow_log;
show global variables
-where Variable_name = 'log' or Variable_name = 'log_slow_queries' or
-Variable_name = 'general_log' or Variable_name = 'slow_query_log';
+where Variable_name = 'general_log' or Variable_name = 'slow_query_log';
flush logs;
set global general_log= ON;
create table t1(f1 int);
@@ -32,8 +31,7 @@ select * from mysql.general_log;
set global general_log= ON;
flush logs;
show global variables
-where Variable_name = 'log' or Variable_name = 'log_slow_queries' or
-Variable_name = 'general_log' or Variable_name = 'slow_query_log';
+where Variable_name = 'general_log' or Variable_name = 'slow_query_log';
--echo # Establish connection con1 (user=root)
connect (con1,localhost,root,,);
@@ -48,7 +46,7 @@ connection con1;
set @long_query_time = 2;
set session long_query_time = @long_query_time;
select sleep(@long_query_time + 1);
---replace_column 1 TIMESTAMP 2 USER_HOST 3 QUERY_TIME
+--replace_column 1 TIMESTAMP 2 USER_HOST 3 QUERY_TIME 12 THREAD_ID
select * from mysql.slow_log where sql_text NOT LIKE '%slow_log%';
--echo # Switch to connection default
connection default;
@@ -58,13 +56,12 @@ set global slow_query_log= ON;
connection con1;
set session long_query_time = @long_query_time;
select sleep(@long_query_time + 1);
---replace_column 1 TIMESTAMP 2 USER_HOST 3 QUERY_TIME
+--replace_column 1 TIMESTAMP 2 USER_HOST 3 QUERY_TIME 12 THREAD_ID
select * from mysql.slow_log where sql_text NOT LIKE '%slow_log%';
--echo # Switch to connection default
connection default;
show global variables
-where Variable_name = 'log' or Variable_name = 'log_slow_queries' or
-Variable_name = 'general_log' or Variable_name = 'slow_query_log';
+where Variable_name = 'general_log' or Variable_name = 'slow_query_log';
set global general_log= ON;
set global general_log= OFF;
@@ -85,8 +82,7 @@ truncate table mysql.general_log;
select * from mysql.general_log;
set global general_log= ON;
show global variables
-where Variable_name = 'log' or Variable_name = 'log_slow_queries' or
-Variable_name = 'general_log' or Variable_name = 'slow_query_log';
+where Variable_name = 'general_log' or Variable_name = 'slow_query_log';
--replace_column 2 #
show variables like 'general_log_file';
@@ -206,42 +202,6 @@ SET GLOBAL slow_query_log = @old_slow_query_log;
###########################################################################
#
-# Bug#29131: SHOW VARIABLES reports variable 'log' but SET doesn't recognize it
-#
-
-SET GLOBAL general_log = ON;
-
-SHOW VARIABLES LIKE 'general_log';
-SHOW VARIABLES LIKE 'log';
-SELECT @@general_log, @@log;
-SET GLOBAL log = 0;
-SHOW VARIABLES LIKE 'general_log';
-SHOW VARIABLES LIKE 'log';
-SELECT @@general_log, @@log;
-SET GLOBAL general_log = 1;
-SHOW VARIABLES LIKE 'general_log';
-SHOW VARIABLES LIKE 'log';
-SELECT @@general_log, @@log;
-
-SHOW VARIABLES LIKE 'slow_query_log';
-SHOW VARIABLES LIKE 'log_slow_queries';
-SELECT @@slow_query_log, @@log_slow_queries;
-SET GLOBAL log_slow_queries = 0;
-SHOW VARIABLES LIKE 'slow_query_log';
-SHOW VARIABLES LIKE 'log_slow_queries';
-SELECT @@slow_query_log, @@log_slow_queries;
-SET GLOBAL slow_query_log = 1;
-SHOW VARIABLES LIKE 'slow_query_log';
-SHOW VARIABLES LIKE 'log_slow_queries';
-SELECT @@slow_query_log, @@log_slow_queries;
-
-SET GLOBAL general_log = @old_general_log;
-SET GLOBAL slow_query_log = @old_slow_query_log;
-
-
-###########################################################################
-
-#
# Bug#31604: server crash when setting slow_query_log_file/general_log_file
#
@@ -284,37 +244,6 @@ SET GLOBAL slow_query_log_file = @old_slow_query_log_file;
###########################################################################
-# WL#4403 - deprecate @log and @slow_log_queries variables
-
-# These server system variables are all deprecated
-# -- show for command-line as well!
---echo deprecated:
-SET GLOBAL log = 0;
-SET GLOBAL log_slow_queries = 0;
-SET GLOBAL log = DEFAULT;
-SET GLOBAL log_slow_queries = DEFAULT;
-
-# These server system variables are NOT deprecated.
---echo not deprecated:
-SELECT @@global.general_log_file INTO @my_glf;
-SELECT @@global.slow_query_log_file INTO @my_sqlf;
-SET GLOBAL general_log = 0;
-SET GLOBAL slow_query_log = 0;
-SET GLOBAL general_log_file = 'WL4403_G.log';
-SET GLOBAL slow_query_log_file = 'WL4403_SQ.log';
-SET GLOBAL general_log_file = @my_glf;
-SET GLOBAL slow_query_log_file = @my_sqlf;
-SET GLOBAL general_log = DEFAULT;
-SET GLOBAL slow_query_log = DEFAULT;
-
-## Reset to initial values
-SET @@global.general_log = @old_general_log;
-SET @@global.general_log_file = @old_general_log_file;
-SET @@global.slow_query_log = @old_slow_query_log;
-SET @@global.slow_query_log_file = @old_slow_query_log_file;
-
-###########################################################################
-
--echo #
--echo # Bug #49756 Rows_examined is always 0 in the slow query log
--echo # for update statements
diff --git a/mysql-test/t/log_state_bug33693-master.opt b/mysql-test/t/log_state_bug33693-master.opt
index 9f4ae1a0c8f..fa3cf2ef78f 100644
--- a/mysql-test/t/log_state_bug33693-master.opt
+++ b/mysql-test/t/log_state_bug33693-master.opt
@@ -1 +1 @@
---pid-file=$MYSQLTEST_VARDIR/run/mysqld.1.pid --log=
+--pid-file=$MYSQLTEST_VARDIR/run/mysqld.1.pid --general-log --general-log-file=
diff --git a/mysql-test/t/log_tables.test b/mysql-test/t/log_tables.test
index eb652946672..6fd26ab2011 100644
--- a/mysql-test/t/log_tables.test
+++ b/mysql-test/t/log_tables.test
@@ -3,7 +3,6 @@
#
# Basic log tables test
#
-
# check that CSV engine was compiled in
--source include/have_csv.inc
@@ -180,7 +179,7 @@ drop table bug16905;
truncate table mysql.slow_log;
set session long_query_time=1;
select sleep(2);
---replace_column 1 TIMESTAMP 2 USER_HOST 3 QUERY_TIME
+--replace_column 1 TIMESTAMP 2 USER_HOST 3 QUERY_TIME 12 THREAD_ID
select * from mysql.slow_log;
set @@session.long_query_time = @saved_long_query_time;
@@ -290,10 +289,10 @@ drop table mysql.slow_log;
use mysql;
CREATE TABLE `general_log` (
- `event_time` timestamp(6) NOT NULL DEFAULT CURRENT_TIMESTAMP
+ `event_time` TIMESTAMP(6) NOT NULL DEFAULT CURRENT_TIMESTAMP
ON UPDATE CURRENT_TIMESTAMP,
`user_host` mediumtext NOT NULL,
- `thread_id` int(11) NOT NULL,
+ `thread_id` BIGINT(21) UNSIGNED NOT NULL,
`server_id` int(10) unsigned NOT NULL,
`command_type` varchar(64) NOT NULL,
`argument` mediumtext NOT NULL
@@ -311,7 +310,8 @@ CREATE TABLE `slow_log` (
`last_insert_id` int(11) NOT NULL,
`insert_id` int(11) NOT NULL,
`server_id` int(10) unsigned NOT NULL,
- `sql_text` mediumtext NOT NULL
+ `sql_text` mediumtext NOT NULL,
+ `thread_id` BIGINT(21) UNSIGNED NOT NULL
) ENGINE=CSV DEFAULT CHARSET=utf8 COMMENT='Slow log';
set global general_log='ON';
@@ -727,7 +727,8 @@ CREATE TABLE `db_17876.slow_log_data` (
`last_insert_id` int(11) default NULL,
`insert_id` int(11) default NULL,
`server_id` int(11) default NULL,
- `sql_text` mediumtext
+ `sql_text` mediumtext,
+ `thread_id` bigint(21) unsigned default NULL
);
CREATE TABLE `db_17876.general_log_data` (
@@ -746,6 +747,7 @@ BEGIN
DECLARE start_time, query_time, lock_time CHAR(28);
DECLARE user_host MEDIUMTEXT;
DECLARE rows_set, rows_examined, last_insert_id, insert_id, server_id INT;
+ DECLARE thread_id BIGINT UNSIGNED;
DECLARE dbname MEDIUMTEXT;
DECLARE sql_text BLOB;
DECLARE done INT DEFAULT 0;
@@ -763,7 +765,7 @@ BEGIN
FETCH cur1 INTO
start_time, user_host, query_time, lock_time,
rows_set, rows_examined, dbname, last_insert_id,
- insert_id, server_id, sql_text;
+ insert_id, server_id, sql_text, thread_id;
END;
IF NOT done THEN
@@ -771,7 +773,7 @@ BEGIN
INSERT INTO
`db_17876.slow_log_data`
VALUES(start_time, user_host, query_time, lock_time, rows_set, rows_examined,
- dbname, last_insert_id, insert_id, server_id, sql_text);
+ dbname, last_insert_id, insert_id, server_id, sql_text, thread_id);
END;
END IF;
END;
diff --git a/mysql-test/t/log_tables_upgrade.test b/mysql-test/t/log_tables_upgrade.test
index a638a27c9d1..d08d74174db 100644
--- a/mysql-test/t/log_tables_upgrade.test
+++ b/mysql-test/t/log_tables_upgrade.test
@@ -1,11 +1,6 @@
---source include/not_embedded.inc
--source include/have_csv.inc
-
-# Only run test if "mysql_upgrade" is found
---require r/have_mysql_upgrade.result
---disable_query_log
-select LENGTH("$MYSQL_UPGRADE")>0 as have_mysql_upgrade;
---enable_query_log
+--source include/have_innodb.inc
+--source include/mysql_upgrade_preparation.inc
--echo #
--echo # Bug#49823: mysql_upgrade fatal error due to general_log / slow_low CSV NULL
diff --git a/mysql-test/t/lowercase_fs_off.test b/mysql-test/t/lowercase_fs_off.test
index 1be0351f9bc..01989ef5367 100644
--- a/mysql-test/t/lowercase_fs_off.test
+++ b/mysql-test/t/lowercase_fs_off.test
@@ -102,3 +102,11 @@ CREATE TRIGGER t1_bi BEFORE INSERT ON t1 FOR EACH ROW SET new.a= 1;
RENAME TABLE t1 TO T1;
ALTER TABLE T1 RENAME t1;
DROP TABLE t1;
+
+#
+# MDEV-9014 SHOW TRIGGERS not case sensitive
+#
+create table t1 (a int);
+create trigger t1_bi before insert on t1 for each row set new.a= 1;
+show triggers like '%T1%';
+drop table t1;
diff --git a/mysql-test/t/lowercase_table.test b/mysql-test/t/lowercase_table.test
index 31513f1bd06..c339105aae4 100644
--- a/mysql-test/t/lowercase_table.test
+++ b/mysql-test/t/lowercase_table.test
@@ -105,3 +105,16 @@ drop table Ä°Ä°;
set names latin1;
--echo End of 5.0 tests
+
+#
+# Bug#21317: SHOW CREATE DATABASE does not obey to lower_case_table_names
+#
+create database mysql_TEST character set latin2;
+create table mysql_TEST.T1 (a int);
+show create database mysql_TEST;
+show create table mysql_TEST.T1;
+show databases like "mysql%";
+show databases like "mysql_TE%";
+drop database mysql_TEST;
+
+--echo End of 10.0 tests
diff --git a/mysql-test/t/lowercase_table2.test b/mysql-test/t/lowercase_table2.test
index 30433d15be4..ec495ac4708 100644
--- a/mysql-test/t/lowercase_table2.test
+++ b/mysql-test/t/lowercase_table2.test
@@ -80,6 +80,15 @@ SHOW TABLES LIKE "T1";
SELECT * from T1;
DROP TABLE T1;
+create database mysqltest_UPPERCASE;
+CREATE TABLE mysqltest_UPPERCASE.T1 (a int) engine=innodb;
+CREATE TABLE mysqltest_uppercase.t2 (a int) engine=innodb;
+CREATE TABLE mysqltest_UPPERCASE.t3 (a int) engine=innodb;
+drop table mysqltest_UPPERCASE.T1;
+drop table mysqltest_UPPERCASE.T2;
+drop table mysqltest_uppercase.t3;
+drop database mysqltest_UPPERCASE;
+
#
# Test problem with temporary tables (Bug #2858)
#
@@ -119,6 +128,7 @@ drop table T1;
create database mysqltest_LC2;
use mysqltest_LC2;
create table myUC (i int);
+show tables;
insert into myUC values (1),(2),(3);
select * from myUC;
use test;
@@ -208,13 +218,18 @@ drop table if exists t_bug44738_UPPERCASE;
--enable_warnings
create database mysqltest_UPPERCASE;
use mysqltest_UPPERCASE;
+select database();
create table t_bug44738_UPPERCASE (i int) comment='Old comment';
create table t_bug44738_lowercase (i int) comment='Old comment';
+create table t_bug44738_UPPERCASE2 (i int) comment='Old comment';
+create table t_bug44738_lowercase2 (i int) comment='Old comment';
select table_schema, table_name, table_comment from information_schema.tables
where table_schema like 'mysqltest_%' and table_name like 't_bug44738_%'
order by table_name;
alter table t_bug44738_UPPERCASE comment='New comment';
alter table t_bug44738_lowercase comment='New comment';
+alter table mysqltest_uppercase.t_bug44738_UPPERCASE2 comment='New comment';
+alter table mysqltest_UPPERCASE.t_bug44738_lowercase2 comment='New comment';
--echo # There should be no stale entries in TDC for our tables after the
--echo # above ALTER TABLE statements so new version of comments should be
--echo # returned by the below query to I_S.
@@ -251,9 +266,25 @@ let $MYSQLD_DATADIR= `select @@datadir`;
--echo # Check that still there is an entry for table in TDC.
show open tables like 't_bug44738_%';
--echo # So attempt to create table with the same name should fail.
---error ER_FILE_NOT_FOUND
+--error ER_TABLE_EXISTS_ERROR
create table t_bug44738_UPPERCASE (i int);
--echo # And should succeed after FLUSH TABLES.
flush tables;
create table t_bug44738_UPPERCASE (i int);
drop table t_bug44738_UPPERCASE;
+
+--echo #
+--echo # Bug #21317 SHOW CREATE DATABASE does not obey to
+--echo # lower_case_table_names
+--echo #
+
+create database mysql_TEST;
+create table mysql_TEST.T1(a int);
+show databases like 'mysql%';
+show databases like 'mysql_T%';
+show databases like 'mysql_t%';
+show create database mysql_test;
+show create database mysql_TEST;
+show create table mysql_TEST.T1;
+show create table mysql_test.t1;
+drop database mysql_TEST;
diff --git a/mysql-test/t/lowercase_table4.test b/mysql-test/t/lowercase_table4.test
index 0775d87fc9d..435ff0dae66 100644
--- a/mysql-test/t/lowercase_table4.test
+++ b/mysql-test/t/lowercase_table4.test
@@ -72,7 +72,7 @@ CREATE TABLE `Table1`(c1 INT PRIMARY KEY) ENGINE=InnoDB;
CREATE TABLE `Table2`(c1 INT PRIMARY KEY, c2 INT) ENGINE=InnoDB;
ALTER TABLE `Table2` ADD CONSTRAINT fk1 FOREIGN KEY(c2) REFERENCES `Table1`(c1);
query_vertical SHOW CREATE TABLE `Table2`;
-query_vertical SELECT * FROM INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS;
+query_vertical SELECT * FROM INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS WHERE CONSTRAINT_SCHEMA='test';
DROP TABLE `Table2`;
DROP TABLE `Table1`;
@@ -101,7 +101,7 @@ CREATE TABLE Product_Order (No INT NOT NULL AUTO_INCREMENT,
query_vertical SHOW CREATE TABLE Product_Order;
query_vertical SHOW CREATE TABLE Product;
query_vertical SHOW CREATE TABLE Customer;
-query_vertical SELECT * FROM INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS;
+query_vertical SELECT * FROM INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS WHERE CONSTRAINT_SCHEMA='test';
DROP TABLE Product_Order;
DROP TABLE Product;
DROP TABLE Customer;
diff --git a/mysql-test/t/lowercase_table5.test b/mysql-test/t/lowercase_table5.test
new file mode 100644
index 00000000000..dfdfafcb3da
--- /dev/null
+++ b/mysql-test/t/lowercase_table5.test
@@ -0,0 +1,20 @@
+#
+# Tests that requires lower_case_table_names to be 0
+# (Normal case on Unix)
+#
+--source include/have_lowercase0.inc
+--source include/have_case_sensitive_file_system.inc
+
+#
+# Check caching of database options
+#
+
+CREATE DATABASE mysql_TEST CHARACTER SET utf8;
+SHOW CREATE DATABASE mysql_TEST;
+CREATE DATABASE mysql_test CHARACTER SET latin2;
+SHOW CREATE DATABASE mysql_test;
+SHOW CREATE DATABASE mysql_TEST;
+DROP DATABASE mysql_test;
+DROP DATABASE mysql_TEST;
+
+# End of 10.0 tests
diff --git a/mysql-test/t/mdev-504.test b/mysql-test/t/mdev-504.test
new file mode 100644
index 00000000000..b96c8779c68
--- /dev/null
+++ b/mysql-test/t/mdev-504.test
@@ -0,0 +1,80 @@
+--source include/not_valgrind.inc
+--disable_ps_protocol
+
+SET GLOBAL net_write_timeout = 900;
+
+CREATE TABLE A (
+ pk INTEGER AUTO_INCREMENT PRIMARY KEY,
+ fdate DATE
+) ENGINE=MyISAM;
+
+--delimiter |
+
+CREATE PROCEDURE p_analyze()
+BEGIN
+ DECLARE attempts INTEGER DEFAULT 100;
+ wl_loop: WHILE attempts > 0 DO
+ ANALYZE TABLE A;
+ SET attempts = attempts - 1;
+ END WHILE wl_loop;
+END |
+
+CREATE FUNCTION rnd3() RETURNS INT
+BEGIN
+ RETURN ROUND(3 * RAND() + 0.5);
+END |
+
+--delimiter ;
+
+SET GLOBAL use_stat_tables = PREFERABLY;
+
+--let $trial = 100
+
+--disable_query_log
+--disable_result_log
+--disable_warnings
+while ($trial)
+{
+
+ --connect (con1,localhost,root,,)
+ --send CALL p_analyze()
+
+ --connect (con2,localhost,root,,)
+ --send CALL p_analyze()
+
+ --let $run = 100
+
+ while ($run)
+ {
+ --connect (con3,localhost,root,,)
+
+ let $query = `SELECT CASE rnd3()
+ WHEN 1 THEN 'INSERT INTO A (pk) VALUES (NULL)'
+ WHEN 2 THEN 'DELETE FROM A LIMIT 1'
+ ELSE 'UPDATE A SET fdate = 2 LIMIT 1' END`;
+ --eval $query
+ --disconnect con3
+ --dec $run
+ }
+
+ --connection con2
+ --reap
+ --disconnect con2
+ --connection con1
+ --reap
+ --disconnect con1
+
+ --dec $trial
+}
+
+--enable_query_log
+--enable_result_log
+--enable_warnings
+
+# Cleanup
+--connection default
+DROP TABLE A;
+DROP PROCEDURE p_analyze;
+DROP FUNCTION rnd3;
+SET GLOBAL use_stat_tables = DEFAULT;
+SET GLOBAL net_write_timeout = DEFAULT;
diff --git a/mysql-test/t/mdev13607.test b/mysql-test/t/mdev13607.test
new file mode 100644
index 00000000000..45fdb0a74d4
--- /dev/null
+++ b/mysql-test/t/mdev13607.test
@@ -0,0 +1,60 @@
+--echo #
+--echo # Bug mdev-13607: overflow of current_record_count
+--echo #
+
+--source include/have_innodb.inc
+
+CREATE TABLE t1 (id INT) ENGINE=InnoDB;
+INSERT INTO t1 VALUES
+(1),(2),(3),(4),(5),(6),(7),(8),(9),(10),
+(11),(12),(13),(14),(15),(16),(17),(18),(19),(20),
+(21),(22),(23),(24),(25),(26),(27),(28),(29),(30),
+(31),(32),(33),(34),(35),(36),(37),(38),(39),(40),
+(41),(42),(43),(44),(45),(46),(47),(48),(49),(50);
+
+CREATE TABLE t2 (id INT) ENGINE=InnoDB;
+INSERT INTO t2 VALUES (1),(2);
+
+CREATE TABLE t3 (id INT) ENGINE=InnoDB;
+INSERT INTO t3 VALUES (1),(2);
+
+ANALYZE TABLE t1, t2, t3;
+
+let $q=
+SELECT * FROM
+(SELECT p1.* FROM t1 p1 NATURAL JOIN t2 r1 NATURAL JOIN t3 d1 NATURAL JOIN t1 p2 NATURAL JOIN t2 r2 NATURAL JOIN t3 d2 NATURAL JOIN t1 p3 NATURAL JOIN t2 r3 NATURAL JOIN t3 d3 NATURAL JOIN t1 p4 NATURAL JOIN t2 r4 NATURAL JOIN t3 d4 NATURAL JOIN t1 p5 NATURAL JOIN t2 r5 NATURAL JOIN t3 d5 NATURAL JOIN t1 p6 NATURAL JOIN t2 r6 NATURAL JOIN t3 d6 NATURAL JOIN t1 p7 NATURAL JOIN t2 r7 NATURAL JOIN t3 d7 NATURAL JOIN t1 p8 NATURAL JOIN t2 r8 NATURAL JOIN t3 d8 NATURAL JOIN t1 p9 ) gp_1
+INNER JOIN
+(SELECT p1.* FROM t1 p1 NATURAL JOIN t2 r1 NATURAL JOIN t3 d1 NATURAL JOIN t1 p2 NATURAL JOIN t2 r2 NATURAL JOIN t3 d2 NATURAL JOIN t1 p3 NATURAL JOIN t2 r3 NATURAL JOIN t3 d3 NATURAL JOIN t1 p4 NATURAL JOIN t2 r4 NATURAL JOIN t3 d4 NATURAL JOIN t1 p5 NATURAL JOIN t2 r5 NATURAL JOIN t3 d5 NATURAL JOIN t1 p6 NATURAL JOIN t2 r6 NATURAL JOIN t3 d6 NATURAL JOIN t1 p7 NATURAL JOIN t2 r7 NATURAL JOIN t3 d7 NATURAL JOIN t1 p8 NATURAL JOIN t2 r8 NATURAL JOIN t3 d8 NATURAL JOIN t1 p9 ) gp_2
+INNER JOIN
+(SELECT p1.* FROM t1 p1 NATURAL JOIN t2 r1 NATURAL JOIN t3 d1 NATURAL JOIN t1 p2 NATURAL JOIN t2 r2 NATURAL JOIN t3 d2 NATURAL JOIN t1 p3 NATURAL JOIN t2 r3 NATURAL JOIN t3 d3 NATURAL JOIN t1 p4 NATURAL JOIN t2 r4 NATURAL JOIN t3 d4 NATURAL JOIN t1 p5 NATURAL JOIN t2 r5 NATURAL JOIN t3 d5 NATURAL JOIN t1 p6 NATURAL JOIN t2 r6 NATURAL JOIN t3 d6 NATURAL JOIN t1 p7 NATURAL JOIN t2 r7 NATURAL JOIN t3 d7 NATURAL JOIN t1 p8 NATURAL JOIN t2 r8 NATURAL JOIN t3 d8 NATURAL JOIN t1 p9 ) gp_3
+INNER JOIN
+(SELECT p1.* FROM t1 p1 NATURAL JOIN t2 r1 NATURAL JOIN t3 d1 NATURAL JOIN t1 p2 NATURAL JOIN t2 r2 NATURAL JOIN t3 d2 NATURAL JOIN t1 p3 NATURAL JOIN t2 r3 NATURAL JOIN t3 d3 NATURAL JOIN t1 p4 NATURAL JOIN t2 r4 NATURAL JOIN t3 d4 NATURAL JOIN t1 p5 NATURAL JOIN t2 r5 NATURAL JOIN t3 d5 NATURAL JOIN t1 p6 NATURAL JOIN t2 r6 NATURAL JOIN t3 d6 NATURAL JOIN t1 p7 NATURAL JOIN t2 r7 NATURAL JOIN t3 d7 NATURAL JOIN t1 p8 NATURAL JOIN t2 r8 NATURAL JOIN t3 d8 NATURAL JOIN t1 p9 ) gp_4
+INNER JOIN
+(SELECT p1.* FROM t1 p1 NATURAL JOIN t2 r1 NATURAL JOIN t3 d1 NATURAL JOIN t1 p2 NATURAL JOIN t2 r2 NATURAL JOIN t3 d2 NATURAL JOIN t1 p3 NATURAL JOIN t2 r3 NATURAL JOIN t3 d3 NATURAL JOIN t1 p4 NATURAL JOIN t2 r4 NATURAL JOIN t3 d4 NATURAL JOIN t1 p5 NATURAL JOIN t2 r5 NATURAL JOIN t3 d5 NATURAL JOIN t1 p6 NATURAL JOIN t2 r6 NATURAL JOIN t3 d6 NATURAL JOIN t1 p7 NATURAL JOIN t2 r7 NATURAL JOIN t3 d7 NATURAL JOIN t1 p8 NATURAL JOIN t2 r8 NATURAL JOIN t3 d8 NATURAL JOIN t1 p9 ) gp_5
+INNER JOIN
+(SELECT p1.* FROM t1 p1 NATURAL JOIN t2 r1 NATURAL JOIN t3 d1 NATURAL JOIN t1 p2 NATURAL JOIN t2 r2 NATURAL JOIN t3 d2 NATURAL JOIN t1 p3 NATURAL JOIN t2 r3 NATURAL JOIN t3 d3 NATURAL JOIN t1 p4 NATURAL JOIN t2 r4 NATURAL JOIN t3 d4 NATURAL JOIN t1 p5 NATURAL JOIN t2 r5 NATURAL JOIN t3 d5 NATURAL JOIN t1 p6 NATURAL JOIN t2 r6 NATURAL JOIN t3 d6 NATURAL JOIN t1 p7 NATURAL JOIN t2 r7 NATURAL JOIN t3 d7 NATURAL JOIN t1 p8 NATURAL JOIN t2 r8 NATURAL JOIN t3 d8 NATURAL JOIN t1 p9 ) gp_6
+INNER JOIN
+(SELECT p1.* FROM t1 p1 NATURAL JOIN t2 r1 NATURAL JOIN t3 d1 NATURAL JOIN t1 p2 NATURAL JOIN t2 r2 NATURAL JOIN t3 d2 NATURAL JOIN t1 p3 NATURAL JOIN t2 r3 NATURAL JOIN t3 d3 NATURAL JOIN t1 p4 NATURAL JOIN t2 r4 NATURAL JOIN t3 d4 NATURAL JOIN t1 p5 NATURAL JOIN t2 r5 NATURAL JOIN t3 d5 NATURAL JOIN t1 p6 NATURAL JOIN t2 r6 NATURAL JOIN t3 d6 NATURAL JOIN t1 p7 NATURAL JOIN t2 r7 NATURAL JOIN t3 d7 NATURAL JOIN t1 p8 NATURAL JOIN t2 r8 NATURAL JOIN t3 d8 NATURAL JOIN t1 p9 ) gp_7
+INNER JOIN
+(SELECT p1.* FROM t1 p1 NATURAL JOIN t2 r1 NATURAL JOIN t3 d1 NATURAL JOIN t1 p2 NATURAL JOIN t2 r2 NATURAL JOIN t3 d2 NATURAL JOIN t1 p3 NATURAL JOIN t2 r3 NATURAL JOIN t3 d3 NATURAL JOIN t1 p4 NATURAL JOIN t2 r4 NATURAL JOIN t3 d4 NATURAL JOIN t1 p5 NATURAL JOIN t2 r5 NATURAL JOIN t3 d5 NATURAL JOIN t1 p6 NATURAL JOIN t2 r6 NATURAL JOIN t3 d6 NATURAL JOIN t1 p7 NATURAL JOIN t2 r7 NATURAL JOIN t3 d7 NATURAL JOIN t1 p8 NATURAL JOIN t2 r8 NATURAL JOIN t3 d8 NATURAL JOIN t1 p9 ) gp_8
+INNER JOIN
+(SELECT p1.* FROM t1 p1 NATURAL JOIN t2 r1 NATURAL JOIN t3 d1 NATURAL JOIN t1 p2 NATURAL JOIN t2 r2 NATURAL JOIN t3 d2 NATURAL JOIN t1 p3 NATURAL JOIN t2 r3 NATURAL JOIN t3 d3 NATURAL JOIN t1 p4 NATURAL JOIN t2 r4 NATURAL JOIN t3 d4 NATURAL JOIN t1 p5 NATURAL JOIN t2 r5 NATURAL JOIN t3 d5 NATURAL JOIN t1 p6 NATURAL JOIN t2 r6 NATURAL JOIN t3 d6 NATURAL JOIN t1 p7 NATURAL JOIN t2 r7 NATURAL JOIN t3 d7 NATURAL JOIN t1 p8 NATURAL JOIN t2 r8 NATURAL JOIN t3 d8 NATURAL JOIN t1 p9 ) gp_9
+INNER JOIN
+(SELECT p1.* FROM t1 p1 NATURAL JOIN t2 r1 NATURAL JOIN t3 d1 NATURAL JOIN t1 p2 NATURAL JOIN t2 r2 NATURAL JOIN t3 d2 NATURAL JOIN t1 p3 NATURAL JOIN t2 r3 NATURAL JOIN t3 d3 NATURAL JOIN t1 p4 NATURAL JOIN t2 r4 NATURAL JOIN t3 d4 NATURAL JOIN t1 p5 NATURAL JOIN t2 r5 NATURAL JOIN t3 d5 NATURAL JOIN t1 p6 NATURAL JOIN t2 r6 NATURAL JOIN t3 d6 NATURAL JOIN t1 p7 NATURAL JOIN t2 r7 NATURAL JOIN t3 d7 NATURAL JOIN t1 p8 NATURAL JOIN t2 r8 NATURAL JOIN t3 d8 NATURAL JOIN t1 p9 ) gp_10
+INNER JOIN
+(SELECT p1.* FROM t1 p1 NATURAL JOIN t2 r1 NATURAL JOIN t3 d1 NATURAL JOIN t1 p2 NATURAL JOIN t2 r2 NATURAL JOIN t3 d2 NATURAL JOIN t1 p3 NATURAL JOIN t2 r3 NATURAL JOIN t3 d3 NATURAL JOIN t1 p4 NATURAL JOIN t2 r4 NATURAL JOIN t3 d4 NATURAL JOIN t1 p5 NATURAL JOIN t2 r5 NATURAL JOIN t3 d5 NATURAL JOIN t1 p6 NATURAL JOIN t2 r6 NATURAL JOIN t3 d6 NATURAL JOIN t1 p7 NATURAL JOIN t2 r7 NATURAL JOIN t3 d7 NATURAL JOIN t1 p8 NATURAL JOIN t2 r8 NATURAL JOIN t3 d8 NATURAL JOIN t1 p9 ) gp_11
+INNER JOIN
+(SELECT p1.* FROM t1 p1 NATURAL JOIN t2 r1 NATURAL JOIN t3 d1 NATURAL JOIN t1 p2 NATURAL JOIN t2 r2 NATURAL JOIN t3 d2 NATURAL JOIN t1 p3 NATURAL JOIN t2 r3 NATURAL JOIN t3 d3 NATURAL JOIN t1 p4 NATURAL JOIN t2 r4 NATURAL JOIN t3 d4 NATURAL JOIN t1 p5 NATURAL JOIN t2 r5 NATURAL JOIN t3 d5 NATURAL JOIN t1 p6 NATURAL JOIN t2 r6 NATURAL JOIN t3 d6 NATURAL JOIN t1 p7 NATURAL JOIN t2 r7 NATURAL JOIN t3 d7 NATURAL JOIN t1 p8 NATURAL JOIN t2 r8 NATURAL JOIN t3 d8 NATURAL JOIN t1 p9 ) gp_12
+INNER JOIN
+(SELECT p1.* FROM t1 p1 NATURAL JOIN t2 r1 NATURAL JOIN t3 d1 NATURAL JOIN t1 p2 NATURAL JOIN t2 r2 NATURAL JOIN t3 d2 NATURAL JOIN t1 p3 NATURAL JOIN t2 r3 NATURAL JOIN t3 d3 NATURAL JOIN t1 p4 NATURAL JOIN t2 r4 NATURAL JOIN t3 d4 NATURAL JOIN t1 p5 NATURAL JOIN t2 r5 NATURAL JOIN t3 d5 NATURAL JOIN t1 p6 NATURAL JOIN t2 r6 NATURAL JOIN t3 d6 NATURAL JOIN t1 p7 NATURAL JOIN t2 r7 NATURAL JOIN t3 d7 NATURAL JOIN t1 p8 NATURAL JOIN t2 r8 NATURAL JOIN t3 d8 NATURAL JOIN t1 p9 ) gp_13
+INNER JOIN
+(SELECT p1.* FROM t1 p1 NATURAL JOIN t2 r1 NATURAL JOIN t3 d1 NATURAL JOIN t1 p2 NATURAL JOIN t2 r2 NATURAL JOIN t3 d2 NATURAL JOIN t1 p3 NATURAL JOIN t2 r3 NATURAL JOIN t3 d3 NATURAL JOIN t1 p4 NATURAL JOIN t2 r4 NATURAL JOIN t3 d4 NATURAL JOIN t1 p5 NATURAL JOIN t2 r5 NATURAL JOIN t3 d5 NATURAL JOIN t1 p6 NATURAL JOIN t2 r6 NATURAL JOIN t3 d6 NATURAL JOIN t1 p7 NATURAL JOIN t2 r7 NATURAL JOIN t3 d7 NATURAL JOIN t1 p8 NATURAL JOIN t2 r8 NATURAL JOIN t3 d8 NATURAL JOIN t1 p9 ) gp_14
+INNER JOIN
+(SELECT p1.* FROM t1 p1 NATURAL JOIN t2 r1 NATURAL JOIN t3 d1 NATURAL JOIN t1 p2 NATURAL JOIN t2 r2 NATURAL JOIN t3 d2 NATURAL JOIN t1 p3 NATURAL JOIN t2 r3 NATURAL JOIN t3 d3 NATURAL JOIN t1 p4 NATURAL JOIN t2 r4 NATURAL JOIN t3 d4 NATURAL JOIN t1 p5 NATURAL JOIN t2 r5 NATURAL JOIN t3 d5 NATURAL JOIN t1 p6 NATURAL JOIN t2 r6 NATURAL JOIN t3 d6 NATURAL JOIN t1 p7 NATURAL JOIN t2 r7 NATURAL JOIN t3 d7 NATURAL JOIN t1 p8 NATURAL JOIN t2 r8 NATURAL JOIN t3 d8 NATURAL JOIN t1 p9 ) gp_15
+INNER JOIN
+(SELECT p1.* FROM t1 p1 NATURAL JOIN t2 r1 NATURAL JOIN t3 d1 NATURAL JOIN t1 p2 NATURAL JOIN t2 r2 NATURAL JOIN t3 d2 NATURAL JOIN t1 p3 NATURAL JOIN t2 r3 NATURAL JOIN t3 d3 NATURAL JOIN t1 p4 NATURAL JOIN t2 r4 NATURAL JOIN t3 d4 NATURAL JOIN t1 p5 NATURAL JOIN t2 r5 NATURAL JOIN t3 d5 NATURAL JOIN t1 p6 NATURAL JOIN t2 r6 NATURAL JOIN t3 d6 NATURAL JOIN t1 p7 NATURAL JOIN t2 r7 NATURAL JOIN t3 d7 NATURAL JOIN t1 p8 NATURAL JOIN t2 r8 NATURAL JOIN t3 d8 NATURAL JOIN t1 p9 ) gp_16
+;
+
+eval explain $q;
+
+DROP TABLE t1,t2,t3;
diff --git a/mysql-test/t/mdl_sync.test b/mysql-test/t/mdl_sync.test
index f6caa299fd4..8e809788a08 100644
--- a/mysql-test/t/mdl_sync.test
+++ b/mysql-test/t/mdl_sync.test
@@ -38,7 +38,7 @@ lock tables t2 read;
connection con1;
--echo connection: con1
-set debug_sync='mdl_upgrade_shared_lock_to_exclusive SIGNAL parked WAIT_FOR go';
+set debug_sync='mdl_upgrade_lock SIGNAL parked WAIT_FOR go';
--send alter table t1 rename t3
connection default;
@@ -110,8 +110,13 @@ select column_name from information_schema.columns where
table_schema='test' and table_name='t1';
select count(*) from t1;
insert into t1 values (1), (1);
+--echo # Check that SU lock is compatible with it. To do this use ALTER TABLE
+--echo # which will fail when constructing .frm and thus obtaining SU metadata
+--echo # lock.
+--error ER_KEY_COLUMN_DOES_NOT_EXITS
+alter table t1 add index (not_exist);
--echo # Check that SNW lock is compatible with it. To do this use ALTER TABLE
---echo # which will fail after opening the table and thus obtaining SNW metadata
+--echo # which will fail during copying the table and thus obtaining SNW metadata
--echo # lock.
--error ER_DUP_ENTRY
alter table t1 add primary key (c1);
@@ -230,8 +235,13 @@ select column_name from information_schema.columns where
table_schema='test' and table_name='t1';
select count(*) from t1;
insert into t1 values (1);
+--echo # Check that SU lock is compatible with it. To do this use ALTER TABLE
+--echo # which will fail when constructing .frm and thus obtaining SU metadata
+--echo # lock.
+--error ER_KEY_COLUMN_DOES_NOT_EXITS
+alter table t1 add index (not_exist);
--echo # Check that SNW lock is compatible with it. To do this use ALTER TABLE
---echo # which will fail after opening the table and thus obtaining SNW metadata
+--echo # which will fail during copying the table and thus obtaining SNW metadata
--echo # lock.
--error ER_DUP_ENTRY
alter table t1 add primary key (c1);
@@ -359,8 +369,13 @@ select column_name from information_schema.columns where
table_schema='test' and table_name='t1';
select count(*) from t1;
insert into t1 values (1);
+--echo # Check that SU lock is compatible with it. To do this use ALTER TABLE
+--echo # which will fail when constructing .frm and thus obtaining SU metadata
+--echo # lock.
+--error ER_KEY_COLUMN_DOES_NOT_EXITS
+alter table t1 add index (not_exist);
--echo # Check that SNW lock is compatible with it. To do this use ALTER TABLE
---echo # which will fail after opening the table and thus obtaining SNW metadata
+--echo # which will fail during copying the table and thus obtaining SNW metadata
--echo # lock.
--error ER_DUP_ENTRY
alter table t1 add primary key (c1);
@@ -477,8 +492,13 @@ select column_name from information_schema.columns where
select * from t1;
--enable_result_log
insert into t1 values (1);
+--echo # Check that SU lock is compatible with it. To do this use ALTER TABLE
+--echo # which will fail when constructing .frm and thus obtaining SU metadata
+--echo # lock.
+--error ER_KEY_COLUMN_DOES_NOT_EXITS
+alter table t1 add index (not_exist);
--echo # Check that SNW lock is not compatible with SW lock.
---echo # Again we use ALTER TABLE which fails after opening
+--echo # Again we use ALTER TABLE which fails during copying
--echo # the table to avoid upgrade of SNW -> X.
--echo # Sending:
--send alter table t1 add primary key (c1);
@@ -570,16 +590,144 @@ rename table t2 to t1;
connection default;
--echo #
--echo #
---echo # 5) Acquire SNW lock on the table. We have to use DEBUG_SYNC for
---echo # this, to prevent SNW from being immediately upgraded to X.
+--echo # 5) Acquire SU lock on the table. We have to use DEBUG_SYNC for
+--echo # this, to prevent SU from being immediately upgraded to X.
--echo #
-set debug_sync= 'after_open_table_mdl_shared SIGNAL locked WAIT_FOR finish';
+set debug_sync= 'alter_opened_table SIGNAL locked WAIT_FOR finish';
+--echo # Sending:
+--send alter table t1 add primary key (c1);
+--echo #
+--echo # Switching to connection 'mdl_con1'.
+connection mdl_con1;
+set debug_sync= 'now WAIT_FOR locked';
+--echo # Check that S, SH, SR and SW locks are compatible with it.
+handler t1 open;
+handler t1 close;
+select column_name from information_schema.columns where
+ table_schema='test' and table_name='t1';
+select count(*) from t1;
+delete from t1 limit 1;
+--echo # Check that SU lock is incompatible with SU lock.
+--echo # Sending:
+--send alter table t1 add primary key (c1);
+--echo #
+--echo # Switching to connection 'mdl_con2'.
+connection mdl_con2;
+--echo # Check that the above ALTER is blocked because of SU lock.
+let $wait_condition=
+ select count(*) = 1 from information_schema.processlist
+ where state = "Waiting for table metadata lock" and
+ info = "alter table t1 add primary key (c1)";
+--source include/wait_condition.inc
+--echo # Unblock ALTERs.
+set debug_sync= 'now SIGNAL finish';
+--echo #
+--echo # Switching to connection 'default'.
+connection default;
+--echo # Reaping first ALTER TABLE.
+--error ER_DUP_ENTRY
+--reap
+--echo #
+--echo # Switching to connection 'mdl_con1'.
+connection mdl_con1;
+--echo # Reaping another ALTER TABLE.
+--error ER_DUP_ENTRY
+--reap
+--echo #
+--echo # Switching to connection 'default'.
+connection default;
+set debug_sync= 'alter_opened_table SIGNAL locked WAIT_FOR finish';
--echo # Sending:
--send alter table t1 add primary key (c1);
--echo #
--echo # Switching to connection 'mdl_con1'.
connection mdl_con1;
set debug_sync= 'now WAIT_FOR locked';
+--echo # Check that SNRW lock is incompatible with SU lock.
+--echo # Sending:
+--send lock table t1 write;
+--echo #
+--echo # Switching to connection 'mdl_con2'.
+connection mdl_con2;
+--echo # Check that the above LOCK TABLES is blocked because of SU lock.
+let $wait_condition=
+ select count(*) = 1 from information_schema.processlist
+ where state = "Waiting for table metadata lock" and
+ info = "lock table t1 write";
+--source include/wait_condition.inc
+--echo # Unblock ALTER and thus LOCK TABLES.
+set debug_sync= 'now SIGNAL finish';
+--echo #
+--echo # Switching to connection 'default'.
+connection default;
+--echo # Reaping ALTER TABLE.
+--error ER_DUP_ENTRY
+--reap
+--echo #
+--echo # Switching to connection 'mdl_con1'.
+connection mdl_con1;
+--echo # Reaping LOCK TABLES
+--reap
+insert into t1 values (1);
+unlock tables;
+--echo #
+--echo # Switching to connection 'default'.
+connection default;
+set debug_sync= 'alter_opened_table SIGNAL locked WAIT_FOR finish';
+--echo # Sending:
+--send alter table t1 add primary key (c1);
+--echo #
+--echo # Switching to connection 'mdl_con1'.
+connection mdl_con1;
+set debug_sync= 'now WAIT_FOR locked';
+--echo # Check that X lock is incompatible with SU lock.
+--echo # Sending:
+--send rename table t1 to t2;
+--echo #
+--echo # Switching to connection 'mdl_con2'.
+connection mdl_con2;
+--echo # Check that the above RENAME is blocked because of SU lock.
+let $wait_condition=
+ select count(*) = 1 from information_schema.processlist
+ where state = "Waiting for table metadata lock" and
+ info = "rename table t1 to t2";
+--source include/wait_condition.inc
+--echo # Unblock ALTER and thus RENAME TABLE.
+set debug_sync= 'now SIGNAL finish';
+--echo #
+--echo # Switching to connection 'default'.
+connection default;
+--echo # Now we have ALTER TABLE with SU->SNW and RENAME TABLE with pending
+--echo # X-lock. In this case ALTER TABLE should be chosen as victim.
+--echo # Reaping ALTER TABLE.
+--error ER_LOCK_DEADLOCK
+--reap
+--echo #
+--echo # Switching to connection 'mdl_con1'.
+connection mdl_con1;
+--echo # Reaping RENAME TABLE
+--reap
+--echo # Revert back to original state of things.
+rename table t2 to t1;
+--echo #
+--echo # There is no need to check that upgrade from SNW/SNRW to X is
+--echo # blocked by presence of another SU lock because SNW/SNRW is
+--echo # incompatible with SU anyway.
+--echo #
+--echo # Switching to connection 'default'.
+connection default;
+--echo #
+--echo #
+--echo # 6) Acquire SNW lock on the table. We have to use DEBUG_SYNC for
+--echo # this, to prevent SNW from being immediately upgraded to X.
+--echo #
+set debug_sync= 'alter_table_copy_after_lock_upgrade SIGNAL locked WAIT_FOR finish';
+--echo # Sending:
+--send alter table t1 add primary key (c1), lock=shared, algorithm=copy;
+--echo #
+--echo # Switching to connection 'mdl_con1'.
+connection mdl_con1;
+set debug_sync= 'now WAIT_FOR locked';
--echo # Check that S, SH and SR locks are compatible with it.
handler t1 open;
handler t1 close;
@@ -614,14 +762,14 @@ connection mdl_con1;
--echo #
--echo # Switching to connection 'default'.
connection default;
-set debug_sync= 'after_open_table_mdl_shared SIGNAL locked WAIT_FOR finish';
+set debug_sync= 'alter_table_copy_after_lock_upgrade SIGNAL locked WAIT_FOR finish';
--echo # Sending:
---send alter table t1 add primary key (c1);
+--send alter table t1 add primary key (c1), lock=shared, algorithm=copy;
--echo #
--echo # Switching to connection 'mdl_con1'.
connection mdl_con1;
set debug_sync= 'now WAIT_FOR locked';
---echo # Check that SNW lock is incompatible with SNW lock.
+--echo # Check that SU lock is incompatible with SNW lock.
--echo # Sending:
--send alter table t1 add primary key (c1);
--echo #
@@ -648,11 +796,15 @@ connection mdl_con1;
--error ER_DUP_ENTRY
--reap
--echo #
+--echo # Note that we can't easily check SNW vs SNW locks since
+--echo # SNW is only used by ALTER TABLE after upgrading from SU
+--echo # and SU is also incompatible with SNW.
+--echo #
--echo # Switching to connection 'default'.
connection default;
-set debug_sync= 'after_open_table_mdl_shared SIGNAL locked WAIT_FOR finish';
+set debug_sync= 'alter_table_copy_after_lock_upgrade SIGNAL locked WAIT_FOR finish';
--echo # Sending:
---send alter table t1 add primary key (c1);
+--send alter table t1 add primary key (c1), lock=shared, algorithm=copy;
--echo #
--echo # Switching to connection 'mdl_con1'.
connection mdl_con1;
@@ -687,9 +839,9 @@ unlock tables;
--echo #
--echo # Switching to connection 'default'.
connection default;
-set debug_sync= 'after_open_table_mdl_shared SIGNAL locked WAIT_FOR finish';
+set debug_sync= 'alter_table_copy_after_lock_upgrade SIGNAL locked WAIT_FOR finish';
--echo # Sending:
---send alter table t1 add primary key (c1);
+--send alter table t1 add primary key (c1), algorithm=copy, lock=shared;
--echo #
--echo # Switching to connection 'mdl_con1'.
connection mdl_con1;
@@ -730,7 +882,7 @@ rename table t2 to t1;
connection default;
--echo #
--echo #
---echo # 6) Acquire SNRW lock on the table.
+--echo # 7) Acquire SNRW lock on the table.
--echo #
--echo #
lock table t1 write;
@@ -794,13 +946,13 @@ lock table t1 write;
--echo #
--echo # Switching to connection 'mdl_con1'.
connection mdl_con1;
---echo # Check that SNW lock is incompatible with SNRW lock.
+--echo # Check that SU lock is incompatible with SNRW lock.
--echo # Sending:
--send alter table t1 add primary key (c1);
--echo #
--echo # Switching to connection 'default'.
connection default;
---echo # Check that the above ALTER is blocked because of UNWR lock.
+--echo # Check that the above ALTER is blocked because of SNRW lock.
let $wait_condition=
select count(*) = 1 from information_schema.processlist
where state = "Waiting for table metadata lock" and
@@ -815,6 +967,10 @@ connection mdl_con1;
--error ER_DUP_ENTRY
--reap
--echo #
+--echo # Note that we can't easily check SNW vs SNRW locks since
+--echo # SNW is only used by ALTER TABLE after upgrading from SU
+--echo # and SU is also incompatible with SNRW.
+--echo #
--echo # Switching to connection 'default'.
connection default;
lock table t1 write;
@@ -879,7 +1035,7 @@ rename table t2 to t1;
connection default;
--echo #
--echo #
---echo # 7) Now do the same round of tests for X lock. We use additional
+--echo # 8) Now do the same round of tests for X lock. We use additional
--echo # table to get long-lived lock of this type.
--echo #
create table t2 (c1 int);
@@ -1083,7 +1239,7 @@ select count(*) = 1 from information_schema.processlist
where state = "Waiting for table metadata lock" and
info = "rename table t1 to t2";
--source include/wait_condition.inc
---echo # Check that SNW lock is incompatible with X lock.
+--echo # Check that SU lock is incompatible with X lock.
--echo # Sending:
--send alter table t1 add primary key (c1);
--echo #
@@ -1110,7 +1266,11 @@ connection mdl_con1;
--echo # Reaping ALTER.
--error ER_DUP_ENTRY
--reap
---echo #
+--echo #
+--echo # Note that we can't easily check SNW vs X locks since
+--echo # SNW is only used by ALTER TABLE after upgrading from SU
+--echo # and SU is also incompatible with X.
+--echo #
--echo # Switching to connection 'mdl_con2'.
connection mdl_con2;
--echo # Prepare for blocking RENAME TABLE.
@@ -1208,6 +1368,9 @@ rename table t3 to t1;
--echo # are pending. I.e. let us test rules for priorities between
--echo # different types of metadata locks.
--echo #
+--echo # Note: No tests for pending SU lock as this lock requires
+--echo # even stronger active or pending lock.
+--echo #
--echo #
--echo # Switching to connection 'mdl_con2'.
@@ -1657,6 +1820,9 @@ connection default;
--echo # transactional context. Obviously we are mostly interested
--echo # in conflicting types of locks.
--echo #
+--echo # Note: No tests for active/pending SU lock since
+--echo # ALTER TABLE is in its own transaction.
+--echo #
--echo #
--echo # 1) Let us check how various locks used within transactional
@@ -1673,9 +1839,9 @@ connection mdl_con1;
--echo # We have to use DEBUG_SYNC facility as otherwise SNW lock
--echo # will be immediately released (or upgraded to X lock).
insert into t2 values (1), (1);
-set debug_sync= 'after_open_table_mdl_shared SIGNAL locked WAIT_FOR finish';
+set debug_sync= 'alter_table_copy_after_lock_upgrade SIGNAL locked WAIT_FOR finish';
--echo # Sending:
---send alter table t2 add primary key (c1);
+--send alter table t2 add primary key (c1), algorithm=copy, lock=shared;
--echo #
--echo # Switching to connection 'default'.
connection default;
@@ -1724,9 +1890,9 @@ select count(*) from t1;
--echo # Switching to connection 'mdl_con1'.
connection mdl_con1;
--echo # Create an active SNW lock on t1.
-set debug_sync= 'after_open_table_mdl_shared SIGNAL locked WAIT_FOR finish';
+set debug_sync= 'alter_table_copy_after_lock_upgrade SIGNAL locked WAIT_FOR finish';
--echo # Sending:
---send alter table t1 add primary key (c1);
+--send alter table t1 add primary key (c1), algorithm=copy, lock=shared;
--echo #
--echo # Switching to connection 'default'.
connection default;
@@ -2812,7 +2978,7 @@ drop tables t1, t2;
create table t1 (i int);
--echo # Ensure that ALTER waits once it has acquired SNW lock.
-set debug_sync='after_open_table_mdl_shared SIGNAL parked1 WAIT_FOR go1';
+set debug_sync='alter_table_copy_after_lock_upgrade SIGNAL parked1 WAIT_FOR go1';
--echo # Sending:
--send alter table t1 add column j int
@@ -3312,18 +3478,33 @@ drop tables if exists t1, t2;
--enable_warnings
connect (con46044, localhost, root,,);
connect (con46044_2, localhost, root,,);
+connect (con46044_3, localhost, root,,);
connection default;
create table t1 (i int);
+insert into t1 values(1);
--echo # Let us check that we won't deadlock if during filling
--echo # of I_S table we encounter conflicting metadata lock
--echo # which owner is in its turn waiting for our connection.
lock tables t1 read;
+--echo # Switching to connection 'con46044_2'.
+connection con46044_2;
+--echo # Sending:
+--send update t1 set i = 2
+
--echo # Switching to connection 'con46044'.
connection con46044;
+
+--echo # Waiting until UPDATE t1 SET ... is blocked.
+let $wait_condition=
+ select count(*) = 1 from information_schema.processlist
+ where state = "Waiting for table level lock" and
+ info = "update t1 set i = 2";
+--source include/wait_condition.inc
+
--echo # Sending:
---send create table t2 select * from t1 for update;
+--send create table t2 select * from t1;
--echo # Switching to connection 'default'.
connection default;
@@ -3331,7 +3512,7 @@ connection default;
let $wait_condition=
select count(*) = 1 from information_schema.processlist
where state = "Waiting for table level lock" and
- info = "create table t2 select * from t1 for update";
+ info = "create table t2 select * from t1";
--source include/wait_condition.inc
--echo # First let us check that SHOW FIELDS/DESCRIBE doesn't
@@ -3362,6 +3543,10 @@ connection con46044;
--reap
drop table t2;
+connection con46044_2;
+--echo # Reaping UPDATE t1 statement
+--reap
+
--echo #
--echo # Let us also check that queries to I_S wait for conflicting metadata
--echo # locks to go away instead of skipping table with a warning in cases
@@ -3374,10 +3559,23 @@ drop table t2;
connection con46044_2;
lock tables t1 read;
+--echo # Switching to connection 'con46044_3'.
+connection con46044_3;
+--echo # Sending:
+send update t1 set i = 3;
+
--echo # Switching to connection 'con46044'.
connection con46044;
+
+--echo # Waiting until UPDATE t1 SET ... is blocked.
+let $wait_condition=
+ select count(*) = 1 from information_schema.processlist
+ where state = "Waiting for table level lock" and
+ info = "update t1 set i = 3";
+--source include/wait_condition.inc
+
--echo # Sending:
---send create table t2 select * from t1 for update;
+--send create table t2 select * from t1;
--echo # Switching to connection 'default'.
connection default;
@@ -3385,7 +3583,7 @@ connection default;
let $wait_condition=
select count(*) = 1 from information_schema.processlist
where state = "Waiting for table level lock" and
- info = "create table t2 select * from t1 for update";
+ info = "create table t2 select * from t1";
--source include/wait_condition.inc
--echo # Let us check that SHOW FIELDS/DESCRIBE gets blocked.
@@ -3414,14 +3612,31 @@ connection default;
--reap
drop table t2;
+connection con46044_3;
+--echo # Reaping UPDATE t1 statement
+--reap
+
--echo # Switching to connection 'con46044_2'.
connection con46044_2;
lock tables t1 read;
+--echo # Switching to connection 'con46044_3'.
+connection con46044_3;
+--echo # Sending:
+--send update t1 set i = 4
+
--echo # Switching to connection 'con46044'.
connection con46044;
+
+--echo # Waiting until UPDATE t1 SET ... is blocked.
+let $wait_condition=
+ select count(*) = 1 from information_schema.processlist
+ where state = "Waiting for table level lock" and
+ info = "update t1 set i = 4";
+--source include/wait_condition.inc
+
--echo # Sending:
---send create table t2 select * from t1 for update;
+--send create table t2 select * from t1;
--echo # Switching to connection 'default'.
connection default;
@@ -3429,7 +3644,7 @@ connection default;
let $wait_condition=
select count(*) = 1 from information_schema.processlist
where state = "Waiting for table level lock" and
- info = "create table t2 select * from t1 for update";
+ info = "create table t2 select * from t1";
--source include/wait_condition.inc
--echo # Check that I_S query which reads only .FRMs gets blocked.
@@ -3458,14 +3673,31 @@ connection default;
--reap
drop table t2;
+connection con46044_3;
+--echo # Reaping UPDATE t1 statement
+--reap
+
--echo # Switching to connection 'con46044_2'.
connection con46044_2;
lock tables t1 read;
+--echo # Switching to connection 'con46044_3'.
+connection con46044_3;
+--echo # Sending:
+--send update t1 set i = 5
+
--echo # Switching to connection 'con46044'.
connection con46044;
+
+--echo # Waiting until UPDATE t1 SET ... is blocked.
+let $wait_condition=
+ select count(*) = 1 from information_schema.processlist
+ where state = "Waiting for table level lock" and
+ info = "update t1 set i = 5";
+--source include/wait_condition.inc
+
--echo # Sending:
---send create table t2 select * from t1 for update;
+--send create table t2 select * from t1;
--echo # Switching to connection 'default'.
connection default;
@@ -3473,7 +3705,7 @@ connection default;
let $wait_condition=
select count(*) = 1 from information_schema.processlist
where state = "Waiting for table level lock" and
- info = "create table t2 select * from t1 for update";
+ info = "create table t2 select * from t1";
--source include/wait_condition.inc
--echo # Finally, check that I_S query which does full-blown table open
@@ -3503,11 +3735,16 @@ connection default;
--reap
drop table t2;
+connection con46044_3;
+--echo # Reaping UPDATE t1 statement
+--reap
+
--echo # Switching to connection 'default'.
connection default;
--echo # Clean-up.
disconnect con46044;
disconnect con46044_2;
+disconnect con46044_3;
drop table t1;
@@ -3530,7 +3767,7 @@ select * from t1 where c2 = 3;
--echo #
--echo # Switching to connection 'con46273'.
connection con46273;
-set debug_sync='after_lock_tables_takes_lock SIGNAL alter_table_locked WAIT_FOR alter_go';
+set debug_sync='alter_table_copy_after_lock_upgrade SIGNAL alter_table_locked WAIT_FOR alter_go';
--send alter table t1 add column e int, rename to t2;
--echo #
@@ -3780,9 +4017,9 @@ create table t1 (i int) engine=InnoDB;
--echo # Switching to connection 'con50913_1'.
connection con50913_1;
-set debug_sync= 'thr_multi_lock_after_thr_lock SIGNAL parked WAIT_FOR go';
+set debug_sync= 'alter_table_copy_after_lock_upgrade SIGNAL parked WAIT_FOR go';
--echo # Sending:
---send alter table t1 add column j int
+--send alter table t1 add column j int, ALGORITHM=COPY
--echo # Switching to connection 'default'.
connection default;
@@ -3851,7 +4088,7 @@ select * from t1;
connection default;
--echo # Start ALTER TABLE which will acquire SNW lock and
--echo # table lock and get blocked on sync point.
-set debug_sync= 'thr_multi_lock_after_thr_lock SIGNAL parked WAIT_FOR go';
+set debug_sync= 'alter_table_copy_after_lock_upgrade SIGNAL parked WAIT_FOR go';
--echo # Sending:
--send alter table t1 add column j int
@@ -4336,7 +4573,7 @@ connection default;
--echo # Connection con2
connection con2;
--echo # Reaping: RENAME TABLE db1.t1 TO test.t1
---error ER_FILE_NOT_FOUND, ER_FILE_NOT_FOUND
+--error ER_NO_SUCH_TABLE
--reap
--echo # Connection default
@@ -4513,10 +4750,13 @@ INSERT INTO t2 VALUES (3), (4);
connect(con1, localhost, root);
connect(con2, localhost, root);
+connect(con3, localhost, root);
--echo # Connection con1
connection con1;
-SET DEBUG_SYNC= 'mdl_upgrade_shared_lock_to_exclusive SIGNAL upgrade WAIT_FOR continue';
+--echo # We need EXECUTE 2 since ALTER TABLE does SU => SNW => X and we want
+--echo # to stop at the second upgrade.
+SET DEBUG_SYNC= 'mdl_upgrade_lock SIGNAL upgrade WAIT_FOR continue EXECUTE 2';
--echo # Sending:
--send ALTER TABLE m1 engine=MERGE UNION=(t2, t1)
@@ -4524,11 +4764,13 @@ SET DEBUG_SYNC= 'mdl_upgrade_shared_lock_to_exclusive SIGNAL upgrade WAIT_FOR co
connection con2;
--echo # Waiting for ALTER TABLE to try lock upgrade
SET DEBUG_SYNC= 'now WAIT_FOR upgrade';
+SET DEBUG_SYNC= 'now SIGNAL continue';
+SET DEBUG_SYNC= 'now WAIT_FOR upgrade';
--echo # Sending:
--send DELETE FROM t2 WHERE a = 3
--echo # Connection default
-connection default;
+connection con3;
--echo # Check that DELETE is waiting on a metadata lock and not a table lock.
let $wait_condition=
SELECT COUNT(*) = 1 FROM information_schema.processlist
@@ -4538,7 +4780,9 @@ let $wait_condition=
--echo # Now that DELETE blocks on a metadata lock, we should be able to do
--echo # SELECT * FROM m1 here. SELECT used to be blocked by a DELETE table
--echo # lock request.
-SELECT * FROM m1;
+--send SELECT * FROM m1 WHERE a < 3
+
+connection default;
--echo # Resuming ALTER TABLE
SET DEBUG_SYNC= 'now SIGNAL continue';
@@ -4550,12 +4794,16 @@ connection con1;
connection con2;
--echo # Reaping: DELETE FROM t2 WHERE a = 3
--reap
+connection con3;
+--echo # Reaping: SELECT * FROM m1 WHERE a < 3
+--reap
--echo # Connection default
connection default;
DROP TABLE m1, t1, t2;
SET DEBUG_SYNC= 'RESET';
disconnect con1;
disconnect con2;
+disconnect con3;
# Check that all connections opened by test cases in this file are really
diff --git a/mysql-test/t/merge.test b/mysql-test/t/merge.test
index 9d0ddd01752..311eb6f12f3 100644
--- a/mysql-test/t/merge.test
+++ b/mysql-test/t/merge.test
@@ -655,7 +655,7 @@ insert into t1 values (1);
flush tables;
# Open t2 and (implicitly) t1.
select * from t2;
-# Truncate t1, wich was not recognized as open without the bugfix.
+# Truncate t1, which was not recognized as open without the bugfix.
# After fix for Bug#8306 and before fix for Bug#26379,
# it should fail with a table-in-use error message, otherwise succeed.
truncate table t1;
@@ -1559,7 +1559,7 @@ CREATE TABLE m1 (
) ENGINE=MRG_MyISAM DEFAULT CHARSET=latin1 INSERT_METHOD=LAST UNION=(t1);
insert into m1 (col1) values (1);
---error ER_DUP_ENTRY
+--error ER_DUP_KEY
insert into m1 (col1) values (1);
drop table m1, t1;
@@ -1593,7 +1593,7 @@ CREATE TABLE t1 (c1 INT, c2 INT, UNIQUE (c1), UNIQUE (c2));
CREATE TABLE m1 (c1 INT, c2 INT, UNIQUE (c1)) ENGINE=MRG_MyISAM INSERT_METHOD=LAST UNION=(t1);
INSERT INTO m1 VALUES (1,2);
--echo # insert the duplicate value into the merge table
---error ER_DUP_ENTRY
+--error ER_DUP_KEY
INSERT INTO m1 VALUES (3,2);
DROP TABLE m1,t1;
@@ -2895,6 +2895,85 @@ DROP TABLE t1, tmerge;
--echo End of 5.5 tests
+
+--echo #
+--echo # Additional coverage for refactoring which is made as part
+--echo # of fix for bug #27480 "Extend CREATE TEMPORARY TABLES privilege
+--echo # to allow temp table operations".
+--echo #
+--echo # Check that prelocking works correctly for various variants of
+--echo # merge tables.
+--disable_warnings
+drop table if exists t1, t2, m1;
+drop function if exists f1;
+--enable_warnings
+create table t1 (j int);
+insert into t1 values (1);
+create function f1() returns int return (select count(*) from m1);
+create temporary table t2 (a int) engine=myisam;
+insert into t2 values (1);
+create temporary table m1 (a int) engine=merge union=(t2);
+select f1() from t1;
+drop tables t2, m1;
+create table t2 (a int) engine=myisam;
+insert into t2 values (1);
+create table m1 (a int) engine=merge union=(t2);
+select f1() from t1;
+drop table m1;
+create temporary table m1 (a int) engine=merge union=(t2);
+select f1() from t1;
+drop tables t1, t2, m1;
+drop function f1;
+--echo #
+--echo # Check that REPAIR/CHECK and CHECKSUM statements work correctly
+--echo # for various variants of merge tables.
+create table t1 (a int) engine=myisam;
+insert into t1 values (1);
+create table m1 (a int) engine=merge union=(t1);
+check table m1;
+repair table m1;
+checksum table m1;
+drop tables t1, m1;
+create temporary table t1 (a int) engine=myisam;
+insert into t1 values (1);
+create temporary table m1 (a int) engine=merge union=(t1);
+check table m1;
+repair table m1;
+checksum table m1;
+drop tables t1, m1;
+create table t1 (a int) engine=myisam;
+insert into t1 values (1);
+create temporary table m1 (a int) engine=merge union=(t1);
+check table m1;
+repair table m1;
+checksum table m1;
+drop tables t1, m1;
+
+# Check effect of Bug#27480-preliminary patch:
+# a merge-table with non-existing children, opened from a prelocked list.
+
+--disable_warnings
+DROP TABLE IF EXISTS t1;
+DROP TABLE IF EXISTS m1;
+DROP TRIGGER IF EXISTS trg1;
+DROP TABLE IF EXISTS q1;
+DROP TABLE IF EXISTS q2;
+--enable_warnings
+
+CREATE TABLE t1(a INT);
+CREATE TABLE m1(a INT) ENGINE = MERGE UNION (q1, q2);
+
+CREATE TRIGGER trg1 BEFORE DELETE ON t1
+FOR EACH ROW
+ INSERT INTO m1 VALUES (1);
+
+--error ER_WRONG_MRG_TABLE
+DELETE FROM t1;
+
+DROP TRIGGER trg1;
+DROP TABLE t1;
+DROP TABLE m1;
+
--disable_result_log
--disable_query_log
eval set global storage_engine=$default;
diff --git a/mysql-test/t/multi_update.test b/mysql-test/t/multi_update.test
index 8184d8ded1a..04611fef7dc 100644
--- a/mysql-test/t/multi_update.test
+++ b/mysql-test/t/multi_update.test
@@ -1057,3 +1057,53 @@ drop view v3,v2,v1;
drop table t1,t2,t3;
--echo end of 5.5 tests
+
+--source include/have_xtradb.inc
+
+--echo
+--echo # Bug mdev-5970
+--echo # Bug#13256831 - ERROR 1032 (HY000): CAN'T FIND RECORD
+--echo
+
+CREATE TABLE t1 (f1 INT PRIMARY KEY, f2 INT) ENGINE=InnoDB;
+CREATE TABLE t2 (f1 INT PRIMARY KEY, f2 INT) ENGINE=InnoDB;
+INSERT INTO t1 VALUES (5, 7);
+INSERT INTO t2 VALUES (6, 97);
+
+CREATE ALGORITHM = MERGE VIEW v1 AS
+SELECT a2.f1 AS f1, a2.f2 AS f2
+FROM t1 AS a1 JOIN t2 AS a2 ON a1.f2 > a2.f1
+WITH LOCAL CHECK OPTION;
+
+SELECT * FROM v1;
+UPDATE v1 SET f1 = 1;
+SELECT * FROM v1;
+
+DROP TABLE t1, t2;
+DROP VIEW v1;
+
+--echo #
+--echo # MDEV-5973: MySQL Bug#11757486:49539: NON-DESCRIPTIVE ERR (ERROR 0
+--echo # FROM STORAGE ENGINE) WITH MULTI-TABLE UPDATE
+--echo #
+
+CREATE TABLE table_11757486 (field1 tinyint) ENGINE=INNODB;
+INSERT INTO table_11757486 VALUES (0),(0);
+SET SESSION SQL_MODE='STRICT_ALL_TABLES';
+UPDATE IGNORE (SELECT 128 as col1) x, table_11757486 SET field1=x.col1;
+UPDATE IGNORE table_11757486 SET field1=128;
+
+--error ER_WARN_DATA_OUT_OF_RANGE
+UPDATE (SELECT 128 as col1) x, table_11757486 SET field1=x.col1;
+--error ER_WARN_DATA_OUT_OF_RANGE
+UPDATE table_11757486 SET field1=128;
+
+SET SESSION SQL_MODE='';
+UPDATE IGNORE (SELECT 128 as col1) x, table_11757486 SET field1=x.col1;
+UPDATE IGNORE table_11757486 SET field1=128;
+
+DROP TABLE table_11757486;
+
+SET SESSION SQL_MODE=default;
+
+--echo end of 10.0 tests
diff --git a/mysql-test/t/myisam-metadata.test b/mysql-test/t/myisam-metadata.test
deleted file mode 100644
index c6c6347e6b4..00000000000
--- a/mysql-test/t/myisam-metadata.test
+++ /dev/null
@@ -1,59 +0,0 @@
-#
-# Test bugs in MyISAM that may cause problems for metadata
-#
-
---source include/big_test.inc
---source include/have_debug_sync.inc
-
---disable_warnings
-DROP TABLE IF EXISTS t1;
---enable_warnings
-
-#
-# LP:989055 - Querying myisam table metadata may corrupt the table
-#
-
-CREATE TABLE t1 (
- id INT PRIMARY KEY,
- a VARCHAR(100),
- INDEX(a)
-) ENGINE=MyISAM;
-ALTER TABLE t1 DISABLE KEYS;
-
-let $1=100000;
---disable_query_log
-while ($1)
-{
- eval insert into t1 values($1, "line number $1");
- dec $1;
-}
---enable_query_log
-
---connect(con1,localhost,root,,)
-# Set a debug_sync waitpoint.
-# This is just to ensure that the ALTER does not have time to complete
-# its operation and change the status away from "Repair by sorting" before
-# wait_condition has a chance to see it.
-SET debug_sync= 'myisam_after_repair_by_sort WAIT_FOR go';
-send
- ALTER TABLE t1 ENABLE KEYS;
-
---connection default
---let $wait_timeout=60
---let $show_statement= SHOW PROCESSLIST
---let $field= State
-# If the sort completes early and we hit the debug_sync point, the processlist
-# will show the debug_sync state, so we need to check for that also.
---let $condition= RLIKE 'Repair by sorting|myisam_after_repair_by_sort'
---source include/wait_show_condition.inc
-SET debug_sync= 'now SIGNAL go';
-
---replace_column 7 # 8 # 9 # 12 # 13 # 14 #
-SHOW TABLE STATUS LIKE 't1';
-
---connection con1
---reap
---connection default
---disconnect con1
-DROP TABLE t1;
-set debug_sync='reset';
diff --git a/mysql-test/t/myisam-system.test b/mysql-test/t/myisam-system.test
index d908e639a4e..cece33bb00b 100644
--- a/mysql-test/t/myisam-system.test
+++ b/mysql-test/t/myisam-system.test
@@ -9,14 +9,21 @@ drop table if exists t1,t2;
create table t1 (a int) engine=myisam;
let $MYSQLD_DATADIR= `select @@datadir`;
--remove_file $MYSQLD_DATADIR/test/t1.MYI
+--replace_result $MYSQLD_DATADIR ./
drop table if exists t1;
create table t1 (a int) engine=myisam;
--remove_file $MYSQLD_DATADIR/test/t1.MYI
---error ER_BAD_TABLE_ERROR,6
+--replace_result $MYSQLD_DATADIR ./
+--error ER_FILE_NOT_FOUND
+select * from t1;
+--replace_result $MYSQLD_DATADIR ./
drop table t1;
create table t1 (a int) engine=myisam;
--remove_file $MYSQLD_DATADIR/test/t1.MYD
---error ER_BAD_TABLE_ERROR,6,29
+--replace_result $MYSQLD_DATADIR ./
+--error 29
+select * from t1;
+--replace_result $MYSQLD_DATADIR ./
drop table t1;
--error ER_BAD_TABLE_ERROR
drop table t1;
diff --git a/mysql-test/t/myisam.test b/mysql-test/t/myisam.test
index c4bb93b6bfe..62260ba43aa 100644
--- a/mysql-test/t/myisam.test
+++ b/mysql-test/t/myisam.test
@@ -1601,6 +1601,7 @@ INSERT INTO t1 SELECT a+1280,b FROM t1;
INSERT INTO t1 SELECT a+2560,b FROM t1;
INSERT INTO t1 SELECT a+5120,b FROM t1;
SET myisam_sort_buffer_size=4;
+--replace_regex /Current myisam_sort_buffer_size.*/X/
REPAIR TABLE t1;
SET myisam_repair_threads=2;
@@ -1649,6 +1650,7 @@ DROP TABLE t1, t2, t3;
CREATE TABLE t1(a CHAR(255), KEY(a));
SELECT * FROM t1, t1 AS a1;
SET myisam_sort_buffer_size=4;
+--replace_regex /Current myisam_sort_buffer_size.*/X/
INSERT INTO t1 VALUES
('0'),('0'),('0'),('0'),('0'),('0'),('0'),('0'),('0'),('0'),
('0'),('0'),('0'),('0'),('0'),('0'),('0'),('0'),('0'),('0'),
diff --git a/mysql-test/t/myisam_debug.test b/mysql-test/t/myisam_debug.test
index 5b5d006bd22..57d423d88c9 100644
--- a/mysql-test/t/myisam_debug.test
+++ b/mysql-test/t/myisam_debug.test
@@ -59,3 +59,16 @@ KILL QUERY @thread_id;
CHECK TABLE t1;
DROP TABLE t1,t2;
DISCONNECT insertConn;
+
+#
+# MDEV-12761 Error return from external_lock make the server crash
+#
+call mtr.add_suppression('Incorrect key file for table');
+create table t1 (a int, index(a));
+lock tables t1 write;
+insert t1 values (1),(2),(1);
+set @old_dbug=@@debug_dbug;
+set debug_dbug='+d,mi_lock_database_failure';
+unlock tables;
+set debug_dbug=@old_dbug;
+drop table t1;
diff --git a/mysql-test/t/myisam_explain_non_select_all.test b/mysql-test/t/myisam_explain_non_select_all.test
new file mode 100644
index 00000000000..ccd4ebd6297
--- /dev/null
+++ b/mysql-test/t/myisam_explain_non_select_all.test
@@ -0,0 +1,21 @@
+#
+# Run explain_non_select.inc on MyISAM with all of the so-called 6.0 features.
+#
+
+#--source include/have_semijoin.inc
+#--source include/have_materialization.inc
+#--source include/have_firstmatch.inc
+#--source include/have_loosescan.inc
+#--source include/have_index_condition_pushdown.inc
+#--source include/have_mrr.inc
+
+#set optimizer_switch='semijoin=on,materialization=on,firstmatch=on,loosescan=on,index_condition_pushdown=on,mrr=on,mrr_cost_based=off';
+
+set @save_storage_engine= @@session.default_storage_engine;
+set session default_storage_engine = MyISAM;
+--let $json = 0
+--let $validation = 0
+--source include/explain_non_select.inc
+set default_storage_engine= @save_storage_engine;
+
+set optimizer_switch=default;
diff --git a/mysql-test/t/myisam_optimize.test b/mysql-test/t/myisam_optimize.test
index 3788534e2a5..5e133aea853 100644
--- a/mysql-test/t/myisam_optimize.test
+++ b/mysql-test/t/myisam_optimize.test
@@ -14,13 +14,13 @@ delete from t1 where a < 3;
explain select a, left(b,10) from t1 order by a;
select left(b,10), a from t1 order by a;
-set debug_sync='myisam_after_repair_by_sort wait_for go';
+set debug_sync='myisam_before_repair_by_sort wait_for go';
send optimize table t1;
connect (con1,localhost,root,,);
let $wait_condition=
select count(*) = 1 from information_schema.processlist
- where state like "%myisam_after_repair_by_sort%";
+ where state like "%myisam_before_repair_by_sort%";
--source include/wait_condition.inc
send select a, left(b,10) from t1 order by a;
@@ -46,3 +46,20 @@ connection default;
drop table t1;
set debug_sync='reset';
+--echo # End of 5.5 tests
+
+#
+# MDEV-11539 test_if_reopen: Assertion `strcmp(share->unique_file_name,filename) || share->last_version' failed upon select from I_S
+#
+CREATE TABLE t1 (i INT) ENGINE=MyISAM;
+INSERT t1 VALUES (1);
+LOCK TABLE t1 WRITE;
+OPTIMIZE TABLE t1;
+--disable_result_log
+SELECT * FROM INFORMATION_SCHEMA.TABLES;
+--enable_result_log
+SELECT * FROM t1;
+UNLOCK TABLES;
+DROP TABLE t1;
+
+--echo # End of 10.0 tests
diff --git a/mysql-test/t/myisampack.test b/mysql-test/t/myisampack.test
index cc9429a1707..1f97a28e6fd 100644
--- a/mysql-test/t/myisampack.test
+++ b/mysql-test/t/myisampack.test
@@ -314,3 +314,15 @@ flush table t1;
check table t1;
checksum table t1;
drop table t1;
+
+--echo #
+--echo # BUG#11751736: DROP DATABASE STATEMENT SHOULD REMOVE .OLD SUFFIX FROM
+--echo # DATABASE DIRECTORY
+--echo #
+CREATE DATABASE db1;
+CREATE TABLE db1.t1(c1 INT) ENGINE=MyISAM;
+## Added -f to force pack db in any case regardless the size of database
+## being packed
+let $MYSQLD_DATADIR = `SELECT @@datadir`;
+--exec $MYISAMPACK -b -f $MYSQLD_DATADIR/db1/t1
+DROP DATABASE db1;
diff --git a/mysql-test/t/mysql.test b/mysql-test/t/mysql.test
index dd964c46420..4403a9d668f 100644
--- a/mysql-test/t/mysql.test
+++ b/mysql-test/t/mysql.test
@@ -223,10 +223,10 @@ drop table t17583;
--echo Test connect with dbname + _invalid_ hostname
# Mask the errno of the error message
---replace_regex /\([0-9]*\)/(errno)/
+--replace_regex /\([0-9|-]*\)/(errno)/
--error 1
--exec $MYSQL test -e "\r test invalid_hostname" 2>&1
---replace_regex /\([0-9]*\)/(errno)/
+--replace_regex /\([0-9|-]*\)/(errno)/
--error 1
--exec $MYSQL test -e "connect test invalid_hostname" 2>&1
@@ -235,7 +235,7 @@ drop table t17583;
--error 1
--exec $MYSQL test -e "\r\r\n\r\n cyril\ has\ found\ a\ bug\ :)XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" 2>&1
-#--replace_regex /\([0-9]*\)/(errno)/
+#--replace_regex /\([0-9|-]*\)/(errno)/
#--error 1
#--exec echo '\r\r\n\r\n cyril\ has\ found\ a\ bug\ :)XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX' | $MYSQL 2>&1
@@ -244,7 +244,7 @@ drop table t17583;
--exec $MYSQL test -e "\r test_really_long_dbnamexxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx localhost" 2>&1
--echo Too long hostname
---replace_regex /\([0-9]*\)/(errno)/
+--replace_regex /\([0-9|-]*\)/(errno)/
--error 1
--exec $MYSQL test -e "\r test cyrils_superlonghostnameXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" 2>&1
@@ -360,7 +360,7 @@ remove_file $MYSQLTEST_VARDIR/tmp/bug31060.sql;
#
# Bug#37268 'binary' character set makes CLI-internal commands case sensitive
#
---replace_regex /\([0-9]*\)/(errno)/
+--replace_regex /\([0-9|-]*\)/(errno)/
--error 1
--exec $MYSQL --default-character-set=binary test -e "CONNECT test invalid_hostname" 2>&1
--exec $MYSQL --default-character-set=binary test -e "DELIMITER //" 2>&1
diff --git a/mysql-test/t/mysql5613mysql.test b/mysql-test/t/mysql5613mysql.test
new file mode 100644
index 00000000000..c4baf6ca166
--- /dev/null
+++ b/mysql-test/t/mysql5613mysql.test
@@ -0,0 +1,120 @@
+let $MYSQLD_DATADIR= `select @@datadir`;
+
+--echo #
+--echo # MDEV-4819 Upgrade from MySQL 5.6 does not work
+--echo # Testing that we can open system tables created in MySQL-5.6 (5.6.13)
+--echo #
+
+
+--copy_file std_data/mysql5613mysql/columns_priv.frm $MYSQLD_DATADIR/test/columns_priv.frm
+--copy_file std_data/mysql5613mysql/columns_priv.MYD $MYSQLD_DATADIR/test/columns_priv.MYD
+--copy_file std_data/mysql5613mysql/columns_priv.MYI $MYSQLD_DATADIR/test/columns_priv.MYI
+SHOW CREATE TABLE columns_priv;
+SELECT * FROM columns_priv LIMIT 0;
+DROP TABLE columns_priv;
+
+--copy_file std_data/mysql5613mysql/db.frm $MYSQLD_DATADIR/test/db.frm
+--copy_file std_data/mysql5613mysql/db.MYD $MYSQLD_DATADIR/test/db.MYD
+--copy_file std_data/mysql5613mysql/db.MYI $MYSQLD_DATADIR/test/db.MYI
+SHOW CREATE TABLE db;
+SELECT * FROM db LIMIT 0;
+DROP TABLE db;
+
+
+--copy_file std_data/mysql5613mysql/event.frm $MYSQLD_DATADIR/test/event.frm
+--copy_file std_data/mysql5613mysql/event.MYD $MYSQLD_DATADIR/test/event.MYD
+--copy_file std_data/mysql5613mysql/event.MYI $MYSQLD_DATADIR/test/event.MYI
+SHOW CREATE TABLE event;
+SELECT * FROM event LIMIT 0;
+DROP TABLE event;
+
+--copy_file std_data/mysql5613mysql/func.frm $MYSQLD_DATADIR/test/func.frm
+--copy_file std_data/mysql5613mysql/func.MYD $MYSQLD_DATADIR/test/func.MYD
+--copy_file std_data/mysql5613mysql/func.MYI $MYSQLD_DATADIR/test/func.MYI
+SHOW CREATE TABLE func;
+SELECT * FROM func LIMIT 0;
+DROP TABLE func;
+
+--copy_file std_data/mysql5613mysql/plugin.frm $MYSQLD_DATADIR/test/plugin.frm
+--copy_file std_data/mysql5613mysql/plugin.MYD $MYSQLD_DATADIR/test/plugin.MYD
+--copy_file std_data/mysql5613mysql/plugin.MYI $MYSQLD_DATADIR/test/plugin.MYI
+SHOW CREATE TABLE plugin;
+SELECT * FROM plugin LIMIT 0;
+DROP TABLE plugin;
+
+--copy_file std_data/mysql5613mysql/proc.frm $MYSQLD_DATADIR/test/proc.frm
+--copy_file std_data/mysql5613mysql/proc.MYD $MYSQLD_DATADIR/test/proc.MYD
+--copy_file std_data/mysql5613mysql/proc.MYI $MYSQLD_DATADIR/test/proc.MYI
+SHOW CREATE TABLE proc;
+SELECT * FROM proc LIMIT 0;
+DROP TABLE proc;
+
+--copy_file std_data/mysql5613mysql/procs_priv.frm $MYSQLD_DATADIR/test/procs_priv.frm
+--copy_file std_data/mysql5613mysql/procs_priv.MYD $MYSQLD_DATADIR/test/procs_priv.MYD
+--copy_file std_data/mysql5613mysql/procs_priv.MYI $MYSQLD_DATADIR/test/procs_priv.MYI
+SHOW CREATE TABLE procs_priv;
+SELECT * FROM procs_priv LIMIT 0;
+DROP TABLE procs_priv;
+
+--copy_file std_data/mysql5613mysql/proxies_priv.frm $MYSQLD_DATADIR/test/proxies_priv.frm
+--copy_file std_data/mysql5613mysql/proxies_priv.MYD $MYSQLD_DATADIR/test/proxies_priv.MYD
+--copy_file std_data/mysql5613mysql/proxies_priv.MYI $MYSQLD_DATADIR/test/proxies_priv.MYI
+SHOW CREATE TABLE proxies_priv;
+SELECT * FROM proxies_priv LIMIT 0;
+DROP TABLE proxies_priv;
+
+--copy_file std_data/mysql5613mysql/servers.frm $MYSQLD_DATADIR/test/servers.frm
+--copy_file std_data/mysql5613mysql/servers.MYD $MYSQLD_DATADIR/test/servers.MYD
+--copy_file std_data/mysql5613mysql/servers.MYI $MYSQLD_DATADIR/test/servers.MYI
+SHOW CREATE TABLE servers;
+SELECT * FROM servers LIMIT 0;
+DROP TABLE servers;
+
+--copy_file std_data/mysql5613mysql/tables_priv.frm $MYSQLD_DATADIR/test/tables_priv.frm
+--copy_file std_data/mysql5613mysql/tables_priv.MYD $MYSQLD_DATADIR/test/tables_priv.MYD
+--copy_file std_data/mysql5613mysql/tables_priv.MYI $MYSQLD_DATADIR/test/tables_priv.MYI
+SHOW CREATE TABLE tables_priv;
+SELECT * FROM tables_priv LIMIT 0;
+DROP TABLE tables_priv;
+
+--copy_file std_data/mysql5613mysql/time_zone_leap_second.frm $MYSQLD_DATADIR/test/time_zone_leap_second.frm
+--copy_file std_data/mysql5613mysql/time_zone_leap_second.MYD $MYSQLD_DATADIR/test/time_zone_leap_second.MYD
+--copy_file std_data/mysql5613mysql/time_zone_leap_second.MYI $MYSQLD_DATADIR/test/time_zone_leap_second.MYI
+SHOW CREATE TABLE time_zone_leap_second;
+SELECT * FROM time_zone_leap_second LIMIT 0;
+DROP TABLE time_zone_leap_second;
+
+--copy_file std_data/mysql5613mysql/time_zone.frm $MYSQLD_DATADIR/test/time_zone.frm
+--copy_file std_data/mysql5613mysql/time_zone.MYD $MYSQLD_DATADIR/test/time_zone.MYD
+--copy_file std_data/mysql5613mysql/time_zone.MYI $MYSQLD_DATADIR/test/time_zone.MYI
+SHOW CREATE TABLE time_zone;
+SELECT * FROM time_zone LIMIT 0;
+DROP TABLE time_zone;
+
+--copy_file std_data/mysql5613mysql/time_zone_name.frm $MYSQLD_DATADIR/test/time_zone_name.frm
+--copy_file std_data/mysql5613mysql/time_zone_name.MYD $MYSQLD_DATADIR/test/time_zone_name.MYD
+--copy_file std_data/mysql5613mysql/time_zone_name.MYI $MYSQLD_DATADIR/test/time_zone_name.MYI
+SHOW CREATE TABLE time_zone_name;
+SELECT * FROM time_zone_name LIMIT 0;
+DROP TABLE time_zone_name;
+
+--copy_file std_data/mysql5613mysql/time_zone_transition.frm $MYSQLD_DATADIR/test/time_zone_transition.frm
+--copy_file std_data/mysql5613mysql/time_zone_transition.MYD $MYSQLD_DATADIR/test/time_zone_transition.MYD
+--copy_file std_data/mysql5613mysql/time_zone_transition.MYI $MYSQLD_DATADIR/test/time_zone_transition.MYI
+SHOW CREATE TABLE time_zone_transition;
+SELECT * FROM time_zone_transition LIMIT 0;
+DROP TABLE time_zone_transition;
+
+--copy_file std_data/mysql5613mysql/time_zone_transition_type.frm $MYSQLD_DATADIR/test/time_zone_transition_type.frm
+--copy_file std_data/mysql5613mysql/time_zone_transition_type.MYD $MYSQLD_DATADIR/test/time_zone_transition_type.MYD
+--copy_file std_data/mysql5613mysql/time_zone_transition_type.MYI $MYSQLD_DATADIR/test/time_zone_transition_type.MYI
+SHOW CREATE TABLE time_zone_transition_type;
+SELECT * FROM time_zone_transition_type LIMIT 0;
+DROP TABLE time_zone_transition_type;
+
+--copy_file std_data/mysql5613mysql/user.frm $MYSQLD_DATADIR/test/user.frm
+--copy_file std_data/mysql5613mysql/user.MYD $MYSQLD_DATADIR/test/user.MYD
+--copy_file std_data/mysql5613mysql/user.MYI $MYSQLD_DATADIR/test/user.MYI
+SHOW CREATE TABLE user;
+SELECT * FROM user LIMIT 0;
+DROP TABLE user;
diff --git a/mysql-test/t/mysql_client_test-master.opt b/mysql-test/t/mysql_client_test-master.opt
index 69debb24dae..fcaf2b69fbc 100644
--- a/mysql-test/t/mysql_client_test-master.opt
+++ b/mysql-test/t/mysql_client_test-master.opt
@@ -1,2 +1,4 @@
---log=$MYSQLTEST_VARDIR/log/master.log
+--general-log
+--general-log-file=$MYSQLTEST_VARDIR/log/master.log
--log-output=FILE,TABLE
+--max-allowed-packet=32000000
diff --git a/mysql-test/t/mysql_client_test.test b/mysql-test/t/mysql_client_test.test
index 90da022fb38..bf5331ca4f9 100644
--- a/mysql-test/t/mysql_client_test.test
+++ b/mysql-test/t/mysql_client_test.test
@@ -6,6 +6,8 @@
SET @old_general_log= @@global.general_log;
SET @old_slow_query_log= @@global.slow_query_log;
+call mtr.add_suppression(" Error reading file './client_test_db/test_frm_bug.frm'");
+
# We run with different binaries for normal and --embedded-server
#
# If this test fails with "command "$MYSQL_CLIENT_TEST" failed",
diff --git a/mysql-test/t/mysql_client_test_comp-master.opt b/mysql-test/t/mysql_client_test_comp-master.opt
new file mode 100644
index 00000000000..783093c900b
--- /dev/null
+++ b/mysql-test/t/mysql_client_test_comp-master.opt
@@ -0,0 +1,2 @@
+--loose-enable-performance-schema
+--max-allowed-packet=32000000
diff --git a/mysql-test/t/mysql_client_test_comp.test b/mysql-test/t/mysql_client_test_comp.test
new file mode 100644
index 00000000000..0a6b0ba1130
--- /dev/null
+++ b/mysql-test/t/mysql_client_test_comp.test
@@ -0,0 +1,20 @@
+# run mysql_client_test with performance schema
+
+# No need to run this with embedded server
+-- source include/not_embedded.inc
+
+# need to have the dynamic loading turned on for the client plugin tests
+--source include/have_plugin_auth.inc
+
+SET @old_slow_query_log= @@global.slow_query_log;
+
+call mtr.add_suppression(" Error reading file './client_test_db/test_frm_bug.frm'");
+
+--exec echo "$MYSQL_CLIENT_TEST" > $MYSQLTEST_VARDIR/log/mysql_client_test_comp.out.log 2>&1
+--exec $MYSQL_CLIENT_TEST --getopt-ll-test=25600M >> $MYSQLTEST_VARDIR/log/mysql_client_test_comp.out.log 2>&1
+
+# End of test
+echo ok;
+
+# Restore state changed by mysql_test_run
+SET @@global.slow_query_log= @old_slow_query_log;
diff --git a/mysql-test/t/mysql_client_test_nonblock-master.opt b/mysql-test/t/mysql_client_test_nonblock-master.opt
index 4c683f7f0a2..5775e707c5f 100644
--- a/mysql-test/t/mysql_client_test_nonblock-master.opt
+++ b/mysql-test/t/mysql_client_test_nonblock-master.opt
@@ -1 +1,2 @@
---log=$MYSQLTEST_VARDIR/log/master.log --log-output=FILE,TABLE
+--general-log --general-log-file=$MYSQLTEST_VARDIR/log/master.log --log-output=FILE,TABLE
+--max-allowed-packet=32000000
diff --git a/mysql-test/t/mysql_client_test_nonblock.test b/mysql-test/t/mysql_client_test_nonblock.test
index fc2e0b1d01b..51263854e58 100644
--- a/mysql-test/t/mysql_client_test_nonblock.test
+++ b/mysql-test/t/mysql_client_test_nonblock.test
@@ -5,6 +5,7 @@
SET @old_general_log= @@global.general_log;
SET @old_slow_query_log= @@global.slow_query_log;
+call mtr.add_suppression(" Error reading file './client_test_db/test_frm_bug.frm'");
# We run with different binaries for normal and --embedded-server
#
diff --git a/mysql-test/t/mysql_upgrade-6984.opt b/mysql-test/t/mysql_upgrade-6984.opt
new file mode 100644
index 00000000000..97669d95260
--- /dev/null
+++ b/mysql-test/t/mysql_upgrade-6984.opt
@@ -0,0 +1 @@
+--skip-grant-tables --group-concat-max-len=1023
diff --git a/mysql-test/t/mysql_upgrade-6984.test b/mysql-test/t/mysql_upgrade-6984.test
new file mode 100644
index 00000000000..9bbfbeb3f87
--- /dev/null
+++ b/mysql-test/t/mysql_upgrade-6984.test
@@ -0,0 +1,23 @@
+#
+# MDEV-6984 Can't migrate from MySQL 5.6.21 to MariaDB 10
+#
+--source include/not_embedded.inc
+
+#
+# When 'root' account is password protected and MYSQL_UPGRADE doesn't
+# know the password (meaning, MYSQL_UPGRADE is run automatically
+# on upgrade), MYSQLD has to be started with --skip-grant-tables.
+#
+# In this setup MYSQL_UPGRADE cannot continue after issuing FLUSH PRIVILEGES
+#
+
+update mysql.user set password=password("foo") where user='root';
+
+--exec $MYSQL_UPGRADE
+
+connect(con1,localhost,root,foo,,,);
+
+update mysql.user set password='' where user='root';
+flush privileges;
+# Load event table
+set global event_scheduler=OFF;
diff --git a/mysql-test/t/mysql_upgrade.test b/mysql-test/t/mysql_upgrade.test
index 86de04a9aef..f8026df8770 100644
--- a/mysql-test/t/mysql_upgrade.test
+++ b/mysql-test/t/mysql_upgrade.test
@@ -1,5 +1,7 @@
-- source include/mysql_upgrade_preparation.inc
-- source include/have_working_dns.inc
+-- source include/have_innodb.inc
+-- source include/have_partition.inc
#
# Basic test that we can run mysql_upgrde and that it finds the
@@ -51,7 +53,7 @@ DROP USER mysqltest1@'%';
--echo Run mysql_upgrade with a non existing server socket
--replace_result $MYSQLTEST_VARDIR var
---replace_regex /.*mysqlcheck.*: Got/mysqlcheck: Got/ /\([0-9]*\)/(errno)/
+--replace_regex /.*mysqlcheck.*: Got/mysqlcheck: Got/ /\([0-9|-]*\)/(errno)/
--error 1
# NC: Added --skip-version-check, as the version check would fail when
# mysql_upgrade tries to get the server version.
@@ -137,27 +139,11 @@ let $MYSQLD_DATADIR= `select @@datadir`;
--error 1
--exec $MYSQL_UPGRADE --skip-verbose --user=root --password=wrong_password 2>&1
-# 5.5-only test (involves manual modification of system tables)
--echo #
--echo # MDEV-4332 Increase username length from 16 characters
--echo # MDEV-6068, MDEV-6178 mysql_upgrade breaks databases with long user names
--echo #
-alter table mysql.user modify User char(80) binary not null default '';
-alter table mysql.db modify User char(80) binary not null default '';
-alter table mysql.tables_priv modify User char(80) binary not null default '';
-alter table mysql.columns_priv modify User char(80) binary not null default '';
-alter table mysql.procs_priv modify User char(80) binary not null default '';
-alter table mysql.proc modify definer char(141) collate utf8_bin not null default '';
-alter table mysql.event modify definer char(141) collate utf8_bin not null default '';
-alter table mysql.proxies_priv modify User char(80) COLLATE utf8_bin not null default '';
-alter table mysql.proxies_priv modify Proxied_user char(80) COLLATE utf8_bin not null default '';
-alter table mysql.proxies_priv modify Grantor char(141) COLLATE utf8_bin not null default '';
-alter table mysql.servers modify Username char(80) not null default '';
-alter table mysql.procs_priv modify Grantor char(141) COLLATE utf8_bin not null default '';
-alter table mysql.tables_priv modify Grantor char(141) COLLATE utf8_bin not null default '';
-flush privileges;
-
connection default;
GRANT SELECT ON mysql.* TO very_long_user_name_number_1;
GRANT SELECT ON mysql.* TO very_long_user_name_number_2;
@@ -181,21 +167,26 @@ SELECT grantor FROM mysql.tables_priv WHERE db = 'mysql' AND table_name = 'user'
DROP USER very_long_user_name_number_1, very_long_user_name_number_2, even_longer_user_name_number_3_to_test_the_grantor_and_definer_field_length@localhost;
DROP PROCEDURE test.pr;
-# Restore system tables
-
-alter table mysql.user modify User char(16) binary not null default '';
-alter table mysql.db modify User char(16) binary not null default '';
-alter table mysql.tables_priv modify User char(16) binary not null default '';
-alter table mysql.columns_priv modify User char(16) binary not null default '';
-alter table mysql.procs_priv modify User char(16) binary not null default '';
-alter table mysql.proc modify definer char(77) collate utf8_bin not null default '';
-alter table mysql.event modify definer char(77) collate utf8_bin not null default '';
-alter table mysql.proxies_priv modify User char(16) COLLATE utf8_bin not null default '';
-alter table mysql.proxies_priv modify Proxied_user char(16) COLLATE utf8_bin not null default '';
-alter table mysql.proxies_priv modify Grantor char(77) COLLATE utf8_bin not null default '';
-alter table mysql.servers modify Username char(64) not null default '';
-alter table mysql.procs_priv modify Grantor char(77) COLLATE utf8_bin not null default '';
-alter table mysql.tables_priv modify Grantor char(77) COLLATE utf8_bin not null default '';
-flush privileges;
-
---echo End of tests
+#
+# MDEV-13274 mysql_upgrade fails if dbname+tablename+partioname > 64 chars
+#
+use test;
+alter table mysql.innodb_table_stats modify last_update int not null;
+
+create table extralongname_extralongname_extralongname_extralongname_ext (
+ id int(10) unsigned not null,
+ created_date date not null,
+ created timestamp not null,
+ primary key (created,id,created_date)
+) engine=innodb stats_persistent=1 default charset=latin1
+ partition by range (year(created_date))
+ subpartition by hash (month(created_date))
+ subpartitions 2 (
+ partition p2007 values less than (2008),
+ partition p2008 values less than (2009)
+ );
+--exec $MYSQL_UPGRADE --skip-verbose --force 2>&1
+select length(table_name) from mysql.innodb_table_stats;
+drop table extralongname_extralongname_extralongname_extralongname_ext;
+
+--echo End of 10.0 tests
diff --git a/mysql-test/t/mysql_upgrade_no_innodb.test b/mysql-test/t/mysql_upgrade_no_innodb.test
new file mode 100644
index 00000000000..8813a450450
--- /dev/null
+++ b/mysql-test/t/mysql_upgrade_no_innodb.test
@@ -0,0 +1,6 @@
+--source include/mysql_upgrade_preparation.inc
+
+--exec $MYSQL_UPGRADE --force --upgrade-system-tables 2>&1
+
+let $MYSQLD_DATADIR= `select @@datadir`;
+--remove_file $MYSQLD_DATADIR/mysql_upgrade_info
diff --git a/mysql-test/t/mysql_upgrade_ssl.test b/mysql-test/t/mysql_upgrade_ssl.test
index 8ed818186b2..9049bf73821 100644
--- a/mysql-test/t/mysql_upgrade_ssl.test
+++ b/mysql-test/t/mysql_upgrade_ssl.test
@@ -2,6 +2,7 @@
-- source include/have_ssl_communication.inc
-- source include/mysql_upgrade_preparation.inc
+-- source include/have_innodb.inc
--echo #
--echo # Bug#55672 mysql_upgrade dies with internal error
diff --git a/mysql-test/t/mysqlbinlog.test b/mysql-test/t/mysqlbinlog.test
index e8ce861dd53..7e680702a7a 100644
--- a/mysql-test/t/mysqlbinlog.test
+++ b/mysql-test/t/mysqlbinlog.test
@@ -275,25 +275,24 @@ FLUSH LOGS;
DROP TABLE t1;
-# We create a table, patch, and load the output into it
-# By using LINES STARTING BY '#' + SELECT WHERE a LIKE 'Query'
-# We can easily see if a 'Query' line is missing the '#' character
-# as described in the original bug
+# We create a table named "patch", and load the output into it.
+# By using LIKE, we can easily see if the output is missing the '#'
+# character, as described in the bug.
--disable_query_log
CREATE TABLE patch (a BLOB);
--exec $MYSQL_BINLOG --hexdump --local-load=$MYSQLTEST_VARDIR/tmp/ $MYSQLD_DATADIR/master-bin.000012 > $MYSQLTEST_VARDIR/tmp/mysqlbinlog_tmp.dat
### Starting master-bin.000014
eval LOAD DATA LOCAL INFILE '$MYSQLTEST_VARDIR/tmp/mysqlbinlog_tmp.dat'
- INTO TABLE patch FIELDS TERMINATED BY '' LINES STARTING BY '#';
+ INTO TABLE patch FIELDS TERMINATED BY '';
--remove_file $MYSQLTEST_VARDIR/tmp/mysqlbinlog_tmp.dat
--enable_query_log
---echo We expect this value to be 1
+--echo We expect this value to be 2 (one for the INSERT, one for COMMIT).
--echo The bug being tested was that 'Query' lines were not preceded by '#'
--echo If the line is in the table, it had to have been preceded by a '#'
--echo
-SELECT COUNT(*) AS `BUG#28293_expect_3` FROM patch WHERE a LIKE '%Query%';
+SELECT COUNT(*) AS `BUG#28293_expect_2` FROM patch WHERE a LIKE '#%Query%';
DROP TABLE patch;
#
@@ -594,3 +593,19 @@ SHOW TABLES IN test;
--exec $MYSQL_BINLOG --server-id=2 $MYSQLD_DATADIR/$master_binlog | $MYSQL
SHOW TABLES IN test;
eval SET GLOBAL SERVER_ID = $old_server_id;
+
+--echo #
+--echo # MDEV-4645: Incorrect reads of frozen binlog events;
+--echo # FDE corrupted in relay log
+--echo #
+--let TZ=GMT
+--exec $MYSQL_BINLOG --hexdump std_data/mdev-4645-binlog_checksum.binlog
+--exec $MYSQL_BINLOG --hexdump std_data/mdev-4645-binlog_group_id.binlog
+--exec $MYSQL_BINLOG --hexdump std_data/mdev-4645-binlog_group_id_checksum.binlog
+--exec $MYSQL_BINLOG --hexdump std_data/mdev-4645-binlog_none.binlog
+
+#
+# MDEV-12372 mysqlbinlog --version output is the same on 10.x as on 5.5.x, and contains not only version
+#
+replace_regex /.*mysqlbinlog(\.exe)? Ver .* for .* at [-_a-zA-Z0-9]+/mysqlbinlog Ver VER for OS at ARCH/;
+exec $MYSQL_BINLOG --version;
diff --git a/mysql-test/t/mysqlcheck.test b/mysql-test/t/mysqlcheck.test
index 781af357408..779ea8d13d4 100644
--- a/mysql-test/t/mysqlcheck.test
+++ b/mysql-test/t/mysqlcheck.test
@@ -1,3 +1,4 @@
+call mtr.add_suppression("Invalid .old.. table or database name");
# Embedded server doesn't support external clients
--source include/not_embedded.inc
@@ -93,6 +94,7 @@ drop view v1;
# Bug#37527: mysqlcheck fails to report entire database
# when frm file corruption
#
+call mtr.add_suppression("Error reading file './test/t1.frm'");
CREATE TABLE t1(a INT) engine=myisam;
CREATE TABLE t2(a INT) engine=myisam;
# backup then null t1.frm
@@ -258,10 +260,7 @@ FLUSH TABLE bug47205;
CHECK TABLE bug47205 FOR UPGRADE;
--echo # ALTER TABLE ... FORCE should rebuild the table
---echo # and therefore output "affected rows: 1"
---enable_info
ALTER TABLE bug47205 FORCE;
---disable_info
--echo # Table should now be ok
CHECK TABLE bug47205 FOR UPGRADE;
@@ -341,9 +340,9 @@ check table `t.1`, `t.2`, `t.3` for upgrade;
drop view `v.1`;
drop table test.`t.1`, `t.2`, `t.3`;
-#
-# MDEV-8123 mysqlcheck: new --process-views option conflicts with --quick, --extended and such
-#
+--echo #
+--echo # MDEV-8123 mysqlcheck: new --process-views option conflicts with --quick, --extended and such
+--echo #
create view v1 as select 1;
--echo mysqlcheck --process-views test
--exec $MYSQL_CHECK --process-views test
@@ -362,9 +361,9 @@ create view v1 as select 1;
drop view v1;
-#
-# MDEV-8124 mysqlcheck: --auto-repair runs REPAIR TABLE instead of REPAIR VIEW on views
-#
+--echo #
+--echo # MDEV-8124 mysqlcheck: --auto-repair runs REPAIR TABLE instead of REPAIR VIEW on views
+--echo #
create table t1(a int);
--copy_file $MYSQL_TEST_DIR/std_data/mysql_upgrade/v1.frm $MYSQLD_DATADIR/test/v1.frm
--echo mysqlcheck --process-views --check-upgrade --auto-repair test
@@ -398,3 +397,13 @@ check table mysqltest1.t1;
drop table t2;
drop database mysqltest1;
+
+--echo #
+--echo #MDEV-7384 [PATCH] add PERSISENT FOR ALL option to mysqlanalyze/mysqlcheck
+--echo #
+create table t1(a int);
+insert into t1 (a) values (1), (2), (3);
+select * from mysql.column_stats;
+--exec $MYSQL_CHECK --analyze test t1 --persistent
+select * from mysql.column_stats where db_name = 'test' and table_name = 't1';
+drop table t1;
diff --git a/mysql-test/t/mysqld--help.test b/mysql-test/t/mysqld--help.test
index 5f61b4b7c43..96774d829ec 100644
--- a/mysql-test/t/mysqld--help.test
+++ b/mysql-test/t/mysqld--help.test
@@ -3,6 +3,7 @@
#
--source include/not_embedded.inc
--source include/have_perfschema.inc
+--source include/have_profiling.inc
--source include/platform.inc
#
@@ -20,14 +21,18 @@ perl;
# their paths may vary:
@skipvars=qw/basedir open-files-limit general-log-file log plugin-dir
log-slow-queries pid-file slow-query-log-file log-basename
- datadir slave-load-tmpdir tmpdir socket/;
+ datadir slave-load-tmpdir tmpdir socket thread-pool-size
+ large-files-support lower-case-file-system system-time-zone
+ collation-server character-set-server
+ version.*/;
# Plugins which may or may not be there:
@plugins=qw/innodb ndb archive blackhole federated partition ndbcluster
- feedback debug temp-pool ssl des-key-file
- xtradb thread-concurrency super-large-pages
- mutex-deadlock-detector null-audit maria aria oqgraph
- sphinx thread-handling thread-pool query-cache-info/;
+ feedback debug temp-pool ssl des-key-file xtradb sequence
+ thread-concurrency super-large-pages mutex-deadlock-detector
+ connect null-audit aria oqgraph sphinx thread-handling
+ test-sql-discovery rpl-semi-sync query-cache-info
+ query-response-time metadata-lock-info locales unix-socket/;
# And substitute the content some environment variables with their
# names:
diff --git a/mysql-test/t/mysqldump-max.test b/mysql-test/t/mysqldump-max.test
index 27c1a3ce20c..d0a4870ba31 100644
--- a/mysql-test/t/mysqldump-max.test
+++ b/mysql-test/t/mysqldump-max.test
@@ -1194,7 +1194,7 @@ DROP TABLE t2;
--exec $MYSQL test < $MYSQLTEST_VARDIR/tmp/mwl136.sql
--replace_regex /\/\* xid=.* \*\//\/* XID *\// /Server ver: .*, Binlog ver: .*/Server ver: #, Binlog ver: #/ /table_id: [0-9]+/table_id: #/
-SHOW BINLOG EVENTS LIMIT 6,3;
+SHOW BINLOG EVENTS LIMIT 7,3;
--perl
my $f= "$ENV{MYSQLTEST_VARDIR}/tmp/mwl136.sql";
open F, '<', $f or die "Failed to open $f: $!\n";
diff --git a/mysql-test/t/mysqldump.test b/mysql-test/t/mysqldump.test
index 39ca5b3c58e..bb5a9ae1846 100644
--- a/mysql-test/t/mysqldump.test
+++ b/mysql-test/t/mysqldump.test
@@ -13,6 +13,9 @@ let collation=utf8_unicode_ci;
# Save the initial number of concurrent sessions
--source include/count_sessions.inc
+# There are tables in 'mysql' database of type innodb
+--source include/have_innodb.inc
+
disable_query_log;
call mtr.add_suppression("Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEMENT");
enable_query_log;
@@ -698,7 +701,7 @@ drop table t1;
--echo #
---echo # Bug#15328 Segmentation fault occured if my.cnf is invalid for escape sequence
+--echo # Bug#15328 Segmentation fault occurred if my.cnf is invalid for escape sequence
--echo #
--exec $MYSQL_MY_PRINT_DEFAULTS --config-file=$MYSQL_TEST_DIR/std_data/bug15328.cnf mysqldump
diff --git a/mysql-test/t/mysqlshow.test b/mysql-test/t/mysqlshow.test
index 4602c15e566..8c60b64a5f1 100644
--- a/mysql-test/t/mysqlshow.test
+++ b/mysql-test/t/mysqlshow.test
@@ -28,6 +28,7 @@ select "---- -v -v -t ------" as "";
--exec $MYSQL_SHOW test -v -v -t
DROP TABLE t1, t2;
+--echo End of 5.0 tests
# because of lp:1066512 this test shows xtradb I_S plugins, even when
# xtradb is supposed to be disabled
@@ -39,4 +40,3 @@ DROP TABLE t1, t2;
#--exec $MYSQL_SHOW INFORMATION_SCHEMA
#--exec $MYSQL_SHOW inf_rmation_schema
---echo End of 5.0 tests
diff --git a/mysql-test/t/mysqltest.test b/mysql-test/t/mysqltest.test
index afe37926591..aea4ba6432d 100644
--- a/mysql-test/t/mysqltest.test
+++ b/mysql-test/t/mysqltest.test
@@ -2044,7 +2044,7 @@ select "at" as col1, "AT" as col2, "c" as col3;
--replace_regex /a/b/ /ct/d/
select "a" as col1, "ct" as col2;
---replace_regex /(strawberry)/raspberry and \1/ /blueberry/blackberry/ /potato/tomato/;
+--replace_regex /(strawberry)/raspberry and \1/ /blueberry/blackberry/ /potato/tomato/
select "strawberry","blueberry","potato";
--error 1
@@ -2089,6 +2089,12 @@ select "a is a and less is more" as txt;
select "a is a and less is more" as txt;
--enable_query_log
+#
+# different delimiters
+#
+--replace_regex (a)[b] /c/d/ <e>{f}i {g\/\}}/h/
+select 'ABCDEF abcdef g/}' as txt;
+
#-------------------------------------------------------------------------
# BUG #11754855 : Passing variable to --error
#-------------------------------------------------------------------------
diff --git a/mysql-test/t/no-threads-master.opt b/mysql-test/t/no-threads-master.opt
index e263cad427c..33e3e97bc0e 100644
--- a/mysql-test/t/no-threads-master.opt
+++ b/mysql-test/t/no-threads-master.opt
@@ -1 +1 @@
---one-thread --thread-handling=no-threads
+--thread-handling=no-threads
diff --git a/mysql-test/t/not_embedded_server.test b/mysql-test/t/not_embedded_server.test
index 5b99c37ee29..e74da3a8ff4 100644
--- a/mysql-test/t/not_embedded_server.test
+++ b/mysql-test/t/not_embedded_server.test
@@ -18,10 +18,8 @@ SHOW VARIABLES like 'slave_skip_errors';
--echo # Bug#58026: massive recursion and crash in regular expression handling
--echo #
---disable_result_log
---error ER_STACK_OVERRUN_NEED_MORE
+--error ER_STACK_OVERRUN_NEED_MORE,ER_REGEXP_ERROR
SELECT '1' RLIKE RPAD('1', 10000, '(');
---enable_result_log
# End of 5.1 tests
@@ -104,3 +102,110 @@ DROP USER nopriv_user@localhost;
--echo #
--echo # End Bug#54812
--echo #
+
+
+--echo
+--echo #
+--echo # Test for Bug#12601974 - STORED PROCEDURE SQL_MODE=NO_BACKSLASH_ESCAPES
+--echo # IGNORED AND BREAKS REPLICATION
+--echo #
+
+SET @org_mode=@@sql_mode;
+
+SET @@sql_mode='';
+
+--echo # USER NAME CONTAINING BACKSLASH IN CREATE USER OPERATION
+CREATE USER 'user\'s_12601974'@'localhost';
+--error ER_CANNOT_USER
+CREATE USER 'user\'s_12601974'@'localhost';
+DROP USER 'user\'s_12601974'@'localhost';
+
+CREATE USER 'user\"s_12601974'@'localhost';
+--error ER_CANNOT_USER
+CREATE USER 'user\"s_12601974'@'localhost';
+DROP USER 'user\"s_12601974'@'localhost';
+
+CREATE USER 'user\bs_12601974'@'localhost';
+--error ER_CANNOT_USER
+CREATE USER 'user\bs_12601974'@'localhost';
+DROP USER 'user\bs_12601974'@'localhost';
+
+CREATE USER 'user\ns_12601974'@'localhost';
+--error ER_CANNOT_USER
+CREATE USER 'user\ns_12601974'@'localhost';
+DROP USER 'user\ns_12601974'@'localhost';
+
+CREATE USER 'user\rs_12601974'@'localhost';
+--error ER_CANNOT_USER
+CREATE USER 'user\rs_12601974'@'localhost';
+DROP USER 'user\rs_12601974'@'localhost';
+
+CREATE USER 'user\ts_12601974'@'localhost';
+--error ER_CANNOT_USER
+CREATE USER 'user\ts_12601974'@'localhost';
+DROP USER 'user\ts_12601974'@'localhost';
+
+CREATE USER 'user\\s_12601974'@'localhost';
+--error ER_CANNOT_USER
+CREATE USER 'user\\s_12601974'@'localhost';
+DROP USER 'user\\s_12601974'@'localhost';
+
+CREATE USER 'user\%s_12601974'@'localhost';
+--error ER_CANNOT_USER
+CREATE USER 'user\%s_12601974'@'localhost';
+DROP USER 'user\%s_12601974'@'localhost';
+
+CREATE USER 'user\_s_12601974'@'localhost';
+--error ER_CANNOT_USER
+CREATE USER 'user\_s_12601974'@'localhost';
+DROP USER 'user\_s_12601974'@'localhost';
+--echo
+--echo # END OF CASE - USER NAME CONTAINING BACKSLASH IN CREATE USER OPERATION
+
+SET @@sql_mode='NO_BACKSLASH_ESCAPES';
+--echo # USER NAME CONTAINING BACKSLASH IN DROP USER OPERATION
+CREATE USER 'user\"s_12601974'@'localhost';
+--error ER_CANNOT_USER
+CREATE USER 'user\"s_12601974'@'localhost';
+DROP USER 'user\"s_12601974'@'localhost';
+
+CREATE USER 'user\bs_12601974'@'localhost';
+--error ER_CANNOT_USER
+CREATE USER 'user\bs_12601974'@'localhost';
+DROP USER 'user\bs_12601974'@'localhost';
+
+CREATE USER 'user\ns_12601974'@'localhost';
+--error ER_CANNOT_USER
+CREATE USER 'user\ns_12601974'@'localhost';
+DROP USER 'user\ns_12601974'@'localhost';
+
+CREATE USER 'user\rs_12601974'@'localhost';
+--error ER_CANNOT_USER
+CREATE USER 'user\rs_12601974'@'localhost';
+DROP USER 'user\rs_12601974'@'localhost';
+
+CREATE USER 'user\ts_12601974'@'localhost';
+--error ER_CANNOT_USER
+CREATE USER 'user\ts_12601974'@'localhost';
+DROP USER 'user\ts_12601974'@'localhost';
+
+CREATE USER 'user\\s_12601974'@'localhost';
+--error ER_CANNOT_USER
+CREATE USER 'user\\s_12601974'@'localhost';
+DROP USER 'user\\s_12601974'@'localhost';
+
+CREATE USER 'user\%s_12601974'@'localhost';
+--error ER_CANNOT_USER
+CREATE USER 'user\%s_12601974'@'localhost';
+DROP USER 'user\%s_12601974'@'localhost';
+
+CREATE USER 'user\_s_12601974'@'localhost';
+--error ER_CANNOT_USER
+CREATE USER 'user\_s_12601974'@'localhost';
+DROP USER 'user\_s_12601974'@'localhost';
+--echo
+--echo # END OF CASE - USER NAME CONTAINING BACKSLASH IN CREATE USER OPERATION
+SET @@sql_mode= @org_mode;
+
+--echo
+--echo #End of Test for Bug#12601974
diff --git a/mysql-test/t/not_partition.test b/mysql-test/t/not_partition.test
index b930214e008..dd52e4b97e6 100644
--- a/mysql-test/t/not_partition.test
+++ b/mysql-test/t/not_partition.test
@@ -2,10 +2,10 @@
# Run this test only when mysqld doesn't have partitioning (not compiled with)
# the statements are not expected to work, just check that we
# can't crash the server
--- require r/not_partition.require
-disable_query_log;
-show variables like "have_partitioning";
-enable_query_log;
+if (`SELECT COUNT(*) = 1 FROM INFORMATION_SCHEMA.PLUGINS WHERE PLUGIN_NAME = 'partition'`)
+{
+ --skip Test requires no partitioning
+}
--disable_warnings
DROP TABLE IF EXISTS t1;
--enable_warnings
@@ -84,3 +84,17 @@ create table t1 (a varchar(10) charset latin1 collate latin1_bin);
insert into t1 values (''),(' '),('a'),('a '),('a ');
explain partitions select * from t1 where a='a ' OR a='a';
drop table t1;
+--echo #
+--echo # bug#11760213-52599: ALTER TABLE REMOVE PARTITIONING ON NON-PARTITIONED
+--echo # TABLE CORRUPTS MYISAM
+--disable_warnings
+DROP TABLE if exists `t1`;
+--enable_warnings
+CREATE TABLE `t1`(`a` INT)ENGINE=myisam;
+ALTER TABLE `t1` ADD COLUMN `b` INT;
+CREATE UNIQUE INDEX `i1` ON `t1`(`b`);
+CREATE UNIQUE INDEX `i2` ON `t1`(`a`);
+ALTER TABLE `t1` ADD PRIMARY KEY (`a`);
+ALTER TABLE `t1` REMOVE PARTITIONING;
+CHECK TABLE `t1` EXTENDED;
+DROP TABLE t1;
diff --git a/mysql-test/t/null.test b/mysql-test/t/null.test
index 81951a9ce68..40f66946822 100644
--- a/mysql-test/t/null.test
+++ b/mysql-test/t/null.test
@@ -295,3 +295,16 @@ CREATE TABLE t2 (d DATE) ENGINE=MyISAM;
SELECT * FROM t1,t2 WHERE 1 IS NOT NULL AND t1.b IS NULL;
DROP TABLE t1,t2;
+
+--echo #
+--echo # Start of 10.0 tests
+--echo #
+
+--echo #
+--echo # MDEV-7001 Bad result for NOT NOT STRCMP('a','b') and NOT NOT NULLIF(2,3)
+--echo #
+SELECT NOT NOT NULLIF(2,3);
+
+--echo #
+--echo # End of 10.0 tests
+--echo #
diff --git a/mysql-test/t/old-mode.test b/mysql-test/t/old-mode.test
index cf2167c8027..c2a43f91ecb 100644
--- a/mysql-test/t/old-mode.test
+++ b/mysql-test/t/old-mode.test
@@ -20,8 +20,56 @@ drop table t1,t2;
# Test that SHOW PROCESSLIST doesn't have the Progress column
#
---replace_column 1 <Id> 3 <Host> 6 <Time>
+--replace_column 1 <Id> 3 <Host> 6 <Time> 7 <State>
# Embedded server is hardcoded to show "Writing to net" as STATE.
--replace_result "Writing to net" "NULL"
--replace_regex /localhost[:0-9]*/localhost/
SHOW PROCESSLIST;
+
+--echo #
+--echo # MDEV-5372 Make "CAST(time_expr AS DATETIME)" compatible with the SQL Standard)
+--echo #
+set @@old_mode=zero_date_time_cast;
+SELECT CAST(TIME'-10:30:30' AS DATETIME);
+SELECT CAST(TIME'10:20:30' AS DATETIME);
+SELECT CAST(TIME'830:20:30' AS DATETIME);
+CREATE TABLE t1 (a DATETIME);
+INSERT INTO t1 VALUES (TIME'-10:20:30');
+INSERT INTO t1 VALUES (TIME'10:20:30');
+INSERT INTO t1 VALUES (TIME'830:20:30');
+SELECT * FROM t1;
+DROP TABLE t1;
+CREATE TABLE t1 (a TIMESTAMP);
+INSERT INTO t1 VALUES (TIME'-10:20:30');
+INSERT INTO t1 VALUES (TIME'10:20:30');
+INSERT INTO t1 VALUES (TIME'830:20:30');
+SELECT * FROM t1;
+DROP TABLE t1;
+CREATE TABLE t1 (a TIME);
+INSERT INTO t1 VALUES (TIME'-10:20:30');
+INSERT INTO t1 VALUES (TIME'10:20:30');
+INSERT INTO t1 VALUES (TIME'830:20:30');
+SELECT a, CAST(a AS DATETIME), TO_DAYS(a) FROM t1;
+DROP TABLE t1;
+# Note, it was actually a bug that TO_DAYS('830:20:30') returned NULL
+# for a column, while 3 for an expression. We won't fix this,
+# it's "old_mode" anyway.
+SELECT TO_DAYS(TIME'-10:20:30');
+SELECT TO_DAYS(TIME'10:20:30');
+SELECT TO_DAYS(TIME'830:20:30');
+
+# This is to cover Item_temporal_hybrid_func::fix_temporal_type in old_mode:
+CREATE TABLE t1 (a DATETIME, b TIME);
+INSERT INTO t1 VALUES (NULL, '00:20:12');
+INSERT INTO t1 VALUES (NULL, '-00:20:12');
+SELECT IF(1,ADDDATE(IFNULL(a,b),0),1) FROM t1;
+DROP TABLE t1;
+
+--echo #
+--echo # MDEV-6649 Different warnings for TIME and TIME(N) when @@old_mode=zero_date_time_cast
+--echo #
+SET @@old_mode=zero_date_time_cast;
+CREATE TABLE t1 (a TIME,b TIME(1));
+INSERT INTO t1 VALUES (TIME'830:20:30',TIME'830:20:30');
+SELECT TO_DAYS(a), TO_DAYS(b) FROM t1;
+DROP TABLE t1;
diff --git a/mysql-test/t/openssl_1.test b/mysql-test/t/openssl_1.test
index 62b5c9c10e0..7063cffbb36 100644
--- a/mysql-test/t/openssl_1.test
+++ b/mysql-test/t/openssl_1.test
@@ -23,7 +23,7 @@ flush privileges;
connect (con1,localhost,ssl_user1,,,,,SSL-CIPHER=DHE-RSA-AES256-SHA);
--replace_result $MASTER_MYSOCK MASTER_SOCKET $MASTER_MYPORT MASTER_PORT
--error ER_ACCESS_DENIED_ERROR
-connect (con2,localhost,ssl_user2,,,,,SSL-CIPHER=RC4-SHA);
+connect (con2,localhost,ssl_user2,,,,,SSL-CIPHER=AES256-SHA);
connect (con2,localhost,ssl_user2,,,,,SSL-CIPHER=DHE-RSA-AES256-SHA);
connect (con3,localhost,ssl_user3,,,,,SSL-CIPHER=DHE-RSA-AES256-SHA);
connect (con4,localhost,ssl_user4,,,,,SSL-CIPHER=DHE-RSA-AES256-SHA);
@@ -132,8 +132,7 @@ drop table t1;
# verification of servers certificate by setting both ca certificate
# and ca path to NULL
#
---replace_result DHE-RSA-AES256-GCM-SHA384 DHE-RSA-AES256-SHA
---exec $MYSQL --ssl --ssl-key=$MYSQL_TEST_DIR/std_data/client-key.pem --ssl-cert=$MYSQL_TEST_DIR/std_data/client-cert.pem -e "SHOW STATUS LIKE 'ssl_Cipher'" 2>&1
+--exec $MYSQL --ssl --ssl-key=$MYSQL_TEST_DIR/std_data/client-key.pem --ssl-cert=$MYSQL_TEST_DIR/std_data/client-cert.pem -e "SELECT (VARIABLE_VALUE <> '') AS have_ssl FROM INFORMATION_SCHEMA.SESSION_STATUS WHERE VARIABLE_NAME='Ssl_cipher'" 2>&1
--echo End of 5.0 tests
#
@@ -222,7 +221,6 @@ DROP TABLE t1;
# Common ciphers to openssl and yassl
--exec $MYSQL --host=localhost -e "SHOW STATUS LIKE 'Ssl_cipher';" --ssl-cipher=DHE-RSA-AES256-SHA
--exec $MYSQL --host=localhost -e "SHOW STATUS LIKE 'Ssl_cipher';" --ssl-cipher=EDH-RSA-DES-CBC3-SHA
---exec $MYSQL --host=localhost -e "SHOW STATUS LIKE 'Ssl_cipher';" --ssl-cipher=RC4-SHA
--disable_query_log
--disable_result_log
@@ -258,13 +256,19 @@ select 'is still running; no cipher request crashed the server' as result from d
GRANT SELECT ON test.* TO bug42158@localhost REQUIRE X509;
FLUSH PRIVILEGES;
connect(con1,localhost,bug42158,,,,,SSL);
---replace_result DHE-RSA-AES256-GCM-SHA384 DHE-RSA-AES256-SHA
-SHOW STATUS LIKE 'Ssl_cipher';
+SELECT (VARIABLE_VALUE <> '') AS have_ssl FROM INFORMATION_SCHEMA.SESSION_STATUS WHERE VARIABLE_NAME='Ssl_cipher';
disconnect con1;
connection default;
DROP USER bug42158@localhost;
--echo End of 5.1 tests
+#
+# MDEV-9605 mysqlbinlog does not accept ssl-ca option as expected.
+#
+
+--error 1
+--exec $MYSQL_BINLOG --read-from-remote-server --ssl-ca --user=root --host=localhost nobinlog.111111
+
# Wait till we reached the initial number of concurrent sessions
--source include/wait_until_count_sessions.inc
diff --git a/mysql-test/t/openssl_6975.test b/mysql-test/t/openssl_6975.test
index bc6397c5c28..89e6983cf47 100644
--- a/mysql-test/t/openssl_6975.test
+++ b/mysql-test/t/openssl_6975.test
@@ -15,6 +15,7 @@ let $mysql=$MYSQL --ssl-key=$MYSQL_TEST_DIR/std_data/client-key.pem --ssl-cert=$
disable_abort_on_error;
echo TLS1.2 ciphers: user is ok with any cipher;
exec $mysql --ssl-cipher=AES128-SHA256;
+--replace_result DHE-RSA-CHACHA20-POLY1305 DHE-RSA-AES256-GCM-SHA384
exec $mysql --ssl-cipher=TLSv1.2;
echo TLS1.2 ciphers: user requires SSLv3 cipher RC4-SHA;
exec $mysql --user ssl_sslv3 --ssl-cipher=AES128-SHA256;
diff --git a/mysql-test/t/order_by.test b/mysql-test/t/order_by.test
index 398f9cb7dd2..e48bcbe00de 100644
--- a/mysql-test/t/order_by.test
+++ b/mysql-test/t/order_by.test
@@ -868,6 +868,7 @@ CALL mtr.add_suppression("Out of sort memory");
--error ER_OUT_OF_SORTMEMORY
select * from t1 order by b;
drop table t1;
+set session sort_buffer_size= 30000;
--echo #
--echo # Bug #39844: Query Crash Mysql Server 5.0.67
@@ -1394,7 +1395,205 @@ ORDER BY t2.c LIMIT 5;
DROP TABLE t1,t2,t3;
-#
+--echo #
+--echo # WL#1393 - Optimizing filesort with small limit
+--echo #
+
+CREATE TABLE t1(f0 int auto_increment primary key, f1 int, f2 varchar(200));
+INSERT INTO t1(f1, f2) VALUES
+(0,"0"),(1,"1"),(2,"2"),(3,"3"),(4,"4"),(5,"5"),
+(6,"6"),(7,"7"),(8,"8"),(9,"9"),(10,"10"),
+(11,"11"),(12,"12"),(13,"13"),(14,"14"),(15,"15"),
+(16,"16"),(17,"17"),(18,"18"),(19,"19"),(20,"20"),
+(21,"21"),(22,"22"),(23,"23"),(24,"24"),(25,"25"),
+(26,"26"),(27,"27"),(28,"28"),(29,"29"),(30,"30"),
+(31,"31"),(32,"32"),(33,"33"),(34,"34"),(35,"35"),
+(36,"36"),(37,"37"),(38,"38"),(39,"39"),(40,"40"),
+(41,"41"),(42,"42"),(43,"43"),(44,"44"),(45,"45"),
+(46,"46"),(47,"47"),(48,"48"),(49,"49"),(50,"50"),
+(51,"51"),(52,"52"),(53,"53"),(54,"54"),(55,"55"),
+(56,"56"),(57,"57"),(58,"58"),(59,"59"),(60,"60"),
+(61,"61"),(62,"62"),(63,"63"),(64,"64"),(65,"65"),
+(66,"66"),(67,"67"),(68,"68"),(69,"69"),(70,"70"),
+(71,"71"),(72,"72"),(73,"73"),(74,"74"),(75,"75"),
+(76,"76"),(77,"77"),(78,"78"),(79,"79"),(80,"80"),
+(81,"81"),(82,"82"),(83,"83"),(84,"84"),(85,"85"),
+(86,"86"),(87,"87"),(88,"88"),(89,"89"),(90,"90"),
+(91,"91"),(92,"92"),(93,"93"),(94,"94"),(95,"95"),
+(96,"96"),(97,"97"),(98,"98"),(99,"99");
+
+################
+## Test sort when source data fits in memory
+
+SELECT * FROM t1 ORDER BY f1 ASC, f0 LIMIT 100;
+SELECT * FROM t1 ORDER BY f1 ASC, f0 LIMIT 30;
+SELECT * FROM t1 ORDER BY f1 ASC, f0 LIMIT 0;
+SELECT * FROM t1 ORDER BY f2 DESC, f0 LIMIT 30;
+SELECT * FROM t1 ORDER BY f2 DESC, f0 LIMIT 0;
+SELECT * FROM t1 WHERE f1>10 ORDER BY f2, f0 LIMIT 20;
+SELECT * FROM t1 WHERE f1>10 ORDER BY f2, f0 LIMIT 0;
+SELECT * FROM t1 WHERE f1>10 ORDER BY f2, f0 LIMIT 10 OFFSET 10;
+SELECT * FROM t1 WHERE f1>10 ORDER BY f2, f0 LIMIT 0 OFFSET 10;
+
+################
+## Test sort when source data does not fit in memory
+set sort_buffer_size= 32768;
+CREATE TEMPORARY TABLE tmp (f1 int, f2 varchar(20));
+INSERT INTO tmp SELECT f1, f2 FROM t1;
+INSERT INTO t1(f1, f2) SELECT * FROM tmp;
+INSERT INTO tmp SELECT f1, f2 FROM t1;
+INSERT INTO t1(f1, f2) SELECT * FROM tmp;
+
+SELECT * FROM t1 ORDER BY f1 ASC, f0 LIMIT 30;
+SELECT * FROM t1 ORDER BY f1 ASC, f0 LIMIT 0;
+SELECT * FROM t1 ORDER BY f2 DESC, f0 LIMIT 30;
+SELECT * FROM t1 ORDER BY f2 DESC, f0 LIMIT 0;
+SELECT * FROM t1 WHERE f1>10 ORDER BY f2, f0 LIMIT 20;
+SELECT * FROM t1 WHERE f1>10 ORDER BY f2, f0 LIMIT 0;
+SELECT * FROM t1 WHERE f1>10 ORDER BY f2, f0 LIMIT 10 OFFSET 10;
+SELECT * FROM t1 WHERE f1>10 ORDER BY f2, f0 LIMIT 0 OFFSET 10;
+
+################
+## Test with SQL_CALC_FOUND_ROWS
+set sort_buffer_size= 32768;
+SELECT SQL_CALC_FOUND_ROWS * FROM t1
+ORDER BY f1, f0 LIMIT 30;
+SELECT FOUND_ROWS();
+
+SELECT SQL_CALC_FOUND_ROWS * FROM t1
+ORDER BY f1, f0 LIMIT 0;
+SELECT FOUND_ROWS();
+
+SELECT SQL_CALC_FOUND_ROWS * FROM t1 WHERE f1>10
+ORDER BY f2, f0 LIMIT 20;
+SELECT FOUND_ROWS();
+
+SELECT SQL_CALC_FOUND_ROWS * FROM t1 WHERE f1>10
+ORDER BY f2, f0 LIMIT 0;
+SELECT FOUND_ROWS();
+
+SELECT SQL_CALC_FOUND_ROWS * FROM t1 WHERE f1>10
+ORDER BY f2, f0 LIMIT 10 OFFSET 10;
+SELECT FOUND_ROWS();
+
+SELECT SQL_CALC_FOUND_ROWS * FROM t1 WHERE f1>10
+ORDER BY f2, f0 LIMIT 0 OFFSET 10;
+SELECT FOUND_ROWS();
+
+################
+## Test sorting with join
+## These are re-written to use PQ during execution.
+set sort_buffer_size= 327680;
+
+SELECT * FROM t1 JOIN tmp on t1.f2=tmp.f2
+ORDER BY tmp.f1, f0 LIMIT 30;
+
+SELECT * FROM t1 JOIN tmp on t1.f2=tmp.f2
+ORDER BY tmp.f1, f0 LIMIT 30 OFFSET 30;
+
+SELECT SQL_CALC_FOUND_ROWS * FROM t1 JOIN tmp on t1.f2=tmp.f2
+ORDER BY tmp.f1, f0 LIMIT 30 OFFSET 30;
+SELECT FOUND_ROWS();
+
+SELECT SQL_CALC_FOUND_ROWS * FROM t1 JOIN tmp on t1.f2=tmp.f2
+WHERE t1.f2>20
+ORDER BY tmp.f1, f0 LIMIT 30 OFFSET 30;
+SELECT FOUND_ROWS();
+
+################
+## Test views
+CREATE VIEW v1 as SELECT * FROM t1 ORDER BY f1, f0 LIMIT 30;
+SELECT * FROM v1;
+drop view v1;
+
+CREATE VIEW v1 as SELECT * FROM t1 ORDER BY f1, f0 LIMIT 100;
+SELECT * FROM v1 ORDER BY f2, f0 LIMIT 30;
+
+CREATE VIEW v2 as SELECT * FROM t1 ORDER BY f2, f0 LIMIT 100;
+SELECT * FROM v1 JOIN v2 on v1.f1=v2.f1 ORDER BY v1.f2,v1.f0,v2.f0
+LIMIT 30;
+
+################
+## Test group & having
+SELECT floor(f1/10) f3, count(f2) FROM t1
+GROUP BY 1 ORDER BY 2,1 LIMIT 5;
+
+SELECT floor(f1/10) f3, count(f2) FROM t1
+GROUP BY 1 ORDER BY 2,1 LIMIT 0;
+
+################
+## Test SP
+delimiter |;
+CREATE PROCEDURE wl1393_sp_test()
+BEGIN
+SELECT * FROM t1 WHERE f1>10 ORDER BY f2, f0 LIMIT 30;
+SELECT * FROM t1 WHERE f1>10 ORDER BY f2, f0 LIMIT 15 OFFSET 15;
+SELECT SQL_CALC_FOUND_ROWS * FROM t1 WHERE f1>10
+ORDER BY f2, f0 LIMIT 15 OFFSET 15;
+SELECT FOUND_ROWS();
+SELECT * FROM v1 ORDER BY f2, f0 LIMIT 30;
+END|
+CALL wl1393_sp_test()|
+DROP PROCEDURE wl1393_sp_test|
+delimiter ;|
+
+################
+## Test with subqueries
+SELECT d1.f1, d1.f2 FROM t1
+LEFT JOIN (SELECT * FROM t1 ORDER BY f1 LIMIT 30) d1 on t1.f1=d1.f1
+ORDER BY d1.f2 DESC LIMIT 30;
+
+SELECT * FROM t1 WHERE f1 = (SELECT f1 FROM t1 ORDER BY 1 LIMIT 1);
+
+--error ER_SUBQUERY_NO_1_ROW
+SELECT * FROM t1 WHERE f1 = (SELECT f1 FROM t1 ORDER BY 1 LIMIT 2);
+
+DROP TABLE t1, tmp;
+DROP VIEW v1, v2;
+
+--echo # end of WL#1393 - Optimizing filesort with small limit
+
+--echo #
+--echo # Bug #58761
+--echo # Crash in Field::is_null in field.h on subquery in WHERE clause
+--echo #
+
+CREATE TABLE t1 (
+ pk INT NOT NULL AUTO_INCREMENT,
+ col_int_key INT DEFAULT NULL,
+ col_varchar_key VARCHAR(1) DEFAULT NULL,
+ PRIMARY KEY (pk),
+ KEY col_varchar_key (col_varchar_key,col_int_key)
+);
+
+INSERT INTO t1 VALUES (27,7,'x');
+INSERT INTO t1 VALUES (28,6,'m');
+INSERT INTO t1 VALUES (29,4,'c');
+
+CREATE TABLE where_subselect
+ SELECT DISTINCT `pk` AS field1 , `pk` AS field2
+ FROM t1 AS alias1
+ WHERE alias1 . `col_int_key` > 229
+ OR alias1 . `col_varchar_key` IS NOT NULL
+ GROUP BY field1, field2
+;
+
+SELECT *
+FROM where_subselect
+WHERE (field1, field2) IN (
+ SELECT DISTINCT `pk` AS field1 , `pk` AS field2
+ FROM t1 AS alias1
+ WHERE alias1 . `col_int_key` > 229
+ OR alias1 . `col_varchar_key` IS NOT NULL
+ GROUP BY field1, field2
+);
+
+DROP TABLE t1;
+DROP TABLE where_subselect;
+
+--echo # End of Bug #58761
+
+##
# Bug#35844: Covering index for ref access not compatible with ORDER BY list
#
@@ -1796,4 +1995,14 @@ DROP TABLE t1,t2,t3;
--echo End of 5.5 tests
-
+--echo #
+--echo # MDEV-5884: EXPLAIN UPDATE ... ORDER BY LIMIT shows wrong #rows
+--echo #
+create table t2(a int);
+insert into t2 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
+create table t1 (key1 int, col1 int, key(key1));
+insert into t1
+select A.a + 10 * B.a + 100 * C.a, 1234 from t2 A, t2 B, t2 C;
+--echo # Should show rows=2, not rows=100
+explain update t1 set key1=key1+1 where key1 between 10 and 110 order by key1 limit 2;
+drop table t1,t2;
diff --git a/mysql-test/t/order_by_sortkey.test b/mysql-test/t/order_by_sortkey.test
new file mode 100644
index 00000000000..43de028496e
--- /dev/null
+++ b/mysql-test/t/order_by_sortkey.test
@@ -0,0 +1,64 @@
+#
+# WL#1393 - ORDER BY with LIMIT tests
+#
+# A big test in a separate file, so that we can run the original
+# order_by test with --debug without timeout.
+#
+# All the sort keys fit in memory, but the addon fields do not.
+#
+CREATE TABLE t1(
+ f0 int auto_increment PRIMARY KEY,
+ f1 int,
+ f2 varchar(200)
+);
+
+INSERT INTO t1(f1, f2) VALUES
+(0,"0"),(1,"1"),(2,"2"),(3,"3"),(4,"4"),(5,"5"),
+(6,"6"),(7,"7"),(8,"8"),(9,"9"),(10,"10"),
+(11,"11"),(12,"12"),(13,"13"),(14,"14"),(15,"15"),
+(16,"16"),(17,"17"),(18,"18"),(19,"19"),(20,"20"),
+(21,"21"),(22,"22"),(23,"23"),(24,"24"),(25,"25"),
+(26,"26"),(27,"27"),(28,"28"),(29,"29"),(30,"30"),
+(31,"31"),(32,"32"),(33,"33"),(34,"34"),(35,"35"),
+(36,"36"),(37,"37"),(38,"38"),(39,"39"),(40,"40"),
+(41,"41"),(42,"42"),(43,"43"),(44,"44"),(45,"45"),
+(46,"46"),(47,"47"),(48,"48"),(49,"49"),(50,"50"),
+(51,"51"),(52,"52"),(53,"53"),(54,"54"),(55,"55"),
+(56,"56"),(57,"57"),(58,"58"),(59,"59"),(60,"60"),
+(61,"61"),(62,"62"),(63,"63"),(64,"64"),(65,"65"),
+(66,"66"),(67,"67"),(68,"68"),(69,"69"),(70,"70"),
+(71,"71"),(72,"72"),(73,"73"),(74,"74"),(75,"75"),
+(76,"76"),(77,"77"),(78,"78"),(79,"79"),(80,"80"),
+(81,"81"),(82,"82"),(83,"83"),(84,"84"),(85,"85"),
+(86,"86"),(87,"87"),(88,"88"),(89,"89"),(90,"90"),
+(91,"91"),(92,"92"),(93,"93"),(94,"94"),(95,"95"),
+(96,"96"),(97,"97"),(98,"98"),(99,"99");
+
+CREATE TEMPORARY TABLE tmp (f1 int, f2 varchar(20));
+INSERT INTO tmp SELECT f1,f2 FROM t1;
+INSERT INTO t1(f1,f2) SELECT * FROM tmp;
+INSERT INTO tmp SELECT f1,f2 FROM t1;
+INSERT INTO t1(f1,f2) SELECT * FROM tmp;
+INSERT INTO t1(f1,f2) SELECT * FROM tmp;
+INSERT INTO tmp SELECT f1,f2 FROM t1;
+INSERT INTO t1(f1,f2) SELECT * FROM tmp;
+INSERT INTO tmp SELECT f1,f2 FROM t1;
+INSERT INTO t1(f1,f2) SELECT * FROM tmp;
+INSERT INTO tmp SELECT f1,f2 FROM t1;
+INSERT INTO t1(f1,f2) SELECT * FROM tmp;
+INSERT INTO tmp SELECT f1,f2 FROM t1;
+INSERT INTO t1(f1,f2) SELECT * FROM tmp;
+INSERT INTO tmp SELECT f1,f2 FROM t1;
+INSERT INTO t1(f1,f2) SELECT * FROM tmp;
+
+# Test when only sortkeys fits to memory
+set sort_buffer_size= 32768;
+
+FLUSH STATUS;
+SHOW SESSION STATUS LIKE 'Sort%';
+
+SELECT * FROM t1 ORDER BY f2 LIMIT 100;
+
+SHOW SESSION STATUS LIKE 'Sort%';
+
+DROP TABLE t1, tmp;
diff --git a/mysql-test/t/order_by_zerolength-4285.test b/mysql-test/t/order_by_zerolength-4285.test
new file mode 100644
index 00000000000..2fb58edd36d
--- /dev/null
+++ b/mysql-test/t/order_by_zerolength-4285.test
@@ -0,0 +1,8 @@
+#
+# MDEV-4285 Server crashes in ptr_compare on NOW and CAST in ORDER BY
+#
+create table t1 (pk int primary key);
+insert into t1 values (1),(2),(3),(4),(5),(6),(7),(8),(9),(10);
+select * from t1 order by now(), cast(pk as char(0));
+drop table t1;
+
diff --git a/mysql-test/t/parser.test b/mysql-test/t/parser.test
index 06ec3164ad1..6a69f666a81 100644
--- a/mysql-test/t/parser.test
+++ b/mysql-test/t/parser.test
@@ -553,7 +553,7 @@ select master_pos_wait();
-- error ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT
select master_pos_wait(1);
-- error ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT
-select master_pos_wait(1, 2, 3, 4);
+select master_pos_wait(1, 2, 3, 4, 5);
-- error ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT
select rand(1, 2, 3);
diff --git a/mysql-test/t/parser_not_embedded.test b/mysql-test/t/parser_not_embedded.test
index 22e9ae5a140..3ebd23e888e 100644
--- a/mysql-test/t/parser_not_embedded.test
+++ b/mysql-test/t/parser_not_embedded.test
@@ -8,15 +8,15 @@
--write_file $MYSQLTEST_VARDIR/tmp/bug39559.sql
select 2 as expected, /*!01000/**/*/ 2 as result;
-select 1 as expected, /*!99998/**/*/ 1 as result;
+select 1 as expected, /*!999998/**/*/ 1 as result;
select 3 as expected, /*!01000 1 + */ 2 as result;
-select 2 as expected, /*!99990 1 + */ 2 as result;
+select 2 as expected, /*!999990 1 + */ 2 as result;
select 7 as expected, /*!01000 1 + /* 8 + */ 2 + */ 4 as result;
-select 8 as expected, /*!99998 1 + /* 2 + */ 4 + */ 8 as result;
+select 8 as expected, /*!999998 1 + /* 2 + */ 4 + */ 8 as result;
select 7 as expected, /*!01000 1 + /*!01000 8 + */ 2 + */ 4 as result;
-select 7 as expected, /*!01000 1 + /*!99998 8 + */ 2 + */ 4 as result;
-select 4 as expected, /*!99998 1 + /*!99998 8 + */ 2 + */ 4 as result;
-select 4 as expected, /*!99998 1 + /*!01000 8 + */ 2 + */ 4 as result;
+select 7 as expected, /*!01000 1 + /*!999998 8 + */ 2 + */ 4 as result;
+select 4 as expected, /*!999998 1 + /*!999998 8 + */ 2 + */ 4 as result;
+select 4 as expected, /*!999998 1 + /*!01000 8 + */ 2 + */ 4 as result;
select 7 as expected, /*!01000 1 + /*!01000 8 + /*!01000 error */ 16 + */ 2 + */ 4 as result;
select 4 as expected, /* 1 + /*!01000 8 + */ 2 + */ 4;
EOF
diff --git a/mysql-test/t/partition.test b/mysql-test/t/partition.test
index 206f9042efb..1c8cd0375d6 100644
--- a/mysql-test/t/partition.test
+++ b/mysql-test/t/partition.test
@@ -89,6 +89,16 @@ AND A.c = 343;
DROP TABLE t1;
--echo #
+--echo # Bug#59503: explain extended crash in get_mm_leaf
+--echo #
+CREATE TABLE t1 (a VARCHAR(51) CHARACTER SET latin1)
+ENGINE=MyISAM
+PARTITION BY KEY (a) PARTITIONS 1;
+INSERT INTO t1 VALUES ('a'),('b'),('c');
+EXPLAIN EXTENDED SELECT 1 FROM t1 WHERE a > 1;
+DROP TABLE t1;
+
+--echo #
--echo # Bug#57778: failed primary key add to partitioned innodb table
--echo # inconsistent and crashes
--echo #
@@ -303,6 +313,31 @@ DROP TABLE t1;
#
# Bug#35765: ALTER TABLE produces wrong error when non-existent storage engine
# used
+SET sql_mode=no_engine_substitution;
+--error ER_UNKNOWN_STORAGE_ENGINE
+CREATE TABLE t1 (a INT)
+ENGINE=NonExistentEngine;
+--error ER_UNKNOWN_STORAGE_ENGINE
+CREATE TABLE t1 (a INT)
+ENGINE=NonExistentEngine
+PARTITION BY HASH (a);
+CREATE TABLE t1 (a INT)
+ENGINE=Memory;
+--error ER_UNKNOWN_STORAGE_ENGINE
+ALTER TABLE t1 ENGINE=NonExistentEngine;
+# OK to only specify one partitions engine, since it is already assigned at
+# table level (after create, it is specified on all levels and all parts).
+--error ER_UNKNOWN_STORAGE_ENGINE
+ALTER TABLE t1
+PARTITION BY HASH (a)
+(PARTITION p0 ENGINE=Memory,
+ PARTITION p1 ENGINE=NonExistentEngine);
+--error ER_UNKNOWN_STORAGE_ENGINE
+ALTER TABLE t1 ENGINE=NonExistentEngine;
+SHOW CREATE TABLE t1;
+DROP TABLE t1;
+
+SET sql_mode='';
CREATE TABLE t1 (a INT)
ENGINE=NonExistentEngine;
DROP TABLE t1;
@@ -322,6 +357,7 @@ PARTITION BY HASH (a)
ALTER TABLE t1 ENGINE=NonExistentEngine;
SHOW CREATE TABLE t1;
DROP TABLE t1;
+SET sql_mode=DEFAULT;
#
# Bug#40494: Crash MYSQL server crashes on range access with partitioning
@@ -990,13 +1026,13 @@ drop table t1;
#
# Bug #16775: Wrong engine type stored for subpartition
#
-set session storage_engine= 'memory';
+set session default_storage_engine= 'memory';
create table t1 (f_int1 int(11) default null) engine = memory
partition by range (f_int1) subpartition by hash (f_int1)
(partition part1 values less than (1000)
(subpartition subpart11 engine = memory));
drop table t1;
-set session storage_engine='myisam';
+set session default_storage_engine='myisam';
#
# Bug #16782: Crash using REPLACE on table with primary key
@@ -1840,8 +1876,7 @@ WHERE t1.id IN (
SELECT distinct id
FROM t4
WHERE taken BETWEEN @f_date AND date_add(@t_date, INTERVAL 1 DAY))
-ORDER BY t1.id
-;
+ORDER BY t1.id;
drop table t1, t2, t4;
@@ -2822,3 +2857,43 @@ INSERT INTO t1 (CustomerID, City, Country) VALUES
SELECT * FROM t1 WHERE Country = 'USA';
DROP TABLE t1;
+#
+# Test ALTER TABLE ADD/DROP PARTITION IF EXISTS
+#
+
+CREATE TABLE t1 ( d DATE NOT NULL)
+PARTITION BY RANGE( YEAR(d) ) (
+ PARTITION p0 VALUES LESS THAN (1960),
+ PARTITION p1 VALUES LESS THAN (1970),
+ PARTITION p2 VALUES LESS THAN (1980),
+ PARTITION p3 VALUES LESS THAN (1990)
+);
+
+ALTER TABLE t1 ADD PARTITION IF NOT EXISTS(
+PARTITION `p5` VALUES LESS THAN (2010)
+COMMENT 'APSTART \' APEND'
+);
+
+ALTER TABLE t1 ADD PARTITION IF NOT EXISTS(
+PARTITION `p5` VALUES LESS THAN (2010)
+COMMENT 'APSTART \' APEND'
+);
+
+alter table t1 drop partition if exists p5;
+alter table t1 drop partition if exists p5;
+
+DROP TABLE t1;
+
+#
+# MDEV-14696 Server crashes in in prep_alter_part_table on 2nd execution of PS.
+#
+
+CREATE TABLE t1 (a INT) ENGINE=MyISAM PARTITION BY RANGE(a) (PARTITION p1 VALUES LESS THAN (0));
+ALTER TABLE t1 ADD PARTITION (PARTITION p2 VALUES LESS THAN (1));
+PREPARE stmt FROM 'ALTER TABLE t1 ADD PARTITION IF NOT EXISTS (PARTITION p2 VALUES LESS THAN (2))';
+EXECUTE stmt;
+EXECUTE stmt;
+
+DEALLOCATE PREPARE stmt;
+DROP TABLE t1;
+
diff --git a/mysql-test/t/partition_alter.test b/mysql-test/t/partition_alter.test
new file mode 100644
index 00000000000..592d8fdaeaa
--- /dev/null
+++ b/mysql-test/t/partition_alter.test
@@ -0,0 +1,66 @@
+--source include/have_partition.inc
+
+CREATE TABLE `test_data` (
+ `hid` bigint(20) unsigned NOT NULL,
+ `itid` bigint(20) unsigned NOT NULL,
+ `clocktime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
+ `values` double(16,4) NOT NULL,
+ PRIMARY KEY (`hid`,`itid`,`clocktime`)
+ ) ;
+
+INSERT INTO `test_data` (`hid`, `itid`, `clocktime`, `values`) VALUES
+ (1, 1, '2015-03-10 06:25:16', 0.0000),
+ (1, 1, '2015-03-10 06:26:24', 0.0000),
+ (1, 1, '2015-03-10 06:27:32', 0.0000),
+ (1, 1, '2015-03-10 06:28:40', 0.0000),
+ (1, 1, '2015-03-10 06:29:49', 0.0000),
+ (1, 1, '2015-03-10 06:30:57', 0.0000),
+ (1, 1, '2015-03-10 06:32:05', 0.0000),
+ (1, 1, '2015-03-10 06:33:14', 0.0000),
+ (1, 1, '2015-03-10 06:34:22', 0.0000),
+ (1, 1, '2015-03-10 06:35:30', 0.0000),
+ (1, 1, '2015-03-10 06:36:39', 0.0000),
+ (1, 1, '2015-03-10 06:37:47', 0.0000),
+ (1, 1, '2015-03-10 06:38:55', 0.0000),
+ (1, 1, '2015-03-10 06:40:03', 0.0000),
+ (1, 1, '2015-03-10 06:41:09', 0.0000),
+ (1, 1, '2015-03-10 06:42:21', 0.0000),
+ (1, 1, '2015-03-10 06:43:29', 0.0000),
+ (1, 1, '2015-03-10 06:44:37', 0.0000),
+ (1, 1, '2015-03-10 06:45:46', 0.0000),
+ (1, 1, '2015-03-10 06:47:05', 0.0000),
+ (1, 1, '2015-03-10 06:48:21', 0.0000),
+ (1, 1, '2015-03-10 06:49:41', 0.0000),
+ (1, 1, '2015-03-10 06:50:58', 0.0000),
+ (1, 1, '2015-03-10 06:52:08', 0.0000),
+ (1, 1, '2015-03-10 06:53:17', 0.0000),
+ (1, 1, '2015-03-10 06:54:25', 0.0000),
+ (563, 1, '2015-03-17 14:28:28', 0.3125),
+ (563, 1, '2015-03-17 14:29:39', 0.2775),
+ (563, 1, '2015-03-17 14:30:49', 0.2675);
+
+
+CREATE PROCEDURE `create_part_max`()
+ alter table `test_data`
+ partition by range(unix_timestamp(clocktime)) (
+ partition partMAX values less than MAXVALUE
+ );
+
+call create_part_max();
+
+call create_part_max();
+
+drop procedure create_part_max;
+
+prepare stmt from "alter table `test_data`
+ partition by range(unix_timestamp(clocktime)) (
+ partition partMAX values less than MAXVALUE
+ )";
+
+execute stmt;
+execute stmt;
+
+deallocate prepare stmt;
+
+drop table test_data;
+
diff --git a/mysql-test/t/partition_binlog.test b/mysql-test/t/partition_binlog.test
index 9869be75759..d6986c86ebe 100644
--- a/mysql-test/t/partition_binlog.test
+++ b/mysql-test/t/partition_binlog.test
@@ -20,7 +20,7 @@ INSERT INTO t1 VALUES (1), (10), (100), (1000);
--let $binlog_file=query_get_value(SHOW MASTER STATUS, File, 1)
--let $binlog_start=query_get_value(SHOW MASTER STATUS, Position, 1)
---error ER_WRONG_PARTITION_NAME
+--error ER_UNKNOWN_PARTITION
ALTER TABLE t1 TRUNCATE PARTITION p1;
--error ER_DROP_PARTITION_NON_EXISTENT
ALTER TABLE t1 DROP PARTITION p1;
diff --git a/mysql-test/t/partition_debug_sync.test b/mysql-test/t/partition_debug_sync.test
index 027a4bd19a7..90f1d4173ff 100644
--- a/mysql-test/t/partition_debug_sync.test
+++ b/mysql-test/t/partition_debug_sync.test
@@ -5,6 +5,8 @@
#
--source include/have_partition.inc
--source include/have_debug_sync.inc
+--source include/have_debug.inc
+--source include/have_innodb.inc
--disable_warnings
DROP TABLE IF EXISTS t1, t2;
@@ -16,7 +18,9 @@ SET DEBUG_SYNC= 'RESET';
--echo # Test when remove partitioning is done while drop table is waiting
--echo # for the table.
--echo # After MDL was introduced, there is no longer any race, so test is done
---echo # by adding a small sleep to verify that the delete waits.
+--echo # by adding a small sleep to verify that the delete waits. This happens
+--echo # only until ALTER tries to upgrade its MDL lock, which ends up in MDL
+--echo # deadlock which is correctly reported.
connect(con1, localhost, root,,);
--echo # Con 1
SET DEBUG_SYNC= 'RESET';
@@ -30,20 +34,19 @@ ENGINE = MYISAM
PARTITION p1 VALUES LESS THAN (20),
PARTITION p2 VALUES LESS THAN (100),
PARTITION p3 VALUES LESS THAN MAXVALUE ) */;
-SET SESSION debug_dbug= "+d,sleep_before_create_table_no_lock";
SET DEBUG_SYNC= 'alter_table_before_create_table_no_lock SIGNAL removing_partitioning WAIT_FOR waiting_for_alter';
-SET DEBUG_SYNC= 'alter_table_before_main_binlog SIGNAL partitioning_removed';
+SET DEBUG_SYNC= 'mdl_acquire_lock_wait SIGNAL waiting_for_upgrade';
--send ALTER TABLE t1 REMOVE PARTITIONING
connection default;
--echo # Con default
SET DEBUG_SYNC= 'now WAIT_FOR removing_partitioning';
SET DEBUG_SYNC= 'mdl_acquire_lock_wait SIGNAL waiting_for_alter';
-SET DEBUG_SYNC= 'rm_table_no_locks_before_delete_table WAIT_FOR partitioning_removed';
+SET DEBUG_SYNC= 'rm_table_no_locks_before_delete_table WAIT_FOR waiting_for_upgrade';
DROP TABLE IF EXISTS t1;
--echo # Con 1
connection con1;
+--error ER_LOCK_DEADLOCK
--reap
-SET SESSION debug_dbug= "-d,sleep_before_create_table_no_lock";
connection default;
SET DEBUG_SYNC= 'RESET';
connection con1;
@@ -60,30 +63,74 @@ CREATE TABLE t2
b INTEGER NOT NULL,
KEY (b))
ENGINE = MYISAM
-/*!50100 PARTITION BY RANGE (a)
-(PARTITION p0 VALUES LESS THAN (2),
- PARTITION p1 VALUES LESS THAN (20),
- PARTITION p2 VALUES LESS THAN (100),
- PARTITION p3 VALUES LESS THAN MAXVALUE ) */;
+PARTITION BY RANGE (a) (PARTITION p0 VALUES LESS THAN (2),
+ PARTITION p1 VALUES LESS THAN (20),
+ PARTITION p2 VALUES LESS THAN (100),
+ PARTITION p3 VALUES LESS THAN MAXVALUE);
SET DEBUG_SYNC= 'alter_table_before_open_tables SIGNAL removing_partitions WAIT_FOR waiting_for_alter';
SET DEBUG_SYNC= 'alter_table_before_rename_result_table WAIT_FOR delete_done';
--send ALTER TABLE t2 REMOVE PARTITIONING
connection default;
--echo # Con default
-SET SESSION debug_dbug= "+d,sleep_before_no_locks_delete_table";
SET DEBUG_SYNC= 'now WAIT_FOR removing_partitions';
SET DEBUG_SYNC= 'rm_table_no_locks_before_delete_table SIGNAL waiting_for_alter';
SET DEBUG_SYNC= 'rm_table_no_locks_before_binlog SIGNAL delete_done';
DROP TABLE IF EXISTS t2;
-SET SESSION debug_dbug= "-d,sleep_before_no_locks_delete_table";
--echo # Con 1
connection con1;
--error ER_NO_SUCH_TABLE
--reap
SET DEBUG_SYNC= 'RESET';
disconnect con1;
+--source include/wait_until_disconnected.inc
connection default;
--echo # Con default
SET DEBUG_SYNC= 'RESET';
--echo End of 5.1 tests
+
+--echo #
+--echo # Coverage test for non pruned ha_partition::store_lock()
+--echo #
+CREATE TABLE t1 (a int) ENGINE = InnoDB;
+CREATE TABLE t2 (a int PRIMARY KEY)
+ENGINE = InnoDB PARTITION BY HASH (a) PARTITIONS 3;
+
+HANDLER t1 OPEN;
+
+--echo # Con1
+connect (con1, localhost, root,,);
+
+LOCK TABLES t1 WRITE, t2 READ;
+
+--echo # Default
+connection default;
+
+SET DEBUG_SYNC="wait_for_lock SIGNAL locking";
+send INSERT INTO t2 VALUES (1), (2), (3);
+
+--echo # Con1
+connection con1;
+SET DEBUG_SYNC="now WAIT_FOR locking";
+
+send ALTER TABLE t1 ADD COLUMN b int;
+
+--echo # Default
+connection default;
+--error ER_LOCK_ABORTED
+--reap
+
+SELECT 1;
+
+--echo # Con1
+connection con1;
+--reap
+
+UNLOCK TABLES;
+--disconnect con1
+
+--echo # Default
+connection default;
+SET DEBUG_SYNC = 'RESET';
+
+DROP TABLE t1, t2;
diff --git a/mysql-test/t/partition_disabled.test b/mysql-test/t/partition_disabled.test
index 320d6238502..940aea105ce 100644
--- a/mysql-test/t/partition_disabled.test
+++ b/mysql-test/t/partition_disabled.test
@@ -2,10 +2,10 @@
# Run this test only when mysqld has partitioning, but it is disabled.
# The statements are not expected to work, just check that we
# can't crash the server.
---require r/disabled_partition.require
---disable_query_log
-show variables like "have_partitioning";
---enable_query_log
+if (`SELECT COUNT(*) = 0 FROM INFORMATION_SCHEMA.PLUGINS WHERE PLUGIN_NAME = 'partition' AND PLUGIN_STATUS='DISABLED'`)
+{
+ --skip Test requires disabled partitioning
+}
--disable_warnings
DROP TABLE IF EXISTS t1;
--enable_warnings
@@ -29,7 +29,9 @@ ALTER TABLE t1 ANALYZE PARTITION ALL;
ALTER TABLE t1 REBUILD PARTITION ALL;
ALTER TABLE t1 ENGINE Memory;
ALTER TABLE t1 ADD (new INT);
+--disable_warnings
DROP TABLE t1;
+--enable_warnings
--error ER_OPTION_PREVENTS_STATEMENT
CREATE TABLE t1 (
@@ -83,3 +85,20 @@ create table t1 (a varchar(10) charset latin1 collate latin1_bin);
insert into t1 values (''),(' '),('a'),('a '),('a ');
explain partitions select * from t1 where a='a ' OR a='a';
drop table t1;
+
+--echo #
+--echo # bug#11760213-52599: ALTER TABLE REMOVE PARTITIONING ON NON-PARTITIONED
+--echo # TABLE CORRUPTS MYISAM
+--disable_warnings
+DROP TABLE if exists `t1`;
+--enable_warnings
+CREATE TABLE `t1`(`a` INT)ENGINE=myisam;
+ALTER TABLE `t1` ADD COLUMN `b` INT;
+CREATE UNIQUE INDEX `i1` ON `t1`(`b`);
+CREATE UNIQUE INDEX `i2` ON `t1`(`a`);
+ALTER TABLE `t1` ADD PRIMARY KEY (`a`);
+--error ER_PARTITION_MGMT_ON_NONPARTITIONED
+ALTER TABLE `t1` REMOVE PARTITIONING;
+CHECK TABLE `t1` EXTENDED;
+DROP TABLE t1;
+
diff --git a/mysql-test/t/partition_error.test b/mysql-test/t/partition_error.test
index 6b6e54b1052..858213b1e30 100644
--- a/mysql-test/t/partition_error.test
+++ b/mysql-test/t/partition_error.test
@@ -11,6 +11,17 @@ drop table if exists t1, t2;
let $MYSQLD_DATADIR= `SELECT @@datadir`;
--echo #
+--echo # Bug#60039: crash when exchanging a partition on
+--echo # nonpartitioned table with a view
+--echo #
+CREATE TABLE t1 (a int);
+CREATE OR REPLACE VIEW v1 AS SELECT * FROM t1;
+--error ER_CHECK_NO_SUCH_TABLE
+ALTER TABLE t1 EXCHANGE PARTITION p0 WITH TABLE v1;
+DROP VIEW v1;
+DROP TABLE t1;
+
+--echo #
--echo # Bug#13608188 - 64038: CRASH IN HANDLER::HA_THD ON ALTER TABLE AFTER
--echo # REPAIR NON-EXISTING PARTITION
--echo #
@@ -2016,3 +2027,49 @@ create table t1 (a int) partition by list (values(a) div 1) (partition p0 values
create table t1 (a int) partition by list (uuid_short()) (partition p0 values in (0), partition p1 values in (1));
--echo End of 5.5 tests
+
+CREATE TABLE t1 (a INT)
+PARTITION BY LIST (a)
+SUBPARTITION BY HASH (a) SUBPARTITIONS 2
+(PARTITION p1 VALUES IN (1) COMMENT "Comment in p1"
+ (SUBPARTITION p1spFirst COMMENT "SubPartition comment in p1spFirst",
+ SUBPARTITION p1spSecond COMMENT "SubPartition comment in p1spSecond"),
+ PARTITION p2 VALUES IN (2) COMMENT "Comment in p2"
+ (SUBPARTITION p2spFirst COMMENT "SubPartition comment in p2spFirst",
+ SUBPARTITION p2spSecond COMMENT "SubPartition comment in p2spSecond"));
+SHOW CREATE TABLE t1;
+SELECT PARTITION_NAME, SUBPARTITION_NAME, PARTITION_COMMENT FROM INFORMATION_SCHEMA.PARTITIONS
+WHERE TABLE_NAME = 't1' AND TABLE_SCHEMA = 'test';
+DROP TABLE t1;
+
+CREATE TABLE t1 (a INT)
+PARTITION BY LIST (a)
+SUBPARTITION BY HASH (a) SUBPARTITIONS 2
+(PARTITION p1 VALUES IN (1)
+ (SUBPARTITION p1spFirst COMMENT "SubPartition comment in p1spFirst",
+ SUBPARTITION p1spSecond),
+ PARTITION p2 VALUES IN (2) COMMENT "Comment in p2"
+ (SUBPARTITION p2spFirst,
+ SUBPARTITION p2spSecond COMMENT "SubPartition comment in p2spSecond"));
+SHOW CREATE TABLE t1;
+SELECT PARTITION_NAME, SUBPARTITION_NAME, PARTITION_COMMENT FROM INFORMATION_SCHEMA.PARTITIONS
+WHERE TABLE_NAME = 't1' AND TABLE_SCHEMA = 'test';
+DROP TABLE t1;
+
+CREATE TABLE t1
+(a INT ,
+ KEY inx_a (a) )
+PARTITION BY RANGE (a)
+SUBPARTITION BY HASH (a) SUBPARTITIONS 2
+(PARTITION pUpTo10 VALUES LESS THAN (10) COMMENT
+"This is a long comment (2050 ascii characters) 50 pUpTo10 partition ......80-!.................. 100 ................................................................................................ 200....................................................................................................................................................................................................................................................................................................... 500 ............................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................... 1000 ..............1024-|.......................................................................................................................................................................................................................................................................................................................................................................................................................................................................................... 1500 .............................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................. 2000 ......................................2048-|++"
+ (SUBPARTITION `p-10sp0` ,SUBPARTITION `p-10sp1` ),
+ PARTITION pMax VALUES LESS THAN MAXVALUE COMMENT
+"This is a long comment (2050 ascii characters) 50 pMax partition comment .80-!.................. 100 ................................................................................................ 200....................................................................................................................................................................................................................................................................................................... 500 ............................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................... 1000 ..............1024-|.......................................................................................................................................................................................................................................................................................................................................................................................................................................................................................... 1500 .............................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................. 2000 ......................................2048-|++"
+ (SUBPARTITION `pMaxsp0` ,SUBPARTITION `pMaxsp1` ));
+
+SHOW CREATE TABLE t1;
+SELECT PARTITION_NAME, SUBPARTITION_NAME, PARTITION_COMMENT FROM INFORMATION_SCHEMA.PARTITIONS
+WHERE TABLE_NAME = 't1' AND TABLE_SCHEMA = 'test';
+
+DROP TABLE t1;
diff --git a/mysql-test/t/partition_exchange.test b/mysql-test/t/partition_exchange.test
new file mode 100644
index 00000000000..e538bee16cd
--- /dev/null
+++ b/mysql-test/t/partition_exchange.test
@@ -0,0 +1,517 @@
+--source include/have_innodb.inc
+--source include/have_partition.inc
+
+--disable_warnings
+DROP TABLE IF EXISTS t1, t2, t3, t, tp, tsp, tmp;
+--enable_warnings
+
+--echo #
+--echo # Bug#11894100: EXCHANGE PARTITION CAN'T BE EXECUTED IF
+--echo # ROW_FORMAT WAS SET EXPLICITLY
+--echo #
+
+--echo # Same definition (both have ROW_FORMAT set)
+CREATE TABLE t1 (
+ id int(11) NOT NULL AUTO_INCREMENT,
+ year year(2) DEFAULT NULL,
+ modified timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
+ PRIMARY KEY (id)
+) ENGINE=InnoDB ROW_FORMAT=COMPACT
+PARTITION BY HASH (id)
+PARTITIONS 2;
+
+CREATE TABLE t2 LIKE t1;
+ALTER TABLE t2 REMOVE PARTITIONING;
+
+--vertical_results
+SHOW CREATE TABLE t1;
+SHOW CREATE TABLE t2;
+
+SELECT TABLE_NAME, TABLE_TYPE, ENGINE, ROW_FORMAT, CREATE_OPTIONS
+FROM INFORMATION_SCHEMA.TABLES
+WHERE TABLE_SCHEMA = 'test' AND TABLE_NAME IN ('t1', 't2');
+
+ALTER TABLE t1 EXCHANGE PARTITION p1 WITH TABLE t2;
+SHOW CREATE TABLE t1;
+SHOW CREATE TABLE t2;
+SELECT TABLE_NAME, TABLE_TYPE, ENGINE, ROW_FORMAT, CREATE_OPTIONS
+FROM INFORMATION_SCHEMA.TABLES
+WHERE TABLE_SCHEMA = 'test' AND TABLE_NAME IN ('t1', 't2');
+
+DROP TABLE t2;
+
+--echo # Only the partitioned table have ROW_FORMAT set.
+CREATE TABLE t2 (
+ id int(11) NOT NULL AUTO_INCREMENT,
+ year year(2) DEFAULT NULL,
+ modified timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
+ PRIMARY KEY (id)
+) ENGINE=InnoDB;
+
+ALTER TABLE t1 EXCHANGE PARTITION p1 WITH TABLE t2;
+SHOW CREATE TABLE t1;
+SHOW CREATE TABLE t2;
+SELECT TABLE_NAME, TABLE_TYPE, ENGINE, ROW_FORMAT, CREATE_OPTIONS
+FROM INFORMATION_SCHEMA.TABLES
+WHERE TABLE_SCHEMA = 'test' AND TABLE_NAME IN ('t1', 't2');
+
+--echo # Only the non partitioned table have ROW_FORMAT set.
+DROP TABLE t1, t2;
+CREATE TABLE t1 (
+ id int(11) NOT NULL AUTO_INCREMENT,
+ year year(2) DEFAULT NULL,
+ modified timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
+ PRIMARY KEY (id)
+) ENGINE=InnoDB
+PARTITION BY HASH (id)
+PARTITIONS 2;
+CREATE TABLE t2 (
+ id int(11) NOT NULL AUTO_INCREMENT,
+ year year(2) DEFAULT NULL,
+ modified timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
+ PRIMARY KEY (id)
+) ENGINE=InnoDB ROW_FORMAT = COMPACT;
+
+ALTER TABLE t1 EXCHANGE PARTITION p1 WITH TABLE t2;
+SHOW CREATE TABLE t1;
+SHOW CREATE TABLE t2;
+SELECT TABLE_NAME, TABLE_TYPE, ENGINE, ROW_FORMAT, CREATE_OPTIONS
+FROM INFORMATION_SCHEMA.TABLES
+WHERE TABLE_SCHEMA = 'test' AND TABLE_NAME IN ('t1', 't2');
+
+--echo # No table have ROW_FORMAT set.
+DROP TABLE t1, t2;
+CREATE TABLE t1 (
+ id int(11) NOT NULL AUTO_INCREMENT,
+ year year(2) DEFAULT NULL,
+ modified timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
+ PRIMARY KEY (id)
+) ENGINE=InnoDB
+PARTITION BY HASH (id)
+PARTITIONS 2;
+CREATE TABLE t2 (
+ id int(11) NOT NULL AUTO_INCREMENT,
+ year year(2) DEFAULT NULL,
+ modified timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
+ PRIMARY KEY (id)
+) ENGINE=InnoDB;
+
+ALTER TABLE t1 EXCHANGE PARTITION p1 WITH TABLE t2;
+SHOW CREATE TABLE t1;
+SHOW CREATE TABLE t2;
+SELECT TABLE_NAME, TABLE_TYPE, ENGINE, ROW_FORMAT, CREATE_OPTIONS
+FROM INFORMATION_SCHEMA.TABLES
+WHERE TABLE_SCHEMA = 'test' AND TABLE_NAME IN ('t1', 't2');
+
+--echo # Not same ROW_FORMAT as default (but same).
+DROP TABLE t1, t2;
+CREATE TABLE t1 (
+ id int(11) NOT NULL AUTO_INCREMENT,
+ year year(2) DEFAULT NULL,
+ modified timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
+ PRIMARY KEY (id)
+) ENGINE=InnoDB ROW_FORMAT = REDUNDANT
+PARTITION BY HASH (id)
+PARTITIONS 2;
+CREATE TABLE t2 (
+ id int(11) NOT NULL AUTO_INCREMENT,
+ year year(2) DEFAULT NULL,
+ modified timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
+ PRIMARY KEY (id)
+) ENGINE=InnoDB ROW_FORMAT = REDUNDANT;
+
+ALTER TABLE t1 EXCHANGE PARTITION p1 WITH TABLE t2;
+SHOW CREATE TABLE t1;
+SHOW CREATE TABLE t2;
+SELECT TABLE_NAME, TABLE_TYPE, ENGINE, ROW_FORMAT, CREATE_OPTIONS
+FROM INFORMATION_SCHEMA.TABLES
+WHERE TABLE_SCHEMA = 'test' AND TABLE_NAME IN ('t1', 't2');
+
+--echo # Not same ROW_FORMAT as default (tables differs).
+DROP TABLE t1, t2;
+CREATE TABLE t1 (
+ id int(11) NOT NULL AUTO_INCREMENT,
+ year year(2) DEFAULT NULL,
+ modified timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
+ PRIMARY KEY (id)
+) ENGINE=InnoDB
+PARTITION BY HASH (id)
+PARTITIONS 2;
+CREATE TABLE t2 (
+ id int(11) NOT NULL AUTO_INCREMENT,
+ year year(2) DEFAULT NULL,
+ modified timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
+ PRIMARY KEY (id)
+) ENGINE=InnoDB ROW_FORMAT = REDUNDANT;
+
+--error ER_PARTITION_EXCHANGE_DIFFERENT_OPTION
+ALTER TABLE t1 EXCHANGE PARTITION p1 WITH TABLE t2;
+SHOW CREATE TABLE t1;
+SHOW CREATE TABLE t2;
+SELECT TABLE_NAME, TABLE_TYPE, ENGINE, ROW_FORMAT, CREATE_OPTIONS
+FROM INFORMATION_SCHEMA.TABLES
+WHERE TABLE_SCHEMA = 'test' AND TABLE_NAME IN ('t1', 't2');
+
+--echo # Different than default (forced ROW_TYPE)
+DROP TABLE t1, t2;
+CREATE TABLE t1 (
+ id int(11) NOT NULL AUTO_INCREMENT,
+ year year(2) DEFAULT NULL,
+ modified timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
+ PRIMARY KEY (id)
+) ENGINE=InnoDB ROW_FORMAT = COMPACT
+PARTITION BY HASH (id)
+PARTITIONS 2;
+CREATE TABLE t2 (
+ id int(11) NOT NULL AUTO_INCREMENT,
+ year year(2) DEFAULT NULL,
+ modified timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
+ PRIMARY KEY (id)
+) ENGINE=InnoDB ROW_FORMAT = REDUNDANT;
+
+--error ER_PARTITION_EXCHANGE_DIFFERENT_OPTION
+ALTER TABLE t1 EXCHANGE PARTITION p1 WITH TABLE t2;
+SHOW CREATE TABLE t1;
+SHOW CREATE TABLE t2;
+SELECT TABLE_NAME, TABLE_TYPE, ENGINE, ROW_FORMAT, CREATE_OPTIONS
+FROM INFORMATION_SCHEMA.TABLES
+WHERE TABLE_SCHEMA = 'test' AND TABLE_NAME IN ('t1', 't2');
+--horizontal_results
+DROP TABLE t1, t2;
+
+--echo #
+--echo # Bug#56484: !table || (!table->read_set ||
+--echo # bitmap_is_set(table->read_set, field_index))
+--echo #
+CREATE TABLE t1 (a INT NOT NULL,b TIME NOT NULL DEFAULT '00:00:00')
+ENGINE=MyISAM
+PARTITION BY HASH (a) PARTITIONS 2;
+
+CREATE TABLE t2 (a INT) ENGINE=MYISAM;
+--error ER_TABLES_DIFFERENT_METADATA
+ALTER TABLE t1 EXCHANGE PARTITION p1 WITH TABLE t2;
+DROP TABLE t1, t2;
+
+--echo #
+--echo # Bug#55784: Foreign key integrity broken by alter table
+--echo #
+CREATE TABLE t1 (s1 INT PRIMARY KEY) ENGINE=InnoDB;
+
+CREATE TABLE t2 (s1 INT, FOREIGN KEY (s1) REFERENCES t1 (s1)) ENGINE=InnoDB;
+
+INSERT INTO t1 VALUES (1),(2),(3);
+
+INSERT INTO t2 VALUES (1),(2),(3);
+
+CREATE TABLE t3 (s1 INT PRIMARY KEY)
+ ENGINE=InnoDB
+ PARTITION BY LIST (s1)
+ (PARTITION p1 VALUES IN (1,2,3));
+
+--error ER_PARTITION_EXCHANGE_FOREIGN_KEY
+ALTER TABLE t3 EXCHANGE PARTITION p1 WITH TABLE t1;
+
+DROP TABLE t2, t1, t3;
+
+--echo # Tests for WL#4445
+CREATE TABLE t (a INT,
+ b VARCHAR(55),
+ PRIMARY KEY (a))
+ENGINE = MyISAM;
+
+CREATE TABLE tp (a INT,
+ b VARCHAR(55),
+ PRIMARY KEY (a))
+ENGINE = MyISAM
+PARTITION BY RANGE (a)
+(PARTITION p0 VALUES LESS THAN (100),
+ PARTITION p1 VALUES LESS THAN MAXVALUE);
+
+CREATE TABLE tsp (a INT,
+ b VARCHAR(55),
+ PRIMARY KEY (a))
+ENGINE = MyISAM
+PARTITION BY RANGE (a)
+SUBPARTITION BY HASH(a)
+(PARTITION p0 VALUES LESS THAN (100)
+ (SUBPARTITION sp0,
+ SUBPARTITION sp1),
+ PARTITION p1 VALUES LESS THAN MAXVALUE
+ (SUBPARTITION sp2,
+ SUBPARTITION sp3));
+
+INSERT INTO t VALUES (1, "First value"), (3, "Three"), (5, "Five"), (99, "End of values");
+INSERT INTO tp VALUES (2, "First value"), (10, "Ten"), (50, "Fifty"), (200, "Two hundred, end of values"), (61, "Sixty one"), (62, "Sixty two"), (63, "Sixty three"), (64, "Sixty four"), (161, "161"), (162, "162"), (163, "163"), (164, "164");
+INSERT INTO tsp VALUES (2, "First value"), (10, "Ten"), (50, "Fifty"), (200, "Two hundred, end of values"), (61, "Sixty one"), (62, "Sixty two"), (63, "Sixty three"), (64, "Sixty four"), (161, "161"), (162, "162"), (163, "163"), (164, "164");
+SHOW CREATE TABLE t;
+SHOW CREATE TABLE tp;
+--sorted_result
+SELECT * FROM t;
+--sorted_result
+SELECT * FROM tp;
+ALTER TABLE tp EXCHANGE PARTITION p0 WITH TABLE t;
+SHOW CREATE TABLE t;
+SHOW CREATE TABLE tp;
+--sorted_result
+SELECT * FROM t;
+--sorted_result
+SELECT * FROM tp;
+ALTER TABLE tp EXCHANGE PARTITION p0 WITH TABLE t;
+--sorted_result
+SELECT * FROM t;
+--sorted_result
+SELECT * FROM tp;
+--error ER_ROW_DOES_NOT_MATCH_PARTITION
+ALTER TABLE tp EXCHANGE PARTITION p1 WITH TABLE t;
+SHOW CREATE TABLE t;
+SHOW CREATE TABLE tp;
+--sorted_result
+SELECT * FROM t;
+--sorted_result
+SELECT * FROM tp;
+--echo # Test list of partitions
+--error ER_PARSE_ERROR
+ALTER TABLE tp EXCHANGE PARTITION p1 WITH TABLE t IGNORE;
+--error ER_PARSE_ERROR
+ALTER TABLE tp EXCHANGE PARTITION p0,p1 WITH TABLE t IGNORE;
+--error ER_PARSE_ERROR
+ALTER TABLE tp EXCHANGE PARTITION p0,p1 WITH TABLE t;
+--error ER_PARSE_ERROR
+ALTER TABLE tp EXCHANGE PARTITION (p0,p1) WITH TABLE t;
+--error ER_PARSE_ERROR
+ALTER TABLE tp EXCHANGE PARTITION p0 WITH TABLE (t,t2);
+--error ER_PARSE_ERROR
+ALTER TABLE tp EXCHANGE PARTITION p0 WITH TABLE t,t2;
+--error ER_UNKNOWN_PARTITION
+ALTER TABLE tp EXCHANGE PARTITION non_existent WITH TABLE t;
+--error ER_PARTITION_INSTEAD_OF_SUBPARTITION
+ALTER TABLE tsp EXCHANGE PARTITION p0 WITH TABLE t;
+--error ER_PARTITION_EXCHANGE_PART_TABLE
+ALTER TABLE tsp EXCHANGE PARTITION sp0 WITH TABLE tp;
+SHOW CREATE TABLE t;
+SHOW CREATE TABLE tp;
+SHOW CREATE TABLE tsp;
+--sorted_result
+SELECT * FROM t;
+--sorted_result
+SELECT * FROM tp;
+--echo # Test exchange partition
+ALTER TABLE tp EXCHANGE PARTITION p0 WITH TABLE t;
+SHOW CREATE TABLE t;
+SHOW CREATE TABLE tp;
+--sorted_result
+SELECT * FROM t;
+--sorted_result
+SELECT * FROM tp;
+ALTER TABLE tp EXCHANGE PARTITION p0 WITH TABLE t;
+SHOW CREATE TABLE t;
+SHOW CREATE TABLE tp;
+--sorted_result
+SELECT * FROM t;
+--sorted_result
+SELECT * FROM tp;
+--echo # Test exchange subpartition
+ALTER TABLE tsp EXCHANGE PARTITION sp1 WITH TABLE t;
+SHOW CREATE TABLE t;
+SHOW CREATE TABLE tsp;
+--sorted_result
+SELECT * FROM t;
+--sorted_result
+SELECT * FROM tsp;
+ALTER TABLE tsp EXCHANGE PARTITION sp1 WITH TABLE t;
+ALTER TABLE t ENGINE = InnoDB;
+ALTER TABLE tp ENGINE = InnoDB;
+SHOW CREATE TABLE t;
+SHOW CREATE TABLE tp;
+--sorted_result
+SELECT * FROM t;
+--sorted_result
+SELECT * FROM tp;
+ALTER TABLE tp EXCHANGE PARTITION p0 WITH TABLE t;
+SHOW CREATE TABLE t;
+SHOW CREATE TABLE tp;
+--sorted_result
+SELECT * FROM t;
+--sorted_result
+SELECT * FROM tp;
+ALTER TABLE tp EXCHANGE PARTITION p0 WITH TABLE t;
+--echo # test different engines
+ALTER TABLE t ENGINE = MyISAM;
+ALTER TABLE tp ENGINE = InnoDB;
+SHOW CREATE TABLE t;
+SHOW CREATE TABLE tp;
+--error ER_MIX_HANDLER_ERROR
+ALTER TABLE tp EXCHANGE PARTITION p0 WITH TABLE t;
+SHOW CREATE TABLE t;
+SHOW CREATE TABLE tp;
+--echo # Test different charsets
+ALTER TABLE t ENGINE = MyISAM;
+CREATE TABLE tmp LIKE t;
+INSERT INTO tmp SELECT * FROM t;
+RENAME TABLE t TO tmp2, tmp TO t;
+ALTER TABLE tp ENGINE = MyISAM;
+ALTER TABLE t CHARACTER SET = koi8r COLLATE koi8r_general_ci;
+--error ER_PARTITION_EXCHANGE_DIFFERENT_OPTION
+ALTER TABLE tp EXCHANGE PARTITION p0 WITH TABLE t;
+DROP TABLE t;
+--echo # Test multiple different table options
+CREATE TABLE t (a INT,
+ b VARCHAR(55),
+ PRIMARY KEY (a))
+ENGINE = MyISAM MAX_ROWS = 100000 MIN_ROWS = 1000;
+INSERT INTO t SELECT * FROM tmp2;
+SHOW CREATE TABLE t;
+SHOW CREATE TABLE tp;
+--error ER_PARTITION_EXCHANGE_DIFFERENT_OPTION
+ALTER TABLE tp EXCHANGE PARTITION p0 WITH TABLE t;
+SHOW WARNINGS;
+DROP TABLE t;
+RENAME TABLE tmp2 TO t;
+# test different keys
+ALTER TABLE t ADD KEY ba_key (b, a);
+ALTER TABLE tp ADD KEY ba_key (b, a);
+ALTER TABLE tsp ADD KEY ba_key (b, a);
+ALTER TABLE tp EXCHANGE PARTITION p0 WITH TABLE t;
+SHOW CREATE TABLE t;
+SHOW CREATE TABLE tp;
+--sorted_result
+SELECT * FROM t;
+--sorted_result
+SELECT * FROM tp;
+ALTER TABLE tp EXCHANGE PARTITION p0 WITH TABLE t;
+ALTER TABLE t DROP KEY ba_key;
+--error ER_TABLES_DIFFERENT_METADATA
+ALTER TABLE tp EXCHANGE PARTITION p0 WITH TABLE t;
+ALTER TABLE t ADD KEY b_key (b);
+--error ER_TABLES_DIFFERENT_METADATA
+ALTER TABLE tsp EXCHANGE PARTITION sp1 WITH TABLE t;
+ALTER TABLE t ADD KEY ba_key (b, a);
+ALTER TABLE t DROP KEY b_key;
+# test different index types
+# test different columns
+ALTER TABLE t CHANGE a c INT;
+--error ER_TABLES_DIFFERENT_METADATA
+ALTER TABLE tsp EXCHANGE PARTITION sp1 WITH TABLE t;
+ALTER TABLE t CHANGE c a INT;
+# test different data/index dir
+# test different options (row_format, max/min_rows, comments, tablespace,
+# pack_keys, delay_key_write, checksum etc.
+# test foreign keys
+--echo # test temporary table
+ALTER TABLE t ENGINE = MyISAM;
+ALTER TABLE tp ENGINE = MyISAM;
+CREATE TEMPORARY TABLE tmp LIKE t;
+INSERT INTO tmp SELECT * FROM t;
+ALTER TABLE t RENAME TO tmp2;
+ALTER TABLE tmp RENAME TO t;
+SHOW CREATE TABLE t;
+SHOW CREATE TABLE tp;
+--error ER_PARTITION_EXCHANGE_TEMP_TABLE
+ALTER TABLE tp EXCHANGE PARTITION p0 WITH TABLE t;
+SHOW CREATE TABLE t;
+SHOW CREATE TABLE tp;
+DROP TEMPORARY TABLE t;
+ALTER TABLE tmp2 RENAME TO t;
+--echo # Test non partitioned table
+ALTER TABLE tp REMOVE PARTITIONING;
+--error ER_PARTITION_MGMT_ON_NONPARTITIONED
+ALTER TABLE tp EXCHANGE PARTITION p0 WITH TABLE t;
+
+# TODO:
+# Verify that it is possible to read a table that is going to be exchanged
+# (but not write)
+# Verify that it is possible to both read and write to the partition that is
+# going to be exchanged
+# test mdl locking (i.e. together with transactions and other ddl)
+# Add test in lc_0-2 to make sure renameing operators is ok with different lc
+# Add test to exchange between databases, also check grants.
+# Add test for privileges
+# check if correct error whithout partitioning support
+DROP TABLE t, tp, tsp;
+
+
+--echo # Test with general_log
+use mysql;
+SET @old_general_log_state = @@global.general_log;
+SET GLOBAL general_log = 0;
+ALTER TABLE general_log ENGINE = MyISAM;
+CREATE TABLE t LIKE general_log;
+ALTER TABLE t PARTITION BY RANGE (UNIX_TIMESTAMP(event_time) DIV 1)
+(PARTITION p0 VALUES LESS THAN (123456789),
+ PARTITION pMAX VALUES LESS THAN MAXVALUE);
+--error ER_BAD_LOG_STATEMENT
+ALTER TABLE t EXCHANGE PARTITION p0 WITH TABLE general_log;
+ALTER TABLE general_log ENGINE = CSV;
+SET @@global.general_log = @old_general_log_state;
+DROP TABLE t;
+use test;
+
+--echo # Test with LOCK TABLE
+# Test with only one table locked at a time, both table locked + read, write
+
+CREATE TABLE tp
+(a VARCHAR(24),
+ b DATETIME,
+ PRIMARY KEY (a,b))
+PARTITION BY RANGE COLUMNS (a, b)
+(PARTITION p0 VALUES LESS THAN ("Middle", '0000-00-00'),
+ PARTITION p1 VALUES LESS THAN (MAXVALUE, '9999-12-31 23:59:59'));
+CREATE TABLE t LIKE tp;
+ALTER TABLE t REMOVE PARTITIONING;
+CREATE TABLE t2 LIKE t;
+INSERT INTO tp VALUES ("First in tp", '2000-01-02 03:04:25'), ("Zebra in tp", '0000-00-00 00:00:00'), ("Second in tp", '2010-01-01 05:12:24');
+INSERT INTO t VALUES ("First in t", '2000-01-02 03:04:25'), ("a test in t", '0000-00-00 00:00:00'), ("Echo in t", '2010-01-01 05:12:24');
+# 3 different kind of locks (none, READ, WRITE) for three different tables.
+# 3^3 = 18. The variant with no locks does not need testing -> 17
+let $count = 17;
+while ($count)
+{
+let $t_lock = `SELECT (CASE ($count % 3) WHEN 0 THEN 0 WHEN 1 THEN 'WRITE' WHEN 2 THEN 'READ' END)`;
+let $tp_lock = `SELECT (CASE ((($count + 2) DIV 3) % 3) WHEN 0 THEN 0 WHEN 1 THEN 'WRITE' WHEN 2 THEN 'READ' END)`;
+let $t2_lock = `SELECT (CASE ((($count + 8) DIV 9) % 3) WHEN 0 THEN 0 WHEN 1 THEN 'WRITE' WHEN 2 THEN 'READ' END)`;
+--echo # tp_lock '$tp_lock' t_lock '$t_lock' t2_lock '$t2_lock' count '$count'
+let $lock_cmd = LOCK TABLE;
+let $take_lock = 0;
+if ($t_lock)
+{
+ let $lock_cmd = $lock_cmd t $t_lock;
+ let $take_lock = 1;
+}
+if ($tp_lock)
+{
+ if ($take_lock)
+ {
+ let $lock_cmd = $lock_cmd, tp $tp_lock;
+ }
+ if (!$take_lock)
+ {
+ let $lock_cmd = $lock_cmd tp $tp_lock;
+ }
+ let $take_lock = 1;
+}
+if ($t2_lock)
+{
+ if ($take_lock)
+ {
+ let $lock_cmd = $lock_cmd, t2 $t2_lock;
+ }
+ if (!$take_lock)
+ {
+ let $lock_cmd = $lock_cmd t2 $t2_lock;
+ }
+ let $take_lock = 1;
+}
+if ($take_lock)
+{
+ eval $lock_cmd;
+}
+--error 0, ER_TABLE_NOT_LOCKED, ER_TABLE_NOT_LOCKED_FOR_WRITE
+ALTER TABLE tp EXCHANGE PARTITION p0 WITH TABLE t;
+SHOW WARNINGS;
+--error 0, ER_TABLE_NOT_LOCKED, ER_TABLE_NOT_LOCKED_FOR_WRITE
+ALTER TABLE tp EXCHANGE PARTITION p0 WITH TABLE t2;
+SHOW WARNINGS;
+UNLOCK TABLES;
+dec $count;
+}
+DROP TABLE t, t2, tp;
diff --git a/mysql-test/t/partition_explicit_prune.test b/mysql-test/t/partition_explicit_prune.test
new file mode 100644
index 00000000000..68b829fbcc3
--- /dev/null
+++ b/mysql-test/t/partition_explicit_prune.test
@@ -0,0 +1,860 @@
+--source include/have_innodb.inc
+--source include/have_partition.inc
+
+# Helper statement
+let $get_handler_status_counts= SELECT * FROM INFORMATION_SCHEMA.SESSION_STATUS
+WHERE VARIABLE_NAME LIKE 'HANDLER_%' AND VARIABLE_VALUE > 0;
+
+--echo #
+--echo # Bug#13559657: PARTITION SELECTION DOES NOT WORK WITH VIEWS
+--echo #
+CREATE TABLE t1 (a int)
+ENGINE = InnoDB
+PARTITION BY HASH (a) PARTITIONS 2;
+INSERT INTO t1 VALUES (0), (1), (2), (3);
+CREATE VIEW v1 AS SELECT a FROM t1 PARTITION (p0);
+SHOW CREATE VIEW v1;
+FLUSH STATUS;
+--sorted_result
+SELECT * FROM v1;
+eval $get_handler_status_counts;
+--echo # 4 locks (1 table, 1 partition lock/unlock)
+FLUSH STATUS;
+--sorted_result
+SELECT a FROM t1 PARTITION (p0);
+eval $get_handler_status_counts;
+--echo # 4 locks (1 table, 1 partition lock/unlock)
+FLUSH STATUS;
+INSERT INTO v1 VALUES (10);
+eval $get_handler_status_counts;
+--echo # 4 locks (1 table, 1 partition lock/unlock)
+FLUSH STATUS;
+# --error ER_ROW_DOES_NOT_MATCH_GIVEN_PARTITION_SET
+# INSERT INTO v1 VALUES (11);
+eval $get_handler_status_counts;
+--echo # 2 locks (1 table, all partitions pruned)
+FLUSH STATUS;
+--sorted_result
+SELECT * FROM v1;
+eval $get_handler_status_counts;
+--echo # 4 locks (1 table, 1 partition lock/unlock)
+FLUSH STATUS;
+--sorted_result
+SELECT a FROM t1 PARTITION (p0);
+eval $get_handler_status_counts;
+--echo # 4 locks (1 table, 1 partition lock/unlock)
+--sorted_result
+SELECT * FROM t1;
+DROP VIEW v1;
+CREATE VIEW v1 AS SELECT a FROM t1 PARTITION (p0) WITH CHECK OPTION;
+FLUSH STATUS;
+INSERT INTO v1 VALUES (20);
+eval $get_handler_status_counts;
+--echo # 4 locks (1 table, 1 partition lock/unlock)
+FLUSH STATUS;
+# --error ER_ROW_DOES_NOT_MATCH_GIVEN_PARTITION_SET
+# INSERT INTO v1 VALUES (21);
+eval $get_handler_status_counts;
+--echo # 2 locks (1 table, all partitions pruned)
+--sorted_result
+SELECT * FROM v1;
+--sorted_result
+SELECT * FROM t1;
+DROP VIEW v1;
+CREATE VIEW v1 AS
+SELECT a FROM t1 PARTITION (p0) WHERE a = 30 WITH CHECK OPTION;
+FLUSH STATUS;
+INSERT INTO v1 VALUES (30);
+eval $get_handler_status_counts;
+--echo # 4 locks (1 table, 1 partition lock/unlock)
+FLUSH STATUS;
+--error ER_VIEW_CHECK_FAILED
+INSERT INTO v1 VALUES (31);
+eval $get_handler_status_counts;
+--echo # 2 locks (1 table, all partitions pruned)
+FLUSH STATUS;
+--error ER_VIEW_CHECK_FAILED
+INSERT INTO v1 VALUES (32);
+eval $get_handler_status_counts;
+--echo # 4 locks (1 table, 1 partition lock/unlock)
+--sorted_result
+SELECT * FROM v1;
+--sorted_result
+SELECT * FROM t1;
+DROP VIEW v1;
+DROP TABLE t1;
+
+--echo # Original tests for WL#5217
+
+--echo # Must have InnoDB as engine to get the same statistics results.
+--echo # embedded uses MyISAM as default. CREATE SELECT uses the default engine.
+SET @old_default_storage_engine = @@default_storage_engine;
+SET @@default_storage_engine = 'InnoDB';
+
+--let $MYSQLD_DATADIR= `SELECT @@datadir`
+
+--echo # Test to show if I_S affects HANDLER_ counts
+FLUSH STATUS;
+eval $get_handler_status_counts;
+eval $get_handler_status_counts;
+--echo # OK, seems to add number of variables processed before HANDLER_WRITE
+--echo # and number of variables + 1 evaluated in the previous call in RND_NEXT
+
+CREATE TABLE t1
+(a INT NOT NULL,
+ b varchar (64),
+ INDEX (b,a),
+ PRIMARY KEY (a))
+ENGINE = InnoDB
+PARTITION BY RANGE (a)
+SUBPARTITION BY HASH (a) SUBPARTITIONS 2
+(PARTITION pNeg VALUES LESS THAN (0)
+ (SUBPARTITION subp0,
+ SUBPARTITION subp1),
+ PARTITION `p0-9` VALUES LESS THAN (10)
+ (SUBPARTITION subp2,
+ SUBPARTITION subp3),
+ PARTITION `p10-99` VALUES LESS THAN (100)
+ (SUBPARTITION subp4,
+ SUBPARTITION subp5),
+ PARTITION `p100-99999` VALUES LESS THAN (100000)
+ (SUBPARTITION subp6,
+ SUBPARTITION subp7));
+
+SHOW CREATE TABLE t1;
+--echo # First test that the syntax is OK
+--error ER_PARSE_ERROR
+SHOW CREATE TABLE t1 PARTITION (subp0);
+--echo # Not a correct partition list
+--error ER_PARSE_ERROR
+INSERT INTO t1 PARTITION () VALUES (1, "error");
+--error ER_UNKNOWN_PARTITION
+INSERT INTO t1 PARTITION (pNonExisting) VALUES (1, "error");
+--error ER_UNKNOWN_PARTITION
+INSERT INTO t1 PARTITION (pNeg, pNonExisting) VALUES (1, "error");
+--echo # Duplicate partitions and overlapping partitions and subpartitios is OK
+FLUSH STATUS;
+INSERT INTO t1 PARTITION (pNeg, pNeg) VALUES (-1, "pNeg(-subp1)");
+eval $get_handler_status_counts;
+--echo # Should be 1 commit
+--echo # 4 external locks (due to pruning of locks)
+--echo # (1 ha_partition + 1 ha_innobase) x 2 (lock + unlock)
+--echo # and 18 write (1 ha_innobase + 17 internal I_S write)
+INSERT INTO t1 PARTITION (pNeg, subp0) VALUES (-3, "pNeg(-subp1)");
+INSERT INTO t1 PARTITION (pNeg, subp0) VALUES (-2, "(pNeg-)subp0");
+
+--echo # should be correct
+INSERT INTO t1 PARTITION (`p100-99999`) VALUES (100, "`p100-99999`(-subp6)"), (101, "`p100-99999`(-subp7)"), (1000, "`p100-99999`(-subp6)");
+INSERT INTO t1 PARTITION(`p10-99`,subp3) VALUES (1, "subp3"), (10, "p10-99");
+FLUSH STATUS;
+INSERT INTO t1 PARTITION(subp3) VALUES (3, "subp3");
+eval $get_handler_status_counts;
+--echo # Should be 1 commit
+--echo # 4 external locks
+--echo # (1 ha_partition + 1 ha_innobase) x 2 (lock + unlock)
+--echo # and 18 write (1 ha_innobase + 17 internal I_S write)
+FLUSH STATUS;
+LOCK TABLE t1 WRITE;
+eval $get_handler_status_counts;
+--echo # should be 1 commit
+--echo # 9 locks (1 ha_partition + 8 ha_innobase)
+--echo # 17 writes (internal I_S)
+INSERT INTO t1 PARTITION(`p0-9`) VALUES (5, "p0-9:subp3");
+eval $get_handler_status_counts;
+--echo # + 1 commit
+--echo # + 19 rnd next (internal I_S)
+--echo # + 19 write (18 internal I_S + 1 insert)
+UNLOCK TABLES;
+eval $get_handler_status_counts;
+--echo # + 9 locks (unlocks)
+--echo # + 19 rnd next (internal I_S)
+--echo # + 18 write (internal I_S)
+
+--echo # Not matching partitions with inserted value
+--error ER_ROW_DOES_NOT_MATCH_GIVEN_PARTITION_SET
+INSERT INTO t1 PARTITION (pNeg, pNeg) VALUES (1, "error");
+--error ER_ROW_DOES_NOT_MATCH_GIVEN_PARTITION_SET
+INSERT INTO t1 PARTITION (pNeg, subp0) VALUES (1, "error");
+--error ER_ROW_DOES_NOT_MATCH_GIVEN_PARTITION_SET
+INSERT INTO t1 PARTITION (`p100-99999`) VALUES (1, "error"), (10, "error");
+--error ER_NO_PARTITION_FOR_GIVEN_VALUE
+INSERT INTO t1 VALUES (1000000, "error"), (9999999, "error");
+--error ER_NO_PARTITION_FOR_GIVEN_VALUE
+INSERT INTO t1 PARTITION (`p100-99999`) VALUES (1000000, "error"), (9999999, "error");
+--error ER_DUP_ENTRY,ER_DUP_KEY
+INSERT INTO t1 PARTITION (pNeg, subp4) VALUES (-7, "pNeg(-subp1)"), (-10, "pNeg(-subp0)"), (-1, "pNeg(-subp1)"), (-99, "pNeg(-subp1)");
+
+SELECT * FROM t1 ORDER BY a;
+ANALYZE TABLE t1;
+
+SET @save_innodb_stats_on_metadata=@@global.innodb_stats_on_metadata;
+SET @@global.innodb_stats_on_metadata=ON;
+SELECT PARTITION_NAME, SUBPARTITION_NAME, TABLE_ROWS
+FROM INFORMATION_SCHEMA.PARTITIONS
+WHERE TABLE_SCHEMA = 'test'
+AND TABLE_NAME = 't1' ORDER BY SUBPARTITION_NAME;
+SET @@global.innodb_stats_on_metadata=@save_innodb_stats_on_metadata;
+
+FLUSH STATUS;
+--error ER_UNKNOWN_PARTITION
+SELECT * FROM t1 PARTITION (pNonexistent);
+eval $get_handler_status_counts;
+--echo # should have failed before locking (only 17 internal I_S writes)
+FLUSH STATUS;
+SELECT * FROM t1 PARTITION (subp2);
+eval $get_handler_status_counts;
+--echo # Should be 1 commit
+--echo # 4 locks (1 ha_partition + 1 ha_innobase) x 2 (lock/unlock)
+--echo # 1 read first (also calls index_read)
+--echo # 2 read key (first from innobase_get_index and second from index first)
+--echo # 17 writes (internal I_S)
+FLUSH STATUS;
+SELECT * FROM t1 PARTITION (subp2,pNeg) AS TableAlias;
+eval $get_handler_status_counts;
+--echo # Should be 1 commit
+--echo # 8 locks (1 ha_partition + 2 + 1 ha_innobase) x 2
+--echo # 3 read first (one for each partition)
+--echo # 6 read key (3 from read first and 3 from innobase_get_index)
+--echo # 3 read next (one next call after each read row)
+--echo # 17 writes (internal I_S)
+FLUSH STATUS;
+LOCK TABLE t1 READ, t1 as TableAlias READ;
+eval $get_handler_status_counts;
+--echo # 1 commit
+--echo # 18 locks
+--echo # 18 READ KEY from opening a new partition table instance,
+--echo # (1 innobase_get_index for each index, per partition, 1 x 2 x 8 = 16
+--echo # + info(HA_STATUS_CONST) call on the partition with the most number
+--echo # of rows, 2 innobase_get_index for updating both index statistics)
+--echo # 17 writes (internal I_S)
+SELECT * FROM t1 PARTITION (subp3) AS TableAlias;
+eval $get_handler_status_counts;
+--echo # + 1 commit
+--echo # + 1 read first (read first key from index in one partition)
+--echo # + 2 read key (innobase_get_index from index_init + from index_first)
+--echo # + 3 read next (one after each row)
+--echo # + 19 rnd next (from the last I_S query)
+--echo # + 18 write (internal I_S)
+SELECT COUNT(*) FROM t1 PARTITION (`p10-99`);
+eval $get_handler_status_counts;
+--echo # + 1 commit
+--echo # + 2 read first (one for each subpart)
+--echo # + 4 read key (innobase_get_index from index_init + from index_first)
+--echo # + 1 read next (one after each row)
+--echo # + 19 rnd next (from the last I_S query)
+--echo # + 18 write (internal I_S)
+SELECT * FROM t1 WHERE a = 1000000;
+eval $get_handler_status_counts;
+--echo # No matching partition, only internal I_S.
+SELECT * FROM t1 PARTITION (pNeg) WHERE a = 100;
+UNLOCK TABLES;
+eval $get_handler_status_counts;
+--echo # + 18 for unlock (same as lock above) (100 is not in pNeg, no match)
+
+--echo # Test that EXPLAIN PARTITION works
+--error ER_UNKNOWN_PARTITION
+EXPLAIN PARTITIONS SELECT * FROM t1 PARTITION (pNonexistent);
+EXPLAIN PARTITIONS SELECT * FROM t1 PARTITION (subp2);
+FLUSH STATUS;
+EXPLAIN PARTITIONS SELECT * FROM t1 PARTITION (subp2,pNeg) AS TableAlias;
+eval $get_handler_status_counts;
+--echo # 8 locks (1 ha_partition + 3 ha_innobase) x 2 (lock/unlock)
+EXPLAIN PARTITIONS SELECT * FROM t1 PARTITION (subp3) AS TableAlias;
+EXPLAIN PARTITIONS SELECT COUNT(*) FROM t1 PARTITION (`p10-99`);
+EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a = 1000000;
+EXPLAIN PARTITIONS SELECT * FROM t1 PARTITION (pNeg) WHERE a = 100;
+
+--echo # Test how it changes the alias/keywords/reserved words
+--error ER_PARSE_ERROR
+SELECT * FROM t1 PARTITION;
+SELECT * FROM t1 `PARTITION`;
+--error ER_PARSE_ERROR
+SELECT * FROM t1 AS PARTITION;
+SELECT * FROM t1 AS `PARTITION`;
+
+--echo #
+--echo # Test REPLACE
+--echo #
+FLUSH STATUS;
+--error ER_ROW_DOES_NOT_MATCH_GIVEN_PARTITION_SET
+REPLACE INTO t1 PARTITION (subp0) VALUES (-21, 'Should fail!');
+eval $get_handler_status_counts;
+--echo # 2 locks (1 ha_partition) x 2 (lock/unlock), Was 4 locks before WL4443
+--echo # explicit pruning says part_id 0 and implicit pruning says part_id 1
+--echo # so no partition will be locked!
+--echo # 0 rollback (since no locked partition)
+--echo # 17 writes (I_S internal)
+FLUSH STATUS;
+REPLACE INTO t1 PARTITION (subp1) VALUES (-21, 'Insert by REPLACE');
+eval $get_handler_status_counts;
+--echo # 1 commit
+--echo # 4 locks (1 ha_partition + 1 ha_innobase) x 2 (lock/unlock)
+--echo # 18 writes (17 I_S internal, 1 ha_innobase)
+SELECT * FROM t1 PARTITION (pNeg);
+FLUSH STATUS;
+REPLACE INTO t1 PARTITION (subp1) VALUES (-21, 'REPLACEd by REPLACE');
+eval $get_handler_status_counts;
+--echo # 1 commit
+--echo # 4 locks (1 ha_partition + 1 ha_innobase) x 2 (lock/unlock)
+--echo # 2 read key (1 innobase_get_index when init the index + 1 index read
+--echo # to get the position to update)
+--echo # 1 update (updated one row, since there is no delete trigger, update
+--echo # is used instead of delete+insert)
+--echo # 18 write (17 from I_S, 1 for the failed insert)
+SELECT * FROM t1 PARTITION (pNeg);
+FLUSH STATUS;
+LOCK TABLE t1 WRITE;
+eval $get_handler_status_counts;
+--echo # 1 commit
+--echo # 9 locks
+--echo # 17 write (internal I_S)
+DELETE FROM t1 PARTITION(subp1) WHERE b = "REPLACEd by REPLACE";
+eval $get_handler_status_counts;
+--echo # + 1 commit
+--echo # + 1 delete (one row deleted)
+--echo # + 3 read key (1 innodb_get_index in records_in_range,
+--echo # 1 innodb_get_index in index_init, 1 index_read in index_read_first)
+--echo # + 1 read next (search for another row in secondary index)
+--echo # + 19 rnd next (internal I_S)
+--echo # + 18 write (internal I_S)
+--error ER_ROW_DOES_NOT_MATCH_GIVEN_PARTITION_SET
+REPLACE INTO t1 PARTITION (subp0) VALUES (-21, 'Should fail!');
+eval $get_handler_status_counts;
+--echo # Failed before start_stmt/execution.
+--echo # + 19 rnd next (internal I_S)
+--echo # 0 rollback (No partition had called start_stmt, all parts pruned)
+--echo # + 18 write (internal I_S)
+REPLACE INTO t1 PARTITION (pNeg) VALUES (-21, 'Insert by REPLACE');
+eval $get_handler_status_counts;
+--echo # + 1 commit
+--echo # + 19 rnd next (internal I_S)
+--echo # + 19 write (18 internal I_S + 1 real write)
+REPLACE INTO t1 PARTITION (subp1) VALUES (-21, 'REPLACEd by REPLACE');
+eval $get_handler_status_counts;
+--echo # + 1 commit
+--echo # + 2 read key (see non locked query)
+--echo # + 19 rnd next (internal I_S)
+--echo # + 1 update (see non locked query)
+--echo # + 19 write (18 internal I_S + 1 failed write)
+SELECT * FROM t1 PARTITION (subp1);
+eval $get_handler_status_counts;
+--echo # + 1 commit
+--echo # + 1 read first
+--echo # + 2 read key
+--echo # + 3 read next
+--echo # + 19 rnd next (internal I_S)
+--echo # + 18 write (internal I_S)
+UNLOCK TABLES;
+eval $get_handler_status_counts;
+--echo # + 9 locks
+--echo # + 19 rnd next (internal I_S)
+--echo # + 18 write (internal I_S)
+
+--echo #
+--echo # Test LOAD
+--echo #
+SELECT * FROM t1 PARTITION (pNeg, `p10-99`);
+FLUSH STATUS;
+SELECT * FROM t1 PARTITION (pNeg, `p10-99`) INTO OUTFILE 'loadtest.txt';
+eval $get_handler_status_counts;
+--echo # 1 commit
+--echo # 10 locks (1 ha_partition + 4 ha_innobase) x 2 (lock/unlock)
+--echo # 4 read first (for reading the first row in 4 partitions)
+--echo # 8 read key (4 from read first + 4 for index init)
+--echo # 5 read next (one after each row)
+--echo # 17 write (internal I_S)
+FLUSH STATUS;
+ALTER TABLE t1 TRUNCATE PARTITION pNeg, `p10-99`;
+eval $get_handler_status_counts;
+--echo # 10 locks (table + 4 partition) x (lock + unlock)
+SELECT * FROM t1 PARTITION (pNeg, `p10-99`);
+FLUSH STATUS;
+--error ER_ROW_DOES_NOT_MATCH_GIVEN_PARTITION_SET
+LOAD DATA INFILE 'loadtest.txt' INTO TABLE t1 PARTITION (pNeg);
+eval $get_handler_status_counts;
+--echo # 6 locks (1 ha_partition + 2 ha_innobase) x 2 (lock+unlock)
+--echo # 1 rollback
+SELECT * FROM t1 PARTITION (pNeg, `p10-99`);
+FLUSH STATUS;
+LOAD DATA INFILE 'loadtest.txt' INTO TABLE t1 PARTITION (pNeg, subp4, subp5);
+eval $get_handler_status_counts;
+--echo # 10 lock (1 ha_partition + 4 ha_innobase) x 2 (lock + unlock)
+ALTER TABLE t1 TRUNCATE PARTITION pNeg, `p10-99`;
+FLUSH STATUS;
+LOCK TABLE t1 WRITE;
+eval $get_handler_status_counts;
+--echo # 9 locks
+--echo # 18 read key (ALTER forces table to be closed, see above for open)
+LOAD DATA INFILE 'loadtest.txt' INTO TABLE t1 PARTITION (pNeg, `p10-99`);
+eval $get_handler_status_counts;
+--echo # + 23 write (18 internal I_S + 5 rows)
+UNLOCK TABLES;
+eval $get_handler_status_counts;
+--echo # + 9 locks
+--remove_file $MYSQLD_DATADIR/test/loadtest.txt
+
+--echo #
+--echo # Test UPDATE
+--echo #
+FLUSH STATUS;
+UPDATE t1 PARTITION(subp0) SET b = concat(b, ', Updated');
+eval $get_handler_status_counts;
+--echo # 1 commit
+--echo # 4 lock (1 ha_partition + 1 ha_innobase) x 2 (lock + unlock)
+--echo # 1 read first (read first row, called from first rnd_next)
+--echo # 2 read key (innobase_get_index from rnd_init +
+--echo # read next row from second rnd_next)
+--echo # 1 update (update the row)
+# EXPLAIN PARTITIONS UPDATE t1 PARTITION(subp0) SET b = concat(b, ', Updated');
+SELECT * FROM t1 PARTITION (subp0) ORDER BY a;
+FLUSH STATUS;
+UPDATE t1 PARTITION(subp0) SET b = concat(b, ', Updated2') WHERE a = -2;
+eval $get_handler_status_counts;
+--echo # 1 commit
+--echo # 4 lock
+--echo # 1 read key
+--echo # 1 update
+# EXPLAIN PARTITIONS UPDATE t1 PARTITION(subp0) SET b = concat(b, ', Updated2') WHERE a = -2;
+FLUSH STATUS;
+UPDATE t1 PARTITION(subp0) SET a = -4, b = concat(b, ', Updated from a = -2')
+WHERE a = -2;
+eval $get_handler_status_counts;
+--echo # 1 commit
+--echo # 4 lock
+--echo # 2 read key - (2 index read)
+--echo # 1 read rnd - rnd_pos
+--echo # 1 update
+# EXPLAIN PARTITIONS UPDATE t1 PARTITION(subp0) SET a = -4, b = concat(b, ', Updated from a = -2');
+FLUSH STATUS;
+UPDATE t1 PARTITION(subp0) SET b = concat(b, ', Updated2') WHERE a = 100;
+eval $get_handler_status_counts;
+--echo # Nothing, since impossible PARTITION+WHERE clause.
+# EXPLAIN PARTITIONS UPDATE t1 PARTITION(subp0) SET b = concat(b, ', Updated2') WHERE a = 100;
+FLUSH STATUS;
+UPDATE t1 PARTITION(subp0) SET a = -2, b = concat(b, ', Updated from a = 100')
+WHERE a = 100;
+eval $get_handler_status_counts;
+--echo # Nothing, since impossible PARTITION+WHERE clause.
+# EXPLAIN PARTITIONS UPDATE t1 PARTITION(subp0)
+# SET a = -2, b = concat(b, ', Updated from a = 100') WHERE a = 100;
+FLUSH STATUS;
+--error ER_ROW_DOES_NOT_MATCH_GIVEN_PARTITION_SET
+UPDATE t1 PARTITION(`p100-99999`) SET a = -2, b = concat(b, ', Updated from a = 100')
+WHERE a = 100;
+eval $get_handler_status_counts;
+--echo # 6 lock
+--echo # 4 read key (1 index init + 1 index read + 1 rnd init + 1 rnd pos)
+--echo # 1 read rnd (rnd pos)
+--echo # 1 rollback
+FLUSH STATUS;
+--error ER_DUP_ENTRY,ER_DUP_KEY
+UPDATE t1 PARTITION(`p100-99999`, pNeg) SET a = -4, b = concat(b, ', Updated from a = 100')
+WHERE a = 100;
+eval $get_handler_status_counts;
+--echo # 10 locks
+--echo # 4 read key
+--echo # 1 read rnd
+--echo # 1 rollback
+--echo # 18 write (17 internal I_S + 1 failed insert)
+FLUSH STATUS;
+UPDATE t1 PARTITION(`p100-99999`, pNeg) SET a = -222, b = concat(b, ', Updated from a = 100')
+WHERE a = 100;
+eval $get_handler_status_counts;
+--echo # 1 commit
+--echo # 1 delete
+--echo # 4 read key
+--echo # 1 read rnd
+--echo # 18 write (17 internal I_S + 1 insert)
+
+SELECT * FROM t1 ORDER BY a;
+--echo # Test of non matching partition (i.e ER_NO_PARTITION_FOUND)
+FLUSH STATUS;
+UPDATE t1 SET b = concat(b, ', Updated2') WHERE a = 1000000;
+eval $get_handler_status_counts;
+--echo # Nothing (no matching partition found)
+FLUSH STATUS;
+UPDATE t1 PARTITION (pNeg) SET b = concat(b, ', Updated2') WHERE a = 1000000;
+eval $get_handler_status_counts;
+--echo # Nothing (no matching partition found)
+FLUSH STATUS;
+LOCK TABLE t1 WRITE;
+eval $get_handler_status_counts;
+--echo # 9 locks
+UPDATE t1 PARTITION (subp7) SET b = concat(b, ', Updated to 103'), a = 103 WHERE a = 101;
+eval $get_handler_status_counts;
+--echo # + 4 read key
+--echo # + 1 read rnd
+--echo # + 1 update
+UPDATE t1 PARTITION (`p100-99999`) SET b = concat(b, ', Updated to 110'), a = 110 WHERE a = 103;
+eval $get_handler_status_counts;
+--echo # + 1 delete
+--echo # + 4 read key
+--echo # + 1 read rnd
+--echo # + 19 write (18 internal I_S + 1 insert)
+UNLOCK TABLES;
+eval $get_handler_status_counts;
+--echo + 9 locks
+
+--echo #
+--echo # Test DELETE
+--echo #
+SELECT * FROM t1 ORDER BY b, a;
+FLUSH STATUS;
+DELETE FROM t1 PARTITION (pNeg) WHERE a = -1;
+eval $get_handler_status_counts;
+--echo # 1 delete
+--echo # 4 locks (pruning works!).
+--echo # 1 read key (index read)
+FLUSH STATUS;
+DELETE FROM t1 PARTITION (subp1) WHERE b like '%subp1%';
+eval $get_handler_status_counts;
+--echo # 1 delete
+--echo # 4 locks
+--echo # 1 read first
+--echo # 2 read key
+--echo # 3 read rnd
+FLUSH STATUS;
+LOCK TABLE t1 WRITE;
+eval $get_handler_status_counts;
+--echo # 9 locks
+DELETE FROM t1 PARTITION (subp1) WHERE b = 'p0-9:subp3';
+eval $get_handler_status_counts;
+--echo # + 3 read key (1 innodb_get_index in records_in_range
+--echo # + 1 innobase_get_index in index_init + 1 index read)
+DELETE FROM t1 PARTITION (`p0-9`) WHERE b = 'p0-9:subp3';
+eval $get_handler_status_counts;
+--echo # + 1 delete
+--echo # + 6 read key (same as above, but for two subpartitions)
+--echo # + 1 read next (read next after found row)
+UNLOCK TABLES;
+eval $get_handler_status_counts;
+--echo # + 9 locks
+
+--echo # Test multi-table DELETE
+--echo # Can be expressed in two different ways.
+CREATE TABLE t2 LIKE t1;
+FLUSH STATUS;
+INSERT INTO t2 PARTITION (`p10-99`, subp3, `p100-99999`) SELECT * FROM t1 PARTITION (subp3, `p10-99`, `p100-99999`);
+eval $get_handler_status_counts;
+--echo # 24 locks (2 table, 5 + 5 subpartitions lock/unlock)
+FLUSH STATUS;
+ALTER TABLE t2 TRUNCATE PARTITION `p10-99`, `p0-9`, `p100-99999`;
+eval $get_handler_status_counts;
+--echo # 14 locks (1 table, 6 subpartitions lock/unlock)
+FLUSH STATUS;
+--error ER_ROW_DOES_NOT_MATCH_GIVEN_PARTITION_SET
+INSERT INTO t2 PARTITION (subp3) SELECT * FROM t1 PARTITION (subp3, `p10-99`, `p100-99999`);
+eval $get_handler_status_counts;
+--echo # 16 locks (2 tables, 1 + 5 subpartitions lock/unlock)
+FLUSH STATUS;
+INSERT IGNORE INTO t2 PARTITION (subp3) SELECT * FROM t1 PARTITION (subp3, `p10-99`, `p100-99999`);
+eval $get_handler_status_counts;
+--echo # 16 locks (2 tables, 1 + 5 subpartitions lock/unlock)
+TRUNCATE TABLE t2;
+FLUSH STATUS;
+INSERT INTO t2 SELECT * FROM t1 PARTITION (subp3, `p10-99`, `p100-99999`);
+eval $get_handler_status_counts;
+--echo # 30 locks (2 table, 8 + 5 subpartitions lock/unlock)
+FLUSH STATUS;
+CREATE TABLE t3 SELECT * FROM t1 PARTITION (pNeg,subp3,`p100-99999`);
+eval $get_handler_status_counts;
+--echo # 14 locks (2 table, 5 subpartitions lock/unlock)
+SHOW CREATE TABLE t1;
+SELECT * FROM t1;
+SHOW CREATE TABLE t2;
+SELECT * FROM t2;
+SHOW CREATE TABLE t3;
+SELECT * FROM t3;
+FLUSH STATUS;
+--error ER_PARSE_ERROR
+DELETE t1 PARTITION (pNeg), t3 FROM t1, t3
+WHERE t1.a = t3.a AND t3.b = 'subp3';
+eval $get_handler_status_counts;
+--echo # Multi table delete without any matching rows
+FLUSH STATUS;
+DELETE t1, t2 FROM t1 PARTITION (pNeg), t3, t2 PARTITION (subp3)
+WHERE t1.a = t3.a AND t3.b = 'subp3' AND t3.a = t2.a;
+eval $get_handler_status_counts;
+--echo # 12 locks (3 in t1, 1 in t3, 2 in t2) x 2 (lock + unlock)
+--echo # 1 read first (first rnd_next in t2)
+--echo # 4 read key (1 innodb_get_index in rnd_init in t2 + index read in t2
+--echo # + 2 innodb_get_index in index_init in t1)
+--echo # 3 read rnd next (3 rnd next in t2, 2 rows + 1 empty)
+--echo # Multi table delete matching all rows in subp3 (2 rows in per table)
+FLUSH STATUS;
+DELETE FROM t2, t3 USING t2 PARTITION (`p0-9`), t3, t1 PARTITION (subp3)
+WHERE t1.a = t3.a AND t3.b = 'subp3' AND t2.a = t1.a;
+eval $get_handler_status_counts;
+--echo # 4 delete (2 in t2 + 2 in t3)
+--echo # 12 locks (3 in t2, 1 in t3, 2 in t1) x 2 (lock + unlock)
+--echo # 3 read first (1 in t1 + 1 in t3 + 1 in t3, for second row in t1)
+--echo # 17 read key (1 index_init in t1 + 1 read first in t1 +
+--echo # 2 index_init in t2 + 1 index read in t2 +
+--echo # 1 index_init in t3 + 1 index read in t3 +
+--echo # 1 index read in t2 +
+--echo # 1 index_init in t3 + 1 index read in t3 +
+--echo # 2 index_init in t2 + 2 index read in t2 (from rnd_pos)
+--echo # 1 index_init in t3 + 2 index read in t3 (from rnd_pos))
+--echo # 2 read next (1 in t1 + 1 in t1, second row)
+--echo # 4 read rnd (position on 4 found rows to delete)
+--echo # 16 rnd next (8 in t3 + 8 in t3, for second row)
+SELECT * FROM t1 ORDER BY a;
+SELECT * FROM t2 ORDER BY a;
+SELECT * FROM t3 ORDER BY a;
+
+
+--echo # Test TRUNCATE TABLE (should fail, since one should use
+--echo # ALTER TABLE ... TRUNCATE PARTITION instead)
+--error ER_PARSE_ERROR
+TRUNCATE TABLE t1 PARTITION(`p10-99`);
+
+--echo # Test of locking in TRUNCATE PARTITION
+--echo # Note that it does not support truncating subpartitions
+FLUSH STATUS;
+ALTER TABLE t1 TRUNCATE PARTITION pNeg;
+eval $get_handler_status_counts;
+--echo # 6 locks (lock/unlock two subpartitions + table)
+
+--echo # Test on non partitioned table
+--error ER_PARTITION_CLAUSE_ON_NONPARTITIONED
+SELECT * FROM t3 PARTITION (pNeg);
+
+DROP TABLE t1, t2, t3;
+#
+--echo # Test from superseeded WL# 2682
+# Partition select tests.
+#
+--disable_warnings
+drop table if exists t1,t2,t3,t4,t5,t6,t7,t8,t9;
+--enable_warnings
+
+CREATE TABLE `t1` (
+`id` int(11) default NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+PARTITION BY RANGE (id) (
+PARTITION p0 VALUES LESS THAN (6) ENGINE = MyISAM,
+PARTITION p1 VALUES LESS THAN (11) ENGINE = MyISAM,
+PARTITION p2 VALUES LESS THAN (16) ENGINE = MyISAM,
+PARTITION p3 VALUES LESS THAN (21) ENGINE = MyISAM);
+
+INSERT INTO `t1` VALUES (1), (2), (3), (4), (5), (6), (7), (8), (9), (10),
+(11), (12), (13), (14), (15), (16), (17), (18), (19), (20);
+
+SELECT * FROM t1;
+SELECT * FROM t1 PARTITION (p0);
+SELECT * FROM t1 PARTITION (p1);
+SELECT * FROM t1 PARTITION (p2);
+SELECT * FROM t1 PARTITION (p3);
+SELECT * FROM t1 PARTITION (p3) WHERE id = 2;
+--error ER_UNKNOWN_PARTITION
+SELECT * FROM t1 PARTITION (foo);
+
+# now try indexes
+CREATE TABLE `t2` (
+`id` int(11) NOT NULL DEFAULT 0,
+PRIMARY KEY (`id`)
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+PARTITION BY RANGE (id) (
+PARTITION p0 VALUES LESS THAN (6) ENGINE = MyISAM,
+PARTITION p1 VALUES LESS THAN (11) ENGINE = MyISAM,
+PARTITION p2 VALUES LESS THAN (16) ENGINE = MyISAM,
+PARTITION p3 VALUES LESS THAN (21) ENGINE = MyISAM);
+
+INSERT INTO `t2` VALUES (1), (2), (3), (4), (5), (6), (7), (8), (9), (10),
+(11), (12), (13), (14), (15), (16), (17), (18), (19), (20);
+
+SELECT * FROM t2;
+SELECT * FROM t2 PARTITION (p0);
+SELECT * FROM t2 PARTITION (p1);
+SELECT * FROM t2 PARTITION (p2);
+SELECT * FROM t2 PARTITION (p3);
+SELECT * FROM t2 PARTITION (p3) ORDER BY id;
+SELECT * FROM t2 PARTITION (p3) WHERE id = 2;
+--error ER_UNKNOWN_PARTITION
+SELECT * FROM t2 PARTITION (foo);
+
+
+CREATE TABLE `t3` (
+ `id` int(32) default NULL,
+ `name` varchar(32) default NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+PARTITION BY LIST (id) (
+ PARTITION p0 VALUES IN (1,3,5,7),
+ PARTITION p1 VALUES IN (0,2,4,6,8),
+ PARTITION p2 VALUES IN (9,10,11,12,13)
+);
+
+INSERT INTO `t3` VALUES (1,'first'), (3,'third'),(5,'fifth'),(7,'seventh'),(0,'zilch'),(2,'second'),(4,'fourth'),(6,'sixth'),(8,'eighth'),(9,'ninth'),(10,'tenth'),(11,'eleventh'),(12,'twelfth'),(13,'thirteenth');
+
+SELECT * FROM `t3`;
+SELECT * FROM `t3` PARTITION (p0);
+SELECT * FROM `t3` PARTITION (p1);
+SELECT * FROM `t3` PARTITION (p2);
+SELECT * FROM `t3` PARTITION (p2) ORDER BY id;
+
+DROP TABLE IF EXISTS `t4`;
+CREATE TABLE `t4` (
+ `id` int(32) default NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1 PARTITION BY HASH (id) ;
+
+INSERT INTO `t4` SELECT * FROM `t2`;
+INSERT INTO `t4` SELECT * FROM `t2` ORDER BY id;
+# not sure how to do this, since names could be anything
+#SELECT * FROM `t4` PARTITION (p0);
+#SELECT * FROM `t4` PARTITION (p1);
+#SELECT * FROM `t4` PARTITION (p2);
+#SELECT * FROM `t4` PARTITION (p3);
+#SELECT * FROM `t4` PARTITION (p3) ORDER BY id;
+
+CREATE TABLE `t5` (
+ id int(32),
+ name varchar(64),
+ purchased date)
+PARTITION BY RANGE( YEAR(purchased) )
+ SUBPARTITION BY HASH( TO_DAYS(purchased) ) (
+ PARTITION p0 VALUES LESS THAN (1990) (
+ SUBPARTITION s0,
+ SUBPARTITION s1
+ ),
+ PARTITION p1 VALUES LESS THAN (2000) (
+ SUBPARTITION s2,
+ SUBPARTITION s3
+ ),
+ PARTITION p2 VALUES LESS THAN MAXVALUE (
+ SUBPARTITION s4,
+ SUBPARTITION s5
+ )
+ );
+
+INSERT INTO `t5` VALUES (1, 'aaaaaaa', '2006-01-05 00:00:00');
+INSERT INTO `t5` VALUES (2, 'bbbbbbb', '2005-08-05 00:00:00');
+INSERT INTO `t5` VALUES (3, 'ccccccc', '1985-08-07 00:00:00');
+INSERT INTO `t5` VALUES (4, 'ddddddd', '2000-01-01 00:00:00');
+INSERT INTO `t5` VALUES (5, 'eeeeeee', '1999-12-01 00:00:00');
+INSERT INTO `t5` VALUES (6, 'fffffff', '2003-11-12 00:00:00');
+INSERT INTO `t5` VALUES (7, 'ggggggg', '1990-01-05 00:00:00');
+INSERT INTO `t5` VALUES (8, 'hhhhhhh', '1978-01-05 00:00:00');
+INSERT INTO `t5` VALUES (9, 'iiiiiii', '1979-01-05 00:00:00');
+INSERT INTO `t5` VALUES (10, 'jjjjjjj', '1992-01-05 00:00:00');
+INSERT INTO `t5` VALUES (11, 'kkkkkkk', '1993-01-05 00:00:00');
+INSERT INTO `t5` VALUES (12, 'mmmmmmm', '1994-01-05 00:00:00');
+INSERT INTO `t5` VALUES (13, 'nnnnnnn', '1989-01-05 00:00:00');
+INSERT INTO `t5` VALUES (14, 'ooooooo', '1983-12-05 00:00:00');
+INSERT INTO `t5` VALUES (15, 'ppppppp', '1986-06-05 00:00:00');
+INSERT INTO `t5` VALUES (16, 'qqqqqqq', '1974-04-11 00:00:00');
+INSERT INTO `t5` VALUES (17, 'qqqqqqq', '1960-03-15 00:00:00');
+INSERT INTO `t5` VALUES (18, 'sssssss', '1950-09-23 00:00:00');
+INSERT INTO `t5` VALUES (19, 'ttttttt', '1999-08-02 00:00:00');
+INSERT INTO `t5` VALUES (20, 'uuuuuuu', '1994-05-28 00:00:00');
+
+SELECT * FROM `t5`;
+SELECT * FROM `t5` PARTITION(p0) ORDER BY id;
+SELECT * FROM `t5` PARTITION(s0) ORDER BY id;
+SELECT * FROM `t5` PARTITION(s1) ORDER BY id;
+SELECT * FROM `t5` PARTITION(p1) ORDER BY id;
+SELECT * FROM `t5` PARTITION(s2) ORDER BY id;
+SELECT * FROM `t5` PARTITION(s3) ORDER BY id;
+SELECT * FROM `t5` PARTITION(p2) ORDER BY id;
+SELECT * FROM `t5` PARTITION(s4) ORDER BY id;
+SELECT * FROM `t5` PARTITION(s5) ORDER BY id;
+
+--disable_warnings
+drop table t1,t2,t3,t4,t5;
+--enable_warnings
+
+# Tests for working together with partition pruning.
+create table t1 (a int) partition by hash(a) partitions 3;
+insert into t1 values(1),(2),(3);
+explain partitions select * from t1 where a=1;
+explain partitions select * from t1 partition (p1) where a=1;
+explain partitions select * from t1 partition (p1) where a=1 or a=2;
+explain partitions select * from t1 partition (p2) where a=1;
+
+drop table t1;
+
+--echo #
+--echo # Bug#59864: Crash if table empty: DELETE FROM t2 PARTITION (subp3).
+--echo #
+CREATE TABLE t1
+(a INT NOT NULL,
+ b varchar (64),
+ INDEX (b,a),
+ PRIMARY KEY (a))
+PARTITION BY RANGE (a)
+SUBPARTITION BY HASH (a) SUBPARTITIONS 3
+(PARTITION pNeg VALUES LESS THAN (0)
+ (SUBPARTITION subp0,
+ SUBPARTITION subp1,
+ SUBPARTITION subp2),
+ PARTITION `p0-29` VALUES LESS THAN (30)
+ (SUBPARTITION subp3,
+ SUBPARTITION subp4,
+ SUBPARTITION subp5),
+ PARTITION `p30-299` VALUES LESS THAN (300)
+ (SUBPARTITION subp6,
+ SUBPARTITION subp7,
+ SUBPARTITION subp8),
+ PARTITION `p300-2999` VALUES LESS THAN (3000)
+ (SUBPARTITION subp9,
+ SUBPARTITION subp10,
+ SUBPARTITION subp11),
+ PARTITION `p3000-299999` VALUES LESS THAN (300000)
+ (SUBPARTITION subp12,
+ SUBPARTITION subp13,
+ SUBPARTITION subp14));
+
+eval SHOW CREATE TABLE t1;
+
+INSERT INTO t1 VALUES (-9, "negative nine"), (-8, "-8"), (-7, "-7"), (-6, "-6"), (-5, "-5"), (-4, "-4"), (-3, "-3"), (-2, "-2"), (-1, "-1");
+INSERT INTO t1 VALUES (9, "nine"), (8, "8"), (7, "7"), (6, "6"), (5, "5"), (4, "4"), (3, "3"), (2, "2"), (1, "1");
+INSERT INTO t1 VALUES (39, "Thirty nine"), (38, "38"), (37, "37"), (36, "36"), (35, "35"), (34, "34"), (33, "33"), (32, "32"), (31, "31");
+INSERT INTO t1 VALUES (339, "Three hundred thirty nine"), (338, "338"), (337, "337"), (336, "336"), (335, "335"), (334, "334"), (333, "333"), (332, "332"), (331, "331");
+INSERT INTO t1 VALUES (3339, "Three thousand three hundred thirty nine"), (3338, "3338"), (3337, "3337"), (3336, "3336"), (3335, "3335"), (3334, "3334"), (3333, "3333"), (3332, "3332"), (3331, "3331");
+
+--sorted_result
+SELECT * FROM t1;
+--sorted_result
+SELECT * FROM t1 PARTITION (subp3);
+
+DELETE FROM t1 PARTITION (subp3);
+
+--sorted_result
+SELECT * FROM t1;
+--sorted_result
+SELECT * FROM t1 PARTITION (subp3);
+
+DELETE FROM t1 PARTITION (`p0-29`);
+
+--sorted_result
+SELECT * FROM t1;
+--sorted_result
+SELECT * FROM t1 PARTITION (`p0-29`);
+
+ALTER TABLE t1 PARTITION BY HASH (a) PARTITIONS 3;
+
+DELETE FROM t1 PARTITION (p2);
+
+--sorted_result
+SELECT * FROM t1;
+--sorted_result
+SELECT * FROM t1 PARTITION (p2);
+
+DROP TABLE t1;
+
+--echo #
+--echo # Test explicit partition selection on a non partitioned temp table
+--echo #
+CREATE TEMPORARY TABLE t1 (a INT);
+--error ER_PARTITION_CLAUSE_ON_NONPARTITIONED
+SELECT * FROM t1 PARTITION(pNonexisting);
+DROP TEMPORARY TABLE t1;
+
+--echo #
+--echo # Test CREATE LIKE does not take PARTITION clause
+--echo #
+CREATE TABLE t1 (a INT) PARTITION BY HASH (a) PARTITIONS 3;
+--error ER_PARSE_ERROR
+CREATE TABLE t2 LIKE t1 PARTITION (p0, p2);
+DROP TABLE t1;
+
+SET @@default_storage_engine = @old_default_storage_engine;
diff --git a/mysql-test/t/partition_innodb.test b/mysql-test/t/partition_innodb.test
index b661e4bd3fa..f6faa4cb0e6 100644
--- a/mysql-test/t/partition_innodb.test
+++ b/mysql-test/t/partition_innodb.test
@@ -1,6 +1,6 @@
-if (`select plugin_auth_version <= "5.5.43-MariaDB-37.2" from information_schema.plugins where plugin_name='innodb'`)
+if (`select plugin_auth_version < "5.6.25" from information_schema.plugins where plugin_name='innodb'`)
{
- --skip Not fixed in XtraDB as of 5.5.43-MariaDB-37.2 or earlier
+ --skip Not fixed in InnoDB as of 5.6.24 or earlier
}
--source include/not_embedded.inc
--source include/have_partition.inc
@@ -45,6 +45,17 @@ EXPLAIN SELECT b FROM t1 WHERE b between 'L' and 'N' AND a > -100;
DROP TABLE t1;
--echo #
+--echo # Bug#13007154: Crash in keys_to_use_for_scanning with ORDER BY
+--echo # and PARTITIONING
+--echo #
+CREATE TABLE t1 (a INT, KEY(a))
+ENGINE = InnoDB
+PARTITION BY KEY (a) PARTITIONS 1;
+SELECT 1 FROM t1 WHERE a > (SELECT LAST_INSERT_ID() FROM t1 LIMIT 0)
+ORDER BY a;
+DROP TABLE t1;
+
+--echo #
--echo # Bug#56287: crash when using Partition datetime in sub in query
--echo #
@@ -64,8 +75,8 @@ insert into t1(c2,c3) values ("Test row",'2010-01-01 00:00:00');
SELECT PARTITION_NAME, TABLE_ROWS FROM INFORMATION_SCHEMA.PARTITIONS WHERE TABLE_NAME = 't1' AND TABLE_SCHEMA = 'test';
SELECT count(*) FROM t1 p where c3 in
-(select c3 from t1 t where t.c3 < date '2011-04-26 19:19:44'
- and t.c3 > date '2011-04-26 19:18:44') ;
+(select c3 from t1 t where t.c3 < timestamp '2011-04-26 19:19:44'
+ and t.c3 > timestamp '2011-04-26 19:18:44') ;
DROP TABLE t1;
@@ -75,7 +86,8 @@ DROP TABLE t1;
--echo # SELECT is not detected
--echo #
-SET @old_innodb_thread_concurrency:= @@innodb_thread_concurrency;
+SET @old_innodb_thread_concurrency := @@innodb_thread_concurrency;
+SET @old_innodb_thread_sleep_delay := @@innodb_thread_sleep_delay;
SET GLOBAL innodb_thread_concurrency = 1;
CREATE TABLE t1
@@ -124,6 +136,7 @@ COMMIT;
--connection default
SET GLOBAL innodb_thread_concurrency = @old_innodb_thread_concurrency;
+SET GLOBAL innodb_thread_sleep_delay = @old_innodb_thread_sleep_delay;
DROP TABLE t1;
@@ -572,7 +585,7 @@ CREATE INDEX i1 ON t1 (a);
DROP TABLE t1;
# Before the fix it should show extra file like #sql-2405_2.par
---list_files $MYSQLD_DATADIR/test/ *
+--list_files $MYSQLD_DATADIR/test/ *.par
--disable_parsing
--echo #
@@ -607,7 +620,7 @@ ALTER TABLE t1 REORGANIZE PARTITION pMAX INTO
SHOW WARNINGS;
#Contents of the 'test' database directory:
---list_files $MYSQLD_DATADIR/test
+--list_files $MYSQLD_DATADIR/test/ *.par
disconnect con1;
connection default;
@@ -901,3 +914,85 @@ GROUP BY A.IMORY_ID, A.NUMBER, A.NAME, DATE_FORMAT(A.DATETIME, '%Y-%m-%d')
;
drop table t2, t1;
+
+
+set global default_storage_engine='innodb';
+
+--echo #
+--echo # MDEV-5963: InnoDB: Assertion failure in file row0sel.cc line 2503,
+--echo # Failing assertion: 0 with "key ptr now exceeds key end by 762 bytes"
+--echo # (independent testcase for Oracle Bug#13947868)
+--echo #
+CREATE TABLE t1 (f1 VARCHAR(512) CHARACTER SET utf8) ENGINE=InnoDB;
+INSERT INTO t1 VALUES ('j');
+
+CREATE TABLE t2 (
+ f2 VARCHAR(5) CHARACTER SET latin1,
+ f3 VARCHAR(5) CHARACTER SET utf8,
+ f4 INT,
+ f5 VARCHAR(512) CHARACTER SET utf8,
+ f6 VARCHAR(256) CHARACTER SET utf8,
+ key (f2),
+ key (f3),
+ key (f5)
+) ENGINE=InnoDB PARTITION BY LIST COLUMNS (f4)
+ SUBPARTITION BY KEY(f6) SUBPARTITIONS 4 (
+ PARTITION p0 VALUES IN (1,3,9,null),
+ PARTITION p1 VALUES IN (2,4,0)
+);
+
+INSERT INTO t2 VALUES
+ ('k','s',3,'b','j'),('a','b',NULL,'v','j'),('c','m',9,'t',NULL),
+ ('b','l',9,'b',NULL),('i','y',3,'o','w'),('c','m',NULL,'a','m'),
+ ('f','o',9,'m','w'),('f','q',NULL,'o','a');
+
+CREATE TABLE t3 LIKE t2;
+
+SELECT * FROM t1 INNER JOIN t2 ON ( f5 = f1 );
+INSERT INTO t3 SELECT * FROM t2 WHERE f3 = 'm' AND f2 ='c';
+
+DROP TABLE t1,t2,t3;
+
+set global default_storage_engine=default;
+
+--echo #
+--echo # Bug#13737949: CRASH IN HA_PARTITION::INDEX_INIT
+--echo # Bug#18694052: SERVER CRASH IN HA_PARTITION::INIT_RECORD_PRIORITY_QUEUE
+--echo #
+CREATE TABLE t1
+(a INT,
+ b INT,
+ PRIMARY KEY (a))
+ ENGINE = InnoDB
+ PARTITION BY HASH (a) PARTITIONS 3;
+ START TRANSACTION WITH CONSISTENT SNAPSHOT;
+ --connect (con1, localhost, root,,)
+ --echo # con1
+ ALTER TABLE t1 ADD INDEX idx1 (b);
+ --connection default
+ --echo # con default
+ --error ER_TABLE_DEF_CHANGED
+ SELECT b FROM t1 WHERE b = 0;
+ --error ER_TABLE_DEF_CHANGED
+ SELECT b FROM t1 WHERE b = 0;
+ --disconnect con1
+ DROP TABLE t1;
+
+--echo # Same test without partitioning
+CREATE TABLE t1
+(a INT,
+ b INT,
+ PRIMARY KEY (a))
+ ENGINE = InnoDB;
+START TRANSACTION WITH CONSISTENT SNAPSHOT;
+--echo # con1
+--connect (con1, localhost, root,,)
+ALTER TABLE t1 ADD INDEX idx1 (b);
+--connection default
+--echo # con default
+--error ER_TABLE_DEF_CHANGED
+SELECT b FROM t1 WHERE b = 0;
+--error ER_TABLE_DEF_CHANGED
+SELECT b FROM t1 WHERE b = 0;
+--disconnect con1
+DROP TABLE t1;
diff --git a/mysql-test/t/partition_innodb_plugin.test b/mysql-test/t/partition_innodb_plugin.test
index a951945a87c..d25a4b95bf1 100644
--- a/mysql-test/t/partition_innodb_plugin.test
+++ b/mysql-test/t/partition_innodb_plugin.test
@@ -52,7 +52,7 @@ KEY_BLOCK_SIZE=4
PARTITION BY HASH(id) PARTITIONS 1;
--replace_result #p# #P#
---list_files $MYSQLD_DATADIR/test
+--list_files $MYSQLD_DATADIR/test t1*
SHOW CREATE TABLE t1;
SET GLOBAL innodb_file_per_table = OFF;
@@ -66,18 +66,19 @@ LOCK TABLE t1 WRITE;
--echo # ALTER fails because COMPRESSED/KEY_BLOCK_SIZE
--echo # are incompatible with innodb_file_per_table = OFF;
+--replace_regex / - .*//
--error ER_GET_ERRNO
ALTER TABLE t1 ADD PARTITION PARTITIONS 1;
--replace_result #p# #P#
---list_files $MYSQLD_DATADIR/test
+--list_files $MYSQLD_DATADIR/test t1*
--echo # This SET is not needed to reproduce the bug,
--echo # it is here just to make the test case more realistic
SET innodb_strict_mode = OFF;
ALTER TABLE t1 ADD PARTITION PARTITIONS 2;
--replace_result #p# #P#
---list_files $MYSQLD_DATADIR/test
+--list_files $MYSQLD_DATADIR/test t1*
# really bug#56172
ALTER TABLE t1 REBUILD PARTITION p0;
@@ -144,11 +145,11 @@ UPDATE `t``\""e` SET a = 4 WHERE a = 22;
# NOTE: replace_regex is very slow on match copy/past '(.*)' regex's
# on big texts, removing a lot of text before + after makes it much faster.
#/.*in (.*) trx.*/\1/
---replace_regex /.*RECORD LOCKS space id [0-9]* page no [0-9]* n bits [0-9]* // / trx id .*// /.*index .* in //
+--replace_regex /.*RECORD LOCKS space id [0-9]* page no [0-9]* n bits [0-9]* // / trx id .*// /.*index .* in // /trx table locks [0-9]* // /total table locks [0-9]* //
SHOW ENGINE InnoDB STATUS;
set @old_sql_mode = @@sql_mode;
set sql_mode = 'ANSI_QUOTES';
---replace_regex /.*RECORD LOCKS space id [0-9]* page no [0-9]* n bits [0-9]* // / trx id .*// /.*index .* in //
+--replace_regex /.*RECORD LOCKS space id [0-9]* page no [0-9]* n bits [0-9]* // / trx id .*// /.*index .* in // /trx table locks [0-9]* // /total table locks [0-9]* //
SHOW ENGINE InnoDB STATUS;
set @@sql_mode = @old_sql_mode;
--echo # con1
diff --git a/mysql-test/t/partition_mgm_err.test b/mysql-test/t/partition_mgm_err.test
index f921fa8ebca..0987c427fc7 100644
--- a/mysql-test/t/partition_mgm_err.test
+++ b/mysql-test/t/partition_mgm_err.test
@@ -147,7 +147,7 @@ PARTITION BY KEY (a)
ALTER TABLE t1 ADD PARTITION PARTITIONS 0;
--error ER_TOO_MANY_PARTITIONS_ERROR
-ALTER TABLE t1 ADD PARTITION PARTITIONS 1024;
+ALTER TABLE t1 ADD PARTITION PARTITIONS 8192;
--error ER_ONLY_ON_RANGE_LIST_PARTITION
ALTER TABLE t1 DROP PARTITION x0;
diff --git a/mysql-test/t/partition_myisam.test b/mysql-test/t/partition_myisam.test
index d6b1af1379e..4d083c37b68 100644
--- a/mysql-test/t/partition_myisam.test
+++ b/mysql-test/t/partition_myisam.test
@@ -1,5 +1,4 @@
--- source include/have_partition.inc
-
+--source include/have_partition.inc
--disable_warnings
DROP TABLE IF EXISTS t1, t2;
--enable_warnings
@@ -10,53 +9,88 @@ DROP TABLE IF EXISTS t1, t2;
let $MYSQLD_DATADIR= `SELECT @@datadir`;
-
--echo #
---echo # Bug#50036: Inconsistent errors when using TIMESTAMP
---echo # columns/expressions
-
---echo # Added test with existing TIMESTAMP partitioning (when it was allowed).
-CREATE TABLE t1 (a TIMESTAMP)
-ENGINE = MyISAM
-PARTITION BY HASH (UNIX_TIMESTAMP(a));
-INSERT INTO t1 VALUES ('2000-01-02 03:04:05');
---sorted_result
-SELECT * FROM t1;
-FLUSH TABLES;
---echo # replacing t1.frm with TO_DAYS(a) which was allowed earlier.
---remove_file $MYSQLD_DATADIR/test/t1.frm
---copy_file std_data/parts/t1TIMESTAMP.frm $MYSQLD_DATADIR/test/t1.frm
---echo # Disable warnings, since the result would differ when running with
---echo # --ps-protocol (only for the 'SELECT * FROM t1' statement).
---disable_warnings
---sorted_result
-SELECT * FROM t1;
---enable_warnings
---replace_result MyISAM <curr_engine> InnoDB <curr_engine>
-SHOW CREATE TABLE t1;
-INSERT INTO t1 VALUES ('2001-02-03 04:05:06');
---sorted_result
-SELECT * FROM t1;
-ALTER TABLE t1 ADD PARTITION PARTITIONS 2;
---error ER_WRONG_EXPR_IN_PARTITION_FUNC_ERROR
-ALTER TABLE t1
-PARTITION BY RANGE (TO_DAYS(a))
-(PARTITION p0 VALUES LESS THAN (10000),
- PARTITION p1 VALUES LESS THAN (MAXVALUE));
+--echo # BUG#11933226 - 60681: CHECKSUM TABLE RETURNS 0 FOR PARTITIONED TABLE
+--echo #
+CREATE TABLE t1 (
+ i INT
+)
+ENGINE=MyISAM
+PARTITION BY RANGE (i)
+(PARTITION p3 VALUES LESS THAN (3),
+ PARTITION p5 VALUES LESS THAN (5),
+ PARTITION pMax VALUES LESS THAN MAXVALUE);
+INSERT INTO t1 VALUES (1), (2), (3), (4), (5), (6);
+CHECKSUM TABLE t1;
+ALTER TABLE t1 CHECKSUM = 1;
+CHECKSUM TABLE t1 EXTENDED;
+--echo # Before patch this returned 0!
+CHECKSUM TABLE t1;
SHOW CREATE TABLE t1;
-CREATE TABLE t2 LIKE t1;
-SHOW CREATE TABLE t2;
-DROP TABLE t2;
-CREATE TABLE t2 SELECT * FROM t1;
-DROP TABLE t2;
-ALTER TABLE t1 PARTITION BY HASH (UNIX_TIMESTAMP(a));
+DROP TABLE t1;
+
+--echo # Same test without partitioning
+CREATE TABLE t1 (
+ i INT
+) ENGINE=MyISAM;
SHOW CREATE TABLE t1;
-ALTER TABLE t1 ADD PARTITION PARTITIONS 2;
+INSERT INTO t1 VALUES (1), (2), (3), (4), (5), (6);
+CHECKSUM TABLE t1;
+ALTER TABLE t1 CHECKSUM = 1;
+CHECKSUM TABLE t1 EXTENDED;
+CHECKSUM TABLE t1;
SHOW CREATE TABLE t1;
---sorted_result
-SELECT * FROM t1;
DROP TABLE t1;
+#
+# Disabled by WL#946: binary format for timestamp column is not compatible.
+# So the trick with replacing FRM file does not work any more.
+#--echo #
+#--echo # Bug#50036: Inconsistent errors when using TIMESTAMP
+#--echo # columns/expressions
+#
+#--echo # Added test with existing TIMESTAMP partitioning (when it was allowed).
+#CREATE TABLE t1 (a TIMESTAMP)
+#ENGINE = MyISAM
+#PARTITION BY HASH (UNIX_TIMESTAMP(a));
+#INSERT INTO t1 VALUES ('2000-01-02 03:04:05');
+#--sorted_result
+#SELECT * FROM t1;
+#FLUSH TABLES;
+#--echo # replacing t1.frm with TO_DAYS(a) which was allowed earlier.
+#--remove_file $MYSQLD_DATADIR/test/t1.frm
+#--copy_file std_data/parts/t1TIMESTAMP.frm $MYSQLD_DATADIR/test/t1.frm
+#--echo # Disable warnings, since the result would differ when running with
+#--echo # --ps-protocol (only for the 'SELECT * FROM t1' statement).
+#--disable_warnings
+#--sorted_result
+#SELECT * FROM t1;
+#--enable_warnings
+#--replace_result MyISAM <curr_engine> InnoDB <curr_engine>
+#SHOW CREATE TABLE t1;
+#INSERT INTO t1 VALUES ('2001-02-03 04:05:06');
+#--sorted_result
+#SELECT * FROM t1;
+#SELECT a, hex(weight_string(a)) FROM t1;
+#ALTER TABLE t1 ADD PARTITION PARTITIONS 2;
+#--error ER_WRONG_EXPR_IN_PARTITION_FUNC_ERROR
+#ALTER TABLE t1
+#PARTITION BY RANGE (TO_DAYS(a))
+#(PARTITION p0 VALUES LESS THAN (10000),
+# PARTITION p1 VALUES LESS THAN (MAXVALUE));
+#SHOW CREATE TABLE t1;
+#CREATE TABLE t2 LIKE t1;
+#SHOW CREATE TABLE t2;
+#DROP TABLE t2;
+#CREATE TABLE t2 SELECT * FROM t1;
+#DROP TABLE t2;
+#ALTER TABLE t1 PARTITION BY HASH (UNIX_TIMESTAMP(a));
+#SHOW CREATE TABLE t1;
+#ALTER TABLE t1 ADD PARTITION PARTITIONS 2;
+#SHOW CREATE TABLE t1;
+#--sorted_result
+#SELECT * FROM t1;
+#DROP TABLE t1;
--echo #
--echo # Bug#31931: Mix of handlers error message
@@ -87,10 +121,12 @@ FLUSH TABLES;
CHECK TABLE t1;
--error ER_FAILED_READ_FROM_PAR_FILE
SELECT * FROM t1;
---echo # Note that we will remove the frm file when we detect that
---echo # .par file has been deleted.
---error ER_BAD_TABLE_ERROR
+--echo # Note that it is currently impossible to drop a partitioned table
+--echo # without the .par file
+--replace_result "Not owner" "Operation not permitted"
+--error ER_GET_ERRNO
DROP TABLE t1;
+--remove_file $MYSQLD_DATADIR/test/t1.frm
--remove_file $MYSQLD_DATADIR/test/t1#P#p0.MYI
--remove_file $MYSQLD_DATADIR/test/t1#P#p0.MYD
@@ -201,3 +237,19 @@ SELECT * FROM t2;
DROP VIEW v;
DROP TABLE t2;
DROP TABLE t1;
+
+--echo #
+--echo # bug#11760213-52599: ALTER TABLE REMOVE PARTITIONING ON NON-PARTITIONED
+--echo # TABLE CORRUPTS MYISAM
+--disable_warnings
+DROP TABLE if exists `t1`;
+--enable_warnings
+CREATE TABLE `t1`(`a` INT)ENGINE=myisam;
+ALTER TABLE `t1` ADD COLUMN `b` INT;
+CREATE UNIQUE INDEX `i1` ON `t1`(`b`);
+CREATE UNIQUE INDEX `i2` ON `t1`(`a`);
+ALTER TABLE `t1` ADD PRIMARY KEY (`a`);
+--error ER_PARTITION_MGMT_ON_NONPARTITIONED
+ALTER TABLE `t1` REMOVE PARTITIONING;
+CHECK TABLE `t1` EXTENDED;
+DROP TABLE t1;
diff --git a/mysql-test/t/partition_not_blackhole.test b/mysql-test/t/partition_not_blackhole.test
index 7352aeaa230..fe7452432b2 100644
--- a/mysql-test/t/partition_not_blackhole.test
+++ b/mysql-test/t/partition_not_blackhole.test
@@ -19,7 +19,10 @@ SHOW TABLES;
--replace_result $MYSQLD_DATADIR ./
--error ER_NOT_FORM_FILE
SHOW CREATE TABLE t1;
---error ER_BAD_TABLE_ERROR
+
+# The replace is needed for Solaris
+--replace_result "Not owner" "Operation not permitted"
+--error ER_GET_ERRNO
DROP TABLE t1;
--list_files $MYSQLD_DATADIR/test t1*
--remove_file $MYSQLD_DATADIR/test/t1.frm
diff --git a/mysql-test/t/partition_not_windows.test b/mysql-test/t/partition_not_windows.test
index 333e12e2b16..429329c79bb 100644
--- a/mysql-test/t/partition_not_windows.test
+++ b/mysql-test/t/partition_not_windows.test
@@ -199,7 +199,7 @@ DROP TABLE example;
--rmdir $MYSQLTEST_VARDIR/p2Index
--rmdir $MYSQLTEST_VARDIR/p3Index
---error ER_CANT_CREATE_TABLE,1
+--error 1
CREATE TABLE `example` (
`ID_EXAMPLE` int(10) unsigned NOT NULL AUTO_INCREMENT,
`DESCRIPTION` varchar(30) NOT NULL,
diff --git a/mysql-test/t/partition_pruning.test b/mysql-test/t/partition_pruning.test
index a34ffe7b365..9d72e9c0d01 100644
--- a/mysql-test/t/partition_pruning.test
+++ b/mysql-test/t/partition_pruning.test
@@ -622,7 +622,6 @@ insert into t3 values (5),(15);
explain partitions select * from t3 where a=11;
explain partitions select * from t3 where a=10;
explain partitions select * from t3 where a=20;
-
explain partitions select * from t3 where a=30;
# LIST(expr) partitioning
@@ -1518,3 +1517,22 @@ and dept_id in (select dept_id from t2 where COMPANY_ID = 1000);
drop table t1,t2;
+--echo #
+--echo # MDEV-9505: Valgrind failure in SEL_ARG::store_min,find_used_partitions,...
+--echo #
+create table t1 (a int, b char(10), c varchar(5), d int)
+partition by range columns(a,b,c)
+subpartition by key (c,d)
+subpartitions 3
+( partition p0 values less than (1,'abc','abc'),
+ partition p1 values less than (2,'abc','abc'),
+ partition p2 values less than (3,'abc','abc'),
+ partition p3 values less than (4,'abc','abc')
+);
+
+insert into t1 values (1,'a','b',1),(2,'a','b',2),(3,'a','b',3);
+select * from t1 where (a = 1 AND b < 'd' AND (c = 'b' OR (c = 'c' AND d = 1)) OR
+ (a = 1 AND b >= 'a' AND (c = 'c' OR (c = 'd' AND d = 2))));
+drop table t1;
+
+
diff --git a/mysql-test/t/partition_symlink.test b/mysql-test/t/partition_symlink.test
index 5fdde8e0abc..f2e3eba5de6 100644
--- a/mysql-test/t/partition_symlink.test
+++ b/mysql-test/t/partition_symlink.test
@@ -12,6 +12,48 @@ DROP TABLE IF EXISTS t1;
DROP DATABASE IF EXISTS mysqltest2;
-- enable_warnings
+--echo #
+--echo # Test for WL#4445: EXCHANGE PARTITION
+--echo #
+--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
+eval CREATE TABLE t1 (a INT)
+ENGINE = MyISAM
+PARTITION BY LIST (a)
+(PARTITION p0 VALUES IN (0)
+ DATA DIRECTORY '$MYSQLTEST_VARDIR/tmp'
+ INDEX DIRECTORY '$MYSQLTEST_VARDIR/tmp',
+ PARTITION p1 VALUES IN (1)
+ DATA DIRECTORY '$MYSQLTEST_VARDIR/tmp'
+ INDEX DIRECTORY '$MYSQLTEST_VARDIR/tmp',
+ PARTITION p2 VALUES IN (2));
+
+--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
+eval CREATE TABLE t2 (a INT)
+ENGINE = MyISAM
+ DATA DIRECTORY '$MYSQLTEST_VARDIR/tmp'
+ INDEX DIRECTORY '$MYSQLTEST_VARDIR/tmp';
+
+--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
+SHOW CREATE TABLE t1;
+--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
+SHOW CREATE TABLE t2;
+INSERT INTO t1 VALUES (0), (1), (2);
+--error ER_TABLES_DIFFERENT_METADATA
+ALTER TABLE t1 EXCHANGE PARTITION p0 WITH TABLE t2;
+--error ER_TABLES_DIFFERENT_METADATA
+ALTER TABLE t1 EXCHANGE PARTITION p2 WITH TABLE t2;
+--sorted_result
+SELECT * FROM t2;
+DROP TABLE t1, t2;
+# skipped because of bug#52354
+#CREATE TABLE t1 LIKE t2;
+#ALTER TABLE t1 PARTITION BY LIST (a)
+#(PARTITION p0 VALUES in (0));
+#--error ER_TABLES_DIFFERENT_METADATA
+#ALTER TABLE t1 EXCHANGE PARTITION p2 WITH TABLE t2;
+#SELECT * FROM t2;
+#DROP TABLE t1, t2;
+
#
# Bug 32091: Security breach via directory changes
#
diff --git a/mysql-test/t/partition_truncate.test b/mysql-test/t/partition_truncate.test
index 165213d204c..62ed548808f 100644
--- a/mysql-test/t/partition_truncate.test
+++ b/mysql-test/t/partition_truncate.test
@@ -11,7 +11,7 @@ partition by list (a)
(partition p1 values in (0));
--error ER_WRONG_PARTITION_NAME
alter table t1 truncate partition p1,p1;
---error ER_WRONG_PARTITION_NAME
+--error ER_UNKNOWN_PARTITION
alter table t1 truncate partition p0;
drop table t1;
diff --git a/mysql-test/t/plugin.test b/mysql-test/t/plugin.test
index c61a9239218..ec7117bb832 100644
--- a/mysql-test/t/plugin.test
+++ b/mysql-test/t/plugin.test
@@ -6,7 +6,7 @@ DROP TABLE t1;
INSTALL PLUGIN example SONAME 'ha_example';
--replace_regex /\.dll/.so/
---error 1125
+--error ER_PLUGIN_INSTALLED
INSTALL PLUGIN EXAMPLE SONAME 'ha_example';
UNINSTALL PLUGIN example;
@@ -16,12 +16,13 @@ INSTALL SONAME 'ha_example';
--replace_regex /\.dll/.so/
--query_vertical select * from information_schema.plugins where plugin_library like 'ha_example%'
-CREATE TABLE t1(a int) ENGINE=EXAMPLE;
+CREATE TABLE t1 (a int) ENGINE=EXAMPLE;
+CREATE TABLE t2 (a int) ENGINE=EXAMPLE;
+FLUSH TABLES;
# Let's do some advanced ops with the example engine :)
SELECT * FROM t1;
-
# a couple of tests for variables
set global example_ulong_var=500;
set global example_enum_var= e1;
@@ -32,12 +33,26 @@ show variables like 'example%';
select @@session.example_int_var;
UNINSTALL SONAME 'ha_example';
+
+# the engine is NOT uninstalled yet,
+# because the table `t1` is open, sitting in the table defintion cache
+
--replace_column 5 #
--replace_regex /\.dll/.so/
--query_vertical select * from information_schema.plugins where plugin_library like 'ha_example%'
-
DROP TABLE t1;
+# now the engine IS unloaded
+# and the table `t2` belongs to an unknown engine
+
+--replace_column 5 #
+--replace_regex /\.dll/.so/
+--query_vertical select * from information_schema.plugins where plugin_library like 'ha_example%'
+--error ER_UNKNOWN_STORAGE_ENGINE
+SELECT * FROM t2;
+DROP TABLE t2;
+
+
--error 1305
UNINSTALL PLUGIN EXAMPLE;
@@ -109,7 +124,7 @@ SET @OLD_SQL_MODE=@@SQL_MODE;
SET SQL_MODE='IGNORE_BAD_TABLE_OPTIONS';
--echo #illegal value fixed
-CREATE TABLE t1 (a int) ENGINE=example ULL=10000000000000000000 one_or_two='ttt' YESNO=SSS;
+CREATE TABLE t1 (a int, b int) ENGINE=example ULL=10000000000000000000 one_or_two='ttt' YESNO=SSS;
show create table t1;
--echo #alter table
@@ -117,6 +132,8 @@ alter table t1 ULL=10000000;
show create table t1;
alter table t1 change a a int complex='c,c,c';
show create table t1;
+alter table t1 one_or_two=two;
+show create table t1;
drop table t1;
--echo #illegal value error
@@ -132,6 +149,7 @@ CREATE TABLE t1 (a int) ENGINE=example ULL=1e2;
CREATE TABLE t1 (a int) ENGINE=example ULL=0x1234;
SHOW CREATE TABLE t1;
+SET example_varopt_default=33; # does not affect varopt of t1
select create_options from information_schema.tables where table_schema='test' and table_name='t1';
@@ -140,6 +158,16 @@ SHOW CREATE TABLE t1;
DROP TABLE t1;
+create table t1 (a int) engine=example; # varopt is 10
+show create table t1;
+drop table t1;
+
+create table t1 (a int) engine=example varopt=15;
+show create table t1;
+alter table t1 varopt=default;
+show create table t1;
+drop table t1;
+
SET @@SQL_MODE=@OLD_SQL_MODE;
#
@@ -224,3 +252,16 @@ select plugin_name from information_schema.plugins where plugin_library like 'ha
uninstall soname 'ha_example';
select plugin_name from information_schema.plugins where plugin_library like 'ha_example%';
+
+--echo #
+--echo # MDEV-5309 - RENAME TABLE does not check for existence of the table's
+--echo # engine
+--echo #
+INSTALL PLUGIN example SONAME 'ha_example';
+CREATE TABLE t1(a INT) ENGINE=EXAMPLE;
+SELECT * FROM t1;
+FLUSH TABLES;
+UNINSTALL PLUGIN example;
+--error ER_NO_SUCH_TABLE
+RENAME TABLE t1 TO t2;
+DROP TABLE t1;
diff --git a/mysql-test/t/plugin_auth.test b/mysql-test/t/plugin_auth.test
index 815ec72dfe6..5e620654e0a 100644
--- a/mysql-test/t/plugin_auth.test
+++ b/mysql-test/t/plugin_auth.test
@@ -1,6 +1,7 @@
--source include/have_plugin_auth.inc
--source include/not_embedded.inc
--source include/mysql_upgrade_preparation.inc
+--source include/have_innodb.inc
query_vertical SELECT PLUGIN_STATUS, PLUGIN_TYPE, PLUGIN_DESCRIPTION
FROM INFORMATION_SCHEMA.PLUGINS WHERE PLUGIN_NAME='test_plugin_server';
@@ -168,7 +169,7 @@ connection grant_plug_dest_con;
--echo ## testing what an ordinary user can grant
--echo this should fail : no rights to grant all
--error ER_ACCESS_DENIED_NO_PASSWORD_ERROR
-GRANT PROXY ON ''@'' TO grant_plug;
+GRANT PROXY ON ''@'%%' TO grant_plug;
--echo this should fail : not the same user
--error ER_ACCESS_DENIED_NO_PASSWORD_ERROR
@@ -211,11 +212,11 @@ disconnect grant_plug_dest_con;
--echo # test what root can grant
--echo should work : root has PROXY to all users
-GRANT PROXY ON ''@'' TO grant_plug;
-REVOKE PROXY ON ''@'' FROM grant_plug;
+GRANT PROXY ON ''@'%%' TO grant_plug;
+REVOKE PROXY ON ''@'%%' FROM grant_plug;
--echo should work : root has PROXY to all users
-GRANT PROXY ON ''@'' TO proxy_admin IDENTIFIED BY 'test'
+GRANT PROXY ON ''@'%%' TO proxy_admin IDENTIFIED BY 'test'
WITH GRANT OPTION;
--echo need USAGE : PROXY doesn't contain it.
@@ -225,7 +226,7 @@ connect (proxy_admin_con,localhost,proxy_admin,test);
connection proxy_admin_con;
--echo in proxy_admin_con;
---echo should work : proxy_admin has proxy to ''@''
+--echo should work : proxy_admin has proxy to ''@'%%'
GRANT PROXY ON future_user TO grant_plug;
connection default;
@@ -317,9 +318,9 @@ DROP USER plug_dest;
--echo #
GRANT ALL PRIVILEGES ON *.* TO power_user;
-GRANT USAGE ON anonymous_db.* TO ''@''
+GRANT USAGE ON anonymous_db.* TO ''@'%%'
IDENTIFIED WITH 'test_plugin_server' AS 'power_user';
-GRANT PROXY ON power_user TO ''@'';
+GRANT PROXY ON power_user TO ''@'%%';
CREATE DATABASE confidential_db;
connect(plug_con,localhost, test_login_user, power_user, confidential_db);
@@ -329,24 +330,23 @@ connection default;
disconnect plug_con;
DROP USER power_user;
-DROP USER ''@'';
+DROP USER ''@'%%';
DROP DATABASE confidential_db;
--echo # Test case #2 (crash with double grant proxy)
-CREATE USER ''@'' IDENTIFIED WITH 'test_plugin_server' AS 'standard_user';
+CREATE USER ''@'%%' IDENTIFIED WITH 'test_plugin_server' AS 'standard_user';
CREATE USER standard_user;
CREATE DATABASE shared;
GRANT ALL PRIVILEGES ON shared.* TO standard_user;
-GRANT PROXY ON standard_user TO ''@'';
+GRANT PROXY ON standard_user TO ''@'%%';
--echo #should not crash
-GRANT PROXY ON standard_user TO ''@'';
+GRANT PROXY ON standard_user TO ''@'%%';
-DROP USER ''@'';
+DROP USER ''@'%%';
DROP USER standard_user;
DROP DATABASE shared;
-
--echo #
--echo # Bug #57551 : Live upgrade fails between 5.1.52 -> 5.5.7-rc
--echo #
diff --git a/mysql-test/t/plugin_auth_qa_1.test b/mysql-test/t/plugin_auth_qa_1.test
index 93e471da25d..55fef4254e1 100644
--- a/mysql-test/t/plugin_auth_qa_1.test
+++ b/mysql-test/t/plugin_auth_qa_1.test
@@ -184,7 +184,7 @@ DROP USER new_user,new_dest,plug_dest;
--echo ========== test 2, 2.1, 2.2 ================================
-CREATE USER ''@'' IDENTIFIED WITH test_plugin_server AS 'proxied_user';
+CREATE USER ''@'%%' IDENTIFIED WITH test_plugin_server AS 'proxied_user';
CREATE USER proxied_user IDENTIFIED BY 'proxied_user_passwd';
--sorted_result
SELECT user,plugin,authentication_string FROM mysql.user WHERE user != 'root';
@@ -202,7 +202,7 @@ disconnect proxy_con;
--error ER_ACCESS_DENIED_ERROR : this should fail : no grant
connect(proxy_con,localhost,proxy_user,proxied_user);
--enable_query_log
-GRANT PROXY ON proxied_user TO ''@'';
+GRANT PROXY ON proxied_user TO ''@'%%';
--echo connect(proxy_con,localhost,proxied_user,proxied_user_passwd);
connect(proxy_con,localhost,proxied_user,proxied_user_passwd);
SELECT USER(),CURRENT_USER();
@@ -219,9 +219,9 @@ SELECT @@proxy_user;
connection default;
--echo disconnect proxy_con;
disconnect proxy_con;
-DROP USER ''@'',proxied_user;
+DROP USER ''@'%%',proxied_user;
#
-GRANT ALL PRIVILEGES ON test_user_db.* TO ''@''
+GRANT ALL PRIVILEGES ON test_user_db.* TO ''@'%%'
IDENTIFIED WITH test_plugin_server AS 'proxied_user';
CREATE USER proxied_user IDENTIFIED BY 'proxied_user_passwd';
--sorted_result
@@ -239,7 +239,7 @@ disconnect proxy_con;
--error ER_ACCESS_DENIED_ERROR : this should fail : no grant
connect(proxy_con,localhost,proxy_user,proxied_user);
--enable_query_log
-GRANT PROXY ON proxied_user TO ''@'';
+GRANT PROXY ON proxied_user TO ''@'%%';
--echo connect(proxy_con,localhost,proxied_user,proxied_user_passwd);
connect(proxy_con,localhost,proxied_user,proxied_user_passwd);
SELECT USER(),CURRENT_USER();
@@ -255,19 +255,19 @@ SELECT @@proxy_user;
connection default;
--echo disconnect proxy_con;
disconnect proxy_con;
-DROP USER ''@'',proxied_user;
+DROP USER ''@'%%',proxied_user;
#
-CREATE USER ''@'' IDENTIFIED WITH test_plugin_server AS 'proxied_user';
+CREATE USER ''@'%%' IDENTIFIED WITH test_plugin_server AS 'proxied_user';
CREATE USER proxied_user_1 IDENTIFIED BY 'proxied_user_1_pwd';
CREATE USER proxied_user_2 IDENTIFIED BY 'proxied_user_2_pwd';
CREATE USER proxied_user_3 IDENTIFIED BY 'proxied_user_3_pwd';
CREATE USER proxied_user_4 IDENTIFIED BY 'proxied_user_4_pwd';
CREATE USER proxied_user_5 IDENTIFIED BY 'proxied_user_5_pwd';
-GRANT PROXY ON proxied_user_1 TO ''@'';
-GRANT PROXY ON proxied_user_2 TO ''@'';
-GRANT PROXY ON proxied_user_3 TO ''@'';
-GRANT PROXY ON proxied_user_4 TO ''@'';
-GRANT PROXY ON proxied_user_5 TO ''@'';
+GRANT PROXY ON proxied_user_1 TO ''@'%%';
+GRANT PROXY ON proxied_user_2 TO ''@'%%';
+GRANT PROXY ON proxied_user_3 TO ''@'%%';
+GRANT PROXY ON proxied_user_4 TO ''@'%%';
+GRANT PROXY ON proxied_user_5 TO ''@'%%';
--sorted_result
SELECT user,plugin,authentication_string FROM mysql.user WHERE user != 'root';
--echo connect(proxy_con_1,localhost,proxied_user_1,'proxied_user_1_pwd');
@@ -312,7 +312,7 @@ disconnect proxy_con_3;
disconnect proxy_con_4;
--echo disconnect proxy_con_5;
disconnect proxy_con_5;
-DROP USER ''@'',proxied_user_1,proxied_user_2,proxied_user_3,proxied_user_4,proxied_user_5;
+DROP USER ''@'%%',proxied_user_1,proxied_user_2,proxied_user_3,proxied_user_4,proxied_user_5;
--echo ========== test 3 ==========================================
diff --git a/mysql-test/t/plugin_auth_qa_2-master.opt b/mysql-test/t/plugin_auth_qa_2-master.opt
index 1a023ad271c..6429a4458aa 100644
--- a/mysql-test/t/plugin_auth_qa_2-master.opt
+++ b/mysql-test/t/plugin_auth_qa_2-master.opt
@@ -1 +1 @@
---plugin-load=$QA_AUTH_INTERFACE_SO
+--plugin-load-add=$QA_AUTH_INTERFACE_SO
diff --git a/mysql-test/t/plugin_auth_qa_3-master.opt b/mysql-test/t/plugin_auth_qa_3-master.opt
index 5d53a9dbe04..db4629aa09d 100644
--- a/mysql-test/t/plugin_auth_qa_3-master.opt
+++ b/mysql-test/t/plugin_auth_qa_3-master.opt
@@ -1 +1 @@
---plugin-load=$QA_AUTH_SERVER_SO
+--plugin-load-add=$QA_AUTH_SERVER_SO
diff --git a/mysql-test/t/plugin_load-master.opt b/mysql-test/t/plugin_load-master.opt
deleted file mode 100644
index aadeef2fb66..00000000000
--- a/mysql-test/t/plugin_load-master.opt
+++ /dev/null
@@ -1,2 +0,0 @@
---plugin-load=EXAMPLE=$HA_EXAMPLE_SO
---loose-plugin-example-enum-var=e2
diff --git a/mysql-test/t/plugin_load.opt b/mysql-test/t/plugin_load.opt
new file mode 100644
index 00000000000..aeeb2e4eb7d
--- /dev/null
+++ b/mysql-test/t/plugin_load.opt
@@ -0,0 +1,6 @@
+--plugin-load-add=$DIALOG_EXAMPLES_SO
+--plugin-load=$LIBDAEMON_EXAMPLE_SO
+--plugin-load-add=EXAMPLE=$HA_EXAMPLE_SO
+--plugin-load-add=$MYPLUGLIB_SO
+--plugin-load-add=$HA_EXAMPLE_SO
+--loose-plugin-example-enum-var=e2
diff --git a/mysql-test/t/plugin_load.test b/mysql-test/t/plugin_load.test
index 97b2afbe219..fdae622645a 100644
--- a/mysql-test/t/plugin_load.test
+++ b/mysql-test/t/plugin_load.test
@@ -1,4 +1,18 @@
--source include/not_windows_embedded.inc
--source include/have_example_plugin.inc
+if (!$MYPLUGLIB_SO) {
+ --echo needs SIMPLE_PARSER plugin
+}
+if (!$LIBDAEMON_EXAMPLE_SO) {
+ --echo needs DAEMON_EXAMPLE plugin
+}
+if (!$DIALOG_EXAMPLES_SO) {
+ --echo needs dialog examples plugins
+}
SELECT @@global.example_enum_var = 'e2';
+
+--sorted_result
+select plugin_name, plugin_status from information_schema.plugins
+ where plugin_name in ('SIMPLE_PARSER', 'EXAMPLE',
+ 'DAEMON_EXAMPLE', 'TWO_QUESTIONS', 'THREE_ATTEMPTS');
diff --git a/mysql-test/t/plugin_load_option-master.opt b/mysql-test/t/plugin_load_option.opt
index a5a12e7b0d6..be9bc9d5487 100644
--- a/mysql-test/t/plugin_load_option-master.opt
+++ b/mysql-test/t/plugin_load_option.opt
@@ -1,2 +1,2 @@
---plugin-load=EXAMPLE=$HA_EXAMPLE_SO
+--plugin-load-add=EXAMPLE=$HA_EXAMPLE_SO
--loose-plugin-example=FORCE_PLUS_PERMANENT
diff --git a/mysql-test/t/ps.test b/mysql-test/t/ps.test
index ea67e1074f9..d60edf4f6a0 100644
--- a/mysql-test/t/ps.test
+++ b/mysql-test/t/ps.test
@@ -677,8 +677,8 @@ insert into t2 values ("1", "1", "sup", "0"), ("2", "1", "sup", "1"),
create table t3 (
id int(11) not null default '0',
- preceeding_id int(11) not null default '0',
- primary key (id,preceeding_id)
+ preceding_id int(11) not null default '0',
+ primary key (id,preceding_id)
);
create table t4 (
@@ -692,7 +692,7 @@ insert into t4 values("nicke", "imp");
prepare stmt from
'select distinct t1.partner_id
from t1 left join t3 on t1.id = t3.id
- left join t1 pp on pp.id = t3.preceeding_id
+ left join t1 pp on pp.id = t3.preceding_id
where
exists (
select *
diff --git a/mysql-test/t/ps_1general.test b/mysql-test/t/ps_1general.test
index 7b7b87ef851..0fa339229d1 100644
--- a/mysql-test/t/ps_1general.test
+++ b/mysql-test/t/ps_1general.test
@@ -582,10 +582,7 @@ drop table t2;
# cases derived from client_test.c: test_rename()
prepare stmt1 from ' rename table t5 to t6, t7 to t8 ' ;
create table t5 (a int) ;
-# rename must fail, t7 does not exist
-# Clean up the filename here because embedded server reports whole path
---replace_result $MYSQLTEST_VARDIR . mysqld.1/data/ '' t7.frm t7
---error ER_FILE_NOT_FOUND
+--error ER_NO_SUCH_TABLE
execute stmt1 ;
create table t7 (a int) ;
# rename, t5 -> t6 and t7 -> t8
diff --git a/mysql-test/t/ps_ddl.test b/mysql-test/t/ps_ddl.test
index fb194c6b5b9..21355ca42b7 100644
--- a/mysql-test/t/ps_ddl.test
+++ b/mysql-test/t/ps_ddl.test
@@ -353,23 +353,22 @@ select * from t2;
drop view v1;
create view v1 as select a from t2;
set @var=8;
---echo # XXX: bug, the SQL statement in the trigger is still
---echo # pointing at table 't3', since the view was expanded
---echo # at first statement execution.
---echo # Since the view definition is inlined in the statement
---echo # at prepare, changing the view definition does not cause
---echo # repreparation.
---echo # Repreparation of the main statement doesn't cause repreparation
---echo # of trigger statements.
-execute stmt using @var;
-call p_verify_reprepare_count(0);
+--echo # View in the INSERT-statement in the trigger is still pointing to
+--echo # table 't3', because the trigger hasn't noticed the change
+--echo # in view definition. This will be fixed by WL#4179.
--echo #
---echo # Sic: the insert went into t3, even though the view now
---echo # points at t2. This is because neither the merged view
---echo # nor its prelocking list are affected by view DDL
---echo # The binary log is of course wrong, since it is not
---echo # using prepared statements
+--echo # The prepared INSERT-statement however does notice the change,
+--echo # but repreparation of the main statement doesn't cause repreparation
+--echo # of trigger statements.
--echo #
+--echo # The following EXECUTE results in ER_NO_SUCH_TABLE (t3) error, because
+--echo # pre-locking list of the prepared statement has been changed
+--echo # (the prepared statement has noticed the meta-data change),
+--echo # but the trigger still tries to deal with 't3', which is not opened.
+--echo # That's why '8' is not inserted neither into 't2', nor into 't3'.
+--error ER_NO_SUCH_TABLE
+execute stmt using @var;
+call p_verify_reprepare_count(1);
select * from t2;
select * from t3;
flush table t1;
@@ -736,21 +735,136 @@ drop view t1;
create view t1 as select a, 2*a as b, 5*a as c from t2;
select * from t1;
---echo # Currently a different result from conventional statements.
---echo # A view is inlined once at prepare, later on view DDL
---echo # does not affect prepared statement and it is not re-prepared.
---echo # This is reported in Bug#36002 Prepared statements: if a view
---echo # used in a statement is replaced, bad data
+--echo # This is actually a test case for Bug#11748352 (36002 Prepared
+--echo # statements: if a view used in a statement is replaced, bad data).
execute stmt;
-call p_verify_reprepare_count(0);
+call p_verify_reprepare_count(1);
+
flush table t2;
+
+execute stmt;
+call p_verify_reprepare_count(1);
+
+--echo # Check that we properly handle ALTER VIEW statements.
+execute stmt;
+call p_verify_reprepare_count(0);
+alter view t1 as select a, 3*a as b, 4*a as c from t2;
execute stmt;
call p_verify_reprepare_count(1);
+execute stmt;
+call p_verify_reprepare_count(0);
+execute stmt;
+call p_verify_reprepare_count(0);
+select * from t1;
+
+--echo # Check that DROP & CREATE is properly handled under LOCK TABLES.
+drop view t1;
+flush tables; # empty TDC
+create view t1 as select a, 5*a as b, 6*a as c from t2;
+lock tables t1 read, t2 read;
+execute stmt;
+call p_verify_reprepare_count(1);
+execute stmt;
+call p_verify_reprepare_count(0);
+execute stmt;
+call p_verify_reprepare_count(0);
+unlock tables;
+--echo # ... and once again...
+drop view t1;
+create view t1 as select a, 6*a as b, 7*a as c from t2;
+lock tables t1 read, t2 read;
+execute stmt;
+call p_verify_reprepare_count(1);
+execute stmt;
+call p_verify_reprepare_count(0);
+execute stmt;
+call p_verify_reprepare_count(0);
+unlock tables;
+
+--echo # Check that ALTER VIEW is properly handled under LOCK TABLES.
+alter view t1 as select a, 7*a as b, 8*a as c from t2;
+lock tables t1 read, t2 read;
+execute stmt;
+call p_verify_reprepare_count(1);
+execute stmt;
+call p_verify_reprepare_count(0);
+execute stmt;
+call p_verify_reprepare_count(0);
+unlock tables;
drop table t2;
drop view t1;
deallocate prepare stmt;
+--echo # Check that DROP & CREATE is properly handled under LOCK TABLES when
+--echo # LOCK TABLES does not contain the complete set of views.
+
+create table t1(a int);
+insert into t1 values (1), (2), (3);
+
+create view v1 as select a from t1;
+
+lock tables t1 read, v1 read;
+
+prepare stmt from 'select * from v1';
+
+execute stmt;
+call p_verify_reprepare_count(0);
+
+execute stmt;
+call p_verify_reprepare_count(0);
+
+unlock tables;
+
+drop view v1;
+create view v1 as select 2*a from t1;
+
+# Miss v1.
+lock tables t1 read;
+
+--error ER_TABLE_NOT_LOCKED
+execute stmt;
+
+unlock tables;
+
+drop table t1;
+drop view v1;
+deallocate prepare stmt;
+
+--echo # Check that ALTER VIEW is properly handled under LOCK TABLES when
+--echo # LOCK TABLES does not contain the complete set of views.
+
+create table t1(a int);
+insert into t1 values (1), (2), (3);
+
+create view v1 as select a from t1;
+
+lock tables t1 read, v1 read;
+
+prepare stmt from 'select * from v1';
+
+execute stmt;
+call p_verify_reprepare_count(0);
+
+execute stmt;
+call p_verify_reprepare_count(0);
+
+unlock tables;
+
+alter view v1 as select 2*a from t1;
+
+# Miss v1.
+lock tables t1 read;
+
+--error ER_TABLE_NOT_LOCKED
+execute stmt;
+
+unlock tables;
+
+drop table t1;
+drop view v1;
+deallocate prepare stmt;
+
--echo =====================================================================
--echo Part 18: VIEW -> VIEW (VIEW dependencies) transitions
--echo =====================================================================
@@ -819,10 +933,10 @@ drop view v2;
create view v2 as select a from t2;
execute stmt;
execute stmt;
-call p_verify_reprepare_count(0);
+call p_verify_reprepare_count(1);
flush table t1;
execute stmt;
-call p_verify_reprepare_count(1);
+call p_verify_reprepare_count(0);
execute stmt;
--echo # Test 18-d: dependent TABLE has changed
drop view v2;
@@ -1496,7 +1610,7 @@ call p_verify_reprepare_count(0);
# Base table with name of table to be created exists
--error ER_TABLE_EXISTS_ERROR
execute stmt;
-call p_verify_reprepare_count(1);
+call p_verify_reprepare_count(0);
--error ER_TABLE_EXISTS_ERROR
execute stmt;
call p_verify_reprepare_count(0);
@@ -1508,7 +1622,7 @@ execute stmt;
call p_verify_reprepare_count(0);
--error ER_TABLE_EXISTS_ERROR
execute stmt;
-call p_verify_reprepare_count(1);
+call p_verify_reprepare_count(0);
drop temporary table t2;
--error ER_TABLE_EXISTS_ERROR
execute stmt;
@@ -1527,7 +1641,7 @@ drop table t2;
create view t2 as select 1;
--error ER_TABLE_EXISTS_ERROR,9999
execute stmt;
-call p_verify_reprepare_count(1);
+call p_verify_reprepare_count(0);
--error ER_TABLE_EXISTS_ERROR,9999
execute stmt;
call p_verify_reprepare_count(0);
@@ -2102,3 +2216,46 @@ drop procedure if exists p1;
drop function if exists f1;
drop view if exists v1, v2;
--enable_warnings
+
+
+--echo #
+--echo # Additional coverage for refactoring which was made as part of work
+--echo # on bug '27480: Extend CREATE TEMPORARY TABLES privilege to allow
+--echo # temp table operations'.
+--echo #
+--echo # Check that we don't try to pre-open temporary tables for the elements
+--echo # from prelocking list, as this can lead to unwarranted ER_CANT_REOPEN
+--echo # errors.
+--disable_warnings ONCE
+DROP TABLE IF EXISTS t1, tm;
+CREATE TABLE t1 (a INT);
+CREATE TRIGGER t1_bi BEFORE INSERT ON t1 FOR EACH ROW
+ SET @a:= (SELECT COUNT(*) FROM t1);
+--echo # Prelocking list for the below statement should
+--echo # contain t1 twice - once for the INSERT and once
+--echo # SELECT from the trigger.
+PREPARE stmt1 FROM 'INSERT INTO t1 VALUES (1)';
+EXECUTE stmt1;
+--echo # Create temporary table which will shadow t1.
+CREATE TEMPORARY TABLE t1 (b int);
+--echo # The below execution of statement should not fail with ER_CANT_REOPEN
+--echo # error. Instead stmt1 should be auto-matically reprepared and succeed.
+EXECUTE stmt1;
+DEALLOCATE PREPARE stmt1;
+DROP TEMPORARY TABLE t1;
+DROP TABLE t1;
+--echo #
+--echo # Also check that we properly reset table list elements from UNION
+--echo # clause of CREATE TABLE and ALTER TABLE statements.
+--echo #
+CREATE TEMPORARY TABLE t1 (i INT);
+PREPARE stmt2 FROM 'CREATE TEMPORARY TABLE tm (i INT) ENGINE=MERGE UNION=(t1)';
+EXECUTE stmt2;
+DROP TEMPORARY TABLE tm;
+EXECUTE stmt2;
+DEALLOCATE PREPARE stmt2;
+PREPARE stmt3 FROM 'ALTER TABLE tm UNION=(t1)';
+EXECUTE stmt3;
+EXECUTE stmt3;
+DEALLOCATE PREPARE stmt3;
+DROP TEMPORARY TABLES tm, t1;
diff --git a/mysql-test/t/query_cache.test b/mysql-test/t/query_cache.test
index 47fa628190a..387dcd205bd 100644
--- a/mysql-test/t/query_cache.test
+++ b/mysql-test/t/query_cache.test
@@ -439,10 +439,10 @@ create table t1 (a int);
insert into t1 values (1),(2);
show status like "Qcache_queries_in_cache";
select * from t1;
-SET OPTION SQL_SELECT_LIMIT=1;
+SET SQL_SELECT_LIMIT=1;
select * from t1;
show status like "Qcache_queries_in_cache";
-SET OPTION SQL_SELECT_LIMIT=DEFAULT;
+SET SQL_SELECT_LIMIT=DEFAULT;
drop table t1;
#
@@ -1710,6 +1710,36 @@ SET GLOBAL userstat=default;
--echo End of 5.5 tests
+--echo #
+--echo # Bug#12977203: SERVER CRASH ON A DERIVED TABLE WITH QUERY CACHE ENABLED
+--echo #
+SET @qc= @@query_cache_size;
+SET GLOBAL query_cache_size=1355776;
+CREATE TABLE t1 (f1 blob);
+SELECT COUNT(*) FROM (SELECT * FROM t1 ) tt;
+DROP TABLE t1;
+SET GLOBAL query_cache_size= @qc;
+
+--echo #
+--echo # MDEV-617 LP:671189 - Query cache is not used for tables or
+--echo # databases with dots in their names
+--echo #
+CREATE DATABASE `foo.bar`;
+use `foo.bar`;
+flush status;
+CREATE TABLE moocow (a int);
+INSERT INTO moocow VALUES (1), (2), (3);
+SHOW STATUS LIKE 'Qcache_inserts';
+SELECT * FROM moocow;
+SHOW STATUS LIKE 'Qcache_inserts';
+SHOW STATUS LIKE 'Qcache_hits';
+SELECT * FROM moocow;
+SHOW STATUS LIKE 'Qcache_hits';
+use test;
+drop database `foo.bar`;
+
+--echo End of 10.0 tests
+
--echo restore defaults
SET GLOBAL query_cache_type= default;
SET GLOBAL query_cache_size= default;
diff --git a/mysql-test/t/query_cache_ps_no_prot.test b/mysql-test/t/query_cache_ps_no_prot.test
index 16533c7194e..4b2bb842e34 100644
--- a/mysql-test/t/query_cache_ps_no_prot.test
+++ b/mysql-test/t/query_cache_ps_no_prot.test
@@ -16,12 +16,7 @@ let collation=utf8_unicode_ci;
--source include/have_collation.inc
# The file with expected results fits only to a run without
-# ps-protocol/sp-protocol/cursor-protocol/view-protocol.
-if (`SELECT $PS_PROTOCOL + $SP_PROTOCOL + $CURSOR_PROTOCOL
- + $VIEW_PROTOCOL > 0`)
-{
- --skip Test requires: ps-protocol/sp-protocol/cursor-protocol/view-protocol disabled
-}
+--source include/no_protocol.inc
# The main testing script
--source include/query_cache_sql_prepare.inc
diff --git a/mysql-test/t/range.test b/mysql-test/t/range.test
index 393ca68e945..7cd1c44ec24 100644
--- a/mysql-test/t/range.test
+++ b/mysql-test/t/range.test
@@ -1718,3 +1718,71 @@ where (key1varchar='value1' AND (key2int <=1 OR key2int > 1));
--echo # The following must show col1=12345 for all rows:
select * from t1;
drop table t1;
+
+--echo #
+--echo # BUG#13731380: RANGE OPTIMIZER CALLS RECORDS_IN_RANGE() FOR OPEN RANGE
+--echo #
+
+CREATE TABLE t1 (pk INT PRIMARY KEY);
+INSERT INTO t1 VALUES (1),(3),(5);
+SELECT * FROM t1 WHERE pk <> 3 OR pk < 4;
+DROP TABLE t1;
+
+--echo #
+--echo # BUG#13803810: TOO FEW ROWS RETURNED FOR RANGE ACCESS IN
+--echo # VARCHAR INDEX USING DATETIME VALUE
+--echo
+CREATE TABLE t1 (a DATETIME);
+INSERT INTO t1 VALUES ('2001-01-01 00:00:00');
+INSERT INTO t1 VALUES ('2001-01-01 11:22:33');
+
+CREATE TABLE t2 (b VARCHAR(64), KEY (b));
+INSERT INTO t2 VALUES ('2001-01-01');
+INSERT INTO t2 VALUES ('2001.01.01');
+INSERT INTO t2 VALUES ('2001#01#01');
+INSERT INTO t2 VALUES ('2001-01-01 00:00:00');
+INSERT INTO t2 VALUES ('2001-01-01 11:22:33');
+
+
+--echo
+--echo # range/ref access cannot be used for this query
+--echo
+EXPLAIN SELECT * FROM t2 WHERE b=CAST('2001-01-01' AS DATE);
+SELECT * FROM t2 WHERE b=CAST('2001-01-01' AS DATE);
+
+let $query_ab=SELECT * FROM t1, t2 WHERE a=b ORDER BY BINARY a, BINARY b;
+let $query_ba=SELECT * FROM t1, t2 WHERE b=a ORDER BY BINARY a, BINARY b;
+
+--echo
+--echo # range/ref access cannot be used for any of the queries below.
+--echo # See BUG#13814468 about 'Range checked for each record'
+--echo
+eval EXPLAIN $query_ab;
+eval $query_ab;
+--echo
+eval EXPLAIN $query_ba;
+eval $query_ba;
+
+--echo
+DROP TABLE t1,t2;
+
+--echo #
+--echo # MDEV-5606: range optimizer: "x < y" is sargable, while "y > x" is not
+--echo #
+create table t1(a int);
+insert into t1 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
+create table t2(a int);
+insert into t2 select A.a + B.a* 10 + C.a * 100 from t1 A, t1 B, t1 C;
+alter table t2 add key(a);
+--echo # Should have "range checked for each table" for second table:
+explain select * from t1, t2 where t2.a < t1.a;
+--echo # Should have "range checked for each table" for second table:
+explain select * from t1, t2 where t1.a > t2.a;
+
+create table t3 (a int primary key, b int);
+insert into t3 select a,a from t1;
+--echo # The second table should use 'range':
+explain select * from t3, t2 where t2.a < t3.b and t3.a=1;
+--echo # The second table should use 'range':
+explain select * from t3, t2 where t3.b > t2.a and t3.a=1;
+drop table t1,t2,t3;
diff --git a/mysql-test/t/range_vs_index_merge.test b/mysql-test/t/range_vs_index_merge.test
index e3a699322b2..84b87579e85 100644
--- a/mysql-test/t/range_vs_index_merge.test
+++ b/mysql-test/t/range_vs_index_merge.test
@@ -454,6 +454,8 @@ SELECT * FROM City WHERE Name LIKE 'Pa%';
# index merge retrievals over:
# 2. key1 and key3
# 3. key2 and key3
+set @tmp_range_vs_index_merge=@@optimizer_switch;
+set optimizer_switch='extended_keys=off';
EXPLAIN
SELECT * FROM City
@@ -578,6 +580,7 @@ SELECT * FROM City
DROP INDEX Population ON City;
DROP INDEX Name ON City;
+set optimizer_switch=@tmp_range_vs_index_merge;
# The pattern of the WHERE condition used in the following query is
# (key1|2_p1=c AND range(key1_p2)) OR (key1|2_p1=c AND range(key2_p2))
@@ -1238,6 +1241,59 @@ WHERE ( state = 'Alabama' OR state >= 'Colorado' ) AND id != 9
DROP TABLE t1;
+--echo #
+--echo # mdev-11574: do not build index merge of two indexes when
+--echo # one index is an infix of the other index
+--echo #
+
+set names utf8;
+
+CREATE DATABASE world;
+
+use world;
+
+--source include/world_schema.inc
+
+--disable_query_log
+--disable_result_log
+--disable_warnings
+--source include/world.inc
+--enable_warnings
+--enable_result_log
+--enable_query_log
+
+DROP INDEX Country ON City;
+CREATE INDEX CountryName ON City(Country,Name);
+CREATE INDEX Name ON City(Name);
+
+--disable_query_log
+--disable_result_log
+--disable_warnings
+ANALYZE TABLE City;
+--enable_warnings
+--enable_result_log
+--enable_query_log
+
+let $q=
+select * from City
+where
+ Country='FIN' AND Name IN ('Lahti','Imatra') OR
+ Country='RUS' AND Name IN ('St Petersburg', 'Moscow') OR
+ Country='SWE' AND Name IN ('Stockholm', 'Uppsala') OR
+ Country='DEU' AND Name IN ('Berlin', 'Bonn') OR
+ Country='BEL' AND Name IN ('Antwerpen', 'Gent') OR
+ Country='PRT' AND Name IN ('Braga', 'Porto') OR
+ Country='FRA' AND Name IN ('Paris', 'Marcel') OR
+ Country='POL' AND Name IN ('Warszawa', 'Wroclaw') OR
+ Country='NOR' AND Name IN ('Oslo', 'Bergen') OR
+ Country='ITA' AND Name IN ('Napoli', 'Venezia');
+
+eval $q;
+eval explain $q;
+
+
+DROP DATABASE world;
+
#the following command must be the last one in the file
set session optimizer_switch='index_merge_sort_intersection=default';
diff --git a/mysql-test/t/read_only.test b/mysql-test/t/read_only.test
index eb9bea803c2..691c4104148 100644
--- a/mysql-test/t/read_only.test
+++ b/mysql-test/t/read_only.test
@@ -307,6 +307,65 @@ flush privileges;
drop database mysqltest_db1;
set global read_only= @start_read_only;
+
+--echo #
+--echo # WL#5968 Implement START TRANSACTION READ (WRITE|ONLY);
+--echo #
+
+--echo #
+--echo # Test interaction with read_only system variable.
+
+--disable_warnings
+DROP TABLE IF EXISTS t1;
+--enable_warnings
+
+CREATE TABLE t1(a INT);
+INSERT INTO t1 VALUES (1), (2);
+
+CREATE USER user1;
+connect (con1, localhost, user1);
+connection default;
+
+SET GLOBAL read_only= 1;
+
+--echo # All allowed with super privilege
+START TRANSACTION;
+COMMIT;
+
+START TRANSACTION READ ONLY;
+COMMIT;
+
+START TRANSACTION READ WRITE;
+COMMIT;
+
+--echo # We allow implicit RW transaction without super privilege
+--echo # for compatibility reasons
+connection con1;
+START TRANSACTION;
+--echo # Check that table updates are still disallowed.
+--error ER_OPTION_PREVENTS_STATEMENT
+INSERT INTO t1 VALUES (3);
+--error ER_OPTION_PREVENTS_STATEMENT
+UPDATE t1 SET a= 1;
+--error ER_OPTION_PREVENTS_STATEMENT
+DELETE FROM t1;
+COMMIT;
+
+START TRANSACTION READ ONLY;
+COMMIT;
+
+--echo # Explicit RW trans is not allowed without super privilege
+--error ER_OPTION_PREVENTS_STATEMENT
+START TRANSACTION READ WRITE;
+COMMIT;
+disconnect con1;
+--source include/wait_until_disconnected.inc
+connection default;
+DROP USER user1;
+
+SET GLOBAL read_only= 0;
+DROP TABLE t1;
+
# Wait till all disconnects are completed
--source include/wait_until_count_sessions.inc
diff --git a/mysql-test/t/rename.test b/mysql-test/t/rename.test
index bb90cbafd74..a55bc845acc 100644
--- a/mysql-test/t/rename.test
+++ b/mysql-test/t/rename.test
@@ -21,16 +21,16 @@ rename table t3 to t4, t2 to t3, t1 to t2, t4 to t1;
select * from t1;
# The following should give errors
---error ER_TABLE_EXISTS_ERROR,ER_TABLE_EXISTS_ERROR
+--error ER_TABLE_EXISTS_ERROR
rename table t1 to t2;
---error ER_TABLE_EXISTS_ERROR,ER_TABLE_EXISTS_ERROR
+--error ER_TABLE_EXISTS_ERROR
rename table t1 to t1;
---error ER_TABLE_EXISTS_ERROR,ER_TABLE_EXISTS_ERROR
+--error ER_TABLE_EXISTS_ERROR
rename table t3 to t4, t2 to t3, t1 to t2, t4 to t2;
show tables like "t_";
---error ER_TABLE_EXISTS_ERROR,ER_TABLE_EXISTS_ERROR
+--error ER_TABLE_EXISTS_ERROR
rename table t3 to t1, t2 to t3, t1 to t2, t4 to t1;
---error ER_FILE_NOT_FOUND,ER_FILE_NOT_FOUND
+--error ER_NO_SUCH_TABLE
rename table t3 to t4, t5 to t3, t1 to t2, t4 to t1;
select * from t1;
diff --git a/mysql-test/t/repair.test b/mysql-test/t/repair.test
index f625965090a..5494e370133 100644
--- a/mysql-test/t/repair.test
+++ b/mysql-test/t/repair.test
@@ -61,6 +61,7 @@ DROP TABLE t1;
#
CREATE TABLE t1(a CHAR(255), KEY(a));
SET myisam_sort_buffer_size=4096;
+--replace_regex /Current myisam_sort_buffer_size.*/X/
INSERT INTO t1 VALUES
('0'),('0'),('0'),('0'),('0'),('0'),('0'),('0'),('0'),('0'),
('0'),('0'),('0'),('0'),('0'),('0'),('0'),('0'),('0'),('0'),
@@ -79,6 +80,7 @@ INSERT INTO t1 VALUES
('0'),('0'),('0'),('0'),('0'),('0'),('0'),('0'),('0'),('0'),
('0'),('0'),('0'),('0'),('0'),('0'),('0');
SET myisam_repair_threads=2;
+--replace_regex /Current myisam_sort_buffer_size.*/X/
REPAIR TABLE t1;
SET myisam_repair_threads=@@global.myisam_repair_threads;
SET myisam_sort_buffer_size=@@global.myisam_sort_buffer_size;
@@ -113,7 +115,7 @@ SET myisam_repair_threads=@@global.myisam_repair_threads;
SET myisam_sort_buffer_size=@@global.myisam_sort_buffer_size;
DROP TABLE t1;
---echo End of 4.1 tests
+--echo # End of 4.1 tests
#
# BUG#36055 - mysql_upgrade doesn't really 'upgrade' tables
@@ -145,7 +147,8 @@ REPAIR TABLE t1 USE_FRM;
SELECT * FROM t1;
DROP TABLE t1;
-# End of 5.0 tests
+
+--echo # End of 5.0 tests
#
# Bug#18775 - Temporary table from alter table visible to other threads
@@ -200,7 +203,7 @@ let $MYSQLD_DATADIR= `select @@datadir`;
--copy_file std_data/host_old.MYD $MYSQLD_DATADIR/test/t1.MYD
--copy_file std_data/host_old.MYI $MYSQLD_DATADIR/test/t1.MYI
---error ER_GET_ERRMSG
+--error ER_GET_ERRNO
select count(*) from t1;
check table t1;
repair table t1;
@@ -217,3 +220,21 @@ create view v1 as select * from t1;
repair view v1;
drop view v1;
drop table t1;
+
+--echo # End of 5.5 tests
+
+#
+# MDEV-11539 test_if_reopen: Assertion `strcmp(share->unique_file_name,filename) || share->last_version' failed upon select from I_S
+#
+CREATE TABLE t1 (i INT) ENGINE=MyISAM;
+INSERT t1 VALUES (1);
+LOCK TABLE t1 WRITE;
+REPAIR TABLE t1;
+--disable_result_log
+SELECT * FROM INFORMATION_SCHEMA.TABLES;
+--enable_result_log
+SELECT * FROM t1;
+UNLOCK TABLES;
+DROP TABLE t1;
+
+--echo # End of 10.0 tests
diff --git a/mysql-test/t/rpl_mysqldump_slave.test b/mysql-test/t/rpl_mysqldump_slave.test
index 3fbcfe49324..345bdb82535 100644
--- a/mysql-test/t/rpl_mysqldump_slave.test
+++ b/mysql-test/t/rpl_mysqldump_slave.test
@@ -30,10 +30,59 @@ connection slave;
#
# MDEV-5624 mysqldump --dump-slave option does not restart the replication if the dump has failed
#
-slave start;
+start slave;
--replace_regex /MASTER_LOG_POS=[0-9]+/MASTER_LOG_POS=BINLOG_START/
--error 2
--exec $MYSQL_DUMP_SLAVE --compact --dump-slave no_such_db
-slave start;
+start slave;
+
+
+--echo *** Test mysqldump --dump-slave GTID functionality.
+
+--connection master
+SET gtid_seq_no = 1000;
+CREATE TABLE t1 (a INT PRIMARY KEY);
+DROP TABLE t1;
+--sync_slave_with_master
+
+--connection slave
+# Inject a local transaction on the slave to check that this is not considered
+# for --dump-slave.
+CREATE TABLE t2 (a INT PRIMARY KEY);
+DROP TABLE t2;
+
+--echo
+--echo 1. --dump-slave=1
+--echo
+--replace_regex /MASTER_LOG_POS=[0-9]+/MASTER_LOG_POS=BINLOG_START/
+--exec $MYSQL_DUMP_SLAVE --compact --dump-slave=1 --gtid test
+
+--echo
+--echo 2. --dump-slave=2
+--echo
+--replace_regex /MASTER_LOG_POS=[0-9]+/MASTER_LOG_POS=BINLOG_START/
+--exec $MYSQL_DUMP_SLAVE --compact --dump-slave=2 --gtid test
+
+
+--echo *** Test mysqldump --master-data GTID functionality.
+--echo
+--echo 1. --master-data=1
+--echo
+--replace_regex /MASTER_LOG_POS=[0-9]+/MASTER_LOG_POS=BINLOG_START/
+--exec $MYSQL_DUMP_SLAVE --compact --master-data=1 --gtid test
+
+--echo
+--echo 2. --master-data=2
+--echo
+--replace_regex /MASTER_LOG_POS=[0-9]+/MASTER_LOG_POS=BINLOG_START/
+--exec $MYSQL_DUMP_SLAVE --compact --master-data=2 --gtid test
+
+--echo
+--echo 3. --master-data --single-transaction
+--echo
+--replace_regex /MASTER_LOG_POS=[0-9]+/MASTER_LOG_POS=BINLOG_START/
+--exec $MYSQL_DUMP_SLAVE --compact --master-data --single-transaction --gtid test
+
+
--source include/rpl_end.inc
diff --git a/mysql-test/t/select.test b/mysql-test/t/select.test
index 3c56ef2837b..2d75dc48f73 100644
--- a/mysql-test/t/select.test
+++ b/mysql-test/t/select.test
@@ -1424,9 +1424,9 @@ drop table tmp;
# big table done
-SET SQL_BIG_TABLES=1;
+SET BIG_TABLES=1;
select distinct concat(fld3," ",fld3) as namn from t2,t3 where t2.fld1=t3.t2nr order by namn limit 10;
-SET SQL_BIG_TABLES=0;
+SET BIG_TABLES=0;
select distinct concat(fld3," ",fld3) from t2,t3 where t2.fld1=t3.t2nr order by fld3 limit 10;
select distinct fld5 from t2 limit 10;
@@ -1435,9 +1435,9 @@ select distinct fld5 from t2 limit 10;
#
select distinct fld3,count(*) from t2 group by companynr,fld3 limit 10;
-SET SQL_BIG_TABLES=1; # Force use of MyISAM
+SET BIG_TABLES=1; # Force use of MyISAM
select distinct fld3,count(*) from t2 group by companynr,fld3 limit 10;
-SET SQL_BIG_TABLES=0;
+SET BIG_TABLES=0;
select distinct fld3,repeat("a",length(fld3)),count(*) from t2 group by companynr,fld3 limit 100,10;
#
@@ -4363,6 +4363,30 @@ DROP TABLE t1,t2,t_empty;
--echo End of 5.1 tests
+--echo #
+--echo # Bug#45227: Lost HAVING clause led to a wrong result.
+--echo #
+CREATE TABLE `CC` (
+ `int_nokey` int(11) NOT NULL,
+ `int_key` int(11) NOT NULL,
+ `varchar_key` varchar(1) NOT NULL,
+ `varchar_nokey` varchar(1) NOT NULL,
+ KEY `int_key` (`int_key`),
+ KEY `varchar_key` (`varchar_key`)
+);
+INSERT INTO `CC` VALUES
+(0,8,'q','q'),(5,8,'m','m'),(7,3,'j','j'),(1,2,'z','z'),(8,2,'a','a'),(2,6,'',''),(1,8,'e'
+,'e'),(8,9,'t','t'),(5,2,'q','q'),(4,6,'b','b'),(5,5,'w','w'),(3,2,'m','m'),(0,4,'x','x'),
+(8,9,'',''),(0,6,'w','w'),(4,5,'x','x'),(0,0,'e','e'),(0,0,'e','e'),(2,8,'p','p'),(0,0,'x'
+,'x');
+EXPLAIN SELECT `varchar_nokey` G1 FROM CC WHERE `int_nokey` AND `int_key` <= 4
+ HAVING G1 ORDER BY `varchar_key` LIMIT 6 ;
+
+SELECT `varchar_nokey` G1 FROM CC WHERE `int_nokey` AND `int_key` <= 4
+ HAVING G1 ORDER BY `varchar_key` LIMIT 6 ;
+
+DROP TABLE CC;
+--echo # End of test#45227
--echo #
--echo # BUG#776274: substitution of a single row table
--echo #
@@ -4446,6 +4470,14 @@ DROP TABLE t1;
DROP VIEW view_t1;
--echo # End of test BUG#63020
+--echo #
+--echo # Bug #13571700 TINYBLOB NOT NULL, CRASH IN PROTOCOL::NET_STORE_DATA
+--echo #
+
+CREATE TABLE t1 (a TINYBLOB NOT NULL);
+SELECT a, COUNT(*) FROM t1 WHERE 0;
+DROP TABLE t1;
+
SET optimizer_switch=@save_optimizer_switch;
--echo #
@@ -4607,3 +4639,34 @@ DROP TABLE t1,t2;
--echo End of 5.3 tests
+--echo #
+--echo # mysql BUG#1271 Undefined variable in PASSWORD()
+--echo # function is not handled correctly
+--echo #
+
+create table t1 (
+name VARCHAR(50) NOT NULL PRIMARY KEY,
+pw VARCHAR(41) NOT NULL);
+
+INSERT INTO t1 (name, pw)
+VALUES ('tom', PASSWORD('my_pw'));
+
+SET @pass='my_pw';
+SET @wrong='incorrect';
+
+select * from t1;
+select length(PASSWORD(@pass));
+
+
+SELECT name FROM t1 WHERE name='tom' AND pw=PASSWORD(@pass);
+SELECT name FROM t1 WHERE name='tom' AND pw=PASSWORD(@wrong);
+SELECT name FROM t1 WHERE name='tom' AND pw=PASSWORD(@undefined);
+
+
+select (SELECT name FROM t1 WHERE name='tom' AND pw=PASSWORD(@pass));
+select (SELECT name FROM t1 WHERE name='tom' AND pw=PASSWORD(@wrong));
+select (SELECT name FROM t1 WHERE name='tom' AND pw=PASSWORD(@undefined));
+
+drop table t1;
+
+--echo End of 10.0 tests
diff --git a/mysql-test/t/select_found.test b/mysql-test/t/select_found.test
index e043ec4d143..33613697722 100644
--- a/mysql-test/t/select_found.test
+++ b/mysql-test/t/select_found.test
@@ -195,3 +195,95 @@ SELECT FOUND_ROWS();
DROP TABLE t1;
# End of 4.1 tests
+
+#
+# MDEV-5549 Wrong row counter in found_rows() result
+#
+create table t1 (f1 int primary key, f2 tinyint) engine=myisam;
+insert t1 values (10,3),(11,2),(12,3);
+create table t2 (f3 int primary key) engine=myisam;
+insert t2 values (11),(12),(13);
+#explain select f1 from t1,t2 where f1=f3 and f2=3 order by f1;
+select f1 from t1,t2 where f1=f3 and f2=3 order by f1;
+select found_rows();
+drop table t1, t2;
+
+#
+# MDEV-5898 FOUND_ROWS() return incorrect value when using DISTINCT
+#
+create table t1 (a1 int auto_increment primary key, c1 int);
+
+insert t1 (a1) values (null);
+insert t1 (a1) select null from t1;
+insert t1 (a1) select null from t1;
+insert t1 (a1) select null from t1;
+insert t1 (a1) select null from t1;
+insert t1 (a1) select null from t1;
+insert t1 (a1) select null from t1;
+insert t1 (a1) select null from t1;
+insert t1 (a1) select null from t1;
+insert t1 (a1) select null from t1;
+update t1 set c1=a1 % 2;
+
+create table t2 (a2 int, b2 int, c2 char(16) default '', primary key (a2, b2));
+
+insert t2 select a1, 1, 'ok' from t1;
+insert t2 select a1, 2, 'ko' from t1;
+insert t2 select a1, 3, 'ko' from t1;
+insert t2 select a1, 4, 'ok' from t1;
+insert t2 select a1, 5, 'ok' from t1;
+
+--disable_result_log ONCE
+select sql_calc_found_rows distinct a1,c2 from t1 join t2 on a2=a1
+ where a1 <= 256 and c1=0 and c2='ok' order by a1 desc limit 46;
+
+select found_rows();
+
+drop table t1, t2;
+
+#
+# MDEV-6221 SQL_CALC_FOUND_ROWS yields wrong result again
+#
+create table t1 (i1 int, v1 int, primary key(i1,v1));
+insert into t1 values (1,1),(2,2),(3,3);
+create table t2 (i2 int primary key, v2 int);
+insert into t2 values (1,5),(2,5),(3,10);
+select 1 as res from t1 left join t2 on i1 = i2 where v2 = 5 or v1 = 5 or v1 = 10 order by v1;
+--disable_result_log ONCE
+select sql_calc_found_rows 1 as res from t1 left join t2 on i1 = i2 where v2 = 5 or v1 = 5 or v1 = 10 order by v1 limit 1;
+select found_rows() as count;
+--disable_result_log ONCE
+select sql_calc_found_rows 1 as res from t1 left join t2 on i1 = i2 where v2 = 5 order by v1 limit 1;
+select found_rows() as count;
+drop table t1, t2;
+
+#
+# MDEV-7219 SQL_CALC_FOUND_ROWS yields wrong result
+#
+create table t1 (i int, v varchar(64), key (i));
+
+--disable_query_log
+let $1=150;
+while ($1)
+{
+ eval insert into t1 values ($1 % 2, 'foo');
+ dec $1;
+}
+--enable_query_log
+
+select sql_calc_found_rows * from t1 where i = 0 order by v limit 59,2;
+select found_rows();
+select sql_calc_found_rows * from t1 ignore index (i) where i = 0 order by v limit 59,2;
+select found_rows();
+drop table t1;
+
+#
+# MDEV-9390 Function found_rows() gives incorrect result where the previous SELECT contains ORDER BY clause
+#
+create table t1(c1 int);
+insert into t1 values(1),(2),(3),(4),(5);
+select * from t1 order by c1 limit 2,1;
+select found_rows();
+select sql_calc_found_rows * from t1 order by c1 limit 2,1;
+select found_rows();
+drop table t1;
diff --git a/mysql-test/t/selectivity.test b/mysql-test/t/selectivity.test
new file mode 100644
index 00000000000..548ef295fb2
--- /dev/null
+++ b/mysql-test/t/selectivity.test
@@ -0,0 +1,1048 @@
+--source include/have_stat_tables.inc
+
+--disable_warnings
+drop table if exists t0,t1,t2,t3;
+--enable_warnings
+
+select @@global.use_stat_tables;
+select @@session.use_stat_tables;
+
+set @save_use_stat_tables=@@use_stat_tables;
+
+set use_stat_tables='preferably';
+
+set @save_optimizer_use_condition_selectivity=@@optimizer_use_condition_selectivity;
+set @save_histogram_size=@@histogram_size;
+set @save_histogram_type=@@histogram_type;
+
+# check that statistics on nulls is used
+
+set optimizer_use_condition_selectivity=3;
+
+create table t1 (a int);
+insert into t1 values
+ (9), (3), (2), (NULL), (NULL), (2), (NULL), (1), (5), (NULL);
+
+analyze table t1;
+
+select * from mysql.column_stats;
+
+flush table t1;
+
+explain extended
+select * from t1 where a is null;
+
+explain extended
+select * from t1 where a is not null;
+
+drop table t1;
+
+set optimizer_use_condition_selectivity=@save_optimizer_use_condition_selectivity;
+
+--disable_warnings
+DROP DATABASE IF EXISTS dbt3_s001;
+--enable_warnings
+
+CREATE DATABASE dbt3_s001;
+
+use dbt3_s001;
+
+--disable_query_log
+--disable_result_log
+--disable_warnings
+--source include/dbt3_s001.inc
+
+ANALYZE TABLE
+customer, lineitem, nation, orders, part, partsupp, region, supplier;
+FLUSH TABLE
+customer, lineitem, nation, orders, part, partsupp, region, supplier;
+--enable_warnings
+--enable_result_log
+--enable_query_log
+
+--echo === Q2 ===
+
+set optimizer_use_condition_selectivity=5;
+explain extended
+select
+ s_acctbal, s_name, n_name, p_partkey, p_mfgr, s_address, s_phone, s_comment
+from
+ part, supplier, partsupp, nation, region
+where
+ p_partkey = ps_partkey
+ and s_suppkey = ps_suppkey
+ and p_size = 9
+ and p_type like '%TIN'
+ and s_nationkey = n_nationkey
+ and n_regionkey = r_regionkey
+ and r_name = 'ASIA'
+ and ps_supplycost = (
+ select
+ min(ps_supplycost)
+ from
+ partsupp, supplier, nation, region
+ where
+ p_partkey = ps_partkey
+ and s_suppkey = ps_suppkey
+ and s_nationkey = n_nationkey
+ and n_regionkey = r_regionkey
+ and r_name = 'ASIA'
+ )
+order by
+ s_acctbal desc, n_name, s_name, p_partkey;
+set optimizer_use_condition_selectivity=4;
+explain extended
+select
+ s_acctbal, s_name, n_name, p_partkey, p_mfgr, s_address, s_phone, s_comment
+from
+ part, supplier, partsupp, nation, region
+where
+ p_partkey = ps_partkey
+ and s_suppkey = ps_suppkey
+ and p_size = 9
+ and p_type like '%TIN'
+ and s_nationkey = n_nationkey
+ and n_regionkey = r_regionkey
+ and r_name = 'ASIA'
+ and ps_supplycost = (
+ select
+ min(ps_supplycost)
+ from
+ partsupp, supplier, nation, region
+ where
+ p_partkey = ps_partkey
+ and s_suppkey = ps_suppkey
+ and s_nationkey = n_nationkey
+ and n_regionkey = r_regionkey
+ and r_name = 'ASIA'
+ )
+order by
+ s_acctbal desc, n_name, s_name, p_partkey;
+
+--echo === Q15 ===
+
+create view revenue0 (supplier_no, total_revenue) as
+ select l_suppkey, sum(l_extendedprice * (1 - l_discount))
+ from lineitem
+ where
+ l_shipdate >= '1995-08-01'
+ and l_shipdate < date_add('1995-08-01', interval 90 day)
+ group by l_suppkey;
+
+let $Q15=
+select s_suppkey, s_name, s_address, s_phone, total_revenue
+from supplier, revenue0
+where s_suppkey = supplier_no
+ and total_revenue = (select max(total_revenue) from revenue0)
+order by s_suppkey;
+
+set @save_optimizer_switch=@@optimizer_switch;
+set optimizer_switch='index_condition_pushdown=off';
+
+set optimizer_use_condition_selectivity=1;
+eval EXPLAIN EXTENDED $Q15;
+eval $Q15;
+
+set optimizer_use_condition_selectivity=3;
+eval EXPLAIN EXTENDED $Q15;
+eval $Q15;
+
+set optimizer_switch=@save_optimizer_switch;
+
+drop view revenue0;
+
+
+--echo === Q16 ===
+
+let $Q16=
+select p_brand, p_type, p_size, count(distinct ps_suppkey) as supplier_cnt
+from partsupp, part
+where p_partkey = ps_partkey
+ and p_brand <> 'Brand#11'
+ and p_type not like 'SMALL POLISHED%'
+ and p_size in (49, 37, 27, 5, 40, 6, 22, 8)
+ and ps_suppkey not in (select s_suppkey from supplier
+ where s_comment like '%Customer%Complaints%')
+group by p_brand, p_type, p_size
+order by supplier_cnt desc, p_brand, p_type, p_size;
+
+set optimizer_use_condition_selectivity=1;
+eval EXPLAIN EXTENDED $Q16;
+eval $Q16;
+
+set optimizer_use_condition_selectivity=3;
+eval EXPLAIN EXTENDED $Q16;
+eval $Q16;
+
+set optimizer_use_condition_selectivity=4;
+eval EXPLAIN EXTENDED $Q16;
+eval $Q16;
+
+
+--echo === Q18 ===
+
+let $Q18=
+select
+ c_name, c_custkey, o_orderkey, o_orderdate, o_totalprice, sum(l_quantity)
+from customer, orders, lineitem
+where
+ o_orderkey in (select l_orderkey from lineitem
+ group by l_orderkey having sum(l_quantity) > 250)
+ and c_custkey = o_custkey
+ and o_orderkey = l_orderkey
+group by c_name, c_custkey, o_orderkey, o_orderdate, o_totalprice
+order by o_totalprice desc, o_orderdate;
+
+set optimizer_use_condition_selectivity=1;
+eval EXPLAIN EXTENDED $Q18;
+eval $Q18;
+
+set optimizer_use_condition_selectivity=3;
+eval EXPLAIN EXTENDED $Q18;
+eval $Q18;
+
+
+--echo === Q22 ===
+
+let $Q22=
+select cntrycode, count(*) as numcust, sum(c_acctbal) as totacctbal
+from (
+ select substr(c_phone, 1, 2) as cntrycode, c_acctbal
+ from customer
+ where
+ substr(c_phone, 1, 2) in ('10', '20', '14', '19', '11', '28', '25')
+ and c_acctbal > (select avg(c_acctbal) from customer
+ where c_acctbal > 0.00
+ and substr(c_phone, 1, 2) in
+ ('10', '20', '14', '19', '11', '28', '25'))
+ and not exists (select * from orders where o_custkey = c_custkey)
+ ) as vip
+group by cntrycode
+order by cntrycode;
+
+set optimizer_use_condition_selectivity=1;
+eval EXPLAIN EXTENDED $Q22;
+eval $Q22;
+
+set optimizer_use_condition_selectivity=3;
+eval EXPLAIN EXTENDED $Q22;
+eval $Q22;
+
+
+--echo === Q20 ===
+
+let $Q20=
+select sql_calc_found_rows
+ s_name, s_address
+from supplier, nation
+where s_suppkey in (select ps_suppkey from partsupp
+ where ps_partkey in (select p_partkey from part
+ where p_name like 'g%')
+ and ps_availqty >
+ (select 0.5 * sum(l_quantity)
+ from lineitem
+ where l_partkey = ps_partkey
+ and l_suppkey = ps_suppkey
+ and l_shipdate >= date('1993-01-01')
+ and l_shipdate < date('1993-01-01') +
+ interval '1' year ))
+and s_nationkey = n_nationkey
+and n_name = 'UNITED STATES'
+order by s_name
+limit 10;
+
+set optimizer_use_condition_selectivity=1;
+eval EXPLAIN EXTENDED $Q20;
+eval $Q20;
+
+SELECT ((SELECT COUNT(*) FROM part WHERE p_name LIKE 'g%') /
+ (SELECT COUNT(*) FROM part)) AS sel;
+
+set optimizer_use_condition_selectivity=3;
+eval EXPLAIN EXTENDED $Q20;
+eval $Q20;
+
+set histogram_size=127;
+
+ANALYZE TABLE part PERSISTENT FOR COLUMNS(p_name) INDEXES();
+
+flush table part;
+
+set optimizer_use_condition_selectivity=4;
+eval EXPLAIN EXTENDED $Q20;
+eval $Q20;
+
+set histogram_type='DOUBLE_PREC_HB';
+set histogram_size=126;
+
+ANALYZE TABLE part PERSISTENT FOR COLUMNS(p_name) INDEXES();
+
+flush table part;
+
+eval EXPLAIN EXTENDED $Q20;
+eval $Q20;
+
+set histogram_type='SINGLE_PREC_HB';
+set histogram_size=24;
+
+ANALYZE TABLE nation PERSISTENT FOR COLUMNS(n_name) INDEXES();
+
+flush table nation;
+
+eval EXPLAIN EXTENDED $Q20;
+eval $Q20;
+
+DROP DATABASE dbt3_s001;
+
+set histogram_type=@save_histogram_type;
+set histogram_size=@save_histogram_size;
+set optimizer_use_condition_selectivity=@save_optimizer_use_condition_selectivity;
+
+use test;
+
+--echo #
+--echo # Bug mdev-4348: using view with use_condition_selectivity > 1
+--echo #
+
+set @tmp_use_stat_tables=@@use_stat_tables;
+set use_stat_tables='never';
+set optimizer_use_condition_selectivity=3;
+
+CREATE TABLE t1 (a int, b int);
+INSERT t1 VALUES (7,1), (0,7);
+CREATE ALGORITHM=MERGE VIEW v1 AS SELECT * FROM t1;
+
+CREATE TABLE t2 (c int, d int, index idx(d));
+INSERT INTO t2 VALUES
+ (0,4), (8,6), (1,3), (8,5), (9,3), (2,2), (6,2),
+ (1,9), (6,3), (2,8), (4,1), (0,7), (4,8), (4,5);
+
+EXPLAIN EXTENDED
+SELECT * FROM v1 INNER JOIN t2 ON ( a = c AND b = d );
+
+SELECT * FROM v1 INNER JOIN t2 ON ( a = c AND b = d );
+
+DROP VIEW v1;
+DROP TABLE t1,t2;
+
+set optimizer_use_condition_selectivity=@save_optimizer_use_condition_selectivity;
+set use_stat_tables=@tmp_use_stat_tables;
+
+--echo #
+--echo # Bug mdev-4349: impossible range for non-indexed column
+--echo #
+
+set optimizer_use_condition_selectivity=3;
+
+create table t1 (a int);
+insert into t1 values
+ (3), (7), (2), (5), (7), (1), (2), (2);
+
+set optimizer_use_condition_selectivity=1;
+explain extended
+select * from t1 where a < 1 and a > 7;
+select * from t1 where a < 1 and a > 7;
+
+set optimizer_use_condition_selectivity=3;
+explain extended
+select * from t1 where a < 1 and a > 7;
+select * from t1 where a < 1 and a > 7;
+
+drop table t1;
+
+create table t1 (a int);
+insert into t1 values (1);
+
+create table t2 (b int);
+insert into t2 values (2),(3);
+
+explain extended
+select * from t1 where a in ( select b from t2 ) AND ( a > 3 );
+select * from t1 where a in ( select b from t2 ) AND ( a > 3 );
+
+drop table t1,t2;
+
+set optimizer_use_condition_selectivity=@save_optimizer_use_condition_selectivity;
+
+--echo #
+--echo # Bug mdev-4350: erroneous negative selectivity
+--echo #
+
+create table t1 (a int);
+insert into t1 values (1), (1);
+insert into t1 select * from t1;
+insert into t1 select * from t1;
+insert into t1 select * from t1;
+insert into t1 select * from t1;
+insert into t1 select * from t1;
+insert into t1 select * from t1;
+insert into t1 select * from t1;
+insert into t1 select * from t1;
+insert into t1 select * from t1;
+insert into t1 values (0);
+select count(*) from t1;
+
+set use_stat_tables='preferably';
+set histogram_size=127;
+set histogram_type='SINGLE_PREC_HB';
+analyze table t1;
+flush table t1;
+
+set optimizer_use_condition_selectivity=4;
+explain extended select * from t1 where a=0;
+
+drop table t1;
+
+set histogram_size=@save_histogram_size;
+set histogram_type=@save_histogram_type;
+set optimizer_use_condition_selectivity=@save_optimizer_use_condition_selectivity;
+
+--echo #
+--echo # Bug mdev-4367: 2-way join with an empty table
+--echo # when optimizer_use_condition_selectivity=3
+--echo #
+
+set optimizer_use_condition_selectivity=3;
+
+CREATE TABLE t1 (a varchar(1)) ENGINE=MyISAM;
+INSERT INTO t1 VALUES ('j'),('k');
+
+CREATE TABLE t2 (b varchar(1)) ENGINE=MyISAM;
+INSERT INTO t2 VALUES ('x'),('y');
+
+CREATE TABLE t3 (c varchar(1), KEY(c)) ENGINE=MyISAM;
+
+SELECT * FROM t1 STRAIGHT_JOIN (t2 JOIN t3 ON c = b AND b > 'z');
+
+DROP TABLE t1,t2,t3;
+
+set optimizer_use_condition_selectivity=@save_optimizer_use_condition_selectivity;
+
+--echo #
+--echo # Bug mdev-4366: impossible condition on an indexed column discovered after
+--echo # substitution of constant tables
+--echo # with optimizer_use_condition_selectivity=3
+--echo #
+
+CREATE TABLE t1 (pk int PRIMARY KEY, a int);
+INSERT INTO t1 VALUES
+ (1,4), (2,6), (3,3), (4,5);
+
+CREATE TABLE t2 (b int);
+INSERT INTO t2 VALUES (1), (7);
+
+set optimizer_use_condition_selectivity=1;
+EXPLAIN EXTENDED
+SELECT 1 FROM t1, t2 WHERE pk = 6 AND a = 2 AND b = 10;
+SELECT 1 FROM t1, t2 WHERE pk = 6 AND a = 2 AND b = 10;
+
+set optimizer_use_condition_selectivity=3;
+EXPLAIN EXTENDED
+SELECT 1 FROM t1, t2 WHERE pk = 6 AND a = 2 AND b = 10;
+SELECT 1 FROM t1, t2 WHERE pk = 6 AND a = 2 AND b = 10;
+
+DROP TABLE t1,t2;
+
+set optimizer_use_condition_selectivity=@save_optimizer_use_condition_selectivity;
+
+--echo #
+--echo # Bug mdev-4370: Histograms have bean created, but the query is run after
+--echo # FLUSH TABLES with optimizer_use_condition_selectivity=3
+--echo #
+
+set use_stat_tables=PREFERABLY;
+set histogram_size=10;
+set histogram_type='SINGLE_PREC_HB';
+
+CREATE TABLE t1 (a int);
+INSERT INTO t1 VALUES (9), (1);
+ANALYZE TABLE t1;
+FLUSH TABLES;
+
+set optimizer_use_condition_selectivity=3;
+
+EXPLAIN EXTENDED
+SELECT * FROM t1 WHERE a > 3;
+SELECT * FROM t1 WHERE a > 3;
+
+set optimizer_use_condition_selectivity=@save_optimizer_use_condition_selectivity;
+
+DROP TABLE t1;
+
+set histogram_size=@save_histogram_size;
+set histogram_type=@save_histogram_type;
+set use_stat_tables=@save_use_stat_tables;
+
+--echo #
+--echo # Bug mdev-4371: Join with condition supported by index on an empty table
+--echo # with optimizer_use_condition_selectivity=3
+--echo #
+
+set use_stat_tables=PREFERABLY;
+
+CREATE TABLE t1 (a int, b int, INDEX(a));
+
+CREATE TABLE t2 (c int);
+INSERT INTO t2 VALUES (1),(2),(3),(4),(5),(6),(7),(8);
+
+ANALYZE TABLE t1, t2;
+FLUSH TABLES;
+
+set optimizer_use_condition_selectivity=3;
+
+set @save_optimizer_switch=@@optimizer_switch;
+set optimizer_switch='index_condition_pushdown=off';
+
+EXPLAIN EXTENDED
+SELECT * FROM t1, t2 WHERE a > 9;
+SELECT * FROM t1, t2 WHERE a > 9;
+
+set optimizer_switch=@save_optimizer_switch;
+
+set optimizer_use_condition_selectivity=@save_optimizer_use_condition_selectivity;
+
+DROP TABLE t1,t2;
+
+set use_stat_tables=@save_use_stat_tables;
+
+--echo #
+--echo # Bug mdev-4373: condition on a short varchar column
+--echo # with optimizer_use_condition_selectivity=3
+--echo #
+
+set use_stat_tables=PREFERABLY;
+
+CREATE TABLE t1 (a varchar(1));
+INSERT INTO t1 VALUES ('x'), ('y');
+
+ANALYZE TABLE t1;
+FLUSH TABLES;
+
+set optimizer_use_condition_selectivity=3;
+
+SELECT * FROM t1 WHERE a <= 'w';
+
+set optimizer_use_condition_selectivity=@save_optimizer_use_condition_selectivity;
+
+DROP TABLE t1;
+
+set use_stat_tables=@save_use_stat_tables;
+
+--echo #
+--echo # Bug mdev-4372: exists subquery in WHERE
+--echo # with optimizer_use_condition_selectivity=3
+--echo #
+
+set use_stat_tables = PREFERABLY;
+
+CREATE TABLE t1 (a int);
+INSERT INTO t1 VALUES
+ (1),(7),(4),(7),(0),(2),(9),(4),(0),(9),(1),(3),(8),(8);
+CREATE TABLE t2 (b int);
+INSERT INTO t2 VALUES (4),(5),(2),(5),(1),(1),(2);
+
+ANALYZE TABLE t1, t2;
+FLUSH TABLES;
+
+set optimizer_use_condition_selectivity=3;
+
+EXPLAIN EXTENDED
+SELECT * FROM t1, t2 WHERE EXISTS ( SELECT 1 FROM t1, t2 ) AND a != b OR a <= 4;
+
+set optimizer_use_condition_selectivity=@save_optimizer_use_condition_selectivity;
+
+DROP TABLE t1,t2;
+
+set use_stat_tables=@save_use_stat_tables;
+
+
+--echo #
+--echo # Bug mdev-4363: selectivity of the condition a IS NULL OR IS NOT NULL
+--echo # with optimizer_use_condition_selectivity=3
+--echo #
+
+set use_stat_tables = PREFERABLY;
+
+CREATE TABLE t1 (a int);
+INSERT INTO t1 VALUES
+ (1),(7),(4),(7),(NULL),(2),(NULL),(4),(NULL),(NULL),(1),(3),(8),(8);
+
+ANALYZE TABLE t1;
+FLUSH TABLE t1;
+
+set optimizer_use_condition_selectivity=3;
+
+EXPLAIN EXTENDED
+SELECT * FROM t1 WHERE a IS NULL;
+EXPLAIN EXTENDED
+SELECT * FROM t1 WHERE a IS NOT NULL;
+EXPLAIN EXTENDED
+SELECT * FROM t1 WHERE a IS NULL OR a IS NOT NULL;
+EXPLAIN EXTENDED
+SELECT * FROM t1 WHERE a IS NULL OR a < 5;
+
+set optimizer_use_condition_selectivity=@save_optimizer_use_condition_selectivity;
+
+DROP TABLE t1;
+
+set use_stat_tables=@save_use_stat_tables;
+
+--echo #
+--echo # Bug mdev-4378: 2-way join with a materialized IN subquery in WHERE
+--echo # when optimizer_use_condition_selectivity=4
+--echo #
+
+set use_stat_tables=PREFERABLY;
+set histogram_size=50;
+set histogram_type=SINGLE_PREC_HB;
+
+CREATE TABLE t1 (a INT) ENGINE=MyISAM;
+INSERT INTO t1 VALUES (8),(9),(6);
+
+CREATE TABLE t2 (b INT) ENGINE=MyISAM;
+INSERT INTO t2 VALUES (8),(1),(8),(9),(24),(6),(1),(6),(2),(4);
+
+CREATE TABLE t3 (ln VARCHAR(16)) ENGINE=MyISAM;
+INSERT INTO t3 VALUES
+('smith'),('black'),('white'),('jones'),
+('brown'),('taylor'),('anderson'),('taylor');
+
+ANALYZE TABLE t1, t2, t3;
+FLUSH TABLES;
+
+set optimizer_use_condition_selectivity=4;
+
+SELECT * FROM t1, t2 WHERE 'garcia' IN ( SELECT MIN( ln ) FROM t3 WHERE ln = 'sun' );
+
+set histogram_size=@save_histogram_size;
+set histogram_type=@save_histogram_type;
+set optimizer_use_condition_selectivity=@save_optimizer_use_condition_selectivity;
+
+DROP TABLE t1,t2,t3;
+
+set use_stat_tables=@save_use_stat_tables;
+
+--echo #
+--echo # Bug mdev-4380: 2-way join with a materialized IN subquery in WHERE
+--echo # when optimizer_use_condition_selectivity=3
+--echo #
+
+set use_stat_tables=PREFERABLY;
+CREATE TABLE t1 (a INT);
+INSERT INTO t1 VALUES (5),(9);
+
+CREATE TABLE t2 (b VARCHAR(8));
+INSERT INTO t2 VALUES ('red'),('blue');
+
+CREATE TABLE t3 (c VARCHAR(8), d VARCHAR(8));
+INSERT INTO t3 VALUES ('white','black'),('cyan','yellow');
+
+ANALYZE TABLE t1, t2, t3;
+FLUSH TABLES;
+
+set optimizer_use_condition_selectivity=3;
+
+SELECT * FROM t1, t2 WHERE ( 'orange', 'green' ) IN (
+ SELECT MAX(c), MAX(d) FROM t3, t2 WHERE c >= d AND b = c
+);
+
+set optimizer_use_condition_selectivity=@save_optimizer_use_condition_selectivity;
+
+DROP TABLE t1,t2,t3;
+
+set use_stat_tables=@save_use_stat_tables;
+
+--echo #
+--echo # Bug mdev-4389: join with degenerated range condition in WHERE
+--echo # when optimizer_use_condition_selectivity=3
+--echo #
+
+set use_stat_tables=PREFERABLY;
+
+CREATE TABLE t1 (f1 VARCHAR(1));
+INSERT t1 VALUES ('p'),('q');
+
+CREATE TABLE t2 (f2 VARCHAR(1));
+INSERT INTO t2 VALUES
+ ('o'),('v'),('f'),('f'),('e'),('l'),('j'),('p'),('r'),('j'),
+ ('j'),('u'),('i'),('r'),('x'),('a'),('x'),('s');
+
+ANALYZE TABLE t1, t2;
+FLUSH TABLES;
+
+SET optimizer_use_condition_selectivity=3;
+
+SELECT * FROM t1, t2 AS t2a, t2 AS t2b WHERE f1 <= 'a' AND t2a.f2 = f1;
+
+set optimizer_use_condition_selectivity=@save_optimizer_use_condition_selectivity;
+
+DROP TABLE t1,t2;
+
+set use_stat_tables=@save_use_stat_tables;
+
+--echo #
+--echo # Bug mdev-4406: range condition for non-nullable column
+--echo # when optimizer_use_condition_selectivity=3
+--echo #
+
+create table t1 (a int not null);
+insert into t1 values
+ (7), (6), (4), (9), (1), (5), (2), (1), (3), (8);
+
+set use_stat_tables='preferably';
+
+analyze table t1;
+flush table t1;
+
+set optimizer_use_condition_selectivity=3;
+
+select count(*) from t1 where a between 5 and 7;
+explain extended select * from t1 where a between 5 and 7;
+
+alter table t1 change column a a int;
+analyze table t1;
+flush table t1;
+
+explain extended select * from t1 where a between 5 and 7;
+
+set optimizer_use_condition_selectivity=@save_optimizer_use_condition_selectivity;
+
+drop table t1;
+
+set use_stat_tables=@save_use_stat_tables;
+
+
+--echo #
+--echo # Bug mdev-5200: impossible where with a semijoin subquery
+--echo # when optimizer_use_condition_selectivity=2
+--echo #
+
+set use_stat_tables = 'preferably';
+set optimizer_use_condition_selectivity = 2;
+
+CREATE TABLE t1 (i1 int) ENGINE=MyISAM;
+INSERT INTO t1 VALUES (0), (1);
+
+CREATE TABLE t2 (pk2 int, i2 int, c2 char(1), PRIMARY KEY(pk2)) ENGINE=MyISAM;
+INSERT INTO t2 VALUES (1,8,'m'), (2,9,'b');
+
+CREATE TABLE t3 (c3 char(1), INDEX(c3)) ENGINE=MyISAM;
+INSERT INTO t3 VALUES ('v'), ('c');
+
+ANALYZE TABLE t1,t2,t3;
+
+SELECT * FROM t1
+ WHERE 2 IN ( SELECT pk2 FROM t2 LEFT JOIN t3 ON (c3 = c2 ) WHERE i2 = 3 );
+EXPLAIN EXTENDED
+SELECT * FROM t1
+ WHERE 2 IN ( SELECT pk2 FROM t2 LEFT JOIN t3 ON (c3 = c2 ) WHERE i2 = 3 );
+
+set optimizer_use_condition_selectivity=@save_optimizer_use_condition_selectivity;
+
+DROP TABLE t1,t2,t3;
+
+--echo #
+--echo # Bug mdev-5415: query over an information schema table
+--echo # when optimizer_use_condition_selectivity=3
+--echo #
+
+set optimizer_use_condition_selectivity = 3;
+
+SELECT * FROM INFORMATION_SCHEMA.TRIGGERS WHERE SQL_MODE != '';
+
+set optimizer_use_condition_selectivity=@save_optimizer_use_condition_selectivity;
+
+--echo #
+--echo # Bug mdev-5630: always true conjunctive condition
+--echo # when optimizer_use_condition_selectivity=3
+--echo #
+
+set use_stat_tables = 'preferably';
+set optimizer_use_condition_selectivity = 3;
+
+CREATE TABLE t1 (a int) ENGINE=MyISAM;
+INSERT INTO t1 VALUES (10);
+
+CREATE TABLE t2 (id int, flag char(1), INDEX(id)) ENGINE=MyISAM;
+INSERT INTO t2 VALUES (100,'0'),(101,'1');
+
+ANALYZE TABLE t1, t2;
+
+SELECT * FROM t1, t2 WHERE id = a AND ( a = 16 OR flag AND a != 6 );
+
+DROP TABLE t1,t2;
+
+--echo #
+--echo # Bug mdev-4429: join with range condition whose selectivity == 0
+--echo # when optimizer_use_condition_selectivity=3
+--echo #
+
+CREATE TABLE language (lang_group INT, lang VARCHAR(16) PRIMARY KEY);
+INSERT INTO language VALUES
+ (1,'Chinese'),(6,'English'),(1,'French'),
+ (1,'German'),(1,'Italian'),(0,'Japanese');
+
+CREATE TABLE country (code varchar(3) PRIMARY KEY,
+ country_group INT DEFAULT NULL);
+INSERT INTO country VALUES ('USA',3),('FRA',5);
+
+CREATE TABLE continent (cont_group INT, cont varchar(16) PRIMARY KEY);
+INSERT INTO continent VALUES
+ (1,'N.America'),(1,'S.America'),(3,'Australia'),
+ (4,'Africa'),(5,'Antarctica'),(6,'Eurasia');
+
+SET use_stat_tables=PREFERABLY;
+ANALYZE TABLE country, language, continent;
+FLUSH TABLES;
+SET optimizer_use_condition_selectivity=3;
+
+SELECT * FROM language, country, continent
+ WHERE country_group = lang_group AND lang_group IS NULL;
+EXPLAIN EXTENDED
+SELECT * FROM language, country, continent
+ WHERE country_group = lang_group AND lang_group IS NULL;
+
+set optimizer_use_condition_selectivity=@save_optimizer_use_condition_selectivity;
+
+drop table language, country, continent;
+
+set use_stat_tables=@save_use_stat_tables;
+
+--echo #
+--echo # Bug mdev-5191: performance degradation due to a suboptimal chosen plan
+--echo # when optimizer_use_condition_selectivity=3
+--echo #
+
+set use_stat_tables = 'preferably';
+
+set @@RAND_SEED1=810763568, @@RAND_SEED2=600681772;
+set TIMESTAMP=1394806993;
+
+create table t1 (a int, b int) engine=myisam;
+insert t1 values (rand()*1e5, rand()*1e5);
+insert t1 select rand()*1e5, rand()*1e5 from t1;
+insert t1 select rand()*1e5, rand()*1e5 from t1;
+insert t1 select rand()*1e5, rand()*1e5 from t1;
+insert t1 select rand()*1e5, rand()*1e5 from t1;
+insert t1 select rand()*1e5, rand()*1e5 from t1;
+insert t1 select rand()*1e5, rand()*1e5 from t1;
+insert t1 select rand()*1e5, rand()*1e5 from t1;
+insert t1 select rand()*1e5, rand()*1e5 from t1;
+insert t1 select rand()*1e5, rand()*1e5 from t1;
+insert t1 select rand()*1e5, rand()*1e5 from t1;
+insert t1 select rand()*1e5, rand()*1e5 from t1;
+insert t1 select rand()*1e5, rand()*1e5 from t1;
+insert t1 select rand()*1e5, rand()*1e5 from t1;
+insert t1 select rand()*1e5, rand()*1e5 from t1;
+insert t1 select rand()*1e5, rand()*1e5 from t1;
+insert t1 select rand()*1e5, rand()*1e5 from t1;
+insert t1 select rand()*1e5, rand()*1e5 from t1;
+insert t1 select rand()*1e5, rand()*1e5 from t1;
+
+create table t2 (c int, d int, key(c), key(d)) engine=myisam;
+insert t2 select floor(rand()*1e5/2)*2, floor(rand()*1e5/3)*3 from t1;
+
+analyze table t1,t2;
+
+set optimizer_use_condition_selectivity=1;
+explain extended
+select * from t1, t2, t1 as t3
+ where t1.b=t2.c and t2.d=t3.a and t3.b<5 and t1.a < 2000;
+select * from t1, t2, t1 as t3
+ where t1.b=t2.c and t2.d=t3.a and t3.b<5 and t1.a < 2000;
+
+set optimizer_use_condition_selectivity=3;
+explain extended
+select * from t1, t2, t1 as t3
+ where t1.b=t2.c and t2.d=t3.a and t3.b<5 and t1.a < 2000;
+select * from t1, t2, t1 as t3
+ where t1.b=t2.c and t2.d=t3.a and t3.b<5 and t1.a < 2000;
+
+set optimizer_use_condition_selectivity=@save_optimizer_use_condition_selectivity;
+
+drop table t1,t2;
+
+set histogram_type=@save_histogram_type;
+set histogram_size=@save_histogram_size;
+set optimizer_use_condition_selectivity=@save_optimizer_use_condition_selectivity;
+
+
+--echo #
+--echo # Bug mdev-5931: no where condition after constant table row substitution
+--echo # with optimizer_use_condition_selectivity=3
+--echo #
+
+CREATE TABLE t1 (a varchar(3), b varchar(3)) ENGINE=MyISAM;
+INSERT INTO t1 VALUES ('foo', 'foo');
+
+CREATE TABLE t2 (c INT) ENGINE=MyISAM;
+INSERT INTO t2 VALUES (1), (2);
+
+set optimizer_use_condition_selectivity=3;
+
+EXPLAIN EXTENDED
+SELECT * FROM t1, t2 WHERE c >= 0 OR a = b ;
+
+SELECT * FROM t1, t2 WHERE c >= 0 OR a = b ;
+
+set optimizer_use_condition_selectivity=@save_optimizer_use_condition_selectivity;
+
+DROP TABLE t1,t2;
+
+--echo #
+--echo # Bug mdev-6325: wrong selectivity of a column with ref access
+--echo #
+
+create table t0(a int);
+insert into t0 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
+create table t1(a int);
+insert into t1 select A.a + B.a* 10 + C.a * 100 from t0 A, t0 B, t0 C;
+create table t2 (a int, b int, key(a));
+insert into t2 select A.a + 10*B.a, 12345 from t0 A, t0 B, t0 C;
+
+set use_stat_tables='preferably';
+set histogram_size=100;
+
+set optimizer_use_condition_selectivity=4;
+analyze table t1 persistent for all;
+analyze table t2 persistent for all;
+
+explain extended
+select * from t1 straight_join t2 where t1.a=t2.a and t1.a<10;
+explain extended
+select * from t1 straight_join t2 where t1.a=t2.a and t2.a<10;
+
+set histogram_size=@save_histogram_size;
+set optimizer_use_condition_selectivity=@save_optimizer_use_condition_selectivity;
+
+drop table t0,t1,t2;
+
+--echo #
+--echo # Bug mdev-6843: col IS NULL in where condition when col is always NULL
+--echo #
+
+create table t0(a int);
+insert into t0 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
+create table t1(a int);
+insert into t1 select A.a + B.a* 10 + C.a * 100 from t0 A, t0 B, t0 C;
+create table t2 (a int, b int);
+insert into t2 select NULL, a from t1;
+
+set use_stat_tables='preferably';
+set histogram_size=100;
+
+set optimizer_use_condition_selectivity=4;
+analyze table t2 persistent for all;
+
+explain extended
+select * from t2 a straight_join t2 b where a.a is null;
+
+set histogram_size=@save_histogram_size;
+set optimizer_use_condition_selectivity=@save_optimizer_use_condition_selectivity;
+
+drop table t0,t1,t2;
+
+--echo #
+--echo # Bug mdev-7316: a conjunct in WHERE with selectivity == 0
+--echo #
+
+CREATE TABLE t1 (a varchar(16), b int, PRIMARY KEY(a), KEY(b)) ENGINE=INNODB;
+INSERT INTO t1 VALUES
+ ('USAChinese',10), ('USAEnglish',20), ('USAFrench',30);
+
+CREATE TABLE t2 (i int) ENGINE=INNODB;
+INSERT INTO t2 VALUES
+ (1),(2),(3),(4),(5),(6),(7),(8),(9),(10),(1),(2),(3),(4);
+
+ANALYZE TABLE t1, t2;
+
+set use_stat_tables='preferably';
+set optimizer_use_condition_selectivity=3;
+
+EXPLAIN EXTENDED
+SELECT * FROM t1, t2
+ WHERE a <> 'USARussian' AND b IS NULL;
+
+SELECT * FROM t1, t2
+ WHERE a <> 'USARussian' AND b IS NULL;
+
+set optimizer_use_condition_selectivity=@save_optimizer_use_condition_selectivity;
+
+DROP TABLE t1,t2;
+
+set use_stat_tables=@save_use_stat_tables;
+
+--echo #
+--echo # Bug mdev-11096: range condition over column without statistical data
+--echo #
+
+set use_stat_tables='preferably';
+set optimizer_use_condition_selectivity=3;
+
+create table t1(col1 char(32));
+insert into t1 values ('a'),('b'),('c'),('d'), ('e'),('f'),('g'),('h');
+analyze table t1 persistent for columns () indexes ();
+
+explain extended
+select * from t1 where col1 > 'b' and col1 < 'e';
+select * from t1 where col1 > 'b' and col1 < 'e';
+
+drop table t1;
+
+set optimizer_use_condition_selectivity=@save_optimizer_use_condition_selectivity;
+set use_stat_tables=@save_use_stat_tables;
+
+--echo #
+--echo # Bug mdev-9628: unindexed blob column without min-max statistics
+--echo # with optimizer_use_condition_selectivity=3
+--echo #
+
+set use_stat_tables='preferably';
+set optimizer_use_condition_selectivity=3;
+
+create table t1(col1 char(32));
+insert into t1 values ('a'),('b'),('c'),('d'), ('e'),('f'),('g'),('h');
+analyze table t1;
+
+create table t2(col1 text);
+insert into t2 values ('a'),('b'),('c'),('d'), ('e'),('f'),('g'),('h');
+analyze table t2;
+
+select * from t1 where col1 > 'b' and col1 < 'd';
+explain extended
+select * from t1 where col1 > 'b' and col1 < 'd';
+
+select * from t2 where col1 > 'b' and col1 < 'd';
+explain extended
+select * from t2 where col1 > 'b' and col1 < 'd';
+
+select * from t2 where col1 < 'b' and col1 > 'd';
+explain extended
+select * from t2 where col1 < 'b' and col1 > 'd';
+
+drop table t1,t2;
+
+set optimizer_use_condition_selectivity=@save_optimizer_use_condition_selectivity;
+set use_stat_tables=@save_use_stat_tables;
+
+--echo #
+--echo # Bug mdev-11364: IS NULL over not nullable datetime column
+--echo # in mergeable derived
+--echo #
+
+set use_stat_tables='preferably';
+set optimizer_use_condition_selectivity=4;
+set HISTOGRAM_SIZE = 255;
+
+CREATE TABLE t1 (t TIME, d DATE NOT NULL);
+INSERT INTO t1 VALUES ('10:00:00', '0000-00-00'),('11:00:00','0000-00-00');
+
+ANALYZE TABLE t1;
+
+SELECT * FROM (SELECT t FROM t1 WHERE d IS NULL) sq;
+
+DROP TABLE t1;
+
+set histogram_size=@save_histogram_size;
+set optimizer_use_condition_selectivity=@save_optimizer_use_condition_selectivity;
+set use_stat_tables=@save_use_stat_tables;
diff --git a/mysql-test/t/selectivity_innodb.test b/mysql-test/t/selectivity_innodb.test
new file mode 100644
index 00000000000..25aa0abbc3b
--- /dev/null
+++ b/mysql-test/t/selectivity_innodb.test
@@ -0,0 +1,143 @@
+--source include/have_innodb.inc
+
+SET SESSION STORAGE_ENGINE='InnoDB';
+
+set @save_optimizer_switch_for_selectivity_test=@@optimizer_switch;
+set optimizer_switch='extended_keys=on';
+
+--source selectivity.test
+
+set optimizer_switch=@save_optimizer_switch_for_selectivity_test;
+set @tmp_ust= @@use_stat_tables;
+set @tmp_oucs= @@optimizer_use_condition_selectivity;
+
+
+--echo #
+--echo # MDEV-6808: MariaDB 10.0.13 crash with optimizer_use_condition_selectivity > 1
+--echo #
+set @tmp_mdev6808= @@optimizer_use_condition_selectivity;
+SET optimizer_use_condition_selectivity = 2;
+CREATE TABLE t1 (
+ event_id int(11) unsigned NOT NULL AUTO_INCREMENT,
+ PRIMARY KEY (event_id)
+) ENGINE=InnoDB;
+
+CREATE TABLE t2 (
+ repost_id int(11) unsigned NOT NULL AUTO_INCREMENT,
+ subject_type varchar(24) CHARACTER SET latin1 COLLATE latin1_general_ci NOT NULL,
+ subject_id int(11) unsigned NOT NULL,
+ object_type varchar(24) CHARACTER SET latin1 COLLATE latin1_general_ci NOT NULL,
+ object_id int(11) unsigned NOT NULL,
+ is_private int(1) NOT NULL DEFAULT '0',
+ PRIMARY KEY (repost_id),
+ UNIQUE KEY `BETWEEN` (subject_type,subject_id,object_type,object_id,is_private),
+ KEY SUBJECT (subject_type,subject_id),
+ KEY OBJECT (object_type,object_id)
+) ENGINE=InnoDB;
+
+SELECT
+ *
+FROM
+ t2, t1
+WHERE
+ t2.object_type = 'event' AND
+ t2.object_id = t1.event_id AND
+ t2.is_private = 0 AND
+ t2.subject_id = 127994 AND
+ t2.subject_type in ('user')
+;
+DROP TABLE t1, t2;
+set optimizer_use_condition_selectivity=@tmp_mdev6808;
+
+--echo #
+--echo # MDEV-6442: Assertion `join->best_read < double(...)' failed with optimizer_use_condition_selectivity >=3, ...
+--echo #
+SET use_stat_tables = PREFERABLY;
+SET optimizer_use_condition_selectivity = 3;
+
+CREATE TABLE t1 ( a VARCHAR(3), b VARCHAR(8), KEY (a,b) ) ENGINE=InnoDB;
+INSERT INTO t1 VALUES ('USA','Chinese'),('USA','English');
+
+CREATE TABLE t2 (i INT) ENGINE=InnoDB;
+
+SELECT * FROM t1, t2 WHERE ( 't', 'o' ) IN (
+ SELECT t1_2.b, t1_1.a FROM t1 AS t1_1 STRAIGHT_JOIN t1 AS t1_2 ON ( t1_2.a = t1_1.b )
+);
+DROP TABLE t1,t2;
+
+--echo #
+--echo # MDEV-6738: use_stat_table + histograms crashing optimizer
+--echo #
+
+set use_stat_tables='preferably';
+set optimizer_use_condition_selectivity=4;
+
+--echo # Need innodb because there is a special kind of field_bit for non-myisam tables
+create table t1(col1 int, col2 bit(1) DEFAULT NULL) engine=innodb;
+
+select * from t1 where col2 != true;
+
+drop table t1;
+
+--echo #
+--echo # MDEV-7413: optimizer_use_condition_selectivity > 2 crashes 10.0.15+maria-1~wheezy
+--echo #
+
+CREATE TABLE t1 (
+ parent_id int,
+ child_group_id int,
+ child_user_id int,
+ KEY (parent_id,child_group_id,child_user_id)
+) ENGINE=InnoDB;
+
+CREATE TABLE t2 (
+ id int,
+ lower_group_name varchar(255),
+ directory_id int(20),
+ UNIQUE KEY (directory_id)
+) ENGINE=InnoDB;
+
+CREATE TABLE t3 (id int) ENGINE=InnoDB;
+
+insert into t1 values (1,1,1),(2,2,2);
+insert into t2 values (10,'foo',10),(20,'bar',20);
+insert into t3 values (101),(102);
+set use_stat_tables = PREFERABLY, optimizer_use_condition_selectivity = 3;
+
+select * from t1, t2, t3
+where t1.child_user_id=t3.id and t1.child_group_id is null and t2.lower_group_name='foo' and t1.parent_id=t2.id and t2.directory_id=10;
+
+drop table t1,t2,t3;
+
+--echo #
+--echo # MDEV-9187: duplicate of bug mdev-9628
+--echo #
+
+set use_stat_tables = preferably;
+set optimizer_use_condition_selectivity=3;
+
+CREATE TABLE t1 (f1 char(32)) ENGINE=InnoDB;
+INSERT INTO t1 VALUES ('foo'),('bar'),('qux');
+ANALYZE TABLE t1;
+
+SELECT * FROM t1 WHERE f1 < 'm';
+EXPLAIN EXTENDED
+SELECT * FROM t1 WHERE f1 < 'm';
+
+CREATE TABLE t2 (f1 TEXT) ENGINE=InnoDB;
+INSERT INTO t2 VALUES ('foo'),('bar'),('qux');
+ANALYZE TABLE t2;
+
+SELECT * FROM t2 WHERE f1 <> 'qux';
+EXPLAIN EXTENDED
+SELECT * FROM t2 WHERE f1 <> 'qux';
+
+DROP TABLE t1,t2;
+
+--echo #
+--echo # End of 10.0 tests
+--echo #
+
+set use_stat_tables= @tmp_ust;
+set optimizer_use_condition_selectivity= @tmp_oucs;
+SET SESSION STORAGE_ENGINE=DEFAULT;
diff --git a/mysql-test/t/selectivity_no_engine.test b/mysql-test/t/selectivity_no_engine.test
new file mode 100644
index 00000000000..2a31c01ed97
--- /dev/null
+++ b/mysql-test/t/selectivity_no_engine.test
@@ -0,0 +1,238 @@
+--source include/have_stat_tables.inc
+
+--echo #
+--echo # Engine-agnostic tests for statistics-based selectivity calculations.
+--echo # - selectivity tests that depend on the engine should go into
+--echo # t/selectivity.test. That test is run with myisam/innodb/xtradb.
+--echo # - this file is for tests that don't depend on the engine.
+--echo #
+
+--disable_warnings
+drop table if exists t0,t1,t2,t3;
+--enable_warnings
+
+select @@global.use_stat_tables;
+select @@session.use_stat_tables;
+
+set @save_use_stat_tables=@@use_stat_tables;
+
+set use_stat_tables='preferably';
+
+set @save_optimizer_use_condition_selectivity=@@optimizer_use_condition_selectivity;
+set @save_histogram_size=@@histogram_size;
+set @save_histogram_type=@@histogram_type;
+
+--echo #
+--echo # MDEV-5917: EITS: different order of predicates in IN (...) causes different estimates
+--echo #
+create table t1(a int);
+insert into t1 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
+
+create table t2 (col1 int);
+--echo # one value in 1..100 range
+insert into t2 select ta.a + tb.a*10 from t1 ta, t1 tb;
+--echo # ten values in 100...200 range
+insert into t2 select 100 + ta.a + tb.a*10 from t1 ta, t1 tb, t1 tc;
+
+set histogram_type='SINGLE_PREC_HB';
+set histogram_size=100;
+set optimizer_use_condition_selectivity=4;
+analyze table t2 persistent for all;
+
+--echo # The following two must have the same in 'Extra' column:
+explain extended select * from t2 where col1 IN (20, 180);
+explain extended select * from t2 where col1 IN (180, 20);
+
+drop table t1, t2;
+
+--echo #
+--echo # MDEV-5926: EITS: Histogram estimates for column=least_possible_value are wrong
+--echo #
+create table t0(a int);
+insert into t0 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
+create table t1(a int);
+insert into t1 select ta.a from t0 ta, t0 tb, t0 tc;
+set histogram_size=20;
+set histogram_type='single_prec_hb';
+analyze table t1 persistent for all;
+set use_stat_tables='preferably';
+set optimizer_use_condition_selectivity=4;
+--echo # Should select about 10%:
+explain extended select * from t1 where a=2;
+--echo # Should select about 10%:
+explain extended select * from t1 where a=1;
+--echo # Must not have filtered=100%:
+explain extended select * from t1 where a=0;
+--echo # Again, must not have filtered=100%:
+explain extended select * from t1 where a=-1;
+
+drop table t0, t1;
+
+--echo #
+--echo # MDEV-4362: Selectivity estimates for IN (...) do not depend on whether the values are in range
+--echo #
+create table t1 (col1 int);
+set @a=-1;
+create table t2 (a int) select (@a:=@a+1) as a from information_schema.session_variables ta limit 100;
+insert into t1 select ta.a from t2 ta, t2 tb where ta.a < 100 and tb.a < 100;
+select min(col1), max(col1), count(*) from t1;
+set histogram_size=100;
+analyze table t1 persistent for all;
+explain extended select * from t1 where col1 in (1,2,3);
+--echo # Must not cause fp division by zero, or produce nonsense numbers:
+explain extended select * from t1 where col1 in (-1,-2,-3);
+explain extended select * from t1 where col1<=-1;
+drop table t1, t2;
+
+--echo #
+--echo # MDEV-5984: EITS: Incorrect filtered% value for single-table select with range access
+--echo #
+create table t1(a int);
+insert into t1 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
+
+create table t2 (a int, b int, col1 varchar(64), col2 varchar(64), key(a,b));
+insert into t2 select ta.a+10*tb.a, tc.a+10*td.a, 'filler-data1', 'filler-data2' from t1 ta, t1 tb, t1 tc, t1 td;
+
+set histogram_size=100;
+set optimizer_use_condition_selectivity=4;
+set use_stat_tables='preferably';
+analyze table t2 persistent for all;
+--echo # This must show filtered=100%:
+explain extended select * from t2 where a in (1,2,3) and b in (1,2,3);
+
+drop table t2, t1;
+
+--echo #
+--echo # MDEV-5980: EITS: if condition is used for REF access, its selectivity is still in filtered%
+--echo #
+create table t0(a int);
+insert into t0 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
+create table t1(key1 int, col1 int, key(key1));
+insert into t1 select ta.a, ta.a from t0 ta, t0 tb, t0 tc;
+
+set histogram_size=100;
+set use_stat_tables='preferably';
+set optimizer_use_condition_selectivity=4;
+analyze table t1 persistent for all;
+--echo # 10% is ok
+explain extended select * from t1 where col1=2;
+--echo # Must show 100%, not 10%
+explain extended select * from t1 where key1=2;
+drop table t0, t1;
+
+--echo # MDEV-6003: EITS: ref access, keypart2=const vs keypart2=expr - inconsistent filtered% value
+--echo #
+create table t0(a int);
+insert into t0 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
+create table t1 (
+ kp1 int, kp2 int,
+ filler1 char(100),
+ filler2 char(100),
+ key(kp1, kp2)
+);
+
+insert into t1
+select
+ ta.a,
+ tb.a,
+ 'filler-data-1',
+ 'filler-data-2'
+from t0 ta, t0 tb, t0 tc;
+set histogram_size=100;
+set use_stat_tables='preferably';
+set optimizer_use_condition_selectivity=4;
+analyze table t1 persistent for all;
+--echo # NOTE: 10*100%, 10*100% rows is ok
+explain extended select * from t0, t1 where t1.kp1=t0.a and t1.kp2=t0.a+1;
+
+--echo # NOTE: t0: 10*100% is ok, t1: 10*9.90% is bad. t1 should have 10*100%.
+explain extended select * from t0, t1 where t1.kp1=t0.a and t1.kp2=4;
+drop table t0, t1;
+
+--echo #
+--echo # MDEV-6209: Assertion `join->best_read < double(1.79769313486231570815e+308L)'
+--echo # failed in bool greedy_search with optimizer_use_condition_selectivity>1
+--echo #
+SET optimizer_use_condition_selectivity = 2;
+
+CREATE TABLE t1 (a CHAR(6), b INT, PRIMARY KEY (a,b)) ENGINE=MyISAM;
+INSERT INTO t1 VALUES ('foo',1),('bar',2);
+
+SELECT * FROM t1 AS t1_1, t1 AS t1_2 WHERE NOT ( t1_1.a <> 'baz');
+DROP TABLE t1;
+
+--echo #
+--echo # MDEV-6308: Server crashes in table_multi_eq_cond_selectivity with ...
+--echo #
+CREATE TABLE t1 (
+ id varchar(40) COLLATE utf8_bin,
+ dt datetime,
+ PRIMARY KEY (id)
+);
+
+INSERT INTO t1 VALUES ('foo','2011-04-12 05:18:08'),
+ ('bar','2013-09-19 11:37:03');
+
+CREATE TABLE t2 (
+ t1_id varchar(40) COLLATE utf8_bin,
+ f1 varchar(64),
+ f2 varchar(1024),
+ KEY (f1,f2(255))
+);
+
+INSERT INTO t2 VALUES ('foo','baz','qux'),('bar','baz','qux');
+
+set optimizer_use_condition_selectivity=2;
+explain
+select * from t1,t2 where t1.id = t2.t1_id and t2.f2='qux' and t2.f1='baz';
+select * from t1,t2 where t1.id = t2.t1_id and t2.f2='qux' and t2.f1='baz';
+
+drop table t1,t2;
+
+--echo #
+--echo # MDEV-5985: EITS: selectivity estimates look illogical for join and non-key equalities
+--echo #
+
+create table t0(a int);
+insert into t0 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
+create table t1(a int);
+insert into t1 select ta.a + tb.a* 10 + tc.a * 100 from t0 ta, t0 tb, t0 tc;
+create table t2 as select * from t1;
+set histogram_size=100;
+set use_stat_tables='preferably';
+set optimizer_use_condition_selectivity=4;
+analyze table t1 persistent for all;
+analyze table t2 persistent for all;
+--echo # Filtered will be 4.95, 9.90
+explain extended select * from t1 ta, t2 tb where ta.a < 40 and tb.a < 100;
+--echo # Here, tb.filtered should not become 100%:
+explain extended select * from t1 ta, t2 tb where ta.a < 40 and tb.a < 100 and tb.a=ta.a;
+
+drop table t0,t1,t2;
+
+--echo #
+--echo # MDEV-8779: mysqld got signal 11 in sql/opt_range_mrr.cc:100(step_down_to)
+--echo #
+set @tmp_mdev8779=@@optimizer_use_condition_selectivity;
+set optimizer_use_condition_selectivity=5;
+CREATE TABLE t1 (
+ i int(10) unsigned NOT NULL AUTO_INCREMENT,
+ n varchar(2048) NOT NULL,
+ d tinyint(1) unsigned NOT NULL,
+ p int(10) unsigned NOT NULL,
+ PRIMARY KEY (i)
+) DEFAULT CHARSET=utf8;
+insert into t1 values (1,'aaa',1,1), (2,'bbb',2,2);
+SELECT * FROM t1 WHERE t1.d = 0 AND t1.p = '1' AND t1.i != '-1' AND t1.n = 'some text';
+set optimizer_use_condition_selectivity= @tmp_mdev8779;
+DROP TABLE t1;
+
+--echo #
+--echo # End of the test file
+--echo #
+
+set use_stat_tables= @save_use_stat_tables;
+set histogram_type=@save_histogram_type;
+set histogram_size=@save_histogram_size;
+set optimizer_use_condition_selectivity=@save_optimizer_use_condition_selectivity;
+
diff --git a/mysql-test/t/servers.test b/mysql-test/t/servers.test
new file mode 100644
index 00000000000..ee0fa637b87
--- /dev/null
+++ b/mysql-test/t/servers.test
@@ -0,0 +1,8 @@
+# Generic tests for servers (do not require FEDERATED)
+
+--echo #
+--echo # MDEV-4594 - CREATE SERVER crashes embedded
+--echo #
+CREATE SERVER s1 FOREIGN DATA WRAPPER mysql OPTIONS(HOST 'localhost');
+SELECT * FROM mysql.servers;
+DROP SERVER s1;
diff --git a/mysql-test/t/show_check-master.opt b/mysql-test/t/show_check-master.opt
index 108caf42203..a16d72855a2 100644
--- a/mysql-test/t/show_check-master.opt
+++ b/mysql-test/t/show_check-master.opt
@@ -1 +1 @@
---log-output=table,file --log-slow-queries --log-queries-not-using-indexes --myisam-recover=""
+--log-output=table,file --slow-query-log --log-queries-not-using-indexes --myisam-recover=""
diff --git a/mysql-test/t/show_check.test b/mysql-test/t/show_check.test
index c2edef87d41..c43193d1b57 100644
--- a/mysql-test/t/show_check.test
+++ b/mysql-test/t/show_check.test
@@ -429,7 +429,9 @@ system echo "this is a junk file for test" >> $MYSQLD_DATADIR/test/t1.frm ;
SHOW TABLE STATUS like 't1';
--error ER_NOT_FORM_FILE
show create table t1;
+--disable_warnings
drop table if exists t1;
+--enable_warnings
--error 1,0
--remove_file $MYSQLD_DATADIR/test/t1.frm
@@ -1208,33 +1210,8 @@ disconnect conn1;
connection default;
DROP USER test_u@localhost;
-
---echo #
---echo # Bug #48985: show create table crashes if previous access to the table
---echo # was killed
---echo #
-
-connect(con1,localhost,root,,);
-CONNECTION con1;
-LET $ID= `SELECT connection_id()`;
-
-CONNECTION default;
---disable_query_log
-eval KILL QUERY $ID;
---enable_query_log
-
-CONNECTION con1;
---error ER_QUERY_INTERRUPTED
-SHOW CREATE TABLE non_existent;
-
-DISCONNECT con1;
---source include/wait_until_disconnected.inc
-CONNECTION default;
-
-
--echo End of 5.1 tests
-
--echo #
--echo # Bug#52593 SHOW CREATE TABLE is blocked if table is locked
--echo # for write by another connection
@@ -1373,7 +1350,7 @@ SET NAMES latin1;
--echo #
---echo # WL#6454: Deprecate SHOW AUTHORS and SHOW CONTRIBUTORS
+--echo # Test SHOW AUTHORS and SHOW CONTRIBUTORS
--echo #
--disable_result_log
diff --git a/mysql-test/t/show_explain.test b/mysql-test/t/show_explain.test
new file mode 100644
index 00000000000..83c05d93007
--- /dev/null
+++ b/mysql-test/t/show_explain.test
@@ -0,0 +1,1204 @@
+#
+# Tests for SHOW EXPLAIN FOR functionality
+#
+--source include/have_debug.inc
+--source include/have_innodb.inc
+
+--disable_warnings
+drop table if exists t0, t1, t2, t3, t4;
+drop view if exists v1;
+--enable_warnings
+SET @old_debug= @@session.debug;
+
+#
+# Testcases in this file do not work with embedded server. The reason for this
+# is that we use the following commands for synchronization:
+#
+# set @show_explain_probe_select_id=1;
+# set debug_dbug='d,show_explain_probe_join_exec_start';
+# send select count(*) from t1 where a < 100000;
+#
+# When ran with mysqltest_embedded, this translates into:
+#
+# Thread1> DBUG_PUSH("d,show_explain_probe_join_exec_start");
+# Thread1> create another thread for doing "send ... reap"
+# Thread2> mysql_parse("select count(*) from t1 where a < 100000");
+#
+# That is, "select count(*) ..." is ran in a thread for which DBUG_PUSH(...)
+# has not been called. As a result, show_explain_probe_join_exec_start does not fire, and
+# "select count(*) ..." does not wait till its SHOW EXPLAIN command, and the
+# test fails.
+#
+-- source include/not_embedded.inc
+
+set debug_sync='RESET';
+
+create table t0 (a int);
+insert into t0 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
+create table t1 (a int);
+insert into t1 select A.a + 10*B.a + 100*C.a from t0 A, t0 B, t0 C;
+alter table t1 add b int, add c int, add filler char(32);
+update t1 set b=a, c=a, filler='fooo';
+alter table t1 add key(a), add key(b);
+
+#
+# Try killing a non-existent thread
+#
+--error ER_NO_SUCH_THREAD
+show explain for 2000000000;
+
+--error ER_SET_CONSTANTS_ONLY
+show explain for (select max(a) from t0);
+
+#
+# Setup two threads and their ids
+#
+let $thr1=`select connection_id()`;
+connect (con1, localhost, root,,);
+connection con1;
+let $thr2=`select connection_id()`;
+SET @old_debug= @@session.debug;
+connection default;
+
+# SHOW EXPLAIN FOR <idle thread>
+--error ER_TARGET_NOT_EXPLAINABLE
+evalp show explain for $thr2;
+
+# SHOW EXPLAIN FOR <ourselves>
+--error ER_TARGET_NOT_EXPLAINABLE
+evalp show explain for $thr1;
+
+let $wait_condition= select State='show_explain_trap' from information_schema.processlist where id=$thr2;
+
+#
+# Test SHOW EXPLAIN for simple queries
+#
+connection con1;
+set @show_explain_probe_select_id=1;
+set debug_dbug='+d,show_explain_probe_join_exec_start';
+send select count(*) from t1 where a < 100000;
+
+connection default;
+--source include/wait_condition.inc
+evalp show explain for $thr2;
+connection con1;
+reap;
+
+
+send select max(c) from t1 where a < 10;
+connection default;
+--source include/wait_condition.inc
+evalp show explain for $thr2;
+connection con1;
+reap;
+
+
+--echo # We can catch EXPLAIN, too.
+set @show_expl_tmp= @@optimizer_switch;
+set optimizer_switch='index_condition_pushdown=on,mrr=on,mrr_sort_keys=on';
+send explain select max(c) from t1 where a < 10;
+connection default;
+--source include/wait_condition.inc
+evalp show explain for $thr2;
+connection con1;
+reap;
+set optimizer_switch= @show_expl_tmp;
+set debug_dbug=@old_debug;
+
+--echo # UNION, first branch
+set @show_explain_probe_select_id=1;
+set debug_dbug='+d,show_explain_probe_join_exec_start';
+send explain select a from t0 A union select a+1 from t0 B;
+connection default;
+--source include/wait_condition.inc
+evalp show explain for $thr2;
+connection con1;
+reap;
+set debug_dbug=@old_debug;
+
+
+--echo # UNION, second branch
+set @show_explain_probe_select_id=1;
+set debug_dbug='+d,show_explain_probe_join_exec_start';
+send explain select a from t0 A union select a+1 from t0 B;
+connection default;
+--source include/wait_condition.inc
+evalp show explain for $thr2;
+connection con1;
+reap;
+set debug_dbug=@old_debug;
+
+
+--echo # Uncorrelated subquery, select
+set @show_explain_probe_select_id=1;
+set debug_dbug='+d,show_explain_probe_join_exec_start';
+send select a, (select max(a) from t0 B) from t0 A where a<1;
+connection default;
+--source include/wait_condition.inc
+evalp show explain for $thr2;
+connection con1;
+reap;
+set debug_dbug=@old_debug;
+
+
+--echo # Uncorrelated subquery, explain
+set @show_explain_probe_select_id=1;
+set debug_dbug='+d,show_explain_probe_join_exec_start';
+send explain select a, (select max(a) from t0 B) from t0 A where a<1;
+connection default;
+--source include/wait_condition.inc
+evalp show explain for $thr2;
+connection con1;
+reap;
+set debug_dbug=@old_debug;
+
+--echo # correlated subquery, select
+set @show_explain_probe_select_id=1;
+set debug_dbug='+d,show_explain_probe_join_exec_start';
+send select a, (select max(a) from t0 b where b.a+a.a<10) from t0 a where a<1;
+connection default;
+--source include/wait_condition.inc
+evalp show explain for $thr2;
+connection con1;
+reap;
+set debug_dbug=@old_debug;
+
+--echo # correlated subquery, explain
+set @show_explain_probe_select_id=1;
+set debug_dbug='+d,show_explain_probe_join_exec_start';
+send select a, (select max(a) from t0 b where b.a+a.a<10) from t0 a where a<1;
+connection default;
+--source include/wait_condition.inc
+evalp show explain for $thr2;
+connection con1;
+reap;
+set debug_dbug=@old_debug;
+
+--echo # correlated subquery, select, while inside the subquery
+set @show_explain_probe_select_id=2; # <---
+set debug_dbug='+d,show_explain_probe_join_exec_start';
+send select a, (select max(a) from t0 b where b.a+a.a<10) from t0 a where a<1;
+connection default;
+--source include/wait_condition.inc
+evalp show explain for $thr2;
+connection con1;
+reap;
+set debug_dbug=@old_debug;
+
+--echo # correlated subquery, explain, while inside the subquery
+set @show_explain_probe_select_id=2;
+set debug_dbug='+d,show_explain_probe_join_exec_start';
+send select a, (select max(a) from t0 b where b.a+a.a<10) from t0 a where a<1;
+connection default;
+--source include/wait_condition.inc
+evalp show explain for $thr2;
+connection con1;
+reap;
+set debug_dbug=@old_debug;
+
+--echo # correlated subquery, explain, while inside the subquery
+set @show_explain_probe_select_id=1;
+set debug_dbug='+d,show_explain_probe_join_exec_end';
+send select a, (select max(a) from t0 b where b.a+a.a<10) from t0 a where a<1;
+connection default;
+--source include/wait_condition.inc
+evalp show explain for $thr2;
+connection con1;
+reap;
+set debug_dbug=@old_debug;
+
+# TODO: explain in the parent subuqery when the un-correlated child has been
+# run (and have done irreversible cleanups)
+# ^^ Is this at all possible after 5.3?
+# Maybe, for 5.3 try this:
+# - run before/after the parent has invoked child's optimization
+# - run after materialization
+
+--echo # Try to do SHOW EXPLAIN for a query that runs a SET command:
+--echo # I've found experimentally that select_id==2 here...
+--echo #
+set @show_explain_probe_select_id=2;
+set debug_dbug='+d,show_explain_probe_join_exec_start';
+send set @foo= (select max(a) from t0 where sin(a) >0);
+connection default;
+--source include/wait_condition.inc
+--error ER_TARGET_NOT_EXPLAINABLE
+evalp show explain for $thr2;
+evalp kill query $thr2;
+connection con1;
+--error ER_QUERY_INTERRUPTED
+reap;
+set debug_dbug=@old_debug;
+
+--echo #
+--echo # Attempt SHOW EXPLAIN for an UPDATE
+--echo #
+create table t2 as select a as a, a as dummy from t0 limit 2;
+set @show_explain_probe_select_id=2;
+set debug_dbug='+d,show_explain_probe_join_exec_start';
+send update t2 set dummy=0 where (select max(a) from t0 where t2.a + t0.a <3) >3 ;
+connection default;
+--source include/wait_condition.inc
+#--error ER_TARGET_NOT_EXPLAINABLE
+evalp show explain for $thr2;
+--source include/wait_condition.inc
+#--error ER_TARGET_NOT_EXPLAINABLE
+evalp show explain for $thr2;
+connection con1;
+reap;
+drop table t2;
+set debug_dbug=@old_debug;
+
+--echo #
+--echo # Attempt SHOW EXPLAIN for a DELETE (UPD: now works)
+--echo #
+create table t2 as select a as a, a as dummy from t0 limit 2;
+set @show_explain_probe_select_id=2;
+set debug_dbug='+d,show_explain_probe_join_exec_start';
+send delete from t2 where (select max(a) from t0 where t2.a + t0.a <3) >3 ;
+connection default;
+--source include/wait_condition.inc
+#--error ER_TARGET_NOT_EXPLAINABLE
+evalp show explain for $thr2;
+--source include/wait_condition.inc
+#--error ER_TARGET_NOT_EXPLAINABLE
+evalp show explain for $thr2;
+connection con1;
+reap;
+drop table t2;
+set debug_dbug=@old_debug;
+
+--echo #
+--echo # Multiple SHOW EXPLAIN calls for one select
+--echo #
+create table t2 as select a as a, a as dummy from t0 limit 3;
+set @show_explain_probe_select_id=2;
+set debug_dbug='+d,show_explain_probe_join_exec_start';
+send select t2.a, ((select max(a) from t0 where t2.a + t0.a <3) >3) as SUBQ from t2;
+connection default;
+--source include/wait_condition.inc
+evalp show explain for $thr2;
+--source include/wait_condition.inc
+evalp show explain for $thr2;
+--source include/wait_condition.inc
+evalp show explain for $thr2;
+connection con1;
+reap;
+drop table t2;
+set debug_dbug=@old_debug;
+
+--echo #
+--echo # SHOW EXPLAIN for SELECT ... ORDER BY with "Using filesort"
+--echo #
+explain select * from t0 order by a;
+
+set debug_dbug='+d,show_explain_probe_join_exec_start';
+set @show_explain_probe_select_id=1;
+send select * from t0 order by a;
+connection default;
+--source include/wait_condition.inc
+evalp show explain for $thr2;
+connection con1;
+reap;
+set debug_dbug=@old_debug;
+
+--echo #
+--echo # SHOW EXPLAIN for SELECT ... with "Using temporary"
+--echo #
+connection default;
+explain select distinct a from t0;
+connection con1;
+
+set debug_dbug='+d,show_explain_probe_join_exec_start';
+set @show_explain_probe_select_id=1;
+send select distinct a from t0;
+connection default;
+--source include/wait_condition.inc
+evalp show explain for $thr2;
+connection con1;
+reap;
+set debug_dbug=@old_debug;
+
+--echo #
+--echo # SHOW EXPLAIN for SELECT ... with "Using temporary; Using filesort"
+--echo #
+connection default;
+explain select distinct a from t0;
+connection con1;
+
+set debug_dbug='+d,show_explain_probe_join_exec_start';
+set @show_explain_probe_select_id=1;
+send select distinct a from t0;
+connection default;
+--source include/wait_condition.inc
+evalp show explain for $thr2;
+connection con1;
+reap;
+set debug_dbug=@old_debug;
+
+--echo #
+--echo # MDEV-238: SHOW EXPLAIN: Server crashes in JOIN::print_explain with FROM subquery and GROUP BY
+--echo #
+CREATE TABLE t2 ( a INT );
+INSERT INTO t2 VALUES (1),(2),(1),(4),(2);
+explain SELECT alias.a FROM t2, ( SELECT * FROM t2 ) AS alias GROUP BY alias.a;
+
+set debug_dbug='+d,show_explain_in_find_all_keys';
+send SELECT alias.a FROM t2, ( SELECT * FROM t2 ) AS alias GROUP BY alias.a;
+
+connection default;
+--source include/wait_condition.inc
+--echo # FIXED by "conservative assumptions about when QEP is available" fix:
+--echo # NOTE: current code will not show "Using join buffer":
+#--error ER_TARGET_NOT_EXPLAINABLE
+evalp show explain for $thr2;
+connection con1;
+reap;
+set debug_dbug=@old_debug;
+DROP TABLE t2;
+
+
+--echo #
+--echo # MDEV-239: Assertion `field_types == 0 ... ' failed in Protocol_text::store(double, uint32, String*) with
+--echo # SHOW EXPLAIN over EXPLAIN EXTENDED
+--echo #
+
+
+CREATE TABLE t2 (a INT);
+INSERT INTO t2 VALUES (1),(2),(1),(4),(2);
+
+EXPLAIN EXTENDED SELECT alias.a FROM t2, ( SELECT * FROM t2 ) AS alias GROUP BY alias.a ;
+
+set @show_explain_probe_select_id=1;
+set debug_dbug='+d,show_explain_probe_join_exec_end';
+send EXPLAIN EXTENDED SELECT alias.a FROM t2, ( SELECT * FROM t2 ) AS alias GROUP BY alias.a ;
+
+connection default;
+--source include/wait_condition.inc
+evalp show explain for $thr2;
+connection con1;
+reap;
+set debug_dbug=@old_debug;
+DROP TABLE t2;
+
+
+--echo #
+--echo # MDEV-240: SHOW EXPLAIN: Assertion `this->optimized == 2' failed in
+--echo # JOIN::print_explain on query with a JOIN, TEMPTABLE view,
+--echo #
+CREATE TABLE t3 (a INT);
+CREATE ALGORITHM=TEMPTABLE VIEW v1 AS SELECT * FROM t3;
+INSERT INTO t3 VALUES (8);
+CREATE TABLE t2 (b INT);
+INSERT INTO t2 VALUES (4),(5),(6),(7),(8),(9);
+explain SELECT * FROM v1, t2;
+
+set @show_explain_probe_select_id=2;
+set debug_dbug='+d,show_explain_probe_join_exec_end';
+send SELECT * FROM v1, t2;
+
+connection default;
+--source include/wait_condition.inc
+--error ER_TARGET_NOT_EXPLAINABLE
+evalp show explain for $thr2;
+evalp kill query $thr2;
+connection con1;
+--error ER_QUERY_INTERRUPTED
+reap;
+set debug_dbug=@old_debug;
+DROP VIEW v1;
+DROP TABLE t2, t3;
+
+--echo #
+--echo # MDEV-267: SHOW EXPLAIN: Server crashes in JOIN::print_explain on most of queries
+--echo #
+set @show_explain_probe_select_id=1;
+set debug_dbug='+d,show_explain_probe_join_exec_end';
+send select sleep(1);
+connection default;
+--source include/wait_condition.inc
+evalp show explain for $thr2;
+connection con1;
+reap;
+set debug_dbug=@old_debug;
+
+
+--echo #
+--echo # Same as above, but try another reason for JOIN to be degenerate
+--echo #
+set @show_explain_probe_select_id=1;
+set debug_dbug='+d,show_explain_probe_join_exec_end';
+send select * from t0 where 1>10;
+connection default;
+--source include/wait_condition.inc
+#--error ER_TARGET_NOT_EXPLAINABLE
+evalp show explain for $thr2;
+connection con1;
+reap;
+set debug_dbug=@old_debug;
+
+--echo #
+--echo # Same as above, but try another reason for JOIN to be degenerate (2)
+--echo #
+create table t3(a int primary key);
+insert into t3 select a from t0;
+set @show_explain_probe_select_id=1;
+set debug_dbug='+d,show_explain_probe_join_exec_end';
+send select * from t0,t3 where t3.a=112233;
+connection default;
+--source include/wait_condition.inc
+# --error ER_TARGET_NOT_EXPLAINABLE
+evalp show explain for $thr2;
+connection con1;
+reap;
+set debug_dbug=@old_debug;
+drop table t3;
+
+--echo #
+--echo # MDEV-270: SHOW EXPLAIN: server crashes in JOIN::print_explain on a query with
+--echo # select tables optimized away
+--echo #
+
+CREATE TABLE t2 (pk INT PRIMARY KEY, a INT ) ENGINE=MyISAM;
+INSERT INTO t2 VALUES
+ (1,4),(2,62),(3,7),(4,1),(5,0),(6,7),(7,7),(8,1),(9,7),(10,1),
+ (11,5),(12,2),(13,0),(14,1),(15,8),(16,1),(17,1),(18,9),(19,1),(20,5) ;
+
+explain SELECT * FROM t2 WHERE a =
+ (SELECT MAX(a) FROM t2
+ WHERE pk= (SELECT MAX(pk) FROM t2 WHERE pk = 3)
+ );
+
+set @show_explain_probe_select_id=1;
+set debug_dbug='+d,show_explain_probe_do_select';
+send SELECT * FROM t2 WHERE a =
+ (SELECT MAX(a) FROM t2
+ WHERE pk= (SELECT MAX(pk) FROM t2 WHERE pk = 3)
+ );
+connection default;
+--source include/wait_condition.inc
+evalp show explain for $thr2;
+connection con1;
+reap;
+set debug_dbug=@old_debug;
+drop table t2;
+
+
+--echo #
+--echo # MDEV-273: SHOW EXPLAIN: server crashes in JOIN::print_explain on a query with impossible WHERE
+--echo #
+CREATE TABLE t2 (a1 INT, KEY(a1)) ENGINE=MyISAM;
+INSERT INTO t2 VALUES
+ (4),(6),(7),(1),(0),(7),(7),(1),(7),(1),
+ (5),(2),(0),(1),(8),(1),(1),(9),(1),(5);
+
+CREATE TABLE t3 (b1 INT) ENGINE=MyISAM;
+INSERT INTO t3 VALUES
+ (4),(5),(8),(4),(8),(2),(9),(6),(4),(8),
+ (3),(5),(9),(6),(8),(3),(2),(6),(3),(1),
+ (4),(3),(1),(7),(0),(0),(9),(5),(9),(0),
+ (2),(2),(5),(9),(1),(4),(8),(6),(5),(5),
+ (1),(7),(2),(8),(9),(3),(2),(6),(6),(5),
+ (4),(3),(2),(7),(4),(6),(0),(8),(5),(8),
+ (2),(9),(7),(5),(7),(0),(4),(3),(1),(0),
+ (6),(2),(8),(3),(7),(3),(5),(5),(1),(2),
+ (1),(7),(1),(9),(9),(8),(3);
+CREATE TABLE t4 (c1 INT) ENGINE=MyISAM;
+
+EXPLAIN
+SELECT count(*) FROM t2, t3
+WHERE a1 < ALL (
+ SELECT a1 FROM t2
+ WHERE a1 IN ( SELECT a1 FROM t2, t4 )
+);
+
+set @show_explain_probe_select_id=1;
+set debug_dbug='+d,show_explain_probe_do_select';
+send
+SELECT count(*) FROM t2, t3
+WHERE a1 < ALL (
+ SELECT a1 FROM t2
+ WHERE a1 IN ( SELECT a1 FROM t2, t4 )
+);
+
+connection default;
+--source include/wait_condition.inc
+evalp show explain for $thr2;
+connection con1;
+reap;
+set debug_dbug=@old_debug;
+drop table t2, t3, t4;
+
+--echo #
+--echo # MDEV-275: SHOW EXPLAIN: server crashes in JOIN::print_explain with IN subquery and aggregate function
+--echo #
+CREATE TABLE t2 ( `pk` INT NOT NULL PRIMARY KEY, `a1` INT NOT NULL, KEY(`a1`)) ENGINE=MyISAM;
+INSERT INTO t2 VALUES
+ (1,5),(2,4),(3,6),(4,9),(5,2),(6,8),(7,4),(8,8),(9,0),(10,43),
+ (11,23),(12,3),(13,45),(14,16),(15,2),(16,33),(17,2),(18,5),(19,9),(20,2);
+
+set @show_explain_probe_select_id=1;
+set debug_dbug='+d,show_explain_probe_join_exec_end';
+send
+ SELECT * FROM t2 WHERE (5, 78) IN (SELECT `a1`, MAX(`a1`) FROM t2 GROUP BY `a1`);
+connection default;
+--source include/wait_condition.inc
+# --error ER_TARGET_NOT_EXPLAINABLE
+evalp show explain for $thr2;
+connection con1;
+reap;
+set debug_dbug=@old_debug;
+
+DROP TABLE t2;
+DROP TABLE t1;
+
+--echo #
+--echo # MDEV-305: SHOW EXPLAIN: ref returned by SHOW EXPLAIN is different from the normal EXPLAIN ('const' vs empty string)
+--echo #
+CREATE TABLE t1(a INT, KEY(a));
+INSERT INTO t1 VALUES (3),(1),(5),(1);
+
+set @show_explain_probe_select_id=1;
+set debug_dbug='+d,show_explain_probe_join_exec_start';
+
+send SELECT 'test' FROM t1 WHERE a=1;
+connection default;
+--source include/wait_condition.inc
+evalp show explain for $thr2;
+connection con1;
+reap;
+set debug_dbug=@old_debug;
+
+DROP TABLE t1;
+
+
+--echo #
+--echo # MDEV-299: SHOW EXPLAIN: Plan produced by SHOW EXPLAIN changes back and forth during query execution
+--echo #
+
+create table t1 (key1 int, col1 int, col2 int, filler char(100), key(key1));
+insert into t1 select A.a+ 10 * B.a, 10, 10, 'filler-data' from t0 A, t0 B;
+
+# Make matches 3 records
+update t1 set col1=3, col2=10 where key1=1; # small range
+update t1 set col1=3, col2=1000 where key1=2; # big range
+update t1 set col1=3, col2=10 where key1=3; # small range again
+update t1 set col1=3, col2=1000 where key1=4; # big range
+
+set @tmp_mdev299_jcl= @@join_cache_level;
+set join_cache_level=0;
+
+explain select count(*) from t1 A, t1 B where B.key1 < A.col2 and A.col1=3 AND B.col2 + 1 < 100;
+
+set @show_explain_probe_select_id=1;
+set debug_dbug='+d,show_explain_probe_test_if_quick_select';
+
+send
+select count(*) from t1 A, t1 B where B.key1 < A.col2 and A.col1=3 AND B.col2 + 1 < 100;
+
+connection default;
+--source include/wait_condition.inc
+evalp show explain for $thr2;
+--source include/wait_condition.inc
+evalp show explain for $thr2;
+--source include/wait_condition.inc
+evalp show explain for $thr2;
+--source include/wait_condition.inc
+evalp show explain for $thr2;
+connection con1;
+reap;
+
+set debug_dbug=@old_debug;
+drop table t1;
+
+--echo #
+--echo # MDEV-297: SHOW EXPLAIN: Server gets stuck until timeout occurs while
+--echo # executing SHOW INDEX and SHOW EXPLAIN in parallel
+--echo #
+CREATE TABLE t1(a INT, b INT, c INT, KEY(a), KEY(b), KEY(c));
+INSERT INTO t1 (a) VALUES (3),(1),(5),(1);
+
+set @show_explain_probe_select_id=1;
+set debug_dbug='+d,show_explain_probe_join_exec_start';
+
+send SHOW INDEX FROM t1;
+connection default;
+--source include/wait_condition.inc
+evalp show explain for $thr2;
+connection con1;
+reap;
+set debug_dbug=@old_debug;
+
+DROP TABLE t1;
+
+--echo #
+--echo # MDEV-324: SHOW EXPLAIN: Plan produced by SHOW EXPLAIN for a query with TEMPTABLE view
+--echo # loses 'DERIVED' line on the way without saying that the plan was already deleted
+--echo #
+CREATE TABLE t1 (a INT);
+INSERT INTO t1 VALUES (1),(2);
+CREATE ALGORITHM=TEMPTABLE VIEW v1 AS SELECT * FROM t1;
+
+EXPLAIN SELECT a + 1 FROM v1;
+
+set debug_dbug='+d,show_explain_probe_join_tab_preread';
+set @show_explain_probe_select_id=1;
+
+send
+ SELECT a + 1 FROM v1;
+connection default;
+--source include/wait_condition.inc
+evalp show explain for $thr2;
+connection con1;
+reap;
+set debug_dbug=@old_debug;
+
+DROP VIEW v1;
+DROP TABLE t1;
+
+
+--echo #
+--echo # MDEV-323: SHOW EXPLAIN: Plan produced by SHOW EXPLAIN loses
+--echo # 'UNION RESULT' line on the way without saying that the plan was already deleted
+--echo #
+CREATE TABLE t1 (a INT);
+INSERT INTO t1 VALUES (4),(6);
+
+EXPLAIN
+SELECT a FROM t1 WHERE a IN ( SELECT 1+SLEEP(0.01) UNION SELECT 2 );
+
+set debug_dbug='+d,show_explain_probe_union_read';
+send
+SELECT a FROM t1 WHERE a IN ( SELECT 1+SLEEP(0.01) UNION SELECT 2 );
+
+connection default;
+--source include/wait_condition.inc
+evalp show explain for $thr2;
+
+--source include/wait_condition.inc
+evalp show explain for $thr2;
+
+connection con1;
+reap;
+
+set debug_dbug=@old_debug;
+DROP TABLE t1;
+
+--echo #
+--echo # MDEV-327: SHOW EXPLAIN: Different select_type in plans produced by SHOW EXPLAIN
+--echo # and standard EXPLAIN: 'SUBQUERY' vs 'DEPENDENT SUBQUERY'
+--echo #
+CREATE TABLE t1 (a INT) ENGINE=Aria;
+INSERT INTO t1 VALUES
+(4),(6),(3),(5),(3),(246),(2),(9),(3),(8),
+(1),(8),(8),(5),(7),(5),(1),(6),(2),(9);
+
+CREATE TABLE t2 (b INT) ENGINE=Aria;
+INSERT INTO t2 VALUES
+(1),(7),(4),(7),(0),(2),(9),(4),(0),(9),
+(1),(3),(8),(8),(18),(84),(6),(3),(6),(6);
+
+EXPLAIN
+SELECT * FROM t1, ( SELECT * FROM t2 ) AS alias
+WHERE a < ALL ( SELECT b FROM t1, t2 WHERE a = b );
+
+set @show_explain_probe_select_id=1;
+set debug_dbug='+d,show_explain_probe_join_exec_start';
+--send
+SELECT * FROM t1, ( SELECT * FROM t2 ) AS alias
+WHERE a < ALL ( SELECT b FROM t1, t2 WHERE a = b );
+
+connection default;
+--source include/wait_condition.inc
+evalp show explain for $thr2;
+
+connection con1;
+reap;
+set debug_dbug=@old_debug;
+DROP TABLE t1, t2;
+
+--echo #
+--echo # Test that SHOW EXPLAIN will print 'Distinct'.
+--echo #
+CREATE TABLE t1 (a int(10) unsigned not null primary key,b int(10) unsigned);
+INSERT INTO t1 VALUES (1,1),(2,1),(3,1),(4,1);
+
+CREATE TABLE t3 (a int(10) unsigned, key(A), b text);
+INSERT INTO t3 VALUES (1,'1'),(2,'2');
+
+create temporary table t4 select * from t3;
+insert into t3 select * from t4;
+insert into t4 select * from t3;
+insert into t3 select * from t4;
+insert into t4 select * from t3;
+insert into t3 select * from t4;
+insert into t4 select * from t3;
+insert into t3 select * from t4;
+explain select distinct t1.a from t1,t3 where t1.a=t3.a;
+
+set @show_explain_probe_select_id=1;
+set debug_dbug='+d,show_explain_probe_join_exec_start';
+--send
+select distinct t1.a from t1,t3 where t1.a=t3.a;
+connection default;
+--source include/wait_condition.inc
+evalp show explain for $thr2;
+
+connection con1;
+reap;
+set debug_dbug=@old_debug;
+
+drop table t1,t3,t4;
+
+--echo #
+--echo # ---------- SHOW EXPLAIN and permissions -----------------
+--echo #
+grant ALL on test.* to test2@localhost;
+
+# Give the user SUPER privilege so it can set debug_dbug variable.
+grant super on *.* to test2@localhost;
+connect (con2, localhost, test2,,);
+connection con1;
+
+--echo #
+--echo # First, make sure that user 'test2' cannot do SHOW EXPLAIN on us
+--echo #
+set @show_explain_probe_select_id=1;
+set debug_dbug='+d,show_explain_probe_join_exec_start';
+send
+select * from t0 where a < 3;
+
+connection default;
+--source include/wait_condition.inc
+
+connection con2;
+--error ER_SPECIFIC_ACCESS_DENIED_ERROR
+evalp show explain for $thr2;
+
+connection default;
+evalp show explain for $thr2;
+
+connection con1;
+reap;
+set debug_dbug=@old_debug;
+
+--echo #
+--echo # Check that user test2 can do SHOW EXPLAIN on its own queries
+--echo #
+connect (con3, localhost, test2,,);
+
+connection con2;
+let $thr_con2=`select connection_id()`;
+set @show_explain_probe_select_id=1;
+set debug_dbug='+d,show_explain_probe_join_exec_start';
+send
+select * from t0 where a < 3;
+
+connection con1;
+let $save_wait_condition= $wait_condition;
+let $wait_condition= select State='show_explain_trap' from information_schema.processlist where id=$thr_con2;
+--source include/wait_condition.inc
+
+connection con3;
+evalp show explain for $thr_con2;
+
+connection con2;
+reap;
+
+connection con1;
+
+disconnect con3;
+let $wait_condition= $save_wait_condition;
+--echo #
+--echo # Now, grant test2 a PROCESSLIST permission, and see that he's able to observe us
+--echo #
+disconnect con2;
+grant process on *.* to test2@localhost;
+connect (con2, localhost, test2,,);
+connection con1;
+set debug_dbug=@old_debug;
+
+set @show_explain_probe_select_id=1;
+set debug_dbug='+d,show_explain_probe_join_exec_start';
+send
+select * from t0 where a < 3;
+
+connection default;
+--source include/wait_condition.inc
+
+connection con2;
+evalp show explain for $thr2;
+
+connection con1;
+reap;
+set debug_dbug=@old_debug;
+
+revoke all privileges on test.* from test2@localhost;
+drop user test2@localhost;
+
+disconnect con2;
+--echo #
+--echo # Test that it is possible to KILL a SHOW EXPLAIN command that's waiting
+--echo # on its target thread
+--echo #
+connect (con2, localhost, root,,);
+connect (con3, localhost, root,,);
+connection con2;
+create table t1 (pk int primary key, data char(64)) engine=innodb;
+insert into t1 select A.a + 10 * B.a + 100 * C.a, 'data1' from t0 A, t0 B, t0 C;
+
+--echo # Lock two threads
+set autocommit=0;
+select * from t1 where pk between 10 and 20 for update;
+
+connection con1;
+set autocommit=0;
+# This will freeze
+send
+select * from t1 where pk between 10 and 20 for update;
+
+# run SHOW EXPLAIN on a frozen thread
+connection default;
+let $save_wait_condition= $wait_condition;
+let $wait_condition= select State='Sending data' from information_schema.processlist where id=$thr2;
+let $thr_default=`select connection_id()`;
+--source include/wait_condition.inc
+--echo # do: send_eval show explain for thr2;
+--disable_query_log
+send_eval show explain for $thr2;
+--enable_query_log
+
+# kill the SHOW EXPLAIN command
+connection con3;
+let $wait_condition= select State='show explain' from information_schema.processlist where id=$thr_default;
+--source include/wait_condition.inc
+evalp kill query $thr_default;
+
+connection default;
+--error ER_QUERY_INTERRUPTED
+reap;
+
+connection con2;
+rollback;
+
+connection con1;
+reap;
+
+drop table t1;
+disconnect con3;
+disconnect con2;
+let $wait_condition= $save_wait_condition;
+
+--echo #
+--echo # Check that the I_S table is invisible
+--echo #
+select table_name from information_schema.tables where table_schema='information_schema' and table_name like '%explain%';
+
+--echo #
+--echo # MDEV-325: SHOW EXPLAIN: Plan produced by SHOW EXPLAIN is different from standard EXPLAIN: type ALL vs 'index_merge'..
+--echo #
+CREATE TABLE t1 (a INT, b INT, KEY(a), KEY(b)) ENGINE=MyISAM;
+INSERT INTO t1 VALUES
+(8,0),(128,5050),(5372,8),(234,7596),(2,0),(2907,8930),(1,0),
+(0,5224),(8,7638),(960,5),(9872,1534),(0,2295),(3408,9809),
+(7,0),(1168,0),(2089,5570),(0,205),(88,1018),(0,26528),
+(0,0),(4,5567),(1444,145),(6,0),(1,7535),(7793,534),(70,9),
+(178,1),(44,5),(189,0),(3,0);
+
+EXPLAIN
+SELECT a+SLEEP(0.01) FROM t1
+WHERE a IN ( 255, 0 ) OR b BETWEEN 6 AND 129
+ORDER BY b;
+
+set @show_explain_probe_select_id=1;
+set debug_dbug='+d,show_explain_probe_join_exec_start';
+--send
+SELECT a+SLEEP(0.01) FROM t1
+WHERE a IN ( 255, 0 ) OR b BETWEEN 6 AND 129
+ORDER BY b;
+
+connection default;
+--source include/wait_condition.inc
+evalp show explain for $thr2;
+
+connection con1;
+reap;
+set debug_dbug=@old_debug;
+
+set @show_explain_probe_select_id=1;
+set debug_dbug='+d,show_explain_probe_do_select';
+--send
+SELECT a+SLEEP(0.01) FROM t1
+WHERE a IN ( 255, 0 ) OR b BETWEEN 6 AND 129
+ORDER BY b;
+
+connection default;
+--source include/wait_condition.inc
+evalp show explain for $thr2;
+
+connection con1;
+reap;
+
+set debug_dbug=@old_debug;
+
+drop table t1;
+
+--echo #
+--echo # MDEV-298: SHOW EXPLAIN: Plan returned by SHOW EXPLAIN only contains
+--echo # 'Using temporary' while the standard EXPLAIN says 'Using temporary; Using filesort'
+--echo #
+CREATE TABLE t1 (a INT);
+INSERT INTO t1 VALUES (1),(2),(3),(4),(5),(6),(7),(8),(9),
+ (10),(11),(12),(13),(14),(15),(16);
+INSERT INTO t1 SELECT t11.a FROM t1 t11, t1 t12, t1 t13;
+
+EXPLAIN SELECT a FROM t1 GROUP BY a;
+
+set @show_explain_probe_select_id=1;
+set debug_dbug='+d,show_explain_probe_join_exec_start';
+--send
+SELECT a FROM t1 GROUP BY a;
+
+connection default;
+--source include/wait_condition.inc
+evalp show explain for $thr2;
+
+connection con1;
+reap;
+
+set debug_dbug=@old_debug;
+
+drop table t1;
+
+--echo #
+--echo # MDEV-408: SHOW EXPLAIN: Some values are chopped off in SHOW EXPLAIN output
+--echo #
+CREATE TABLE t1 (a INT, b VARCHAR(35)) ENGINE=InnoDB;
+INSERT INTO t1 VALUES (3989,'Abilene'),(3873,'Akron');
+
+CREATE TABLE t2 (c INT, d VARCHAR(52) PRIMARY KEY, KEY(c)) ENGINE=InnoDB;
+INSERT INTO t2 VALUES (86,'English'),(87,'Russian');
+
+explain SELECT SUM(a + SLEEP(0.1)) FROM t1 WHERE a IN ( SELECT c FROM t2 WHERE d < b ) OR b < 's';
+
+set @show_explain_probe_select_id=1;
+set debug_dbug='+d,show_explain_probe_join_exec_start';
+--send
+SELECT SUM(a + SLEEP(0.1)) FROM t1 WHERE a IN ( SELECT c FROM t2 WHERE d < b ) OR b < 's';
+
+connection default;
+--source include/wait_condition.inc
+evalp show explain for $thr2;
+
+connection con1;
+reap;
+
+set debug_dbug=@old_debug;
+drop table t1, t2;
+
+--echo #
+--echo # MDEV-412: SHOW EXPLAIN: Server crashes in JOIN::print_explain on a query with inner join and ORDER BY the same column twice
+--echo #
+CREATE TABLE t1 (a INT PRIMARY KEY, b VARCHAR(3), KEY(b)) ENGINE=MyISAM;
+INSERT INTO t1 VALUES
+(3795,'USA'),(3913,'USA'),(3846,'ITA'),(4021,'USA'),(4005,'RUS'),(4038,'USA'),
+(3825,'USA'),(3840,'USA'),(3987,'USA'),(3807,'USA'),(3896,'USA'),(4052,'USA'),
+(3973,'USA'),(3982,'ITA'),(3965,'USA'),(3852,'RUS'),(4006,'USA'),(3800,'USA'),
+(4020,'USA'),(4040,'USA'),(3916,'USA'),(3817,'USA'),(3885,'USA'),(3802,'USA'),
+(4009,'ITA'),(3895,'USA'),(3963,'RUS'),(4045,'USA'),(3988,'USA'),(3815,'USA'),
+(4063,'USA'),(3978,'USA'),(4019,'USA'),(3954,'USA'),(3950,'USA'),(3974,'ITA'),
+(4054,'USA'),(4061,'RUS'),(3976,'USA'),(3966,'USA'),(3957,'USA'),(3981,'USA'),
+(3923,'USA'),(3876,'USA'),(3819,'USA'),(3877,'USA'),(3829,'ITA'),(3964,'USA'),
+(4053,'RUS'),(3917,'USA'),(3874,'USA'),(4023,'USA'),(4001,'USA'),(3872,'USA'),
+(3890,'USA'),(3962,'USA'),(3886,'USA'),(4026,'ITA'),(3869,'USA'),(3937,'RUS'),
+(3975,'USA'),(3944,'USA'),(3908,'USA'),(3867,'USA'),(3947,'USA'),(3838,'USA'),
+(3796,'USA'),(3893,'USA'),(3920,'ITA'),(3994,'USA'),(3875,'RUS'),(4011,'USA'),
+(4013,'USA'),(3810,'USA'),(3834,'USA'),(3968,'USA'),(3931,'USA'),(3839,'USA'),
+(4042,'USA'),(4039,'ITA'),(3811,'USA'),(3837,'RUS'),(4041,'USA'),(3884,'USA'),
+(3894,'USA'),(3879,'USA'),(3942,'USA'),(3959,'USA'),(3814,'USA'),(4044,'USA'),
+(3971,'ITA'),(3823,'USA'),(3793,'RUS'),(3855,'USA'),(3905,'USA'),(3865,'USA'),
+(4046,'USA'),(3990,'USA'),(4022,'USA'),(3833,'USA'),(3918,'USA'),(4064,'ITA'),
+(3821,'USA'),(3836,'RUS'),(3921,'USA'),(3914,'USA'),(3888,'USA');
+
+CREATE TABLE t2 (c VARCHAR(3) PRIMARY KEY) ENGINE=MyISAM;
+INSERT INTO t2 VALUES ('USA');
+
+CREATE TABLE t3 (d VARCHAR(3), e VARCHAR(52), PRIMARY KEY (d,e)) ENGINE=MyISAM;
+INSERT INTO t3 VALUES
+('JPN','Japanese'),('KOR','Korean'),('POL','Polish'),('PRT','Portuguese'),
+('ESP','Spanish'),('FRA','French'),('VNM','Vietnamese');
+
+explain
+SELECT b AS field1, b AS field2 FROM t1, t2, t3 WHERE d = b ORDER BY field1, field2;
+
+set @show_explain_probe_select_id=1;
+set debug_dbug='+d,show_explain_probe_do_select';
+
+send
+SELECT b AS field1, b AS field2 FROM t1, t2, t3 WHERE d = b ORDER BY field1, field2;
+
+connection default;
+--source include/wait_condition.inc
+evalp show explain for $thr2;
+
+connection con1;
+reap;
+
+set debug_dbug=@old_debug;
+
+DROP TABLE t1,t2,t3;
+
+
+--echo #
+--echo # MDEV-423: SHOW EXPLAIN: 'Using where' for a subquery is shown in EXPLAIN, but not in SHOW EXPLAIN output
+--echo #
+CREATE TABLE t1 (a INT) ENGINE=MyISAM;
+INSERT INTO t1 VALUES (7),(0),(9),(3),(4),(2),(5),(7),(0),(9),(3),(4),(2),(5);
+
+CREATE TABLE t2 (b INT, c INT) ENGINE=MyISAM;
+INSERT INTO t2 VALUES
+(0,4),(8,6),(1,3),(8,5),(9,3),(24,246),(6,2),(1,9),(6,3),(2,8),
+(4,1),(8,8),(4,8),(4,5),(7,7),(4,5),(1,1),(9,6),(4,2),(8,9);
+
+create table t3 like t2;
+insert into t3 select * from t2;
+
+explain
+SELECT max(a+b+c) FROM t1 AS alias1, ( SELECT * FROM t2 ) AS alias
+WHERE EXISTS ( SELECT * FROM t3 WHERE b = c ) OR a <= 10;
+
+set @show_explain_probe_select_id=1;
+set debug_dbug='+d,show_explain_probe_join_exec_start';
+
+send
+SELECT max(a+b+c) FROM t1 AS alias1, ( SELECT * FROM t2 ) AS alias
+WHERE EXISTS ( SELECT * FROM t3 WHERE b = c ) OR a <= 10;
+
+connection default;
+--source include/wait_condition.inc
+evalp show explain for $thr2;
+
+connection con1;
+reap;
+
+set debug_dbug=@old_debug;
+DROP TABLE t1,t2,t3;
+
+--echo #
+--echo # MDEV-416: Server crashes in SQL_SELECT::cleanup on EXPLAIN with SUM ( DISTINCT ) in a non-correlated subquery (5.5-show-explain tree)
+--echo #
+CREATE TABLE t1 (a INT);
+INSERT INTO t1 VALUES (1),(2);
+
+CREATE TABLE t2 (b INT);
+INSERT INTO t2 VALUES (8),(9);
+
+EXPLAIN SELECT * FROM t1
+WHERE ( 8, 89 ) IN ( SELECT b, SUM( DISTINCT b ) FROM t2 GROUP BY b );
+
+DROP TABLE t1,t2;
+
+--echo #
+--echo # Check if queries in non-default charsets work.
+--echo #
+
+set names cp1251;
+# The below are two Russian letters with codes E3FB in cp1251 encoding.
+select charset('ãû');
+select hex('ãû');
+
+set @show_explain_probe_select_id=1;
+set debug_dbug='+d,show_explain_probe_join_exec_start';
+
+send
+select * from t0 where length('ãû') = a;
+
+connection default;
+set names utf8;
+--source include/wait_condition.inc
+evalp show explain for $thr2;
+set names default;
+
+connection con1;
+# The constant should be two letters, the last looking like 'bl'
+reap;
+
+set debug_dbug=@old_debug;
+set names default;
+
+--echo #
+--echo # MDEV-462: SHOW EXPLAIN: Assertion `table_list->table' fails in find_field_in_table_ref if FOR contains a non-numeric value
+--echo #
+--error ER_SET_CONSTANTS_ONLY
+show explain for foo;
+
+--echo #
+--echo # MDEV-411: SHOW EXPLAIN: For dependent subquery EXPLAIN produces type=index, key, 'Using where; Using index',
+--echo # while SHOW EXPLAIN says type=ALL, no key, 'Range checked for each record'
+--echo #
+CREATE TABLE t1 (a INT NOT NULL, KEY(a)) ENGINE=MyISAM;
+INSERT INTO t1 VALUES (7),(0);
+
+CREATE TABLE t2 (b INT NOT NULL) ENGINE=MyISAM;
+INSERT INTO t2 VALUES (0),(8);
+
+explain
+SELECT SUM(b) FROM ( SELECT * FROM t1 ) AS alias1, t2
+WHERE b <= ANY (
+ SELECT a FROM t1
+ WHERE a = b + SLEEP(0.2) OR a >= ( SELECT SUM(b) FROM t2 ));
+
+
+set @show_explain_probe_select_id=1;
+set debug_dbug='+d,show_explain_probe_join_exec_start';
+
+send
+SELECT SUM(b) FROM ( SELECT * FROM t1 ) AS alias1, t2
+WHERE b <= ANY (
+ SELECT a FROM t1
+ WHERE a = b + SLEEP(0.2) OR a >= ( SELECT SUM(b) FROM t2 ));
+
+connection default;
+--source include/wait_condition.inc
+evalp show explain for $thr2;
+
+connection con1;
+reap;
+
+set debug_dbug=@old_debug;
+DROP TABLE t1,t2;
+drop table t0;
+
+--echo #
+--echo # MDEV-5148: Server crashes in print_explain on killing EXPLAIN EXTENDED
+--echo #
+create table t0 (a int not null);
+insert into t0 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
+
+create table t1 (a int, b int);
+insert into t1 select a,a from t0;
+
+create table t2 as select * from t1;
+
+set @show_explain_probe_select_id=2;
+set debug_dbug='+d,show_explain_probe_best_ext_lim_search';
+send
+explain
+select * from t0
+where not exists ( select 1 from t1, t2 where t1.b=t2.b and t2.a=t0.a) and a is null;
+
+connection default;
+--source include/wait_condition.inc
+evalp kill query $thr2;
+
+connection con1;
+--error ER_QUERY_INTERRUPTED
+reap;
+
+drop table t0,t1,t2;
+
+--echo # End
+connection default;
+disconnect con1;
+set debug_sync='RESET';
+
diff --git a/mysql-test/t/show_explain_non_select.test b/mysql-test/t/show_explain_non_select.test
new file mode 100644
index 00000000000..21b16739141
--- /dev/null
+++ b/mysql-test/t/show_explain_non_select.test
@@ -0,0 +1,78 @@
+#
+# SHOW EXPLAIN tests for non-select subqueries
+#
+--source include/have_debug.inc
+--source include/have_innodb.inc
+--source include/not_embedded.inc
+
+--disable_warnings
+drop table if exists t0, t1;
+--enable_warnings
+
+SET @old_debug= @@session.debug;
+set debug_sync='RESET';
+
+#
+# Setup two threads and their ids
+#
+let $thr1=`select connection_id()`;
+connect (con2, localhost, root,,);
+connection con2;
+let $thr2=`select connection_id()`;
+connection default;
+
+#
+# Create tables
+#
+create table t0 (a int) engine=myisam;
+insert into t0 values (1),(2),(3),(4),(5),(6),(7),(8);
+
+create table t1 (a int, b int, filler char(100), key(a), key(b));
+insert into t1
+select A.a+10*B.a + 10*C.a, A.a+10*B.a + 10*C.a, 'filler'
+from t0 A, t0 B, t0 C;
+
+let $wait_condition= select State='show_explain_trap' from information_schema.processlist where id=$thr2;
+
+--echo #
+--echo # Test SHOW EXPLAIN for single-table DELETE
+--echo #
+connection con2;
+set debug_dbug='+d,show_explain_probe_delete_exec_start';
+send delete from t1 where a<10 and b+1>1000;
+
+connection default;
+--source include/wait_condition.inc
+evalp show explain for $thr2;
+connection con2;
+reap;
+
+--echo #
+--echo # Test SHOW EXPLAIN for multi-table DELETE
+--echo #
+set @show_explain_probe_select_id=1;
+set debug_dbug='+d,show_explain_probe_do_select';
+send delete t1 from t1, t0 where t0.a=t1.a and t1.b +1 > 1000;
+connection default;
+--source include/wait_condition.inc
+evalp show explain for $thr2;
+connection con2;
+reap;
+
+--echo #
+--echo # Test SHOW EXPLAIN for single-table UPDATE
+--echo #
+connection con2;
+set debug_dbug='+d,show_explain_probe_update_exec_start';
+send update t1 set filler='filler-data-2' where a<10 and b+1>1000;
+
+connection default;
+--source include/wait_condition.inc
+evalp show explain for $thr2;
+connection con2;
+reap;
+
+drop table t0,t1;
+
+set debug_dbug=@old_debug;
+set debug_sync='RESET';
diff --git a/mysql-test/t/show_explain_ps.test b/mysql-test/t/show_explain_ps.test
new file mode 100644
index 00000000000..4ad1e4304de
--- /dev/null
+++ b/mysql-test/t/show_explain_ps.test
@@ -0,0 +1,51 @@
+#
+# Test how SHOW EXPLAIN is represented in performance schema
+#
+--source include/have_debug.inc
+--source include/have_perfschema.inc
+# Like all other perfschema tests, we don't work on embedded server:
+--source include/not_embedded.inc
+
+--disable_warnings
+drop table if exists t0, t1;
+--enable_warnings
+
+select * from performance_schema.setup_instruments where name like '%show_explain%';
+
+--echo # We've got no instances
+select * from performance_schema.cond_instances where name like '%show_explain%';
+
+--echo # Check out if our cond is hit.
+
+create table t0 (a int);
+insert into t0 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
+
+let $thr1=`select connection_id()`;
+connect (con1, localhost, root,,);
+connection con1;
+let $thr2=`select connection_id()`;
+connection default;
+
+let $wait_condition= select State='show_explain_trap' from information_schema.processlist where id=$thr2;
+
+#
+# Test SHOW EXPLAIN for simple queries
+#
+connection con1;
+set @show_explain_probe_select_id=1;
+set debug_dbug='d,show_explain_probe_join_exec_start';
+send select count(*) from t0 where a < 100000;
+
+connection default;
+--source include/wait_condition.inc
+evalp show explain for $thr2;
+connection con1;
+reap;
+
+set debug_dbug='';
+
+select event_name
+from performance_schema.events_waits_history_long
+where event_name='wait/synch/cond/sql/show_explain';
+
+drop table t0;
diff --git a/mysql-test/t/show_grants_with_plugin-7985.test b/mysql-test/t/show_grants_with_plugin-7985.test
new file mode 100644
index 00000000000..339c75c7c49
--- /dev/null
+++ b/mysql-test/t/show_grants_with_plugin-7985.test
@@ -0,0 +1,161 @@
+--source include/not_embedded.inc
+--enable_connect_log
+call mtr.add_suppression("password and an authentication plugin");
+
+--echo #
+--echo # Create a user with mysql_native_password plugin.
+--echo # The user has no password or auth_string set.
+--echo #
+
+create user u1;
+GRANT SELECT ON mysql.* to u1 IDENTIFIED VIA mysql_native_password;
+select user, host, password, plugin, authentication_string from mysql.user where user = 'u1';
+
+--echo #
+--echo # The user's grants should show no password at all.
+--echo #
+show grants for u1;
+--echo #
+--echo # Test to see if connecting with no password is succesful.
+--echo #
+--connect (con1, localhost, u1,,)
+show grants;
+--disconnect con1
+
+--connection default
+--echo #
+--echo # Test after flushing privileges.
+--echo #
+flush privileges;
+--connect (con1, localhost, u1,,)
+show grants;
+--disconnect con1
+
+--connection default
+--echo #
+--echo # Now add a mysql_native password string in authentication_string.
+--echo #
+# Password string is SOMETHING
+GRANT SELECT ON mysql.* to u1 IDENTIFIED VIA mysql_native_password
+USING '*7AFEFD08B6B720E781FB000CAA418F54FA662626';
+select user, host, password, plugin, authentication_string from mysql.user where user = 'u1';
+--echo #
+--echo # Test to see if connecting with password is succesful.
+--echo #
+--connect (con1, localhost, u1,'SOMETHING',)
+show grants;
+--disconnect con1
+
+--connection default
+--echo #
+--echo # Test after flushing privileges.
+--echo #
+flush privileges;
+--connect (con1, localhost, u1,'SOMETHING',)
+show grants;
+--disconnect con1
+--connection default
+
+--echo #
+--echo # Now we also set a password for the user.
+--echo #
+set password for u1 = PASSWORD('SOMETHINGELSE');
+select user, host, password, plugin, authentication_string from mysql.user where user = 'u1';
+
+--echo #
+--echo # Here we should use the password field, as that primes over
+--echo # the authentication_string field.
+--echo #
+show grants for u1;
+
+--echo #
+--echo # Logging in with the user's password should work.
+--echo #
+--connect (con1, localhost, u1,'SOMETHINGELSE',)
+show grants;
+--disconnect con1
+--connection default
+--echo #
+--echo # Reload privileges and test logging in again.
+--echo #
+flush privileges;
+show grants for u1;
+--echo #
+--echo # Here we connect via the user's password again.
+--echo #
+--connect (con1, localhost, u1,'SOMETHINGELSE',)
+show grants;
+--disconnect con1
+--connection default
+
+--echo #
+--echo # Now we remove the authentication plugin password, flush privileges and
+--echo # try again.
+--echo #
+update mysql.user set authentication_string = '' where user='u1';
+select user, host, password, plugin, authentication_string from mysql.user where user = 'u1';
+flush privileges;
+show grants for u1;
+--echo #
+--echo # Here we connect via the user's password.
+--echo #
+--connect (con1, localhost, u1,'SOMETHINGELSE',)
+select user, host, password, plugin, authentication_string from mysql.user where user = 'u1';
+--disconnect con1
+--connection default
+
+--echo #
+--echo # Try and set a wrong auth_string password, with mysql_native_password.
+--echo # Make sure it fails.
+--echo #
+--error ER_PASSWD_LENGTH
+GRANT USAGE ON *.* TO u1 IDENTIFIED VIA mysql_native_password USING 'asd';
+--echo #
+--echo # Now set a correct password.
+--echo #
+GRANT SELECT ON mysql.* to u1 IDENTIFIED VIA mysql_native_password
+USING '*7AFEFD08B6B720E781FB000CAA418F54FA662626';
+show grants for u1;
+
+--echo #
+--echo # Test if the user can now use that password instead.
+--echo #
+--connect (con1, localhost, u1,'SOMETHING',)
+show grants;
+--disconnect con1
+
+--echo #
+--echo # Test if the user can now use that password instead, after flushing privileges;
+--echo #
+--connection default
+flush privileges;
+
+--connect (con1, localhost, u1,'SOMETHING',)
+show grants;
+--disconnect con1
+--connection default
+
+--echo #
+--echo # Clear all passwords from the user.
+--echo #
+GRANT SELECT ON mysql.* to u1 IDENTIFIED VIA mysql_native_password;
+select user, host, password, plugin, authentication_string from mysql.user where user = 'u1';
+
+--echo #
+--echo # Test no password connect.
+--echo #
+--connect (con1, localhost, u1,,)
+show grants;
+--disconnect con1
+--connection default
+
+--echo #
+--echo # Test no password connect, after flushing privileges.
+--echo #
+flush privileges;
+--connect (con1, localhost, u1,,)
+show grants;
+--disconnect con1
+--connection default
+
+drop user u1;
diff --git a/mysql-test/t/shutdown.test b/mysql-test/t/shutdown.test
new file mode 100644
index 00000000000..ac7f06b116d
--- /dev/null
+++ b/mysql-test/t/shutdown.test
@@ -0,0 +1,32 @@
+--source include/not_embedded.inc
+#
+# SHUTDOWN statement
+#
+create user user1@localhost;
+
+connect (c1,localhost,user1,,);
+
+--error ER_SPECIFIC_ACCESS_DENIED_ERROR
+shutdown;
+
+connection default;
+disconnect c1;
+--connect (c1,localhost,root,,)
+
+create procedure try_shutdown() shutdown;
+drop procedure try_shutdown;
+
+--let $_server_id= `SELECT @@server_id`
+--let $_expect_file_name= $MYSQLTEST_VARDIR/tmp/mysqld.$_server_id.expect
+--exec echo "wait" > $_expect_file_name
+
+--send shutdown
+--connection default
+--source include/wait_until_disconnected.inc
+
+--exec echo "restart" > $_expect_file_name
+--enable_reconnect
+--source include/wait_until_connected_again.inc
+
+drop user user1@localhost;
+
diff --git a/mysql-test/t/sighup-6580.test b/mysql-test/t/sighup-6580.test
new file mode 100644
index 00000000000..c89b3d20a0a
--- /dev/null
+++ b/mysql-test/t/sighup-6580.test
@@ -0,0 +1,10 @@
+#
+# MDEV-6580 Assertion `thd' failed in my_malloc_size_cb_func upon writing status report into error log
+#
+source include/not_windows.inc;
+source include/not_embedded.inc;
+let $pid=`select @@pid_file`;
+exec kill -1 `cat $pid`;
+
+select 'ok';
+
diff --git a/mysql-test/t/signal.test b/mysql-test/t/signal.test
index 13a0db2029b..31bc7bc9633 100644
--- a/mysql-test/t/signal.test
+++ b/mysql-test/t/signal.test
@@ -1551,15 +1551,24 @@ drop procedure test_signal $$
--echo # Test where SIGNAL can be used
--echo #
+--echo
+--echo # RETURN statement clears Diagnostics Area, thus
+--echo # the warnings raised in a stored function are not
+--echo # visible outsidef the stored function. So, we're using
+--echo # @@warning_count variable to check that SIGNAL succeeded.
+--echo
+
create function test_signal_func() returns integer
begin
+ DECLARE v INT;
DECLARE warn CONDITION FOR SQLSTATE "01XXX";
SIGNAL warn SET
MESSAGE_TEXT = "This function SIGNAL a warning",
MYSQL_ERRNO = 1012;
- return 5;
+ SELECT @@warning_count INTO v;
+ return v;
end $$
select test_signal_func() $$
diff --git a/mysql-test/t/skip_grants.test b/mysql-test/t/skip_grants.test
index 6f4d23e1e14..77339478fdb 100644
--- a/mysql-test/t/skip_grants.test
+++ b/mysql-test/t/skip_grants.test
@@ -112,8 +112,8 @@ DROP FUNCTION f3;
#
# Bug #26807 "set global event_scheduler=1" and --skip-grant-tables crashes server
#
---error ER_OPTION_PREVENTS_STATEMENT
set global event_scheduler=1;
+set global event_scheduler=0;
#
# Bug#26285 Selecting information_schema crahes server
diff --git a/mysql-test/t/sp-bugs.test b/mysql-test/t/sp-bugs.test
index 44e60bb10d0..4671aee11e1 100644
--- a/mysql-test/t/sp-bugs.test
+++ b/mysql-test/t/sp-bugs.test
@@ -167,6 +167,15 @@ USE test;
--echo End of 5.1 tests
--echo #
+--echo # BUG#13489996 valgrind:conditional jump or move depends on
+--echo # uninitialised values-field_blob
+--echo #
+
+CREATE FUNCTION sf() RETURNS BLOB RETURN "";
+SELECT sf();
+DROP FUNCTION sf;
+
+--echo #
--echo # Bug#11763507 - 56224: FUNCTION NAME IS CASE-SENSITIVE
--echo #
SET @@SQL_MODE = '';
diff --git a/mysql-test/t/sp-bugs2.test b/mysql-test/t/sp-bugs2.test
new file mode 100644
index 00000000000..2579e3485c6
--- /dev/null
+++ b/mysql-test/t/sp-bugs2.test
@@ -0,0 +1,29 @@
+#
+# MDEV-6610 Assertion `thd->is_error() || thd->killed' failed in mysql_execute_command on executing an SP with repeated CREATE TABLE .. SELECT
+#
+CREATE TABLE t1 (i INT);
+SET @a = 2;
+
+CREATE TABLE IF NOT EXISTS t2 (i INT) ENGINE = MyISAM
+ AS SELECT * FROM t1;
+CREATE TABLE IF NOT EXISTS t2 (i INT) ENGINE = MyISAM
+ AS SELECT * FROM t1;
+DROP TABLE t2;
+
+--delimiter |
+CREATE PROCEDURE sp()
+BEGIN
+REPEAT
+ CREATE TABLE IF NOT EXISTS t2 (i INT) ENGINE = MyISAM
+ AS SELECT * FROM t1;
+ SET @a = @a - 1;
+UNTIL @a = 0
+END REPEAT ;
+END |
+--delimiter ;
+
+CALL sp();
+
+DROP PROCEDURE sp;
+DROP TABLE t1, t2;
+
diff --git a/mysql-test/t/sp-destruct.test b/mysql-test/t/sp-destruct.test
index e5314f89fd5..7e16ac302fa 100644
--- a/mysql-test/t/sp-destruct.test
+++ b/mysql-test/t/sp-destruct.test
@@ -7,9 +7,6 @@
# In the case of trouble you might want to skip this.
#
-# embedded server returns different paths in error messages
-# in lines like 'call bug14233();'
-# mysqltest should be fixed to allow REPLACE_RESULT in error message
-- source include/not_embedded.inc
# Supress warnings written to the log file
@@ -43,13 +40,13 @@ create trigger t1_ai after insert on t1 for each row call bug14233();
# Unsupported tampering with the mysql.proc definition
alter table mysql.proc drop type;
---error ER_COL_COUNT_DOESNT_MATCH_CORRUPTED
+--error ER_COL_COUNT_DOESNT_MATCH_CORRUPTED_V2
call bug14233();
---error ER_COL_COUNT_DOESNT_MATCH_CORRUPTED
+--error ER_COL_COUNT_DOESNT_MATCH_CORRUPTED_V2
create view v1 as select bug14233_f();
---error ER_COL_COUNT_DOESNT_MATCH_CORRUPTED
+--error ER_COL_COUNT_DOESNT_MATCH_CORRUPTED_V2
insert into t1 values (0);
---error ER_COL_COUNT_DOESNT_MATCH_CORRUPTED
+--error ER_COL_COUNT_DOESNT_MATCH_CORRUPTED_V2
show procedure status;
flush table mysql.proc;
@@ -188,12 +185,12 @@ SHOW PROCEDURE STATUS;
ALTER TABLE mysql.proc MODIFY comment CHAR (32);
---error ER_CANNOT_LOAD_FROM_TABLE
+--error ER_CANNOT_LOAD_FROM_TABLE_V2
CREATE PROCEDURE p2()
SET @foo = 10;
--echo # Procedure loaded from the cache
CALL p1();
---error ER_CANNOT_LOAD_FROM_TABLE
+--error ER_CANNOT_LOAD_FROM_TABLE_V2
SHOW PROCEDURE STATUS;
DROP TABLE mysql.proc;
@@ -295,7 +292,7 @@ drop database mysqltest1;
#
create procedure p1() set @foo = 10;
alter table mysql.proc drop primary key;
---error ER_CANNOT_LOAD_FROM_TABLE
+--error ER_CANNOT_LOAD_FROM_TABLE_V2
drop procedure p1;
alter table mysql.proc add primary key (db,name,type);
drop procedure p1;
diff --git a/mysql-test/t/sp-error.test b/mysql-test/t/sp-error.test
index 063b30c01cb..711e639191e 100644
--- a/mysql-test/t/sp-error.test
+++ b/mysql-test/t/sp-error.test
@@ -2881,3 +2881,973 @@ SHOW WARNINGS;
DROP TABLE t1;
DROP TABLE t2;
DROP PROCEDURE p1;
+
+--echo
+--echo ###################################################################
+--echo # Tests for the following bugs:
+--echo # - Bug#11763171: 55852 - Possibly inappropriate handler activation.
+--echo # - Bug#11749343: 38806 - Wrong scope for SQL HANDLERS in SP.
+--echo ###################################################################
+--echo
+
+#
+# Structure of SQL-block:
+# BEGIN
+# <Handler declaration block>
+# <Statement block>
+# END
+#
+# Scope of Handler-decl-block is Statement-block.
+# I.e. SQL-conditions thrown in the Handler-decl-block can not be handled by
+# the same block, only by outer SQL-blocks.
+#
+# This rule is recursive, i.e. if a Handler-decl-block has nested SQL-blocks,
+# the SQL-conditions from those nested blocks can not be handled by the this
+# Handler-decl-block, only by outer SQL-blocks.
+#
+
+delimiter |;
+
+--echo
+--echo # -- Check that SQL-conditions thrown by Statement-blocks are
+--echo # -- handled by Handler-decl blocks properly.
+--echo
+
+CREATE PROCEDURE p1()
+BEGIN
+ DECLARE CONTINUE HANDLER FOR SQLEXCEPTION
+ SELECT 'H1' AS HandlerId;
+
+ DECLARE CONTINUE HANDLER FOR SQLWARNING
+ SELECT 'H2' AS HandlerId;
+
+ SIGNAL SQLSTATE '01000'; # Should be handled by H2.
+END|
+
+--echo
+CALL p1()|
+
+--echo
+--echo # -- Check that SQL-conditions thrown by Statement-blocks are
+--echo # -- handled by Handler-decl blocks properly in case of nested
+--echo # -- SQL-blocks.
+--echo
+
+CREATE PROCEDURE p2()
+BEGIN
+ DECLARE CONTINUE HANDLER FOR SQLEXCEPTION
+ SELECT 'H1' AS HandlerId;
+
+ DECLARE CONTINUE HANDLER FOR SQLWARNING
+ SELECT 'H2' AS HandlerId;
+
+ BEGIN
+
+ SELECT 'B1' AS BlockId;
+ BEGIN
+
+ SELECT 'B2' AS BlockId;
+ BEGIN
+ SELECT 'B3' AS BlockId;
+ SIGNAL SQLSTATE '01000'; # Should be handled by H2.
+ END;
+
+ END;
+
+ END;
+
+END|
+
+--echo
+CALL p2()|
+
+--echo
+--echo # -- Check SQL-handler resolution rules.
+--echo
+
+CREATE PROCEDURE p3()
+BEGIN
+ DECLARE CONTINUE HANDLER FOR SQLEXCEPTION
+ SELECT 'H1' AS HandlerId;
+
+ DECLARE CONTINUE HANDLER FOR SQLWARNING
+ SELECT 'H2' AS HandlerId;
+
+ DECLARE CONTINUE HANDLER FOR SQLSTATE '01000'
+ SELECT 'H3' AS HandlerId;
+
+ SIGNAL SQLSTATE '01000'; # Should be handled by H3.
+END|
+
+--echo
+CALL p3()|
+--echo
+
+CREATE PROCEDURE p4()
+BEGIN
+ DECLARE CONTINUE HANDLER FOR SQLEXCEPTION
+ SELECT 'H1' AS HandlerId;
+
+ DECLARE CONTINUE HANDLER FOR SQLSTATE '01000'
+ SELECT 'H2' AS HandlerId;
+
+ DECLARE CONTINUE HANDLER FOR SQLWARNING
+ SELECT 'H3' AS HandlerId;
+
+ SIGNAL SQLSTATE '01000'; # Should be handled by H2.
+END|
+
+--echo
+CALL p4()|
+--echo
+
+CREATE PROCEDURE p5()
+BEGIN
+ DECLARE CONTINUE HANDLER FOR SQLEXCEPTION
+ SELECT 'H1' AS HandlerId;
+
+ DECLARE CONTINUE HANDLER FOR SQLSTATE '01000'
+ SELECT 'H2' AS HandlerId;
+
+ BEGIN
+ DECLARE CONTINUE HANDLER FOR SQLWARNING
+ SELECT 'H3' AS HandlerId;
+
+ SIGNAL SQLSTATE '01000'; # Should be handled by H3.
+ END;
+END|
+
+--echo
+CALL p5()|
+
+--echo
+--echo # -- Check that handlers don't handle its own exceptions.
+--echo
+
+CREATE PROCEDURE p6()
+BEGIN
+ DECLARE CONTINUE HANDLER FOR SQLEXCEPTION
+ BEGIN
+ SELECT 'H1' AS HandlerId;
+ SIGNAL SQLSTATE 'HY000'; # Should *not* be handled by H1.
+ END;
+
+ SELECT 'S1' AS SignalId;
+ SIGNAL SQLSTATE 'HY000'; # Should be handled by H1.
+END|
+
+--echo
+--error ER_SIGNAL_EXCEPTION
+CALL p6()|
+
+--echo
+--echo # -- Check that handlers don't handle its own warnings.
+--echo
+
+CREATE PROCEDURE p7()
+BEGIN
+ DECLARE CONTINUE HANDLER FOR SQLWARNING
+ BEGIN
+ SELECT 'H1' AS HandlerId;
+ SIGNAL SQLSTATE '01000'; # Should *not* be handled by H1.
+ END;
+
+ SELECT 'S1' AS SignalId;
+ SIGNAL SQLSTATE '01000'; # Should be handled by H1.
+END|
+
+--echo
+CALL p7()|
+
+--echo
+--echo # -- Check that conditions for handlers are not handled by the handlers
+--echo # -- from the same block.
+--echo
+
+CREATE PROCEDURE p8()
+BEGIN
+ DECLARE CONTINUE HANDLER FOR SQLWARNING
+ SELECT 'H1' AS HandlerId;
+
+ DECLARE CONTINUE HANDLER FOR SQLEXCEPTION
+ BEGIN
+ SELECT 'H2' AS HandlerId;
+ SIGNAL SQLSTATE '01000'; # Should *not* be handled by H1.
+ END;
+
+ SELECT 'S1' AS SignalId;
+ SIGNAL SQLSTATE 'HY000'; # Should be handled by H2.
+END|
+
+--echo
+CALL p8()|
+
+--echo
+--echo # -- Check that conditions for handlers are not handled by the handlers
+--echo # -- from the same block even if they are thrown deep down the stack.
+--echo
+
+CREATE PROCEDURE p9()
+BEGIN
+
+ DECLARE CONTINUE HANDLER FOR SQLSTATE '01000'
+ SELECT 'Wrong:H1:1' AS HandlerId;
+
+ DECLARE CONTINUE HANDLER FOR SQLWARNING
+ SELECT 'Wrong:H1:2' AS HandlerId;
+
+ DECLARE CONTINUE HANDLER FOR SQLEXCEPTION
+ BEGIN
+
+ DECLARE CONTINUE HANDLER FOR SQLSTATE '01000'
+ SELECT 'Wrong:H2:1' AS HandlerId;
+
+ DECLARE CONTINUE HANDLER FOR SQLWARNING
+ SELECT 'Wrong:H2:2' AS HandlerId;
+
+ DECLARE CONTINUE HANDLER FOR SQLEXCEPTION
+ BEGIN
+
+ DECLARE CONTINUE HANDLER FOR SQLSTATE '01000'
+ SELECT 'Wrong:H3:1' AS HandlerId;
+
+ DECLARE CONTINUE HANDLER FOR SQLWARNING
+ SELECT 'Wrong:H3:2' AS HandlerId;
+
+ DECLARE CONTINUE HANDLER FOR SQLEXCEPTION
+ BEGIN
+
+ DECLARE CONTINUE HANDLER FOR SQLSTATE '01000'
+ SELECT 'Wrong:H4:1' AS HandlerId;
+
+ DECLARE CONTINUE HANDLER FOR SQLWARNING
+ SELECT 'Wrong:H4:2' AS HandlerId;
+
+ DECLARE CONTINUE HANDLER FOR SQLEXCEPTION
+ BEGIN
+
+ DECLARE CONTINUE HANDLER FOR SQLSTATE '01000'
+ SELECT 'Wrong:H5:1' AS HandlerId;
+
+ DECLARE CONTINUE HANDLER FOR SQLWARNING
+ SELECT 'Wrong:H5:2' AS HandlerId;
+
+ DECLARE CONTINUE HANDLER FOR SQLEXCEPTION
+ BEGIN
+
+ DECLARE CONTINUE HANDLER FOR SQLSTATE '01000'
+ SELECT 'Wrong:H6:1' AS HandlerId;
+
+ DECLARE CONTINUE HANDLER FOR SQLWARNING
+ SELECT 'Wrong:H6:2' AS HandlerId;
+
+ DECLARE CONTINUE HANDLER FOR SQLEXCEPTION
+ BEGIN
+ SELECT 'H2' AS HandlerId;
+ SIGNAL SQLSTATE '01000'; # Should *not* be handled by H1.
+ END;
+
+ SELECT 'S6' AS SignalId;
+ SIGNAL SQLSTATE 'HY000';
+ END;
+
+ SELECT 'S5' AS SignalId;
+ SIGNAL SQLSTATE 'HY000';
+
+ END;
+
+ SELECT 'S4' AS SignalId;
+ SIGNAL SQLSTATE 'HY000';
+
+ END;
+
+ SELECT 'S3' AS SignalId;
+ SIGNAL SQLSTATE 'HY000';
+
+ END;
+
+ SELECT 'S2' AS SignalId;
+ SIGNAL SQLSTATE 'HY000';
+
+ END;
+
+ SELECT 'S1' AS SignalId;
+ SIGNAL SQLSTATE 'HY000'; # Should be handled by H2.
+
+END|
+
+--echo
+CALL p9()|
+
+--echo
+--echo # -- Check that handlers are choosen properly in case of deep stack and
+--echo # -- nested SQL-blocks.
+--echo
+
+CREATE PROCEDURE p10()
+BEGIN
+ DECLARE CONTINUE HANDLER FOR SQLSTATE '01000'
+ SELECT 'H1' AS HandlerId;
+
+ DECLARE CONTINUE HANDLER FOR SQLWARNING
+ SELECT 'H2' AS HandlerId;
+
+ BEGIN
+ BEGIN
+ BEGIN
+
+ DECLARE CONTINUE HANDLER FOR SQLSTATE '01000'
+ SELECT 'Wrong:H1:1' AS HandlerId;
+
+ DECLARE CONTINUE HANDLER FOR SQLWARNING
+ SELECT 'Wrong:H1:2' AS HandlerId;
+
+ DECLARE CONTINUE HANDLER FOR SQLEXCEPTION
+ BEGIN
+
+ DECLARE CONTINUE HANDLER FOR SQLSTATE '01000'
+ SELECT 'Wrong:H2:1' AS HandlerId;
+
+ DECLARE CONTINUE HANDLER FOR SQLWARNING
+ SELECT 'Wrong:H2:2' AS HandlerId;
+
+ DECLARE CONTINUE HANDLER FOR SQLEXCEPTION
+ BEGIN
+
+ DECLARE CONTINUE HANDLER FOR SQLSTATE '01000'
+ SELECT 'Wrong:H3:1' AS HandlerId;
+
+ DECLARE CONTINUE HANDLER FOR SQLWARNING
+ SELECT 'Wrong:H3:2' AS HandlerId;
+
+ DECLARE CONTINUE HANDLER FOR SQLEXCEPTION
+ BEGIN
+
+ DECLARE CONTINUE HANDLER FOR SQLSTATE '01000'
+ SELECT 'Wrong:H4:1' AS HandlerId;
+
+ DECLARE CONTINUE HANDLER FOR SQLWARNING
+ SELECT 'Wrong:H4:2' AS HandlerId;
+
+ DECLARE CONTINUE HANDLER FOR SQLEXCEPTION
+ BEGIN
+
+ DECLARE CONTINUE HANDLER FOR SQLSTATE '01000'
+ SELECT 'Wrong:H5:1' AS HandlerId;
+
+ DECLARE CONTINUE HANDLER FOR SQLWARNING
+ SELECT 'Wrong:H5:2' AS HandlerId;
+
+ DECLARE CONTINUE HANDLER FOR SQLEXCEPTION
+ BEGIN
+
+ DECLARE CONTINUE HANDLER FOR SQLSTATE '01000'
+ SELECT 'Wrong:H6:1' AS HandlerId;
+
+ DECLARE CONTINUE HANDLER FOR SQLWARNING
+ SELECT 'Wrong:H6:2' AS HandlerId;
+
+ DECLARE CONTINUE HANDLER FOR SQLEXCEPTION
+ BEGIN
+ SELECT 'H2' AS HandlerId;
+ SIGNAL SQLSTATE '01000'; # Should be handled by H1.
+ END;
+
+ SELECT 'S6' AS SignalId;
+ SIGNAL SQLSTATE 'HY000';
+ END;
+
+ SELECT 'S5' AS SignalId;
+ SIGNAL SQLSTATE 'HY000';
+
+ END;
+
+ SELECT 'S4' AS SignalId;
+ SIGNAL SQLSTATE 'HY000';
+
+ END;
+
+ SELECT 'S3' AS SignalId;
+ SIGNAL SQLSTATE 'HY000';
+
+ END;
+
+ SELECT 'S2' AS SignalId;
+ SIGNAL SQLSTATE 'HY000';
+
+ END;
+
+ SELECT 'S1' AS SignalId;
+ SIGNAL SQLSTATE 'HY000'; # Should be handled by H2.
+
+ END;
+ END;
+ END;
+END|
+
+--echo
+CALL p10()|
+
+--echo
+--echo # -- Test stored procedure from Peter's mail.
+--echo
+
+CREATE PROCEDURE p11()
+BEGIN
+ DECLARE CONTINUE HANDLER FOR SQLEXCEPTION
+ SELECT 'H1' AS HandlerId;
+
+ DECLARE CONTINUE HANDLER FOR SQLWARNING
+ SELECT 'H2' AS HandlerId;
+
+ BEGIN
+ DECLARE CONTINUE HANDLER FOR SQLSTATE '01000', 1249
+ BEGIN
+ DECLARE CONTINUE HANDLER FOR SQLEXCEPTION
+ SELECT 'H3' AS HandlerId;
+
+ DECLARE CONTINUE HANDLER FOR SQLWARNING
+ SELECT 'H4' AS HandlerId;
+
+ BEGIN
+ SELECT 'H5' AS HandlerId;
+
+ SELECT 'S3' AS SignalId;
+ SIGNAL SQLSTATE 'HY000'; # H3
+
+ SELECT 'S4' AS SignalId;
+ SIGNAL SQLSTATE '22003'; # H3
+
+ SELECT 'S5' AS SignalId;
+ SIGNAL SQLSTATE '01000' SET MYSQL_ERRNO = 1249; # H4
+ END;
+ END;
+
+ SELECT 'S6' AS SignalId;
+ SIGNAL SQLSTATE 'HY000'; # H1
+
+ SELECT 'S7' AS SignalId;
+ SIGNAL SQLSTATE '22003'; # H1
+
+ SELECT 'S8' AS SignalId;
+ SIGNAL SQLSTATE '01000' SET MYSQL_ERRNO = 1249; # H5
+ END;
+
+ SELECT 'S1' AS SignalId;
+ SIGNAL SQLSTATE 'HY000'; # H1
+
+ SELECT 'S2' AS SignalId;
+ SIGNAL SQLSTATE '01000' SET MYSQL_ERRNO = 1249; # H2
+END|
+
+--echo
+CALL p11()|
+
+--echo
+--echo # -- Check that runtime stack-trace can be deeper than parsing-time one.
+--echo
+
+CREATE PROCEDURE p12()
+BEGIN
+ DECLARE CONTINUE HANDLER FOR SQLSTATE '01001'
+ BEGIN
+ DECLARE CONTINUE HANDLER FOR SQLSTATE '01001'
+ BEGIN
+ DECLARE CONTINUE HANDLER FOR SQLSTATE '01001'
+ BEGIN
+ DECLARE CONTINUE HANDLER FOR SQLSTATE '01001'
+ BEGIN
+ DECLARE CONTINUE HANDLER FOR SQLSTATE '01001'
+ BEGIN
+ SELECT 'H1:5' AS HandlerId;
+ SIGNAL SQLSTATE '01002';
+ END;
+ SELECT 'H1:4' AS HandlerId;
+ SIGNAL SQLSTATE '01001';
+ END;
+ SELECT 'H1:3' AS HandlerId;
+ SIGNAL SQLSTATE '01001';
+ END;
+ SELECT 'H1:2' AS HandlerId;
+ SIGNAL SQLSTATE '01001';
+ END;
+ SELECT 'H1:1' AS HandlerId;
+ SIGNAL SQLSTATE '01001';
+ END;
+
+ #########################################################
+
+ DECLARE CONTINUE HANDLER FOR SQLSTATE '01002'
+ SELECT 'OK' AS Msg;
+
+ #########################################################
+
+ BEGIN
+
+ DECLARE CONTINUE HANDLER FOR SQLWARNING
+ BEGIN
+ DECLARE CONTINUE HANDLER FOR SQLWARNING
+ BEGIN
+ DECLARE CONTINUE HANDLER FOR SQLWARNING
+ BEGIN
+ DECLARE CONTINUE HANDLER FOR SQLWARNING
+ BEGIN
+ DECLARE CONTINUE HANDLER FOR SQLWARNING
+ BEGIN
+ SELECT 'H2:5' AS HandlerId;
+ SIGNAL SQLSTATE '01001';
+ END;
+ SELECT 'H2:4' AS HandlerId;
+ SIGNAL SQLSTATE '01000';
+ END;
+ SELECT 'H2:3' AS HandlerId;
+ SIGNAL SQLSTATE '01000';
+ END;
+ SELECT 'H2:2' AS HandlerId;
+ SIGNAL SQLSTATE '01000';
+ END;
+ SELECT 'H2:1' AS HandlerId;
+ SIGNAL SQLSTATE '01000';
+ END;
+
+ #######################################################
+
+ SELECT 'Throw 01000' AS Msg;
+ SIGNAL SQLSTATE '01000';
+ END;
+
+END|
+
+--echo
+CALL p12()|
+
+--echo
+--echo # -- Check that handler-call-frames are removed properly for EXIT
+--echo # -- handlers.
+--echo
+
+CREATE PROCEDURE p13()
+BEGIN
+
+ DECLARE CONTINUE HANDLER FOR SQLWARNING
+ BEGIN
+ DECLARE CONTINUE HANDLER FOR SQLWARNING
+ BEGIN
+ DECLARE EXIT HANDLER FOR SQLWARNING
+ BEGIN
+ SELECT 'EXIT handler 3' AS Msg;
+ END;
+
+ SELECT 'CONTINUE handler 2: 1' AS Msg;
+ SIGNAL SQLSTATE '01000';
+ SELECT 'CONTINUE handler 2: 2' AS Msg;
+ END;
+
+ SELECT 'CONTINUE handler 1: 1' AS Msg;
+ SIGNAL SQLSTATE '01000';
+ SELECT 'CONTINUE handler 1: 2' AS Msg;
+ END;
+
+ SELECT 'Throw 01000' AS Msg;
+ SIGNAL SQLSTATE '01000';
+END|
+
+--echo
+CALL p13()|
+
+delimiter ;|
+
+--echo
+--echo # That's it. Cleanup.
+--echo
+
+DROP PROCEDURE p1;
+DROP PROCEDURE p2;
+DROP PROCEDURE p3;
+DROP PROCEDURE p4;
+DROP PROCEDURE p5;
+DROP PROCEDURE p6;
+DROP PROCEDURE p7;
+DROP PROCEDURE p8;
+DROP PROCEDURE p9;
+DROP PROCEDURE p10;
+DROP PROCEDURE p11;
+DROP PROCEDURE p12;
+DROP PROCEDURE p13;
+
+--echo
+--echo # Bug#12731619: NESTED SP HANDLERS CAN TRIGGER ASSERTION
+--echo
+
+--disable_warnings
+DROP FUNCTION IF EXISTS f1;
+DROP TABLE IF EXISTS t1;
+--enable_warnings
+
+CREATE TABLE t1(msg VARCHAR(255));
+
+delimiter |;
+CREATE FUNCTION f1() RETURNS INT
+BEGIN
+
+ DECLARE CONTINUE HANDLER FOR SQLEXCEPTION # handler 1
+ BEGIN
+ DECLARE CONTINUE HANDLER FOR SQLEXCEPTION # handler 2
+ BEGIN
+ INSERT INTO t1 VALUE('WRONG: Inside H2');
+ RETURN 2;
+ END;
+
+ INSERT INTO t1 VALUE('CORRECT: Inside H1');
+ RETURN 1;
+ END;
+
+ BEGIN
+ DECLARE CONTINUE HANDLER FOR SQLWARNING # handler 3
+ BEGIN
+ INSERT INTO t1 VALUE('WRONG: Inside H3');
+ RETURN 3;
+ END;
+
+ INSERT INTO t1 VALUE('CORRECT: Calling f1()');
+ RETURN f1(); # -- exception here
+ END;
+
+ INSERT INTO t1 VALUE('WRONG: Returning 10');
+ RETURN 10;
+
+END|
+
+delimiter ;|
+
+--echo
+SELECT f1();
+--echo
+SELECT * FROM t1;
+--echo
+
+DROP FUNCTION f1;
+DROP TABLE t1;
+
+
+--echo
+--echo # Check that handled SQL-conditions are properly cleared from DA.
+--echo
+
+--disable_warnings
+DROP TABLE IF EXISTS t1;
+DROP TABLE IF EXISTS t2;
+DROP PROCEDURE IF EXISTS p1;
+DROP PROCEDURE IF EXISTS p2;
+DROP PROCEDURE IF EXISTS p3;
+DROP PROCEDURE IF EXISTS p4;
+DROP PROCEDURE IF EXISTS p5;
+--enable_warnings
+
+CREATE TABLE t1(a CHAR, b CHAR, c CHAR);
+CREATE TABLE t2(a SMALLINT, b SMALLINT, c SMALLINT);
+
+delimiter |;
+
+--echo
+--echo # Check that SQL-conditions for which SQL-handler has been invoked,
+--echo # are cleared from the Diagnostics Area. Note, there might be several
+--echo # SQL-conditions, but SQL-handler must be invoked only once.
+--echo
+
+CREATE PROCEDURE p1()
+BEGIN
+ DECLARE EXIT HANDLER FOR SQLWARNING
+ SELECT 'Warning caught' AS msg;
+
+ # The INSERT below raises 3 SQL-conditions (warnings). The EXIT HANDLER
+ # above must be invoked once (for one condition), but all three conditions
+ # must be cleared from the Diagnostics Area.
+
+ INSERT INTO t1 VALUES('qqqq', 'ww', 'eee');
+
+ # The following INSERT will not be executed, because of the EXIT HANDLER.
+
+ INSERT INTO t1 VALUES('zzz', 'xx', 'yyyy');
+END|
+
+--echo
+CALL p1()|
+--echo
+SELECT * FROM t1|
+
+--echo
+--echo # Check that SQL-conditions for which SQL-handler has *not* been
+--echo # invoked, are *still* cleared from the Diagnostics Area.
+--echo
+
+CREATE PROCEDURE p2()
+BEGIN
+ DECLARE CONTINUE HANDLER FOR 1292
+ SELECT 'Warning 1292 caught' AS msg;
+
+ # The following INSERT raises 6 SQL-warnings with code 1292,
+ # and 3 SQL-warnings with code 1264. The CONTINUE HANDLER above must be
+ # invoked once, and all nine SQL-warnings must be cleared from
+ # the Diagnostics Area.
+
+ INSERT INTO t2
+ SELECT
+ CAST(CONCAT(CAST('1 ' AS UNSIGNED INTEGER), '999999 ') AS SIGNED INTEGER),
+ CAST(CONCAT(CAST('2 ' AS UNSIGNED INTEGER), '999999 ') AS SIGNED INTEGER),
+ CAST(CONCAT(CAST('3 ' AS UNSIGNED INTEGER), '999999 ') AS SIGNED INTEGER);
+END|
+
+--echo
+CALL p2()|
+
+--echo
+--echo # Check that if there are two equally ranked SQL-handlers to handle
+--echo # SQL-conditions from SQL-statement, only one of them will be invoked.
+--echo
+
+CREATE PROCEDURE p3()
+BEGIN
+ DECLARE CONTINUE HANDLER FOR 1292
+ SELECT 'Warning 1292 caught' AS msg;
+
+ DECLARE CONTINUE HANDLER FOR 1264
+ SELECT 'Warning 1264 caught' AS msg;
+
+ # The following INSERT raises 6 SQL-warnings with code 1292,
+ # and 3 SQL-warnings with code 1264. Only one of the CONTINUE HANDLERs above
+ # must be called, and only once. The SQL Standard does not define, which one
+ # should be invoked.
+
+ INSERT INTO t2
+ SELECT
+ CAST(CONCAT(CAST('1 ' AS UNSIGNED INTEGER), '999999 ') AS SIGNED INTEGER),
+ CAST(CONCAT(CAST('2 ' AS UNSIGNED INTEGER), '999999 ') AS SIGNED INTEGER),
+ CAST(CONCAT(CAST('3 ' AS UNSIGNED INTEGER), '999999 ') AS SIGNED INTEGER);
+END|
+
+--echo
+CALL p3()|
+
+--echo
+--echo # The same as p3, but 1264 comes first.
+--echo
+
+CREATE PROCEDURE p4()
+BEGIN
+ DECLARE CONTINUE HANDLER FOR 1292
+ SELECT 'Warning 1292 caught' AS msg;
+
+ DECLARE CONTINUE HANDLER FOR 1264
+ SELECT 'Warning 1264 caught' AS msg;
+
+ # The following INSERT raises 4 SQL-warnings with code 1292,
+ # and 3 SQL-warnings with code 1264. Only one of the CONTINUE HANDLERs above
+ # must be called, and only once. The SQL Standard does not define, which one
+ # should be invoked.
+
+ INSERT INTO t2
+ SELECT
+ CAST(999999 AS SIGNED INTEGER),
+ CAST(CONCAT(CAST('2 ' AS UNSIGNED INTEGER), '999999 ') AS SIGNED INTEGER),
+ CAST(CONCAT(CAST('3 ' AS UNSIGNED INTEGER), '999999 ') AS SIGNED INTEGER);
+END|
+
+--echo
+CALL p4()|
+
+--echo
+--echo # Check that if a SQL-handler raised its own SQL-conditions, there are
+--echo # preserved after handler exit.
+--echo
+
+CREATE PROCEDURE p5()
+BEGIN
+ DECLARE EXIT HANDLER FOR 1292
+ BEGIN
+ SELECT 'Handler for 1292 (1)' AS Msg;
+ SIGNAL SQLSTATE '01000' SET MYSQL_ERRNO = 1234;
+ SHOW WARNINGS;
+ SELECT 'Handler for 1292 (2)' AS Msg;
+ END;
+
+ INSERT INTO t2
+ SELECT
+ CAST(999999 AS SIGNED INTEGER),
+ CAST(CONCAT(CAST('2 ' AS UNSIGNED INTEGER), '999999 ') AS SIGNED INTEGER),
+ CAST(CONCAT(CAST('3 ' AS UNSIGNED INTEGER), '999999 ') AS SIGNED INTEGER);
+END|
+
+--echo
+CALL p5()|
+
+--echo
+--echo # Check that SQL-conditions are available inside the handler, but
+--echo # cleared after the handler exits.
+--echo
+
+CREATE PROCEDURE p6()
+BEGIN
+ DECLARE CONTINUE HANDLER FOR 1292
+ BEGIN
+ SHOW WARNINGS;
+ SELECT 'Handler for 1292' Msg;
+ END;
+
+ INSERT INTO t2
+ SELECT
+ CAST(CONCAT(CAST('1 ' AS UNSIGNED INTEGER), '999999 ') AS SIGNED INTEGER),
+ CAST(CONCAT(CAST('2 ' AS UNSIGNED INTEGER), '999999 ') AS SIGNED INTEGER),
+ CAST(CONCAT(CAST('3 ' AS UNSIGNED INTEGER), '999999 ') AS SIGNED INTEGER);
+END|
+
+--echo
+CALL p6()|
+
+delimiter ;|
+
+--echo
+DROP PROCEDURE p1;
+DROP PROCEDURE p2;
+DROP PROCEDURE p3;
+DROP PROCEDURE p4;
+DROP PROCEDURE p5;
+DROP PROCEDURE p6;
+DROP TABLE t1;
+DROP TABLE t2;
+
+--echo
+--echo # Bug#13059316: ASSERTION FAILURE IN SP_RCONTEXT.CC
+--echo # Check DECLARE statements that raise conditions before handlers
+--echo # are declared.
+--echo
+
+--disable_warnings
+DROP PROCEDURE IF EXISTS p1;
+DROP PROCEDURE IF EXISTS p2;
+--enable_warnings
+
+delimiter |;
+
+CREATE PROCEDURE p1()
+BEGIN
+ DECLARE var1 INTEGER DEFAULT 'string';
+ DECLARE EXIT HANDLER FOR SQLWARNING SELECT 'H1';
+END|
+
+--echo
+CALL p1()|
+--echo
+
+CREATE PROCEDURE p2()
+BEGIN
+ DECLARE EXIT HANDLER FOR SQLWARNING SELECT 'H2';
+ CALL p1();
+END|
+
+--echo
+CALL p2()|
+
+delimiter ;|
+
+--echo
+DROP PROCEDURE p1;
+DROP PROCEDURE p2;
+
+
+--echo #
+--echo # Bug#13113222 RQG_SIGNAL_RESIGNAL FAILED WITH ASSERTION.
+--echo #
+
+--disable_warnings
+DROP PROCEDURE IF EXISTS p1;
+DROP PROCEDURE IF EXISTS p2;
+--enable_warnings
+
+delimiter |;
+CREATE PROCEDURE p1()
+BEGIN
+ DECLARE CONTINUE HANDLER FOR SQLEXCEPTION SELECT 'triggered p1';
+ # This will trigger an error.
+ SIGNAL SQLSTATE 'HY000';
+END|
+
+CREATE PROCEDURE p2()
+BEGIN
+ DECLARE CONTINUE HANDLER FOR SQLWARNING SELECT 'triggered p2';
+ # This will trigger a warning.
+ SIGNAL SQLSTATE '01000';
+END|
+delimiter ;|
+
+SET @old_max_error_count= @@session.max_error_count;
+SET SESSION max_error_count= 0;
+CALL p1();
+CALL p2();
+SET SESSION max_error_count= @old_max_error_count;
+
+DROP PROCEDURE p1;
+DROP PROCEDURE p2;
+
+--echo
+--echo # Bug#12652873: 61392: Continue handler for NOT FOUND being triggered
+--echo # from internal stored function.
+--echo
+
+--disable_warnings
+DROP FUNCTION IF EXISTS f1;
+DROP FUNCTION IF EXISTS f2;
+DROP TABLE IF EXISTS t1;
+--enable_warnings
+
+--echo
+
+CREATE TABLE t1 (a INT, b INT);
+INSERT INTO t1 VALUES (1, 2);
+
+delimiter |;
+
+--echo
+--echo # f1() raises NOT_FOUND condition.
+--echo # Raising NOT_FOUND can not be simulated by SIGNAL,
+--echo # because SIGNAL would raise SQL-error in that case.
+--echo
+
+CREATE FUNCTION f1() RETURNS INTEGER
+BEGIN
+ DECLARE v VARCHAR(5) DEFAULT -1;
+ SELECT b FROM t1 WHERE a = 2 INTO v;
+ RETURN v;
+END|
+
+--echo
+--echo # Here we check that the NOT_FOUND condition raised in f1()
+--echo # is not visible in the outer function (f2), i.e. the continue
+--echo # handler in f2() will not be called.
+--echo
+
+CREATE FUNCTION f2() RETURNS INTEGER
+BEGIN
+ DECLARE v INTEGER;
+
+ DECLARE CONTINUE HANDLER FOR NOT FOUND
+ SET @msg = 'Handler activated.';
+
+ SELECT f1() INTO v;
+
+ RETURN v;
+END|
+
+delimiter ;|
+
+SET @msg = '';
+
+--echo
+SELECT f2();
+--echo
+SELECT @msg;
+--echo
+
+DROP FUNCTION f1;
+DROP FUNCTION f2;
+DROP TABLE t1;
diff --git a/mysql-test/t/sp-prelocking.test b/mysql-test/t/sp-prelocking.test
index c1378d59196..38cbd5aa110 100644
--- a/mysql-test/t/sp-prelocking.test
+++ b/mysql-test/t/sp-prelocking.test
@@ -414,3 +414,33 @@ SELECT f1();
DROP FUNCTION f1;
DROP VIEW v1;
DROP TABLE t1,t2;
+
+--echo #
+--echo # Bug #16672723 "CAN'T FIND TEMPORARY TABLE".
+--echo #
+CREATE FUNCTION f1() RETURNS INT RETURN 1;
+CREATE TEMPORARY TABLE tmp1(a INT);
+PREPARE stmt1 FROM "CREATE TEMPORARY TABLE tmp2 AS SELECT b FROM (SELECT f1() AS b FROM tmp1) AS t";
+--echo # The below statement failed before the fix.
+EXECUTE stmt1;
+DROP TEMPORARY TABLES tmp1, tmp2;
+DEALLOCATE PREPARE stmt1;
+DROP FUNCTION f1;
+
+#
+# MDEV-9084 Calling a stored function from a nested select from temporary table causes unpredictable behavior
+#
+delimiter $$;
+create procedure sp1()
+begin
+ drop table if exists t1, t2;
+ create temporary table t1 select 1 v;
+ create table t2 (col varchar(45)) select distinct col from (select sf1() as col from t1) t;
+end$$
+delimiter ;$$
+create function sf1() returns text return 'blah';
+call test.sp1();
+call test.sp1();
+drop procedure sp1;
+drop function sf1;
+drop table t2;
diff --git a/mysql-test/t/sp-security.test b/mysql-test/t/sp-security.test
index ca4e6b04f13..a2079e91440 100644
--- a/mysql-test/t/sp-security.test
+++ b/mysql-test/t/sp-security.test
@@ -995,6 +995,47 @@ disconnect con2;
DROP USER user2@localhost;
DROP DATABASE db1;
+--echo #
+--echo # Test for bug#12602983 - User without privilege on routine can discover
+--echo # its existence by executing "select non_existing_func();" or by
+--echo # "call non_existing_proc()";
+--echo #
+--disable_warnings
+drop database if exists mysqltest_db;
+--enable_warnings
+create database mysqltest_db;
+create function mysqltest_db.f1() returns int return 0;
+create procedure mysqltest_db.p1() begin end;
+
+--echo # Create user with no privileges on mysqltest_db database.
+create user bug12602983_user@localhost;
+
+--echo # Connect as user 'bug12602983_user@localhost'
+connect (conn1, localhost, bug12602983_user,,);
+
+--echo # Attempt to execute routine on which user doesn't have privileges
+--echo # should result in the same 'access denied' error whether
+--echo # routine exists or not.
+--error ER_PROCACCESS_DENIED_ERROR
+select mysqltest_db.f_does_not_exist();
+--error ER_PROCACCESS_DENIED_ERROR
+call mysqltest_db.p_does_not_exist();
+
+--error ER_PROCACCESS_DENIED_ERROR
+select mysqltest_db.f1();
+--error ER_PROCACCESS_DENIED_ERROR
+call mysqltest_db.p1();
+
+--error ER_PROCACCESS_DENIED_ERROR
+create view bug12602983_v1 as select mysqltest_db.f_does_not_exist();
+--error ER_PROCACCESS_DENIED_ERROR
+create view bug12602983_v1 as select mysqltest_db.f1();
+
+--echo # Connection 'default'.
+connection default;
+disconnect conn1;
+drop user bug12602983_user@localhost;
+drop database mysqltest_db;
# Wait till all disconnects are completed
--source include/wait_until_count_sessions.inc
diff --git a/mysql-test/t/sp.test b/mysql-test/t/sp.test
index 0e42bf3c831..c5d37d1017d 100644
--- a/mysql-test/t/sp.test
+++ b/mysql-test/t/sp.test
@@ -6273,7 +6273,7 @@ DROP FUNCTION IF EXISTS bug16899_f1|
--enable_warnings
--error ER_WRONG_STRING_LENGTH
-CREATE DEFINER=1234567890abcdefGHIKL@localhost PROCEDURE bug16899_p1()
+CREATE DEFINER=longer_than_80_456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789@localhost PROCEDURE bug16899_p1()
BEGIN
SET @a = 1;
END|
@@ -7394,7 +7394,7 @@ begin
/*! select 2; */
select 3;
/*!00000 select 4; */
- /*!99999 select 5; */
+ /*!999999 select 5; */
end
$$
@@ -7402,7 +7402,7 @@ create procedure proc_25411_b(
/* real comment */
/*! p1 int, */
/*!00000 p2 int */
-/*!99999 ,p3 int */
+/*!999999 ,p3 int */
)
begin
select p1, p2;
@@ -7411,11 +7411,11 @@ $$
create procedure proc_25411_c()
begin
- select 1/*!,2*//*!00000,3*//*!99999,4*/;
- select 1/*! ,2*//*!00000 ,3*//*!99999 ,4*/;
- select 1/*!,2 *//*!00000,3 *//*!99999,4 */;
- select 1/*! ,2 *//*!00000 ,3 *//*!99999 ,4 */;
- select 1 /*!,2*/ /*!00000,3*/ /*!99999,4*/ ;
+ select 1/*!,2*//*!00000,3*//*!999999,4*/;
+ select 1/*! ,2*//*!00000 ,3*//*!999999 ,4*/;
+ select 1/*!,2 *//*!00000,3 *//*!999999,4 */;
+ select 1/*! ,2 *//*!00000 ,3 *//*!999999 ,4 */;
+ select 1 /*!,2*/ /*!00000,3*/ /*!999999,4*/ ;
end
$$
@@ -9354,3 +9354,111 @@ drop function if exists f1;
drop table t1,t2;
--echo # End of 5.5 test
+
+--echo #
+--echo # MDEV-7040: Crash in field_conv, memcpy_field_possible, part#2
+--echo #
+create table t1 (
+ col1 bigint(20),
+ col2 char(1),
+ col3 char(2)
+);
+insert into t1 values (1,'a','a'), (2,'b','b');
+
+create table t2 as select * from t1;
+create table t3 as select * from t1;
+create table t4 as select * from t1;
+create table t5 as select * from t1;
+create table t6 as select * from t1;
+
+flush tables;
+
+DELIMITER |;
+
+CREATE PROCEDURE p1()
+begin
+ DECLARE _var1 bigint(20) UNSIGNED;
+ DECLARE _var2 CHAR(1) DEFAULT NULL;
+ DECLARE _var3 CHAR(1) DEFAULT NULL;
+
+ DECLARE _done BOOLEAN DEFAULT 0;
+
+ declare cur1 cursor for
+ select col1, col2, col3
+ from t1
+ where
+ col1 in (select t2.col1 from t2 where t2.col2=t1.col2) or
+ col2 in (select t3.col3 from t3 where t3.col3=t1.col2) ;
+
+ DECLARE CONTINUE HANDLER FOR NOT FOUND SET _done = 1;
+
+ OPEN cur1;
+
+ set _var1 = (select _var1 from t4 limit 1);
+ set _var1 = (select _var1 from t5 limit 1);
+ set _var1 = (select _var1 from t6 limit 1);
+label1:
+ LOOP
+ SET _done = 0;
+ FETCH cur1 INTO _var1, _var2, _var3;
+ IF _done THEN
+ LEAVE label1;
+ END IF;
+ END LOOP label1;
+ CLOSE cur1;
+end|
+DELIMITER ;|
+
+set @tmp_toc= @@table_open_cache;
+set @tmp_tdc= @@table_definition_cache;
+
+set global table_open_cache=1;
+set global table_definition_cache=1;
+call p1();
+
+set global table_open_cache= @tmp_toc;
+set global table_definition_cache= @tmp_tdc;
+drop procedure p1;
+
+drop table t1,t2,t3,t4,t5,t6;
+
+--echo #
+--echo # MDEV-11935: Queries in stored procedures with and
+--echo # EXISTS(SELECT * FROM VIEW) crashes and closes hte conneciton.
+--echo #
+
+CREATE TABLE ANY_TABLE (
+ ENTITY_UID BIGINT NOT NULL
+);
+CREATE TABLE SECURITY_PATH(
+origid BIGINT UNSIGNED NOT NULL,
+destid BIGINT UNSIGNED NOT NULL,
+KEY (destid)
+);
+CREATE VIEW ENTITY_ACCESS (
+ENTITY_UID,
+OWNER_UID
+) AS
+SELECT SP1.origid,
+ SP2.destid
+FROM SECURITY_PATH SP1
+JOIN SECURITY_PATH SP2 ON SP1.destid = SP2.origid
+;
+--delimiter //
+CREATE PROCEDURE SP_EXAMPLE_SELECT ()
+BEGIN
+ SELECT *
+ FROM ANY_TABLE AT1
+ WHERE EXISTS ( SELECT *
+ FROM ENTITY_ACCESS EA
+ WHERE AT1.ENTITY_UID = EA.ENTITY_UID
+ AND EA.OWNER_UID IS NULL );
+END
+//
+--delimiter ;
+CALL SP_EXAMPLE_SELECT ();
+CALL SP_EXAMPLE_SELECT ();
+
+drop procedure SP_EXAMPLE_SELECT;
+drop view ENTITY_ACCESS;
+drop table ANY_TABLE, SECURITY_PATH;
diff --git a/mysql-test/t/sp_notembedded.test b/mysql-test/t/sp_notembedded.test
index 447a1db762e..2a24ab3d005 100644
--- a/mysql-test/t/sp_notembedded.test
+++ b/mysql-test/t/sp_notembedded.test
@@ -63,10 +63,10 @@ drop procedure if exists bug6807|
--enable_warnings
create procedure bug6807()
begin
- declare id int;
+ declare a int;
- set id = connection_id();
- kill query id;
+ set a = connection_id();
+ kill query a;
select 'Not reached';
end|
@@ -248,7 +248,7 @@ create procedure p1() update t1 set value='updated' where value='old';
# load the procedure into sp cache and execute once
call p1();
-insert into t1 (value) values ("old");
+insert into t1 (value) values ("old"),("irrelevant");
connect (rl_holder, localhost, root,,);
connect (rl_acquirer, localhost, root,,);
@@ -374,6 +374,9 @@ CREATE VIEW v1 AS SELECT f1('a') FROM t1;
--send SELECT * FROM v1
--connection default
+let $wait_condition=
+ select count(*) = 2 from information_schema.processlist where state = "User sleep";
+--source include/wait_condition.inc
--disable_query_log
--eval KILL QUERY $ID_2
--eval KILL QUERY $ID_1
@@ -459,6 +462,26 @@ DROP EVENT teste_bug11763507;
--echo # ------------------------------------------------------------------
#
+# A case of SHOW GRANTS
+# (creating a new procedure changes the password)
+#
+grant create routine on test.* to foo1@localhost identified by 'foo';
+update mysql.user set password = replace(password, '*', '-') where user='foo1';
+--connect (foo,localhost,foo1,foo)
+show grants;
+--connection default
+flush privileges;
+--connection foo
+show grants;
+create procedure spfoo() select 1;
+show grants;
+
+--connection default
+--disconnect foo
+drop procedure spfoo;
+drop user foo1@localhost;
+
+#
# Restore global concurrent_insert value. Keep in the end of the test file.
#
diff --git a/mysql-test/t/sp_trans_log.test b/mysql-test/t/sp_trans_log.test
index 8eb1fcb98fa..deea6e6d9b6 100644
--- a/mysql-test/t/sp_trans_log.test
+++ b/mysql-test/t/sp_trans_log.test
@@ -30,18 +30,18 @@ begin
select count(*) from t1 into @a;
return @a;
end|
+delimiter ;|
-reset master|
+reset master;
--error ER_DUP_ENTRY
-insert into t2 values (bug23333(),1)|
+insert into t2 values (bug23333(),1);
# the following must show there are events after the query
# the binlog_limit is used to hide the differences between the mixed
# and row logging formats after BUG#53259
-let $binlog_limit= 0, 4|
-source include/show_binlog_events.inc|
-select count(*),@a from t1 /* must be 1,1 */|
+let $binlog_limit= 0, 4;
+source include/show_binlog_events.inc;
+select count(*),@a from t1 /* must be 1,1 */;
-delimiter ;|
# clean-up
diff --git a/mysql-test/t/ssl.test b/mysql-test/t/ssl.test
index d6f88fe888e..67db668a1c2 100644
--- a/mysql-test/t/ssl.test
+++ b/mysql-test/t/ssl.test
@@ -11,21 +11,26 @@
connect (ssl_con,localhost,root,,,,,SSL);
# Check ssl turned on
---replace_result DHE-RSA-AES256-GCM-SHA384 DHE-RSA-AES256-SHA
-SHOW STATUS LIKE 'Ssl_cipher';
+SELECT (VARIABLE_VALUE <> '') AS have_ssl FROM INFORMATION_SCHEMA.SESSION_STATUS WHERE VARIABLE_NAME='Ssl_cipher';
+
+# Check ssl expiration
+SHOW STATUS LIKE 'Ssl_server_not_before';
+SHOW STATUS LIKE 'Ssl_server_not_after';
# Source select test case
-- source include/common-tests.inc
# Check ssl turned on
---replace_result DHE-RSA-AES256-GCM-SHA384 DHE-RSA-AES256-SHA
-SHOW STATUS LIKE 'Ssl_cipher';
+SELECT (VARIABLE_VALUE <> '') AS have_ssl FROM INFORMATION_SCHEMA.SESSION_STATUS WHERE VARIABLE_NAME='Ssl_cipher';
+
+#
+# MDEV-7697 Client reports ERROR 2006 (MySQL server has gone away) or ERROR 2013 (Lost connection to MySQL server during query) while executing AES* functions under SSL
+#
+select aes_decrypt('MySQL','adf');
+select 'still connected?';
connection default;
disconnect ssl_con;
# Wait till all disconnects are completed
--source include/wait_until_count_sessions.inc
-
-## This test file is for testing encrypted communication only, not other
-## encryption routines that the SSL library happens to provide!
diff --git a/mysql-test/t/ssl_8k_key.test b/mysql-test/t/ssl_8k_key.test
index a07d0eb7d02..27cffdce1f2 100644
--- a/mysql-test/t/ssl_8k_key.test
+++ b/mysql-test/t/ssl_8k_key.test
@@ -1,3 +1,6 @@
+# This test should work in embedded server after we fix mysqltest
+-- source include/not_embedded.inc
+
-- source include/have_ssl_communication.inc
#
# Bug#29784 YaSSL assertion failure when reading 8k key.
diff --git a/mysql-test/t/ssl_ca.test b/mysql-test/t/ssl_ca.test
index 3652040dd0b..8d830a75879 100644
--- a/mysql-test/t/ssl_ca.test
+++ b/mysql-test/t/ssl_ca.test
@@ -1,4 +1,4 @@
---source include/have_ssl.inc
+--source include/have_ssl_communication.inc
--source include/not_embedded.inc
--echo #
@@ -7,11 +7,10 @@
--echo # try to connect with wrong '--ssl-ca' path : should fail
--error 1
---exec $MYSQL --ssl-ca=$MYSQL_TEST_DIR/std_data/wrong-cacert.pem --ssl-key=$MYSQL_TEST_DIR/std_data/client-key.pem --ssl-cert=$MYSQL_TEST_DIR/std_data/client-cert.pem test -e "SHOW STATUS LIKE 'Ssl_cipher'" 2>&1
+--exec $MYSQL --ssl-ca=$MYSQL_TEST_DIR/std_data/wrong-cacert.pem --ssl-key=$MYSQL_TEST_DIR/std_data/client-key.pem --ssl-cert=$MYSQL_TEST_DIR/std_data/client-cert.pem test -e "SELECT (VARIABLE_VALUE <> '') AS have_ssl FROM INFORMATION_SCHEMA.SESSION_STATUS WHERE VARIABLE_NAME='Ssl_cipher'" 2>&1
--echo # try to connect with correct '--ssl-ca' path : should connect
---replace_result DHE-RSA-AES256-GCM-SHA384 DHE-RSA-AES256-SHA
---exec $MYSQL --ssl-ca=$MYSQL_TEST_DIR/std_data/cacert.pem --ssl-key=$MYSQL_TEST_DIR/std_data/client-key.pem --ssl-cert=$MYSQL_TEST_DIR/std_data/client-cert.pem test -e "SHOW STATUS LIKE 'Ssl_cipher'"
+--exec $MYSQL --ssl-ca=$MYSQL_TEST_DIR/std_data/cacert.pem --ssl-key=$MYSQL_TEST_DIR/std_data/client-key.pem --ssl-cert=$MYSQL_TEST_DIR/std_data/client-cert.pem test -e "SELECT (VARIABLE_VALUE <> '') AS have_ssl FROM INFORMATION_SCHEMA.SESSION_STATUS WHERE VARIABLE_NAME='Ssl_cipher'"
--echo #
--echo # Bug#21920678: SSL-CA DOES NOT ACCEPT ~USER TILDE HOME DIRECTORY
@@ -22,15 +21,12 @@
--echo # try to connect with '--ssl-ca' option using tilde home directoy
--echo # path substitution : should connect
---replace_result DHE-RSA-AES256-GCM-SHA384 DHE-RSA-AES256-SHA
---exec $MYSQL --ssl-ca$mysql_test_dir_path/std_data/cacert.pem --ssl-key=$MYSQL_TEST_DIR/std_data/client-key.pem --ssl-cert=$MYSQL_TEST_DIR/std_data/client-cert.pem test -e "SHOW STATUS LIKE 'Ssl_cipher'"
+--exec $MYSQL --ssl-ca$mysql_test_dir_path/std_data/cacert.pem --ssl-key=$MYSQL_TEST_DIR/std_data/client-key.pem --ssl-cert=$MYSQL_TEST_DIR/std_data/client-cert.pem test -e "SELECT (VARIABLE_VALUE <> '') AS have_ssl FROM INFORMATION_SCHEMA.SESSION_STATUS WHERE VARIABLE_NAME='Ssl_cipher'"
--echo # try to connect with '--ssl-key' option using tilde home directoy
--echo # path substitution : should connect
---replace_result DHE-RSA-AES256-GCM-SHA384 DHE-RSA-AES256-SHA
---exec $MYSQL --ssl-ca=$MYSQL_TEST_DIR/std_data/cacert.pem --ssl-key$mysql_test_dir_path/std_data/client-key.pem --ssl-cert=$MYSQL_TEST_DIR/std_data/client-cert.pem test -e "SHOW STATUS LIKE 'Ssl_cipher'"
+--exec $MYSQL --ssl-ca=$MYSQL_TEST_DIR/std_data/cacert.pem --ssl-key$mysql_test_dir_path/std_data/client-key.pem --ssl-cert=$MYSQL_TEST_DIR/std_data/client-cert.pem test -e "SELECT (VARIABLE_VALUE <> '') AS have_ssl FROM INFORMATION_SCHEMA.SESSION_STATUS WHERE VARIABLE_NAME='Ssl_cipher'"
--echo # try to connect with '--ssl-cert' option using tilde home directoy
--echo # path substitution : should connect
---replace_result DHE-RSA-AES256-GCM-SHA384 DHE-RSA-AES256-SHA
---exec $MYSQL --ssl-ca=$MYSQL_TEST_DIR/std_data/cacert.pem --ssl-key=$MYSQL_TEST_DIR/std_data/client-key.pem --ssl-cert$mysql_test_dir_path/std_data/client-cert.pem test -e "SHOW STATUS LIKE 'Ssl_cipher'"
+--exec $MYSQL --ssl-ca=$MYSQL_TEST_DIR/std_data/cacert.pem --ssl-key=$MYSQL_TEST_DIR/std_data/client-key.pem --ssl-cert$mysql_test_dir_path/std_data/client-cert.pem test -e "SELECT (VARIABLE_VALUE <> '') AS have_ssl FROM INFORMATION_SCHEMA.SESSION_STATUS WHERE VARIABLE_NAME='Ssl_cipher'"
diff --git a/mysql-test/t/ssl_cipher.test b/mysql-test/t/ssl_cipher.test
index 5346968175c..cf249343324 100644
--- a/mysql-test/t/ssl_cipher.test
+++ b/mysql-test/t/ssl_cipher.test
@@ -5,7 +5,7 @@
--echo # BUG#11760210 - SSL_CIPHER_LIST NOT SET OR RETURNED FOR "SHOW STATUS LIKE 'SSL_CIPHER_LIST'"
--echo #
--- source include/have_ssl.inc
+-- source include/have_ssl_communication.inc
# Save the initial number of concurrent sessions
--source include/count_sessions.inc
diff --git a/mysql-test/t/ssl_compress.test b/mysql-test/t/ssl_compress.test
index 5e45e3824a2..588d4555db8 100644
--- a/mysql-test/t/ssl_compress.test
+++ b/mysql-test/t/ssl_compress.test
@@ -11,8 +11,7 @@
connect (ssl_compress_con,localhost,root,,,,,SSL COMPRESS);
# Check ssl turned on
---replace_result DHE-RSA-AES256-GCM-SHA384 DHE-RSA-AES256-SHA
-SHOW STATUS LIKE 'Ssl_cipher';
+SELECT (VARIABLE_VALUE <> '') AS have_ssl FROM INFORMATION_SCHEMA.SESSION_STATUS WHERE VARIABLE_NAME='Ssl_cipher';
# Check compression turned on
SHOW STATUS LIKE 'Compression';
@@ -21,8 +20,7 @@ SHOW STATUS LIKE 'Compression';
-- source include/common-tests.inc
# Check ssl turned on
---replace_result DHE-RSA-AES256-GCM-SHA384 DHE-RSA-AES256-SHA
-SHOW STATUS LIKE 'Ssl_cipher';
+SELECT (VARIABLE_VALUE <> '') AS have_ssl FROM INFORMATION_SCHEMA.SESSION_STATUS WHERE VARIABLE_NAME='Ssl_cipher';
# Check compression turned on
SHOW STATUS LIKE 'Compression';
diff --git a/mysql-test/t/ssl_crl-master.opt b/mysql-test/t/ssl_crl-master.opt
new file mode 100644
index 00000000000..8500f8cd6e7
--- /dev/null
+++ b/mysql-test/t/ssl_crl-master.opt
@@ -0,0 +1,4 @@
+--ssl-ca=$MYSQL_TEST_DIR/std_data/crl-ca-cert.pem
+--ssl-key=$MYSQL_TEST_DIR/std_data/crl-server-key.pem
+--ssl-cert=$MYSQL_TEST_DIR/std_data/crl-server-cert.pem
+--ssl-crl=$MYSQL_TEST_DIR/std_data/crl-client-revoked.crl
diff --git a/mysql-test/t/ssl_crl.test b/mysql-test/t/ssl_crl.test
new file mode 100644
index 00000000000..65c14837e50
--- /dev/null
+++ b/mysql-test/t/ssl_crl.test
@@ -0,0 +1,16 @@
+# This test should work in embedded server after we fix mysqltest
+-- source include/not_embedded.inc
+-- source include/have_openssl.inc
+
+--echo # test --crl for the client : should connect
+--replace_result $MYSQL_TEST_DIR MYSQL_TEST_DIR
+--exec $MYSQL --ssl-ca=$MYSQL_TEST_DIR/std_data/crl-ca-cert.pem --ssl-key=$MYSQL_TEST_DIR/std_data/crl-client-valid-key.pem --ssl-cert=$MYSQL_TEST_DIR/std_data/crl-client-valid-cert.pem test --ssl-crl=$MYSQL_TEST_DIR/std_data/crl-client-revoked.crl -e "SHOW VARIABLES like '%ssl%';"
+
+--echo # test --crlpath for the client : should connect
+--replace_result $MYSQL_TEST_DIR MYSQL_TEST_DIR
+--exec $MYSQL --ssl-ca=$MYSQL_TEST_DIR/std_data/crl-ca-cert.pem --ssl-key=$MYSQL_TEST_DIR/std_data/crl-client-valid-key.pem --ssl-cert=$MYSQL_TEST_DIR/std_data/crl-client-valid-cert.pem --ssl-crlpath=$MYSQL_TEST_DIR/std_data/crldir test -e "SHOW VARIABLES like '%ssl%';"
+
+--echo # try logging in with a certificate in the server's --ssl-crl : should fail
+--replace_result $MYSQL_TEST_DIR MYSQL_TEST_DIR
+--error 1
+--exec $MYSQL --ssl-ca=$MYSQL_TEST_DIR/std_data/crl-ca-cert.pem --ssl-key=$MYSQL_TEST_DIR/std_data/crl-client-key.pem --ssl-cert=$MYSQL_TEST_DIR/std_data/crl-client-cert.pem test -e "SHOW VARIABLES like '%ssl%';"
diff --git a/mysql-test/t/ssl_crl_clients-master.opt b/mysql-test/t/ssl_crl_clients-master.opt
new file mode 100644
index 00000000000..fa885a61a0c
--- /dev/null
+++ b/mysql-test/t/ssl_crl_clients-master.opt
@@ -0,0 +1,4 @@
+--ssl-ca=$MYSQL_TEST_DIR/std_data/crl-ca-cert.pem
+--ssl-key=$MYSQL_TEST_DIR/std_data/crl-client-key.pem
+--ssl-cert=$MYSQL_TEST_DIR/std_data/crl-client-cert.pem
+--ssl-crl=$MYSQL_TEST_DIR/std_data/crl-client-revoked.crl
diff --git a/mysql-test/t/ssl_crl_clients.test b/mysql-test/t/ssl_crl_clients.test
new file mode 100644
index 00000000000..7c05f498fbe
--- /dev/null
+++ b/mysql-test/t/ssl_crl_clients.test
@@ -0,0 +1,41 @@
+# This test should work in embedded server after we fix mysqltest
+-- source include/not_embedded.inc
+-- source include/have_openssl.inc
+
+--echo # Test clients with and without CRL lists
+
+let $ssl_base = --ssl-ca=$MYSQL_TEST_DIR/std_data/crl-ca-cert.pem --ssl-key=$MYSQL_TEST_DIR/std_data/crl-server-key.pem --ssl-cert=$MYSQL_TEST_DIR/std_data/crl-server-cert.pem;
+let $ssl_crl = $ssl_base --ssl-crl=$MYSQL_TEST_DIR/std_data/crl-client-revoked.crl;
+let $ssl_crlpath = $ssl_base --ssl-crlpath=$MYSQL_TEST_DIR/std_data/crldir;
+
+
+--echo ############ Test mysql ##############
+
+--echo # Test mysql connecting to a server with a certificate revoked by -crl
+--replace_result $MYSQL_TEST_DIR MYSQL_TEST_DIR
+--error 1
+--exec $MYSQL $ssl_crl test -e "SHOW VARIABLES like '%ssl%';"
+
+--echo # Test mysql connecting to a server with a certificate revoked by -crlpath
+--replace_result $MYSQL_TEST_DIR MYSQL_TEST_DIR
+--error 1
+--exec $MYSQL $ssl_crlpath test -e "SHOW VARIABLES like '%ssl%';"
+
+
+--echo ############ Test mysqladmin ##############
+let $admin_prefix = --no-defaults;
+let $admin_suffix = --default-character-set=latin1 -S $MASTER_MYSOCK -P $MASTER_MYPORT -u root --password= ping;
+
+--echo # Test mysqladmin connecting to a server with a certificate revoked by -crl
+--disable_result_log
+--replace_regex /.*mysqladmin.*: connect/mysqladmin: connect/
+--error 2
+--exec $MYSQLADMIN $admin_prefix $ssl_crl $admin_suffix 2>&1
+--enable_result_log
+
+--disable_result_log
+--echo # Test mysqladmin connecting to a server with a certificate revoked by -crlpath
+--replace_regex /.*mysqladmin.*: connect/mysqladmin: connect/
+--error 2
+--exec $MYSQLADMIN $admin_prefix $ssl_crlpath $admin_suffix 2>&1
+--enable_result_log
diff --git a/mysql-test/t/ssl_crl_clients_valid-master.opt b/mysql-test/t/ssl_crl_clients_valid-master.opt
new file mode 100644
index 00000000000..258df564eba
--- /dev/null
+++ b/mysql-test/t/ssl_crl_clients_valid-master.opt
@@ -0,0 +1,4 @@
+--ssl-ca=$MYSQL_TEST_DIR/std_data/crl-ca-cert.pem
+--ssl-key=$MYSQL_TEST_DIR/std_data/crl-client-valid-key.pem
+--ssl-cert=$MYSQL_TEST_DIR/std_data/crl-client-valid-cert.pem
+--ssl-crl=$MYSQL_TEST_DIR/std_data/crl-client-revoked.crl
diff --git a/mysql-test/t/ssl_crl_clients_valid.test b/mysql-test/t/ssl_crl_clients_valid.test
new file mode 100644
index 00000000000..f08fbf09397
--- /dev/null
+++ b/mysql-test/t/ssl_crl_clients_valid.test
@@ -0,0 +1,23 @@
+# This test should work in embedded server after we fix mysqltest
+-- source include/not_embedded.inc
+-- source include/have_openssl.inc
+
+--echo # Test clients with and without CRL lists
+
+let $ssl_base = --ssl-ca=$MYSQL_TEST_DIR/std_data/crl-ca-cert.pem --ssl-key=$MYSQL_TEST_DIR/std_data/crl-server-key.pem --ssl-cert=$MYSQL_TEST_DIR/std_data/crl-server-cert.pem;
+let $ssl_crl = $ssl_base --ssl-crl=$MYSQL_TEST_DIR/std_data/crl-client-revoked.crl;
+let $ssl_crlpath = $ssl_base --ssl-crlpath=$MYSQL_TEST_DIR/std_data/crldir;
+
+
+--echo ############ Test mysql ##############
+
+--echo # Test mysql connecting to a server with an empty crl
+--replace_result $MYSQL_TEST_DIR MYSQL_TEST_DIR
+--exec $MYSQL $ssl_crl test -e "SHOW VARIABLES like '%ssl%';" 2>&1
+
+--echo ############ Test mysqladmin ##############
+let $admin_prefix = --no-defaults;
+let $admin_suffix = --default-character-set=latin1 -S $MASTER_MYSOCK -P $MASTER_MYPORT -u root --password= ping;
+
+--echo # Test mysqladmin connecting to a server with an empty crl
+--exec $MYSQLADMIN $admin_prefix $ssl_crl $admin_suffix 2>&1
diff --git a/mysql-test/t/ssl_crl_clrpath-master.opt b/mysql-test/t/ssl_crl_clrpath-master.opt
new file mode 100644
index 00000000000..b1f486a322b
--- /dev/null
+++ b/mysql-test/t/ssl_crl_clrpath-master.opt
@@ -0,0 +1,4 @@
+--ssl-ca=$MYSQL_TEST_DIR/std_data/crl-ca-cert.pem
+--ssl-key=$MYSQL_TEST_DIR/std_data/crl-server-key.pem
+--ssl-cert=$MYSQL_TEST_DIR/std_data/crl-server-cert.pem
+--ssl-crlpath=$MYSQL_TEST_DIR/std_data/crldir
diff --git a/mysql-test/t/ssl_crl_clrpath.test b/mysql-test/t/ssl_crl_clrpath.test
new file mode 100644
index 00000000000..50d84ad175e
--- /dev/null
+++ b/mysql-test/t/ssl_crl_clrpath.test
@@ -0,0 +1,16 @@
+# This test should work in embedded server after we fix mysqltest
+-- source include/not_embedded.inc
+-- source include/have_openssl.inc
+
+--echo # test --crl for the client : should connect
+--replace_result $MYSQL_TEST_DIR MYSQL_TEST_DIR
+--exec $MYSQL --ssl-ca=$MYSQL_TEST_DIR/std_data/crl-ca-cert.pem --ssl-key=$MYSQL_TEST_DIR/std_data/crl-client-valid-key.pem --ssl-cert=$MYSQL_TEST_DIR/std_data/crl-client-valid-cert.pem test --ssl-crl=$MYSQL_TEST_DIR/std_data/crl-client-revoked.crl -e "SHOW VARIABLES like '%ssl%';"
+
+--echo # test --crlpath for the client : should connect
+--replace_result $MYSQL_TEST_DIR MYSQL_TEST_DIR
+--exec $MYSQL --ssl-ca=$MYSQL_TEST_DIR/std_data/crl-ca-cert.pem --ssl-key=$MYSQL_TEST_DIR/std_data/crl-client-valid-key.pem --ssl-cert=$MYSQL_TEST_DIR/std_data/crl-client-valid-cert.pem --ssl-crlpath=$MYSQL_TEST_DIR/std_data/crldir test -e "SHOW VARIABLES like '%ssl%';"
+
+--echo # try logging in with a certificate in the server's --ssl-crlpath : should fail
+--replace_result $MYSQL_TEST_DIR MYSQL_TEST_DIR
+--error 1
+--exec $MYSQL --ssl-ca=$MYSQL_TEST_DIR/std_data/crl-ca-cert.pem --ssl-key=$MYSQL_TEST_DIR/std_data/crl-client-key.pem --ssl-cert=$MYSQL_TEST_DIR/std_data/crl-client-cert.pem test -e "SHOW VARIABLES like '%ssl%';"
diff --git a/mysql-test/t/ssl_timeout.test b/mysql-test/t/ssl_timeout.test
new file mode 100644
index 00000000000..430fe7130de
--- /dev/null
+++ b/mysql-test/t/ssl_timeout.test
@@ -0,0 +1,20 @@
+--source include/have_ssl_communication.inc
+
+# Save the initial number of concurrent sessions
+--source include/count_sessions.inc
+
+--echo # connect with read timeout so SLEEP() should timeout
+connect (ssl_con,localhost,root,,,,,SSL read_timeout=5);
+
+--echo # Check ssl turned on
+SELECT (VARIABLE_VALUE <> '') AS have_ssl FROM INFORMATION_SCHEMA.SESSION_STATUS WHERE VARIABLE_NAME='Ssl_cipher';
+
+# --error CR_SERVER_LOST
+--error 2013
+SELECT SLEEP(600);
+
+connection default;
+disconnect ssl_con;
+
+# Wait till all disconnects are completed
+--source include/wait_until_count_sessions.inc
diff --git a/mysql-test/t/stat_tables-enospc.test b/mysql-test/t/stat_tables-enospc.test
new file mode 100644
index 00000000000..12e42f6adc0
--- /dev/null
+++ b/mysql-test/t/stat_tables-enospc.test
@@ -0,0 +1,23 @@
+#
+# MDEV-6181 EITS could eat all tmpdir space and hang
+#
+# test that ANALYZE TABLE is immediately aborted when going out of disk space
+--source include/have_debug.inc
+call mtr.add_suppression("No space left on device");
+create table t1 (a varchar(255), b varchar(255), c varchar(255));
+--disable_query_log
+let $i=10000;
+while ($i) {
+ insert t1 values (repeat(format(rand(),10), 20),
+ repeat(format(rand(),10), 20),
+ repeat(format(rand(),10), 20));
+ dec $i;
+}
+--enable_query_log
+set use_stat_tables=PREFERABLY, optimizer_use_condition_selectivity=3;
+set debug_dbug='+d,simulate_file_write_error';
+--replace_regex /'.*'/'tmp-file'/
+analyze table t1;
+set debug_dbug='';
+drop table t1;
+
diff --git a/mysql-test/t/stat_tables.test b/mysql-test/t/stat_tables.test
new file mode 100644
index 00000000000..4cbaa9e27c8
--- /dev/null
+++ b/mysql-test/t/stat_tables.test
@@ -0,0 +1,308 @@
+--source include/have_stat_tables.inc
+
+select @@global.use_stat_tables;
+select @@session.use_stat_tables;
+
+set @save_use_stat_tables=@@use_stat_tables;
+
+set use_stat_tables='preferably';
+
+--disable_warnings
+DROP DATABASE IF EXISTS dbt3_s001;
+--enable_warnings
+
+CREATE DATABASE dbt3_s001;
+
+use dbt3_s001;
+
+set @save_optimizer_switch=@@optimizer_switch;
+set optimizer_switch='extended_keys=off';
+
+--disable_query_log
+--disable_result_log
+--disable_warnings
+--source include/dbt3_s001.inc
+create index i_p_retailprice on part(p_retailprice);
+delete from mysql.table_stats;
+delete from mysql.column_stats;
+delete from mysql.index_stats;
+ANALYZE TABLE
+customer, lineitem, nation, orders, part, partsupp, region, supplier;
+FLUSH TABLE mysql.table_stats, mysql.index_stats;
+--enable_warnings
+--enable_result_log
+--enable_query_log
+
+select * from mysql.table_stats;
+select * from mysql.index_stats;
+
+set optimizer_switch=@save_optimizer_switch;
+
+set @save_optimizer_switch=@@optimizer_switch;
+set optimizer_switch='index_condition_pushdown=off';
+
+let $Q5=
+select n_name, sum(l_extendedprice * (1 - l_discount)) as revenue
+from customer, orders, lineitem, supplier, nation, region
+where c_custkey = o_custkey and l_orderkey = o_orderkey
+ and l_suppkey = s_suppkey and c_nationkey = s_nationkey
+ and s_nationkey = n_nationkey and n_regionkey = r_regionkey
+ and r_name = 'AMERICA' and o_orderdate >= date '1995-01-01'
+ and o_orderdate < date '1995-01-01' + interval '1' year
+group by n_name
+order by revenue desc;
+
+eval EXPLAIN $Q5;
+eval $Q5;
+
+set optimizer_switch=@save_optimizer_switch;
+
+delete from mysql.index_stats;
+
+--disable_query_log
+--disable_result_log
+--disable_warnings
+ANALYZE TABLE
+customer, lineitem, nation, orders, part, partsupp, region, supplier;
+FLUSH TABLE mysql.table_stats, mysql.index_stats;
+--enable_warnings
+--enable_result_log
+--enable_query_log
+
+select * from mysql.table_stats;
+select * from mysql.index_stats;
+
+select * from mysql.table_stats where table_name='orders';
+select * from mysql.index_stats where table_name='orders';
+select (select cardinality from mysql.table_stats where table_name='orders') /
+ (select avg_frequency from mysql.index_stats
+ where index_name='i_o_orderdate' and prefix_arity=1) as n_distinct;
+select count(distinct o_orderdate) from orders;
+select (select cardinality from mysql.table_stats where table_name='orders') /
+ (select avg_frequency from mysql.index_stats
+ where index_name='i_o_custkey' and prefix_arity=1) as n_distinct;
+select count(distinct o_custkey) from orders;
+show index from orders;
+select index_name, column_name, cardinality from information_schema.statistics
+ where table_name='orders';
+
+set @save_optimizer_switch=@@optimizer_switch;
+set optimizer_switch='index_condition_pushdown=off';
+
+eval EXPLAIN $Q5;
+eval $Q5;
+
+set optimizer_switch=@save_optimizer_switch;
+
+let $Q8=
+select o_year,
+ sum(case when nation = 'UNITED STATES' then volume else 0 end) /
+ sum(volume) as mkt_share
+from (select extract(year from o_orderdate) as o_year,
+ l_extendedprice * (1-l_discount) as volume,
+ n2.n_name as nation
+ from part, supplier, lineitem, orders, customer,
+ nation n1, nation n2, region
+ where p_partkey = l_partkey and s_suppkey = l_suppkey
+ and l_orderkey = o_orderkey and o_custkey = c_custkey
+ and c_nationkey = n1.n_nationkey and n1.n_regionkey = r_regionkey
+ and r_name = 'AMERICA' and s_nationkey = n2.n_nationkey
+ and o_orderdate between date '1995-01-01' and date '1996-12-31'
+ and p_type = 'STANDARD BRUSHED STEEL' ) as all_nations
+group by o_year
+order by o_year;
+
+eval EXPLAIN $Q8;
+eval $Q8;
+
+
+let $Q9=
+select nation, o_year, sum(amount) as sum_profit
+from (select n_name as nation,
+ extract(year from o_orderdate) as o_year,
+ l_extendedprice * (1 - l_discount) - ps_supplycost * l_quantity as amount
+ from part, supplier, lineitem, partsupp, orders, nation
+ where s_suppkey = l_suppkey and ps_suppkey = l_suppkey
+ and ps_partkey = l_partkey and p_partkey = l_partkey
+ and o_orderkey = l_orderkey and s_nationkey = n_nationkey
+ and p_name like '%green%') as profit
+group by nation, o_year
+order by nation, o_year desc;
+
+eval EXPLAIN $Q9;
+eval $Q9;
+
+
+set @save_optimizer_switch=@@optimizer_switch;
+set optimizer_switch='extended_keys=on';
+
+let $QQ1=
+select o_orderkey, p_partkey
+ from part, lineitem, orders
+ where p_retailprice > 1100 and o_orderdate='1997-01-01'
+ and o_orderkey=l_orderkey and p_partkey=l_partkey;
+
+eval EXPLAIN $QQ1;
+eval $QQ1;
+
+set optimizer_switch=@save_optimizer_switch;
+
+
+DROP DATABASE dbt3_s001;
+
+use test;
+
+--echo #
+--echo # Bug mdev-473: ANALYZE table locked for write
+--echo #
+
+set use_stat_tables='complementary';
+
+create table t1 (i int);
+
+lock table t1 write;
+analyze table t1;
+alter table t1 add column a varchar(8);
+
+drop table t1;
+
+--echo #
+--echo # Bug mdev-487: memory leak in ANALYZE with stat tables
+--echo #
+
+SET use_stat_tables = 'preferably';
+
+CREATE TABLE t1 (a INT);
+INSERT INTO t1 VALUES (1),(2);
+DELETE FROM t1 WHERE a=1;
+
+ANALYZE TABLE t1;
+
+DROP TABLE t1;
+
+--echo #
+--echo # Bug mdev-518: corrupted/missing statistical tables
+--echo #
+
+CREATE TABLE t1 (i int) ENGINE=MyISAM;
+INSERT INTO t1 VALUES (1),(2);
+
+FLUSH TABLE t1;
+SET use_stat_tables='never';
+EXPLAIN SELECT * FROM t1;
+
+--move_file $MYSQLTEST_VARDIR/mysqld.1/data/mysql/table_stats.MYD $MYSQLTEST_VARDIR/mysqld.1/data/mysql/table_stats.MYD.save
+
+FLUSH TABLES;
+SET use_stat_tables='preferably';
+--disable_warnings
+EXPLAIN SELECT * FROM t1;
+--enable_warnings
+
+# Cleanup
+--move_file $MYSQLTEST_VARDIR/mysqld.1/data/mysql/table_stats.MYD.save $MYSQLTEST_VARDIR/mysqld.1/data/mysql/table_stats.MYD
+DROP TABLE t1;
+
+set use_stat_tables=@save_use_stat_tables;
+
+--echo #
+--echo # Bug mdev-5204: invalid impossible where after reading const tables
+--echo # when use_stat_tables = 'preferably'
+--echo #
+
+set use_stat_tables = 'preferably';
+
+CREATE TABLE t1 (id int PRIMARY KEY) ENGINE=MyISAM;
+INSERT INTO t1 VALUES (1),(2);
+ANALYZE TABLE t1;
+
+CREATE TABLE t2 (name char(3)) ENGINE=MyISAM;
+ANALYZE TABLE t2;
+INSERT INTO t2 VALUES ('USA'),('AUS');
+
+SELECT * FROM t1 STRAIGHT_JOIN t2 WHERE name IN ( 'AUS','YEM' ) AND id = 1;
+EXPLAIN
+SELECT * FROM t1 STRAIGHT_JOIN t2 WHERE name IN ( 'AUS','YEM' ) AND id = 1;
+
+ANALYZE TABLE t2;
+
+SELECT * FROM t1 STRAIGHT_JOIN t2 WHERE name IN ( 'AUS','YEM' ) AND id = 1;
+EXPLAIN
+SELECT * FROM t1 STRAIGHT_JOIN t2 WHERE name IN ( 'AUS','YEM' ) AND id = 1;
+
+DROP TABLE t1,t2;
+
+--echo #
+--echo # MDEV-7370: Server deadlocks on renaming a table for which persistent statistics exists
+--echo #
+
+--disable_warnings
+drop database if exists db1;
+drop database if exists db1;
+--enable_warnings
+
+create database db1;
+create database db2;
+use db1;
+--echo #
+--echo # First, run the original testcase:
+--echo #
+create table t1 (i int);
+insert into t1 values (10),(20);
+analyze table t1 persistent for all;
+rename table t1 to db2.t1;
+
+--echo # Verify that stats in the old database are gone:
+select * from mysql.column_stats where db_name='db1' and table_name='t1';
+select * from mysql.table_stats where db_name='db1' and table_name='t1';
+
+--echo # Verify that stats are present in the new database:
+select * from mysql.column_stats where db_name='db2' and table_name='t1';
+select * from mysql.table_stats where db_name='db2' and table_name='t1';
+
+
+--echo #
+--echo # Now, try with more than one column and with indexes:
+--echo #
+use test;
+create table t1(a int primary key);
+insert into t1 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
+
+
+use db1;
+create table t2 (a int, b int, c int, key IDX1(a), key IDX2(a,b));
+insert into t2 select a/10, a/2, a from test.t1;
+analyze table t2 persistent for all;
+
+alter table t2 rename db2.t2;
+
+--echo # Verify that stats in the old database are gone:
+select * from mysql.table_stats where db_name='db1' and table_name='t2';
+select * from mysql.column_stats where db_name='db1' and table_name='t2';
+select * from mysql.index_stats where db_name='db1' and table_name='t2';
+
+--echo # Verify that stats are present in the new database:
+select * from mysql.table_stats where db_name='db2' and table_name='t2';
+select * from mysql.column_stats where db_name='db2' and table_name='t2';
+select * from mysql.index_stats where db_name='db2' and table_name='t2';
+
+use db2;
+--echo #
+--echo # Now, rename within the same database and verify:
+--echo #
+rename table t2 to t3;
+--echo # No stats under old name:
+select * from mysql.table_stats where db_name='db2' and table_name='t2';
+select * from mysql.column_stats where db_name='db2' and table_name='t2';
+select * from mysql.index_stats where db_name='db2' and table_name='t2';
+--echo # Stats under the new name:
+select * from mysql.table_stats where db_name='db2' and table_name='t3';
+select * from mysql.column_stats where db_name='db2' and table_name='t3';
+select * from mysql.index_stats where db_name='db2' and table_name='t3';
+
+use test;
+drop database db1;
+drop database db2;
+drop table t1;
+
+set use_stat_tables=@save_use_stat_tables;
diff --git a/mysql-test/t/stat_tables_disabled.test b/mysql-test/t/stat_tables_disabled.test
new file mode 100644
index 00000000000..c9d923f903b
--- /dev/null
+++ b/mysql-test/t/stat_tables_disabled.test
@@ -0,0 +1,78 @@
+--source include/have_innodb.inc
+
+SET SESSION STORAGE_ENGINE='InnoDB';
+
+select @@global.use_stat_tables;
+select @@session.use_stat_tables;
+
+set @save_use_stat_tables=@@use_stat_tables;
+
+set use_stat_tables='preferably';
+
+--disable_warnings
+DROP DATABASE IF EXISTS dbt3_s001;
+--enable_warnings
+
+CREATE DATABASE dbt3_s001;
+
+use dbt3_s001;
+
+set @save_optimizer_switch=@@optimizer_switch;
+set optimizer_switch='extended_keys=off';
+
+--disable_query_log
+--disable_result_log
+--disable_warnings
+--source include/dbt3_s001.inc
+delete from mysql.table_stats;
+delete from mysql.column_stats;
+delete from mysql.index_stats;
+ANALYZE TABLE
+customer, lineitem, nation, orders, part, partsupp, region, supplier;
+--enable_warnings
+--enable_result_log
+--enable_query_log
+
+--echo #
+--echo # Bug mdev-503: optimizer ignores setting use_stat_tables='preferably'
+--echo #
+
+flush tables
+customer, lineitem, nation, orders, part, partsupp, region, supplier;
+
+let $Q3S=
+select sql_calc_found_rows straight_join
+ l_orderkey, sum(l_extendedprice*(1-l_discount)) as revenue,
+ o_orderdate, o_shippriority
+from orders, customer, lineitem
+where c_mktsegment = 'BUILDING' and c_custkey = o_custkey
+ and l_orderkey = o_orderkey and o_orderdate < date '1995-03-15'
+ and l_shipdate > date '1995-03-15'
+group by l_orderkey, o_orderdate, o_shippriority
+order by revenue desc, o_orderdate
+limit 10;
+
+set use_stat_tables='never';
+--replace_column 9 #
+eval EXPLAIN $Q3S;
+
+set use_stat_tables='preferably';
+--replace_result 2 1
+eval EXPLAIN $Q3S;
+
+flush tables customer, orders, lineitem;
+eval EXPLAIN $Q3S;
+
+--echo # End of the test case for mdev-503
+
+set optimizer_switch=@save_optimizer_switch;
+
+
+DROP DATABASE dbt3_s001;
+
+use test;
+
+set use_stat_tables=@save_use_stat_tables;
+
+
+SET SESSION STORAGE_ENGINE=DEFAULT;
diff --git a/mysql-test/t/stat_tables_innodb.test b/mysql-test/t/stat_tables_innodb.test
new file mode 100644
index 00000000000..04e81de8f9d
--- /dev/null
+++ b/mysql-test/t/stat_tables_innodb.test
@@ -0,0 +1,12 @@
+--source include/have_innodb.inc
+
+SET SESSION STORAGE_ENGINE='InnoDB';
+
+set @save_optimizer_switch_for_stat_tables_test=@@optimizer_switch;
+set optimizer_switch='extended_keys=on';
+
+--source stat_tables.test
+
+set optimizer_switch=@save_optimizer_switch_for_stat_tables_test;
+
+SET SESSION STORAGE_ENGINE=DEFAULT;
diff --git a/mysql-test/t/stat_tables_par.test b/mysql-test/t/stat_tables_par.test
new file mode 100644
index 00000000000..7305d1453a8
--- /dev/null
+++ b/mysql-test/t/stat_tables_par.test
@@ -0,0 +1,278 @@
+--source include/have_stat_tables.inc
+--source include/have_debug_sync.inc
+--source include/not_embedded.inc
+
+set @save_use_stat_tables=@@use_stat_tables;
+
+set use_stat_tables='preferably';
+
+--disable_warnings
+DROP DATABASE IF EXISTS dbt3_s001;
+--enable_warnings
+
+CREATE DATABASE dbt3_s001;
+
+use dbt3_s001;
+
+set @save_optimizer_switch=@@optimizer_switch;
+set optimizer_switch='extended_keys=off';
+
+--disable_query_log
+--disable_result_log
+--disable_warnings
+--source include/dbt3_s001.inc
+delete from mysql.table_stats;
+delete from mysql.column_stats;
+delete from mysql.index_stats;
+ANALYZE TABLE
+customer, lineitem, nation, orders, part, partsupp, region, supplier;
+--enable_warnings
+--enable_result_log
+--enable_query_log
+
+select * from mysql.table_stats;
+select * from mysql.index_stats;
+
+
+#
+# Test for parallel memory allocation for statistical data
+#
+# assumes that start the code of memory allocation for stats data has this line:
+#
+# DEBUG_SYNC(thd, "statistics_mem_alloc_start1");
+# DEBUG_SYNC(thd, "statistics_mem_alloc_start2");
+#
+
+let $Q6=
+select sum(l_extendedprice*l_discount) as revenue
+from lineitem
+where l_shipdate >= date '1994-01-01'
+ and l_shipdate < date '1994-01-01' + interval '1' year
+ and l_discount between 0.06 - 0.01 and 0.06 + 0.01
+ and l_quantity < 24;
+
+flush table lineitem;
+set use_stat_tables='never';
+eval $Q6;
+
+connect (con1, localhost, root,,);
+connect (con2, localhost, root,,);
+
+connection con1;
+set debug_sync='statistics_mem_alloc_start1 WAIT_FOR second_thread_started_too';
+set debug_sync='statistics_mem_alloc_start2 SIGNAL first_thread_working';
+use dbt3_s001;
+set use_stat_tables='preferably';
+--send_eval $Q6
+
+connection con2;
+set debug_sync='statistics_mem_alloc_start1 SIGNAL second_thread_started_too';
+set debug_sync='statistics_mem_alloc_start2 WAIT_FOR first_thread_working';
+use dbt3_s001;
+set use_stat_tables='preferably';
+--send_eval $Q6
+
+connection con1;
+--reap
+
+connection con2;
+--reap
+
+connection default;
+set use_stat_tables='preferably';
+disconnect con1;
+disconnect con2;
+set debug_sync='RESET';
+
+#
+# Test for parallel statistics collection
+#
+# assumes that start of stats collection code has this line:
+#
+# DEBUG_SYNC(thd, "statistics_collection_start1");
+# DEBUG_SYNC(thd, "statistics_collection_start2");
+#
+
+select * from mysql.index_stats where table_name='lineitem' order by index_name;
+delete from mysql.index_stats
+ where table_name='lineitem' and
+ index_name in ('i_l_shipdate', 'i_l_receiptdate');
+select * from mysql.index_stats where table_name='lineitem' order by index_name;
+--disable_result_log
+--disable_warnings
+analyze table lineitem persistent for columns() indexes (i_l_shipdate);
+--enable_warnings
+--enable_result_log
+select * from mysql.index_stats where table_name='lineitem' order by index_name;
+delete from mysql.index_stats
+ where table_name='lineitem' and index_name= 'i_l_shipdate';
+select * from mysql.index_stats where table_name='lineitem' order by index_name;
+
+connect (con1, localhost, root,,);
+connect (con2, localhost, root,,);
+
+connection con1;
+set debug_sync='statistics_collection_start1 WAIT_FOR second_thread_started_too';
+set debug_sync='statistics_collection_start2 SIGNAL first_thread_working';
+use dbt3_s001;
+set use_stat_tables='preferably';
+--send analyze table lineitem persistent for columns() indexes (i_l_shipdate)
+
+connection con2;
+set debug_sync='statistics_collection_start1 SIGNAL second_thread_started_too';
+set debug_sync='statistics_collection_start2 WAIT_FOR first_thread_working';
+use dbt3_s001;
+set use_stat_tables='preferably';
+--send analyze table lineitem persistent for columns() indexes (i_l_receiptdate)
+
+connection con1;
+--disable_result_log
+--disable_warnings
+--reap
+--enable_warnings
+--enable_result_log
+
+connection con2;
+--disable_result_log
+--disable_warnings
+--reap
+--enable_warnings
+--enable_result_log
+
+connection default;
+disconnect con1;
+disconnect con2;
+set debug_sync='RESET';
+
+select * from mysql.index_stats where table_name='lineitem' order by index_name, prefix_arity;
+
+#
+# Test for parallel statistics collection and update (innodb)
+#
+
+select * from mysql.index_stats where table_name='lineitem'
+ order by index_name, prefix_arity;
+set debug_sync='RESET';
+
+let $innodb_storage_engine= 0;
+if (`SELECT UPPER(@@storage_engine) = 'INNODB'`)
+{
+ let $innodb_storage_engine= 1;
+}
+
+connect (con1, localhost, root,,);
+connect (con2, localhost, root,,);
+
+connection con1;
+set debug_sync='statistics_collection_start SIGNAL parked WAIT_FOR finish';
+use dbt3_s001;
+set use_stat_tables='preferably';
+--send analyze table lineitem persistent for all
+
+connection con2;
+set debug_sync='now WAIT_FOR parked';
+use dbt3_s001;
+set use_stat_tables='never';
+if ($innodb_storage_engine)
+{
+ select * from lineitem where l_orderkey=1 and l_partkey=156;
+ delete from lineitem where l_orderkey=1 and l_partkey=156;
+ select * from lineitem where l_orderkey=1 and l_partkey=156;
+}
+set debug_sync='now SIGNAL finish';
+
+connection con1;
+--disable_result_log
+--disable_warnings
+--reap
+--enable_warnings
+--enable_result_log
+
+connection default;
+disconnect con1;
+disconnect con2;
+set debug_sync='RESET';
+
+select * from mysql.index_stats where table_name='lineitem'
+ order by index_name, prefix_arity;
+
+#
+# Bug mdev-3891: deadlock for ANALYZE and SELECT over mysql.index_stats
+#
+
+set @save_global_use_stat_tables=@@global.use_stat_tables;
+set global use_stat_tables='preferably';
+set debug_sync='RESET';
+
+connect (con1, localhost, root,,);
+connect (con2, localhost, root,,);
+
+connection con1;
+set debug_sync='statistics_update_start SIGNAL parker WAIT_FOR go1 EXECUTE 1';
+set debug_sync='thr_multi_lock_after_thr_lock SIGNAL go2 EXECUTE 2';
+use dbt3_s001;
+--send analyze table lineitem persistent for all
+
+connection con2;
+set debug_sync='open_and_process_table WAIT_FOR parker';
+set debug_sync='statistics_read_start SIGNAL go1 WAIT_FOR go2';
+use dbt3_s001;
+--send select * from mysql.index_stats, lineitem where index_name= 'i_l_shipdate' and l_orderkey=1 and l_partkey=68 order by prefix_arity;
+
+connection con1;
+--disable_result_log
+--disable_warnings
+--reap
+--enable_warnings
+--enable_result_log
+
+connection con2;
+--disable_warnings
+--reap
+--enable_warnings
+
+connection default;
+disconnect con1;
+disconnect con2;
+set debug_sync='RESET';
+
+set global use_stat_tables=@save_global_use_stat_tables;
+
+DROP DATABASE dbt3_s001;
+
+use test;
+
+#
+# Bug mdev-4019: crash when executing in parallel ANALYZE and
+# SELECT * FROM information_schema.statistics
+#
+
+set @save_global_use_stat_tables=@@global.use_stat_tables;
+set global use_stat_tables='preferably';
+set debug_sync='RESET';
+
+create table t1 (a int, b int, key(a));
+insert t1 values (1,1),(2,2);
+
+analyze table t1;
+
+SET debug_sync='after_open_table_ignore_flush WAIT_FOR go';
+send select * from information_schema.statistics where table_schema='test';
+
+connect(con1, localhost, root);
+connection con1;
+select * from t1;
+SET DEBUG_SYNC= "now SIGNAL go";
+
+connection default;
+reap;
+
+connection default;
+disconnect con1;
+set debug_sync='RESET';
+
+drop table t1;
+set global use_stat_tables=@save_global_use_stat_tables;
+
+
+set use_stat_tables=@save_use_stat_tables;
diff --git a/mysql-test/t/stat_tables_par_innodb.test b/mysql-test/t/stat_tables_par_innodb.test
new file mode 100644
index 00000000000..fd5833e4aaf
--- /dev/null
+++ b/mysql-test/t/stat_tables_par_innodb.test
@@ -0,0 +1,12 @@
+--source include/have_innodb.inc
+
+SET SESSION STORAGE_ENGINE='InnoDB';
+
+set @save_optimizer_switch_for_stat_tables_test=@@optimizer_switch;
+set optimizer_switch='extended_keys=on';
+
+--source stat_tables_par.test
+
+set optimizer_switch=@save_optimizer_switch_for_stat_tables_test;
+
+SET SESSION STORAGE_ENGINE=DEFAULT;
diff --git a/mysql-test/t/stat_tables_partition.test b/mysql-test/t/stat_tables_partition.test
new file mode 100644
index 00000000000..1316e5cca11
--- /dev/null
+++ b/mysql-test/t/stat_tables_partition.test
@@ -0,0 +1,17 @@
+--source include/have_partition.inc
+
+--echo #
+--echo # Bug mdev-3866: valgrind complain from ANALYZE on a table with BIT field
+--echo #
+
+SET use_stat_tables = 'preferably';
+
+CREATE TABLE t1 (pk int PRIMARY KEY, a bit(1), INDEX idx(a)
+) ENGINE=MyISAM PARTITION BY KEY(pk) PARTITIONS 2;
+INSERT INTO t1 VALUES (1,1),(2,0),(3,0),(4,1);
+
+ANALYZE TABLE t1;
+
+SET use_stat_tables = DEFAULT;
+
+DROP TABLE t1;
diff --git a/mysql-test/t/stat_tables_rbr.test b/mysql-test/t/stat_tables_rbr.test
new file mode 100644
index 00000000000..4336c02c34b
--- /dev/null
+++ b/mysql-test/t/stat_tables_rbr.test
@@ -0,0 +1,31 @@
+--source include/have_binlog_format_row.inc
+--source include/have_innodb.inc
+--source include/have_partition.inc
+
+--echo #
+--echo # Bug mdev-463: assertion failure when running ANALYZE with RBR on
+--echo #
+
+SET GLOBAL use_stat_tables = PREFERABLY;
+
+--connect (con1,localhost,root,,)
+CREATE TABLE t1 (i INT) ENGINE=InnoDB;
+ANALYZE TABLE t1;
+
+# Cleanup
+DROP TABLE t1;
+SET GLOBAL use_stat_tables = DEFAULT;
+--disconnect con1
+
+--connection default
+
+SET use_stat_tables = PREFERABLY;
+
+CREATE TABLE t1 ( a INT ) ENGINE=MyISAM PARTITION BY HASH(a) PARTITIONS 2;
+ALTER TABLE t1 ANALYZE PARTITION p1;
+--replace_regex /\/\* xid=.* \*\//\/* XID *\// /Server ver: .*, Binlog ver: .*/Server ver: #, Binlog ver: #/ /table_id: [0-9]+/table_id: #/
+SHOW BINLOG EVENTS;
+
+SET use_stat_tables = DEFAULT;
+
+DROP TABLE t1;
diff --git a/mysql-test/t/stat_tables_repl.test b/mysql-test/t/stat_tables_repl.test
new file mode 100644
index 00000000000..ac24c9dcbd7
--- /dev/null
+++ b/mysql-test/t/stat_tables_repl.test
@@ -0,0 +1,58 @@
+--source include/have_stat_tables.inc
+--source include/have_binlog_format_row.inc
+--source include/master-slave.inc
+
+--echo #
+--echo # Bug mdev-485: unexpected failure with replication of DROP/ALTER table
+--echo # when RBR is on
+--echo #
+
+CREATE TABLE t1 ( a int, b int ) ENGINE=MyISAM;
+INSERT INTO t1 VALUES (2,20), (1,20), (3,30);
+ANALYZE TABLE t1;
+DROP TABLE t1;
+
+--sync_slave_with_master
+--connection master
+
+CREATE TABLE t1 ( a int, b int, INDEX idx1(b) ) ENGINE=MyISAM;
+INSERT INTO t1 VALUES (2,20), (1,20), (3,30);
+ANALYZE TABLE t1;
+DROP INDEX idx1 ON t1;
+
+--sync_slave_with_master
+--connection master
+
+DROP TABLE t1;
+
+CREATE TABLE t1 ( a int, b int, INDEX idx1(b) ) ENGINE=MyISAM;
+INSERT INTO t1 VALUES (2,20), (1,20), (3,30);
+ANALYZE TABLE t1;
+ALTER TABLE t1 DROP COLUMN b;
+
+--sync_slave_with_master
+--connection master
+
+DROP TABLE t1;
+
+CREATE TABLE t1 ( a int, b int, INDEX idx1(b) ) ENGINE=MyISAM;
+INSERT INTO t1 VALUES (2,20), (1,20), (3,30);
+ANALYZE TABLE t1;
+ALTER TABLE t1 RENAME to s;
+
+--sync_slave_with_master
+--connection master
+
+DROP TABLE s;
+
+CREATE TABLE t1 ( a int, b int, INDEX idx1(b) ) ENGINE=MyISAM;
+INSERT INTO t1 VALUES (2,20), (1,20), (3,30);
+ANALYZE TABLE t1;
+ALTER TABLE t1 CHANGE COLUMN b c int ;
+
+--sync_slave_with_master
+--connection master
+
+DROP TABLE t1;
+
+--source include/rpl_end.inc
diff --git a/mysql-test/t/statistics.test b/mysql-test/t/statistics.test
new file mode 100644
index 00000000000..0ab42453125
--- /dev/null
+++ b/mysql-test/t/statistics.test
@@ -0,0 +1,739 @@
+--source include/have_stat_tables.inc
+--source include/have_innodb.inc
+--disable_warnings
+drop table if exists t1,t2;
+--enable_warnings
+
+set @save_use_stat_tables=@@use_stat_tables;
+
+DELETE FROM mysql.table_stats;
+DELETE FROM mysql.column_stats;
+DELETE FROM mysql.index_stats;
+
+set use_stat_tables='preferably';
+
+CREATE TABLE t1 (
+ a int NOT NULL PRIMARY KEY,
+ b varchar(32),
+ c char(16),
+ d date,
+ e double,
+ f bit(3),
+ INDEX idx1 (b, e),
+ INDEX idx2 (c, d),
+ INDEX idx3 (d),
+ INDEX idx4 (e, b, d)
+) ENGINE= MYISAM;
+
+INSERT INTO t1 VALUES
+ (0, NULL, NULL, NULL, NULL, NULL),
+ (7, 'xxxxxxxxxxxxxxxxxxxxxxxxxx', 'dddddddd', '1990-05-15', 0.1, b'100'),
+ (17, 'vvvvvvvvvvvvv', 'aaaa', '1989-03-12', 0.01, b'101'),
+ (1, 'vvvvvvvvvvvvv', NULL, '1989-03-12', 0.01, b'100'),
+ (12, 'wwwwwwwwwwwwwwwwwwwwwwwwwwww', 'dddddddd', '1999-07-23', 0.112, b'001'),
+ (23, 'vvvvvvvvvvvvv', 'dddddddd', '1999-07-23', 0.1, b'100'),
+ (8, 'vvvvvvvvvvvvv', 'aaaa', '1999-07-23', 0.1, b'100'),
+ (22, 'xxxxxxxxxxxxxxxxxxxxxxxxxx', 'aaaa', '1989-03-12', 0.112, b'001'),
+ (31, 'wwwwwwwwwwwwwwwwwwwwwwwwwwww', 'aaaa', '1999-07-23', 0.01, b'001'),
+ (10, NULL, 'aaaa', NULL, 0.01, b'010'),
+ (5, 'wwwwwwwwwwwwwwwwwwwwwwwwwwww', 'dddddddd', '1999-07-23', 0.1, b'100'),
+ (15, 'vvvvvvvvvvvvv', 'ccccccccc', '1990-05-15', 0.1, b'010'),
+ (30, NULL, 'bbbbbb', NULL, NULL, b'100'),
+ (38, 'zzzzzzzzzzzzzzzzzz', 'bbbbbb', NULL, NULL, NULL),
+ (18, 'zzzzzzzzzzzzzzzzzz', 'ccccccccc', '1990-05-15', 0.01, b'010'),
+ (9, 'yyy', 'bbbbbb', '1998-08-28', 0.01, NULL),
+ (29, 'vvvvvvvvvvvvv', 'dddddddd', '1999-07-23', 0.012, b'010'),
+ (3, 'yyy', 'dddddddd', '1990-05-15', 0.112, b'010'),
+ (39, 'zzzzzzzzzzzzzzzzzz', 'bbbbbb', NULL, 0.01, b'100'),
+ (14, 'xxxxxxxxxxxxxxxxxxxxxxxxxx', 'ccccccccc', '1990-05-15', 0.1, b'100'),
+ (40, 'zzzzzzzzzzzzzzzzzz', 'bbbbbb', '1989-03-12', NULL, NULL),
+ (44, NULL, 'aaaa', '1989-03-12', NULL, b'010'),
+ (19, 'vvvvvvvvvvvvv', 'ccccccccc', '1990-05-15', 0.012, b'011'),
+ (21, 'zzzzzzzzzzzzzzzzzz', 'dddddddd', '1989-03-12', 0.112, b'100'),
+ (45, NULL, NULL, '1989-03-12', NULL, b'011'),
+ (2, 'wwwwwwwwwwwwwwwwwwwwwwwwwwww', 'ccccccccc', '1990-05-15', 0.1, b'001'),
+ (35, 'yyy', 'aaaa', '1990-05-15', 0.05, b'011'),
+ (4, 'vvvvvvvvvvvvv', 'dddddddd', '1999-07-23', 0.01, b'101'),
+ (47, NULL, 'aaaa', '1990-05-15', 0.05, b'010'),
+ (42, NULL, 'ccccccccc', '1989-03-12', 0.01, b'010'),
+ (32, NULL, 'bbbbbb', '1990-05-15', 0.01, b'011'),
+ (49, 'wwwwwwwwwwwwwwwwwwwwwwwwwwww' , 'aaaa', '1990-05-15', NULL, NULL),
+ (43, 'wwwwwwwwwwwwwwwwwwwwwwwwwwww' , 'bbbbbb', '1990-05-15', NULL, b'100'),
+ (37, 'yyy', NULL, '1989-03-12', 0.05, b'011'),
+ (41, 'xxxxxxxxxxxxxxxxxxxxxxxxxx', 'ccccccccc', '1990-05-15', 0.05, NULL),
+ (34, 'yyy', NULL, NULL, NULL, NULL),
+ (33, 'zzzzzzzzzzzzzzzzzz', 'dddddddd', '1989-03-12', 0.05, b'011'),
+ (24, 'wwwwwwwwwwwwwwwwwwwwwwwwwwww', 'dddddddd', '1990-05-15', 0.01, b'101'),
+ (11, 'yyy', 'ccccccccc', '1999-07-23', 0.1, NULL),
+ (25, 'zzzzzzzzzzzzzzzzzz', 'bbb', '1989-03-12', 0.01, b'101');
+
+ANALYZE TABLE t1;
+
+SELECT * FROM mysql.table_stats;
+SELECT * FROM mysql.column_stats;
+SELECT * FROM mysql.index_stats;
+
+SELECT COUNT(*) FROM t1;
+
+SELECT * FROM mysql.column_stats
+ WHERE db_name='test' AND table_name='t1' AND column_name='a';
+SELECT MIN(t1.a), MAX(t1.a),
+ (SELECT COUNT(*) FROM t1 WHERE t1.b IS NULL) /
+ (SELECT COUNT(*) FROM t1) AS "NULLS_RATIO(t1.a)",
+ (SELECT COUNT(t1.a) FROM t1) /
+ (SELECT COUNT(DISTINCT t1.a) FROM t1) AS "AVG_FREQUENCY(t1.a)"
+FROM t1;
+
+SELECT * FROM mysql.column_stats
+ WHERE db_name='test' AND table_name='t1' AND column_name='b';
+SELECT MIN(t1.b), MAX(t1.b),
+ (SELECT COUNT(*) FROM t1 WHERE t1.b IS NULL) /
+ (SELECT COUNT(*) FROM t1) AS "NULLS_RATIO(t1.b)",
+ (SELECT COUNT(t1.b) FROM t1) /
+ (SELECT COUNT(DISTINCT t1.b) FROM t1) AS "AVG_FREQUENCY(t1.b)"
+FROM t1;
+
+SELECT * FROM mysql.column_stats
+ WHERE db_name='test' AND table_name='t1' AND column_name='c';
+SELECT MIN(t1.c), MAX(t1.c),
+ (SELECT COUNT(*) FROM t1 WHERE t1.c IS NULL) /
+ (SELECT COUNT(*) FROM t1) AS "NULLS_RATIO(t1.c)",
+ (SELECT COUNT(t1.c) FROM t1) /
+ (SELECT COUNT(DISTINCT t1.c) FROM t1) AS "AVG_FREQUENCY(t1.c)"
+FROM t1;
+
+SELECT * FROM mysql.column_stats
+ WHERE db_name='test' AND table_name='t1' AND column_name='d';
+SELECT MIN(t1.d), MAX(t1.d),
+ (SELECT COUNT(*) FROM t1 WHERE t1.d IS NULL) /
+ (SELECT COUNT(*) FROM t1) AS "NULLS_RATIO(t1.d)",
+ (SELECT COUNT(t1.d) FROM t1) /
+ (SELECT COUNT(DISTINCT t1.d) FROM t1) AS "AVG_FREQUENCY(t1.d)"
+FROM t1;
+
+SELECT * FROM mysql.column_stats
+ WHERE db_name='test' AND table_name='t1' AND column_name='e';
+SELECT MIN(t1.e), MAX(t1.e),
+ (SELECT COUNT(*) FROM t1 WHERE t1.e IS NULL) /
+ (SELECT COUNT(*) FROM t1) AS "NULLS_RATIO(t1.e)",
+ (SELECT COUNT(t1.e) FROM t1) /
+ (SELECT COUNT(DISTINCT t1.e) FROM t1) AS "AVG_FREQUENCY(t1.e)"
+FROM t1;
+
+SELECT * FROM mysql.index_stats
+ WHERE db_name='test' AND table_name='t1' AND index_name='idx1';
+SELECT
+ (SELECT COUNT(*) FROM t1 WHERE t1.b IS NOT NULL) /
+ (SELECT COUNT(DISTINCT t1.b) FROM t1 WHERE t1.b IS NOT NULL)
+ AS 'ARITY 1',
+ (SELECT COUNT(*) FROM t1 WHERE t1.b IS NOT NULL AND t1.e IS NOT NULL) /
+ (SELECT COUNT(DISTINCT t1.b, t1.e) FROM t1
+ WHERE t1.b IS NOT NULL AND t1.e IS NOT NULL)
+ AS 'ARITY 2';
+
+SELECT * FROM mysql.index_stats
+ WHERE db_name='test' AND table_name='t1' AND index_name='idx2';
+SELECT
+ (SELECT COUNT(*) FROM t1 WHERE t1.c IS NOT NULL) /
+ (SELECT COUNT(DISTINCT t1.c) FROM t1 WHERE t1.c IS NOT NULL)
+ AS 'ARITY 1',
+ (SELECT COUNT(*) FROM t1 WHERE t1.c IS NOT NULL AND t1.d IS NOT NULL) /
+ (SELECT COUNT(DISTINCT t1.c, t1.d) FROM t1
+ WHERE t1.c IS NOT NULL AND t1.d IS NOT NULL)
+ AS 'ARITY 2';
+
+SELECT * FROM mysql.index_stats
+ WHERE db_name='test' AND table_name='t1' AND index_name='idx3';
+SELECT
+ (SELECT COUNT(*) FROM t1 WHERE t1.d IS NOT NULL) /
+ (SELECT COUNT(DISTINCT t1.d) FROM t1 WHERE t1.d IS NOT NULL)
+ AS 'ARITY 1';
+
+SELECT * FROM mysql.index_stats
+ WHERE db_name='test' AND table_name='t1' AND index_name='idx4';
+SELECT
+ (SELECT COUNT(*) FROM t1 WHERE t1.e IS NOT NULL) /
+ (SELECT COUNT(DISTINCT t1.e) FROM t1 WHERE t1.e IS NOT NULL)
+ AS 'ARITY 1',
+ (SELECT COUNT(*) FROM t1 WHERE t1.e IS NOT NULL AND t1.b IS NOT NULL) /
+ (SELECT COUNT(DISTINCT t1.e, t1.b) FROM t1
+ WHERE t1.e IS NOT NULL AND t1.b IS NOT NULL)
+ AS 'ARITY 2',
+ (SELECT COUNT(*) FROM t1
+ WHERE t1.e IS NOT NULL AND t1.b IS NOT NULL AND t1.d IS NOT NULL) /
+ (SELECT COUNT(DISTINCT t1.e, t1.b, t1.d) FROM t1
+ WHERE t1.e IS NOT NULL AND t1.b IS NOT NULL AND t1.d IS NOT NULL)
+ AS 'ARITY 3';
+
+
+DELETE FROM mysql.column_stats;
+
+set histogram_size=4;
+ANALYZE TABLE t1;
+
+SELECT db_name, table_name, column_name,
+ min_value, max_value,
+ nulls_ratio, avg_frequency,
+ hist_size, hist_type, HEX(histogram)
+ FROM mysql.column_stats;
+
+DELETE FROM mysql.column_stats;
+
+set histogram_size=8;
+set histogram_type='DOUBLE_PREC_HB';
+ANALYZE TABLE t1;
+
+SELECT db_name, table_name, column_name,
+ min_value, max_value,
+ nulls_ratio, avg_frequency,
+ hist_size, hist_type, HEX(histogram)
+ FROM mysql.column_stats;
+
+DELETE FROM mysql.column_stats;
+
+set histogram_size= 0;
+set histogram_type=default;
+ANALYZE TABLE t1;
+
+
+CREATE TABLE t3 (
+ a int NOT NULL PRIMARY KEY,
+ b varchar(32),
+ c char(16),
+ INDEX idx (c)
+) ENGINE=MYISAM;
+
+INSERT INTO t3 VALUES
+ (0, NULL, NULL),
+ (7, 'xxxxxxxxxxxxxxxxxxxxxxxxxx', 'dddddddd'),
+ (17, 'vvvvvvvvvvvvv', 'aaaa'),
+ (1, 'vvvvvvvvvvvvv', NULL),
+ (12, 'wwwwwwwwwwwwwwwwwwwwwwwwwwww', 'dddddddd'),
+ (23, 'vvvvvvvvvvvvv', 'dddddddd'),
+ (8, 'vvvvvvvvvvvvv', 'aaaa'),
+ (22, 'xxxxxxxxxxxxxxxxxxxxxxxxxx', 'aaaa'),
+ (31, 'wwwwwwwwwwwwwwwwwwwwwwwwwwww', 'aaaa'),
+ (10, NULL, 'aaaa'),
+ (5, 'wwwwwwwwwwwwwwwwwwwwwwwwwwww', 'dddddddd'),
+ (15, 'vvvvvvvvvvvvv', 'ccccccccc'),
+ (30, NULL, 'bbbbbb'),
+ (38, 'zzzzzzzzzzzzzzzzzz', 'bbbbbb'),
+ (18, 'zzzzzzzzzzzzzzzzzz', 'ccccccccc'),
+ (9, 'yyy', 'bbbbbb'),
+ (29, 'vvvvvvvvvvvvv', 'dddddddd');
+
+ANALYZE TABLE t3;
+
+SELECT * FROM mysql.table_stats;
+SELECT * FROM mysql.column_stats;
+SELECT * FROM mysql.index_stats;
+
+ALTER TABLE t1 RENAME TO s1;
+SELECT * FROM mysql.table_stats;
+SELECT * FROM mysql.column_stats;
+SELECT * FROM mysql.index_stats;
+
+RENAME TABLE s1 TO t1;
+SELECT * FROM mysql.table_stats;
+SELECT * FROM mysql.column_stats;
+SELECT * FROM mysql.index_stats;
+
+DROP TABLE t3;
+SELECT * FROM mysql.table_stats;
+SELECT * FROM mysql.column_stats;
+SELECT * FROM mysql.index_stats;
+
+
+CREATE TEMPORARY TABLE t0 (
+ a int NOT NULL PRIMARY KEY,
+ b varchar(32)
+);
+INSERT INTO t0 SELECT a,b FROM t1;
+
+ALTER TABLE t1 CHANGE COLUMN b x varchar(32),
+ CHANGE COLUMN e y double;
+SHOW CREATE TABLE t1;
+SELECT * FROM mysql.column_stats;
+
+ALTER TABLE t1 CHANGE COLUMN x b varchar(32),
+ CHANGE COLUMN y e double;
+SHOW CREATE TABLE t1;
+SELECT * FROM mysql.column_stats;
+
+ALTER TABLE t1 RENAME TO s1, CHANGE COLUMN b x varchar(32);
+SHOW CREATE TABLE s1;
+SELECT * FROM mysql.table_stats;
+SELECT * FROM mysql.column_stats;
+SELECT * FROM mysql.index_stats;
+
+ALTER TABLE s1 RENAME TO t1, CHANGE COLUMN x b varchar(32);
+SHOW CREATE TABLE t1;
+SELECT * FROM mysql.table_stats;
+SELECT * FROM mysql.column_stats;
+SELECT * FROM mysql.index_stats;
+
+ALTER TABLE t1 CHANGE COLUMN b x varchar(30);
+SHOW CREATE TABLE t1;
+SELECT * FROM mysql.column_stats;
+SELECT * FROM mysql.index_stats;
+
+ALTER TABLE t1 CHANGE COLUMN x b varchar(32);
+SHOW CREATE TABLE t1;
+SELECT * FROM mysql.column_stats;
+SELECT * FROM mysql.index_stats;
+
+ANALYZE TABLE t1 PERSISTENT FOR COLUMNS(b) INDEXES(idx1, idx4);
+SELECT * FROM mysql.column_stats;
+SELECT * FROM mysql.index_stats;
+
+--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
+eval
+SELECT * INTO OUTFILE '$MYSQLTEST_VARDIR/tmp/save_column_stats'
+ FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"' LINES TERMINATED BY '\n'
+ FROM mysql.column_stats WHERE column_name='b';
+--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
+eval
+SELECT * INTO OUTFILE '$MYSQLTEST_VARDIR/tmp/save_index_stats'
+ FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"' LINES TERMINATED BY '\n'
+ FROM mysql.index_stats WHERE index_name IN ('idx1', 'idx4');
+
+ALTER TABLE t1 CHANGE COLUMN b x varchar(30);
+SHOW CREATE TABLE t1;
+SELECT * FROM mysql.column_stats;
+SELECT * FROM mysql.index_stats;
+
+ALTER TABLE t1 CHANGE COLUMN x b varchar(32);
+SHOW CREATE TABLE t1;
+SELECT * FROM mysql.column_stats;
+SELECT * FROM mysql.index_stats;
+
+--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
+eval
+LOAD DATA INFILE '$MYSQLTEST_VARDIR/tmp/save_column_stats'
+ INTO TABLE mysql.column_stats
+ FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"' LINES TERMINATED BY '\n';
+--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
+eval
+LOAD DATA INFILE '$MYSQLTEST_VARDIR/tmp/save_index_stats'
+ INTO TABLE mysql.index_stats
+ FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"' LINES TERMINATED BY '\n';
+SELECT * FROM mysql.column_stats;
+SELECT * FROM mysql.index_stats;
+remove_file $MYSQLTEST_VARDIR/tmp/save_column_stats;
+remove_file $MYSQLTEST_VARDIR/tmp/save_index_stats;
+
+
+ALTER TABLE t1 DROP COLUMN b;
+SHOW CREATE TABLE t1;
+SELECT * FROM mysql.column_stats;
+SELECT * FROM mysql.index_stats;
+
+DROP INDEX idx2 ON t1;
+SHOW CREATE TABLE t1;
+SELECT * FROM mysql.index_stats;
+
+DROP INDEX idx1 ON t1;
+DROP INDEX idx4 ON t1;
+SHOW CREATE TABLE t1;
+
+ALTER TABLE t1 ADD COLUMN b varchar(32);
+CREATE INDEX idx1 ON t1(b, e);
+CREATE INDEX idx2 ON t1(c, d);
+CREATE INDEX idx4 ON t1(e, b, d);
+SHOW CREATE TABLE t1;
+SELECT * FROM mysql.column_stats;
+SELECT * FROM mysql.index_stats;
+
+ANALYZE TABLE t1 PERSISTENT FOR COLUMNS(b) INDEXES(idx1, idx2, idx4);
+SELECT * FROM mysql.column_stats;
+SELECT * FROM mysql.index_stats;
+
+UPDATE t1 SET b=(SELECT b FROM t0 WHERE t0.a= t1.a);
+ANALYZE TABLE t1 PERSISTENT FOR COLUMNS(b) INDEXES(idx1, idx2, idx4);
+SELECT * FROM mysql.column_stats;
+SELECT * FROM mysql.index_stats;
+
+ALTER TABLE t1 DROP COLUMN b,
+ DROP INDEX idx1, DROP INDEX idx2, DROP INDEX idx4;
+SHOW CREATE TABLE t1;
+SELECT * FROM mysql.column_stats;
+SELECT * FROM mysql.index_stats;
+
+ALTER TABLE t1 ADD COLUMN b varchar(32);
+ALTER TABLE t1
+ ADD INDEX idx1 (b, e), ADD INDEX idx2 (c, d), ADD INDEX idx4 (e, b, d);
+UPDATE t1 SET b=(SELECT b FROM t0 WHERE t0.a= t1.a);
+SHOW CREATE TABLE t1;
+SELECT * FROM mysql.column_stats;
+SELECT * FROM mysql.index_stats;
+ANALYZE TABLE t1 PERSISTENT FOR COLUMNS(b) INDEXES(idx1, idx2, idx4);
+SELECT * FROM mysql.column_stats;
+SELECT * FROM mysql.index_stats;
+
+DELETE FROM mysql.table_stats;
+DELETE FROM mysql.column_stats;
+DELETE FROM mysql.index_stats;
+
+ANALYZE TABLE t1 PERSISTENT FOR COLUMNS() INDEXES();
+SELECT * FROM mysql.table_stats;
+SELECT * FROM mysql.column_stats;
+SELECT * FROM mysql.index_stats;
+
+ANALYZE TABLE t1 PERSISTENT FOR COLUMNS(c,e,b) INDEXES(idx2,idx4);
+SELECT * FROM mysql.table_stats;
+SELECT * FROM mysql.column_stats;
+SELECT * FROM mysql.index_stats;
+
+DELETE FROM mysql.index_stats WHERE table_name='t1' AND index_name='primary';
+SELECT * FROM mysql.index_stats;
+ANALYZE TABLE t1 PERSISTENT FOR COLUMNS() INDEXES(primary);
+SELECT * FROM mysql.index_stats;
+
+DELETE FROM mysql.table_stats;
+DELETE FROM mysql.column_stats;
+DELETE FROM mysql.index_stats;
+
+ANALYZE TABLE t1 PERSISTENT FOR COLUMNS ALL INDEXES ALL;
+
+SELECT * FROM mysql.table_stats;
+SELECT * FROM mysql.column_stats;
+SELECT * FROM mysql.index_stats;
+
+CREATE TABLE t2 LIKE t1;
+ALTER TABLE t2 ENGINE=InnoDB;
+INSERT INTO t2 SELECT * FROM t1;
+
+set optimizer_switch='extended_keys=off';
+
+ANALYZE TABLE t2;
+
+SELECT * FROM mysql.table_stats;
+SELECT * FROM mysql.column_stats ORDER BY column_name;
+SELECT * FROM mysql.index_stats ORDER BY index_name, prefix_arity, table_name;
+
+DELETE FROM mysql.table_stats;
+DELETE FROM mysql.column_stats;
+DELETE FROM mysql.index_stats;
+
+set optimizer_switch='extended_keys=on';
+
+ANALYZE TABLE t2;
+
+SELECT * FROM mysql.table_stats;
+SELECT * FROM mysql.column_stats ORDER BY column_name;
+SELECT * FROM mysql.index_stats ORDER BY index_name, prefix_arity, table_name;
+
+ALTER TABLE t2 DROP PRIMARY KEY, DROP INDEX idx1;
+SELECT * FROM mysql.index_stats ORDER BY index_name, prefix_arity, table_name;
+
+UPDATE t2 SET b=0 WHERE b IS NULL;
+ALTER TABLE t2 ADD PRIMARY KEY (a,b);
+SELECT * FROM mysql.index_stats ORDER BY index_name, prefix_arity, table_name;
+
+ANALYZE TABLE t2 PERSISTENT FOR COLUMNS() INDEXES ALL;
+SELECT * FROM mysql.index_stats ORDER BY index_name, prefix_arity, table_name;
+
+ALTER TABLE t2 CHANGE COLUMN b b varchar(30);
+SELECT * FROM mysql.index_stats ORDER BY index_name, prefix_arity, table_name;
+
+ANALYZE TABLE t2 PERSISTENT FOR COLUMNS ALL INDEXES ALL;
+SELECT * FROM mysql.index_stats ORDER BY index_name, prefix_arity, table_name;
+
+ALTER TABLE t2 CHANGE COLUMN b b varchar(32);
+SELECT * FROM mysql.index_stats ORDER BY index_name, prefix_arity, table_name;
+
+ANALYZE TABLE t2 PERSISTENT FOR COLUMNS ALL INDEXES ALL;
+SELECT * FROM mysql.index_stats ORDER BY index_name, prefix_arity, table_name;
+
+ALTER TABLE t2 DROP COLUMN b;
+SELECT * FROM mysql.index_stats ORDER BY index_name, prefix_arity, table_name;
+
+ANALYZE TABLE t2 PERSISTENT FOR COLUMNS() INDEXES ALL;
+SELECT * FROM mysql.index_stats ORDER BY index_name, prefix_arity, table_name;
+
+set optimizer_switch='extended_keys=off';
+
+ALTER TABLE t1
+ DROP INDEX idx1,
+ DROP INDEX idx4;
+ALTER TABLE t1
+ MODIFY COLUMN b text,
+ ADD INDEX idx1 (b(4), e),
+ ADD INDEX idx4 (e, b(4), d);
+
+SELECT * FROM mysql.column_stats;
+SELECT * FROM mysql.index_stats;
+
+ANALYZE TABLE t1;
+
+SELECT * FROM mysql.column_stats;
+SELECT * FROM mysql.index_stats;
+
+DELETE FROM mysql.table_stats;
+DELETE FROM mysql.column_stats;
+DELETE FROM mysql.index_stats;
+
+ANALYZE TABLE mysql.column_stats PERSISTENT FOR ALL;
+
+ANALYZE TABLE mysql.column_stats;
+
+SELECT * FROM mysql.table_stats;
+SELECT * FROM mysql.column_stats;
+SELECT * FROM mysql.index_stats;
+
+set use_stat_tables='never';
+
+ANALYZE TABLE t1 PERSISTENT FOR ALL;
+
+SELECT * FROM mysql.table_stats;
+SELECT * FROM mysql.column_stats;
+SELECT * FROM mysql.index_stats;
+
+
+DELETE FROM mysql.table_stats;
+DELETE FROM mysql.column_stats;
+DELETE FROM mysql.index_stats;
+
+DROP TABLE t1,t2;
+
+set names utf8;
+
+CREATE DATABASE world;
+
+use world;
+
+--source include/world_schema_utf8.inc
+
+--disable_query_log
+--disable_result_log
+--disable_warnings
+--source include/world.inc
+--enable_warnings
+--enable_result_log
+--enable_query_log
+
+set use_stat_tables='preferably';
+
+--disable_result_log
+ANALYZE TABLE Country, City, CountryLanguage;
+--enable_result_log
+
+SELECT UPPER(db_name), UPPER(table_name), cardinality
+ FROM mysql.table_stats;
+SELECT UPPER(db_name), UPPER(table_name),
+ column_name, min_value, max_value, nulls_ratio, avg_length, avg_frequency
+ FROM mysql.column_stats;
+SELECT UPPER(db_name), UPPER(table_name),
+ index_name, prefix_arity, avg_frequency
+ FROM mysql.index_stats;
+
+use test;
+
+set use_stat_tables='never';
+
+CREATE DATABASE world_innodb;
+
+use world_innodb;
+
+--source include/world_schema_utf8.inc
+
+ALTER TABLE Country ENGINE=InnoDB;
+ALTER TABLE City ENGINE=InnoDB;
+ALTER TABLE CountryLanguage ENGINE=InnoDB;
+
+--disable_query_log
+--disable_result_log
+--disable_warnings
+--source include/world.inc
+--enable_warnings
+--enable_result_log
+--enable_query_log
+
+set use_stat_tables='preferably';
+
+--disable_result_log
+ANALYZE TABLE Country, City, CountryLanguage;
+--enable_result_log
+
+SELECT UPPER(db_name), UPPER(table_name), cardinality
+ FROM mysql.table_stats;
+SELECT UPPER(db_name), UPPER(table_name),
+ column_name, min_value, max_value, nulls_ratio, avg_length, avg_frequency
+ FROM mysql.column_stats;
+SELECT UPPER(db_name), UPPER(table_name),
+ index_name, prefix_arity, avg_frequency
+ FROM mysql.index_stats;
+
+use world;
+set use_stat_tables='preferably';
+--disable_result_log
+set histogram_size=100;
+set histogram_type='SINGLE_PREC_HB';
+ANALYZE TABLE CountryLanguage;
+set histogram_size=254;
+set histogram_type='DOUBLE_PREC_HB';
+ANALYZE TABLE City;
+FLUSH TABLES;
+--enable_result_log
+
+--query_vertical select UPPER(db_name),UPPER(table_name),UPPER(column_name),min_value,max_value,nulls_ratio,avg_length,avg_frequency,hist_size,hist_type,hex(histogram),decode_histogram(hist_type,histogram) from mysql.column_stats where UPPER(db_name)='WORLD' and UPPER(table_name)='COUNTRYLANGUAGE' and UPPER(column_name) = 'PERCENTAGE';
+--query_vertical select UPPER(db_name),UPPER(table_name),UPPER(column_name),min_value,max_value,nulls_ratio,avg_length,avg_frequency,hist_size,hist_type,hex(histogram),decode_histogram(hist_type,histogram) from mysql.column_stats where UPPER(db_name)='WORLD' and UPPER(table_name)='CITY' and UPPER(column_name) = 'POPULATION';
+
+set histogram_type=default;
+set histogram_size=default;
+
+use test;
+DROP DATABASE world;
+
+SELECT UPPER(db_name), UPPER(table_name), cardinality
+ FROM mysql.table_stats;
+SELECT UPPER(db_name), UPPER(table_name),
+ column_name, min_value, max_value, nulls_ratio, avg_length, avg_frequency
+ FROM mysql.column_stats;
+SELECT UPPER(db_name), UPPER(table_name),
+ index_name, prefix_arity, avg_frequency
+ FROM mysql.index_stats;
+
+DROP DATABASE world_innodb;
+SELECT UPPER(db_name), UPPER(table_name), cardinality
+ FROM mysql.table_stats;
+SELECT UPPER(db_name), UPPER(table_name),
+ column_name, min_value, max_value, nulls_ratio, avg_length, avg_frequency
+ FROM mysql.column_stats;
+SELECT UPPER(db_name), UPPER(table_name),
+ index_name, prefix_arity, avg_frequency
+ FROM mysql.index_stats;
+
+DELETE FROM mysql.table_stats;
+DELETE FROM mysql.column_stats;
+DELETE FROM mysql.index_stats;
+
+--echo #
+--echo # Bug mdev-4357: empty string as a value of the HIST_SIZE column
+--echo # from mysql.column_stats
+--echo #
+
+create table t1 (a int);
+insert into t1 values (1),(2),(3);
+
+set histogram_size=10;
+
+analyze table t1 persistent for all;
+
+select db_name, table_name, column_name,
+ min_value, max_value,
+ nulls_ratio, avg_frequency,
+ hist_size, hist_type, HEX(histogram)
+ FROM mysql.column_stats;
+
+set histogram_size=default;
+
+drop table t1;
+
+--echo #
+--echo # Bug mdev-4359: wrong setting of the HIST_SIZE column
+--echo # (see also mdev-4357) from mysql.column_stats
+--echo #
+
+create table t1 ( a int);
+insert into t1 values (1),(2),(3),(4),(5);
+
+set histogram_size=10;
+set histogram_type='double_prec_hb';
+
+show variables like 'histogram%';
+
+analyze table t1 persistent for all;
+
+select db_name, table_name, column_name,
+ min_value, max_value,
+ nulls_ratio, avg_frequency,
+ hist_size, hist_type, HEX(histogram)
+ FROM mysql.column_stats;
+
+set histogram_size=default;
+set histogram_type=default;
+
+drop table t1;
+
+--echo #
+--echo # Bug mdev-4369: histogram for a column with many distinct values
+--echo #
+
+
+CREATE TABLE t1 (id int);
+CREATE TABLE t2 (id int);
+
+INSERT INTO t1 (id) VALUES (1), (1), (1),(1);
+INSERT INTO t1 (id) SELECT id FROM t1;
+INSERT INTO t1 SELECT id+1 FROM t1;
+INSERT INTO t1 SELECT id+2 FROM t1;
+INSERT INTO t1 SELECT id+4 FROM t1;
+INSERT INTO t1 SELECT id+8 FROM t1;
+INSERT INTO t1 SELECT id+16 FROM t1;
+INSERT INTO t1 SELECT id+32 FROM t1;
+INSERT INTO t1 SELECT id+64 FROM t1;
+INSERT INTO t1 SELECT id+128 FROM t1;
+INSERT INTO t1 SELECT id+256 FROM t1;
+INSERT INTO t1 SELECT id+512 FROM t1;
+
+INSERT INTO t2 SELECT id FROM t1 ORDER BY id*rand();
+
+SELECT COUNT(*) FROM t2;
+SELECT COUNT(DISTINCT id) FROM t2;
+
+set @@tmp_table_size=1024*16;
+set @@max_heap_table_size=1024*16;
+
+set histogram_size=63;
+
+analyze table t2 persistent for all;
+
+select db_name, table_name, column_name,
+ min_value, max_value,
+ nulls_ratio, avg_frequency,
+ hist_size, hist_type, HEX(histogram)
+ FROM mysql.column_stats;
+
+set histogram_size=default;
+
+drop table t1, t2;
+
+set use_stat_tables=@save_use_stat_tables;
+
+--echo #
+--echo # Bug MDEV-7383: min/max value for a column not utf8 compatible
+--echo #
+
+create table t1 (a varchar(100)) engine=MyISAM;
+insert into t1 values(unhex('D879626AF872675F73E662F8'));
+analyze table t1 persistent for all;
+show warnings;
+
+select db_name, table_name, column_name,
+ HEX(min_value), HEX(max_value),
+ nulls_ratio, avg_frequency,
+ hist_size, hist_type, HEX(histogram)
+ FROM mysql.column_stats;
+
+drop table t1;
+
+--echo #
+--echo # MDEB-9744: session optimizer_use_condition_selectivity=5 causing SQL Error (1918):
+--echo # Encountered illegal value '' when converting to DECIMAL
+--echo #
+
+set @save_optimizer_use_condition_selectivity= @@optimizer_use_condition_selectivity;
+set optimizer_use_condition_selectivity=3, use_stat_tables=preferably;
+
+create table t1 (id int(10),cost decimal(9,2)) engine=innodb;
+ANALYZE TABLE t1 PERSISTENT FOR ALL;
+
+create temporary table t2 (id int);
+insert into t2 (id) select id from t1 where cost > 0;
+select * from t2;
+
+set use_stat_tables=@save_use_stat_tables;
+set optimizer_use_condition_selectivity= @save_optimizer_use_condition_selectivity;
+drop table t1,t2;
+
diff --git a/mysql-test/t/statistics_index_crash-7362.test b/mysql-test/t/statistics_index_crash-7362.test
new file mode 100644
index 00000000000..3873b896dae
--- /dev/null
+++ b/mysql-test/t/statistics_index_crash-7362.test
@@ -0,0 +1,30 @@
+# Test cases that cover the crashes within:
+# MDEV-7362 ANALYZE TABLES crash with table-independent-statistics gathering
+# MDEV-7380 engine-independent stats SEGV on ANALYZE TABLE (#2)
+
+--source include/have_stat_tables.inc
+--source include/have_innodb.inc
+
+CREATE TABLE t1 (a longtext, FULLTEXT KEY (`a`)) ENGINE=InnoDB;
+INSERT INTO t1 VALUES (unhex('3E0D0A4141414142334E7A6143317963324541414141424977414141674541726D'));
+ANALYZE TABLE t1 PERSISTENT FOR ALL;
+--sorted_result
+SELECT * FROM mysql.index_stats WHERE index_name='a' AND table_name='t1';
+DROP TABLE t1;
+
+CREATE TABLE t1 (a longtext, FULLTEXT KEY (`a`)) ENGINE=MyISAM;
+INSERT INTO t1 VALUES (unhex('3E0D0A4141414142334E7A6143317963324541414141424977414141674541726D'));
+ANALYZE TABLE t1 PERSISTENT FOR ALL;
+--sorted_result
+SELECT * FROM mysql.index_stats WHERE index_name='a' AND table_name='t1';
+DROP TABLE t1;
+
+CREATE TABLE geom (g GEOMETRY NOT NULL, SPATIAL INDEX(g)) ENGINE=MyISAM;
+INSERT INTO geom VALUES
+ (MultiPolygonFromText('MULTIPOLYGON(((28 26,28 0,84 0,84 42,28 26),(52 18,66 23,73 9,48 6,52 18)),((59 18,67 18,67 13,59 13,59 18)))')),
+ (MPolyFromText('MULTIPOLYGON(((28 26,28 0,84 0,84 42,28 26),(52 18,66 23,73 9,48 6,52 18)),((59 18,67 18,67 13,59 13,59 18)))')),
+ (MPolyFromWKB(AsWKB(MultiPolygon(Polygon(LineString(Point(0, 3), Point(3, 3), Point(3, 0), Point(0, 3)))))));
+ANALYZE TABLE geom PERSISTENT FOR ALL;
+--sorted_result
+SELECT * FROM mysql.index_stats WHERE index_name='g' AND table_name='geom';
+DROP TABLE geom;
diff --git a/mysql-test/t/str_to_datetime_457.test b/mysql-test/t/str_to_datetime_457.test
new file mode 100644
index 00000000000..dd25f98ebdd
--- /dev/null
+++ b/mysql-test/t/str_to_datetime_457.test
@@ -0,0 +1,26 @@
+#
+# MDEV-457 Inconsistent data truncation on datetime values with fractional seconds represented as strings with no delimiters
+# (and other problems with str_to_datetime)
+#
+
+# first was ok, second was not
+select cast('01:02:03 ' as time), cast('01:02:03 ' as time);
+# first two were ok, third was not
+select cast('2002-011-012' as date), cast('2002.11.12' as date), cast('2002.011.012' as date);
+# only two microsecond digits were ok, third was truncated with a warning
+select cast('2012103123595912' as datetime(6)), cast('20121031235959123' as datetime(6));
+# zero string date was considered 'out of range'. Must be either ok or invalid format
+select cast(0 as date), cast('0000-00-00' as date), cast('0' as date);
+# first was ok, second was not
+select extract(hour from '100000:02:03'), extract(hour from '100000:02:03 ');
+
+--echo #
+--echo # backward compatibility craziness
+--echo #
+select cast('12:00:00.12.34.56' as time); # was 12:00:00
+select cast('12:00:00 12.34.56' as time); # was 12:34:56
+select cast('12:00:00-12.34.56' as time); # was 12:00:00
+select cast('12:00:00.12.34.56' as datetime);
+select cast('12:00:00-12.34.56' as datetime);
+select cast('12:00:00 12.34.56' as datetime);
+select cast('12:00:00.123456' as time);
diff --git a/mysql-test/t/strict.test b/mysql-test/t/strict.test
index c429e9cfe5b..71b625e0843 100644
--- a/mysql-test/t/strict.test
+++ b/mysql-test/t/strict.test
@@ -1350,3 +1350,23 @@ select count(*) from t1 where a is null;
drop table t1;
--echo End of 5.0 tests
+
+--echo #
+--echo # Start of 5.6 tests
+--echo #
+
+--echo #
+--echo # WL#946 TIME/TIMESTAMP/DATETIME with fractional seconds: CAST to DATETIME
+--echo #
+
+--echo #
+--echo # STR_TO_DATE with NO_ZERO_DATE did not return NULL (with warning)
+--echo # in get_date(). Only did in val_str() and val_int().
+SET sql_mode='NO_ZERO_DATE';
+SELECT STR_TO_DATE('2001','%Y'),CONCAT(STR_TO_DATE('2001','%Y')), STR_TO_DATE('2001','%Y')+1, STR_TO_DATE('0','%Y')+1, STR_TO_DATE('0000','%Y')+1;
+SET sql_mode='NO_ZERO_IN_DATE';
+SELECT STR_TO_DATE('2001','%Y'),CONCAT(STR_TO_DATE('2001','%Y')), STR_TO_DATE('2001','%Y')+1, STR_TO_DATE('0000','%Y')+1;
+
+--echo #
+--echo # End of 5.6 tests
+--echo #
diff --git a/mysql-test/t/subselect.test b/mysql-test/t/subselect.test
index e6233e9de78..8c9a4893be2 100644
--- a/mysql-test/t/subselect.test
+++ b/mysql-test/t/subselect.test
@@ -5965,6 +5965,7 @@ EXECUTE stmt;
deallocate prepare stmt;
drop table t1,t2,t3,t4;
+--echo #
--echo # MDEV-7122
--echo # Assertion `0' failed in subselect_hash_sj_engine::init
--echo #
@@ -5975,7 +5976,6 @@ SELECT * FROM t1 WHERE a IN(SELECT MIN(a) FROM t1);
DROP TABLE t1;
SET SESSION big_tables=0;
-
--echo #
--echo # MDEV-10776: Server crash on query
--echo #
@@ -5990,6 +5990,35 @@ group by round((select 1 from t1 limit 1));
drop table t1;
--echo #
+--echo # MDEV-7930: Assertion `table_share->tmp_table != NO_TMP_TABLE ||
+--echo # m_lock_type != 2' failed in handler::ha_index_read_map
+--echo #
+
+CREATE TABLE t1 (f1 INT);
+INSERT INTO t1 VALUES (1),(2);
+
+CREATE TABLE t2 (f2 INT, KEY(f2));
+INSERT INTO t2 VALUES (3);
+
+CREATE ALGORITHM=MERGE VIEW v2 AS SELECT * FROM t2;
+
+--error ER_WRONG_GROUP_FIELD
+SELECT ( SELECT MIN(t2.f2) FROM t1 ) AS sq FROM t2 GROUP BY sq;
+--error ER_WRONG_GROUP_FIELD
+SELECT ( SELECT MIN(v2.f2) FROM t1 ) AS sq FROM v2 GROUP BY sq;
+SELECT * FROM v2 where ( SELECT MIN(v2.f2) FROM t1 ) > 0;
+SELECT count(*) FROM v2 group by ( SELECT MIN(v2.f2) FROM t1 );
+
+delete from t1;
+--error ER_WRONG_GROUP_FIELD
+SELECT ( SELECT MIN(t2.f2) FROM t1 ) AS sq FROM t2 GROUP BY sq;
+--error ER_WRONG_GROUP_FIELD
+SELECT ( SELECT MIN(v2.f2) FROM t1 ) AS sq FROM v2 GROUP BY sq;
+
+drop view v2;
+drop table t1,t2;
+
+--echo #
--echo # MDEV-10386 Assertion `fixed == 1' failed in virtual String* Item_func_conv_charset::val_str(String*)
--echo #
@@ -6030,8 +6059,15 @@ drop table t1,t2;
CREATE TABLE t1 (f1 INT, KEY(f1)) ENGINE=MyISAM;
INSERT t1 VALUES (4),(8);
CREATE TABLE t2 (f2 INT, KEY(f2)) ENGINE=MyISAM;
-INSERT t2 VALUES (6),(9);
+INSERT t2 VALUES (6);
SELECT (SELECT MAX(sq.f2) FROM t1) FROM (SELECT * FROM t2) AS sq WHERE f2 = 2;
+--echo #
+--echo # Disable this query till MDEV-13399 is resolved
+--echo #
+--echo # INSERT t2 VALUES (9);
+--echo # --error ER_SUBQUERY_NO_1_ROW
+--echo # SELECT (SELECT MAX(sq.f2) FROM t1) FROM (SELECT * FROM t2) AS sq WHERE f2 = 2;
+--echo #
drop table t1, t2;
--echo #
diff --git a/mysql-test/t/subselect4.test b/mysql-test/t/subselect4.test
index 2b53b55b735..2520159b165 100644
--- a/mysql-test/t/subselect4.test
+++ b/mysql-test/t/subselect4.test
@@ -298,18 +298,15 @@ CREATE TABLE `t1` (
) AUTO_INCREMENT=12 DEFAULT CHARSET=latin1;
INSERT INTO `t1` VALUES (10,'00:00:00','i','i'),(11,'00:00:00','','');
-set @old_optimizer_switch = @@session.optimizer_switch,
- @old_engine_condition_pushdown = @@session.engine_condition_pushdown;
+set @old_optimizer_switch = @@session.optimizer_switch;
-SET SESSION OPTIMIZER_SWITCH = 'materialization=off,semijoin=off,loosescan=off,firstmatch=off,mrr=on';
-SET SESSION engine_condition_pushdown = 1;
+SET SESSION OPTIMIZER_SWITCH = 'materialization=off,semijoin=off,loosescan=off,firstmatch=off,mrr=on,engine_condition_pushdown=on';
SELECT `time_nokey` G1 FROM t1 WHERE ( `varchar_nokey` , `varchar_key` ) IN (
SELECT `varchar_nokey` , `varchar_nokey` ) AND `varchar_key` >= 'c' HAVING G1 ORDER
BY `pk` ;
-set @@session.optimizer_switch = @old_optimizer_switch,
- @@session.engine_condition_pushdown = @old_engine_condition_pushdown;
+set @@session.optimizer_switch = @old_optimizer_switch;
DROP TABLE t1;
@@ -476,8 +473,8 @@ INSERT INTO t2 VALUES (9,1);
--echo # Enable Index condition pushdown
--replace_column 1 #
-SELECT @old_icp:=@@engine_condition_pushdown;
-SET SESSION engine_condition_pushdown = 'ON';
+set @old_icp=@@optimizer_switch;
+SET SESSION optimizer_switch="engine_condition_pushdown=on";
--echo
SELECT pk
@@ -490,7 +487,7 @@ WHERE
ORDER BY t1.i2 desc);
--echo # Restore old value for Index condition pushdown
-SET SESSION engine_condition_pushdown=@old_icp;
+SET SESSION optimizer_switch=@old_icp;
DROP TABLE t1,t2;
diff --git a/mysql-test/t/subselect_cache.test b/mysql-test/t/subselect_cache.test
index 6a104144302..1276e546030 100644
--- a/mysql-test/t/subselect_cache.test
+++ b/mysql-test/t/subselect_cache.test
@@ -419,12 +419,12 @@ show status like "subquery_cache%";
drop table t1;
--echo #test of sql_big_tables switch and outer table reference in subquery with grouping
-set option sql_big_tables=1;
+set big_tables=1;
CREATE TABLE t1 (a INT PRIMARY KEY, b INT);
INSERT INTO t1 VALUES (1,1),(2,1),(3,2),(4,2),(5,3),(6,3);
SELECT (SELECT t1_outer.a FROM t1 AS t1_inner GROUP BY b LIMIT 1) FROM t1 AS t1_outer;
drop table t1;
-set option sql_big_tables=0;
+set big_tables=0;
--echo #test of function reference to outer query
set local group_concat_max_len=400;
diff --git a/mysql-test/t/subselect_exists2in.test b/mysql-test/t/subselect_exists2in.test
new file mode 100644
index 00000000000..5a8ddb3612f
--- /dev/null
+++ b/mysql-test/t/subselect_exists2in.test
@@ -0,0 +1,832 @@
+
+--disable_warnings
+drop table if exists t1,t2,t3;
+--enable_warnings
+
+set optimizer_switch='exists_to_in=on';
+--echo #
+--echo # LP BUG#884644 exists2in broke name resolution
+--echo #
+
+CREATE TABLE t1 (f1 integer);
+
+--error ER_BAD_FIELD_ERROR
+SELECT * FROM t1 WHERE EXISTS (SELECT NO_SUCH_TABLE.NO_SUCH_FIELD FROM t1);
+
+drop table t1;
+
+--echo #
+--echo # LP BUG#884657 Wrong result with exists2in , correlated subquery
+--echo #
+
+CREATE TABLE t1 ( a varchar(1)) ;
+INSERT INTO t1 VALUES ('c'),('b');
+
+CREATE TABLE t2 ( b varchar(1)) ;
+INSERT INTO t2 VALUES ('v'),('v'),('c'),(NULL),('x'),('i'),('e'),('p'),('s'),('j'),('z'),('c'),('a'),('q'),('y'),(NULL),('r'),('v'),(NULL),('r');
+
+CREATE TABLE t3 ( a int NOT NULL , b varchar(1)) ;
+INSERT INTO t3 VALUES (29,'c');
+
+SELECT *
+FROM t1, t2
+WHERE EXISTS (
+ SELECT a
+ FROM t3
+ WHERE t3.b = t1.a
+ AND t3.b <> t2.b
+);
+
+
+INSERT INTO t3 VALUES (2,'c');
+alter table t1 add index aa (a);
+alter table t3 add index bb (b);
+--echo -- EXIST to IN then semijoin (has priority over IN to EXISTS)
+set optimizer_switch='exists_to_in=on,in_to_exists=on,semijoin=on,materialization=off,subquery_cache=off';
+SELECT * FROM t1 WHERE EXISTS ( SELECT a FROM t3 WHERE t3.b = t1.a);
+explain extended
+SELECT * FROM t1 WHERE EXISTS ( SELECT a FROM t3 WHERE t3.b = t1.a);
+--echo -- EXIST to IN then IN to EXISTS
+set optimizer_switch='exists_to_in=on,in_to_exists=on,semijoin=off,materialization=off,subquery_cache=off';
+SELECT * FROM t1 WHERE EXISTS ( SELECT a FROM t3 WHERE t3.b = t1.a);
+explain extended
+SELECT * FROM t1 WHERE EXISTS ( SELECT a FROM t3 WHERE t3.b = t1.a);
+--echo -- EXIST2IN then MATERIALIZATION
+set optimizer_switch='exists_to_in=on,in_to_exists=off,semijoin=off,materialization=on,subquery_cache=off';
+SELECT * FROM t1 WHERE EXISTS ( SELECT a FROM t3 WHERE t3.b = t1.a);
+explain extended
+SELECT * FROM t1 WHERE EXISTS ( SELECT a FROM t3 WHERE t3.b = t1.a);
+--echo -- NO EXIST2IN
+set optimizer_switch='exists_to_in=off,subquery_cache=off';
+SELECT * FROM t1 WHERE EXISTS ( SELECT a FROM t3 WHERE t3.b = t1.a);
+explain extended
+SELECT * FROM t1 WHERE EXISTS ( SELECT a FROM t3 WHERE t3.b = t1.a);
+set optimizer_switch=default;
+set optimizer_switch='exists_to_in=on';
+
+drop table t1,t2,t3;
+
+--echo #
+--echo # From group_min_max.test
+--echo #
+create table t1 (
+ a1 char(64), a2 char(64), b char(16), c char(16) not null, d char(16), dummy char(64) default ' '
+);
+
+insert into t1 (a1, a2, b, c, d) values
+('a','a','a','a111','xy1'),('a','a','a','b111','xy2'),('a','a','a','c111','xy3'),('a','a','a','d111','xy4'),
+('a','a','b','e112','xy1'),('a','a','b','f112','xy2'),('a','a','b','g112','xy3'),('a','a','b','h112','xy4'),
+('a','b','a','i121','xy1'),('a','b','a','j121','xy2'),('a','b','a','k121','xy3'),('a','b','a','l121','xy4'),
+('a','b','b','m122','xy1'),('a','b','b','n122','xy2'),('a','b','b','o122','xy3'),('a','b','b','p122','xy4'),
+('b','a','a','a211','xy1'),('b','a','a','b211','xy2'),('b','a','a','c211','xy3'),('b','a','a','d211','xy4'),
+('b','a','b','e212','xy1'),('b','a','b','f212','xy2'),('b','a','b','g212','xy3'),('b','a','b','h212','xy4'),
+('b','b','a','i221','xy1'),('b','b','a','j221','xy2'),('b','b','a','k221','xy3'),('b','b','a','l221','xy4'),
+('b','b','b','m222','xy1'),('b','b','b','n222','xy2'),('b','b','b','o222','xy3'),('b','b','b','p222','xy4'),
+('c','a','a','a311','xy1'),('c','a','a','b311','xy2'),('c','a','a','c311','xy3'),('c','a','a','d311','xy4'),
+('c','a','b','e312','xy1'),('c','a','b','f312','xy2'),('c','a','b','g312','xy3'),('c','a','b','h312','xy4'),
+('c','b','a','i321','xy1'),('c','b','a','j321','xy2'),('c','b','a','k321','xy3'),('c','b','a','l321','xy4'),
+('c','b','b','m322','xy1'),('c','b','b','n322','xy2'),('c','b','b','o322','xy3'),('c','b','b','p322','xy4'),
+('d','a','a','a411','xy1'),('d','a','a','b411','xy2'),('d','a','a','c411','xy3'),('d','a','a','d411','xy4'),
+('d','a','b','e412','xy1'),('d','a','b','f412','xy2'),('d','a','b','g412','xy3'),('d','a','b','h412','xy4'),
+('d','b','a','i421','xy1'),('d','b','a','j421','xy2'),('d','b','a','k421','xy3'),('d','b','a','l421','xy4'),
+('d','b','b','m422','xy1'),('d','b','b','n422','xy2'),('d','b','b','o422','xy3'),('d','b','b','p422','xy4'),
+('a','a','a','a111','xy1'),('a','a','a','b111','xy2'),('a','a','a','c111','xy3'),('a','a','a','d111','xy4'),
+('a','a','b','e112','xy1'),('a','a','b','f112','xy2'),('a','a','b','g112','xy3'),('a','a','b','h112','xy4'),
+('a','b','a','i121','xy1'),('a','b','a','j121','xy2'),('a','b','a','k121','xy3'),('a','b','a','l121','xy4'),
+('a','b','b','m122','xy1'),('a','b','b','n122','xy2'),('a','b','b','o122','xy3'),('a','b','b','p122','xy4'),
+('b','a','a','a211','xy1'),('b','a','a','b211','xy2'),('b','a','a','c211','xy3'),('b','a','a','d211','xy4'),
+('b','a','b','e212','xy1'),('b','a','b','f212','xy2'),('b','a','b','g212','xy3'),('b','a','b','h212','xy4'),
+('b','b','a','i221','xy1'),('b','b','a','j221','xy2'),('b','b','a','k221','xy3'),('b','b','a','l221','xy4'),
+('b','b','b','m222','xy1'),('b','b','b','n222','xy2'),('b','b','b','o222','xy3'),('b','b','b','p222','xy4'),
+('c','a','a','a311','xy1'),('c','a','a','b311','xy2'),('c','a','a','c311','xy3'),('c','a','a','d311','xy4'),
+('c','a','b','e312','xy1'),('c','a','b','f312','xy2'),('c','a','b','g312','xy3'),('c','a','b','h312','xy4'),
+('c','b','a','i321','xy1'),('c','b','a','j321','xy2'),('c','b','a','k321','xy3'),('c','b','a','l321','xy4'),
+('c','b','b','m322','xy1'),('c','b','b','n322','xy2'),('c','b','b','o322','xy3'),('c','b','b','p322','xy4'),
+('d','a','a','a411','xy1'),('d','a','a','b411','xy2'),('d','a','a','c411','xy3'),('d','a','a','d411','xy4'),
+('d','a','b','e412','xy1'),('d','a','b','f412','xy2'),('d','a','b','g412','xy3'),('d','a','b','h412','xy4'),
+('d','b','a','i421','xy1'),('d','b','a','j421','xy2'),('d','b','a','k421','xy3'),('d','b','a','l421','xy4'),
+('d','b','b','m422','xy1'),('d','b','b','n422','xy2'),('d','b','b','o422','xy3'),('d','b','b','p422','xy4');
+
+create index idx_t1_0 on t1 (a1);
+create index idx_t1_1 on t1 (a1,a2,b,c);
+create index idx_t1_2 on t1 (a1,a2,b);
+analyze table t1;
+
+# t2 is the same as t1, but with some NULLs in the MIN/MAX column, and
+# one more nullable attribute
+
+create table t2 (
+ a1 char(64), a2 char(64) not null, b char(16), c char(16), d char(16), dummy char(64) default ' '
+);
+insert into t2 select * from t1;
+# add few rows with NULL's in the MIN/MAX column
+insert into t2 (a1, a2, b, c, d) values
+('a','a',NULL,'a777','xyz'),('a','a',NULL,'a888','xyz'),('a','a',NULL,'a999','xyz'),
+('a','a','a',NULL,'xyz'),
+('a','a','b',NULL,'xyz'),
+('a','b','a',NULL,'xyz'),
+('c','a',NULL,'c777','xyz'),('c','a',NULL,'c888','xyz'),('c','a',NULL,'c999','xyz'),
+('d','b','b',NULL,'xyz'),
+('e','a','a',NULL,'xyz'),('e','a','a',NULL,'xyz'),('e','a','a',NULL,'xyz'),('e','a','a',NULL,'xyz'),
+('e','a','b',NULL,'xyz'),('e','a','b',NULL,'xyz'),('e','a','b',NULL,'xyz'),('e','a','b',NULL,'xyz'),
+('a','a',NULL,'a777','xyz'),('a','a',NULL,'a888','xyz'),('a','a',NULL,'a999','xyz'),
+('a','a','a',NULL,'xyz'),
+('a','a','b',NULL,'xyz'),
+('a','b','a',NULL,'xyz'),
+('c','a',NULL,'c777','xyz'),('c','a',NULL,'c888','xyz'),('c','a',NULL,'c999','xyz'),
+('d','b','b',NULL,'xyz'),
+('e','a','a',NULL,'xyz'),('e','a','a',NULL,'xyz'),('e','a','a',NULL,'xyz'),('e','a','a',NULL,'xyz'),
+('e','a','b',NULL,'xyz'),('e','a','b',NULL,'xyz'),('e','a','b',NULL,'xyz'),('e','a','b',NULL,'xyz');
+
+create index idx_t2_0 on t2 (a1);
+create index idx_t2_1 on t2 (a1,a2,b,c);
+create index idx_t2_2 on t2 (a1,a2,b);
+analyze table t2;
+
+# Table t3 is the same as t1, but with smaller column lenghts.
+# This allows to test different branches of the cost computation procedure
+# when the number of keys per block are less than the number of keys in the
+# sub-groups formed by predicates over non-group attributes.
+
+create table t3 (
+ a1 char(1), a2 char(1), b char(1), c char(4) not null, d char(3), dummy char(1) default ' '
+);
+
+insert into t3 (a1, a2, b, c, d) values
+('a','a','a','a111','xy1'),('a','a','a','b111','xy2'),('a','a','a','c111','xy3'),('a','a','a','d111','xy4'),
+('a','a','b','e112','xy1'),('a','a','b','f112','xy2'),('a','a','b','g112','xy3'),('a','a','b','h112','xy4'),
+('a','b','a','i121','xy1'),('a','b','a','j121','xy2'),('a','b','a','k121','xy3'),('a','b','a','l121','xy4'),
+('a','b','b','m122','xy1'),('a','b','b','n122','xy2'),('a','b','b','o122','xy3'),('a','b','b','p122','xy4'),
+('b','a','a','a211','xy1'),('b','a','a','b211','xy2'),('b','a','a','c211','xy3'),('b','a','a','d211','xy4'),
+('b','a','b','e212','xy1'),('b','a','b','f212','xy2'),('b','a','b','g212','xy3'),('b','a','b','h212','xy4'),
+('b','b','a','i221','xy1'),('b','b','a','j221','xy2'),('b','b','a','k221','xy3'),('b','b','a','l221','xy4'),
+('b','b','b','m222','xy1'),('b','b','b','n222','xy2'),('b','b','b','o222','xy3'),('b','b','b','p222','xy4'),
+('c','a','a','a311','xy1'),('c','a','a','b311','xy2'),('c','a','a','c311','xy3'),('c','a','a','d311','xy4'),
+('c','a','b','e312','xy1'),('c','a','b','f312','xy2'),('c','a','b','g312','xy3'),('c','a','b','h312','xy4'),
+('c','b','a','i321','xy1'),('c','b','a','j321','xy2'),('c','b','a','k321','xy3'),('c','b','a','l321','xy4'),
+('c','b','b','m322','xy1'),('c','b','b','n322','xy2'),('c','b','b','o322','xy3'),('c','b','b','p322','xy4');
+insert into t3 (a1, a2, b, c, d) values
+('a','a','a','a111','xy1'),('a','a','a','b111','xy2'),('a','a','a','c111','xy3'),('a','a','a','d111','xy4'),
+('a','a','b','e112','xy1'),('a','a','b','f112','xy2'),('a','a','b','g112','xy3'),('a','a','b','h112','xy4'),
+('a','b','a','i121','xy1'),('a','b','a','j121','xy2'),('a','b','a','k121','xy3'),('a','b','a','l121','xy4'),
+('a','b','b','m122','xy1'),('a','b','b','n122','xy2'),('a','b','b','o122','xy3'),('a','b','b','p122','xy4'),
+('b','a','a','a211','xy1'),('b','a','a','b211','xy2'),('b','a','a','c211','xy3'),('b','a','a','d211','xy4'),
+('b','a','b','e212','xy1'),('b','a','b','f212','xy2'),('b','a','b','g212','xy3'),('b','a','b','h212','xy4'),
+('b','b','a','i221','xy1'),('b','b','a','j221','xy2'),('b','b','a','k221','xy3'),('b','b','a','l221','xy4'),
+('b','b','b','m222','xy1'),('b','b','b','n222','xy2'),('b','b','b','o222','xy3'),('b','b','b','p222','xy4'),
+('c','a','a','a311','xy1'),('c','a','a','b311','xy2'),('c','a','a','c311','xy3'),('c','a','a','d311','xy4'),
+('c','a','b','e312','xy1'),('c','a','b','f312','xy2'),('c','a','b','g312','xy3'),('c','a','b','h312','xy4'),
+('c','b','a','i321','xy1'),('c','b','a','j321','xy2'),('c','b','a','k321','xy3'),('c','b','a','l321','xy4'),
+('c','b','b','m322','xy1'),('c','b','b','n322','xy2'),('c','b','b','o322','xy3'),('c','b','b','p322','xy4');
+insert into t3 (a1, a2, b, c, d) values
+('a','a','a','a111','xy1'),('a','a','a','b111','xy2'),('a','a','a','c111','xy3'),('a','a','a','d111','xy4'),
+('a','a','b','e112','xy1'),('a','a','b','f112','xy2'),('a','a','b','g112','xy3'),('a','a','b','h112','xy4'),
+('a','b','a','i121','xy1'),('a','b','a','j121','xy2'),('a','b','a','k121','xy3'),('a','b','a','l121','xy4'),
+('a','b','b','m122','xy1'),('a','b','b','n122','xy2'),('a','b','b','o122','xy3'),('a','b','b','p122','xy4'),
+('b','a','a','a211','xy1'),('b','a','a','b211','xy2'),('b','a','a','c211','xy3'),('b','a','a','d211','xy4'),
+('b','a','b','e212','xy1'),('b','a','b','f212','xy2'),('b','a','b','g212','xy3'),('b','a','b','h212','xy4'),
+('b','b','a','i221','xy1'),('b','b','a','j221','xy2'),('b','b','a','k221','xy3'),('b','b','a','l221','xy4'),
+('b','b','b','m222','xy1'),('b','b','b','n222','xy2'),('b','b','b','o222','xy3'),('b','b','b','p222','xy4'),
+('c','a','a','a311','xy1'),('c','a','a','b311','xy2'),('c','a','a','c311','xy3'),('c','a','a','d311','xy4'),
+('c','a','b','e312','xy1'),('c','a','b','f312','xy2'),('c','a','b','g312','xy3'),('c','a','b','h312','xy4'),
+('c','b','a','i321','xy1'),('c','b','a','j321','xy2'),('c','b','a','k321','xy3'),('c','b','a','l321','xy4'),
+('c','b','b','m322','xy1'),('c','b','b','n322','xy2'),('c','b','b','o322','xy3'),('c','b','b','p322','xy4');
+insert into t3 (a1, a2, b, c, d) values
+('a','a','a','a111','xy1'),('a','a','a','b111','xy2'),('a','a','a','c111','xy3'),('a','a','a','d111','xy4'),
+('a','a','b','e112','xy1'),('a','a','b','f112','xy2'),('a','a','b','g112','xy3'),('a','a','b','h112','xy4'),
+('a','b','a','i121','xy1'),('a','b','a','j121','xy2'),('a','b','a','k121','xy3'),('a','b','a','l121','xy4'),
+('a','b','b','m122','xy1'),('a','b','b','n122','xy2'),('a','b','b','o122','xy3'),('a','b','b','p122','xy4'),
+('b','a','a','a211','xy1'),('b','a','a','b211','xy2'),('b','a','a','c211','xy3'),('b','a','a','d211','xy4'),
+('b','a','b','e212','xy1'),('b','a','b','f212','xy2'),('b','a','b','g212','xy3'),('b','a','b','h212','xy4'),
+('b','b','a','i221','xy1'),('b','b','a','j221','xy2'),('b','b','a','k221','xy3'),('b','b','a','l221','xy4'),
+('b','b','b','m222','xy1'),('b','b','b','n222','xy2'),('b','b','b','o222','xy3'),('b','b','b','p222','xy4'),
+('c','a','a','a311','xy1'),('c','a','a','b311','xy2'),('c','a','a','c311','xy3'),('c','a','a','d311','xy4'),
+('c','a','b','e312','xy1'),('c','a','b','f312','xy2'),('c','a','b','g312','xy3'),('c','a','b','h312','xy4'),
+('c','b','a','i321','xy1'),('c','b','a','j321','xy2'),('c','b','a','k321','xy3'),('c','b','a','l321','xy4'),
+('c','b','b','m322','xy1'),('c','b','b','n322','xy2'),('c','b','b','o322','xy3'),('c','b','b','p322','xy4');
+
+create index idx_t3_0 on t3 (a1);
+create index idx_t3_1 on t3 (a1,a2,b,c);
+create index idx_t3_2 on t3 (a1,a2,b);
+analyze table t3;
+
+
+explain select a1,a2,b,c,min(c), max(c) from t1
+where exists ( select * from t2
+ where t2.c in (select c from t3 where t3.c > t1.b) and
+ t2.c > 'b1' )
+group by a1,a2,b;
+
+select a1,a2,b,c,min(c), max(c) from t1
+where exists ( select * from t2
+ where t2.c in (select c from t3 where t3.c > t1.b) and
+ t2.c > 'b1' )
+group by a1,a2,b;
+
+explain select a1,a2,b,c,min(c), max(c) from t1
+where exists ( select * from t2
+ where t2.c in (select c from t3 where t3.c > t1.c) and
+ t2.c > 'b1' )
+group by a1,a2,b;
+
+select a1,a2,b,c,min(c), max(c) from t1
+where exists ( select * from t2
+ where t2.c in (select c from t3 where t3.c > t1.c) and
+ t2.c > 'b1' )
+group by a1,a2,b;
+
+drop table t1, t2, t3;
+
+#
+# LP BUG#901835 - incorrect semi-join conversion after exists2in
+#
+CREATE TABLE t1 ( a INT );
+INSERT INTO t1 VALUES (7),(0);
+CREATE TABLE t2 ( b INT );
+INSERT INTO t2 VALUES (0),(8);
+
+SELECT * FROM t1 WHERE
+ EXISTS ( SELECT * FROM t2 WHERE b = a )
+ OR a > 0;
+
+explain extended
+SELECT * FROM t1 WHERE
+ EXISTS ( SELECT * FROM t2 WHERE b = a )
+ OR a > 0;
+
+drop tables t1,t2;
+
+#
+# NOT EXISTS test
+#
+CREATE TABLE t1 ( a INT );
+INSERT INTO t1 VALUES (1),(5);
+CREATE TABLE t2 ( b INT ) ENGINE=MyISAM;
+INSERT INTO t2 VALUES (1);
+
+CREATE TABLE t3 ( c INT );
+INSERT INTO t3 VALUES (4),(5);
+
+SET optimizer_switch='exists_to_in=on,subquery_cache=off,materialization=on,in_to_exists=off,semijoin=off';
+
+explain extended
+SELECT ( SELECT b FROM t2 WHERE NOT EXISTS ( SELECT c FROM t3 WHERE c = b ) ) FROM t1;
+SELECT ( SELECT b FROM t2 WHERE NOT EXISTS ( SELECT c FROM t3 WHERE c = b ) ) FROM t1;
+
+SET optimizer_switch='exists_to_in=on,subquery_cache=off';
+
+
+explain extended
+SELECT ( SELECT b FROM t2 WHERE NOT EXISTS ( SELECT c FROM t3 WHERE c = b ) ) FROM t1;
+SELECT ( SELECT b FROM t2 WHERE NOT EXISTS ( SELECT c FROM t3 WHERE c = b ) ) FROM t1;
+
+SET optimizer_switch='exists_to_in=off,subquery_cache=off';
+
+explain extended
+SELECT ( SELECT b FROM t2 WHERE NOT EXISTS ( SELECT c FROM t3 WHERE c = b ) ) FROM t1;
+SELECT ( SELECT b FROM t2 WHERE NOT EXISTS ( SELECT c FROM t3 WHERE c = b ) ) FROM t1;
+
+set optimizer_switch=default;
+set optimizer_switch='exists_to_in=on';
+drop table t1,t2,t3;
+
+--echo # multi condition test
+CREATE TABLE t1 ( a varchar(1), a1 varchar(1)) ;
+INSERT INTO t1 VALUES ('c', 'c'), ('b', 'b');
+
+CREATE TABLE t3 ( a int NOT NULL , b varchar(1), b1 varchar(1)) ;
+INSERT INTO t3 VALUES (29,'c','c');
+INSERT INTO t3 VALUES (2,'c','c');
+alter table t1 add index aa (a,a1);
+alter table t3 add index bb (b,b1);
+--echo -- EXIST to IN then semijoin (has priority over IN to EXISTS)
+set optimizer_switch='exists_to_in=on,in_to_exists=on,semijoin=on,materialization=off,subquery_cache=off';
+SELECT * FROM t1 WHERE EXISTS ( SELECT * FROM t3 WHERE t3.b = t1.a and t3.b1 = t1.a1);
+explain extended
+SELECT * FROM t1 WHERE EXISTS ( SELECT * FROM t3 WHERE t3.b = t1.a and t3.b1 = t1.a1);
+--echo -- EXIST to IN then IN to EXISTS
+set optimizer_switch='exists_to_in=on,in_to_exists=on,semijoin=off,materialization=off,subquery_cache=off';
+SELECT * FROM t1 WHERE EXISTS ( SELECT * FROM t3 WHERE t3.b = t1.a and t3.b1 = t1.a1);
+explain extended
+SELECT * FROM t1 WHERE EXISTS ( SELECT * FROM t3 WHERE t3.b = t1.a and t3.b1 = t1.a1);
+--echo -- EXIST2IN then MATERIALIZATION
+set optimizer_switch='exists_to_in=on,in_to_exists=off,semijoin=off,materialization=on,subquery_cache=off';
+SELECT * FROM t1 WHERE EXISTS ( SELECT * FROM t3 WHERE t3.b = t1.a and t3.b1 = t1.a1);
+explain extended
+SELECT * FROM t1 WHERE EXISTS ( SELECT * FROM t3 WHERE t3.b = t1.a and t3.b1 = t1.a1);
+--echo -- NO EXIST2IN
+set optimizer_switch='exists_to_in=off,subquery_cache=off';
+SELECT * FROM t1 WHERE EXISTS ( SELECT * FROM t3 WHERE t3.b = t1.a and t3.b1 = t1.a1);
+explain extended
+SELECT * FROM t1 WHERE EXISTS ( SELECT * FROM t3 WHERE t3.b = t1.a and t3.b1 = t1.a1);
+set optimizer_switch=default;
+set optimizer_switch='exists_to_in=on';
+
+drop table t1,t3;
+
+--echo #
+--echo # MDEV-159 Assertion about not marked for read failed in
+--echo # String* Field_varstring::val_str(String*, String*)
+--echo #
+
+SET optimizer_switch = REPLACE( @@optimizer_switch, '=on', '=off' );
+SET optimizer_switch='in_to_exists=on,exists_to_in=on';
+
+CREATE TABLE t1 ( a VARCHAR(1) );
+INSERT INTO t1 VALUES ('k'),('m');
+
+CREATE TABLE t2 ( b INT,
+ c VARCHAR(1),
+ d VARCHAR(1) NOT NULL );
+
+INSERT INTO t2 VALUES
+ (4,'j','j'),(6,'v','v');
+
+CREATE ALGORITHM=MERGE VIEW v AS SELECT * FROM t2 WHERE b < 1;
+
+SELECT c FROM v
+WHERE EXISTS (
+ SELECT * FROM t1, t2
+ WHERE a <= v.d AND b = v.b
+);
+
+explain extended
+SELECT c FROM v
+WHERE EXISTS (
+ SELECT * FROM t1, t2
+ WHERE a <= v.d AND b = v.b
+);
+
+set optimizer_switch=default;
+set optimizer_switch='exists_to_in=on';
+drop view v;
+drop table t1,t2;
+
+
+--echo #
+--echo # MDEV-160 Exists2In: Crash in in hp_movelink with subquery_cache=ON
+--echo #
+
+SET optimizer_switch = 'in_to_exists=on,subquery_cache=on,exists_to_in=on';
+
+CREATE TABLE t1 (
+ a VARCHAR(3) NOT NULL,
+ b VARCHAR(50)
+);
+INSERT INTO t1 VALUES
+ ('USA','Chinese'),('USA','English'),
+ ('FRA','French'),('ITA','Italian');
+
+CREATE TABLE t2 ( c VARCHAR(3) );
+INSERT INTO t2 VALUES ('USA'),('FRA');
+
+SELECT * FROM t1 AS alias1, t1 AS alias2
+WHERE EXISTS (
+ SELECT * FROM t1, t2
+ WHERE a <= alias2.a AND c = alias1.b
+) OR alias1 .a = 'foo';
+
+SELECT * FROM t1 AS alias1, t1 AS alias2
+WHERE EXISTS (
+ SELECT * FROM t1, t2
+ WHERE a <= alias2.a AND c = alias1.a
+) OR alias1 .a = 'foo';
+
+drop table t1,t2;
+set optimizer_switch=default;
+set optimizer_switch='exists_to_in=on';
+
+--echo #
+--echo # MDEV-160 Exists2In: Crash in in hp_movelink with subquery_cache=ON
+--echo #
+SET optimizer_switch = 'in_to_exists=on,subquery_cache=on,exists_to_in=on';
+
+CREATE TABLE t1 (
+ a VARCHAR(3) NOT NULL,
+ b VARCHAR(50)
+);
+INSERT INTO t1 VALUES
+ ('USA','Chinese'),('USA','English'),
+ ('FRA','French'),('ITA','Italian');
+
+CREATE TABLE t2 ( c VARCHAR(3) );
+INSERT INTO t2 VALUES ('USA'),('FRA');
+
+SELECT * FROM t1 AS alias1, t1 AS alias2
+WHERE EXISTS (
+ SELECT * FROM t1, t2
+ WHERE a <= alias2.a AND c = alias1.b
+) OR alias1 .a = 'foo';
+
+explain extended
+SELECT * FROM t1 AS alias1, t1 AS alias2
+WHERE EXISTS (
+ SELECT * FROM t1, t2
+ WHERE a <= alias2.a AND c = alias1.b
+) OR alias1 .a = 'foo';
+
+drop table t1,t2;
+set optimizer_switch=default;
+set optimizer_switch='exists_to_in=on';
+
+--echo #
+--echo # MDEV-245 Exists2In: Wrong result (extra rows) with
+--echo # exists_to_in=ON, materialization=OFF, NOT EXISTS subquery
+--echo #
+SET optimizer_switch='materialization=off,exists_to_in=on';
+
+CREATE TABLE t1 ( a INT ) ;
+INSERT INTO t1 VALUES (0),(8),(1);
+
+CREATE TABLE t2 ( b INT ) ;
+INSERT INTO t2 VALUES (1),(2),(3);
+
+SELECT * FROM t1 WHERE NOT EXISTS ( SELECT * FROM t2 WHERE b = a );
+explain extended
+SELECT * FROM t1 WHERE NOT EXISTS ( SELECT * FROM t2 WHERE b = a );
+
+drop table t1,t2;
+set optimizer_switch=default;
+set optimizer_switch='exists_to_in=on';
+
+--echo #
+--echo # MDEV-243 Wrong result (extra or missing rows) with
+--echo # exists_to_in + materialization, EXISTS subquery
+--echo #
+
+SET optimizer_switch='index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_merge_sort_intersection=off,engine_condition_pushdown=off,index_condition_pushdown=on,derived_merge=on,derived_with_keys=on,firstmatch=on,loosescan=on,materialization=on,in_to_exists=on,semijoin=on,partial_match_rowid_merge=on,partial_match_table_scan=on,subquery_cache=on,mrr=off,mrr_cost_based=off,mrr_sort_keys=off,outer_join_with_cache=on,semijoin_with_cache=on,join_cache_incremental=on,join_cache_hashed=on,join_cache_bka=on,optimize_join_buffer_size=off,table_elimination=on,extended_keys=off,exists_to_in=on';
+
+CREATE TABLE t1 ( a VARCHAR(1), b VARCHAR(1) );
+INSERT INTO t1 VALUES ('v','v'),('s','v');
+
+SELECT * FROM t1 AS alias
+WHERE EXISTS ( SELECT * FROM t1 WHERE a > alias.a AND a = alias.b );
+explain extended
+SELECT * FROM t1 AS alias
+WHERE EXISTS ( SELECT * FROM t1 WHERE a > alias.a AND a = alias.b );
+
+SET optimizer_switch = REPLACE( @@optimizer_switch, '=on', '=off' );
+SET optimizer_switch = 'exists_to_in=on,materialization=on,semijoin=off';
+SELECT * FROM t1 AS alias
+WHERE EXISTS ( SELECT * FROM t1 WHERE a > alias.a AND a = alias.b );
+explain extended
+SELECT * FROM t1 AS alias
+WHERE EXISTS ( SELECT * FROM t1 WHERE a > alias.a AND a = alias.b );
+SET optimizer_switch = 'exists_to_in=on,materialization=on,semijoin=on';
+SELECT * FROM t1 AS alias
+WHERE EXISTS ( SELECT * FROM t1 WHERE a > alias.a AND a = alias.b );
+explain extended
+SELECT * FROM t1 AS alias
+WHERE EXISTS ( SELECT * FROM t1 WHERE a > alias.a AND a = alias.b );
+
+drop table t1;
+set optimizer_switch=default;
+set optimizer_switch='exists_to_in=on';
+
+--echo #
+--echo # MDEV-403 Wrong result (missing rows) with subquery in
+--echo # EXISTS and an OR condition outside
+--echo #
+CREATE TABLE t1 (a INT);
+INSERT INTO t1 VALUES (2),(3);
+
+CREATE TABLE t2 (b INT);
+INSERT INTO t2 VALUES (1),(3);
+SET optimizer_switch = 'exists_to_in=off,in_to_exists=on';
+SELECT * FROM t1 AS alias1, t2 AS alias2
+WHERE EXISTS (
+ SELECT 1 FROM t2 WHERE b = alias1.a AND b > alias2.b
+) OR a = 5;
+
+SET optimizer_switch = 'exists_to_in=on,in_to_exists=on';
+
+SELECT * FROM t1 AS alias1, t2 AS alias2
+WHERE EXISTS (
+ SELECT 1 FROM t2 WHERE b = alias1.a AND b > alias2.b
+) OR a = 5;
+
+explain extended
+SELECT * FROM t1 AS alias1, t2 AS alias2
+WHERE EXISTS (
+ SELECT 1 FROM t2 WHERE b = alias1.a AND b > alias2.b
+) OR a = 5;
+
+drop table t1, t2;
+set optimizer_switch=default;
+set optimizer_switch='exists_to_in=on';
+
+--echo #
+--echo # MDEV-404: Wrong result (extra rows) with STRAIGHT_JOIN,
+--echo # EXISTS subquery, NOT NULL column
+--echo # (same as above)
+--echo #
+SET optimizer_switch = 'exists_to_in=on,in_to_exists=on';
+
+CREATE TABLE t1 (a INT, b VARCHAR(1) NOT NULL);
+INSERT INTO t1 VALUES (1,'s'),(2,'e');
+
+SELECT STRAIGHT_JOIN * FROM t1 AS alias1, t1 AS alias2
+WHERE EXISTS ( SELECT 1 FROM t1 WHERE b < alias2.b AND a = alias1.a );
+
+drop table t1;
+set optimizer_switch=default;
+set optimizer_switch='exists_to_in=on';
+
+
+--echo #
+--echo # MDEV-3800: ORDER BY doesn't work with exists_to_in=ON on
+--echo # a query with EXISTS subquery and OR condition
+--echo #
+SET optimizer_switch = 'in_to_exists=on,exists_to_in=on';
+CREATE TABLE t1 (a INT, b VARCHAR(1)) ENGINE=MyISAM;
+INSERT INTO t1 VALUES (4,'j'),(6,'v'),(3,'c');
+
+CREATE TABLE t2 (c VARCHAR(1)) ENGINE=MyISAM;
+INSERT INTO t2 VALUES ('b'),('y');
+
+SELECT a FROM t1
+WHERE EXISTS (
+ SELECT 1 FROM t2 WHERE c = b
+) OR b NOT IN ('U')
+ORDER BY a;
+
+select `test`.`t1`.`a` AS `a` from `test`.`t1` where `test`.`t1`.`b` in (select `test`.`t2`.`c` from `test`.`t2` where 1 ) or (`test`.`t1`.`b` <> 'U') order by `test`.`t1`.`a`;
+
+drop table t1,t2;
+set optimizer_switch=default;
+set optimizer_switch='exists_to_in=on';
+
+
+--echo #
+--echo # correct calculation of reserved items (postreview-fix)
+--echo #
+create table t1 (col1 int, col2 int, col3 int);
+insert into t1 values (1,2,3),(2,3,4),(4,5,6);
+create table t2 as select * from t1;
+explain extended
+select * from t1 where exists (select col2 from t2 where t2.col1=t1.col1 and t2.col2=t1.col2);
+select * from t1 where exists (select col2 from t2 where t2.col1=t1.col1 and t2.col2=t1.col2);
+drop table t1,t2;
+
+--echo #
+--echo # MDEV-3879: Exists2In: Wrong result (extra row) and unexpected
+--echo # warning with exists_to_in=on and a NOT EXISTS subquery
+--echo #
+SET optimizer_switch = 'exists_to_in=on';
+
+CREATE TABLE t1 (a1 INT, b1 CHAR(1)) ENGINE=MyISAM;
+INSERT INTO t1 VALUES (3,'y'),(6,'w');
+
+CREATE TABLE t2 (a2 INT, b2 CHAR(1)) ENGINE=MyISAM;
+INSERT INTO t2 VALUES (3,'y'),(6,'d');
+
+SELECT * FROM t1
+WHERE NOT EXISTS ( SELECT * FROM t2 WHERE b2 = b1 AND a2 = a1 );
+
+drop table t1, t2;
+
+--echo #
+--echo # MDEV-3880: Wrong result (missing rows) with exists_to_in=on,
+--echo # LEFT JOIN and NOT EXISTS subquery.
+--echo # (Duplicate of above MDEV-3879).
+--echo #
+
+SET optimizer_switch = 'exists_to_in=on';
+CREATE TABLE t1 (a1 INT, b1 CHAR(1)) ENGINE=MyISAM;
+INSERT INTO t1 VALUES (4,'b'),(5,'y');
+
+CREATE TABLE t2 (b2 CHAR(1)) ENGINE=MyISAM;
+INSERT INTO t2 VALUES ('z'),('b');
+
+CREATE TABLE t3 (a3 INT, b3 CHAR(1)) ENGINE=MyISAM;
+INSERT INTO t3 VALUES (4,'j'),(6,'v');
+
+SELECT * FROM t1 LEFT JOIN t2 ON ( b2 = b1 )
+WHERE NOT EXISTS ( SELECT * FROM t3 WHERE b3 = b2 AND a3 = a1 ) ;
+
+drop table t1, t2, t3;
+
+
+
+--echo #
+--echo # MDEV-3881: Endless loop and crash in Item_ref::real_item with
+--echo # exists_to_in=on, NOT EXISTS subquery, merge view or from subquery,
+--echo # constant table
+--echo #
+SET optimizer_switch = 'exists_to_in=on';
+
+CREATE TABLE t1 (a INT) ENGINE=MyISAM;
+INSERT INTO t1 VALUES (1),(7);
+
+CREATE TABLE t2 (b INT) ENGINE=MyISAM;
+INSERT INTO t2 VALUES (8);
+CREATE ALGORITHM=MERGE VIEW v1 AS SELECT * FROM t2;
+
+CREATE TABLE t3 (c INT) ENGINE=MyISAM;
+INSERT INTO t3 VALUES (4),(6);
+
+SELECT * FROM t1, v1 WHERE NOT EXISTS ( SELECT * FROM t3 WHERE c = b ) AND a = b;
+
+drop view v1;
+drop table t1, t2, t3;
+
+CREATE TABLE t1 (a INT) ENGINE=MyISAM;
+INSERT INTO t1 VALUES (1),(7);
+
+CREATE TABLE t2 (b INT) ENGINE=MyISAM;
+INSERT INTO t2 VALUES (8);
+
+CREATE TABLE t3 (c INT) ENGINE=MyISAM;
+INSERT INTO t3 VALUES (4),(6);
+
+SELECT * FROM t1, ( SELECT * FROM t2 ) alias WHERE NOT EXISTS ( SELECT * FROM t3 WHERE c = b ) AND a = b;
+
+drop table t1, t2, t3;
+
+--echo #
+--echo # MDEV-3906: Server crashes in Dependency_marker::visit_field
+--echo # on 2nd execution of PS with exists_to_in and NOT EXISTS subquery
+--echo #
+SET optimizer_switch='exists_to_in=on';
+
+CREATE TABLE t1 (a INT) ENGINE=MyISAM;
+INSERT INTO t1 VALUES (1),(7);
+
+PREPARE stmt FROM '
+SELECT * FROM t1 AS alias
+WHERE NOT EXISTS ( SELECT * FROM t1 WHERE t1.a = alias.a )
+';
+
+EXECUTE stmt;
+EXECUTE stmt;
+
+drop table t1;
+
+--echo #
+--echo # MDEV-3904: Assertion `in_subs->has_strategy()' failed in
+--echo # JOIN::choose_subquery_plan on 2nd execution of PS with
+--echo # exists_to_in+semijoin, EXISTS subquery, MERGE view or FROM subquery
+--echo #
+SET optimizer_switch='in_to_exists=on,semijoin=on,exists_to_in=on';
+
+CREATE TABLE t1 (a INT) ENGINE=MyISAM;
+INSERT INTO t1 VALUES (1),(2);
+
+CREATE TABLE t2 (b INT) ENGINE=MyISAM;
+INSERT INTO t2 VALUES (4),(6);
+
+CREATE ALGORITHM=MERGE VIEW v AS
+SELECT * FROM t1 WHERE EXISTS ( SELECT * FROM t2 WHERE b = a );
+
+PREPARE stmt FROM ' SELECT * FROM v ';
+
+EXECUTE stmt;
+EXECUTE stmt;
+
+drop view v;
+drop table t1,t2;
+set optimizer_switch=default;
+set optimizer_switch='exists_to_in=on';
+
+--echo #
+--echo # MDEV-3903: Server crashes in Item_cond::fix_fields on 2nd execution
+--echo # of a prepared stmt with exists_to_in+materialization+semijoin,
+--echo # EXISTS subquery, STRAIGHT_JOIN
+--echo #
+
+SET optimizer_switch='materialization=on,semijoin=on,exists_to_in=on';
+
+CREATE TABLE t1 (a INT) ENGINE=MyISAM;
+INSERT INTO t1 VALUES (1),(2);
+
+CREATE TABLE t2 (b INT) ENGINE=MyISAM;
+INSERT INTO t2 VALUES (3),(4);
+
+PREPARE stmt FROM
+'SELECT STRAIGHT_JOIN * FROM t1
+WHERE EXISTS ( SELECT * FROM t2 WHERE b = a )';
+
+EXECUTE stmt;
+EXECUTE stmt;
+
+drop table t1,t2;
+set optimizer_switch=default;
+set optimizer_switch='exists_to_in=on';
+
+--echo #
+--echo # MDEV-4152: Wrong result (missing rows) with exists_to_in=on,
+--echo # inner joins
+--echo #
+SET optimizer_switch='materialization=on,semijoin=on,exists_to_in=on';
+
+CREATE TABLE t1 (i INT, c1 CHAR(5), c2 CHAR(5), t1_field VARCHAR(1)) ENGINE=MyISAM;
+INSERT INTO t1 VALUES (1,'test1','test2','f'), (2,'test3','test4','d');
+
+CREATE TABLE t2 (t2_field VARCHAR(1)) ENGINE=MyISAM;
+INSERT INTO t2 VALUES ('m'), ('b');
+
+CREATE TABLE t3 (t3_field VARCHAR(1)) ENGINE=MyISAM;
+INSERT INTO t3 VALUES ('b'),('c');
+
+SELECT * FROM t1, t2 outer_t2
+WHERE EXISTS ( SELECT 1 FROM t2, t3 WHERE t3_field = outer_t2.t2_field AND t2_field <= t1_field );
+
+drop table t1,t2,t3;
+set optimizer_switch=default;
+set optimizer_switch='exists_to_in=on';
+
+--echo #
+--echo #MDEV-5401: Wrong result (missing row) on a 2nd execution of PS with
+--echo #exists_to_in=on, MERGE view or a SELECT SQ
+--echo #
+CREATE TABLE t1 (a INT) ENGINE=MyISAM;
+INSERT INTO t1 VALUES (1),(2);
+
+CREATE ALGORITHM=MERGE VIEW v1 AS SELECT * FROM t1;
+
+CREATE TABLE t2 (b INT) ENGINE=MyISAM;
+INSERT INTO t2 VALUES (2),(3);
+
+SELECT * FROM v1 WHERE EXISTS ( SELECT * FROM t2 t2x, t2 t2y WHERE t2y.b = a );
+
+PREPARE stmt FROM "SELECT * FROM v1 WHERE EXISTS ( SELECT * FROM t2 t2x, t2 t2y WHERE t2y.b = a )";
+EXECUTE stmt;
+EXECUTE stmt;
+
+deallocate prepare stmt;
+
+drop view v1;
+drop table t1,t2;
+
+--echo #
+--echo #MDEV-10053: EXIST to IN transformation turned down
+--echo #
+
+CREATE TABLE t1 (
+ pk INT, f1 INT NOT NULL, f2 VARCHAR(3), f3 INT NULL, PRIMARY KEY(pk))
+ENGINE=MyISAM;
+INSERT INTO t1 VALUES (1,1,'foo',8), (2,5,'bar',7);
+
+let $q=
+SELECT STRAIGHT_JOIN sq1.f2
+ FROM ( SELECT * FROM t1 ) AS sq1
+ WHERE EXISTS ( SELECT * FROM t1 AS sq2
+ WHERE sq1.`pk` IN ( SELECT f1 FROM t1 ) AND sq2.f1 = sq1.f1 );
+
+set @optimizer_switch_save=@@optimizer_switch;
+
+set optimizer_switch='exists_to_in=off';
+eval explain extended $q;
+eval $q;
+set optimizer_switch='exists_to_in=on';
+eval explain extended $q;
+eval $q;
+
+set optimizer_switch= @optimizer_switch_save;
+
+DROP TABLE t1;
+
+--echo #
+--echo # MDEV-14164: Unknown column error when adding aggregate to function
+--echo # in oracle style procedure FOR loop
+--echo #
+
+CREATE TABLE t1(id INT, val INT);
+DELIMITER //;
+CREATE PROCEDURE p1()
+BEGIN
+ DECLARE cur1 CURSOR FOR SELECT * FROM (
+ SELECT DISTINCT id FROM t1) a
+ WHERE NOT EXISTS (SELECT * FROM ( SELECT id FROM t1) b
+ WHERE a.id=b.id);
+ OPEN cur1;
+ CLOSE cur1;
+ OPEN cur1;
+ CLOSE cur1;
+END;
+//
+DELIMITER ;//
+CALL p1();
+DROP PROCEDURE p1;
+DROP TABLE t1;
+
+CREATE TABLE t1(id INT, val INT);
+DELIMITER //;
+CREATE PROCEDURE p1()
+BEGIN
+ SELECT * FROM (SELECT DISTINCT id FROM t1) a
+ WHERE NOT a.id IN (SELECT b.id FROM t1 b);
+ SELECT * FROM (SELECT DISTINCT id FROM t1) a
+ WHERE NOT EXISTS (SELECT * FROM t1 b WHERE a.id=b.id);
+END;
+//
+DELIMITER ;//
+CALL p1();
+CALL p1();
+DROP PROCEDURE p1;
+DROP TABLE t1;
+
+--echo # End of 10.0 tests
+
+#restore defaults
+set optimizer_switch=default;
diff --git a/mysql-test/t/subselect_exists2in_costmat.test b/mysql-test/t/subselect_exists2in_costmat.test
new file mode 100644
index 00000000000..5d5eeaee268
--- /dev/null
+++ b/mysql-test/t/subselect_exists2in_costmat.test
@@ -0,0 +1,83 @@
+#
+# Tests of cost-based choice between the materialization and in-to-exists
+# subquery execution strategies (MWL#89)
+#
+# The test file is divided into two groups of tests:
+# A. Typical cases when either of the two strategies is selected:
+# 1. Subquery in disjunctive WHERE clause of the outer query.
+# 2. NOT IN subqueries
+# 3. Subqueries with GROUP BY, HAVING, and aggregate functions
+# 4. Subqueries in the SELECT and HAVING clauses
+# 5. Subqueries with UNION
+# B. Reasonably exhaustive tests of the various combinations of optimizer
+# switches, data distribution, available indexes, and typical queries.
+#
+
+set @subselect_mat_cost=@@optimizer_switch;
+set optimizer_switch='mrr=on,mrr_sort_keys=on,index_condition_pushdown=on';
+#
+# Test logging to slow log (there was some errors in the log files about
+# the slow log when running under valgrind, so better to get this tested)
+#
+set long_query_time=0.1;
+
+
+--disable_warnings
+drop database if exists world;
+--enable_warnings
+
+set names utf8;
+
+create database world;
+use world;
+
+--source include/world_schema.inc
+--disable_query_log
+--disable_result_log
+--disable_warnings
+--source include/world.inc
+--enable_warnings
+--enable_result_log
+--enable_query_log
+
+-- echo Make the schema and data more diverse by adding more indexes, nullable
+-- echo columns, and NULL data.
+create index SurfaceArea on Country(SurfaceArea);
+create index Language on CountryLanguage(Language);
+create index CityName on City(Name);
+alter table City change population population int(11) null default 0;
+
+select max(id) from City into @max_city_id;
+insert into City values (@max_city_id + 1,'Kilifarevo','BGR',NULL);
+
+
+SELECT COUNT(*) FROM Country;
+SELECT COUNT(*) FROM City;
+SELECT COUNT(*) FROM CountryLanguage;
+
+set @@optimizer_switch = 'exists_to_in=on,in_to_exists=on,semijoin=on,materialization=on,partial_match_rowid_merge=on,partial_match_table_scan=on,subquery_cache=on';
+
+-- echo
+-- echo 1. Subquery in a disjunctive WHERE clause of the outer query.
+-- echo
+
+-- echo
+-- echo Q1.1m:
+-- echo MATERIALIZATION: there are too many rows in the outer query
+-- echo to be looked up in the inner table.
+EXPLAIN
+SELECT Name FROM Country
+WHERE (EXISTS (select 1 from City where City.Population > 100000 and
+Code = Country) OR
+ Name LIKE 'L%') AND
+ surfacearea > 1000000;
+
+SELECT Name FROM Country
+WHERE (EXISTS (select 1 from City where City.Population > 100000 and
+Code = Country) OR
+ Name LIKE 'L%') AND
+ surfacearea > 1000000;
+
+drop database world;
+
+set optimizer_switch=@subselect_mat_cost;
diff --git a/mysql-test/t/subselect_innodb.test b/mysql-test/t/subselect_innodb.test
index 3945c6b10b9..2451bc60fee 100644
--- a/mysql-test/t/subselect_innodb.test
+++ b/mysql-test/t/subselect_innodb.test
@@ -244,6 +244,54 @@ drop procedure p1;
drop tables t1,t2,t3;
--echo #
+--echo # Bug #58756
+--echo # Crash in heap_rrnd on query with HAVING ... IN (subquery) + LIMIT
+--echo #
+
+CREATE TABLE t1 (
+ col_time_key time DEFAULT NULL,
+ col_datetime_key datetime DEFAULT NULL,
+ col_varchar_nokey varchar(1) DEFAULT NULL,
+ KEY col_time_key (col_time_key),
+ KEY col_datetime_key (col_datetime_key)
+) ENGINE=InnoDB DEFAULT CHARSET=latin1;
+
+INSERT INTO t1 VALUES ('17:53:30','2005-11-10 12:40:29','h');
+INSERT INTO t1 VALUES ('11:35:49','2009-04-25 00:00:00','b');
+INSERT INTO t1 VALUES (NULL,'2002-11-27 00:00:00','s');
+INSERT INTO t1 VALUES ('06:01:40','2004-01-26 20:32:32','e');
+INSERT INTO t1 VALUES ('05:45:11','2007-10-26 11:41:40','j');
+INSERT INTO t1 VALUES ('00:00:00','2005-10-07 00:00:00','e');
+INSERT INTO t1 VALUES ('00:00:00','2000-07-15 05:00:34','f');
+INSERT INTO t1 VALUES ('06:11:01','2000-04-03 16:33:32','v');
+INSERT INTO t1 VALUES ('13:02:46',NULL,'x');
+INSERT INTO t1 VALUES ('21:44:25','2001-04-25 01:26:12','m');
+INSERT INTO t1 VALUES ('22:43:58','2000-12-27 00:00:00','c');
+
+CREATE TABLE t2 (
+ col_time_key time DEFAULT NULL,
+ col_datetime_key datetime DEFAULT NULL,
+ col_varchar_nokey varchar(1) DEFAULT NULL,
+ KEY col_time_key (col_time_key),
+ KEY col_datetime_key (col_datetime_key)
+) ENGINE=InnoDB DEFAULT CHARSET=latin1;
+
+INSERT INTO t2 VALUES ('11:28:45','2004-10-11 18:13:16','w');
+
+SELECT col_time_key, col_datetime_key
+FROM
+( SELECT * FROM t1 ) AS table1
+HAVING ( 'r' , 'e' ) IN
+ ( SELECT col_varchar_nokey , col_varchar_nokey FROM t2 )
+ORDER BY col_datetime_key
+LIMIT 10;
+
+DROP TABLE t1;
+DROP TABLE t2;
+
+--echo # End of Bug #58756
+
+--echo #
--echo # Bug#60085 crash in Item::save_in_field() with time data type
--echo #
@@ -475,3 +523,56 @@ SELECT * FROM t1
DROP TABLE t1,t2,t3;
+--echo #
+--echo # MDEV-6041: ORDER BY+subqueries: subquery_table.key=outer_table.col is not recongized as binding
+--echo #
+create table t1(a int) engine=innodb;
+insert into t1 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
+
+create table t2(
+ id int primary key,
+ key1 int,
+ col1 int,
+ key(key1)
+) engine=innodb;
+
+insert into t2
+ select
+ A.a + B.a*10 + C.a*100 + D.a* 1000,
+ A.a + 10*B.a,
+ 123456
+from t1 A, t1 B, t1 C, t1 D;
+
+--echo # Table tsubq:
+--echo # - must use 'ref' (not 'index'), and must not use 'Using filesort'
+--echo # - shows a bad estimate for 'rows' (but I'm not sure if one can do better w/o histograms)
+explain select
+ (SELECT
+ concat(id, '-', key1, '-', col1)
+ FROM t2
+ WHERE t2.key1 = t1.a
+ ORDER BY t2.id ASC LIMIT 1)
+from
+ t1;
+
+--echo #
+--echo # MDEV-6081: ORDER BY+ref(const): selectivity is very incorrect (MySQL Bug#14338686)
+--echo #
+
+alter table t2 add key2 int;
+update t2 set key2=key1;
+alter table t2 add key(key2);
+analyze table t2;
+flush tables;
+--echo # Table tsubq must use 'ref' + Using filesort (not 'index' w/o filesort)
+--replace_column 9 #
+explain select
+ (SELECT
+ concat(id, '-', key1, '-', col1)
+ FROM t2
+ WHERE t2.key1 = t1.a
+ ORDER BY t2.key2 ASC LIMIT 1)
+from
+ t1;
+
+drop table t1,t2;
diff --git a/mysql-test/t/subselect_mat_cost-master.opt b/mysql-test/t/subselect_mat_cost-master.opt
index dc7ac6cc205..cb4a9db9617 100644
--- a/mysql-test/t/subselect_mat_cost-master.opt
+++ b/mysql-test/t/subselect_mat_cost-master.opt
@@ -1 +1 @@
---log-output=TABLE,FILE --log --log-slow-queries --slow-query-log=1
+--log-output=TABLE,FILE --general-log --slow-query-log=1
diff --git a/mysql-test/t/subselect_no_exists_to_in.test b/mysql-test/t/subselect_no_exists_to_in.test
new file mode 100644
index 00000000000..7145a4594bc
--- /dev/null
+++ b/mysql-test/t/subselect_no_exists_to_in.test
@@ -0,0 +1,11 @@
+#
+# Run subselect.test with exists to in transformation
+#
+select @@optimizer_switch like '%exists_to_in=off%';
+set optimizer_switch='exists_to_in=off';
+
+--source t/subselect.test
+
+set optimizer_switch=default;
+select @@optimizer_switch like '%exists_to_in=off%';
+
diff --git a/mysql-test/t/subselect_sj.test b/mysql-test/t/subselect_sj.test
index 0a35a61ecd3..f98f5ac236f 100644
--- a/mysql-test/t/subselect_sj.test
+++ b/mysql-test/t/subselect_sj.test
@@ -79,6 +79,8 @@ select * from t1 left join (t2 A, t2 B) on ( A.a= t1.a and B.a in (select pk fro
explain extended
select * from t1 left join t2 on (t2.a= t1.a and t2.a in (select pk from t10));
+set join_buffer_size=8*1024;
+
--echo we shouldn't flatten if we're going to get a join of > MAX_TABLES.
explain select * from
t1 s00, t1 s01, t1 s02, t1 s03, t1 s04,t1 s05,t1 s06,t1 s07,t1 s08,t1 s09,
@@ -97,6 +99,8 @@ select * from
t1 left join t2 on (t2.a= t1.a and t2.a in (select pk from t10))
where t1.a < 5;
+set join_buffer_size=default;
+
#
# Prepared statements
#
@@ -897,8 +901,8 @@ insert into t2 values ("1", "1", "sup", "0"), ("2", "1", "sup", "1"),
("4", "1", "sup", "0");
create table t3 (
id int(11) not null default '0',
- preceeding_id int(11) not null default '0',
- primary key (id,preceeding_id)
+ preceding_id int(11) not null default '0',
+ primary key (id,preceding_id)
);
create table t4 (
diff --git a/mysql-test/t/subselect_sj2.test b/mysql-test/t/subselect_sj2.test
index 0bf9c6d9d10..6ed36083b33 100644
--- a/mysql-test/t/subselect_sj2.test
+++ b/mysql-test/t/subselect_sj2.test
@@ -1391,5 +1391,44 @@ eval explain $query;
drop table t3,t2,t1;
set optimizer_search_depth=@tmp7474;
+--echo #
+--echo #
+--echo #
+CREATE TABLE t1 (
+ id int(16) NOT NULL AUTO_INCREMENT,
+ PRIMARY KEY (id)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8;
+
+CREATE TABLE t2 (
+ id int(16) NOT NULL AUTO_INCREMENT,
+ t3_id int(16) NOT NULL DEFAULT '0',
+ t1_id int(16) NOT NULL DEFAULT '0',
+ PRIMARY KEY (id),
+ KEY t3_idx (t3_id),
+ KEY t1_idx (t1_id)
+) ENGINE=MyISAM DEFAULT CHARSET=utf8;
+
+CREATE TABLE t3 (
+ id int(16) NOT NULL AUTO_INCREMENT,
+ PRIMARY KEY (id)
+) ENGINE=MyISAM DEFAULT CHARSET=utf8;
+
+
+INSERT INTO t3 VALUES (1);
+
+INSERT INTO t2 VALUES (1, 1, 1);
+INSERT INTO t2 VALUES (2, 1, 2);
+INSERT INTO t2 VALUES (3, 1, 2);
+INSERT INTO t2 VALUES (4, 1, 1);
+
+INSERT INTO t1 VALUES (1);
+INSERT INTO t1 VALUES (2);
+
+SELECT * FROM t1 WHERE t1.id IN (
+ SELECT t2.t1_id FROM t3 JOIN t2 ON t3.id = t2.t3_id WHERE t3.id = 1
+);
+
+drop table t1,t2,t3;
+
--echo # This must be the last in the file:
set optimizer_switch=@subselect_sj2_tmp;
diff --git a/mysql-test/t/subselect_sj_mat.test b/mysql-test/t/subselect_sj_mat.test
index 90f63bea561..c626d88e6ff 100644
--- a/mysql-test/t/subselect_sj_mat.test
+++ b/mysql-test/t/subselect_sj_mat.test
@@ -1864,22 +1864,25 @@ drop table t1;
CREATE TABLE t1 (
pk INT, f1 INT NOT NULL, f2 VARCHAR(3), f3 INT NULL, PRIMARY KEY(pk)) ENGINE=MyISAM;
INSERT INTO t1 VALUES (1,1,'foo',8), (2,5,'bar',7);
-
-SELECT sq1.f2 FROM t1 AS sq1
- WHERE EXISTS ( SELECT * FROM t1 AS sq2
+
+SELECT sq1.f2 FROM t1 AS sq1
+ WHERE EXISTS ( SELECT * FROM t1 AS sq2
WHERE sq1.`pk` IN ( SELECT f1 FROM t1 ) AND sq2.f1 = sq1.f1 );
+set @save_optimizer_switch= @@optimizer_switch;
+
+set optimizer_switch='exists_to_in=off';
EXPLAIN
-SELECT sq1.f2 FROM t1 AS sq1
- WHERE EXISTS ( SELECT * FROM t1 AS sq2
+SELECT sq1.f2 FROM t1 AS sq1
+ WHERE EXISTS ( SELECT * FROM t1 AS sq2
WHERE sq1.`pk` IN ( SELECT f1 FROM t1 ) AND sq2.f1 = sq1.f1 );
--echo # this checks the result set above
-set @save_optimizer_switch= @@optimizer_switch;
set optimizer_switch= 'materialization=off,semijoin=off';
-SELECT sq1.f2 FROM t1 AS sq1
- WHERE EXISTS ( SELECT * FROM t1 AS sq2
+SELECT sq1.f2 FROM t1 AS sq1
+ WHERE EXISTS ( SELECT * FROM t1 AS sq2
WHERE sq1.`pk` IN ( SELECT f1 FROM t1 ) AND sq2.f1 = sq1.f1 );
+
set optimizer_switch= @save_optimizer_switch;
DROP TABLE t1;
@@ -1897,20 +1900,23 @@ INSERT INTO t2 VALUES (8),(7),(1);
CREATE TABLE t3 (f3 INT, i3 INT, KEY(i3)) ENGINE=MyISAM;
INSERT INTO t3 VALUES (8,0),(6,3),(2,8),(3,8),(1,6),(0,0),(1,0),(1,5);
-SELECT * FROM t1
+set @save_optimizer_switch= @@optimizer_switch;
+
+set optimizer_switch='exists_to_in=off';
+SELECT * FROM t1
WHERE EXISTS ( SELECT * FROM t2, t3
WHERE i3 = i2 AND f1 IN ( SELECT f3 FROM t3 ) );
EXPLAIN EXTENDED
-SELECT * FROM t1
+SELECT * FROM t1
WHERE EXISTS ( SELECT * FROM t2, t3
WHERE i3 = i2 AND f1 IN ( SELECT f3 FROM t3 ) );
--echo # this checks the result set above
-set @save_optimizer_switch= @@optimizer_switch;
set optimizer_switch= 'materialization=off,semijoin=off';
-SELECT * FROM t1
+SELECT * FROM t1
WHERE EXISTS ( SELECT * FROM t2, t3
WHERE i3 = i2 AND f1 IN ( SELECT f3 FROM t3 ) );
+
set optimizer_switch= @save_optimizer_switch;
DROP TABLE t1,t2,t3;
@@ -1921,24 +1927,24 @@ DROP TABLE t1,t2,t3;
CREATE TABLE t1 (pk INT PRIMARY KEY, f1 INT);
INSERT INTO t1 VALUES (1, 4),(2, 3),(3, 3),(4, 6),(5, 3);
-
+
CREATE TABLE t2 (f2 INT);
INSERT INTO t2 VALUES (1),(2),(3),(4),(5);
-
---echo # t1.pk is always IN ( SELECT f2 FROM t2 ),
---echo # so the IN condition should be true for every row,
+
+--echo # t1.pk is always IN ( SELECT f2 FROM t2 ),
+--echo # so the IN condition should be true for every row,
--echo # and thus COUNT(*) should always return 5
-
-SELECT pk, f1, ( SELECT COUNT(*) FROM t2
+
+SELECT pk, f1, ( SELECT COUNT(*) FROM t2
WHERE t1.pk IN ( SELECT f2 FROM t2 ) ) AS sq FROM t1;
EXPLAIN EXTENDED
-SELECT pk, f1, ( SELECT COUNT(*) FROM t2
+SELECT pk, f1, ( SELECT COUNT(*) FROM t2
WHERE t1.pk IN ( SELECT f2 FROM t2 ) ) AS sq FROM t1;
--echo # this checks the result set above
set @save_optimizer_switch= @@optimizer_switch;
set optimizer_switch= 'materialization=off,semijoin=off';
-SELECT pk, f1, ( SELECT COUNT(*) FROM t2
+SELECT pk, f1, ( SELECT COUNT(*) FROM t2
WHERE t1.pk IN ( SELECT f2 FROM t2 ) ) AS sq FROM t1;
set optimizer_switch= @save_optimizer_switch;
@@ -2152,3 +2158,70 @@ DROP TABLE t1,t2,t3;
set optimizer_switch=@save_optimizer_switch;
--echo # End of 5.5 tests
+--echo #
+--echo # MDEV-7220: Materialization strategy is not used for REPLACE ... SELECT
+--echo #
+create table t0(a int);
+insert into t0 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
+
+create table t1 (a int, b int, c int);
+insert into t1
+select A.a+B.a*10+C.a*100, A.a+B.a*10+C.a*100, A.a+B.a*10+C.a*100
+from t0 A, t0 B, t0 C;
+
+create table t2 (a int, b int, c int);
+insert into t2 select A.a, A.a, A.a from t1 A;
+insert into t2 select * from t2;
+insert into t2 select * from t2;
+
+create table t3 as select * from t2 limit 1;
+
+--echo # The testcase only makes sense if the following uses Materialization:
+explain
+select * from t1 where (a,b) in (select max(a),b from t2 group by b);
+
+flush status;
+replace into t3
+select * from t1 where (a,b) in (select max(a),b from t2 group by b);
+--echo # Sequential reads:
+--echo # 1K is read from t1
+--echo # 4K is read from t2
+--echo # 1K groups is read from the tmp. table
+--echo #
+--echo # Lookups:
+--echo # 4K lookups in group by table
+--echo # 1K lookups in temp.table
+--echo #
+--echo # Writes:
+--echo # 2x 1K writes to temporary tables (grouping table and subquery materialization table
+--echo #
+--echo # The point is that neither counter should be in the millions (this
+--echo # will happen if Materialization is not used
+show status where Variable_name like 'Handler_read%' or Variable_name like 'Handler_%write%';
+
+drop table t0,t1,t2,t3;
+
+--echo #
+--echo # MDEV-7971: Assertion `name != __null' failed in ACL_internal_schema_registry::lookup
+--echo # on 2nd execution os PS with multi-table update
+--echo #
+CREATE TABLE t1 (f1 INT);
+INSERT INTO t1 VALUES (1),(2);
+
+CREATE TABLE t2 (f2 INT);
+INSERT INTO t2 VALUES (3),(4);
+
+CREATE TABLE t3 (f3 INT);
+INSERT INTO t3 VALUES (5),(6);
+
+PREPARE stmt FROM '
+ UPDATE t1, t2
+ SET f1 = 5
+ WHERE 8 IN ( SELECT MIN(f3) FROM t3 )
+';
+
+EXECUTE stmt;
+EXECUTE stmt;
+
+DROP TABLE t1,t2,t3;
+
diff --git a/mysql-test/t/symlink-myisam-11902.test b/mysql-test/t/symlink-myisam-11902.test
index 7e35ad117d0..8fd4961d1fb 100644
--- a/mysql-test/t/symlink-myisam-11902.test
+++ b/mysql-test/t/symlink-myisam-11902.test
@@ -25,7 +25,7 @@ exec rm -r $MYSQLTEST_VARDIR/tmp/foo;
exec ln -s $datadir/mysql $MYSQLTEST_VARDIR/tmp/foo;
set debug_sync='now SIGNAL go';
connection default;
-replace_regex / '.*\/tmp\// 'MYSQLTEST_VARDIR\/tmp\// /31/20/;
+replace_regex / '.*\/tmp\// 'MYSQLTEST_VARDIR\/tmp\// /31/20/ /40/20/ /20.*/20 <errmsg>)/;
error 29;
reap;
flush tables;
@@ -49,7 +49,7 @@ exec rm -r $MYSQLTEST_VARDIR/tmp/foo;
exec ln -s $datadir/mysql $MYSQLTEST_VARDIR/tmp/foo;
set debug_sync='now SIGNAL run';
connection default;
-replace_regex / '.*\/tmp\// 'MYSQLTEST_VARDIR\/tmp\// /31/20/;
+replace_regex / '.*\/test\// '.\/test\// /31/20/ /40/20/ /20.*/20 <errmsg>)/;
error ER_FILE_NOT_FOUND;
reap;
flush tables;
diff --git a/mysql-test/t/system_mysql_db_fix40123.test b/mysql-test/t/system_mysql_db_fix40123.test
index 5c82f0022b8..fd1212d4ce6 100644
--- a/mysql-test/t/system_mysql_db_fix40123.test
+++ b/mysql-test/t/system_mysql_db_fix40123.test
@@ -1,5 +1,6 @@
# Embedded server doesn't support external clients
--source include/not_embedded.inc
+--source include/have_innodb.inc
# Don't run this test if $MYSQL_FIX_PRIVILEGE_TABLES isn't set
# to the location of mysql_fix_privilege_tables.sql
@@ -36,7 +37,7 @@ CREATE TABLE host ( Host char(60) binary DEFAULT '' NOT NULL, Db char(64) bina
CREATE TABLE user ( Host char(60) binary DEFAULT '' NOT NULL, User char(16) binary DEFAULT '' NOT NULL, Password char(41) binary DEFAULT '' NOT NULL, Select_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Insert_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Update_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Delete_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Create_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Drop_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Reload_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Shutdown_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Process_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, File_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Grant_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, References_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Index_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Alter_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Show_db_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Super_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Create_tmp_table_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Lock_tables_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Execute_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Repl_slave_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Repl_client_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, ssl_type enum('','ANY','X509', 'SPECIFIED') COLLATE utf8_general_ci DEFAULT '' NOT NULL, ssl_cipher BLOB NOT NULL, x509_issuer BLOB NOT NULL, x509_subject BLOB NOT NULL, max_questions int(11) unsigned DEFAULT 0 NOT NULL, max_updates int(11) unsigned DEFAULT 0 NOT NULL, max_connections int(11) unsigned DEFAULT 0 NOT NULL, PRIMARY KEY Host (Host,User) ) engine=MyISAM CHARACTER SET utf8 COLLATE utf8_bin comment='Users and global privileges';
INSERT INTO user VALUES ('localhost','root','','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','','','','',0,0,0);
- INSERT INTO user VALUES ('localhost','','','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','','','','',0,0,0);
+INSERT INTO user VALUES ('localhost','','','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','','','','',0,0,0);
CREATE TABLE func ( name char(64) binary DEFAULT '' NOT NULL, ret tinyint(1) DEFAULT '0' NOT NULL, dl char(128) DEFAULT '' NOT NULL, type enum ('function','aggregate') COLLATE utf8_general_ci NOT NULL, PRIMARY KEY (name) ) engine=MyISAM CHARACTER SET utf8 COLLATE utf8_bin comment='User defined functions';
@@ -59,7 +60,6 @@ CREATE TABLE time_zone_transition_type ( Time_zone_id int unsigned NOT NULL,
CREATE TABLE time_zone_leap_second ( Transition_time bigint signed NOT NULL, Correction int signed NOT NULL, PRIMARY KEY TranTime (Transition_time) ) engine=MyISAM CHARACTER SET utf8 comment='Leap seconds information for time zones';
-
# Run the mysql_fix_privilege_tables.sql using "mysql --force"
--exec $MYSQL --force test < $MYSQL_FIX_PRIVILEGE_TABLES
@@ -72,7 +72,7 @@ CREATE TABLE time_zone_leap_second ( Transition_time bigint signed NOT NULL,
-- disable_query_log
# Drop all tables created by this test
-DROP TABLE db, host, user, func, plugin, tables_priv, columns_priv, procs_priv, servers, help_category, help_keyword, help_relation, help_topic, proc, time_zone, time_zone_leap_second, time_zone_name, time_zone_transition, time_zone_transition_type, general_log, slow_log, event, ndb_binlog_index, proxies_priv;
+DROP TABLE db, host, user, func, plugin, tables_priv, columns_priv, procs_priv, servers, help_category, help_keyword, help_relation, help_topic, proc, time_zone, time_zone_leap_second, time_zone_name, time_zone_transition, time_zone_transition_type, general_log, slow_log, event, proxies_priv, innodb_index_stats, innodb_table_stats, table_stats, column_stats, index_stats, roles_mapping, gtid_slave_pos;
-- enable_query_log
diff --git a/mysql-test/t/system_mysql_db_fix50030.test b/mysql-test/t/system_mysql_db_fix50030.test
index e8cfe6a6cf3..c3e7dd7b9b1 100644
--- a/mysql-test/t/system_mysql_db_fix50030.test
+++ b/mysql-test/t/system_mysql_db_fix50030.test
@@ -1,5 +1,6 @@
# Embedded server doesn't support external clients
--source include/not_embedded.inc
+--source include/have_innodb.inc
# Don't run this test if $MYSQL_FIX_PRIVILEGE_TABLES isn't set
# to the location of mysql_fix_privilege_tables.sql
@@ -78,7 +79,7 @@ INSERT INTO servers VALUES ('test','localhost','test','root','', 0,'','mysql','r
-- disable_query_log
# Drop all tables created by this test
-DROP TABLE db, host, user, func, plugin, tables_priv, columns_priv, procs_priv, servers, help_category, help_keyword, help_relation, help_topic, proc, time_zone, time_zone_leap_second, time_zone_name, time_zone_transition, time_zone_transition_type, general_log, slow_log, event, ndb_binlog_index, proxies_priv;
+DROP TABLE db, host, user, func, plugin, tables_priv, columns_priv, procs_priv, servers, help_category, help_keyword, help_relation, help_topic, proc, time_zone, time_zone_leap_second, time_zone_name, time_zone_transition, time_zone_transition_type, general_log, slow_log, event, proxies_priv, innodb_index_stats, innodb_table_stats, table_stats, column_stats, index_stats, roles_mapping, gtid_slave_pos;
-- enable_query_log
diff --git a/mysql-test/t/system_mysql_db_fix50117.test b/mysql-test/t/system_mysql_db_fix50117.test
index 69ad68faaa8..fd452668a9e 100644
--- a/mysql-test/t/system_mysql_db_fix50117.test
+++ b/mysql-test/t/system_mysql_db_fix50117.test
@@ -1,5 +1,6 @@
# Embedded server doesn't support external clients
--source include/not_embedded.inc
+--source include/have_innodb.inc
# Don't run this test if $MYSQL_FIX_PRIVILEGE_TABLES isn't set
# to the location of mysql_fix_privilege_tables.sql
@@ -83,7 +84,8 @@ CREATE TABLE IF NOT EXISTS procs_priv ( Host char(60) binary DEFAULT '' NOT NULL
CREATE TABLE IF NOT EXISTS event ( db char(64) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL default '', name char(64) CHARACTER SET utf8 NOT NULL default '', body longblob NOT NULL, definer char(77) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL default '', execute_at DATETIME default NULL, interval_value int(11) default NULL, interval_field ENUM('YEAR','QUARTER','MONTH','DAY','HOUR','MINUTE','WEEK','SECOND','MICROSECOND','YEAR_MONTH','DAY_HOUR','DAY_MINUTE','DAY_SECOND','HOUR_MINUTE','HOUR_SECOND','MINUTE_SECOND','DAY_MICROSECOND','HOUR_MICROSECOND','MINUTE_MICROSECOND','SECOND_MICROSECOND') default NULL, created TIMESTAMP NOT NULL, modified TIMESTAMP NOT NULL, last_executed DATETIME default NULL, starts DATETIME default NULL, ends DATETIME default NULL, status ENUM('ENABLED','DISABLED') NOT NULL default 'ENABLED', on_completion ENUM('DROP','PRESERVE') NOT NULL default 'DROP', sql_mode set('REAL_AS_FLOAT','PIPES_AS_CONCAT','ANSI_QUOTES','IGNORE_SPACE','NOT_USED','ONLY_FULL_GROUP_BY','NO_UNSIGNED_SUBTRACTION','NO_DIR_IN_CREATE','POSTGRESQL','ORACLE','MSSQL','DB2','MAXDB','NO_KEY_OPTIONS','NO_TABLE_OPTIONS','NO_FIELD_OPTIONS','MYSQL323','MYSQL40','ANSI','NO_AUTO_VALUE_ON_ZERO','NO_BACKSLASH_ESCAPES','STRICT_TRANS_TABLES','STRICT_ALL_TABLES','NO_ZERO_IN_DATE','NO_ZERO_DATE','INVALID_DATES','ERROR_FOR_DIVISION_BY_ZERO','TRADITIONAL','NO_AUTO_CREATE_USER','HIGH_NOT_PRECEDENCE','NO_ENGINE_SUBSTITUTION','PAD_CHAR_TO_FULL_LENGTH') DEFAULT '' NOT NULL, comment char(64) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL default '', time_zone char(64) CHARACTER SET latin1 NOT NULL DEFAULT 'SYSTEM', PRIMARY KEY (db, name) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COMMENT 'Events';
-CREATE TABLE IF NOT EXISTS ndb_binlog_index (Position BIGINT UNSIGNED NOT NULL, File VARCHAR(255) NOT NULL, epoch BIGINT UNSIGNED NOT NULL, inserts BIGINT UNSIGNED NOT NULL, updates BIGINT UNSIGNED NOT NULL, deletes BIGINT UNSIGNED NOT NULL, schemaops BIGINT UNSIGNED NOT NULL, PRIMARY KEY(epoch)) ENGINE=MYISAM;
+# MariaDB: don't:
+# CREATE TABLE IF NOT EXISTS ndb_binlog_index (Position BIGINT UNSIGNED NOT NULL, File VARCHAR(255) NOT NULL, epoch BIGINT UNSIGNED NOT NULL, inserts BIGINT UNSIGNED NOT NULL, updates BIGINT UNSIGNED NOT NULL, deletes BIGINT UNSIGNED NOT NULL, schemaops BIGINT UNSIGNED NOT NULL, PRIMARY KEY(epoch)) ENGINE=MYISAM;
# Run the mysql_fix_privilege_tables.sql using "mysql --force"
--exec $MYSQL --force test < $MYSQL_FIX_PRIVILEGE_TABLES
@@ -97,7 +99,7 @@ CREATE TABLE IF NOT EXISTS ndb_binlog_index (Position BIGINT UNSIGNED NOT NULL,
-- disable_query_log
# Drop all tables created by this test
-DROP TABLE db, host, user, func, plugin, tables_priv, columns_priv, procs_priv, servers, help_category, help_keyword, help_relation, help_topic, proc, time_zone, time_zone_leap_second, time_zone_name, time_zone_transition, time_zone_transition_type, general_log, slow_log, event, ndb_binlog_index, proxies_priv;
+DROP TABLE db, host, user, func, plugin, tables_priv, columns_priv, procs_priv, servers, help_category, help_keyword, help_relation, help_topic, proc, time_zone, time_zone_leap_second, time_zone_name, time_zone_transition, time_zone_transition_type, general_log, slow_log, event, proxies_priv, innodb_index_stats, innodb_table_stats, table_stats, column_stats, index_stats, roles_mapping, gtid_slave_pos;
-- enable_query_log
diff --git a/mysql-test/t/table_options-5867.test b/mysql-test/t/table_options-5867.test
new file mode 100644
index 00000000000..153ec08e675
--- /dev/null
+++ b/mysql-test/t/table_options-5867.test
@@ -0,0 +1,30 @@
+#
+# MDEV-5867 ALTER TABLE t1 ENGINE=InnoDB keeps bad options when t1 ENGINE is CONNECT
+#
+# verify that SHOW CREATE TABLE hides unknown options when IGNORE_BAD_TABLE_OPTIONS is not set
+
+--source include/have_example_plugin.inc
+--source include/not_embedded.inc
+
+install soname 'ha_example';
+
+set sql_mode='ignore_bad_table_options';
+create table t1 (
+ a int complex='c,f,f,f' invalid=3
+) engine=example ull=10000 str='dskj' one_or_two='one' yesno=0
+ foobar=barfoo;
+
+create table t2 (a int, key (a) some_option=2014);
+
+show create table t1;
+show create table t2;
+
+set sql_mode='';
+
+show create table t1;
+show create table t2;
+
+drop table t1, t2;
+
+uninstall soname 'ha_example';
+
diff --git a/mysql-test/t/tc_heuristic_recover.test b/mysql-test/t/tc_heuristic_recover.test
new file mode 100644
index 00000000000..5766f9b5e85
--- /dev/null
+++ b/mysql-test/t/tc_heuristic_recover.test
@@ -0,0 +1,106 @@
+# The test verifies a few server/engine recovery option combinations.
+# Specifically, MDEV-13437,13438 are concerned with no crashes
+# due to InnoDB being read-only during --tc-heuristic-recover=ROLLBACK|COMMIT.
+#
+# Initially the test commits a transaction and in the following proceeds
+# throughout some phases.
+# Within them the server is shut down and attempted to restart, to succeed
+# that in the end.
+# All this proves no crashes and effective rollback of the transaction.
+#
+--source include/have_innodb.inc
+# The test logics really requires --log-bin.
+--source include/have_binlog_format_mixed.inc
+--source include/have_debug_sync.inc
+--source include/not_embedded.inc
+
+call mtr.add_suppression("Can't init tc log");
+call mtr.add_suppression("Found 1 prepared transactions!");
+call mtr.add_suppression("Aborting");
+
+# Now take a shapshot of the last time server options.
+#
+# The "restart" expect-file facility can't be engaged because the server
+# having conflicting options may not succeed to boot up.
+# Also notice $MYSQLD_CMD is too "static" being unaware of the actual options
+# of the last (before shutdown or kill) server run.
+# That's why $MYSQLD_LAST_CMD that allows for the server new start
+# with more options appended to a stub set which is settled at this very point.
+--let $mysqld_stub_cmd= $MYSQLD_LAST_CMD
+--let $error_log= $MYSQLTEST_VARDIR/log/mysqld.1.err
+--let SEARCH_FILE= $error_log
+set debug_sync='RESET';
+
+CREATE TABLE t1 (i INT) ENGINE=InnoDB;
+SET GLOBAL innodb_flush_log_at_trx_commit=1;
+FLUSH TABLES; # we need the table post crash-restart, see MDEV-8841.
+
+# Run transaction in a separate "prey" connection
+--connect (con1,localhost,root,,)
+# The signal won't arrive though
+set debug_sync='ha_commit_trans_after_prepare WAIT_FOR go';
+--send INSERT INTO t1 VALUES (1);
+
+--connection default
+
+--let $table= information_schema.processlist
+--let $where= where state = 'debug sync point: ha_commit_trans_after_prepare'
+--let $wait_condition= SELECT count(*) = 1 FROM $table $where
+--source include/wait_condition.inc
+
+--echo # Prove that no COMMIT or ROLLBACK occurred yet.
+SELECT * FROM t1;
+SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED;
+SELECT * FROM t1;
+
+# TODO: MDEV-12700 Allow innodb_read_only startup without prior slow shutdown.
+--source include/kill_mysqld.inc
+--let $restart_parameters= --innodb-force-recovery=4
+--source include/fail_start_mysqld.inc
+
+--let SEARCH_PATTERN= was in the XA prepared state
+--source include/search_pattern_in_file++.inc
+--let SEARCH_PATTERN= Found 1 prepared transactions!
+--source include/search_pattern_in_file++.inc
+--let SEARCH_PATTERN= \\[ERROR\\] Can\\'t init tc log
+--source include/search_pattern_in_file++.inc
+
+--let $restart_parameters= --innodb-force-recovery=4 --tc-heuristic-recover=COMMIT
+--source include/fail_start_mysqld.inc
+--let SEARCH_PATTERN= was in the XA prepared state
+--source include/search_pattern_in_file++.inc
+--let SEARCH_PATTERN= Found 1 prepared transactions!
+--source include/search_pattern_in_file++.inc
+--let SEARCH_PATTERN= \\[ERROR\\] Can\\'t init tc log
+--source include/search_pattern_in_file++.inc
+--let SEARCH_PATTERN= Please restart mysqld without --tc-heuristic-recover
+--source include/search_pattern_in_file++.inc
+
+--let $restart_parameters= --tc-heuristic-recover=ROLLBACK
+--source include/fail_start_mysqld.inc
+
+--let SEARCH_PATTERN= was in the XA prepared state
+--source include/search_pattern_in_file++.inc
+--let SEARCH_PATTERN= Found 1 prepared transactions!
+--source include/search_pattern_in_file++.inc
+--let SEARCH_PATTERN= \\[ERROR\\] Can\\'t init tc log
+--source include/search_pattern_in_file++.inc
+--let SEARCH_PATTERN= Please restart mysqld without --tc-heuristic-recover
+--source include/search_pattern_in_file++.inc
+
+--let $restart_parameters=
+--source include/start_mysqld.inc
+
+--let SEARCH_PATTERN= was in the XA prepared state
+--source include/search_pattern_in_file++.inc
+--let SEARCH_PATTERN= Found 1 prepared transactions!
+--source include/search_pattern_in_file++.inc
+
+SET TRANSACTION ISOLATION LEVEL READ COMMITTED;
+SELECT * FROM t1;
+SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED;
+SELECT * FROM t1;
+#
+# Cleanup
+#
+DROP TABLE t1;
diff --git a/mysql-test/t/temp_table.test b/mysql-test/t/temp_table.test
index 92c22242cdb..1de0f086a5e 100644
--- a/mysql-test/t/temp_table.test
+++ b/mysql-test/t/temp_table.test
@@ -1,5 +1,6 @@
# mysqltest should be fixed
-- source include/not_embedded.inc
+
#
# Test of temporary tables
#
@@ -9,6 +10,30 @@ drop table if exists t1,t2;
drop view if exists v1;
--enable_warnings
+--echo #
+--echo # test basic creation of temporary tables together with normal table
+--echo #
+
+create table t1 (a int);
+create temporary table t1 AS SELECT 1;
+--error 1050
+create temporary table t1 AS SELECT 1;
+--error 1050
+create temporary table t1 (a int);
+drop temporary table t1;
+drop table t1;
+
+create temporary table t1 AS SELECT 1;
+--error 1050
+create temporary table t1 AS SELECT 1;
+--error 1050
+create temporary table t1 (a int);
+drop temporary table t1;
+
+--echo #
+--echo # Test with rename
+--echo #
+
CREATE TABLE t1 (c int not null, d char (10) not null);
insert into t1 values(1,""),(2,"a"),(3,"b");
CREATE TEMPORARY TABLE t1 (a int not null, b char (10) not null);
@@ -251,3 +276,50 @@ DROP DATABASE bug48067;
DROP TEMPORARY table bug48067.t1;
--echo End of 5.1 tests
+
+--echo #
+--echo # Test that admin statements work for temporary tables.
+--echo #
+--disable_warnings
+DROP TABLE IF EXISTS t1,t2;
+--enable_warnings
+CREATE TEMPORARY TABLE t1(a INT);
+CREATE TEMPORARY TABLE t2(b INT);
+CREATE TEMPORARY TABLE t3(c INT);
+
+INSERT INTO t1 VALUES (1), (2), (3);
+INSERT INTO t2 VALUES (11), (12), (13);
+INSERT INTO t3 VALUES (101), (102), (103);
+
+ANALYZE TABLE t1, t2, t3;
+
+INSERT INTO t1 VALUES (1), (2), (3);
+INSERT INTO t2 VALUES (11), (12), (13);
+INSERT INTO t3 VALUES (101), (102), (103);
+
+CHECK TABLE t1, t2, t3;
+
+INSERT INTO t1 VALUES (1), (2), (3);
+INSERT INTO t2 VALUES (11), (12), (13);
+INSERT INTO t3 VALUES (101), (102), (103);
+
+--replace_column 2 xxx
+CHECKSUM TABLE t1, t2, t3;
+
+INSERT INTO t1 VALUES (1), (2), (3);
+INSERT INTO t2 VALUES (11), (12), (13);
+INSERT INTO t3 VALUES (101), (102), (103);
+
+OPTIMIZE TABLE t1, t2, t3;
+
+INSERT INTO t1 VALUES (1), (2), (3);
+INSERT INTO t2 VALUES (11), (12), (13);
+INSERT INTO t3 VALUES (101), (102), (103);
+
+REPAIR TABLE t1, t2, t3;
+
+DROP TABLES t1, t2, t3;
+
+CREATE TEMPORARY TABLE t1 (a int);
+RENAME TABLE t1 TO t2;
+DROP TABLE t2;
diff --git a/mysql-test/t/temporal_literal.test b/mysql-test/t/temporal_literal.test
new file mode 100644
index 00000000000..6783b19a7d4
--- /dev/null
+++ b/mysql-test/t/temporal_literal.test
@@ -0,0 +1,346 @@
+--disable_warnings
+DROP TABLE IF EXISTS t1, t2;
+--enable_warnings
+
+SET NAMES latin1;
+
+
+--echo #
+--echo # Testing DATE literals
+--echo #
+--error ER_WRONG_VALUE
+SELECT DATE'xxxx';
+--error ER_WRONG_VALUE
+SELECT DATE'01';
+--error ER_WRONG_VALUE
+SELECT DATE'01-01';
+--error ER_WRONG_VALUE
+SELECT DATE'2001';
+--error ER_WRONG_VALUE
+SELECT DATE'2001-01';
+SELECT DATE'2001-00-00';
+SELECT DATE'2001-01-00';
+SELECT DATE'0000-00-00';
+--error ER_WRONG_VALUE
+SELECT DATE'2001-01-01 00:00:00';
+SELECT DATE'01:01:01';
+SELECT DATE'01-01-01';
+SELECT DATE'2010-01-01';
+SELECT DATE '2010-01-01';
+CREATE TABLE t1 AS SELECT DATE'2010-01-01';
+SHOW CREATE TABLE t1;
+DROP TABLE t1;
+CREATE TABLE t1 AS SELECT
+ {d'2001-01-01'},
+ { d '2001-01-01' },
+ {d'2001-01-01 10:10:10'};
+SHOW CREATE TABLE t1;
+DROP TABLE t1;
+EXPLAIN EXTENDED SELECT {d'2010-01-01'};
+EXPLAIN EXTENDED SELECT DATE'2010-01-01';
+
+--echo #
+--echo # Testing DATE literals in non-default sql_mode
+--echo #
+SET sql_mode=no_zero_in_date;
+--error ER_WRONG_VALUE
+SELECT DATE'2001-00-00';
+--error ER_WRONG_VALUE
+SELECT DATE'2001-01-00';
+SELECT DATE'0000-00-00';
+
+SET sql_mode=no_zero_date;
+--error ER_WRONG_VALUE
+SELECT DATE'0000-00-00';
+SET sql_mode=default;
+
+--echo #
+--echo # Testing TIME literals
+--echo #
+--error ER_WRONG_VALUE
+SELECT TIME'xxxx';
+--error ER_WRONG_VALUE
+SELECT TIME'900:00:00';
+--error ER_WRONG_VALUE
+SELECT TIME'-900:00:00';
+SELECT TIME'1 24:00:00';
+SELECT TIME'30 24:00:00';
+--error ER_WRONG_VALUE
+SELECT TIME'0000-00-00 00:00:00';
+--error ER_WRONG_VALUE
+SELECT TIME'40 24:00:00';
+SELECT TIME'10';
+SELECT TIME'10:10';
+SELECT TIME'10:11.12';
+SELECT TIME'10:10:10';
+SELECT TIME'10:10:10.';
+SELECT TIME'10:10:10.1';
+SELECT TIME'10:10:10.12';
+SELECT TIME'10:10:10.123';
+SELECT TIME'10:10:10.1234';
+SELECT TIME'10:10:10.12345';
+SELECT TIME'10:10:10.123456';
+SELECT TIME'-10:00:00';
+SELECT TIME '10:11:12';
+CREATE TABLE t1 AS SELECT
+ TIME'10:10:10',
+ TIME'10:10:10.',
+ TIME'10:10:10.1',
+ TIME'10:10:10.12',
+ TIME'10:10:10.123',
+ TIME'10:10:10.1234',
+ TIME'10:10:10.12345',
+ TIME'10:10:10.123456';
+SHOW CREATE TABLE t1;
+DROP TABLE t1;
+CREATE TABLE t1 AS SELECT
+ {t'10:10:10'},
+ { t '10:10:10' },
+ {t'10:10:10.'},
+ {t'10:10:10.123456'},
+ {t'2001-01-01'};
+SHOW CREATE TABLE t1;
+DROP TABLE t1;
+EXPLAIN EXTENDED SELECT {t'10:01:01'};
+EXPLAIN EXTENDED SELECT TIME'10:01:01';
+
+
+--echo #
+--echo # Testing TIMESTAMP literals
+--echo #
+--error ER_WRONG_VALUE
+SELECT TIMESTAMP'xxxx';
+--error ER_WRONG_VALUE
+SELECT TIMESTAMP'2010';
+--error ER_WRONG_VALUE
+SELECT TIMESTAMP'2010-01';
+--error ER_WRONG_VALUE
+SELECT TIMESTAMP'2010-01-01';
+SELECT TIMESTAMP'2010-01-01 00';
+SELECT TIMESTAMP'2010-01-01 00:01';
+SELECT TIMESTAMP'2010-01-01 10:10:10';
+SELECT TIMESTAMP'2010-01-01 10:10:10.';
+SELECT TIMESTAMP'2010-01-01 10:10:10.1';
+SELECT TIMESTAMP'2010-01-01 10:10:10.12';
+SELECT TIMESTAMP'2010-01-01 10:10:10.123';
+SELECT TIMESTAMP'2010-01-01 10:10:10.1234';
+SELECT TIMESTAMP'2010-01-01 10:10:10.12345';
+SELECT TIMESTAMP'2010-01-01 10:10:10.123456';
+SELECT TIMESTAMP '2010-01-01 10:20:30';
+CREATE TABLE t1 AS SELECT
+ TIMESTAMP'2010-01-01 10:10:10',
+ TIMESTAMP'2010-01-01 10:10:10.',
+ TIMESTAMP'2010-01-01 10:10:10.1',
+ TIMESTAMP'2010-01-01 10:10:10.12',
+ TIMESTAMP'2010-01-01 10:10:10.123',
+ TIMESTAMP'2010-01-01 10:10:10.1234',
+ TIMESTAMP'2010-01-01 10:10:10.12345',
+ TIMESTAMP'2010-01-01 10:10:10.123456';
+SHOW CREATE TABLE t1;
+DROP TABLE t1;
+CREATE TABLE t1 AS SELECT
+ {ts'2001-01-01 10:10:10'},
+ { ts '2001-01-01 10:10:10' },
+ {ts'2001-01-01 10:10:10.'},
+ {ts'2001-01-01 10:10:10.123456'},
+ {ts'2001-01-01'};
+SHOW CREATE TABLE t1;
+DROP TABLE t1;
+EXPLAIN EXTENDED SELECT {ts'2010-01-01 10:10:10'};
+EXPLAIN EXTENDED SELECT TIMESTAMP'2010-01-01 10:10:10';
+
+--echo #
+--echo # Testing nanosecond rounding for TIMESTAMP literals with bad dates
+--echo #
+SELECT TIMESTAMP'2001-00-00 00:00:00.999999';
+SELECT TIMESTAMP'2001-00-01 00:00:00.999999';
+SELECT TIMESTAMP'2001-01-00 00:00:00.999999';
+--disable_ps_protocol
+SELECT TIMESTAMP'2001-00-00 00:00:00.9999999';
+SELECT TIMESTAMP'2001-00-01 00:00:00.9999999';
+SELECT TIMESTAMP'2001-01-00 00:00:00.9999999';
+--enable_ps_protocol
+
+--echo #
+--echo # String literal with bad dates and nanoseconds to DATETIME(N)
+--echo #
+CREATE TABLE t1 (a DATETIME(6));
+INSERT INTO t1 VALUES ('2001-00-00 00:00:00.9999999');
+INSERT INTO t1 VALUES ('2001-00-01 00:00:00.9999999');
+INSERT INTO t1 VALUES ('2001-01-00 00:00:00.9999999');
+SELECT * FROM t1;
+DROP TABLE t1;
+CREATE TABLE t1 (a DATETIME(5));
+INSERT INTO t1 VALUES ('2001-00-00 00:00:00.9999999');
+INSERT INTO t1 VALUES ('2001-00-01 00:00:00.9999999');
+INSERT INTO t1 VALUES ('2001-01-00 00:00:00.9999999');
+SELECT * FROM t1;
+DROP TABLE t1;
+CREATE TABLE t1 (a DATETIME);
+INSERT INTO t1 VALUES ('2001-00-00 00:00:00.9999999');
+INSERT INTO t1 VALUES ('2001-00-01 00:00:00.9999999');
+INSERT INTO t1 VALUES ('2001-01-00 00:00:00.9999999');
+SELECT * FROM t1;
+DROP TABLE t1;
+
+--echo #
+--echo # Testing Item_date_literal::eq
+--echo #
+CREATE TABLE t1 (a DATE);
+INSERT INTO t1 VALUES ('2001-01-01'),('2003-01-01');
+SELECT * FROM t1 WHERE a BETWEEN DATE'2001-01-01' AND DATE'2002-01-01';
+SELECT DATE'2001-01-01' FROM t1 GROUP BY DATE'2001-01-01';
+DROP TABLE t1;
+
+--echo #
+--echo # TIME literals in no-zero date context
+--echo #
+SET timestamp=unix_timestamp('2001-02-03 10:20:30');
+SELECT TO_DAYS(TIME'00:00:00');
+SELECT TO_SECONDS(TIME'00:00:00');
+SELECT DAYOFYEAR(TIME'00:00:00');
+SELECT WEEK(TIME'00:00:00');
+SELECT YEARWEEK(TIME'00:00:00');
+SELECT WEEKDAY(TIME'00:00:00');
+SELECT CONVERT_TZ(TIME'00:00:00','+00:00','+01:00');
+SELECT DATE_ADD(TIME'00:00:00', INTERVAL 1 HOUR);
+SELECT TIMESTAMPDIFF(SECOND,TIME'00:00:00', TIME'00:00:00');
+SET timestamp=DEFAULT;
+
+--echo #
+--echo # Testing Item_func::fix_fields()
+--echo #
+--error ER_WRONG_ARGUMENTS
+SELECT 'a' LIKE 'a' ESCAPE DATE'2001-01-01';
+--error ER_WRONG_ARGUMENTS
+SELECT 'a' LIKE 'a' ESCAPE TIMESTAMP'2001-01-01 00:00:00';
+--error ER_WRONG_ARGUMENTS
+SELECT 'a' LIKE 'a' ESCAPE TIME'00:00:00';
+
+--echo #
+--echo # MDEV-4871 Temporal literals do not accept nanoseconds
+--echo #
+--disable_ps_protocol
+SELECT TIME'10:10:10.1234567';
+--enable_ps_protocol
+SELECT TIME('10:10:10.1234567');
+--error ER_WRONG_VALUE
+SELECT TIME'10:10:10.123456xyz';
+--error ER_WRONG_VALUE
+SELECT TIME'10:10:10.1234567xyz';
+SELECT TIME('10:10:10.123456xyz');
+SELECT TIME('10:10:10.1234567xyz');
+
+--disable_ps_protocol
+SELECT TIMESTAMP'2001-01-01 10:10:10.1234567';
+--enable_ps_protocol
+SELECT TIMESTAMP('2001-01-01 10:10:10.1234567');
+--error ER_WRONG_VALUE
+SELECT TIMESTAMP'2001-01-01 10:10:10.123456xyz';
+--error ER_WRONG_VALUE
+SELECT TIMESTAMP'2001-01-01 10:10:10.1234567xyz';
+SELECT TIMESTAMP('2001-01-01 10:10:10.123456xyz');
+SELECT TIMESTAMP('2001-01-01 10:10:10.1234567xyz');
+
+CREATE TABLE t1 (a TIME(6));
+INSERT INTO t1 VALUES (TIME'10:20:30.1234567');
+INSERT INTO t1 VALUES (TIME('10:20:30.1234567'));
+SELECT * FROM t1;
+DROP TABLE t1;
+
+--echo #
+--echo # MDEV-5969 Crash in prepared statement with NO_ZERO_IN_DATE and ROLLUP
+--echo #
+CREATE TABLE t1
+(
+ year INT NOT NULL,
+ product VARCHAR(32) NOT NULL,
+ profit INT
+);
+INSERT INTO t1 VALUES ('2001','car',101);
+INSERT INTO t1 VALUES ('2001','gas',102);
+INSERT INTO t1 VALUES ('2001','toy',103);
+INSERT INTO t1 VALUES ('2002','car',201);
+INSERT INTO t1 VALUES ('2002','gas',202);
+INSERT INTO t1 VALUES ('2002','toy',203);
+SET sql_mode=DEFAULT;
+PREPARE stmt FROM "SELECT DATE'2001-00-00' AS c,year, SUM(profit) FROM t1 GROUP BY c,year WITH ROLLUP";
+EXECUTE stmt;
+SET sql_mode='no_zero_in_date';
+EXECUTE stmt;
+SET sql_mode=DEFAULT;
+DROP TABLE t1;
+
+--echo #
+--echo # MDEV-5971 Asymmetry between CAST(DATE'2001-00-00') to INT and TO CHAR in prepared statements
+--echo #
+SET sql_mode=DEFAULT;
+PREPARE stmt FROM "SELECT CAST(DATE'2001-00-00' AS SIGNED) AS c";
+SET sql_mode='no_zero_in_date';
+EXECUTE stmt;
+SET sql_mode=DEFAULT;
+PREPARE stmt FROM "SELECT CAST(DATE'2001-00-00' AS CHAR) AS c";
+SET sql_mode='no_zero_in_date';
+EXECUTE stmt;
+SET sql_mode=DEFAULT;
+PREPARE stmt FROM "SELECT CAST(DATE'2001-00-00' AS DECIMAL(30,0)) AS c";
+SET sql_mode='no_zero_in_date';
+EXECUTE stmt;
+SET sql_mode=DEFAULT;
+PREPARE stmt FROM "SELECT CAST(DATE'2001-00-00' AS DOUBLE) AS c";
+SET sql_mode='no_zero_in_date';
+EXECUTE stmt;
+
+--echo #
+--echo # Zero month or zero day automatically mean NULL flag, no matter SQL_MODE is.
+--echo # Only zero year is OK for NOT NULL.
+--echo #
+
+SET sql_mode=DEFAULT;
+PREPARE stmt FROM "CREATE TABLE t1 AS SELECT CAST(DATE'2001-00-00' AS CHAR) AS c";
+EXECUTE stmt;
+SHOW COLUMNS FROM t1;
+SELECT * FROM t1;
+DROP TABLE t1;
+SET sql_mode='no_zero_in_date';
+EXECUTE stmt;
+SHOW COLUMNS FROM t1;
+SELECT * FROM t1;
+DROP TABLE t1;
+SET sql_mode=DEFAULT;
+
+CREATE TABLE t1 AS SELECT
+ DATE'2001-01-01',
+ DATE'0000-01-01',
+ DATE'2001-00-00',
+ DATE'2001-00-01',
+ DATE'2001-01-00';
+SHOW CREATE TABLE t1;
+DROP TABLE t1;
+
+CREATE TABLE t1 AS SELECT
+ TIMESTAMP'2001-01-01 00:00:00',
+ TIMESTAMP'0000-01-01 00:00:00',
+ TIMESTAMP'2001-00-00 00:00:00',
+ TIMESTAMP'2001-00-01 00:00:00',
+ TIMESTAMP'2001-01-00 00:00:00';
+SHOW CREATE TABLE t1;
+DROP TABLE t1;
+
+--echo #
+--echo # MDEV-5975 Prepared statements with DATE literals do not honor NO_ZERO_IN_DATE
+--echo #
+SET sql_mode=DEFAULT;
+PREPARE stmt FROM "SELECT (SELECT DATE'2001-00-00') AS c";
+EXECUTE stmt;
+SET sql_mode='no_zero_in_date';
+EXECUTE stmt;
+DEALLOCATE PREPARE stmt;
+
+SET sql_mode=DEFAULT;
+PREPARE stmt FROM "SELECT (SELECT TIMESTAMP'2001-00-00 10:20:30') AS c";
+EXECUTE stmt;
+SET sql_mode='no_zero_in_date';
+EXECUTE stmt;
+DEALLOCATE PREPARE stmt;
+SET sql_mode=DEFAULT;
diff --git a/mysql-test/t/timezone2.test b/mysql-test/t/timezone2.test
index 2d61c7631f2..7a38610ad95 100644
--- a/mysql-test/t/timezone2.test
+++ b/mysql-test/t/timezone2.test
@@ -294,8 +294,10 @@ DROP TABLE t1;
--echo # MDEV-4653 Wrong result for CONVERT_TZ(TIME('00:00:00'),'+00:00','+7:5')
--echo #
+SET timestamp=unix_timestamp('2001-02-03 10:20:30');
SELECT CONVERT_TZ(TIME('00:00:00'),'+00:00','+7:5');
SELECT CONVERT_TZ(TIME('2010-01-01 00:00:00'),'+00:00','+7:5');
+SET timestamp=DEFAULT;
--echo #
--echo # MDEV-5506 safe_mutex: Trying to lock unitialized mutex at safemalloc.c on server shutdown after SELECT with CONVERT_TZ
diff --git a/mysql-test/t/tmp_table_count-7586.test b/mysql-test/t/tmp_table_count-7586.test
new file mode 100644
index 00000000000..e7bac127815
--- /dev/null
+++ b/mysql-test/t/tmp_table_count-7586.test
@@ -0,0 +1,56 @@
+# MDEV-7586 regression test.
+# Test if created_tmp_tables status variable is correctly incremented.
+--source include/have_perfschema.inc
+--source include/not_embedded.inc
+
+create table t2 (a int);
+insert into t2 values (1),(2),(3);
+create view v2 as select a from t2;
+
+flush status;
+select * from v2;
+show status like '%Created_tmp%';
+
+explain select * from v2;
+
+select * from (select * from t2) T1;
+show status like '%Created_tmp%';
+
+explain select * from (select * from t2) T1;
+
+
+drop view v2;
+drop table t2;
+
+
+--disable_ps_protocol
+
+CREATE TABLE t1(a int);
+INSERT INTO t1 values(1),(2);
+CREATE TABLE t2(a int);
+INSERT INTO t2 values(1),(2);
+
+EXPLAIN SELECT * FROM t1 WHERE a IN (SELECT * FROM t2 GROUP BY a HAVING a > 1);
+truncate table performance_schema.events_statements_history_long;
+flush status;
+CREATE TABLE t3 SELECT * FROM t1 WHERE a IN (SELECT * FROM t2 GROUP BY a HAVING a > 1);
+--echo # Performance schema should be the same as "Created_tmp_tables" variable below
+select sum(created_tmp_tables) from performance_schema.events_statements_history_long;
+show status like '%Created_tmp%';
+drop table t3;
+
+EXPLAIN SELECT * FROM t1 WHERE a IN (SELECT * FROM t2 GROUP BY a);
+truncate table performance_schema.events_statements_history_long;
+flush status;
+CREATE TABLE t3 SELECT * FROM t1 WHERE a IN (SELECT * FROM t2 GROUP BY a);
+--echo # Performance schema should be the same as "Created_tmp_tables" variable below
+select sum(created_tmp_tables) from performance_schema.events_statements_history_long;
+show status like '%Created_tmp%';
+
+drop table t1,t2,t3;
+
+truncate table performance_schema.events_statements_history_long;
+flush status;
+--echo # Performance schema should be the same as "Created_tmp_tables" variable below
+select sum(created_tmp_tables) from performance_schema.events_statements_history_long;
+show status like '%Created_tmp%';
diff --git a/mysql-test/t/trans_read_only-master.opt b/mysql-test/t/trans_read_only-master.opt
new file mode 100644
index 00000000000..cf84816ec90
--- /dev/null
+++ b/mysql-test/t/trans_read_only-master.opt
@@ -0,0 +1 @@
+--transaction-read-only=true
diff --git a/mysql-test/t/trans_read_only.test b/mysql-test/t/trans_read_only.test
new file mode 100644
index 00000000000..f50fb7db376
--- /dev/null
+++ b/mysql-test/t/trans_read_only.test
@@ -0,0 +1,50 @@
+--source include/not_embedded.inc
+
+--echo #
+--echo # WL#5968: Implement START TRANSACTION READ (WRITE|ONLY);
+--echo #
+
+--echo #
+--echo # Test9: The --transaction-read-only startup option.
+
+--echo # Check that the option was set by the .opt file.
+SELECT @@tx_read_only;
+
+--echo # Also for new connections. Switching to con1
+connect (con1, localhost, root);
+SELECT @@tx_read_only;
+SET SESSION TRANSACTION READ WRITE;
+SELECT @@tx_read_only;
+disconnect con1;
+--source include/wait_until_disconnected.inc
+
+--echo # Connection default
+connection default;
+SELECT @@tx_read_only;
+
+
+--echo #
+--echo # Test 10: SET TRANSACTION / START TRANSACTION + implicit commit.
+
+SET SESSION TRANSACTION READ WRITE;
+--disable_ps_protocol
+SET TRANSACTION READ ONLY;
+--echo # Since DDL does implicit commit before starting, SET TRANSACTION
+--echo # will have no effect because the "next" transaction will already
+--echo # be over before the DDL statement starts.
+CREATE TABLE t1 (a INT);
+
+START TRANSACTION READ ONLY;
+--echo # The same happens with START TRANSACTION
+DROP TABLE t1;
+--enable_ps_protocol
+
+--echo #
+--echo # Test 11: INSERT DELAYED
+
+CREATE TABLE t1(a INT);
+START TRANSACTION READ ONLY;
+--error ER_CANT_EXECUTE_IN_READ_ONLY_TRANSACTION
+INSERT DELAYED INTO t1 VALUES (1);
+COMMIT;
+DROP TABLE t1;
diff --git a/mysql-test/t/trigger.test b/mysql-test/t/trigger.test
index ea4ede6da41..4a1a3a6167c 100644
--- a/mysql-test/t/trigger.test
+++ b/mysql-test/t/trigger.test
@@ -1410,7 +1410,7 @@ CREATE TABLE t1(c INT);
CREATE TABLE t2(c INT);
--error ER_WRONG_STRING_LENGTH
-CREATE DEFINER=1234567890abcdefGHIKL@localhost
+CREATE DEFINER=longer_than_80_456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789@localhost
TRIGGER t1_bi BEFORE INSERT ON t1 FOR EACH ROW SET @a = 1;
--error ER_WRONG_STRING_LENGTH
diff --git a/mysql-test/t/truncate_badse.test b/mysql-test/t/truncate_badse.test
new file mode 100644
index 00000000000..71545cab11a
--- /dev/null
+++ b/mysql-test/t/truncate_badse.test
@@ -0,0 +1,15 @@
+#
+# test what TRUNCATE TABLE does, if the table was created in
+# now-unknown storage engine.
+#
+--source include/have_example_plugin.inc
+install plugin example soname 'ha_example';
+create table t1 (a int) engine=example;
+select 1;
+uninstall plugin example;
+flush tables;
+select count(*) from information_schema.plugins where plugin_name='example';
+--error ER_UNKNOWN_STORAGE_ENGINE
+truncate table t1;
+drop table t1;
+
diff --git a/mysql-test/t/truncate_coverage.test b/mysql-test/t/truncate_coverage.test
index 135935b53b3..6f5c773ac6a 100644
--- a/mysql-test/t/truncate_coverage.test
+++ b/mysql-test/t/truncate_coverage.test
@@ -40,7 +40,7 @@ HANDLER t1 OPEN;
--connection default
let $ID= `SELECT @id := CONNECTION_ID()`;
LOCK TABLE t1 WRITE;
-SET DEBUG_SYNC='mdl_upgrade_shared_lock_to_exclusive SIGNAL waiting';
+SET DEBUG_SYNC='mdl_upgrade_lock SIGNAL waiting';
send TRUNCATE TABLE t1;
#
# Get the default connection ID into a variable in an invisible statement.
@@ -92,7 +92,7 @@ HANDLER t1 OPEN;
--echo # connection default
--connection default
LOCK TABLE t1 WRITE;
-SET DEBUG_SYNC='mdl_upgrade_shared_lock_to_exclusive SIGNAL waiting';
+SET DEBUG_SYNC='mdl_upgrade_lock SIGNAL waiting';
send TRUNCATE TABLE t1;
#
# Remove datafile.
diff --git a/mysql-test/t/type_binary.test b/mysql-test/t/type_binary.test
index 4d5a5312472..b583e257aa9 100644
--- a/mysql-test/t/type_binary.test
+++ b/mysql-test/t/type_binary.test
@@ -100,3 +100,29 @@ select hex(f2), hex(f3) from t1;
drop table t1;
--echo End of 5.0 tests
+
+--echo #
+--echo # Start of 10.0 tests
+--echo #
+
+--echo #
+--echo # MDEV-8472 BINARY, VARBINARY and BLOB return different warnings on CAST to DECIMAL
+--echo #
+SET NAMES utf8;
+CREATE TABLE t1 (a BINARY(30));
+INSERT INTO t1 VALUES ('1äÖüß@µ*$');
+SELECT CAST(a AS DECIMAL) FROM t1;
+DROP TABLE t1;
+CREATE TABLE t1 (a VARBINARY(30));
+INSERT INTO t1 VALUES ('1äÖüß@µ*$');
+SELECT CAST(a AS DECIMAL) FROM t1;
+DROP TABLE t1;
+CREATE TABLE t1 (a BLOB);
+INSERT INTO t1 VALUES ('1äÖüß@µ*$');
+SELECT CAST(a AS DECIMAL) FROM t1;
+DROP TABLE t1;
+
+--echo #
+--echo # End of 10.0 tests
+--echo #
+
diff --git a/mysql-test/t/type_bit.test b/mysql-test/t/type_bit.test
index 8bedf9357ef..2ca608e76ff 100644
--- a/mysql-test/t/type_bit.test
+++ b/mysql-test/t/type_bit.test
@@ -362,11 +362,11 @@ f2 bit(14) NOT NULL default b'11110000111100'
SHOW CREATE TABLE t1;
DROP TABLE t1;
---error ER_INVALID_DEFAULT
CREATE TABLE IF NOT EXISTS t1 (
f1 bit(2) NOT NULL default b''
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci;
-
+SHOW CREATE TABLE t1;
+DROP TABLE t1;
#
# Bug#31399 Wrong query result when doing join buffering over BIT fields
diff --git a/mysql-test/t/type_bit_innodb.test b/mysql-test/t/type_bit_innodb.test
index 7ba90bf08fa..27eaeda0f99 100644
--- a/mysql-test/t/type_bit_innodb.test
+++ b/mysql-test/t/type_bit_innodb.test
@@ -148,3 +148,12 @@ select * from t1;
drop table t1;
--echo End of 5.0 tests
+
+#
+# MDEV-6052 Inconsistent results with bit type
+#
+create table t1(f1 bit(2) not null default b'10',f2 bit(14) not null default b'11110000111100');
+insert into t1 (f1) values (default);
+insert into t1 values (b'',b''),('','');
+select hex(f1), hex(f2) from t1;
+drop table t1;
diff --git a/mysql-test/t/type_blob.test b/mysql-test/t/type_blob.test
index d5f6fc6ed32..a20173e231a 100644
--- a/mysql-test/t/type_blob.test
+++ b/mysql-test/t/type_blob.test
@@ -112,7 +112,7 @@ select distinct t from t1 order by t;
select distinct b from t1 order by b;
select t from t1 group by t;
select b from t1 group by b;
-set option sql_big_tables=1;
+set big_tables=1;
select distinct t from t1;
select distinct b from t1;
select distinct t from t1 order by t;
@@ -123,7 +123,7 @@ select distinct c from t1 order by c;
select distinct d from t1 order by d;
select c from t1 group by c;
select d from t1 group by d;
-set option sql_big_tables=0;
+set big_tables=0;
select distinct * from t1;
select t,count(*) from t1 group by t;
select b,count(*) from t1 group by b;
diff --git a/mysql-test/t/type_date.test b/mysql-test/t/type_date.test
index 832e72520ce..91f9774969b 100644
--- a/mysql-test/t/type_date.test
+++ b/mysql-test/t/type_date.test
@@ -310,7 +310,6 @@ SELECT
DATE('0'),
IFNULL(DATE('0'),CURRENT_DATE) AS d1,
DATE('20011107')>IFNULL(DATE('0'),CURRENT_DATE) AS cmp;
-SET @@timestamp=DEFAULT;
--echo #
--echo # MDEV-5041 Inserting a TIME with hour>24 into a DATETIME column produces a wrong value
@@ -339,7 +338,7 @@ DELIMITER ;|
call test5041();
drop procedure test5041;
-
+SET @@timestamp=DEFAULT;
--echo #
--echo # End of 5.3 tests
--echo #
@@ -407,3 +406,11 @@ DROP TABLE t1,t2;
SELECT
LEAST(COALESCE(DATE(NULL), DATE(NULL)), COALESCE(DATE(NULL), DATE(NULL))) AS d0,
LEAST(IFNULL(DATE(NULL), DATE(NULL)), IFNULL(DATE(NULL), DATE(NULL))) AS d1;
+
+--echo #
+--echo # MDEV-9511 Valgrind warnings 'Invalid read' in Field_newdate::cmp and Field_newdate::val_str
+--echo #
+CREATE TABLE t1 (f1 DATE, f2 VARCHAR(1));
+INSERT INTO t1 VALUES ('2003-04-27','a'),('1900-01-01','a');
+SELECT GROUP_CONCAT(f2, IF(f1, f2, f1), f1 ORDER BY 2,1,3) FROM t1;
+DROP TABLE t1;
diff --git a/mysql-test/t/type_datetime.test b/mysql-test/t/type_datetime.test
index f69b44f9892..3f96673c43f 100644
--- a/mysql-test/t/type_datetime.test
+++ b/mysql-test/t/type_datetime.test
@@ -466,10 +466,12 @@ DROP TABLE t1;
#
# MDEV-4281 Assertion `maybe_null && item->null_value' fails in make_sortkey on CASE with different return types, GROUP_CONCAT, GROUP BY
#
+SET timestamp=UNIX_TIMESTAMP('2001-01-01 10:20:30');
create table t1 (d date, t time) engine=myisam;
insert into t1 values ('2000-12-03','22:55:23'),('2008-05-03','10:19:31');
select case when d = '2012-12-12' then d else t end as cond, group_concat( d ) from t1 group by cond;
drop table t1;
+SET timestamp=DEFAULT;
--echo #
--echo # Semantics of the condition <non-nullable datetime field> IS NULL
@@ -495,6 +497,7 @@ SELECT CONVERT_TZ(GREATEST(TIMESTAMP('2021-00-00'),TIMESTAMP('2022-00-00')),'+00
--echo #
--echo # MDEV-5041 Inserting a TIME with hour>24 into a DATETIME column produces a wrong value
--echo #
+SET @@timestamp=UNIX_TIMESTAMP('2013-08-19 20:30:00');
SELECT CAST(TIME('-800:20:30') AS DATETIME);
SELECT CAST(TIME('800:20:30') AS DATETIME);
SELECT CAST(TIME('33 08:20:30') AS DATETIME);
@@ -518,6 +521,7 @@ END;|
DELIMITER ;|
call test5041();
drop procedure test5041;
+SET @@timestamp=DEFAULT;
--echo #
--echo # MDEV-6097 Inconsistent results for CAST(int,decimal,double AS DATETIME)
@@ -527,7 +531,6 @@ SELECT
CAST(010203101112.2 AS DATETIME(1)) AS c2,
CAST(010203101112.2+0e0 AS DATETIME(1)) AS c3;
-
--echo End of 5.3 tests
--echo #
@@ -608,5 +611,13 @@ DEALLOCATE PREPARE stmt1;
DROP TABLE t1,t2;
--echo #
+--echo # MDEV-9374 having '2015-01-01 01:00:00.000001' > coalesce(NULL) returns true
+--echo #
+CREATE TABLE t1 (c1 DATETIME(0));
+INSERT INTO t1 VALUES (NULL);
+SELECT * FROM t1 HAVING '2015-01-01 01:00:00.000001' > COALESCE(c1);
+DROP TABLE t1;
+
+--echo #
--echo # End of 5.5 tests
--echo #
diff --git a/mysql-test/t/type_enum.test b/mysql-test/t/type_enum.test
index 5b0b70631a5..9ce34c0b55b 100644
--- a/mysql-test/t/type_enum.test
+++ b/mysql-test/t/type_enum.test
@@ -236,3 +236,124 @@ SELECT AVG(f1) FROM t1;
drop table t1;
--echo End of 5.3 tests
+
+--echo #
+--echo # Start of 10.0 tests
+--echo #
+
+--echo #
+--echo # MDEV-6950 Bad results with joins comparing DATE/DATETIME and INT/ENUM/VARCHAR columns
+--echo #
+
+CREATE TABLE t1 (c1 DATE PRIMARY KEY);
+INSERT INTO t1 VALUES ('2001-01-01');
+CREATE TABLE t2 (c1 ENUM('2001-01-01','2001/01/01'));
+INSERT INTO t2 VALUES ('2001-01-01');
+INSERT INTO t2 VALUES ('2001/01/01');
+SELECT t1.* FROM t1,t2 WHERE t1.c1=t2.c1;
+SELECT t1.* FROM t1 LEFT JOIN t2 ON t1.c1=t2.c1;
+ALTER TABLE t2 ADD PRIMARY KEY(c1);
+SELECT t1.* FROM t1,t2 WHERE t1.c1=t2.c1;
+EXPLAIN SELECT t1.* FROM t1,t2 WHERE t1.c1=t2.c1;
+SELECT t1.* FROM t1 LEFT JOIN t2 USING (c1);
+--echo # t2 should NOT be eliminated
+EXPLAIN SELECT t1.* FROM t1 LEFT JOIN t2 USING (c1);
+DROP TABLE t1, t2;
+
+--echo #
+--echo # MDEV-6978 Bad results with join comparing case insensitive VARCHAR/ENUM/SET expression to a _bin ENUM column
+--echo #
+CREATE TABLE t1 (c1 ENUM('a') CHARACTER SET latin1 PRIMARY KEY);
+INSERT INTO t1 VALUES ('a');
+CREATE TABLE t2 (c1 ENUM('a','A') CHARACTER SET latin1 COLLATE latin1_bin);
+INSERT INTO t2 VALUES ('a'),('A');
+SELECT t1.* FROM t1 JOIN t2 ON t1.c1 COLLATE latin1_swedish_ci=t2.c1;
+SELECT t1.* FROM t1 LEFT JOIN t2 ON t1.c1 COLLATE latin1_swedish_ci=t2.c1;
+ALTER TABLE t2 ADD PRIMARY KEY(c1);
+SELECT t1.* FROM t1 JOIN t2 ON t1.c1 COLLATE latin1_swedish_ci=t2.c1;
+SELECT t1.* FROM t1 LEFT JOIN t2 ON t1.c1 COLLATE latin1_swedish_ci=t2.c1;
+--echo # t2 should NOT be eliminated
+EXPLAIN SELECT t1.* FROM t1 LEFT JOIN t2 ON t1.c1 COLLATE latin1_swedish_ci=t2.c1;
+DROP TABLE IF EXISTS t1,t2;
+
+CREATE TABLE t1 (c1 SET('a') CHARACTER SET latin1 PRIMARY KEY);
+INSERT INTO t1 VALUES ('a');
+CREATE TABLE t2 (c1 ENUM('a','A') CHARACTER SET latin1 COLLATE latin1_bin);
+INSERT INTO t2 VALUES ('a'),('A');
+SELECT t1.* FROM t1 JOIN t2 ON t1.c1 COLLATE latin1_swedish_ci=t2.c1;
+SELECT t1.* FROM t1 LEFT JOIN t2 ON t1.c1 COLLATE latin1_swedish_ci=t2.c1;
+ALTER TABLE t2 ADD PRIMARY KEY(c1);
+SELECT t1.* FROM t1 JOIN t2 ON t1.c1 COLLATE latin1_swedish_ci=t2.c1;
+SELECT t1.* FROM t1 LEFT JOIN t2 ON t1.c1 COLLATE latin1_swedish_ci=t2.c1;
+--echo # t2 should NOT be eliminated
+EXPLAIN SELECT t1.* FROM t1 LEFT JOIN t2 ON t1.c1 COLLATE latin1_swedish_ci=t2.c1;
+DROP TABLE IF EXISTS t1,t2;
+
+CREATE TABLE t1 (c1 VARCHAR(10) CHARACTER SET latin1 PRIMARY KEY);
+INSERT INTO t1 VALUES ('a');
+CREATE TABLE t2 (c1 ENUM('a','A') CHARACTER SET latin1 COLLATE latin1_bin);
+INSERT INTO t2 VALUES ('a'),('A');
+SELECT t1.* FROM t1 JOIN t2 ON t1.c1 COLLATE latin1_swedish_ci=t2.c1;
+SELECT t1.* FROM t1 LEFT JOIN t2 ON t1.c1 COLLATE latin1_swedish_ci=t2.c1;
+ALTER TABLE t2 ADD PRIMARY KEY(c1);
+SELECT t1.* FROM t1 JOIN t2 ON t1.c1 COLLATE latin1_swedish_ci=t2.c1;
+SELECT t1.* FROM t1 LEFT JOIN t2 ON t1.c1 COLLATE latin1_swedish_ci=t2.c1;
+--echo # t2 should NOT be eliminated
+EXPLAIN SELECT t1.* FROM t1 LEFT JOIN t2 ON t1.c1 COLLATE latin1_swedish_ci=t2.c1;
+DROP TABLE IF EXISTS t1,t2;
+
+--echo #
+--echo # MDEV-6991 GROUP_MIN_MAX optimization is erroneously applied in some cases
+--echo #
+CREATE TABLE t1 (id INT NOT NULL, a ENUM('04','03','02','01')) ENGINE=MyISAM;
+INSERT INTO t1 VALUES (1,'01');
+INSERT INTO t1 VALUES (1,'02');
+INSERT INTO t1 VALUES (1,'03');
+INSERT INTO t1 VALUES (1,'04');
+INSERT INTO t1 VALUES (2,'01');
+INSERT INTO t1 VALUES (2,'02');
+INSERT INTO t1 VALUES (2,'03');
+INSERT INTO t1 VALUES (2,'04');
+INSERT INTO t1 VALUES (3,'01');
+INSERT INTO t1 VALUES (3,'02');
+INSERT INTO t1 VALUES (3,'03');
+INSERT INTO t1 VALUES (3,'04');
+INSERT INTO t1 VALUES (4,'01');
+INSERT INTO t1 VALUES (4,'02');
+INSERT INTO t1 VALUES (4,'03');
+INSERT INTO t1 VALUES (4,'04');
+SELECT id,MIN(a),MAX(a) FROM t1 WHERE a>='02' GROUP BY id;
+SELECT id,MIN(a),MAX(a) FROM t1 WHERE a<=3 GROUP BY id;
+ALTER TABLE t1 ADD KEY(id,a);
+SELECT id,MIN(a),MAX(a) FROM t1 WHERE a>='02' GROUP BY id;
+--echo # Should NOT use group_min_max optimization
+EXPLAIN SELECT id,MIN(a),MAX(a) FROM t1 WHERE a>='02' GROUP BY id;
+SELECT id,MIN(a),MAX(a) FROM t1 WHERE a<=3 GROUP BY id;
+--echo # Should NOT use group_min_max optimization
+EXPLAIN SELECT id,MIN(a),MAX(a) FROM t1 WHERE a<=3 GROUP BY id;
+DROP TABLE t1;
+
+--echo #
+--echo # MDEV-6993 Bad results with join comparing DECIMAL and ENUM/SET columns
+--echo #
+CREATE TABLE t1 (c1 DECIMAL(10,1) PRIMARY KEY);
+INSERT INTO t1 VALUES (1),(2);
+CREATE TABLE t2 (c1 ENUM('a','b'));
+INSERT INTO t2 VALUES ('a'),('b');
+SELECT t1.* FROM t1 NATURAL JOIN t2;
+ALTER TABLE t2 ADD PRIMARY KEY(c1);
+SELECT t1.* FROM t1 NATURAL JOIN t2;
+SELECT t1.* FROM t1 LEFT OUTER JOIN t2 USING (c1);
+DROP TABLE t1,t2;
+
+CREATE TABLE t1 (a DECIMAL(10,1), b ENUM('1','2'));
+INSERT INTO t1 (a) VALUES (1),(2);
+UPDATE t1 SET b=a;
+SELECT * FROM t1;
+ALTER TABLE t1 MODIFY a ENUM('1','2');
+SELECT * FROM t1;
+DROP TABLE t1;
+
+--echo #
+--echo # End of 10.0 tests
+--echo #
diff --git a/mysql-test/t/type_float.test b/mysql-test/t/type_float.test
index b33c51566a0..bb7a784553e 100644
--- a/mysql-test/t/type_float.test
+++ b/mysql-test/t/type_float.test
@@ -331,3 +331,57 @@ eval select concat((truncate((-1.7976931348623157E+307),(0x1e))),
--echo #
select format(truncate('1.7976931348623157E+308',-12),1,'fr_BE') as foo;
+
+--echo #
+--echo # Bug #13500371 63704: CONVERSION OF '1.' TO A NUMBER GIVES ERROR 1265
+--echo # (WARN_DATA_TRUNCATED)
+--echo #
+
+CREATE TABLE t1 (f FLOAT);
+INSERT INTO t1 VALUES ('1.');
+INSERT INTO t1 VALUES ('2.0.');
+INSERT INTO t1 VALUES ('.');
+SELECT * FROM t1 ORDER BY f;
+DROP TABLE t1;
+
+
+--echo #
+--echo # Start of 10.0 tests
+--echo #
+
+--echo #
+--echo # MDEV-6950 Bad results with joins comparing DATE/DATETIME and INT/DECIMAL/DOUBLE/ENUM/VARCHAR columns
+--echo #
+CREATE TABLE t1 (a DATETIME PRIMARY KEY);
+INSERT INTO t1 VALUES ('1999-01-01 00:00:00');
+CREATE TABLE t2 (a DOUBLE);
+INSERT INTO t2 VALUES (19990101000000);
+INSERT INTO t2 VALUES (990101000000);
+SELECT t1.* FROM t1,t2 WHERE t1.a=t2.a;
+SELECT t1.* FROM t1 LEFT JOIN t2 ON t1.a=t2.a;
+ALTER TABLE t2 ADD PRIMARY KEY(a);
+SELECT t1.* FROM t1,t2 WHERE t1.a=t2.a;
+SELECT t1.* FROM t1 LEFT JOIN t2 ON t1.a=t2.a;
+--echo # t2 should NOT be eliminated
+EXPLAIN SELECT t1.* FROM t1 LEFT JOIN t2 ON t1.a=t2.a;
+DROP TABLE t1,t2;
+
+--echo #
+--echo # MDEV-6971 Bad results with joins comparing TIME and DOUBLE/DECIMAL columns
+--echo #
+CREATE TABLE t1 (a TIME(6) PRIMARY KEY);
+INSERT INTO t1 VALUES ('10:20:30');
+CREATE TABLE t2 (a DOUBLE);
+INSERT INTO t2 VALUES (102030),(102030.000000001);
+SELECT t1.* FROM t1 JOIN t2 USING(a);
+SELECT t1.* FROM t1 LEFT JOIN t2 USING(a);
+ALTER TABLE t2 ADD PRIMARY KEY(a);
+SELECT t1.* FROM t1 JOIN t2 USING(a);
+SELECT t1.* FROM t1 LEFT JOIN t2 USING(a);
+--echo # t2 should NOT be elimitated
+EXPLAIN SELECT t1.* FROM t1 LEFT JOIN t2 USING(a);
+DROP TABLE t1,t2;
+
+--echo #
+--echo # End of 10.0 tests
+--echo #
diff --git a/mysql-test/t/type_newdecimal.test b/mysql-test/t/type_newdecimal.test
index bb5a61d84ec..09149253c67 100644
--- a/mysql-test/t/type_newdecimal.test
+++ b/mysql-test/t/type_newdecimal.test
@@ -1581,3 +1581,44 @@ select 0.000000000000000000000000000000000000000000000000001 mod 1;
select 0.0000000001 mod 1;
select 0.01 mod 1;
+--echo #
+--echo # Start of 10.0 tests
+--echo #
+
+--echo #
+--echo # MDEV-6950 Bad results with joins comparing DATE and INT/ENUM/VARCHAR columns
+--echo #
+CREATE TABLE t1 (a DATETIME PRIMARY KEY);
+INSERT INTO t1 VALUES ('1999-01-01 00:00:00');
+CREATE TABLE t2 (a DECIMAL(30,1));
+INSERT INTO t2 VALUES (19990101000000);
+INSERT INTO t2 VALUES (990101000000);
+SELECT t1.* FROM t1,t2 WHERE t1.a=t2.a;
+SELECT t1.* FROM t1 LEFT JOIN t2 ON t1.a=t2.a;
+ALTER TABLE t2 ADD PRIMARY KEY(a);
+SELECT t1.* FROM t1,t2 WHERE t1.a=t2.a;
+SELECT t1.* FROM t1 LEFT JOIN t2 ON t1.a=t2.a;
+--echo # t2 should NOT be eliminated
+EXPLAIN SELECT t1.* FROM t1 LEFT JOIN t2 ON t1.a=t2.a;
+DROP TABLE t1,t2;
+
+--echo #
+--echo # MDEV-6971 Bad results with joins comparing TIME and DOUBLE/DECIMAL columns
+--echo #
+CREATE TABLE t1 (a TIME(6) PRIMARY KEY);
+INSERT INTO t1 VALUES ('10:20:30');
+CREATE TABLE t2 (a DECIMAL(30,10));
+INSERT INTO t2 VALUES (102030),(102030.000000001);
+SELECT t1.* FROM t1 JOIN t2 USING(a);
+SELECT t1.* FROM t1 LEFT JOIN t2 USING(a);
+ALTER TABLE t2 ADD PRIMARY KEY(a);
+SELECT t1.* FROM t1 JOIN t2 USING(a);
+SELECT t1.* FROM t1 LEFT JOIN t2 USING(a);
+--echo # t2 should NOT be eliminated
+EXPLAIN SELECT t1.* FROM t1 LEFT JOIN t2 USING(a);
+DROP TABLE t1,t2;
+
+
+--echo #
+--echo # End of 10.0 tests
+--echo #
diff --git a/mysql-test/t/type_set.test b/mysql-test/t/type_set.test
index a851d116743..8b9da6962d5 100644
--- a/mysql-test/t/type_set.test
+++ b/mysql-test/t/type_set.test
@@ -95,3 +95,93 @@ DROP TABLE t1;
--echo End of 5.0 tests
+
+--echo #
+--echo # Start of 10.0 tests
+--echo #
+
+--echo #
+--echo # MDEV-6950 Bad results with joins compating DATE and INT/ENUM/VARCHAR columns
+--echo #
+
+CREATE TABLE t1 (c1 DATE PRIMARY KEY);
+INSERT INTO t1 VALUES ('2001-01-01');
+CREATE TABLE t2 (c1 SET('2001-01-01','2001/01/01'));
+INSERT INTO t2 VALUES ('2001-01-01');
+INSERT INTO t2 VALUES ('2001/01/01');
+SELECT t1.* FROM t1,t2 WHERE t1.c1=t2.c1;
+SELECT t1.* FROM t1 LEFT JOIN t2 ON t1.c1=t2.c1;
+ALTER TABLE t2 ADD PRIMARY KEY(c1);
+SELECT t1.* FROM t1,t2 WHERE t1.c1=t2.c1;
+EXPLAIN SELECT t1.* FROM t1,t2 WHERE t1.c1=t2.c1;
+SELECT t1.* FROM t1 LEFT JOIN t2 ON t1.c1=t2.c1;
+--echo # t2 should NOT be eliminated
+EXPLAIN SELECT t1.* FROM t1 LEFT JOIN t2 ON t1.c1=t2.c1;
+DROP TABLE t1, t2;
+
+--echo #
+--echo # MDEV-6978 Bad results with join comparing case insensitive VARCHAR/ENUM/SET expression to a _bin ENUM column
+--echo #
+CREATE TABLE t1 (c1 ENUM('a') CHARACTER SET latin1 PRIMARY KEY);
+INSERT INTO t1 VALUES ('a');
+CREATE TABLE t2 (c1 SET('a','A') CHARACTER SET latin1 COLLATE latin1_bin);
+INSERT INTO t2 VALUES ('a'),('A');
+SELECT t1.* FROM t1 JOIN t2 ON t1.c1 COLLATE latin1_swedish_ci=t2.c1;
+SELECT t1.* FROM t1 LEFT JOIN t2 ON t1.c1 COLLATE latin1_swedish_ci=t2.c1;
+ALTER TABLE t2 ADD PRIMARY KEY(c1);
+SELECT t1.* FROM t1 JOIN t2 ON t1.c1 COLLATE latin1_swedish_ci=t2.c1;
+SELECT t1.* FROM t1 LEFT JOIN t2 ON t1.c1 COLLATE latin1_swedish_ci=t2.c1;
+--echo # t2 should NOT be eliminated
+EXPLAIN SELECT t1.* FROM t1 LEFT JOIN t2 ON t1.c1 COLLATE latin1_swedish_ci=t2.c1;
+DROP TABLE IF EXISTS t1,t2;
+
+CREATE TABLE t1 (c1 SET('a') CHARACTER SET latin1 PRIMARY KEY);
+INSERT INTO t1 VALUES ('a');
+CREATE TABLE t2 (c1 SET('a','A') CHARACTER SET latin1 COLLATE latin1_bin);
+INSERT INTO t2 VALUES ('a'),('A');
+SELECT t1.* FROM t1 JOIN t2 ON t1.c1 COLLATE latin1_swedish_ci=t2.c1;
+SELECT t1.* FROM t1 LEFT JOIN t2 ON t1.c1 COLLATE latin1_swedish_ci=t2.c1;
+ALTER TABLE t2 ADD PRIMARY KEY(c1);
+SELECT t1.* FROM t1 JOIN t2 ON t1.c1 COLLATE latin1_swedish_ci=t2.c1;
+SELECT t1.* FROM t1 LEFT JOIN t2 ON t1.c1 COLLATE latin1_swedish_ci=t2.c1;
+--echo # t2 should NOT be eliminated
+EXPLAIN SELECT t1.* FROM t1 LEFT JOIN t2 ON t1.c1 COLLATE latin1_swedish_ci=t2.c1;
+DROP TABLE IF EXISTS t1,t2;
+
+CREATE TABLE t1 (c1 VARCHAR(10) CHARACTER SET latin1 PRIMARY KEY);
+INSERT INTO t1 VALUES ('a');
+CREATE TABLE t2 (c1 SET('a','A') CHARACTER SET latin1 COLLATE latin1_bin);
+INSERT INTO t2 VALUES ('a'),('A');
+SELECT t1.* FROM t1 JOIN t2 ON t1.c1 COLLATE latin1_swedish_ci=t2.c1;
+SELECT t1.* FROM t1 LEFT JOIN t2 ON t1.c1 COLLATE latin1_swedish_ci=t2.c1;
+ALTER TABLE t2 ADD PRIMARY KEY(c1);
+SELECT t1.* FROM t1 JOIN t2 ON t1.c1 COLLATE latin1_swedish_ci=t2.c1;
+SELECT t1.* FROM t1 LEFT JOIN t2 ON t1.c1 COLLATE latin1_swedish_ci=t2.c1;
+--echo # t2 should NOT be eliminated
+EXPLAIN SELECT t1.* FROM t1 LEFT JOIN t2 ON t1.c1 COLLATE latin1_swedish_ci=t2.c1;
+DROP TABLE IF EXISTS t1,t2;
+
+--echo #
+--echo # MDEV-6993 Bad results with join comparing DECIMAL and ENUM/SET columns
+--echo #
+CREATE TABLE t1 (c1 DECIMAL(10,1) PRIMARY KEY);
+INSERT INTO t1 VALUES (1),(2);
+CREATE TABLE t2 (c1 SET('a','b'));
+INSERT INTO t2 VALUES ('a'),('b');
+SELECT t1.* FROM t1 NATURAL JOIN t2;
+ALTER TABLE t2 ADD PRIMARY KEY(c1);
+SELECT t1.* FROM t1 NATURAL JOIN t2;
+SELECT t1.* FROM t1 LEFT OUTER JOIN t2 USING (c1);
+DROP TABLE t1,t2;
+
+CREATE TABLE t1 (a DECIMAL(10,1), b SET('1','2'));
+INSERT INTO t1 (a) VALUES (1),(2);
+UPDATE t1 SET b=a;
+SELECT * FROM t1;
+ALTER TABLE t1 MODIFY a SET('1','2');
+SELECT * FROM t1;
+DROP TABLE t1;
+
+--echo #
+--echo # End of 10.0 tests
+--echo #
diff --git a/mysql-test/t/type_temporal_mysql56.test b/mysql-test/t/type_temporal_mysql56.test
new file mode 100644
index 00000000000..98529bfe1c1
--- /dev/null
+++ b/mysql-test/t/type_temporal_mysql56.test
@@ -0,0 +1,23 @@
+
+let $MYSQLD_DATADIR= `select @@datadir`;
+--copy_file std_data/mysql56time.frm $MYSQLD_DATADIR/test/mysql56time.frm
+--copy_file std_data/mysql56time.MYD $MYSQLD_DATADIR/test/mysql56time.MYD
+--copy_file std_data/mysql56time.MYI $MYSQLD_DATADIR/test/mysql56time.MYI
+SHOW CREATE TABLE mysql56time;
+--query_vertical SELECT * FROM mysql56time
+DROP TABLE mysql56time;
+
+--copy_file std_data/mysql56datetime.frm $MYSQLD_DATADIR/test/mysql56datetime.frm
+--copy_file std_data/mysql56datetime.MYD $MYSQLD_DATADIR/test/mysql56datetime.MYD
+--copy_file std_data/mysql56datetime.MYI $MYSQLD_DATADIR/test/mysql56datetime.MYI
+SHOW CREATE TABLE mysql56datetime;
+--query_vertical SELECT * FROM mysql56datetime
+DROP TABLE mysql56datetime;
+
+--copy_file std_data/mysql56timestamp.frm $MYSQLD_DATADIR/test/mysql56timestamp.frm
+--copy_file std_data/mysql56timestamp.MYD $MYSQLD_DATADIR/test/mysql56timestamp.MYD
+--copy_file std_data/mysql56timestamp.MYI $MYSQLD_DATADIR/test/mysql56timestamp.MYI
+SET TIME_ZONE='+00:00';
+SHOW CREATE TABLE mysql56timestamp;
+--query_vertical SELECT * FROM mysql56timestamp
+DROP TABLE mysql56timestamp;
diff --git a/mysql-test/t/type_time.test b/mysql-test/t/type_time.test
index 259b1819d21..d36c6af65e8 100644
--- a/mysql-test/t/type_time.test
+++ b/mysql-test/t/type_time.test
@@ -94,10 +94,12 @@ DROP TABLE t1;
--echo # Bug#53942 valgrind warnings with timestamp() function and incomplete datetime values
--echo #
+SET timestamp=unix_timestamp('2001-02-03 10:20:30');
CREATE TABLE t1(f1 TIME);
INSERT INTO t1 VALUES ('23:38:57');
SELECT TIMESTAMP(f1,'1') FROM t1;
DROP TABLE t1;
+SET timestamp=DEFAULT;
--echo End of 5.1 tests
@@ -113,6 +115,12 @@ create table t1 (f1 time , f2 varchar(5), key(f1));
insert into t1 values ('00:20:01','a'),('00:20:03','b');
select * from t1 force key (f1) where f1 < curdate();
select * from t1 ignore key (f1) where f1 < curdate();
+select * from t1 force key (f1) where f1 > curdate();
+select * from t1 ignore key (f1) where f1 > curdate();
+delete from t1;
+insert into t1 values ('-00:20:01','a'),('-00:20:03','b');
+select * from t1 force key (f1) where f1 < curdate();
+select * from t1 ignore key (f1) where f1 < curdate();
drop table t1;
#
@@ -126,7 +134,9 @@ drop table t1;
--echo #
--echo # MDEV-4634 Crash in CONVERT_TZ
--echo #
+SET timestamp=unix_timestamp('2001-02-03 10:20:30');
SELECT CONVERT_TZ(GREATEST(TIME('00:00:00'),TIME('00:00:00')),'+00:00','+7:5');
+SET timestamp=DEFAULT;
--echo #
--echo # MDEV-4652 Wrong result for CONCAT(GREATEST(TIME('00:00:01'),TIME('00:00:00')))
@@ -250,3 +260,19 @@ DROP TABLE t1;
--echo #
--echo # End of 5.5 tests
--echo #
+
+--echo #
+--echo # Start of 10.0 tests
+--echo #
+
+--echo #
+--echo # MDEV-6102 Comparison between TIME and DATETIME does not use CURRENT_DATE
+--echo #
+SET timestamp=UNIX_TIMESTAMP('2014-04-14 01:02:03');
+SELECT CAST(TIME'10:20:30' AS DATETIME), TIME'10:20:30'=TIMESTAMP'2014-04-14 10:20:30' AS cmp;
+SET timestamp=DEFAULT;
+
+--echo #
+--echo # End of 10.0 tests
+--echo #
+
diff --git a/mysql-test/t/type_time_6065.test b/mysql-test/t/type_time_6065.test
new file mode 100644
index 00000000000..fc91c530760
--- /dev/null
+++ b/mysql-test/t/type_time_6065.test
@@ -0,0 +1,200 @@
+#
+# MDEV-6065 MySQL Bug#13623473 "MISSING ROWS ON SELECT AND JOIN WITH TIME/DATETIME COMPARE"
+#
+
+# Systematic testing of ref access and range scan
+
+SET TIMESTAMP=UNIX_TIMESTAMP('2012-01-31 10:14:35');
+
+CREATE TABLE t1 (col_time_key TIME, KEY(col_time_key));
+INSERT INTO t1 VALUES ('00:00:00'),('-24:00:00'),('-48:00:00'),('24:00:00'),('48:00:00');
+CREATE TABLE t2 (col_datetime_key DATETIME, KEY(col_datetime_key));
+INSERT INTO t2 SELECT * FROM t1;
+
+let $cnt_0=5;
+let $operator= =;
+# For operator in =, >=, >, <=, <
+while ($cnt_0)
+{
+ let $cnt_1=2;
+ let $first_table=t1;
+ # for table in t1,t2
+ while ($cnt_1)
+ {
+ if ($first_table==t1)
+ {
+ let $first_index=col_time_key;
+ let $second_table=t2;
+ let $second_index=col_datetime_key;
+ }
+ if ($first_table==t2)
+ {
+ let $first_index=col_datetime_key;
+ let $second_table=t1;
+ let $second_index=col_time_key;
+ }
+ let $cnt_2=2;
+ let $first_index_hint=ignore;
+ # for first_index_hint in ignore,force
+ while ($cnt_2)
+ {
+ let $cnt_3=2;
+ let $second_index_hint=ignore;
+ # for second_index_hint in ignore, force
+ while ($cnt_3)
+ {
+ let $cnt_4=2;
+ let $first_operand=col_time_key;
+ # for first_operand in col_time_key, col_datetime_key
+ while ($cnt_4)
+ {
+ if ($first_operand==col_time_key)
+ {
+ let $second_operand=col_datetime_key;
+ }
+ if ($first_operand==col_datetime_key)
+ {
+ let $second_operand=col_time_key;
+ }
+
+ eval EXPLAIN EXTENDED SELECT * FROM
+ $first_table $first_index_hint INDEX ($first_index)
+ STRAIGHT_JOIN
+ $second_table $second_index_hint INDEX ($second_index)
+ WHERE $first_operand $operator $second_operand;
+ --sorted_result
+ eval SELECT * FROM
+ $first_table $first_index_hint INDEX ($first_index)
+ STRAIGHT_JOIN
+ $second_table $second_index_hint INDEX ($second_index)
+ WHERE $first_operand $operator $second_operand;
+
+ let $first_operand=col_datetime_key;
+ dec $cnt_4;
+ }
+ let $second_index_hint=force;
+ dec $cnt_3;
+ }
+ let $first_index_hint=force;
+ dec $cnt_2;
+ }
+ let $first_table=t2;
+ dec $cnt_1;
+ }
+ if ($cnt_0==5)
+ {
+ let $operator= >=;
+ }
+ if ($cnt_0==4)
+ {
+ let $operator= >;
+ }
+ if ($cnt_0==3)
+ {
+ let $operator= <=;
+ }
+ if ($cnt_0==2)
+ {
+ let $operator= <;
+ }
+ dec $cnt_0;
+}
+
+DROP TABLE t1,t2;
+
+#
+# Original test of the bug report
+#
+
+CREATE TABLE t1 (
+ pk INT NOT NULL AUTO_INCREMENT,
+ col_int_nokey INT,
+ col_int_key INT NOT NULL,
+ PRIMARY KEY (pk),
+ KEY col_int_key (col_int_key)
+);
+
+INSERT INTO t1 VALUES (10,1,7), (11,7,0), (12,4,9), (13,7,3),
+(14,0,4), (15,2,2), (16,9,5), (17,4,3), (18,0,1), (19,9,3), (20,1,6),
+(21,3,7), (22,8,5), (23,8,1), (24,18,204), (25,84,224), (26,6,9),
+(27,3,5), (28,6,0), (29,6,3);
+
+CREATE TABLE t2 (
+ col_int_nokey INT NOT NULL,
+ col_datetime_key DATETIME NOT NULL,
+ col_varchar_key VARCHAR(1) NOT NULL,
+ KEY col_datetime_key (col_datetime_key),
+ KEY col_varchar_key (col_varchar_key)
+);
+
+INSERT INTO t2 VALUES (1,'2001-11-04 19:07:55','k');
+
+CREATE TABLE t3 (
+ col_time_key TIME,
+ KEY col_time_key (col_time_key)
+);
+
+INSERT INTO t3 VALUES ('21:22:34'), ('10:50:38'), ('00:21:38'),
+('04:08:02'), ('16:25:11'), ('10:14:58'), ('19:47:59'), ('11:14:24'),
+('00:00:00'), ('00:00:00'), ('15:57:25'), ('07:05:51'), ('19:22:21'),
+('03:53:16'), ('09:16:38'), ('15:37:26'), ('00:00:00'), ('05:03:03'),
+('02:59:24'), ('00:01:58');
+
+let $query=SELECT * FROM t2 STRAIGHT_JOIN t3 FORCE INDEX (col_time_key)
+ ON t3.col_time_key > t2.col_datetime_key;
+eval EXPLAIN EXTENDED $query;
+--sorted_result
+eval $query;
+
+let $query=SELECT * FROM t2 STRAIGHT_JOIN t3 IGNORE INDEX (col_time_key)
+ ON t3.col_time_key > t2.col_datetime_key;
+eval EXPLAIN EXTENDED $query;
+--sorted_result
+eval $query;
+
+let $query=SELECT outr.col_int_nokey
+FROM t2 as outr
+ STRAIGHT_JOIN t3 AS outr2
+ ON outr2.col_time_key > outr.col_datetime_key
+WHERE outr.col_int_nokey IN (
+ SELECT col_int_key
+ FROM t1 AS innr
+ WHERE innr.pk >= innr.col_int_nokey
+) AND (
+ outr.col_int_nokey <= 6
+ OR
+ outr.col_varchar_key IS NULL
+);
+eval EXPLAIN EXTENDED $query;
+--sorted_result
+eval $query;
+
+DROP TABLE t1,t2,t3;
+SET TIMESTAMP=0; # back to current time
+
+
+--echo #
+--echo # MDEV-15262 Wrong results for SELECT..WHERE non_indexed_datetime_column=indexed_time_column
+--echo #
+
+SET TIMESTAMP=UNIX_TIMESTAMP('2012-01-31 10:14:35');
+CREATE TABLE t1 (col_time_key TIME, KEY(col_time_key));
+CREATE TABLE t2 (col_datetime_key DATETIME);
+INSERT INTO t1 VALUES ('-760:00:00'),('760:00:00');
+INSERT INTO t1 VALUES ('-770:00:00'),('770:00:00');
+INSERT INTO t2 SELECT * FROM t1;
+SELECT * FROM t2 STRAIGHT_JOIN t1 IGNORE INDEX(col_time_key) WHERE col_time_key = col_datetime_key;
+SELECT * FROM t2 STRAIGHT_JOIN t1 FORCE INDEX (col_time_key) WHERE col_time_key = col_datetime_key;
+INSERT INTO t1 VALUES ('-838:59:59'),('838:59:59');
+INSERT INTO t2 VALUES (DATE_ADD(CURRENT_DATE, INTERVAL '-838:59:59' HOUR_SECOND));
+INSERT INTO t2 VALUES (DATE_ADD(CURRENT_DATE, INTERVAL '838:59:59' HOUR_SECOND));
+INSERT INTO t2 VALUES (DATE_ADD(CURRENT_DATE, INTERVAL '-839:00:00' HOUR_SECOND));
+INSERT INTO t2 VALUES (DATE_ADD(CURRENT_DATE, INTERVAL '839:00:00' HOUR_SECOND));
+SELECT * FROM t2 STRAIGHT_JOIN t1 IGNORE INDEX(col_time_key) WHERE col_time_key = col_datetime_key;
+SELECT * FROM t2 STRAIGHT_JOIN t1 FORCE INDEX (col_time_key) WHERE col_time_key = col_datetime_key;
+DROP TABLE t1, t2;
+SET TIMESTAMP=DEFAULT;
+
+#
+# End of 10.0 tests
+#
diff --git a/mysql-test/t/type_timestamp.test b/mysql-test/t/type_timestamp.test
index 0cc9c37fee9..0ef0832602f 100644
--- a/mysql-test/t/type_timestamp.test
+++ b/mysql-test/t/type_timestamp.test
@@ -86,17 +86,16 @@ drop table t1;
# Test for TIMESTAMP column with default now() and on update now() clauses
#
-# These statements should fail.
---error 1293
create table t1 (t1 timestamp, t2 timestamp default now());
---error 1293
+drop table t1;
create table t1 (t1 timestamp, t2 timestamp on update now());
---error 1293
+drop table t1;
create table t1 (t1 timestamp, t2 timestamp default now() on update now());
---error 1293
+drop table t1;
create table t1 (t1 timestamp default now(), t2 timestamp on update now());
---error 1293
+drop table t1;
create table t1 (t1 timestamp on update now(), t2 timestamp default now() on update now());
+drop table t1;
# Let us test TIMESTAMP auto-update behaviour
# Also we will test behaviour of TIMESTAMP field in SHOW CREATE TABLE and
@@ -455,3 +454,77 @@ SELECT c1, '2016-06-13 20:00:00.000003' >= COALESCE( c1 ) FROM t1;
DROP TABLE t1;
--echo End of 5.5 tests
+
+--echo #
+--echo # MDEV-7254: Assigned expression is evaluated twice when updating column TIMESTAMP NOT NULL
+--echo #
+
+SET time_zone='+02:00';
+create table t1(value timestamp not null);
+set @a:=0;
+delimiter //;
+create function f1 () returns timestamp
+begin
+ set @a = @a + 1;
+ return NULL;
+end//
+delimiter ;//
+set timestamp=12340;
+insert t1 values (f1());
+select @a, value from t1;
+set timestamp=12350;
+update t1 set value = f1();
+select @a, value from t1;
+drop table t1;
+drop function f1;
+set timestamp=0;
+
+# Verify no regressions to TIMESTAMP NULL
+create table t1(value timestamp null);
+set @a:=0;
+delimiter //;
+create function f1 () returns timestamp
+begin
+ set @a = @a + 1;
+ return NULL;
+end//
+delimiter ;//
+set timestamp=12340;
+insert t1 values (f1());
+select @a, value from t1;
+set timestamp=12350;
+update t1 set value = f1();
+select @a, value from t1;
+drop table t1;
+drop function f1;
+set timestamp=0;
+SET time_zone=DEFAULT;
+
+--echo #
+--echo # MDEV-7778 impossible create copy of table, if table contain default value for timestamp field
+--echo #
+
+SET sql_mode="NO_ZERO_DATE";
+CREATE TABLE t1 (
+ ts timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP
+);
+CREATE TABLE t2 AS SELECT * from t1 LIMIT 0;
+SHOW CREATE TABLE t1;
+SHOW CREATE TABLE t2;
+DROP TABLE t1,t2;
+SET sql_mode=DEFAULT;
+
+--echo #
+--echo # MDEV-8082 ON UPDATE is not preserved by CREATE TABLE .. SELECT
+--echo #
+CREATE TABLE t1 (
+ vc VARCHAR(10) NOT NULL DEFAULT 'test',
+ ts timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP
+);
+CREATE TABLE t2 AS SELECT * FROM t1 LIMIT 0;
+SHOW CREATE TABLE t1;
+SHOW CREATE TABLE t2;
+DROP TABLE t1,t2;
+
+
+--echo End of 10.0 tests
diff --git a/mysql-test/t/type_timestamp_hires.test b/mysql-test/t/type_timestamp_hires.test
index 8e1f8586956..17a2c3e1f1f 100644
--- a/mysql-test/t/type_timestamp_hires.test
+++ b/mysql-test/t/type_timestamp_hires.test
@@ -14,3 +14,18 @@ insert t1 values ();
select * from t1;
drop table t1;
+#
+# MDEV-438 Microseconds: Precision is ignored in CURRENT_TIMESTAMP(N) when it is given as a default column value
+#
+create table t1 (a timestamp(5) default current_timestamp); drop table t1;
+create table t1 (a timestamp(5) default current_timestamp()); drop table t1;
+--error ER_INVALID_DEFAULT
+create table t1 (a timestamp(5) default current_timestamp(2));
+create table t1 (a timestamp(5) default current_timestamp(5)); drop table t1;
+create table t1 (a timestamp(5) default current_timestamp(6)); drop table t1;
+create table t1 (a timestamp(5) on update current_timestamp); drop table t1;
+create table t1 (a timestamp(5) on update current_timestamp()); drop table t1;
+--error ER_INVALID_ON_UPDATE
+create table t1 (a timestamp(5) on update current_timestamp(3));
+create table t1 (a timestamp(5) on update current_timestamp(5)); drop table t1;
+create table t1 (a timestamp(5) on update current_timestamp(6)); drop table t1;
diff --git a/mysql-test/t/type_uint.test b/mysql-test/t/type_uint.test
index 14e5e3bd621..84fca993d09 100644
--- a/mysql-test/t/type_uint.test
+++ b/mysql-test/t/type_uint.test
@@ -23,3 +23,28 @@ create table t2 as select a from t1 union select b from t1;
show create table t2;
select * from t2;
drop table t1, t2;
+
+--echo #
+--echo # Start of 10.0 tests
+--echo #
+
+--echo #
+--echo # MDEV-6950 Bad results with joins comparing DATE and INT/ENUM/VARCHAR columns
+--echo #
+CREATE TABLE t1 (a DATE PRIMARY KEY);
+INSERT INTO t1 VALUES ('1999-01-01');
+CREATE TABLE t2 (a INT UNSIGNED);
+INSERT INTO t2 VALUES (19990101);
+INSERT INTO t2 VALUES (990101);
+SELECT t1.* FROM t1,t2 WHERE t1.a=t2.a;
+SELECT t1.* FROM t1 LEFT JOIN t2 ON t1.a=t2.a;
+ALTER TABLE t2 ADD PRIMARY KEY(a);
+SELECT t1.* FROM t1,t2 WHERE t1.a=t2.a;
+SELECT t1.* FROM t1 LEFT JOIN t2 ON t1.a=t2.a;
+--echo # t2 should NOT be eliminated
+EXPLAIN SELECT t1.* FROM t1 LEFT JOIN t2 ON t1.a=t2.a;
+DROP TABLE t1,t2;
+
+--echo #
+--echo # End of 10.0 tests
+--echo #
diff --git a/mysql-test/t/type_varchar.test b/mysql-test/t/type_varchar.test
index ed8218208c3..909dc516703 100644
--- a/mysql-test/t/type_varchar.test
+++ b/mysql-test/t/type_varchar.test
@@ -261,3 +261,29 @@ DROP TABLE t1;
CREATE TABLE t1 (c1 VARCHAR(65536));
DESCRIBE t1;
DROP TABLE t1;
+
+--echo #
+--echo # End of 5.5 tests
+--echo #
+
+--echo #
+--echo # MDEV-6950 Bad results with joins comparing DATE and INT/ENUM/VARCHAR columns
+--echo #
+CREATE TABLE t1 (c1 DATE PRIMARY KEY);
+INSERT INTO t1 VALUES ('2001-01-01');
+CREATE TABLE t2 (c1 VARCHAR(20));
+INSERT INTO t2 VALUES ('2001-01-01');
+INSERT INTO t2 VALUES ('2001/01/01');
+SELECT t1.* FROM t1,t2 WHERE t1.c1=t2.c1;
+SELECT t1.* FROM t1 LEFT JOIN t2 ON t1.c1=t2.c1;
+ALTER TABLE t2 ADD PRIMARY KEY(c1);
+SELECT t1.* FROM t1,t2 WHERE t1.c1=t2.c1;
+EXPLAIN SELECT t1.* FROM t1,t2 WHERE t1.c1=t2.c1;
+SELECT t1.* FROM t1 LEFT JOIN t2 ON t1.c1=t2.c1;
+--echo # t2 should NOT be eliminated
+EXPLAIN SELECT t1.* FROM t1 LEFT JOIN t2 ON t1.c1=t2.c1;
+DROP TABLE IF EXISTS t1,t2;
+
+--echo #
+--echo # End of 10.0 tests
+--echo #
diff --git a/mysql-test/t/update.test b/mysql-test/t/update.test
index e9d7ff243dd..e5ef0b11127 100644
--- a/mysql-test/t/update.test
+++ b/mysql-test/t/update.test
@@ -632,3 +632,25 @@ SET data_entry_cost
drop view v1;
drop table t1, t2;
+--echo #
+--echo # MDEV-4410: update does not want to use a covering index, but select uses it.
+--echo #
+create table t2(a int);
+insert into t2 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
+
+create table t1 (key1 int, col1 int, key(key1));
+insert into t1
+select A.a + 10 * B.a + 100 * C.a, 1234 from t2 A, t2 B, t2 C;
+
+--echo # This must not have "Using filesort":
+explain
+update t1 set key1=key1+1 where key1 between 10 and 110 order by key1 limit 2;
+
+flush status;
+update t1 set key1=key1+1 where key1 between 10 and 110 order by key1 limit 2;
+# Handler_read_next should be 1 (due to LIMIT), not 100:
+show status like 'Handler_read%';
+
+drop table t1, t2;
+
+--echo # End of MariaDB 10.0 tests
diff --git a/mysql-test/t/update_innodb.test b/mysql-test/t/update_innodb.test
index 67c356c4e2e..059ae8abbb0 100644
--- a/mysql-test/t/update_innodb.test
+++ b/mysql-test/t/update_innodb.test
@@ -37,3 +37,16 @@ UPDATE t1 a JOIN t2 b ON a.c1 = b.c1 JOIN v1 vw ON b.c2 = vw.c1 JOIN t3 del ON v
drop view v1;
drop table t1,t2,t3,t4;
+
+--echo #
+--echo # MDEV-14862: Server crashes in Bitmap<64u>::merge / add_key_field
+--echo #
+
+CREATE TABLE t1 (a INT) ENGINE=InnoDB;
+CREATE VIEW v1 AS SELECT * FROM t1;
+CREATE TABLE t2 (b INT) ENGINE=InnoDB;
+DELETE FROM v1 WHERE a IN ( SELECT a FROM t2 );
+DELETE FROM v1 WHERE (a,a) IN ( SELECT a,a FROM t2 );
+
+drop view v1;
+drop table t1,t2;
diff --git a/mysql-test/t/upgrade.test b/mysql-test/t/upgrade.test
index a8c875ef764..ab9330176f8 100644
--- a/mysql-test/t/upgrade.test
+++ b/mysql-test/t/upgrade.test
@@ -1,3 +1,4 @@
+call mtr.add_suppression("Invalid .old.. table or database name");
-- source include/not_embedded.inc
--disable_warnings
@@ -33,18 +34,17 @@ drop database `mysqltest-1`;
#
# Bug#17142: Crash if create with encoded name
#
---disable_warnings
-drop table if exists `txu@0023p@0023p1`;
-drop table if exists `txu#p#p1`;
---enable_warnings
create table `txu#p#p1` (s1 int);
insert into `txu#p#p1` values (1);
--error 1146
select * from `txu@0023p@0023p1`;
---error ER_TABLE_EXISTS_ERROR
create table `txu@0023p@0023p1` (s1 int);
+show tables;
+insert into `txu@0023p@0023p1` values (2);
+select * from `txu@0023p@0023p1`;
select * from `txu#p#p1`;
drop table `txu#p#p1`;
+drop table `txu@0023p@0023p1`;
--echo #
--echo # Bug#37631 Incorrect key file for table after upgrading from 5.0 to 5.1
diff --git a/mysql-test/t/user_var.test b/mysql-test/t/user_var.test
index 9b6714a1bbb..2c889c2cc0c 100644
--- a/mysql-test/t/user_var.test
+++ b/mysql-test/t/user_var.test
@@ -449,4 +449,55 @@ SELECT f1, f2 FROM t1 ORDER BY f2;
DROP TRIGGER trg1;
DROP TABLE t1;
+--echo #
+--echo # Bug #12408412: GROUP_CONCAT + ORDER BY + INPUT/OUTPUT
+--echo # SAME USER VARIABLE = CRASH
+--echo #
+
+SET @bug12408412=1;
+SELECT GROUP_CONCAT(@bug12408412 ORDER BY 1) INTO @bug12408412;
+
+#
+# MDEV-616 LP BUG#1002126
+# Bug #11764371 57196: MORE FUN WITH ASSERTION: !TABLE->FILE ||
+# TABLE->FILE->INITED == HANDLER::
+#
+
+CREATE TABLE t1(a INT);
+INSERT INTO t1 VALUES (0);
+SELECT DISTINCT POW(COUNT(*), @a:=(SELECT 1 FROM t1 LEFT JOIN t1 AS t2 ON @a))
+AS b FROM t1 GROUP BY a;
+SELECT @a;
+DROP TABLE t1;
+CREATE TABLE t1(f1 INT, f2 INT);
+INSERT INTO t1 VALUES (1,2),(2,3),(3,1);
+CREATE TABLE t2(a INT);
+INSERT INTO t2 VALUES (1);
+SET @var=NULL;
+SELECT @var:=(SELECT f2 FROM t2 WHERE @var) FROM t1 GROUP BY f1 ORDER BY f2 DESC
+LIMIT 1;
+SELECT @var;
+DROP TABLE t1, t2;
+
+CREATE TABLE t1(a INT);
+INSERT INTO t1 VALUES (0),(1),(3);
+SELECT DISTINCT POW(COUNT(distinct a), @a:=(SELECT 1 FROM t1 LEFT JOIN t1 AS t2 ON @a limit 1)) AS b FROM t1 GROUP BY a;
+SELECT @a;
+DROP TABLE t1;
+
--echo End of 5.5 tests
+
+--echo #
+--echo # Check that used memory extends if we set a variable
+--echo #
+
+# Execute twice so number stablizes a bit
+let $tmp= `select memory_used from information_schema.processlist`;
+set @var= repeat('a',20000);
+let $tmp2= `select memory_used from information_schema.processlist`;
+--disable_query_log
+--disable_column_names
+eval select $tmp < $tmp2;
+--enable_column_names
+--enable_query_log
+
diff --git a/mysql-test/t/variables.test b/mysql-test/t/variables.test
index 28f4344bd38..79cd5e1b24d 100644
--- a/mysql-test/t/variables.test
+++ b/mysql-test/t/variables.test
@@ -337,11 +337,9 @@ select @@sql_auto_is_null;
set @@sql_auto_is_null=0;
select @@sql_auto_is_null;
set sql_big_selects=1;
-set sql_big_tables=1;
set sql_buffer_result=1;
set sql_log_bin=1;
set sql_log_off=1;
-set sql_low_priority_updates=1;
set sql_quote_show_create=1;
set sql_safe_updates=1;
set sql_select_limit=1;
@@ -517,14 +515,6 @@ set character_set_results=NULL;
select ifnull(@@character_set_results,"really null");
set names latin1;
-
-#
-# Bug #9613: @@have_innodb
-#
-
---replace_column 1 #
-select @@have_innodb;
-
#
# Tests for lc_time_names
# Note, when adding new locales, please fix ID accordingly:
@@ -559,11 +549,11 @@ set lc_time_names=NULL;
set lc_time_names=-1;
select @@lc_time_names;
--echo LC_TIME_NAMES: testing locale with the last ID:
-set lc_time_names=109;
+set lc_time_names=110;
select @@lc_time_names;
--echo LC_TIME_NAMES: testing a number beyond the valid ID range:
--error ER_UNKNOWN_LOCALE
-set lc_time_names=110;
+set lc_time_names=111;
select @@lc_time_names;
--echo LC_TIME_NAMES: testing that 0 is en_US:
set lc_time_names=0;
@@ -1206,22 +1196,6 @@ SET GLOBAL server_id = -1;
SELECT @@GLOBAL.server_id;
SET GLOBAL server_id = @old_server_id;
-#
-# Bug #42778: delete order by null global variable causes
-# assertion .\filesort.cc, line 797
-#
-
-SELECT @@GLOBAL.INIT_CONNECT, @@GLOBAL.INIT_CONNECT IS NULL;
-
-CREATE TABLE t1 (a INT);
-INSERT INTO t1 VALUES ();
-SET @bug42778= @@sql_safe_updates;
-SET @@sql_safe_updates= 0;
-DELETE FROM t1 ORDER BY (@@GLOBAL.INIT_CONNECT) ASC LIMIT 10;
-SET @@sql_safe_updates= @bug42778;
-
-DROP TABLE t1;
-
--echo #
--echo # BUG#10206 - InnoDB: Transaction requiring Max_BinLog_Cache_size > 4GB always rollsback
--echo #
diff --git a/mysql-test/t/view.test b/mysql-test/t/view.test
index 835f12957d4..c59eaa9d96d 100644
--- a/mysql-test/t/view.test
+++ b/mysql-test/t/view.test
@@ -1,3 +1,4 @@
+--source include/have_partition.inc
--disable_warnings
drop table if exists t1,t2,t3,t4,t5,t6,t9,`t1a``b`,v1,v2,v3,v4,v5,v6;
@@ -141,7 +142,7 @@ drop view v100;
drop view t1;
# try to drop VIEW with DROP TABLE
--- error ER_BAD_TABLE_ERROR
+-- error ER_IT_IS_A_VIEW
drop table v1;
# try to drop table with DROP VIEW
@@ -2866,7 +2867,7 @@ DROP VIEW IF EXISTS v2;
CREATE TABLE t1(a INT, b INT);
--error ER_WRONG_STRING_LENGTH
-CREATE DEFINER=1234567890abcdefGHIKL@localhost
+CREATE DEFINER=longer_than_80_456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789@localhost
VIEW v1 AS SELECT a FROM t1;
--error ER_WRONG_STRING_LENGTH
@@ -5678,4 +5679,301 @@ drop view v60;
--echo # -- End of 5.5 tests.
--echo # -----------------------------------------------------------------
+--echo # some subqueries in SELECT list test
+create table t1 (a int, b int);
+create table t2 (a int, b int);
+insert into t1 values (1,2), (3,4), (3,3), (5,6), (7,8), (9,10);
+insert into t2 values (1,2), (3,4), (3,3), (5,6), (7,8), (9,10);
+create algorithm=merge view v1 as select t1.a as a, (select max(b) from t2 where t1.a=t2.a) as c from t1;
+explain extended
+select * from v1;
+select * from v1;
+explain extended
+select * from t2, v1 where t2.a=v1.a;
+select * from t2, v1 where t2.a=v1.a;
+explain extended
+select * from t1, v1 where t1.a=v1.a;
+select * from t1, v1 where t1.a=v1.a;
+explain extended
+select * from t1, v1 where t1.b=v1.c;
+select * from t1, v1 where t1.b=v1.c;
+explain extended
+select * from t2, t1, v1 where t1.a=t2.a and t1.a=v1.a;
+select * from t2, t1, v1 where t1.a=t2.a and t1.a=v1.a;
+
+drop view v1;
+drop table t1,t2;
+
+#
+# MDEV-6785 Wrong result on 2nd execution of PS with aggregate function, FROM SQ or MERGE view
+#
+
+create table t1 (i int not null);
+insert into t1 values (1),(2);
+create table t2 (j int not null);
+insert into t2 values (11),(12);
+create algorithm=merge view v3 as select t1.* from t2 left join t1 on (t2.j = t1.i);
+prepare stmt from 'select count(v3.i) from t1, v3';
+execute stmt;
+execute stmt;
+drop table t1, t2;
+drop view v3;
+
+--echo #
+--echo # MDEV-8525: mariadb 10.0.20 crashing when data is read by Kodi
+--echo # media center (http://kodi.tv).
+--echo #
+
+CREATE TABLE `t1` (
+ `idSong` int(11) NOT NULL AUTO_INCREMENT,
+ `idAlbum` int(11) DEFAULT NULL,
+ `idPath` int(11) DEFAULT NULL,
+ `strArtists` text,
+ `strGenres` text,
+ `strTitle` varchar(512) DEFAULT NULL,
+ `iTrack` int(11) DEFAULT NULL,
+ `iDuration` int(11) DEFAULT NULL,
+ `iYear` int(11) DEFAULT NULL,
+ `dwFileNameCRC` text,
+ `strFileName` text,
+ `strMusicBrainzTrackID` text,
+ `iTimesPlayed` int(11) DEFAULT NULL,
+ `iStartOffset` int(11) DEFAULT NULL,
+ `iEndOffset` int(11) DEFAULT NULL,
+ `idThumb` int(11) DEFAULT NULL,
+ `lastplayed` varchar(20) DEFAULT NULL,
+ `rating` char(1) DEFAULT '0',
+ `comment` text,
+ `mood` text,
+ PRIMARY KEY (`idSong`),
+ UNIQUE KEY `idxSong7` (`idAlbum`,`strMusicBrainzTrackID`(36)),
+ KEY `idxSong` (`strTitle`(255)),
+ KEY `idxSong1` (`iTimesPlayed`),
+ KEY `idxSong2` (`lastplayed`),
+ KEY `idxSong3` (`idAlbum`),
+ KEY `idxSong6` (`idPath`,`strFileName`(255))
+) DEFAULT CHARSET=utf8;
+
+INSERT INTO `t1` VALUES (1,1,1,'strArtists1','strGenres1','strTitle1',1,100,2000,NULL,'strFileName1','strMusicBrainzTrackID1',0,0,0,NULL,NULL,'0','',''),(2,2,2,'strArtists2','strGenres2','strTitle2',2,200,2001,NULL,'strFileName2','strMusicBrainzTrackID2',0,0,0,NULL,NULL,'0','','');
+
+CREATE TABLE `t2` (
+ `idAlbum` int(11) NOT NULL AUTO_INCREMENT,
+ `strAlbum` varchar(256) DEFAULT NULL,
+ `strMusicBrainzAlbumID` text,
+ `strArtists` text,
+ `strGenres` text,
+ `iYear` int(11) DEFAULT NULL,
+ `idThumb` int(11) DEFAULT NULL,
+ `bCompilation` int(11) NOT NULL DEFAULT '0',
+ `strMoods` text,
+ `strStyles` text,
+ `strThemes` text,
+ `strReview` text,
+ `strImage` text,
+ `strLabel` text,
+ `strType` text,
+ `iRating` int(11) DEFAULT NULL,
+ `lastScraped` varchar(20) DEFAULT NULL,
+ `dateAdded` varchar(20) DEFAULT NULL,
+ `strReleaseType` text,
+ PRIMARY KEY (`idAlbum`),
+ UNIQUE KEY `idxAlbum_2` (`strMusicBrainzAlbumID`(36)),
+ KEY `idxAlbum` (`strAlbum`(255)),
+ KEY `idxAlbum_1` (`bCompilation`)
+) DEFAULT CHARSET=utf8;
+
+INSERT INTO `t2` VALUES (1,'strAlbum1','strMusicBrainzAlbumID1','strArtists1','strGenres1',2000,NULL,0,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,'album');
+
+CREATE TABLE `t3` (
+ `idArtist` int(11) DEFAULT NULL,
+ `idAlbum` int(11) DEFAULT NULL,
+ `strJoinPhrase` text,
+ `boolFeatured` int(11) DEFAULT NULL,
+ `iOrder` int(11) DEFAULT NULL,
+ `strArtist` text,
+ UNIQUE KEY `idxAlbumArtist_1` (`idAlbum`,`idArtist`),
+ UNIQUE KEY `idxAlbumArtist_2` (`idArtist`,`idAlbum`),
+ KEY `idxAlbumArtist_3` (`boolFeatured`)
+) DEFAULT CHARSET=utf8;
+
+INSERT INTO `t3` VALUES (1,1,'',0,0,'strArtist1');
+
+CREATE TABLE `t4` (
+ `idArtist` int(11) NOT NULL AUTO_INCREMENT,
+ `strArtist` varchar(256) DEFAULT NULL,
+ `strMusicBrainzArtistID` text,
+ `strBorn` text,
+ `strFormed` text,
+ `strGenres` text,
+ `strMoods` text,
+ `strStyles` text,
+ `strInstruments` text,
+ `strBiography` text,
+ `strDied` text,
+ `strDisbanded` text,
+ `strYearsActive` text,
+ `strImage` text,
+ `strFanart` text,
+ `lastScraped` varchar(20) DEFAULT NULL,
+ `dateAdded` varchar(20) DEFAULT NULL,
+ PRIMARY KEY (`idArtist`),
+ UNIQUE KEY `idxArtist1` (`strMusicBrainzArtistID`(36)),
+ KEY `idxArtist` (`strArtist`(255))
+) DEFAULT CHARSET=utf8;
+
+INSERT INTO `t4` VALUES (1,'strArtist1','strMusicBrainzArtistID',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL);
+
+CREATE VIEW `v1` AS select `t2`.`idAlbum` AS `idAlbum`,`t2`.`strAlbum` AS `strAlbum`,`t2`.`strMusicBrainzAlbumID` AS `strMusicBrainzAlbumID`,`t2`.`strArtists` AS `strArtists`,`t2`.`strGenres` AS `strGenres`,`t2`.`iYear` AS `iYear`,`t2`.`strMoods` AS `strMoods`,`t2`.`strStyles` AS `strStyles`,`t2`.`strThemes` AS `strThemes`,`t2`.`strReview` AS `strReview`,`t2`.`strLabel` AS `strLabel`,`t2`.`strType` AS `strType`,`t2`.`strImage` AS `strImage`,`t2`.`iRating` AS `iRating`,`t2`.`bCompilation` AS `bCompilation`,(select min(`t1`.`iTimesPlayed`) from `t1` where (`t1`.`idAlbum` = `t2`.`idAlbum`)) AS `iTimesPlayed`,`t2`.`strReleaseType` AS `strReleaseType` from `t2`;
+
+CREATE VIEW `v2` AS select `t3`.`idAlbum` AS `idAlbum`,`t3`.`idArtist` AS `idArtist`,`t4`.`strArtist` AS `strArtist`,`t4`.`strMusicBrainzArtistID` AS `strMusicBrainzArtistID`,`t3`.`boolFeatured` AS `boolFeatured`,`t3`.`strJoinPhrase` AS `strJoinPhrase`,`t3`.`iOrder` AS `iOrder` from (`t3` join `t4` on((`t3`.`idArtist` = `t4`.`idArtist`)));
+
+SELECT v1.*,v2.* FROM v1 LEFT JOIN v2 ON v1.idAlbum = v2.idAlbum WHERE v1.idAlbum = 1 ORDER BY v2.iOrder;
+
+drop view v1,v2;
+drop table t1,t2,t3,t4;
+
+--echo #
+--echo # MDEV-8913: Derived queries with same column names as final
+--echo # projection causes issues when using Order By
+--echo #
+create table t1 (field int);
+insert into t1 values (10),(5),(3),(8),(20);
+
+SELECT sq.f2 AS f1, sq.f1 AS f2
+FROM ( SELECT field AS f1, 1 AS f2 FROM t1) AS sq
+ORDER BY sq.f1;
+
+create view v1 as SELECT field AS f1, 1 AS f2 FROM t1;
+
+SELECT sq.f2 AS f1, sq.f1 AS f2
+FROM v1 AS sq
+ORDER BY sq.f1;
+
+drop view v1;
+
+create table t2 SELECT field AS f1, 1 AS f2 FROM t1;
+
+SELECT
+ sq.f2 AS f1,
+ sq.f1 AS f2
+FROM t2 AS sq
+ORDER BY sq.f1;
+
+drop table t1, t2;
+
+--error ER_BAD_FIELD_ERROR
+SELECT 1 FROM (SELECT 1 as a) AS b HAVING (SELECT `SOME_GARBAGE`.b.a)=1;
+
+
+--echo #
+--echo # MDEV-10035: DBUG_ASSERT on CREATE VIEW v1 AS SELECT * FROM t1
+--echo # FOR UPDATE
+--echo #
+
+CREATE TABLE t1 (a INT);
+insert into t1 values (1),(2);
+
+CREATE VIEW v1 AS SELECT * FROM t1 FOR UPDATE;
+SHOW CREATE VIEW v1;
+select * from v1;
+DROP VIEW v1;
+
+CREATE VIEW v1 AS SELECT * FROM t1 LOCK IN SHARE MODE;
+SHOW CREATE VIEW v1;
+select * from v1;
+DROP VIEW v1;
+
+DROP TABLE t1;
+
+--echo #
+--echo # MDEV-8642: WHERE Clause not applied on View - Empty result set returned
+--echo #
+
+CREATE TABLE `t1` (
+ `id` int(20) NOT NULL AUTO_INCREMENT,
+ `use_case` int(11) DEFAULT NULL,
+ `current_deadline` date DEFAULT NULL,
+ `ts_create` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
+ PRIMARY KEY (`id`),
+ UNIQUE KEY `id_UNIQUE` (`id`)
+) ENGINE=MyISAM AUTO_INCREMENT=13976 DEFAULT CHARSET=latin1;
+INSERT INTO `t1` VALUES (1,10,'2015-12-18','2015-08-18 08:38:16');
+INSERT INTO `t1` VALUES (2,20,'2015-10-18','2015-08-18 08:43:30');
+CREATE VIEW v1 AS SELECT
+ use_case as use_case_id,
+ (
+ SELECT
+ deadline_sub.current_deadline
+ FROM
+ t1 deadline_sub
+ WHERE
+ deadline_sub.use_case = use_case_id
+ AND ts_create = (SELECT
+ MIN(ts_create)
+ FROM
+ t1 startdate_sub
+ WHERE
+ startdate_sub.use_case = use_case_id
+ )
+ ) AS InitialDeadline
+FROM
+ t1;
+
+SELECT * FROM v1 where use_case_id = 10;
+
+drop view v1;
+drop table t1;
+
+--echo #
+--echo # MDEV-12666: CURRENT_ROLE() and DATABASE() does not work in a view
+--echo #
+--echo # DATABASE() fails only when the initial view creation features a NULL
+--echo # default database.
+--echo #
+--echo # CREATE, USE and DROP database so that we have no "default" database.
+--echo #
+CREATE DATABASE temporary;
+USE temporary;
+DROP DATABASE temporary;
+SELECT DATABASE();
+
+CREATE VIEW test.v_no_db AS SELECT DATABASE() = 'temporary_two';
+SHOW CREATE VIEW test.v_no_db;
+PREPARE prepared_no_database FROM "SELECT DATABASE() = 'temporary_two'";
+
+--echo #
+--echo # All statements should return NULL
+--echo #
+EXECUTE prepared_no_database;
+SELECT DATABASE() = 'temporary_two';
+SELECT * FROM test.v_no_db;
+
+CREATE DATABASE temporary_two;
+USE temporary_two;
+CREATE VIEW test.v_with_db AS SELECT DATABASE() = 'temporary_two';
+PREPARE prepared_with_database FROM "SELECT DATABASE() = 'temporary_two'";
+
+--echo #
+--echo # All statements should return 1;
+--echo #
+SELECT DATABASE() = 'temporary_two';
+SELECT * FROM test.v_no_db;
+SELECT * FROM test.v_with_db;
+EXECUTE prepared_with_database;
+
+--echo #
+--echo # Prepared statements maintain default database to be the same
+--echo # during on creation so this should return NULL still.
+--echo # See MySQL bug #25843
+--echo #
+EXECUTE prepared_no_database;
+
+DROP DATABASE temporary_two;
+DROP VIEW test.v_no_db;
+DROP VIEW test.v_with_db;
+USE test;
+
+--echo # -----------------------------------------------------------------
+--echo # -- End of 10.0 tests.
+--echo # -----------------------------------------------------------------
SET optimizer_switch=@save_optimizer_switch;
diff --git a/mysql-test/t/view_alias.test b/mysql-test/t/view_alias.test
index b155ba6c2a9..09d707296bb 100644
--- a/mysql-test/t/view_alias.test
+++ b/mysql-test/t/view_alias.test
@@ -90,3 +90,12 @@ eval CREATE VIEW v1 AS $query;
DROP VIEW v1;
DROP TABLE t1, t2;
+
+#
+# MDEV-7482 VIEW containing INTERVAL(...)
+#
+create view v1 as select interval(55,10) as my_col;
+show create view v1;
+select * from v1;
+drop view v1;
+
diff --git a/mysql-test/t/view_grant.test b/mysql-test/t/view_grant.test
index 847153d19f4..8907c726ae3 100644
--- a/mysql-test/t/view_grant.test
+++ b/mysql-test/t/view_grant.test
@@ -2047,6 +2047,168 @@ DROP DATABASE mysqltest1;
DROP USER 'mysqluser1'@'%';
DROP USER 'mysqluser2'@'%';
+--echo #
+--echo # Test for bug #11766767 - "59957: VIEW USING MERGE PERMISSIONS
+--echo # IN MULTI-TABLE UPDATE".
+--echo #
+--disable_warnings
+drop database if exists mysqltest1;
+drop database if exists mysqltest2;
+--enable_warnings
+--echo #
+--echo # Prepare playground.
+create database mysqltest1;
+create database mysqltest2;
+create user user_11766767;
+grant select on mysqltest1.* to user_11766767;
+grant all on mysqltest2.* to user_11766767;
+use mysqltest1;
+create table t1 (id int primary key, val varchar(20));
+insert into t1 values (1, 'test1');
+create table t11 (id int primary key);
+insert into t11 values (1);
+create algorithm=temptable view v1_temp as select * from t1;
+create algorithm=merge view v1_merge as select * from t1;
+create algorithm=temptable view v11_temp as
+ select t1.id as id, t1.val as val from t1, t11 where t1.id= t11.id;
+create algorithm=merge view v11_merge as
+ select t1.id as id, t1.val as val from t1, t11 where t1.id= t11.id;
+use mysqltest2;
+create table t2 (id int primary key, val varchar(20));
+insert into t2 values (1, 'test2');
+create table t21 (id int primary key);
+insert into t21 values (1);
+create algorithm=temptable view v2_temp as select * from t2;
+create algorithm=merge view v2_merge as select * from t2;
+create algorithm=temptable view v21_temp as
+ select t2.id as id, t2.val as val from t2, t21 where t2.id= t21.id;
+create algorithm=merge view v21_merge as
+ select t2.id as id, t2.val as val from t2, t21 where t2.id= t21.id;
+create algorithm=temptable sql security invoker view v3_temp as
+ select t1.id as id, t1.val as val from mysqltest1.t1 as t1, mysqltest1.t11 as t11
+ where t1.id = t11.id;
+create algorithm=merge sql security invoker view v3_merge as
+ select t1.id as id, t1.val as val from mysqltest1.t1 as t1, mysqltest1.t11 as t11
+ where t1.id = t11.id;
+create sql security invoker view v31 as
+ select t2.id as id, t2.val as val from mysqltest2.t2 as t2, mysqltest1.t11 as t11
+ where t2.id = t11.id;
+create sql security invoker view v4 as
+ select t2.id as id, t2.val as val from mysqltest2.t2 as t2, mysqltest1.v1_merge as v1
+ where t2.id = v1.id;
+create sql security invoker view v41 as
+ select v1.id as id, v1.val as val from mysqltest2.t2 as t2, mysqltest1.v1_merge as v1
+ where t2.id = v1.id;
+create sql security invoker view v42 as
+ select v2.id as id, v2.val as val from mysqltest2.t2 as t2, mysqltest2.v2_merge as v2
+ where t2.id = v2.id;
+
+
+--echo #
+--echo # Connect as user_11766767
+connect (conn_11766767, localhost, user_11766767,,);
+
+--echo #
+--echo # A) Check how we handle privilege checking in multi-update for
+--echo # directly used views.
+--echo #
+--echo # A.1) Originally reported problem, view is used in read-only mode.
+--echo # This should work with only SELECT privilege for both mergeable
+--echo # and temptable algorithms.
+update mysqltest2.t2 as t2, mysqltest1.v1_merge as v1 set t2.val= 'test3'
+ where t2.id= v1.id;
+update mysqltest2.t2 as t2, mysqltest1.v1_temp as v1 set t2.val= 'test4'
+ where t2.id= v1.id;
+--echo #
+--echo # A.2) If view is updated an UPDATE privilege on it is required.
+--echo # Temptable views can't be updated.
+--error ER_TABLEACCESS_DENIED_ERROR
+update mysqltest2.t2 as t2, mysqltest1.v1_merge as v1 set v1.val= 'test5'
+ where t2.id= v1.id;
+update mysqltest1.t1 as t1, mysqltest2.v2_merge as v2 set v2.val= 'test6'
+ where t1.id= v2.id;
+--echo #
+--echo # Note that the below error is OK even though user lacks UPDATE
+--echo # privilege on v1_temp since he/she still has SELECT privilege on
+--echo # this view.
+--error ER_NON_UPDATABLE_TABLE
+update mysqltest2.t2 as t2, mysqltest1.v1_temp as v1 set v1.val= 'test7'
+ where t2.id= v1.id;
+--error ER_NON_UPDATABLE_TABLE
+update mysqltest1.t1 as t1, mysqltest2.v2_temp as v2 set v2.val= 'test8'
+ where t1.id= v2.id;
+--echo #
+--echo # A.3) This also works for correctly for multi-table views.
+--echo # When usage is read-only SELECT is enough.
+update mysqltest2.t2 as t2, mysqltest1.v11_merge as v11 set t2.val= 'test9'
+ where t2.id= v11.id;
+update mysqltest2.t2 as t2, mysqltest1.v11_temp as v11 set t2.val= 'test10'
+ where t2.id= v11.id;
+--echo # When one of view's tables is updated, UPDATE is required
+--echo # on a view.
+--error ER_TABLEACCESS_DENIED_ERROR
+update mysqltest2.t2 as t2, mysqltest1.v11_merge as v11 set v11.val= 'test11'
+ where t2.id= v11.id;
+update mysqltest1.t1 as t1, mysqltest2.v21_merge as v21 set v21.val= 'test12'
+ where t1.id= v21.id;
+--echo # As before, temptable views are not updateable.
+--error ER_NON_UPDATABLE_TABLE
+update mysqltest2.t2 as t2, mysqltest1.v11_temp as v11 set v11.val= 'test13'
+ where t2.id= v11.id;
+--error ER_NON_UPDATABLE_TABLE
+update mysqltest1.t1 as t1, mysqltest2.v21_temp as v21 set v21.val= 'test14'
+ where t1.id= v21.id;
+
+--echo #
+--echo # B) Now check that correct privileges are required on underlying
+--echo # tables. To simplify this part of test we will use SECURITY
+--echo # INVOKER views in it.
+--echo #
+--echo # B.1) In case when view is used for read only it is enough to have
+--echo # SELECT on its underlying tables.
+update mysqltest2.t2 as t2, mysqltest2.v3_merge as v3 set t2.val= 'test15'
+ where t2.id= v3.id;
+update mysqltest2.t2 as t2, mysqltest2.v3_temp as v3 set t2.val= 'test16'
+ where t2.id= v3.id;
+--echo #
+--echo # B.2) If view is updated, UPDATE privilege on the table being updated
+--echo # is required (since we already checked that temptable views are
+--echo # not updateable we don't test them here).
+--error ER_VIEW_INVALID
+update mysqltest2.t2 as t2, mysqltest2.v3_merge as v3 set v3.val= 'test17'
+ where t2.id= v3.id;
+update mysqltest1.t11 as t11, mysqltest2.v31 as v31 set v31.val= 'test18'
+ where t11.id= v31.id;
+
+--disable_ps_protocol
+--echo #
+--echo # C) Finally, check how we handle privilege checking in case when
+--echo # view is used through another view. Again we will use SECURITY
+--echo # INVOKER views for simplicity.
+--echo #
+--echo # C.1) As usual, when a view used by another view is going to be used
+--echo # in read-only fashion, only SELECT privilege is necessary.
+update mysqltest1.t11 as t11, mysqltest2.v4 as v4 set v4.val= 'test19'
+ where t11.id= v4.id;
+--echo #
+--echo # C.2) If one of underlying tables of the view is updated then
+--echo # UPDATE on a view is necessary.
+--error ER_VIEW_INVALID
+update mysqltest1.t11 as t11, mysqltest2.v41 as v4 set v4.val= 'test20'
+ where t11.id= v4.id;
+update mysqltest1.t11 as t11, mysqltest2.v42 as v4 set v4.val= 'test20'
+ where t11.id= v4.id;
+--enable_ps_protocol
+
+--echo #
+--echo # Clean-up.
+--echo #
+--echo # Switching to connection 'default'.
+disconnect conn_11766767;
+connection default;
+drop user user_11766767;
+drop database mysqltest1;
+drop database mysqltest2;
# Wait till we reached the initial number of concurrent sessions
--source include/wait_until_count_sessions.inc
diff --git a/mysql-test/t/xa_binlog.test b/mysql-test/t/xa_binlog.test
index 48f1dc6dfaa..ecbf1f4f066 100644
--- a/mysql-test/t/xa_binlog.test
+++ b/mysql-test/t/xa_binlog.test
@@ -26,7 +26,7 @@ COMMIT;
SELECT * FROM t1 ORDER BY a;
--replace_column 2 # 5 #
---replace_regex /xid=[0-9]+/xid=XX/
-SHOW BINLOG EVENTS LIMIT 1,9;
+--replace_regex /xid=[0-9]+/xid=XX/ /GTID [0-9]+-[0-9]+-[0-9]+/GTID #-#-#/
+SHOW BINLOG EVENTS LIMIT 3,9;
DROP TABLE t1;
diff --git a/mysql-test/t/xml.test b/mysql-test/t/xml.test
index ec632eb90c3..e9e7864c418 100644
--- a/mysql-test/t/xml.test
+++ b/mysql-test/t/xml.test
@@ -692,5 +692,72 @@ SELECT ExtractValue('<a><a>aa</a><b>bb</b></a>','(a)/a|(a)/b');
SELECT ExtractValue('<a><b>abc</b><c>2</c><d>1</d></a>','substring(/a/b,..)');
--echo #
+--echo # Bug#62429 XML: ExtractValue, UpdateXML max arg length 127 chars
+--echo #
+CREATE TABLE t1 (id INT AUTO_INCREMENT, txt VARCHAR(1000), PRIMARY KEY(id));
+
+INSERT INTO t1 (txt) VALUES
+(CONCAT('<', REPEAT('a',127), '>127</', REPEAT('a',127), '>')),
+(CONCAT('<', REPEAT('a',128), '>128</', REPEAT('a',128), '>')),
+(CONCAT('<', REPEAT('a',63), '><', REPEAT('b',63), '>63/63</', REPEAT('b',63), '></', REPEAT('a',63),'>')),
+(CONCAT('<', REPEAT('a',63), '><', REPEAT('b',64), '>63/64</', REPEAT('b',64), '></', REPEAT('a',63),'>'));
+
+--vertical_results
+SELECT
+ txt,
+ EXTRACTVALUE(txt, CONCAT('/', REPEAT('a', 127))) as a127,
+ EXTRACTVALUE(txt, CONCAT('/', REPEAT('a', 128))) as a128,
+ EXTRACTVALUE(txt, CONCAT('//', REPEAT('b', 63))) as a63b63,
+ EXTRACTVALUE(txt, CONCAT('//', REPEAT('b', 64))) as a63b64
+FROM t1;
+SELECT UPDATEXML(txt, CONCAT('//', REPEAT('b', 63)), '63/63+') FROM t1;
+DROP TABLE t1;
+
+# This will call my_str_realloc_mysqld()
+CREATE TABLE t1 (a TEXT);
+INSERT INTO t1 VALUES (CONCAT('<a><', REPEAT('b',128),'>b128</',REPEAT('b',128),'><',REPEAT('c',512),'>c512</',REPEAT('c',512),'></a>'));
+SELECT ExtractValue (a, CONCAT('//',REPEAT('c',512))) AS c512 FROM t1;
+DROP TABLE t1;
+
+--horizontal_results
+
+--echo #
--echo # End of 5.5 tests
--echo #
+
+--echo #
+--echo # Start of 10.0 tests
+--echo #
+
+
+--echo #
+--echo # MDEV-5689 ExtractValue(xml, 'substring(/x,/y)') crashes
+--echo #
+SELECT ExtractValue('<a><b>abc</b><c>2</c><d>1</d></a>','substring(/a/b,..)') AS e;
+SELECT ExtractValue('<a><b>abc</b><c>2</c><d>1</d></a>','substring(/a/b,/a/c)') AS e;
+SELECT ExtractValue('<a><b>abc</b><c>2</c><d>1</d></a>','substring(/a/b,/a/d)') AS e;
+SELECT ExtractValue('<a><b>abc</b><c>2</c><d>1</d></a>','substring(/a/b,/a/c,/a/d)') AS e;
+SELECT ExtractValue('<a><b>abc</b><c>2</c><d>1</d></a>','substring(/a/b,/a/d,/a/c)') AS e;
+
+--echo #
+--echo # MDEV-5709 ExtractValue() with XPath variable references returns wrong result
+--echo #
+CREATE TABLE t1 (c1 INT, c2 VARCHAR(10));
+INSERT INTO t1 VALUES (1,'b1'),(2,'b2');
+SELECT *,IF(@i:=c1,ExtractValue('<a><b>b1</b><b>b2</b></a>','//b[$@i]'),0) AS xpath FROM t1;
+SELECT * FROM t1 WHERE c2=IF(@i:=c1,ExtractValue('<a><b>b1</b><b>b2</b></a>','//b[$@i]'),0);
+DROP TABLE t1;
+
+--echo #
+--echo # MDEV-15118 ExtractValue(xml,something_complex) does not work
+--echo #
+
+CREATE TABLE t1 (a TEXT);
+INSERT INTO t1 VALUES (CONCAT('<a>aaa</a>'));
+SELECT ExtractValue(a, '/a') AS a FROM t1;
+SELECT ExtractValue(a, FROM_BASE64(TO_BASE64('/a'))) AS a FROM t1;
+DROP TABLE t1;
+
+--echo #
+--echo # End of 10.0 tests
+--echo #