summaryrefslogtreecommitdiffstats
path: root/mysql-test/suite/innodb/t
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--mysql-test/suite/innodb/t/101_compatibility.test109
-rw-r--r--mysql-test/suite/innodb/t/add_constraint.test20
-rw-r--r--mysql-test/suite/innodb/t/alter_algorithm.combinations15
-rw-r--r--mysql-test/suite/innodb/t/alter_algorithm.inc2
-rw-r--r--mysql-test/suite/innodb/t/alter_algorithm.test145
-rw-r--r--mysql-test/suite/innodb/t/alter_algorithm2.test63
-rw-r--r--mysql-test/suite/innodb/t/alter_candidate_key.test74
-rw-r--r--mysql-test/suite/innodb/t/alter_copy.test94
-rw-r--r--mysql-test/suite/innodb/t/alter_crash.opt1
-rw-r--r--mysql-test/suite/innodb/t/alter_crash.test229
-rw-r--r--mysql-test/suite/innodb/t/alter_crash_rebuild.test24
-rw-r--r--mysql-test/suite/innodb/t/alter_dml_apply.opt2
-rw-r--r--mysql-test/suite/innodb/t/alter_dml_apply.test60
-rw-r--r--mysql-test/suite/innodb/t/alter_foreign_crash.test47
-rw-r--r--mysql-test/suite/innodb/t/alter_inplace_perfschema.opt2
-rw-r--r--mysql-test/suite/innodb/t/alter_inplace_perfschema.test42
-rw-r--r--mysql-test/suite/innodb/t/alter_key_block_size-11757.test32
-rw-r--r--mysql-test/suite/innodb/t/alter_kill-master.opt1
-rw-r--r--mysql-test/suite/innodb/t/alter_kill.test175
-rw-r--r--mysql-test/suite/innodb/t/alter_large_dml.opt2
-rw-r--r--mysql-test/suite/innodb/t/alter_large_dml.test51
-rw-r--r--mysql-test/suite/innodb/t/alter_mdl_timeout.opt1
-rw-r--r--mysql-test/suite/innodb/t/alter_mdl_timeout.test33
-rw-r--r--mysql-test/suite/innodb/t/alter_missing_tablespace.test76
-rw-r--r--mysql-test/suite/innodb/t/alter_non_null.inc2
-rw-r--r--mysql-test/suite/innodb/t/alter_not_null.combinations5
-rw-r--r--mysql-test/suite/innodb/t/alter_not_null.test102
-rw-r--r--mysql-test/suite/innodb/t/alter_not_null_debug.test99
-rw-r--r--mysql-test/suite/innodb/t/alter_partitioned.test68
-rw-r--r--mysql-test/suite/innodb/t/alter_partitioned_debug.test34
-rw-r--r--mysql-test/suite/innodb/t/alter_partitioned_xa.test31
-rw-r--r--mysql-test/suite/innodb/t/alter_persistent_autoinc.test86
-rw-r--r--mysql-test/suite/innodb/t/alter_primary_key.test35
-rw-r--r--mysql-test/suite/innodb/t/alter_rename_existing.test93
-rw-r--r--mysql-test/suite/innodb/t/alter_sql_mode.combinations5
-rw-r--r--mysql-test/suite/innodb/t/alter_sql_mode.inc2
-rw-r--r--mysql-test/suite/innodb/t/alter_table.test143
-rw-r--r--mysql-test/suite/innodb/t/alter_table_upgrade.test36
-rw-r--r--mysql-test/suite/innodb/t/alter_varchar_change.test375
-rw-r--r--mysql-test/suite/innodb/t/analyze_table.test23
-rw-r--r--mysql-test/suite/innodb/t/auto_increment_dup.opt2
-rw-r--r--mysql-test/suite/innodb/t/auto_increment_dup.test157
-rw-r--r--mysql-test/suite/innodb/t/autoinc_debug.test94
-rw-r--r--mysql-test/suite/innodb/t/autoinc_persist.combinations2
-rw-r--r--mysql-test/suite/innodb/t/autoinc_persist.test569
-rw-r--r--mysql-test/suite/innodb/t/binlog_consistent.test126
-rw-r--r--mysql-test/suite/innodb/t/blob-crash.test211
-rw-r--r--mysql-test/suite/innodb/t/blob-update-debug.test19
-rw-r--r--mysql-test/suite/innodb/t/blob_cmp_empty.test26
-rw-r--r--mysql-test/suite/innodb/t/blob_unique2pk.test20
-rw-r--r--mysql-test/suite/innodb/t/buf_pool_resize_oom.opt1
-rw-r--r--mysql-test/suite/innodb/t/buf_pool_resize_oom.test27
-rw-r--r--mysql-test/suite/innodb/t/change_column_collation.test156
-rw-r--r--mysql-test/suite/innodb/t/check_ibd_filesize.test59
-rw-r--r--mysql-test/suite/innodb/t/compression_providers_loaded.combinations19
-rw-r--r--mysql-test/suite/innodb/t/compression_providers_loaded.test18
-rw-r--r--mysql-test/suite/innodb/t/compression_providers_unloaded.combinations14
-rw-r--r--mysql-test/suite/innodb/t/compression_providers_unloaded.test13
-rw-r--r--mysql-test/suite/innodb/t/corrupted_during_recovery.opt2
-rw-r--r--mysql-test/suite/innodb/t/corrupted_during_recovery.test95
-rw-r--r--mysql-test/suite/innodb/t/count_distinct.test15
-rw-r--r--mysql-test/suite/innodb/t/create-index.test11
-rw-r--r--mysql-test/suite/innodb/t/create_isl_with_direct.opt1
-rw-r--r--mysql-test/suite/innodb/t/create_isl_with_direct.test21
-rw-r--r--mysql-test/suite/innodb/t/create_select.test28
-rw-r--r--mysql-test/suite/innodb/t/create_table_insert_skip_locked.test73
-rw-r--r--mysql-test/suite/innodb/t/cursor-restore-locking.test87
-rw-r--r--mysql-test/suite/innodb/t/data_types.opt1
-rw-r--r--mysql-test/suite/innodb/t/data_types.test152
-rw-r--r--mysql-test/suite/innodb/t/ddl_purge.test41
-rw-r--r--mysql-test/suite/innodb/t/deadlock_detect.combinations7
-rw-r--r--mysql-test/suite/innodb/t/deadlock_detect.test79
-rw-r--r--mysql-test/suite/innodb/t/deadlock_in_subqueries_join.test81
-rw-r--r--mysql-test/suite/innodb/t/deadlock_on_lock_upgrade.test143
-rw-r--r--mysql-test/suite/innodb/t/deadlock_victim_race.test113
-rw-r--r--mysql-test/suite/innodb/t/deadlock_wait_lock_race.opt1
-rw-r--r--mysql-test/suite/innodb/t/deadlock_wait_lock_race.test67
-rw-r--r--mysql-test/suite/innodb/t/deadlock_wait_thr_race.opt1
-rw-r--r--mysql-test/suite/innodb/t/deadlock_wait_thr_race.test71
-rw-r--r--mysql-test/suite/innodb/t/default_row_format_alter.test172
-rw-r--r--mysql-test/suite/innodb/t/default_row_format_compatibility.test174
-rw-r--r--mysql-test/suite/innodb/t/default_row_format_create.test81
-rw-r--r--mysql-test/suite/innodb/t/defrag_mdl-9155.test22
-rw-r--r--mysql-test/suite/innodb/t/dml_purge.test78
-rw-r--r--mysql-test/suite/innodb/t/doublewrite.combinations7
-rw-r--r--mysql-test/suite/innodb/t/doublewrite.test467
-rw-r--r--mysql-test/suite/innodb/t/dropdb.test27
-rw-r--r--mysql-test/suite/innodb/t/dropdb_cs.test17
-rw-r--r--mysql-test/suite/innodb/t/encryption_threads_shutdown.opt6
-rw-r--r--mysql-test/suite/innodb/t/encryption_threads_shutdown.test32
-rw-r--r--mysql-test/suite/innodb/t/evict_tables_on_commit_debug.test11
-rw-r--r--mysql-test/suite/innodb/t/file_format_defaults.test44
-rw-r--r--mysql-test/suite/innodb/t/fk_col_alter.test152
-rw-r--r--mysql-test/suite/innodb/t/flush.opt1
-rw-r--r--mysql-test/suite/innodb/t/flush.test19
-rw-r--r--mysql-test/suite/innodb/t/foreign-keys.test270
-rw-r--r--mysql-test/suite/innodb/t/foreign_key.combinations5
-rw-r--r--mysql-test/suite/innodb/t/foreign_key.test1135
-rw-r--r--mysql-test/suite/innodb/t/foreign_key_debug.test77
-rw-r--r--mysql-test/suite/innodb/t/foreign_key_not_windows.test77
-rw-r--r--mysql-test/suite/innodb/t/full_crc32_import.test224
-rw-r--r--mysql-test/suite/innodb/t/gap_lock_split.test43
-rw-r--r--mysql-test/suite/innodb/t/gap_locks.test29
-rw-r--r--mysql-test/suite/innodb/t/group_commit.test120
-rw-r--r--mysql-test/suite/innodb/t/group_commit_binlog_pos-master.opt1
-rw-r--r--mysql-test/suite/innodb/t/group_commit_binlog_pos.test105
-rw-r--r--mysql-test/suite/innodb/t/group_commit_binlog_pos_no_optimize_thread-master.opt1
-rw-r--r--mysql-test/suite/innodb/t/group_commit_binlog_pos_no_optimize_thread.test105
-rw-r--r--mysql-test/suite/innodb/t/group_commit_crash-master.opt1
-rw-r--r--mysql-test/suite/innodb/t/group_commit_crash.test78
-rw-r--r--mysql-test/suite/innodb/t/group_commit_crash_no_optimize_thread-master.opt1
-rw-r--r--mysql-test/suite/innodb/t/group_commit_crash_no_optimize_thread.test78
-rw-r--r--mysql-test/suite/innodb/t/group_commit_force_recovery-master.opt1
-rw-r--r--mysql-test/suite/innodb/t/group_commit_force_recovery.test21
-rw-r--r--mysql-test/suite/innodb/t/group_commit_no_optimize_thread-master.opt1
-rw-r--r--mysql-test/suite/innodb/t/group_commit_no_optimize_thread.test120
-rw-r--r--mysql-test/suite/innodb/t/help_url.test8
-rw-r--r--mysql-test/suite/innodb/t/ibuf_delete.test67
-rw-r--r--mysql-test/suite/innodb/t/ibuf_not_empty.combinations9
-rw-r--r--mysql-test/suite/innodb/t/ibuf_not_empty.test117
-rw-r--r--mysql-test/suite/innodb/t/implicit_gap_lock_convertion.test21
-rw-r--r--mysql-test/suite/innodb/t/import_bugs.test35
-rw-r--r--mysql-test/suite/innodb/t/import_corrupted.test67
-rw-r--r--mysql-test/suite/innodb/t/import_tablespace_race.test55
-rw-r--r--mysql-test/suite/innodb/t/index_merge_threshold.opt2
-rw-r--r--mysql-test/suite/innodb/t/index_merge_threshold.test188
-rw-r--r--mysql-test/suite/innodb/t/index_tree_operation.opt1
-rw-r--r--mysql-test/suite/innodb/t/index_tree_operation.test74
-rw-r--r--mysql-test/suite/innodb/t/index_vcol_purge_startup.test28
-rw-r--r--mysql-test/suite/innodb/t/information_schema_grants.opt29
-rw-r--r--mysql-test/suite/innodb/t/information_schema_grants.test277
-rw-r--r--mysql-test/suite/innodb/t/innodb-16k-master.opt2
-rw-r--r--mysql-test/suite/innodb/t/innodb-16k.test463
-rw-r--r--mysql-test/suite/innodb/t/innodb-32k-crash-master.opt5
-rw-r--r--mysql-test/suite/innodb/t/innodb-32k-crash.test195
-rw-r--r--mysql-test/suite/innodb/t/innodb-32k-master.opt4
-rw-r--r--mysql-test/suite/innodb/t/innodb-32k.test609
-rw-r--r--mysql-test/suite/innodb/t/innodb-64k-crash-master.opt5
-rw-r--r--mysql-test/suite/innodb/t/innodb-64k-crash.test316
-rw-r--r--mysql-test/suite/innodb/t/innodb-64k-master.opt4
-rw-r--r--mysql-test/suite/innodb/t/innodb-64k.test652
-rw-r--r--mysql-test/suite/innodb/t/innodb-agregate.test18
-rw-r--r--mysql-test/suite/innodb/t/innodb-alter-autoinc.test104
-rw-r--r--mysql-test/suite/innodb/t/innodb-alter-debug.test192
-rw-r--r--mysql-test/suite/innodb/t/innodb-alter-nullable.test161
-rw-r--r--mysql-test/suite/innodb/t/innodb-alter-table.test208
-rw-r--r--mysql-test/suite/innodb/t/innodb-alter-tempfile.test91
-rw-r--r--mysql-test/suite/innodb/t/innodb-alter-timestamp.test114
-rw-r--r--mysql-test/suite/innodb/t/innodb-alter.opt3
-rw-r--r--mysql-test/suite/innodb/t/innodb-alter.test706
-rw-r--r--mysql-test/suite/innodb/t/innodb-analyze.test60
-rw-r--r--mysql-test/suite/innodb/t/innodb-autoinc-18274.test26
-rw-r--r--mysql-test/suite/innodb/t/innodb-autoinc-44030.test36
-rw-r--r--mysql-test/suite/innodb/t/innodb-autoinc-56228-master.opt1
-rw-r--r--mysql-test/suite/innodb/t/innodb-autoinc-56228.test34
-rw-r--r--mysql-test/suite/innodb/t/innodb-autoinc-61209.test43
-rw-r--r--mysql-test/suite/innodb/t/innodb-autoinc-optimize.test19
-rw-r--r--mysql-test/suite/innodb/t/innodb-autoinc-part.test24
-rw-r--r--mysql-test/suite/innodb/t/innodb-autoinc.opt3
-rw-r--r--mysql-test/suite/innodb/t/innodb-autoinc.test783
-rw-r--r--mysql-test/suite/innodb/t/innodb-bigblob.opt3
-rw-r--r--mysql-test/suite/innodb/t/innodb-bigblob.test16
-rw-r--r--mysql-test/suite/innodb/t/innodb-blob.test215
-rw-r--r--mysql-test/suite/innodb/t/innodb-bug-14068765.test59
-rw-r--r--mysql-test/suite/innodb/t/innodb-bug-14084530.test39
-rw-r--r--mysql-test/suite/innodb/t/innodb-consistent-master.opt1
-rw-r--r--mysql-test/suite/innodb/t/innodb-consistent.test58
-rw-r--r--mysql-test/suite/innodb/t/innodb-corrupted-table.test47
-rw-r--r--mysql-test/suite/innodb/t/innodb-dict.test32
-rw-r--r--mysql-test/suite/innodb/t/innodb-enlarge-blob.opt4
-rw-r--r--mysql-test/suite/innodb/t/innodb-enlarge-blob.test29
-rw-r--r--mysql-test/suite/innodb/t/innodb-fk-virtual.test61
-rw-r--r--mysql-test/suite/innodb/t/innodb-fk-warnings.test133
-rw-r--r--mysql-test/suite/innodb/t/innodb-fk.test262
-rw-r--r--mysql-test/suite/innodb/t/innodb-fkcheck.test125
-rw-r--r--mysql-test/suite/innodb/t/innodb-get-fk.test71
-rw-r--r--mysql-test/suite/innodb/t/innodb-index-debug.opt1
-rw-r--r--mysql-test/suite/innodb/t/innodb-index-debug.test179
-rw-r--r--mysql-test/suite/innodb/t/innodb-index-online-delete.test36
-rw-r--r--mysql-test/suite/innodb/t/innodb-index-online-fk.opt4
-rw-r--r--mysql-test/suite/innodb/t/innodb-index-online-fk.test484
-rw-r--r--mysql-test/suite/innodb/t/innodb-index-online-norebuild.opt1
-rw-r--r--mysql-test/suite/innodb/t/innodb-index-online-norebuild.test71
-rw-r--r--mysql-test/suite/innodb/t/innodb-index-online-purge.test73
-rw-r--r--mysql-test/suite/innodb/t/innodb-index-online.opt5
-rw-r--r--mysql-test/suite/innodb/t/innodb-index-online.test524
-rw-r--r--mysql-test/suite/innodb/t/innodb-index.opt1
-rw-r--r--mysql-test/suite/innodb/t/innodb-index.test1234
-rw-r--r--mysql-test/suite/innodb/t/innodb-index_ucs2.opt1
-rw-r--r--mysql-test/suite/innodb/t/innodb-index_ucs2.test5
-rw-r--r--mysql-test/suite/innodb/t/innodb-isolation.test357
-rw-r--r--mysql-test/suite/innodb/t/innodb-lock.test224
-rw-r--r--mysql-test/suite/innodb/t/innodb-lru-force-no-free-page.test24
-rw-r--r--mysql-test/suite/innodb/t/innodb-master.opt6
-rw-r--r--mysql-test/suite/innodb/t/innodb-mdev-7408.opt2
-rw-r--r--mysql-test/suite/innodb/t/innodb-mdev-7408.test18
-rw-r--r--mysql-test/suite/innodb/t/innodb-mdev-7513-master.opt1
-rw-r--r--mysql-test/suite/innodb/t/innodb-mdev-7513.test219
-rw-r--r--mysql-test/suite/innodb/t/innodb-mdev7046.test57
-rw-r--r--mysql-test/suite/innodb/t/innodb-on-duplicate-update.test63
-rw-r--r--mysql-test/suite/innodb/t/innodb-online-alter-gis.test68
-rw-r--r--mysql-test/suite/innodb/t/innodb-page_compression_none.test26
-rw-r--r--mysql-test/suite/innodb/t/innodb-read-view.test208
-rw-r--r--mysql-test/suite/innodb/t/innodb-replace-debug.test16
-rw-r--r--mysql-test/suite/innodb/t/innodb-replace.test22
-rw-r--r--mysql-test/suite/innodb/t/innodb-rollback.test17
-rw-r--r--mysql-test/suite/innodb/t/innodb-semi-consistent-master.opt1
-rw-r--r--mysql-test/suite/innodb/t/innodb-semi-consistent.test69
-rw-r--r--mysql-test/suite/innodb/t/innodb-stats-initialize-failure.test41
-rw-r--r--mysql-test/suite/innodb/t/innodb-stats-modified-counter.opt1
-rw-r--r--mysql-test/suite/innodb/t/innodb-stats-modified-counter.test28
-rw-r--r--mysql-test/suite/innodb/t/innodb-stats-sample.test75
-rw-r--r--mysql-test/suite/innodb/t/innodb-system-table-view.opt11
-rw-r--r--mysql-test/suite/innodb/t/innodb-system-table-view.test146
-rw-r--r--mysql-test/suite/innodb/t/innodb-table-online-master.opt1
-rw-r--r--mysql-test/suite/innodb/t/innodb-table-online.test482
-rw-r--r--mysql-test/suite/innodb/t/innodb-timeout.test200
-rw-r--r--mysql-test/suite/innodb/t/innodb-trim.test43
-rw-r--r--mysql-test/suite/innodb/t/innodb-truncate.test110
-rw-r--r--mysql-test/suite/innodb/t/innodb-ucs2.test230
-rw-r--r--mysql-test/suite/innodb/t/innodb-update-insert.test39
-rw-r--r--mysql-test/suite/innodb/t/innodb-virtual-columns-debug.test27
-rw-r--r--mysql-test/suite/innodb/t/innodb-virtual-columns.test319
-rw-r--r--mysql-test/suite/innodb/t/innodb-virtual-columns2.test74
-rw-r--r--mysql-test/suite/innodb/t/innodb-wl5522-1.test965
-rw-r--r--mysql-test/suite/innodb/t/innodb-wl5522-debug.test1401
-rw-r--r--mysql-test/suite/innodb/t/innodb-wl5522.test1116
-rw-r--r--mysql-test/suite/innodb/t/innodb-wl5980-alter.opt3
-rw-r--r--mysql-test/suite/innodb/t/innodb-wl5980-alter.test710
-rw-r--r--mysql-test/suite/innodb/t/innodb-xa.test50
-rw-r--r--mysql-test/suite/innodb/t/innodb.opt1
-rw-r--r--mysql-test/suite/innodb/t/innodb.test2611
-rw-r--r--mysql-test/suite/innodb/t/innodb_28867993.test16
-rw-r--r--mysql-test/suite/innodb/t/innodb_autoinc_lock_mode_zero-master.opt1
-rw-r--r--mysql-test/suite/innodb/t/innodb_autoinc_lock_mode_zero.test43
-rw-r--r--mysql-test/suite/innodb/t/innodb_buffer_pool_dump_pct.test95
-rw-r--r--mysql-test/suite/innodb/t/innodb_buffer_pool_fail.test11
-rw-r--r--mysql-test/suite/innodb/t/innodb_buffer_pool_load_now.opt3
-rw-r--r--mysql-test/suite/innodb/t/innodb_buffer_pool_load_now.test190
-rw-r--r--mysql-test/suite/innodb/t/innodb_buffer_pool_resize.opt2
-rw-r--r--mysql-test/suite/innodb/t/innodb_buffer_pool_resize.test72
-rw-r--r--mysql-test/suite/innodb/t/innodb_buffer_pool_resize_bigtest.opt2
-rw-r--r--mysql-test/suite/innodb/t/innodb_buffer_pool_resize_bigtest.test28
-rw-r--r--mysql-test/suite/innodb/t/innodb_buffer_pool_resize_debug.opt1
-rw-r--r--mysql-test/suite/innodb/t/innodb_buffer_pool_resize_temporary.test27
-rw-r--r--mysql-test/suite/innodb/t/innodb_buffer_pool_resize_with_chunks.opt3
-rw-r--r--mysql-test/suite/innodb/t/innodb_buffer_pool_resize_with_chunks.test61
-rw-r--r--mysql-test/suite/innodb/t/innodb_bug11754376.test15
-rw-r--r--mysql-test/suite/innodb/t/innodb_bug12400341.test102
-rw-r--r--mysql-test/suite/innodb/t/innodb_bug12661768.test50
-rw-r--r--mysql-test/suite/innodb/t/innodb_bug12902967.test25
-rw-r--r--mysql-test/suite/innodb/t/innodb_bug13510739.test20
-rw-r--r--mysql-test/suite/innodb/t/innodb_bug14007649.test62
-rw-r--r--mysql-test/suite/innodb/t/innodb_bug14147491-master.opt4
-rw-r--r--mysql-test/suite/innodb/t/innodb_bug14147491.test83
-rw-r--r--mysql-test/suite/innodb/t/innodb_bug14676111.opt1
-rw-r--r--mysql-test/suite/innodb/t/innodb_bug14676111.test130
-rw-r--r--mysql-test/suite/innodb/t/innodb_bug21704.test76
-rw-r--r--mysql-test/suite/innodb/t/innodb_bug30113362.opt1
-rw-r--r--mysql-test/suite/innodb/t/innodb_bug30113362.test244
-rw-r--r--mysql-test/suite/innodb/t/innodb_bug30423.test213
-rw-r--r--mysql-test/suite/innodb/t/innodb_bug30919-master.opt1
-rw-r--r--mysql-test/suite/innodb/t/innodb_bug30919.test72
-rw-r--r--mysql-test/suite/innodb/t/innodb_bug34300.test38
-rw-r--r--mysql-test/suite/innodb/t/innodb_bug35220.test15
-rw-r--r--mysql-test/suite/innodb/t/innodb_bug38231.test76
-rw-r--r--mysql-test/suite/innodb/t/innodb_bug39438-master.opt1
-rw-r--r--mysql-test/suite/innodb/t/innodb_bug39438.test50
-rw-r--r--mysql-test/suite/innodb/t/innodb_bug40360.test16
-rw-r--r--mysql-test/suite/innodb/t/innodb_bug40565.test10
-rw-r--r--mysql-test/suite/innodb/t/innodb_bug41904.test14
-rw-r--r--mysql-test/suite/innodb/t/innodb_bug42419.test80
-rw-r--r--mysql-test/suite/innodb/t/innodb_bug44032.test13
-rw-r--r--mysql-test/suite/innodb/t/innodb_bug44369.test17
-rw-r--r--mysql-test/suite/innodb/t/innodb_bug44571.test22
-rw-r--r--mysql-test/suite/innodb/t/innodb_bug45357.test10
-rw-r--r--mysql-test/suite/innodb/t/innodb_bug46000.test32
-rw-r--r--mysql-test/suite/innodb/t/innodb_bug46676.test16
-rw-r--r--mysql-test/suite/innodb/t/innodb_bug47621.test57
-rw-r--r--mysql-test/suite/innodb/t/innodb_bug47622.test55
-rw-r--r--mysql-test/suite/innodb/t/innodb_bug47777.test24
-rw-r--r--mysql-test/suite/innodb/t/innodb_bug48024.test22
-rw-r--r--mysql-test/suite/innodb/t/innodb_bug49164.test47
-rw-r--r--mysql-test/suite/innodb/t/innodb_bug51378.test77
-rw-r--r--mysql-test/suite/innodb/t/innodb_bug51920.test45
-rw-r--r--mysql-test/suite/innodb/t/innodb_bug52199.test10
-rw-r--r--mysql-test/suite/innodb/t/innodb_bug52663.test34
-rw-r--r--mysql-test/suite/innodb/t/innodb_bug53046.test44
-rw-r--r--mysql-test/suite/innodb/t/innodb_bug53290.test23
-rw-r--r--mysql-test/suite/innodb/t/innodb_bug53592.test84
-rw-r--r--mysql-test/suite/innodb/t/innodb_bug53674-master.opt1
-rw-r--r--mysql-test/suite/innodb/t/innodb_bug53674.test9
-rw-r--r--mysql-test/suite/innodb/t/innodb_bug53756-master.opt1
-rw-r--r--mysql-test/suite/innodb/t/innodb_bug53756.test105
-rw-r--r--mysql-test/suite/innodb/t/innodb_bug54044.test18
-rw-r--r--mysql-test/suite/innodb/t/innodb_bug56143.test585
-rw-r--r--mysql-test/suite/innodb/t/innodb_bug56716.test9
-rw-r--r--mysql-test/suite/innodb/t/innodb_bug56947.test19
-rw-r--r--mysql-test/suite/innodb/t/innodb_bug57252.test45
-rw-r--r--mysql-test/suite/innodb/t/innodb_bug57255.test38
-rw-r--r--mysql-test/suite/innodb/t/innodb_bug57904.test27
-rw-r--r--mysql-test/suite/innodb/t/innodb_bug59307.test32
-rw-r--r--mysql-test/suite/innodb/t/innodb_bug59410.test24
-rw-r--r--mysql-test/suite/innodb/t/innodb_bug59641.test58
-rw-r--r--mysql-test/suite/innodb/t/innodb_bug59733.test53
-rw-r--r--mysql-test/suite/innodb/t/innodb_bug60196-master.opt1
-rw-r--r--mysql-test/suite/innodb/t/innodb_bug60196.test159
-rw-r--r--mysql-test/suite/innodb/t/innodb_bug60229.test43
-rw-r--r--mysql-test/suite/innodb/t/innodb_bug68148.test38
-rw-r--r--mysql-test/suite/innodb/t/innodb_bug84958.test93
-rw-r--r--mysql-test/suite/innodb/t/innodb_bulk_create_index.test46
-rw-r--r--mysql-test/suite/innodb/t/innodb_bulk_create_index_debug.test24
-rw-r--r--mysql-test/suite/innodb/t/innodb_bulk_create_index_flush.opt1
-rw-r--r--mysql-test/suite/innodb/t/innodb_bulk_create_index_replication.test182
-rw-r--r--mysql-test/suite/innodb/t/innodb_bulk_create_index_small.test148
-rw-r--r--mysql-test/suite/innodb/t/innodb_corrupt_bit.opt1
-rw-r--r--mysql-test/suite/innodb/t/innodb_corrupt_bit.test99
-rw-r--r--mysql-test/suite/innodb/t/innodb_ctype_big5.test25
-rw-r--r--mysql-test/suite/innodb/t/innodb_ctype_latin1.test25
-rw-r--r--mysql-test/suite/innodb/t/innodb_ctype_ldml-master.opt3
-rw-r--r--mysql-test/suite/innodb/t/innodb_ctype_ldml.test370
-rw-r--r--mysql-test/suite/innodb/t/innodb_ctype_tis620.test91
-rw-r--r--mysql-test/suite/innodb/t/innodb_ctype_utf8.test54
-rw-r--r--mysql-test/suite/innodb/t/innodb_default_row_format.combinations6
-rw-r--r--mysql-test/suite/innodb/t/innodb_default_row_format.inc2
-rw-r--r--mysql-test/suite/innodb/t/innodb_defrag_binlog.opt5
-rw-r--r--mysql-test/suite/innodb/t/innodb_defrag_binlog.test21
-rw-r--r--mysql-test/suite/innodb/t/innodb_defrag_concurrent.opt5
-rw-r--r--mysql-test/suite/innodb/t/innodb_defrag_concurrent.test143
-rw-r--r--mysql-test/suite/innodb/t/innodb_defrag_stats.opt1
-rw-r--r--mysql-test/suite/innodb/t/innodb_defrag_stats.test88
-rw-r--r--mysql-test/suite/innodb/t/innodb_defrag_stats_many_tables.opt1
-rw-r--r--mysql-test/suite/innodb/t/innodb_defrag_stats_many_tables.test77
-rw-r--r--mysql-test/suite/innodb/t/innodb_defragment.opt5
-rw-r--r--mysql-test/suite/innodb/t/innodb_defragment.test157
-rw-r--r--mysql-test/suite/innodb/t/innodb_defragment_small.test41
-rw-r--r--mysql-test/suite/innodb/t/innodb_force_pk.opt1
-rw-r--r--mysql-test/suite/innodb/t/innodb_force_pk.test49
-rw-r--r--mysql-test/suite/innodb/t/innodb_force_recovery.test161
-rw-r--r--mysql-test/suite/innodb/t/innodb_force_recovery_rollback.test35
-rw-r--r--mysql-test/suite/innodb/t/innodb_gis.test22
-rw-r--r--mysql-test/suite/innodb/t/innodb_information_schema.test279
-rw-r--r--mysql-test/suite/innodb/t/innodb_information_schema_buffer.opt3
-rw-r--r--mysql-test/suite/innodb/t/innodb_information_schema_buffer.test57
-rw-r--r--mysql-test/suite/innodb/t/innodb_information_schema_tables.opt28
-rw-r--r--mysql-test/suite/innodb/t/innodb_information_schema_tables.test64
-rw-r--r--mysql-test/suite/innodb/t/innodb_lock_wait_timeout_1-master.opt1
-rw-r--r--mysql-test/suite/innodb/t/innodb_lock_wait_timeout_1.test244
-rw-r--r--mysql-test/suite/innodb/t/innodb_multi_update.test39
-rw-r--r--mysql-test/suite/innodb/t/innodb_mysql-master.opt2
-rw-r--r--mysql-test/suite/innodb/t/innodb_mysql.test1076
-rw-r--r--mysql-test/suite/innodb/t/innodb_mysql_rbk-master.opt1
-rw-r--r--mysql-test/suite/innodb/t/innodb_mysql_rbk.test35
-rw-r--r--mysql-test/suite/innodb/t/innodb_notembedded.test50
-rw-r--r--mysql-test/suite/innodb/t/innodb_page_compressed.combinations11
-rw-r--r--mysql-test/suite/innodb/t/innodb_page_compressed.test86
-rw-r--r--mysql-test/suite/innodb/t/innodb_prefix_index_restart_server.test95
-rw-r--r--mysql-test/suite/innodb/t/innodb_query_cache.test47
-rw-r--r--mysql-test/suite/innodb/t/innodb_rename_index.test538
-rw-r--r--mysql-test/suite/innodb/t/innodb_row_lock_time_ms.test42
-rw-r--r--mysql-test/suite/innodb/t/innodb_scrub.opt1
-rw-r--r--mysql-test/suite/innodb/t/innodb_scrub.test45
-rw-r--r--mysql-test/suite/innodb/t/innodb_skip_innodb_is_tables.opt61
-rw-r--r--mysql-test/suite/innodb/t/innodb_skip_innodb_is_tables.test29
-rw-r--r--mysql-test/suite/innodb/t/innodb_stats.test65
-rw-r--r--mysql-test/suite/innodb/t/innodb_stats_create_on_corrupted.test60
-rw-r--r--mysql-test/suite/innodb/t/innodb_stats_create_table.test66
-rw-r--r--mysql-test/suite/innodb/t/innodb_stats_drop_locked.test65
-rw-r--r--mysql-test/suite/innodb/t/innodb_stats_fetch.test83
-rw-r--r--mysql-test/suite/innodb/t/innodb_stats_fetch_corrupted.test58
-rw-r--r--mysql-test/suite/innodb/t/innodb_stats_fetch_nonexistent.test38
-rw-r--r--mysql-test/suite/innodb/t/innodb_stats_persistent.test84
-rw-r--r--mysql-test/suite/innodb/t/innodb_stats_persistent_debug.test32
-rw-r--r--mysql-test/suite/innodb/t/innodb_stats_rename_table.test42
-rw-r--r--mysql-test/suite/innodb/t/innodb_stats_rename_table_if_exists.test75
-rw-r--r--mysql-test/suite/innodb/t/innodb_status_variables.test7
-rw-r--r--mysql-test/suite/innodb/t/innodb_sys_var_valgrind.test52
-rw-r--r--mysql-test/suite/innodb/t/innodb_timeout_rollback-master.opt1
-rw-r--r--mysql-test/suite/innodb/t/innodb_timeout_rollback.test4
-rw-r--r--mysql-test/suite/innodb/t/innodb_trx_weight.test106
-rw-r--r--mysql-test/suite/innodb/t/innodb_uninstall.opt3
-rw-r--r--mysql-test/suite/innodb/t/innodb_uninstall.test66
-rw-r--r--mysql-test/suite/innodb/t/insert-before-delete.test72
-rw-r--r--mysql-test/suite/innodb/t/insert_debug.test49
-rw-r--r--mysql-test/suite/innodb/t/insert_into_empty.opt1
-rw-r--r--mysql-test/suite/innodb/t/insert_into_empty.test497
-rw-r--r--mysql-test/suite/innodb/t/insert_into_empty_debug.test36
-rw-r--r--mysql-test/suite/innodb/t/insert_into_empty_notembedded.test60
-rw-r--r--mysql-test/suite/innodb/t/instant_alter.opt1
-rw-r--r--mysql-test/suite/innodb/t/instant_alter.test966
-rw-r--r--mysql-test/suite/innodb/t/instant_alter_bugs.test529
-rw-r--r--mysql-test/suite/innodb/t/instant_alter_charset.test890
-rw-r--r--mysql-test/suite/innodb/t/instant_alter_crash.test258
-rw-r--r--mysql-test/suite/innodb/t/instant_alter_debug.combinations6
-rw-r--r--mysql-test/suite/innodb/t/instant_alter_debug.test609
-rw-r--r--mysql-test/suite/innodb/t/instant_alter_extend.combinations5
-rw-r--r--mysql-test/suite/innodb/t/instant_alter_extend.test258
-rw-r--r--mysql-test/suite/innodb/t/instant_alter_import.test235
-rw-r--r--mysql-test/suite/innodb/t/instant_alter_index_rename.test233
-rw-r--r--mysql-test/suite/innodb/t/instant_alter_inject.test46
-rw-r--r--mysql-test/suite/innodb/t/instant_alter_limit.test76
-rw-r--r--mysql-test/suite/innodb/t/instant_alter_null.test67
-rw-r--r--mysql-test/suite/innodb/t/instant_alter_purge.test34
-rw-r--r--mysql-test/suite/innodb/t/instant_alter_rollback.test70
-rw-r--r--mysql-test/suite/innodb/t/instant_alter_upgrade.test16
-rw-r--r--mysql-test/suite/innodb/t/instant_auto_inc.test13
-rw-r--r--mysql-test/suite/innodb/t/instant_drop.test108
-rw-r--r--mysql-test/suite/innodb/t/leaf_page_corrupted_during_recovery.combinations5
-rw-r--r--mysql-test/suite/innodb/t/leaf_page_corrupted_during_recovery.opt2
-rw-r--r--mysql-test/suite/innodb/t/leaf_page_corrupted_during_recovery.test60
-rw-r--r--mysql-test/suite/innodb/t/lock_delete_updated.test32
-rw-r--r--mysql-test/suite/innodb/t/lock_deleted.test72
-rw-r--r--mysql-test/suite/innodb/t/lock_insert_into_empty.test63
-rw-r--r--mysql-test/suite/innodb/t/lock_move_wait_lock_race.test58
-rw-r--r--mysql-test/suite/innodb/t/lock_update_split_rc.test76
-rw-r--r--mysql-test/suite/innodb/t/log_corruption.test642
-rw-r--r--mysql-test/suite/innodb/t/log_data_file_size.opt2
-rw-r--r--mysql-test/suite/innodb/t/log_data_file_size.test80
-rw-r--r--mysql-test/suite/innodb/t/log_file.test219
-rw-r--r--mysql-test/suite/innodb/t/log_file_name.test217
-rw-r--r--mysql-test/suite/innodb/t/log_file_size.test175
-rw-r--r--mysql-test/suite/innodb/t/log_file_size_online.combinations11
-rw-r--r--mysql-test/suite/innodb/t/log_file_size_online.test44
-rw-r--r--mysql-test/suite/innodb/t/log_upgrade.test120
-rw-r--r--mysql-test/suite/innodb/t/max_record_size.test1422
-rw-r--r--mysql-test/suite/innodb/t/mdev-117.test34
-rw-r--r--mysql-test/suite/innodb/t/mdev-14846.opt1
-rw-r--r--mysql-test/suite/innodb/t/mdev-14846.test71
-rw-r--r--mysql-test/suite/innodb/t/mdev-15707.opt1
-rw-r--r--mysql-test/suite/innodb/t/mdev-15707.test30
-rw-r--r--mysql-test/suite/innodb/t/missing_tablespaces.test37
-rw-r--r--mysql-test/suite/innodb/t/mon_lock_wait_current_count.test97
-rw-r--r--mysql-test/suite/innodb/t/monitor.test469
-rw-r--r--mysql-test/suite/innodb/t/multi_repair-7404.test18
-rw-r--r--mysql-test/suite/innodb/t/mvcc.test72
-rw-r--r--mysql-test/suite/innodb/t/mvcc_secondary.test26
-rw-r--r--mysql-test/suite/innodb/t/no_pad.test10
-rw-r--r--mysql-test/suite/innodb/t/online_table_rebuild.opt2
-rw-r--r--mysql-test/suite/innodb/t/online_table_rebuild.test87
-rw-r--r--mysql-test/suite/innodb/t/page_cleaner.test30
-rw-r--r--mysql-test/suite/innodb/t/page_id_innochecksum.test70
-rw-r--r--mysql-test/suite/innodb/t/page_reorganize.test64
-rw-r--r--mysql-test/suite/innodb/t/partition_locking.test178
-rw-r--r--mysql-test/suite/innodb/t/purge.test113
-rw-r--r--mysql-test/suite/innodb/t/purge_secondary.opt4
-rw-r--r--mysql-test/suite/innodb/t/purge_secondary.test172
-rw-r--r--mysql-test/suite/innodb/t/purge_thread_shutdown.test43
-rw-r--r--mysql-test/suite/innodb/t/read_only_recover_committed.test99
-rw-r--r--mysql-test/suite/innodb/t/read_only_recovery.test45
-rw-r--r--mysql-test/suite/innodb/t/readahead.test25
-rw-r--r--mysql-test/suite/innodb/t/recovery_memory.opt1
-rw-r--r--mysql-test/suite/innodb/t/recovery_memory.test51
-rw-r--r--mysql-test/suite/innodb/t/recovery_shutdown.test73
-rw-r--r--mysql-test/suite/innodb/t/rename_table.opt2
-rw-r--r--mysql-test/suite/innodb/t/rename_table.test61
-rw-r--r--mysql-test/suite/innodb/t/restart.opt2
-rw-r--r--mysql-test/suite/innodb/t/restart.test171
-rw-r--r--mysql-test/suite/innodb/t/row_format_redundant.opt1
-rw-r--r--mysql-test/suite/innodb/t/row_format_redundant.test166
-rw-r--r--mysql-test/suite/innodb/t/row_lock.test50
-rw-r--r--mysql-test/suite/innodb/t/row_size_error_log_warnings_3.test87
-rw-r--r--mysql-test/suite/innodb/t/scrub.test18
-rw-r--r--mysql-test/suite/innodb/t/scrub_debug.test28
-rw-r--r--mysql-test/suite/innodb/t/skip_locked_nowait.test208
-rw-r--r--mysql-test/suite/innodb/t/skip_symbolic_links.opt1
-rw-r--r--mysql-test/suite/innodb/t/skip_symbolic_links.test51
-rw-r--r--mysql-test/suite/innodb/t/snapshot.test18
-rw-r--r--mysql-test/suite/innodb/t/sp_temp_table.test103
-rw-r--r--mysql-test/suite/innodb/t/sql_mode_pad_char_to_full_length.test18
-rw-r--r--mysql-test/suite/innodb/t/stat_tables.test84
-rw-r--r--mysql-test/suite/innodb/t/stats_persistent.test28
-rw-r--r--mysql-test/suite/innodb/t/stored_fk.test98
-rw-r--r--mysql-test/suite/innodb/t/strict_mode.test422
-rw-r--r--mysql-test/suite/innodb/t/system_tables.test12
-rw-r--r--mysql-test/suite/innodb/t/table_definition_cache_debug.opt1
-rw-r--r--mysql-test/suite/innodb/t/table_definition_cache_debug.test71
-rw-r--r--mysql-test/suite/innodb/t/table_flags.combinations5
-rw-r--r--mysql-test/suite/innodb/t/table_flags.opt2
-rw-r--r--mysql-test/suite/innodb/t/table_flags.test253
-rw-r--r--mysql-test/suite/innodb/t/table_index_statistics.inc61
-rw-r--r--mysql-test/suite/innodb/t/table_index_statistics.test8
-rw-r--r--mysql-test/suite/innodb/t/temp_table.test54
-rw-r--r--mysql-test/suite/innodb/t/temp_table_savepoint.test215
-rw-r--r--mysql-test/suite/innodb/t/temporary_table.test638
-rw-r--r--mysql-test/suite/innodb/t/temporary_table_optimization.opt1
-rw-r--r--mysql-test/suite/innodb/t/temporary_table_optimization.test240
-rw-r--r--mysql-test/suite/innodb/t/tmpdir.test61
-rw-r--r--mysql-test/suite/innodb/t/trigger.test47
-rw-r--r--mysql-test/suite/innodb/t/trigger_error.test31
-rw-r--r--mysql-test/suite/innodb/t/truncate.test81
-rw-r--r--mysql-test/suite/innodb/t/truncate_crash.test26
-rw-r--r--mysql-test/suite/innodb/t/truncate_foreign.test112
-rw-r--r--mysql-test/suite/innodb/t/truncate_missing.test22
-rw-r--r--mysql-test/suite/innodb/t/trx_id_future.combinations5
-rw-r--r--mysql-test/suite/innodb/t/trx_id_future.test66
-rw-r--r--mysql-test/suite/innodb/t/trx_sys_t_find_lf_hash_error.test87
-rw-r--r--mysql-test/suite/innodb/t/undo_log.test153
-rw-r--r--mysql-test/suite/innodb/t/undo_space_dblwr.opt2
-rw-r--r--mysql-test/suite/innodb/t/undo_space_dblwr.test46
-rw-r--r--mysql-test/suite/innodb/t/undo_truncate.opt3
-rw-r--r--mysql-test/suite/innodb/t/undo_truncate.test72
-rw-r--r--mysql-test/suite/innodb/t/undo_truncate_recover.combinations5
-rw-r--r--mysql-test/suite/innodb/t/undo_truncate_recover.opt1
-rw-r--r--mysql-test/suite/innodb/t/undo_truncate_recover.test57
-rw-r--r--mysql-test/suite/innodb/t/undo_upgrade.opt2
-rw-r--r--mysql-test/suite/innodb/t/undo_upgrade.test78
-rw-r--r--mysql-test/suite/innodb/t/undo_upgrade_debug.test70
-rw-r--r--mysql-test/suite/innodb/t/update-cascade.test221
-rw-r--r--mysql-test/suite/innodb/t/update_time-master.opt1
-rw-r--r--mysql-test/suite/innodb/t/update_time.test48
-rw-r--r--mysql-test/suite/innodb/t/update_time_wl6658.test232
-rw-r--r--mysql-test/suite/innodb/t/xa_debug.test46
-rw-r--r--mysql-test/suite/innodb/t/xa_prepare_reset_supremum_lock.test48
-rw-r--r--mysql-test/suite/innodb/t/xa_recovery.test63
-rw-r--r--mysql-test/suite/innodb/t/xa_recovery_debug.test43
-rw-r--r--mysql-test/suite/innodb/t/xap_release_locks_on_dict_stats_table.test33
516 files changed, 53452 insertions, 0 deletions
diff --git a/mysql-test/suite/innodb/t/101_compatibility.test b/mysql-test/suite/innodb/t/101_compatibility.test
new file mode 100644
index 00000000..878daad2
--- /dev/null
+++ b/mysql-test/suite/innodb/t/101_compatibility.test
@@ -0,0 +1,109 @@
+--source include/innodb_page_size.inc
+--source include/not_embedded.inc
+--source include/have_symlink.inc
+
+-- echo #
+-- echo # MDEV-11623 MariaDB 10.1 fails to start datadir created with
+-- echo # MariaDB 10.0/MySQL 5.6 using innodb-page-size!=16K
+-- echo #
+
+# This is actually testing the opposite: starting the fixed 10.1 with
+# buggy 10.1 files (by manually converting the flags in the files).
+
+--disable_query_log
+call mtr.add_suppression("InnoDB: adjusting FSP_SPACE_FLAGS of file ");
+FLUSH TABLES;
+--enable_query_log
+let INNODB_PAGE_SIZE=`select @@innodb_page_size`;
+let MYSQLD_DATADIR=`select @@datadir`;
+
+CREATE TABLE tr(a INT)ENGINE=InnoDB ROW_FORMAT=REDUNDANT;
+CREATE TABLE tc(a INT)ENGINE=InnoDB ROW_FORMAT=COMPACT;
+CREATE TABLE td(a INT)ENGINE=InnoDB ROW_FORMAT=DYNAMIC;
+--disable_warnings
+# ROW_FORMAT=COMPRESSED is not available with innodb_page_size>16k
+SET INNODB_STRICT_MODE=OFF;
+CREATE TABLE tz(a INT)ENGINE=InnoDB ROW_FORMAT=COMPRESSED KEY_BLOCK_SIZE=1;
+SET INNODB_STRICT_MODE=ON;
+--enable_warnings
+
+--replace_result $MYSQL_TMP_DIR MYSQL_TMP_DIR
+EVAL CREATE TABLE tdd(a INT) ENGINE=InnoDB, DATA DIRECTORY='$MYSQL_TMP_DIR';
+
+CREATE TABLE tp(a INT) ENGINE=InnoDB ROW_FORMAT=DYNAMIC PAGE_COMPRESSED=1;
+CREATE TABLE ti(a INT) ENGINE=InnoDB;
+FLUSH TABLES ti FOR EXPORT;
+perl;
+do "$ENV{MTR_SUITE_DIR}/include/innodb-util.pl";
+ib_backup_tablespaces("test", "ti");
+EOF
+UNLOCK TABLES;
+ALTER TABLE ti DISCARD TABLESPACE;
+perl;
+do "$ENV{MTR_SUITE_DIR}/include/innodb-util.pl";
+ib_discard_tablespaces("test", "ti");
+ib_restore_tablespaces("test", "ti");
+do "$ENV{MTR_SUITE_DIR}/include/crc32.pl";
+do "$ENV{MTR_SUITE_DIR}/include/ibd_convert.pl";
+my $ps = $ENV{INNODB_PAGE_SIZE};
+my $dd = $ENV{MYSQLD_DATADIR};
+convert_to_mariadb_101("$dd/test/ti.ibd", $ps);
+EOF
+
+ALTER TABLE ti IMPORT TABLESPACE;
+
+BEGIN;
+INSERT INTO tr VALUES(1);
+INSERT INTO tc VALUES(1);
+INSERT INTO td VALUES(1);
+INSERT INTO tz VALUES(1);
+INSERT INTO tdd VALUES(1);
+INSERT INTO tp VALUES(1);
+INSERT INTO ti VALUES(1);
+
+--source include/kill_mysqld.inc
+
+perl;
+do "$ENV{MTR_SUITE_DIR}/include/crc32.pl";
+do "$ENV{MTR_SUITE_DIR}/include/ibd_convert.pl";
+my $ps = $ENV{INNODB_PAGE_SIZE};
+my $dd = $ENV{MYSQLD_DATADIR};
+
+convert_to_mariadb_101("$dd/ibdata1", $ps);
+convert_to_mariadb_101("$dd/test/tr.ibd", $ps);
+convert_to_mariadb_101("$dd/test/tc.ibd", $ps);
+convert_to_mariadb_101("$dd/test/td.ibd", $ps);
+convert_to_mariadb_101("$dd/test/tz.ibd", 1024) if $ps<32768;
+convert_to_mariadb_101("$dd/test/tp.ibd", $ps);
+convert_to_mariadb_101("$dd/test/ti.ibd", $ps);
+convert_to_mariadb_101("$ENV{MYSQL_TMP_DIR}/test/tdd.ibd", $ps);
+EOF
+
+--source include/start_mysqld.inc
+CHECK TABLE tr,tc,td,tz,tdd,tp,ti;
+--source include/shutdown_mysqld.inc
+
+perl;
+do "$ENV{MTR_SUITE_DIR}/include/crc32.pl";
+do "$ENV{MTR_SUITE_DIR}/include/ibd_convert.pl";
+my $ps = $ENV{INNODB_PAGE_SIZE};
+my $dd = $ENV{MYSQLD_DATADIR};
+
+convert_to_mariadb_101("$dd/ibdata1", $ps);
+convert_to_mariadb_101("$dd/test/tr.ibd", $ps);
+convert_to_mariadb_101("$dd/test/tc.ibd", $ps);
+convert_to_mariadb_101("$dd/test/td.ibd", $ps);
+convert_to_mariadb_101("$dd/test/tz.ibd", 1024) if $ps<32768;
+convert_to_mariadb_101("$dd/test/tp.ibd", $ps);
+convert_to_mariadb_101("$dd/test/ti.ibd", $ps);
+convert_to_mariadb_101("$ENV{MYSQL_TMP_DIR}/test/tdd.ibd", $ps);
+EOF
+
+--let $restart_parameters=--innodb-read-only
+--source include/start_mysqld.inc
+CHECK TABLE tr,tc,td,tz,tdd,tp,ti;
+--source include/shutdown_mysqld.inc
+
+--let $restart_parameters=
+--source include/start_mysqld.inc
+DROP TABLE tr,tc,td,tz,tdd,tp,ti;
diff --git a/mysql-test/suite/innodb/t/add_constraint.test b/mysql-test/suite/innodb/t/add_constraint.test
new file mode 100644
index 00000000..f43f2977
--- /dev/null
+++ b/mysql-test/suite/innodb/t/add_constraint.test
@@ -0,0 +1,20 @@
+--source include/have_innodb.inc
+
+--echo #
+--echo # Bug #20762798 FK DDL: CRASH IN DICT_FOREIGN_REMOVE_FROM_CACHE
+--echo #
+
+create table t1(a int, b int, key(a),key(b))engine=innodb;
+create table t2(a int, b int, key(a),key(b))engine=innodb;
+
+alter table t2 add constraint b foreign key (b) references t1(a);
+alter table t1 add constraint b1 foreign key (b) references t2(a);
+
+--error ER_CANT_CREATE_TABLE
+alter table t2 add constraint b1 foreign key (b) references t1(a);
+
+alter table t2 drop foreign key b;
+alter table t1 drop foreign key b1;
+
+drop table t2;
+drop table t1;
diff --git a/mysql-test/suite/innodb/t/alter_algorithm.combinations b/mysql-test/suite/innodb/t/alter_algorithm.combinations
new file mode 100644
index 00000000..af644d65
--- /dev/null
+++ b/mysql-test/suite/innodb/t/alter_algorithm.combinations
@@ -0,0 +1,15 @@
+[COPY]
+--alter_algorithm=copy
+--skip-innodb-read-only-compressed
+
+[INPLACE]
+--alter_algorithm=inplace
+--skip-innodb-read-only-compressed
+
+[NOCOPY]
+--alter_algorithm=nocopy
+--skip-innodb-read-only-compressed
+
+[INSTANT]
+--alter_algorithm=instant
+--skip-innodb-read-only-compressed
diff --git a/mysql-test/suite/innodb/t/alter_algorithm.inc b/mysql-test/suite/innodb/t/alter_algorithm.inc
new file mode 100644
index 00000000..1aa3caf7
--- /dev/null
+++ b/mysql-test/suite/innodb/t/alter_algorithm.inc
@@ -0,0 +1,2 @@
+# See also alter_algorithm.combinations
+--source include/have_innodb.inc
diff --git a/mysql-test/suite/innodb/t/alter_algorithm.test b/mysql-test/suite/innodb/t/alter_algorithm.test
new file mode 100644
index 00000000..08c23b50
--- /dev/null
+++ b/mysql-test/suite/innodb/t/alter_algorithm.test
@@ -0,0 +1,145 @@
+--source include/have_innodb.inc
+let $algorithm = `SELECT @@ALTER_ALGORITHM`;
+let $error_code = 0;
+
+if ($algorithm == "NOCOPY") {
+ let $error_code = ER_ALTER_OPERATION_NOT_SUPPORTED, ER_ALTER_OPERATION_NOT_SUPPORTED_REASON;
+}
+
+if ($algorithm == "INSTANT") {
+ let $error_code = ER_ALTER_OPERATION_NOT_SUPPORTED, ER_ALTER_OPERATION_NOT_SUPPORTED_REASON;
+}
+
+CREATE TABLE t1(f1 INT NOT NULL,
+ f2 INT NOT NULL,
+ f3 INT NULL,
+ f4 INT as (f2) STORED,
+ f5 INT as (f3) STORED,
+ PRIMARY KEY(f1))ROW_FORMAT=COMPRESSED, ENGINE=INNODB;
+INSERT INTO t1(f1, f2, f3) VALUES(1, 1, 1);
+
+SELECT @@alter_algorithm;
+
+--enable_info
+--echo # All the following cases needs table rebuild
+
+--echo # Add and Drop primary key
+--error $error_code
+ALTER TABLE t1 ADD COLUMN col1 INT NOT NULL,DROP PRIMARY KEY,ADD PRIMARY KEY(col1);
+
+--echo # Make existing column NULLABLE
+--error $error_code
+ALTER TABLE t1 MODIFY f2 INT;
+
+--echo # Drop Stored Column
+--error $error_code
+ALTER TABLE t1 DROP COLUMN f5;
+
+--echo # Add base non-generated column as a last column in the compressed table
+--error $error_code
+ALTER TABLE t1 ADD COLUMN f6 INT NOT NULL;
+
+--echo # Add base non-generated column but not in the last position
+--error $error_code
+ALTER TABLE t1 ADD COLUMN f7 INT NOT NULL after f3;
+
+--echo # Force the table to rebuild
+--error $error_code
+ALTER TABLE t1 FORCE;
+
+--echo # Row format changes
+--error $error_code
+ALTER TABLE t1 ROW_FORMAT=COMPRESSED;
+
+--echo # Engine table
+--error $error_code
+ALTER TABLE t1 ENGINE=INNODB;
+
+# Irrespective of alter_algorithm value, the following command
+# should succeed because of explicitly mentioning ALGORTHM=DEFAULT
+ALTER TABLE t1 FORCE, ALGORITHM=DEFAULT;
+
+DROP TABLE t1;
+--disable_info
+
+if ($algorithm == "NOCOPY") {
+ let $error_code = 0;
+}
+
+if ($algorithm == "INSTANT") {
+ let $error_code = ER_ALTER_OPERATION_NOT_SUPPORTED_REASON;
+}
+
+CREATE TABLE t1(f1 INT PRIMARY KEY, f2 INT NOT NULL,
+ f3 INT AS (f2 * f2) VIRTUAL,
+ f4 INT NOT NULL UNIQUE,
+ f5 INT NOT NULL,
+ INDEX idx(f2))ENGINE=INNODB;
+
+CREATE TABLE t2(f1 INT NOT NULL, f2 INT NOT NULL,
+ INDEX(f1),
+ FOREIGN KEY fidx(f1) REFERENCES t1(f1))ENGINE=INNODB;
+
+INSERT INTO t1(f1, f2, f4, f5) VALUES(1, 2, 3, 4);
+
+--enable_info
+--error $error_code
+ALTER TABLE t1 ADD INDEX idx1(f4), page_compressed=1;
+
+--error $error_code
+ALTER TABLE t1 DROP INDEX idx, page_compression_level=5;
+
+--error $error_code
+ALTER TABLE t1 ADD UNIQUE INDEX u1(f2);
+
+--error $error_code
+ALTER TABLE t1 DROP INDEX f4, page_compression_level=9;
+
+SET foreign_key_checks = 0;
+--error $error_code
+ALTER TABLE t1 ADD FOREIGN KEY(f5) REFERENCES t2(f1);
+
+DROP TABLE t2, t1;
+--disable_info
+
+CREATE TABLE t1(f1 INT NOT NULL,
+ f2 INT NOT NULL,
+ f3 INT AS (f2 * f2) VIRTUAL,
+ INDEX idx (f2))engine=innodb;
+
+CREATE TABLE t2(f1 INT NOT NULL, f2 INT NOT NULL,
+ f3 VARCHAR(10),
+ INDEX(f1))ENGINE=INNODB;
+
+INSERT INTO t1(f1, f2) VALUES(1, 1);
+
+--enable_info
+--echo # Add column at the end of the table
+ALTER TABLE t1 ADD COLUMN f4 char(100) default 'BIG WALL';
+
+--echo # Change virtual column expression
+ALTER TABLE t1 CHANGE f3 f3 INT AS (f2 * f2) VIRTUAL;
+
+--echo # Add virtual column
+ALTER TABLE t1 ADD COLUMN f5 INT AS (f2) VIRTUAL;
+
+--echo # Rename Column
+ALTER TABLE t1 CHANGE f3 vcol INT AS (f2) VIRTUAL;
+
+--echo # Rename table
+ALTER TABLE t1 RENAME t3;
+
+--echo # Drop Virtual Column
+ALTER TABLE t3 DROP COLUMN vcol;
+
+--echo # Column length varies
+ALTER TABLE t2 CHANGE f3 f3 VARCHAR(20);
+
+SET foreign_key_checks = 0;
+ALTER TABLE t3 ADD FOREIGN KEY fidx(f2) REFERENCES t2(f1);
+
+SET foreign_key_checks = 1;
+ALTER TABLE t3 DROP FOREIGN KEY fidx;
+
+DROP TABLE t3, t2;
+--disable_info
diff --git a/mysql-test/suite/innodb/t/alter_algorithm2.test b/mysql-test/suite/innodb/t/alter_algorithm2.test
new file mode 100644
index 00000000..cdece239
--- /dev/null
+++ b/mysql-test/suite/innodb/t/alter_algorithm2.test
@@ -0,0 +1,63 @@
+--source include/have_innodb.inc
+CREATE TABLE t1 (a INT)ENGINE=InnoDB;
+INSERT INTO t1 VALUES(1);
+
+# alter_algorithm variable doesn't affect when ALTER stmt
+# during PREPARE PHASE or CREATE PROCEDURE
+# Only when execution/call happens, alter uses the alter_algorithm
+# variable when user does not mention algorithm explicitly.
+
+--enable_info
+SET alter_algorithm='INPLACE';
+PREPARE stmt FROM 'ALTER TABLE t1 ADD KEY idx(a)';
+PREPARE stmt1 FROM 'ALTER TABLE t1 DROP KEY idx';
+DELIMITER |;
+CREATE OR REPLACE PROCEDURE p1()
+BEGIN
+ ALTER TABLE t1 ADD KEY idx2(a);
+END|
+
+CREATE OR REPLACE PROCEDURE p2()
+BEGIN
+ ALTER TABLE t1 DROP KEY idx2;
+END|
+DELIMITER ;|
+
+SET alter_algorithm='COPY';
+EXECUTE stmt;
+EXECUTE stmt1;
+call p1();
+call p2();
+
+SET alter_algorithm='NOCOPY';
+EXECUTE stmt;
+EXECUTE stmt1;
+call p1();
+call p2();
+
+SET alter_algorithm='INSTANT';
+--error ER_ALTER_OPERATION_NOT_SUPPORTED_REASON
+EXECUTE stmt;
+--error ER_ALTER_OPERATION_NOT_SUPPORTED_REASON
+call p1();
+
+DROP TABLE t1;
+DROP PROCEDURE p1;
+DROP PROCEDURE p2;
+
+SET @save_allowed= @@GLOBAL.innodb_instant_alter_column_allowed;
+SET GLOBAL innodb_instant_alter_column_allowed=never;
+
+CREATE TABLE t1(id INT PRIMARY KEY,
+ col1 INT UNSIGNED NOT NULL UNIQUE)ENGINE=InnoDB;
+INSERT INTO t1 VALUES(1,1),(2,2),(3,3);
+SET ALTER_ALGORITHM=INSTANT;
+--error ER_ALTER_OPERATION_NOT_SUPPORTED_REASON
+ALTER TABLE t1 DROP COLUMN col1;
+--error ER_ALTER_OPERATION_NOT_SUPPORTED_REASON
+ALTER TABLE t1 DROP COLUMN col1, ALGORITHM=NOCOPY;
+ALTER TABLE t1 DROP COLUMN col1, ALGORITHM=DEFAULT;
+ALTER TABLE t1 DROP PRIMARY KEY, ALGORITHM=DEFAULT;
+DROP TABLE t1;
+--disable_info
+SET GLOBAL innodb_instant_alter_column_allowed=@save_allowed;
diff --git a/mysql-test/suite/innodb/t/alter_candidate_key.test b/mysql-test/suite/innodb/t/alter_candidate_key.test
new file mode 100644
index 00000000..824ad1ea
--- /dev/null
+++ b/mysql-test/suite/innodb/t/alter_candidate_key.test
@@ -0,0 +1,74 @@
+--source include/have_innodb.inc
+--source include/have_debug.inc
+--source include/have_debug_sync.inc
+
+CREATE TABLE t1 (f1 INT NOT NULL, f2 INT NOT NULL,
+ UNIQUE KEY uidx2(f1,f2),
+ UNIQUE KEY uidx1(f2)) ENGINE=InnoDB;
+INSERT INTO t1 VALUES(1, 1);
+SHOW CREATE TABLE t1;
+SET DEBUG_SYNC = 'innodb_inplace_alter_table_enter
+ SIGNAL conc_dml WAIT_FOR go_ahead';
+--send ALTER TABLE t1 CHANGE COLUMN f1 f11 INT, ALGORITHM=INPLACE
+connect (con1,localhost,root,,);
+SET DEBUG_SYNC = 'now WAIT_FOR conc_dml';
+DELETE FROM t1;
+SET DEBUG_SYNC = 'now SIGNAL go_ahead';
+connection default;
+reap;
+SHOW CREATE TABLE t1;
+CHECK TABLE t1;
+DROP TABLE t1;
+
+CREATE TABLE t1(f1 INT, f2 INT,
+ PRIMARY KEY(f1, f2),
+ UNIQUE INDEX uidx2 (f1, f2),
+ UNIQUE INDEX uidx1 (f2))ENGINE=InnoDB;
+INSERT INTO t1 VALUES(2, 2);
+ALTER TABLE t1 DROP PRIMARY KEY;
+SHOW CREATE TABLE t1;
+SET DEBUG_SYNC = 'innodb_inplace_alter_table_enter
+ SIGNAL conc_dml WAIT_FOR go_ahead';
+--send ALTER TABLE t1 CHANGE COLUMN f1 f11 INT, ALGORITHM=INPLACE
+connection con1;
+SET DEBUG_SYNC = 'now WAIT_FOR conc_dml';
+--error ER_DUP_ENTRY
+INSERT INTO t1 VALUES(1, 1), (1, 1);
+SET DEBUG_SYNC = 'now SIGNAL go_ahead';
+connection default;
+reap;
+SHOW CREATE TABLE t1;
+CHECK TABLE t1;
+DROP TABLE t1;
+
+SET SQL_MODE= strict_trans_tables;
+CREATE TABLE t1(a INT UNIQUE) ENGINE=InnoDB;
+INSERT INTO t1 VALUES(1);
+SET DEBUG_SYNC='row_log_table_apply1_before SIGNAL dml WAIT_FOR dml_done';
+--send ALTER TABLE t1 MODIFY COLUMN a INT NOT NULL
+connection con1;
+SET DEBUG_SYNC='now WAIT_FOR dml';
+BEGIN;
+INSERT INTO t1 SET a=NULL;
+COMMIT;
+set DEBUG_SYNC='now SIGNAL dml_done';
+connection default;
+--error ER_INVALID_USE_OF_NULL
+reap;
+DROP TABLE t1;
+disconnect con1;
+SET DEBUG_SYNC="RESET";
+SET SQL_MODE=DEFAULT;
+
+CREATE TABLE t1(f1 INT NOT NULL, f2 INT NOT NULL, PRIMARY KEY(f1, f2),
+ UNIQUE KEY(f2))ENGINE=InnoDB;
+ALTER TABLE t1 DROP PRIMARY KEY;
+SHOW CREATE TABLE t1;
+DROP TABLE t1;
+
+CREATE TABLE t1(f1 INT NOT NULL, f2 INT NOT NULL,
+ UNIQUE KEY(f2), UNIQUE KEY(f2))ENGINE=InnoDB;
+SHOW CREATE TABLE t1;
+ALTER TABLE t1 DROP INDEX f2, ALGORITHM=INPLACE;
+SHOW CREATE TABLE t1;
+DROP TABLE t1;
diff --git a/mysql-test/suite/innodb/t/alter_copy.test b/mysql-test/suite/innodb/t/alter_copy.test
new file mode 100644
index 00000000..b62f812f
--- /dev/null
+++ b/mysql-test/suite/innodb/t/alter_copy.test
@@ -0,0 +1,94 @@
+--source include/have_innodb.inc
+--source include/have_debug.inc
+--source include/have_debug_sync.inc
+--source include/not_embedded.inc
+--source include/no_valgrind_without_big.inc
+
+--echo #
+--echo # MDEV-11415 AVOID INTERMEDIATE COMMIT WHILE DOING
+--echo # ALTER TABLE...ALGORITHM=COPY
+--echo #
+
+CREATE TABLE t(a SERIAL, b INT, c INT, d INT) ENGINE=InnoDB;
+CREATE TABLE t1(a INT, b TEXT, c TEXT,
+ FULLTEXT(b), FULLTEXT(c(3)), FULLTEXT(b,c)) ENGINE=InnoDB;
+
+let $c = 999;
+BEGIN;
+--disable_query_log
+while ($c) {
+INSERT INTO t() VALUES();
+dec $c;
+}
+--enable_query_log
+COMMIT;
+
+SELECT COUNT(*) FROM t;
+# try to make the to-be-created secondary index keys randomly distributed
+UPDATE t SET b=a%7, c=a%11, d=a%13;
+
+INSERT INTO t1 VALUES(1, 'This is a first b column', 'This is a first c column');
+INSERT INTO t1 VALUES(2, 'This is a second b column', 'This is a second c column');
+INSERT INTO t1(a) VALUES(3);
+INSERT INTO t1 VALUES(4, 'This is a third b column', 'This is a third c column');
+DELETE FROM t1 WHERE a = 2;
+SELECT * FROM t1 WHERE MATCH(b) AGAINST ('first');
+SELECT * FROM t1 WHERE MATCH(c) AGAINST ('first');
+SELECT * FROM t1 WHERE MATCH(b,c) AGAINST ('column');
+SHOW CREATE TABLE t1;
+ALTER TABLE t1 FORCE, ALGORITHM=COPY;
+
+# kill right after the last write_row(), before the first commit of ALTER TABLE
+connect (hang,localhost,root);
+
+SET DEBUG_SYNC='alter_table_copy_trans_commit SIGNAL hung WAIT_FOR ever';
+send
+# create 32 secondary indexes
+ALTER TABLE t ADD INDEX(b,c,d,a),ADD INDEX(b,c,a,d),ADD INDEX(b,a,c,d),ADD INDEX(b,a,d,c),
+ ADD INDEX(b,d,a,c),ADD INDEX(b,d,c,a),ADD INDEX(a,b,c,d),ADD INDEX(a,b,d,c),
+ ADD INDEX(a,c,b,d),ADD INDEX(a,c,d,b),ADD INDEX(a,d,b,c),ADD INDEX(a,d,c,b),
+ ADD INDEX(c,a,b,d),ADD INDEX(c,a,d,b),ADD INDEX(c,b,a,d),ADD INDEX(c,b,d,a),
+ ADD INDEX(c,d,a,b),ADD INDEX(c,d,b,a),ADD INDEX(d,a,b,c),ADD INDEX(d,a,c,b),
+ ADD INDEX(d,b,a,c),ADD INDEX(d,b,c,a),ADD INDEX(d,c,a,b),ADD INDEX(d,c,b,a),
+ ADD INDEX(a,b,c), ADD INDEX(a,c,b), ADD INDEX(a,c,d), ADD INDEX(a,d,c),
+ ADD INDEX(a,b,d), ADD INDEX(a,d,b), ADD INDEX(b,c,d), ADD INDEX(b,d,c),
+ ALGORITHM=COPY;
+
+connection default;
+SET DEBUG_SYNC='now WAIT_FOR hung';
+let $shutdown_timeout=0;
+--let $restart_parameters= --innodb-force-recovery=3 --debug_dbug="+d,recv_ran_out_of_buffer"
+--source include/restart_mysqld.inc
+disconnect hang;
+let $shutdown_timeout=;
+let $datadir=`select @@datadir`;
+--replace_regex /FTS_[0-9a-f]*_[0-9a-f]*/FTS/
+--list_files $datadir/test
+SHOW CREATE TABLE t;
+SELECT COUNT(*) FROM t;
+CHECK TABLE t;
+SELECT * FROM t1 WHERE MATCH(b) AGAINST ('first');
+SELECT * FROM t1 WHERE MATCH(c) AGAINST ('first');
+SELECT * FROM t1 WHERE MATCH(b,c) AGAINST ('column');
+SHOW CREATE TABLE t1;
+CHECK TABLE t1;
+
+--let $restart_parameters= --innodb-read-only
+--source include/restart_mysqld.inc
+--replace_regex /FTS_[0-9a-f]*_[0-9a-f]*/FTS/
+
+--list_files $datadir/test
+SHOW CREATE TABLE t;
+SELECT COUNT(*) FROM t;
+CHECK TABLE t;
+SELECT * FROM t1 WHERE MATCH(b) AGAINST ('first');
+SELECT * FROM t1 WHERE MATCH(c) AGAINST ('first');
+SELECT * FROM t1 WHERE MATCH(b,c) AGAINST ('column');
+SHOW CREATE TABLE t1;
+CHECK TABLE t1;
+
+--let $restart_parameters=
+--source include/restart_mysqld.inc
+--replace_regex /FTS_[0-9a-f]*_[0-9a-f]*/FTS/
+--list_files $datadir/test
+DROP TABLE t1,t;
diff --git a/mysql-test/suite/innodb/t/alter_crash.opt b/mysql-test/suite/innodb/t/alter_crash.opt
new file mode 100644
index 00000000..39b93371
--- /dev/null
+++ b/mysql-test/suite/innodb/t/alter_crash.opt
@@ -0,0 +1 @@
+--loose-innodb-sys-tables
diff --git a/mysql-test/suite/innodb/t/alter_crash.test b/mysql-test/suite/innodb/t/alter_crash.test
new file mode 100644
index 00000000..164ff877
--- /dev/null
+++ b/mysql-test/suite/innodb/t/alter_crash.test
@@ -0,0 +1,229 @@
+# Crash-safe InnoDB ALTER operations
+
+--source include/not_valgrind.inc
+--source include/not_embedded.inc
+--source include/have_innodb.inc
+--source include/have_debug.inc
+--source include/have_debug_sync.inc
+--source include/not_crashrep.inc
+
+--disable_query_log
+call mtr.add_suppression('InnoDB: Flagged corruption of `c[23]`');
+call mtr.add_suppression('InnoDB: Index `c[23]` .*is corrupted');
+--enable_query_log
+
+--echo #
+--echo # Bug#20015132 ALTER TABLE FAILS TO CHECK IF TABLE IS CORRUPTED
+--echo #
+
+CREATE TABLE t1(c1 INT PRIMARY KEY, c2 CHAR(1), c3 INT UNSIGNED) ENGINE=InnoDB;
+SET @saved_debug_dbug = @@SESSION.debug_dbug;
+SET DEBUG_DBUG='+d,create_index_metadata_fail';
+--error ER_RECORD_FILE_FULL
+ALTER TABLE t1 ADD INDEX (c2), ADD INDEX (c3);
+
+SET DEBUG_DBUG='+d,ib_create_table_fail_too_many_trx';
+--error ER_TOO_MANY_CONCURRENT_TRXS
+ALTER TABLE t1 ADD INDEX (c2), ADD INDEX (c3);
+
+SET DEBUG_DBUG=@saved_debug_dbug;
+ALTER TABLE t1 ADD INDEX (c2), ADD INDEX (c3);
+# Flag the secondary indexes corrupted.
+SET DEBUG_DBUG='+d,dict_set_index_corrupted';
+CHECK TABLE t1;
+
+# Ensure that the corruption is permanent.
+--source include/restart_mysqld.inc
+CHECK TABLE t1;
+ALTER TABLE t1 DROP INDEX c2;
+CHECK TABLE t1;
+# We refuse an ALTER TABLE that would modify the InnoDB data dictionary
+# while leaving some of the table corrupted.
+--error ER_INDEX_CORRUPT
+ALTER TABLE t1 ADD INDEX (c2,c3);
+# This will rebuild the table, uncorrupting all secondary indexes.
+ALTER TABLE t1 CHANGE c3 c3 INT NOT NULL;
+CHECK TABLE t1;
+ALTER TABLE t1 ADD INDEX (c2,c3);
+DROP TABLE t1;
+
+let $MYSQLD_DATADIR= `select @@datadir`;
+let datadir= `select @@datadir`;
+
+# These are from include/shutdown_mysqld.inc and allow to call start_mysqld.inc
+--let $_expect_file_name= `select regexp_replace(@@tmpdir, '^.*/','')`
+--let $_expect_file_name= $MYSQLTEST_VARDIR/tmp/$_expect_file_name.expect
+
+--echo #
+--echo # Bug #14669848 CRASH DURING ALTER MAKES ORIGINAL TABLE INACCESSIBLE
+--echo #
+--echo # -- Scenario 1:
+--echo # Crash the server in ha_innobase::commit_inplace_alter_table()
+--echo # just after committing the dictionary changes.
+
+CREATE TABLE t1 (f1 INT NOT NULL, f2 INT NOT NULL) ENGINE=innodb;
+INSERT INTO t1 VALUES (1,2),(3,4);
+SET DEBUG_DBUG='+d,innodb_alter_commit_crash_after_commit';
+
+let $orig_table_id = `SELECT table_id
+ FROM information_schema.innodb_sys_tables
+ WHERE name = 'test/t1'`;
+
+# Write file to make mysql-test-run.pl expect crash
+--exec echo "restart" > $MYSQLTEST_VARDIR/tmp/mysqld.1.expect
+
+--error 2013
+ALTER TABLE t1 ADD PRIMARY KEY (f2, f1);
+
+--echo # Restart mysqld after the crash and reconnect.
+--source include/start_mysqld.inc
+
+--replace_result $orig_table_id ID
+eval SELECT * FROM information_schema.innodb_sys_tables
+WHERE table_id = $orig_table_id;
+
+--echo # Files in datadir after manual recovery.
+--list_files $MYSQLD_DATADIR/test
+
+SHOW TABLES;
+SHOW CREATE TABLE t1;
+INSERT INTO t1 VALUES (5,6),(7,8);
+SELECT * FROM t1;
+DROP TABLE t1;
+
+CREATE TABLE t1 (f1 INT NOT NULL, f2 INT NOT NULL) ENGINE=InnoDB;
+ALTER TABLE t1 ADD PRIMARY KEY (f2, f1);
+DROP TABLE t1;
+
+--echo # -- Scenario 2:
+--echo # Crash the server in ha_innobase::commit_inplace_alter_table()
+--echo # just before committing the dictionary changes, but after
+--echo # writing the MLOG_FILE_RENAME records. As the mini-transaction
+--echo # is not committed, the renames will not be replayed.
+
+CREATE TABLE t2 (f1 int not null, f2 int not null) ENGINE=InnoDB;
+INSERT INTO t2 VALUES (1,2),(3,4);
+SET DEBUG_DBUG='+d,innodb_alter_commit_crash_before_commit';
+
+let $orig_table_id = `SELECT table_id
+ FROM information_schema.innodb_sys_tables
+ WHERE name = 'test/t2'`;
+
+# Write file to make mysql-test-run.pl expect crash
+--exec echo "restart" > $MYSQLTEST_VARDIR/tmp/mysqld.1.expect
+
+--error 2013
+ALTER TABLE t2 ADD PRIMARY KEY (f2, f1);
+
+--echo # Startup the server after the crash
+--source include/start_mysqld.inc
+
+SELECT * FROM information_schema.innodb_sys_tables
+WHERE name LIKE 'test/#sql-%';
+
+SHOW TABLES;
+INSERT INTO t2 VALUES (5,6),(7,8);
+SELECT * from t2;
+SHOW CREATE TABLE t2;
+DROP TABLE t2;
+
+CREATE TABLE t2 (f1 INT NOT NULL, f2 INT NOT NULL) ENGINE=InnoDB;
+ALTER TABLE t2 ADD PRIMARY KEY (f2, f1);
+DROP TABLE t2;
+--list_files $MYSQLD_DATADIR/test
+
+--echo # -------------------------
+--echo # End of Testing Scenario 2
+--echo # -------------------------
+
+--echo #
+--echo # Bug#19330255 WL#7142 - CRASH DURING ALTER TABLE LEADS TO
+--echo # DATA DICTIONARY INCONSISTENCY
+--echo #
+
+CREATE TABLE t1(a int PRIMARY KEY, b varchar(255), c int NOT NULL)
+ENGINE=InnoDB;
+INSERT INTO t1 SET a=1,c=2;
+SET DEBUG_DBUG='+d,innodb_alter_commit_crash_after_commit';
+
+let $orig_table_id = `select table_id from
+ information_schema.innodb_sys_tables where name = 'test/t1'`;
+
+# Write file to make mysql-test-run.pl expect crash
+--exec echo "restart" > $MYSQLTEST_VARDIR/tmp/mysqld.1.expect
+#
+--error 2013
+ALTER TABLE t1 ADD INDEX (b), CHANGE c d int, ALGORITHM=INPLACE;
+
+--echo # Restart mysqld after the crash and reconnect.
+--source include/start_mysqld.inc
+
+--replace_result $orig_table_id ID
+eval SELECT * FROM information_schema.innodb_sys_tables
+WHERE table_id = $orig_table_id;
+
+--list_files $MYSQLD_DATADIR/test
+
+SHOW TABLES;
+SHOW CREATE TABLE t1;
+UPDATE t1 SET d=NULL;
+SELECT * FROM t1;
+DROP TABLE t1;
+
+--echo #
+--echo # MDEV-22637 Rollback of insert fails when column reorder happens
+--echo #
+SET @@SQL_MODE = REPLACE(@@SQL_MODE, 'STRICT_TRANS_TABLES', '');
+SET @@SQL_MODE = REPLACE(@@SQL_MODE, 'STRICT_ALL_TABLES', '');
+CREATE TABLE t1(f1 INT NOT NULL, f2 CHAR(100),
+ f3 CHAR(100), f4 CHAR(100))ENGINE=InnoDB;
+INSERT INTO t1 VALUES(1, "This is column2", "This is column3",
+ "This is column4");
+set DEBUG_SYNC = 'row_log_table_apply1_before SIGNAL scanned WAIT_FOR insert_done';
+--send ALTER TABLE t1 ADD COLUMN f6 int after f3, add primary key(f6, f4(3), f3(3))
+connect(con1,localhost,root,,);
+SET DEBUG_SYNC = 'now WAIT_FOR scanned';
+BEGIN;
+INSERT INTO t1(f1, f2) VALUES(2, "This is column2 value");
+ROLLBACK;
+set DEBUG_SYNC = 'now SIGNAL insert_done';
+
+connection default;
+reap;
+SHOW CREATE TABLE t1;
+SELECT COUNT(*) FROM t1;
+disconnect con1;
+DROP TABLE t1;
+SET DEBUG_SYNC = 'RESET';
+SET SQL_MODE=DEFAULT;
+
+--echo #
+--echo # MDEV-26936 Recovery crash on rolling back DELETE FROM SYS_INDEXES
+--echo #
+
+CREATE TABLE t1(a INT PRIMARY KEY, b INT) ENGINE=InnoDB;
+INSERT INTO t1 VALUES(1,1);
+
+connect ddl, localhost, root;
+SET DEBUG_SYNC = 'row_merge_after_scan SIGNAL scanned WAIT_FOR commit';
+SET DEBUG_SYNC = 'before_commit_rollback_inplace SIGNAL c WAIT_FOR ever';
+send ALTER TABLE t1 ADD UNIQUE INDEX(b), ALGORITHM=INPLACE;
+
+connection default;
+SET DEBUG_SYNC = 'now WAIT_FOR scanned';
+BEGIN;
+INSERT INTO t1 VALUES(2,1);
+COMMIT;
+SET DEBUG_SYNC = 'now SIGNAL commit';
+SET DEBUG_SYNC = 'now WAIT_FOR c';
+# Make all pending changes durable for recovery.
+SET GLOBAL innodb_fil_make_page_dirty_debug=0;
+
+--source include/kill_mysqld.inc
+disconnect ddl;
+--source include/start_mysqld.inc
+
+CHECK TABLE t1;
+SHOW CREATE TABLE t1;
+SELECT * FROM t1;
+DROP TABLE t1;
diff --git a/mysql-test/suite/innodb/t/alter_crash_rebuild.test b/mysql-test/suite/innodb/t/alter_crash_rebuild.test
new file mode 100644
index 00000000..0ed3e4a1
--- /dev/null
+++ b/mysql-test/suite/innodb/t/alter_crash_rebuild.test
@@ -0,0 +1,24 @@
+--source include/have_innodb.inc
+--source include/have_debug.inc
+--source include/have_debug_sync.inc
+
+CREATE TABLE t1 (a INT NOT NULL) ENGINE=InnoDB STATS_PERSISTENT=0;
+
+connect ddl,localhost,root;
+SET DEBUG_SYNC='after_trx_committed_in_memory SIGNAL stuck WAIT_FOR ever';
+send ALTER TABLE t1 ADD PRIMARY KEY(a);
+
+connection default;
+SET DEBUG_SYNC='now WAIT_FOR stuck';
+
+SET GLOBAL innodb_log_checkpoint_now=ON;
+
+--let $shutdown_timeout=0
+--source include/restart_mysqld.inc
+
+disconnect ddl;
+
+SHOW CREATE TABLE t1;
+SELECT * FROM t1;
+DROP TABLE t1;
+--source include/wait_all_purged.inc
diff --git a/mysql-test/suite/innodb/t/alter_dml_apply.opt b/mysql-test/suite/innodb/t/alter_dml_apply.opt
new file mode 100644
index 00000000..fa341828
--- /dev/null
+++ b/mysql-test/suite/innodb/t/alter_dml_apply.opt
@@ -0,0 +1,2 @@
+--innodb_online_alter_log_max_size=64k
+--innodb_sort_buffer_size=64k
diff --git a/mysql-test/suite/innodb/t/alter_dml_apply.test b/mysql-test/suite/innodb/t/alter_dml_apply.test
new file mode 100644
index 00000000..ac045590
--- /dev/null
+++ b/mysql-test/suite/innodb/t/alter_dml_apply.test
@@ -0,0 +1,60 @@
+--source include/have_innodb.inc
+--source include/have_debug.inc
+--source include/have_debug_sync.inc
+--source include/have_sequence.inc
+--source include/no_valgrind_without_big.inc
+
+CREATE TABLE t1(f1 INT NOT NULL, f2 INT NOT NULL,
+ f3 CHAR(200), f4 CHAR(200),
+ PRIMARY KEY(f1))ENGINE=InnoDB;
+INSERT INTO t1 VALUES(6000, 6000, "InnoDB", "MariaDB");
+
+# InnoDB DML thread applies the online log, aborts other online index
+
+SET DEBUG_SYNC="inplace_after_index_build SIGNAL dml_start WAIT_FOR dml_commit";
+SEND ALTER TABLE t1 ADD UNIQUE KEY(f2), ADD UNIQUE INDEX(f4(10));
+
+# InnoDB DML thread applies insert log
+
+connect(con1,localhost,root,,,);
+SET DEBUG_SYNC="now WAIT_FOR dml_start";
+# Rollback should avoid online index
+BEGIN;
+DELETE FROM t1 WHERE f1= 6000;
+INSERT INTO t1 VALUES(6000, 6000, "InnoDB", "MariaDB");
+ROLLBACK;
+
+# Insert log will fetch the previous version in this case
+BEGIN;
+DELETE FROM t1 WHERE f1= 6000;
+INSERT INTO t1 VALUES(6000, 6000, "InnoDB", "MariaDB");
+INSERT INTO t1 SELECT seq, seq, repeat('a', 200), repeat('b', 200) FROM seq_1_to_4000;
+COMMIT;
+SET DEBUG_SYNC="now SIGNAL dml_commit";
+
+connection default;
+--error ER_DUP_ENTRY
+reap;
+
+# DML Thread applies update log
+
+SET DEBUG_SYNC="inplace_after_index_build SIGNAL dml_start WAIT_FOR dml_commit";
+SEND ALTER TABLE t1 ADD UNIQUE KEY(f2), ADD INDEX(f3(10));
+
+connection con1;
+SET DEBUG_SYNC="now WAIT_FOR dml_start";
+BEGIN;
+DELETE FROM t1;
+INSERT INTO t1 SELECT seq, seq, repeat('d', 200), repeat('e', 200) FROM
+seq_1_to_4000;
+UPDATE t1 SET f3=repeat('c', 200), f4= repeat('d', 200), f2=3;
+COMMIT;
+SET DEBUG_SYNC="now SIGNAL dml_commit";
+
+connection default;
+--error ER_DUP_ENTRY
+reap;
+disconnect con1;
+CHECK TABLE t1;
+DROP TABLE t1;
+SET DEBUG_SYNC=reset;
diff --git a/mysql-test/suite/innodb/t/alter_foreign_crash.test b/mysql-test/suite/innodb/t/alter_foreign_crash.test
new file mode 100644
index 00000000..b65dfa17
--- /dev/null
+++ b/mysql-test/suite/innodb/t/alter_foreign_crash.test
@@ -0,0 +1,47 @@
+--source include/have_innodb.inc
+--source include/have_debug_sync.inc
+# The embedded server does not support restarting.
+--source include/not_embedded.inc
+--source include/have_case_sensitive_file_system.inc
+
+--echo #
+--echo # Bug #20476395 DICT_LOAD_FOREIGNS() FAILED IN
+--echo # COMMIT_INPLACE_ALTER_TABLE
+--echo #
+
+call mtr.add_suppression("InnoDB: Failed to load table");
+
+CREATE DATABASE Bug;
+CREATE TABLE Bug.parent(a SERIAL) ENGINE=INNODB;
+CREATE TABLE Bug.child(a SERIAL, FOREIGN KEY f(a) REFERENCES Bug.parent(a))
+ENGINE=INNODB;
+
+create database bug;
+use bug;
+
+create table parent(a serial) engine=innodb;
+create table child(a serial, foreign key fk (a) references parent(a))engine=innodb;
+
+insert into parent values(1);
+insert into child values(1);
+drop database Bug;
+
+connect (con1,localhost,root,,bug);
+SET DEBUG_SYNC='innodb_rename_table_ready SIGNAL s1 WAIT_FOR s2 EXECUTE 2';
+--send ALTER TABLE child ROW_FORMAT=DYNAMIC, ALGORITHM=COPY
+connection default;
+SET DEBUG_SYNC='now WAIT_FOR s1';
+SET DEBUG_SYNC='now SIGNAL s2 WAIT_FOR s1';
+
+--let $shutdown_timeout= 0
+--source include/restart_mysqld.inc
+disconnect con1;
+
+show tables;
+alter table parent row_format=dynamic;
+select * from child;
+--error ER_ROW_IS_REFERENCED_2
+drop table parent;
+drop table child;
+drop table parent;
+drop database bug;
diff --git a/mysql-test/suite/innodb/t/alter_inplace_perfschema.opt b/mysql-test/suite/innodb/t/alter_inplace_perfschema.opt
new file mode 100644
index 00000000..f5612552
--- /dev/null
+++ b/mysql-test/suite/innodb/t/alter_inplace_perfschema.opt
@@ -0,0 +1,2 @@
+--innodb-sort-buffer-size=64k
+--tmpdir=$MYSQLTEST_VARDIR/tmp
diff --git a/mysql-test/suite/innodb/t/alter_inplace_perfschema.test b/mysql-test/suite/innodb/t/alter_inplace_perfschema.test
new file mode 100644
index 00000000..e0451e12
--- /dev/null
+++ b/mysql-test/suite/innodb/t/alter_inplace_perfschema.test
@@ -0,0 +1,42 @@
+--source include/have_innodb.inc
+--source include/have_perfschema.inc
+--source include/have_debug.inc
+--source include/have_debug_sync.inc
+--source include/not_embedded.inc
+
+select count_star into @init_count from performance_schema.events_waits_summary_global_by_event_name WHERE event_name LIKE '%wait%io%file%innodb%innodb_temp_file%';
+connect (ddl, localhost, root,,);
+update performance_schema.setup_instruments set enabled='yes';
+update performance_schema.setup_consumers set enabled='yes';
+CREATE TABLE t1 (a serial, b varchar(255)) ENGINE=InnoDB;
+
+BEGIN;
+let $n=247;
+--disable_query_log
+while ($n) {
+dec $n;
+INSERT INTO t1 SELECT NULL, REPEAT('b',255);
+}
+--enable_query_log
+COMMIT;
+
+SET DEBUG_SYNC = 'row_log_apply_before SIGNAL go WAIT_FOR gone';
+send ALTER TABLE t1 ADD INDEX(b), ALGORITHM=INPLACE;
+
+connection default;
+SET DEBUG_SYNC = 'now WAIT_FOR go';
+
+select count_star into @final_count from performance_schema.events_waits_summary_global_by_event_name WHERE event_name LIKE '%wait%io%file%innodb%innodb_temp_file%';
+
+SELECT @final_count - @init_count;
+
+#--exec lsof -p `pidof mysqld`
+SET DEBUG_SYNC = 'now SIGNAL gone';
+
+connection ddl;
+reap;
+disconnect ddl;
+
+connection default;
+SET DEBUG_SYNC = 'RESET';
+DROP TABLE t1;
diff --git a/mysql-test/suite/innodb/t/alter_key_block_size-11757.test b/mysql-test/suite/innodb/t/alter_key_block_size-11757.test
new file mode 100644
index 00000000..6eb81210
--- /dev/null
+++ b/mysql-test/suite/innodb/t/alter_key_block_size-11757.test
@@ -0,0 +1,32 @@
+#
+# MDEV-11757 KEY_BLOCK_SIZE strangeness when UNCOMPRESSing COMPRESSed InnoDB tables
+#
+source include/have_innodb.inc;
+--disable_query_log
+SET @save_innodb_read_only_compressed=@@GLOBAL.innodb_read_only_compressed;
+SET GLOBAL innodb_read_only_compressed=OFF;
+--enable_query_log
+
+create table t1 (
+ id1 bigint(20) not null,
+ id2 bigint(20) not null,
+ primary key (id1),
+ unique key id2 (id2)
+) engine=innodb row_format=compressed key_block_size=8;
+show create table t1;
+SET innodb_strict_mode=ON;
+--error ER_ILLEGAL_HA_CREATE_OPTION
+alter table t1 row_format=dynamic;
+SET innodb_strict_mode=OFF;
+alter table t1 row_format=dynamic;
+show create table t1;
+SET innodb_strict_mode=ON;
+--disable_query_log
+SET GLOBAL innodb_read_only_compressed=@save_innodb_read_only_compressed;
+--enable_query_log
+alter table t1 key_block_size=0;
+show create table t1;
+alter table t1 drop primary key, add primary key (id1),
+ drop key id2, add unique (id2);
+show create table t1;
+drop table t1;
diff --git a/mysql-test/suite/innodb/t/alter_kill-master.opt b/mysql-test/suite/innodb/t/alter_kill-master.opt
new file mode 100644
index 00000000..e472160c
--- /dev/null
+++ b/mysql-test/suite/innodb/t/alter_kill-master.opt
@@ -0,0 +1 @@
+--innodb-doublewrite=false
diff --git a/mysql-test/suite/innodb/t/alter_kill.test b/mysql-test/suite/innodb/t/alter_kill.test
new file mode 100644
index 00000000..461e1f47
--- /dev/null
+++ b/mysql-test/suite/innodb/t/alter_kill.test
@@ -0,0 +1,175 @@
+--source include/have_innodb.inc
+# The embedded server does not support restarting in mysql-test-run.
+-- source include/not_embedded.inc
+-- source include/no_valgrind_without_big.inc
+-- source include/innodb_checksum_algorithm.inc
+
+let MYSQLD_DATADIR=`select @@datadir`;
+let PAGE_SIZE=`select @@innodb_page_size`;
+
+-- disable_query_log
+call mtr.add_suppression("InnoDB: innodb_force_recovery is on.");
+call mtr.add_suppression("InnoDB: Ignoring tablespace for.*bug16720368");
+call mtr.add_suppression("Found 1 prepared XA transactions");
+call mtr.add_suppression("InnoDB: Operating system error.*in a file operation");
+call mtr.add_suppression("InnoDB: \(The error means\|If you are\)");
+call mtr.add_suppression("InnoDB: Ignoring tablespace `test/bug16720368` because it could not be opened");
+call mtr.add_suppression("InnoDB: Tablespace .* was not found at.*bug16735660");
+call mtr.add_suppression("InnoDB: Plugin initialization aborted*");
+call mtr.add_suppression("Plugin 'InnoDB' init function returned error.");
+call mtr.add_suppression("Plugin 'InnoDB' registration as a STORAGE ENGINE failed.");
+call mtr.add_suppression("Table .*bug16720368.* is corrupted");
+-- enable_query_log
+
+-- echo #
+-- echo # Bug#16720368 INNODB CRASHES ON BROKEN #SQL*.IBD FILE AT STARTUP
+-- echo #
+
+SET GLOBAL innodb_file_per_table=1;
+
+CREATE TABLE bug16720368_1 (a INT PRIMARY KEY) ENGINE=InnoDB;
+
+connect (con1,localhost,root);
+CREATE TABLE bug16720368 (a INT PRIMARY KEY, b INT) ENGINE=InnoDB;
+INSERT INTO bug16720368 (a) VALUES (1),(2),(3),(4),(5),(6),(7),(8);
+--source include/wait_all_purged.inc
+
+connection default;
+
+-- echo # Cleanly shutdown mysqld
+-- source include/shutdown_mysqld.inc
+
+disconnect con1;
+
+-- echo # Corrupt FIL_PAGE_TYPE in bug16720368.ibd,
+-- echo # and recompute innodb_checksum_algorithm=crc32
+perl;
+do "$ENV{MTR_SUITE_DIR}/include/crc32.pl";
+my $file = "$ENV{MYSQLD_DATADIR}/test/bug16720368.ibd";
+open(FILE, "+<$file") || die "Unable to open $file";
+binmode FILE;
+my $ps= $ENV{PAGE_SIZE};
+my $page;
+die "Unable to read $file" unless sysread(FILE, $page, $ps) == $ps;
+my $full_crc32 = unpack("N",substr($page,54,4)) & 0x10; # FIL_SPACE_FLAGS
+sysseek(FILE, 3*$ps, 0) || die "Unable to seek $file\n";
+die "Unable to read $file" unless sysread(FILE, $page, $ps) == $ps;
+substr($page,24,2)='42';
+my $polynomial = 0x82f63b78; # CRC-32C
+if ($full_crc32)
+{
+ my $ck = mycrc32(substr($page, 0, $ps-4), 0, $polynomial);
+ substr($page, $ps-4, 4) = pack("N", $ck);
+}
+else
+{
+ my $ck= pack("N",mycrc32(substr($page, 4, 22), 0, $polynomial) ^
+ mycrc32(substr($page, 38, $ps - 38 - 8), 0, $polynomial));
+ substr($page,0,4)=$ck;
+ substr($page,$ps-8,4)=$ck;
+}
+sysseek(FILE, 3*$ps, 0) || die "Unable to rewind $file\n";
+syswrite(FILE, $page, $ps)==$ps || die "Unable to write $file\n";
+close(FILE) || die "Unable to close $file";
+EOF
+
+-- source include/start_mysqld.inc
+
+--error ER_NO_SUCH_TABLE_IN_ENGINE
+SELECT COUNT(*) FROM bug16720368;
+--error ER_TABLE_CORRUPT
+INSERT INTO bug16720368 VALUES(1);
+INSERT INTO bug16720368_1 VALUES(1);
+
+-- echo # Shut down the server to uncorrupt the data.
+-- source include/shutdown_mysqld.inc
+
+# Uncorrupt the FIL_PAGE_TYPE.
+perl;
+do "$ENV{MTR_SUITE_DIR}/include/crc32.pl";
+my $file = "$ENV{MYSQLD_DATADIR}/test/bug16720368.ibd";
+open(FILE, "+<$file") || die "Unable to open $file";
+binmode FILE;
+my $ps= $ENV{PAGE_SIZE};
+my $page;
+die "Unable to read $file" unless sysread(FILE, $page, $ps) == $ps;
+my $full_crc32 = unpack("N",substr($page,54,4)) & 0x10; # FIL_SPACE_FLAGS
+sysseek(FILE, 3*$ps, 0) || die "Unable to seek $file\n";
+die "Unable to read $file" unless sysread(FILE, $page, $ps) == $ps;
+substr($page,24,2)=pack("H*","45BF");
+my $polynomial = 0x82f63b78; # CRC-32C
+if ($full_crc32)
+{
+ my $ck = mycrc32(substr($page, 0, $ps-4), 0, $polynomial);
+ substr($page, $ps-4, 4) = pack("N", $ck);
+}
+else
+{
+ my $ck= pack("N",mycrc32(substr($page, 4, 22), 0, $polynomial) ^
+ mycrc32(substr($page, 38, $ps - 38 - 8), 0, $polynomial));
+ substr($page,0,4)=$ck;
+ substr($page,$ps-8,4)=$ck;
+}
+sysseek(FILE, 3*$ps, 0) || die "Unable to rewind $file\n";
+syswrite(FILE, $page, $ps)==$ps || die "Unable to write $file\n";
+close(FILE) || die "Unable to close $file";
+EOF
+
+-- source include/start_mysqld.inc
+
+INSERT INTO bug16720368 VALUES(9,1);
+SELECT COUNT(*) FROM bug16720368;
+# A debug assertion would fail in buf_block_align_instance()
+# if we did not uncorrupt the page number first.
+DROP TABLE bug16720368, bug16720368_1;
+
+-- echo #
+-- echo # Bug#16735660 ASSERT TABLE2 == NULL, ROLLBACK OF RESURRECTED TXNS,
+-- echo # DICT_TABLE_ADD_TO_CACHE
+-- echo #
+
+SET GLOBAL innodb_file_per_table=1;
+
+CREATE TEMPORARY TABLE t1 (a INT PRIMARY KEY) ENGINE=InnoDB;
+BEGIN;
+INSERT INTO t1 VALUES(42);
+
+-- connect (con1,localhost,root)
+
+CREATE TABLE bug16735660 (a INT PRIMARY KEY) ENGINE=InnoDB;
+
+XA START 'x';
+--source ../include/no_checkpoint_start.inc
+INSERT INTO bug16735660 VALUES(1),(2),(3);
+XA END 'x';
+XA PREPARE 'x';
+--connection default
+--let CLEANUP_IF_CHECKPOINT=XA ROLLBACK 'x';DROP TABLE bug16735660;
+--source ../include/no_checkpoint_end.inc
+
+-- disconnect con1
+-- move_file $MYSQLD_DATADIR/test/bug16735660.ibd $MYSQLD_DATADIR/bug16735660.omg
+
+-- echo # Attempt to start without an *.ibd file.
+let SEARCH_FILE= $MYSQLTEST_VARDIR/log/mysqld.1.err;
+--source include/start_mysqld.inc
+
+let SEARCH_PATTERN= \[ERROR\] InnoDB: Tablespace [0-9]+ was not found at .*test.bug16735660.ibd;
+-- source include/search_pattern_in_file.inc
+
+-- move_file $MYSQLD_DATADIR/bug16735660.omg $MYSQLD_DATADIR/test/bug16735660.ibd
+
+-- source include/restart_mysqld.inc
+
+SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED;
+--disable_ps2_protocol
+SELECT * FROM bug16735660;
+--enable_ps2_protocol
+
+XA RECOVER;
+XA ROLLBACK 'x';
+
+--disable_ps2_protocol
+SELECT * FROM bug16735660;
+--enable_ps2_protocol
+DROP TABLE bug16735660;
diff --git a/mysql-test/suite/innodb/t/alter_large_dml.opt b/mysql-test/suite/innodb/t/alter_large_dml.opt
new file mode 100644
index 00000000..f6d3b842
--- /dev/null
+++ b/mysql-test/suite/innodb/t/alter_large_dml.opt
@@ -0,0 +1,2 @@
+--innodb_fatal_semaphore_wait_threshold=20
+--innodb_online_alter_log_max_size=536870912
diff --git a/mysql-test/suite/innodb/t/alter_large_dml.test b/mysql-test/suite/innodb/t/alter_large_dml.test
new file mode 100644
index 00000000..7320fa00
--- /dev/null
+++ b/mysql-test/suite/innodb/t/alter_large_dml.test
@@ -0,0 +1,51 @@
+--source include/big_test.inc
+# debug sync points times out when using valgrind
+--source include/not_valgrind.inc
+--source include/have_innodb.inc
+--source include/have_debug.inc
+--source include/have_debug_sync.inc
+--source include/have_sequence.inc
+# This test often times out with MemorySanitizer.
+--source include/not_msan.inc
+
+CREATE TABLE t1(f1 char(200), f2 char(200), f3 char(200),
+ f4 char(200), f5 char(200), f6 char(200),
+ f7 char(200), f8 char(200))ENGINE=InnoDB;
+
+INSERT INTO t1 SELECT '','','','','','','','' FROM seq_1_to_16384;
+
+SET DEBUG_SYNC = 'inplace_after_index_build SIGNAL rebuilt WAIT_FOR dml_pause';
+SET DEBUG_SYNC = 'alter_table_inplace_before_lock_upgrade SIGNAL dml_restart WAIT_FOR dml_done';
+SET DEBUG_SYNC = 'row_log_table_apply2_before SIGNAL ddl_start';
+--send
+ALTER TABLE t1 FORCE, ALGORITHM=INPLACE;
+
+--connect(con1,localhost,root,,test)
+SET DEBUG_SYNC = 'now WAIT_FOR rebuilt';
+BEGIN;
+INSERT INTO t1 SELECT '','','','','','','','' FROM seq_1_to_16384;
+SET DEBUG_SYNC = 'now SIGNAL dml_pause';
+SET DEBUG_SYNC = 'now WAIT_FOR dml_restart';
+ROLLBACK;
+
+BEGIN;
+INSERT INTO t1 SELECT '','','','','','','','' FROM seq_1_to_81920;
+ROLLBACK;
+
+BEGIN;
+INSERT INTO t1 SELECT '','','','','','','','' FROM seq_1_to_114688;
+ROLLBACK;
+
+SET DEBUG_SYNC = 'now SIGNAL dml_done';
+
+--connect(con2, localhost,root,,test)
+SET DEBUG_SYNC = 'now WAIT_FOR ddl_start';
+CREATE TABLE t2(f1 INT NOT NULL)ENGINE=InnoDB;
+
+connection default;
+reap;
+SHOW CREATE TABLE t1;
+
+SELECT COUNT(*) FROM t1;
+SET DEBUG_SYNC = 'RESET';
+DROP TABLE t1, t2;
diff --git a/mysql-test/suite/innodb/t/alter_mdl_timeout.opt b/mysql-test/suite/innodb/t/alter_mdl_timeout.opt
new file mode 100644
index 00000000..9e0e38bd
--- /dev/null
+++ b/mysql-test/suite/innodb/t/alter_mdl_timeout.opt
@@ -0,0 +1 @@
+--lock_wait_timeout=2
diff --git a/mysql-test/suite/innodb/t/alter_mdl_timeout.test b/mysql-test/suite/innodb/t/alter_mdl_timeout.test
new file mode 100644
index 00000000..6d916a3f
--- /dev/null
+++ b/mysql-test/suite/innodb/t/alter_mdl_timeout.test
@@ -0,0 +1,33 @@
+--source include/have_innodb.inc
+--source include/have_debug.inc
+--source include/have_debug_sync.inc
+
+create table t1(f1 char(10), f2 char(10) not null, f3 int not null,
+ f4 int not null, primary key(f3))engine=innodb;
+insert into t1 values('a','a', 1, 1), ('b','b', 2, 2), ('c', 'c', 3, 3), ('d', 'd', 4, 4);
+SET DEBUG_SYNC="row_merge_after_scan SIGNAL con1_start WAIT_FOR con1_insert";
+SET DEBUG_SYNC="innodb_commit_inplace_alter_table_wait SIGNAL con1_wait WAIT_FOR con1_update";
+send ALTER TABLE t1 ADD UNIQUE INDEX(f1(3), f4), ADD UNIQUE INDEX(f2), ALGORITHM=INPLACE;
+
+connect(con1,localhost,root,,,);
+SET DEBUG_SYNC="now WAIT_FOR con1_start";
+begin;
+INSERT INTO t1 VALUES('e','e',5, 5);
+SET DEBUG_SYNC="now SIGNAL con1_insert";
+SET DEBUG_SYNC="now WAIT_FOR con1_wait";
+SET DEBUG_SYNC="after_row_upd_clust SIGNAL con1_update WAIT_FOR alter_rollback";
+SEND UPDATE t1 set f4 = 10 order by f1 desc limit 2;
+
+connection default;
+--error ER_LOCK_WAIT_TIMEOUT
+reap;
+SET DEBUG_SYNC="now SIGNAL alter_rollback";
+
+connection con1;
+reap;
+commit;
+
+connection default;
+disconnect con1;
+DROP TABLE t1;
+SET DEBUG_SYNC="RESET";
diff --git a/mysql-test/suite/innodb/t/alter_missing_tablespace.test b/mysql-test/suite/innodb/t/alter_missing_tablespace.test
new file mode 100644
index 00000000..9742adc3
--- /dev/null
+++ b/mysql-test/suite/innodb/t/alter_missing_tablespace.test
@@ -0,0 +1,76 @@
+--source include/not_embedded.inc
+--source include/innodb_page_size.inc
+--source include/no_valgrind_without_big.inc
+
+--echo #
+--echo # Bug#13955083 ALLOW IN-PLACE DDL OPERATIONS ON MISSING
+--echo # OR DISCARDED TABLESPACES
+--echo #
+
+--disable_query_log
+call mtr.add_suppression("InnoDB: Cannot open datafile for read-only: ");
+call mtr.add_suppression("InnoDB: Operating system error number .* in a file operation");
+call mtr.add_suppression("InnoDB: Error number \\d+ means");
+call mtr.add_suppression("InnoDB: Ignoring tablespace for test/\(t\|x@002e@002ed\) because it could not be opened");
+call mtr.add_suppression("InnoDB: Cannot calculate statistics for table .* because the .ibd file is missing");
+call mtr.add_suppression("Could not find a valid tablespace file for");
+call mtr.add_suppression("InnoDB: Failed to find tablespace for table `test`\.`\(t\|x\.\.d\)` in the cache");
+call mtr.add_suppression("InnoDB: Cannot delete tablespace [0-9]+.*not found");
+call mtr.add_suppression("Table .* in the InnoDB data dictionary has tablespace id .*, but tablespace with that id or name does not exist");
+call mtr.add_suppression("InnoDB: ALTER TABLE `test`.`t` DISCARD TABLESPACE failed to find tablespace");
+--enable_query_log
+
+let $MYSQLD_DATADIR=`select @@datadir`;
+SET GLOBAL innodb_file_per_table=1;
+CREATE TABLE t(a SERIAL)ENGINE=InnoDB;
+CREATE TABLE `x..d` (a INT PRIMARY KEY, b INT) ENGINE=InnoDB;
+CREATE TABLE t1(a SERIAL)ENGINE=InnoDB;
+INSERT INTO t1 VALUES(1),(2),(3);
+
+--source include/shutdown_mysqld.inc
+
+# Remove the tablespace files.
+--remove_file $MYSQLD_DATADIR/test/t.ibd
+--remove_file $MYSQLD_DATADIR/test/x@002e@002ed.ibd
+
+--source include/start_mysqld.inc
+
+# The table does exist, only the tablespace does not exist.
+--error ER_GET_ERRNO
+SELECT * FROM t;
+
+--error ER_GET_ERRNO
+ALTER TABLE t ADD INDEX (a), ALGORITHM=INPLACE;
+SHOW WARNINGS;
+
+--error ER_GET_ERRNO
+ALTER TABLE t ADD INDEX (a), ALGORITHM=COPY;
+SHOW WARNINGS;
+
+--error ER_GET_ERRNO
+ALTER TABLE t AUTO_INCREMENT=1, ALGORITHM=INPLACE;
+--error ER_GET_ERRNO
+ALTER TABLE t AUTO_INCREMENT=1, ALGORITHM=COPY;
+
+--error ER_PARSE_ERROR
+ALTER TABLE t ALGORITHM=INPLACE, DISCARD TABLESPACE;
+--error ER_PARSE_ERROR
+ALTER TABLE t ALGORITHM=COPY, DISCARD TABLESPACE;
+--error ER_PARSE_ERROR
+ALTER TABLE t ALGORITHM=DEFAULT, DISCARD TABLESPACE;
+ALTER TABLE t DISCARD TABLESPACE;
+RENAME TABLE t TO u;
+RENAME TABLE u TO v;
+DROP TABLE v;
+--error ER_GET_ERRNO
+SELECT * FROM `x..d`;
+DROP TABLE `x..d`;
+
+ALTER TABLE t1 DISCARD TABLESPACE;
+--error ER_TABLESPACE_DISCARDED
+ALTER TABLE t1 AUTO_INCREMENT=1, ALGORITHM=INPLACE;
+--error ER_TABLESPACE_DISCARDED
+ALTER TABLE t1 AUTO_INCREMENT=1, FORCE, ALGORITHM=INPLACE;
+--error ER_TABLESPACE_DISCARDED
+ALTER TABLE t1 AUTO_INCREMENT=1, ALGORITHM=COPY;
+DROP TABLE t1;
diff --git a/mysql-test/suite/innodb/t/alter_non_null.inc b/mysql-test/suite/innodb/t/alter_non_null.inc
new file mode 100644
index 00000000..3d26aab5
--- /dev/null
+++ b/mysql-test/suite/innodb/t/alter_non_null.inc
@@ -0,0 +1,2 @@
+# See also alter_non_null.combinations
+--source include/have_innodb.inc
diff --git a/mysql-test/suite/innodb/t/alter_not_null.combinations b/mysql-test/suite/innodb/t/alter_not_null.combinations
new file mode 100644
index 00000000..815223ce
--- /dev/null
+++ b/mysql-test/suite/innodb/t/alter_not_null.combinations
@@ -0,0 +1,5 @@
+[COPY]
+--alter_algorithm=copy
+
+[INPLACE]
+--alter_algorithm=inplace
diff --git a/mysql-test/suite/innodb/t/alter_not_null.test b/mysql-test/suite/innodb/t/alter_not_null.test
new file mode 100644
index 00000000..64683859
--- /dev/null
+++ b/mysql-test/suite/innodb/t/alter_not_null.test
@@ -0,0 +1,102 @@
+--source include/have_innodb.inc
+--source alter_sql_mode.inc
+
+let $sql_mode = `SELECT @@SQL_MODE`;
+let $error_code = 0;
+
+if ($sql_mode == "STRICT_TRANS_TABLES") {
+ let $error_code = WARN_DATA_TRUNCATED;
+}
+
+CREATE TABLE t1(f1 INT)ENGINE=INNODB;
+INSERT INTO t1 VALUES(NULL);
+SELECT * FROM t1;
+--enable_info
+--error $error_code
+ALTER TABLE t1 CHANGE f1 f1 INT NOT NULL;
+--disable_info
+SELECT * FROM t1;
+DROP TABLE t1;
+
+CREATE TABLE t1(f1 CHAR(10))ENGINE=INNODB;
+INSERT INTO t1 VALUES(NULL);
+SELECT * FROM t1;
+--enable_info
+--error $error_code
+ALTER TABLE t1 CHANGE f1 f1 CHAR(10) NOT NULL;
+--disable_info
+SELECT * FROM t1;
+DROP TABLE t1;
+
+CREATE TABLE t1(f1 VARCHAR(10))ENGINE=INNODB;
+INSERT INTO t1 VALUES(NULL);
+SELECT * FROM t1;
+--enable_info
+--error $error_code
+ALTER TABLE t1 CHANGE f1 f1 VARCHAR(20) NOT NULL;
+--disable_info
+SELECT * FROM t1;
+DROP TABLE t1;
+
+CREATE TABLE t1(f1 TEXT)ENGINE=INNODB;
+INSERT INTO t1 VALUES(NULL);
+SELECT * FROM t1;
+--enable_info
+--error $error_code
+ALTER TABLE t1 CHANGE f1 f1 TEXT NOT NULL DEFAULT 'abc';
+--disable_info
+SELECT * FROM t1;
+DROP TABLE t1;
+
+CREATE TABLE t1(f1 INT NOT NULL, f2 INT NOT NULL, f3 INT)ENGINE=INNODB;
+INSERT INTO t1 VALUES(2, 2, NULL);
+SELECT * FROM t1;
+--enable_info
+--error $error_code
+ALTER TABLE t1 CHANGE f3 f3 INT NOT NULL DEFAULT (f1 + f2);
+--disable_info
+SELECT * FROM t1;
+DROP TABLE t1;
+
+CREATE TABLE t1(f1 INT NOT NULL DEFAULT 0, b TINYINT)ENGINE=InnoDB;
+INSERT INTO t1 VALUES(10, NULL);
+SELECT * FROM t1;
+--enable_info
+--error $error_code
+ALTER TABLE t1 CHANGE b b TINYINT NOT NULL DEFAULT if(unix_timestamp()>1,1000,0);
+--disable_info
+SELECT * FROM t1;
+DROP TABLE t1;
+
+CREATE TABLE t1(a INT, v INT AS (a), c INT, d INT NOT NULL, e INT) ENGINE=InnoDB;
+--enable_info
+ALTER TABLE t1 DROP COLUMN c, CHANGE COLUMN e e INT NOT NULL;
+--disable_info
+DROP TABLE t1;
+
+CREATE TABLE t1 (a INT, v INT AS (a), d INT NOT NULL, e INT) ENGINE=InnoDB;
+--enable_info
+ALTER TABLE t1 FORCE;
+--disable_info
+DROP TABLE t1;
+
+# Alter ignore should work irrespective of sql mode
+
+CREATE TABLE t1(c1 INT NOT NULL, c2 INT, PRIMARY KEY(c1))ENGINE=INNODB;
+INSERT INTO t1 VALUES(1, NULL);
+--enable_info
+ALTER IGNORE TABLE t1 CHANGE c2 c2 INT NOT NULL DEFAULT 2;
+--disable_info
+SELECT * FROM t1;
+DROP TABLE t1;
+
+--echo #
+--echo # MDEV-16126 Crash or ASAN heap-buffer-overflow in
+--echo # mach_read_from_n_little_endian upon ALTER TABLE with blob
+--echo #
+
+CREATE TABLE t1(a INT, v INT AS (a), b INT, c BLOB) ENGINE=InnoDB;
+--enable_info
+ALTER TABLE t1 ADD PRIMARY KEY(b);
+--disable_info
+DROP TABLE t1;
diff --git a/mysql-test/suite/innodb/t/alter_not_null_debug.test b/mysql-test/suite/innodb/t/alter_not_null_debug.test
new file mode 100644
index 00000000..87113b2b
--- /dev/null
+++ b/mysql-test/suite/innodb/t/alter_not_null_debug.test
@@ -0,0 +1,99 @@
+--source include/have_innodb.inc
+--source include/have_debug.inc
+--source include/have_debug_sync.inc
+--source alter_sql_mode.inc
+
+let $sql_mode = `SELECT @@SQL_MODE`;
+let $error_code = 0;
+
+if ($sql_mode == "STRICT_TRANS_TABLES") {
+ let $error_code = ER_INVALID_USE_OF_NULL;
+}
+
+
+# Alter table should fail for strict sql mode
+
+CREATE TABLE t1(c1 INT NOT NULL, c2 INT, PRIMARY KEY(c1))ENGINE=INNODB;
+INSERT INTO t1 VALUES(1, 1);
+--enable_info
+SET DEBUG_SYNC= 'row_merge_after_scan
+SIGNAL opened WAIT_FOR flushed';
+send ALTER TABLE t1 CHANGE c2 c2 INT NOT NULL DEFAULT 2;
+connect (con1,localhost,root);
+SET DEBUG_SYNC= 'now WAIT_FOR opened';
+INSERT INTO t1 VALUES(2, NULL);
+UPDATE t1 SET c1 = 3 WHERE c2 = 1;
+SET DEBUG_SYNC= 'now SIGNAL flushed';
+connection default;
+--error $error_code
+reap;
+--disable_info
+SELECT * FROM t1;
+DROP TABLE t1;
+
+# Alter table should successfully apply the log for the alter operation
+
+CREATE TABLE t1(c1 INT NOT NULL, c2 INT, PRIMARY KEY(c1))ENGINE=INNODB;
+INSERT INTO t1 VALUES(1, 1);
+--enable_info
+SET DEBUG_SYNC= 'row_merge_after_scan
+SIGNAL opened WAIT_FOR flushed';
+send ALTER TABLE t1 CHANGE c2 c2 INT NOT NULL DEFAULT 2;
+connection con1;
+SET DEBUG_SYNC= 'now WAIT_FOR opened';
+INSERT INTO t1 VALUES(2, 3);
+UPDATE t1 SET c1 = 3 WHERE c2 = 1;
+SET DEBUG_SYNC= 'now SIGNAL flushed';
+connection default;
+reap;
+--disable_info
+SELECT * FROM t1;
+DROP TABLE t1;
+
+# Alter ignore should not give error
+
+CREATE TABLE t1(c1 INT NOT NULL, c2 INT, c3 INT, PRIMARY KEY(c1))ENGINE=INNODB;
+INSERT INTO t1 VALUES(1, 2, 3);
+--enable_info
+SET DEBUG_SYNC= 'row_merge_after_scan
+SIGNAL opened WAIT_FOR flushed';
+send ALTER IGNORE TABLE t1 CHANGE c2 c2 INT NOT NULL DEFAULT 2;
+connection con1;
+SET DEBUG_SYNC= 'now WAIT_FOR opened';
+UPDATE t1 SET c2= 2 WHERE c1 = 1;
+INSERT INTO t1 VALUES (2, NULL, 4);
+SET DEBUG_SYNC= 'now SIGNAL flushed';
+connection default;
+reap;
+--disable_info
+SELECT * FROM t1;
+DROP TABLE t1;
+SET DEBUG_SYNC='RESET';
+
+--echo #
+--echo # MDEV-21539 Assertion ...prtype... in row_log_table_apply_convert_mrec
+--echo #
+CREATE TABLE t1 (f VARCHAR(8) CHARACTER SET latin1 COLLATE latin1_swedish_ci)
+ENGINE=InnoDB;
+INSERT INTO t1 VALUES('ZERO');
+connection con1;
+SET DEBUG_SYNC = 'row_log_table_apply1_before SIGNAL scanned WAIT_FOR insert_done';
+send ALTER TABLE t1 MODIFY f VARCHAR(256) COLLATE latin1_german2_ci NOT NULL;
+
+--echo # session default
+connection default;
+SET DEBUG_SYNC = 'now WAIT_FOR scanned';
+INSERT INTO t1 VALUES('one');
+SET DEBUG_SYNC = 'now SIGNAL insert_done';
+
+connection con1;
+reap;
+disconnect con1;
+connection default;
+SET DEBUG_SYNC=RESET;
+
+ALTER TABLE t1 CHANGE f eins VARCHAR(257) COLLATE latin1_german1_ci NOT NULL,
+ALGORITHM=INSTANT;
+
+SELECT * FROM t1;
+DROP TABLE t1;
diff --git a/mysql-test/suite/innodb/t/alter_partitioned.test b/mysql-test/suite/innodb/t/alter_partitioned.test
new file mode 100644
index 00000000..8c6adbbb
--- /dev/null
+++ b/mysql-test/suite/innodb/t/alter_partitioned.test
@@ -0,0 +1,68 @@
+--source include/have_innodb.inc
+--source include/have_partition.inc
+
+--echo #
+--echo # MDEV-26077 Assertion failure err != DB_DUPLICATE_KEY
+--echo # or unexpected ER_TABLE_EXISTS_ERROR
+--echo #
+
+CREATE TABLE t1 (pk INT PRIMARY KEY) ENGINE=InnoDB;
+CREATE TABLE t2 (pk INT PRIMARY KEY) ENGINE=InnoDB;
+
+--connect (con1,localhost,root,,test)
+
+START TRANSACTION;
+INSERT INTO t2 (pk) VALUES (1);
+SAVEPOINT sp;
+INSERT INTO t1 (pk) VALUES (1);
+ROLLBACK TO SAVEPOINT sp;
+
+--connection default
+SET @save_timeout=@@lock_wait_timeout;
+SET @save_innodb_timeout=@@innodb_lock_wait_timeout;
+SET lock_wait_timeout=0;
+SET innodb_lock_wait_timeout=0;
+--error ER_LOCK_WAIT_TIMEOUT
+ALTER TABLE t1 PARTITION BY HASH(pk);
+SET lock_wait_timeout=@save_timeout;
+SET innodb_lock_wait_timeout=@save_innodb_timeout;
+
+SHOW CREATE TABLE t1;
+--connection con1
+COMMIT;
+--connection default
+SET lock_wait_timeout=@save_timeout;
+SET innodb_lock_wait_timeout=@save_innodb_timeout;
+ALTER TABLE t2 PARTITION BY HASH(pk);
+# Cleanup
+--disconnect con1
+--connection default
+DROP TABLE t1, t2;
+
+--echo # End of 10.2 tests
+
+CREATE TABLE t1(a INT, b VARCHAR(10), INDEX(a))ENGINE=InnoDB
+PARTITION BY RANGE(a)
+(PARTITION pa VALUES LESS THAN (3),
+PARTITION pb VALUES LESS THAN (5));
+
+--error ER_FEATURE_NOT_SUPPORTED_WITH_PARTITIONING
+CREATE TABLE t2(a INT, FOREIGN KEY(a) REFERENCES t1(a))ENGINE=INNODB
+PARTITION BY RANGE(a)
+(PARTITION pa VALUES LESS THAN (2),
+PARTITION pb VALUES LESS THAN (4));
+
+DROP TABLE t1;
+
+--echo # End of 10.3 tests
+
+--echo #
+--echo # MDEV-24754 Server crash in
+--echo # ha_partition_inplace_ctx::~ha_partition_inplace_ctx
+--echo #
+CREATE TABLE t1 (id INT PRIMARY KEY, a INT, va INT AS (a) VIRTUAL)
+ENGINE=InnoDB PARTITION BY HASH(id) PARTITIONS 2;
+ALTER TABLE t1 ADD b INT, ALGORITHM=INSTANT;
+DROP TABLE t1;
+
+--echo # End of 10.5 tests
diff --git a/mysql-test/suite/innodb/t/alter_partitioned_debug.test b/mysql-test/suite/innodb/t/alter_partitioned_debug.test
new file mode 100644
index 00000000..34565e12
--- /dev/null
+++ b/mysql-test/suite/innodb/t/alter_partitioned_debug.test
@@ -0,0 +1,34 @@
+--source include/have_innodb.inc
+--source include/have_partition.inc
+--source include/have_debug.inc
+--source include/have_debug_sync.inc
+
+CREATE TABLE t1 (a INT, b VARCHAR(10)) ENGINE=InnoDB
+PARTITION BY RANGE(a)
+(PARTITION pa VALUES LESS THAN (3),
+PARTITION pb VALUES LESS THAN (5));
+
+INSERT INTO t1 VALUES(2,'two'),(2,'two'),(4,'four');
+
+connect ddl,localhost,root,,test;
+SET DEBUG_SYNC = 'inplace_after_index_build SIGNAL go WAIT_FOR done';
+send ALTER TABLE t1 ADD UNIQUE KEY (a,b(3));
+
+connection default;
+SET DEBUG_SYNC = 'now WAIT_FOR go';
+BEGIN;
+SELECT * FROM t1 FOR UPDATE;
+SET DEBUG_SYNC = 'now SIGNAL done';
+
+connection ddl;
+--error ER_DUP_ENTRY
+reap;
+
+connection default;
+DELETE FROM t1;
+disconnect ddl;
+
+SET DEBUG_SYNC = 'RESET';
+
+CHECK TABLE t1;
+DROP TABLE t1;
diff --git a/mysql-test/suite/innodb/t/alter_partitioned_xa.test b/mysql-test/suite/innodb/t/alter_partitioned_xa.test
new file mode 100644
index 00000000..f0883802
--- /dev/null
+++ b/mysql-test/suite/innodb/t/alter_partitioned_xa.test
@@ -0,0 +1,31 @@
+--source include/have_innodb.inc
+--source include/have_partition.inc
+
+--echo #
+--echo # MDEV-14693 XA: Assertion `!clust_index->online_log' failed
+--echo # in rollback_inplace_alter_table
+--echo #
+
+# A bug in meta-data locking (MDL) for XA transactions causes
+# a bug in InnoDB error handling for ALTER TABLE to be triggered.
+CREATE TABLE t1 (a INT, b INT) ENGINE=InnoDB PARTITION BY HASH(a) PARTITIONS 2;
+XA START 'xid';
+INSERT INTO t1 VALUES (1,10);
+# XA bug: The following releases the MDL on t1!
+--error ER_XAER_RMFAIL
+CREATE DATABASE IF NOT EXISTS db;
+
+--connect (con1,localhost,root,,test)
+SET innodb_lock_wait_timeout= 1, lock_wait_timeout= 2;
+# Here, innodb_lock_wait_timeout would be exceeded, causing the operation
+# to roll back when InnoDB is attempting to commit.
+# (Instead, lock_wait_timeout should be exceeded!)
+--error ER_LOCK_WAIT_TIMEOUT
+ALTER TABLE t1 FORCE;
+
+# Cleanup
+--disconnect con1
+--connection default
+XA END 'xid';
+XA ROLLBACK 'xid';
+DROP TABLE t1;
diff --git a/mysql-test/suite/innodb/t/alter_persistent_autoinc.test b/mysql-test/suite/innodb/t/alter_persistent_autoinc.test
new file mode 100644
index 00000000..dcaea327
--- /dev/null
+++ b/mysql-test/suite/innodb/t/alter_persistent_autoinc.test
@@ -0,0 +1,86 @@
+# Test the ability to remove AUTO_INCREMENT attribute
+--source include/have_innodb.inc
+--source include/have_partition.inc
+
+CREATE TABLE t1 (c INT AUTO_INCREMENT NULL UNIQUE) ENGINE=InnoDB;
+ALTER TABLE t1 MODIFY c INT NULL, ALGORITHM=INSTANT;
+INSERT INTO t1 SET c=1;
+
+CREATE TABLE t2 (c INT AUTO_INCREMENT NULL UNIQUE) ENGINE=InnoDB;
+ALTER TABLE t2 MODIFY c INT NULL, FORCE, ALGORITHM=INPLACE;
+INSERT INTO t2 SET c=1;
+
+CREATE TABLE t3 (c INT AUTO_INCREMENT NULL UNIQUE) ENGINE=InnoDB;
+ALTER TABLE t3 MODIFY c INT NULL, ALGORITHM=INPLACE;
+INSERT INTO t3 SET c=1;
+
+CREATE TABLE t4 (c1 INT AUTO_INCREMENT NULL UNIQUE, c2 INT) ENGINE=InnoDB;
+ALTER TABLE t4 MODIFY c1 INT NULL, CHANGE COLUMN c2 c3 INT, ALGORITHM=INPLACE;
+INSERT INTO t4 SET c1=1;
+
+CREATE TABLE t5 (c1 INT AUTO_INCREMENT NULL UNIQUE, c2 INT, c3 INTEGER GENERATED ALWAYS AS (c2)) ENGINE=InnoDB;
+# ha_innobase::commit_inplace_alter_table() should invoke innobase_reload_table()
+ALTER TABLE t5 MODIFY c1 INT NULL, MODIFY COLUMN c2 INT FIRST, ALGORITHM=INPLACE;
+INSERT INTO t5 SET c1=1;
+
+CREATE TABLE t6 (c INT AUTO_INCREMENT NULL UNIQUE) ENGINE=InnoDB
+ PARTITION BY LIST(c) (
+ PARTITION p1 VALUES IN (1),
+ PARTITION p2 VALUES IN (2)
+ );
+ALTER TABLE t6 MODIFY c INT NULL, ALGORITHM=INSTANT;
+INSERT INTO t6 SET c=1;
+INSERT INTO t6 SET c=2;
+
+CREATE TABLE t7 (c INT AUTO_INCREMENT NULL UNIQUE) ENGINE=InnoDB
+ PARTITION BY LIST(c) (
+ PARTITION p1 VALUES IN (1),
+ PARTITION p2 VALUES IN (2)
+ );
+ALTER TABLE t7 MODIFY c INT NULL, ALGORITHM=INPLACE;
+INSERT INTO t7 SET c=1;
+INSERT INTO t7 SET c=2;
+
+CREATE TABLE t8 (c1 INT AUTO_INCREMENT NULL UNIQUE, c2 INT) ENGINE=InnoDB
+ PARTITION BY LIST(c1) (
+ PARTITION p1 VALUES IN (1), PARTITION p2 VALUES IN (2));
+ALTER TABLE t8 MODIFY c1 INT NULL, CHANGE COLUMN c2 c3 INT, ALGORITHM=INPLACE;
+INSERT INTO t8 SET c1=1;
+INSERT INTO t8 SET c1=2;
+
+FLUSH TABLES t1, t2, t3, t4, t5, t6, t7, t8 FOR EXPORT;
+
+--let INNODB_PAGE_SIZE=`select @@innodb_page_size`
+--let MYSQLD_DATADIR = `SELECT @@datadir`
+
+--perl
+my $ps= $ENV{INNODB_PAGE_SIZE};
+my $PAGE_HEADER = 38;
+my $PAGE_ROOT_AUTO_INC = 18;
+print "AUTO_INCREMENT not partitioned: ";
+for (my $i = 1; $i <= 5; ++$i) {
+ my $autoinc= read_autoinc("$ENV{MYSQLD_DATADIR}/test/t$i.ibd");
+ print "$autoinc ";
+}
+print "\n";
+print "AUTO_INCREMENT partitioned: ";
+for (my $i = 6; $i <= 8; ++$i) {
+ my $p1= read_autoinc("$ENV{MYSQLD_DATADIR}/test/t$i#P#p1.ibd");
+ my $p2= read_autoinc("$ENV{MYSQLD_DATADIR}/test/t$i#P#p2.ibd");
+ print "($p1, $p2) ";
+}
+print "\n";
+sub read_autoinc {
+ my $file= shift;
+ open(FILE, "<", $file) || die "Unable to open $file\n";
+ sysseek(FILE, 3*$ps + $PAGE_HEADER + $PAGE_ROOT_AUTO_INC + 4, 0)
+ || die "Unable to seek $file\n";
+ die "Unable to read $file\n" unless sysread(FILE, $_, 4) == 4;
+ my $t1=unpack("N",$_);
+ close(FILE);
+ return $t1;
+}
+EOF
+
+UNLOCK TABLES;
+DROP TABLE t1, t2, t3, t4, t5, t6, t7, t8;
diff --git a/mysql-test/suite/innodb/t/alter_primary_key.test b/mysql-test/suite/innodb/t/alter_primary_key.test
new file mode 100644
index 00000000..bf961c14
--- /dev/null
+++ b/mysql-test/suite/innodb/t/alter_primary_key.test
@@ -0,0 +1,35 @@
+--source innodb_default_row_format.inc
+--source include/have_debug.inc
+--source include/have_debug_sync.inc
+
+--echo #
+--echo # MDEV-23244 ALTER TABLE…ADD PRIMARY KEY fails to flag
+--echo # duplicate key error from concurrent DML
+--echo #
+
+CREATE TABLE t0 (pk INT PRIMARY KEY) ENGINE=InnoDB;
+CREATE TABLE t1 (c CHAR(2) NOT NULL) ENGINE=InnoDB;
+INSERT INTO t1 VALUES('cd');
+
+connect (con1,localhost,root,,);
+BEGIN;
+INSERT INTO t0 VALUES(1);
+
+connection default;
+SET DEBUG_SYNC='row_log_table_apply1_before SIGNAL dml WAIT_FOR dml_done';
+send ALTER TABLE t1 ADD PRIMARY KEY(c(1));
+
+connection con1;
+SET DEBUG_SYNC='now WAIT_FOR dml';
+INSERT INTO t1 VALUES ('ab'),('ac');
+COMMIT;
+SET DEBUG_SYNC='now SIGNAL dml_done';
+disconnect con1;
+
+connection default;
+--error ER_DUP_ENTRY
+reap;
+SET DEBUG_SYNC='RESET';
+
+SELECT * FROM t1;
+DROP TABLE t0,t1;
diff --git a/mysql-test/suite/innodb/t/alter_rename_existing.test b/mysql-test/suite/innodb/t/alter_rename_existing.test
new file mode 100644
index 00000000..556d8e66
--- /dev/null
+++ b/mysql-test/suite/innodb/t/alter_rename_existing.test
@@ -0,0 +1,93 @@
+--echo #
+--echo # Show what happens during ALTER TABLE when an existing file
+--echo # exists in the target location.
+--echo #
+--echo # Bug #19218794: IF TABLESPACE EXISTS, CAN'T CREATE TABLE,
+--echo # BUT CAN ALTER ENGINE=INNODB
+--echo #
+
+--source include/have_innodb.inc
+
+--disable_query_log
+LET $MYSQLD_DATADIR = `select @@datadir`;
+SET @old_innodb_file_per_table = @@innodb_file_per_table;
+--enable_query_log
+
+CREATE TABLE t1 (a SERIAL, b CHAR(10)) ENGINE=Memory;
+INSERT INTO t1(b) VALUES('one'), ('two'), ('three');
+
+--echo #
+--echo # Create a file called MYSQLD_DATADIR/test/t1.ibd
+--exec echo "This is not t1.ibd" > $MYSQLD_DATADIR/test/t1.ibd
+
+--echo # Directory listing of test/*.ibd
+--echo #
+--list_files $MYSQLD_DATADIR/test/ *.ibd
+
+--replace_regex /Error on rename of '.*' to '.*'/Error on rename of 'OLD_FILE_NAME' to 'NEW_FILE_NAME'/
+--error ER_ERROR_ON_RENAME
+ALTER TABLE t1 ENGINE = InnoDB;
+
+--echo #
+--echo # Move the file to InnoDB as t2
+--echo #
+ALTER TABLE t1 RENAME TO t2, ENGINE = INNODB;
+SHOW CREATE TABLE t2;
+SELECT * from t2;
+
+--replace_regex /Error on rename of '.*' to '.*'/Error on rename of 'OLD_FILE_NAME' to 'NEW_FILE_NAME'/
+--error ER_ERROR_ON_RENAME
+ALTER TABLE t2 RENAME TO t1;
+
+--echo #
+--echo # Create another t1, but in the system tablespace.
+--echo #
+SET GLOBAL innodb_file_per_table=OFF;
+CREATE TABLE t1 (a SERIAL, b CHAR(20)) ENGINE=InnoDB;
+INSERT INTO t1(b) VALUES('one'), ('two'), ('three');
+SHOW CREATE TABLE t1;
+SELECT name, space=0 FROM information_schema.innodb_sys_tables WHERE name = 'test/t1';
+
+--echo #
+--echo # ALTER TABLE from system tablespace to system tablespace
+--echo #
+ALTER TABLE t1 ADD COLUMN c INT, ALGORITHM=INPLACE;
+ALTER TABLE t1 ADD COLUMN d INT, ALGORITHM=COPY;
+
+--echo #
+--echo # Try to move t1 from the system tablespace to a file-per-table
+--echo # while a blocking t1.ibd file exists.
+--echo #
+SET GLOBAL innodb_file_per_table=ON;
+--replace_regex /#sql-ib[1-9][0-9]*/#sql-ib/
+--error ER_TABLESPACE_EXISTS
+ALTER TABLE t1 FORCE, ALGORITHM=INPLACE;
+--replace_regex /Error on rename of '.*' to '.*'/Error on rename of 'OLD_FILE_NAME' to 'NEW_FILE_NAME'/
+--error ER_ERROR_ON_RENAME
+ALTER TABLE t1 FORCE, ALGORITHM=COPY;
+
+--echo #
+--echo # Delete the blocking file called MYSQLD_DATADIR/test/t1.ibd
+--remove_file $MYSQLD_DATADIR/test/t1.ibd
+
+--echo # Move t1 to file-per-table using ALGORITHM=INPLACE with no blocking t1.ibd.
+--echo #
+ALTER TABLE t1 FORCE, ALGORITHM=INPLACE;
+SHOW CREATE TABLE t1;
+SELECT name, space=0 FROM information_schema.innodb_sys_tables WHERE name = 'test/t1';
+
+DROP TABLE t1;
+
+--echo #
+--echo # Rename t2.ibd to t1.ibd.
+--echo #
+ALTER TABLE t2 RENAME TO t1;
+SELECT name, space=0 FROM information_schema.innodb_sys_tables WHERE name = 'test/t1';
+SELECT * from t1;
+
+DROP TABLE t1;
+
+--disable_query_log
+call mtr.add_suppression("\\[ERROR\\] InnoDB: Cannot rename '.*' to '.*' because the target file exists");
+SET GLOBAL innodb_file_per_table = @old_innodb_file_per_table;
+--enable_query_log
diff --git a/mysql-test/suite/innodb/t/alter_sql_mode.combinations b/mysql-test/suite/innodb/t/alter_sql_mode.combinations
new file mode 100644
index 00000000..2749bd10
--- /dev/null
+++ b/mysql-test/suite/innodb/t/alter_sql_mode.combinations
@@ -0,0 +1,5 @@
+[STRICT]
+--sql_mode=STRICT_TRANS_TABLES
+
+[NON-STRICT]
+--sql_mode=
diff --git a/mysql-test/suite/innodb/t/alter_sql_mode.inc b/mysql-test/suite/innodb/t/alter_sql_mode.inc
new file mode 100644
index 00000000..d5120850
--- /dev/null
+++ b/mysql-test/suite/innodb/t/alter_sql_mode.inc
@@ -0,0 +1,2 @@
+# See also alter_sql_mode.combinations
+--source include/have_innodb.inc
diff --git a/mysql-test/suite/innodb/t/alter_table.test b/mysql-test/suite/innodb/t/alter_table.test
new file mode 100644
index 00000000..67ada081
--- /dev/null
+++ b/mysql-test/suite/innodb/t/alter_table.test
@@ -0,0 +1,143 @@
+--source include/have_innodb.inc
+--source include/have_sequence.inc
+#
+# MDEV-11995 ALTER TABLE proceeds despite reporting ER_TOO_LONG_KEY error
+#
+set @@sql_mode=strict_trans_tables;
+create table t1(a text not null) row_format=dynamic engine=innodb;
+create index idx1 on t1(a(3073));
+show create table t1;
+drop table t1;
+set @@sql_mode=default;
+
+#
+# MDEV-14081 ALTER TABLE CHANGE COLUMN Corrupts Index Leading to Crashes in 10.2
+#
+create table t1 (
+ id1 int(11) not null auto_increment,
+ id2 varchar(30) not null,
+ id3 datetime not null default current_timestamp,
+ primary key (id1),
+ unique key unique_id2 (id2)
+) engine=innodb;
+alter table t1 change column id2 id4 varchar(100) not null;
+select * from t1 where id4 like 'a';
+drop table t1;
+
+--echo #
+--echo # MDEV-17725 Assertion `!is_set() || (m_status == DA_OK_BULK && is_bulk_op())' failed in Diagnostics_area::set_ok_status upon ALTER failing due to error from engine
+--echo #
+
+SET sql_mode=STRICT_ALL_TABLES;
+CREATE TABLE t1 (pk INT PRIMARY KEY) ENGINE=InnoDB;
+ALTER TABLE t1 ORDER BY a;
+DROP TABLE t1;
+
+SET sql_mode='';
+CREATE TABLE t1 (pk INT PRIMARY KEY) ENGINE=InnoDB;
+ALTER TABLE t1 ORDER BY a;
+DROP TABLE t1;
+
+SET sql_mode=DEFAULT;
+
+--echo #
+--echo # MDEV-18775 Server crashes in dict_table_t::instant_column
+--echo # upon ADD COLUMN
+--echo #
+
+CREATE TABLE tx (pk INT PRIMARY KEY) ENGINE=InnoDB;
+CREATE TABLE t1 (pk INT, a INT, PRIMARY KEY (pk), KEY (a), FOREIGN KEY (a) REFERENCES tx (pk)) ENGINE=InnoDB;
+
+SET FOREIGN_KEY_CHECKS=OFF;
+
+--error ER_FK_COLUMN_CANNOT_DROP
+ALTER TABLE t1 DROP a;
+
+SET FOREIGN_KEY_CHECKS=ON;
+
+ALTER TABLE t1 ADD b INT;
+--error ER_DROP_INDEX_FK
+ALTER TABLE t1 DROP a;
+ALTER TABLE t1 ADD c INT;
+DROP TABLE t1, tx;
+
+--echo #
+--echo # MDEV-14119 Assertion cmp_rec_rec() on ALTER TABLE
+--echo #
+CREATE TABLE t1(a INT NOT NULL UNIQUE) ENGINE=InnoDB;
+INSERT INTO t1 SELECT * FROM seq_1_to_128;
+ALTER TABLE t1 ADD b TINYINT AUTO_INCREMENT PRIMARY KEY, DROP KEY a;
+DROP TABLE t1;
+
+--echo #
+--echo # MDEV-22939 Server crashes in row_make_new_pathname()
+--echo #
+CREATE TABLE t (a INT) ENGINE=INNODB;
+ALTER TABLE t DISCARD TABLESPACE;
+--error ER_TABLESPACE_DISCARDED
+ALTER TABLE t ENGINE INNODB;
+--error ER_TABLESPACE_DISCARDED
+ALTER TABLE t FORCE;
+DROP TABLE t;
+
+--echo #
+--echo # MDEV-24763 ALTER TABLE fails to rename a column in SYS_FIELDS
+--echo #
+CREATE TABLE t1 (a INT, b TEXT, c INT, PRIMARY KEY(b(9)), INDEX(c,a))
+ENGINE=InnoDB;
+ALTER TABLE t1 CHANGE COLUMN a u INT;
+--replace_column 1 ID
+SELECT sf.* FROM information_schema.innodb_sys_fields sf
+INNER JOIN information_schema.innodb_sys_indexes si ON sf.index_id=si.index_id
+INNER JOIN information_schema.innodb_sys_tables st ON si.table_id=st.table_id
+WHERE st.name='test/t1' ORDER BY sf.index_id,sf.pos;
+DROP TABLE t1;
+
+--echo #
+--echo # End of 10.2 tests
+--echo #
+
+--echo #
+--echo # Check that innodb supports transactional=1
+--echo #
+
+create table t1 (a int) transactional=1 engine=aria;
+create table t2 (a int) transactional=1 engine=innodb;
+show create table t1;
+show create table t2;
+alter table t1 engine=innodb;
+alter table t1 add column b int;
+drop table t1,t2;
+
+--echo #
+--echo # MDEV-19272 Assertion unireg_check...Field::NEXT_NUMBER failed
+--echo #
+CREATE TABLE t1 (c INT AUTO_INCREMENT NULL UNIQUE) ENGINE=InnoDB;
+ALTER TABLE t1 MODIFY c INT NOT NULL, ALGORITHM=INPLACE;
+DROP TABLE t1;
+--error ER_WRONG_FIELD_SPEC
+CREATE TABLE t1 (c TIMESTAMP AUTO_INCREMENT UNIQUE) ENGINE=InnoDB;
+--error ER_WRONG_FIELD_SPEC
+CREATE TABLE t1 (c DATETIME AUTO_INCREMENT UNIQUE) ENGINE=InnoDB;
+
+--echo #
+--echo # End of 10.4 tests
+--echo #
+
+--echo #
+--echo # MDEV-21748 ASAN use-after-poison in PageBulk::insertPage()
+--echo #
+CREATE TABLE t1 (pk TIMESTAMP PRIMARY KEY, a TIMESTAMP NULL UNIQUE)
+ENGINE=InnoDB;
+INSERT INTO t1 VALUES
+ ('2020-03-10 10:21:00', NULL),
+ ('0000-00-00 00:00:00', '0000-00-00 00:00:00');
+ALTER TABLE t1 FORCE, ALGORITHM=INPLACE;
+DROP TABLE t1;
+--echo #
+--echo # MDEV-21850 ASAN use-after-poison in page_cur_insert_rec_low()
+--echo #
+CREATE TABLE t1 (id INT PRIMARY KEY, a YEAR, INDEX(id,a)) ENGINE=InnoDB;
+INSERT INTO t1 VALUES (1,NULL),(2,NULL);
+UPDATE t1 SET a=0;
+DROP TABLE t1;
diff --git a/mysql-test/suite/innodb/t/alter_table_upgrade.test b/mysql-test/suite/innodb/t/alter_table_upgrade.test
new file mode 100644
index 00000000..cd058aee
--- /dev/null
+++ b/mysql-test/suite/innodb/t/alter_table_upgrade.test
@@ -0,0 +1,36 @@
+--source include/have_innodb.inc
+
+let $datadir=`select @@datadir`;
+
+--echo #
+--echo # Start of 10.4 tests
+--echo #
+
+--echo #
+--echo # MDEV-29481 mariadb-upgrade prints confusing statement
+--echo #
+
+CREATE TABLE pet4 (
+ build_time double(18,7) DEFAULT NULL,
+ KEY idx1 (build_time)) ENGINE=InnoDB;
+FLUSH TABLES;
+remove_file $datadir/test/pet4.frm;
+copy_file std_data/mysql_upgrade/mdev29481_100104_innodb.frm $datadir/test/pet4.frm;
+SHOW CREATE TABLE pet4;
+CHECK TABLE pet4 FOR UPGRADE;
+ALTER TABLE pet4 ADD i1 INTEGER, ALGORITHM=INSTANT;
+DROP TABLE pet4;
+
+CREATE TABLE pet4 (
+ build_time double(18,7) DEFAULT NULL,
+ KEY idx1 (build_time)) ENGINE=InnoDB;
+FLUSH TABLES;
+remove_file $datadir/test/pet4.frm;
+copy_file std_data/mysql_upgrade/mdev29481_100104_innodb.frm $datadir/test/pet4.frm;
+SHOW CREATE TABLE pet4;
+ALTER TABLE pet4 ADD i1 INTEGER, ALGORITHM=NOCOPY;
+DROP TABLE pet4;
+
+--echo #
+--echo # End of 10.4 tests
+--echo #
diff --git a/mysql-test/suite/innodb/t/alter_varchar_change.test b/mysql-test/suite/innodb/t/alter_varchar_change.test
new file mode 100644
index 00000000..d1ce5d74
--- /dev/null
+++ b/mysql-test/suite/innodb/t/alter_varchar_change.test
@@ -0,0 +1,375 @@
+--source include/have_innodb.inc
+
+DELIMITER |;
+CREATE PROCEDURE get_index_id(IN tbl_id INT, IN idx_name char(100), OUT idx_id INT)
+BEGIN
+SELECT index_id into idx_id FROM INFORMATION_SCHEMA.INNODB_SYS_INDEXES WHERE
+ NAME=idx_name and TABLE_ID=tbl_id;
+END|
+
+CREATE PROCEDURE get_table_id(IN tbl_name char(100), OUT tbl_id INT)
+BEGIN
+SELECT table_id into tbl_id FROM INFORMATION_SCHEMA.INNODB_SYS_TABLES WHERE
+ NAME = tbl_name;
+END|
+
+DELIMITER ;|
+
+SET @tbl_id = 0;
+SET @tbl1_id = 0;
+SET @idx_id = 0;
+SET @idx1_id = 0;
+
+# Table should avoid rebuild for the following varchar change.
+
+CREATE TABLE t1(f1 INT NOT NULL,
+ f2 VARCHAR(100) PRIMARY KEY)ENGINE=InnoDB;
+
+CALL get_table_id("test/t1", @tbl_id);
+ALTER TABLE t1 MODIFY f2 VARCHAR(200), ALGORITHM=INSTANT;
+CALL get_table_id("test/t1", @tbl1_id);
+
+SELECT @tbl1_id = @tbl_id;
+SHOW CREATE TABLE t1;
+DROP TABLE t1;
+
+# Index should avoid rebuild
+CREATE TABLE t1(f1 INT NOT NULL,
+ f2 VARCHAR(100),
+ INDEX idx(f2))ENGINE=InnoDB;
+
+CALL get_table_id("test/t1", @tbl_id);
+ALTER TABLE t1 MODIFY f2 VARCHAR(200), ALGORITHM=INSTANT;
+CALL get_table_id("test/t1", @tbl1_id);
+
+SELECT @tbl1_id = @tbl_id;
+SHOW CREATE TABLE t1;
+DROP TABLE t1;
+
+CREATE TABLE t1(f1 INT NOT NULL, f2 VARCHAR(100), f3 VARCHAR(100),
+ INDEX idx(f2, f3), index idx1(f3, f2))ENGINE=InnoDB;
+
+CALL get_table_id("test/t1", @tbl_id);
+CALL get_index_id(@tbl_id, "idx", @idx_id);
+ALTER TABLE t1 MODIFY f2 VARCHAR(200), MODIFY f3 VARCHAR(150), ALGORITHM=INSTANT;
+CALL get_table_id("test/t1", @tbl1_id);
+CALL get_index_id(@tbl1_id, "idx", @idx1_id);
+
+SELECT @tbl1_id = @tbl_id;
+SELECT @idx1_id = @idx_id;
+SHOW CREATE TABLE t1;
+DROP TABLE t1;
+
+CREATE TABLE t1(f1 INT NOT NULL, f2 VARCHAR(100),
+ INDEX idx(f2(40)))ENGINE=InnoDB;
+
+CALL get_table_id("test/t1", @tbl_id);
+CALL get_index_id(@tbl_id, "idx", @idx_id);
+ALTER TABLE t1 MODIFY f2 VARCHAR(200), ALGORITHM=INSTANT;
+CALL get_table_id("test/t1", @tbl1_id);
+CALL get_index_id(@tbl1_id, "idx", @idx1_id);
+
+SELECT @tbl1_id = @tbl_id;
+SELECT @idx1_id = @idx_id;
+
+SHOW CREATE TABLE t1;
+DROP TABLE t1;
+
+CREATE TABLE t1(f1 INT NOT NULL,
+ f2 VARCHAR(100), FULLTEXT idx(f2))ENGINE=InnoDB;
+
+CALL get_table_id("test/t1", @tbl_id);
+CALL get_index_id(@tbl_id, "idx", @idx_id);
+ALTER TABLE t1 MODIFY f2 VARCHAR(200), ALGORITHM=INSTANT;
+CALL get_table_id("test/t1", @tbl1_id);
+CALL get_index_id(@tbl1_id, "idx", @idx1_id);
+
+SELECT @tbl1_id = @tbl_id;
+SELECT @idx1_id = @idx_id;
+SHOW CREATE TABLE t1;
+DROP TABLE t1;
+
+CREATE TABLE t1(f1 INT NOT NULL,
+ f2 VARCHAR(100),
+ f3 VARCHAR(50) as (f2) VIRTUAL,
+ INDEX idx(f3))ENGINE=InnoDB;
+
+INSERT INTO t1(f1, f2) VALUES(1, repeat('a', 40));
+
+CALL get_table_id("test/t1", @tbl_id);
+CALL get_index_id(@tbl_id, "idx", @idx_id);
+ALTER TABLE t1 MODIFY f2 VARCHAR(100), ALGORITHM=INSTANT;
+CALL get_table_id("test/t1", @tbl1_id);
+CALL get_index_id(@tbl1_id, "idx", @idx1_id);
+
+SELECT @tbl1_id = @tbl_id;
+SELECT @idx1_id = @idx_id;
+SHOW CREATE TABLE t1;
+DROP TABLE t1;
+
+CREATE TABLE t1(f1 INT NOT NULL,
+ f2 VARCHAR(100),
+ INDEX idx(f2(10)),
+ INDEX idx1(f1))ENGINE=InnoDB;
+
+CALL get_table_id("test/t1", @tbl_id);
+CALL get_index_id(@tbl_id, "idx", @idx_id);
+ALTER TABLE t1 MODIFY f2 VARCHAR(200), DROP INDEX idx1;
+CALL get_table_id("test/t1", @tbl1_id);
+CALL get_index_id(@tbl1_id, "idx", @idx1_id);
+
+SELECT @tbl1_id = @tbl_id;
+SELECT @idx1_id = @idx_id;
+SHOW CREATE TABLE t1;
+DROP TABLE t1;
+
+CREATE TABLE t1(f1 INT NOT NULL,
+ f2 VARCHAR(100),
+ INDEX idx(f2(10)))ENGINE=InnoDB;
+
+CALL get_table_id("test/t1", @tbl_id);
+CALL get_index_id(@tbl_id, "idx", @idx_id);
+ALTER TABLE t1 MODIFY f2 VARCHAR(200), DROP INDEX idx, ADD INDEX idx(f2(10)), ALGORITHM=INSTANT;
+CALL get_table_id("test/t1", @tbl1_id);
+CALL get_index_id(@tbl1_id, "idx", @idx1_id);
+
+SELECT @tbl1_id = @tbl_id;
+SELECT @idx1_id = @idx_id;
+SHOW CREATE TABLE t1;
+DROP TABLE t1;
+
+CREATE TABLE t1(f1 INT NOT NULL,
+ f2 VARCHAR(100),
+ INDEX idx(f2(10)))ENGINE=InnoDB;
+
+CALL get_table_id("test/t1", @tbl_id);
+CALL get_index_id(@tbl_id, "idx", @idx_id);
+ALTER TABLE t1 MODIFY f2 VARCHAR(200), DROP INDEX idx, ADD INDEX idx(f2(50));
+CALL get_table_id("test/t1", @tbl1_id);
+CALL get_index_id(@tbl1_id, "idx", @idx1_id);
+
+SELECT @tbl1_id = @tbl_id;
+SELECT @idx1_id = @idx_id;
+SHOW CREATE TABLE t1;
+DROP TABLE t1;
+
+# Newly added index should built
+
+CREATE TABLE t1(f1 INT NOT NULL,
+ f2 VARCHAR(100),
+ INDEX idx(f2(100)))ENGINE=InnoDB;
+
+CALL get_table_id("test/t1", @tbl_id);
+CALL get_index_id(@tbl_id, "idx", @idx_id);
+ALTER TABLE t1 MODIFY f2 VARCHAR(200), ADD INDEX idx1(f1);
+CALL get_table_id("test/t1", @tbl1_id);
+CALL get_index_id(@tbl1_id, "idx", @idx1_id);
+
+SELECT @tbl1_id = @tbl_id;
+SELECT @idx1_id = @idx_id;
+SHOW CREATE TABLE t1;
+DROP TABLE t1;
+
+CREATE TABLE t1(f1 INT NOT NULL,
+ f2 VARCHAR(100),
+ INDEX idx(f2(10)))ENGINE=InnoDB;
+
+CALL get_table_id("test/t1", @tbl_id);
+CALL get_index_id(@tbl_id, "idx", @idx_id);
+ALTER TABLE t1 MODIFY f2 VARCHAR(200), DROP INDEX idx, ADD INDEX idx(f2(6));
+CALL get_table_id("test/t1", @tbl1_id);
+CALL get_index_id(@tbl1_id, "idx", @idx1_id);
+
+SELECT @tbl1_id = @tbl_id;
+SELECT @idx1_id = @idx_id;
+SHOW CREATE TABLE t1;
+DROP TABLE t1;
+
+# Table should rebuild
+
+CREATE TABLE t1(f1 INT NOT NULL,
+ f2 VARCHAR(100),
+ INDEX idx(f2))ENGINE=InnoDB;
+
+CALL get_table_id("test/t1", @tbl_id);
+ALTER TABLE t1 MODIFY f2 VARCHAR(200), ADD COLUMN f3 INT, ALGORITHM=INSTANT;
+CALL get_table_id("test/t1", @tbl1_id);
+
+SELECT @tbl1_id = @tbl_id;
+SHOW CREATE TABLE t1;
+DROP TABLE t1;
+
+CREATE TABLE t1(f1 INT NOT NULL, f2 VARCHAR(100) PRIMARY KEY)ENGINE=InnoDB;
+
+CALL get_table_id("test/t1", @tbl_id);
+ALTER TABLE t1 MODIFY f2 VARCHAR(200), ADD COLUMN f3 INT, ALGORITHM=INSTANT;
+CALL get_table_id("test/t1", @tbl1_id);
+
+SELECT @tbl1_id = @tbl_id;
+SHOW CREATE TABLE t1;
+DROP TABLE t1;
+
+CREATE TABLE t1(f1 INT NOT NULL, f2 VARCHAR(100))ENGINE=INNODB;
+
+CALL get_table_id("test/t1", @tbl_id);
+ALTER TABLE t1 MODIFY f2 VARCHAR(200), ADD FULLTEXT idx(f2);
+CALL get_table_id("test/t1", @tbl1_id);
+
+SELECT @tbl1_id = @tbl_id;
+SHOW CREATE TABLE t1;
+DROP TABLE t1;
+
+CREATE TABLE t1(f1 INT NOT NULL,
+ f2 CHAR(100) PRIMARY KEY)ENGINE=InnoDB;
+
+CALL get_table_id("test/t1", @tbl_id);
+ALTER TABLE t1 MODIFY f2 CHAR(200);
+CALL get_table_id("test/t1", @tbl1_id);
+
+SELECT @tbl1_id = @tbl_id;
+SHOW CREATE TABLE t1;
+DROP TABLE t1;
+
+CREATE TABLE t1(f1 INT NOT NULL,
+ f2 VARCHAR(100),
+ INDEX idx(f2(10)),
+ INDEX idx1(f1))ENGINE=InnoDB;
+
+CALL get_table_id("test/t1", @tbl_id);
+ALTER TABLE t1 MODIFY f2 VARCHAR(50);
+CALL get_table_id("test/t1", @tbl1_id);
+
+SELECT @tbl1_id = @tbl_id;
+SHOW CREATE TABLE t1;
+DROP TABLE t1;
+
+CREATE TABLE t1(f1 INT NOT NULL,
+ f2 VARCHAR(100),
+ INDEX idx(f2(10)),
+ INDEX idx1(f1))ENGINE=InnoDB;
+
+CALL get_table_id("test/t1", @tbl_id);
+ALTER TABLE t1 MODIFY f2 VARCHAR(5), DROP INDEX idx1;
+CALL get_table_id("test/t1", @tbl1_id);
+
+SELECT @tbl1_id = @tbl_id;
+SHOW CREATE TABLE t1;
+DROP TABLE t1;
+
+CREATE TABLE t1(f1 INT NOT NULL,
+ f2 VARCHAR(100), FULLTEXT idx(f2))ENGINE=InnoDB;
+
+CALL get_table_id("test/t1", @tbl_id);
+CALL get_index_id(@tbl_id, "idx", @idx_id);
+ALTER TABLE t1 MODIFY f2 VARCHAR(50);
+CALL get_table_id("test/t1", @tbl1_id);
+CALL get_index_id(@tbl1_id, "idx", @idx1_id);
+
+SELECT @tbl1_id = @tbl_id;
+SELECT @idx1_id = @idx_id;
+SHOW CREATE TABLE t1;
+DROP TABLE t1;
+
+CREATE TABLE t1(f1 INT NOT NULL,
+ f2 VARCHAR(100),
+ INDEX idx(f2))ENGINE=InnoDB;
+
+CALL get_table_id("test/t1", @tbl_id);
+ALTER TABLE t1 MODIFY f2 CHAR(200);
+CALL get_table_id("test/t1", @tbl1_id);
+
+SELECT @tbl1_id = @tbl_id;
+SHOW CREATE TABLE t1;
+DROP TABLE t1;
+
+CREATE TABLE t1(f1 INT NOT NULL,
+ f2 VARCHAR(100),
+ INDEX idx(f2(40)))ENGINE=InnoDB;
+
+CALL get_table_id("test/t1", @tbl_id);
+ALTER TABLE t1 MODIFY f2 TEXT;
+CALL get_table_id("test/t1", @tbl1_id);
+
+SELECT @tbl1_id = @tbl_id;
+SHOW CREATE TABLE t1;
+DROP TABLE t1;
+
+CREATE TABLE t1(f1 INT NOT NULL,
+ f2 VARCHAR(100),
+ INDEX idx(f2(40)))ENGINE=InnoDB;
+
+CALL get_table_id("test/t1", @tbl_id);
+ALTER TABLE t1 MODIFY f2 VARCHAR(300);
+CALL get_table_id("test/t1", @tbl1_id);
+
+SELECT @tbl1_id = @tbl_id;
+SHOW CREATE TABLE t1;
+DROP TABLE t1;
+
+CREATE TABLE t1(f1 INT NOT NULL,
+ f2 VARCHAR(128),
+ INDEX idx(f2(40)))ENGINE=InnoDB;
+
+CALL get_table_id("test/t1", @tbl_id);
+ALTER TABLE t1 MODIFY f2 VARCHAR(300);
+CALL get_table_id("test/t1", @tbl1_id);
+
+SELECT @tbl1_id = @tbl_id;
+SHOW CREATE TABLE t1;
+DROP TABLE t1;
+
+CREATE TABLE t1(f1 INT NOT NULL,
+ f2 VARCHAR(128),
+ INDEX idx(f2(40)))ENGINE=InnoDB ROW_FORMAT=REDUNDANT;
+
+CALL get_table_id("test/t1", @tbl_id);
+ALTER TABLE t1 MODIFY f2 VARCHAR(300);
+CALL get_table_id("test/t1", @tbl1_id);
+
+SELECT @tbl1_id = @tbl_id;
+SHOW CREATE TABLE t1;
+DROP TABLE t1;
+
+CREATE TABLE t1(f1 INT NOT NULL,
+ f2 VARCHAR(100),
+ INDEX idx(f2(40)))ENGINE=InnoDB;
+
+CALL get_table_id("test/t1", @tbl_id);
+ALTER TABLE t1 MODIFY f2 VARCHAR(200) CHARACTER SET UTF16;
+CALL get_table_id("test/t1", @tbl1_id);
+
+SELECT @tbl1_id = @tbl_id;
+SHOW CREATE TABLE t1;
+DROP TABLE t1;
+# Show error when virtual varchar column got changed
+
+CREATE TABLE t1(f1 INT NOT NULL,
+ f2 VARCHAR(100),
+ f3 VARCHAR(50) as (f2) VIRTUAL,
+ INDEX idx(f3))ENGINE=InnoDB;
+
+--echo # If varchar virtual column extension is allowed in the future then
+--echo # InnoDB must rebuild the index
+
+--error ER_UNSUPPORTED_ACTION_ON_GENERATED_COLUMN
+ALTER TABLE t1 MODIFY f3 VARCHAR(100);
+SHOW CREATE TABLE t1;
+DROP TABLE t1;
+
+DROP PROCEDURE get_index_id;
+DROP PROCEDURE get_table_id;
+
+# LEN must increase here
+create table t (a varchar(100)) engine=innodb;
+select sc.name, sc.pos, sc.mtype, sc.prtype, sc.len
+from information_schema.innodb_sys_columns sc
+inner join information_schema.innodb_sys_tables st
+on sc.table_id=st.table_id where st.name='test/t' and sc.name='a';
+alter table t modify a varchar(110), algorithm=inplace;
+select sc.name, sc.pos, sc.mtype, sc.prtype, sc.len
+from information_schema.innodb_sys_columns sc
+inner join information_schema.innodb_sys_tables st
+on sc.table_id=st.table_id where st.name='test/t' and sc.name='a';
+drop table t;
+
+--echo # End of 10.2 tests
diff --git a/mysql-test/suite/innodb/t/analyze_table.test b/mysql-test/suite/innodb/t/analyze_table.test
new file mode 100644
index 00000000..538eed04
--- /dev/null
+++ b/mysql-test/suite/innodb/t/analyze_table.test
@@ -0,0 +1,23 @@
+--source include/have_innodb.inc
+--source include/have_sequence.inc
+
+#
+# MDEV-22073 MSAN use-of-uninitialized-value in collect_statistics_for_table()
+#
+
+set use_stat_tables='preferably';
+
+CREATE TABLE t1(
+ class INT,
+ id INT,
+ title VARCHAR(100)
+) ENGINE=InnoDB;
+
+insert into t1 select seq, seq, concat('a', seq) from seq_1_to_500;
+
+SELECT COUNT(*) FROM t1;
+
+set @@max_heap_table_size=16384;
+ANALYZE TABLE t1;
+
+DROP TABLE t1;
diff --git a/mysql-test/suite/innodb/t/auto_increment_dup.opt b/mysql-test/suite/innodb/t/auto_increment_dup.opt
new file mode 100644
index 00000000..ab372c3a
--- /dev/null
+++ b/mysql-test/suite/innodb/t/auto_increment_dup.opt
@@ -0,0 +1,2 @@
+--innodb_autoinc_lock_mode=1
+--innodb_lock_wait_timeout=2
diff --git a/mysql-test/suite/innodb/t/auto_increment_dup.test b/mysql-test/suite/innodb/t/auto_increment_dup.test
new file mode 100644
index 00000000..9e54a6a8
--- /dev/null
+++ b/mysql-test/suite/innodb/t/auto_increment_dup.test
@@ -0,0 +1,157 @@
+##########################################################################
+# LP bug #1035225 / MySQL bug #66301: INSERT ... ON DUPLICATE KEY UPDATE +
+# innodb_autoinc_lock_mode=1 is broken
+##########################################################################
+
+--source include/have_innodb.inc
+--source include/have_debug.inc
+--source include/have_debug_sync.inc
+--source include/innodb_binlog.inc
+
+set global transaction isolation level repeatable read;
+
+CREATE TABLE t1(
+ id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
+ k INT,
+ c CHAR(1),
+ UNIQUE KEY(k)) ENGINE=InnoDB;
+
+SHOW CREATE TABLE t1;
+
+--enable_info
+
+--echo #
+--echo # Sequential execution
+--echo #
+
+INSERT INTO t1(k) VALUES (1), (2), (3) ON DUPLICATE KEY UPDATE c='1';
+
+--echo #
+--echo # 1 duplicate
+--echo #
+INSERT INTO t1(k) VALUES (2), (4), (5) ON DUPLICATE KEY UPDATE c='2';
+--echo #
+--echo # 5 rows, consecutive auto_inc values
+--echo #
+
+SELECT * FROM t1 order by k;
+
+DROP TABLE t1;
+
+CREATE TABLE t1(
+ id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
+ k INT,
+ c CHAR(1),
+ UNIQUE KEY(k)) ENGINE=InnoDB;
+
+--echo #
+--echo # Sequential execution 2
+--echo #
+
+INSERT INTO t1(k) VALUES (2), (4), (5) ON DUPLICATE KEY UPDATE c='2';
+
+--echo #
+--echo # 1 duplicate
+--echo #
+INSERT INTO t1(k) VALUES (1), (2), (3) ON DUPLICATE KEY UPDATE c='1';
+--echo #
+--echo # 5 rows, consecutive auto_inc values
+--echo #
+
+SELECT * FROM t1 order by k;
+
+DROP TABLE t1;
+
+CREATE TABLE t1(
+ id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
+ k INT,
+ c CHAR(1),
+ UNIQUE KEY(k)) ENGINE=InnoDB;
+
+--echo #
+--echo # Parallel execution
+--echo #
+
+--connect(con2, localhost, root)
+--send SET DEBUG_SYNC='now WAIT_FOR write_row_done'
+
+--connect(con1, localhost, root)
+SET DEBUG_SYNC='ha_write_row_end SIGNAL write_row_done WAIT_FOR continue';
+--send INSERT INTO t1(k) VALUES (1), (2), (3) ON DUPLICATE KEY UPDATE c='1'
+--connection con2
+--reap
+
+SET DEBUG_SYNC='execute_command_after_close_tables SIGNAL continue';
+INSERT INTO t1(k) VALUES (2), (4), (5) ON DUPLICATE KEY UPDATE c='2';
+
+--connection con1
+--echo #
+--echo # 2 duplicates
+--echo #
+--reap
+--connection default
+--echo #
+--echo # 3 rows
+--echo #
+
+SELECT * FROM t1 order by k;
+
+INSERT INTO t1(k) VALUES (2), (4), (5) ON DUPLICATE KEY UPDATE c='2';
+
+SELECT * FROM t1 order by k;
+
+
+--disable_info
+
+--disconnect con1
+--disconnect con2
+
+--connection default
+
+DROP TABLE t1;
+
+--echo #
+--echo # Parallel test with read_committed
+--echo #
+
+set global transaction isolation level read committed;
+
+--disable_warnings
+drop table if exists t1;
+--enable_warnings
+
+CREATE TABLE t1(
+ id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
+ k INT,
+ c CHAR(1),
+ UNIQUE KEY(k)) ENGINE=InnoDB;
+
+--enable_info
+
+--connect(con1, localhost, root)
+SET DEBUG_SYNC='ha_write_row_end SIGNAL continue2 WAIT_FOR continue1';
+--send INSERT INTO t1(k) VALUES (1), (2), (3) ON DUPLICATE KEY UPDATE c='1'
+
+--connect(con2, localhost, root)
+SET DEBUG_SYNC='ha_write_row_start WAIT_FOR continue2';
+SET DEBUG_SYNC='after_mysql_insert SIGNAL continue1';
+INSERT INTO t1(k) VALUES (2), (4), (5) ON DUPLICATE KEY UPDATE c='2';
+--disconnect con2
+
+--connection con1
+--reap
+--disable_info
+SET DEBUG_SYNC='RESET';
+
+--echo #
+--echo # 5 rows, gap in autoinc values
+--echo #
+SELECT * FROM t1 ORDER BY k;
+
+--disconnect con1
+
+--connection default
+
+DROP TABLE t1;
+
+set global transaction isolation level repeatable read;
diff --git a/mysql-test/suite/innodb/t/autoinc_debug.test b/mysql-test/suite/innodb/t/autoinc_debug.test
new file mode 100644
index 00000000..7722b848
--- /dev/null
+++ b/mysql-test/suite/innodb/t/autoinc_debug.test
@@ -0,0 +1,94 @@
+--source include/have_innodb.inc
+--source include/have_debug.inc
+--source include/have_debug_sync.inc
+--source include/not_embedded.inc
+
+# Two parallel connection with autoinc column after restart.
+
+CREATE TABLE t1 (id INT AUTO_INCREMENT PRIMARY KEY)ENGINE=INNODB;
+
+--echo # SETTING auto_increment_increment IN CONNECTION DEFAULT
+SET AUTO_INCREMENT_INCREMENT = 1;
+
+--echo # MDEV-24348 InnoDB shutdown hang with innodb_flush_sync=0
+SET GLOBAL innodb_flush_sync=OFF;
+--echo # For the server to hang, we must have pages for temporary tables
+--echo # (and the bug depended on MDEV-12227 not being fixed).
+CREATE TEMPORARY TABLE t (id SERIAL) ENGINE=InnoDB;
+SET debug_dbug= '+d,ib_log_flush_ahead';
+
+INSERT INTO t1 VALUES(NULL);
+SELECT * FROM t1;
+SHOW CREATE TABLE t1;
+
+--source include/restart_mysqld.inc
+
+--echo # SETTING auto_increment_increment IN CONNECTION1
+SET AUTO_INCREMENT_INCREMENT = 2;
+
+SET DEBUG_SYNC= 'ib_after_row_insert SIGNAL opened WAIT_FOR flushed1';
+
+SEND INSERT INTO t1 VALUES(NULL);
+
+connect(con1, localhost, root,,);
+SET AUTO_INCREMENT_INCREMENT = 2;
+SET DEBUG_SYNC= 'now WAIT_FOR opened';
+SET DEBUG_SYNC= 'ib_after_row_insert_step SIGNAL flushed1 WAIT_FOR opened1';
+send insert into t1 values(NULL);
+
+connection default;
+reap;
+SELECT * FROM t1;
+SHOW CREATE TABLE t1;
+SET DEBUG_SYNC= 'now SIGNAL opened1';
+
+connection con1;
+reap;
+SELECT * FROM t1;
+SHOW CREATE TABLE t1;
+connection default;
+disconnect con1;
+
+DROP TABLE t1;
+
+# Two parallel connection with autoinc column without restart.
+
+CREATE TABLE t1(id INT AUTO_INCREMENT PRIMARY KEY)ENGINE=INNODB;
+
+--echo # SETTING auto_increment_increment IN CONNECTION DEFAULT
+SET AUTO_INCREMENT_INCREMENT = 1;
+INSERT INTO t1 VALUES(NULL);
+SELECT * FROM t1;
+SHOW CREATE TABLE t1;
+SET DEBUG_SYNC = 'now SIGNAL flushed';
+
+connect(con1, localhost, root,,);
+
+--echo # SETTING auto_increment_increment in connection1
+SET AUTO_INCREMENT_INCREMENT = 2;
+
+SET DEBUG_SYNC= 'now WAIT_FOR flushed';
+SET DEBUG_SYNC= 'ib_after_row_insert SIGNAL opened WAIT_FOR flushed1';
+
+send INSERT INTO t1 values(NULL);
+
+connection default;
+
+SET DEBUG_SYNC= 'now WAIT_FOR opened';
+SET DEBUG_SYNC= 'ib_after_row_insert_step SIGNAL flushed1 WAIT_FOR opened1';
+
+send INSERT INTO t1 VALUES(NULL);
+
+connection con1;
+reap;
+SELECT * FROM t1;
+SHOW CREATE TABLE t1;
+SET DEBUG_SYNC= 'now SIGNAL opened1';
+disconnect con1;
+
+connection default;
+reap;
+SELECT * FROM t1;
+SHOW CREATE TABLE t1;
+DROP TABLE t1;
+SET DEBUG_SYNC='RESET';
diff --git a/mysql-test/suite/innodb/t/autoinc_persist.combinations b/mysql-test/suite/innodb/t/autoinc_persist.combinations
new file mode 100644
index 00000000..4ae2948e
--- /dev/null
+++ b/mysql-test/suite/innodb/t/autoinc_persist.combinations
@@ -0,0 +1,2 @@
+[asc]
+[desc]
diff --git a/mysql-test/suite/innodb/t/autoinc_persist.test b/mysql-test/suite/innodb/t/autoinc_persist.test
new file mode 100644
index 00000000..ac933cc7
--- /dev/null
+++ b/mysql-test/suite/innodb/t/autoinc_persist.test
@@ -0,0 +1,569 @@
+--source include/have_innodb.inc
+# Restarting is not supported when testing the embedded server.
+--source include/not_embedded.inc
+--source include/no_valgrind_without_big.inc
+
+if ($MTR_COMBINATION_DESC) {
+ let $AUTO_INCREMENT_KEY_a= AUTO_INCREMENT, PRIMARY KEY(a DESC);
+ let $AUTO_INCREMENT_KEY_b= AUTO_INCREMENT, INDEX(b DESC);
+ let $AUTO_INCREMENT_PRIMARY_KEY_a= AUTO_INCREMENT, PRIMARY KEY(a DESC);
+ let $AUTO_INCREMENT_PRIMARY_KEY_b= AUTO_INCREMENT, ADD PRIMARY KEY(b DESC);
+}
+if (!$MTR_COMBINATION_DESC) {
+ let $AUTO_INCREMENT_KEY_a= AUTO_INCREMENT KEY;
+ let $AUTO_INCREMENT_KEY_b= AUTO_INCREMENT, KEY(b);
+ let $AUTO_INCREMENT_PRIMARY_KEY_a= AUTO_INCREMENT PRIMARY KEY;
+ let $AUTO_INCREMENT_PRIMARY_KEY_b= AUTO_INCREMENT PRIMARY KEY;
+}
+
+--echo #
+--echo # MDEV-6076 Persistent AUTO_INCREMENT for InnoDB
+--echo #
+--echo # WL#6204 InnoDB persistent max value for autoinc columns
+--echo #
+--echo # Most of this test case is copied from the test innodb.autoinc_persist
+--echo # that was introduced in MySQL 8.0.0. The observable behaviour
+--echo # of MDEV-6076 is equivalent to WL#6204, with the exception that
+--echo # there is less buffering taking place and redo log checkpoints
+--echo # are not being treated specially.
+--echo # Due to less buffering, there is no debug instrumentation testing
+--echo # for MDEV-6076.
+--echo #
+
+--echo # Pre-create several tables
+
+SET SQL_MODE='STRICT_ALL_TABLES';
+
+eval CREATE TABLE t1(a TINYINT $AUTO_INCREMENT_KEY_a) ENGINE = InnoDB;
+INSERT INTO t1 VALUES(0), (0), (0), (0), (-1), (-10), (0),
+(20), (30), (31);
+SELECT * FROM t1;
+
+eval CREATE TABLE t2(a TINYINT UNSIGNED $AUTO_INCREMENT_KEY_a) ENGINE = InnoDB;
+--error ER_WARN_DATA_OUT_OF_RANGE
+INSERT INTO t2 VALUES(-5);
+INSERT INTO t2 VALUES(0), (0), (0), (0), (8), (10), (0),
+(20), (30), (31);
+SELECT * FROM t2;
+
+eval CREATE TABLE t3(a SMALLINT $AUTO_INCREMENT_KEY_a) ENGINE = InnoDB;
+INSERT INTO t3 VALUES(0), (0), (0), (0), (-1), (-10), (0),
+(20), (30), (31), (1024), (4096);
+SELECT * FROM t3;
+
+eval CREATE TABLE t4(a SMALLINT UNSIGNED $AUTO_INCREMENT_KEY_a) ENGINE = InnoDB;
+--error ER_WARN_DATA_OUT_OF_RANGE
+INSERT INTO t4 VALUES(-5);
+INSERT INTO t4 VALUES(0), (0), (0), (0), (8), (10), (0),
+(20), (30), (31), (1024), (4096);
+SELECT * FROM t4;
+
+eval CREATE TABLE t5(a MEDIUMINT $AUTO_INCREMENT_KEY_a) ENGINE = InnoDB;
+INSERT INTO t5 VALUES(0), (0), (0), (0), (-1), (-10), (0),
+(20), (30), (31), (1000000), (1000005);
+SELECT * FROM t5;
+
+eval CREATE TABLE t6(a MEDIUMINT UNSIGNED $AUTO_INCREMENT_KEY_a) ENGINE = InnoDB;
+--error ER_WARN_DATA_OUT_OF_RANGE
+INSERT INTO t6 VALUES(-5);
+INSERT INTO t6 VALUES(0), (0), (0), (0), (8), (10), (0),
+(20), (30), (31), (1000000), (1000005);
+SELECT * FROM t6;
+
+eval CREATE TABLE t7(a INT $AUTO_INCREMENT_KEY_a) ENGINE = InnoDB;
+INSERT INTO t7 VALUES(0), (0), (0), (0), (-1), (-10), (0),
+(20), (30), (31), (100000000), (100000008);
+SELECT * FROM t7;
+
+eval CREATE TABLE t8(a INT UNSIGNED $AUTO_INCREMENT_KEY_a) ENGINE = InnoDB;
+--error ER_WARN_DATA_OUT_OF_RANGE
+INSERT INTO t8 VALUES(-5);
+INSERT INTO t8 VALUES(0), (0), (0), (0), (8), (10), (0),
+(20), (30), (31), (100000000), (100000008);
+SELECT * FROM t8;
+
+eval CREATE TABLE t9(a BIGINT $AUTO_INCREMENT_KEY_a) ENGINE = InnoDB;
+INSERT INTO t9 VALUES(0), (0), (0), (0), (-1), (-10), (0),
+(20), (30), (31), (100000000000), (100000000006);
+SELECT * FROM t9;
+
+eval CREATE TABLE t10(a BIGINT UNSIGNED $AUTO_INCREMENT_KEY_a) ENGINE = InnoDB;
+--error ER_WARN_DATA_OUT_OF_RANGE
+INSERT INTO t10 VALUES(-5);
+INSERT INTO t10 VALUES(0), (0), (0), (0), (8), (10), (0),
+(20), (30), (31), (100000000000), (100000000006);
+SELECT * FROM t10;
+
+eval CREATE TABLE t11(a FLOAT $AUTO_INCREMENT_KEY_a) ENGINE = InnoDB;
+INSERT INTO t11 VALUES(0), (0), (0), (0), (-1), (-10), (0),
+(20), (30), (31);
+SELECT * FROM t11;
+
+eval CREATE TABLE t12(a DOUBLE $AUTO_INCREMENT_KEY_a) ENGINE = InnoDB;
+INSERT INTO t12 VALUES(0), (0), (0), (0), (-1), (-10), (0),
+(20), (30), (31);
+SELECT * FROM t12;
+
+--echo # Scenario 1: Normal restart, to test if the counters are persisted
+--echo # Scenario 2: Delete some values, to test the counters should not be the
+--echo # one which is the largest in current table
+
+DELETE FROM t1 WHERE a > 30;
+SELECT MAX(a) AS `Expect 30` FROM t1;
+DELETE FROM t3 WHERE a > 2000;
+SELECT MAX(a) AS `Expect 2000` FROM t3;
+DELETE FROM t5 WHERE a > 1000000;
+SELECT MAX(a) AS `Expect 1000000` FROM t5;
+DELETE FROM t7 WHERE a > 100000000;
+SELECT MAX(a) AS `Expect 100000000` FROM t7;
+DELETE FROM t9 WHERE a > 100000000000;
+SELECT MAX(a) AS `Expect 100000000000` FROM t9;
+
+eval CREATE TABLE t13(a INT $AUTO_INCREMENT_KEY_a) ENGINE = InnoDB,
+AUTO_INCREMENT = 1234;
+
+--source include/restart_mysqld.inc
+
+SHOW CREATE TABLE t13;
+INSERT INTO t13 VALUES(0);
+SELECT a AS `Expect 1234` FROM t13;
+DROP TABLE t13;
+
+INSERT INTO t1 VALUES(0), (0);
+SELECT MAX(a) AS `Expect 33` FROM t1;
+INSERT INTO t3 VALUES(0), (0);
+SELECT MAX(a) AS `Expect 4098` FROM t3;
+INSERT INTO t5 VALUES(0), (0);
+SELECT MAX(a) AS `Expect 1000007` FROM t5;
+INSERT INTO t7 VALUES(0), (0);
+SELECT MAX(a) AS `Expect 100000010` FROM t7;
+INSERT INTO t9 VALUES(0), (0);
+SELECT MAX(a) AS `Expect 100000000008` FROM t9;
+
+--echo # Scenario 3: Insert some bigger counters, the next counter should start
+--echo # from there
+
+INSERT INTO t1 VALUES(40), (0);
+INSERT INTO t1 VALUES(42), (0);
+SELECT a AS `Expect 43, 42` FROM t1 ORDER BY a DESC LIMIT 4;
+INSERT INTO t3 VALUES(5000), (0);
+INSERT INTO t3 VALUES(5010), (0);
+SELECT a AS `Expect 5011, 5010` FROM t3 ORDER BY a DESC LIMIT 4;
+INSERT INTO t5 VALUES(1000010), (0);
+INSERT INTO t5 VALUES(1000020), (0);
+SELECT a AS `Expect 1000021, 1000020` FROM t5 ORDER BY a DESC LIMIT 4;
+INSERT INTO t7 VALUES(100000020), (0);
+INSERT INTO t7 VALUES(100000030), (0);
+SELECT a AS `Expect 100000031, 100000030` FROM t7 ORDER BY a DESC LIMIT 4;
+INSERT INTO t9 VALUES(100000000010), (0);
+INSERT INTO t9 VALUES(100000000020), (0);
+SELECT a AS `Expect 100000000021, 100000000020` FROM t9 ORDER BY a DESC LIMIT 4;
+
+--echo # Scenario 4: Update some values, to test the counters should be updated
+--echo # to the bigger value, but not smaller value.
+
+INSERT INTO t1 VALUES(50), (55);
+# Updating to bigger value will update the auto-increment counter
+UPDATE t1 SET a = 105 WHERE a = 5;
+# Updating to smaller value will not update the counter
+UPDATE t1 SET a = 100 WHERE a = 55;
+--echo # This should insert 102, 106, 107, and make next counter 109.
+INSERT INTO t1 VALUES(102), (0), (0);
+SELECT a AS `Expect 107, 106` FROM t1 ORDER BY a DESC LIMIT 2;
+DELETE FROM t1 WHERE a > 105;
+INSERT INTO t1 VALUES(0);
+SELECT MAX(a) AS `Expect 109` FROM t1;
+
+--echo # Test the same things on t3, t5, t7, t9, to test if DDTableBuffer would
+--echo # be updated accordingly
+
+INSERT INTO t3 VALUES(60), (65);
+# Updating to bigger value will update the auto-increment counter
+UPDATE t3 SET a = 6005 WHERE a = 5;
+# Updating to smaller value will not update the counter
+UPDATE t3 SET a = 6000 WHERE a = 60;
+--echo # This should insert 6002, 6006, 6007, and make next counter 6009.
+INSERT INTO t3 VALUES(6002), (0), (0);
+SELECT a AS `Expect 6007, 6006` FROM t3 ORDER BY a DESC LIMIT 2;
+DELETE FROM t3 WHERE a > 6005;
+INSERT INTO t3 VALUES(0);
+SELECT MAX(a) AS `Expect 6009` FROM t3;
+
+INSERT INTO t5 VALUES(100), (200);
+# Updating to bigger value will update the auto-increment counter
+UPDATE t5 SET a = 1000105 WHERE a = 5;
+# Updating to smaller value will not update the counter
+UPDATE t5 SET a = 1000100 WHERE a = 100;
+--echo # This should insert 1000102, 1000106, 1000107, and make next counter
+--echo # 1000109.
+INSERT INTO t5 VALUES(1000102), (0), (0);
+SELECT a AS `Expect 1000107, 1000106` FROM t5 ORDER BY a DESC LIMIT 2;
+DELETE FROM t5 WHERE a > 1000105;
+INSERT INTO t5 VALUES(0);
+SELECT MAX(a) AS `Expect 1000109` FROM t5;
+
+INSERT INTO t7 VALUES(100), (200);
+# Updating to bigger value will update the auto-increment counter
+UPDATE t7 SET a = 100000105 WHERE a = 5;
+# Updating to smaller value will not update the counter
+UPDATE t7 SET a = 100000100 WHERE a = 100;
+--echo # This should insert 100000102, 1100000106, 100000107, and make next
+--echo # counter 100000109.
+INSERT INTO t7 VALUES(100000102), (0), (0);
+SELECT a AS `Expect 100000107, 100000106` FROM t7 ORDER BY a DESC LIMIT 2;
+DELETE FROM t7 WHERE a > 100000105;
+INSERT INTO t7 VALUES(0);
+SELECT MAX(a) AS `Expect 100000109` FROM t7;
+
+INSERT INTO t9 VALUES(100), (200);
+# Updating to bigger value will update the auto-increment counter
+UPDATE t9 SET a = 100000000105 WHERE a = 5;
+# Updating to smaller value will not update the counter
+UPDATE t9 SET a = 100000000100 WHERE a = 100;
+--echo # This should insert 100000000102, 100000000106, 100000000107, and make
+--echo # next counter 100000000109.
+INSERT INTO t9 VALUES(100000000102), (0), (0);
+SELECT a AS `Expect 100000000107, 100000000106` FROM t9 ORDER BY a DESC LIMIT 2;
+DELETE FROM t9 WHERE a > 100000000105;
+INSERT INTO t9 VALUES(0);
+SELECT MAX(a) AS `Expect 100000000109` FROM t9;
+
+--source include/restart_mysqld.inc
+
+INSERT INTO t1 VALUES(0), (0);
+SELECT a AS `Expect 110, 111` FROM t1 ORDER BY a DESC LIMIT 2;
+
+INSERT INTO t3 VALUES(0), (0);
+SELECT a AS `Expect 6010, 6011` FROM t3 ORDER BY a DESC LIMIT 2;
+
+INSERT INTO t5 VALUES(0), (0);
+SELECT a AS `Expect 1100111, 1100110` FROM t5 ORDER BY a DESC LIMIT 2;
+
+INSERT INTO t7 VALUES(0), (0);
+SELECT a AS `Expect 100000111, 100000110` FROM t7 ORDER BY a DESC LIMIT 2;
+
+INSERT INTO t9 VALUES(0), (0);
+SELECT a AS `Expect 100000000111, 100000000110` FROM t9 ORDER BY a DESC LIMIT 2;
+
+--echo # Scenario 5: Test kill the server
+
+INSERT INTO t1 VALUES(125);
+DELETE FROM t1 WHERE a = 125;
+
+INSERT INTO t3 VALUES(6100);
+DELETE FROM t3 WHERE a = 6100;
+
+INSERT INTO t5 VALUES(1100200);
+DELETE FROM t5 WHERE a = 1100200;
+
+INSERT INTO t7 VALUES(100000200);
+DELETE FROM t7 WHERE a = 100000200;
+
+--echo # Ensure that all changes before the server is killed are persisted.
+set global innodb_flush_log_at_trx_commit=1;
+
+INSERT INTO t9 VALUES(100000000200);
+DELETE FROM t9 WHERE a = 100000000200;
+
+--let $shutdown_timeout=0
+--source include/restart_mysqld.inc
+
+INSERT INTO t1 VALUES(0);
+SELECT a AS `Expect 126` FROM t1 ORDER BY a DESC LIMIT 1;
+
+INSERT INTO t3 VALUES(0);
+SELECT a AS `Expect 6101` FROM t3 ORDER BY a DESC LIMIT 1;
+
+INSERT INTO t5 VALUES(0);
+SELECT a AS `Expect 1100201` FROM t5 ORDER BY a DESC LIMIT 1;
+
+INSERT INTO t7 VALUES(0);
+SELECT a AS `Expect 100000201` FROM t7 ORDER BY a DESC LIMIT 1;
+
+INSERT INTO t9 VALUES(0);
+SELECT a AS `Expect 100000000201` FROM t9 ORDER BY a DESC LIMIT 1;
+
+--echo # Scenario 6: Test truncate will reset the counters to 0
+
+TRUNCATE TABLE t1;
+TRUNCATE TABLE t3;
+TRUNCATE TABLE t5;
+TRUNCATE TABLE t7;
+TRUNCATE TABLE t9;
+
+INSERT INTO t1 VALUES(0), (0);
+SELECT * FROM t1;
+
+INSERT INTO t3 VALUES(0), (0);
+SELECT * FROM t3;
+
+INSERT INTO t5 VALUES(0), (0);
+SELECT * FROM t5;
+
+INSERT INTO t7 VALUES(0), (0);
+SELECT * FROM t7;
+
+INSERT INTO t9 VALUES(0), (0);
+SELECT * FROM t9;
+
+--echo # Ensure that all changes before the server is killed are persisted.
+set global innodb_flush_log_at_trx_commit=1;
+
+TRUNCATE TABLE t1;
+TRUNCATE TABLE t3;
+TRUNCATE TABLE t5;
+TRUNCATE TABLE t7;
+TRUNCATE TABLE t9;
+
+--echo # Scenario 7: Test explicit rename table won't change the counter
+
+RENAME TABLE t9 to t19;
+INSERT INTO t19 VALUES(0), (0);
+SELECT * FROM t19;
+
+--source include/restart_mysqld.inc
+
+INSERT INTO t1 VALUES(0), (0);
+SELECT * FROM t1;
+
+INSERT INTO t3 VALUES(0), (0);
+SELECT * FROM t3;
+
+INSERT INTO t5 VALUES(0), (0);
+SELECT * FROM t5;
+
+INSERT INTO t7 VALUES(0), (0);
+SELECT * FROM t7;
+
+INSERT INTO t19 VALUES(0), (0);
+SELECT * FROM t19;
+DELETE FROM t19 WHERE a = 4;
+
+RENAME TABLE t19 to t9;
+INSERT INTO t9 VALUES(0), (0);
+SELECT * FROM t9;
+
+TRUNCATE TABLE t9;
+
+INSERT INTO t9 VALUES(0), (0);
+SELECT * FROM t9;
+
+--echo # Scenario 8: Test ALTER TABLE operations
+
+INSERT INTO t3 VALUES(0), (0), (100), (200), (1000);
+SELECT * FROM t3;
+DELETE FROM t3 WHERE a > 300;
+SELECT MAX(a) AS `Expect 200` FROM t3;
+--echo # This will not change the counter to 150, but to 201, which is the next
+--echo # of current max counter in the table
+ALTER TABLE t3 AUTO_INCREMENT = 150;
+SHOW CREATE TABLE t3;
+INSERT INTO t3 VALUES(0);
+SELECT MAX(a) AS `Expect 201` FROM t3;
+--echo # This will change the counter to 500, which is bigger than any counter
+--echo # in the table
+ALTER TABLE t3 AUTO_INCREMENT = 500;
+SHOW CREATE TABLE t3;
+INSERT INTO t3 VALUES(0);
+SELECT MAX(a) AS `Expect 500` FROM t3;
+
+TRUNCATE TABLE t3;
+ALTER TABLE t3 AUTO_INCREMENT = 100;
+SHOW CREATE TABLE t3;
+INSERT INTO t3 VALUES(0), (0);
+SELECT * FROM t3;
+
+INSERT INTO t3 VALUES(150), (180);
+UPDATE t3 SET a = 200 WHERE a = 150;
+INSERT INTO t3 VALUES(220);
+--echo # This still fails to set to 120, but just 221
+ALTER TABLE t3 AUTO_INCREMENT = 120;
+SHOW CREATE TABLE t3;
+INSERT INTO t3 VALUES(0);
+SELECT MAX(a) AS `Expect 221` FROM t3;
+
+DELETE FROM t3 WHERE a > 120;
+
+ALTER TABLE t3 AUTO_INCREMENT = 120;
+SHOW CREATE TABLE t3;
+
+--echo # MDEV-6076: Test adding an AUTO_INCREMENT COLUMN
+CREATE TABLE mdev6076a (b INT) ENGINE=InnoDB;
+INSERT INTO mdev6076a VALUES(2),(1);
+CREATE TABLE mdev6076b (b INT) ENGINE=InnoDB;
+INSERT INTO mdev6076b VALUES(2),(1);
+--error ER_ALTER_OPERATION_NOT_SUPPORTED_REASON
+ALTER TABLE mdev6076a ADD COLUMN a SERIAL FIRST, LOCK=NONE;
+ALTER TABLE mdev6076a ADD COLUMN a SERIAL FIRST, ALGORITHM=INPLACE;
+ALTER TABLE mdev6076b ADD COLUMN a SERIAL FIRST, AUTO_INCREMENT=100,
+ALGORITHM=INPLACE;
+--echo # MDEV-6076: Test root page split and page_create_empty()
+CREATE TABLE mdev6076empty (b SERIAL, pad CHAR(255) NOT NULL DEFAULT '')
+ENGINE=InnoDB;
+BEGIN;
+--echo # Insert records in descending order of AUTO_INCREMENT,
+--echo # causing a page split on the very last insert.
+--echo # Without the fix in btr_page_empty() this would lose the counter value.
+--echo # Without the fix in page_create_empty() the counter value would be lost
+--echo # when ROLLBACK deletes the last row.
+--disable_query_log
+let $i= 55;
+while ($i) {
+ eval INSERT INTO mdev6076empty SET b=$i;
+ dec $i;
+}
+--enable_query_log
+ROLLBACK;
+
+--source include/restart_mysqld.inc
+
+INSERT INTO t3 VALUES(0);
+SELECT MAX(a) AS `Expect 120` FROM t3;
+
+INSERT INTO mdev6076a SET b=NULL;
+SELECT * FROM mdev6076a;
+INSERT INTO mdev6076b SET b=NULL;
+SELECT * FROM mdev6076b;
+# MDEV-515 resets the PAGE_ROOT_AUTOINC field in
+# root page during rollback.
+--disable_query_log
+BEGIN;
+let $i = 55;
+WHILE ($i) {
+ eval INSERT INTO mdev6076empty SET b=$i;
+ dec $i;
+}
+ROLLBACK;
+--enable_query_log
+INSERT INTO mdev6076empty SET b=NULL;
+SELECT * FROM mdev6076empty;
+DROP TABLE mdev6076a, mdev6076b, mdev6076empty;
+
+INSERT INTO t3 VALUES(0), (0), (200), (210);
+
+--echo # Test the different algorithms in ALTER TABLE
+
+--let $template = t3
+--let $algorithm = INPLACE
+--let $table = t_inplace
+--source suite/innodb/include/autoinc_persist_alter.inc
+--let $algorithm = COPY
+--let $table = t_copy
+--source suite/innodb/include/autoinc_persist_alter.inc
+
+--echo # Scenario 9: Test the sql_mode = NO_AUTO_VALUE_ON_ZERO
+
+eval CREATE TABLE t30 (a INT NOT NULL $AUTO_INCREMENT_PRIMARY_KEY_a, b INT, key(b)) ENGINE = InnoDB;
+
+set SQL_MODE = NO_AUTO_VALUE_ON_ZERO;
+
+INSERT INTO t30 VALUES(NULL, 1), (200, 2), (0, 3);
+INSERT INTO t30(b) VALUES(4), (5), (6), (7);
+SELECT * FROM t30 ORDER BY b;
+ALTER TABLE t30 MODIFY b MEDIUMINT;
+SELECT * FROM t30 ORDER BY b;
+
+--echo # Ensure that all changes before the server is killed are persisted.
+set global innodb_flush_log_at_trx_commit=1;
+
+CREATE TABLE t31 (a INT) ENGINE = InnoDB;
+INSERT INTO t31 VALUES(1), (2);
+eval ALTER TABLE t31 ADD b INT $AUTO_INCREMENT_PRIMARY_KEY_b;
+INSERT INTO t31 VALUES(3, 0), (4, NULL), (5, NULL);
+--error ER_DUP_ENTRY
+INSERT INTO t31 VALUES(6, 0);
+SELECT * FROM t31;
+
+SET SQL_MODE = 0;
+
+--echo # Scenario 10: Rollback would not rollback the counter
+eval CREATE TABLE t32 (a BIGINT $AUTO_INCREMENT_PRIMARY_KEY_a) ENGINE=InnoDB;
+
+INSERT INTO t32 VALUES(0), (0);
+
+--echo # Ensure that all changes before the server is killed are persisted.
+set global innodb_flush_log_at_trx_commit=1;
+
+START TRANSACTION;
+INSERT INTO t32 VALUES(0), (0);
+SELECT MAX(a) AS `Expect 4` FROM t32;
+DELETE FROM t32 WHERE a >= 2;
+ROLLBACK;
+
+--echo # Scenario 11: Test duplicate primary key/secondary key will not stop
+--echo # increasing the counter
+
+eval CREATE TABLE t33 (
+a BIGINT NOT NULL PRIMARY KEY,
+b BIGINT NOT NULL $AUTO_INCREMENT_KEY_b) ENGINE = InnoDB;
+
+INSERT INTO t33 VALUES(1, NULL);
+INSERT INTO t33 VALUES(2, NULL);
+--error ER_DUP_ENTRY
+INSERT INTO t33 VALUES(2, NULL);
+
+INSERT INTO t33 VALUES(3, NULL);
+SELECT MAX(b) AS `Expect 4` FROM t33;
+
+TRUNCATE TABLE t33;
+
+INSERT INTO t33 VALUES(1, NULL);
+INSERT INTO t33 VALUES(2, NULL);
+
+set global innodb_flush_log_at_trx_commit=1;
+
+START TRANSACTION;
+UPDATE t33 SET a = 10 WHERE a = 1;
+--error ER_DUP_ENTRY
+INSERT INTO t33 VALUES(2, NULL);
+COMMIT;
+
+--source include/restart_mysqld.inc
+
+--echo # This will not insert 0
+INSERT INTO t31(a) VALUES(6), (0);
+SELECT * FROM t31;
+DROP TABLE t31;
+
+set SQL_MODE = NO_AUTO_VALUE_ON_ZERO;
+
+DELETE FROM t30 WHERE a = 0;
+UPDATE t30 set a = 0 where b = 5;
+SELECT * FROM t30 ORDER BY b;
+DELETE FROM t30 WHERE a = 0;
+
+UPDATE t30 SET a = NULL WHERE b = 6;
+UPDATE t30 SET a = 300 WHERE b = 7;
+
+SELECT * FROM t30 ORDER BY b;
+
+SET SQL_MODE = 0;
+
+SELECT MAX(a) AS `Expect 2` FROM t32;
+INSERT INTO t32 VALUES(0), (0);
+SELECT MAX(a) AS `Expect 6` FROM t32;
+
+FLUSH TABLES t33 FOR EXPORT;
+let MYSQLD_DATADIR=`select @@datadir`;
+perl;
+do "$ENV{MTR_SUITE_DIR}/include/innodb-util.pl";
+ib_backup_tablespaces("test", "t33");
+EOF
+UNLOCK TABLES;
+DROP TABLE t33;
+eval CREATE TABLE t33 (
+a BIGINT NOT NULL PRIMARY KEY,
+b BIGINT NOT NULL $AUTO_INCREMENT_KEY_b) ENGINE = InnoDB;
+ALTER TABLE t33 DISCARD TABLESPACE;
+perl;
+do "$ENV{MTR_SUITE_DIR}/include/innodb-util.pl";
+ib_discard_tablespaces("test", "t33");
+ib_restore_tablespaces("test", "t33");
+EOF
+ALTER TABLE t33 IMPORT TABLESPACE;
+
+INSERT INTO t33 VALUES(3, NULL);
+SELECT MAX(b) AS `Expect 4` FROM t33;
+SELECT * FROM t33;
+
+DROP TABLE t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t30, t32, t33;
diff --git a/mysql-test/suite/innodb/t/binlog_consistent.test b/mysql-test/suite/innodb/t/binlog_consistent.test
new file mode 100644
index 00000000..3b03d291
--- /dev/null
+++ b/mysql-test/suite/innodb/t/binlog_consistent.test
@@ -0,0 +1,126 @@
+--source include/have_innodb.inc
+--source include/have_log_bin.inc
+--source include/have_binlog_format_mixed_or_statement.inc
+--source include/binlog_start_pos.inc
+
+RESET MASTER;
+
+# Test that we get the correct binlog position from START TRANSACTION WITH
+# CONSISTENT SNAPSHOT even when other transactions are active.
+
+connect(con1,localhost,root,,);
+connect(con2,localhost,root,,);
+connect(con3,localhost,root,,);
+connect(con4,localhost,root,,);
+
+connection default;
+
+CREATE TABLE t1 (a INT, b VARCHAR(100), PRIMARY KEY (a,b)) ENGINE=innodb;
+# MDEV-515 takes X-lock on the table for the first insert.
+# So concurrent insert won't happen on the table
+INSERT INTO t1 VALUES(9, "");
+let pos=`select $binlog_start_pos + 431`;
+--replace_result $pos <pos>
+SHOW MASTER STATUS;
+--replace_result $pos <pos>
+SHOW STATUS LIKE 'binlog_snapshot_%';
+BEGIN;
+INSERT INTO t1 VALUES (0, "");
+
+connection con1;
+BEGIN;
+INSERT INTO t1 VALUES (1, "");
+
+connection con2;
+CREATE TABLE t2 (a INT PRIMARY KEY) ENGINE=myisam;
+BEGIN;
+INSERT INTO t1 VALUES (2, "first");
+INSERT INTO t2 VALUES (2);
+INSERT INTO t1 VALUES (2, "second");
+
+connection default;
+COMMIT;
+
+SET TRANSACTION ISOLATION LEVEL REPEATABLE READ;
+START TRANSACTION WITH CONSISTENT SNAPSHOT;
+
+connection con3;
+BEGIN;
+INSERT INTO t1 VALUES (3, "");
+INSERT INTO t2 VALUES (3);
+
+connection con4;
+BEGIN;
+INSERT INTO t1 VALUES (4, "");
+COMMIT;
+
+connection default;
+SELECT * FROM t1 ORDER BY a,b;
+let pos=`select $binlog_start_pos + 974`;
+--replace_result $pos <pos>
+SHOW STATUS LIKE 'binlog_snapshot_%';
+let pos=`select $binlog_start_pos + 1350`;
+--replace_result $pos <pos>
+SHOW MASTER STATUS;
+SELECT * FROM t2 ORDER BY a;
+
+connection con1;
+COMMIT;
+
+connection con2;
+COMMIT;
+
+connection con3;
+COMMIT;
+FLUSH LOGS;
+--source include/wait_for_binlog_checkpoint.inc
+
+connection default;
+SELECT * FROM t1 ORDER BY a,b;
+let pos=`select $binlog_start_pos + 974`;
+--replace_result $pos <pos>
+SHOW STATUS LIKE 'binlog_snapshot_%';
+let pos=`select $binlog_start_pos + 131`;
+--replace_result $pos <pos>
+SHOW MASTER STATUS;
+COMMIT;
+--replace_result $pos <pos>
+SHOW STATUS LIKE 'binlog_snapshot_%';
+--replace_result $pos <pos>
+SHOW MASTER STATUS;
+
+source include/show_binlog_events.inc;
+
+
+--echo *** MDEV-7310: last_commit_pos_offset set to wrong value after binlog rotate in group commit ***
+
+SET @old_size= @@GLOBAL.max_binlog_size;
+SET GLOBAL max_binlog_size=4096;
+
+CREATE TABLE t3 (a INT PRIMARY KEY, b VARBINARY(8192)) ENGINE=MyISAM;
+INSERT INTO t3 VALUES (10, '');
+--let $bigdata= `SELECT REPEAT('a', 5000)`
+eval INSERT INTO t3 VALUES (11, '$bigdata');
+
+# The bug was that binlog_snapshot_file pointed to the new file after binlog
+# rotation, but binlog_snapshot_position was the offset in the old file before
+# binlog rotation. So the position was invalid.
+# So here, we check that the values are consistent with SHOW MASTER STATUS,
+# which uses a different code path and did not have the bug.
+
+--source include/wait_for_binlog_checkpoint.inc
+--let $snap_file= query_get_value(SHOW STATUS LIKE 'binlog_snapshot_file', Value, 1)
+--let $snap_pos= query_get_value(SHOW STATUS LIKE 'binlog_snapshot_position', Value, 1)
+
+--let $master_file= query_get_value(SHOW MASTER STATUS, File, 1)
+--let $master_pos= query_get_value(SHOW MASTER STATUS, Position, 1)
+
+--disable_query_log
+eval SET @errmsg= 'ERROR: ($snap_file, $snap_pos) != ($master_file, $master_pos)';
+eval SELECT IF('$snap_file' = '$master_file' AND $snap_pos = $master_pos, 'OK', @errmsg) AS test_result;
+--enable_query_log
+
+SET GLOBAL max_binlog_size=@old_size;
+
+
+DROP TABLE t1,t2, t3;
diff --git a/mysql-test/suite/innodb/t/blob-crash.test b/mysql-test/suite/innodb/t/blob-crash.test
new file mode 100644
index 00000000..77787a34
--- /dev/null
+++ b/mysql-test/suite/innodb/t/blob-crash.test
@@ -0,0 +1,211 @@
+--source include/innodb_page_size_small.inc
+--source include/no_valgrind_without_big.inc
+
+let $have_debug_sync=`select count(*) = 1 from information_schema.session_variables where variable_name = 'debug_sync' and variable_value like 'on %'`;
+
+--echo #
+--echo # Bug #16963396 INNODB: USE OF LARGE EXTERNALLY-STORED FIELDS MAKES
+--echo # CRASH RECOVERY LOSE DATA
+--echo #
+
+# ..........................................................................
+
+--echo #
+--echo # Uncompressed Table - Insert Operation - Crash Test
+--echo # Fresh insert with blobs
+--echo #
+
+CREATE TABLE t1 (a BIGINT PRIMARY KEY, b LONGBLOB) ENGINE=InnoDB;
+
+# Insert a few rows (it doesn't really matter how many). These transactions
+# are committed once they are acked, so they should not be lost.
+INSERT INTO t1 (a, b) VALUES (1, repeat('^', 40000));
+INSERT INTO t1 (a, b) VALUES (2, '2');
+INSERT INTO t1 (a, b) VALUES (3, '3');
+INSERT INTO t1 (a, b) VALUES (4, '4');
+INSERT INTO t1 (a, b) VALUES (5, '5');
+
+# The BLOB insert will fail, and should disappear. However no data committed
+# up to this point should be lost.
+begin;
+INSERT INTO t1 (a, b) VALUES (6, REPEAT('a', 4*1024*1024));
+
+let $shutdown_timeout=0;
+let $restart_noprint=2;
+--source include/restart_mysqld.inc
+
+SELECT a, right(b, 50) FROM t1;
+
+# ..........................................................................
+
+--echo #
+--echo # Uncompressed Table - UPDATE Operation - Crash Test
+--echo # Update of non-blob column so that blob is needed.
+--echo #
+
+# The BLOB update will fail, and should disappear. However no data committed
+# up to this point should be lost.
+begin;
+UPDATE t1 set b = REPEAT('a', 4*1024*1024) where a = 5 ;
+
+let $shutdown_timeout=0;
+--source include/restart_mysqld.inc
+
+SELECT a, right(b, 50) FROM t1;
+
+# ..........................................................................
+
+--echo #
+--echo # Uncompressed Table - UPDATE Operation - Crash Test
+--echo # Update of blob column to blob.
+--echo #
+
+# The BLOB update will fail, and should disappear. However no data committed
+# up to this point should be lost.
+connect (con1,localhost,root,,);
+begin;
+UPDATE t1 set b = REPEAT('$', 50000) where a = 1;
+
+connection default;
+SET GLOBAL innodb_flush_log_at_trx_commit=1;
+UPDATE t1 SET b='five' WHERE a=5;
+
+let $shutdown_timeout=0;
+--source include/restart_mysqld.inc
+
+disconnect con1;
+
+SELECT a, right(b, 50) FROM t1;
+
+# ..........................................................................
+
+--echo #
+--echo # Uncompressed Table - Rollback of UPDATE operation
+--echo # Update moves offpage data to inline data.
+--echo #
+
+create table t2 (f1 bigint primary key, f2 longblob, f3 longblob,
+ index(f2(10), f3(10))) engine=innodb;
+
+insert into t2 values (10, repeat('.', 40000), repeat('?', 40000));
+
+connect (con1,localhost,root,,);
+begin;
+update t2 set f2 = '=';
+select f1, right(f2, 20), right(f3, 20) from t2;
+update t2 set f3 = '&';
+select f1, right(f2, 20), right(f3, 20) from t2;
+
+if ($have_debug_sync) {
+--disable_query_log
+set DEBUG_SYNC='blob_rollback_middle SIGNAL stuck WAIT_FOR ever';
+send ROLLBACK;
+--enable_query_log
+}
+
+connection default;
+if ($have_debug_sync) {
+--disable_query_log
+SET DEBUG_SYNC = 'now WAIT_FOR stuck';
+--enable_query_log
+}
+SET GLOBAL innodb_flush_log_at_trx_commit=1;
+DELETE FROM t1 WHERE a=1;
+
+let $shutdown_timeout=0;
+--source include/restart_mysqld.inc
+
+disconnect con1;
+
+select f1, right(f2, 20), right(f3, 20) from t2;
+check table t2;
+drop table t2;
+
+# ..........................................................................
+
+--echo #
+--echo # Compressed Table - Insert Operation - Crash Test
+--echo # fresh insert with BLOBs
+--echo #
+
+set global innodb_compression_level = 0;
+
+create table t3 (f1 bigint primary key, f2 longblob, f3 longblob,
+ index(f2(10), f3(10))) engine=innodb row_format=compressed;
+
+# The BLOB insert will fail, and should disappear. However no data committed
+# up to this point should be lost.
+connect (con1,localhost,root,,);
+begin;
+INSERT INTO t3 (f1, f2, f3) VALUES (6, repeat('/', 40000), repeat('<', 40000));
+
+connection default;
+SET GLOBAL innodb_flush_log_at_trx_commit=1;
+DELETE FROM t1 WHERE a=2;
+
+let $shutdown_timeout=0;
+--source include/restart_mysqld.inc
+
+disconnect con1;
+
+select f1, length(f2), length(f3) from t3;
+select f1, right(f2, 30), right(f3, 20) from t3;
+check table t3;
+
+# ..........................................................................
+
+--echo #
+--echo # Compressed Table - Update Operation - Crash Test
+--echo # update of a non-BLOB column so that BLOB is needed
+--echo #
+
+set global innodb_compression_level = 0;
+insert into t3 values (2, repeat('!', 30), repeat('+', 30));
+
+# The BLOB update will fail, and should disappear. However no data committed
+# up to this point should be lost.
+connect (con1,localhost,root,,);
+begin;
+UPDATE t3 set f2 = repeat('>', 40000) where f1 = 2;
+
+connection default;
+SET GLOBAL innodb_flush_log_at_trx_commit=1;
+DELETE FROM t1 WHERE a=3;
+
+let $shutdown_timeout=0;
+--source include/restart_mysqld.inc
+
+disconnect con1;
+
+select f1, length(f2), length(f3) from t3;
+select f1, right(f2, 30), right(f3, 20) from t3;
+check table t3;
+
+# ..........................................................................
+
+--echo #
+--echo # Compressed Table - Update Operation - Crash Test
+--echo # update blob to blob
+--echo #
+
+set global innodb_compression_level = 0;
+insert into t3 values (3, repeat('%', 40000), repeat('~', 40000));
+
+# The BLOB update will fail, and should disappear. However no data committed
+# up to this point should be lost.
+connect (con1,localhost,root,,);
+begin;
+UPDATE t3 set f2 = concat(f2, repeat(',', 10)) where f1 = 3;
+
+connection default;
+SET GLOBAL innodb_flush_log_at_trx_commit=1;
+DELETE FROM t1 WHERE a=4;
+
+let $shutdown_timeout=0;
+--source include/restart_mysqld.inc
+
+select f1, length(f2), length(f3) from t3;
+select f1, right(f2, 30), right(f3, 20) from t3;
+check table t3;
+
+DROP TABLE t1,t3;
diff --git a/mysql-test/suite/innodb/t/blob-update-debug.test b/mysql-test/suite/innodb/t/blob-update-debug.test
new file mode 100644
index 00000000..8d35dbfc
--- /dev/null
+++ b/mysql-test/suite/innodb/t/blob-update-debug.test
@@ -0,0 +1,19 @@
+# This file contains tests involving update operations on blob data type.
+
+--source include/have_innodb.inc
+--source include/have_debug.inc
+
+--echo #
+--echo # Bug#18185930 UPD_NODE_INSERT_BLOB CAUSES BTR_EXTERN_OWNER_FLAG
+--echo # ASSERTION
+--echo #
+
+create table t1 (f1 int primary key, f2 blob) engine = innodb;
+insert into t1 values (1, repeat('*', 50000));
+select f1, substring(f2, 1, 40) from t1;
+set @saved_debug = @@session.debug_dbug;
+SET debug_dbug = 'd,row_ins_index_entry_timeout';
+update t1 set f1 = 3;
+select f1, substring(f2, 1, 40) from t1;
+drop table t1;
+SET debug_dbug= @saved_debug;
diff --git a/mysql-test/suite/innodb/t/blob_cmp_empty.test b/mysql-test/suite/innodb/t/blob_cmp_empty.test
new file mode 100644
index 00000000..f41ac79b
--- /dev/null
+++ b/mysql-test/suite/innodb/t/blob_cmp_empty.test
@@ -0,0 +1,26 @@
+--source include/innodb_row_format.inc
+--source include/count_sessions.inc
+--connect(prevent_purge,localhost,root,,)
+start transaction with consistent snapshot;
+
+--connection default
+SET @fill_amount = (@@innodb_page_size / 2 ) + 1;
+CREATE TABLE t1 (col_text TEXT NOT NULL, KEY (col_text(9))) ENGINE=InnoDB;
+
+INSERT INTO t1 (col_text) VALUES (REPEAT('x', @fill_amount));
+UPDATE t1 SET col_text='';
+UPDATE t1 SET col_text=REPEAT('y', @fill_amount);
+
+--connect(con1,localhost,root,,)
+SET @fill_amount = (@@innodb_page_size / 2 ) + 1;
+BEGIN;
+INSERT INTO t1 (col_text) VALUES (REPEAT('z', @fill_amount));
+
+--connection default
+# If the bug is not fixed, CHECK TABLE will complain about wrong secondary index
+# rows count
+CHECK TABLE t1;
+--disconnect con1
+--disconnect prevent_purge
+DROP TABLE t1;
+--source include/wait_until_count_sessions.inc
diff --git a/mysql-test/suite/innodb/t/blob_unique2pk.test b/mysql-test/suite/innodb/t/blob_unique2pk.test
new file mode 100644
index 00000000..ff672069
--- /dev/null
+++ b/mysql-test/suite/innodb/t/blob_unique2pk.test
@@ -0,0 +1,20 @@
+--source include/have_innodb.inc
+
+
+#
+# Bug#16368875 INNODB: FAILING ASSERTION: PRIMARY_KEY_NO == -1 || PRIMARY_KEY_NO == 0
+#
+create table t1 (f1 tinyblob not null) engine=innodb;
+alter table t1 add unique index (f1(255));
+drop table t1;
+
+create table t1 (f1 tinyblob not null) engine=innodb;
+alter table t1 add unique index (f1(356));
+show create table t1;
+drop table t1;
+
+create table t1 (f1 point not null) engine=innodb;
+alter table t1 add unique index (f1);
+drop table t1;
+
+
diff --git a/mysql-test/suite/innodb/t/buf_pool_resize_oom.opt b/mysql-test/suite/innodb/t/buf_pool_resize_oom.opt
new file mode 100644
index 00000000..09fd8bd8
--- /dev/null
+++ b/mysql-test/suite/innodb/t/buf_pool_resize_oom.opt
@@ -0,0 +1 @@
+--innodb-buffer-pool-size=8m --innodb-buffer-pool-chunk-size=1m
diff --git a/mysql-test/suite/innodb/t/buf_pool_resize_oom.test b/mysql-test/suite/innodb/t/buf_pool_resize_oom.test
new file mode 100644
index 00000000..ea13129e
--- /dev/null
+++ b/mysql-test/suite/innodb/t/buf_pool_resize_oom.test
@@ -0,0 +1,27 @@
+--source include/have_innodb.inc
+--source include/have_debug.inc
+--source include/not_embedded.inc
+
+--echo #
+--echo # Bug #21348684 SIGABRT DURING RESIZING THE INNODB BUFFER POOL
+--echo # ONLINE WITH MEMORY FULL CONDITION
+--echo #
+
+call mtr.add_suppression("InnoDB: failed to allocate the chunk array");
+
+SET GLOBAL debug_dbug='+d,buf_pool_resize_chunk_null';
+
+--disable_warnings
+SET GLOBAL innodb_buffer_pool_size=@@innodb_buffer_pool_size + 1048576;
+--enable_warnings
+
+let $wait_timeout = 60;
+let $wait_condition =
+ SELECT SUBSTR(variable_value, 1, 27) = 'Resizing buffer pool failed'
+ FROM information_schema.global_status
+ WHERE variable_name = 'INNODB_BUFFER_POOL_RESIZE_STATUS';
+
+--source include/wait_condition.inc
+# Restart the server, because the buffer pool would not necessarily be
+# shrunk afterwards even if we request it.
+--source include/restart_mysqld.inc
diff --git a/mysql-test/suite/innodb/t/change_column_collation.test b/mysql-test/suite/innodb/t/change_column_collation.test
new file mode 100644
index 00000000..edc298fe
--- /dev/null
+++ b/mysql-test/suite/innodb/t/change_column_collation.test
@@ -0,0 +1,156 @@
+--source include/have_innodb.inc
+--source include/have_debug.inc
+--source include/have_debug_sync.inc
+
+--source include/count_sessions.inc
+
+--echo #
+--echo # MDEV-26294 Duplicate entries in unique index not detected when
+--echo # changing collation with INPLACE algorithm
+--echo #
+
+# Detect the duplicate entry after collation change of column
+
+SET NAMES utf8;
+CREATE TABLE t1 (
+ id INT PRIMARY KEY,
+ msg VARCHAR(100) CHARACTER SET utf8 COLLATE utf8_swedish_ci UNIQUE
+) ENGINE=INNODB;
+INSERT INTO t1 VALUES (1, 'aaa');
+INSERT INTO t1 VALUES (2, 'ååå');
+--error ER_DUP_ENTRY
+ALTER TABLE t1 MODIFY msg VARCHAR(100) CHARACTER SET utf8 COLLATE utf8_unicode_ci, ALGORITHM=inplace;
+DROP TABLE t1;
+
+# PageBulk insert shouldn't fail like records are not in ascending order
+
+CREATE TABLE t1 (
+ id INT PRIMARY KEY,
+ msg VARCHAR(100) CHARACTER SET utf8 COLLATE utf8_bin,
+ id_2 INT not null,
+ unique index(msg, id_2)
+) ENGINE=INNODB;
+
+INSERT INTO t1 VALUES (1, 'aaa', 2);
+INSERT INTO t1 VALUES (2, 'AAA', 3);
+
+ALTER TABLE t1 MODIFY msg VARCHAR(100) CHARACTER SET utf8 COLLATE utf8_unicode_ci, ALGORITHM=inplace;
+
+DROP TABLE t1;
+
+# Detect the duplicate entry from concurrent DML
+
+CREATE TABLE t1 (
+ id INT PRIMARY KEY,
+ msg VARCHAR(100) CHARACTER SET utf8 COLLATE utf8_bin,
+ unique index(msg)
+) ENGINE=INNODB;
+
+INSERT INTO t1 VALUES (1, 'aaa');
+INSERT INTO t1 VALUES (2, 'bbb');
+INSERT INTO t1 VALUES (3, 'ccc');
+
+SET DEBUG_SYNC = 'RESET';
+SET DEBUG_SYNC = 'row_log_apply_before SIGNAL before_apply WAIT_FOR go_ahead';
+--send
+ALTER TABLE t1 MODIFY msg VARCHAR(100) CHARACTER SET utf8 COLLATE utf8_unicode_ci, ALGORITHM=NOCOPY;
+
+connect (con1,localhost,root,,);
+connection con1;
+
+SET DEBUG_SYNC = 'now WAIT_FOR before_apply';
+INSERT INTO t1 VALUES (4, 'AAA');
+UPDATE t1 set msg = "ddd" where id = 2;
+DELETE FROM t1 WHERE id= 3;
+SET DEBUG_SYNC = 'now SIGNAL go_ahead';
+
+connection default;
+
+--error ER_DUP_ENTRY
+reap;
+
+SET DEBUG_SYNC = 'RESET';
+SELECT * FROM t1;
+DROP TABLE t1;
+
+# InnoDB should store the changed collation column into
+# change_col_info in index when rollback of alter happens
+
+CREATE TABLE t1 (
+ id INT PRIMARY KEY,
+ f1 INT NOT NULL,
+ f2 INT NOT NULL,
+ f3 INT NOT NULL,
+ msg VARCHAR(100) CHARACTER SET utf8 COLLATE utf8_bin,
+ msg_1 VARCHAR(100) CHARACTER SET utf8 COLLATE utf8_bin,
+ unique index(f1, msg, f2, msg_1, f3),
+ unique index(f1, msg_1, f2, msg, f3),
+ unique index(f1, msg, f3, msg_1, f2),
+ unique index(f1, msg_1, f3, msg, f2),
+ unique index(f2, msg_1, f1, msg, f3),
+ unique index(f2, msg, f3, msg_1, f1),
+ unique index(f3, f2, msg, msg_1, f1),
+ unique index(f3, msg, msg_1, f1, f2)
+) ENGINE=INNODB;
+
+INSERT INTO t1 VALUES (1, 1, 1, 1, 'aaa', 'aaa');
+SET DEBUG_DBUG="+d,create_index_fail";
+SET DEBUG_SYNC="innodb_inplace_alter_table_enter SIGNAL con1_go WAIT_FOR alter_signal";
+--send
+ALTER TABLE t1 MODIFY msg VARCHAR(100) CHARACTER SET utf8 COLLATE utf8_unicode_ci, MODIFY msg_1 VARCHAR(100) CHARACTER SET utf8 COLLATE utf8_unicode_ci, ALGORITHM=NOCOPY;
+
+connection con1;
+SET DEBUG_SYNC="now WAIT_FOR con1_go";
+BEGIN;
+SELECT * FROM t1;
+SET DEBUG_SYNC="now SIGNAL alter_signal";
+connection default;
+--error ER_DUP_ENTRY
+reap;
+CHECK TABLE t1;
+connection con1;
+rollback;
+INSERT INTO t1 VALUES(2, 2, 2, 2, 'bbb', 'bbb');
+disconnect con1;
+connection default;
+SET DEBUG_SYNC=reset;
+SHOW CREATE TABLE t1;
+INSERT INTO t1 VALUES(3, 3, 3, 3, 'ccc', 'ccc');
+DROP TABLE t1;
+
+# Inplace Collation change is not supported for virtual column
+# and stored column
+
+CREATE TABLE t1(id INT PRIMARY KEY, msg VARCHAR(100),
+ msg_1 VARCHAR(100) AS (msg) VIRTUAL,
+ msg_2 VARCHAR(100) AS (msg) STORED,
+ UNIQUE(msg), UNIQUE(msg_1),
+ UNIQUE(msg_2))ENGINE=InnoDB;
+--error ER_UNSUPPORTED_ACTION_ON_GENERATED_COLUMN
+ALTER TABLE t1 MODIFY msg_1 VARCHAR(100) CHARACTER SET utf8
+ COLLATE utf8_unicode_ci, ALGORITHM=inplace;
+--error ER_ALTER_OPERATION_NOT_SUPPORTED_REASON
+ALTER TABLE t1 MODIFY msg_2 VARCHAR(100) CHARACTER SET utf8
+ COLLATE utf8_unicode_ci, ALGORITHM=inplace;
+DROP TABLE t1;
+
+--echo #
+--echo # MDEV-29314 Assertion `n_fields > n_cols' failed
+--echo # in dict_index_t::init_change_cols
+--echo #
+CREATE TABLE t (a VARCHAR(16) COLLATE utf8_bin,
+ FULLTEXT (a)) ENGINE=InnoDB COLLATE utf8_unicode_520_ci;
+ALTER TABLE t MODIFY COLUMN a VARCHAR(512);
+SHOW CREATE TABLE t;
+DROP TABLE t;
+
+--echo #
+--echo # MDEV-31416 ASAN errors in dict_v_col_t::detach upon
+--echo # adding key to virtual column
+--echo #
+CREATE TABLE t (a INT) ENGINE=InnoDB WITH SYSTEM VERSIONING;
+SET SYSTEM_VERSIONING_ALTER_HISTORY= KEEP;
+ALTER TABLE t ADD COLUMN v VARCHAR(128) GENERATED ALWAYS AS (CRC32('MariaDB'));
+ALTER TABLE t ADD INDEX (v);
+DROP TABLE t;
+--source include/wait_until_count_sessions.inc
diff --git a/mysql-test/suite/innodb/t/check_ibd_filesize.test b/mysql-test/suite/innodb/t/check_ibd_filesize.test
new file mode 100644
index 00000000..b6ab95e1
--- /dev/null
+++ b/mysql-test/suite/innodb/t/check_ibd_filesize.test
@@ -0,0 +1,59 @@
+--source include/innodb_page_size.inc
+--source include/have_sequence.inc
+
+--echo #
+--echo # Bug #21950389 SMALL TABLESPACES WITH BLOBS TAKE UP TO 80 TIMES MORE
+--echo # SPACE IN 5.7 THAN IN 5.6
+--echo #
+
+#
+# Table 1: small rows
+#
+CREATE TABLE t1 (a INT PRIMARY KEY) ENGINE=InnoDB;
+let MYSQLD_DATADIR=`select @@datadir`;
+perl;
+print "# bytes: ", (-s "$ENV{MYSQLD_DATADIR}/test/t1.ibd"), "\n";
+EOF
+
+INSERT INTO t1 SELECT * FROM seq_1_to_25000;
+perl;
+print "# bytes: ", (-s "$ENV{MYSQLD_DATADIR}/test/t1.ibd"), "\n";
+EOF
+DROP TABLE t1;
+
+#
+# Table 2: BLOB
+#
+CREATE TABLE t1 (a INT PRIMARY KEY, b BLOB) ENGINE=InnoDB;
+perl;
+print "# bytes: ", (-s "$ENV{MYSQLD_DATADIR}/test/t1.ibd"), "\n";
+EOF
+INSERT INTO t1 SELECT seq,REPEAT('a',30000) FROM seq_1_to_20;
+perl;
+print "# bytes: ", (-s "$ENV{MYSQLD_DATADIR}/test/t1.ibd"), "\n";
+EOF
+DROP TABLE t1;
+
+let $page_size=`SELECT @@innodb_page_size`;
+if ($page_size < 32768)
+{
+#
+# Table 3: compressed BLOB
+#
+CREATE TABLE t1 (a INT PRIMARY KEY, b BLOB)
+ENGINE=InnoDB ROW_FORMAT=COMPRESSED KEY_BLOCK_SIZE=1;
+perl;
+print "# bytes: ", (-s "$ENV{MYSQLD_DATADIR}/test/t1.ibd"), "\n";
+EOF
+INSERT INTO t1 SELECT seq,REPEAT('a',30000) FROM seq_1_to_20;
+# Ensure that the file will be extended with the last 1024-byte page
+# after the file was pre-extended in 4096-byte increments.
+--disable_query_log
+FLUSH TABLE t1 FOR EXPORT;
+UNLOCK TABLES;
+--enable_query_log
+perl;
+print "# bytes: ", (-s "$ENV{MYSQLD_DATADIR}/test/t1.ibd"), "\n";
+EOF
+DROP TABLE t1;
+}
diff --git a/mysql-test/suite/innodb/t/compression_providers_loaded.combinations b/mysql-test/suite/innodb/t/compression_providers_loaded.combinations
new file mode 100644
index 00000000..d2a413f3
--- /dev/null
+++ b/mysql-test/suite/innodb/t/compression_providers_loaded.combinations
@@ -0,0 +1,19 @@
+[bzip2]
+innodb
+plugin-load-add=$PROVIDER_BZIP2_SO
+
+[lz4]
+innodb
+plugin-load-add=$PROVIDER_LZ4_SO
+
+[lzma]
+innodb
+plugin-load-add=$PROVIDER_LZMA_SO
+
+[lzo]
+innodb
+plugin-load-add=$PROVIDER_LZO_SO
+
+[snappy]
+innodb
+plugin-load-add=$PROVIDER_SNAPPY_SO
diff --git a/mysql-test/suite/innodb/t/compression_providers_loaded.test b/mysql-test/suite/innodb/t/compression_providers_loaded.test
new file mode 100644
index 00000000..1b6c348c
--- /dev/null
+++ b/mysql-test/suite/innodb/t/compression_providers_loaded.test
@@ -0,0 +1,18 @@
+let $alg = $MTR_COMBINATIONS;
+
+if (`SELECT COUNT(*) = 0 FROM information_schema.plugins WHERE plugin_name = "provider_$alg" AND plugin_status = "active"`)
+{
+ skip Needs provider_$alg plugin;
+}
+
+--echo #
+--echo # Testing unloaded compression provider: $alg
+--echo #
+
+--echo # Innodb_have_$alg reflects that the provider is loaded
+eval SHOW GLOBAL STATUS WHERE Variable_name = "Innodb_have_$alg";
+
+--echo # Innodb_compression_algorithm can be set to $alg
+let $innodb_compression_algorithm_orig = `SELECT @@Innodb_compression_algorithm`;
+eval SET GLOBAL Innodb_compression_algorithm = $alg;
+eval SET GLOBAL Innodb_compression_algorithm = $innodb_compression_algorithm_orig;
diff --git a/mysql-test/suite/innodb/t/compression_providers_unloaded.combinations b/mysql-test/suite/innodb/t/compression_providers_unloaded.combinations
new file mode 100644
index 00000000..20c49960
--- /dev/null
+++ b/mysql-test/suite/innodb/t/compression_providers_unloaded.combinations
@@ -0,0 +1,14 @@
+[bzip2]
+innodb
+
+[lz4]
+innodb
+
+[lzma]
+innodb
+
+[lzo]
+innodb
+
+[snappy]
+innodb
diff --git a/mysql-test/suite/innodb/t/compression_providers_unloaded.test b/mysql-test/suite/innodb/t/compression_providers_unloaded.test
new file mode 100644
index 00000000..84bcce59
--- /dev/null
+++ b/mysql-test/suite/innodb/t/compression_providers_unloaded.test
@@ -0,0 +1,13 @@
+let $alg = $MTR_COMBINATIONS;
+
+--echo #
+--echo # Testing unloaded compression provider: $alg
+--echo #
+
+--echo # Innodb_have_$alg reflects that the provider is not loaded
+eval SHOW GLOBAL STATUS WHERE Variable_name = "Innodb_have_$alg";
+
+--echo # Innodb_compression_algorithm cannot be set to $alg
+error ER_WRONG_VALUE_FOR_VAR;
+eval SET GLOBAL Innodb_compression_algorithm = $alg;
+show warnings;
diff --git a/mysql-test/suite/innodb/t/corrupted_during_recovery.opt b/mysql-test/suite/innodb/t/corrupted_during_recovery.opt
new file mode 100644
index 00000000..ba4fa744
--- /dev/null
+++ b/mysql-test/suite/innodb/t/corrupted_during_recovery.opt
@@ -0,0 +1,2 @@
+--skip-innodb-doublewrite
+--skip-innodb-buffer-pool-load-at-startup
diff --git a/mysql-test/suite/innodb/t/corrupted_during_recovery.test b/mysql-test/suite/innodb/t/corrupted_during_recovery.test
new file mode 100644
index 00000000..f383d9ab
--- /dev/null
+++ b/mysql-test/suite/innodb/t/corrupted_during_recovery.test
@@ -0,0 +1,95 @@
+--source include/have_innodb.inc
+
+--disable_query_log
+call mtr.add_suppression("InnoDB: Plugin initialization aborted");
+call mtr.add_suppression("Plugin 'InnoDB' init function returned error");
+call mtr.add_suppression("Plugin 'InnoDB' registration as a STORAGE ENGINE failed");
+call mtr.add_suppression("InnoDB: Database page corruption on disk or a failed read of file '.*test.t1\\.ibd' page");
+call mtr.add_suppression("InnoDB: Failed to read page 3 from file '.*test.t1\\.ibd': Page read from tablespace is corrupted.");
+call mtr.add_suppression("InnoDB: (Unable to apply log to|Discarding log for) corrupted page .*, page number=3\\]");
+call mtr.add_suppression("Table test/t1 is corrupted. Please drop the table and recreate\\.");
+call mtr.add_suppression("InnoDB: File '.*test/t1\\.ibd' is corrupted");
+call mtr.add_suppression("InnoDB: A long wait .* was observed for dict_sys");
+--enable_query_log
+
+let INNODB_PAGE_SIZE=`select @@innodb_page_size`;
+CREATE TABLE t1(a BIGINT PRIMARY KEY) ENGINE=InnoDB;
+INSERT INTO t1 VALUES(1);
+# Force a redo log checkpoint.
+let $restart_noprint=2;
+--source include/restart_mysqld.inc
+--source ../include/no_checkpoint_start.inc
+CREATE TABLE t2(a BIGINT PRIMARY KEY) ENGINE=InnoDB;
+INSERT INTO t1 VALUES(2);
+SET GLOBAL innodb_flush_log_at_trx_commit=1;
+INSERT INTO t2 VALUES(1);
+
+--let CLEANUP_IF_CHECKPOINT=DROP TABLE t1,t2;
+--source ../include/no_checkpoint_end.inc
+
+--echo # Corrupt the pages
+
+perl;
+my $ps = $ENV{INNODB_PAGE_SIZE};
+
+my $file = "$ENV{MYSQLD_DATADIR}/test/t1.ibd";
+open(FILE, "+<$file") || die "Unable to open $file";
+binmode FILE;
+sysseek(FILE, 3*$ps, 0) || die "Unable to seek $file\n";
+die "Unable to read $file" unless sysread(FILE, $page, $ps) == $ps;
+# Replace the a=1 with a=0.
+$page =~ s/\x80\x0\x0\x0\x0\x0\x0\x1/\x80\x0\x0\x0\x0\x0\x0\x0/;
+sysseek(FILE, 3*$ps, 0) || die "Unable to seek $file\n";
+syswrite(FILE, $page, $ps)==$ps || die "Unable to write $file\n";
+close FILE or die "close";
+
+$file = "$ENV{MYSQLD_DATADIR}/test/t2.ibd";
+open(FILE, "+<$file") || die "Unable to open $file";
+binmode FILE;
+# Corrupt pages 1 to 3. MLOG_INIT_FILE_PAGE2 should protect us!
+# Unfortunately, we are not immune to page 0 corruption.
+seek (FILE, $ps, SEEK_SET) or die "seek";
+print FILE chr(0xff) x ($ps * 3);
+close FILE or die "close";
+EOF
+
+--source include/start_mysqld.inc
+--error ER_UNKNOWN_STORAGE_ENGINE
+SELECT * FROM t1;
+let $restart_parameters=--innodb_force_recovery=1;
+--source include/restart_mysqld.inc
+
+--error ER_TABLE_CORRUPT
+SELECT * FROM t1;
+SELECT * FROM t2;
+CHECK TABLE t2;
+
+DROP TABLE t1, t2;
+
+# MDEV-21572 buf_page_get_gen() should apply buffered page
+# initialized redo log during recovery
+--source ../include/no_checkpoint_start.inc
+CREATE TABLE t1(pk SERIAL) ENGINE=InnoDB;
+INSERT INTO t1 VALUES (1),(2),(3);
+connect (con1,localhost,root,,);
+BEGIN;
+DELETE FROM t1 WHERE pk=1;
+connection default;
+SET GLOBAL innodb_flush_log_at_trx_commit=1;
+DELETE FROM t1 WHERE pk=3;
+--let CLEANUP_IF_CHECKPOINT=DROP TABLE t1;
+--source ../include/no_checkpoint_end.inc
+disconnect con1;
+
+--echo # Corrupt the pages
+perl;
+my $file = "$ENV{MYSQLD_DATADIR}/test/t1.ibd";
+open(FILE, "+<$file") || die "Unable to open $file";
+binmode FILE;
+seek (FILE, $ENV{INNODB_PAGE_SIZE} * 3, SEEK_SET) or die "seek";
+print FILE "junk";
+close FILE or die "close";
+EOF
+--source include/start_mysqld.inc
+SELECT * FROM t1;
+DROP TABLE t1;
diff --git a/mysql-test/suite/innodb/t/count_distinct.test b/mysql-test/suite/innodb/t/count_distinct.test
new file mode 100644
index 00000000..94a70260
--- /dev/null
+++ b/mysql-test/suite/innodb/t/count_distinct.test
@@ -0,0 +1,15 @@
+--source include/have_innodb.inc
+
+#
+# MDEV-4925 Wrong result - count(distinct), Using index for group-by (scanning)
+#
+CREATE TABLE t1 (
+ id int NOT NULL AUTO_INCREMENT,
+ a int NOT NULL,
+ b int NOT NULL,
+ PRIMARY KEY (id),
+ UNIQUE KEY ba (b, a)
+) ENGINE=InnoDB;
+INSERT INTO t1 (a, b) VALUES(1,101),(1,102),(1,103),(1,104),(1,105),(1,106),(1,107),(1,108),(1,109),(1,110);
+SELECT COUNT(DISTINCT b) FROM t1 WHERE a = 1;
+DROP TABLE t1;
diff --git a/mysql-test/suite/innodb/t/create-index.test b/mysql-test/suite/innodb/t/create-index.test
new file mode 100644
index 00000000..e1e5b856
--- /dev/null
+++ b/mysql-test/suite/innodb/t/create-index.test
@@ -0,0 +1,11 @@
+--source include/have_innodb.inc
+
+--echo #
+--echo # Bug #18010711 UNIQUE PREFIX INDEX ON BINARY COLUMN: FAILING
+--echo # ASSERTION: FLEN == LEN
+--echo #
+create table t1 (f1 binary(5)) engine=innodb;
+insert into t1 values ('w'), ('w');
+--error ER_DUP_ENTRY
+create unique index index_t1 on t1(f1(4));
+drop table t1;
diff --git a/mysql-test/suite/innodb/t/create_isl_with_direct.opt b/mysql-test/suite/innodb/t/create_isl_with_direct.opt
new file mode 100644
index 00000000..8f80f02e
--- /dev/null
+++ b/mysql-test/suite/innodb/t/create_isl_with_direct.opt
@@ -0,0 +1 @@
+--innodb_flush_method=O_DIRECT
diff --git a/mysql-test/suite/innodb/t/create_isl_with_direct.test b/mysql-test/suite/innodb/t/create_isl_with_direct.test
new file mode 100644
index 00000000..45d7fbf4
--- /dev/null
+++ b/mysql-test/suite/innodb/t/create_isl_with_direct.test
@@ -0,0 +1,21 @@
+--source include/not_embedded.inc
+--source include/have_innodb.inc
+--source include/have_symlink.inc
+
+SHOW VARIABLES LIKE 'innodb_flush_method';
+
+let MYSQLD_DATADIR=`SELECT @@datadir`;
+
+--replace_result $MYSQL_TMP_DIR MYSQL_TMP_DIR
+
+# Create a table with explicit data directory option.
+EVAL CREATE TABLE t1 (x INT) ENGINE=INNODB, DATA DIRECTORY='$MYSQL_TMP_DIR';
+
+--echo # Contents of tmp/test directory containing .ibd file
+--list_files $MYSQL_TMP_DIR/test
+
+--echo # Contents of the 'test' database directory containing .isl and .frm files
+--list_files $MYSQLD_DATADIR/test
+
+DROP TABLE t1;
+ \ No newline at end of file
diff --git a/mysql-test/suite/innodb/t/create_select.test b/mysql-test/suite/innodb/t/create_select.test
new file mode 100644
index 00000000..8103902e
--- /dev/null
+++ b/mysql-test/suite/innodb/t/create_select.test
@@ -0,0 +1,28 @@
+--source include/have_innodb.inc
+--source include/have_sequence.inc
+--source include/count_sessions.inc
+
+let $ID= `SELECT @id := CONNECTION_ID()`;
+
+connect (con1, localhost, root,,);
+let $ignore= `SELECT @id := $ID`;
+
+connection default;
+send CREATE TABLE t1 ENGINE=InnoDB SELECT * FROM seq_1_to_100000000;
+
+connection con1;
+let $wait_condition=
+ select count(*) = 1 from information_schema.processlist
+ where state = 'Sending data'
+ and info = 'CREATE TABLE t1 ENGINE=InnoDB SELECT * FROM seq_1_to_100000000';
+--source include/wait_condition.inc
+KILL QUERY @id;
+disconnect con1;
+
+connection default;
+--error ER_QUERY_INTERRUPTED
+reap;
+
+CREATE TABLE t1 (a SERIAL) ENGINE=InnoDB;
+DROP TABLE t1;
+--source include/wait_until_count_sessions.inc
diff --git a/mysql-test/suite/innodb/t/create_table_insert_skip_locked.test b/mysql-test/suite/innodb/t/create_table_insert_skip_locked.test
new file mode 100644
index 00000000..e889883e
--- /dev/null
+++ b/mysql-test/suite/innodb/t/create_table_insert_skip_locked.test
@@ -0,0 +1,73 @@
+#
+# MDEV-13115 Implement SKIP LOCKED
+#
+--source include/have_innodb.inc
+
+
+connect (con1,localhost,root,,);
+SET SESSION innodb_lock_wait_timeout=1;
+
+connection default;
+SET SESSION innodb_lock_wait_timeout=1;
+
+--echo # Case 1: Test primary index - CREATE TABLE .. SELECT .. SKIP LOCKED
+CREATE TABLE t1(
+ seat_id INT,
+ state INT,
+ PRIMARY KEY(seat_id)
+) ENGINE=InnoDB;
+
+INSERT INTO t1 VALUES(1,0), (2,0), (3,0), (4,0);
+
+BEGIN;
+SELECT * FROM t1 WHERE state = 0 LIMIT 2 LOCK IN SHARE MODE;
+
+connection con1;
+BEGIN;
+CREATE TEMPORARY TABLE s0 AS SELECT * FROM t1 WHERE state = 0 LIMIT 2 LOCK IN SHARE MODE;
+SELECT * FROM s0;
+
+CREATE TEMPORARY TABLE s1 AS SELECT * FROM t1 WHERE state = 0 LIMIT 2 FOR UPDATE SKIP LOCKED;
+SELECT * FROM s1;
+
+connection default;
+CREATE TEMPORARY TABLE s0 AS SELECT * FROM t1 WHERE state = 0 LOCK IN SHARE MODE SKIP LOCKED;
+SELECT * FROM s0;
+
+COMMIT;
+DROP TABLE s0;
+
+connection con1;
+COMMIT;
+DROP TABLE s0, s1;
+
+connection default;
+
+--echo # Case 2: Test primary index - INSERT .. SELECT .. SKIP LOCKED
+
+CREATE TABLE t2 LIKE t1;
+
+BEGIN;
+SELECT * FROM t1 WHERE state = 0 LIMIT 2 LOCK IN SHARE MODE;
+
+connection con1;
+BEGIN;
+
+INSERT INTO t2 SELECT * FROM t1 WHERE state = 0 LIMIT 2 LOCK IN SHARE MODE RETURNING seat_id, state;
+
+CREATE TEMPORARY TABLE t2s LIKE t1;
+INSERT INTO t2s SELECT * FROM t1 WHERE state = 0 LIMIT 2 FOR UPDATE SKIP LOCKED RETURNING seat_id, state;
+
+connection default;
+CREATE TEMPORARY TABLE t2s LIKE t1;
+INSERT INTO t2s SELECT * FROM t1 WHERE state = 0 LOCK IN SHARE MODE SKIP LOCKED RETURNING seat_id, state;
+COMMIT;
+DROP TABLE t2s;
+
+connection con1;
+COMMIT;
+DROP TABLE t2s;
+DROP TABLE t2;
+
+connection default;
+DROP TABLE t1;
diff --git a/mysql-test/suite/innodb/t/cursor-restore-locking.test b/mysql-test/suite/innodb/t/cursor-restore-locking.test
new file mode 100644
index 00000000..0f90055f
--- /dev/null
+++ b/mysql-test/suite/innodb/t/cursor-restore-locking.test
@@ -0,0 +1,87 @@
+--source include/have_innodb.inc
+--source include/count_sessions.inc
+source include/have_debug.inc;
+source include/have_debug_sync.inc;
+
+CREATE TABLE t (a int PRIMARY KEY, b int NOT NULL UNIQUE) engine = InnoDB, STATS_PERSISTENT=0;
+
+--source include/wait_all_purged.inc
+--connect(prevent_purge,localhost,root,,)
+start transaction with consistent snapshot;
+
+--connect(con_del_1,localhost,root,,)
+INSERT INTO t VALUES (20,20);
+SET DEBUG_SYNC = 'innodb_row_search_for_mysql_exit SIGNAL first_del_row_search_mvcc_finished WAIT_FOR first_del_cont';
+--send DELETE FROM t WHERE b = 20 # trx_1
+
+--connect(con_ins_1,localhost,root,,)
+SET DEBUG_SYNC = 'now WAIT_FOR first_del_row_search_mvcc_finished';
+# It's supposed the following INSERT will be suspended just after
+# lock_wait_start syncpoint, and will be awaken
+# after trx_1 DELETE commits. ib_after_row_insert will be executed
+# after the trx_2 INSERT is woken up. The trx_1 DELETE will wait for
+# first_del_cont signal before commit, and this signal will be sent later.
+# So it's safe to use two signals in a row here, it's guaranted the first
+# signal will be received before the second signal is sent.
+SET DEBUG_SYNC = 'lock_wait_start SIGNAL first_ins_locked';
+SET DEBUG_SYNC = 'ib_after_row_insert SIGNAL first_ins_row_inserted WAIT_FOR first_ins_cont';
+--send INSERT INTO t VALUES(10, 20) # trx_2
+
+--connect(con_del_2,localhost,root,,)
+# After MDEV-30225 is fixed, the following DELETE creates next-key lock for
+# unqique search for RR, and the above INSERT kills it as deadlock victim.
+# But it still requests not-gap lock for RC.
+SET TRANSACTION ISOLATION LEVEL READ COMMITTED;
+SET DEBUG_SYNC = 'now WAIT_FOR first_ins_locked';
+SET DEBUG_SYNC = 'lock_wait_start SIGNAL second_del_locked';
+##############################################################################
+# trx_3 DELETE is locked by trx_1 DELETE, after trx_1 DELETE is
+# committed, it will still be locked by trx_2 INSERT on delete-marked
+# heap_no 2 record. After trx_2 INSERT inserted the record with heap_no 3,
+# and after heap_no 2 record is purged, trx_3 DELETE will be unlocked and
+# must restore persistent cursor position at heap_no 3 record, as it has the
+# same secondary key value as former heap_no 2 record. Then it must be blocked
+# by trx_2 INSERT, and after trx_2 INSERT is committed, it must
+# delete the record, inserted by trx_2 INSERT, and trx_4 INSERT(see
+# below) must be finished without error. But instead this DELETE restores
+# persistent cursor position to supremum, as a result, it does not delete the
+# record, inserted by trx_2 INSERT, and trx_4 INSERT is finished with
+# duplicate key check error.
+###############################################################################
+--send DELETE FROM t WHERE b = 20 # trx_3
+
+--connection default
+SET DEBUG_SYNC = 'now WAIT_FOR second_del_locked';
+SET @saved_dbug = @@GLOBAL.debug_dbug;
+SET @@GLOBAL.debug_dbug="d,enable_row_purge_del_mark_exit_sync_point";
+SET DEBUG_SYNC = 'now SIGNAL first_del_cont';
+SET DEBUG_SYNC = 'now WAIT_FOR first_ins_row_inserted';
+--connection con_del_1
+--reap
+
+--connection default
+--disconnect prevent_purge
+SET DEBUG_SYNC = 'now WAIT_FOR row_purge_del_mark_finished';
+SET @@GLOBAL.debug_dbug = @saved_dbug;
+SET DEBUG_SYNC = 'now SIGNAL first_ins_cont';
+
+--connection con_del_2
+--reap
+
+--connection con_ins_1
+--reap
+
+--connection default
+###############################################################################
+# Duplicate key error is expected if the bug is not fixed.
+###############################################################################
+INSERT INTO t VALUES(30, 20); # trx_4
+
+--disconnect con_ins_1
+--disconnect con_del_1
+--disconnect con_del_2
+--connection default
+
+SET DEBUG_SYNC = 'RESET';
+DROP TABLE t;
+--source include/wait_until_count_sessions.inc
diff --git a/mysql-test/suite/innodb/t/data_types.opt b/mysql-test/suite/innodb/t/data_types.opt
new file mode 100644
index 00000000..3ad568c8
--- /dev/null
+++ b/mysql-test/suite/innodb/t/data_types.opt
@@ -0,0 +1 @@
+--loose-innodb-sys-columns
diff --git a/mysql-test/suite/innodb/t/data_types.test b/mysql-test/suite/innodb/t/data_types.test
new file mode 100644
index 00000000..19e37a41
--- /dev/null
+++ b/mysql-test/suite/innodb/t/data_types.test
@@ -0,0 +1,152 @@
+#
+# MDEV-5248 Serious incompatibility and data corruption of DATETIME and DATE types due to get_innobase_type_from_mysql_type refactor combined with InnoDB Online DDL
+#
+
+#
+# This test records what *internal type codes* innodb is using for every
+# MariaDB data type. THEY MUST ALWAYS BE THE SAME AND NEVER CHANGE!
+# Otherwise we create a compatibility problem and possible silent data
+# corruption too, see MDEV-5248
+#
+
+--source include/have_innodb.inc
+
+--enable_prepare_warnings
+
+CREATE TABLE t1
+(
+ t1_BIGINT BIGINT,
+ t1_BIGINT_UNSIGNED BIGINT UNSIGNED,
+ t1_BINARY_100 BINARY(100),
+ t1_BIT_2 BIT(2),
+ t1_BIT_20 BIT(20),
+ t1_BLOB BLOB,
+ t1_CHAR_100 CHAR(100),
+ t1_CHAR_100_BINARY CHAR(100) BINARY,
+ t1_DATE DATE,
+ t1_DATETIME DATETIME,
+ t1_DATETIME_6 DATETIME(6),
+ t1_DECIMAL_10_3 DECIMAL(10,3),
+ t1_DECIMAL_10_3_UNSIGNED DECIMAL(10,3) UNSIGNED,
+ t1_DOUBLE DOUBLE,
+ t1_DOUBLE_UNSIGNED DOUBLE UNSIGNED,
+ t1_ENUM ENUM('a', 'b', 'c'),
+ t1_ENUM_BINARY ENUM('a','b') BINARY,
+ t1_ENUM_256 ENUM('a1', 'a2', 'a3', 'a4', 'a5', 'a6', 'a7', 'a8', 'a9',
+ 'a10', 'a11', 'a12', 'a13', 'a14', 'a15', 'a16', 'a17', 'a18', 'a19',
+ 'a20', 'a21', 'a22', 'a23', 'a24', 'a25', 'a26', 'a27', 'a28', 'a29',
+ 'a30', 'a31', 'a32', 'a33', 'a34', 'a35', 'a36', 'a37', 'a38', 'a39',
+ 'a40', 'a41', 'a42', 'a43', 'a44', 'a45', 'a46', 'a47', 'a48', 'a49',
+ 'a50', 'a51', 'a52', 'a53', 'a54', 'a55', 'a56', 'a57', 'a58', 'a59',
+ 'a60', 'a61', 'a62', 'a63', 'a64', 'a65', 'a66', 'a67', 'a68', 'a69',
+ 'a70', 'a71', 'a72', 'a73', 'a74', 'a75', 'a76', 'a77', 'a78', 'a79',
+ 'a80', 'a81', 'a82', 'a83', 'a84', 'a85', 'a86', 'a87', 'a88', 'a89',
+ 'a90', 'a91', 'a92', 'a93', 'a94', 'a95', 'a96', 'a97', 'a98', 'a99',
+ 'a100', 'a101', 'a102', 'a103', 'a104', 'a105', 'a106', 'a107', 'a108',
+ 'a109', 'a110', 'a111', 'a112', 'a113', 'a114', 'a115', 'a116', 'a117',
+ 'a118', 'a119', 'a120', 'a121', 'a122', 'a123', 'a124', 'a125', 'a126',
+ 'a127', 'a128', 'a129', 'a130', 'a131', 'a132', 'a133', 'a134', 'a135',
+ 'a136', 'a137', 'a138', 'a139', 'a140', 'a141', 'a142', 'a143', 'a144',
+ 'a145', 'a146', 'a147', 'a148', 'a149', 'a150', 'a151', 'a152', 'a153',
+ 'a154', 'a155', 'a156', 'a157', 'a158', 'a159', 'a160', 'a161', 'a162',
+ 'a163', 'a164', 'a165', 'a166', 'a167', 'a168', 'a169', 'a170', 'a171',
+ 'a172', 'a173', 'a174', 'a175', 'a176', 'a177', 'a178', 'a179', 'a180',
+ 'a181', 'a182', 'a183', 'a184', 'a185', 'a186', 'a187', 'a188', 'a189',
+ 'a190', 'a191', 'a192', 'a193', 'a194', 'a195', 'a196', 'a197', 'a198',
+ 'a199', 'a200', 'a201', 'a202', 'a203', 'a204', 'a205', 'a206', 'a207',
+ 'a208', 'a209', 'a210', 'a211', 'a212', 'a213', 'a214', 'a215', 'a216',
+ 'a217', 'a218', 'a219', 'a220', 'a221', 'a222', 'a223', 'a224', 'a225',
+ 'a226', 'a227', 'a228', 'a229', 'a230', 'a231', 'a232', 'a233', 'a234',
+ 'a235', 'a236', 'a237', 'a238', 'a239', 'a240', 'a241', 'a242', 'a243',
+ 'a244', 'a245', 'a246', 'a247', 'a248', 'a249', 'a250', 'a251', 'a252',
+ 'a253', 'a254', 'a255', 'a256'),
+ t1_FLOAT FLOAT,
+ t1_FLOAT_UNSIGNED FLOAT UNSIGNED,
+ t1_INT INT,
+ t1_INT_UNSIGNED INT UNSIGNED,
+ t1_LONGBLOB LONGBLOB,
+ t1_LONGTEXT LONGTEXT,
+ t1_MEDIUMBLOB MEDIUMBLOB,
+ t1_MEDIUMINT MEDIUMINT,
+ t1_MEDIUMINT_UNSIGNED MEDIUMINT UNSIGNED,
+ t1_MEDIUMTEXT MEDIUMTEXT,
+ t1_SET SET('a', 'b', 'c'),
+ t1_SET_BINARY SET('a','b') BINARY,
+ t1_SET_9 SET('a1', 'a2', 'a3', 'a4', 'a5', 'a6', 'a7', 'a8', 'a9'),
+ t1_SMALLINT SMALLINT,
+ t1_SMALLINT_UNSIGNED SMALLINT UNSIGNED,
+ t1_TEXT TEXT,
+ t1_TIME TIME,
+ t1_TIME_4 TIME(4),
+ t1_TIMESTAMP TIMESTAMP,
+ t1_TIMESTAMP_5 TIMESTAMP(5),
+ t1_TINYBLOB TINYBLOB,
+ t1_TINYINT TINYINT,
+ t1_TINYINT_UNSIGNED TINYINT UNSIGNED,
+ t1_TINYTEXT TINYTEXT,
+ t1_VARBINARY_100 VARBINARY(100),
+ t1_VARCHAR_10 VARCHAR(10),
+ t1_VARCHAR_10_BINARY VARCHAR(10) BINARY,
+ t1_VARCHAR_500 VARCHAR(500),
+ t1_VARCHAR_500_BINARY VARCHAR(500) BINARY,
+ t1_YEAR_2 YEAR(2),
+ t1_YEAR_4 YEAR(4),
+ t1_CHAR_0 CHAR(0),
+ t1_MYSQL_0 CHAR(0) CHARACTER SET utf8,
+ t1_VARCHAR_0 VARCHAR(0),
+ t1_VARMYSQL_0 VARCHAR(0) CHARACTER SET utf8
+) ENGINE=InnoDB;
+
+--disable_prepare_warnings
+
+INSERT INTO t1 () VALUES ();
+
+SELECT
+ name,
+ CASE mtype
+ WHEN 1 THEN "DATA_VARCHAR"
+ WHEN 2 THEN "DATA_CHAR"
+ WHEN 3 THEN "DATA_FIXBINARY"
+ WHEN 4 THEN "DATA_BINARY"
+ WHEN 5 THEN "DATA_BLOB"
+ WHEN 6 THEN "DATA_INT"
+ WHEN 7 THEN "DATA_SYS_CHILD"
+ WHEN 8 THEN "DATA_SYS"
+ WHEN 9 THEN "DATA_FLOAT"
+ WHEN 10 THEN "DATA_DOUBLE"
+ WHEN 11 THEN "DATA_DECIMAL"
+ WHEN 12 THEN "DATA_VARMYSQL"
+ WHEN 13 THEN "DATA_MYSQL"
+ WHEN 63 THEN "DATA_MTYPE_MAX"
+ ELSE mtype
+ END AS mtype,
+ IF((prtype & 512) = 512,"UNSIGNED","") AS is_unsigned
+FROM information_schema.INNODB_SYS_COLUMNS
+WHERE name LIKE "t1\_%"
+ORDER BY name;
+
+DROP TABLE t1;
+
+--echo #
+--echo # MDEV-17815 Assertion failed in btr_node_ptr_max_size for CHAR(0)
+--echo #
+CREATE TABLE t1 (c CHAR(0), KEY(c)) ENGINE=InnoDB;
+INSERT INTO t1 VALUES ('');
+DROP TABLE t1;
+
+--echo #
+--echo # MDEV-18039 Assertion failed in btr_node_ptr_max_size for VARCHAR(0)
+--echo #
+CREATE TABLE t1 (c VARCHAR(0), KEY(c)) ENGINE=InnoDB;
+INSERT INTO t1 VALUES ('');
+DROP TABLE t1;
+
+--echo #
+--echo # MDEV-19216 Assertion ...SYS_FOREIGN failed in btr_node_ptr_max_size
+--echo #
+
+CREATE TABLE t1 (b BINARY(0), v VARBINARY(0), KEY(b), KEY(v)) ENGINE=InnoDB;
+INSERT INTO t1 SET b='',v='';
+DROP TABLE t1;
+
+--echo # End of 10.4 tests
diff --git a/mysql-test/suite/innodb/t/ddl_purge.test b/mysql-test/suite/innodb/t/ddl_purge.test
new file mode 100644
index 00000000..8f84206c
--- /dev/null
+++ b/mysql-test/suite/innodb/t/ddl_purge.test
@@ -0,0 +1,41 @@
+--source innodb_default_row_format.inc
+--source include/have_debug.inc
+--source include/have_debug_sync.inc
+
+CREATE TABLE t0 (pk INT PRIMARY KEY) ENGINE=InnoDB;
+CREATE TABLE t1 (pk INT PRIMARY KEY, b INT) ENGINE=InnoDB;
+# MDEV-515 takes X-lock on the table for the first insert.
+# So concurrent insert won't happen on the table
+INSERT INTO t0 VALUES(100);
+
+INSERT INTO t1 VALUES(100, 100);
+
+--connect (con1,localhost,root,,test)
+BEGIN;
+INSERT INTO t0 SET pk=1;
+
+--connect (con2,localhost,root,,test)
+BEGIN;
+INSERT INTO t0 SET pk=2;
+
+--connection default
+SET DEBUG_SYNC='alter_table_inplace_after_lock_downgrade SIGNAL prepared WAIT_FOR logged';
+send ALTER TABLE t1 FORCE;
+
+--connection con1
+SET DEBUG_SYNC='now WAIT_FOR prepared';
+INSERT INTO t1 SET pk=1;
+COMMIT;
+--disconnect con1
+
+--connection con2
+UPDATE t1 SET b=1;
+DELETE FROM t1;
+ROLLBACK;
+SET DEBUG_SYNC='now SIGNAL logged';
+--disconnect con2
+
+--connection default
+reap;
+SET DEBUG_SYNC='RESET';
+DROP TABLE t0,t1;
diff --git a/mysql-test/suite/innodb/t/deadlock_detect.combinations b/mysql-test/suite/innodb/t/deadlock_detect.combinations
new file mode 100644
index 00000000..67d1a486
--- /dev/null
+++ b/mysql-test/suite/innodb/t/deadlock_detect.combinations
@@ -0,0 +1,7 @@
+[OFF]
+--innodb-deadlock-detect=OFF
+--innodb-lock-wait-timeout=1
+
+[ON]
+--innodb-deadlock-detect=ON
+--innodb-lock-wait-timeout=1
diff --git a/mysql-test/suite/innodb/t/deadlock_detect.test b/mysql-test/suite/innodb/t/deadlock_detect.test
new file mode 100644
index 00000000..e8537907
--- /dev/null
+++ b/mysql-test/suite/innodb/t/deadlock_detect.test
@@ -0,0 +1,79 @@
+#
+# wl#9383 INNODB: ADD AN OPTION TO TURN OFF/ON DEADLOCK CHECKER
+#
+
+--source include/have_innodb.inc
+--source include/count_sessions.inc
+
+let $have_deadlock=`select @@GLOBAL.innodb_deadlock_detect`;
+
+connection default;
+
+CREATE TABLE t1(
+ id INT,
+ PRIMARY KEY(id)
+) ENGINE=InnoDB;
+
+INSERT INTO t1 VALUES(1), (2), (3);
+
+# We are not interested query results, only errors
+--disable_result_log
+BEGIN;
+
+SELECT * FROM t1 WHERE id = 1 LOCK IN SHARE MODE;
+
+connect (con1,localhost,root,,);
+BEGIN;
+SELECT * FROM t1 WHERE id = 2 LOCK IN SHARE MODE;
+
+connect (con2,localhost,root,,);
+BEGIN;
+SELECT * FROM t1 WHERE id = 2 LOCK IN SHARE MODE;
+
+send SELECT * FROM t1 WHERE id = 1 FOR UPDATE;
+
+connection default;
+send SELECT * FROM t1 WHERE id = 2 FOR UPDATE;
+
+connection con2;
+if (!$have_deadlock) {
+--error ER_LOCK_WAIT_TIMEOUT
+reap;
+disconnect con1;
+}
+if ($have_deadlock) {
+connection con1;
+COMMIT;
+disconnect con1;
+connection con2;
+--error 0,ER_LOCK_DEADLOCK,ER_LOCK_WAIT_TIMEOUT
+reap;
+}
+ROLLBACK;
+disconnect con2;
+
+#
+# Note here that con1 is the older transaction as it
+# query started wait first. Thus, con1 gets lock
+# wait timeout first. There is possibility that
+# default connection gets lock timeout also or
+# as con1 is rolled back it gets the locks it waited
+# and does the update.
+#
+connection default;
+if (!$have_deadlock) {
+--error 0,ER_LOCK_WAIT_TIMEOUT
+reap;
+}
+if ($have_deadlock) {
+--error 0,ER_LOCK_DEADLOCK
+reap;
+}
+
+ROLLBACK;
+
+--enable_result_log
+
+DROP TABLE t1;
+
+--source include/wait_until_count_sessions.inc
diff --git a/mysql-test/suite/innodb/t/deadlock_in_subqueries_join.test b/mysql-test/suite/innodb/t/deadlock_in_subqueries_join.test
new file mode 100644
index 00000000..b3adfb3b
--- /dev/null
+++ b/mysql-test/suite/innodb/t/deadlock_in_subqueries_join.test
@@ -0,0 +1,81 @@
+--source include/have_innodb.inc
+--source include/count_sessions.inc
+
+CREATE TABLE t1 (
+ pkey int NOT NULL PRIMARY KEY,
+ c int
+) ENGINE=InnoDB;
+
+INSERT INTO t1 VALUES(1,1);
+
+CREATE TABLE t2 (
+ pkey int NOT NULL PRIMARY KEY,
+ c int
+) ENGINE=InnoDB DEFAULT CHARSET=latin1;
+
+INSERT INTO t2 VALUES (2, NULL);
+
+# The following table is to increase tansaction weight on deadlock resolution
+CREATE TABLE t3 (c int) engine = InnoDB;
+INSERT INTO t3 VALUES (10), (20), (30), (40), (50);
+
+--let $i= 2
+--let $delete= 2
+--let $update= 1
+--connect(con1, localhost,root,,)
+
+while($i) {
+--connection default
+START TRANSACTION; # trx 1
+# The following update is necessary to increase the transaction weight, which is
+# calculated as the number of locks + the number of undo records during deadlock
+# report. Victim's transaction should have minimum weight. We need trx 2 to be
+# choosen as victim, that's why we need to increase the current transaction
+# weight.
+UPDATE t3 SET c=c+1000;
+SELECT * FROM t1 FOR UPDATE;
+
+--connection con1
+START TRANSACTION; # trx 2
+# 1) read record from t2, lock it
+# 2) check if the read record should be deleted, i.e. read record from t1,
+# as the record from t1 is locked by trx 1, the subselect will be suspended.
+# see 'while' loop in mysql_delete() or mysql_update() and
+# select->skip_record(thd) call for details.
+if ($i == $delete) {
+--send DELETE FROM t2 WHERE c NOT IN (SELECT ref_0.pkey FROM t1 AS ref_0 INNER JOIN t1 AS ref_1 ON ref_0.c = ref_0.pkey)
+}
+if ($i == $update) {
+--send UPDATE t2 SET pkey=pkey+10 WHERE c NOT IN (SELECT ref_0.pkey FROM t1 AS ref_0 INNER JOIN t1 AS ref_1 ON ref_0.c = ref_0.pkey)
+}
+
+--connection default
+let $wait_condition=
+ SELECT count(*) = 1 FROM information_schema.processlist
+ WHERE (state = 'Sending data' OR state = "Updating")
+ AND (info LIKE 'delete from t2 where%' OR
+ info LIKE 'UPDATE t2 SET pkey=pkey+10 WHERE%');
+--source include/wait_condition.inc
+
+# The record from t2 is locked by the previous delete, so trx 2 is waiting for
+# trx 1, and trx 1 will be blocked by trx 2 with the following SELECT. So we
+# have deadlock here. And trx 2 is chosen as deadlock victim as trx 1 has
+# greater weight.
+SELECT * FROM t2 FOR UPDATE;
+COMMIT;
+
+--connection con1
+# If the bug is not fixed, there will be assertion failure as
+# mysql_delete()/mysql_update() will continue execution despite its subselect
+# got deadlock error
+--error ER_LOCK_DEADLOCK
+--reap
+COMMIT;
+--dec $i
+}
+
+--disconnect con1
+
+--connection default
+DROP TABLE t1,t2,t3;
+--source include/wait_until_count_sessions.inc
diff --git a/mysql-test/suite/innodb/t/deadlock_on_lock_upgrade.test b/mysql-test/suite/innodb/t/deadlock_on_lock_upgrade.test
new file mode 100644
index 00000000..79adbe22
--- /dev/null
+++ b/mysql-test/suite/innodb/t/deadlock_on_lock_upgrade.test
@@ -0,0 +1,143 @@
+--echo #
+--echo # Bug #23755664 DEADLOCK WITH 3 CONCURRENT DELETES BY UNIQUE KEY
+--echo #
+
+--source include/have_innodb.inc
+--source include/have_debug.inc
+--source include/have_debug_sync.inc
+--source include/count_sessions.inc
+
+--connection default
+# There are various scenarious in which a transaction already holds "half"
+# of a record lock (for example, a lock on the record but not on the gap)
+# and wishes to "upgrade it" to a full lock (i.e. on both gap and record).
+# This is often a cause for a deadlock, if there is another transaction
+# which is already waiting for the lock being blocked by us:
+# 1. our granted lock for one half
+# 2. her waiting lock for the same half
+# 3. our waiting lock for the whole
+
+#
+# SCENARIO 1
+#
+# In this scenario, three different threads try to delete the same row,
+# identified by a secondary index key.
+# This kind of operation (besides LOCK_IX on a table) requires
+# an LOCK_REC_NOT_GAP|LOCK_REC|LOCK_X lock on a secondary index
+# 1. `deleter` is the first to get the required lock
+# 2. `holder` enqueues a waiting lock
+# 3. `waiter` enqueues right after `holder`
+# 4. `deleter` commits, releasing the lock, and granting it to `holder`
+# 5. `holder` now observes that the row was deleted, so it needs to
+# "seal the gap", by obtaining a LOCK_X|LOCK_REC, but..
+# 6. this causes a deadlock between `holder` and `waiter`
+#
+# This scenario does not fail if MDEV-10962 is not fixed because of MDEV-30225
+# fix, as the 'holder' does not "seal the gap" after 'deleter' was committed,
+# because it was initially sealed, as row_search_mvcc() requests next-key lock
+# after MDEV-30225 fix in the case when it requested not-gap lock before the
+# fix.
+#
+# But let the scenario be in the tests, because it can fail if MDEV-30225
+# related code is changed
+
+CREATE TABLE `t`(
+ `id` INT,
+ `a` INT DEFAULT NULL,
+ PRIMARY KEY(`id`),
+ UNIQUE KEY `u`(`a`)
+) ENGINE=InnoDB;
+
+INSERT INTO t (`id`,`a`) VALUES
+ (1,1),
+ (2,9999),
+ (3,10000);
+
+--connect(deleter,localhost,root,,)
+--connect(holder,localhost,root,,)
+--connect(waiter,localhost,root,,)
+
+
+--connection deleter
+ SET DEBUG_SYNC =
+ 'lock_sec_rec_read_check_and_lock_has_locked
+ SIGNAL deleter_has_locked
+ WAIT_FOR waiter_has_locked';
+ --send DELETE FROM t WHERE a = 9999
+
+--connection holder
+ SET DEBUG_SYNC=
+ 'now WAIT_FOR deleter_has_locked';
+ SET DEBUG_SYNC=
+ 'lock_sec_rec_read_check_and_lock_has_locked SIGNAL holder_has_locked';
+ --send DELETE FROM t WHERE a = 9999
+
+--connection waiter
+ SET DEBUG_SYNC=
+ 'now WAIT_FOR holder_has_locked';
+ SET DEBUG_SYNC=
+ 'lock_sec_rec_read_check_and_lock_has_locked SIGNAL waiter_has_locked';
+ --send DELETE FROM t WHERE a = 9999
+
+--connection deleter
+ --reap
+
+--connection holder
+ --reap
+
+--connection waiter
+ --reap
+
+--connection default
+
+--disconnect deleter
+--disconnect holder
+--disconnect waiter
+
+DROP TABLE `t`;
+SET DEBUG_SYNC='reset';
+
+# SCENARIO 2
+#
+# Here, we form a situation in which con1 has LOCK_REC_NOT_GAP on rows 1 and 2
+# con2 waits for lock on row 1, and then con1 wants to upgrade the lock on row 1,
+# which might cause a deadlock, unless con1 properly notices that even though the
+# lock on row 1 can not be upgraded, a separate LOCK_GAP can be obtaied easily.
+
+CREATE TABLE `t`(
+ `id` INT NOT NULL PRIMARY KEY
+) ENGINE=InnoDB;
+
+INSERT INTO t (`id`) VALUES (1), (2);
+
+--connect(holder,localhost,root,,)
+--connect(waiter,localhost,root,,)
+
+--connection holder
+ BEGIN;
+ SELECT id FROM t WHERE id=1 FOR UPDATE;
+ SELECT id FROM t WHERE id=2 FOR UPDATE;
+
+--connection waiter
+ SET DEBUG_SYNC=
+ 'lock_wait_before_suspend SIGNAL waiter_will_wait';
+ --send SELECT id FROM t WHERE id = 1 FOR UPDATE
+
+--connection holder
+ SET DEBUG_SYNC=
+ 'now WAIT_FOR waiter_will_wait';
+ SELECT * FROM t FOR UPDATE;
+ COMMIT;
+
+--connection waiter
+ --reap
+
+--connection default
+
+--disconnect holder
+--disconnect waiter
+
+DROP TABLE `t`;
+SET DEBUG_SYNC='reset';
+
+--source include/wait_until_count_sessions.inc
diff --git a/mysql-test/suite/innodb/t/deadlock_victim_race.test b/mysql-test/suite/innodb/t/deadlock_victim_race.test
new file mode 100644
index 00000000..b9a442fc
--- /dev/null
+++ b/mysql-test/suite/innodb/t/deadlock_victim_race.test
@@ -0,0 +1,113 @@
+--source include/have_innodb.inc
+--source include/have_debug_sync.inc
+--source include/count_sessions.inc
+
+--connect(cancel_purge,localhost,root,,)
+# Purge can cause deadlock in the test, requesting page's RW_X_LATCH for trx
+# ids reseting, after trx 2 acqured RW_S_LATCH and suspended in debug sync point
+# lock_trx_handle_wait_enter, waiting for upd_cont signal, which must be
+# emitted after the last SELECT in this test. The last SELECT will hang waiting
+# for purge RW_X_LATCH releasing, and trx 2 will be rolled back by timeout.
+# The last SELECT will then be successfully executed instead of finishing by
+# lock wait timeout.
+START TRANSACTION WITH CONSISTENT SNAPSHOT;
+
+--connection default
+CREATE TABLE t (a int PRIMARY KEY, b int) engine = InnoDB;
+CREATE TABLE t2 (a int PRIMARY KEY) engine = InnoDB;
+
+INSERT INTO t VALUES (10, 10), (20, 20), (30, 30);
+INSERT INTO t2 VALUES (10), (20), (30);
+
+BEGIN; # trx 1
+SELECT * FROM t WHERE a = 20 FOR UPDATE;
+# Locking order:
+# (10,10) (20,20) (30,30)
+# ^
+# trx 1
+
+--connect(con_2,localhost,root,,)
+# RC is neccessary to do semi-consistent read
+SET TRANSACTION ISOLATION LEVEL READ COMMITTED;
+BEGIN; # trx 2
+# The first time it will be hit on trying to lock (20,20), the second hit
+# will be on (30,30).
+SET DEBUG_SYNC = 'lock_trx_handle_wait_enter SIGNAL upd_locked WAIT_FOR upd_cont EXECUTE 2';
+# We must not modify primary key fields to cause rr_sequential() read record
+# function choosing in mysql_update(), i.e. both query_plan.using_filesort and
+# query_plan.using_io_buffer must be false during init_read_record() call.
+--send UPDATE t SET b = 100
+
+--connect(con_3,localhost,root,,)
+BEGIN; # trx 3
+# The following update is necessary to increase the transaction weight, which is
+# calculated as the number of locks + the number of undo records during deadlock
+# report. Victim's transaction should have minimum weight. We need trx 2 to be
+# choosen as victim, that's why we need to increase the current transaction
+# weight.
+UPDATE t2 SET a = a + 100;
+SELECT * FROM t WHERE a = 30 FOR UPDATE;
+SET DEBUG_SYNC='now WAIT_FOR upd_locked';
+# Locking queue:
+# (10,10) (20,20) (30,30)
+# ^ ^ ^
+# trx 2 trx 1 trx 3
+# trx 2 (waiting for 1)
+
+SET DEBUG_SYNC = 'lock_wait_start SIGNAL sel_locked';
+--send SELECT * FROM t WHERE a = 20 FOR UPDATE
+--connection default
+SET DEBUG_SYNC='now WAIT_FOR sel_locked';
+# Locking queue:
+# (10,10) (20,20) (30,30)
+# ^ ^ ^
+# trx 2 trx 1 trx 3
+# trx 2 (waiting for 1)
+# trx 3 (waiting for 1)
+#
+# Note trx 1 must grant lock to trx2 before trx 2 checks the lock state in
+# lock_trx_handle_wait(), i.e. the function must return DB_SUCCESS, that's why
+# the following ROLLBACK must be executed before sending upd_cont signal.
+ROLLBACK;
+SET DEBUG_SYNC='now SIGNAL upd_cont';
+
+SET DEBUG_SYNC="now WAIT_FOR upd_locked";
+# Locking queue:
+# (10,10) (20,20) (30,30)
+# ^ ^ ^
+# trx 2 trx 2 trx 3
+# trx 3 (waiting for 2) trx 2 (waiting for 3)
+#
+# Deadlock happened after trx 1 granted lock to trx 2, and trx2 continued
+# sequential read (with rr_sequential() read record function), and requested
+# lock on (30,30). But the deadlock has not been determined yet.
+
+SET SESSION innodb_lock_wait_timeout=1;
+--error ER_LOCK_WAIT_TIMEOUT
+# The deadlock will be determined in lock_wait() after lock wait timeout
+# expired.
+SELECT * FROM t WHERE a = 10 FOR UPDATE;
+SET DEBUG_SYNC="now SIGNAL upd_cont";
+
+--connection con_3
+--reap
+
+--connection con_2
+# As lock_trx_handle_wait() wrongly returned DB_SUCCESS instead of
+# DB_DEADLOCK, row_search_mvcc() of trx 2 behaves so as if (30,30) was locked.
+# But the waiting(for trx 3) lock was cancelled by deadlock checker after
+# trx 2 was choosen as a victim (see lock_cancel_waiting_and_release() call
+# from Deadlock::report() for details). The try to update non-locked record
+# will cause assertion if the bug is not fixed.
+--error ER_LOCK_DEADLOCK
+--reap
+
+--disconnect con_3
+--disconnect con_2
+
+--connection default
+SET DEBUG_SYNC = 'RESET';
+DROP TABLE t;
+DROP TABLE t2;
+--disconnect cancel_purge
+--source include/wait_until_count_sessions.inc
diff --git a/mysql-test/suite/innodb/t/deadlock_wait_lock_race.opt b/mysql-test/suite/innodb/t/deadlock_wait_lock_race.opt
new file mode 100644
index 00000000..65470e63
--- /dev/null
+++ b/mysql-test/suite/innodb/t/deadlock_wait_lock_race.opt
@@ -0,0 +1 @@
+--innodb-force-recovery=2
diff --git a/mysql-test/suite/innodb/t/deadlock_wait_lock_race.test b/mysql-test/suite/innodb/t/deadlock_wait_lock_race.test
new file mode 100644
index 00000000..79a62b09
--- /dev/null
+++ b/mysql-test/suite/innodb/t/deadlock_wait_lock_race.test
@@ -0,0 +1,67 @@
+--source include/have_innodb.inc
+--source include/have_debug_sync.inc
+--source include/count_sessions.inc
+
+# Purge can cause deadlock in the test, requesting page's RW_X_LATCH for trx
+# ids reseting, after trx 2 acqured RW_S_LATCH and suspended in debug sync point
+# lock_trx_handle_wait_enter, waiting for upd_cont signal, which must be
+# emitted after the last SELECT in this test. The last SELECT will hang waiting
+# for purge RW_X_LATCH releasing, and trx 2 will be rolled back by timeout.
+
+# There is deadlock_report_before_lock_releasing sync point in
+# Deadlock::report(), which is waiting for sel_cont signal under
+# lock_sys_t lock. The signal must be issued after "UPDATE t SET b = 100"
+# rollback, and that rollback is executing undo record, which is blocked on
+# dict_sys latch request. dict_sys is locked by the thread of statistics
+# update(dict_stats_save()), and during that update lock_sys lock is requested,
+# and can't be acquired as Deadlock::report() holds it. We have to disable
+# statistics update to make the test stable.
+
+CREATE TABLE t (a int PRIMARY KEY, b int) engine = InnoDB STATS_PERSISTENT=0;
+CREATE TABLE t2 (a int PRIMARY KEY) engine = InnoDB STATS_PERSISTENT=0;
+
+INSERT INTO t VALUES (10, 10), (20, 20), (30, 30);
+INSERT INTO t2 VALUES (10), (20), (30);
+
+BEGIN; # trx 1
+# The following update is necessary to increase the transaction weight, which is
+# calculated as the number of locks + the number of undo records during deadlock
+# report. Victim's transaction should have minimum weight. We need trx 2 to be
+# choosen as victim, that's why we need to increase the current transaction
+# weight.
+UPDATE t2 SET a = a + 100;
+SELECT * FROM t WHERE a = 20 FOR UPDATE;
+
+--connect(con_2,localhost,root,,)
+# RC is necessary to do semi-consistent read
+SET TRANSACTION ISOLATION LEVEL READ COMMITTED;
+BEGIN; # trx 2
+# The first time it will be hit on trying to lock (20,20), the second hit
+# will be on (30,30).
+SET DEBUG_SYNC = 'lock_trx_handle_wait_before_unlocked_wait_lock_check SIGNAL upd_locked WAIT_FOR upd_cont';
+# We must not modify primary key fields to cause rr_sequential() read record
+# function choosing in mysql_update(), i.e. both query_plan.using_filesort and
+# query_plan.using_io_buffer must be false during init_read_record() call.
+--send UPDATE t SET b = 100
+
+--connection default
+SET DEBUG_SYNC="now WAIT_FOR upd_locked";
+SET DEBUG_SYNC="lock_wait_before_suspend SIGNAL upd_cont";
+--send SELECT * FROM t WHERE a = 10 FOR UPDATE
+
+--connection con_2
+# If the bug is not fixed, lock_trx_handle_wait() wrongly returns DB_SUCCESS
+# instead of DB_DEADLOCK, row_search_mvcc() of trx 2 behaves so as if (20,20)
+# was locked. Some debug assertion must crash the server. If the bug is fixed,
+# trx 2 must just be rolled back by deadlock detector.
+--error ER_LOCK_DEADLOCK
+--reap
+
+--disconnect con_2
+
+--connection default
+--reap
+SET DEBUG_SYNC = 'RESET';
+DROP TABLE t;
+DROP TABLE t2;
+--source include/wait_until_count_sessions.inc
diff --git a/mysql-test/suite/innodb/t/deadlock_wait_thr_race.opt b/mysql-test/suite/innodb/t/deadlock_wait_thr_race.opt
new file mode 100644
index 00000000..65470e63
--- /dev/null
+++ b/mysql-test/suite/innodb/t/deadlock_wait_thr_race.opt
@@ -0,0 +1 @@
+--innodb-force-recovery=2
diff --git a/mysql-test/suite/innodb/t/deadlock_wait_thr_race.test b/mysql-test/suite/innodb/t/deadlock_wait_thr_race.test
new file mode 100644
index 00000000..42576f35
--- /dev/null
+++ b/mysql-test/suite/innodb/t/deadlock_wait_thr_race.test
@@ -0,0 +1,71 @@
+--source include/have_innodb.inc
+--source include/have_debug_sync.inc
+--source include/count_sessions.inc
+
+# Purge can cause deadlock in the test, requesting page's RW_X_LATCH for trx
+# ids reseting, after trx 2 acqured RW_S_LATCH and suspended in debug sync point
+# lock_trx_handle_wait_enter, waiting for upd_cont signal, which must be
+# emitted after the last SELECT in this test. The last SELECT will hang waiting
+# for purge RW_X_LATCH releasing, and trx 2 will be rolled back by timeout.
+
+# There is deadlock_report_before_lock_releasing sync point in
+# Deadlock::report(), which is waiting for sel_cont signal under
+# lock_sys_t lock. The signal must be issued after "UPDATE t SET b = 100"
+# rollback, and that rollback is executing undo record, which is blocked on
+# dict_sys latch request. dict_sys is locked by the thread of statistics
+# update(dict_stats_save()), and during that update lock_sys lock is requested,
+# and can't be acquired as Deadlock::report() holds it. We have to disable
+# statistics update to make the test stable.
+
+CREATE TABLE t (a int PRIMARY KEY, b int) engine = InnoDB STATS_PERSISTENT=0;
+CREATE TABLE t2 (a int PRIMARY KEY) engine = InnoDB STATS_PERSISTENT=0;
+
+INSERT INTO t VALUES (10, 10), (20, 20), (30, 30);
+INSERT INTO t2 VALUES (10), (20), (30);
+
+BEGIN; # trx 1
+# The following update is necessary to increase the transaction weight, which is
+# calculated as the number of locks + the number of undo records during deadlock
+# report. Victim's transaction should have minimum weight. We need trx 2 to be
+# choosen as victim, that's why we need to increase the current transaction
+# weight.
+UPDATE t2 SET a = a + 100;
+SELECT * FROM t WHERE a = 20 FOR UPDATE;
+
+--connect(con_2,localhost,root,,)
+# RC is necessary to do semi-consistent read
+SET TRANSACTION ISOLATION LEVEL READ COMMITTED;
+# It will be hit on trying to lock (20,20).
+SET DEBUG_SYNC = 'lock_trx_handle_wait_enter SIGNAL upd_locked WAIT_FOR upd_cont';
+SET DEBUG_SYNC = 'trx_t_release_locks_enter SIGNAL sel_cont WAIT_FOR upd_cont_2';
+BEGIN; # trx 2
+# We must not modify primary key fields to cause rr_sequential() read record
+# function choosing in mysql_update(), i.e. both query_plan.using_filesort and
+# query_plan.using_io_buffer must be false during init_read_record() call.
+# The following UPDATE will be chosen as deadlock victim and rolled back.
+--send UPDATE t SET b = 100
+
+--connection default
+SET DEBUG_SYNC="now WAIT_FOR upd_locked";
+SET DEBUG_SYNC="deadlock_report_before_lock_releasing SIGNAL upd_cont WAIT_FOR sel_cont";
+SET DEBUG_SYNC="lock_wait_before_suspend SIGNAL sel_before_suspend";
+# If the bug is not fixed, the following SELECT will crash, as the above UPDATE
+# will reset trx->lock.wait_thr during rollback
+--send SELECT * FROM t WHERE a = 10 FOR UPDATE;
+
+--connect(con_3,localhost,root,,)
+SET DEBUG_SYNC="now WAIT_FOR sel_before_suspend";
+SET DEBUG_SYNC="now SIGNAL upd_cont_2";
+--disconnect con_3
+
+--connection con_2
+--error ER_LOCK_DEADLOCK
+--reap
+--disconnect con_2
+
+--connection default
+--reap
+SET DEBUG_SYNC = 'RESET';
+DROP TABLE t;
+DROP TABLE t2;
+--source include/wait_until_count_sessions.inc
diff --git a/mysql-test/suite/innodb/t/default_row_format_alter.test b/mysql-test/suite/innodb/t/default_row_format_alter.test
new file mode 100644
index 00000000..5f217045
--- /dev/null
+++ b/mysql-test/suite/innodb/t/default_row_format_alter.test
@@ -0,0 +1,172 @@
+--source include/have_innodb.inc
+--source include/innodb_row_format.inc
+
+SET @row_format = @@GLOBAL.innodb_default_row_format;
+
+--echo ####################################
+--echo # Check if table rebuilding alter isn't affect if table is created
+--echo # with explicit row_format
+CREATE TABLE t1 (a INT PRIMARY KEY, b TEXT) ROW_FORMAT=COMPACT ENGINE=INNODB;
+INSERT INTO t1 VALUES (1, 'abc');
+--replace_column 3 # 5 # 6 # 7 # 8 # 9 # 10 # 12 # 13 #
+SHOW TABLE STATUS LIKE 't1';
+
+SET GLOBAL innodb_default_row_format=DYNAMIC;
+ALTER TABLE t1 DROP PRIMARY KEY, ADD COLUMN c INT PRIMARY KEY;
+
+--echo # Here we expect COMPACT because it was explicitly specified at CREATE
+--replace_column 3 # 5 # 6 # 7 # 8 # 9 # 10 # 12 # 13 #
+SHOW TABLE STATUS LIKE 't1';
+DROP TABLE t1;
+
+--echo ####################################
+--echo # Check if table rebuilding alter is affected when there is no
+--echo # row_format specified at CREATE TABLE.
+SET GLOBAL innodb_default_row_format = COMPACT;
+CREATE TABLE t1 (a INT PRIMARY KEY, b TEXT) ENGINE=INNODB;
+INSERT INTO t1 VALUES (1, 'abc');
+
+--replace_column 3 # 5 # 6 # 7 # 8 # 9 # 10 # 12 # 13 #
+SHOW TABLE STATUS LIKE 't1';
+
+CREATE TABLE t2 (b VARCHAR(255) CHARACTER SET utf8mb4 NOT NULL) ENGINE=InnoDB;
+
+SET GLOBAL innodb_default_row_format = DYNAMIC;
+ALTER TABLE t1 DROP PRIMARY KEY, ADD COLUMN c INT PRIMARY KEY;
+
+--echo # Here we expect DYNAMIC because there is no explicit ROW_FORMAT and the
+--echo # default_row_format is changed to DYNAMIC just before ALTER
+--replace_column 3 # 5 # 6 # 7 # 8 # 9 # 10 # 12 # 13 #
+SHOW TABLE STATUS LIKE 't1';
+DROP TABLE t1;
+
+--error ER_INDEX_COLUMN_TOO_LONG
+ALTER TABLE t2 ADD INDEX(b);
+ALTER TABLE t2 FORCE, ADD INDEX(b);
+DROP TABLE t2;
+
+--echo ####################################
+--echo # Check the row_format effect on ALTER, ALGORITHM=COPY
+SET GLOBAL innodb_default_row_format = REDUNDANT;
+CREATE TABLE t1 (a INT PRIMARY KEY, b TEXT) ENGINE=INNODB;
+INSERT INTO t1 VALUES (1, REPEAT('abc',1000));
+
+--replace_column 3 # 5 # 6 # 7 # 8 # 9 # 10 # 12 # 13 #
+SHOW TABLE STATUS LIKE 't1';
+
+CREATE TABLE t2 (b VARCHAR(255) CHARACTER SET utf8mb4 NOT NULL) ENGINE=InnoDB;
+
+SET GLOBAL innoDB_default_row_format = COMPACT;
+ALTER TABLE t1 ADD COLUMN c2 BLOB, ALGORITHM=COPY;
+
+--echo # Because of ALGORITHM=COPY, there is TABLE REBUILD and the table isn't
+--echo # created with explicit row_format, so we expect ROW_FORMAT=COMPACT
+--replace_column 3 # 5 # 6 # 7 # 8 # 9 # 10 # 12 # 13 #
+SHOW TABLE STATUS LIKE 't1';
+DROP TABLE t1;
+
+--error ER_INDEX_COLUMN_TOO_LONG
+ALTER TABLE t2 ADD INDEX(b);
+--error ER_INDEX_COLUMN_TOO_LONG
+ALTER TABLE t2 FORCE, ADD INDEX(b);
+
+SET GLOBAL innodb_default_row_format = DYNAMIC;
+--error ER_INDEX_COLUMN_TOO_LONG
+ALTER TABLE t2 ADD INDEX(b);
+ALTER TABLE t2 FORCE, ADD INDEX(b);
+
+DROP TABLE t2;
+
+--echo
+--echo ###################################
+--echo # Check the row_format effect on ALTER, ALGORITHM=COPY on
+--echo # create table with explicit row_format
+CREATE TABLE t1 (a INT PRIMARY KEY, b TEXT) ROW_FORMAT=REDUNDANT ENGINE=INNODB;
+INSERT INTO t1 VALUES (1, REPEAT('abc',1000));
+
+--replace_column 3 # 5 # 6 # 7 # 8 # 9 # 10 # 12 # 13 #
+SHOW TABLE STATUS LIKE 't1';
+
+SET GLOBAL innoDB_default_row_format = COMPACT;
+ALTER TABLE t1 ADD COLUMN c2 BLOB, ALGORITHM=COPY;
+
+--echo # Because of ALGORITHM=COPY, there is TABLE REBUILD and the table is
+--echo # created with explicit row_format, so we expect original
+--echo # ROW_FORMAT=REDUNDANT
+--replace_column 3 # 5 # 6 # 7 # 8 # 9 # 10 # 12 # 13 #
+SHOW TABLE STATUS LIKE 't1';
+DROP TABLE t1;
+
+--echo
+--echo ##################################
+--echo # Check row_format on ALTER ALGORITHM=INPLACE
+SET GLOBAL innodb_default_row_format=COMPACT;
+
+CREATE TABLE t1 (a INT PRIMARY KEY, b TEXT, KEY k1(b(10))) ENGINE=INNODB;
+INSERT INTO t1 VALUES (1, REPEAT('abc',1000));
+
+--replace_column 3 # 5 # 6 # 7 # 8 # 9 # 10 # 12 # 13 #
+SHOW TABLE STATUS LIKE 't1';
+
+SET GLOBAL innodb_default_row_format=DYNAMIC;
+ALTER TABLE t1 DROP INDEX k1;
+
+--echo # Because it is in-place operation, there is no rebuild, so the
+--echo # original format has to be retained.
+--replace_column 3 # 5 # 6 # 7 # 8 # 9 # 10 # 12 # 13 #
+SHOW TABLE STATUS LIKE 't1';
+DROP TABLE t1;
+
+--echo #
+--echo # MDEV-24758 heap-use-after-poison in innobase_add_instant_try/rec_copy
+--echo #
+
+CREATE TABLE t1 (pk INT PRIMARY KEY) CHARACTER SET utf8 ENGINE=InnoDB;
+INSERT INTO t1 VALUES (1);
+SET GLOBAL innodb_default_row_format = REDUNDANT;
+ALTER TABLE t1 ADD a CHAR(8) DEFAULT '';
+DROP TABLE t1;
+SET GLOBAL innodb_default_row_format = @row_format;
+
+--echo # End of 10.3 tests
+
+--echo #
+--echo # MDEV-23295 Assertion fields[i].same(instant.fields[i]) failed
+--echo #
+SET GLOBAL innodb_default_row_format = @row_format;
+CREATE TABLE t1 (a char(8)) ENGINE=InnoDB DEFAULT CHARSET utf8;
+SET GLOBAL innodb_default_row_format= COMPACT;
+ALTER TABLE t1 ADD b INT;
+SELECT ROW_FORMAT FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME='t1';
+DROP TABLE t1;
+
+--echo #
+--echo # MDEV-23345 Assertion not_redundant() == old.not_redundant() failed
+--echo #
+SET GLOBAL innodb_default_row_format = @row_format;
+CREATE TABLE t1 (a INT PRIMARY KEY, b INT, KEY(b)) ENGINE=InnoDB;
+SET GLOBAL innodb_default_row_format= COMPACT;
+ALTER TABLE t1 DROP b;
+SELECT ROW_FORMAT FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME='t1';
+DROP TABLE t1;
+
+--echo #
+--echo # MDEV-31025 Redundant table alter fails when fixed column
+--echo # stored externally
+--echo #
+set @old_sql_mode = @@sql_mode;
+SET @@sql_mode='';
+CREATE TABLE t1(pk INT,c CHAR(255),c2 CHAR(255),c3 CHAR(255),
+ c4 char(255), c5 char(255), c6 char(255),
+ c7 char(255), c8 char(255), primary key(pk)
+ )Engine=InnoDB character set utf32 ROW_FORMAT=REDUNDANT;
+INSERT INTO t1(pk, c) VALUES (1, repeat('a', 255));
+ALTER TABLE t1 FORCE;
+CHECK TABLE t1;
+SELECT LENGTH(c) FROM t1;
+DROP TABLE t1;
+set @@sql_mode = @old_sql_mode;
+
+--echo # End of 10.4 tests
+
+SET GLOBAL innodb_default_row_format = @row_format;
diff --git a/mysql-test/suite/innodb/t/default_row_format_compatibility.test b/mysql-test/suite/innodb/t/default_row_format_compatibility.test
new file mode 100644
index 00000000..5ebbe200
--- /dev/null
+++ b/mysql-test/suite/innodb/t/default_row_format_compatibility.test
@@ -0,0 +1,174 @@
+--source include/have_innodb.inc
+
+call mtr.add_suppression("Index for table 'tab' is corrupt; try to repair it");
+
+
+SET @row_format = @@GLOBAL.innodb_default_row_format;
+
+# set the variables
+let $MYSQLD_DATADIR = `SELECT @@datadir`;
+
+--echo # ###########################################################
+--echo # Check with Import/Export tablespace with Default_row_format
+
+# Set row_format=Compact
+SET GLOBAL innodb_default_row_format=Compact;
+
+# Check row_format=Compact
+SELECT @@innodb_default_row_format;
+
+# Check file_per_table=1
+SELECT @@innodb_file_per_table;
+
+CREATE TABLE tab(a INT) ENGINE=InnoDB;
+--replace_column 3 # 5 # 6 # 7 # 8 # 9 # 10 # 12 #
+SHOW TABLE STATUS LIKE 'tab';
+
+INSERT INTO tab VALUES(1);
+INSERT INTO tab VALUES(2);
+
+# Check the rows
+SELECT * FROM tab;
+
+FLUSH TABLE tab FOR EXPORT;
+
+# Take the backup of the ibd and cfg files
+--copy_file $MYSQLD_DATADIR/test/tab.cfg $MYSQLD_DATADIR/tab.cfg
+--copy_file $MYSQLD_DATADIR/test/tab.ibd $MYSQLD_DATADIR/tab.ibd
+
+UNLOCK TABLES;
+
+# Cleanup
+DROP TABLE tab;
+
+# Set the default_row_format=Dynamic
+SET GLOBAL innodb_default_row_format=Dynamic;
+
+CREATE TABLE tab(a INT) ENGINE=InnoDB;
+
+# Remove the *.ibd file
+ALTER TABLE tab DISCARD TABLESPACE;
+
+# Move the *.ibd,*.cfg file into original location
+--move_file $MYSQLD_DATADIR/tab.cfg $MYSQLD_DATADIR/test/tab.cfg
+--move_file $MYSQLD_DATADIR/tab.ibd $MYSQLD_DATADIR/test/tab.ibd
+
+--error ER_TABLE_SCHEMA_MISMATCH
+ALTER TABLE tab IMPORT TABLESPACE;
+
+--move_file $MYSQLD_DATADIR/test/tab.cfg $MYSQLD_DATADIR/tab.cfg
+--move_file $MYSQLD_DATADIR/test/tab.ibd $MYSQLD_DATADIR/tab.ibd
+
+# Cleanup
+DROP TABLE tab;
+
+# Set the default_row_format=Compact
+SET GLOBAL innodb_default_row_format=Compact;
+
+# Check row_format=Compact
+SELECT @@innodb_default_row_format;
+
+CREATE TABLE tab(a INT) ENGINE=InnoDB;
+--replace_column 3 # 5 # 6 # 7 # 8 # 9 # 10 # 12 #
+SHOW TABLE STATUS LIKE 'tab';
+
+# Remove the *.ibd file
+ALTER TABLE tab DISCARD TABLESPACE;
+
+# Move the *ibd,*.cfg file into orginal location
+--copy_file $MYSQLD_DATADIR/tab.cfg $MYSQLD_DATADIR/test/tab.ibd
+--move_file $MYSQLD_DATADIR/tab.cfg $MYSQLD_DATADIR/test/tab.cfg
+
+call mtr.add_suppression("InnoDB: Tried to read .* bytes at offset 0");
+
+--error ER_NOT_KEYFILE
+ALTER TABLE tab IMPORT TABLESPACE;
+--remove_file $MYSQLD_DATADIR/test/tab.ibd
+--move_file $MYSQLD_DATADIR/tab.ibd $MYSQLD_DATADIR/test/tab.ibd
+
+# Check import is successful (because same row_format)
+ALTER TABLE tab IMPORT TABLESPACE;
+
+# Check the rows
+SELECT * FROM tab;
+
+# Cleanup
+DROP TABLE tab;
+
+--echo # ###########################################################
+# Check when Index Column size (3070 bytes) is too long, Change row_format
+# Check when Index Column size (767 bytes), Change row_format
+# Dynamic to Compact to Dynamic
+
+# Set the default_row_format=Dynamic
+SET GLOBAL innodb_default_row_format=Dynamic;
+
+SELECT @@innodb_default_row_format;
+
+CREATE TABLE tab(a INT PRIMARY KEY, b VARCHAR(5000), KEY idx1(b(3070))) ENGINE= InnoDB;
+--replace_column 3 # 5 # 6 # 7 # 8 # 9 # 10 # 12 #
+SHOW TABLE STATUS LIKE 'tab';
+
+INSERT INTO tab(a,b) VALUES(1,'Check with max column size');
+
+# Check by SELECT, no errors
+SELECT * FROM tab;
+
+# Change row_format to Compact
+SET GLOBAL innodb_default_row_format=COMPACT;
+
+# Check error ERROR 1709 (HY000): Index column size too large
+-- error ER_INDEX_COLUMN_TOO_LONG
+ALTER TABLE tab ROW_FORMAT=COMPACT;
+
+# Cleanup
+DROP TABLE tab;
+
+# Change the default_row_format to default
+SET GLOBAL innodb_default_row_format=Default;
+SELECT @@innodb_default_row_format;
+SET GLOBAL innodb_default_row_format=Dynamic;
+
+# Change row_format to Dynamic
+SELECT @@innodb_default_row_format;
+
+CREATE TABLE tab(a INT PRIMARY KEY, b VARCHAR(5000), KEY idx1(b(767))) ENGINE= InnoDB;
+--replace_column 3 # 5 # 6 # 7 # 8 # 9 # 10 # 12 #
+SHOW TABLE STATUS LIKE 'tab';
+
+INSERT INTO tab(a,b) VALUES(1,'Check with max column size');
+
+# Check by SELECT, no errors
+SELECT * FROM tab;
+
+# Check no errors because Compact allows 767 bytes
+ALTER TABLE tab ROW_FORMAT=COMPACT;
+--replace_column 3 # 5 # 6 # 7 # 8 # 9 # 10 # 12 #
+SHOW TABLE STATUS LIKE 'tab';
+
+# Check by SELECT, no errors
+SELECT * FROM tab;
+
+SET @save_innodb_read_only_compressed=@@GLOBAL.innodb_read_only_compressed;
+SET GLOBAL innodb_read_only_compressed=ON;
+
+--error ER_UNSUPPORTED_COMPRESSED_TABLE
+ALTER TABLE tab ROW_FORMAT=COMPRESSED;
+SET GLOBAL innodb_read_only_compressed=OFF;
+ALTER TABLE tab ROW_FORMAT=COMPRESSED;
+SET GLOBAL innodb_read_only_compressed=ON;
+
+# Check by SELECT, no errors
+SELECT * FROM tab;
+
+ALTER TABLE tab ROW_FORMAT=Dynamic;
+SET GLOBAL innodb_read_only_compressed=@save_innodb_read_only_compressed;
+
+# Check no errors
+--replace_column 3 # 5 # 6 # 7 # 8 # 9 # 10 # 12 #
+SHOW TABLE STATUS LIKE 'tab';
+
+# Cleanup
+DROP TABLE tab;
+
+SET GLOBAL innodb_default_row_format = @row_format;
diff --git a/mysql-test/suite/innodb/t/default_row_format_create.test b/mysql-test/suite/innodb/t/default_row_format_create.test
new file mode 100644
index 00000000..cd497d74
--- /dev/null
+++ b/mysql-test/suite/innodb/t/default_row_format_create.test
@@ -0,0 +1,81 @@
+--source include/have_innodb.inc
+--source include/innodb_row_format.inc
+
+CREATE TABLE t1(c1 TEXT,c2 BLOB) ENGINE=InnoDB;
+--replace_column 3 # 5 # 6 # 7 # 8 # 9 # 10 # 12 #
+SHOW TABLE STATUS LIKE 't1';
+DROP TABLE t1;
+
+CREATE TABLE t1(c1 TEXT,c2 BLOB) ENGINE=InnoDB ROW_FORMAT=DYNAMIC;
+--replace_column 3 # 5 # 6 # 7 # 8 # 9 # 10 # 12 #
+SHOW TABLE STATUS LIKE 't1';
+DROP TABLE t1;
+
+CREATE TABLE t1(c1 TEXT,c2 BLOB) ENGINE=InnoDB ROW_FORMAT=COMPACT;
+--replace_column 3 # 5 # 6 # 7 # 8 # 9 # 10 # 12 #
+SHOW TABLE STATUS LIKE 't1';
+DROP TABLE t1;
+
+CREATE TABLE t1(c1 TEXT,c2 BLOB) ENGINE=InnoDB ROW_FORMAT=REDUNDANT;
+--replace_column 3 # 5 # 6 # 7 # 8 # 9 # 10 # 12 #
+SHOW TABLE STATUS LIKE 't1';
+DROP TABLE t1;
+
+--disable_query_log
+SET @save_innodb_read_only_compressed=@@GLOBAL.innodb_read_only_compressed;
+SET GLOBAL innodb_read_only_compressed=OFF;
+--enable_query_log
+CREATE TABLE t1(c1 TEXT,c2 BLOB) ENGINE=InnoDB
+ROW_FORMAT=COMPRESSED;
+--replace_column 3 # 5 # 6 # 7 # 8 # 9 # 10 # 12 #
+SHOW TABLE STATUS LIKE 't1';
+TRUNCATE TABLE t1;
+--replace_column 3 # 5 # 6 # 7 # 8 # 9 # 10 # 12 #
+SHOW TABLE STATUS LIKE 't1';
+--disable_query_log
+SET GLOBAL innodb_read_only_compressed=@save_innodb_read_only_compressed;
+--enable_query_log
+DROP TABLE t1;
+
+--error 0,ER_CANT_CREATE_TABLE
+CREATE TABLE t1 (c1 INT) ENGINE=InnoDB page_compressed=1;
+--replace_column 3 # 5 # 6 # 7 # 8 # 9 # 10 # 12 #
+SHOW TABLE STATUS LIKE 't1';
+DROP TABLE IF EXISTS t1;
+
+SET @save_format = @@GLOBAL.innodb_default_row_format;
+SET GLOBAL innodb_default_row_format = redundant;
+CREATE TABLE t1 (c1 INT) ENGINE=InnoDB;
+SET GLOBAL innodb_default_row_format = @save_format;
+TRUNCATE TABLE t1;
+--replace_column 3 # 5 # 6 # 7 # 8 # 9 # 10 # 12 #
+SHOW TABLE STATUS LIKE 't1';
+DROP TABLE t1;
+
+SET @save_level=@@GLOBAL.innodb_compression_level;
+SET GLOBAL innodb_compression_level=0;
+--error ER_CANT_CREATE_TABLE
+CREATE TABLE t(c INT) ENGINE=InnoDB page_compressed=1;
+SHOW WARNINGS;
+--disable_warnings
+--error 0,ER_CANT_CREATE_TABLE
+CREATE TABLE t(c INT) ENGINE=InnoDB page_compressed=1 page_compression_level=1;
+DROP TABLE IF EXISTS t;
+SET GLOBAL innodb_compression_level=1;
+--error 0,ER_CANT_CREATE_TABLE
+CREATE TABLE t(c INT) ENGINE=InnoDB page_compressed=1;
+DROP TABLE IF EXISTS t;
+--enable_warnings
+
+SET GLOBAL innodb_compression_level=1;
+CREATE TABLE t(a INT)ENGINE=InnoDB ROW_FORMAT=DYNAMIC page_compressed=1;
+CREATE TEMPORARY TABLE tt(a INT PRIMARY KEY)
+ROW_FORMAT=DYNAMIC page_compressed=1 ENGINE=InnoDB;
+SET GLOBAL innodb_compression_level=0;
+--error ER_ILLEGAL_HA_CREATE_OPTION
+ALTER TABLE t FORCE, ROW_FORMAT=DEFAULT, ALGORITHM=INPLACE;
+--error ER_CANT_CREATE_TABLE
+ALTER TABLE t FORCE, ROW_FORMAT=DEFAULT, ALGORITHM=COPY;
+DROP TABLE t;
+TRUNCATE tt;
+SET GLOBAL innodb_compression_level=@save_level;
diff --git a/mysql-test/suite/innodb/t/defrag_mdl-9155.test b/mysql-test/suite/innodb/t/defrag_mdl-9155.test
new file mode 100644
index 00000000..1e1efb9c
--- /dev/null
+++ b/mysql-test/suite/innodb/t/defrag_mdl-9155.test
@@ -0,0 +1,22 @@
+#
+# MDEV-9155 Enabling Defragmenting in 10.1.8 still causes OPTIMIZE TABLE to take metadatalocks
+#
+source include/have_innodb.inc;
+source include/have_sequence.inc;
+
+set global innodb_defragment=1;
+create table t1 (a int not null primary key auto_increment, b varchar(256), key second(a, b)) engine=innodb;
+insert t1 select null, repeat('a', 256) from seq_1_to_100;
+select count(*) from t1;
+
+connect (con1,localhost,root);
+start transaction;
+select count(*) from t1;
+
+connection default;
+optimize table t1;
+
+connection con1;
+drop table t1;
+
+set global innodb_defragment=default;
diff --git a/mysql-test/suite/innodb/t/dml_purge.test b/mysql-test/suite/innodb/t/dml_purge.test
new file mode 100644
index 00000000..463ae390
--- /dev/null
+++ b/mysql-test/suite/innodb/t/dml_purge.test
@@ -0,0 +1,78 @@
+--source include/innodb_page_size.inc
+
+let INNODB_PAGE_SIZE=`select @@innodb_page_size`;
+let MYSQLD_DATADIR=`select @@datadir`;
+
+--echo #
+--echo # MDEV-12288 Reset DB_TRX_ID when the history is removed,
+--echo # to speed up MVCC
+--echo #
+
+CREATE TABLE t1(a INT PRIMARY KEY, b INT NOT NULL)
+ROW_FORMAT=REDUNDANT ENGINE=InnoDB;
+--source include/wait_all_purged.inc
+
+--connect (prevent_purge,localhost,root)
+START TRANSACTION WITH CONSISTENT SNAPSHOT;
+
+--connection default
+INSERT INTO t1 VALUES(1,2),(3,4);
+ALTER TABLE t1 ADD COLUMN c INT;
+UPDATE t1 SET b=-3 WHERE a=3;
+
+--connect (con1,localhost,root)
+BEGIN;
+# For purgeable records, we must record DB_TRX_ID=0 in the undo log!
+UPDATE t1 SET b=4 WHERE a=3;
+--disconnect prevent_purge
+
+--connection default
+# Initiate a full purge, which should reset the DB_TRX_ID except for a=3.
+SET GLOBAL innodb_max_purge_lag_wait=1;
+# Initiate a ROLLBACK of the update, which should reset the DB_TRX_ID for a=3.
+--connection con1
+ROLLBACK;
+--disconnect con1
+--connection default
+# Reset the DB_TRX_ID for the hidden ADD COLUMN metadata record.
+--source include/wait_all_purged.inc
+
+FLUSH TABLE t1 FOR EXPORT;
+# The following is based on innodb.table_flags:
+--perl
+use strict;
+my $ps= $ENV{INNODB_PAGE_SIZE};
+my $file= "$ENV{MYSQLD_DATADIR}/test/t1.ibd";
+open(FILE, "<", $file) || die "Unable to open $file\n";
+my $page;
+print "Clustered index root page contents:\n";
+sysseek(FILE, 3*$ps, 0) || die "Unable to seek $file";
+die "Unable to read $file" unless sysread(FILE, $page, $ps) == $ps;
+print "N_RECS=", unpack("n", substr($page,38+16,2));
+print "; LEVEL=", unpack("n", substr($page,38+26,2)), "\n";
+my @fields=qw(a DB_TRX_ID DB_ROLL_PTR b c);
+for (my $offset= 0x65; $offset;
+ $offset= unpack("n", substr($page,$offset-2,2)))
+{
+ print "header=0x", unpack("H*",substr($page,$offset-6,6)), " (";
+ my $n_fields= unpack("n", substr($page,$offset-4,2)) >> 1 & 0x3ff;
+ my $start= 0;
+ my $name;
+ for (my $i= 0; $i < $n_fields; $i++) {
+ my $end= unpack("C", substr($page, $offset-7-$i, 1));
+ print ",\n " if $i;
+ print "$fields[$i]=";
+ if ($end & 0x80) {
+ print "NULL(", ($end & 0x7f) - $start, " bytes)"
+ } else {
+ print "0x", unpack("H*", substr($page,$offset+$start,$end-$start))
+ }
+ $start= $end & 0x7f;
+ }
+ print ")\n";
+}
+close(FILE) || die "Unable to close $file\n";
+EOF
+UNLOCK TABLES;
+SELECT * FROM t1;
+DROP TABLE t1;
diff --git a/mysql-test/suite/innodb/t/doublewrite.combinations b/mysql-test/suite/innodb/t/doublewrite.combinations
new file mode 100644
index 00000000..4f52013f
--- /dev/null
+++ b/mysql-test/suite/innodb/t/doublewrite.combinations
@@ -0,0 +1,7 @@
+[strict_crc32]
+--innodb-checksum-algorithm=strict_crc32
+--innodb-use-atomic-writes=0
+
+[strict_full_crc32]
+--innodb-checksum-algorithm=strict_full_crc32
+--innodb-use-atomic-writes=0
diff --git a/mysql-test/suite/innodb/t/doublewrite.test b/mysql-test/suite/innodb/t/doublewrite.test
new file mode 100644
index 00000000..d8dac955
--- /dev/null
+++ b/mysql-test/suite/innodb/t/doublewrite.test
@@ -0,0 +1,467 @@
+--echo #
+--echo # Bug #17335427 INNODB CAN NOT USE THE DOUBLEWRITE BUFFER PROPERLY
+--echo # Bug #18144349 INNODB CANNOT USE THE DOUBLEWRITE BUFFER FOR THE FIRST
+--echo # PAGE OF SYSTEM TABLESPACE
+--echo #
+
+--source include/innodb_page_size.inc
+--source include/have_debug.inc
+--source include/not_embedded.inc
+# This test is slow on buildbot.
+--source include/big_test.inc
+
+# Slow shutdown and restart to make sure ibuf merge is finished
+SET GLOBAL innodb_fast_shutdown = 0;
+--disable_query_log
+call mtr.add_suppression("InnoDB: Data file .* uses page size .* but the innodb_page_size start-up parameter is");
+call mtr.add_suppression("InnoDB: adjusting FSP_SPACE_FLAGS");
+call mtr.add_suppression("InnoDB: New log files created");
+call mtr.add_suppression("InnoDB: Cannot create doublewrite buffer: the first file in innodb_data_file_path must be at least (3|6|12)M\\.");
+call mtr.add_suppression("InnoDB: Database creation was aborted");
+call mtr.add_suppression("Plugin 'InnoDB' (init function returned error|registration as a STORAGE ENGINE failed)");
+call mtr.add_suppression("InnoDB: A bad Space ID was found in datafile");
+call mtr.add_suppression("InnoDB: Checksum mismatch in datafile: ");
+call mtr.add_suppression("InnoDB: Inconsistent tablespace ID in .*t1\\.ibd");
+--enable_query_log
+--source include/restart_mysqld.inc
+
+let INNODB_PAGE_SIZE=`select @@innodb_page_size`;
+let MYSQLD_DATADIR=`select @@datadir`;
+let ALGO=`select @@innodb_checksum_algorithm`;
+let SEARCH_FILE= $MYSQLTEST_VARDIR/log/mysqld.1.err;
+
+show variables like 'innodb_doublewrite';
+show variables like 'innodb_fil_make_page_dirty_debug';
+show variables like 'innodb_saved_page_number_debug';
+
+connect (stop_purge,localhost,root,,);
+START TRANSACTION WITH CONSISTENT SNAPSHOT;
+connection default;
+
+create table t1 (f1 int primary key, f2 blob) engine=innodb stats_persistent=0;
+
+start transaction;
+insert into t1 values(1, repeat('#',12));
+insert into t1 values(2, repeat('+',12));
+insert into t1 values(3, repeat('/',12));
+insert into t1 values(4, repeat('-',12));
+insert into t1 values(5, repeat('.',12));
+commit work;
+
+--echo # ---------------------------------------------------------------
+--echo # Test Begin: Test if recovery works if first page of user
+--echo # tablespace is full of zeroes.
+
+select space into @space_id from information_schema.innodb_sys_tables
+where name = 'test/t1';
+
+begin;
+insert into t1 values (6, repeat('%', 12));
+--echo # Ensure that dirty pages of table t1 are flushed.
+set global innodb_buf_flush_list_now = 1;
+
+--source ../include/no_checkpoint_start.inc
+
+--echo # Make the first page dirty for table t1
+set global innodb_saved_page_number_debug = 0;
+set global innodb_fil_make_page_dirty_debug = @space_id;
+
+--echo # Ensure that dirty pages of table t1 are flushed.
+set global innodb_buf_flush_list_now = 1;
+
+--let CLEANUP_IF_CHECKPOINT=drop table t1;
+--source ../include/no_checkpoint_end.inc
+disconnect stop_purge;
+
+--echo # Make the first page (page_no=0) of the user tablespace
+--echo # full of zeroes.
+--echo #
+--echo # MDEV-11623: Use old FSP_SPACE_FLAGS in the doublewrite buffer.
+
+perl;
+use IO::Handle;
+do "$ENV{MTR_SUITE_DIR}/include/crc32.pl";
+my $polynomial = 0x82f63b78; # CRC-32C
+my $algo = $ENV{ALGO};
+die "Unsupported innodb_checksum_algorithm=$algo\n" unless $algo =~ /crc32/;
+
+my $fname= "$ENV{'MYSQLD_DATADIR'}test/t1.ibd";
+my $page_size = $ENV{INNODB_PAGE_SIZE};
+my $page;
+do "$ENV{MTR_SUITE_DIR}/../innodb/include/crc32.pl";
+open(FILE, "+<", $fname) or die;
+sysread(FILE, $page, $page_size)==$page_size||die "Unable to read $name\n";
+my $page1 = $page;
+substr($page1, 34, 4) = pack("N", 0);
+my $polynomial0 = 0x82f63b78; # CRC-32C
+my $ck0 = mycrc32(substr($page1, 0, ($page_size-4)), 0, $polynomial0);
+substr($page1, ($page_size - 4), 4) = pack("N", $ck0);
+sysseek(FILE, 0, 0)||die "Unable to seek $fname\n";
+die unless syswrite(FILE, $page1, $page_size) == $page_size;
+close FILE;
+
+open(FILE, "+<", "$ENV{MYSQLD_DATADIR}ibdata1")||die "cannot open ibdata1\n";
+sysseek(FILE, 6 * $page_size - 190, 0)||die "Unable to seek ibdata1\n";
+sysread(FILE, $_, 12) == 12||die "Unable to read TRX_SYS\n";
+my($magic,$d1,$d2)=unpack "NNN", $_;
+die "magic=$magic, $d1, $d2\n" unless $magic == 536853855 && $d2 >= $d1 + 64;
+sysseek(FILE, $d1 * $page_size, 0)||die "Unable to seek ibdata1\n";
+# Find the page in the doublewrite buffer
+for (my $d = $d1; $d < $d2 + 64; $d++)
+{
+ sysread(FILE, $_, $page_size)==$page_size||die "Cannot read doublewrite\n";
+ next unless $_ eq $page;
+ sysseek(FILE, $d * $page_size, 0)||die "Unable to seek ibdata1\n";
+ # Write buggy MariaDB 10.1.x FSP_SPACE_FLAGS to the doublewrite buffer
+ my($flags) = unpack "x[54]N", $_;
+ my $badflags = ($flags & 0x3f);
+ my $compression_level=6;
+ $badflags |= 1<<6|$compression_level<<7 if ($flags & 1 << 16);
+ $badflags |= ($flags & 15 << 6) << 7; # PAGE_SSIZE
+
+ substr ($_, 54, 4) = pack("N", $badflags);
+ if ($algo =~ /full_crc32/)
+ {
+ my $ck = mycrc32(substr($_, 0, $page_size - 4), 0, $polynomial);
+ substr($_, $page_size - 4, 4) = pack("N", $ck);
+ }
+ else
+ {
+ # Replace the innodb_checksum_algorithm=crc32 checksum
+ my $ck= pack("N",
+ mycrc32(substr($_, 4, 22), 0, $polynomial) ^
+ mycrc32(substr($_, 38, $page_size - 38 - 8), 0,
+ $polynomial));
+ substr ($_, 0, 4) = $ck;
+ substr ($_, $page_size - 8, 4) = $ck;
+ }
+ syswrite(FILE, $_, $page_size)==$page_size||die;
+ close(FILE);
+ exit 0;
+}
+die "Did not find the page in the doublewrite buffer ($d1,$d2)\n";
+EOF
+
+--source include/start_mysqld.inc
+
+check table t1;
+select f1, f2 from t1;
+
+--echo # Test End
+--echo # ---------------------------------------------------------------
+--echo # Test Begin: Test if recovery works if first page of user
+--echo # tablespace is corrupted.
+
+select space into @space_id from information_schema.innodb_sys_tables
+where name = 'test/t1';
+
+--echo # Ensure that dirty pages of table t1 is flushed.
+flush tables t1 for export;
+unlock tables;
+
+set global innodb_log_checkpoint_now=1;
+
+begin;
+insert into t1 values (6, repeat('%', 12));
+
+--source ../include/no_checkpoint_start.inc
+
+--echo # Make the first page dirty for table t1
+set global innodb_saved_page_number_debug = 0;
+set global innodb_fil_make_page_dirty_debug = @space_id;
+
+--echo # Ensure that dirty pages of table t1 are flushed.
+set global innodb_buf_flush_list_now = 1;
+
+--source include/no_checkpoint_end.inc
+
+--echo # Corrupt the first page (page_no=0) of the user tablespace.
+perl;
+use IO::Handle;
+my $fname= "$ENV{'MYSQLD_DATADIR'}test/t1.ibd";
+my $page_size = $ENV{INNODB_PAGE_SIZE};
+open(FILE, "+<", $fname) or die;
+sysread(FILE, $page, $page_size)==$page_size||die "Unable to read $name\n";
+substr($page, 28, 4) = pack("N", 1000);
+sysseek(FILE, 0, 0)||die "Unable to seek $fname\n";
+die unless syswrite(FILE, $page, $page_size) == $page_size;
+close FILE;
+EOF
+
+--source include/start_mysqld.inc
+
+check table t1;
+select f1, f2 from t1;
+
+--echo # Test End
+--echo # ---------------------------------------------------------------
+--echo # Test Begin: Test if recovery works if 2nd page of user
+--echo # tablespace is full of zeroes.
+
+select space into @space_id from information_schema.innodb_sys_tables
+where name = 'test/t1';
+
+--echo # Ensure that dirty pages of table t1 is flushed.
+flush tables t1 for export;
+unlock tables;
+
+begin;
+insert into t1 values (6, repeat('%', 400));
+
+--source ../include/no_checkpoint_start.inc
+
+--echo # Make the 2nd page dirty for table t1
+set global innodb_saved_page_number_debug = 1;
+set global innodb_fil_make_page_dirty_debug = @space_id;
+
+--echo # Ensure that dirty pages of table t1 are flushed.
+set global innodb_buf_flush_list_now = 1;
+
+--source include/no_checkpoint_end.inc
+
+--echo # Make the 2nd page (page_no=1) of the tablespace all zeroes.
+perl;
+use IO::Handle;
+my $fname= "$ENV{'MYSQLD_DATADIR'}test/t1.ibd";
+open(FILE, "+<", $fname) or die;
+FILE->autoflush(1);
+binmode FILE;
+seek(FILE, $ENV{'INNODB_PAGE_SIZE'}, SEEK_SET);
+print FILE chr(0) x ($ENV{'INNODB_PAGE_SIZE'});
+close FILE;
+EOF
+
+--source include/start_mysqld.inc
+
+check table t1;
+select f1, f2 from t1;
+
+--echo # Test End
+--echo # ---------------------------------------------------------------
+--echo # Test Begin: Test if recovery works if 2nd page of user
+--echo # tablespace is corrupted.
+
+select space into @space_id from information_schema.innodb_sys_tables
+where name = 'test/t1';
+
+--echo # Ensure that dirty pages of table t1 is flushed.
+flush tables t1 for export;
+unlock tables;
+
+begin;
+insert into t1 values (6, repeat('%', 400));
+
+--source ../include/no_checkpoint_start.inc
+
+--echo # Make the 2nd page dirty for table t1
+set global innodb_saved_page_number_debug = 1;
+set global innodb_fil_make_page_dirty_debug = @space_id;
+
+--echo # Ensure that the dirty pages of table t1 are flushed.
+set global innodb_buf_flush_list_now = 1;
+
+--source include/no_checkpoint_end.inc
+
+--echo # Corrupt the 2nd page (page_no=1) of the user tablespace.
+perl;
+use IO::Handle;
+my $fname= "$ENV{'MYSQLD_DATADIR'}test/t1.ibd";
+open(FILE, "+<", $fname) or die;
+FILE->autoflush(1);
+binmode FILE;
+seek(FILE, $ENV{'INNODB_PAGE_SIZE'}, SEEK_SET);
+print FILE chr(0) x ($ENV{'INNODB_PAGE_SIZE'}/2);
+close FILE;
+EOF
+
+--source include/start_mysqld.inc
+
+check table t1;
+select f1, f2 from t1;
+
+--echo # Test End
+--echo # ---------------------------------------------------------------
+--echo # Test Begin: Test if recovery works if first page of
+--echo # system tablespace is full of zeroes.
+
+begin;
+insert into t1 values (6, repeat('%', 400));
+
+--echo # Ensure that all dirty pages in the system are flushed.
+set global innodb_buf_flush_list_now = 1;
+
+--echo # Make the first page dirty for system tablespace
+set global innodb_saved_page_number_debug = 0;
+set global innodb_fil_make_page_dirty_debug = 0;
+
+--echo # Ensure that the dirty page of system tablespace is also flushed.
+# We do this after the transaction starts and all dirty pages have been flushed
+# already. So flushing of this specified dirty page will surely keep the
+# copy in doublewrite buffer, and no more writes to doublewrite buffer would
+# overwrite the copy. Thus, we can safely modify the original page when server
+# is down. So do the following testings.
+set global innodb_buf_flush_list_now = 1;
+
+--source include/kill_mysqld.inc
+
+--echo # Make the first page (page_no=0) of the system tablespace
+--echo # all zeroes.
+perl;
+use IO::Handle;
+my $fname= "$ENV{'MYSQLD_DATADIR'}ibdata1";
+open(FILE, "+<", $fname) or die;
+FILE->autoflush(1);
+binmode FILE;
+print FILE chr(0) x ($ENV{'INNODB_PAGE_SIZE'});
+close FILE;
+EOF
+
+--source include/start_mysqld.inc
+
+check table t1;
+select f1, f2 from t1;
+
+--echo # Test End
+--echo # ---------------------------------------------------------------
+--echo # Test Begin: Test if recovery works if first page of
+--echo # system tablespace is corrupted.
+
+begin;
+insert into t1 values (6, repeat('%', 400));
+
+--echo # Ensure that all dirty pages in the system are flushed.
+set global innodb_buf_flush_list_now = 1;
+
+--echo # Make the first page dirty for system tablespace
+set global innodb_saved_page_number_debug = 0;
+set global innodb_fil_make_page_dirty_debug = 0;
+
+--echo # Ensure that the dirty page of system tablespace is also flushed.
+set global innodb_buf_flush_list_now = 1;
+
+--source include/kill_mysqld.inc
+
+--echo # Corrupt the first page (page_no=0) of the system tablespace.
+perl;
+use IO::Handle;
+my $fname= "$ENV{'MYSQLD_DATADIR'}ibdata1";
+open(FILE, "+<", $fname) or die;
+FILE->autoflush(1);
+binmode FILE;
+print FILE chr(0) x ($ENV{'INNODB_PAGE_SIZE'}/2);
+close FILE;
+EOF
+
+--source include/start_mysqld.inc
+
+check table t1;
+select f1, f2 from t1;
+
+--echo # Test End
+--echo # ---------------------------------------------------------------
+--echo # Test Begin: Test if recovery works if 2nd page of
+--echo # system tablespace is full of zeroes.
+
+begin;
+insert into t1 values (6, repeat('%', 400));
+
+--echo # Ensure that all dirty pages in the system are flushed.
+set global innodb_buf_flush_list_now = 1;
+
+--echo # Make the second page dirty for system tablespace
+set global innodb_saved_page_number_debug = 1;
+set global innodb_fil_make_page_dirty_debug = 0;
+
+--echo # Ensure that the dirty page of system tablespace is also flushed.
+set global innodb_buf_flush_list_now = 1;
+
+--source include/kill_mysqld.inc
+
+--echo # Make the 2nd page (page_no=1) of the system tablespace
+--echo # all zeroes.
+perl;
+use IO::Handle;
+my $fname= "$ENV{'MYSQLD_DATADIR'}ibdata1";
+open(FILE, "+<", $fname) or die;
+FILE->autoflush(1);
+binmode FILE;
+seek(FILE, $ENV{'INNODB_PAGE_SIZE'}, SEEK_SET);
+print FILE chr(0) x ($ENV{'INNODB_PAGE_SIZE'});
+close FILE;
+EOF
+
+--source include/start_mysqld.inc
+
+check table t1;
+select f1, f2 from t1;
+
+--echo # Test End
+--echo # ---------------------------------------------------------------
+--echo # Test Begin: Test if recovery works if 2nd page of
+--echo # system tablespace is corrupted.
+
+begin;
+insert into t1 values (6, repeat('%', 400));
+
+--echo # Ensure that all dirty pages in the system are flushed.
+set global innodb_buf_flush_list_now = 1;
+
+--echo # Make the second page dirty for system tablespace
+set global innodb_saved_page_number_debug = 1;
+set global innodb_fil_make_page_dirty_debug = 0;
+
+--echo # Ensure that the dirty page of system tablespace is also flushed.
+set global innodb_buf_flush_list_now = 1;
+
+--source include/kill_mysqld.inc
+
+--echo # Make the 2nd page (page_no=1) of the system tablespace
+--echo # all zeroes.
+perl;
+use IO::Handle;
+my $fname= "$ENV{'MYSQLD_DATADIR'}ibdata1";
+open(FILE, "+<", $fname) or die;
+FILE->autoflush(1);
+binmode FILE;
+seek(FILE, $ENV{'INNODB_PAGE_SIZE'}, SEEK_SET);
+print FILE chr(0) x ($ENV{'INNODB_PAGE_SIZE'}/2);
+close FILE;
+EOF
+
+--source include/start_mysqld.inc
+
+check table t1;
+--let SEARCH_PATTERN= InnoDB: .*test.t1\\.ibd
+--source include/search_pattern_in_file.inc
+
+select f1, f2 from t1;
+
+drop table t1;
+
+--echo #
+--echo # MDEV-12600 crash during install_db with innodb_page_size=32K
+--echo # and ibdata1=3M
+--echo #
+let bugdir= $MYSQLTEST_VARDIR/tmp/doublewrite;
+--mkdir $bugdir
+
+let $check_no_innodb=SELECT * FROM INFORMATION_SCHEMA.ENGINES
+WHERE engine = 'innodb'
+AND support IN ('YES', 'DEFAULT', 'ENABLED');
+
+--let $ibp=--innodb-log-group-home-dir=$bugdir --innodb-data-home-dir=$bugdir
+--let $ibd=$ibp --innodb-undo-tablespaces=0
+--let $ibp=$ibp --innodb-data-file-path=ibdata1:1M;ibdata2:1M:autoextend
+
+--let $restart_parameters= $ibp
+--source include/restart_mysqld.inc
+eval $check_no_innodb;
+--let SEARCH_PATTERN= \[ERROR\] InnoDB: Cannot create doublewrite buffer
+--source include/search_pattern_in_file.inc
+--let $restart_parameters=
+--source include/restart_mysqld.inc
+
+--remove_file $bugdir/ibdata1
+--remove_file $bugdir/ibdata2
+--remove_file $bugdir/ib_logfile0
+--rmdir $bugdir
diff --git a/mysql-test/suite/innodb/t/dropdb.test b/mysql-test/suite/innodb/t/dropdb.test
new file mode 100644
index 00000000..f27aede7
--- /dev/null
+++ b/mysql-test/suite/innodb/t/dropdb.test
@@ -0,0 +1,27 @@
+--source include/have_innodb.inc
+
+SET NAMES utf8;
+call mtr.add_suppression("Invalid .old.. table or database name");
+
+--echo #
+--echo # Bug #19929435 DROP DATABASE HANGS WITH MALFORMED TABLE
+--echo #
+
+set session default_storage_engine=innodb;
+create database `b`;
+use `b`;
+--error ER_WRONG_TABLE_NAME
+create table `#mysql50#q.q` select 1;
+create table `#mysql50#q·q` select 1;
+drop database `b`;
+
+--echo #
+--echo # MDEV-27336 Crash on DROP DATABASE due to out-of-bounds result
+--echo # from InnoDB SUBSTR() function
+--echo #
+USE test;
+CREATE TABLE t1(a INT PRIMARY KEY) ENGINE=InnoDB;
+CREATE TABLE t2(a INT PRIMARY KEY REFERENCES t1(a)) ENGINE=InnoDB;
+CREATE DATABASE somewhat_longer_name_to_cause_trouble;
+DROP DATABASE somewhat_longer_name_to_cause_trouble;
+DROP TABLE t2,t1;
diff --git a/mysql-test/suite/innodb/t/dropdb_cs.test b/mysql-test/suite/innodb/t/dropdb_cs.test
new file mode 100644
index 00000000..0053ca73
--- /dev/null
+++ b/mysql-test/suite/innodb/t/dropdb_cs.test
@@ -0,0 +1,17 @@
+--source include/have_innodb.inc
+--source include/have_case_sensitive_file_system.inc
+
+--echo #
+--echo # MDEV-28802 DROP DATABASE in InnoDB still is case-insensitive
+--echo #
+
+SET @save_fpt=@@GLOBAL.innodb_file_per_table;
+SET GLOBAL innodb_file_per_table=0;
+CREATE DATABASE Db;
+CREATE TABLE Db.t1 (c1 INT KEY) ENGINE=InnoDB;
+CREATE DATABASE DB;
+DROP DATABASE DB;
+SELECT NAME FROM INFORMATION_SCHEMA.INNODB_SYS_TABLES WHERE NAME LIKE 'D%';
+DROP DATABASE Db;
+SELECT * FROM INFORMATION_SCHEMA.INNODB_SYS_TABLES WHERE NAME LIKE 'D%';
+SET GLOBAL innodb_file_per_table=@save_fpt;
diff --git a/mysql-test/suite/innodb/t/encryption_threads_shutdown.opt b/mysql-test/suite/innodb/t/encryption_threads_shutdown.opt
new file mode 100644
index 00000000..e5a02a1a
--- /dev/null
+++ b/mysql-test/suite/innodb/t/encryption_threads_shutdown.opt
@@ -0,0 +1,6 @@
+--innodb-encryption-rotate-key-age=2
+--innodb-encryption-threads=4
+--innodb-tablespaces-encryption
+--plugin-load-add=$FILE_KEY_MANAGEMENT_SO
+--loose-file-key-management
+--loose-file-key-management-filename=$MYSQL_TEST_DIR/std_data/logkey.txt
diff --git a/mysql-test/suite/innodb/t/encryption_threads_shutdown.test b/mysql-test/suite/innodb/t/encryption_threads_shutdown.test
new file mode 100644
index 00000000..5a63df5d
--- /dev/null
+++ b/mysql-test/suite/innodb/t/encryption_threads_shutdown.test
@@ -0,0 +1,32 @@
+# This test is for MDEV-24612 fix
+--source include/have_innodb.inc
+--source include/not_embedded.inc
+
+call mtr.add_suppression("Creating system tablespace with existing redo log file is not recommended.");
+call mtr.add_suppression("InnoDB: Database creation was aborted");
+call mtr.add_suppression("Plugin 'InnoDB' init function returned error.");
+call mtr.add_suppression("Plugin 'InnoDB' registration as a STORAGE ENGINE failed.");
+
+--let $MYSQLD_DATADIR=`SELECT @@datadir`
+--let $DATA= $MYSQLD_DATADIR/ibdata1
+--let $DATACOPY=$MYSQLTEST_VARDIR/tmp/ibdata1
+CREATE TABLE t(a INT) ENGINE=InnoDB;
+--source include/kill_mysqld.inc
+# Move the file to cause srv_init_abort_low() call from srv_start()
+--move_file $DATA $DATACOPY
+
+# If the bug is not fixed, the server will hang here. Note that the test is
+# unstable because the condition
+# "srv_n_fil_crypt_threads_started != srv_n_fil_crypt_threads" can be true
+# in fil_crypt_set_thread_cnt() functions if encryption threads have not yet
+# been finished. To make the test stable we need to add debug code which would
+# check that all encryption threads were finished before the "while" loop
+# with the above condition. And in this test we can't detect if the debug code
+# itself caused the hang or the code we are testing did it.
+--source include/start_mysqld.inc
+--error ER_UNKNOWN_STORAGE_ENGINE
+SELECT * FROM t;
+--source include/kill_mysqld.inc
+--move_file $DATACOPY $DATA
+--source include/start_mysqld.inc
+DROP TABLE t;
diff --git a/mysql-test/suite/innodb/t/evict_tables_on_commit_debug.test b/mysql-test/suite/innodb/t/evict_tables_on_commit_debug.test
new file mode 100644
index 00000000..8cb45d01
--- /dev/null
+++ b/mysql-test/suite/innodb/t/evict_tables_on_commit_debug.test
@@ -0,0 +1,11 @@
+--source include/have_innodb.inc
+--source include/have_debug.inc
+SET @save_debug= @@GLOBAL.innodb_evict_tables_on_commit_debug;
+SET GLOBAL innodb_evict_tables_on_commit_debug=on;
+CREATE TEMPORARY TABLE t1(a INT) ENGINE=InnoDB;
+CREATE TABLE t2 (a INT) ENGINE=InnoDB;
+INSERT INTO t1 VALUES(1);
+INSERT INTO t2 VALUES(2);
+DROP TABLE t2;
+SET GLOBAL innodb_evict_tables_on_commit_debug=@save_debug;
+DROP TEMPORARY TABLE t1;
diff --git a/mysql-test/suite/innodb/t/file_format_defaults.test b/mysql-test/suite/innodb/t/file_format_defaults.test
new file mode 100644
index 00000000..f648610f
--- /dev/null
+++ b/mysql-test/suite/innodb/t/file_format_defaults.test
@@ -0,0 +1,44 @@
+#***********************************************************
+# WL#7703:
+# Check boundary value of max key length 3073
+#***********************************************************
+-- source include/have_innodb.inc
+-- source include/have_innodb_16k.inc
+
+call mtr.add_suppression("InnoDB: Cannot add field `c1` in table `test`\\.`tab0`");
+
+# Check some default settings
+SELECT @@innodb_strict_mode;
+
+SELECT @@innodb_file_per_table;
+
+SET SQL_MODE=strict_all_tables;
+
+--disable_query_log
+SET @save_innodb_read_only_compressed=@@GLOBAL.innodb_read_only_compressed;
+SET GLOBAL innodb_read_only_compressed=OFF;
+--enable_query_log
+
+CREATE TABLE tab0 (c1 VARCHAR(65530), KEY(c1(3073))) ENGINE=InnoDB ROW_FORMAT=COMPRESSED;
+SHOW CREATE TABLE tab0;
+DROP TABLE tab0;
+
+--error ER_TOO_BIG_ROWSIZE
+CREATE TABLE tab0 (c1 VARCHAR(65530), KEY(c1(3073))) ENGINE=InnoDB KEY_BLOCK_SIZE=2;
+
+CREATE TABLE tab0(c1 INT,c2 LONGBLOB ) ENGINE=InnoDB ROW_FORMAT=Dynamic;
+DROP TABLE tab0;
+
+SET GLOBAL innodb_strict_mode=OFF;
+
+# Check with default value
+SET GLOBAL innodb_strict_mode=Default;
+
+SELECT @@innodb_strict_mode;
+
+CREATE TABLE tab1(c1 int ) ENGINE=InnoDB ROW_FORMAT=COMPRESSED;
+DROP TABLE tab1;
+
+--disable_query_log
+SET GLOBAL innodb_read_only_compressed=@save_innodb_read_only_compressed;
+--enable_query_log
diff --git a/mysql-test/suite/innodb/t/fk_col_alter.test b/mysql-test/suite/innodb/t/fk_col_alter.test
new file mode 100644
index 00000000..2ed10a95
--- /dev/null
+++ b/mysql-test/suite/innodb/t/fk_col_alter.test
@@ -0,0 +1,152 @@
+--source include/have_innodb.inc
+--echo #
+--echo # MDEV-31086 MODIFY COLUMN can break FK constraints, and
+--echo # lead to unrestorable dumps
+--echo #
+CREATE TABLE t1(
+ id SERIAL,
+ msg VARCHAR(100) CHARACTER SET utf8mb3,
+ KEY(msg))ENGINE=InnoDB;
+
+--error ER_CANT_CREATE_TABLE
+CREATE TABLE t2(
+id SERIAL,
+msg varchar(100) CHARACTER SET utf8mb4,
+CONSTRAINT fk_t1 FOREIGN KEY (msg) REFERENCES t1 (msg))ENGINE=InnoDB;
+
+CREATE TABLE t2(
+id SERIAL,
+msg varchar(100) CHARACTER SET utf8mb3,
+msg_1 varchar(100) CHARACTER SET utf8mb3,
+INDEX (msg_1),
+INDEX (msg),
+CONSTRAINT fk_t1 FOREIGN KEY (msg) REFERENCES t1 (msg)
+ON DELETE CASCADE)ENGINE=InnoDB;
+
+# Changing column used in FK constraint
+SET FOREIGN_KEY_CHECKS=1;
+--error ER_FK_COLUMN_CANNOT_CHANGE
+ALTER TABLE t2 MODIFY COLUMN msg VARCHAR(200) character set utf8mb3, ALGORITHM=COPY;
+--error ER_FK_COLUMN_CANNOT_CHANGE
+ALTER TABLE t2 MODIFY COLUMN msg VARCHAR(200) character set utf8mb3, ALGORITHM=INPLACE;
+
+SET FOREIGN_KEY_CHECKS=0;
+--error ER_FK_COLUMN_CANNOT_CHANGE
+ALTER TABLE t2 MODIFY COLUMN msg VARCHAR(200) character set utf8mb3, ALGORITHM=COPY;
+--error ER_FK_COLUMN_CANNOT_CHANGE
+ALTER TABLE t2 MODIFY COLUMN msg VARCHAR(400) character set utf8mb3, ALGORITHM=INPLACE;
+
+# Changing column charset used in FK constraint
+SET FOREIGN_KEY_CHECKS=1;
+--error ER_FK_COLUMN_CANNOT_CHANGE
+ALTER TABLE t2 MODIFY COLUMN msg VARCHAR(100) CHARACTER SET utf8mb4, ALGORITHM=COPY;
+
+--error ER_FK_COLUMN_CANNOT_CHANGE
+ALTER TABLE t2 MODIFY COLUMN msg VARCHAR(100) CHARACTER SET utf8mb4, ALGORITHM=INPLACE;
+
+SET FOREIGN_KEY_CHECKS=0;
+--error ER_FK_COLUMN_CANNOT_CHANGE
+ALTER TABLE t2 MODIFY COLUMN msg VARCHAR(100) CHARACTER SET utf8mb4,ALGORITHM=COPY;
+
+--error ER_FK_COLUMN_CANNOT_CHANGE
+ALTER TABLE t2 MODIFY COLUMN msg VARCHAR(100) CHARACTER SET utf8mb4,ALGORITHM=INPLACE;
+
+# Modify the column in the newly added foreign constraint
+SET FOREIGN_KEY_CHECKS=1;
+--error ER_CANT_CREATE_TABLE
+ALTER TABLE t2 ADD CONSTRAINT FOREIGN KEY(msg_1) REFERENCES t1(msg),MODIFY COLUMN msg_1 VARCHAR(100) CHARACTER SET utf8mb4, ALGORITHM=COPY;
+
+--error ER_ALTER_OPERATION_NOT_SUPPORTED_REASON
+ALTER TABLE t2 ADD CONSTRAINT FOREIGN KEY(msg_1) REFERENCES t1(msg),MODIFY COLUMN msg_1 VARCHAR(100) CHARACTER SET utf8mb4, ALGORITHM=INPLACE;
+
+
+SET FOREIGN_KEY_CHECKS=0;
+--error ER_CANT_CREATE_TABLE
+ALTER TABLE t2 ADD CONSTRAINT FOREIGN KEY(msg_1) REFERENCES t1(msg),MODIFY COLUMN msg_1 VARCHAR(100) CHARACTER SET utf8mb4, ALGORITHM=COPY;
+
+--error ER_FK_COLUMN_CANNOT_CHANGE
+ALTER TABLE t2 ADD CONSTRAINT FOREIGN KEY(msg_1) REFERENCES t1(msg),MODIFY COLUMN msg_1 VARCHAR(100) CHARACTER SET utf8mb4, ALGORITHM=INPLACE;
+
+--error ER_FK_COLUMN_CANNOT_CHANGE
+ALTER TABLE t2 ADD CONSTRAINT FOREIGN KEY(msg_1) REFERENCES t1(msg),MODIFY COLUMN msg_1 VARCHAR(200) CHARACTER SET utf8mb3, ALGORITHM=INPLACE;
+
+# Change referenced table column
+SET FOREIGN_KEY_CHECKS=1;
+# Change referenced column length
+--error ER_FK_COLUMN_CANNOT_CHANGE_CHILD
+ALTER TABLE t1 MODIFY msg VARCHAR(200) CHARSET utf8mb3, ALGORITHM=COPY;
+--error ER_FK_COLUMN_CANNOT_CHANGE_CHILD
+ALTER TABLE t1 MODIFY msg VARCHAR(200) CHARSET utf8mb3, ALGORITHM=INPLACE;
+# Change referenced column character set
+--error ER_FK_COLUMN_CANNOT_CHANGE_CHILD
+ALTER TABLE t1 MODIFY msg VARCHAR(200) CHARSET utf8mb4, ALGORITHM=COPY;
+--error ER_FK_COLUMN_CANNOT_CHANGE_CHILD
+ALTER TABLE t1 MODIFY msg VARCHAR(200) CHARSET utf8mb4, ALGORITHM=INPLACE;
+
+SET FOREIGN_KEY_CHECKS=0;
+# Change referenced column length
+--error ER_FK_COLUMN_CANNOT_CHANGE_CHILD
+ALTER TABLE t1 MODIFY msg VARCHAR(200) CHARSET utf8mb3, ALGORITHM=COPY;
+--error ER_FK_COLUMN_CANNOT_CHANGE_CHILD
+ALTER TABLE t1 MODIFY msg VARCHAR(400) CHARSET utf8mb3, ALGORITHM=INPLACE;
+
+# Change referenced column character set
+--error ER_FK_COLUMN_CANNOT_CHANGE_CHILD
+ALTER TABLE t1 MODIFY msg VARCHAR(200) CHARSET utf8mb4, ALGORITHM=COPY;
+--error ER_FK_COLUMN_CANNOT_CHANGE_CHILD
+ALTER TABLE t1 MODIFY msg VARCHAR(200) CHARSET utf8mb4, ALGORITHM=INPLACE;
+
+# Correct way to change character set in foreign key constraint
+SET FOREIGN_KEY_CHECKS=0;
+ALTER TABLE t2 DROP FOREIGN KEY fk_t1, MODIFY msg VARCHAR(200) CHARSET utf8mb4, ALGORITHM=COPY;
+ALTER TABLE t1 MODIFY msg VARCHAR(200) CHARSET utf8mb4, ALGORITHM=COPY;
+ALTER TABLE t2 ADD CONSTRAINT FOREIGN KEY (msg) REFERENCES t1(msg), aLGORITHM=INPLACE;
+SET FOREIGN_KEY_CHECKS=1;
+
+DROP TABLE t2, t1;
+
+--echo #
+--echo # MDEV-31869 Server aborts when table does drop column
+--echo #
+CREATE TABLE t (a VARCHAR(40), b INT, C INT) ENGINE=InnoDB;
+ALTER TABLE t MODIFY a VARCHAR(50), DROP b;
+DROP TABLE t;
+
+--echo #
+--echo # MDEV-32060 Server aborts when table doesn't
+--echo # have referenced index
+--echo #
+SET SESSION FOREIGN_KEY_CHECKS = OFF;
+CREATE TABLE t1 (a VARCHAR(16) KEY, FOREIGN KEY(a) REFERENCES t2(b)) ENGINE=InnoDB;
+CREATE TABLE t2 (b VARCHAR(8)) ENGINE=InnoDB;
+SET SESSION FOREIGN_KEY_CHECKS = ON;
+ALTER TABLE t2 MODIFY b VARCHAR(16), ADD KEY(b);
+DROP TABLE t1, t2;
+
+--echo #
+--echo # MDEV-32337 Assertion `pos < table->n_def' failed
+--echo # in dict_table_get_nth_col
+--echo #
+CREATE TABLE t (a INT, va INT AS (a), b INT, vb INT AS (b),
+ c INT, vc INT AS (c), vf VARCHAR(16) AS (f),
+ f VARCHAR(4)) ENGINE=InnoDB;
+ALTER TABLE t MODIFY f VARCHAR(8);
+# Altering the virtual column is not supported
+--error ER_UNSUPPORTED_ACTION_ON_GENERATED_COLUMN
+ALTER TABLE t MODIFY vf VARCHAR(18);
+DROP TABLE t;
+
+--echo #
+--echo # MDEV-32527 Server aborts during alter operation
+--echo # when table doesn't have foreign index
+--echo #
+CREATE TABLE t1 (f1 INT NOT NULL, INDEX(f1)) ENGINE=InnoDB;
+CREATE TABLE t2(f1 INT NOT NULL, f2 VARCHAR(100) DEFAULT NULL,
+ INDEX idx(f1, f2),
+ FOREIGN KEY(f1) REFERENCES t1(f1))ENGINE=INNODB;
+SET SESSION FOREIGN_KEY_CHECKS = OFF;
+ALTER TABLE t2 DROP INDEX idx;
+ALTER TABLE t2 MODIFY f2 VARCHAR(1023);
+SET SESSION FOREIGN_KEY_CHECKS = ON;
+DROP TABLE t2, t1;
+--echo # End of 10.4 tests
diff --git a/mysql-test/suite/innodb/t/flush.opt b/mysql-test/suite/innodb/t/flush.opt
new file mode 100644
index 00000000..99dbd8f4
--- /dev/null
+++ b/mysql-test/suite/innodb/t/flush.opt
@@ -0,0 +1 @@
+--innodb-open-files=10
diff --git a/mysql-test/suite/innodb/t/flush.test b/mysql-test/suite/innodb/t/flush.test
new file mode 100644
index 00000000..e0372882
--- /dev/null
+++ b/mysql-test/suite/innodb/t/flush.test
@@ -0,0 +1,19 @@
+--source include/have_innodb.inc
+
+SELECT @@GLOBAL.innodb_open_files;
+
+CREATE TABLE t0 (a INT) ENGINE=InnoDB;
+# Ensure that the created table t0 is clean.
+FLUSH TABLE t0 WITH READ LOCK;
+UNLOCK TABLES;
+CREATE TABLE t1 (a INT) ENGINE=InnoDB;
+CREATE TABLE t2 (a INT) ENGINE=InnoDB;
+CREATE TABLE t3 (a INT) ENGINE=InnoDB;
+CREATE TABLE t4 (a INT) ENGINE=InnoDB;
+CREATE TABLE t5 (a INT) ENGINE=InnoDB;
+CREATE TABLE t6 (a INT) ENGINE=InnoDB;
+CREATE TABLE t7 (a INT) ENGINE=InnoDB;
+# Now, the data file for t0 should not be open anymore.
+FLUSH TABLE t0 WITH READ LOCK;
+UNLOCK TABLES;
+DROP TABLE t0, t1, t2, t3, t4, t5, t6, t7;
diff --git a/mysql-test/suite/innodb/t/foreign-keys.test b/mysql-test/suite/innodb/t/foreign-keys.test
new file mode 100644
index 00000000..b93f82c9
--- /dev/null
+++ b/mysql-test/suite/innodb/t/foreign-keys.test
@@ -0,0 +1,270 @@
+--source include/have_innodb.inc
+--source include/have_debug.inc
+--source include/have_debug_sync.inc
+
+--enable_connect_log
+
+--echo #
+--echo # Bug #19471516 SERVER CRASHES WHEN EXECUTING ALTER TABLE
+--echo # ADD FOREIGN KEY
+--echo #
+
+CREATE TABLE `department` (`department_id` INT, `department_people_fk` INT,
+PRIMARY KEY (`department_id`)) engine=innodb;
+
+CREATE TABLE `title` (`title_id` INT, `title_manager_fk` INT,
+`title_reporter_fk` INT, PRIMARY KEY (`title_id`)) engine=innodb;
+
+CREATE TABLE `people` (`people_id` INT, PRIMARY KEY (`people_id`)) engine=innodb;
+
+ALTER TABLE `department` ADD FOREIGN KEY (`department_people_fk`) REFERENCES
+`people` (`people_id`);
+
+ALTER TABLE `title` ADD FOREIGN KEY (`title_manager_fk`) REFERENCES `people`
+(`people_id`);
+
+ALTER TABLE `title` ADD FOREIGN KEY (`title_reporter_fk`) REFERENCES `people`
+(`people_id`);
+
+drop table title, department, people;
+
+#
+# FK and prelocking:
+# child table accesses (reads and writes) wait for locks.
+#
+create table t1 (a int primary key, b int) engine=innodb;
+create table t2 (c int primary key, d int,
+ foreign key (d) references t1 (a) on update cascade) engine=innodb;
+insert t1 values (1,1),(2,2),(3,3);
+insert t2 values (4,1),(5,2),(6,3);
+flush table t2 with read lock; # this takes MDL_SHARED_NO_WRITE
+connect (con1,localhost,root);
+--error ER_ROW_IS_REFERENCED_2
+delete from t1 where a=2;
+send update t1 set a=10 where a=1;
+connection default;
+let $wait_condition= select 1 from information_schema.processlist where state='Waiting for table metadata lock';
+source include/wait_condition.inc;
+unlock tables;
+connection con1;
+reap;
+connection default;
+lock table t2 write; # this takes MDL_SHARED_NO_READ_WRITE
+connection con1;
+send delete from t1 where a=2;
+connection default;
+let $wait_condition= select 1 from information_schema.processlist where state='Waiting for table metadata lock';
+source include/wait_condition.inc;
+unlock tables;
+connection con1;
+--error ER_ROW_IS_REFERENCED_2
+reap;
+connection default;
+unlock tables;
+disconnect con1;
+
+# but privileges should not be checked
+create user foo;
+grant select,update on test.t1 to foo;
+connect(foo,localhost,foo);
+update t1 set a=30 where a=3;
+disconnect foo;
+connection default;
+select * from t2;
+drop table t2, t1;
+drop user foo;
+
+#
+# MDEV-16465 Invalid (old?) table or database name or hang in ha_innobase::delete_table and log semaphore wait upon concurrent DDL with foreign keys
+#
+create table t1 (f1 int primary key) engine=innodb;
+create table t2 (f2 int primary key) engine=innodb;
+create table t3 (f3 int primary key, foreign key (f3) references t2(f2)) engine=innodb;
+insert into t1 values (1),(2),(3),(4),(5);
+insert into t2 values (1),(2),(3),(4),(5);
+insert into t3 values (1),(2),(3),(4),(5);
+connect con1,localhost,root;
+set debug_sync='alter_table_before_rename_result_table signal g1 wait_for g2';
+send alter table t2 add constraint foreign key (f2) references t1(f1) on delete cascade on update cascade;
+connection default;
+let $conn=`select connection_id()`;
+set debug_sync='before_execute_sql_command wait_for g1';
+send update t1 set f1 = f1 + 100000 limit 2;
+connect con2,localhost,root;
+let $wait_condition= select 1 from information_schema.processlist where state='Waiting for table metadata lock' and info like 'update t1 %';
+source include/wait_condition.inc;
+--replace_result $conn UPDATE
+eval kill query $conn;
+disconnect con2;
+connection default;
+error ER_QUERY_INTERRUPTED;
+reap;
+set debug_sync='now signal g2';
+connection con1;
+reap;
+show create table t2;
+disconnect con1;
+connection default;
+select * from t2 where f2 not in (select f1 from t1);
+select * from t3 where f3 not in (select f2 from t2);
+drop table t3;
+drop table t2;
+drop table t1;
+set debug_sync='reset';
+
+
+--echo #
+--echo # MDEV-17595 - Server crashes in copy_data_between_tables or
+--echo # Assertion `thd->transaction.stmt.is_empty() ||
+--echo # (thd->state_flags & Open_tables_state::BACKUPS_AVAIL)'
+--echo # fails in close_tables_for_reopen upon concurrent
+--echo # ALTER TABLE and FLUSH
+--echo #
+CREATE TABLE t1 (a INT, KEY(a)) ENGINE=InnoDB;
+INSERT INTO t1 VALUES(1),(2);
+CREATE TABLE t2 (b INT, KEY(b)) ENGINE=InnoDB;
+INSERT INTO t2 VALUES(2);
+ALTER TABLE t2 ADD FOREIGN KEY(b) REFERENCES t1(a), LOCK=EXCLUSIVE;
+DROP TABLE t2, t1;
+
+
+--echo #
+--echo # MDEV-16060 - InnoDB: Failing assertion: ut_strcmp(index->name, key->name)
+--echo #
+CREATE TABLE t1 (`pk` INT PRIMARY KEY) ENGINE=InnoDB;
+CREATE TABLE t2 LIKE t1;
+FLUSH TABLES;
+
+SET debug_sync='alter_table_intermediate_table_created SIGNAL ready WAIT_FOR go';
+send ALTER TABLE t1 ADD FOREIGN KEY(pk) REFERENCES t2(pk) ON UPDATE CASCADE;
+
+connect con1, localhost, root;
+SET debug_sync='now WAIT_FOR ready';
+SET lock_wait_timeout=0;
+--error ER_LOCK_WAIT_TIMEOUT
+UPDATE t2 SET pk=10 WHERE pk=1;
+PREPARE stmt FROM 'UPDATE t2 SET pk=10 WHERE pk=1';
+DEALLOCATE PREPARE stmt;
+SET debug_sync='now SIGNAL go';
+
+connection default;
+reap;
+
+# Cleanup
+disconnect con1;
+
+connection default;
+SET debug_sync='reset';
+SHOW OPEN TABLES FROM test;
+DROP TABLE t1, t2;
+
+#
+# FK and prelocking:
+# child table accesses (reads and writes) wait for locks.
+#
+create table t1 (a int primary key, b int) engine=innodb;
+create table t2 (c int primary key, d int,
+ foreign key (d) references t1 (a) on update cascade) engine=innodb;
+insert t1 values (1,1),(2,2),(3,3);
+insert t2 values (4,1),(5,2),(6,3);
+flush table t2 with read lock; # this takes MDL_SHARED_NO_WRITE
+connect (con1,localhost,root);
+--error ER_ROW_IS_REFERENCED_2
+delete from t1 where a=2;
+send update t1 set a=10 where a=1;
+connection default;
+let $wait_condition= select 1 from information_schema.processlist where state='Waiting for table metadata lock';
+source include/wait_condition.inc;
+unlock tables;
+connection con1;
+reap;
+connection default;
+lock table t2 write; # this takes MDL_SHARED_NO_READ_WRITE
+connection con1;
+send delete from t1 where a=2;
+connection default;
+let $wait_condition= select 1 from information_schema.processlist where state='Waiting for table metadata lock';
+source include/wait_condition.inc;
+unlock tables;
+connection con1;
+--error ER_ROW_IS_REFERENCED_2
+reap;
+connection default;
+unlock tables;
+disconnect con1;
+
+# but privileges should not be checked
+create user foo;
+grant select,update on test.t1 to foo;
+connect(foo,localhost,foo);
+update t1 set a=30 where a=3;
+disconnect foo;
+connection default;
+select * from t2;
+drop table t2, t1;
+drop user foo;
+
+--echo #
+--echo # MDEV-17187 table doesn't exist in engine after ALTER other tables
+--echo # with CONSTRAINTs
+--echo #
+
+set foreign_key_checks=on;
+create table t1 (id int not null primary key) engine=innodb;
+create table t2 (id int not null primary key, fid int not null,
+CONSTRAINT fk_fid FOREIGN KEY (fid) REFERENCES t1 (id))engine=innodb;
+
+insert into t1 values (1), (2), (3);
+insert into t2 values (1, 1), (2, 1), (3, 2);
+
+set foreign_key_checks=off;
+alter table t2 drop index fk_fid;
+set foreign_key_checks=on;
+
+--error ER_ROW_IS_REFERENCED_2
+delete from t1 where id=2;
+--error ER_NO_REFERENCED_ROW_2
+insert into t2 values(4, 99);
+
+select * from t1;
+select * from t2;
+
+set foreign_key_checks=off;
+delete from t1 where id=2;
+insert into t2 values(4, 99);
+set foreign_key_checks=on;
+
+select * from t1;
+select * from t2;
+
+show create table t1;
+show create table t2;
+
+# Optional: test DROP TABLE without any prior ha_innobase::open().
+# This was tested manually, but it would cause --embedded to skip the test,
+# and the restart would significantly increase the running time.
+# --source include/restart_mysqld.inc
+
+--error ER_ROW_IS_REFERENCED_2
+drop table t1,t2;
+--error ER_BAD_TABLE_ERROR
+drop table t1,t2;
+
+--echo #
+--echo # MDEV-23470 InnoDB: Failing assertion: cmp < 0 in
+--echo # row_ins_check_foreign_constraint
+--echo #
+CREATE TABLE t1(f1 INT NOT NULL PRIMARY KEY, f2 INT NOT NULL)ENGINE=InnoDB;
+CREATE TABLE t2(f1 VARCHAR(100), f2 INT NOT NULL,
+ INDEX(f2))ENGINE=InnoDB;
+
+INSERT INTO t1 VALUES(99, 2);
+ALTER TABLE t2 ADD FOREIGN KEY(f2) REFERENCES t1(f1);
+
+SET FOREIGN_KEY_CHECKS=0;
+DROP INDEX f2 ON t2;
+SET FOREIGN_KEY_CHECKS=1;
+--error ER_NO_REFERENCED_ROW_2
+INSERT INTO t2 VALUES('G', 3);
+DROP TABLE t2, t1;
+SET FOREIGN_KEY_CHECKS=DEFAULT;
diff --git a/mysql-test/suite/innodb/t/foreign_key.combinations b/mysql-test/suite/innodb/t/foreign_key.combinations
new file mode 100644
index 00000000..53d4cff5
--- /dev/null
+++ b/mysql-test/suite/innodb/t/foreign_key.combinations
@@ -0,0 +1,5 @@
+[read-ahead]
+--innodb-random-read-ahead=ON
+
+[normal]
+--innodb-random-read-ahead=OFF
diff --git a/mysql-test/suite/innodb/t/foreign_key.test b/mysql-test/suite/innodb/t/foreign_key.test
new file mode 100644
index 00000000..06da1b6f
--- /dev/null
+++ b/mysql-test/suite/innodb/t/foreign_key.test
@@ -0,0 +1,1135 @@
+--source include/have_innodb.inc
+--source include/count_sessions.inc
+--source include/default_charset.inc
+
+--echo #
+--echo # Bug #19027905 ASSERT RET.SECOND DICT_CREATE_FOREIGN_CONSTRAINTS_LOW
+--echo # DICT_CREATE_FOREIGN_CONSTR
+--echo #
+
+create table t1 (f1 int primary key) engine=InnoDB;
+--error ER_CANT_CREATE_TABLE
+create table t2 (f1 int primary key,
+constraint c1 foreign key (f1) references t1(f1),
+constraint c1 foreign key (f1) references t1(f1)) engine=InnoDB;
+create table t2 (f1 int primary key,
+ constraint c1 foreign key (f1) references t1(f1)) engine=innodb;
+
+--error ER_CANT_CREATE_TABLE
+alter table t2 add constraint c1 foreign key (f1) references t1(f1);
+
+set foreign_key_checks = 0;
+--error ER_DUP_CONSTRAINT_NAME
+alter table t2 add constraint c1 foreign key (f1) references t1(f1);
+
+drop table t2, t1;
+
+--echo #
+--echo # Bug #20031243 CREATE TABLE FAILS TO CHECK IF FOREIGN KEY COLUMN
+--echo # NULL/NOT NULL MISMATCH
+--echo #
+
+set foreign_key_checks = 1;
+show variables like 'foreign_key_checks';
+
+CREATE TABLE t1
+(a INT NOT NULL,
+ b INT NOT NULL,
+ INDEX idx(a)) ENGINE=InnoDB;
+
+CREATE TABLE t2
+(a INT KEY,
+ b INT,
+ INDEX ind(b),
+ FOREIGN KEY (b) REFERENCES t1(a) ON DELETE CASCADE ON UPDATE CASCADE)
+ ENGINE=InnoDB;
+
+show create table t1;
+show create table t2;
+
+INSERT INTO t1 VALUES (1, 80);
+INSERT INTO t1 VALUES (2, 81);
+INSERT INTO t1 VALUES (3, 82);
+INSERT INTO t1 VALUES (4, 83);
+INSERT INTO t1 VALUES (5, 84);
+
+INSERT INTO t2 VALUES (51, 1);
+INSERT INTO t2 VALUES (52, 2);
+INSERT INTO t2 VALUES (53, 3);
+INSERT INTO t2 VALUES (54, 4);
+INSERT INTO t2 VALUES (55, 5);
+
+SELECT a, b FROM t1 ORDER BY a;
+SELECT a, b FROM t2 ORDER BY a;
+
+--error ER_NO_REFERENCED_ROW_2
+INSERT INTO t2 VALUES (56, 6);
+
+ALTER TABLE t1 CHANGE a id INT;
+
+SELECT id, b FROM t1 ORDER BY id;
+SELECT a, b FROM t2 ORDER BY a;
+
+--echo # Operations on child table
+--error ER_NO_REFERENCED_ROW_2
+INSERT INTO t2 VALUES (56, 6);
+--error ER_NO_REFERENCED_ROW_2
+UPDATE t2 SET b = 99 WHERE a = 51;
+DELETE FROM t2 WHERE a = 53;
+SELECT id, b FROM t1 ORDER BY id;
+SELECT a, b FROM t2 ORDER BY a;
+
+--echo # Operations on parent table
+DELETE FROM t1 WHERE id = 1;
+UPDATE t1 SET id = 50 WHERE id = 5;
+SELECT id, b FROM t1 ORDER BY id;
+SELECT a, b FROM t2 ORDER BY a;
+
+DROP TABLE t2, t1;
+
+--echo #
+--echo # bug#25126722 FOREIGN KEY CONSTRAINT NAME IS NULL AFTER RESTART
+--echo # base bug#24818604 [GR]
+--echo #
+
+CREATE TABLE t1 (c1 INT PRIMARY KEY) ENGINE=InnoDB;
+CREATE TABLE t2 (c1 INT PRIMARY KEY, FOREIGN KEY (c1) REFERENCES t1(c1))
+ENGINE=InnoDB;
+
+INSERT INTO t1 VALUES (1);
+INSERT INTO t2 VALUES (1);
+
+SELECT unique_constraint_name FROM information_schema.referential_constraints
+WHERE table_name = 't2';
+
+--echo #
+--echo # MDEV-28317 Assertion failure on rollback of FOREIGN KEY operation
+--echo #
+
+SET foreign_key_checks=0;
+CREATE TABLE parent(a INT PRIMARY KEY) ENGINE=InnoDB;
+CREATE TABLE child(a INT,FOREIGN KEY(a) REFERENCES parent(a) ON DELETE CASCADE)
+ENGINE=InnoDB;
+INSERT INTO child VALUES(1);
+ALTER TABLE child DROP INDEX a;
+
+connect(incomplete, localhost, root,,);
+BEGIN;
+DELETE FROM child;
+
+connection default;
+INSERT INTO parent SET a=0;
+FLUSH TABLES;
+
+--let $shutdown_timeout=0
+--source include/restart_mysqld.inc
+--let $shutdown_timeout=
+disconnect incomplete;
+
+INSERT INTO child SET a=0;
+--error ER_NO_REFERENCED_ROW_2
+INSERT INTO child SET a=1;
+--error ER_ROW_IS_REFERENCED_2
+DELETE FROM parent;
+ALTER TABLE child ADD INDEX(a);
+--error ER_ROW_IS_REFERENCED_2
+DELETE FROM parent;
+ALTER TABLE child FORCE;
+DELETE FROM parent;
+DROP TABLE child,parent;
+
+SELECT unique_constraint_name FROM information_schema.referential_constraints
+WHERE table_name = 't2';
+
+SELECT * FROM t1;
+
+SELECT unique_constraint_name FROM information_schema.referential_constraints
+WHERE table_name = 't2';
+
+DROP TABLE t2;
+DROP TABLE t1;
+
+#
+# MDEV-12669 Circular foreign keys cause a loop and OOM upon LOCK TABLE
+#
+SET FOREIGN_KEY_CHECKS=0;
+CREATE TABLE staff (
+ staff_id TINYINT UNSIGNED NOT NULL AUTO_INCREMENT,
+ store_id TINYINT UNSIGNED NOT NULL,
+ PRIMARY KEY (staff_id),
+ KEY idx_fk_store_id (store_id),
+ CONSTRAINT fk_staff_store FOREIGN KEY (store_id) REFERENCES store (store_id) ON DELETE RESTRICT ON UPDATE CASCADE
+) ENGINE=InnoDB;
+CREATE TABLE store (
+ store_id TINYINT UNSIGNED NOT NULL AUTO_INCREMENT,
+ manager_staff_id TINYINT UNSIGNED NOT NULL,
+ PRIMARY KEY (store_id),
+ UNIQUE KEY idx_unique_manager (manager_staff_id),
+ CONSTRAINT fk_store_staff FOREIGN KEY (manager_staff_id) REFERENCES staff (staff_id) ON DELETE RESTRICT ON UPDATE CASCADE
+) ENGINE=InnoDB;
+
+LOCK TABLE staff WRITE;
+UNLOCK TABLES;
+DROP TABLES staff, store;
+
+SET FOREIGN_KEY_CHECKS=1;
+
+--echo #
+--echo # MDEV-17531 Crash in RENAME TABLE with FOREIGN KEY and FULLTEXT INDEX
+--echo #
+
+--disable_query_log
+call mtr.add_suppression("InnoDB: Table rename might cause two FOREIGN KEY");
+call mtr.add_suppression("InnoDB: Cannot delete/update rows with cascading foreign key constraints that exceed max depth of 15\\.");
+--enable_query_log
+
+CREATE TABLE t1 (a INT PRIMARY KEY) ENGINE=InnoDB;
+CREATE DATABASE best default character set latin1;
+CREATE TABLE t3 (a INT PRIMARY KEY,
+CONSTRAINT t2_ibfk_1 FOREIGN KEY (a) REFERENCES t1(a)) ENGINE=InnoDB;
+CREATE TABLE best.t2 (a INT PRIMARY KEY, b TEXT, FULLTEXT INDEX(b),
+FOREIGN KEY (a) REFERENCES test.t1(a)) ENGINE=InnoDB;
+--replace_regex /Table '.*t2'/Table 't2'/
+--error ER_TABLE_EXISTS_ERROR
+RENAME TABLE best.t2 TO test.t2;
+SHOW CREATE TABLE best.t2;
+DROP DATABASE best;
+
+--echo #
+--echo # MDEV-17541 KILL QUERY during lock wait in FOREIGN KEY check hangs
+--echo #
+connect (con1, localhost, root,,);
+INSERT INTO t1 SET a=1;
+BEGIN;
+DELETE FROM t1;
+
+connection default;
+let $ID= `SELECT @id := CONNECTION_ID()`;
+send INSERT INTO t3 SET a=1;
+
+connection con1;
+# Check that the above SELECT is blocked
+let $wait_condition=
+ select count(*) = 1 from information_schema.processlist
+ where state = 'update' and info = 'INSERT INTO t3 SET a=1';
+--source include/wait_condition.inc
+let $ignore= `SELECT @id := $ID`;
+kill query @id;
+
+connection default;
+--error ER_QUERY_INTERRUPTED
+reap;
+
+connection con1;
+ROLLBACK;
+connection default;
+disconnect con1;
+
+DROP TABLE t3,t1;
+
+--echo #
+--echo # MDEV-18222 InnoDB: Failing assertion: heap->magic_n == MEM_BLOCK_MAGIC_N
+--echo # or ASAN heap-use-after-free in dict_foreign_remove_from_cache upon CHANGE COLUMN
+--echo #
+CREATE TABLE t1 (a INT, UNIQUE(a), KEY(a)) ENGINE=InnoDB;
+ALTER TABLE t1 ADD FOREIGN KEY (a) REFERENCES t1 (a);
+SET SESSION FOREIGN_KEY_CHECKS = OFF;
+--error ER_FK_COLUMN_CANNOT_CHANGE_CHILD
+ALTER TABLE t1 CHANGE COLUMN a a TIME NOT NULL;
+ALTER TABLE t1 ADD pk INT NOT NULL AUTO_INCREMENT PRIMARY KEY;
+--error ER_ALTER_OPERATION_NOT_SUPPORTED_REASON
+ALTER TABLE t1 CHANGE COLUMN a b TIME;
+ALTER TABLE t1 CHANGE COLUMN a b TIME, DROP FOREIGN KEY t1_ibfk_1;
+SET SESSION FOREIGN_KEY_CHECKS = ON;
+DROP TABLE t1;
+
+--echo #
+--echo # MDEV-18256 InnoDB: Failing assertion: heap->magic_n == MEM_BLOCK_MAGIC_N
+--echo # upon DROP FOREIGN KEY
+--echo #
+CREATE TABLE t1 (a INT PRIMARY KEY) ENGINE=InnoDB;
+CREATE TABLE t2 (b INT PRIMARY KEY, FOREIGN KEY fk1 (b) REFERENCES t1 (a))
+ENGINE=InnoDB;
+ALTER TABLE t2 DROP FOREIGN KEY fk1, DROP FOREIGN KEY fk1;
+DROP TABLE t2, t1;
+
+CREATE TABLE t1 (f VARCHAR(256)) ENGINE=InnoDB;
+SET SESSION FOREIGN_KEY_CHECKS = OFF;
+ALTER TABLE t1 ADD FOREIGN KEY (f) REFERENCES non_existing_table (x);
+SET SESSION FOREIGN_KEY_CHECKS = ON;
+ALTER TABLE t1 ADD FULLTEXT INDEX ft1 (f);
+ALTER TABLE t1 ADD FULLTEXT INDEX ft2 (f);
+DROP TABLE t1;
+
+CREATE TABLE t1 (f VARCHAR(256), FTS_DOC_ID BIGINT UNSIGNED PRIMARY KEY)
+ENGINE=InnoDB;
+SET SESSION FOREIGN_KEY_CHECKS = OFF;
+ALTER TABLE t1 ADD FOREIGN KEY (f) REFERENCES non_existing_table (x);
+SET SESSION FOREIGN_KEY_CHECKS = ON;
+ALTER TABLE t1 ADD FULLTEXT INDEX ft1 (f);
+ALTER TABLE t1 ADD FULLTEXT INDEX ft2 (f);
+DROP TABLE t1;
+
+--echo #
+--echo # MDEV-18630 Conditional jump or move depends on uninitialised value
+--echo # in ib_push_warning / dict_create_foreign_constraints_low
+--echo #
+CREATE TABLE t1 (a INT) ENGINE=InnoDB;
+--error ER_CANT_CREATE_TABLE
+ALTER IGNORE TABLE t1 ADD FOREIGN KEY (a) REFERENCES t2 (b);
+SHOW WARNINGS;
+DROP TABLE t1;
+
+--echo #
+--echo # MDEV-18139 ALTER IGNORE ... ADD FOREIGN KEY causes bogus error
+--echo #
+CREATE TABLE t1 (f1 INT, f2 INT, f3 INT, KEY(f1)) ENGINE=InnoDB;
+CREATE TABLE t2 (f INT, KEY(f)) ENGINE=InnoDB;
+ALTER TABLE t1 ADD FOREIGN KEY (f2) REFERENCES t2 (f);
+ALTER IGNORE TABLE t1 ADD FOREIGN KEY (f3) REFERENCES t1 (f1);
+DROP TABLE t1, t2;
+
+# MDEV-19092 Server crash when renaming the column when
+# FOREIGN_KEY_CHECKS is disabled
+CREATE TABLE t1 (a INT, b INT, KEY idx(a)) ENGINE=InnoDB;
+SET FOREIGN_KEY_CHECKS= OFF;
+ALTER TABLE t1 ADD FOREIGN KEY (a) REFERENCES tx(x);
+ALTER TABLE t1 DROP KEY idx;
+ALTER TABLE t1 CHANGE a c INT;
+# Cleanup
+DROP TABLE t1;
+
+CREATE TABLE t1 (f1 INT, f2 INT, f3 INT, KEY idx(f1)) ENGINE=InnoDB;
+ALTER TABLE t1 ADD FOREIGN KEY (f2) REFERENCES t1 (f1);
+ALTER TABLE t1 ADD COLUMN f INT;
+SET FOREIGN_KEY_CHECKS= OFF;
+ALTER TABLE t1 DROP KEY idx;
+ALTER TABLE t1 ADD KEY idx (f1);
+SET FOREIGN_KEY_CHECKS= ON;
+ALTER TABLE t1 DROP f3;
+ALTER TABLE t1 CHANGE f f3 INT;
+# Cleanup
+DROP TABLE t1;
+
+SET FOREIGN_KEY_CHECKS=1;
+
+--echo #
+--echo # Bug #19471516 SERVER CRASHES WHEN EXECUTING ALTER TABLE
+--echo # ADD FOREIGN KEY
+--echo #
+
+CREATE TABLE `department` (`department_id` INT, `department_people_fk` INT,
+PRIMARY KEY (`department_id`)) engine=innodb;
+
+CREATE TABLE `title` (`title_id` INT, `title_manager_fk` INT,
+`title_reporter_fk` INT, PRIMARY KEY (`title_id`)) engine=innodb;
+
+CREATE TABLE `people` (`people_id` INT, PRIMARY KEY (`people_id`)) engine=innodb;
+
+ALTER TABLE `department` ADD FOREIGN KEY (`department_people_fk`) REFERENCES
+`people` (`people_id`);
+
+ALTER TABLE `title` ADD FOREIGN KEY (`title_manager_fk`) REFERENCES `people`
+(`people_id`);
+
+ALTER TABLE `title` ADD FOREIGN KEY (`title_reporter_fk`) REFERENCES `people`
+(`people_id`);
+
+drop table title, department, people;
+
+#
+# FK and prelocking:
+# child table accesses (reads and writes) wait for locks.
+#
+create table t1 (a int primary key, b int) engine=innodb;
+create table t2 (c int primary key, d int,
+ foreign key (d) references t1 (a) on update cascade) engine=innodb;
+insert t1 values (1,1),(2,2),(3,3);
+insert t2 values (4,1),(5,2),(6,3);
+flush table t2 with read lock; # this takes MDL_SHARED_NO_WRITE
+connect (con1,localhost,root);
+--error ER_ROW_IS_REFERENCED_2
+delete from t1 where a=2;
+send update t1 set a=10 where a=1;
+connection default;
+let $wait_condition= select 1 from information_schema.processlist where state='Waiting for table metadata lock';
+source include/wait_condition.inc;
+unlock tables;
+connection con1;
+reap;
+connection default;
+lock table t2 write; # this takes MDL_SHARED_NO_READ_WRITE
+connection con1;
+send delete from t1 where a=2;
+connection default;
+let $wait_condition= select 1 from information_schema.processlist where state='Waiting for table metadata lock';
+source include/wait_condition.inc;
+unlock tables;
+connection con1;
+--error ER_ROW_IS_REFERENCED_2
+reap;
+connection default;
+unlock tables;
+disconnect con1;
+
+# but privileges should not be checked
+create user foo;
+grant select,update on test.t1 to foo;
+connect(foo,localhost,foo);
+update t1 set a=30 where a=3;
+disconnect foo;
+connection default;
+select * from t2;
+drop table t2, t1;
+drop user foo;
+
+--echo #
+--echo # MDEV-17595 - Server crashes in copy_data_between_tables or
+--echo # Assertion `thd->transaction.stmt.is_empty() ||
+--echo # (thd->state_flags & Open_tables_state::BACKUPS_AVAIL)'
+--echo # fails in close_tables_for_reopen upon concurrent
+--echo # ALTER TABLE and FLUSH
+--echo #
+CREATE TABLE t1 (a INT, KEY(a)) ENGINE=InnoDB;
+INSERT INTO t1 VALUES(1),(2);
+CREATE TABLE t2 (b INT, KEY(b)) ENGINE=InnoDB;
+INSERT INTO t2 VALUES(2);
+ALTER TABLE t2 ADD FOREIGN KEY(b) REFERENCES t1(a), LOCK=EXCLUSIVE;
+DROP TABLE t2, t1;
+
+#
+# MDEV-22180 Planner opens unnecessary tables when updated table is referenced by foreign keys
+#
+
+create table t1 (pk int primary key, data int) engine=innodb;
+insert t1 values (1,1),(2,2),(3,3);
+create table t2 (t1_pk int, foreign key (t1_pk) references t1 (pk)) engine=innodb;
+insert t2 values (1),(2);
+error ER_NO_REFERENCED_ROW_2;
+insert t2 values (10);
+flush tables;
+flush status;
+# with ON UPDATE RESTRICT child tables are not opened
+update t1 set data=10 where pk+1>10;
+show status like '%opened_tab%';
+flush tables;
+flush status;
+# neither are parent tables
+update t2 set t1_pk=11 where t1_pk+1>10;
+show status like '%opened_tab%';
+# under LOCK TABLES
+flush tables;
+flush status;
+lock tables t1 write;
+show status like '%opened_tab%';
+insert t1 values (4,4);
+show status like '%opened_tab%';
+unlock tables;
+delimiter |;
+create function foo() returns int
+begin
+ insert t1 values (5,5);
+ return 5;
+end|
+delimiter ;|
+flush tables;
+flush status;
+--disable_ps2_protocol
+select foo();
+--enable_ps2_protocol
+show status like '%opened_tab%';
+drop function foo;
+drop table t2, t1;
+
+CREATE TABLE t1 (pk INT, a INT, PRIMARY KEY (pk)) ENGINE=InnoDB;
+XA START 'xid';
+INSERT INTO t1 VALUES (1,2);
+--error ER_XAER_RMFAIL
+CREATE TABLE x AS SELECT * FROM t1;
+--connect (con1,localhost,root,,test)
+SET foreign_key_checks= OFF, innodb_lock_wait_timeout= 0;
+SET lock_wait_timeout=2;
+--error ER_LOCK_WAIT_TIMEOUT
+ALTER TABLE t1 ADD FOREIGN KEY f (a) REFERENCES t1 (pk), LOCK=EXCLUSIVE;# Cleanup
+--disconnect con1
+--connection default
+XA END 'xid';
+XA ROLLBACK 'xid';
+DROP TABLE t1;
+
+CREATE TABLE t1 (pk INT PRIMARY KEY,
+ f1 VARCHAR(10), f2 VARCHAR(10),
+ f3 VARCHAR(10), f4 VARCHAR(10),
+ f5 VARCHAR(10), f6 VARCHAR(10),
+ f7 VARCHAR(10), f8 VARCHAR(10),
+ INDEX(f1), INDEX(f2), INDEX(f3), INDEX(f4),
+ INDEX(f5), INDEX(f6), INDEX(f7), INDEX(f8)) ENGINE=InnoDB;
+INSERT INTO t1 VALUES (1, 'mariadb', 'mariadb', 'mariadb', 'mariadb',
+ 'mariadb', 'mariadb', 'mariadb', 'mariadb'),
+ (2, 'mariadb', 'mariadb', 'mariadb', 'mariadb',
+ 'mariadb', 'mariadb', 'mariadb', 'mariadb'),
+ (3, 'innodb', 'innodb', 'innodb', 'innodb',
+ 'innodb', 'innodb', 'innodb', 'innodb');
+ALTER TABLE t1 ADD FOREIGN KEY (f1) REFERENCES t1 (f2) ON DELETE SET NULL;
+START TRANSACTION;
+DELETE FROM t1 where f1='mariadb';
+SELECT * FROM t1;
+ROLLBACK;
+
+ALTER TABLE t1 ADD FOREIGN KEY (f3) REFERENCES t1 (f4) ON DELETE CASCADE;
+
+START TRANSACTION;
+DELETE FROM t1 where f3='mariadb';
+SELECT * FROM t1;
+ROLLBACK;
+
+ALTER TABLE t1 ADD FOREIGN KEY (f5) REFERENCES t1 (f6) ON UPDATE SET NULL;
+--error ER_ROW_IS_REFERENCED_2
+UPDATE t1 SET f6='update';
+
+ALTER TABLE t1 ADD FOREIGN KEY (f7) REFERENCES t1 (f8) ON UPDATE CASCADE;
+--error ER_ROW_IS_REFERENCED_2
+UPDATE t1 SET f6='cascade';
+DROP TABLE t1;
+#
+# End of 10.1 tests
+#
+
+--echo # Start of 10.2 tests
+
+--echo #
+--echo # MDEV-13246 Stale rows despite ON DELETE CASCADE constraint
+--echo #
+
+CREATE TABLE users (
+ id int unsigned AUTO_INCREMENT PRIMARY KEY,
+ name varchar(32) NOT NULL DEFAULT ''
+) ENGINE=InnoDB DEFAULT CHARSET=utf8;
+
+CREATE TABLE matchmaking_groups (
+ id bigint unsigned AUTO_INCREMENT PRIMARY KEY,
+ host_user_id int unsigned NOT NULL UNIQUE,
+ CONSTRAINT FOREIGN KEY (host_user_id) REFERENCES users (id)
+ ON DELETE CASCADE ON UPDATE CASCADE
+) ENGINE=InnoDB DEFAULT CHARSET=utf8;
+
+CREATE TABLE matchmaking_group_users (
+ matchmaking_group_id bigint unsigned NOT NULL,
+ user_id int unsigned NOT NULL,
+ PRIMARY KEY (matchmaking_group_id,user_id),
+ UNIQUE KEY user_id (user_id),
+ CONSTRAINT FOREIGN KEY (matchmaking_group_id)
+ REFERENCES matchmaking_groups (id) ON DELETE CASCADE ON UPDATE CASCADE,
+ CONSTRAINT FOREIGN KEY (user_id)
+ REFERENCES users (id) ON DELETE CASCADE ON UPDATE CASCADE
+) ENGINE=InnoDB DEFAULT CHARSET=utf8;
+
+CREATE TABLE matchmaking_group_maps (
+ matchmaking_group_id bigint unsigned NOT NULL,
+ map_id tinyint unsigned NOT NULL,
+ PRIMARY KEY (matchmaking_group_id,map_id),
+ CONSTRAINT FOREIGN KEY (matchmaking_group_id)
+ REFERENCES matchmaking_groups (id) ON DELETE CASCADE ON UPDATE CASCADE
+) ENGINE=InnoDB DEFAULT CHARSET=utf8;
+
+INSERT INTO users VALUES (NULL,'foo'),(NULL,'bar');
+INSERT INTO matchmaking_groups VALUES (10,1),(11,2);
+INSERT INTO matchmaking_group_users VALUES (10,1),(11,2);
+INSERT INTO matchmaking_group_maps VALUES (10,55),(11,66);
+
+BEGIN;
+UPDATE users SET name = 'qux' WHERE id = 1;
+
+connect (con1,localhost,root);
+--connection con1
+SET innodb_lock_wait_timeout= 0;
+DELETE FROM matchmaking_groups WHERE id = 10;
+
+--connection default
+COMMIT;
+--sorted_result
+SELECT * FROM matchmaking_group_users WHERE matchmaking_group_id NOT IN (SELECT id FROM matchmaking_groups);
+--sorted_result
+SELECT * FROM matchmaking_group_maps WHERE matchmaking_group_id NOT IN (SELECT id FROM matchmaking_groups);
+--sorted_result
+SELECT * FROM users;
+
+DROP TABLE
+matchmaking_group_maps, matchmaking_group_users, matchmaking_groups, users;
+
+--echo #
+--echo # MDEV-13331 FK DELETE CASCADE does not honor innodb_lock_wait_timeout
+--echo #
+
+CREATE TABLE t1 (id INT NOT NULL PRIMARY KEY) ENGINE=InnoDB;
+
+CREATE TABLE t2 (
+ id INT NOT NULL PRIMARY KEY,
+ ref_id INT NOT NULL DEFAULT 0,
+ f INT NULL,
+ FOREIGN KEY (ref_id) REFERENCES t1 (id) ON DELETE CASCADE
+) ENGINE=InnoDB;
+
+INSERT INTO t1 VALUES (1),(2);
+INSERT INTO t2 VALUES (1,1,10),(2,2,20);
+
+SHOW CREATE TABLE t2;
+
+--connection con1
+BEGIN;
+UPDATE t2 SET f = 11 WHERE id = 1;
+
+--connection default
+SET innodb_lock_wait_timeout= 0;
+--error ER_LOCK_WAIT_TIMEOUT
+DELETE FROM t1 WHERE id = 1;
+SET innodb_lock_wait_timeout= 1;
+
+--connection con1
+COMMIT;
+
+--connection default
+SELECT * FROM t2;
+DELETE FROM t1 WHERE id = 1;
+SELECT * FROM t2;
+DROP TABLE t2, t1;
+
+--echo #
+--echo # MDEV-15199 Referential integrity broken in ON DELETE CASCADE
+--echo #
+
+CREATE TABLE member (id int AUTO_INCREMENT PRIMARY KEY) ENGINE=InnoDB;
+INSERT INTO member VALUES (1);
+CREATE TABLE address (
+ id int AUTO_INCREMENT PRIMARY KEY,
+ member_id int NOT NULL,
+ KEY address_FI_1 (member_id),
+ CONSTRAINT address_FK_1 FOREIGN KEY (member_id) REFERENCES member (id)
+ ON DELETE CASCADE ON UPDATE CASCADE
+) ENGINE=InnoDB;
+
+INSERT INTO address VALUES (2,1);
+CREATE TABLE payment_method (
+ id int AUTO_INCREMENT PRIMARY KEY,
+ member_id int NOT NULL,
+ cardholder_address_id int DEFAULT NULL,
+ KEY payment_method_FI_1 (member_id),
+ KEY payment_method_FI_2 (cardholder_address_id),
+ CONSTRAINT payment_method_FK_1 FOREIGN KEY (member_id) REFERENCES member (id) ON DELETE CASCADE ON UPDATE CASCADE,
+ CONSTRAINT payment_method_FK_2 FOREIGN KEY (cardholder_address_id) REFERENCES address (id) ON DELETE SET NULL ON UPDATE CASCADE
+) ENGINE=InnoDB;
+
+INSERT INTO payment_method VALUES (3,1,2);
+
+BEGIN;
+UPDATE member SET id=42;
+SELECT * FROM member;
+SELECT * FROM address;
+SELECT * FROM payment_method;
+DELETE FROM member;
+COMMIT;
+SELECT * FROM member;
+SELECT * FROM address;
+SELECT * FROM payment_method;
+
+DROP TABLE payment_method,address,member;
+
+--echo #
+--echo # Bug #26958695 INNODB NESTED STORED FIELD WITH CONSTRAINT KEY
+--echo # PRODUCE BROKEN TABLE (no bug in MariaDB)
+--echo #
+create table t1(f1 int,f2 int, primary key(f1), key(f2, f1))engine=innodb;
+create table t2(f1 int, f2 int as (2) stored, f3 int as (f2) stored,
+ foreign key(f1) references t1(f2) on update set NULL)
+engine=innodb;
+insert into t1 values(1, 1);
+insert into t2(f1) values(1);
+drop table t2, t1;
+
+#
+# MDEV-12669 Circular foreign keys cause a loop and OOM upon LOCK TABLE
+#
+SET FOREIGN_KEY_CHECKS=0;
+CREATE TABLE staff (
+ staff_id TINYINT UNSIGNED NOT NULL AUTO_INCREMENT,
+ store_id TINYINT UNSIGNED NOT NULL,
+ PRIMARY KEY (staff_id),
+ KEY idx_fk_store_id (store_id),
+ CONSTRAINT fk_staff_store FOREIGN KEY (store_id) REFERENCES store (store_id) ON DELETE RESTRICT ON UPDATE CASCADE
+) ENGINE=InnoDB;
+CREATE TABLE store (
+ store_id TINYINT UNSIGNED NOT NULL AUTO_INCREMENT,
+ manager_staff_id TINYINT UNSIGNED NOT NULL,
+ PRIMARY KEY (store_id),
+ UNIQUE KEY idx_unique_manager (manager_staff_id),
+ CONSTRAINT fk_store_staff FOREIGN KEY (manager_staff_id) REFERENCES staff (staff_id) ON DELETE RESTRICT ON UPDATE CASCADE
+) ENGINE=InnoDB;
+
+LOCK TABLE staff WRITE;
+UNLOCK TABLES;
+DROP TABLES staff, store;
+SET FOREIGN_KEY_CHECKS=1;
+
+--echo #
+--echo # MDEV-17541 KILL QUERY during lock wait in FOREIGN KEY check hangs
+--echo #
+
+CREATE TABLE t1 (a INT PRIMARY KEY) ENGINE=InnoDB;
+CREATE TABLE t2 (a INT PRIMARY KEY, FOREIGN KEY (a) REFERENCES t1(a))
+ENGINE=InnoDB;
+
+connection con1;
+INSERT INTO t1 SET a=1;
+BEGIN;
+DELETE FROM t1;
+
+connection default;
+let $ID= `SELECT @id := CONNECTION_ID()`;
+send INSERT INTO t2 SET a=1;
+
+connection con1;
+let $wait_condition=
+ select count(*) = 1 from information_schema.processlist
+ where state = 'update' and info = 'INSERT INTO t2 SET a=1';
+--source include/wait_condition.inc
+let $ignore= `SELECT @id := $ID`;
+kill query @id;
+
+connection default;
+--error ER_QUERY_INTERRUPTED
+reap;
+
+connection con1;
+ROLLBACK;
+connection default;
+
+DROP TABLE t2,t1;
+
+--echo #
+--echo # MDEV-18272 InnoDB index corruption after failed DELETE CASCADE
+--echo #
+CREATE TABLE t1 (
+ pk TINYINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
+ a TINYINT UNSIGNED NOT NULL, b TINYINT UNSIGNED NOT NULL, KEY(b),
+ CONSTRAINT FOREIGN KEY (a) REFERENCES t1 (b) ON DELETE CASCADE
+) ENGINE=InnoDB;
+
+INSERT INTO t1 (a,b) VALUES
+(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),
+(0,1),(0,1),(1,0);
+connection con1;
+START TRANSACTION WITH CONSISTENT SNAPSHOT;
+
+connection default;
+DELETE IGNORE FROM t1 WHERE b = 1;
+
+SELECT a FROM t1 FORCE INDEX(a);
+# This would wrongly return the empty result if
+# the "goto rollback_to_savept" in row_mysql_handle_errors() is reverted.
+SELECT * FROM t1;
+# Allow purge to continue by closing the read view.
+disconnect con1;
+
+# Wait for purge. With the fix reverted, the server would crash here.
+--source include/wait_all_purged.inc
+CHECK TABLE t1;
+DROP TABLE t1;
+
+--echo #
+--echo # MDEV-17187 table doesn't exist in engine after ALTER other tables
+--echo # with CONSTRAINTs
+--echo #
+
+call mtr.add_suppression("\\[Warning\\] InnoDB: In ALTER TABLE `test`\\.`t2` has or is referenced in foreign key constraints which are not compatible with the new table definition.");
+
+set foreign_key_checks=on;
+create table t1 (id int not null primary key) engine=innodb;
+create table t2 (id int not null primary key, fid int not null,
+CONSTRAINT fk_fid FOREIGN KEY (fid) REFERENCES t1 (id))engine=innodb;
+
+insert into t1 values (1), (2), (3);
+insert into t2 values (1, 1), (2, 1), (3, 2);
+
+set foreign_key_checks=off;
+alter table t2 drop index fk_fid;
+set foreign_key_checks=on;
+
+--error ER_ROW_IS_REFERENCED_2
+delete from t1 where id=2;
+--error ER_NO_REFERENCED_ROW_2
+insert into t2 values(4, 99);
+
+select * from t1;
+select * from t2;
+
+set foreign_key_checks=off;
+delete from t1 where id=2;
+insert into t2 values(4, 99);
+set foreign_key_checks=on;
+
+select * from t1;
+select * from t2;
+
+show create table t1;
+show create table t2;
+
+# Optional: test DROP TABLE without any prior ha_innobase::open().
+# This was tested manually, but it would cause --embedded to skip the test,
+# and the restart would significantly increase the running time.
+# --source include/restart_mysqld.inc
+
+--error ER_ROW_IS_REFERENCED_2
+drop table t1,t2;
+--error ER_BAD_TABLE_ERROR
+drop table t1,t2;
+
+--echo #
+--echo # MDEV-22934 Table disappear after two alter table command
+--echo #
+CREATE TABLE t1(f1 INT NOT NULL AUTO_INCREMENT,
+ f2 INT NOT NULL,
+ PRIMARY KEY (f1), INDEX (f2))ENGINE=InnoDB;
+CREATE TABLE t2(f1 INT NOT NULL,
+ f2 INT NOT NULL, f3 INT NOT NULL,
+ PRIMARY KEY(f1, f2), UNIQUE KEY(f2),
+CONSTRAINT `t2_ibfk_1` FOREIGN KEY (f2) REFERENCES t1(f2) ON DELETE CASCADE,
+CONSTRAINT `t2_ibfk_2` FOREIGN KEY (f1) REFERENCES t1(f1) ON DELETE CASCADE
+) ENGINE=InnoDB;
+
+SET FOREIGN_KEY_CHECKS=0;
+ALTER TABLE t2 DROP PRIMARY KEY, ADD PRIMARY KEY(f3), ALGORITHM=INPLACE;
+ALTER TABLE t2 DROP INDEX `f2`, ALGORITHM=COPY;
+SHOW CREATE TABLE t2;
+--error ER_TABLE_EXISTS_ERROR
+CREATE TABLE t2 (f1 INT NOT NULL)ENGINE=InnoDB;
+DROP TABLE t2, t1;
+
+--echo #
+--echo # MDEV-23685 SIGSEGV on ADD FOREIGN KEY after failed attempt
+--echo # to create unique key on virtual column
+--echo #
+CREATE TABLE t1 (pk INT PRIMARY KEY, a INT, b INT AS (a)) ENGINE=InnODB;
+
+INSERT INTO t1 (pk,a) VALUES (1,10),(2,10);
+--error ER_DUP_ENTRY
+ALTER TABLE t1 ADD UNIQUE INDEX ind9 (b), LOCK=SHARED;
+SET FOREIGN_KEY_CHECKS= 0;
+ALTER TABLE t1 ADD FOREIGN KEY (a) REFERENCES t1 (pk);
+DROP TABLE t1;
+SET FOREIGN_KEY_CHECKS= 1;
+
+--echo #
+--echo # MDEV-23455 Hangs + Sig11 in unknown location(s) due to single complex FK query
+--echo #
+let $constr_prefix= aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa;
+let $fk_ref= xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx;
+let $fk_field= yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy;
+let $constr_count= 200; # each 100 constrs is 1 sec of test execution
+let $i= 0;
+
+while ($i < $constr_count)
+{
+ let $p= $constr_prefix$i;
+ let $constr= CONSTRAINT $p FOREIGN KEY ($fk_field) REFERENCES t1($fk_ref) ON UPDATE SET NULL;
+ if ($i)
+ {
+ let $constrs= $constrs, $constr;
+ }
+ if (!$i)
+ {
+ let $constrs= $constr;
+ }
+ inc $i;
+}
+--disable_query_log
+--echo Parsing foreign keys 1...
+--error ER_CANT_CREATE_TABLE
+eval create table t0($fk_field int, $constrs) engine innodb;
+--echo Parsing foreign keys 2...
+--error ER_CANT_CREATE_TABLE
+eval create table t1($fk_field int, $constrs) engine innodb;
+--echo Parsing foreign keys 3...
+--error ER_CANT_CREATE_TABLE
+eval create table t1($fk_ref int, $fk_field int, $constrs) engine innodb;
+--echo Parsing foreign keys 4...
+eval create table t1($fk_ref int primary key, $fk_field int, $constrs) engine innodb;
+drop table t1;
+--enable_query_log
+
+--echo #
+--echo # MDEV-27583 InnoDB uses different constants for FK cascade
+--echo # error message in SQL vs error log
+--echo #
+
+CREATE TABLE t1
+(a INT, b INT, KEY(b),
+CONSTRAINT FOREIGN KEY (a) REFERENCES t1 (b) ON DELETE CASCADE)
+ENGINE=InnoDB;
+
+INSERT INTO t1 (a,b) VALUES
+(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),
+(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,1),(1,0);
+
+--error ER_GET_ERRMSG
+DELETE FROM t1 WHERE b = 1;
+SHOW WARNINGS;
+DROP TABLE t1;
+
+let SEARCH_FILE= $MYSQLTEST_VARDIR/log/mysqld.1.err;
+let SEARCH_PATTERN= InnoDB: Cannot delete/update rows with cascading foreign key constraints that exceed max depth of 15.*;
+-- source include/search_pattern_in_file.inc
+
+--echo # End of 10.2 tests
+
+--echo #
+--echo # MDEV-28980 InnoDB: Failing assertion: len <= MAX_TABLE_NAME_LEN
+--echo #
+
+SET NAMES utf8;
+CREATE TABLE t (a INT PRIMARY KEY) ENGINE=InnoDB;
+# The maximum identifier length is 64 characters.
+# my_charset_filename will expand some characters to 5 characters,
+# e.g., # to @0023.
+# Many operating systems (such as Linux) or file systems
+# limit the path component length to 255 bytes, such as 51*5 characters.
+# The bug was repeated with a shorter length, which we will use here,
+# to avoid exceeding MAX_PATH on Microsoft Windows.
+let $db=##########################;
+--replace_result $db db
+eval CREATE DATABASE `$db`;
+--replace_result $db db
+eval CREATE TABLE `$db`.u (
+ a INT PRIMARY KEY,
+ CONSTRAINT `††††††††††††††††††††††††††††††††††††††††††††††††††††††††††††††††`
+ FOREIGN KEY (a) REFERENCES test.t (a)) ENGINE=InnoDB;
+--replace_result $db db
+eval DROP TABLE `$db`.u;
+--replace_result $db db
+eval DROP DATABASE `$db`;
+DROP TABLE t;
+
+--echo # End of 10.3 tests
+
+# MDEV-21792 Server aborts upon attempt to create foreign key on spatial field
+# Fail to create foreign key for spatial fields
+--error ER_CANT_CREATE_TABLE
+CREATE TABLE t1 (a GEOMETRY, INDEX(a(8)),
+ FOREIGN KEY (a) REFERENCES x (xx)) ENGINE=InnoDB;
+
+--echo #
+--echo # MDEV-23675 Assertion `pos < table->n_def' in dict_table_get_nth_col
+--echo #
+CREATE TABLE t1 (pk int PRIMARY KEY, a INT, b INT, c INT, KEY(c),
+FOREIGN KEY fx (b) REFERENCES t1 (c))
+ENGINE=InnoDB;
+INSERT INTO t1 VALUES (1,0,10,10);
+ALTER TABLE t1 DROP a, ALGORITHM=INSTANT;
+SET FOREIGN_KEY_CHECKS= 0;
+DROP INDEX fx ON t1;
+INSERT INTO t1 VALUES (2,11,11);
+DROP TABLE t1;
+SET FOREIGN_KEY_CHECKS=DEFAULT;
+
+--echo #
+--echo # MDEV-32018 Allow the setting of Auto_increment on FK referenced columns
+--echo #
+
+CREATE TABLE t1 (
+ id int unsigned NOT NULL PRIMARY KEY
+);
+
+CREATE TABLE t2 (
+ id int unsigned NOT NULL AUTO_INCREMENT PRIMARY KEY,
+ t1_id int unsigned DEFAULT NULL,
+ CONSTRAINT FK_t1_id FOREIGN KEY (t1_id) REFERENCES t1 (id)
+);
+
+ALTER TABLE t1 MODIFY id INT unsigned AUTO_INCREMENT;
+
+DROP TABLE t1,t2;
+
+--echo #
+--echo # End of 10.4 tests
+--echo #
+
+--echo #
+--echo # MDEV-20729 Fix REFERENCES constraint in column definition
+--echo #
+set default_storage_engine= innodb;
+create table t1 (x int primary key, y int unique);
+create table t2 (x int references t1(x), y int constraint fk references t1(y));
+show create table t2;
+create table t3 (z int);
+alter table t3 add x int references t1(x), add y int constraint fk2 references t1(y);
+show create table t3;
+drop tables t3, t2, t1;
+
+create table t1 (id int primary key);
+--error ER_CANT_CREATE_TABLE
+create table t2 (id2 int references t1);
+create table t2 (id int references t1);
+show create table t2;
+drop tables t2, t1;
+
+set default_storage_engine= default;
+
+--echo #
+--echo # MDEV-21690 LeakSanitizer: detected memory leaks in mem_heap_create_block_func
+--echo #
+SET FOREIGN_KEY_CHECKS=1;
+CREATE TABLE t1 (a TEXT, b TEXT) ENGINE=InnoDB;
+--error ER_CANT_CREATE_TABLE
+ALTER TABLE t1 ADD FOREIGN KEY (a) REFERENCES t1 (b);
+SET FOREIGN_KEY_CHECKS=DEFAULT;
+
+# Cleanup
+DROP TABLE t1;
+
+--echo #
+--echo # MDEV-22602 Disable UPDATE CASCADE for SQL constraints
+--echo #
+--echo # TODO: enable them after MDEV-16417 is finished
+create or replace table t1 (a int primary key) engine=innodb;
+--error ER_GENERATED_COLUMN_FUNCTION_IS_NOT_ALLOWED
+create or replace table t2 (a int, constraint foo check(a > 0), foreign key(a) references t1(a) on update cascade) engine=innodb;
+--error ER_GENERATED_COLUMN_FUNCTION_IS_NOT_ALLOWED
+create or replace table t2 (a int, check(a > 0), foreign key(a) references t1(a) on update cascade) engine=innodb;
+
+create or replace table t1 (f1 int, f2 date, f3 date, key(f1,f3,f2)) engine=innodb;
+--error ER_KEY_CANT_HAVE_WITHOUT_OVERLAPS
+create or replace table t2 (
+ a int, s date, e date,
+ period for p (s, e),
+ primary key (a, p without overlaps),
+ foreign key (a, e, s) references t1 (f1, f3, f2) on delete cascade on update cascade) engine=innodb;
+
+# FK on long unique is already disabled
+create or replace table t1 (a varchar(4096) unique) engine=innodb;
+--error ER_CANT_CREATE_TABLE
+create or replace table t2 (pk int primary key, a varchar(4096) unique, foreign key(a) references t1(a) on update cascade) engine=innodb;
+
+drop table t1;
+
+--echo #
+--echo # MDEV-26824 Can't add foreign key with empty referenced columns list
+--echo #
+create table t2(a int primary key) engine=innodb;
+create table t1(a int primary key, b int) engine=innodb;
+--error ER_WRONG_FK_DEF
+alter table t2 add foreign key(a) references t1(a, b);
+create or replace table t1(a tinyint primary key) engine innodb;
+--error ER_CANT_CREATE_TABLE
+alter table t2 add foreign key(a) references t1;
+create or replace table t1(b int primary key) engine innodb;
+--error ER_CANT_CREATE_TABLE
+alter table t2 add foreign key(a) references t1;
+create or replace table t1(a int primary key, b int) engine innodb;
+alter table t2 add foreign key(a) references t1;
+show create table t2;
+drop tables t2, t1;
+
+--echo # End of 10.5 tests
+
+--echo #
+--echo # MDEV-26554 Table-rebuilding DDL on parent table causes crash
+--echo # for INSERT into child table
+--echo #
+
+CREATE TABLE parent(a INT PRIMARY KEY) ENGINE=InnoDB;
+CREATE TABLE child(a INT PRIMARY KEY REFERENCES parent(a)) ENGINE=InnoDB;
+connect (con1, localhost, root,,);
+BEGIN;
+--error ER_NO_REFERENCED_ROW_2
+INSERT INTO child SET a=1;
+connection default;
+SET innodb_lock_wait_timeout=0, foreign_key_checks=0;
+--error ER_LOCK_WAIT_TIMEOUT
+TRUNCATE TABLE parent;
+--error ER_LOCK_WAIT_TIMEOUT
+ALTER TABLE parent FORCE, ALGORITHM=COPY;
+--error ER_LOCK_WAIT_TIMEOUT
+ALTER TABLE parent FORCE, ALGORITHM=INPLACE;
+--error ER_LOCK_WAIT_TIMEOUT
+ALTER TABLE parent ADD COLUMN b INT, ALGORITHM=INSTANT;
+connection con1;
+COMMIT;
+connection default;
+# Restore the timeout to avoid occasional races with purge.
+SET innodb_lock_wait_timeout=DEFAULT;
+TRUNCATE TABLE parent;
+ALTER TABLE parent FORCE, ALGORITHM=COPY;
+ALTER TABLE parent FORCE, ALGORITHM=INPLACE;
+ALTER TABLE parent ADD COLUMN b INT, ALGORITHM=INSTANT;
+DROP TABLE child, parent;
+
+--echo #
+--echo # MDEV-26217 Failing assertion: list.count > 0 in ut_list_remove
+--echo # or Assertion `lock->trx == this' failed in dberr_t trx_t::drop_table
+--echo #
+
+CREATE TABLE t1 (pk INT PRIMARY KEY) ENGINE=InnoDB;
+INSERT INTO t1 VALUES (1);
+
+CREATE TABLE t2 (pk INT PRIMARY KEY, FOREIGN KEY(pk) REFERENCES t1(pk))
+ENGINE=InnoDB;
+
+--connection con1
+SET FOREIGN_KEY_CHECKS=OFF;
+--send
+CREATE OR REPLACE TABLE t1 (b INT) ENGINE=InnoDB;
+
+--connection default
+--error 0,ER_NO_REFERENCED_ROW_2,ER_LOCK_DEADLOCK
+INSERT INTO t2 VALUES (1);
+
+--connection con1
+--error 0,ER_CANT_CREATE_TABLE
+--reap
+
+# Cleanup
+--connection default
+--disable_warnings
+DROP TABLE IF EXISTS t2, t1;
+--enable_warnings
+
+--echo #
+--echo # MDEV-30531 Corrupt index(es) on busy table when using FOREIGN KEY
+--echo #
+
+CREATE TABLE collections (
+ id int(11) unsigned NOT NULL AUTO_INCREMENT,
+ collectionhash varchar(255) NOT NULL DEFAULT '0',
+ PRIMARY KEY (id),
+ UNIQUE KEY ix_collection_collectionhash (collectionhash)
+) ENGINE=InnoDB;
+CREATE TABLE binaries (
+ id bigint(20) unsigned NOT NULL AUTO_INCREMENT,
+ collections_id int(11) unsigned NOT NULL DEFAULT 0,
+ binaryhash binary(16) NOT NULL DEFAULT '0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0',
+ PRIMARY KEY (id),
+ UNIQUE KEY ix_binary_binaryhash (binaryhash),
+ CONSTRAINT FK_collections FOREIGN KEY (collections_id) REFERENCES collections (id) ON DELETE CASCADE
+) ENGINE=InnoDB;
+
+INSERT INTO collections (id) VALUES (NULL);
+
+--connection con1
+INSERT INTO binaries (id,collections_id) VALUES (NULL,1);
+--send
+ REPLACE INTO collections (id) VALUES (NULL);
+
+--connection default
+--error 0,ER_LOCK_DEADLOCK,ER_NO_REFERENCED_ROW_2
+REPLACE INTO binaries (id) VALUES (NULL);
+
+SET GLOBAL innodb_max_purge_lag_wait=0;
+CHECK TABLE binaries, collections EXTENDED;
+
+--disconnect con1
+
+# Cleanup
+DROP TABLE binaries, collections;
+
+--echo # End of 10.6 tests
+
+--source include/wait_until_count_sessions.inc
diff --git a/mysql-test/suite/innodb/t/foreign_key_debug.test b/mysql-test/suite/innodb/t/foreign_key_debug.test
new file mode 100644
index 00000000..166cfb7c
--- /dev/null
+++ b/mysql-test/suite/innodb/t/foreign_key_debug.test
@@ -0,0 +1,77 @@
+--source include/have_innodb.inc
+--source include/have_debug.inc
+--source include/have_debug_sync.inc
+
+--enable_connect_log
+
+#
+# MDEV-16465 Invalid (old?) table or database name or hang in ha_innobase::delete_table and log semaphore wait upon concurrent DDL with foreign keys
+#
+create table t1 (f1 int primary key) engine=innodb;
+create table t2 (f2 int primary key) engine=innodb;
+create table t3 (f3 int primary key, foreign key (f3) references t2(f2)) engine=innodb;
+insert into t1 values (1),(2),(3),(4),(5);
+insert into t2 values (1),(2),(3),(4),(5);
+insert into t3 values (1),(2),(3),(4),(5);
+connect con1,localhost,root;
+set debug_sync='alter_table_before_rename_result_table signal g1 wait_for g2';
+send alter table t2 add constraint foreign key (f2) references t1(f1) on delete cascade on update cascade;
+connection default;
+let $conn=`select connection_id()`;
+set debug_sync='before_execute_sql_command wait_for g1';
+send update t1 set f1 = f1 + 100000 limit 2;
+connect con2,localhost,root;
+let $wait_condition= select 1 from information_schema.processlist where state='Waiting for table metadata lock' and info like 'update t1 %';
+source include/wait_condition.inc;
+--replace_result $conn UPDATE
+eval kill query $conn;
+disconnect con2;
+connection default;
+error ER_QUERY_INTERRUPTED;
+reap;
+set debug_sync='now signal g2';
+connection con1;
+reap;
+show create table t2;
+disconnect con1;
+connection default;
+select * from t2 where f2 not in (select f1 from t1);
+select * from t3 where f3 not in (select f2 from t2);
+drop table t3;
+drop table t2;
+drop table t1;
+set debug_sync='reset';
+
+--echo #
+--echo # MDEV-16060 - InnoDB: Failing assertion: ut_strcmp(index->name, key->name)
+--echo #
+CREATE TABLE t1 (`pk` INT PRIMARY KEY) ENGINE=InnoDB;
+CREATE TABLE t2 LIKE t1;
+FLUSH TABLES;
+
+SET debug_sync='alter_table_intermediate_table_created SIGNAL ready WAIT_FOR go';
+send ALTER TABLE t1 ADD FOREIGN KEY(pk) REFERENCES t2(pk) ON UPDATE CASCADE;
+
+connect con1, localhost, root;
+SET debug_sync='now WAIT_FOR ready';
+SET lock_wait_timeout=0;
+--error ER_LOCK_WAIT_TIMEOUT
+UPDATE t2 SET pk=10 WHERE pk=1;
+PREPARE stmt FROM 'UPDATE t2 SET pk=10 WHERE pk=1';
+DEALLOCATE PREPARE stmt;
+SET debug_sync='now SIGNAL go';
+
+connection default;
+reap;
+
+# Cleanup
+disconnect con1;
+
+connection default;
+SET debug_sync='reset';
+SHOW OPEN TABLES FROM test;
+DROP TABLE t1, t2;
+
+#
+# End of 10.1 tests
+#
diff --git a/mysql-test/suite/innodb/t/foreign_key_not_windows.test b/mysql-test/suite/innodb/t/foreign_key_not_windows.test
new file mode 100644
index 00000000..e5f42a0d
--- /dev/null
+++ b/mysql-test/suite/innodb/t/foreign_key_not_windows.test
@@ -0,0 +1,77 @@
+--source include/have_innodb.inc
+# On Microsoft Windows, there is an additional limit of MAX_PATH
+--source include/not_windows.inc
+# The embedded server prepends --datadir or --innodb-data-home-dir
+# to the path names, which reduces the maximum length of names further.
+--source include/not_embedded.inc
+
+--echo #
+--echo # MDEV-28980 InnoDB: Failing assertion: len <= MAX_TABLE_NAME_LEN
+--echo #
+
+# The main test is innodb.foreign_key. This is an additional test that
+# the maximum length cannot be exceeded for implicitly created
+# constraint names. On Microsoft Windows, MAX_PATH is a much stricter
+# limit than the 255-byte maximum path component length on many other systems,
+# including Linux and IBM AIX.
+
+CREATE TABLE t (a INT PRIMARY KEY) ENGINE=InnoDB;
+
+# The maximum identifier length is 64 characters.
+# my_charset_filename will expand some characters to 5 characters,
+# e.g., # to @0023.
+# Many operating systems (such as Linux) or file systems
+# limit the path component length to 255 bytes,
+# corresponding to the 51 characters below: 5*51=255.
+let $d255=###################################################;
+let $d250=##################################################;
+--replace_result $d255 d255
+eval CREATE DATABASE `$d255`;
+--replace_result $d255 d255
+--error ER_IDENT_CAUSES_TOO_LONG_PATH
+eval CREATE TABLE `$d255`.`$d255`
+(a INT PRIMARY KEY, FOREIGN KEY(a) REFERENCES test.t(a)) ENGINE=InnoDB;
+--replace_result $d255 d255
+--error ER_IDENT_CAUSES_TOO_LONG_PATH
+eval CREATE TABLE `$d255`.`_$d250`
+(a INT PRIMARY KEY, FOREIGN KEY(a) REFERENCES test.t(a)) ENGINE=InnoDB;
+--replace_result $d255 d255
+eval CREATE TABLE `$d255`.`$d250`
+(a INT PRIMARY KEY, FOREIGN KEY(a) REFERENCES test.t(a)) ENGINE=InnoDB;
+
+--echo #
+--echo # MDEV-29258 Failing assertion for name length on RENAME TABLE
+--echo #
+
+let $d245=-------------------------------------------------;
+--replace_result $d245 d245 $d255 d255
+eval CREATE TABLE `$d255`.`$d245` (x INT) ENGINE=InnoDB;
+--replace_result $d250 d250 $d255 d255
+eval DROP TABLE `$d255`.`$d250`;
+
+--replace_result $d245 d245 $d250 d250 d255 d255
+eval RENAME TABLE `$d255`.`$d245` TO `$d255`.`$d250`;
+--replace_result $d250 d250 $d255 d255
+eval RENAME TABLE `$d255`.`$d250` TO a;
+--replace_result $d255 d255
+DROP TABLE a,t;
+
+--echo #
+--echo # MDEV-29409 Buffer overflow in my_wc_mb_filename() on RENAME TABLE
+--echo #
+
+let $d225=#############################################;
+let $d320=################################################################;
+
+--replace_result $d255 d255
+eval CREATE TABLE `$d255`.t(a INT PRIMARY KEY)ENGINE=InnoDB;
+--replace_result $d255 d255 $d320 d320
+eval CREATE TABLE `$d255`.u(a INT PRIMARY KEY,
+CONSTRAINT `$d320` FOREIGN KEY (a) REFERENCES `$d255`.t (a)) ENGINE=InnoDB;
+--replace_result $d255 d255
+eval RENAME TABLE `$d255`.u TO u;
+DROP TABLE u;
+--replace_result $d255 d255
+eval DROP DATABASE `$d255`;
+
+--echo # End of 10.3 tests
diff --git a/mysql-test/suite/innodb/t/full_crc32_import.test b/mysql-test/suite/innodb/t/full_crc32_import.test
new file mode 100644
index 00000000..b79fd954
--- /dev/null
+++ b/mysql-test/suite/innodb/t/full_crc32_import.test
@@ -0,0 +1,224 @@
+-- source include/have_innodb.inc
+# This test is slow on buildbot.
+--source include/big_test.inc
+
+FLUSH TABLES;
+
+let $MYSQLD_TMPDIR = `SELECT @@tmpdir`;
+let $MYSQLD_DATADIR = `SELECT @@datadir`;
+
+--echo # Treating compact format as dynamic format after import stmt
+
+CREATE TABLE t1
+(a int AUTO_INCREMENT PRIMARY KEY,
+ b blob,
+ c blob,
+ KEY (b(200))) ENGINE=InnoDB ROW_FORMAT=COMPACT;
+
+BEGIN;
+INSERT INTO t1 (b, c) values (repeat("ab", 200), repeat("bc", 200));
+INSERT INTO t1 (b, c) values (repeat("bc", 200), repeat("cd", 200));
+INSERT INTO t1 (b, c) values (repeat("cd", 200), repeat("ef", 200));
+INSERT INTO t1 (b, c) values (repeat("de", 200), repeat("fg", 200));
+INSERT INTO t1 (b, c) values (repeat("ef", 200), repeat("gh", 200));
+INSERT INTO t1 (b, c) values (repeat("fg", 200), repeat("hi", 200));
+INSERT INTO t1 (b, c) values (repeat("gh", 200), repeat("ij", 200));
+INSERT INTO t1 (b, c) values (repeat("hi", 200), repeat("jk", 200));
+INSERT INTO t1 (b, c) values (repeat("ij", 200), repeat("kl", 200));
+INSERT INTO t1 (b, c) values (repeat("jk", 200), repeat("lm", 200));
+INSERT INTO t1 (b, c) SELECT b,c FROM t1 ORDER BY a;
+INSERT INTO t1 (b, c) SELECT b,c FROM t1 ORDER BY a;
+COMMIT;
+SELECT COUNT(*) FROM t1;
+
+FLUSH TABLE t1 FOR EXPORT;
+--echo # List before copying files
+let MYSQLD_DATADIR =`SELECT @@datadir`;
+
+--list_files $MYSQLD_DATADIR/test
+perl;
+do "$ENV{MTR_SUITE_DIR}/include/innodb-util.pl";
+ib_backup_tablespaces("test", "t1");
+EOF
+
+UNLOCK TABLES;
+ALTER TABLE t1 ROW_FORMAT=DYNAMIC;
+ALTER TABLE t1 DISCARD TABLESPACE;
+
+--list_files $MYSQLD_DATADIR/test
+perl;
+do "$ENV{MTR_SUITE_DIR}/include/innodb-util.pl";
+ib_discard_tablespaces("test", "t1");
+ib_restore_tablespaces("test", "t1");
+EOF
+
+--remove_file $MYSQLD_DATADIR/test/t1.cfg
+--error ER_INTERNAL_ERROR
+ALTER TABLE t1 IMPORT TABLESPACE;
+ALTER TABLE t1 DROP INDEX b;
+--disable_warnings
+ALTER TABLE t1 IMPORT TABLESPACE;
+--enable_warnings
+SHOW CREATE TABLE t1;
+UPDATE t1 set b = repeat("de", 100) where b = repeat("cd", 200);
+--replace_column 9 #
+explain SELECT a FROM t1 where b = repeat("de", 100);
+SELECT a FROM t1 where b = repeat("de", 100);
+SELECT COUNT(*) FROM t1;
+DELETE FROM t1;
+--source include/wait_all_purged.inc
+CHECK TABLE t1;
+DROP TABLE t1;
+
+CREATE TABLE t1
+(c1 int AUTO_INCREMENT PRIMARY KEY,
+ c2 POINT NOT NULL,
+ c3 LINESTRING NOT NULL,
+ SPATIAL INDEX idx1(c2)) ENGINE=InnoDB ROW_FORMAT=COMPACT;
+
+INSERT INTO t1(c2,c3) VALUES(
+ ST_GeomFromText('POINT(10 10)'),
+ ST_GeomFromText('LINESTRING(5 5,20 20,30 30)'));
+
+INSERT INTO t1(c2,c3) VALUES(
+ ST_GeomFromText('POINT(20 20)'),
+ ST_GeomFromText('LINESTRING(5 15,20 10,30 20)'));
+
+INSERT INTO t1(c2,c3) VALUES(
+ ST_GeomFromText('POINT(30 30)'),
+ ST_GeomFromText('LINESTRING(10 5,20 24,30 32)'));
+
+INSERT INTO t1(c2,c3) VALUES(
+ ST_GeomFromText('POINT(40 40)'),
+ ST_GeomFromText('LINESTRING(15 5,25 20,35 30)'));
+
+INSERT INTO t1(c2,c3) VALUES(
+ ST_GeomFromText('POINT(50 10)'),
+ ST_GeomFromText('LINESTRING(15 15,24 10,31 20)'));
+
+INSERT INTO t1(c2,c3) VALUES(
+ ST_GeomFromText('POINT(60 50)'),
+ ST_GeomFromText('LINESTRING(10 15,20 44,35 32)'));
+
+BEGIN;
+INSERT INTO t1(c2, c3) SELECT c2, c3 FROM t1;
+INSERT INTO t1(c2, c3) SELECT c2, c3 FROM t1;
+INSERT INTO t1(c2, c3) SELECT c2, c3 FROM t1;
+INSERT INTO t1(c2, c3) SELECT c2, c3 FROM t1;
+INSERT INTO t1(c2, c3) SELECT c2, c3 FROM t1;
+INSERT INTO t1(c2, c3) SELECT c2, c3 FROM t1;
+INSERT INTO t1(c2, c3) SELECT c2, c3 FROM t1;
+INSERT INTO t1(c2, c3) SELECT c2, c3 FROM t1;
+INSERT INTO t1(c2, c3) SELECT c2, c3 FROM t1;
+INSERT INTO t1(c2, c3) SELECT c2, c3 FROM t1;
+INSERT INTO t1(c2, c3) SELECT c2, c3 FROM t1;
+COMMIT;
+
+FLUSH TABLE t1 FOR EXPORT;
+--echo # List before copying files
+let MYSQLD_DATADIR =`SELECT @@datadir`;
+
+--list_files $MYSQLD_DATADIR/test
+perl;
+do "$ENV{MTR_SUITE_DIR}/include/innodb-util.pl";
+ib_backup_tablespaces("test", "t1");
+EOF
+
+UNLOCK TABLES;
+ALTER TABLE t1 ROW_FORMAT=DYNAMIC;
+ALTER TABLE t1 DISCARD TABLESPACE;
+perl;
+do "$ENV{MTR_SUITE_DIR}/include/innodb-util.pl";
+ib_discard_tablespaces("test", "t1");
+ib_restore_tablespaces("test", "t1");
+EOF
+
+--remove_file $MYSQLD_DATADIR/test/t1.cfg
+--error ER_INTERNAL_ERROR
+ALTER TABLE t1 IMPORT TABLESPACE;
+--enable_warnings
+ALTER TABLE t1 DROP INDEX idx1;
+--replace_regex /opening '.*\/test\//opening '.\/test\//
+ALTER TABLE t1 IMPORT TABLESPACE;
+--disable_warnings
+SHOW CREATE TABLE t1;
+UPDATE t1 SET C2 = ST_GeomFromText('POINT(0 0)');
+SELECT COUNT(*) FROM t1;
+DELETE FROM t1;
+CHECK TABLE t1;
+--source include/wait_all_purged.inc
+DROP TABLE t1;
+
+SET @save_algo = @@GLOBAL.innodb_compression_algorithm;
+--error 0,ER_WRONG_VALUE_FOR_VAR
+SET GLOBAL innodb_compression_algorithm=2;
+CREATE TABLE t1(a SERIAL) PAGE_COMPRESSED=1 ENGINE=InnoDB;
+INSERT INTO t1 VALUES(1);
+
+FLUSH TABLE t1 FOR EXPORT;
+--echo # List before copying files
+let MYSQLD_DATADIR =`SELECT @@datadir`;
+
+--list_files $MYSQLD_DATADIR/test
+perl;
+do "$ENV{MTR_SUITE_DIR}/include/innodb-util.pl";
+ib_backup_tablespaces("test", "t1");
+EOF
+
+UNLOCK TABLES;
+SET GLOBAL innodb_compression_algorithm=0;
+ALTER TABLE t1 FORCE;
+ALTER TABLE t1 DISCARD TABLESPACE;
+
+--list_files $MYSQLD_DATADIR/test
+perl;
+do "$ENV{MTR_SUITE_DIR}/include/innodb-util.pl";
+ib_discard_tablespaces("test", "t1");
+ib_restore_tablespaces("test", "t1");
+EOF
+
+ALTER TABLE t1 IMPORT TABLESPACE;
+INSERT INTO t1 VALUES(2);
+SELECT * FROM t1;
+
+
+--error 0,ER_WRONG_VALUE_FOR_VAR
+SET GLOBAL innodb_compression_algorithm=3;
+FLUSH TABLE t1 FOR EXPORT;
+--echo # List before copying files
+let MYSQLD_DATADIR =`SELECT @@datadir`;
+
+--list_files $MYSQLD_DATADIR/test
+perl;
+do "$ENV{MTR_SUITE_DIR}/include/innodb-util.pl";
+ib_backup_tablespaces("test", "t1");
+EOF
+
+UNLOCK TABLES;
+SET GLOBAL innodb_compression_algorithm=0;
+ALTER TABLE t1 FORCE;
+ALTER TABLE t1 DISCARD TABLESPACE;
+
+--echo # Display the discarded table name by using SPACE and PAGE_NO
+--echo # column in INNODB_SYS_INDEXES and discard doesn't affect the
+--echo # SPACE in INNODB_SYS_TABLES
+SELECT t.NAME, t.SPACE BETWEEN 1 and 0xFFFFFFEF as SYS_TABLE_SPACE_RANGE
+FROM INFORMATION_SCHEMA.INNODB_SYS_TABLES t
+WHERE t.TABLE_ID IN (
+ SELECT i.TABLE_ID FROM
+ INFORMATION_SCHEMA.INNODB_SYS_INDEXES i WHERE
+ i.PAGE_NO IS NULL and i.SPACE IS NULL);
+
+--list_files $MYSQLD_DATADIR/test
+perl;
+do "$ENV{MTR_SUITE_DIR}/include/innodb-util.pl";
+ib_discard_tablespaces("test", "t1");
+ib_restore_tablespaces("test", "t1");
+EOF
+
+ALTER TABLE t1 IMPORT TABLESPACE;
+INSERT INTO t1 VALUES(3);
+SELECT * FROM t1;
+DROP TABLE t1;
+
+SET GLOBAL innodb_compression_algorithm=@save_algo;
diff --git a/mysql-test/suite/innodb/t/gap_lock_split.test b/mysql-test/suite/innodb/t/gap_lock_split.test
new file mode 100644
index 00000000..c67e693f
--- /dev/null
+++ b/mysql-test/suite/innodb/t/gap_lock_split.test
@@ -0,0 +1,43 @@
+--source include/have_innodb.inc
+--source include/have_sequence.inc
+--source include/have_debug.inc
+--source include/have_debug_sync.inc
+
+CREATE TABLE t1(id INT PRIMARY key, val VARCHAR(16000))
+ ENGINE=InnoDB STATS_PERSISTENT=0;
+INSERT INTO t1 (id,val) SELECT 2*seq,'x' FROM seq_0_to_1023;
+
+connect(con1,localhost,root,,);
+source include/wait_all_purged.inc;
+# Prevent purge.
+START TRANSACTION WITH CONSISTENT SNAPSHOT;
+connection default;
+
+DELETE FROM t1 WHERE id=1788;
+
+SET @saved_dbug = @@GLOBAL.debug_dbug;
+SET @@GLOBAL.debug_dbug="d,enable_row_purge_del_mark_exit_sync_point";
+
+BEGIN;
+# This will return no result, but should acquire a gap lock.
+SELECT * FROM t1 WHERE id=1788 FOR UPDATE;
+
+connection con1;
+COMMIT;
+SET DEBUG_SYNC = 'now WAIT_FOR row_purge_del_mark_finished';
+SET @@GLOBAL.debug_dbug = @saved_dbug;
+
+connection default;
+
+INSERT INTO t1 (id,val) VALUES (1787, REPEAT('x',2000));
+
+connection con1;
+SET innodb_lock_wait_timeout=0;
+--error ER_LOCK_WAIT_TIMEOUT
+INSERT INTO t1 (id,val) VALUES (1788, 'x');
+SELECT * FROM t1 WHERE id=1788 FOR UPDATE;
+disconnect con1;
+
+connection default;
+COMMIT;
+DROP TABLE t1;
diff --git a/mysql-test/suite/innodb/t/gap_locks.test b/mysql-test/suite/innodb/t/gap_locks.test
new file mode 100644
index 00000000..77ce2c84
--- /dev/null
+++ b/mysql-test/suite/innodb/t/gap_locks.test
@@ -0,0 +1,29 @@
+--source include/have_innodb.inc
+
+CREATE TABLE t1(a INT PRIMARY KEY, b VARCHAR(40), c INT, INDEX(b,c))
+ENGINE=InnoDB;
+INSERT INTO t1 VALUES (1,'1',1),(2,'2',1);
+
+SET @save_locks= @@GLOBAL.innodb_status_output_locks;
+SET GLOBAL INNODB_STATUS_OUTPUT_LOCKS = 'ON';
+
+let $isolation= 4;
+while ($isolation) {
+let $tx_isolation= `SELECT CASE $isolation
+WHEN 1 THEN 'READ UNCOMMITTED'
+WHEN 2 THEN 'READ COMMITTED'
+WHEN 3 THEN 'REPEATABLE READ'
+ELSE 'SERIALIZABLE' END`;
+
+eval SET TRANSACTION ISOLATION LEVEL $tx_isolation;
+BEGIN;
+DELETE FROM t1 WHERE b='2' AND c=2;
+--replace_regex /.*(\d+ lock struct...), heap size \d+(, \d+ row lock...).*/\1\2/
+SHOW ENGINE INNODB STATUS;
+ROLLBACK;
+
+dec $isolation;
+}
+
+SET GLOBAL INNODB_STATUS_OUTPUT_LOCKS = @save_locks;
+DROP TABLE t1;
diff --git a/mysql-test/suite/innodb/t/group_commit.test b/mysql-test/suite/innodb/t/group_commit.test
new file mode 100644
index 00000000..3a2018be
--- /dev/null
+++ b/mysql-test/suite/innodb/t/group_commit.test
@@ -0,0 +1,120 @@
+--source include/have_innodb.inc
+--source include/have_debug_sync.inc
+--source include/have_log_bin.inc
+
+# Test some group commit code paths by using debug_sync to do controlled
+# commits of 6 transactions: first 1 alone, then 3 as a group, then 2 as a
+# group.
+#
+# Group 3 is allowed to race as far as possible ahead before group 2 finishes
+# to check some edge case for concurrency control.
+
+CREATE TABLE t1 (a VARCHAR(10) PRIMARY KEY) ENGINE=innodb;
+# MDEV-515 takes X-lock on the table for the first insert.
+# So concurrent insert won't happen on the table
+INSERT INTO t1 VALUES(100);
+
+SELECT variable_value INTO @commits FROM information_schema.global_status
+ WHERE variable_name = 'binlog_commits';
+SELECT variable_value INTO @group_commits FROM information_schema.global_status
+ WHERE variable_name = 'binlog_group_commits';
+
+connect(con1,localhost,root,,);
+connect(con2,localhost,root,,);
+connect(con3,localhost,root,,);
+connect(con4,localhost,root,,);
+connect(con5,localhost,root,,);
+connect(con6,localhost,root,,);
+
+# Start group1 (with one thread) doing commit, waiting for
+# group2 to queue up before finishing.
+
+connection con1;
+SET DEBUG_SYNC= "commit_before_get_LOCK_after_binlog_sync SIGNAL group1_running WAIT_FOR group2_queued";
+send INSERT INTO t1 VALUES ("con1");
+
+# Make group2 (with three threads) queue up.
+# Make sure con2 is the group commit leader for group2.
+# Make group2 wait with running commit_ordered() until group3 has committed.
+
+connection con2;
+set DEBUG_SYNC= "now WAIT_FOR group1_running";
+SET DEBUG_SYNC= "commit_after_prepare_ordered SIGNAL group2_con2";
+SET DEBUG_SYNC= "commit_before_get_LOCK_after_binlog_sync SIGNAL group2_running";
+SET DEBUG_SYNC= "commit_after_release_LOCK_log WAIT_FOR group3_committed";
+SET DEBUG_SYNC= "commit_after_group_run_commit_ordered SIGNAL group2_visible WAIT_FOR group2_checked";
+send INSERT INTO t1 VALUES ("con2");
+connection con3;
+SET DEBUG_SYNC= "now WAIT_FOR group2_con2";
+SET DEBUG_SYNC= "commit_after_prepare_ordered SIGNAL group2_con3";
+send INSERT INTO t1 VALUES ("con3");
+connection con4;
+SET DEBUG_SYNC= "now WAIT_FOR group2_con3";
+SET DEBUG_SYNC= "commit_after_prepare_ordered SIGNAL group2_con4";
+send INSERT INTO t1 VALUES ("con4");
+
+# When group2 is queued, let group1 continue and queue group3.
+
+connection default;
+SET DEBUG_SYNC= "now WAIT_FOR group2_con4";
+
+# At this point, trasaction 1 is still not visible as commit_ordered() has not
+# been called yet.
+SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED;
+SELECT * FROM t1 ORDER BY a;
+
+SET DEBUG_SYNC= "now SIGNAL group2_queued";
+connection con1;
+reap;
+
+# Now transaction 1 is visible.
+connection default;
+SELECT * FROM t1 ORDER BY a;
+
+connection con5;
+SET DEBUG_SYNC= "commit_before_get_LOCK_after_binlog_sync SIGNAL group3_con5";
+SET DEBUG_SYNC= "commit_after_get_LOCK_log SIGNAL con5_leader WAIT_FOR con6_queued";
+set DEBUG_SYNC= "now WAIT_FOR group2_running";
+send INSERT INTO t1 VALUES ("con5");
+
+connection con6;
+SET DEBUG_SYNC= "now WAIT_FOR con5_leader";
+SET DEBUG_SYNC= "commit_after_prepare_ordered SIGNAL con6_queued";
+send INSERT INTO t1 VALUES ("con6");
+
+connection default;
+SET DEBUG_SYNC= "now WAIT_FOR group3_con5";
+# Still only transaction 1 visible, as group2 have not yet run commit_ordered().
+SELECT * FROM t1 ORDER BY a;
+SET DEBUG_SYNC= "now SIGNAL group3_committed";
+SET DEBUG_SYNC= "now WAIT_FOR group2_visible";
+# Now transactions 1-4 visible.
+SELECT * FROM t1 ORDER BY a;
+SET DEBUG_SYNC= "now SIGNAL group2_checked";
+
+connection con2;
+reap;
+
+connection con3;
+reap;
+
+connection con4;
+reap;
+
+connection con5;
+reap;
+
+connection con6;
+reap;
+
+connection default;
+# Check all transactions finally visible.
+SELECT * FROM t1 ORDER BY a;
+
+SELECT variable_value - @commits FROM information_schema.global_status
+ WHERE variable_name = 'binlog_commits';
+SELECT variable_value - @group_commits FROM information_schema.global_status
+ WHERE variable_name = 'binlog_group_commits';
+
+SET DEBUG_SYNC= 'RESET';
+DROP TABLE t1;
diff --git a/mysql-test/suite/innodb/t/group_commit_binlog_pos-master.opt b/mysql-test/suite/innodb/t/group_commit_binlog_pos-master.opt
new file mode 100644
index 00000000..590d44a6
--- /dev/null
+++ b/mysql-test/suite/innodb/t/group_commit_binlog_pos-master.opt
@@ -0,0 +1 @@
+--loose-skip-stack-trace --skip-core-file
diff --git a/mysql-test/suite/innodb/t/group_commit_binlog_pos.test b/mysql-test/suite/innodb/t/group_commit_binlog_pos.test
new file mode 100644
index 00000000..c2e38d54
--- /dev/null
+++ b/mysql-test/suite/innodb/t/group_commit_binlog_pos.test
@@ -0,0 +1,105 @@
+--source include/have_innodb.inc
+--source include/have_debug_sync.inc
+--source include/have_log_bin.inc
+--source include/have_binlog_format_mixed_or_statement.inc
+--source include/binlog_start_pos.inc
+
+# Need DBUG to crash the server intentionally
+--source include/have_debug.inc
+# Don't test this under valgrind, memory leaks will occur as we crash
+--source include/not_valgrind.inc
+
+# The test case currently uses sed and tail, which may be unavailable on
+# some windows systems. But see MWL#191 for how to remove the need for grep.
+--source include/not_windows.inc
+
+# XtraDB stores the binlog position corresponding to the last commit, and
+# prints it during crash recovery.
+# Test that we get the correct position when we group commit several
+# transactions together.
+
+# What we really want to test here is what happens when a group of
+# transactions get written only partially to disk inside InnoDB before
+# the crash. But that is hard to test in mysql-test-run automated
+# tests. Instead, we use debug_sync to tightly control when each
+# transaction is written to the redo log. And we set
+# innodb_flush_log_at_trx_commit=3 so that we can write out
+# transactions individually - as with
+# innodb_flush_log_at_trx_commit=1, all commits are written together,
+# as part of a commit_checkpoint.
+# (Note that we do not have to restore innodb_flush_log_at_trx_commit, as
+# we crash the server).
+SET GLOBAL innodb_flush_log_at_trx_commit=3;
+
+CREATE TABLE t1 (a INT PRIMARY KEY) ENGINE=innodb;
+INSERT INTO t1 VALUES (0);
+
+connect(con1,localhost,root,,);
+connect(con2,localhost,root,,);
+connect(con3,localhost,root,,);
+
+# Queue up three commits for group commit.
+
+connection con1;
+SET DEBUG_SYNC= "commit_after_get_LOCK_log SIGNAL con1_waiting WAIT_FOR con3_queued";
+SET DEBUG_SYNC= "commit_loop_entry_commit_ordered SIGNAL con1_loop WAIT_FOR con1_loop_cont EXECUTE 3";
+send INSERT INTO t1 VALUES (1);
+
+connection con2;
+SET DEBUG_SYNC= "now WAIT_FOR con1_waiting";
+SET DEBUG_SYNC= "commit_after_prepare_ordered SIGNAL con2_queued";
+send INSERT INTO t1 VALUES (2);
+
+connection con3;
+SET DEBUG_SYNC= "now WAIT_FOR con2_queued";
+SET DEBUG_SYNC= "commit_after_prepare_ordered SIGNAL con3_queued";
+send INSERT INTO t1 VALUES (3);
+
+connection default;
+SET DEBUG_SYNC= "now WAIT_FOR con1_loop";
+# At this point, no transactions are committed.
+SET DEBUG_SYNC= "now SIGNAL con1_loop_cont";
+SET DEBUG_SYNC= "now WAIT_FOR con1_loop";
+# At this point, 1 transaction is committed.
+SET DEBUG_SYNC= "now SIGNAL con1_loop_cont";
+SET DEBUG_SYNC= "now WAIT_FOR con1_loop";
+
+# At this point, 2 transactions are committed.
+SELECT * FROM t1 ORDER BY a;
+
+connection con2;
+reap;
+
+# Now crash the server with 1+2 in-memory committed, 3 only prepared.
+connection default;
+system echo wait-group_commit_binlog_pos.test >> $MYSQLTEST_VARDIR/tmp/mysqld.1.expect;
+SET SESSION debug_dbug="+d,crash_dispatch_command_before";
+--error 2006,2013
+SELECT 1;
+
+connection con1;
+--error 2006,2013
+reap;
+connection con3;
+--error 2006,2013
+reap;
+
+system echo restart-group_commit_binlog_pos.test >> $MYSQLTEST_VARDIR/tmp/mysqld.1.expect;
+
+connection default;
+--enable_reconnect
+--source include/wait_until_connected_again.inc
+
+# Crash recovery should recover all three transactions.
+SELECT * FROM t1 ORDER BY a;
+
+# Check that the binlog position reported by InnoDB is the correct one
+# for the end of the second transaction (as can be checked with
+# mysqlbinlog).
+let $MYSQLD_DATADIR= `SELECT @@datadir`;
+let pos=`select $binlog_start_pos + 739`;
+--replace_result $pos <pos>
+--exec sed -ne 's/.*\(InnoDB: Last binlog file .* position.*\)/\1/p' $MYSQLD_DATADIR/../../log/mysqld.1.err | tail -1
+
+SET DEBUG_SYNC= 'RESET';
+DROP TABLE t1;
diff --git a/mysql-test/suite/innodb/t/group_commit_binlog_pos_no_optimize_thread-master.opt b/mysql-test/suite/innodb/t/group_commit_binlog_pos_no_optimize_thread-master.opt
new file mode 100644
index 00000000..b8c4666a
--- /dev/null
+++ b/mysql-test/suite/innodb/t/group_commit_binlog_pos_no_optimize_thread-master.opt
@@ -0,0 +1 @@
+--binlog-optimize-thread-scheduling=0 --loose-skip-stack-trace --skip-core-file
diff --git a/mysql-test/suite/innodb/t/group_commit_binlog_pos_no_optimize_thread.test b/mysql-test/suite/innodb/t/group_commit_binlog_pos_no_optimize_thread.test
new file mode 100644
index 00000000..250f0bee
--- /dev/null
+++ b/mysql-test/suite/innodb/t/group_commit_binlog_pos_no_optimize_thread.test
@@ -0,0 +1,105 @@
+--source include/have_innodb.inc
+--source include/have_debug_sync.inc
+--source include/have_log_bin.inc
+--source include/have_binlog_format_mixed_or_statement.inc
+--source include/binlog_start_pos.inc
+
+# Need DBUG to crash the server intentionally
+--source include/have_debug.inc
+# Don't test this under valgrind, memory leaks will occur as we crash
+--source include/not_valgrind.inc
+
+# The test case currently uses sed and tail, which may be unavailable on
+# some windows systems. But see MWL#191 for how to remove the need for grep.
+--source include/not_windows.inc
+
+# XtraDB stores the binlog position corresponding to the last commit, and
+# prints it during crash recovery.
+# Test that we get the correct position when we group commit several
+# transactions together.
+
+# What we really want to test here is what happens when a group of
+# transactions get written only partially to disk inside InnoDB before
+# the crash. But that is hard to test in mysql-test-run automated
+# tests. Instead, we use debug_sync to tightly control when each
+# transaction is written to the redo log. And we set
+# innodb_flush_log_at_trx_commit=3 so that we can write out
+# transactions individually - as with
+# innodb_flush_log_at_trx_commit=1, all commits are written together,
+# as part of a commit_checkpoint.
+# (Note that we do not have to restore innodb_flush_log_at_trx_commit, as
+# we crash the server).
+SET GLOBAL innodb_flush_log_at_trx_commit=3;
+
+CREATE TABLE t1 (a INT PRIMARY KEY) ENGINE=innodb;
+INSERT INTO t1 VALUES (0);
+
+connect(con1,localhost,root,,);
+connect(con2,localhost,root,,);
+connect(con3,localhost,root,,);
+
+# Queue up three commits for group commit.
+
+connection con1;
+SET DEBUG_SYNC= "commit_after_get_LOCK_log SIGNAL con1_waiting WAIT_FOR con3_queued";
+SET DEBUG_SYNC= "commit_loop_entry_commit_ordered SIGNAL con1_loop WAIT_FOR con1_loop_cont";
+send INSERT INTO t1 VALUES (1);
+
+connection con2;
+SET DEBUG_SYNC= "now WAIT_FOR con1_waiting";
+SET DEBUG_SYNC= "commit_after_prepare_ordered SIGNAL con2_queued";
+SET DEBUG_SYNC= "commit_loop_entry_commit_ordered SIGNAL con1_loop WAIT_FOR con1_loop_cont";
+send INSERT INTO t1 VALUES (2);
+
+connection con3;
+SET DEBUG_SYNC= "now WAIT_FOR con2_queued";
+SET DEBUG_SYNC= "commit_after_prepare_ordered SIGNAL con3_queued";
+SET DEBUG_SYNC= "commit_loop_entry_commit_ordered SIGNAL con1_loop WAIT_FOR con1_loop_cont";
+send INSERT INTO t1 VALUES (3);
+
+connection default;
+SET DEBUG_SYNC= "now WAIT_FOR con1_loop";
+# At this point, no transactions are committed.
+SET DEBUG_SYNC= "now SIGNAL con1_loop_cont";
+SET DEBUG_SYNC= "now WAIT_FOR con1_loop";
+# At this point, 1 transaction is committed.
+SET DEBUG_SYNC= "now SIGNAL con1_loop_cont";
+SET DEBUG_SYNC= "now WAIT_FOR con1_loop";
+
+# At this point, 2 transactions are committed.
+SELECT * FROM t1 ORDER BY a;
+
+connection con1;
+reap;
+connection con2;
+reap;
+
+# Now crash the server with 1+2 in-memory committed, 3 only prepared.
+connection default;
+system echo wait-group_commit_binlog_pos_no_optimize_thread.test >> $MYSQLTEST_VARDIR/tmp/mysqld.1.expect;
+SET SESSION debug_dbug="+d,crash_dispatch_command_before";
+--error 2006,2013
+SELECT 1;
+
+connection con3;
+--error 2006,2013
+reap;
+
+system echo restart-group_commit_binlog_pos_no_optimize_thread.test >> $MYSQLTEST_VARDIR/tmp/mysqld.1.expect;
+
+connection default;
+--enable_reconnect
+--source include/wait_until_connected_again.inc
+
+# Crash recovery should recover all three transactions.
+SELECT * FROM t1 ORDER BY a;
+
+# Check that the binlog position reported by InnoDB is the correct one
+# for the end of the second transaction (as can be checked with
+# mysqlbinlog).
+let $MYSQLD_DATADIR= `SELECT @@datadir`;
+let pos=`select $binlog_start_pos + 739`;
+--replace_result $pos <pos>
+--exec sed -ne 's/.*\(InnoDB: Last binlog file .* position.*\)/\1/p' $MYSQLD_DATADIR/../../log/mysqld.1.err | tail -1
+SET DEBUG_SYNC= 'RESET';
+DROP TABLE t1;
diff --git a/mysql-test/suite/innodb/t/group_commit_crash-master.opt b/mysql-test/suite/innodb/t/group_commit_crash-master.opt
new file mode 100644
index 00000000..590d44a6
--- /dev/null
+++ b/mysql-test/suite/innodb/t/group_commit_crash-master.opt
@@ -0,0 +1 @@
+--loose-skip-stack-trace --skip-core-file
diff --git a/mysql-test/suite/innodb/t/group_commit_crash.test b/mysql-test/suite/innodb/t/group_commit_crash.test
new file mode 100644
index 00000000..12f7ba20
--- /dev/null
+++ b/mysql-test/suite/innodb/t/group_commit_crash.test
@@ -0,0 +1,78 @@
+--source include/have_innodb.inc
+# Testing group commit by crashing a few times.
+# Test adapted from the Facebook patch: lp:mysqlatfacebook
+--source include/not_embedded.inc
+# Don't test this under valgrind, memory leaks will occur
+--source include/not_valgrind.inc
+
+# Binary must be compiled with debug for crash to occur
+--source include/have_debug.inc
+--source include/have_log_bin.inc
+
+CREATE TABLE t1(a CHAR(255),
+ b CHAR(255),
+ c CHAR(255),
+ d CHAR(255),
+ id INT,
+ PRIMARY KEY(id)) ENGINE=InnoDB;
+create table t2 like t1;
+delimiter //;
+create procedure setcrash(IN i INT)
+begin
+ CASE i
+ WHEN 1 THEN SET SESSION debug_dbug="d,crash_commit_after_prepare";
+ WHEN 2 THEN SET SESSION debug_dbug="d,crash_commit_after_log";
+ WHEN 3 THEN SET SESSION debug_dbug="d,crash_commit_before_unlog";
+ WHEN 4 THEN SET SESSION debug_dbug="d,crash_commit_after";
+ WHEN 5 THEN SET SESSION debug_dbug="d,crash_commit_before";
+ ELSE BEGIN END;
+ END CASE;
+end //
+delimiter ;//
+# Avoid getting a crashed mysql.proc table.
+FLUSH TABLES;
+
+let $numtests = 5;
+
+let $numinserts = 10;
+while ($numinserts)
+{
+ dec $numinserts;
+ eval INSERT INTO t2(a, b, c, d, id) VALUES ('a', 'b', 'c', 'd', $numinserts+1);
+}
+
+--enable_reconnect
+
+while ($numtests)
+{
+ SET binlog_format= mixed;
+ RESET MASTER;
+
+ START TRANSACTION;
+ insert into t1 select * from t2;
+ # Write file to make mysql-test-run.pl expect crash
+ --exec echo "restart" > $MYSQLTEST_VARDIR/tmp/mysqld.1.expect
+
+ eval call setcrash($numtests);
+
+ # Run the crashing query
+ --error 2006,2013
+ COMMIT;
+
+ # Poll the server waiting for it to be back online again.
+ --source include/wait_until_connected_again.inc
+
+ # table and binlog should be in sync.
+ SELECT * FROM t1 ORDER BY id;
+--replace_column 2 # 5 #
+ SHOW BINLOG EVENTS LIMIT 4,1;
+
+ delete from t1;
+
+ dec $numtests;
+}
+
+# final cleanup
+DROP TABLE t1;
+DROP TABLE t2;
+DROP PROCEDURE setcrash;
diff --git a/mysql-test/suite/innodb/t/group_commit_crash_no_optimize_thread-master.opt b/mysql-test/suite/innodb/t/group_commit_crash_no_optimize_thread-master.opt
new file mode 100644
index 00000000..b8c4666a
--- /dev/null
+++ b/mysql-test/suite/innodb/t/group_commit_crash_no_optimize_thread-master.opt
@@ -0,0 +1 @@
+--binlog-optimize-thread-scheduling=0 --loose-skip-stack-trace --skip-core-file
diff --git a/mysql-test/suite/innodb/t/group_commit_crash_no_optimize_thread.test b/mysql-test/suite/innodb/t/group_commit_crash_no_optimize_thread.test
new file mode 100644
index 00000000..6115e3f0
--- /dev/null
+++ b/mysql-test/suite/innodb/t/group_commit_crash_no_optimize_thread.test
@@ -0,0 +1,78 @@
+--source include/have_innodb.inc
+# Testing group commit by crashing a few times.
+# Test adapted from the Facebook patch: lp:mysqlatfacebook
+--source include/not_embedded.inc
+# Don't test this under valgrind, memory leaks will occur
+--source include/not_valgrind.inc
+
+# Binary must be compiled with debug for crash to occur
+--source include/have_debug.inc
+--source include/have_log_bin.inc
+
+CREATE TABLE t1(a CHAR(255),
+ b CHAR(255),
+ c CHAR(255),
+ d CHAR(255),
+ id INT,
+ PRIMARY KEY(id)) ENGINE=InnoDB;
+create table t2 like t1;
+delimiter //;
+create procedure setcrash(IN i INT)
+begin
+ CASE i
+ WHEN 1 THEN SET SESSION debug_dbug="d,crash_commit_after_prepare";
+ WHEN 2 THEN SET SESSION debug_dbug="d,crash_commit_after_log";
+ WHEN 3 THEN SET SESSION debug_dbug="d,crash_commit_before_unlog";
+ WHEN 4 THEN SET SESSION debug_dbug="d,crash_commit_after";
+ WHEN 5 THEN SET SESSION debug_dbug="d,crash_commit_before";
+ ELSE BEGIN END;
+ END CASE;
+end //
+delimiter ;//
+# Avoid getting a crashed mysql.proc table.
+FLUSH TABLES;
+
+let $numtests = 5;
+
+let $numinserts = 10;
+while ($numinserts)
+{
+ dec $numinserts;
+ eval INSERT INTO t2(a, b, c, d, id) VALUES ('a', 'b', 'c', 'd', 1+$numinserts);
+}
+
+--enable_reconnect
+
+while ($numtests)
+{
+ SET binlog_format= mixed;
+ RESET MASTER;
+
+ START TRANSACTION;
+ insert into t1 select * from t2;
+ # Write file to make mysql-test-run.pl expect crash
+ --exec echo "restart" > $MYSQLTEST_VARDIR/tmp/mysqld.1.expect
+
+ eval call setcrash($numtests);
+
+ # Run the crashing query
+ --error 2006,2013
+ COMMIT;
+
+ # Poll the server waiting for it to be back online again.
+ --source include/wait_until_connected_again.inc
+
+ # table and binlog should be in sync.
+ SELECT * FROM t1 ORDER BY id;
+--replace_column 2 # 5 #
+ SHOW BINLOG EVENTS LIMIT 4,1;
+
+ delete from t1;
+
+ dec $numtests;
+}
+
+# final cleanup
+DROP TABLE t1;
+DROP TABLE t2;
+DROP PROCEDURE setcrash;
diff --git a/mysql-test/suite/innodb/t/group_commit_force_recovery-master.opt b/mysql-test/suite/innodb/t/group_commit_force_recovery-master.opt
new file mode 100644
index 00000000..65470e63
--- /dev/null
+++ b/mysql-test/suite/innodb/t/group_commit_force_recovery-master.opt
@@ -0,0 +1 @@
+--innodb-force-recovery=2
diff --git a/mysql-test/suite/innodb/t/group_commit_force_recovery.test b/mysql-test/suite/innodb/t/group_commit_force_recovery.test
new file mode 100644
index 00000000..0e476747
--- /dev/null
+++ b/mysql-test/suite/innodb/t/group_commit_force_recovery.test
@@ -0,0 +1,21 @@
+# MDEV-24302 RESET MASTER hangs as Innodb does not report on binlog checkpoint
+# Testing binlog checkpoint notification works under stringent condition
+# set by innodb_force_recovery = 2.
+
+--source include/have_innodb.inc
+--source include/have_binlog_format_mixed.inc
+
+# Binlog checkpoint notification consumers such as RESET MASTER
+# receive one when lsn_0 at the time of the request is finally gets flushed
+# flush_lsn >= lsn_0
+# The bug situation was that when lsn_0 reflects a write of an internal innodb trx
+# and RESET MASTER was not followed by any more user transaction
+# it would hang.
+
+CREATE TABLE t1(a int) ENGINE=InnoDB;
+INSERT INTO t1 SET a=1;
+RESET MASTER;
+
+# final cleanup
+DROP TABLE t1;
+--echo End of the tests.
diff --git a/mysql-test/suite/innodb/t/group_commit_no_optimize_thread-master.opt b/mysql-test/suite/innodb/t/group_commit_no_optimize_thread-master.opt
new file mode 100644
index 00000000..97d8c106
--- /dev/null
+++ b/mysql-test/suite/innodb/t/group_commit_no_optimize_thread-master.opt
@@ -0,0 +1 @@
+--binlog-optimize-thread-scheduling=0
diff --git a/mysql-test/suite/innodb/t/group_commit_no_optimize_thread.test b/mysql-test/suite/innodb/t/group_commit_no_optimize_thread.test
new file mode 100644
index 00000000..107fc6f4
--- /dev/null
+++ b/mysql-test/suite/innodb/t/group_commit_no_optimize_thread.test
@@ -0,0 +1,120 @@
+--source include/have_innodb.inc
+--source include/have_debug_sync.inc
+--source include/have_log_bin.inc
+
+# Test some group commit code paths by using debug_sync to do controlled
+# commits of 6 transactions: first 1 alone, then 3 as a group, then 2 as a
+# group.
+#
+# Group 3 is allowed to race as far as possible ahead before group 2 finishes
+# to check some edge case for concurrency control.
+
+CREATE TABLE t1 (a VARCHAR(10) PRIMARY KEY) ENGINE=innodb;
+# MDEV-515 takes X-LOCK on the table for the first insert.
+# So concurrent insert won't happen on the table
+INSERT INTO t1 VALUES("default");
+
+SELECT variable_value INTO @commits FROM information_schema.global_status
+ WHERE variable_name = 'binlog_commits';
+SELECT variable_value INTO @group_commits FROM information_schema.global_status
+ WHERE variable_name = 'binlog_group_commits';
+
+connect(con1,localhost,root,,);
+connect(con2,localhost,root,,);
+connect(con3,localhost,root,,);
+connect(con4,localhost,root,,);
+connect(con5,localhost,root,,);
+connect(con6,localhost,root,,);
+
+# Start group1 (with one thread) doing commit, waiting for
+# group2 to queue up before finishing.
+
+connection con1;
+SET DEBUG_SYNC= "commit_before_get_LOCK_after_binlog_sync SIGNAL group1_running WAIT_FOR group2_queued";
+send INSERT INTO t1 VALUES ("con1");
+
+# Make group2 (with three threads) queue up.
+# Make sure con2 is the group commit leader for group2.
+# Make group2 wait with running commit_ordered() until group3 has committed.
+
+connection con2;
+set DEBUG_SYNC= "now WAIT_FOR group1_running";
+SET DEBUG_SYNC= "commit_after_prepare_ordered SIGNAL group2_con2";
+SET DEBUG_SYNC= "commit_before_get_LOCK_after_binlog_sync SIGNAL group2_running";
+SET DEBUG_SYNC= "commit_after_release_LOCK_log WAIT_FOR group3_committed";
+send INSERT INTO t1 VALUES ("con2");
+connection con3;
+SET DEBUG_SYNC= "now WAIT_FOR group2_con2";
+SET DEBUG_SYNC= "commit_after_prepare_ordered SIGNAL group2_con3";
+send INSERT INTO t1 VALUES ("con3");
+connection con4;
+SET DEBUG_SYNC= "now WAIT_FOR group2_con3";
+SET DEBUG_SYNC= "commit_after_prepare_ordered SIGNAL group2_con4";
+SET DEBUG_SYNC= "commit_after_group_run_commit_ordered SIGNAL group2_visible WAIT_FOR group2_checked";
+send INSERT INTO t1 VALUES ("con4");
+
+# When group2 is queued, let group1 continue and queue group3.
+
+connection default;
+SET DEBUG_SYNC= "now WAIT_FOR group2_con4";
+
+# At this point, trasaction 1 is still not visible as commit_ordered() has not
+# been called yet.
+SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED;
+SELECT * FROM t1 ORDER BY a;
+
+SET DEBUG_SYNC= "now SIGNAL group2_queued";
+connection con1;
+reap;
+
+# Now transaction 1 is visible.
+connection default;
+SELECT * FROM t1 ORDER BY a;
+
+connection con5;
+SET DEBUG_SYNC= "commit_before_get_LOCK_after_binlog_sync SIGNAL group3_con5";
+SET DEBUG_SYNC= "commit_after_get_LOCK_log SIGNAL con5_leader WAIT_FOR con6_queued";
+set DEBUG_SYNC= "now WAIT_FOR group2_running";
+send INSERT INTO t1 VALUES ("con5");
+
+connection con6;
+SET DEBUG_SYNC= "now WAIT_FOR con5_leader";
+SET DEBUG_SYNC= "commit_after_prepare_ordered SIGNAL con6_queued";
+send INSERT INTO t1 VALUES ("con6");
+
+connection default;
+SET DEBUG_SYNC= "now WAIT_FOR group3_con5";
+# Still only transaction 1 visible, as group2 have not yet run commit_ordered().
+SELECT * FROM t1 ORDER BY a;
+SET DEBUG_SYNC= "now SIGNAL group3_committed";
+SET DEBUG_SYNC= "now WAIT_FOR group2_visible";
+# Now transactions 1-4 visible.
+SELECT * FROM t1 ORDER BY a;
+SET DEBUG_SYNC= "now SIGNAL group2_checked";
+
+connection con2;
+reap;
+
+connection con3;
+reap;
+
+connection con4;
+reap;
+
+connection con5;
+reap;
+
+connection con6;
+reap;
+
+connection default;
+# Check all transactions finally visible.
+SELECT * FROM t1 ORDER BY a;
+
+SELECT variable_value - @commits FROM information_schema.global_status
+ WHERE variable_name = 'binlog_commits';
+SELECT variable_value - @group_commits FROM information_schema.global_status
+ WHERE variable_name = 'binlog_group_commits';
+
+SET DEBUG_SYNC= 'RESET';
+DROP TABLE t1;
diff --git a/mysql-test/suite/innodb/t/help_url.test b/mysql-test/suite/innodb/t/help_url.test
new file mode 100644
index 00000000..bcf74c31
--- /dev/null
+++ b/mysql-test/suite/innodb/t/help_url.test
@@ -0,0 +1,8 @@
+#
+# MDEV-4273 MYSQL_VERSION_MAJOR.MYSQL_VERSION_MINOR not replaced
+#
+--source include/have_innodb.inc
+--source include/not_embedded.inc
+
+create table innodb_table_monitor (a int) engine=InnoDB;
+drop table innodb_table_monitor;
diff --git a/mysql-test/suite/innodb/t/ibuf_delete.test b/mysql-test/suite/innodb/t/ibuf_delete.test
new file mode 100644
index 00000000..82b740b6
--- /dev/null
+++ b/mysql-test/suite/innodb/t/ibuf_delete.test
@@ -0,0 +1,67 @@
+--source include/have_innodb.inc
+--source include/have_sequence.inc
+
+SET @buffering= @@innodb_change_buffering;
+SET GLOBAL innodb_change_buffering= deletes;
+SET @flush= @@innodb_flush_log_at_trx_commit;
+SET GLOBAL innodb_flush_log_at_trx_commit= 0;
+
+CREATE TABLE t1 (
+ a varchar(1024),
+ b varchar(1024),
+ c varchar(1024),
+ d varchar(1024),
+ e varchar(1024),
+ f varchar(1024),
+ g varchar(1024),
+ h varchar(1024),
+ key (a),
+ key (b),
+ key (c),
+ key (d)
+) ENGINE=InnoDB;
+
+INSERT INTO t1
+SELECT REPEAT('x',10), REPEAT('x',13), REPEAT('x',427), REPEAT('x',244),
+REPEAT('x',9), REPEAT('x',112), REPEAT('x',814), REPEAT('x',633)
+FROM seq_1_to_1024;
+
+CREATE TEMPORARY TABLE t2 (
+ a varchar(1024),
+ b varchar(1024),
+ c varchar(1024),
+ d varchar(1024),
+ e varchar(1024),
+ f varchar(1024),
+ g varchar(1024),
+ h varchar(1024),
+ i varchar(1024),
+ j varchar(1024),
+ k varchar(1024),
+ l varchar(1024),
+ m varchar(1024),
+ key (a),
+ key (b),
+ key (c),
+ key (d),
+ key (e),
+ key (f)
+) ENGINE=InnoDB;
+
+SET @x=REPEAT('x',512);
+INSERT INTO t2 SELECT @x, @x, @x, @x, @x, @x, @x, @x, @x, @x, @x, @x, @x
+FROM seq_1_to_768;
+
+--disable_query_log
+--let $run=1024
+while ($run)
+{
+ eval DELETE FROM t1 LIMIT 1 /* $run */;
+ --dec $run
+}
+--enable_query_log
+
+# Cleanup
+DROP TABLE t1, t2;
+SET GLOBAL innodb_change_buffering= @buffering;
+SET GLOBAL innodb_flush_log_at_trx_commit= @flush;
diff --git a/mysql-test/suite/innodb/t/ibuf_not_empty.combinations b/mysql-test/suite/innodb/t/ibuf_not_empty.combinations
new file mode 100644
index 00000000..c4b45dcc
--- /dev/null
+++ b/mysql-test/suite/innodb/t/ibuf_not_empty.combinations
@@ -0,0 +1,9 @@
+[strict_crc32]
+--innodb-checksum-algorithm=strict_crc32
+--innodb-page-size=4k
+--innodb-force-recovery=2
+
+[strict_full_crc32]
+--innodb-checksum-algorithm=strict_full_crc32
+--innodb-page-size=4k
+--innodb-force-recovery=2
diff --git a/mysql-test/suite/innodb/t/ibuf_not_empty.test b/mysql-test/suite/innodb/t/ibuf_not_empty.test
new file mode 100644
index 00000000..9362f8da
--- /dev/null
+++ b/mysql-test/suite/innodb/t/ibuf_not_empty.test
@@ -0,0 +1,117 @@
+--source include/have_innodb.inc
+--source include/no_valgrind_without_big.inc
+# innodb_change_buffering_debug option is debug only
+--source include/have_debug.inc
+# Embedded server tests do not support restarting
+--source include/not_embedded.inc
+--source include/have_sequence.inc
+
+--disable_query_log
+call mtr.add_suppression("InnoDB: Failed to find tablespace for table `test`\\.`t1` in the cache\\. Attempting to load the tablespace with space id");
+call mtr.add_suppression("InnoDB: Allocated tablespace ID \\d+ for test.t1, old maximum was");
+call mtr.add_suppression("InnoDB: Failed to find tablespace for table `mysql`\\.`transaction_registry` in the cache\\. Attempting to load the tablespace with space id");
+call mtr.add_suppression("InnoDB: Allocated tablespace ID \\d+ for mysql.transaction_registry, old maximum was");
+call mtr.add_suppression("InnoDB: Trying to read 4096 bytes");
+call mtr.add_suppression("InnoDB: File './test/t1.ibd' is corrupted");
+--enable_query_log
+
+CREATE TABLE t1(
+ a INT AUTO_INCREMENT PRIMARY KEY,
+ b CHAR(1),
+ c INT,
+ INDEX(b))
+ENGINE=InnoDB STATS_PERSISTENT=0;
+
+# The flag innodb_change_buffering_debug is only available in debug builds.
+# It instructs InnoDB to try to evict pages from the buffer pool when
+# change buffering is possible, so that the change buffer will be used
+# whenever possible.
+SET GLOBAL innodb_change_buffering_debug = 1;
+SET GLOBAL innodb_change_buffering=all;
+
+# Create enough rows for the table, so that the change buffer will be
+# used for modifying the secondary index page. There must be multiple
+# index pages, because changes to the root page are never buffered.
+INSERT INTO t1 SELECT 0,'x',1 FROM seq_1_to_1024;
+let MYSQLD_DATADIR=`select @@datadir`;
+let PAGE_SIZE=`select @@innodb_page_size`;
+
+--source include/shutdown_mysqld.inc
+
+# Corrupt the change buffer bitmap, to claim that pages are clean
+perl;
+do "$ENV{MTR_SUITE_DIR}/include/crc32.pl";
+my $file = "$ENV{MYSQLD_DATADIR}/test/t1.ibd";
+open(FILE, "+<$file") || die "Unable to open $file";
+binmode FILE;
+my $ps= $ENV{PAGE_SIZE};
+my $page;
+die "Unable to read $file" unless sysread(FILE, $page, $ps) == $ps;
+my $full_crc32 = unpack("N",substr($page,54,4)) & 0x10; # FIL_SPACE_FLAGS
+die "Unable to read $file" unless sysread(FILE, $page, $ps) == $ps;
+# Clean the change buffer bitmap.
+substr($page,38,$ps - 38 - 8) = chr(0) x ($ps - 38 - 8);
+my $polynomial = 0x82f63b78; # CRC-32C
+if ($full_crc32)
+{
+ my $ck = mycrc32(substr($page, 0, $ps-4), 0, $polynomial);
+ substr($page, $ps-4, 4) = pack("N", $ck);
+}
+else
+{
+ my $ck= pack("N",mycrc32(substr($page, 4, 22), 0, $polynomial) ^
+ mycrc32(substr($page, 38, $ps - 38 - 8), 0, $polynomial));
+ substr($page,0,4)=$ck;
+ substr($page,$ps-8,4)=$ck;
+}
+sysseek(FILE, $ps, 0) || die "Unable to rewind $file\n";
+syswrite(FILE, $page, $ps)==$ps || die "Unable to write $file\n";
+close(FILE) || die "Unable to close $file";
+EOF
+
+--let $restart_parameters= --innodb-force-recovery=6 --innodb-change-buffer-dump
+--source include/start_mysqld.inc
+
+--replace_regex /contains \d+ entries/contains 990 entries/
+check table t1;
+
+--source include/shutdown_mysqld.inc
+
+# Truncate the file to 5 pages, as if it were empty
+perl;
+do "$ENV{MTR_SUITE_DIR}/include/crc32.pl";
+my $file = "$ENV{MYSQLD_DATADIR}/test/t1.ibd";
+open(FILE, "+<$file") || die "Unable to open $file";
+binmode FILE;
+my $ps= $ENV{PAGE_SIZE};
+my $pages=5;
+my $page;
+die "Unable to read $file" unless sysread(FILE, $page, $ps) == $ps;
+my $full_crc32 = unpack("N",substr($page,54,4)) & 0x10; # FIL_SPACE_FLAGS
+substr($page,46,4)=pack("N", $pages);
+my $polynomial = 0x82f63b78; # CRC-32C
+if ($full_crc32)
+{
+ my $ck = mycrc32(substr($page, 0, $ps-4), 0, $polynomial);
+ substr($page, $ps-4, 4) = pack("N", $ck);
+}
+else
+{
+ my $ck= pack("N",mycrc32(substr($page, 4, 22), 0, $polynomial) ^
+ mycrc32(substr($page, 38, $ps - 38 - 8), 0, $polynomial));
+ substr($page,0,4)=$ck;
+ substr($page,$ps-8,4)=$ck;
+}
+sysseek(FILE, 0, 0) || die "Unable to rewind $file\n";
+syswrite(FILE, $page, $ps)==$ps || die "Unable to write $file\n";
+truncate(FILE, $ps * $pages);
+close(FILE) || die "Unable to close $file";
+EOF
+
+--let $restart_parameters=--innodb-force_recovery=0
+--source include/start_mysqld.inc
+SET GLOBAL innodb_fast_shutdown=0;
+--source include/restart_mysqld.inc
+
+# Cleanup
+DROP TABLE t1;
diff --git a/mysql-test/suite/innodb/t/implicit_gap_lock_convertion.test b/mysql-test/suite/innodb/t/implicit_gap_lock_convertion.test
new file mode 100644
index 00000000..bf2d09ff
--- /dev/null
+++ b/mysql-test/suite/innodb/t/implicit_gap_lock_convertion.test
@@ -0,0 +1,21 @@
+--source include/have_innodb.inc
+--source include/count_sessions.inc
+
+CREATE TABLE t(a INT UNSIGNED PRIMARY KEY) ENGINE=InnoDB;
+
+INSERT INTO t VALUES (10), (30);
+
+--connect (con1,localhost,root,,)
+SET TRANSACTION ISOLATION LEVEL SERIALIZABLE;
+BEGIN;
+INSERT INTO t VALUES (20);
+SELECT * FROM t WHERE a BETWEEN 10 AND 30;
+
+--connection default
+SET session innodb_lock_wait_timeout=1;
+--error ER_LOCK_WAIT_TIMEOUT
+INSERT INTO t VALUES (15);
+
+--disconnect con1
+DROP TABLE t;
+--source include/wait_until_count_sessions.inc
diff --git a/mysql-test/suite/innodb/t/import_bugs.test b/mysql-test/suite/innodb/t/import_bugs.test
new file mode 100644
index 00000000..7fcab9f9
--- /dev/null
+++ b/mysql-test/suite/innodb/t/import_bugs.test
@@ -0,0 +1,35 @@
+--source include/have_innodb.inc
+
+call mtr.add_suppression("Index for table 'imp_t1' is corrupt; try to repair it");
+
+SET @save_innodb_checksum_algorithm=@@GLOBAL.innodb_checksum_algorithm;
+SET GLOBAL innodb_checksum_algorithm=full_crc32;
+
+CREATE TABLE t1 (a INT PRIMARY KEY) ENGINE=InnoDB ROW_FORMAT=REDUNDANT;
+CREATE TABLE imp_t1 (a INT PRIMARY KEY) ENGINE=InnoDB ROW_FORMAT=DYNAMIC;
+ALTER TABLE imp_t1 DISCARD TABLESPACE ;
+FLUSH TABLES t1 FOR EXPORT;
+let $datadir=`select @@datadir`;
+--copy_file $datadir/test/t1.ibd $datadir/test/imp_t1.ibd
+UNLOCK TABLES;
+--error ER_TABLE_SCHEMA_MISMATCH
+ALTER TABLE imp_t1 IMPORT TABLESPACE;
+--error ER_TABLE_EXISTS_ERROR
+CREATE TABLE imp_t1 (a INT PRIMARY KEY) ENGINE=InnoDB;
+DROP TABLE imp_t1;
+CREATE TABLE imp_t1 (a INT PRIMARY KEY) ENGINE=InnoDB;
+DROP TABLE imp_t1, t1;
+
+SET GLOBAL innodb_checksum_algorithm=@save_innodb_checksum_algorithm;
+
+--echo #
+--echo # MDEV-27006 Assertion `!lock_trx_has_sys_table_locks(trx)'
+--echo # failed in dberr_t row_discard_tablespace_for_mysql
+--echo # (dict_table_t*, trx_t*)
+CREATE TABLE t1 (c INT KEY) ENGINE=INNODB;
+CREATE TABLE t2 (c INT KEY,FOREIGN KEY(c) REFERENCES t1 (c)) ENGINE=INNODB;
+--error ER_ROW_IS_REFERENCED_2
+ALTER TABLE t1 DISCARD TABLESPACE;
+DROP TABLE t2, t1;
+
+--echo # End of 10.6 tests
diff --git a/mysql-test/suite/innodb/t/import_corrupted.test b/mysql-test/suite/innodb/t/import_corrupted.test
new file mode 100644
index 00000000..bc2ee341
--- /dev/null
+++ b/mysql-test/suite/innodb/t/import_corrupted.test
@@ -0,0 +1,67 @@
+--source include/have_innodb.inc
+--source include/no_valgrind_without_big.inc
+
+call mtr.add_suppression("Table `test`.`t2` should have 2 indexes but the tablespace has 1 indexes");
+call mtr.add_suppression("Index for table 't2' is corrupt; try to repair it");
+call mtr.add_suppression("Trying to read .* bytes at .* outside the bounds of the file: \\..test.t2\\.ibd");
+call mtr.add_suppression("InnoDB: File '.*test/t2\\.ibd' is corrupted");
+
+let MYSQLD_DATADIR = `SELECT @@datadir`;
+
+CREATE TABLE t1 (
+ id INT AUTO_INCREMENT PRIMARY KEY,
+ not_id INT,
+ data CHAR(255),
+ data2 BLOB
+) ENGINE=INNODB;
+
+--disable_query_log
+--let i = 0
+while ($i != 1000) {
+ eval INSERT INTO t1 VALUES (DEFAULT, $i, REPEAT('b', 255), REPEAT('a', 5000));
+ --inc $i
+}
+--enable_query_log
+
+ALTER TABLE t1 MODIFY not_id INT UNIQUE KEY;
+
+connect (purge_control,localhost,root,,);
+START TRANSACTION WITH CONSISTENT SNAPSHOT;
+connection default;
+
+DELETE FROM t1 WHERE id % 2 = 1;
+
+FLUSH TABLES t1 FOR EXPORT;
+
+--copy_file $MYSQLD_DATADIR/test/t1.ibd $MYSQLD_DATADIR/test/tmp.ibd
+--copy_file $MYSQLD_DATADIR/test/t1.cfg $MYSQLD_DATADIR/test/tmp.cfg
+
+perl;
+use strict;
+die unless open(FILE, "+<$ENV{MYSQLD_DATADIR}/test/tmp.ibd");
+die unless truncate(FILE, 16384*23);
+close(FILE);
+EOF
+
+UNLOCK TABLES;
+connection purge_control;
+COMMIT;
+connection default;
+DROP TABLE t1;
+
+CREATE TABLE t2 (
+ id INT AUTO_INCREMENT PRIMARY KEY,
+ not_id INT UNIQUE KEY,
+ data CHAR(255),
+ data2 BLOB
+) ENGINE=INNODB;
+
+ALTER TABLE t2 DISCARD TABLESPACE;
+
+--move_file $MYSQLD_DATADIR/test/tmp.ibd $MYSQLD_DATADIR/test/t2.ibd
+--move_file $MYSQLD_DATADIR/test/tmp.cfg $MYSQLD_DATADIR/test/t2.cfg
+
+--error ER_NOT_KEYFILE
+ALTER TABLE t2 IMPORT TABLESPACE;
+
+DROP TABLE t2;
diff --git a/mysql-test/suite/innodb/t/import_tablespace_race.test b/mysql-test/suite/innodb/t/import_tablespace_race.test
new file mode 100644
index 00000000..aca0b5df
--- /dev/null
+++ b/mysql-test/suite/innodb/t/import_tablespace_race.test
@@ -0,0 +1,55 @@
+--source include/have_innodb.inc
+--source include/have_sequence.inc
+
+--echo #
+--echo # MDEV-29144 ER_TABLE_SCHEMA_MISMATCH or crash on DISCARD/IMPORT
+--echo #
+
+call mtr.add_suppression("InnoDB: Unknown index id");
+CREATE TABLE t (pk int PRIMARY KEY, c varchar(1024))
+ENGINE=InnoDB CHARSET latin1;
+INSERT INTO t SELECT seq, 'x' FROM seq_1_to_100;
+
+--connect (con1,localhost,root,,test)
+--delimiter $
+--send
+ BEGIN NOT ATOMIC
+ DECLARE a INT DEFAULT 0;
+ REPEAT
+ SET a= a+1;
+ UPDATE t SET c = 'xx' WHERE pk = a;
+ UNTIL a = 100
+ END REPEAT;
+ END
+$
+--delimiter ;
+
+--connection default
+--error 0,ER_LOCK_WAIT_TIMEOUT
+ALTER TABLE t NOWAIT ADD INDEX (c);
+
+--connection con1
+--reap
+
+--connection default
+
+--let $datadir= `select @@datadir`
+
+FLUSH TABLE t FOR EXPORT;
+--let $create= query_get_value(SHOW CREATE TABLE t, Create Table, 1)
+--copy_file $datadir/test/t.cfg $datadir/test/t.cfg.sav
+--copy_file $datadir/test/t.ibd $datadir/test/t.ibd.sav
+UNLOCK TABLES;
+
+DROP TABLE t;
+--disable_query_log
+eval $create;
+--enable_query_log
+
+ALTER TABLE t DISCARD TABLESPACE;
+--move_file $datadir/test/t.cfg.sav $datadir/test/t.cfg
+--move_file $datadir/test/t.ibd.sav $datadir/test/t.ibd
+ALTER TABLE t IMPORT TABLESPACE;
+
+# Cleanup
+DROP TABLE t;
diff --git a/mysql-test/suite/innodb/t/index_merge_threshold.opt b/mysql-test/suite/innodb/t/index_merge_threshold.opt
new file mode 100644
index 00000000..ad0f33c3
--- /dev/null
+++ b/mysql-test/suite/innodb/t/index_merge_threshold.opt
@@ -0,0 +1,2 @@
+--loose-innodb_sys_tablespaces
+--skip-innodb-read-only-compressed
diff --git a/mysql-test/suite/innodb/t/index_merge_threshold.test b/mysql-test/suite/innodb/t/index_merge_threshold.test
new file mode 100644
index 00000000..a60ecf51
--- /dev/null
+++ b/mysql-test/suite/innodb/t/index_merge_threshold.test
@@ -0,0 +1,188 @@
+# #############################################################
+# wl6747 : Set merge threshold at index level
+# Check with CREATE INDEX on all datatypes
+# Check with by ALTER TABLE MODIFY COLUMN TYPE
+# Check with ALTER TABLE ADD Index
+# Check by setting at index level with CREATE TABLE
+# Check with BLOB column at index level with CREATE Index
+# Check with row_format=compressed and key_block_size=8k
+# Check withe valid and invalid merge_threshold values.
+#
+# Check actual behavior for table, partitioned table and temporary table
+# #############################################################
+--source include/have_innodb_16k.inc
+--source include/have_partition.inc
+
+# Check index merge threshold by create index on all datatypes
+
+CREATE TABLE tab(a BIGINT PRIMARY KEY,c1 TINYTEXT,c2 TEXT,c3 MEDIUMTEXT,
+c4 TINYBLOB,c5 BLOB,c6 MEDIUMBLOB,c7 LONGBLOB) ENGINE=InnoDB;
+
+# check index merge threshold on all datatypes
+CREATE INDEX index1 ON tab(c1(255)) COMMENT 'Check index level merge MERGE_THRESHOLD=51';
+CREATE INDEX index2 ON tab(c2(750)) COMMENT 'Check index level merge MERGE_THRESHOLD=-1';
+CREATE INDEX index3 ON tab(c3(750)) COMMENT 'Check index level merge MERGE_THRESHOLD=20';
+CREATE INDEX index4 ON tab(c4(255)) COMMENT 'Check index level merge MERGE_THRESHOLD=25';
+CREATE INDEX index5 ON tab(c5(750)) COMMENT 'Check index level merge MERGE_THRESHOLD=30';
+CREATE INDEX index6 ON tab(c6(750)) COMMENT 'Check index level merge MERGE_THRESHOLD=35';
+CREATE INDEX index7 ON tab(c7(750)) COMMENT 'Check index level merge MERGE_THRESHOLD=40';
+
+SHOW CREATE TABLE tab;
+
+SELECT t.NAME as TABLE_NAME, i.NAME as INDEX_NAME, i.MERGE_THRESHOLD
+FROM INFORMATION_SCHEMA.INNODB_SYS_TABLES t, INFORMATION_SCHEMA.INNODB_SYS_INDEXES i
+WHERE t.TABLE_ID = i.TABLE_ID AND t.NAME = 'test/tab';
+
+ALTER TABLE tab comment='MERGE_THRESHOLD=49';
+
+SHOW CREATE TABLE tab;
+
+SELECT t.NAME as TABLE_NAME, i.NAME as INDEX_NAME, i.MERGE_THRESHOLD
+FROM INFORMATION_SCHEMA.INNODB_SYS_TABLES t, INFORMATION_SCHEMA.INNODB_SYS_INDEXES i
+WHERE t.TABLE_ID = i.TABLE_ID AND t.NAME = 'test/tab';
+
+ALTER TABLE tab MODIFY COLUMN c7 VARCHAR(2048) ;
+
+SHOW CREATE TABLE tab;
+
+SELECT t.NAME as TABLE_NAME, i.NAME as INDEX_NAME, i.MERGE_THRESHOLD
+FROM INFORMATION_SCHEMA.INNODB_SYS_TABLES t, INFORMATION_SCHEMA.INNODB_SYS_INDEXES i
+WHERE t.TABLE_ID = i.TABLE_ID AND t.NAME = 'test/tab';
+
+ALTER TABLE tab ADD INDEX index8 (c7(750)) COMMENT 'Check index level merge MERGE_THRESHOLD=45';
+
+SHOW CREATE TABLE tab;
+
+SELECT t.NAME as TABLE_NAME, i.NAME as INDEX_NAME, i.MERGE_THRESHOLD
+FROM INFORMATION_SCHEMA.INNODB_SYS_TABLES t, INFORMATION_SCHEMA.INNODB_SYS_INDEXES i
+WHERE t.TABLE_ID = i.TABLE_ID AND t.NAME = 'test/tab';
+# Cleanup
+DROP TABLE tab;
+
+
+
+--echo #
+--echo # behavior for deleting records
+--echo #
+
+--echo # test to confirm behavior (MERGE_THRESHOLD=50 (default))
+CREATE TABLE tab1 (a bigint primary key, b varchar(2048)) engine=InnoDB;
+
+--source suite/innodb/include/innodb_merge_threshold_delete.inc
+
+DROP TABLE tab1;
+
+
+--echo # test to confirm behavior (MERGE_THRESHOLD=35)
+CREATE TABLE tab1 (a bigint primary key, b varchar(2048)) engine=InnoDB
+COMMENT='MERGE_THRESHOLD=35';
+
+--source suite/innodb/include/innodb_merge_threshold_delete.inc
+
+DROP TABLE tab1;
+
+
+--echo # test to confirm behavior (MERGE_THRESHOLD=25)
+CREATE TABLE tab1 (a bigint primary key, b varchar(2048)) engine=InnoDB
+COMMENT='MERGE_THRESHOLD=25';
+
+--source suite/innodb/include/innodb_merge_threshold_delete.inc
+
+DROP TABLE tab1;
+
+
+--echo # test to confirm partitioned table (MERGE_THRESHOLD=35)
+CREATE TABLE tab1 (a bigint primary key, b varchar(2048))
+COMMENT='MERGE_THRESHOLD=35'
+PARTITION BY RANGE (a)
+(PARTITION p0 VALUES LESS THAN (20) ENGINE = InnoDB,
+ PARTITION p1 VALUES LESS THAN MAXVALUE ENGINE = InnoDB);
+
+--source suite/innodb/include/innodb_merge_threshold_delete.inc
+
+DROP TABLE tab1;
+
+
+
+--echo #
+--echo # behavior for updating to smaller records
+--echo #
+
+--echo # test to confirm behavior (MERGE_THRESHOLD=50 (default))
+CREATE TABLE tab1 (a bigint primary key, b varchar(2048)) engine=InnoDB;
+
+--source suite/innodb/include/innodb_merge_threshold_update.inc
+
+DROP TABLE tab1;
+
+
+--echo # test to confirm behavior (MERGE_THRESHOLD=35)
+CREATE TABLE tab1 (a bigint primary key, b varchar(2048)) engine=InnoDB
+COMMENT='MERGE_THRESHOLD=35';
+
+--source suite/innodb/include/innodb_merge_threshold_update.inc
+
+DROP TABLE tab1;
+
+
+--echo # test to confirm behavior (MERGE_THRESHOLD=25)
+CREATE TABLE tab1 (a bigint primary key, b varchar(2048)) engine=InnoDB
+COMMENT='MERGE_THRESHOLD=25';
+
+--source suite/innodb/include/innodb_merge_threshold_update.inc
+
+DROP TABLE tab1;
+
+
+--echo # test to confirm explicit temporary table (MERGE_THRESHOLD=35)
+--echo # (though not registered to SYS_TABLES,SYS_INDEXES, it works correctly)
+# Temporary tables are not purged. so deleting records is not caused
+# So, should be tested by updating case only
+CREATE TEMPORARY TABLE tab1 (a bigint primary key, b varchar(2048)) engine=InnoDB
+COMMENT='MERGE_THRESHOLD=35';
+
+--source suite/innodb/include/innodb_merge_threshold_update.inc
+
+DROP TABLE tab1;
+
+
+--echo #
+--echo # behavior for secondary index with blob
+--echo #
+
+--echo # test to confirm behavior (MERGE_THRESHOLD=50 (default))
+# not to cause page operation at primary key, row_format=dynamic and the key is blob
+CREATE TABLE tab1 (a bigint primary key, b blob) engine=InnoDB row_format=dynamic;
+CREATE INDEX index1 ON tab1(b(750));
+
+--source suite/innodb/include/innodb_merge_threshold_secondary.inc
+
+DROP TABLE tab1;
+
+
+--echo # test to confirm behavior (MERGE_THRESHOLD=45)
+CREATE TABLE tab1 (a bigint primary key, b blob) engine=InnoDB row_format=dynamic;
+CREATE INDEX index1 ON tab1(b(750)) COMMENT 'MERGE_THRESHOLD=45';
+
+--source suite/innodb/include/innodb_merge_threshold_secondary.inc
+
+DROP TABLE tab1;
+
+
+--echo # test to confirm behavior (MERGE_THRESHOLD=40)
+CREATE TABLE tab1 (a bigint primary key, b blob) engine=InnoDB row_format=dynamic;
+CREATE INDEX index1 ON tab1(b(750)) COMMENT 'MERGE_THRESHOLD=40';
+
+--source suite/innodb/include/innodb_merge_threshold_secondary.inc
+
+DROP TABLE tab1;
+
+
+--echo # compressed table behaves same (MERGE_THRESHOLD=45)
+CREATE TABLE tab1 (a bigint primary key, b blob) engine=InnoDB
+ROW_FORMAT=COMPRESSED KEY_BLOCK_SIZE=8;
+CREATE INDEX index1 ON tab1(b(750)) COMMENT 'MERGE_THRESHOLD=45';
+
+--source suite/innodb/include/innodb_merge_threshold_secondary.inc
+
+DROP TABLE tab1;
diff --git a/mysql-test/suite/innodb/t/index_tree_operation.opt b/mysql-test/suite/innodb/t/index_tree_operation.opt
new file mode 100644
index 00000000..66bceccc
--- /dev/null
+++ b/mysql-test/suite/innodb/t/index_tree_operation.opt
@@ -0,0 +1 @@
+--innodb-sys-tablespaces
diff --git a/mysql-test/suite/innodb/t/index_tree_operation.test b/mysql-test/suite/innodb/t/index_tree_operation.test
new file mode 100644
index 00000000..b9695db9
--- /dev/null
+++ b/mysql-test/suite/innodb/t/index_tree_operation.test
@@ -0,0 +1,74 @@
+-- source include/have_innodb.inc
+-- source include/have_innodb_16k.inc
+--echo #
+--echo # Bug#15923864 (Bug#67718):
+--echo # INNODB DRASTICALLY UNDER-FILLS PAGES IN CERTAIN CONDITIONS
+--echo #
+# InnoDB should try to insert to the next page before split,
+# if the insert record for split_and_insert is last of the page.
+# Otherwise, the follwing records 999,998,997 cause each page per record.
+#
+
+--disable_query_log
+SET @old_innodb_file_per_table = @@innodb_file_per_table;
+--enable_query_log
+
+SET GLOBAL innodb_file_per_table=ON;
+
+CREATE TABLE t1 (a BIGINT PRIMARY KEY, b VARCHAR(4096)) ENGINE=InnoDB;
+INSERT INTO t1 VALUES (0, REPEAT('a', 4096));
+INSERT INTO t1 VALUES (1000, REPEAT('a', 4096));
+INSERT INTO t1 VALUES (1001, REPEAT('a', 4096));
+INSERT INTO t1 VALUES (1002, REPEAT('a', 4096));
+INSERT INTO t1 VALUES (1, REPEAT('a', 4096));
+INSERT INTO t1 VALUES (2, REPEAT('a', 4096));
+
+# | 0, 1, 2 | 1000, 1001, 1002|
+
+SELECT page_number, number_records
+FROM information_schema.innodb_sys_tablespaces s1,
+information_schema.innodb_buffer_page s2
+WHERE s1.space = s2.space AND name = 'test/t1'
+AND page_type = "INDEX" ORDER BY page_number;
+
+INSERT INTO t1 VALUES (999, REPEAT('a', 4096));
+
+# try to insert '999' to the end of '0,1,2' page, but no space
+# the next '1000,1001,1002' page has also no space.
+# | 0, 1, 2 | 999 | 1000, 1001, 1002|
+
+SELECT page_number, number_records
+FROM information_schema.innodb_sys_tablespaces s1,
+information_schema.innodb_buffer_page s2
+WHERE s1.space = s2.space AND name = 'test/t1'
+AND page_type = "INDEX" ORDER BY page_number;
+
+
+INSERT INTO t1 VALUES (998, REPEAT('a', 4096));
+
+# try to insert to the end of '0,1,2' page, but no space
+# the next '998' page has space.
+# | 0, 1, 2 | 998, 999 | 1000, 1001, 1002|
+
+SELECT page_number, number_records
+FROM information_schema.innodb_sys_tablespaces s1,
+information_schema.innodb_buffer_page s2
+WHERE s1.space = s2.space AND name = 'test/t1'
+AND page_type = "INDEX" ORDER BY page_number;
+
+INSERT INTO t1 VALUES (997, REPEAT('a', 4096));
+
+# same
+# | 0, 1, 2 | 997, 998, 999 | 1000, 1001, 1002|
+
+SELECT page_number, number_records
+FROM information_schema.innodb_sys_tablespaces s1,
+information_schema.innodb_buffer_page s2
+WHERE s1.space = s2.space AND name = 'test/t1'
+AND page_type = "INDEX" ORDER BY page_number;
+
+DROP TABLE t1;
+
+--disable_query_log
+SET GLOBAL innodb_file_per_table = @old_innodb_file_per_table;
+--enable_query_log
diff --git a/mysql-test/suite/innodb/t/index_vcol_purge_startup.test b/mysql-test/suite/innodb/t/index_vcol_purge_startup.test
new file mode 100644
index 00000000..ccc07fe7
--- /dev/null
+++ b/mysql-test/suite/innodb/t/index_vcol_purge_startup.test
@@ -0,0 +1,28 @@
+source include/have_innodb.inc;
+# need to restart server
+source include/not_embedded.inc;
+
+call mtr.add_suppression('SQL_ERROR_LOG');
+call mtr.add_suppression('Failed to initialize plugins');
+call mtr.add_suppression('Aborting');
+
+if (!$SQL_ERRLOG_SO) {
+ skip No SQL_ERROR_LOG plugin;
+}
+
+create table t1(a int primary key, b int as (100-a*a), index(b)) engine=innodb;
+insert t1 (a) values(1),(2),(3);
+start transaction;
+select * from t1 order by a;
+connect(con1, localhost, root);
+delete from t1 where a=2;
+flush tables;
+connection default;
+source include/kill_mysqld.inc;
+echo # Failed restart;
+error 1;
+exec $MYSQLD_LAST_CMD --plugin-load-add=$SQL_ERRLOG_SO --sql-error-log=FORCE --sql-error-log-filename=$MYSQLTEST_VARDIR/nonexistent/nonexistent;
+echo # Start the server;
+source include/start_mysqld.inc;
+select * from t1 order by a;
+drop table t1;
diff --git a/mysql-test/suite/innodb/t/information_schema_grants.opt b/mysql-test/suite/innodb/t/information_schema_grants.opt
new file mode 100644
index 00000000..74a9bcfe
--- /dev/null
+++ b/mysql-test/suite/innodb/t/information_schema_grants.opt
@@ -0,0 +1,29 @@
+--enable-plugin-innodb-trx
+--enable-plugin-innodb-locks
+--enable-plugin-innodb-lock-waits
+--enable-plugin-innodb-cmp
+--enable-plugin-innodb-cmp-reset
+--enable-plugin-innodb-cmpmem
+--enable-plugin-innodb-cmpmem-reset
+--enable-plugin-innodb-cmp-per-index
+--enable-plugin-innodb-cmp-per-index-reset
+--enable-plugin-innodb-buffer-page
+--enable-plugin-innodb-buffer-page-lru
+--enable-plugin-innodb-buffer-pool-stats
+--enable-plugin-innodb-metrics
+--enable-plugin-innodb-ft-default-stopword
+--enable-plugin-innodb-ft-deleted
+--enable-plugin-innodb-ft-being-deleted
+--enable-plugin-innodb-ft-config
+--enable-plugin-innodb-ft-index-cache
+--enable-plugin-innodb-ft-index-table
+--enable-plugin-innodb-sys-tables
+--enable-plugin-innodb-sys-tablestats
+--enable-plugin-innodb-sys-indexes
+--enable-plugin-innodb-sys-columns
+--enable-plugin-innodb-sys-fields
+--enable-plugin-innodb-sys-foreign
+--enable-plugin-innodb-sys-foreign-cols
+--enable-plugin-innodb-sys-tablespaces
+--enable-plugin-innodb-sys-virtual
+--enable-plugin-innodb-tablespaces-encryption
diff --git a/mysql-test/suite/innodb/t/information_schema_grants.test b/mysql-test/suite/innodb/t/information_schema_grants.test
new file mode 100644
index 00000000..d0b2d2db
--- /dev/null
+++ b/mysql-test/suite/innodb/t/information_schema_grants.test
@@ -0,0 +1,277 @@
+source include/have_innodb.inc;
+source include/not_embedded.inc;
+
+# make sure we've enabled everything:
+select plugin_name,plugin_status as 'Must be ACTIVE' from information_schema.plugins where plugin_name like 'inno%' and plugin_status!='ACTIVE';
+
+create user select_only@localhost;
+grant select on *.* to select_only@localhost;
+
+connect select_only,localhost,select_only;
+connection default;
+
+create sql security invoker view i_buffer_page as select * from information_schema.innodb_buffer_page;
+create sql security definer view d_buffer_page as select * from information_schema.innodb_buffer_page;
+
+create sql security invoker view i_buffer_page_lru as select * from information_schema.innodb_buffer_page_lru;
+create sql security definer view d_buffer_page_lru as select * from information_schema.innodb_buffer_page_lru;
+
+create sql security invoker view i_buffer_pool_stats as select * from information_schema.innodb_buffer_pool_stats;
+create sql security definer view d_buffer_pool_stats as select * from information_schema.innodb_buffer_pool_stats;
+
+create sql security invoker view i_cmp as select * from information_schema.innodb_cmp;
+create sql security definer view d_cmp as select * from information_schema.innodb_cmp;
+
+create sql security invoker view i_cmp_per_index as select * from information_schema.innodb_cmp_per_index;
+create sql security definer view d_cmp_per_index as select * from information_schema.innodb_cmp_per_index;
+
+create sql security invoker view i_cmp_per_index_reset as select * from information_schema.innodb_cmp_per_index_reset;
+create sql security definer view d_cmp_per_index_reset as select * from information_schema.innodb_cmp_per_index_reset;
+
+create sql security invoker view i_cmp_reset as select * from information_schema.innodb_cmp_reset;
+create sql security definer view d_cmp_reset as select * from information_schema.innodb_cmp_reset;
+
+create sql security invoker view i_cmpmem as select * from information_schema.innodb_cmpmem;
+create sql security definer view d_cmpmem as select * from information_schema.innodb_cmpmem;
+
+create sql security invoker view i_cmpmem_reset as select * from information_schema.innodb_cmpmem_reset;
+create sql security definer view d_cmpmem_reset as select * from information_schema.innodb_cmpmem_reset;
+
+create sql security invoker view i_ft_being_deleted as select * from information_schema.innodb_ft_being_deleted;
+create sql security definer view d_ft_being_deleted as select * from information_schema.innodb_ft_being_deleted;
+
+create sql security invoker view i_ft_config as select * from information_schema.innodb_ft_config;
+create sql security definer view d_ft_config as select * from information_schema.innodb_ft_config;
+
+create sql security invoker view i_ft_default_stopword as select * from information_schema.innodb_ft_default_stopword;
+create sql security definer view d_ft_default_stopword as select * from information_schema.innodb_ft_default_stopword;
+
+create sql security invoker view i_ft_deleted as select * from information_schema.innodb_ft_deleted;
+create sql security definer view d_ft_deleted as select * from information_schema.innodb_ft_deleted;
+
+create sql security invoker view i_ft_index_cache as select * from information_schema.innodb_ft_index_cache;
+create sql security definer view d_ft_index_cache as select * from information_schema.innodb_ft_index_cache;
+
+create sql security invoker view i_ft_index_table as select * from information_schema.innodb_ft_index_table;
+create sql security definer view d_ft_index_table as select * from information_schema.innodb_ft_index_table;
+
+create sql security invoker view i_lock_waits as select * from information_schema.innodb_lock_waits;
+create sql security definer view d_lock_waits as select * from information_schema.innodb_lock_waits;
+
+create sql security invoker view i_locks as select * from information_schema.innodb_locks;
+create sql security definer view d_locks as select * from information_schema.innodb_locks;
+
+create sql security invoker view i_metrics as select * from information_schema.innodb_metrics;
+create sql security definer view d_metrics as select * from information_schema.innodb_metrics;
+
+create sql security invoker view i_sys_columns as select * from information_schema.innodb_sys_columns;
+create sql security definer view d_sys_columns as select * from information_schema.innodb_sys_columns;
+
+create sql security invoker view i_sys_fields as select * from information_schema.innodb_sys_fields;
+create sql security definer view d_sys_fields as select * from information_schema.innodb_sys_fields;
+
+create sql security invoker view i_sys_foreign as select * from information_schema.innodb_sys_foreign;
+create sql security definer view d_sys_foreign as select * from information_schema.innodb_sys_foreign;
+
+create sql security invoker view i_sys_foreign_cols as select * from information_schema.innodb_sys_foreign_cols;
+create sql security definer view d_sys_foreign_cols as select * from information_schema.innodb_sys_foreign_cols;
+
+create sql security invoker view i_sys_indexes as select * from information_schema.innodb_sys_indexes;
+create sql security definer view d_sys_indexes as select * from information_schema.innodb_sys_indexes;
+
+create sql security invoker view i_sys_tables as select * from information_schema.innodb_sys_tables;
+create sql security definer view d_sys_tables as select * from information_schema.innodb_sys_tables;
+
+create sql security invoker view i_sys_tablespaces as select * from information_schema.innodb_sys_tablespaces;
+create sql security definer view d_sys_tablespaces as select * from information_schema.innodb_sys_tablespaces;
+
+create sql security invoker view i_sys_tablestats as select * from information_schema.innodb_sys_tablestats;
+create sql security definer view d_sys_tablestats as select * from information_schema.innodb_sys_tablestats;
+
+create sql security invoker view i_sys_virtual as select * from information_schema.innodb_sys_virtual;
+create sql security definer view d_sys_virtual as select * from information_schema.innodb_sys_virtual;
+
+create sql security invoker view i_tablespaces_encryption as select * from information_schema.innodb_tablespaces_encryption;
+create sql security definer view d_tablespaces_encryption as select * from information_schema.innodb_tablespaces_encryption;
+
+create sql security invoker view i_trx as select * from information_schema.innodb_trx;
+create sql security definer view d_trx as select * from information_schema.innodb_trx;
+
+connection select_only;
+--error ER_SPECIFIC_ACCESS_DENIED_ERROR
+select count(*) > -1 from information_schema.innodb_buffer_page;
+--error ER_SPECIFIC_ACCESS_DENIED_ERROR
+select count(*) > -1 from i_buffer_page;
+select count(*) > -1 from d_buffer_page;
+
+--error ER_SPECIFIC_ACCESS_DENIED_ERROR
+select count(*) > -1 from information_schema.innodb_buffer_page_lru;
+--error ER_SPECIFIC_ACCESS_DENIED_ERROR
+select count(*) > -1 from i_buffer_page_lru;
+select count(*) > -1 from d_buffer_page_lru;
+
+--error ER_SPECIFIC_ACCESS_DENIED_ERROR
+select count(*) > -1 from information_schema.innodb_buffer_pool_stats;
+--error ER_SPECIFIC_ACCESS_DENIED_ERROR
+select count(*) > -1 from i_buffer_pool_stats;
+select count(*) > -1 from d_buffer_pool_stats;
+
+--error ER_SPECIFIC_ACCESS_DENIED_ERROR
+select count(*) > -1 from information_schema.innodb_cmp;
+--error ER_SPECIFIC_ACCESS_DENIED_ERROR
+select count(*) > -1 from i_cmp;
+select count(*) > -1 from d_cmp;
+
+--error ER_SPECIFIC_ACCESS_DENIED_ERROR
+select count(*) > -1 from information_schema.innodb_cmp_per_index;
+--error ER_SPECIFIC_ACCESS_DENIED_ERROR
+select count(*) > -1 from i_cmp_per_index;
+select count(*) > -1 from d_cmp_per_index;
+
+--error ER_SPECIFIC_ACCESS_DENIED_ERROR
+select count(*) > -1 from information_schema.innodb_cmp_per_index_reset;
+--error ER_SPECIFIC_ACCESS_DENIED_ERROR
+select count(*) > -1 from i_cmp_per_index_reset;
+select count(*) > -1 from d_cmp_per_index_reset;
+
+--error ER_SPECIFIC_ACCESS_DENIED_ERROR
+select count(*) > -1 from information_schema.innodb_cmp_reset;
+--error ER_SPECIFIC_ACCESS_DENIED_ERROR
+select count(*) > -1 from i_cmp_reset;
+select count(*) > -1 from d_cmp_reset;
+
+--error ER_SPECIFIC_ACCESS_DENIED_ERROR
+select count(*) > -1 from information_schema.innodb_cmpmem;
+--error ER_SPECIFIC_ACCESS_DENIED_ERROR
+select count(*) > -1 from i_cmpmem;
+select count(*) > -1 from d_cmpmem;
+
+--error ER_SPECIFIC_ACCESS_DENIED_ERROR
+select count(*) > -1 from information_schema.innodb_cmpmem_reset;
+--error ER_SPECIFIC_ACCESS_DENIED_ERROR
+select count(*) > -1 from i_cmpmem_reset;
+select count(*) > -1 from d_cmpmem_reset;
+
+--error ER_SPECIFIC_ACCESS_DENIED_ERROR
+select count(*) > -1 from information_schema.innodb_ft_being_deleted;
+--error ER_SPECIFIC_ACCESS_DENIED_ERROR
+select count(*) > -1 from i_ft_being_deleted;
+select count(*) > -1 from d_ft_being_deleted;
+
+--error ER_SPECIFIC_ACCESS_DENIED_ERROR
+select count(*) > -1 from information_schema.innodb_ft_config;
+--error ER_SPECIFIC_ACCESS_DENIED_ERROR
+select count(*) > -1 from i_ft_config;
+select count(*) > -1 from d_ft_config;
+
+# non-privileged table
+select count(*) > -1 from information_schema.innodb_ft_default_stopword;
+
+--error ER_SPECIFIC_ACCESS_DENIED_ERROR
+select count(*) > -1 from information_schema.innodb_ft_deleted;
+--error ER_SPECIFIC_ACCESS_DENIED_ERROR
+select count(*) > -1 from i_ft_deleted;
+select count(*) > -1 from d_ft_deleted;
+
+--error ER_SPECIFIC_ACCESS_DENIED_ERROR
+select count(*) > -1 from information_schema.innodb_ft_index_cache;
+--error ER_SPECIFIC_ACCESS_DENIED_ERROR
+select count(*) > -1 from i_ft_index_cache;
+select count(*) > -1 from d_ft_index_cache;
+
+--error ER_SPECIFIC_ACCESS_DENIED_ERROR
+select count(*) > -1 from information_schema.innodb_ft_index_table;
+--error ER_SPECIFIC_ACCESS_DENIED_ERROR
+select count(*) > -1 from i_ft_index_table;
+select count(*) > -1 from d_ft_index_table;
+
+--error ER_SPECIFIC_ACCESS_DENIED_ERROR
+select count(*) > -1 from information_schema.innodb_lock_waits;
+--error ER_SPECIFIC_ACCESS_DENIED_ERROR
+select count(*) > -1 from i_lock_waits;
+select count(*) > -1 from d_lock_waits;
+
+--error ER_SPECIFIC_ACCESS_DENIED_ERROR
+select count(*) > -1 from information_schema.innodb_locks;
+--error ER_SPECIFIC_ACCESS_DENIED_ERROR
+select count(*) > -1 from i_locks;
+select count(*) > -1 from d_locks;
+
+--error ER_SPECIFIC_ACCESS_DENIED_ERROR
+select count(*) > -1 from information_schema.innodb_metrics;
+--error ER_SPECIFIC_ACCESS_DENIED_ERROR
+select count(*) > -1 from i_metrics;
+select count(*) > -1 from d_metrics;
+
+--error ER_SPECIFIC_ACCESS_DENIED_ERROR
+select count(*) > -1 from information_schema.innodb_sys_columns;
+--error ER_SPECIFIC_ACCESS_DENIED_ERROR
+select count(*) > -1 from i_sys_columns;
+select count(*) > -1 from d_sys_columns;
+
+--error ER_SPECIFIC_ACCESS_DENIED_ERROR
+select count(*) > -1 from information_schema.innodb_sys_fields;
+--error ER_SPECIFIC_ACCESS_DENIED_ERROR
+select count(*) > -1 from i_sys_fields;
+select count(*) > -1 from d_sys_fields;
+
+--error ER_SPECIFIC_ACCESS_DENIED_ERROR
+select count(*) > -1 from information_schema.innodb_sys_foreign;
+--error ER_SPECIFIC_ACCESS_DENIED_ERROR
+select count(*) > -1 from i_sys_foreign;
+select count(*) > -1 from d_sys_foreign;
+
+--error ER_SPECIFIC_ACCESS_DENIED_ERROR
+select count(*) > -1 from information_schema.innodb_sys_foreign_cols;
+--error ER_SPECIFIC_ACCESS_DENIED_ERROR
+select count(*) > -1 from i_sys_foreign_cols;
+select count(*) > -1 from d_sys_foreign_cols;
+
+--error ER_SPECIFIC_ACCESS_DENIED_ERROR
+select count(*) > -1 from information_schema.innodb_sys_indexes;
+--error ER_SPECIFIC_ACCESS_DENIED_ERROR
+select count(*) > -1 from i_sys_indexes;
+select count(*) > -1 from d_sys_indexes;
+
+--error ER_SPECIFIC_ACCESS_DENIED_ERROR
+select count(*) > -1 from information_schema.innodb_sys_tables;
+--error ER_SPECIFIC_ACCESS_DENIED_ERROR
+select count(*) > -1 from i_sys_tables;
+select count(*) > -1 from d_sys_tables;
+
+--error ER_SPECIFIC_ACCESS_DENIED_ERROR
+select count(*) > -1 from information_schema.innodb_sys_tablespaces;
+--error ER_SPECIFIC_ACCESS_DENIED_ERROR
+select count(*) > -1 from i_sys_tablespaces;
+select count(*) > -1 from d_sys_tablespaces;
+
+--error ER_SPECIFIC_ACCESS_DENIED_ERROR
+select count(*) > -1 from information_schema.innodb_sys_tablestats;
+--error ER_SPECIFIC_ACCESS_DENIED_ERROR
+select count(*) > -1 from i_sys_tablestats;
+select count(*) > -1 from d_sys_tablestats;
+
+--error ER_SPECIFIC_ACCESS_DENIED_ERROR
+select count(*) > -1 from information_schema.innodb_sys_virtual;
+--error ER_SPECIFIC_ACCESS_DENIED_ERROR
+select count(*) > -1 from i_sys_virtual;
+select count(*) > -1 from d_sys_virtual;
+
+--error ER_SPECIFIC_ACCESS_DENIED_ERROR
+select count(*) > -1 from information_schema.innodb_tablespaces_encryption;
+--error ER_SPECIFIC_ACCESS_DENIED_ERROR
+select count(*) > -1 from i_tablespaces_encryption;
+select count(*) > -1 from d_tablespaces_encryption;
+
+--error ER_SPECIFIC_ACCESS_DENIED_ERROR
+select count(*) > -1 from information_schema.innodb_trx;
+--error ER_SPECIFIC_ACCESS_DENIED_ERROR
+select count(*) > -1 from i_trx;
+select count(*) > -1 from d_trx;
+
+connection default;
+# Starting with MariaDB 10.6, ensure that DDL recovery will have completed.
+SET GLOBAL innodb_max_purge_lag_wait=0;
+drop database test;
+create database test;
+drop user select_only@localhost;
diff --git a/mysql-test/suite/innodb/t/innodb-16k-master.opt b/mysql-test/suite/innodb/t/innodb-16k-master.opt
new file mode 100644
index 00000000..6532d092
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb-16k-master.opt
@@ -0,0 +1,2 @@
+--default_storage_engine=InnoDB
+--skip-innodb-read-only-compressed
diff --git a/mysql-test/suite/innodb/t/innodb-16k.test b/mysql-test/suite/innodb/t/innodb-16k.test
new file mode 100644
index 00000000..8bec6254
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb-16k.test
@@ -0,0 +1,463 @@
+--source include/no_valgrind_without_big.inc
+# Tests for setting innodb-page-size=16k; default value
+--source include/have_innodb.inc
+--source include/have_innodb_16k.inc
+
+call mtr.add_suppression("InnoDB: Cannot add field .* in table");
+let $MYSQLD_DATADIR= `select @@datadir`;
+
+--echo # Test 1) Show the page size from Information Schema
+SELECT variable_value FROM information_schema.global_status
+ WHERE LOWER(variable_name) = 'innodb_page_size';
+
+--echo # Test 4) The maximum row size is dependent upon the page size.
+--echo # Redundant: 8123, Compact: 8126, Dynamic: 8126.
+--echo # Each row format has its own amount of overhead that
+--echo # varies depending on number of fields and other overhead.
+
+SET SESSION innodb_strict_mode = ON;
+SET @save_level=@@GLOBAL.innodb_compression_level;
+SET GLOBAL innodb_compression_level=1;
+
+# Compressed table: compressBound() for the s390x DFLTCC instruction
+CREATE TABLE t1 (
+c01 char(200), c02 char(200), c03 char(200), c04 char(200), c05 char(200),
+c06 char(200), c07 char(200), c08 char(200), c09 char(200), c10 char(200),
+c11 char(200), c12 char(200), c13 char(200), c14 char(200), c15 char(200),
+c16 char(200), c17 char(200), c18 char(200), c19 char(200), c20 char(200),
+c21 char(200), c22 char(200), c23 char(200), c24 char(200), c25 char(200),
+c26 char(200), c27 char(200), c28 char(200), c29 char(200), c30 char(200),
+c31 char(200), c32 char(200), c33 char(200), c34 char(200), c35 char(200),
+c36 char(200), c37 char(200), c38 char(196)
+) ROW_FORMAT=compressed;
+
+DROP TABLE t1;
+
+--error ER_TOO_BIG_ROWSIZE
+CREATE TABLE t1 (
+c01 char(200), c02 char(200), c03 char(200), c04 char(200), c05 char(200),
+c06 char(200), c07 char(200), c08 char(200), c09 char(200), c10 char(200),
+c11 char(200), c12 char(200), c13 char(200), c14 char(200), c15 char(200),
+c16 char(200), c17 char(200), c18 char(200), c19 char(200), c20 char(200),
+c21 char(200), c22 char(200), c23 char(200), c24 char(200), c25 char(200),
+c26 char(200), c27 char(200), c28 char(200), c29 char(200), c30 char(200),
+c31 char(200), c32 char(200), c33 char(200), c34 char(200), c35 char(200),
+c36 char(200), c37 char(200), c38 char(200), c39 char(200), c40 char(160)
+) ROW_FORMAT=compressed;
+
+#
+# Test the maximum key length
+# Max Key Length is 3072 for 16k pages.
+# Max key Part length is 767
+# InnoDB assumes 3 bytes for each UTF8 character.
+#
+CREATE TABLE t1 (a varchar(255) character set utf8,
+ b varchar(255) character set utf8,
+ c varchar(255) character set utf8,
+ d varchar(255) character set utf8,
+ e varchar(4) character set utf8,
+ PRIMARY KEY (a,b,c,d,e))
+ ENGINE=innodb;
+
+DROP TABLE t1;
+
+--error ER_TOO_LONG_KEY
+CREATE TABLE t1 (a varchar(255) character set utf8,
+ b varchar(255) character set utf8,
+ c varchar(255) character set utf8,
+ d varchar(255) character set utf8,
+ e varchar(5) character set utf8,
+ PRIMARY KEY (a,b,c,d,e))
+ ENGINE=innodb;
+
+CREATE TABLE t1 (a varchar(255) character set utf8,
+ b varchar(255) character set utf8,
+ c varchar(255) character set utf8,
+ d varchar(255) character set utf8,
+ e varchar(255) character set utf8,
+ f varchar(4) character set utf8,
+ PRIMARY KEY (a), KEY (b,c,d,e,f))
+ ENGINE=innodb;
+
+DROP TABLE t1;
+
+--error ER_TOO_LONG_KEY
+CREATE TABLE t1 (a varchar(255) character set utf8,
+ b varchar(255) character set utf8,
+ c varchar(255) character set utf8,
+ d varchar(255) character set utf8,
+ e varchar(255) character set utf8,
+ f varchar(5) character set utf8,
+ PRIMARY KEY (a), KEY (b,c,d,e,f))
+ ENGINE=innodb;
+
+--echo # Test 5) Make sure that KEY_BLOCK_SIZE=16, 8, 4, 2 & 1
+--echo # are all accepted.
+
+SET SESSION innodb_strict_mode = ON;
+
+CREATE TABLE t1 (i int) ROW_FORMAT=COMPRESSED KEY_BLOCK_SIZE=16;
+SHOW WARNINGS;
+
+SELECT table_name, row_format, create_options
+ FROM information_schema.tables WHERE table_name = 't1';
+
+ALTER TABLE t1 KEY_BLOCK_SIZE=8;
+SHOW WARNINGS;
+
+SELECT table_name, row_format, create_options
+ FROM information_schema.tables WHERE table_name = 't1';
+
+ALTER TABLE t1 KEY_BLOCK_SIZE=4;
+SHOW WARNINGS;
+
+SELECT table_name, row_format, create_options
+ FROM information_schema.tables WHERE table_name = 't1';
+
+ALTER TABLE t1 KEY_BLOCK_SIZE=2;
+SHOW WARNINGS;
+
+SELECT table_name, row_format, create_options
+ FROM information_schema.tables WHERE table_name = 't1';
+
+ALTER TABLE t1 KEY_BLOCK_SIZE=1;
+SHOW WARNINGS;
+
+SELECT table_name, row_format, create_options
+ FROM information_schema.tables WHERE table_name = 't1';
+
+ALTER TABLE t1 KEY_BLOCK_SIZE=0;
+SHOW WARNINGS;
+
+SELECT table_name, row_format, create_options
+ FROM information_schema.tables WHERE table_name = 't1';
+
+DROP TABLE t1;
+
+SET SESSION innodb_strict_mode = OFF;
+
+CREATE TABLE t1 (i int) ROW_FORMAT=COMPRESSED KEY_BLOCK_SIZE=16;
+SHOW WARNINGS;
+
+SELECT table_name, row_format, create_options
+ FROM information_schema.tables WHERE table_name = 't1';
+
+ALTER TABLE t1 KEY_BLOCK_SIZE=8;
+SHOW WARNINGS;
+
+SELECT table_name, row_format, create_options
+ FROM information_schema.tables WHERE table_name = 't1';
+
+ALTER TABLE t1 KEY_BLOCK_SIZE=4;
+SHOW WARNINGS;
+
+SELECT table_name, row_format, create_options
+ FROM information_schema.tables WHERE table_name = 't1';
+
+ALTER TABLE t1 KEY_BLOCK_SIZE=2;
+SHOW WARNINGS;
+
+SELECT table_name, row_format, create_options
+ FROM information_schema.tables WHERE table_name = 't1';
+
+ALTER TABLE t1 KEY_BLOCK_SIZE=1;
+SHOW WARNINGS;
+
+SELECT table_name, row_format, create_options
+ FROM information_schema.tables WHERE table_name = 't1';
+
+ALTER TABLE t1 KEY_BLOCK_SIZE=0;
+SHOW WARNINGS;
+
+SELECT table_name, row_format, create_options
+ FROM information_schema.tables WHERE table_name = 't1';
+
+DROP TABLE t1;
+
+CREATE TABLE t2(d varchar(17) PRIMARY KEY) ENGINE=innodb DEFAULT CHARSET=utf8;
+CREATE TABLE t3(a int PRIMARY KEY) ENGINE=innodb;
+INSERT INTO t3 VALUES (22),(44),(33),(55),(66);
+INSERT INTO t2 VALUES ('jejdkrun87'),('adfd72nh9k'),
+('adfdpplkeock'),('adfdijnmnb78k'),('adfdijn0loKNHJik');
+CREATE TABLE t1(a int, b blob, c text, d text NOT NULL)
+ENGINE=innodb DEFAULT CHARSET=utf8;
+INSERT INTO t1
+SELECT a,LEFT(REPEAT(d,100*a),65535),REPEAT(d,20*a),d FROM t2,t3
+ORDER BY a,d;
+DROP TABLE t2, t3;
+SELECT COUNT(*) FROM t1 WHERE a=44;
+SELECT a,
+LENGTH(b),b=LEFT(REPEAT(d,100*a),65535),LENGTH(c),c=REPEAT(d,20*a),d FROM t1
+ORDER BY a,d;
+
+# in-place alter table should trigger ER_PRIMARY_CANT_HAVE_NULL
+--error ER_DUP_ENTRY
+ALTER TABLE t1 ADD PRIMARY KEY (a), ADD KEY (b(20));
+DELETE FROM t1 WHERE d='null';
+--error ER_DUP_ENTRY
+ALTER TABLE t1 ADD PRIMARY KEY (a), ADD KEY (b(20));
+DELETE FROM t1 WHERE a%2;
+CHECK TABLE t1;
+ALTER TABLE t1 ADD PRIMARY KEY (a,b(255),c(255)), ADD KEY (b(767));
+SELECT COUNT(*) FROM t1 WHERE a=44;
+SELECT a,
+LENGTH(b), b=LEFT(REPEAT(d,100*a), 65535),LENGTH(c), c=REPEAT(d,20*a), d FROM t1
+ORDER BY a,d;
+SHOW CREATE TABLE t1;
+CHECK TABLE t1;
+DROP TABLE t1;
+
+--echo # Test 8) Test creating a table that could lead to undo log overflow.
+
+CREATE TABLE t1(a blob,b blob,c blob,d blob,e blob,f blob,g blob,
+ h blob,i blob,j blob,k blob,l blob,m blob,n blob,
+ o blob,p blob,q blob,r blob,s blob,t blob,u blob)
+ ENGINE=InnoDB ROW_FORMAT=dynamic;
+
+SET @a = repeat('a', 767);
+SET @b = repeat('b', 767);
+SET @c = repeat('c', 767);
+SET @d = repeat('d', 767);
+SET @e = repeat('e', 767);
+
+# With no indexes defined, we can update all columns to max key part length.
+
+INSERT INTO t1 VALUES (@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a);
+
+UPDATE t1 SET a=@b,b=@b,c=@b,d=@b,e=@b,f=@b,g=@b,h=@b,i=@b,j=@b,
+ k=@b,l=@b,m=@b,n=@b,o=@b,p=@b,q=@b,r=@b,s=@b,t=@b,u=@b;
+
+
+# With this many indexes defined, we can still update all fields.
+CREATE INDEX t1a ON t1 (a(767));
+CREATE INDEX t1b ON t1 (b(767));
+CREATE INDEX t1c ON t1 (c(767));
+CREATE INDEX t1d ON t1 (d(767));
+CREATE INDEX t1e ON t1 (e(767));
+
+UPDATE t1 SET a=@c,b=@c,c=@c,d=@c,e=@c,f=@c,g=@c,h=@c,i=@c,j=@c,
+ k=@c,l=@c,m=@c,n=@c,o=@c,p=@c,q=@c,r=@c,s=@c,t=@c,u=@c;
+
+
+# Add one more index and the UNDO record becomes too big to update all columns.
+# But a single transaction can update the columns in separate statements.
+# because the UNDO records will be smaller.
+
+CREATE INDEX t1f ON t1 (f(767));
+BEGIN;
+UPDATE t1 SET a=@d,b=@d,c=@d,d=@d,e=@d,f=@d,g=@d,h=@d,i=@d,j=@d,
+ k=@d,l=@d,m=@d,n=@d,o=@d,p=@d,q=@d,r=@d,s=@d,t=@d,u=@d;
+ROLLBACK;
+BEGIN;
+UPDATE t1 SET a=@d,b=@d,c=@d,d=@d,e=@d;
+UPDATE t1 SET f=@d,g=@d,h=@d,i=@d,j=@d,k=@d,l=@d,m=@d,
+ n=@d,o=@d,p=@d,q=@d,r=@d,s=@d,t=@d,u=@d;
+COMMIT;
+
+# More indexes can still be added and a single field can still be updated
+CREATE INDEX t1g ON t1 (g(767));
+UPDATE t1 SET g=@e;
+CREATE INDEX t1h ON t1 (h(767));
+UPDATE t1 SET h=@e;
+CREATE INDEX t1i ON t1 (i(767));
+UPDATE t1 SET i=@e;
+CREATE INDEX t1j ON t1 (j(767));
+UPDATE t1 SET j=@e;
+CREATE INDEX t1k ON t1 (k(767));
+UPDATE t1 SET k=@e;
+CREATE INDEX t1l ON t1 (l(767));
+UPDATE t1 SET l=@e;
+CREATE INDEX t1m ON t1 (m(767));
+UPDATE t1 SET m=@e;
+CREATE INDEX t1n ON t1 (n(767));
+UPDATE t1 SET n=@e;
+CREATE INDEX t1o ON t1 (o(767));
+UPDATE t1 SET o=@e;
+CREATE INDEX t1p ON t1 (p(767));
+UPDATE t1 SET p=@e;
+CREATE INDEX t1q ON t1 (q(767));
+UPDATE t1 SET q=@e;
+CREATE INDEX t1r ON t1 (r(767));
+UPDATE t1 SET r=@e;
+CREATE INDEX t1s ON t1 (s(767));
+UPDATE t1 SET s=@e;
+
+# Add one more index and we cannot update a column to its defined index length.
+# This is a problem. It means that the DDL is allowed to create a table
+# that CANNOT be updated.
+
+CREATE INDEX t1t ON t1 (t(767));
+BEGIN;
+UPDATE t1 SET t=@e;
+ROLLBACK;
+
+SHOW CREATE TABLE t1;
+DROP TABLE t1;
+
+--echo Test an assertion failure on purge.
+
+# This test is not in innodb_8k or innodb_4k since the bug is not about
+# page size. It just tests the condition that caused the assertion.
+
+CREATE TABLE t1_purge (
+A int,
+B blob, C blob, D blob, E blob,
+F blob, G blob, H blob,
+PRIMARY KEY (B(767), C(767), D(767), E(767), A),
+INDEX (A)
+) ENGINE=InnoDB ROW_FORMAT=DYNAMIC;
+
+INSERT INTO t1_purge VALUES (1,
+REPEAT('b', 766), REPEAT('c', 766), REPEAT('d', 766), REPEAT('e', 766),
+REPEAT('f', 766), REPEAT('g', 766), REPEAT('h', 766));
+
+CREATE TABLE t2_purge (
+A int PRIMARY KEY,
+B blob, C blob, D blob, E blob,
+F blob, G blob, H blob, I blob,
+J blob, K blob, L blob,
+INDEX (B(767))) ENGINE=InnoDB ROW_FORMAT=DYNAMIC;
+
+INSERT INTO t2_purge VALUES (1,
+REPEAT('b', 766), REPEAT('c', 766), REPEAT('d', 766), REPEAT('e', 766),
+REPEAT('f', 766), REPEAT('g', 766), REPEAT('h', 766), REPEAT('i', 766),
+REPEAT('j', 766), REPEAT('k', 766), REPEAT('l', 766));
+
+CREATE TABLE t3_purge (
+A int,
+B varchar(800), C varchar(800), D varchar(800), E varchar(800),
+F varchar(800), G varchar(800), H varchar(800),
+PRIMARY KEY (B(767), C(767), D(767), E(767), A),
+INDEX (A)
+) ENGINE=InnoDB ROW_FORMAT=DYNAMIC;
+
+INSERT INTO t3_purge SELECT * FROM t1_purge;
+
+CREATE TABLE t4_purge (
+A int PRIMARY KEY,
+B varchar(800), C varchar(800), D varchar(800), E varchar(800),
+F varchar(800), G varchar(800), H varchar(800), I varchar(800),
+J varchar(800), K varchar(800), L varchar(800),
+INDEX (B(767))) ENGINE=InnoDB ROW_FORMAT=DYNAMIC;
+
+INSERT INTO t4_purge SELECT * FROM t2_purge;
+
+# This would trigger the failure
+# if purge gets a chance to run before DROP TABLE t1_purge, ....
+DELETE FROM t1_purge;
+DELETE FROM t2_purge;
+DELETE FROM t3_purge;
+DELETE FROM t4_purge;
+
+# A secondary index tuple is found to be too long to fit into a page.
+SET @r=REPEAT('a',500);
+
+CREATE TABLE tlong(a int,
+ v1 varchar(500), v2 varchar(500), v3 varchar(500),
+ v4 varchar(500), v5 varchar(500), v6 varchar(500),
+ v7 varchar(500), v8 varchar(500), v9 varchar(500),
+ v10 varchar(500), v11 varchar(500), v12 varchar(500),
+ v13 varchar(500), v14 varchar(500), v15 varchar(500),
+ v16 varchar(500), v17 varchar(500), v18 varchar(500)
+) ENGINE=InnoDB ROW_FORMAT=DYNAMIC;
+
+CREATE INDEX idx1 ON tlong(a,v1);
+INSERT INTO tlong VALUES(9,@r,@r,@r,@r,@r,@r,@r,@r,@r,@r,@r,@r,@r,@r,@r,@r,@r,@r);
+UPDATE tlong SET a=1000;
+DELETE FROM tlong;
+
+# the number of indexes has changed since the UNDO record was logged.
+# page size. It just tests the condition that caused the crash.
+
+CREATE TABLE tlong2(a blob,b blob,c blob,d blob,e blob,f blob,g blob,h blob,
+ i blob,j blob,k blob,l blob,m blob,n blob,o blob,p blob)
+ ENGINE=innodb ROW_FORMAT=dynamic;
+
+SET @r = REPEAT('a', 767);
+INSERT INTO tlong2 VALUES (@r,@r,@r,@r, @r,@r,@r,@r, @r,@r,@r,@r, @r,@r,@r,@r);
+CREATE INDEX ndx_a ON tlong2 (a(500));
+CREATE INDEX ndx_b ON tlong2 (b(500));
+CREATE INDEX ndx_c ON tlong2 (c(500));
+CREATE INDEX ndx_d ON tlong2 (d(500));
+CREATE INDEX ndx_e ON tlong2 (e(500));
+CREATE INDEX ndx_f ON tlong2 (f(500));
+CREATE INDEX ndx_k ON tlong2 (k(500));
+CREATE INDEX ndx_l ON tlong2 (l(500));
+
+SET @r = REPEAT('b', 500);
+UPDATE tlong2 set a=@r,b=@r,c=@r,d=@r;
+UPDATE tlong2 set e=@r,f=@r,g=@r,h=@r;
+UPDATE tlong2 set i=@r,j=@r,k=@r,l=@r;
+UPDATE tlong2 set m=@r,n=@r,o=@r,p=@r;
+
+ALTER TABLE tlong2 DROP INDEX ndx_a;
+ALTER TABLE tlong2 DROP INDEX ndx_b;
+CREATE INDEX ndx_g ON tlong2 (g(500));
+CREATE INDEX ndx_h ON tlong2 (h(500));
+CREATE INDEX ndx_i ON tlong2 (i(500));
+CREATE INDEX ndx_j ON tlong2 (j(500));
+CREATE INDEX ndx_m ON tlong2 (m(500));
+CREATE INDEX ndx_n ON tlong2 (n(500));
+CREATE INDEX ndx_o ON tlong2 (o(500));
+CREATE INDEX ndx_p ON tlong2 (p(500));
+SHOW CREATE TABLE tlong2;
+
+# InnoDB cannot know that this undo record would be too big for the undo
+# page. Too much of text field is stored in the clustered record in this
+# DYNAMIC row formatted record.
+
+SET SESSION innodb_strict_mode = ON;
+
+CREATE TABLE bug12547647(
+a int NOT NULL, b blob NOT NULL, c text,
+PRIMARY KEY (b(10), a), INDEX (c(767)), INDEX(b(767))
+) ENGINE=InnoDB ROW_FORMAT=DYNAMIC;
+
+INSERT INTO bug12547647 VALUES (5,REPEAT('khdfo5AlOq',1900),REPEAT('g',7751));
+COMMIT;
+
+# The following used to cause a hang while doing infinite undo log allocation.
+BEGIN;
+UPDATE bug12547647 SET c = REPEAT('b',16928);
+SHOW WARNINGS;
+ROLLBACK;
+DROP TABLE bug12547647;
+
+SET SESSION innodb_strict_mode = on;
+--error ER_TOO_BIG_ROWSIZE
+CREATE TABLE t1(
+ c text NOT NULL, d text NOT NULL,
+ PRIMARY KEY (c(767),d(767)))
+ENGINE=InnoDB ROW_FORMAT=COMPRESSED KEY_BLOCK_SIZE=1 CHARSET=ASCII;
+
+--error ER_TOO_BIG_ROWSIZE
+CREATE TABLE t1(
+ c text NOT NULL, d text NOT NULL,
+ PRIMARY KEY (c(767),d(767)))
+ENGINE=InnoDB ROW_FORMAT=COMPRESSED KEY_BLOCK_SIZE=2 CHARSET=ASCII;
+
+CREATE TABLE t1(
+ c text NOT NULL, d text NOT NULL,
+ PRIMARY KEY (c(767),d(767)))
+ENGINE=InnoDB ROW_FORMAT=COMPRESSED KEY_BLOCK_SIZE=4 CHARSET=ASCII;
+
+drop table t1;
+
+--error ER_TOO_BIG_ROWSIZE
+CREATE TABLE t1(c text, PRIMARY KEY (c(440)))
+ENGINE=InnoDB ROW_FORMAT=COMPRESSED KEY_BLOCK_SIZE=1 CHARSET=ASCII;
+
+CREATE TABLE t1(c text, PRIMARY KEY (c(292)))
+ENGINE=InnoDB ROW_FORMAT=COMPRESSED KEY_BLOCK_SIZE=1 CHARSET=ASCII;
+
+INSERT INTO t1 VALUES(REPEAT('A',512)),(REPEAT('B',512));
+
+DROP TABLE t1;
+
+--source include/wait_all_purged.inc
+
+SET GLOBAL innodb_compression_level=@save_level;
+
+DROP TABLE t1_purge, t2_purge, t3_purge, t4_purge;
+DROP TABLE tlong;
+DROP TABLE tlong2;
diff --git a/mysql-test/suite/innodb/t/innodb-32k-crash-master.opt b/mysql-test/suite/innodb/t/innodb-32k-crash-master.opt
new file mode 100644
index 00000000..4761ed67
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb-32k-crash-master.opt
@@ -0,0 +1,5 @@
+--default_storage_engine=InnoDB
+--innodb-buffer-pool-size=32M
+--innodb-log-file-size=32M
+--innodb-page-size=32K
+
diff --git a/mysql-test/suite/innodb/t/innodb-32k-crash.test b/mysql-test/suite/innodb/t/innodb-32k-crash.test
new file mode 100644
index 00000000..178b32d5
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb-32k-crash.test
@@ -0,0 +1,195 @@
+--source include/have_innodb.inc
+--source include/have_innodb_32k.inc
+# Embedded server does not support restarting
+--source include/not_embedded.inc
+
+let $MYSQLD_DATADIR= `select @@datadir`;
+
+CREATE TABLE t1(a blob,b blob,c blob,d blob,e blob,f blob,g blob,
+ h blob,i blob,j blob,k blob,l blob,m blob,n blob,
+ o blob,p blob,q blob,r blob,s blob,t blob,u blob,
+ v blob, w blob, x blob, y blob, z blob,
+ aa blob,ba blob,ca blob,da blob,ea blob,fa blob,ga blob,
+ ha blob,ia blob,ja blob,ka blob,la blob,ma blob,na blob,
+ oa blob,pa blob,qa blob,ra blob,sa blob,ta blob,ua blob,
+ va blob, wa blob, xa blob, ya blob, za blob)
+ ENGINE=InnoDB ROW_FORMAT=dynamic;
+
+SET innodb_strict_mode=OFF;
+CREATE TABLE t2(a blob,b blob,c blob,d blob,e blob,f blob,g blob,
+ h blob,i blob,j blob,k blob,l blob,m blob,n blob,
+ o blob,p blob,q blob,r blob,s blob,t blob,u blob,
+ v blob, w blob, x blob, y blob, z blob,
+ aa blob,ba blob,ca blob,da blob,ea blob,fa blob,ga blob,
+ ha blob,ia blob,ja blob,ka blob,la blob,ma blob,na blob,
+ oa blob,pa blob,qa blob,ra blob,sa blob,ta blob,ua blob,
+ va blob, wa blob, xa blob, ya blob, za blob)
+ ENGINE=InnoDB ROW_FORMAT=compact;
+SET innodb_strict_mode=ON;
+
+SET @a = repeat('a', 767);
+SET @b = repeat('b', 767);
+SET @c = repeat('c', 767);
+SET @d = repeat('d', 767);
+SET @e = repeat('e', 767);
+SET @f = repeat('f', 767);
+SET @f = repeat('g', 767);
+
+# With no indexes defined, we can update all columns to max key part length.
+
+INSERT INTO t1 VALUES (@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a);
+INSERT INTO t1 VALUES (@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a);
+INSERT INTO t1 VALUES (@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a);
+INSERT INTO t1 VALUES (@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a);
+INSERT INTO t1 VALUES (@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a);
+INSERT INTO t1 VALUES (@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a);
+INSERT INTO t1 VALUES (@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a);
+INSERT INTO t1 VALUES (@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a);
+INSERT INTO t1 VALUES (@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a);
+INSERT INTO t1 VALUES (@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a);
+
+SET @f = repeat('h', 500);
+SET @f = repeat('i', 500);
+SET @f = repeat('j', 500);
+SET @f = repeat('k', 500);
+SET @f = repeat('l', 500);
+SET @f = repeat('m', 500);
+
+INSERT INTO t2 VALUES (@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h);
+INSERT INTO t2 VALUES (@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h);
+INSERT INTO t2 VALUES (@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h);
+INSERT INTO t2 VALUES (@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h);
+INSERT INTO t2 VALUES (@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h);
+INSERT INTO t2 VALUES (@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h);
+INSERT INTO t2 VALUES (@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h);
+INSERT INTO t2 VALUES (@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h);
+INSERT INTO t2 VALUES (@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h);
+INSERT INTO t2 VALUES (@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h,@h);
+
+
+UPDATE t1 SET a=@b,b=@b,c=@b,d=@b,e=@b,f=@b,g=@b,h=@b,i=@b,j=@b,
+ k=@b,l=@b,m=@b,n=@b,o=@b,p=@b,q=@b,r=@b,s=@b,t=@b,u=@b,
+ v=@b,w=@b,x=@b,y=@b,z=@b,
+ aa=@b,ba=@b,ca=@b,da=@b,ea=@b,fa=@b,ga=@b,ha=@b,ia=@b,ja=@b,
+ ka=@b,la=@b,ma=@b,na=@b,oa=@b,pa=@b,qa=@b,ra=@b,sa=@b,ta=@b,ua=@b,
+ va=@b,wa=@b,xa=@b,ya=@b,za=@b;
+
+UPDATE t2 SET a=@i,b=@i,c=@i,d=@i,e=@i,f=@i,g=@i,h=@i,i=@i,j=@i,
+ k=@i,l=@i,m=@i,n=@i,o=@i,p=@i,q=@i,r=@i,s=@i,t=@i,u=@i,
+ v=@i,w=@i,x=@i,y=@i,z=@i,
+ aa=@i,ba=@i,ca=@i,da=@i,ea=@i,fa=@i,ga=@i,ha=@i,ia=@i,ja=@i,
+ ka=@i,la=@i,ma=@i,na=@i,oa=@i,pa=@i,qa=@i,ra=@i,sa=@i,ta=@i,ua=@i,
+ va=@i,wa=@i,xa=@i,ya=@i,za=@i;
+
+CREATE INDEX t1a ON t1 (a(767));
+CREATE INDEX t1b ON t1 (b(767));
+CREATE INDEX t1c ON t1 (c(767));
+CREATE INDEX t1d ON t1 (d(767));
+CREATE INDEX t1e ON t1 (e(767));
+CREATE INDEX t1f1 ON t1 (f(767));
+CREATE INDEX t1f2 ON t1 (g(767));
+CREATE INDEX t1f3 ON t1 (h(767));
+CREATE INDEX t1f4 ON t1 (i(767));
+CREATE INDEX t1f5 ON t1 (j(767));
+
+CREATE INDEX t1a ON t2 (a(767));
+CREATE INDEX t1b ON t2 (b(767));
+CREATE INDEX t1c ON t2 (c(767));
+CREATE INDEX t1d ON t2 (d(767));
+CREATE INDEX t1e ON t2 (e(767));
+CREATE INDEX t1f1 ON t2 (f(767));
+CREATE INDEX t1f2 ON t2 (g(767));
+CREATE INDEX t1f3 ON t2 (h(767));
+
+UPDATE t1 SET a=@c,b=@c,c=@c,d=@c,e=@c,f=@c,g=@c,h=@c,i=@c,j=@c,
+ k=@c,l=@c,m=@c,n=@c,o=@c,p=@c,q=@c,r=@c,s=@c,t=@c,u=@c,
+ v=@c,w=@c,x=@b,y=@c,z=@c,
+ aa=@c,ba=@c,ca=@c,da=@c,ea=@c,fa=@c,ga=@c,ha=@c,ia=@c,ja=@c,
+ ka=@c,la=@c,ma=@c,na=@c,oa=@c,pa=@c,qa=@c,ra=@c,sa=@c,ta=@b,ua=@c,
+ va=@c,wa=@c,xa=@c,ya=@c,za=@c;
+
+UPDATE t2 SET a=@k,b=@k,c=@k,d=@k,e=@k,f=@k,g=@k,h=@k,i=@k,j=@k,
+ k=@k,l=@k,m=@k,n=@k,o=@k,p=@k,q=@k,r=@k,s=@k,t=@k,u=@k,
+ v=@k,w=@k,x=@b,y=@k,z=@k,
+ aa=@k,ba=@k,ca=@k,da=@k,ea=@k,fa=@k,ga=@k,ha=@k,ia=@k,ja=@k,
+ ka=@k,la=@k,ma=@k,na=@k,oa=@k,pa=@k,qa=@k,ra=@k,sa=@k,ta=@b,ua=@k,
+ va=@k,wa=@k,xa=@k,ya=@k,za=@k;
+
+BEGIN;
+UPDATE t1 SET a=@d,b=@d,c=@d,d=@d,e=@d;
+UPDATE t1 SET f=@d,g=@d,h=@d,i=@d,j=@d;
+UPDATE t1 SET k=@d,l=@d,m=@d,n=@d,o=@d;
+UPDATE t1 SET p=@d,q=@d,r=@d,s=@d,t=@d,u=@d;
+UPDATE t1 SET v=@d,w=@d,x=@d,y=@d,z=@d;
+UPDATE t1 SET aa=@d,ba=@d,ca=@d,da=@d;
+UPDATE t1 SET ea=@d,fa=@d,ga=@d,ha=@d,ia=@d,ja=@d;
+UPDATE t1 SET ka=@d,la=@d,ma=@d,na=@d,oa=@d,pa=@d;
+UPDATE t1 SET qa=@d,ra=@d,sa=@d,ta=@d,ua=@d;
+UPDATE t1 SET va=@d,wa=@d,xa=@d,ya=@d,za=@d;
+COMMIT;
+
+BEGIN;
+UPDATE t2 SET a=@l,b=@l,c=@l,d=@l,e=@l;
+UPDATE t2 SET f=@l,g=@l,h=@l,i=@l,j=@l;
+UPDATE t2 SET k=@l,l=@l,m=@l,n=@l,o=@l;
+UPDATE t2 SET p=@l,q=@l,r=@l,s=@l,t=@l,u=@l;
+UPDATE t2 SET v=@l,w=@l,x=@l,y=@l,z=@l;
+UPDATE t2 SET aa=@l,ba=@l,ca=@l,da=@l;
+UPDATE t2 SET ea=@l,fa=@l,ga=@l,ha=@l,ia=@l,ja=@l;
+UPDATE t2 SET ka=@l,la=@l,ma=@l,na=@l,oa=@l,pa=@l;
+UPDATE t2 SET qa=@l,ra=@l,sa=@l,ta=@l,ua=@l;
+UPDATE t2 SET va=@l,wa=@l,xa=@l,ya=@l,za=@l;
+COMMIT;
+
+BEGIN;
+INSERT INTO t1 SELECT * from t2;
+
+BEGIN;
+UPDATE t1 SET a=@e,b=@e,c=@e,d=@e,e=@e;
+--let $shutdown_timeout=0
+--source include/restart_mysqld.inc
+--let $shutdown_timeout=
+
+UPDATE t1 SET a=@f,b=@f,c=@f,d=@f,e=@f,f=@f,g=@f,h=@f,i=@f,j=@f,
+ k=@f,l=@f,m=@f,n=@f,o=@f,p=@f,q=@f,r=@f,s=@f,t=@f,u=@f,
+ v=@f,w=@f,x=@b,y=@f,z=@f,
+ aa=@f,ba=@f,ca=@f,da=@f,ea=@f,fa=@f,ga=@f,ha=@f,ia=@f,ja=@f,
+ ka=@f,la=@f,ma=@f,na=@f,oa=@f,pa=@f,qa=@f,ra=@f,sa=@f,ta=@b,ua=@f,
+ va=@f,wa=@f,xa=@f,ya=@f,za=@f;
+
+UPDATE t2 SET a=@h,b=@h,c=@h,d=@h,e=@h,f=@h,g=@h,h=@h,i=@h,j=@h,
+ k=@h,l=@h,m=@h,n=@h,o=@h,p=@h,q=@h,r=@h,s=@h,t=@h,u=@h,
+ v=@h,w=@h,x=@b,y=@h,z=@h,
+ aa=@h,ba=@h,ca=@h,da=@h,ea=@h,fa=@h,ga=@h,ha=@h,ia=@h,ja=@h,
+ ka=@h,la=@h,ma=@h,na=@h,oa=@h,pa=@h,qa=@h,ra=@h,sa=@h,ta=@b,ua=@h,
+ va=@h,wa=@h,xa=@h,ya=@h,za=@h;
+
+BEGIN;
+UPDATE t1 SET a=@g,b=@g,c=@g,d=@g,e=@g;
+UPDATE t1 SET f=@g,g=@g,h=@g,i=@g,j=@g;
+UPDATE t1 SET k=@g,l=@g,m=@g,n=@g,o=@g;
+UPDATE t1 SET p=@g,q=@g,r=@g,s=@g,t=@g,u=@g;
+UPDATE t1 SET v=@g,w=@g,x=@g,y=@g,z=@g;
+UPDATE t1 SET aa=@g,ba=@g,ca=@g,da=@g;
+UPDATE t1 SET ea=@g,fa=@g,ga=@g,ha=@g,ia=@g,ja=@g;
+UPDATE t1 SET ka=@g,la=@g,ma=@g,na=@g,oa=@g,pa=@g;
+UPDATE t1 SET qa=@g,ra=@g,sa=@g,ta=@g,ua=@g;
+UPDATE t1 SET va=@g,wa=@g,xa=@g,ya=@g,za=@g;
+COMMIT;
+
+BEGIN;
+UPDATE t2 SET a=@m,b=@m,c=@m,d=@m,e=@m;
+UPDATE t2 SET f=@m,g=@m,h=@m,i=@m,j=@m;
+UPDATE t2 SET k=@m,l=@m,m=@m,n=@m,o=@m;
+UPDATE t2 SET p=@m,q=@m,r=@m,s=@m,t=@m,u=@m;
+UPDATE t2 SET v=@m,w=@m,x=@m,y=@m,z=@m;
+UPDATE t2 SET aa=@m,ba=@m,ca=@m,da=@m;
+UPDATE t2 SET ea=@m,fa=@m,ga=@m,ha=@m,ia=@m,ja=@m;
+UPDATE t2 SET ka=@m,la=@m,ma=@m,na=@m,oa=@m,pa=@m;
+UPDATE t2 SET qa=@m,ra=@m,sa=@m,ta=@m,ua=@m;
+UPDATE t2 SET va=@m,wa=@m,xa=@m,ya=@m,za=@m;
+COMMIT;
+
+show create table t1;
+show create table t2;
+drop table t1,t2;
diff --git a/mysql-test/suite/innodb/t/innodb-32k-master.opt b/mysql-test/suite/innodb/t/innodb-32k-master.opt
new file mode 100644
index 00000000..322385f7
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb-32k-master.opt
@@ -0,0 +1,4 @@
+--default_storage_engine=InnoDB
+--innodb-page-size=32K
+--innodb-log-file-size=32M
+--innodb-buffer-pool-size=32M
diff --git a/mysql-test/suite/innodb/t/innodb-32k.test b/mysql-test/suite/innodb/t/innodb-32k.test
new file mode 100644
index 00000000..496977c1
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb-32k.test
@@ -0,0 +1,609 @@
+--source include/no_valgrind_without_big.inc
+# Tests for setting innodb-page-size=32k;
+--source include/have_innodb.inc
+--source include/have_innodb_32k.inc
+
+call mtr.add_suppression("Innodb: Cannot add field.*row size is");
+
+let $MYSQLD_DATADIR= `select @@datadir`;
+
+--echo # Test 1) Show the page size from Information Schema
+SELECT variable_value FROM information_schema.global_status
+ WHERE LOWER(variable_name) = 'innodb_page_size';
+
+--echo # Test 4) The maximum row size is dependent upon the page size.
+--echo # Redundant: 16315, Compact: 16318.
+--echo # Compressed: 16318, Dynamic: ?.
+--echo # Each row format has its own amount of overhead that
+--echo # varies depending on number of fields and other overhead.
+
+SET SESSION innodb_strict_mode = ON;
+
+--replace_regex /> [0-9]*/> max_row_size/
+--error ER_CANT_CREATE_TABLE,ER_UNSUPPORTED_COMPRESSED_TABLE
+CREATE TABLE t1 (
+c01 char(200), c02 char(200), c03 char(200), c04 char(200), c05 char(200),
+c06 char(200), c07 char(200), c08 char(200), c09 char(200), c10 char(200),
+c11 char(200), c12 char(200), c13 char(200), c14 char(200), c15 char(200),
+c16 char(200), c17 char(200), c18 char(200), c19 char(200), c20 char(200),
+c21 char(200), c22 char(200), c23 char(200), c24 char(200), c25 char(200),
+c26 char(200), c27 char(200), c28 char(200), c29 char(200), c30 char(200),
+c31 char(200), c32 char(200), c33 char(200), c34 char(200), c35 char(200),
+c36 char(200), c37 char(200), c38 char(200), c39 char(200), c40 char(200),
+c41 char(200), c42 char(200), c43 char(200), c44 char(200), c45 char(200),
+c46 char(200), c47 char(200), c48 char(200), c49 char(200), c50 char(200),
+c51 char(200), c52 char(200), c53 char(200), c54 char(200), c55 char(200),
+c56 char(200), c57 char(200), c58 char(200), c59 char(200), c60 char(200),
+c61 char(200), c62 char(200), c63 char(200), c64 char(200), c65 char(200),
+c66 char(200), c67 char(200), c68 char(200), c69 char(200), c70 char(200),
+c71 char(200), c72 char(200), c73 char(200), c74 char(200), c75 char(200),
+c76 char(200), c77 char(200), c78 char(200), c79 char(200), c80 char(200),
+c81 char(63)
+) ROW_FORMAT=compressed;
+
+
+#
+# Test the maximum key length
+# Moved from innodb-index.test since each page size has its own max key length.
+# Max Key Length is 3072 for 16k pages.
+# Max key Part length is 767
+# InnoDB assumes 3 bytes for each UTF8 character.
+#
+
+CREATE TABLE t1 (a varchar(255) character set utf8,
+ b varchar(255) character set utf8,
+ c varchar(255) character set utf8,
+ d varchar(255) character set utf8,
+ e varchar(4) character set utf8,
+ PRIMARY KEY (a,b,c,d,e))
+ ENGINE=innodb;
+
+DROP TABLE t1;
+
+--error ER_TOO_LONG_KEY
+CREATE TABLE t1 (a varchar(255) character set utf8,
+ b varchar(255) character set utf8,
+ c varchar(255) character set utf8,
+ d varchar(255) character set utf8,
+ e varchar(5) character set utf8,
+ PRIMARY KEY (a,b,c,d,e))
+ ENGINE=innodb;
+
+CREATE TABLE t1 (a varchar(255) character set utf8,
+ b varchar(255) character set utf8,
+ c varchar(255) character set utf8,
+ d varchar(255) character set utf8,
+ e varchar(255) character set utf8,
+ f varchar(4) character set utf8,
+ PRIMARY KEY (a), KEY (b,c,d,e,f))
+ ENGINE=innodb;
+
+DROP TABLE t1;
+
+--error ER_TOO_LONG_KEY
+CREATE TABLE t1 (a varchar(255) character set utf8,
+ b varchar(255) character set utf8,
+ c varchar(255) character set utf8,
+ d varchar(255) character set utf8,
+ e varchar(255) character set utf8,
+ f varchar(5) character set utf8,
+ PRIMARY KEY (a), KEY (b,c,d,e,f))
+ ENGINE=innodb;
+
+
+
+--echo # Test 8) Test creating a table that could lead to undo log overflow.
+
+CREATE TABLE t1(a blob,b blob,c blob,d blob,e blob,f blob,g blob,
+ h blob,i blob,j blob,k blob,l blob,m blob,n blob,
+ o blob,p blob,q blob,r blob,s blob,t blob,u blob,
+ v blob, w blob, x blob, y blob, z blob,
+ aa blob,ba blob,ca blob,da blob,ea blob,fa blob,ga blob,
+ ha blob,ia blob,ja blob,ka blob,la blob,ma blob,na blob,
+ oa blob,pa blob,qa blob,ra blob,sa blob,ta blob,ua blob,
+ va blob, wa blob, xa blob, ya blob, za blob)
+ ENGINE=InnoDB ROW_FORMAT=dynamic;
+
+SET @a = repeat('a', 767);
+SET @b = repeat('b', 767);
+SET @c = repeat('c', 767);
+SET @d = repeat('d', 767);
+SET @e = repeat('e', 767);
+
+# With no indexes defined, we can update all columns to max key part length.
+
+INSERT INTO t1 VALUES (@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,@a);
+
+UPDATE t1 SET a=@b,b=@b,c=@b,d=@b,e=@b,f=@b,g=@b,h=@b,i=@b,j=@b,
+ k=@b,l=@b,m=@b,n=@b,o=@b,p=@b,q=@b,r=@b,s=@b,t=@b,u=@b,
+ v=@b,w=@b,x=@b,y=@b,z=@b,
+ aa=@b,ba=@b,ca=@b,da=@b,ea=@b,fa=@b,ga=@b,ha=@b,ia=@b,ja=@b,
+ ka=@b,la=@b,ma=@b,na=@b,oa=@b,pa=@b,qa=@b,ra=@b,sa=@b,ta=@b,ua=@b,
+ va=@b,wa=@b,xa=@b,ya=@b,za=@b;
+
+
+# With this many indexes defined, we can still update all fields.
+CREATE INDEX t1a ON t1 (a(767));
+CREATE INDEX t1b ON t1 (b(767));
+CREATE INDEX t1c ON t1 (c(767));
+CREATE INDEX t1d ON t1 (d(767));
+CREATE INDEX t1e ON t1 (e(767));
+CREATE INDEX t1f1 ON t1 (f(767));
+CREATE INDEX t1f2 ON t1 (g(767));
+CREATE INDEX t1f3 ON t1 (h(767));
+CREATE INDEX t1f4 ON t1 (i(767));
+CREATE INDEX t1f5 ON t1 (j(767));
+
+UPDATE t1 SET a=@c,b=@c,c=@c,d=@c,e=@c,f=@c,g=@c,h=@c,i=@c,j=@c,
+ k=@c,l=@c,m=@c,n=@c,o=@c,p=@c,q=@c,r=@c,s=@c,t=@c,u=@c,
+ v=@c,w=@c,x=@c,y=@c,z=@c,
+ aa=@c,ba=@c,ca=@c,da=@c,ea=@c,fa=@c,ga=@c,ha=@c,ia=@c,ja=@c,
+ ka=@c,la=@c,ma=@c,na=@c,oa=@c,pa=@c,qa=@c,ra=@c,sa=@c,ta=@c,ua=@c,
+ va=@c,wa=@c,xa=@c,ya=@c,za=@c;
+
+# Add one more index and the UNDO record becomes too big to update all columns.
+# But a single transaction can update the columns in separate statements.
+# because the UNDO records will be smaller.
+
+CREATE INDEX t1f17 ON t1 (v(767));
+
+BEGIN;
+UPDATE t1 SET a=@d,b=@d,c=@d,d=@d,e=@d,f=@d,g=@d,h=@d,i=@d,j=@d,
+ k=@d,l=@d,m=@d,n=@d,o=@d,p=@d,q=@d,r=@d,s=@d,t=@d,u=@d,
+ v=@d,w=@d,x=@d,y=@d,z=@d,
+ aa=@d,ba=@d,ca=@d,da=@d,ea=@d,fa=@d,ga=@d,ha=@d,ia=@d,ja=@d,
+ ka=@d,la=@d,ma=@d,na=@d,oa=@d,pa=@d,qa=@d,ra=@d,sa=@d,ta=@d,ua=@d,
+ va=@d,wa=@d,xa=@d,ya=@d,za=@d;
+ROLLBACK;
+
+BEGIN;
+UPDATE t1 SET a=@d,b=@d,c=@d,d=@d,e=@d;
+UPDATE t1 SET f=@d,g=@d,h=@d,i=@d,j=@d;
+UPDATE t1 SET k=@d,l=@d,m=@d,n=@d,o=@d;
+UPDATE t1 SET p=@d,q=@d,r=@d,s=@d,t=@d,u=@d;
+UPDATE t1 SET v=@d,w=@d,x=@d,y=@d,z=@d;
+UPDATE t1 SET aa=@d,ba=@d,ca=@d,da=@d;
+UPDATE t1 SET ea=@d,fa=@d,ga=@d,ha=@d,ia=@d,ja=@d;
+UPDATE t1 SET ka=@d,la=@d,ma=@d,na=@d,oa=@d,pa=@d;
+UPDATE t1 SET qa=@d,ra=@d,sa=@d,ta=@d,ua=@d;
+UPDATE t1 SET va=@d,wa=@d,xa=@d,ya=@d,za=@d;
+COMMIT;
+
+# More indexes can still be added and a single field can still be updated
+CREATE INDEX t1k ON t1 (k(767));
+CREATE INDEX t1f7 ON t1 (m(767));
+CREATE INDEX t1f8 ON t1 (n(767));
+CREATE INDEX t1f9 ON t1 (o(767));
+CREATE INDEX t1f11 ON t1 (p(767));
+CREATE INDEX t1f12 ON t1 (q(767));
+CREATE INDEX t1f13 ON t1 (r(767));
+CREATE INDEX t1f14 ON t1 (s(767));
+CREATE INDEX t1f15 ON t1 (t(767));
+CREATE INDEX t1f16 ON t1 (u(767));
+CREATE INDEX t1f18 ON t1 (w(767));
+CREATE INDEX t1f19 ON t1 (x(767));
+CREATE INDEX t1f20 ON t1 (y(767));
+CREATE INDEX t1f21 ON t1 (z(767));
+CREATE INDEX ta1a ON t1 (aa(767));
+CREATE INDEX tb1b ON t1 (ba(767));
+CREATE INDEX tc1c ON t1 (ca(767));
+CREATE INDEX td1d ON t1 (da(767));
+CREATE INDEX te1e ON t1 (ea(767));
+CREATE INDEX tf1f1 ON t1 (fa(767));
+CREATE INDEX tg1f2 ON t1 (ga(767));
+CREATE INDEX th1f3 ON t1 (ha(767));
+CREATE INDEX ti1f4 ON t1 (ia(767));
+CREATE INDEX tj1f5 ON t1 (ka(767));
+CREATE INDEX tk1f6 ON t1 (la(767));
+CREATE INDEX tl1f7 ON t1 (ma(767));
+CREATE INDEX tm1f8 ON t1 (na(767));
+CREATE INDEX tn1f9 ON t1 (oa(767));
+CREATE INDEX to1f11 ON t1 (pa(767));
+UPDATE t1 SET t=@e;
+
+# One more index and row size is too big (not any more!)
+#--replace_regex /> [0-9]*/> max_row_size/
+#--error ER_TOO_BIG_ROWSIZE
+CREATE INDEX t1f6 ON t1 (l(767));
+
+drop table t1;
+
+--echo Test an assertion failure on purge.
+
+# This test is not in innodb_8k or innodb_4k since the bug is not about
+# page size. It just tests the condition that caused the assertion.
+
+CREATE TABLE t1_purge (
+A int,
+B blob, C blob, D blob, E blob,
+F blob, G blob, H blob,
+PRIMARY KEY (B(767), C(767), D(767), E(767), A),
+INDEX (A)
+) ENGINE=InnoDB ROW_FORMAT=DYNAMIC;
+
+INSERT INTO t1_purge VALUES (1,
+REPEAT('b', 766), REPEAT('c', 766), REPEAT('d', 766), REPEAT('e', 766),
+REPEAT('f', 766), REPEAT('g', 766), REPEAT('h', 766));
+
+CREATE TABLE t2_purge (
+A int PRIMARY KEY,
+B blob, C blob, D blob, E blob,
+F blob, G blob, H blob, I blob,
+J blob, K blob, L blob,
+INDEX (B(767))) ENGINE=InnoDB ROW_FORMAT=DYNAMIC;
+
+INSERT INTO t2_purge VALUES (1,
+REPEAT('b', 766), REPEAT('c', 766), REPEAT('d', 766), REPEAT('e', 766),
+REPEAT('f', 766), REPEAT('g', 766), REPEAT('h', 766), REPEAT('i', 766),
+REPEAT('j', 766), REPEAT('k', 766), REPEAT('l', 766));
+
+CREATE TABLE t3_purge (
+A int,
+B varchar(800), C varchar(800), D varchar(800), E varchar(800),
+F varchar(800), G varchar(800), H varchar(800),
+PRIMARY KEY (B(767), C(767), D(767), E(767), A),
+INDEX (A)
+) ENGINE=InnoDB ROW_FORMAT=DYNAMIC;
+
+INSERT INTO t3_purge SELECT * FROM t1_purge;
+
+CREATE TABLE t4_purge (
+A int PRIMARY KEY,
+B varchar(800), C varchar(800), D varchar(800), E varchar(800),
+F varchar(800), G varchar(800), H varchar(800), I varchar(800),
+J varchar(800), K varchar(800), L varchar(800),
+INDEX (B(767))) ENGINE=InnoDB ROW_FORMAT=DYNAMIC;
+
+INSERT INTO t4_purge SELECT * FROM t2_purge;
+
+# This would trigger the failure
+# if purge gets a chance to run before DROP TABLE t1_purge, ....
+DELETE FROM t1_purge;
+DELETE FROM t2_purge;
+DELETE FROM t3_purge;
+DELETE FROM t4_purge;
+
+# A secondary index tuple is found to be too long to fit into a page.
+SET @r=REPEAT('a',500);
+
+CREATE TABLE tlong(a int,
+ v1 varchar(500), v2 varchar(500), v3 varchar(500),
+ v4 varchar(500), v5 varchar(500), v6 varchar(500),
+ v7 varchar(500), v8 varchar(500), v9 varchar(500),
+ v10 varchar(500), v11 varchar(500), v12 varchar(500),
+ v13 varchar(500), v14 varchar(500), v15 varchar(500),
+ v16 varchar(500), v17 varchar(500), v18 varchar(500)
+) ENGINE=InnoDB ROW_FORMAT=DYNAMIC;
+
+CREATE INDEX idx1 ON tlong(a,v1);
+INSERT INTO tlong VALUES(9,@r,@r,@r,@r,@r,@r,@r,@r,@r,@r,@r,@r,@r,@r,@r,@r,@r,@r);
+UPDATE tlong SET a=1000;
+DELETE FROM tlong;
+
+# the number of indexes has changed since the UNDO record was logged.
+# page size. It just tests the condition that caused the crash.
+
+CREATE TABLE tlong2(a blob,b blob,c blob,d blob,e blob,f blob,g blob,h blob,
+ i blob,j blob,k blob,l blob,m blob,n blob,o blob,p blob)
+ ENGINE=innodb ROW_FORMAT=dynamic;
+
+SET @r = REPEAT('a', 767);
+INSERT INTO tlong2 VALUES (@r,@r,@r,@r, @r,@r,@r,@r, @r,@r,@r,@r, @r,@r,@r,@r);
+CREATE INDEX ndx_a ON tlong2 (a(500));
+CREATE INDEX ndx_b ON tlong2 (b(500));
+CREATE INDEX ndx_c ON tlong2 (c(500));
+CREATE INDEX ndx_d ON tlong2 (d(500));
+CREATE INDEX ndx_e ON tlong2 (e(500));
+CREATE INDEX ndx_f ON tlong2 (f(500));
+CREATE INDEX ndx_k ON tlong2 (k(500));
+CREATE INDEX ndx_l ON tlong2 (l(500));
+
+SET @r = REPEAT('b', 500);
+UPDATE tlong2 set a=@r,b=@r,c=@r,d=@r;
+UPDATE tlong2 set e=@r,f=@r,g=@r,h=@r;
+UPDATE tlong2 set i=@r,j=@r,k=@r,l=@r;
+UPDATE tlong2 set m=@r,n=@r,o=@r,p=@r;
+
+ALTER TABLE tlong2 DROP INDEX ndx_a;
+ALTER TABLE tlong2 DROP INDEX ndx_b;
+CREATE INDEX ndx_g ON tlong2 (g(500));
+CREATE INDEX ndx_h ON tlong2 (h(500));
+CREATE INDEX ndx_i ON tlong2 (i(500));
+CREATE INDEX ndx_j ON tlong2 (j(500));
+CREATE INDEX ndx_m ON tlong2 (m(500));
+CREATE INDEX ndx_n ON tlong2 (n(500));
+CREATE INDEX ndx_o ON tlong2 (o(500));
+CREATE INDEX ndx_p ON tlong2 (p(500));
+SHOW CREATE TABLE tlong2;
+
+# InnoDB cannot know that this undo record would be too big for the undo
+# page. Too much of text field is stored in the clustered record in this
+# DYNAMIC row formatted record.
+
+SET SESSION innodb_strict_mode = ON;
+
+CREATE TABLE t3(
+a int NOT NULL, b blob NOT NULL, c text,
+PRIMARY KEY (b(10), a), INDEX (c(767)), INDEX(b(767))
+) ENGINE=InnoDB ROW_FORMAT=DYNAMIC;
+
+INSERT INTO t3 VALUES (5,REPEAT('khdfo5AlOq',1900),REPEAT('g',7751));
+COMMIT;
+
+UPDATE t3 SET c = REPEAT('b',16928);
+SHOW WARNINGS;
+UPDATE t3 SET c = REPEAT('b',32800);
+SHOW WARNINGS;
+
+--source include/wait_all_purged.inc
+
+DROP TABLE t3;
+DROP TABLE t1_purge, t2_purge, t3_purge, t4_purge;
+DROP TABLE tlong;
+DROP TABLE tlong2;
+
+
+CREATE TABLE t2(COL1 TEXT,
+COL2 TEXT,
+COL3 TEXT,
+COL4 TEXT,
+COL5 TEXT,
+COL6 TEXT,
+COL7 TEXT,
+COL8 TEXT,
+COL9 TEXT,
+COL10 TEXT,
+COL11 TEXT,
+COL12 TEXT,
+COL13 TEXT,
+COL14 TEXT,
+COL15 TEXT,
+COL16 TEXT,
+COL17 TEXT,
+COL18 TEXT,
+COL19 TEXT,
+COL20 TEXT,
+COL21 TEXT,
+COL22 TEXT,
+COL23 TEXT,
+COL24 TEXT,
+COL25 TEXT,
+COL26 TEXT,
+COL27 TEXT,
+COL28 TEXT,
+COL29 TEXT,
+COL30 TEXT,
+COL31 TEXT,
+COL32 TEXT,
+COL33 TEXT,
+COL34 TEXT,
+COL35 TEXT,
+COL36 TEXT,
+COL37 TEXT,
+COL38 TEXT,
+COL39 TEXT,
+COL40 TEXT,
+COL41 TEXT,
+COL42 TEXT,
+COL43 TEXT,
+COL44 TEXT,
+COL45 TEXT,
+COL46 TEXT,
+COL47 TEXT,
+COL48 TEXT,
+COL49 TEXT,
+COL50 TEXT,
+COL51 TEXT,
+COL52 TEXT,
+COL53 TEXT,
+COL54 TEXT,
+COL55 TEXT,
+COL56 TEXT,
+COL57 TEXT,
+COL58 TEXT,
+COL59 TEXT,
+COL60 TEXT,
+COL61 TEXT,
+COL62 TEXT,
+COL63 TEXT,
+COL64 TEXT,
+COL65 TEXT,
+COL66 TEXT,
+COL67 TEXT,
+COL68 TEXT,
+COL69 TEXT,
+COL70 TEXT,
+COL71 TEXT,
+COL72 TEXT,
+COL73 TEXT,
+COL74 TEXT,
+COL75 TEXT,
+COL76 TEXT,
+COL77 TEXT,
+COL78 TEXT,
+COL79 TEXT,
+COL80 TEXT,
+COL81 TEXT,
+COL82 TEXT,
+COL83 TEXT,
+COL84 TEXT,
+COL85 TEXT,
+COL86 TEXT,
+COL87 TEXT,
+COL88 TEXT,
+COL89 TEXT,
+COL90 TEXT,
+COL91 TEXT,
+COL92 TEXT,
+COL93 TEXT,
+COL94 TEXT,
+COL95 TEXT,
+COL96 TEXT,
+COL97 TEXT,
+COL98 TEXT,
+COL99 TEXT,
+COL100 TEXT,
+COL101 TEXT,
+COL102 TEXT,
+COL103 TEXT,
+COL104 TEXT,
+COL105 TEXT,
+COL106 TEXT,
+COL107 TEXT,
+COL108 TEXT,
+COL109 TEXT,
+COL110 TEXT,
+COL111 TEXT,
+COL112 TEXT,
+COL113 TEXT,
+COL114 TEXT,
+COL115 TEXT,
+COL116 TEXT,
+COL117 TEXT,
+COL118 TEXT,
+COL119 TEXT,
+COL120 TEXT,
+COL121 TEXT,
+COL122 TEXT,
+COL123 TEXT,
+COL124 TEXT,
+COL125 TEXT,
+COL126 TEXT,
+COL127 TEXT,
+COL128 TEXT,
+COL129 TEXT,
+COL130 TEXT,
+COL131 TEXT,
+COL132 TEXT,
+COL133 TEXT,
+COL134 TEXT,
+COL135 TEXT,
+COL136 TEXT,
+COL137 TEXT,
+COL138 TEXT,
+COL139 TEXT,
+COL140 TEXT,
+COL141 TEXT,
+COL142 TEXT,
+COL143 TEXT,
+COL144 TEXT,
+COL145 TEXT,
+COL146 TEXT,
+COL147 TEXT,
+COL148 TEXT,
+COL149 TEXT,
+COL150 TEXT,
+COL151 TEXT,
+COL152 TEXT,
+COL153 TEXT,
+COL154 TEXT,
+COL155 TEXT,
+COL156 TEXT,
+COL157 TEXT,
+COL158 TEXT,
+COL159 TEXT,
+COL160 TEXT,
+COL161 TEXT,
+COL162 TEXT,
+COL163 TEXT,
+COL164 TEXT,
+COL165 TEXT,
+COL166 TEXT,
+COL167 TEXT,
+COL168 TEXT,
+COL169 TEXT,
+COL170 TEXT,
+COL171 TEXT,
+COL172 TEXT,
+COL173 TEXT,
+COL174 TEXT,
+COL175 TEXT,
+COL176 TEXT,
+COL177 TEXT,
+COL178 TEXT,
+COL179 TEXT,
+COL180 TEXT,
+COL181 TEXT,
+COL182 TEXT,
+COL183 TEXT,
+COL184 TEXT,
+COL185 TEXT,
+COL186 TEXT,
+COL187 TEXT,
+COL188 TEXT,
+COL189 TEXT,
+COL190 TEXT,
+COL191 TEXT,
+COL192 TEXT,
+COL193 TEXT,
+COL194 TEXT,
+COL195 TEXT,
+COL196 TEXT,
+COL197 TEXT)
+row_format=dynamic,ENGINE=INNODB;
+
+set @a = repeat('0123456789', 800);
+set @b = repeat('9876543210', 800);
+
+insert into t2 values(
+@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,
+@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,
+@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,
+@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,
+@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,
+@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,
+@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,
+@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,
+@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,
+@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,
+@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,
+@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,
+@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,
+@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,
+@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,
+@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,
+@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,
+@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,
+@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,
+@a,@a,@a,@a,@a,@a,@a);
+
+update t2 set col190=@b;
+
+set @a = repeat('0123456789', 1650);
+set @b = repeat('9876543210', 2000);
+
+insert into t2 values(
+@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,
+@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,
+@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,
+@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,
+@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,
+@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,
+@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,
+@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,
+@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,
+@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,
+@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,
+@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,
+@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,
+@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,
+@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,
+@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,
+@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,
+@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,
+@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,
+@a,@a,@a,@a,@a,@a,@a);
+
+update t2 set col190=@b;
+#
+# Verify persistence and loading of flags in the ibd files.
+#
+
+--source include/restart_mysqld.inc
+
+set @a = repeat('abcdefghijklmnopqrstuvwxyz', 1650);
+set @b = repeat('zyxwvutsrqponmlkjihgfedcba', 2000);
+show create table t2;
+update t2 set col150=@a;
+update t2 set col145=@b;
+drop table t2;
diff --git a/mysql-test/suite/innodb/t/innodb-64k-crash-master.opt b/mysql-test/suite/innodb/t/innodb-64k-crash-master.opt
new file mode 100644
index 00000000..ce51caf3
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb-64k-crash-master.opt
@@ -0,0 +1,5 @@
+--default_storage_engine=InnoDB
+--innodb-buffer-pool-size=32M
+--innodb-page-size=64K
+--innodb-log-file-size=32M
+
diff --git a/mysql-test/suite/innodb/t/innodb-64k-crash.test b/mysql-test/suite/innodb/t/innodb-64k-crash.test
new file mode 100644
index 00000000..93f6f79e
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb-64k-crash.test
@@ -0,0 +1,316 @@
+--source include/have_innodb.inc
+--source include/have_innodb_64k.inc
+# Embedded server does not support restarting
+--source include/not_embedded.inc
+
+let $MYSQLD_DATADIR= `select @@datadir`;
+
+CREATE TABLE t1(a blob,b blob,c blob,d blob,e blob,f blob,g blob,
+ h blob,i blob,j blob,k blob,l blob,m blob,n blob,
+ o blob,p blob,q blob,r blob,s blob,t blob,u blob,
+ v blob, w blob, x blob, y blob, z blob,
+ aa blob,ba blob,ca blob,da blob,ea blob,fa blob,ga blob,
+ ha blob,ia blob,ja blob,ka blob,la blob,ma blob,na blob,
+ oa blob,pa blob,qa blob,ra blob,sa blob,ta blob,ua blob,
+ va blob, wa blob, xa blob, ya blob, za blob,
+ ab blob,bb blob,cb blob,db blob,eb blob,fb blob,gb blob,
+ hb blob,ib blob,jb blob,kb blob,lb blob,mb blob,nb blob,
+ ob blob,pb blob,qb blob,rb blob,sb blob,tb blob,ub blob,
+ vb blob, wb blob, xb blob, yb blob, zb blob,
+ ac blob, bc blob, cc blob, dc blob, ec blob,fc blob,gc blob,
+ hc blob, ic blob, jc blob, kc blob, lc blob,mc blob,nc blob,
+ oc blob, pc blob, qc blob, rc blob, sc blob,tc blob,uc blob,
+ vc blob, wc blob, xc blob, yc blob, zc blob
+ ) ENGINE=InnoDB ROW_FORMAT=dynamic;
+
+SET innodb_strict_mode=OFF;
+CREATE TABLE t2(a blob,b blob,c blob,d blob,e blob,f blob,g blob,
+ h blob,i blob,j blob,k blob,l blob,m blob,n blob,
+ o blob,p blob,q blob,r blob,s blob,t blob,u blob,
+ v blob, w blob, x blob, y blob, z blob,
+ aa blob,ba blob,ca blob,da blob,ea blob,fa blob,ga blob,
+ ha blob,ia blob,ja blob,ka blob,la blob,ma blob,na blob,
+ oa blob,pa blob,qa blob,ra blob,sa blob,ta blob,ua blob,
+ va blob, wa blob, xa blob, ya blob, za blob,
+ ab blob,bb blob,cb blob,db blob,eb blob,fb blob,gb blob,
+ hb blob,ib blob,jb blob,kb blob,lb blob,mb blob,nb blob,
+ ob blob,pb blob,qb blob,rb blob,sb blob,tb blob,ub blob,
+ vb blob, wb blob, xb blob, yb blob, zb blob,
+ ac blob, bc blob, cc blob, dc blob, ec blob,fc blob,gc blob,
+ hc blob, ic blob, jc blob, kc blob, lc blob,mc blob,nc blob,
+ oc blob, pc blob, qc blob, rc blob, sc blob,tc blob,uc blob,
+ vc blob, wc blob, xc blob, yc blob, zc blob
+ ) ENGINE=InnoDB ROW_FORMAT=compact;
+SET innodb_strict_mode=ON;
+
+SET @a = repeat('a', 767);
+SET @b = repeat('b', 767);
+SET @c = repeat('c', 767);
+SET @d = repeat('d', 767);
+SET @e = repeat('e', 767);
+SET @f = repeat('f', 767);
+SET @f = repeat('g', 767);
+
+INSERT INTO t1 VALUES (@a,@a,@a,@a,@a,@a,@a,
+@a,@a,@a,@a,@a,@a,@a,
+@a,@a,@a,@a,@a,@a,@a,
+@a,@a,@a,@a,@a,
+@a,@a,@a,@a,@a,@a,@a,
+@a,@a,@a,@a,@a,@a,@a,
+@a,@a,@a,@a,@a,@a,@a,
+@a,@a,@a,@a,@a,
+@a,@a,@a,@a,@a,@a,@a,
+@a,@a,@a,@a,@a,@a,@a,
+@a,@a,@a,@a,@a,@a,@a,
+@a,@a,@a,@a,@a,
+@a,@a,@a,@a,@a,@a,@a,
+@a,@a,@a,@a,@a,@a,@a,
+@a,@a,@a,@a,@a,@a,@a,
+@a,@a,@a,@a,@a
+);
+
+INSERT INTO t1 VALUES (@a,@a,@a,@a,@a,@a,@a,
+@a,@a,@a,@a,@a,@a,@a,
+@a,@a,@a,@a,@a,@a,@a,
+@a,@a,@a,@a,@a,
+@a,@a,@a,@a,@a,@a,@a,
+@a,@a,@a,@a,@a,@a,@a,
+@a,@a,@a,@a,@a,@a,@a,
+@a,@a,@a,@a,@a,
+@a,@a,@a,@a,@a,@a,@a,
+@a,@a,@a,@a,@a,@a,@a,
+@a,@a,@a,@a,@a,@a,@a,
+@a,@a,@a,@a,@a,
+@a,@a,@a,@a,@a,@a,@a,
+@a,@a,@a,@a,@a,@a,@a,
+@a,@a,@a,@a,@a,@a,@a,
+@a,@a,@a,@a,@a
+);
+
+INSERT INTO t1 VALUES (@a,@a,@a,@a,@a,@a,@a,
+@a,@a,@a,@a,@a,@a,@a,
+@a,@a,@a,@a,@a,@a,@a,
+@a,@a,@a,@a,@a,
+@a,@a,@a,@a,@a,@a,@a,
+@a,@a,@a,@a,@a,@a,@a,
+@a,@a,@a,@a,@a,@a,@a,
+@a,@a,@a,@a,@a,
+@a,@a,@a,@a,@a,@a,@a,
+@a,@a,@a,@a,@a,@a,@a,
+@a,@a,@a,@a,@a,@a,@a,
+@a,@a,@a,@a,@a,
+@a,@a,@a,@a,@a,@a,@a,
+@a,@a,@a,@a,@a,@a,@a,
+@a,@a,@a,@a,@a,@a,@a,
+@a,@a,@a,@a,@a
+);
+
+INSERT INTO t1 VALUES (@a,@a,@a,@a,@a,@a,@a,
+@a,@a,@a,@a,@a,@a,@a,
+@a,@a,@a,@a,@a,@a,@a,
+@a,@a,@a,@a,@a,
+@a,@a,@a,@a,@a,@a,@a,
+@a,@a,@a,@a,@a,@a,@a,
+@a,@a,@a,@a,@a,@a,@a,
+@a,@a,@a,@a,@a,
+@a,@a,@a,@a,@a,@a,@a,
+@a,@a,@a,@a,@a,@a,@a,
+@a,@a,@a,@a,@a,@a,@a,
+@a,@a,@a,@a,@a,
+@a,@a,@a,@a,@a,@a,@a,
+@a,@a,@a,@a,@a,@a,@a,
+@a,@a,@a,@a,@a,@a,@a,
+@a,@a,@a,@a,@a
+);
+
+SET @h = repeat('h', 100);
+SET @i = repeat('i', 100);
+SET @j = repeat('j', 100);
+SET @k = repeat('k', 100);
+SET @l = repeat('l', 100);
+
+INSERT INTO t2 VALUES (@h,@h,@h,@h,@h,@h,@h,
+@h,@h,@h,@h,@h,@h,@h,
+@h,@h,@h,@h,@h,@h,@h,
+@h,@h,@h,@h,@h,
+@h,@h,@h,@h,@h,@h,@h,
+@h,@h,@h,@h,@h,@h,@h,
+@h,@h,@h,@h,@h,@h,@h,
+@h,@h,@h,@h,@h,
+@h,@h,@h,@h,@h,@h,@h,
+@h,@h,@h,@h,@h,@h,@h,
+@h,@h,@h,@h,@h,@h,@h,
+@h,@h,@h,@h,@h,
+@h,@h,@h,@h,@h,@h,@h,
+@h,@h,@h,@h,@h,@h,@h,
+@h,@h,@h,@h,@h,@h,@h,
+@h,@h,@h,@h,@h
+);
+
+UPDATE t1 SET a=@b,b=@b,c=@b,d=@b,e=@b,f=@b,g=@b,h=@b,i=@b,j=@b,
+ k=@b,l=@b,m=@b,n=@b,o=@b,p=@b,q=@b,r=@b,s=@b,t=@b,u=@b,
+ v=@b,w=@b,x=@b,y=@b,z=@b,
+ aa=@b,ba=@b,ca=@b,da=@b,ea=@b,fa=@b,ga=@b,ha=@b,ia=@b,ja=@b,
+ ka=@b,la=@b,ma=@b,na=@b,oa=@b,pa=@b,qa=@b,ra=@b,sa=@b,ta=@b,ua=@b,
+ va=@b,wa=@b,xa=@b,ya=@b,za=@b,
+ ab=@b,bb=@b,cb=@b,db=@b,eb=@b,fb=@b,gb=@b,hb=@b,ib=@b,jb=@b,
+ kb=@b,lb=@b,mb=@b,nb=@b,ob=@b,pb=@b,qb=@b,rb=@b,sb=@b,tb=@b,ub=@b,
+ vb=@b,wb=@b,xb=@b,yb=@b,zb=@b,
+ ab=@b,bb=@b,cb=@b,db=@b,eb=@b,fb=@b,gb=@b,hb=@b,ib=@b,jb=@b,
+ kb=@b,lb=@b,mb=@b,nb=@b,ob=@b,pb=@b,qb=@b,rb=@b,sb=@b,tb=@b,ub=@b,
+ vb=@b,wb=@b,xb=@b,yb=@b,zb=@b,
+ ac=@b,bc=@b,cc=@b,dc=@b,ec=@b,fc=@b,gc=@b,hc=@b,ic=@b,jc=@b,
+ kc=@b,lc=@b,mc=@b,nc=@b,oc=@b,pc=@b,qc=@b,rc=@b,sc=@b,tc=@b,uc=@b,
+ vc=@b,wc=@b,xc=@b,yc=@b,zc=@b;
+
+UPDATE t2 SET a=@i,b=@i,c=@i,d=@i,e=@i,f=@i,g=@i,h=@i,i=@i,j=@i,
+ k=@i,l=@i,m=@i,n=@i,o=@i,p=@i,q=@i,r=@i,s=@i,t=@i,u=@i,
+ v=@i,w=@i,x=@i,y=@i,z=@i,
+ aa=@i,ba=@i,ca=@i,da=@i,ea=@i,fa=@i,ga=@i,ha=@i,ia=@i,ja=@i,
+ ka=@i,la=@i,ma=@i,na=@i,oa=@i,pa=@i,qa=@i,ra=@i,sa=@i,ta=@i,ua=@i,
+ va=@i,wa=@i,xa=@i,ya=@i,za=@i,
+ ab=@i,bb=@i,cb=@i,db=@i,eb=@i,fb=@i,gb=@i,hb=@i,ib=@i,jb=@i,
+ kb=@i,lb=@i,mb=@i,nb=@i,ob=@i,pb=@i,qb=@i,rb=@i,sb=@i,tb=@i,ub=@i,
+ vb=@i,wb=@i,xb=@i,yb=@i,zb=@i,
+ ab=@i,bb=@i,cb=@i,db=@i,eb=@i,fb=@i,gb=@i,hb=@i,ib=@i,jb=@i,
+ kb=@i,lb=@i,mb=@i,nb=@i,ob=@i,pb=@i,qb=@i,rb=@i,sb=@i,tb=@i,ub=@i,
+ vb=@i,wb=@i,xb=@i,yb=@i,zb=@i,
+ ac=@i,bc=@i,cc=@i,dc=@i,ec=@i,fc=@i,gc=@i,hc=@i,ic=@i,jc=@i,
+ kc=@i,lc=@i,mc=@i,nc=@i,oc=@i,pc=@i,qc=@i,rc=@i,sc=@i,tc=@i,uc=@i,
+ vc=@i,wc=@i,xc=@i,yc=@i,zc=@i;
+
+# With this many indexes defined, we can still update all fields.
+CREATE INDEX t1a ON t1 (a(767),b(767));
+CREATE INDEX t1c ON t1 (c(767),d(767));
+CREATE INDEX t1e ON t1 (e(767),f(767));
+CREATE INDEX t1f2 ON t1 (g(767),h(767));
+CREATE INDEX t1f4 ON t1 (i(767),j(767));
+CREATE INDEX t1k ON t1 (k(767),m(767));
+CREATE INDEX t1f8 ON t1 (n(767),o(767));
+CREATE INDEX t1f11 ON t1 (p(767),q(767));
+CREATE INDEX t1f13 ON t1 (r(767),s(767));
+CREATE INDEX t1f15 ON t1 (t(767),u(767));
+CREATE INDEX t1f18 ON t1 (w(767),x(767));
+CREATE INDEX t1f20 ON t1 (y(767),z(767));
+CREATE INDEX ta1a6 ON t1 (aa(767),ba(767));
+CREATE INDEX tc1c6 ON t1 (ca(767),da(767));
+CREATE INDEX te1e6 ON t1 (ea(767),fa(767));
+
+
+CREATE INDEX t2a ON t2 (a(767),b(767));
+CREATE INDEX t2c ON t2 (c(767),d(767));
+CREATE INDEX t2e ON t2 (e(767),f(767));
+CREATE INDEX t2f2 ON t2 (g(767),h(767));
+CREATE INDEX t2f4 ON t2 (i(767),j(767));
+CREATE INDEX t2k ON t2 (k(767),m(767));
+CREATE INDEX t2f8 ON t2 (n(767),o(767));
+CREATE INDEX t2f11 ON t2 (p(767),q(767));
+CREATE INDEX t2f13 ON t2 (r(767),s(767));
+CREATE INDEX t2f15 ON t2 (t(767),u(767));
+CREATE INDEX t2f18 ON t2 (w(767),x(767));
+CREATE INDEX t2f20 ON t2 (y(767),z(767));
+CREATE INDEX ta2a6 ON t2 (aa(767),ba(767));
+CREATE INDEX tc2c6 ON t2 (ca(767),da(767));
+CREATE INDEX te2e6 ON t2 (ea(767),fa(767));
+
+UPDATE t1 SET a=@c,b=@c,c=@c,d=@c,e=@c,f=@c,g=@c,h=@c,i=@c,j=@c,
+ k=@c,l=@c,m=@c,n=@c,o=@c,p=@c,q=@c,r=@c,s=@c,t=@c,u=@c,
+ v=@c,w=@c,x=@c,y=@c,z=@c,
+ aa=@c,ba=@c,ca=@c,da=@c,ea=@c,fa=@c,ga=@c,ha=@c,ia=@c,ja=@c,
+ ka=@c,la=@c,ma=@c,na=@c,oa=@c,pa=@c,qa=@c,ra=@c,sa=@c,ta=@c,ua=@c,
+ va=@c,wa=@c,xa=@c,ya=@c,za=@c,
+ ab=@c,bb=@c,cb=@c,db=@c,eb=@c,fb=@c,gb=@c,hb=@c,ib=@c,jb=@c,
+ kb=@c,lb=@c,mb=@c,nb=@c,ob=@c,pb=@c,qb=@c,rb=@c,sb=@c,tb=@c,ub=@c,
+ vb=@c,wb=@c,xb=@c,yb=@c,zb=@c,
+ ac=@c,bc=@c,cc=@c,dc=@c,ec=@c,fc=@c,gc=@c,hc=@c,ic=@c,jc=@c,
+ kc=@c,lc=@c,mc=@c,nc=@c,oc=@c,pc=@c,qc=@c,rc=@c,sc=@c,tc=@c,uc=@c,
+ vc=@c,wc=@c,xc=@c,yc=@c,zc=@c;
+
+UPDATE t2 SET a=@k,b=@k,c=@k,d=@k,e=@k,f=@k,g=@k,h=@k,i=@k,j=@k,
+ k=@k,l=@k,m=@k,n=@k,o=@k,p=@k,q=@k,r=@k,s=@k,t=@k,u=@k,
+ v=@k,w=@k,x=@k,y=@k,z=@k,
+ aa=@k,ba=@k,ca=@k,da=@k,ea=@k,fa=@k,ga=@k,ha=@k,ia=@k,ja=@k,
+ ka=@k,la=@k,ma=@k,na=@k,oa=@k,pa=@k,qa=@k,ra=@k,sa=@k,ta=@k,ua=@k,
+ va=@k,wa=@k,xa=@k,ya=@k,za=@k,
+ ab=@k,bb=@k,cb=@k,db=@k,eb=@k,fb=@k,gb=@k,hb=@k,ib=@k,jb=@k,
+ kb=@k,lb=@k,mb=@k,nb=@k,ob=@k,pb=@k,qb=@k,rb=@k,sb=@k,tb=@k,ub=@k,
+ vb=@k,wb=@k,xb=@k,yb=@k,zb=@k,
+ ac=@k,bc=@k,cc=@k,dc=@k,ec=@k,fc=@k,gc=@k,hc=@k,ic=@k,jc=@k,
+ kc=@k,lc=@k,mc=@k,nc=@k,oc=@k,pc=@k,qc=@k,rc=@k,sc=@k,tc=@k,uc=@k,
+ vc=@k,wc=@k,xc=@k,yc=@k,zc=@k;
+
+COMMIT;
+
+BEGIN;
+UPDATE t1 SET a=@d,b=@d,c=@d,d=@d,e=@d;
+UPDATE t1 SET f=@d,g=@d,h=@d,i=@d,j=@d;
+UPDATE t1 SET k=@d,l=@d,m=@d,n=@d,o=@d;
+UPDATE t1 SET p=@d,q=@d,r=@d,s=@d,t=@d,u=@d;
+UPDATE t1 SET v=@d,w=@d,x=@d,y=@d,z=@d;
+UPDATE t1 SET aa=@d,ba=@d,ca=@d,da=@d;
+UPDATE t1 SET ea=@d,fa=@d,ga=@d,ha=@d,ia=@d,ja=@d;
+UPDATE t1 SET ka=@d,la=@d,ma=@d,na=@d,oa=@d,pa=@d;
+UPDATE t1 SET qa=@d,ra=@d,sa=@d,ta=@d,ua=@d;
+UPDATE t1 SET va=@d,wa=@d,xa=@d,ya=@d,za=@d;
+UPDATE t1 SET ab=@d,bb=@d,cb=@d,db=@d;
+UPDATE t1 SET eb=@d,fb=@d,gb=@d,hb=@d,ib=@d,ja=@d;
+UPDATE t1 SET kb=@d,lb=@d,mb=@d,nb=@d,ob=@d,pa=@d;
+UPDATE t1 SET qb=@d,rb=@d,sb=@d,tb=@d,ub=@d;
+UPDATE t1 SET vb=@d,wb=@d,xb=@d,yb=@d,zb=@d;
+UPDATE t1 SET ac=@d,bc=@d,cc=@d,dc=@d;
+UPDATE t1 SET ec=@d,fc=@d,gc=@d,hc=@d,ic=@d,jc=@d;
+UPDATE t1 SET kc=@d,lc=@d,mc=@d,nc=@d,oc=@d,pc=@d;
+UPDATE t1 SET qc=@d,rc=@d,sc=@d,tc=@d,uc=@d;
+UPDATE t1 SET vc=@d,wc=@d,xc=@d,yc=@d,zc=@d;
+COMMIT;
+
+BEGIN;
+UPDATE t2 SET a=@i,b=@i,c=@i,d=@i,e=@i;
+UPDATE t2 SET f=@i,g=@i,h=@i,i=@i,j=@i;
+UPDATE t2 SET k=@i,l=@i,m=@i,n=@i,o=@i;
+UPDATE t2 SET p=@i,q=@i,r=@i,s=@i,t=@i,u=@i;
+UPDATE t2 SET v=@i,w=@i,x=@i,y=@i,z=@i;
+UPDATE t2 SET aa=@i,ba=@i,ca=@i,da=@i;
+UPDATE t2 SET ea=@i,fa=@i,ga=@i,ha=@i,ia=@i,ja=@i;
+UPDATE t2 SET ka=@i,la=@i,ma=@i,na=@i,oa=@i,pa=@i;
+UPDATE t2 SET qa=@i,ra=@i,sa=@i,ta=@i,ua=@i;
+UPDATE t2 SET va=@i,wa=@i,xa=@i,ya=@i,za=@i;
+UPDATE t2 SET ab=@i,bb=@i,cb=@i,db=@i;
+UPDATE t2 SET eb=@i,fb=@i,gb=@i,hb=@i,ib=@i,ja=@i;
+UPDATE t2 SET kb=@i,lb=@i,mb=@i,nb=@i,ob=@i,pa=@i;
+UPDATE t2 SET qb=@i,rb=@i,sb=@i,tb=@i,ub=@i;
+UPDATE t2 SET vb=@i,wb=@i,xb=@i,yb=@i,zb=@i;
+UPDATE t2 SET ac=@i,bc=@i,cc=@i,dc=@i;
+UPDATE t2 SET ec=@i,fc=@i,gc=@i,hc=@i,ic=@i,jc=@i;
+UPDATE t2 SET kc=@i,lc=@i,mc=@i,nc=@i,oc=@i,pc=@i;
+UPDATE t2 SET qc=@i,rc=@i,sc=@i,tc=@i,uc=@i;
+UPDATE t2 SET vc=@i,wc=@i,xc=@i,yc=@i,zc=@i;
+COMMIT;
+
+
+BEGIN;
+UPDATE t1 SET a=@c,b=@c,c=@c,d=@c,e=@c,f=@c,g=@c,h=@c,i=@c,j=@c,
+ k=@c,l=@c,m=@c,n=@c,o=@c,p=@c,q=@c,r=@c,s=@c,t=@c,u=@c,
+ v=@c,w=@c,x=@c,y=@c,z=@c,
+ aa=@c,ba=@c,ca=@c,da=@c,ea=@c,fa=@c,ga=@c,ha=@c,ia=@c,ja=@c,
+ ka=@c,la=@c,ma=@c,na=@c,oa=@c,pa=@c,qa=@c,ra=@c,sa=@c,ta=@c,ua=@c,
+ va=@c,wa=@c,xa=@c,ya=@c,za=@c,
+ ab=@c,bb=@c,cb=@c,db=@c,eb=@c,fb=@c,gb=@c,hb=@c,ib=@c,jb=@c,
+ kb=@c,lb=@c,mb=@c,nb=@c,ob=@c,pb=@c,qb=@c,rb=@c,sb=@c,tb=@c,ub=@c,
+ vb=@c,wb=@c,xb=@c,yb=@c,zb=@c,
+ ac=@c,bc=@c,cc=@c,dc=@c,ec=@c,fc=@c,gc=@c,hc=@c,ic=@c,jc=@c,
+ kc=@c,lc=@c,mc=@c,nc=@c,oc=@c,pc=@c,qc=@c,rc=@c,sc=@c,tc=@c,uc=@c,
+ vc=@c,wc=@c,xc=@c,yc=@c,zc=@c;
+
+connect (con1,localhost,root,,);
+SET GLOBAL innodb_flush_log_at_trx_commit=1;
+DELETE FROM t2 LIMIT 1;
+disconnect con1;
+connection default;
+
+--let $shutdown_timeout=0
+--source include/restart_mysqld.inc
+--let $shutdown_timeout=
+
+check table t1,t2;
+drop table t1,t2;
diff --git a/mysql-test/suite/innodb/t/innodb-64k-master.opt b/mysql-test/suite/innodb/t/innodb-64k-master.opt
new file mode 100644
index 00000000..375b7fcd
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb-64k-master.opt
@@ -0,0 +1,4 @@
+--default_storage_engine=InnoDB
+--innodb-buffer-pool-size=32M
+--innodb-page-size=64K
+--innodb-log-file-size=32M
diff --git a/mysql-test/suite/innodb/t/innodb-64k.test b/mysql-test/suite/innodb/t/innodb-64k.test
new file mode 100644
index 00000000..972ba6bb
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb-64k.test
@@ -0,0 +1,652 @@
+--source include/no_valgrind_without_big.inc
+# Tests for setting innodb-page-size=64k;
+--source include/have_innodb.inc
+--source include/have_innodb_64k.inc
+--source include/have_sequence.inc
+
+call mtr.add_suppression('InnoDB: Cannot add field.*because after adding it, the row size is');
+
+let $MYSQLD_DATADIR= `select @@datadir`;
+
+--echo # Test 1) Show the page size from Information Schema
+SELECT variable_value FROM information_schema.global_status
+ WHERE LOWER(variable_name) = 'innodb_page_size';
+
+--echo # Test 4) The maximum row size is dependent upon the page size.
+
+SET SESSION innodb_strict_mode = ON;
+SELECT @@innodb_strict_mode;
+
+# Redundant table
+--error ER_TOO_BIG_ROWSIZE
+CREATE TABLE tab5(col1 CHAR (255), col2 CHAR (255), col3 CHAR(255),col4 CHAR(255), col5 CHAR(255),
+col6 CHAR(255), col7 CHAR(255), col8 CHAR(255), col9 CHAR(255),col10 CHAR(255), col11 CHAR(255),
+col12 CHAR(255), col13 CHAR(255),col14 CHAR(255),col15 CHAR(255),col16 CHAR(255), col17 CHAR(255),
+col18 CHAR(255),col19 CHAR(255),col20 CHAR(255),col21 CHAR(255),col22 CHAR(255), col23 CHAR(255),
+col24 CHAR(255),col25 CHAR(255),col26 CHAR(255),col27 CHAR(255),col28 CHAR(255), col29 CHAR(255),
+col30 CHAR(255),col31 CHAR(255),col32 CHAR(255),col33 CHAR(255),col34 CHAR(255), col35 CHAR(255),
+col36 CHAR(255),col37 CHAR(255),col38 CHAR(255),col39 CHAR(255),col40 CHAR(255), col41 CHAR(255),
+col42 CHAR(255),col43 CHAR(255),col44 CHAR(255),col45 CHAR(255),col46 CHAR(255), col47 CHAR(255),
+col48 CHAR(255),col49 CHAR(255),col50 CHAR(255),col51 CHAR(255),col52 CHAR(255), col53 CHAR(255),
+col54 CHAR(255),col55 CHAR(255),col56 CHAR(255),col57 CHAR(255),col58 CHAR(255), col59 CHAR(255),
+col60 CHAR(255),col61 CHAR(255),col62 CHAR(255),col63 CHAR(255),col64 CHAR(255), col65 CHAR(255))
+ENGINE = innodb ROW_FORMAT=REDUNDANT;
+show warnings;
+
+# Compact table, 32701 bytes
+
+CREATE TABLE t1 (
+c01 char(200), c02 char(200), c03 char(200), c04 char(200), c05 char(200),
+c06 char(200), c07 char(200), c08 char(200), c09 char(200), c10 char(200),
+c11 char(200), c12 char(200), c13 char(200), c14 char(200), c15 char(200),
+c16 char(200), c17 char(200), c18 char(200), c19 char(200), c20 char(200),
+c21 char(200), c22 char(200), c23 char(200), c24 char(200), c25 char(200),
+c26 char(200), c27 char(200), c28 char(200), c29 char(200), c30 char(200),
+c31 char(200), c32 char(200), c33 char(200), c34 char(200), c35 char(200),
+c36 char(200), c37 char(200), c38 char(200), c39 char(200), c40 char(200),
+c41 char(200), c42 char(200), c43 char(200), c44 char(200), c45 char(200),
+c46 char(200), c47 char(200), c48 char(200), c49 char(200), c50 char(200),
+c51 char(200), c52 char(200), c53 char(200), c54 char(200), c55 char(200),
+c56 char(200), c57 char(200), c58 char(200), c59 char(200), c60 char(200),
+c61 char(200), c62 char(200), c63 char(200), c64 char(200), c65 char(200),
+c66 char(200), c67 char(200), c68 char(200), c69 char(200), c70 char(200),
+c71 char(200), c72 char(200), c73 char(200), c74 char(200), c75 char(200),
+c76 char(200), c77 char(200), c78 char(200), c79 char(200), c80 char(200),
+c101 char(200), c102 char(200), c103 char(200), c104 char(200), c105 char(200),
+c106 char(200), c107 char(200), c108 char(200), c109 char(200), c110 char(200),
+c111 char(200), c112 char(200), c113 char(200), c114 char(200), c115 char(200),
+c116 char(200), c117 char(200), c118 char(200), c119 char(200), c120 char(200),
+c121 char(200), c122 char(200), c123 char(200), c124 char(200), c125 char(200),
+c126 char(200), c127 char(200), c128 char(200), c129 char(200), c130 char(200),
+c131 char(200), c132 char(200), c133 char(200), c134 char(200), c135 char(200),
+c136 char(200), c137 char(200), c138 char(200), c139 char(200), c140 char(200),
+c141 char(200), c142 char(200), c143 char(200), c144 char(200), c145 char(200),
+c146 char(200), c147 char(200), c148 char(200), c149 char(200), c150 char(200),
+c151 char(200), c152 char(200), c153 char(200), c154 char(200), c155 char(200),
+c156 char(200), c157 char(200), c158 char(200), c159 char(200), c160 char(200),
+c161 char(200), c162 char(200), c163 char(200), c164 char(200), c165 char(200),
+c166 char(200), c167 char(200), c168 char(200), c169 char(200), c170 char(200),
+c171 char(200), c172 char(200), c173 char(200), c174 char(200), c175 char(200),
+c176 char(200), c177 char(200), c178 char(200), c179 char(200), c180 char(200),
+c190 char(200), c191 char(200), c192 char(100),
+c81 char(156)
+) ROW_FORMAT=compact;
+
+DROP TABLE t1;
+
+--replace_regex /> [0-9]*/> max_row_size/
+--error ER_TOO_BIG_ROWSIZE
+CREATE TABLE t1 (
+c01 char(200), c02 char(200), c03 char(200), c04 char(200), c05 char(200),
+c06 char(200), c07 char(200), c08 char(200), c09 char(200), c10 char(200),
+c11 char(200), c12 char(200), c13 char(200), c14 char(200), c15 char(200),
+c16 char(200), c17 char(200), c18 char(200), c19 char(200), c20 char(200),
+c21 char(200), c22 char(200), c23 char(200), c24 char(200), c25 char(200),
+c26 char(200), c27 char(200), c28 char(200), c29 char(200), c30 char(200),
+c31 char(200), c32 char(200), c33 char(200), c34 char(200), c35 char(200),
+c36 char(200), c37 char(200), c38 char(200), c39 char(200), c40 char(200),
+c41 char(200), c42 char(200), c43 char(200), c44 char(200), c45 char(200),
+c46 char(200), c47 char(200), c48 char(200), c49 char(200), c50 char(200),
+c51 char(200), c52 char(200), c53 char(200), c54 char(200), c55 char(200),
+c56 char(200), c57 char(200), c58 char(200), c59 char(200), c60 char(200),
+c61 char(200), c62 char(200), c63 char(200), c64 char(200), c65 char(200),
+c66 char(200), c67 char(200), c68 char(200), c69 char(200), c70 char(200),
+c71 char(200), c72 char(200), c73 char(200), c74 char(200), c75 char(200),
+c76 char(200), c77 char(200), c78 char(200), c79 char(200), c80 char(200),
+c101 char(200), c102 char(200), c103 char(200), c104 char(200), c105 char(200),
+c106 char(200), c107 char(200), c108 char(200), c109 char(200), c110 char(200),
+c111 char(200), c112 char(200), c113 char(200), c114 char(200), c115 char(200),
+c116 char(200), c117 char(200), c118 char(200), c119 char(200), c120 char(200),
+c121 char(200), c122 char(200), c123 char(200), c124 char(200), c125 char(200),
+c126 char(200), c127 char(200), c128 char(200), c129 char(200), c130 char(200),
+c131 char(200), c132 char(200), c133 char(200), c134 char(200), c135 char(200),
+c136 char(200), c137 char(200), c138 char(200), c139 char(200), c140 char(200),
+c141 char(200), c142 char(200), c143 char(200), c144 char(200), c145 char(200),
+c146 char(200), c147 char(200), c148 char(200), c149 char(200), c150 char(200),
+c151 char(200), c152 char(200), c153 char(200), c154 char(200), c155 char(200),
+c156 char(200), c157 char(200), c158 char(200), c159 char(200), c160 char(200),
+c161 char(200), c162 char(200), c163 char(200), c164 char(200), c165 char(200),
+c166 char(200), c167 char(200), c168 char(200), c169 char(200), c170 char(200),
+c171 char(200), c172 char(200), c173 char(200), c174 char(200), c175 char(200),
+c176 char(200), c177 char(200), c178 char(200), c179 char(200), c180 char(200),
+c190 char(200), c191 char(200), c192 char(100),
+c81 char(157)
+) ROW_FORMAT=compact;
+
+# Dynamic table, 32701 bytes
+
+CREATE TABLE t1 (
+c01 char(200), c02 char(200), c03 char(200), c04 char(200), c05 char(200),
+c06 char(200), c07 char(200), c08 char(200), c09 char(200), c10 char(200),
+c11 char(200), c12 char(200), c13 char(200), c14 char(200), c15 char(200),
+c16 char(200), c17 char(200), c18 char(200), c19 char(200), c20 char(200),
+c21 char(200), c22 char(200), c23 char(200), c24 char(200), c25 char(200),
+c26 char(200), c27 char(200), c28 char(200), c29 char(200), c30 char(200),
+c31 char(200), c32 char(200), c33 char(200), c34 char(200), c35 char(200),
+c36 char(200), c37 char(200), c38 char(200), c39 char(200), c40 char(200),
+c41 char(200), c42 char(200), c43 char(200), c44 char(200), c45 char(200),
+c46 char(200), c47 char(200), c48 char(200), c49 char(200), c50 char(200),
+c51 char(200), c52 char(200), c53 char(200), c54 char(200), c55 char(200),
+c56 char(200), c57 char(200), c58 char(200), c59 char(200), c60 char(200),
+c61 char(200), c62 char(200), c63 char(200), c64 char(200), c65 char(200),
+c66 char(200), c67 char(200), c68 char(200), c69 char(200), c70 char(200),
+c71 char(200), c72 char(200), c73 char(200), c74 char(200), c75 char(200),
+c76 char(200), c77 char(200), c78 char(200), c79 char(200), c80 char(200),
+c101 char(200), c102 char(200), c103 char(200), c104 char(200), c105 char(200),
+c106 char(200), c107 char(200), c108 char(200), c109 char(200), c110 char(200),
+c111 char(200), c112 char(200), c113 char(200), c114 char(200), c115 char(200),
+c116 char(200), c117 char(200), c118 char(200), c119 char(200), c120 char(200),
+c121 char(200), c122 char(200), c123 char(200), c124 char(200), c125 char(200),
+c126 char(200), c127 char(200), c128 char(200), c129 char(200), c130 char(200),
+c131 char(200), c132 char(200), c133 char(200), c134 char(200), c135 char(200),
+c136 char(200), c137 char(200), c138 char(200), c139 char(200), c140 char(200),
+c141 char(200), c142 char(200), c143 char(200), c144 char(200), c145 char(200),
+c146 char(200), c147 char(200), c148 char(200), c149 char(200), c150 char(200),
+c151 char(200), c152 char(200), c153 char(200), c154 char(200), c155 char(200),
+c156 char(200), c157 char(200), c158 char(200), c159 char(200), c160 char(200),
+c161 char(200), c162 char(200), c163 char(200), c164 char(200), c165 char(200),
+c166 char(200), c167 char(200), c168 char(200), c169 char(200), c170 char(200),
+c171 char(200), c172 char(200), c173 char(200), c174 char(200), c175 char(200),
+c176 char(200), c177 char(200), c178 char(200), c179 char(200), c180 char(200),
+c190 char(200), c191 char(200), c192 char(100),
+c81 char(156)
+) ROW_FORMAT=dynamic;
+
+DROP TABLE t1;
+
+--replace_regex /> [0-9]*/> max_row_size/
+--error ER_TOO_BIG_ROWSIZE
+CREATE TABLE t1 (
+c01 char(200), c02 char(200), c03 char(200), c04 char(200), c05 char(200),
+c06 char(200), c07 char(200), c08 char(200), c09 char(200), c10 char(200),
+c11 char(200), c12 char(200), c13 char(200), c14 char(200), c15 char(200),
+c16 char(200), c17 char(200), c18 char(200), c19 char(200), c20 char(200),
+c21 char(200), c22 char(200), c23 char(200), c24 char(200), c25 char(200),
+c26 char(200), c27 char(200), c28 char(200), c29 char(200), c30 char(200),
+c31 char(200), c32 char(200), c33 char(200), c34 char(200), c35 char(200),
+c36 char(200), c37 char(200), c38 char(200), c39 char(200), c40 char(200),
+c41 char(200), c42 char(200), c43 char(200), c44 char(200), c45 char(200),
+c46 char(200), c47 char(200), c48 char(200), c49 char(200), c50 char(200),
+c51 char(200), c52 char(200), c53 char(200), c54 char(200), c55 char(200),
+c56 char(200), c57 char(200), c58 char(200), c59 char(200), c60 char(200),
+c61 char(200), c62 char(200), c63 char(200), c64 char(200), c65 char(200),
+c66 char(200), c67 char(200), c68 char(200), c69 char(200), c70 char(200),
+c71 char(200), c72 char(200), c73 char(200), c74 char(200), c75 char(200),
+c76 char(200), c77 char(200), c78 char(200), c79 char(200), c80 char(200),
+c101 char(200), c102 char(200), c103 char(200), c104 char(200), c105 char(200),
+c106 char(200), c107 char(200), c108 char(200), c109 char(200), c110 char(200),
+c111 char(200), c112 char(200), c113 char(200), c114 char(200), c115 char(200),
+c116 char(200), c117 char(200), c118 char(200), c119 char(200), c120 char(200),
+c121 char(200), c122 char(200), c123 char(200), c124 char(200), c125 char(200),
+c126 char(200), c127 char(200), c128 char(200), c129 char(200), c130 char(200),
+c131 char(200), c132 char(200), c133 char(200), c134 char(200), c135 char(200),
+c136 char(200), c137 char(200), c138 char(200), c139 char(200), c140 char(200),
+c141 char(200), c142 char(200), c143 char(200), c144 char(200), c145 char(200),
+c146 char(200), c147 char(200), c148 char(200), c149 char(200), c150 char(200),
+c151 char(200), c152 char(200), c153 char(200), c154 char(200), c155 char(200),
+c156 char(200), c157 char(200), c158 char(200), c159 char(200), c160 char(200),
+c161 char(200), c162 char(200), c163 char(200), c164 char(200), c165 char(200),
+c166 char(200), c167 char(200), c168 char(200), c169 char(200), c170 char(200),
+c171 char(200), c172 char(200), c173 char(200), c174 char(200), c175 char(200),
+c176 char(200), c177 char(200), c178 char(200), c179 char(200), c180 char(200),
+c190 char(200), c191 char(200), c192 char(100),
+c81 char(157)
+) ROW_FORMAT=dynamic;
+
+--echo # Test 8) Test creating a table that could lead to undo log overflow.
+
+CREATE TABLE t1(a blob,b blob,c blob,d blob,e blob,f blob,g blob,
+ h blob,i blob,j blob,k blob,l blob,m blob,n blob,
+ o blob,p blob,q blob,r blob,s blob,t blob,u blob,
+ v blob, w blob, x blob, y blob, z blob,
+ aa blob,ba blob,ca blob,da blob,ea blob,fa blob,ga blob,
+ ha blob,ia blob,ja blob,ka blob,la blob,ma blob,na blob,
+ oa blob,pa blob,qa blob,ra blob,sa blob,ta blob,ua blob,
+ va blob, wa blob, xa blob, ya blob, za blob,
+ ab blob,bb blob,cb blob,db blob,eb blob,fb blob,gb blob,
+ hb blob,ib blob,jb blob,kb blob,lb blob,mb blob,nb blob,
+ ob blob,pb blob,qb blob,rb blob,sb blob,tb blob,ub blob,
+ vb blob, wb blob, xb blob, yb blob, zb blob,
+ ac blob, bc blob, cc blob, dc blob, ec blob,fc blob,gc blob,
+ hc blob, ic blob, jc blob, kc blob, lc blob,mc blob,nc blob,
+ oc blob, pc blob, qc blob, rc blob, sc blob,tc blob,uc blob,
+ vc blob, wc blob, xc blob, yc blob, zc blob
+ ) ENGINE=InnoDB ROW_FORMAT=dynamic;
+
+SET @a = repeat('a', 767);
+SET @b = repeat('b', 767);
+SET @c = repeat('c', 767);
+SET @d = repeat('d', 767);
+SET @e = repeat('e', 767);
+
+# With no indexes defined, we can update all columns to max key part length.
+
+INSERT INTO t1 VALUES (@a,@a,@a,@a,@a,@a,@a,
+@a,@a,@a,@a,@a,@a,@a,
+@a,@a,@a,@a,@a,@a,@a,
+@a,@a,@a,@a,@a,
+@a,@a,@a,@a,@a,@a,@a,
+@a,@a,@a,@a,@a,@a,@a,
+@a,@a,@a,@a,@a,@a,@a,
+@a,@a,@a,@a,@a,
+@a,@a,@a,@a,@a,@a,@a,
+@a,@a,@a,@a,@a,@a,@a,
+@a,@a,@a,@a,@a,@a,@a,
+@a,@a,@a,@a,@a,
+@a,@a,@a,@a,@a,@a,@a,
+@a,@a,@a,@a,@a,@a,@a,
+@a,@a,@a,@a,@a,@a,@a,
+@a,@a,@a,@a,@a
+);
+
+UPDATE t1 SET a=@b,b=@b,c=@b,d=@b,e=@b,f=@b,g=@b,h=@b,i=@b,j=@b,
+ k=@b,l=@b,m=@b,n=@b,o=@b,p=@b,q=@b,r=@b,s=@b,t=@b,u=@b,
+ v=@b,w=@b,x=@b,y=@b,z=@b,
+ aa=@b,ba=@b,ca=@b,da=@b,ea=@b,fa=@b,ga=@b,ha=@b,ia=@b,ja=@b,
+ ka=@b,la=@b,ma=@b,na=@b,oa=@b,pa=@b,qa=@b,ra=@b,sa=@b,ta=@b,ua=@b,
+ va=@b,wa=@b,xa=@b,ya=@b,za=@b,
+ ab=@b,bb=@b,cb=@b,db=@b,eb=@b,fb=@b,gb=@b,hb=@b,ib=@b,jb=@b,
+ kb=@b,lb=@b,mb=@b,nb=@b,ob=@b,pb=@b,qb=@b,rb=@b,sb=@b,tb=@b,ub=@b,
+ vb=@b,wb=@b,xb=@b,yb=@b,zb=@b,
+ ab=@b,bb=@b,cb=@b,db=@b,eb=@b,fb=@b,gb=@b,hb=@b,ib=@b,jb=@b,
+ kb=@b,lb=@b,mb=@b,nb=@b,ob=@b,pb=@b,qb=@b,rb=@b,sb=@b,tb=@b,ub=@b,
+ vb=@b,wb=@b,xb=@b,yb=@b,zb=@b,
+ ac=@b,bc=@b,cc=@b,dc=@b,ec=@b,fc=@b,gc=@b,hc=@b,ic=@b,jc=@b,
+ kc=@b,lc=@b,mc=@b,nc=@b,oc=@b,pc=@b,qc=@b,rc=@b,sc=@b,tc=@b,uc=@b,
+ vc=@b,wc=@b,xc=@b,yc=@b,zc=@b;
+
+# With this many indexes defined, we can still update all fields.
+CREATE INDEX t1a ON t1 (a(767),b(767));
+CREATE INDEX t1c ON t1 (c(767),d(767));
+CREATE INDEX t1e ON t1 (e(767),f(767));
+CREATE INDEX t1f2 ON t1 (g(767),h(767));
+CREATE INDEX t1f4 ON t1 (i(767),j(767));
+CREATE INDEX t1k ON t1 (k(767),m(767));
+CREATE INDEX t1f8 ON t1 (n(767),o(767));
+CREATE INDEX t1f11 ON t1 (p(767),q(767));
+CREATE INDEX t1f13 ON t1 (r(767),s(767));
+CREATE INDEX t1f15 ON t1 (t(767),u(767));
+CREATE INDEX t1f18 ON t1 (w(767),x(767));
+CREATE INDEX t1f20 ON t1 (y(767),z(767));
+CREATE INDEX ta1a6 ON t1 (aa(767),ba(767));
+CREATE INDEX tc1c6 ON t1 (ca(767),da(767));
+CREATE INDEX te1e6 ON t1 (ea(767),fa(767));
+
+UPDATE t1 SET a=@c,b=@c,c=@c,d=@c,e=@c,f=@c,g=@c,h=@c,i=@c,j=@c,
+ k=@c,l=@c,m=@c,n=@c,o=@c,p=@c,q=@c,r=@c,s=@c,t=@c,u=@c,
+ v=@c,w=@c,x=@c,y=@c,z=@c,
+ aa=@c,ba=@c,ca=@c,da=@c,ea=@c,fa=@c,ga=@c,ha=@c,ia=@c,ja=@c,
+ ka=@c,la=@c,ma=@c,na=@c,oa=@c,pa=@c,qa=@c,ra=@c,sa=@c,ta=@c,ua=@c,
+ va=@c,wa=@c,xa=@c,ya=@c,za=@c,
+ ab=@c,bb=@c,cb=@c,db=@c,eb=@c,fb=@c,gb=@c,hb=@c,ib=@c,jb=@c,
+ kb=@c,lb=@c,mb=@c,nb=@c,ob=@c,pb=@c,qb=@c,rb=@c,sb=@c,tb=@c,ub=@c,
+ vb=@c,wb=@c,xb=@c,yb=@c,zb=@c,
+ ac=@c,bc=@c,cc=@c,dc=@c,ec=@c,fc=@c,gc=@c,hc=@c,ic=@c,jc=@c,
+ kc=@c,lc=@c,mc=@c,nc=@c,oc=@c,pc=@c,qc=@c,rc=@c,sc=@c,tc=@c,uc=@c,
+ vc=@c,wc=@c,xc=@c,yc=@c,zc=@c;
+
+COMMIT;
+
+# Add one more index and the UNDO record becomes too big to update all columns.
+# But a single transaction can update the columns in separate statements.
+# because the UNDO records will be smaller.
+
+CREATE INDEX tg1f2 ON t1 (ia(767),ja(767));
+
+BEGIN;
+UPDATE t1 SET a=@d,b=@d,c=@d,d=@d,e=@d,f=@d,g=@d,h=@d,i=@d,j=@d,
+ k=@d,l=@d,m=@d,n=@d,o=@d,p=@d,q=@d,r=@d,s=@d,t=@d,u=@d,
+ v=@d,w=@d,x=@d,y=@d,z=@d,
+ aa=@d,ba=@d,ca=@d,da=@d,ea=@d,fa=@d,ga=@d,ha=@d,ia=@d,ja=@d,
+ ka=@d,la=@d,ma=@d,na=@d,oa=@d,pa=@d,qa=@d,ra=@d,sa=@d,ta=@d,ua=@d,
+ va=@d,wa=@d,xa=@d,ya=@d,za=@d,
+ ab=@d,bb=@d,cb=@d,db=@d,eb=@d,fb=@d,gb=@d,hb=@d,ib=@d,jb=@d,
+ kb=@d,lb=@d,mb=@d,nb=@d,ob=@d,pb=@d,qb=@d,rb=@d,sb=@d,tb=@d,ub=@d,
+ vb=@d,wb=@d,xb=@d,yb=@d,zb=@d,
+ ac=@d,bc=@d,cc=@d,dc=@d,ec=@d,fc=@d,gc=@d,hc=@d,ic=@d,jc=@d,
+ kc=@d,lc=@d,mc=@d,nc=@d,oc=@d,pc=@d,qc=@d,rc=@d,sc=@d,tc=@d,uc=@d,
+ vc=@d,wc=@d,xc=@d,yc=@d,zc=@d;
+ROLLBACK;
+
+BEGIN;
+UPDATE t1 SET a=@d,b=@d,c=@d,d=@d,e=@d;
+UPDATE t1 SET f=@d,g=@d,h=@d,i=@d,j=@d;
+UPDATE t1 SET k=@d,l=@d,m=@d,n=@d,o=@d;
+UPDATE t1 SET p=@d,q=@d,r=@d,s=@d,t=@d,u=@d;
+UPDATE t1 SET v=@d,w=@d,x=@d,y=@d,z=@d;
+UPDATE t1 SET aa=@d,ba=@d,ca=@d,da=@d;
+UPDATE t1 SET ea=@d,fa=@d,ga=@d,ha=@d,ia=@d,ja=@d;
+UPDATE t1 SET ka=@d,la=@d,ma=@d,na=@d,oa=@d,pa=@d;
+UPDATE t1 SET qa=@d,ra=@d,sa=@d,ta=@d,ua=@d;
+UPDATE t1 SET va=@d,wa=@d,xa=@d,ya=@d,za=@d;
+UPDATE t1 SET ab=@d,bb=@d,cb=@d,db=@d;
+UPDATE t1 SET eb=@d,fb=@d,gb=@d,hb=@d,ib=@d,ja=@d;
+UPDATE t1 SET kb=@d,lb=@d,mb=@d,nb=@d,ob=@d,pa=@d;
+UPDATE t1 SET qb=@d,rb=@d,sb=@d,tb=@d,ub=@d;
+UPDATE t1 SET vb=@d,wb=@d,xb=@d,yb=@d,zb=@d;
+UPDATE t1 SET ac=@d,bc=@d,cc=@d,dc=@d;
+UPDATE t1 SET ec=@d,fc=@d,gc=@d,hc=@d,ic=@d,jc=@d;
+UPDATE t1 SET kc=@d,lc=@d,mc=@d,nc=@d,oc=@d,pc=@d;
+UPDATE t1 SET qc=@d,rc=@d,sc=@d,tc=@d,uc=@d;
+UPDATE t1 SET vc=@d,wc=@d,xc=@d,yc=@d,zc=@d;
+COMMIT;
+
+# More indexes can still be added and a single field can still be updated
+CREATE INDEX ti1f4 ON t1 (ia(767),ka(767));
+CREATE INDEX tk1f6 ON t1 (la(767),ma(767));
+CREATE INDEX tm1f8 ON t1 (na(767),oa(767));
+CREATE INDEX to1f11 ON t1 (pa(767),qa(767));
+CREATE INDEX tq1f13 ON t1 (ra(767),sa(767));
+CREATE INDEX ts1f15 ON t1 (ta(767),ua(767));
+CREATE INDEX tu1f18 ON t1 (wa(767),xa(767));
+CREATE INDEX tx1f20 ON t1 (ya(767),za(767));
+CREATE INDEX ta1a5 ON t1 (ab(767),bb(767));
+CREATE INDEX tc1c5 ON t1 (cb(767),db(767));
+CREATE INDEX te1e5 ON t1 (eb(767),fb(767));
+CREATE INDEX t5g1f2 ON t1 (gb(767),hb(767));
+CREATE INDEX t5i1f4 ON t1 (ib(767),kb(767));
+CREATE INDEX t5k1f6 ON t1 (lb(767),mb(767));
+CREATE INDEX t5m1f8 ON t1 (nb(767),ob(767));
+CREATE INDEX t5o1f11 ON t1 (pb(767),qb(767));
+CREATE INDEX t65q1f13 ON t1 (rb(767),sb(767));
+CREATE INDEX t65s1f15 ON t1 (tb(767),ub(767));
+CREATE INDEX t65u1f18 ON t1 (wb(767),xb(767));
+CREATE INDEX t65x1f20 ON t1 (yb(767),zb(767));
+CREATE INDEX xta1a5 ON t1 (ac(767),bc(767));
+CREATE INDEX xt5g1f2 ON t1 (gc(767),hc(767));
+CREATE INDEX xt5i1f4 ON t1 (ic(767));
+CREATE INDEX xtc1c5 ON t1 (cc(767),dc(767));
+CREATE INDEX xte1e5 ON t1 (ec(767),fc(767));
+UPDATE t1 SET t=@e;
+
+# One more index and row size is too big (not any more!)
+#--replace_regex /> [0-9]*/> max_row_size/
+#--error ER_TOO_BIG_ROWSIZE
+CREATE INDEX xt5k1f6 ON t1 (lc(767),mc(767));
+SHOW CREATE TABLE t1;
+SHOW WARNINGS;
+
+CREATE TABLE t2(COL1 TEXT,
+COL2 TEXT,
+COL3 TEXT,
+COL4 TEXT,
+COL5 TEXT,
+COL6 TEXT,
+COL7 TEXT,
+COL8 TEXT,
+COL9 TEXT,
+COL10 TEXT,
+COL11 TEXT,
+COL12 TEXT,
+COL13 TEXT,
+COL14 TEXT,
+COL15 TEXT,
+COL16 TEXT,
+COL17 TEXT,
+COL18 TEXT,
+COL19 TEXT,
+COL20 TEXT,
+COL21 TEXT,
+COL22 TEXT,
+COL23 TEXT,
+COL24 TEXT,
+COL25 TEXT,
+COL26 TEXT,
+COL27 TEXT,
+COL28 TEXT,
+COL29 TEXT,
+COL30 TEXT,
+COL31 TEXT,
+COL32 TEXT,
+COL33 TEXT,
+COL34 TEXT,
+COL35 TEXT,
+COL36 TEXT,
+COL37 TEXT,
+COL38 TEXT,
+COL39 TEXT,
+COL40 TEXT,
+COL41 TEXT,
+COL42 TEXT,
+COL43 TEXT,
+COL44 TEXT,
+COL45 TEXT,
+COL46 TEXT,
+COL47 TEXT,
+COL48 TEXT,
+COL49 TEXT,
+COL50 TEXT,
+COL51 TEXT,
+COL52 TEXT,
+COL53 TEXT,
+COL54 TEXT,
+COL55 TEXT,
+COL56 TEXT,
+COL57 TEXT,
+COL58 TEXT,
+COL59 TEXT,
+COL60 TEXT,
+COL61 TEXT,
+COL62 TEXT,
+COL63 TEXT,
+COL64 TEXT,
+COL65 TEXT,
+COL66 TEXT,
+COL67 TEXT,
+COL68 TEXT,
+COL69 TEXT,
+COL70 TEXT,
+COL71 TEXT,
+COL72 TEXT,
+COL73 TEXT,
+COL74 TEXT,
+COL75 TEXT,
+COL76 TEXT,
+COL77 TEXT,
+COL78 TEXT,
+COL79 TEXT,
+COL80 TEXT,
+COL81 TEXT,
+COL82 TEXT,
+COL83 TEXT,
+COL84 TEXT,
+COL85 TEXT,
+COL86 TEXT,
+COL87 TEXT,
+COL88 TEXT,
+COL89 TEXT,
+COL90 TEXT,
+COL91 TEXT,
+COL92 TEXT,
+COL93 TEXT,
+COL94 TEXT,
+COL95 TEXT,
+COL96 TEXT,
+COL97 TEXT,
+COL98 TEXT,
+COL99 TEXT,
+COL100 TEXT,
+COL101 TEXT,
+COL102 TEXT,
+COL103 TEXT,
+COL104 TEXT,
+COL105 TEXT,
+COL106 TEXT,
+COL107 TEXT,
+COL108 TEXT,
+COL109 TEXT,
+COL110 TEXT,
+COL111 TEXT,
+COL112 TEXT,
+COL113 TEXT,
+COL114 TEXT,
+COL115 TEXT,
+COL116 TEXT,
+COL117 TEXT,
+COL118 TEXT,
+COL119 TEXT,
+COL120 TEXT,
+COL121 TEXT,
+COL122 TEXT,
+COL123 TEXT,
+COL124 TEXT,
+COL125 TEXT,
+COL126 TEXT,
+COL127 TEXT,
+COL128 TEXT,
+COL129 TEXT,
+COL130 TEXT,
+COL131 TEXT,
+COL132 TEXT,
+COL133 TEXT,
+COL134 TEXT,
+COL135 TEXT,
+COL136 TEXT,
+COL137 TEXT,
+COL138 TEXT,
+COL139 TEXT,
+COL140 TEXT,
+COL141 TEXT,
+COL142 TEXT,
+COL143 TEXT,
+COL144 TEXT,
+COL145 TEXT,
+COL146 TEXT,
+COL147 TEXT,
+COL148 TEXT,
+COL149 TEXT,
+COL150 TEXT,
+COL151 TEXT,
+COL152 TEXT,
+COL153 TEXT,
+COL154 TEXT,
+COL155 TEXT,
+COL156 TEXT,
+COL157 TEXT,
+COL158 TEXT,
+COL159 TEXT,
+COL160 TEXT,
+COL161 TEXT,
+COL162 TEXT,
+COL163 TEXT,
+COL164 TEXT,
+COL165 TEXT,
+COL166 TEXT,
+COL167 TEXT,
+COL168 TEXT,
+COL169 TEXT,
+COL170 TEXT,
+COL171 TEXT,
+COL172 TEXT,
+COL173 TEXT,
+COL174 TEXT,
+COL175 TEXT,
+COL176 TEXT,
+COL177 TEXT,
+COL178 TEXT,
+COL179 TEXT,
+COL180 TEXT,
+COL181 TEXT,
+COL182 TEXT,
+COL183 TEXT,
+COL184 TEXT,
+COL185 TEXT,
+COL186 TEXT,
+COL187 TEXT,
+COL188 TEXT,
+COL189 TEXT,
+COL190 TEXT,
+COL191 TEXT,
+COL192 TEXT,
+COL193 TEXT,
+COL194 TEXT,
+COL195 TEXT,
+COL196 TEXT,
+COL197 TEXT)
+row_format=dynamic,ENGINE=INNODB;
+
+set @a = repeat('0123456789', 800);
+set @b = repeat('9876543210', 800);
+
+insert into t2 values(
+@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,
+@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,
+@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,
+@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,
+@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,
+@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,
+@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,
+@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,
+@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,
+@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,
+@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,
+@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,
+@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,
+@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,
+@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,
+@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,
+@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,
+@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,
+@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,
+@a,@a,@a,@a,@a,@a,@a);
+
+update t2 set col190=@b;
+
+set @a = repeat('0123456789', 1650);
+set @b = repeat('9876543210', 2000);
+
+insert into t2 values(
+@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,
+@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,
+@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,
+@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,
+@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,
+@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,
+@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,
+@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,
+@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,
+@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,
+@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,
+@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,
+@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,
+@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,
+@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,
+@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,
+@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,
+@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,
+@a,@a,@a,@a,@a,@a,@a,@a,@a,@a,
+@a,@a,@a,@a,@a,@a,@a);
+
+update t2 set col190=@b;
+
+#
+# Verify persistence and loading of flags in the ibd files.
+#
+
+--source include/restart_mysqld.inc
+
+set @a = repeat('abcdefghijklmnopqrstuvwxyz', 1650);
+set @b = repeat('zyxwvutsrqponmlkjihgfedcba', 2000);
+update t2 set col189 = @b;
+insert into t2 select * from t2;
+show create table t1;
+show create table t2;
+
+BEGIN;
+update t2 set col150=@a;
+update t2 set col145=@b;
+COMMIT;
+
+drop table t2;
+DROP TABLE t1;
+
+--echo #
+--echo # MDEV-19526/MDEV-29742 heap number overflow
+--echo #
+CREATE TABLE t1(a SMALLINT NOT NULL UNIQUE AUTO_INCREMENT, KEY(a))
+ENGINE=InnoDB;
+INSERT INTO t1 (a) SELECT seq FROM seq_1_to_8191;
+ALTER TABLE t1 FORCE, ALGORITHM=INPLACE;
+DROP TABLE t1;
+
+--echo # End of 10.3 tests
diff --git a/mysql-test/suite/innodb/t/innodb-agregate.test b/mysql-test/suite/innodb/t/innodb-agregate.test
new file mode 100644
index 00000000..e15548c0
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb-agregate.test
@@ -0,0 +1,18 @@
+--source include/have_innodb.inc
+
+#
+# MDEV-9667: Server hangs after select count(distinct name) from t2 where a=8366 and b>=5 and b<=5;
+#
+
+create table t2 (a smallint(6) not null, b int(10) not null, name varchar(20), primary key(a,b), key(name)) engine=InnoDB;
+
+insert into t2 values (8355,3,"sanja"),(8355,4,"wlad"),(8366,5, "lawrin"),(8366,6,"markusjm");
+
+select count(distinct name) from t2 where a=8366 and b>=5 and b<=5;
+select count(distinct name) from t2 where a=8366 and b=5;
+select count(distinct name) from t2 where a=8366 and b between 5 and 5.5;
+select sum(distinct a) from t2 where a=8366 and b>=5 and b<=5;
+select sum(distinct a) from t2 where a=8366 and b=5;
+select sum(distinct a) from t2 where a=8366 and b between 5 and 5.5;
+
+drop table t2;
diff --git a/mysql-test/suite/innodb/t/innodb-alter-autoinc.test b/mysql-test/suite/innodb/t/innodb-alter-autoinc.test
new file mode 100644
index 00000000..e01c44aa
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb-alter-autoinc.test
@@ -0,0 +1,104 @@
+--source include/have_innodb.inc
+
+CREATE TABLE t1 (a INT) ENGINE=InnoDB;
+INSERT INTO t1 VALUES(347),(33101),(123),(45),(6);
+# NULL -> NOT NULL only allowed INPLACE if strict sql_mode is on.
+SET @old_sql_mode = @@sql_mode;
+SET @@sql_mode = 'STRICT_TRANS_TABLES';
+ALTER TABLE t1 ADD PRIMARY KEY(a);
+SET @@sql_mode = @old_sql_mode;
+
+# We cannot assign AUTO_INCREMENT values during online index creation.
+--error ER_ALTER_OPERATION_NOT_SUPPORTED_REASON
+ALTER TABLE t1 DROP PRIMARY KEY, ADD id INT AUTO_INCREMENT PRIMARY KEY,
+ LOCK=NONE;
+
+--error ER_WRONG_AUTO_KEY
+ALTER TABLE t1 ADD id INT AUTO_INCREMENT;
+
+--error ER_WRONG_AUTO_KEY
+ALTER TABLE t1 ADD id INT AUTO_INCREMENT, ADD INDEX(a, id);
+
+ALTER TABLE t1 ADD id INT NOT NULL, ADD INDEX(id, a);
+
+SELECT * FROM t1;
+
+# Test with a non-default increment and offset
+SET AUTO_INCREMENT_INCREMENT = 5, AUTO_INCREMENT_OFFSET = 30;
+
+ALTER TABLE t1 DROP PRIMARY KEY, ADD id INT AUTO_INCREMENT PRIMARY KEY,
+ DROP COLUMN id, AUTO_INCREMENT = 42, ALGORITHM=COPY;
+
+SHOW CREATE TABLE t1;
+
+# The autoinc next value should increase. It is not rolled back.
+BEGIN;
+INSERT INTO t1 VALUES(7,0);
+SELECT * FROM t1;
+ROLLBACK;
+
+SHOW CREATE TABLE t1;
+
+# We cannot assign AUTO_INCREMENT values during online index creation.
+--error ER_ALTER_OPERATION_NOT_SUPPORTED_REASON
+ALTER TABLE t1 DROP PRIMARY KEY, ADD id INT AUTO_INCREMENT PRIMARY KEY,
+ DROP COLUMN id, AUTO_INCREMENT = 42, LOCK=NONE;
+
+ALTER TABLE t1 DROP PRIMARY KEY, ADD id INT AUTO_INCREMENT PRIMARY KEY,
+ DROP COLUMN id, AUTO_INCREMENT = 42, ALGORITHM=INPLACE;
+
+SELECT * FROM t1;
+SHOW CREATE TABLE t1;
+
+INSERT INTO t1 SET a=123;
+INSERT INTO t1 VALUES(-123,-45);
+
+ALTER TABLE t1 AUTO_INCREMENT = 75;
+
+INSERT INTO t1 SET a=123;
+SELECT * FROM t1;
+
+SHOW CREATE TABLE t1;
+
+DROP TABLE t1;
+
+# ALGORITHM=INPLACE should deliver identical results to ALGORITHM=COPY.
+CREATE TABLE t1 (a INT) ENGINE=InnoDB;
+INSERT INTO t1 VALUES(347),(33101),(123),(45),(6);
+ALTER TABLE t1 ADD PRIMARY KEY(a);
+
+ALTER TABLE t1 ADD id INT NOT NULL, ADD INDEX(id, a);
+
+SELECT * FROM t1;
+
+ALTER TABLE t1 DROP PRIMARY KEY, ADD id INT AUTO_INCREMENT PRIMARY KEY,
+ DROP COLUMN id, AUTO_INCREMENT = 42, ALGORITHM=INPLACE;
+
+SHOW CREATE TABLE t1;
+
+# The autoinc next value should increase. It is not rolled back.
+BEGIN;
+INSERT INTO t1 VALUES(7,0);
+SELECT * FROM t1;
+ROLLBACK;
+
+SHOW CREATE TABLE t1;
+
+ALTER TABLE t1 DROP PRIMARY KEY, ADD id INT AUTO_INCREMENT PRIMARY KEY,
+ DROP COLUMN id, AUTO_INCREMENT = 42, ALGORITHM=COPY;
+
+SELECT * FROM t1;
+
+SHOW CREATE TABLE t1;
+
+INSERT INTO t1 SET a=123;
+INSERT INTO t1 VALUES(-123,-45);
+
+ALTER TABLE t1 AUTO_INCREMENT = 75;
+
+INSERT INTO t1 SET a=123;
+SELECT * FROM t1;
+
+SHOW CREATE TABLE t1;
+
+DROP TABLE t1;
diff --git a/mysql-test/suite/innodb/t/innodb-alter-debug.test b/mysql-test/suite/innodb/t/innodb-alter-debug.test
new file mode 100644
index 00000000..c4a68ac7
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb-alter-debug.test
@@ -0,0 +1,192 @@
+--source include/innodb_page_size.inc
+--source include/have_debug.inc
+--source include/have_debug_sync.inc
+
+--source include/count_sessions.inc
+
+SET NAMES utf8;
+
+CREATE TABLE ① (
+ c1 INT PRIMARY KEY, c2 INT DEFAULT 1, ct TEXT, INDEX(c2))
+ENGINE = InnoDB;
+
+CREATE TABLE t1ć (c1 INT PRIMARY KEY, c2 INT, INDEX(c2),
+ CONSTRAINT t1c2 FOREIGN KEY (c2) REFERENCES ①(c2))
+ENGINE=InnoDB;
+
+INSERT INTO ① SET c1 = 1;
+
+SET @saved_debug_dbug = @@SESSION.debug_dbug;
+SET DEBUG_DBUG = '+d,ib_drop_foreign_error';
+--error ER_RECORD_FILE_FULL
+ALTER TABLE t1ć DROP FOREIGN KEY t1c2, RENAME TO ②;
+SET DEBUG_DBUG = @saved_debug_dbug;
+
+SET DEBUG_DBUG = '+d,ib_rename_column_error';
+--error ER_RECORD_FILE_FULL
+ALTER TABLE ① CHANGE c2 š INT;
+SET DEBUG_DBUG = @saved_debug_dbug;
+
+SHOW CREATE TABLE t1ć;
+
+DROP TABLE t1ć, ①;
+
+--echo #
+--echo # Bug #21364096 THE BOGUS DUPLICATE KEY ERROR IN ONLINE DDL
+--echo # WITH INCORRECT KEY NAME
+
+create table t1 (id int auto_increment primary key, a int, unique key uk(a))
+engine = innodb;
+insert into t1 select 1, 1;
+insert into t1 select 2, 2;
+SET DEBUG_SYNC = 'row_log_table_apply1_before SIGNAL s1 WAIT_FOR s2';
+--send alter table t1 force, add b int, ALGORITHM=inplace
+
+--echo /* connection con1 */
+connect (con1,localhost,root,,);
+SET DEBUG_SYNC = 'now WAIT_FOR s1';
+--error ER_DUP_ENTRY
+insert into t1 select NULL, 1;
+SET DEBUG_SYNC = 'now SIGNAL s2';
+
+--echo /* connection default */
+connection default;
+--echo /* reap */ alter table t1 force, add b int, ALGORITHM=inplace;
+--reap
+
+SET DEBUG_SYNC = 'row_log_table_apply1_before SIGNAL s1 WAIT_FOR s2';
+--send alter table t1 force, add c int, ALGORITHM=inplace;
+
+--echo /* connection con1 */
+connection con1;
+set DEBUG_SYNC = 'now WAIT_FOR s1';
+--error ER_DUP_ENTRY
+update t1 set a=1 where id=2;
+SET DEBUG_SYNC = 'now SIGNAL s2';
+
+--echo /* connection default */
+connection default;
+--echo /* reap */ alter table t1 force, add b int, ALGORITHM=inplace;
+--reap
+SET DEBUG_SYNC = 'RESET';
+
+drop table t1;
+
+--echo #
+--echo # Bug #27753193 ASSERTION `PREBUILT->TRX->ERROR_KEY_NUM <
+--echo # HA_ALTER_INFO->KEY_COUNT'
+
+CREATE TABLE t1 (a INT, UNIQUE KEY(a)) ENGINE=InnoDB;
+INSERT INTO t1 VALUES (1);
+
+SET DEBUG_SYNC = 'row_log_table_apply1_before signal S1 WAIT_FOR S2';
+send ALTER TABLE t1 FORCE, ALGORITHM=INPLACE;
+
+connection con1;
+SET DEBUG_SYNC = 'now WAIT_FOR S1';
+--error ER_DUP_ENTRY
+INSERT INTO t1 VALUES (1);
+SET DEBUG_SYNC = 'now SIGNAL S2';
+disconnect con1;
+
+CONNECTION default;
+reap;
+SET DEBUG_SYNC='RESET';
+
+DROP TABLE t1;
+
+--echo #
+--echo # MDEV-17470 Orphan temporary files after interrupted ALTER
+--echo # cause InnoDB: Operating system error number 17 and eventual
+--echo # fatal error 71
+--echo #
+CREATE TABLE t1 (pk INT AUTO_INCREMENT PRIMARY KEY, i INT) ENGINE=InnoDB;
+INSERT INTO t1 VALUES (NULL,1),(NULL,2),(NULL,3),(NULL,4),(NULL,5),(NULL,6),(NULL,7),(NULL,8);
+INSERT INTO t1 SELECT NULL, i FROM t1;
+INSERT INTO t1 SELECT NULL, i FROM t1;
+INSERT INTO t1 SELECT NULL, i FROM t1;
+INSERT INTO t1 SELECT NULL, i FROM t1;
+INSERT INTO t1 SELECT NULL, i FROM t1;
+
+LOCK TABLE t1 READ;
+
+--connect (con1,localhost,root,,test)
+let $ID= `SELECT @id := CONNECTION_ID()`;
+send ALTER TABLE t1 FORCE, ALGORITHM=COPY;
+
+--connection default
+let $wait_condition= select 1 from information_schema.processlist where state='Waiting for table metadata lock';
+source include/wait_condition.inc;
+let $ignore= `SELECT @id := $ID`;
+kill query @id;
+--connection con1
+--error ER_QUERY_INTERRUPTED
+reap;
+--disconnect con1
+--connection default
+UNLOCK TABLES;
+DROP TABLE t1;
+
+--echo #
+--echo # MDEV-7318 RENAME INDEX
+--echo #
+CREATE TABLE t (c1 INT, c2 INT, KEY i2 (c2)) ENGINE=INNODB;
+
+SET DEBUG_DBUG= '+d,ib_rename_index_fail1';
+-- error ER_LOCK_DEADLOCK
+ALTER TABLE t RENAME INDEX i2 to x, ALGORITHM=INPLACE;
+SET DEBUG_DBUG = @saved_debug_dbug;
+
+DROP TABLE t;
+
+--echo #
+--echo # MDEV-26772 InnoDB DDL fails with DUPLICATE KEY error
+--echo #
+
+create table t1(f1 int not null primary key,
+
+ f2 int not null, index idx(f2))engine=innodb;
+
+insert into t1 values(1, 1);
+
+connect(con1,localhost,root,,,);
+SET DEBUG_SYNC='before_delete_table_stats SIGNAL blocked WAIT_FOR go';
+SET innodb_lock_wait_timeout=0;
+send ALTER TABLE t1 FORCE, ALGORITHM=COPY;
+
+connection default;
+SET DEBUG_SYNC='now WAIT_FOR blocked';
+BEGIN;
+SELECT * FROM mysql.innodb_table_stats FOR UPDATE;
+SET DEBUG_SYNC='now SIGNAL go';
+
+connection con1;
+reap;
+
+connection default;
+COMMIT;
+SET DEBUG_SYNC=RESET;
+
+connection con1;
+ALTER TABLE t1 RENAME KEY idx TO idx1, ALGORITHM=COPY;
+disconnect con1;
+
+connection default;
+DROP TABLE t1;
+
+--echo #
+--echo # MDEV-26903 Assertion ctx->trx->state == TRX_STATE_ACTIVE on DROP INDEX
+--echo #
+
+CREATE TABLE t1(a INT PRIMARY KEY, b INT, INDEX(b)) ENGINE=InnoDB;
+SET @save_dbug=@@debug_dbug;
+SET debug_dbug='+d,deadlock_table_fail';
+--error ER_LOCK_DEADLOCK
+ALTER TABLE t1 DROP INDEX b, ALGORITHM=INPLACE;
+SET debug_dbug=@save_dbug;
+DROP TABLE t1;
+
+--echo # End of 10.6 tests
+
+# Wait till all disconnects are completed
+--source include/wait_until_count_sessions.inc
diff --git a/mysql-test/suite/innodb/t/innodb-alter-nullable.test b/mysql-test/suite/innodb/t/innodb-alter-nullable.test
new file mode 100644
index 00000000..af13a12a
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb-alter-nullable.test
@@ -0,0 +1,161 @@
+--source include/innodb_page_size.inc
+
+# Save the initial number of concurrent sessions.
+--source include/count_sessions.inc
+
+CREATE TABLE t (c1 INT PRIMARY KEY, c2 INT NOT NULL, c3 INT) ENGINE=InnoDB;
+INSERT INTO t VALUES (1,2,3),(4,5,6),(7,8,9);
+
+--enable_info
+# This one will be a no-op.
+# MySQL should perhaps issue an error, because it refuses to modify
+# the PRIMARY KEY column c1 from NOT NULL to NULL.
+ALTER TABLE t CHANGE c1 c1 INT NULL FIRST, ALGORITHM=INPLACE;
+
+# NULL -> NOT NULL only allowed INPLACE if strict sql_mode is on.
+ALTER TABLE t MODIFY c3 INT NOT NULL, ALGORITHM=INPLACE;
+
+# Request some conflicting changes for a single column.
+--error ER_BAD_FIELD_ERROR
+ALTER TABLE t CHANGE c2 c2 INT, CHANGE c2 c2 INT NOT NULL;
+--error ER_BAD_FIELD_ERROR
+ALTER TABLE t MODIFY c2 INT, MODIFY c2 INT NOT NULL;
+--error ER_BAD_FIELD_ERROR
+ALTER TABLE t MODIFY c2 INT UNSIGNED, MODIFY c2 INT;
+--error ER_BAD_FIELD_ERROR
+ALTER TABLE t MODIFY c2 CHAR(1) NOT NULL, MODIFY c2 INT NOT NULL;
+
+# No-ops.
+ALTER TABLE t CHANGE c2 c2 INT NOT NULL;
+ALTER TABLE t MODIFY c2 INT NOT NULL;
+--disable_info
+
+connect (con1,localhost,root,,);
+
+--error ER_BAD_NULL_ERROR
+UPDATE t SET c2=NULL;
+
+SELECT * FROM t;
+
+connection default;
+
+# This should change the column to NULL.
+ALTER TABLE t MODIFY c2 INT, ALGORITHM=INPLACE;
+
+connection con1;
+BEGIN;
+UPDATE t SET c2=NULL;
+SELECT * FROM t;
+ROLLBACK;
+SELECT * FROM t;
+
+disconnect con1;
+connection default;
+
+# This should be no-op.
+ALTER TABLE t MODIFY c2 INT NULL, ALGORITHM=INPLACE;
+
+--replace_column 1 # 5 #
+SELECT * FROM INFORMATION_SCHEMA.INNODB_SYS_TABLES
+WHERE NAME='test/t';
+
+DROP TABLE t;
+
+CREATE TABLE t1(c1 INT) ENGINE=InnoDB;
+ALTER TABLE t1 ADD CONSTRAINT UNIQUE KEY i1(c1);
+ALTER TABLE t1 CHANGE c1 c1 INT NOT NULL,ADD KEY(c1);
+DROP TABLE t1;
+
+--echo #
+--echo # MDEV-18732 InnoDB: ALTER IGNORE returns error for NULL
+--echo #
+
+CREATE TABLE t1(c INT) ENGINE=InnoDB;
+INSERT INTO t1 VALUES (NULL);
+--enable_info
+ALTER IGNORE TABLE t1 MODIFY c INT NOT NULL;
+--disable_info
+--error ER_BAD_NULL_ERROR
+INSERT INTO t1 VALUES (NULL);
+SELECT * FROM t1;
+DROP TABLE t1;
+
+CREATE TABLE t1(c INT) ENGINE=InnoDB;
+INSERT INTO t1 VALUES (NULL),(1),(1);
+--enable_info
+ALTER IGNORE TABLE t1 ADD UNIQUE(c);
+ALTER IGNORE TABLE t1 ADD PRIMARY KEY(c);
+--disable_info
+SELECT * FROM t1;
+DROP TABLE t1;
+
+CREATE TABLE t1(c INT, g INT AS (c) PERSISTENT) ENGINE=InnoDB;
+CREATE TABLE t2(c INT, v INT AS (c) VIRTUAL) ENGINE=InnoDB;
+CREATE TABLE t3(c INT, v INT AS (c) VIRTUAL, INDEX(v)) ENGINE=InnoDB;
+INSERT INTO t1 SET c=NULL;
+INSERT INTO t2 SET c=NULL;
+INSERT INTO t3 SET c=NULL;
+SET @old_sql_mode = @@sql_mode;
+# Allow lossy conversions of data
+SET sql_mode = '';
+--enable_info
+ALTER TABLE t1 MODIFY c INT NOT NULL;
+ALTER TABLE t2 MODIFY c INT NOT NULL;
+ALTER TABLE t3 MODIFY c INT NOT NULL;
+--disable_info
+SET sql_mode = @old_sql_mode;
+SELECT * FROM t1;
+SELECT * FROM t2;
+SELECT * FROM t3;
+SELECT v FROM t3 FORCE INDEX(v);
+CHECK TABLE t1,t2,t3;
+DROP TABLE t1,t2,t3;
+
+CREATE TABLE t1(c INT, g INT AS (c) PERSISTENT) ENGINE=InnoDB;
+CREATE TABLE t2(c INT, v INT AS (c) VIRTUAL) ENGINE=InnoDB;
+CREATE TABLE t3(c INT, v INT AS (c) VIRTUAL, INDEX(v)) ENGINE=InnoDB;
+INSERT INTO t1 SET c=NULL;
+INSERT INTO t2 SET c=NULL;
+INSERT INTO t3 SET c=NULL;
+--enable_info
+ALTER IGNORE TABLE t1 MODIFY c INT NOT NULL;
+ALTER IGNORE TABLE t2 MODIFY c INT NOT NULL;
+ALTER IGNORE TABLE t3 MODIFY c INT NOT NULL;
+--disable_info
+SELECT * FROM t1;
+SELECT * FROM t2;
+SELECT * FROM t3;
+SELECT v FROM t3 FORCE INDEX(v);
+CHECK TABLE t1,t2,t3;
+DROP TABLE t1,t2,t3;
+
+CREATE TABLE t1(c INT, g INT AS (c) PERSISTENT) ENGINE=InnoDB;
+CREATE TABLE t2(c INT, v INT AS (c) VIRTUAL) ENGINE=InnoDB;
+CREATE TABLE t3(c INT, v INT AS (c) VIRTUAL, INDEX(v)) ENGINE=InnoDB;
+INSERT INTO t1 SET c=NULL;
+INSERT INTO t2 SET c=NULL;
+INSERT INTO t3 SET c=NULL;
+--enable_info
+--error WARN_DATA_TRUNCATED
+ALTER TABLE t1 MODIFY c INT NOT NULL;
+--error WARN_DATA_TRUNCATED
+ALTER TABLE t2 MODIFY c INT NOT NULL;
+--error WARN_DATA_TRUNCATED
+ALTER TABLE t3 MODIFY c INT NOT NULL;
+--disable_info
+UPDATE t1 SET c=0;
+UPDATE t2 SET c=0;
+UPDATE t3 SET c=0;
+--enable_info
+ALTER TABLE t1 MODIFY c INT NOT NULL;
+ALTER TABLE t2 MODIFY c INT NOT NULL;
+ALTER TABLE t3 MODIFY c INT NOT NULL;
+--disable_info
+SELECT * FROM t1;
+SELECT * FROM t2;
+SELECT * FROM t3;
+DROP TABLE t1,t2,t3;
+
+# 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/suite/innodb/t/innodb-alter-table.test b/mysql-test/suite/innodb/t/innodb-alter-table.test
new file mode 100644
index 00000000..ab0bd7b3
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb-alter-table.test
@@ -0,0 +1,208 @@
+--source include/innodb_page_size.inc
+--source include/have_partition.inc
+# This test is slow on buildbot.
+--source include/big_test.inc
+
+#
+# MMDEV-8386: MariaDB creates very big tmp file and hangs on xtradb
+#
+drop database if exists moodle19;
+create database moodle19;
+use moodle19;
+
+CREATE TABLE `mdl_course_modules` (
+ `id` bigint(10) NOT NULL AUTO_INCREMENT,
+ `course` bigint(10) NOT NULL DEFAULT '0',
+ `module` bigint(10) NOT NULL DEFAULT '0',
+ `instance` bigint(10) NOT NULL DEFAULT '0',
+ `section` bigint(10) NOT NULL DEFAULT '0',
+ `idnumber` varchar(100) DEFAULT NULL,
+ `added` bigint(10) NOT NULL DEFAULT '0',
+ `delay` varchar(10) NOT NULL DEFAULT '0',
+ `score` smallint(4) NOT NULL DEFAULT '0',
+ `indent` mediumint(5) NOT NULL DEFAULT '0',
+ `visible` tinyint(1) NOT NULL DEFAULT '1',
+ `checkboxesforprereqs` tinyint(1) NOT NULL DEFAULT '0',
+ `stylewhencomplete` varchar(200) DEFAULT '',
+ `checkboxforcomplete` tinyint(1) NOT NULL DEFAULT '0',
+ `stylewhenlocked` varchar(200) DEFAULT 'locked',
+ `visiblewhenlocked` tinyint(1) NOT NULL DEFAULT '1',
+ `visibleold` tinyint(1) NOT NULL DEFAULT '1',
+ `groupmode` smallint(4) NOT NULL DEFAULT '0',
+ `groupingid` bigint(10) NOT NULL DEFAULT '0',
+ `groupmembersonly` smallint(4) NOT NULL DEFAULT '0',
+ `completion` tinyint(1) NOT NULL DEFAULT '0',
+ `completiongradeitemnumber` bigint(10) DEFAULT NULL,
+ `completionview` tinyint(1) NOT NULL DEFAULT '0',
+ `completionexpected` bigint(10) NOT NULL DEFAULT '0',
+ `availablefrom` bigint(10) NOT NULL DEFAULT '0',
+ `availableuntil` bigint(10) NOT NULL DEFAULT '0',
+ `showavailability` tinyint(1) NOT NULL DEFAULT '0',
+ `showdescription` tinyint(1) NOT NULL DEFAULT '0',
+ PRIMARY KEY (`id`),
+ KEY `mdl_courmodu_vis_ix` (`visible`),
+ KEY `mdl_courmodu_cou_ix` (`course`),
+ KEY `mdl_courmodu_mod_ix` (`module`),
+ KEY `mdl_courmodu_ins_ix` (`instance`),
+ KEY `mdl_courmodu_idncou_ix` (`idnumber`,`course`),
+ KEY `mdl_courmodu_gro_ix` (`groupingid`)
+) ENGINE=InnoDB AUTO_INCREMENT=447023 DEFAULT CHARSET=utf8 COMMENT='course_modules table retrofitted from MySQL';
+
+let $num= 2701;
+--disable_query_log
+--echo # Inserting $num rows into the table...
+while ($num)
+{
+ eval INSERT INTO mdl_course_modules VALUES ($num,4,5,5,24,NULL,1141569781,'',0,0,1,0,'',0,'locked',1,1,0,0,0,0,NULL,0,0,0,0,0,0);
+ dec $num;
+}
+--enable_query_log
+ALTER TABLE moodle19.mdl_course_modules ADD stefantest LONGTEXT CHARACTER SET utf8 COLLATE utf8_general_ci AFTER showdescription;
+
+drop database moodle19;
+
+#
+# Mdev-9469: Incorrect key file on alter table
+#
+use test;
+
+CREATE TABLE `w_findispmon05u` (
+`atpkey` INT(11) NOT NULL DEFAULT '0',
+`atzo05` INT(11) NULL DEFAULT NULL,
+`pos` BIGINT(21) NULL DEFAULT NULL,
+`f5BnvB` INT(9) NULL DEFAULT NULL,
+`f5atbvb` INT(11) NULL DEFAULT NULL,
+`f5atbwmg` INT(11) NULL DEFAULT NULL,
+`f5pBneu` BIGINT(12) NULL DEFAULT NULL,
+`atbwdt` INT(11) NULL DEFAULT NULL,
+`atbwzt` INT(11) NULL DEFAULT NULL,
+`atbart` VARCHAR(10) NULL DEFAULT NULL
+)
+COLLATE='utf8_general_ci'
+ENGINE=InnoDB;
+ALTER TABLE `w_findispmon05u`
+CHANGE COLUMN `atpkey` `f5atpkey` INT(11) NOT NULL DEFAULT '0' FIRST,
+CHANGE COLUMN `atzo05` `f5atzo05` INT(11) NULL DEFAULT NULL AFTER `f5atpkey`,
+CHANGE COLUMN `atbwdt` `f5atbwdt` INT(11) NULL DEFAULT NULL AFTER `f5pBneu`,
+CHANGE COLUMN `atbwzt` `f5atbwzt` INT(11) NULL DEFAULT NULL AFTER `f5atbwdt`,
+CHANGE COLUMN `atbart` `f5atbart` VARCHAR(10) NULL DEFAULT NULL AFTER `f5atbwzt`,
+ADD INDEX `atpkey` (`f5atpkey`),
+ADD INDEX `inatkey` (`f5atzo05`, `pos`),
+ADD INDEX `pos` (`pos`, `f5atzo05`);
+
+SHOW WARNINGS;
+SHOW CREATE TABLE `w_findispmon05u`;
+
+DROP TABLE `w_findispmon05u`;
+
+CREATE TABLE t (
+ a INT NOT NULL,
+ b INT NOT NULL,
+ PRIMARY KEY (a)
+) ENGINE=INNODB;
+
+ALTER TABLE t
+ CHANGE COLUMN b c INT NOT NULL,
+ ADD UNIQUE INDEX (c);
+
+SHOW WARNINGS;
+SHOW CREATE TABLE t;
+
+# this should fail
+--error 1072
+ALTER TABLE t
+ CHANGE COLUMN c b INT NOT NULL,
+ ADD UNIQUE INDEX (c);
+
+DROP TABLE t;
+
+#
+# Check Foreign Keys
+#
+CREATE TABLE parent (
+ a INT NOT NULL,
+ b INT NOT NULL,
+ PRIMARY KEY (a)
+) ENGINE=INNODB;
+
+CREATE TABLE child (
+ a INT NOT NULL,
+ b INT NOT NULL,
+ PRIMARY KEY (a)
+) ENGINE=INNODB;
+
+ALTER TABLE child
+ CHANGE COLUMN b c INT NOT NULL,
+ ADD FOREIGN KEY (c) REFERENCES parent(a);
+
+SHOW WARNINGS;
+
+SHOW CREATE TABLE child;
+
+DROP TABLE child, parent;
+
+#
+# MDEV-10535: ALTER TABLE causes standalone/wsrep cluster crash
+#
+CREATE TABLE IF NOT EXISTS ticket (
+ id INT UNSIGNED NOT NULL AUTO_INCREMENT,
+ mask VARCHAR(16) DEFAULT '' NOT NULL,
+ subject VARCHAR(255) DEFAULT '' NOT NULL,
+ is_closed TINYINT(1) UNSIGNED DEFAULT 0 NOT NULL,
+ is_deleted TINYINT(1) UNSIGNED DEFAULT 0 NOT NULL,
+ team_id INT UNSIGNED DEFAULT 0 NOT NULL,
+ category_id INT UNSIGNED DEFAULT 0 NOT NULL,
+ first_message_id INT UNSIGNED DEFAULT 0 NOT NULL,
+ created_date INT UNSIGNED,
+ updated_date INT UNSIGNED,
+ due_date INT UNSIGNED,
+ first_wrote_address_id INT UNSIGNED NOT NULL DEFAULT 0,
+ last_wrote_address_id INT UNSIGNED NOT NULL DEFAULT 0,
+ spam_score DECIMAL(4,4) NOT NULL DEFAULT 0,
+ spam_training VARCHAR(1) NOT NULL DEFAULT '',
+ interesting_words VARCHAR(255) NOT NULL DEFAULT '',
+ next_action VARCHAR(255) NOT NULL DEFAULT '',
+ PRIMARY KEY (id)
+) ENGINE=InnoDB;
+
+ALTER TABLE ticket
+ CHANGE COLUMN team_id group_id INT UNSIGNED NOT NULL DEFAULT 0,
+ CHANGE COLUMN category_id bucket_id INT UNSIGNED NOT NULL DEFAULT 0,
+ ADD COLUMN org_id INT UNSIGNED NOT NULL DEFAULT 0,
+ ADD INDEX org_id (org_id);
+
+SHOW CREATE TABLE ticket;
+
+DROP TABLE ticket;
+
+#
+# MDEV-13838: Wrong result after altering a partitioned table
+#
+
+CREATE TABLE t (
+id bigint(20) unsigned NOT NULL auto_increment,
+d date NOT NULL,
+a bigint(20) unsigned NOT NULL,
+b smallint(5) unsigned DEFAULT NULL,
+PRIMARY KEY (id,d)
+) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_general_cs STATS_SAMPLE_PAGES=2
+PARTITION BY RANGE COLUMNS(d)
+(
+PARTITION p20170914 VALUES LESS THAN ('2017-09-15') ENGINE = InnoDB,
+PARTITION p99991231 VALUES LESS THAN (MAXVALUE) ENGINE = InnoDB);
+
+insert into t(d,a,b) values ('2017-09-15',rand()*10000,rand()*10);
+insert into t(d,a,b) values ('2017-09-15',rand()*10000,rand()*10);
+
+replace into t(d,a,b) select '2017-09-15',rand()*10000,rand()*10 from t t1, t t2, t t3, t t4;
+
+select count(*) from t where d ='2017-09-15';
+
+ALTER TABLE t CHANGE b c smallint(5) unsigned , ADD KEY idx_d_a (d, a);
+SHOW CREATE TABLE t;
+analyze table t;
+
+select count(*) from t where d ='2017-09-15';
+select count(*) from t force index(primary) where d ='2017-09-15';
+
+DROP TABLE t;
diff --git a/mysql-test/suite/innodb/t/innodb-alter-tempfile.test b/mysql-test/suite/innodb/t/innodb-alter-tempfile.test
new file mode 100644
index 00000000..0ae116f5
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb-alter-tempfile.test
@@ -0,0 +1,91 @@
+# Not supported in embedded
+--source include/not_embedded.inc
+
+# This test case needs to crash the server. Needs a debug server.
+--source include/have_debug.inc
+
+# Don't test this under valgrind, memory leaks will occur.
+--source include/not_valgrind.inc
+
+# Avoid CrashReporter popup on Mac
+--source include/not_crashrep.inc
+
+--source include/innodb_page_size.inc
+
+--source include/have_debug_sync.inc
+
+call mtr.add_suppression("Cannot find index f2 in InnoDB index dictionary.");
+call mtr.add_suppression("InnoDB indexes are inconsistent with what defined in .frm for table");
+call mtr.add_suppression("Table test/t1 contains 1 indexes inside InnoDB, which is different from the number of indexes 2 defined in");
+call mtr.add_suppression("InnoDB could not find key no 1 with name f2 from dict cache for table");
+
+
+--echo #
+--echo # Bug #18734396 INNODB IN-PLACE ALTER FAILURES BLOCK FUTURE ALTERS
+--echo #
+--echo # Temporary tablename will be unique. This makes sure that future
+--echo # in-place ALTERs of the same table will not be blocked due to
+--echo # temporary tablename.
+
+let datadir= `select @@datadir`;
+
+--let $_expect_file_name= `select regexp_replace(@@tmpdir, '^.*/','')`
+--let $_expect_file_name= $MYSQLTEST_VARDIR/tmp/$_expect_file_name.expect
+
+CREATE TABLE t1 (f1 INT NOT NULL, f2 INT NOT NULL) ENGINE=innodb;
+SET debug_dbug='+d,innodb_alter_commit_crash_before_commit';
+
+--exec echo "wait" > $MYSQLTEST_VARDIR/tmp/mysqld.1.expect
+
+--error 2013
+ALTER TABLE t1 ADD PRIMARY KEY (f2, f1);
+
+--source include/start_mysqld.inc
+
+show create table t1;
+--echo # Consecutive Alter table does not create same temporary file name
+ALTER TABLE t1 ADD PRIMARY KEY (f2, f1);
+show create table t1;
+drop table t1;
+
+--echo #
+--echo # MDEV-22928 InnoDB fails to fetch index type
+--echo # when index mismatch
+--echo #
+CREATE TABLE t1(f1 INT NOT NULL, f2 INT NOT NULL,
+ index(f1), index(f2))ENGINE=InnoDB;
+INSERT INTO t1 VALUES(1, 1), (2, 2);
+
+connect (con1,localhost,root,,test);
+SET DEBUG_SYNC="alter_table_inplace_after_commit SIGNAL default_signal WAIT_FOR default_done";
+--send
+ALTER TABLE t1 DROP INDEX f2, ALGORITHM=INPLACE;
+connection default;
+set DEBUG_SYNC="now WAIT_FOR default_signal";
+--let $shutdown_timeout=0
+--source include/restart_mysqld.inc
+disconnect con1;
+--replace_column 7 #
+SHOW KEYS FROM t1;
+DROP TABLE t1;
+remove_files_wildcard $datadir/test #sql-*.frm;
+
+--echo #
+--echo # MDEV-25503 InnoDB hangs on startup during recovery
+--echo #
+CREATE TABLE t1 (a INT PRIMARY KEY) ENGINE=InnoDB STATS_PERSISTENT=1;
+connect (con1,localhost,root,,);
+BEGIN;
+DELETE FROM mysql.innodb_table_stats;
+
+connect (con2,localhost,root,,);
+SET DEBUG_SYNC='innodb_inplace_alter_table_enter SIGNAL blocked WAIT_FOR ever';
+send ALTER TABLE t1 FORCE;
+
+connection default;
+SET DEBUG_SYNC='now WAIT_FOR blocked';
+--let $shutdown_timeout=0
+--source include/restart_mysqld.inc
+SELECT * FROM t1;
+DROP TABLE t1;
+remove_files_wildcard $datadir/test #sql-*.frm;
diff --git a/mysql-test/suite/innodb/t/innodb-alter-timestamp.test b/mysql-test/suite/innodb/t/innodb-alter-timestamp.test
new file mode 100644
index 00000000..95df8d6b
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb-alter-timestamp.test
@@ -0,0 +1,114 @@
+--source include/have_innodb.inc
+--source include/have_sequence.inc
+
+CREATE TABLE t1 (i1 INT UNSIGNED NULL DEFAULT 42) ENGINE=innodb;
+INSERT INTO t1 VALUES(NULL);
+--enable_info
+--error WARN_DATA_TRUNCATED
+ALTER TABLE t1 CHANGE i1 i1 INT UNSIGNED NOT NULL DEFAULT rand(),
+ALGORITHM=INPLACE;
+--error WARN_DATA_TRUNCATED
+ALTER TABLE t1 CHANGE i1 i1 INT UNSIGNED NOT NULL DEFAULT rand(),
+ALGORITHM=COPY;
+--error ER_ALTER_OPERATION_NOT_SUPPORTED_REASON
+ALTER TABLE t1 CHANGE i1 id INT UNSIGNED NOT NULL AUTO_INCREMENT,
+ADD PRIMARY KEY(id), ALGORITHM=INPLACE;
+
+# ALTER IGNORE cannot create unique or primary key with ALGORITHM=INPLACE.
+--error ER_ALTER_OPERATION_NOT_SUPPORTED_REASON
+ALTER IGNORE TABLE t1 ADD PRIMARY KEY(i1), ALGORITHM=INPLACE;
+# Try the same with ALTER TABLE, using non-strict sql_mode.
+--disable_info
+SET @old_sql_mode = @@sql_mode;
+SET sql_mode = '';
+--enable_info
+ALTER TABLE t1 ADD PRIMARY KEY(i1), ALGORITHM=INPLACE;
+--disable_info
+SET sql_mode = @old_sql_mode;
+--enable_info
+ALTER TABLE t1 CHANGE i1 id INT UNSIGNED NOT NULL AUTO_INCREMENT;
+--disable_info
+SELECT * FROM t1;
+SHOW CREATE TABLE t1;
+DROP TABLE t1;
+
+CREATE TABLE t1 (i1 INT UNSIGNED NOT NULL, d1 TIMESTAMP NULL) ENGINE=InnoDB;
+
+SHOW CREATE TABLE t1;
+
+INSERT INTO t1 (i1) VALUES (1), (2), (3), (4), (5);
+select * from t1;
+set sql_mode = 'STRICT_ALL_TABLES,NO_ZERO_DATE';
+ALTER TABLE t1 CHANGE d1 d1 TIMESTAMP NULL DEFAULT '2017-05-08 16:23:45',
+ALGORITHM=INPLACE;
+SELECT DISTINCT d1 FROM t1;
+ALTER TABLE t1 CHANGE d1 d1 TIMESTAMP NULL DEFAULT '2017-05-08 16:32:45',
+ALGORITHM=COPY;
+SELECT DISTINCT d1 FROM t1;
+--enable_info
+ALTER TABLE t1 CHANGE d1 d1 TIMESTAMP DEFAULT '2017-05-08 16:32:54';
+--disable_info
+SELECT COUNT(DISTINCT d1),COUNT(d1),COUNT(*) FROM t1;
+drop table t1;
+
+CREATE TABLE t1 (
+ `i1` INT(10) UNSIGNED NOT NULL,
+ `d1` TIMESTAMP NULL DEFAULT NULL
+) ENGINE=innodb;
+INSERT INTO t1 (i1) VALUES (1), (2), (3), (4), (5);
+--enable_info
+ALTER TABLE t1 CHANGE d1 d1 TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP;
+ALTER TABLE t1 ADD COLUMN w1 varchar(20) NULL DEFAULT USER();
+ALTER TABLE t1 CHANGE w1 u1 varchar(30) NULL DEFAULT substr(USER(),1);
+--disable_info
+SELECT u1, COUNT(DISTINCT d1) FROM t1 GROUP BY u1;
+
+--enable_info
+ALTER TABLE t1 ADD COLUMN d2 TIMESTAMP DEFAULT '2017-05-08 16:23:45',
+LOCK=NONE;
+--error ER_ALTER_OPERATION_NOT_SUPPORTED
+ALTER TABLE t1 ADD COLUMN d3 TIMESTAMP DEFAULT d1, LOCK=NONE;
+--error ER_ALTER_OPERATION_NOT_SUPPORTED
+ALTER TABLE t1 ADD COLUMN d3 TIMESTAMP DEFAULT d1, ALGORITHM=INPLACE;
+ALTER TABLE t1 ADD COLUMN d3 TIMESTAMP DEFAULT d1;
+--disable_info
+SELECT d1-d3, d2 FROM t1;
+SHOW CREATE TABLE t1;
+--enable_info
+ALTER TABLE t1 ADD COLUMN d4 TIMESTAMP DEFAULT CURRENT_TIMESTAMP;
+--disable_info
+SELECT COUNT(DISTINCT d4),COUNT(d4),COUNT(*) FROM t1;
+SELECT DISTINCT (CURRENT_TIMESTAMP()-d4) <= 60 FROM t1;
+DROP TABLE t1;
+
+# MDEV-19611 INPLACE ALTER does not fail on bad implicit default value
+
+# Empty-table
+CREATE TABLE t1(f1 int) ENGINE=InnoDB;
+INSERT INTO t1 SELECT * FROM seq_1_to_4096;
+connect(purge_control,localhost,root,,);
+START TRANSACTION WITH CONSISTENT SNAPSHOT;
+
+connection default;
+DELETE FROM t1;
+SET sql_mode='STRICT_ALL_TABLES,STRICT_TRANS_TABLES,NO_ZERO_DATE';
+ALTER TABLE t1 ADD f2 DATE NOT NULL, ALGORITHM=INPLACE;
+
+# Non-empty table
+INSERT INTO t1 VALUES (1, now());
+--error ER_ALTER_OPERATION_NOT_SUPPORTED
+ALTER TABLE t1 ADD f3 DATE NOT NULL, ALGORITHM=INPLACE;
+DROP TABLE t1;
+disconnect purge_control;
+
+--echo #
+--echo # MDEV-26458 SIGSEGV in innobase_table_is_empty() on ALTER TABLE
+--echo #
+CREATE TABLE t(a INT PRIMARY KEY) ENGINE=InnoDB;
+ALTER TABLE t DISCARD TABLESPACE;
+SET sql_mode='NO_ZERO_DATE';
+ALTER TABLE t ADD c DATE NOT NULL;
+SET sql_mode=DEFAULT;
+DROP TABLE t;
+
+--echo # End of 10.3 tests
diff --git a/mysql-test/suite/innodb/t/innodb-alter.opt b/mysql-test/suite/innodb/t/innodb-alter.opt
new file mode 100644
index 00000000..aa400236
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb-alter.opt
@@ -0,0 +1,3 @@
+--loose-innodb-sys-indexes
+--loose-innodb-sys-columns
+--loose-innodb-sys-fields
diff --git a/mysql-test/suite/innodb/t/innodb-alter.test b/mysql-test/suite/innodb/t/innodb-alter.test
new file mode 100644
index 00000000..78550763
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb-alter.test
@@ -0,0 +1,706 @@
+--source include/have_innodb.inc
+--source include/default_charset.inc
+
+SET NAMES utf8mb4;
+
+CREATE TABLE t1 (
+ c1 INT PRIMARY KEY, c2 INT DEFAULT 1, ct TEXT,
+ INDEX(c2))
+ENGINE=InnoDB;
+
+INSERT INTO t1 SET c1=1;
+
+CREATE TABLE sys_tables SELECT * FROM INFORMATION_SCHEMA.INNODB_SYS_TABLES
+WHERE NAME LIKE 'test/t%';
+CREATE TABLE sys_indexes SELECT i.* FROM INFORMATION_SCHEMA.INNODB_SYS_INDEXES i
+INNER JOIN sys_tables st ON i.TABLE_ID=st.TABLE_ID;
+
+CREATE TABLE t1p LIKE t1;
+
+CREATE TABLE t1c (c1 INT PRIMARY KEY, c2 INT, c3 INT, INDEX(c2), INDEX(c3),
+ CONSTRAINT t1c2 FOREIGN KEY (c2) REFERENCES t1(c2),
+ CONSTRAINT t1c3 FOREIGN KEY (c3) REFERENCES t1p(c2))
+ENGINE=InnoDB;
+
+CREATE TABLE sys_foreign SELECT i.*
+FROM INFORMATION_SCHEMA.INNODB_SYS_FOREIGN i
+WHERE FOR_NAME LIKE 'test/t%';
+
+SELECT i.* FROM INFORMATION_SCHEMA.INNODB_SYS_FOREIGN_COLS i
+INNER JOIN sys_foreign sf ON i.ID = sf.ID;
+
+-- source suite/innodb/include/innodb_dict.inc
+
+SHOW CREATE TABLE t1;
+ALTER TABLE t1 ALTER c2 DROP DEFAULT;
+SHOW CREATE TABLE t1;
+
+-- source suite/innodb/include/innodb_dict.inc
+
+# These should be no-op.
+ALTER TABLE t1 CHANGE c2 c2 INT AFTER c1;
+ALTER TABLE t1 CHANGE c1 c1 INT FIRST;
+
+-- source suite/innodb/include/innodb_dict.inc
+
+ALTER TABLE t1 CHANGE C2 c3 INT;
+
+-- source suite/innodb/include/innodb_dict.inc
+
+ALTER TABLE t1 CHANGE c3 C INT;
+
+-- source suite/innodb/include/innodb_dict.inc
+
+ALTER TABLE t1 CHANGE C Cöŀumň_TWO INT;
+
+SELECT i.* FROM INFORMATION_SCHEMA.INNODB_SYS_FOREIGN_COLS i
+INNER JOIN sys_foreign sf ON i.ID = sf.ID;
+
+-- source suite/innodb/include/innodb_dict.inc
+
+-- error ER_BAD_FIELD_ERROR
+ALTER TABLE t1 CHANGE cöĿǖmň_two c3 INT;
+
+ALTER TABLE t1 CHANGE cÖĿUMŇ_two c3 INT, RENAME TO t3;
+
+SELECT st.NAME, i.NAME
+FROM sys_tables st INNER JOIN INFORMATION_SCHEMA.INNODB_SYS_TABLES i
+ON i.TABLE_ID=st.TABLE_ID;
+
+SHOW CREATE TABLE t3;
+SHOW CREATE TABLE t1c;
+
+# The maximum column name length should be 64 characters.
+--error ER_TOO_LONG_IDENT
+ALTER TABLE t3 CHANGE c3
+`12345678901234567890123456789012345678901234567890123456789012345` INT;
+ALTER TABLE t3 CHANGE c3
+`1234567890123456789012345678901234567890123456789012345678901234` INT;
+SHOW CREATE TABLE t3;
+
+# Test the length limit with non-ASCII utf-8 characters.
+--error ER_TOO_LONG_IDENT
+ALTER TABLE t3 CHANGE
+`1234567890123456789012345678901234567890123456789012345678901234`
+`倀倁倂倃倄倅倆倇倈倉倊個倌倍倎倏倐們倒倓倔倕倖倗倘候倚倛倜倝倞借倠倡倢倣値倥倦倧倨倩倪倫倬倭倮倯倰倱倲倳倴倵倶倷倸倹债倻值倽倾倿偀` INT;
+--error ER_TOO_LONG_IDENT
+ALTER TABLE t3 CHANGE
+`1234567890123456789012345678901234567890123456789012345678901234`
+`倀倁倂倃倄倅倆倇倈倉倊個倌倍倎倏倐們倒倓倔倕倖倗倘候倚倛倜倝倞借倠倡倢倣値倥倦倧倨倩倪倫倬倭倮倯倰倱倲倳倴倵倶倷倸倹债倻值倽倾倿ä` INT;
+ALTER TABLE t3 CHANGE
+`1234567890123456789012345678901234567890123456789012345678901234`
+`倀倁倂倃倄倅倆倇倈倉倊個倌倍倎倏倐們倒倓倔倕倖倗倘候倚倛倜倝倞借倠倡倢倣値倥倦倧倨倩倪倫倬倭倮倯倰倱倲倳倴倵倶倷倸倹债倻值倽倾ä` INT;
+
+# check that the rename is case-insensitive (note the upper-case ä at end)
+ALTER TABLE t3 CHANGE
+`倀倁倂倃倄倅倆倇倈倉倊個倌倍倎倏倐們倒倓倔倕倖倗倘候倚倛倜倝倞借倠倡倢倣値倥倦倧倨倩倪倫倬倭倮倯倰倱倲倳倴倵倶倷倸倹债倻值倽倾Ä`
+c3 INT;
+
+# test with 4-byte UTF-8 (should be disallowed)
+--error ER_INVALID_CHARACTER_STRING
+ALTER TABLE t3 CHANGE c3 𐌀𐌁𐌂𐌃𐌄𐌅𐌆𐌇𐌈𐌉𐌊𐌋𐌌𐌍𐌎𐌏𐌐𐌑𐌒𐌓𐌔𐌕𐌖𐌗𐌘𐌙𐌚𐌛𐌜 INT;
+--error ER_INVALID_CHARACTER_STRING
+ALTER TABLE t3 CHANGE c3 😲 INT;
+
+ALTER TABLE t3 RENAME TO t2;
+
+SELECT st.NAME, i.NAME
+FROM sys_tables st INNER JOIN INFORMATION_SCHEMA.INNODB_SYS_TABLES i
+ON i.TABLE_ID=st.TABLE_ID;
+
+SHOW CREATE TABLE t2;
+
+RENAME TABLE t2 TO t1;
+
+SELECT st.NAME, i.NAME
+FROM sys_tables st INNER JOIN INFORMATION_SCHEMA.INNODB_SYS_TABLES i
+ON i.TABLE_ID=st.TABLE_ID;
+
+-- source suite/innodb/include/innodb_dict.inc
+
+--error ER_DROP_INDEX_FK
+ALTER TABLE t1 DROP INDEX c2;
+
+--error ER_CANT_DROP_FIELD_OR_KEY
+ALTER TABLE t1 DROP INDEX c4;
+
+--error ER_CANT_DROP_FIELD_OR_KEY
+ALTER TABLE t1c DROP FOREIGN KEY c2;
+
+--error ER_CANT_DROP_FIELD_OR_KEY
+ALTER TABLE t1c DROP FOREIGN KEY t1c2, DROP FOREIGN KEY c2;
+
+--error ER_CANT_DROP_FIELD_OR_KEY
+ALTER TABLE t1c DROP FOREIGN KEY t1c2, DROP FOREIGN KEY c2, DROP INDEX c2;
+
+--error ER_DROP_INDEX_FK
+ALTER TABLE t1c DROP INDEX c2;
+
+--error ER_CANT_DROP_FIELD_OR_KEY
+ALTER TABLE t1c DROP FOREIGN KEY ẗ1C2;
+
+SHOW CREATE TABLE t1c;
+
+SET foreign_key_checks=0;
+DROP TABLE t1p;
+SET foreign_key_checks=1;
+
+SHOW CREATE TABLE t1c;
+
+-- source suite/innodb/include/innodb_dict.inc
+
+CREATE TABLE t1p (c1 INT PRIMARY KEY, c2 INT, INDEX(c2)) ENGINE=InnoDB;
+
+--error ER_DROP_INDEX_FK
+ALTER TABLE t1c DROP INDEX C2, DROP INDEX C3;
+--error ER_DROP_INDEX_FK
+ALTER TABLE t1c DROP INDEX C3;
+
+SET foreign_key_checks=0;
+ALTER TABLE t1c DROP INDEX C3;
+SET foreign_key_checks=1;
+
+SHOW CREATE TABLE t1c;
+-- source suite/innodb/include/innodb_dict.inc
+
+ALTER TABLE t1c DROP FOREIGN KEY t1C3;
+
+SHOW CREATE TABLE t1c;
+-- source suite/innodb/include/innodb_dict.inc
+
+ALTER TABLE t1c DROP INDEX c2, DROP FOREIGN KEY t1C2;
+
+SHOW CREATE TABLE t1c;
+
+-- source suite/innodb/include/innodb_dict.inc
+
+ALTER TABLE t1 DROP INDEX c2, CHANGE c3 c2 INT;
+
+-- source suite/innodb/include/innodb_dict.inc
+
+CREATE TABLE t1o LIKE t1;
+
+# This will implicitly add a FTS_DOC_ID column, which cannot be done online.
+--error ER_ALTER_OPERATION_NOT_SUPPORTED_REASON
+ALTER TABLE t1 ADD FULLTEXT INDEX (ct),
+CHANGE c1 pk INT, ALTER c2 SET DEFAULT 42, RENAME TO tt,
+ALGORITHM=INPLACE, LOCK=NONE;
+
+ALTER TABLE t1 ADD FULLTEXT INDEX (ct),
+CHANGE c1 pk INT, ALTER c2 SET DEFAULT 42, RENAME TO tt,
+ALGORITHM=INPLACE, LOCK=SHARED;
+
+# The output should be empty, because index->id was reassigned.
+-- source suite/innodb/include/innodb_dict.inc
+
+SHOW CREATE TABLE tt;
+# Non-instant ADD COLUMN would require the table to be rebuilt.
+--error ER_ALTER_OPERATION_NOT_SUPPORTED_REASON
+ALTER TABLE tt ADD COLUMN c CHAR(1) NOT NULL FIRST, LOCK=NONE;
+# This is still non-instant ADD COLUMN, because FTS_DOC_ID is hidden.
+--error ER_ALTER_OPERATION_NOT_SUPPORTED_REASON
+ALTER TABLE tt ADD COLUMN c CHAR(1) NOT NULL, LOCK=NONE;
+
+CREATE TABLE tu (
+ pk INT PRIMARY KEY, FTS_DOC_ID BIGINT UNSIGNED NOT NULL, t TEXT,
+ FULLTEXT INDEX(t)
+) ENGINE=InnoDB;
+--error ER_ALTER_OPERATION_NOT_SUPPORTED_REASON
+ALTER TABLE tu ADD COLUMN c CHAR(1) NOT NULL FIRST, LOCK=NONE;
+--error ER_ALTER_OPERATION_NOT_SUPPORTED_REASON
+ALTER TABLE tu ADD COLUMN c CHAR(1) NOT NULL, LOCK=NONE;
+DROP TABLE tu;
+
+CREATE TABLE tv (
+ pk INT PRIMARY KEY, FTS_DOC_ID BIGINT UNSIGNED NOT NULL, t TEXT,
+ UNIQUE INDEX FTS_DOC_ID_INDEX(FTS_DOC_ID),
+ FULLTEXT INDEX(t)
+) ENGINE=InnoDB;
+--error ER_ALTER_OPERATION_NOT_SUPPORTED_REASON
+ALTER TABLE tv ADD COLUMN c CHAR(1) NOT NULL FIRST, LOCK=NONE;
+--error ER_ALTER_OPERATION_NOT_SUPPORTED_REASON
+ALTER TABLE tv ADD COLUMN c CHAR(1) NOT NULL, LOCK=NONE;
+DROP TABLE tv;
+
+# DB_ROW_ID, DB_TRX_ID, DB_ROLL_PTR are reserved InnoDB system column names.
+--error ER_WRONG_COLUMN_NAME
+ALTER TABLE t1o CHANGE c1 dB_row_Id INT, ALGORITHM=COPY;
+--error ER_WRONG_COLUMN_NAME
+ALTER TABLE t1o CHANGE c1 dB_row_Id INT, ALGORITHM=INPLACE;
+--error ER_WRONG_COLUMN_NAME
+ALTER TABLE t1o CHANGE c1 DB_TRX_ID INT;
+--error ER_WRONG_COLUMN_NAME
+ALTER TABLE t1o CHANGE c1 db_roll_ptr INT;
+--error ER_WRONG_COLUMN_NAME
+ALTER TABLE t1o ADD COLUMN DB_TRX_ID INT;
+--error ER_WRONG_COLUMN_NAME
+ALTER TABLE t1o ADD COLUMN db_roll_ptr INT;
+
+--error ER_INNODB_FT_WRONG_DOCID_COLUMN
+ALTER TABLE t1o ADD FULLTEXT INDEX(ct), ADD COLUMN FTS_DOC_ID BIGINT;
+--error ER_INNODB_FT_WRONG_DOCID_COLUMN
+ALTER TABLE t1o ADD FULLTEXT INDEX(ct), ADD COLUMN FTS_DOC_ID BIGINT UNSIGNED;
+
+ALTER TABLE t1o ADD FULLTEXT INDEX(ct),
+ADD COLUMN FTS_DOC_ID BIGINT UNSIGNED NOT NULL;
+
+--error ER_DUP_FIELDNAME
+ALTER TABLE t1o ADD FULLTEXT INDEX(ct), ADD COLUMN FTS_DOC_ID INT;
+
+--error ER_ALTER_OPERATION_NOT_SUPPORTED_REASON
+ALTER TABLE t1o DROP COLUMN FTS_DOC_ID, ALGORITHM=INPLACE;
+
+ALTER TABLE t1o DROP COLUMN FTS_DOC_ID, DROP INDEX ct, ALGORITHM=INPLACE;
+
+# This creates a hidden FTS_DOC_ID column.
+ALTER TABLE t1o ADD FULLTEXT INDEX(ct), ADD COLUMN cu TEXT;
+
+--error ER_ALTER_OPERATION_NOT_SUPPORTED_REASON
+ALTER TABLE t1o ADD FULLTEXT INDEX(cu), ADD COLUMN FTS_DOC_ID BIGINT,
+ALGORITHM=INPLACE;
+--error ER_WRONG_COLUMN_NAME
+ALTER TABLE t1o ADD FULLTEXT INDEX(cu), ADD COLUMN FTS_DOC_ID BIGINT;
+--error ER_ALTER_OPERATION_NOT_SUPPORTED_REASON
+ALTER TABLE t1o ADD FULLTEXT INDEX(cu), ADD COLUMN FTS_DOC_ID BIGINT UNSIGNED,
+ALGORITHM=INPLACE;
+--error ER_WRONG_COLUMN_NAME
+ALTER TABLE t1o ADD FULLTEXT INDEX(cu), ADD COLUMN FTS_DOC_ID BIGINT UNSIGNED;
+
+# This would drop the hidden FTS_DOC_ID column and create
+# a fulltext index on ct and another fulltext index on cu.
+--error ER_ALTER_OPERATION_NOT_SUPPORTED_REASON
+ALTER TABLE t1o ADD FULLTEXT INDEX(cu),
+ADD COLUMN FTS_DOC_ID BIGINT UNSIGNED NOT NULL, ALGORITHM=INPLACE;
+
+# Replace the hidden FTS_DOC_ID column with a user-visible one.
+ALTER TABLE t1o ADD COLUMN FTS_DOC_ID BIGINT UNSIGNED NOT NULL,
+ALGORITHM=INPLACE;
+# Replace the user-visible FTS_DOC_ID column with a hidden one.
+# We do not support this in-place.
+--error ER_ALTER_OPERATION_NOT_SUPPORTED_REASON
+ALTER TABLE t1o DROP COLUMN FTS_DOC_ID, ALGORITHM=INPLACE;
+ALTER TABLE t1o DROP COLUMN FTS_DOC_ID;
+
+# FTS_DOC_ID is the internal row identifier for full-text search.
+# It should be of type BIGINT UNSIGNED NOT NULL.
+--error ER_WRONG_COLUMN_NAME
+ALTER TABLE t1o ADD FULLTEXT INDEX(ct), CHANGE c1 FTS_DOC_ID INT,
+ALGORITHM=COPY;
+
+--error ER_WRONG_COLUMN_NAME
+ALTER TABLE t1o ADD FULLTEXT INDEX(ct), CHANGE c1 FTS_DOC_ID INT,
+ALGORITHM=INPLACE;
+--error ER_WRONG_COLUMN_NAME
+ALTER TABLE t1o ADD FULLTEXT INDEX(ct), CHANGE c1 FTS_Doc_ID INT,
+ALGORITHM=INPLACE;
+--error ER_ALTER_OPERATION_NOT_SUPPORTED_REASON
+ALTER TABLE t1o ADD FULLTEXT INDEX(ct),
+CHANGE c1 FTS_DOC_ID BIGINT UNSIGNED NOT NULL,
+ALGORITHM=INPLACE;
+
+CREATE TABLE t1n LIKE t1o;
+
+ALTER TABLE t1n ADD FULLTEXT INDEX(ct);
+--error ER_WRONG_COLUMN_NAME
+ALTER TABLE t1n CHANGE c1 Fts_DOC_ID INT, ALGORITHM=INPLACE;
+--error ER_WRONG_COLUMN_NAME
+ALTER TABLE t1n CHANGE c1 Fts_DOC_ID INT, ALGORITHM=COPY;
+--error ER_BAD_FIELD_ERROR
+ALTER TABLE t1n CHANGE FTS_DOC_ID c11 INT, ALGORITHM=INPLACE;
+ALTER TABLE t1n CHANGE c1 FTS_DOC_ïD INT, ALGORITHM=INPLACE;
+
+ALTER TABLE t1n CHANGE FTS_DOC_ÏD c1 INT, ALGORITHM=INPLACE;
+ALTER TABLE t1n CHANGE c1 c2 INT, CHANGE c2 ct INT, CHANGE ct c1 TEXT,
+ALGORITHM=INPLACE;
+SHOW CREATE TABLE t1n;
+ALTER TABLE t1n CHANGE c2 c1 INT, CHANGE ct c2 INT, CHANGE c1 ct TEXT,
+ALGORITHM=COPY;
+SHOW CREATE TABLE t1n;
+
+--error ER_KEY_COLUMN_DOES_NOT_EXIST
+ALTER TABLE t1n ADD INDEX(c2), CHANGE c2 c4 INT, ALGORITHM=INPLACE;
+--error ER_KEY_COLUMN_DOES_NOT_EXIST
+ALTER TABLE t1n ADD INDEX(c2), CHANGE c2 c4 INT, ALGORITHM=COPY;
+ALTER TABLE t1n ADD INDEX(c4), CHANGE c2 c4 INT, ALGORITHM=INPLACE;
+SHOW CREATE TABLE t1n;
+ALTER TABLE t1n DROP INDEX c4;
+--error ER_DUP_FIELDNAME
+ALTER TABLE t1n CHANGE c4 c1 INT, ADD INDEX(c1), ALGORITHM=INPLACE;
+ALTER TABLE t1n CHANGE c4 c11 INT, ADD INDEX(c11), ALGORITHM=INPLACE;
+
+SHOW CREATE TABLE t1n;
+DROP TABLE t1n;
+
+--error ER_ALTER_OPERATION_NOT_SUPPORTED_REASON
+ALTER TABLE t1o MODIFY c1 BIGINT UNSIGNED NOT NULL, DROP INDEX ct,
+ALGORITHM=INPLACE;
+
+# This will copy the table, removing the hidden FTS_DOC_ID column.
+ALTER TABLE t1o MODIFY c1 BIGINT UNSIGNED NOT NULL, DROP INDEX ct;
+
+ALTER TABLE t1o CHANGE c1 FTS_DOC_ID BIGINT UNSIGNED NOT NULL,
+ALGORITHM=INPLACE;
+
+ALTER TABLE t1o ADD FULLTEXT INDEX(ct), ALGORITHM=INPLACE;
+
+--error ER_ALTER_OPERATION_NOT_SUPPORTED_REASON
+ALTER TABLE t1o CHANGE FTS_DOC_ID foo_id BIGINT UNSIGNED NOT NULL,
+ALGORITHM=INPLACE;
+
+# This should not show duplicates.
+SELECT sc.pos FROM information_schema.innodb_sys_columns sc
+INNER JOIN information_schema.innodb_sys_tables st
+ON sc.TABLE_ID=st.TABLE_ID
+WHERE st.NAME='test/t1o' AND sc.NAME='FTS_DOC_ID';
+
+SHOW CREATE TABLE t1o;
+
+ALTER TABLE t1o CHANGE FTS_DOC_ID foo_id BIGINT UNSIGNED NOT NULL,
+DROP INDEX ct, ALGORITHM=INPLACE;
+
+SHOW CREATE TABLE t1o;
+
+DROP TABLE t1c, t1p, sys_tables, sys_indexes, sys_foreign;
+
+# Check the internal schemata of tt, t1o.
+
+CREATE TABLE sys_tables SELECT * FROM INFORMATION_SCHEMA.INNODB_SYS_TABLES
+WHERE NAME='test/t1o';
+CREATE TABLE sys_indexes SELECT i.* FROM INFORMATION_SCHEMA.INNODB_SYS_INDEXES i
+INNER JOIN sys_tables st ON i.TABLE_ID=st.TABLE_ID;
+CREATE TABLE sys_foreign SELECT i.*
+FROM INFORMATION_SCHEMA.INNODB_SYS_FOREIGN i WHERE FOR_NAME='test/t1o';
+
+-- source suite/innodb/include/innodb_dict.inc
+
+# Ensure that there exists no hidden FTS_DOC_ID_INDEX on foo_id.
+
+ALTER TABLE t1o ADD UNIQUE INDEX FTS_DOC_ID_INDEX(FTS_DOC_ID),
+ADD FULLTEXT INDEX(ct),
+CHANGE foo_id FTS_DOC_ID BIGINT UNSIGNED NOT NULL;
+
+ALTER TABLE t1o DROP INDEX ct, DROP INDEX FTS_DOC_ID_INDEX,
+CHANGE FTS_DOC_ID foo_id BIGINT UNSIGNED NOT NULL;
+
+ALTER TABLE t1o ADD UNIQUE INDEX FTS_DOC_ID_INDEX(foo_id);
+
+ALTER TABLE t1o CHANGE foo_id FTS_DOC_ID BIGINT UNSIGNED NOT NULL,
+ADD FULLTEXT INDEX(ct);
+
+DROP TABLE sys_indexes;
+CREATE TABLE sys_indexes SELECT i.* FROM INFORMATION_SCHEMA.INNODB_SYS_INDEXES i
+INNER JOIN sys_tables st ON i.TABLE_ID=st.TABLE_ID;
+
+-- source suite/innodb/include/innodb_dict.inc
+
+DROP TABLE tt, t1o, sys_tables, sys_indexes, sys_foreign;
+
+CREATE TABLE t (t TEXT, FULLTEXT(t)) ENGINE=InnoDB;
+DROP INDEX t ON t;
+
+LET $regexp=/FTS_([0-9a-f_]+)([A-Z_]+)/FTS_AUX_\2/;
+--replace_regex $regexp
+SELECT SUBSTRING(name, LOCATE('_', name) - 3, 5) AS prefix, name
+FROM INFORMATION_SCHEMA.INNODB_SYS_TABLES
+WHERE name LIKE '%FTS_%' ORDER BY 1, 2;
+
+SELECT sc.pos, sc.NAME FROM information_schema.innodb_sys_columns sc
+INNER JOIN information_schema.innodb_sys_tables st
+ON sc.TABLE_ID=st.TABLE_ID
+WHERE st.NAME='test/t';
+
+ALTER TABLE t ROW_FORMAT=REDUNDANT, ALGORITHM=INPLACE;
+
+--replace_regex $regexp
+SELECT SUBSTRING(name, LOCATE('_', name) - 3, 5) AS prefix, name
+FROM INFORMATION_SCHEMA.INNODB_SYS_TABLES
+WHERE name LIKE '%FTS_%' ORDER BY 1, 2;
+
+ALTER TABLE t ADD FULLTEXT INDEX(t);
+
+SELECT sc.pos, sc.NAME FROM information_schema.innodb_sys_columns sc
+INNER JOIN information_schema.innodb_sys_tables st
+ON sc.TABLE_ID=st.TABLE_ID
+WHERE st.NAME='test/t';
+
+DROP TABLE t;
+
+--disable_query_log
+call mtr.add_suppression("deleting orphaned .ibd file");
+--enable_query_log
+
+--echo #
+--echo # Bug #19465984 INNODB DATA DICTIONARY IS NOT UPDATED WHILE
+--echo # RENAMING THE COLUMN
+--echo #
+CREATE TABLE t1(c1 INT NOT NULL, PRIMARY KEY(c1))ENGINE=INNODB;
+CREATE TABLE t2(c2 INT NOT NULL, FOREIGN KEY(c2) REFERENCES t1(c1))ENGINE=INNODB;
+SHOW CREATE TABLE t1;
+SHOW CREATE TABLE t2;
+ALTER TABLE t1 CHANGE COLUMN c1 C1 INT;
+ALTER TABLE t2 CHANGE COLUMN c2 C2 INT;
+SHOW CREATE TABLE t1;
+SHOW CREATE TABLE t2;
+ALTER TABLE t1 CHANGE COLUMN C1 c5 INT;
+ALTER TABLE t2 CHANGE COLUMN C2 c6 INT;
+SHOW CREATE TABLE t1;
+SHOW CREATE TABLE t2;
+
+SELECT C.NAME FROM INFORMATION_SCHEMA.INNODB_SYS_COLUMNS C INNER JOIN
+ INFORMATION_SCHEMA.INNODB_SYS_TABLES T ON C.TABLE_ID=T.TABLE_ID
+ WHERE T.NAME='test/t1';
+
+SELECT F.NAME FROM INFORMATION_SCHEMA.INNODB_SYS_FIELDS F INNER JOIN
+ INFORMATION_SCHEMA.INNODB_SYS_INDEXES I ON F.INDEX_ID=I.INDEX_ID INNER JOIN
+ INFORMATION_SCHEMA.INNODB_SYS_TABLES T ON I.TABLE_ID=T.TABLE_ID
+ WHERE T.NAME='test/t1' AND I.NAME='PRIMARY';
+
+SELECT C.REF_COL_NAME, C.FOR_COL_NAME FROM INFORMATION_SCHEMA.INNODB_SYS_FOREIGN_COLS C INNER JOIN
+ INFORMATION_SCHEMA.INNODB_SYS_FOREIGN F ON C.ID=F.ID
+ WHERE F.FOR_NAME='test/t2';
+
+DROP TABLE t2, t1;
+--echo # virtual columns case too
+CREATE TABLE t1 (a INT, b INT GENERATED ALWAYS AS (a) VIRTUAL) ENGINE = InnoDB;
+ALTER TABLE t1 CHANGE COLUMN a A INT;
+SHOW CREATE TABLE t1;
+SELECT C.NAME FROM INFORMATION_SCHEMA.INNODB_SYS_COLUMNS C INNER JOIN
+ INFORMATION_SCHEMA.INNODB_SYS_TABLES T ON C.TABLE_ID=T.TABLE_ID
+ WHERE T.NAME='test/t1';
+DROP TABLE t1;
+
+
+--echo # different FOREIGN KEY cases
+CREATE TABLE t1 (
+ a INT UNIQUE KEY,
+ b INT UNIQUE KEY,
+ c INT UNIQUE KEY,
+ d INT UNIQUE KEY
+) ENGINE=INNODB;
+CREATE TABLE t2 (
+ aa INT,
+ bb INT,
+ cc INT,
+ dd INT
+) ENGINE=INNODB;
+
+INSERT INTO t1 VALUES (1, 1, 1, 1);
+INSERT INTO t2 VALUES (1, 1, 1, 1);
+
+ALTER TABLE t1 CHANGE a A INT, ALGORITHM=INPLACE;
+ALTER TABLE t1 CHANGE c C INT, ALGORITHM=INPLACE;
+ALTER TABLE t2 CHANGE cc CC INT, ALGORITHM=INPLACE;
+ALTER TABLE t2 CHANGE dd DD INT, ALGORITHM=INPLACE;
+
+SET foreign_key_checks=0;
+ALTER TABLE t2
+ ADD FOREIGN KEY(aa) REFERENCES t1(a),
+ ADD FOREIGN KEY(bb) REFERENCES t1(b),
+ ADD FOREIGN KEY(cc) REFERENCES t1(c),
+ ADD FOREIGN KEY(dd) REFERENCES t1(d),
+ ALGORITHM=INPLACE;
+
+ALTER TABLE t1 CHANGE b B INT, ALGORITHM=INPLACE;
+ALTER TABLE t2 CHANGE aa AA INT, ALGORITHM=INPLACE;
+
+--source include/restart_mysqld.inc
+
+ALTER TABLE t1 CHANGE d D INT, ALGORITHM=INPLACE;
+ALTER TABLE t2 CHANGE bb BB INT, ALGORITHM=INPLACE;
+SHOW CREATE TABLE t1;
+SHOW CREATE TABLE t2;
+
+--error ER_ROW_IS_REFERENCED_2
+DELETE FROM t1 WHERE a=1;
+--error ER_ROW_IS_REFERENCED_2
+DELETE FROM t1 WHERE A=1;
+
+--error ER_ROW_IS_REFERENCED_2
+DELETE FROM t1 WHERE b=1;
+--error ER_ROW_IS_REFERENCED_2
+DELETE FROM t1 WHERE B=1;
+
+--error ER_ROW_IS_REFERENCED_2
+DELETE FROM t1 WHERE c=1;
+--error ER_ROW_IS_REFERENCED_2
+DELETE FROM t1 WHERE C=1;
+
+--error ER_ROW_IS_REFERENCED_2
+DELETE FROM t1 WHERE d=1;
+--error ER_ROW_IS_REFERENCED_2
+DELETE FROM t1 WHERE D=1;
+
+DROP TABLE t2, t1;
+
+--echo # virtual columns case too
+CREATE TABLE t1 (a INT, b INT GENERATED ALWAYS AS (a) VIRTUAL) ENGINE = InnoDB;
+ALTER TABLE t1 CHANGE COLUMN a A INT;
+SHOW CREATE TABLE t1;
+SELECT C.NAME FROM INFORMATION_SCHEMA.INNODB_SYS_COLUMNS C INNER JOIN
+ INFORMATION_SCHEMA.INNODB_SYS_TABLES T ON C.TABLE_ID=T.TABLE_ID
+ WHERE T.NAME='test/t1';
+DROP TABLE t1;
+
+--echo # and an MDEV-18041 regression related to indexes prefixes
+create table `test` (
+ `test_old` varchar(255) NOT NULL,
+ `other` varchar(255) NOT NULL,
+ PRIMARY KEY (`test_old`,`other`),
+ UNIQUE KEY uk (`test_old`(100), `other`)
+) ENGINE=InnoDB;
+
+select name, pos from information_schema.innodb_SYS_FIELDS where name in ('test_old', 'other', 'test_new');
+alter table `test` CHANGE COLUMN `test_old` `test_new` varchar(255) NOT NULL;
+select name, pos from information_schema.innodb_SYS_FIELDS where name in ('test_old', 'other', 'test_new');
+drop table `test`;
+
+
+--echo #
+--echo # BUG 20029625 - HANDLE_FATAL_SIGNAL (SIG=11) IN
+--echo # DICT_MEM_TABLE_COL_RENAME_LOW
+--echo #
+CREATE TABLE parent(a INT, b INT, KEY(a, b)) ENGINE = InnoDB;
+CREATE TABLE t1(a1 INT, a2 INT) ENGINE = InnoDB;
+
+set foreign_key_checks=0;
+ALTER TABLE t1 ADD CONSTRAINT fk_a FOREIGN KEY(a1, a2) REFERENCES parent(a, b) ON DELETE SET NULL ON UPDATE CASCADE;
+
+ALTER TABLE t1 CHANGE a2 a3 INT,ADD CONSTRAINT fk_1 FOREIGN KEY(a1, a3) REFERENCES parent(a, b) ON DELETE SET NULL ON UPDATE CASCADE;
+SHOW CREATE TABLE t1;
+CHECK TABLE t1;
+
+ALTER TABLE t1 CHANGE a3 a4 INT;
+SHOW CREATE TABLE t1;
+CHECK TABLE t1;
+
+ALTER TABLE parent CHANGE b c INT;
+SHOW CREATE TABLE t1;
+CHECK TABLE t1;
+
+DROP TABLE t1, parent;
+
+--echo #
+--echo #BUG#21514135 SCHEMA MISMATCH ERROR WHEN IMPORTING TABLESPACE AFTER
+--echo #DROPPING AN INDEX
+--echo #
+
+--disable_query_log
+call mtr.add_suppression("\\[Warning\\] InnoDB: Unknown index id .* on page");
+--enable_query_log
+
+let $source_db = source_db;
+let $dest_db = dest_db;
+
+SET NAMES utf8mb4;
+
+eval CREATE DATABASE $source_db;
+eval CREATE DATABASE $dest_db;
+
+eval CREATE TABLE $source_db.t1 (
+ id int(11) NOT NULL,
+ age int(11) DEFAULT NULL,
+ name varchar(20),
+ PRIMARY KEY (id),
+ KEY index1 (age)
+ ) ENGINE=InnoDB;
+
+eval ALTER TABLE $source_db.t1 DROP INDEX index1, ADD INDEX index2(name, age), algorithm=inplace;
+
+--source suite/innodb/include/import.inc
+
+eval ALTER TABLE $source_db.t1 DROP INDEX index2, algorithm=inplace;
+
+--source suite/innodb/include/import.inc
+
+eval DROP TABLE $source_db.t1;
+eval DROP DATABASE $source_db;
+eval DROP DATABASE $dest_db;
+
+--echo #
+--echo # BUG #26334149 MYSQL CRASHES WHEN FULL TEXT INDEXES IBD FILES ARE
+--echo # ORPHANED DUE TO RENAME TABLE
+--echo #
+CREATE DATABASE db1; USE db1;
+--disable_query_log
+SET @save_innodb_read_only_compressed=@@GLOBAL.innodb_read_only_compressed;
+SET GLOBAL innodb_read_only_compressed=OFF;
+--enable_query_log
+CREATE TABLE notes (
+ id int(11) NOT NULL AUTO_INCREMENT,
+ body text COLLATE utf8_unicode_ci,
+ PRIMARY KEY (id)
+ ) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8
+COLLATE=utf8_unicode_ci
+ROW_FORMAT=COMPRESSED;
+
+ALTER TABLE notes ADD FULLTEXT INDEX index_ft_body (body(255));
+DROP INDEX index_ft_body ON notes;
+--disable_query_log
+SET GLOBAL innodb_read_only_compressed=@save_innodb_read_only_compressed;
+--enable_query_log
+
+CREATE DATABASE db2;
+RENAME TABLE db1.notes TO db2.notes;
+DROP DATABASE db1;
+DROP DATABASE db2;
+
+USE test;
+
+#
+# End of 10.1 tests
+#
+
+--echo #
+--echo # MDEV-14038 ALTER TABLE does not exit on error with InnoDB + bad default function
+--echo #
+
+CREATE TABLE t1 (a INT NOT NULL DEFAULT 0) ENGINE=InnoDB;
+iNSERT INTO t1 VALUES (10);
+--error ER_WARN_DATA_OUT_OF_RANGE
+ALTER TABLE t1 ADD b TINYINT NOT NULL DEFAULT if(unix_timestamp()>1,1000,0);
+SELECT * FROM t1;
+DROP TABLE t1;
+
+# DATETIME-to-DATE truncation is OK
+CREATE TABLE t1 (a INT NOT NULL DEFAULT 0) ENGINE=InnoDB;
+INSERT INTO t1 VALUES (10);
+--enable_info
+ALTER TABLE t1 ADD b DATE NOT NULL DEFAULT if(unix_timestamp()>1,TIMESTAMP'2001-01-01 10:20:30',0), algorithm=copy;
+--disable_info
+SELECT * FROM t1;
+DROP TABLE t1;
+
+# DATETIME-to-TIME truncation is OK
+CREATE TABLE t1 (a INT NOT NULL DEFAULT 0) ENGINE=InnoDB;
+iNSERT INTO t1 VALUES (10);
+--enable_info
+ALTER TABLE t1 ADD b TIME NOT NULL DEFAULT if(unix_timestamp()>1,TIMESTAMP'2001-01-01 10:20:30',0);
+--disable_info
+SELECT * FROM t1;
+DROP TABLE t1;
+
+--echo #
+--echo # MDEV-18042 Server crashes in mysql_alter_table upon adding a non-null
+--echo # date column under NO_ZERO_DATE with ALGORITHM=INPLACE
+--echo #
+
+SET @OLD_SQL_MODE= @@SQL_MODE;
+SET @@SQL_MODE= 'NO_ZERO_DATE';
+CREATE OR REPLACE TABLE t1 (i INT) ENGINE=MyISAM;
+--error ER_ALTER_OPERATION_NOT_SUPPORTED
+ALTER TABLE t1 ADD COLUMN d DATE NOT NULL, ALGORITHM=INPLACE;
+
+CREATE OR REPLACE TABLE t1 (i INT) ENGINE=InnoDB;
+--error ER_BAD_FIELD_ERROR
+ALTER TABLE t1 ADD d DATETIME NOT NULL CHECK (f <= 0), ALGORITHM=COPY;
+
+CREATE OR REPLACE TABLE t1 (a int) ENGINE=InnoDB;
+ALTER TABLE t1 ADD COLUMN b DATETIME NOT NULL, LOCK=NONE;
+
+--echo # Cleanup
+SET @@SQL_MODE= @OLD_SQL_MODE;
+DROP TABLE t1;
+
+#
+# End of 10.2 tests
+#
diff --git a/mysql-test/suite/innodb/t/innodb-analyze.test b/mysql-test/suite/innodb/t/innodb-analyze.test
new file mode 100644
index 00000000..db699ad4
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb-analyze.test
@@ -0,0 +1,60 @@
+--source include/have_innodb.inc
+#
+# Test that mysqld does not crash when running ANALYZE TABLE with
+# different values of the parameter innodb_stats_transient_sample_pages.
+#
+
+# we care only that the following SQL commands do not produce errors
+# and do not crash the server
+-- disable_query_log
+-- enable_warnings
+
+SET @save_sample_pages = @@GLOBAL.innodb_stats_transient_sample_pages;
+SET GLOBAL innodb_stats_transient_sample_pages=0;
+SHOW VARIABLES LIKE 'innodb_stats_transient_sample_pages';
+-- disable_result_log
+
+CREATE TABLE innodb_analyze (
+ a INT,
+ b INT,
+ KEY(a),
+ KEY(b,a)
+) ENGINE=InnoDB;
+
+# test with empty table
+
+ANALYZE TABLE innodb_analyze;
+
+SET GLOBAL innodb_stats_transient_sample_pages=2;
+ANALYZE TABLE innodb_analyze;
+
+SET GLOBAL innodb_stats_transient_sample_pages=4;
+ANALYZE TABLE innodb_analyze;
+
+SET GLOBAL innodb_stats_transient_sample_pages=8;
+ANALYZE TABLE innodb_analyze;
+
+SET GLOBAL innodb_stats_transient_sample_pages=16;
+ANALYZE TABLE innodb_analyze;
+
+INSERT INTO innodb_analyze VALUES
+(1,1), (1,1), (1,2), (1,3), (1,4), (1,5),
+(8,1), (8,8), (8,2), (7,1), (1,4), (3,5);
+
+SET GLOBAL innodb_stats_transient_sample_pages=1;
+ANALYZE TABLE innodb_analyze;
+
+SET GLOBAL innodb_stats_transient_sample_pages=2;
+ANALYZE TABLE innodb_analyze;
+
+SET GLOBAL innodb_stats_transient_sample_pages=4;
+ANALYZE TABLE innodb_analyze;
+
+SET GLOBAL innodb_stats_transient_sample_pages=8;
+ANALYZE TABLE innodb_analyze;
+
+SET GLOBAL innodb_stats_transient_sample_pages=16;
+ANALYZE TABLE innodb_analyze;
+
+DROP TABLE innodb_analyze;
+SET GLOBAL innodb_stats_transient_sample_pages = @save_sample_pages;
diff --git a/mysql-test/suite/innodb/t/innodb-autoinc-18274.test b/mysql-test/suite/innodb/t/innodb-autoinc-18274.test
new file mode 100644
index 00000000..006982ce
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb-autoinc-18274.test
@@ -0,0 +1,26 @@
+--source include/have_innodb.inc
+# embedded server ignores 'delayed', so skip this
+-- source include/not_embedded.inc
+
+--disable_warnings
+drop table if exists t1;
+--enable_warnings
+
+#
+# Bug #18274 InnoDB auto_increment field reset on OPTIMIZE TABLE
+SET @@SESSION.AUTO_INCREMENT_INCREMENT=1, @@SESSION.AUTO_INCREMENT_OFFSET=1;
+CREATE TABLE t1 (c1 INT PRIMARY KEY AUTO_INCREMENT) ENGINE=InnoDB;
+INSERT INTO t1 VALUES (null);
+SHOW CREATE TABLE t1;
+DELETE FROM t1;
+OPTIMIZE TABLE t1;
+SHOW CREATE TABLE t1;
+INSERT INTO t1 VALUES(null);
+SELECT * FROM t1;
+DROP TABLE t1;
+
+#
+# restore environment to the state it was before this test execution
+#
+
+-- disable_query_log
diff --git a/mysql-test/suite/innodb/t/innodb-autoinc-44030.test b/mysql-test/suite/innodb/t/innodb-autoinc-44030.test
new file mode 100644
index 00000000..61c56127
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb-autoinc-44030.test
@@ -0,0 +1,36 @@
+-- source include/have_innodb.inc
+# embedded server does not support restarting
+-- source include/not_embedded.inc
+
+# Before MDEV-6076 Persistent AUTO_INCREMENT for InnoDB
+# this was a test for
+# Bug #44030: Error: (1500) Couldn't read the MAX(ID) autoinc value from
+# the index (PRIMARY)
+# This test requires a restart of the server
+SET @@SESSION.AUTO_INCREMENT_INCREMENT=1, @@SESSION.AUTO_INCREMENT_OFFSET=1;
+CREATE TABLE t1 (c1 INT PRIMARY KEY AUTO_INCREMENT) ENGINE=InnoDB;
+INSERT INTO t1 VALUES (null);
+INSERT INTO t1 VALUES (null);
+--enable_info
+ALTER TABLE t1 CHANGE c1 d1 INT NOT NULL AUTO_INCREMENT;
+--disable_info
+SELECT * FROM t1;
+-- source include/restart_mysqld.inc
+SHOW CREATE TABLE t1;
+INSERT INTO t1 VALUES(null);
+SELECT * FROM t1;
+
+# Before WL#5534, the following statement would copy the table,
+# and effectively set AUTO_INCREMENT to 4, because while copying
+# it would write values 1,2,3 to the column.
+# WL#5534 makes this an in-place ALTER, setting AUTO_INCREMENT=3 for real.
+# However, to keep compatibility with ALGORITHM=COPY MySQL 5.6.11 will
+# go back to the original behaviour, setting AUTO_INCREMENT to 4.
+--enable_info
+ALTER TABLE t1 AUTO_INCREMENT = 3;
+--disable_info
+SHOW CREATE TABLE t1;
+INSERT INTO t1 VALUES(null);
+INSERT INTO t1 VALUES(null);
+SELECT * FROM t1;
+DROP TABLE t1;
diff --git a/mysql-test/suite/innodb/t/innodb-autoinc-56228-master.opt b/mysql-test/suite/innodb/t/innodb-autoinc-56228-master.opt
new file mode 100644
index 00000000..b21ee4fb
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb-autoinc-56228-master.opt
@@ -0,0 +1 @@
+--loose-innodb_autoinc_lock_mode=0
diff --git a/mysql-test/suite/innodb/t/innodb-autoinc-56228.test b/mysql-test/suite/innodb/t/innodb-autoinc-56228.test
new file mode 100644
index 00000000..a02f7b43
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb-autoinc-56228.test
@@ -0,0 +1,34 @@
+--source include/have_innodb.inc
+##
+# Bug #56228: dropping tables from within an active statement crashes server
+#
+DROP TABLE IF EXISTS t1_56228;
+DROP TABLE IF EXISTS t2_56228;
+DROP FUNCTION IF EXISTS bug56228;
+
+CREATE TEMPORARY TABLE t1_56228(
+ c1 iNT AUTO_INCREMENT PRIMARY KEY) ENGINE=InnoDB;
+CREATE TEMPORARY TABLE t2_56228(
+ c1 iNT AUTO_INCREMENT PRIMARY KEY) ENGINE=InnoDB;
+
+DELIMITER //;
+
+CREATE FUNCTION bug56228() RETURNS INT DETERMINISTIC
+BEGIN
+ INSERT INTO t1_56228 VALUES(NULL);
+ INSERT INTO t2_56228 VALUES(NULL);
+ INSERT INTO t1_56228 VALUES(NULL);
+ INSERT INTO t2_56228 VALUES(NULL);
+ DROP TEMPORARY TABLE t1_56228;
+ RETURN 42;
+END //
+
+DELIMITER ;//
+
+--disable_ps_protocol
+SELECT bug56228();
+--enable_ps2_protocol
+
+DROP FUNCTION bug56228;
+DROP TEMPORARY TABLE t2_56228;
+DROP TEMPORARY TABLE IF EXISTS t1_56228;
diff --git a/mysql-test/suite/innodb/t/innodb-autoinc-61209.test b/mysql-test/suite/innodb/t/innodb-autoinc-61209.test
new file mode 100644
index 00000000..0b285fb2
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb-autoinc-61209.test
@@ -0,0 +1,43 @@
+# This is the test case for bug #61209 - duplicate key errors
+# when using auto_increment_increment > 1 and auto_increment_offset > 1
+#
+--source include/have_innodb.inc
+
+#
+# Precautionary clean up.
+#
+--disable_warnings
+DROP TABLE IF EXISTS bug_61209;
+--enable_warnings
+
+#
+# Create test data.
+#
+CREATE TABLE bug_61209 (a INT auto_increment, PRIMARY KEY(a)) ENGINE=InnoDB;
+
+INSERT INTO bug_61209 VALUES (), (), (), ();
+
+--connect (con1,localhost,root,,)
+--connect (con2,localhost,root,,)
+
+--connection con1
+SET SESSION auto_increment_increment=3;
+SET SESSION auto_increment_offset=2;
+SELECT GET_LOCK('a', 9);
+
+--connection con2
+SET SESSION auto_increment_increment=3;
+SET SESSION auto_increment_offset=2;
+send INSERT INTO bug_61209 (a) VALUES (NULL), (NULL), (NULL + GET_LOCK('a', 10));
+
+--connection con1
+INSERT INTO bug_61209 (a) VALUES (NULL), (NULL), (NULL);
+SELECT RELEASE_LOCK('a');
+
+--connection con2
+reap;
+
+#
+# Clean up
+#
+DROP TABLE bug_61209;
diff --git a/mysql-test/suite/innodb/t/innodb-autoinc-optimize.test b/mysql-test/suite/innodb/t/innodb-autoinc-optimize.test
new file mode 100644
index 00000000..8fc34e94
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb-autoinc-optimize.test
@@ -0,0 +1,19 @@
+--source include/have_innodb.inc
+# embedded server ignores 'delayed', so skip this
+-- source include/not_embedded.inc
+
+--disable_warnings
+drop table if exists t1;
+--enable_warnings
+
+#
+# Bug 34286
+#
+create table t1(a int not null auto_increment primary key) engine=innodb;
+insert into t1 set a = -1;
+# NOTE: The database needs to be shutdown and restarted (here) for
+# the test to work. It's included for reference only.
+optimize table t1;
+
+--echo ==== clean up ====
+DROP TABLE t1;
diff --git a/mysql-test/suite/innodb/t/innodb-autoinc-part.test b/mysql-test/suite/innodb/t/innodb-autoinc-part.test
new file mode 100644
index 00000000..10054670
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb-autoinc-part.test
@@ -0,0 +1,24 @@
+--source include/have_partition.inc
+--source include/have_innodb.inc
+
+--echo #
+--echo # MDEV-28416 Incorrect AUTO_INCREMENT may be issued
+--echo #
+
+SET @aii=@@auto_increment_increment;
+SET auto_increment_increment=300;
+
+CREATE TABLE t1 (a SERIAL) ENGINE=innodb
+PARTITION BY RANGE (a) (
+ PARTITION p0 VALUES LESS THAN (6),
+ PARTITION p1 VALUES LESS THAN MAXVALUE
+);
+INSERT INTO t1 VALUES (18446744073709551613);
+SHOW CREATE TABLE t1;
+--error HA_ERR_AUTOINC_ERANGE
+INSERT INTO t1 VALUES (NULL);
+SHOW CREATE TABLE t1;
+DROP TABLE t1;
+SET auto_increment_increment=@aii;
+
+--echo # End of 10.2 tests
diff --git a/mysql-test/suite/innodb/t/innodb-autoinc.opt b/mysql-test/suite/innodb/t/innodb-autoinc.opt
new file mode 100644
index 00000000..303ec1be
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb-autoinc.opt
@@ -0,0 +1,3 @@
+--default-storage-engine=MyISAM
+--innodb-strict-mode=0
+--innodb-file-per-table=0
diff --git a/mysql-test/suite/innodb/t/innodb-autoinc.test b/mysql-test/suite/innodb/t/innodb-autoinc.test
new file mode 100644
index 00000000..15846055
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb-autoinc.test
@@ -0,0 +1,783 @@
+--source include/have_innodb.inc
+
+#
+# Bug #34335
+#
+CREATE TABLE t1 (c1 BIGINT PRIMARY KEY AUTO_INCREMENT, c2 VARCHAR(10)) ENGINE=InnoDB;
+INSERT INTO t1 VALUES (9223372036854775807, null);
+-- error 167
+INSERT INTO t1 (c2) VALUES ('innodb');
+SELECT * FROM t1;
+DROP TABLE t1;
+#
+## Test AUTOINC overflow
+##
+
+# TINYINT
+CREATE TABLE t1 (c1 TINYINT PRIMARY KEY AUTO_INCREMENT, c2 VARCHAR(10)) ENGINE=InnoDB;
+INSERT INTO t1 VALUES (127, null);
+-- error 167
+INSERT INTO t1 (c2) VALUES ('innodb');
+SELECT * FROM t1;
+DROP TABLE t1;
+
+CREATE TABLE t1 (c1 TINYINT UNSIGNED PRIMARY KEY AUTO_INCREMENT, c2 VARCHAR(10)) ENGINE=InnoDB;
+INSERT INTO t1 VALUES (255, null);
+-- error 167
+INSERT INTO t1 (c2) VALUES ('innodb');
+SELECT * FROM t1;
+DROP TABLE t1;
+#
+# SMALLINT
+#
+CREATE TABLE t1 (c1 SMALLINT PRIMARY KEY AUTO_INCREMENT, c2 VARCHAR(10)) ENGINE=InnoDB;
+INSERT INTO t1 VALUES (32767, null);
+-- error 167
+INSERT INTO t1 (c2) VALUES ('innodb');
+SELECT * FROM t1;
+DROP TABLE t1;
+
+CREATE TABLE t1 (c1 SMALLINT UNSIGNED PRIMARY KEY AUTO_INCREMENT, c2 VARCHAR(10)) ENGINE=InnoDB;
+INSERT INTO t1 VALUES (65535, null);
+-- error 167
+INSERT INTO t1 (c2) VALUES ('innodb');
+SELECT * FROM t1;
+DROP TABLE t1;
+#
+# MEDIUMINT
+#
+CREATE TABLE t1 (c1 MEDIUMINT PRIMARY KEY AUTO_INCREMENT, c2 VARCHAR(10)) ENGINE=InnoDB;
+INSERT INTO t1 VALUES (8388607, null);
+-- error 167
+INSERT INTO t1 (c2) VALUES ('innodb');
+SELECT * FROM t1;
+DROP TABLE t1;
+
+CREATE TABLE t1 (c1 MEDIUMINT UNSIGNED PRIMARY KEY AUTO_INCREMENT, c2 VARCHAR(10)) ENGINE=InnoDB;
+INSERT INTO t1 VALUES (16777215, null);
+-- error 167
+INSERT INTO t1 (c2) VALUES ('innodb');
+SELECT * FROM t1;
+DROP TABLE t1;
+#
+# INT
+#
+CREATE TABLE t1 (c1 INT PRIMARY KEY AUTO_INCREMENT, c2 VARCHAR(10)) ENGINE=InnoDB;
+INSERT INTO t1 VALUES (2147483647, null);
+-- error 167
+INSERT INTO t1 (c2) VALUES ('innodb');
+SELECT * FROM t1;
+DROP TABLE t1;
+
+CREATE TABLE t1 (c1 INT UNSIGNED PRIMARY KEY AUTO_INCREMENT, c2 VARCHAR(10)) ENGINE=InnoDB;
+INSERT INTO t1 VALUES (4294967295, null);
+-- error 167
+INSERT INTO t1 (c2) VALUES ('innodb');
+SELECT * FROM t1;
+DROP TABLE t1;
+#
+# BIGINT
+#
+CREATE TABLE t1 (c1 BIGINT PRIMARY KEY AUTO_INCREMENT, c2 VARCHAR(10)) ENGINE=InnoDB;
+INSERT INTO t1 VALUES (9223372036854775807, null);
+-- error 167
+INSERT INTO t1 (c2) VALUES ('innodb');
+SELECT * FROM t1;
+DROP TABLE t1;
+
+CREATE TABLE t1 (c1 BIGINT UNSIGNED PRIMARY KEY AUTO_INCREMENT, c2 VARCHAR(10)) ENGINE=InnoDB;
+INSERT INTO t1 VALUES (18446744073709551615, null);
+-- error ER_AUTOINC_READ_FAILED,1467
+INSERT INTO t1 (c2) VALUES ('innodb');
+SELECT * FROM t1;
+DROP TABLE t1;
+
+#
+# Bug 37531
+# After truncate, auto_increment behaves incorrectly for InnoDB
+#
+CREATE TABLE t1(c1 INT PRIMARY KEY AUTO_INCREMENT) ENGINE=InnoDB;
+INSERT INTO t1 VALUES (1), (2), (3);
+INSERT INTO t1 VALUES (NULL), (NULL), (NULL);
+SELECT c1 FROM t1;
+SHOW CREATE TABLE t1;
+TRUNCATE TABLE t1;
+SHOW CREATE TABLE t1;
+INSERT INTO t1 VALUES (1), (2), (3);
+INSERT INTO t1 VALUES (NULL), (NULL), (NULL);
+SELECT c1 FROM t1;
+SHOW CREATE TABLE t1;
+DROP TABLE t1;
+
+#
+# Deleting all records should not reset the AUTOINC counter.
+#
+CREATE TABLE t1(c1 INT PRIMARY KEY AUTO_INCREMENT) ENGINE=InnoDB;
+INSERT INTO t1 VALUES (1), (2), (3);
+INSERT INTO t1 VALUES (NULL), (NULL), (NULL);
+SELECT c1 FROM t1;
+SHOW CREATE TABLE t1;
+DELETE FROM t1;
+SHOW CREATE TABLE t1;
+INSERT INTO t1 VALUES (1), (2), (3);
+INSERT INTO t1 VALUES (NULL), (NULL), (NULL);
+SELECT c1 FROM t1;
+SHOW CREATE TABLE t1;
+DROP TABLE t1;
+
+#
+# Bug 38839
+# Reset the last value generated at end of statement
+#
+DROP TABLE IF EXISTS t1;
+CREATE TABLE t1 (c1 INT AUTO_INCREMENT, c2 INT, PRIMARY KEY(c1)) ENGINE=InnoDB;
+INSERT INTO t1 VALUES (NULL, 1);
+DELETE FROM t1 WHERE c1 = 1;
+INSERT INTO t1 VALUES (2,1);
+INSERT INTO t1 VALUES (NULL,8);
+SELECT * FROM t1;
+DROP TABLE t1;
+# Bug 38839 -- same as above but for multi value insert
+DROP TABLE IF EXISTS t1;
+CREATE TABLE t1 (c1 INT AUTO_INCREMENT, c2 INT, PRIMARY KEY(c1)) ENGINE=InnoDB;
+INSERT INTO t1 VALUES (NULL, 1);
+DELETE FROM t1 WHERE c1 = 1;
+INSERT INTO t1 VALUES (2,1), (NULL, 8);
+INSERT INTO t1 VALUES (NULL,9);
+SELECT * FROM t1;
+DROP TABLE t1;
+
+#
+# Test changes to AUTOINC next value calculation
+SET @@SESSION.AUTO_INCREMENT_INCREMENT=100, @@SESSION.AUTO_INCREMENT_OFFSET=10;
+SHOW VARIABLES LIKE "auto_inc%";
+DROP TABLE IF EXISTS t1;
+CREATE TABLE t1 (c1 INT AUTO_INCREMENT, PRIMARY KEY(c1)) ENGINE=InnoDB;
+INSERT INTO t1 VALUES (NULL),(5),(NULL);
+INSERT INTO t1 VALUES (250),(NULL);
+SELECT * FROM t1;
+INSERT INTO t1 VALUES (1000);
+SET @@INSERT_ID=400;
+INSERT INTO t1 VALUES(NULL),(NULL);
+SELECT * FROM t1;
+DROP TABLE t1;
+
+# Test with SIGNED INT column, by inserting a 0 for the first column value
+# 0 is treated in the same was NULL.
+# Reset the AUTOINC session variables
+SET @@SESSION.AUTO_INCREMENT_INCREMENT=1, @@SESSION.AUTO_INCREMENT_OFFSET=1;
+SET @@INSERT_ID=1;
+SHOW VARIABLES LIKE "auto_inc%";
+DROP TABLE IF EXISTS t1;
+CREATE TABLE t1 (c1 INT AUTO_INCREMENT, PRIMARY KEY(c1)) ENGINE=InnoDB;
+INSERT INTO t1 VALUES(0);
+SELECT * FROM t1;
+SET @@SESSION.AUTO_INCREMENT_INCREMENT=100, @@SESSION.AUTO_INCREMENT_OFFSET=10;
+INSERT INTO t1 VALUES (-1), (NULL),(2),(NULL);
+INSERT INTO t1 VALUES (250),(NULL);
+SELECT * FROM t1;
+SET @@INSERT_ID=400;
+# Duplicate error expected here for autoinc_lock_mode != TRADITIONAL
+-- error ER_DUP_ENTRY,1062
+INSERT INTO t1 VALUES(NULL),(NULL);
+SELECT * FROM t1;
+DROP TABLE t1;
+
+# Test with SIGNED INT column
+# Reset the AUTOINC session variables
+SET @@SESSION.AUTO_INCREMENT_INCREMENT=1, @@SESSION.AUTO_INCREMENT_OFFSET=1;
+SET @@INSERT_ID=1;
+SHOW VARIABLES LIKE "auto_inc%";
+DROP TABLE IF EXISTS t1;
+CREATE TABLE t1 (c1 INT AUTO_INCREMENT, PRIMARY KEY(c1)) ENGINE=InnoDB;
+INSERT INTO t1 VALUES(-1);
+SELECT * FROM t1;
+SET @@SESSION.AUTO_INCREMENT_INCREMENT=100, @@SESSION.AUTO_INCREMENT_OFFSET=10;
+SHOW VARIABLES LIKE "auto_inc%";
+INSERT INTO t1 VALUES (-2), (NULL),(2),(NULL);
+INSERT INTO t1 VALUES (250),(NULL);
+SELECT * FROM t1;
+INSERT INTO t1 VALUES (1000);
+SET @@INSERT_ID=400;
+INSERT INTO t1 VALUES(NULL),(NULL);
+SELECT * FROM t1;
+DROP TABLE t1;
+
+# Test with UNSIGNED INT column, single insert
+# The sign in the value is ignored and a new column value is generated
+# Reset the AUTOINC session variables
+SET @@SESSION.AUTO_INCREMENT_INCREMENT=1, @@SESSION.AUTO_INCREMENT_OFFSET=1;
+SET @@INSERT_ID=1;
+SHOW VARIABLES LIKE "auto_inc%";
+DROP TABLE IF EXISTS t1;
+CREATE TABLE t1 (c1 INT UNSIGNED AUTO_INCREMENT, PRIMARY KEY(c1)) ENGINE=InnoDB;
+INSERT IGNORE INTO t1 VALUES(-1);
+SELECT * FROM t1;
+SET @@SESSION.AUTO_INCREMENT_INCREMENT=100, @@SESSION.AUTO_INCREMENT_OFFSET=10;
+SHOW VARIABLES LIKE "auto_inc%";
+INSERT IGNORE INTO t1 VALUES (-2);
+INSERT INTO t1 VALUES (NULL);
+INSERT INTO t1 VALUES (2);
+INSERT INTO t1 VALUES (NULL);
+INSERT INTO t1 VALUES (250);
+INSERT INTO t1 VALUES (NULL);
+SELECT * FROM t1;
+INSERT INTO t1 VALUES (1000);
+SET @@INSERT_ID=400;
+INSERT INTO t1 VALUES(NULL);
+INSERT INTO t1 VALUES(NULL);
+SELECT * FROM t1;
+DROP TABLE t1;
+
+# Test with UNSIGNED INT column, multi-value inserts
+# The sign in the value is ignored and a new column value is generated
+# Reset the AUTOINC session variables
+SET @@SESSION.AUTO_INCREMENT_INCREMENT=1, @@SESSION.AUTO_INCREMENT_OFFSET=1;
+SET @@INSERT_ID=1;
+SHOW VARIABLES LIKE "auto_inc%";
+DROP TABLE IF EXISTS t1;
+CREATE TABLE t1 (c1 INT UNSIGNED AUTO_INCREMENT, PRIMARY KEY(c1)) ENGINE=InnoDB;
+INSERT IGNORE INTO t1 VALUES(-1);
+SELECT * FROM t1;
+SET @@SESSION.AUTO_INCREMENT_INCREMENT=100, @@SESSION.AUTO_INCREMENT_OFFSET=10;
+SHOW VARIABLES LIKE "auto_inc%";
+INSERT IGNORE INTO t1 VALUES (-2),(NULL),(2),(NULL);
+INSERT INTO t1 VALUES (250),(NULL);
+SELECT * FROM t1;
+INSERT INTO t1 VALUES (1000);
+SET @@INSERT_ID=400;
+# Duplicate error expected here for autoinc_lock_mode != TRADITIONAL
+-- error ER_DUP_ENTRY,1062
+INSERT INTO t1 VALUES(NULL),(NULL);
+SELECT * FROM t1;
+DROP TABLE t1;
+
+#
+# Check for overflow handling when increment is > 1
+SET @@SESSION.AUTO_INCREMENT_INCREMENT=1, @@SESSION.AUTO_INCREMENT_OFFSET=1;
+SET @@INSERT_ID=1;
+SHOW VARIABLES LIKE "auto_inc%";
+DROP TABLE IF EXISTS t1;
+CREATE TABLE t1 (c1 BIGINT AUTO_INCREMENT, PRIMARY KEY(c1)) ENGINE=InnoDB;
+# TODO: Fix the autoinc init code
+# We have to do this because of a bug in the AUTOINC init code.
+INSERT INTO t1 VALUES(NULL);
+INSERT INTO t1 VALUES (9223372036854775794); #-- 2^63 - 14
+SELECT * FROM t1;
+SET @@SESSION.AUTO_INCREMENT_INCREMENT=2, @@SESSION.AUTO_INCREMENT_OFFSET=10;
+SHOW VARIABLES LIKE "auto_inc%";
+# This should just fit
+INSERT INTO t1 VALUES (NULL),(NULL),(NULL),(NULL),(NULL),(NULL);
+SELECT * FROM t1;
+DROP TABLE t1;
+
+#
+# Check for overflow handling when increment and offser are > 1
+SET @@SESSION.AUTO_INCREMENT_INCREMENT=1, @@SESSION.AUTO_INCREMENT_OFFSET=1;
+SET @@INSERT_ID=1;
+SHOW VARIABLES LIKE "auto_inc%";
+DROP TABLE IF EXISTS t1;
+CREATE TABLE t1 (c1 BIGINT UNSIGNED AUTO_INCREMENT, PRIMARY KEY(c1)) ENGINE=InnoDB;
+# TODO: Fix the autoinc init code
+# We have to do this because of a bug in the AUTOINC init code.
+INSERT INTO t1 VALUES(NULL);
+INSERT INTO t1 VALUES (18446744073709551603); #-- 2^64 - 13
+SELECT * FROM t1;
+SET @@SESSION.AUTO_INCREMENT_INCREMENT=2, @@SESSION.AUTO_INCREMENT_OFFSET=10;
+SHOW VARIABLES LIKE "auto_inc%";
+--error ER_AUTOINC_READ_FAILED
+INSERT INTO t1 VALUES (NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL);
+SELECT * FROM t1;
+DROP TABLE t1;
+
+#
+# Check for overflow handling when increment and offset are odd numbers
+SET @@SESSION.AUTO_INCREMENT_INCREMENT=1, @@SESSION.AUTO_INCREMENT_OFFSET=1;
+SET @@INSERT_ID=1;
+SHOW VARIABLES LIKE "auto_inc%";
+DROP TABLE IF EXISTS t1;
+CREATE TABLE t1 (c1 BIGINT UNSIGNED AUTO_INCREMENT, PRIMARY KEY(c1)) ENGINE=InnoDB;
+# TODO: Fix the autoinc init code
+# We have to do this because of a bug in the AUTOINC init code.
+INSERT INTO t1 VALUES(NULL);
+INSERT INTO t1 VALUES (18446744073709551603); #-- 2^64 - 13
+SELECT * FROM t1;
+SET @@SESSION.AUTO_INCREMENT_INCREMENT=5, @@SESSION.AUTO_INCREMENT_OFFSET=7;
+SHOW VARIABLES LIKE "auto_inc%";
+--error ER_AUTOINC_READ_FAILED
+INSERT INTO t1 VALUES (NULL),(NULL), (NULL);
+SELECT * FROM t1;
+DROP TABLE t1;
+
+# Check for overflow handling when increment and offset are odd numbers
+# and check for large -ve numbers
+SET @@SESSION.AUTO_INCREMENT_INCREMENT=1, @@SESSION.AUTO_INCREMENT_OFFSET=1;
+SET @@INSERT_ID=1;
+SHOW VARIABLES LIKE "auto_inc%";
+DROP TABLE IF EXISTS t1;
+CREATE TABLE t1 (c1 BIGINT AUTO_INCREMENT, PRIMARY KEY(c1)) ENGINE=InnoDB;
+# TODO: Fix the autoinc init code
+# We have to do this because of a bug in the AUTOINC init code.
+INSERT INTO t1 VALUES(NULL);
+INSERT INTO t1 VALUES(-9223372036854775806); #-- -2^63 + 2
+INSERT INTO t1 VALUES(-9223372036854775807); #-- -2^63 + 1
+INSERT INTO t1 VALUES(-9223372036854775808); #-- -2^63
+SELECT * FROM t1;
+SET @@SESSION.AUTO_INCREMENT_INCREMENT=3, @@SESSION.AUTO_INCREMENT_OFFSET=3;
+SHOW VARIABLES LIKE "auto_inc%";
+INSERT INTO t1 VALUES (NULL),(NULL), (NULL);
+SELECT * FROM t1;
+DROP TABLE t1;
+#
+# Check for overflow handling when increment and offset are very
+# large numbers 2^60
+SET @@SESSION.AUTO_INCREMENT_INCREMENT=1, @@SESSION.AUTO_INCREMENT_OFFSET=1;
+SET @@INSERT_ID=1;
+SHOW VARIABLES LIKE "auto_inc%";
+DROP TABLE IF EXISTS t1;
+CREATE TABLE t1 (c1 BIGINT UNSIGNED AUTO_INCREMENT, PRIMARY KEY(c1)) ENGINE=InnoDB;
+# TODO: Fix the autoinc init code
+# We have to do this because of a bug in the AUTOINC init code.
+INSERT INTO t1 VALUES(NULL);
+INSERT INTO t1 VALUES (18446744073709551610); #-- 2^64 - 2
+SELECT * FROM t1;
+SET @@SESSION.AUTO_INCREMENT_INCREMENT=1152921504606846976, @@SESSION.AUTO_INCREMENT_OFFSET=1152921504606846976;
+SHOW VARIABLES LIKE "auto_inc%";
+--error HA_ERR_AUTOINC_ERANGE
+INSERT INTO t1 VALUES (NULL),(NULL);
+SELECT * FROM t1;
+DROP TABLE t1;
+
+#
+# Check for floating point autoinc column handling
+#
+SET @@SESSION.AUTO_INCREMENT_INCREMENT=1, @@SESSION.AUTO_INCREMENT_OFFSET=1;
+SET @@INSERT_ID=1;
+SHOW VARIABLES LIKE "auto_inc%";
+CREATE TABLE t1 (c1 DOUBLE NOT NULL AUTO_INCREMENT, c2 INT, PRIMARY KEY (c1)) ENGINE=InnoDB;
+INSERT INTO t1 VALUES(NULL, 1);
+INSERT INTO t1 VALUES(NULL, 2);
+SELECT * FROM t1;
+ALTER TABLE t1 CHANGE c1 c1 SERIAL;
+SELECT * FROM t1;
+INSERT INTO t1 VALUES(NULL, 3);
+INSERT INTO t1 VALUES(NULL, 4);
+SELECT * FROM t1;
+DROP TABLE IF EXISTS t1;
+CREATE TABLE t1 (c1 FLOAT NOT NULL AUTO_INCREMENT, c2 INT, PRIMARY KEY (c1)) ENGINE=InnoDB;
+INSERT INTO t1 VALUES(NULL, 1);
+INSERT INTO t1 VALUES(NULL, 2);
+SELECT * FROM t1;
+ALTER TABLE t1 CHANGE c1 c1 SERIAL;
+SELECT * FROM t1;
+INSERT INTO t1 VALUES(NULL, 3);
+INSERT INTO t1 VALUES(NULL, 4);
+SELECT * FROM t1;
+DROP TABLE t1;
+
+--echo #
+--echo # Bug#15851528 DUPLICATE KEY ERROR ON AUTO-INC PK WITH MIXED AUTO_INCREMENT_INCREMENT CLIENTS
+--echo #
+--echo # This test shows that the next record to be inserted is not affected
+--echo # by a change in auto_increment_increment.
+--echo # In addition, current value of auto_increment_increment by the client
+--echo # that uses the existing autoinc value with be used to set next autoinc
+--echo # value, which will be used by next client reguardless of its own session
+--echo # setting for auto_increment_increment.
+--echo #
+
+--connection default
+--echo # Client 1: Insert a record with auto_increment_increment=2
+CREATE TABLE t(
+ a SERIAL PRIMARY KEY,
+ b VARCHAR(200)) ENGINE=InnoDB;
+SET SESSION auto_increment_increment=2;
+SHOW CREATE TABLE t;
+INSERT INTO t(b) VALUES('S1');
+SELECT a,b FROM t;
+--connect(con1,localhost,root,,)
+
+--connection con1
+--echo # Client 2: Insert records with auto_increment_increment 2,1
+SET SESSION auto_increment_increment=2;
+SHOW CREATE TABLE t;
+INSERT INTO t(b) VALUES('S2');
+SELECT a,b FROM t;
+SET SESSION auto_increment_increment=1;
+SHOW CREATE TABLE t;
+INSERT INTO t(b) VALUES('S2');
+SELECT a,b FROM t;
+disconnect con1;
+
+--connection default
+--echo # Client 1: Insert a record with auto_increment_increment=1
+SET SESSION auto_increment_increment=1;
+SHOW CREATE TABLE t;
+INSERT INTO t(b) VALUES('S1');
+SELECT a,b FROM t;
+DROP TABLE t;
+
+--echo # Autoincrement behaviour with mixed insert.
+CREATE TABLE t(
+ a TINYINT AUTO_INCREMENT PRIMARY KEY,
+ b VARCHAR(200)) ENGINE=InnoDB;
+SET SESSION auto_increment_increment=10;
+SHOW CREATE TABLE t;
+INSERT INTO t(b) VALUES('S0'),('S1');
+SHOW CREATE TABLE t;
+INSERT INTO t(a,b) VALUES(28,'S2');
+SET SESSION auto_increment_increment=1;
+SHOW CREATE TABLE t;
+INSERT INTO t(b) VALUES('S3');
+SHOW CREATE TABLE t;
+INSERT INTO t(b) VALUES('S4');
+SELECT * FROM t;
+SHOW CREATE TABLE t;
+DROP TABLE t;
+
+#
+# Bug# 42714: AUTOINC column calculated next value not greater than highest
+# value stored in table.
+#
+SET @@SESSION.AUTO_INCREMENT_INCREMENT=1, @@SESSION.AUTO_INCREMENT_OFFSET=5;
+DROP TABLE IF EXISTS t1;
+DROP TABLE IF EXISTS t2;
+CREATE TABLE t1 (
+ a INT(11) UNSIGNED NOT NULL AUTO_INCREMENT,
+ b INT(10) UNSIGNED NOT NULL,
+ c ENUM('FALSE','TRUE') DEFAULT NULL,
+ PRIMARY KEY (a)) ENGINE = InnoDB;
+CREATE TABLE t2 (
+ m INT(11) UNSIGNED NOT NULL AUTO_INCREMENT,
+ n INT(10) UNSIGNED NOT NULL,
+ o enum('FALSE','TRUE') DEFAULT NULL,
+ PRIMARY KEY (m)) ENGINE = InnoDB;
+INSERT INTO t2 (n,o) VALUES
+ (1 , 'true'), (1 , 'false'), (2 , 'true'), (2 , 'false'), (3 , 'true'),
+ (3 , 'false'), (4 , 'true'), (4 , 'false'), (5 , 'true'), (5 , 'false');
+SELECT * FROM t2;
+SHOW CREATE TABLE t2;
+INSERT INTO t1 (b,c) SELECT n,o FROM t2 ;
+SHOW CREATE TABLE t1;
+INSERT INTO t1 (b,c) SELECT n,o FROM t2 ;
+SELECT * FROM t1;
+SHOW CREATE TABLE t1;
+INSERT INTO t1 (b,c) SELECT n,o FROM t2 WHERE o = 'false';
+SELECT * FROM t1;
+SHOW CREATE TABLE t1;
+INSERT INTO t1 (b,c) SELECT n,o FROM t2 WHERE o = 'false';
+SELECT * FROM t1;
+SHOW CREATE TABLE t1;
+INSERT INTO t1 (b,c) SELECT n,o FROM t2 WHERE o = 'false';
+SHOW CREATE TABLE t1;
+INSERT INTO t1 (b,c) SELECT n,o FROM t2 WHERE o = 'false';
+SHOW CREATE TABLE t1;
+INSERT INTO t1 (b,c) SELECT n,o FROM t2 WHERE o = 'false';
+SELECT * FROM t1;
+SHOW CREATE TABLE t1;
+DROP TABLE t1;
+DROP TABLE t2;
+#
+# 43203: Overflow from auto incrementing causes server segv
+#
+
+DROP TABLE IF EXISTS t1;
+DROP TABLE IF EXISTS t2;
+SET sql_mode = 'NO_ENGINE_SUBSTITUTION';
+CREATE TABLE t1(
+ c1 INT(10) UNSIGNED NOT NULL AUTO_INCREMENT
+ PRIMARY KEY) ENGINE=InnoDB;
+INSERT INTO t1 VALUES (NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL);
+CREATE TABLE t2(
+ c1 TINYINT(3) UNSIGNED NOT NULL AUTO_INCREMENT
+ PRIMARY KEY) ENGINE=InnoDB;
+-- error ER_DUP_ENTRY,1062
+INSERT INTO t2 SELECT c1 FROM t1;
+-- error 167
+INSERT INTO t2 SELECT NULL FROM t1;
+DROP TABLE t1;
+DROP TABLE t2;
+SET sql_mode = DEFAULT;
+
+# If the user has specified negative values for an AUTOINC column then
+# InnoDB should ignore those values when setting the table's max value.
+SET @@SESSION.AUTO_INCREMENT_INCREMENT=1, @@SESSION.AUTO_INCREMENT_OFFSET=1;
+SHOW VARIABLES LIKE "auto_inc%";
+# TINYINT
+CREATE TABLE t1 (c1 TINYINT PRIMARY KEY AUTO_INCREMENT, c2 VARCHAR(10)) ENGINE=InnoDB;
+INSERT INTO t1 VALUES (1, NULL);
+INSERT INTO t1 VALUES (-1, 'innodb');
+INSERT INTO t1 VALUES (-127, 'innodb');
+INSERT INTO t1 VALUES (NULL, NULL);
+SHOW CREATE TABLE t1;
+SELECT * FROM t1;
+DROP TABLE t1;
+
+CREATE TABLE t1 (c1 TINYINT UNSIGNED PRIMARY KEY AUTO_INCREMENT, c2 VARCHAR(10)) ENGINE=InnoDB;
+INSERT INTO t1 VALUES (1, NULL);
+INSERT IGNORE INTO t1 VALUES (-1, 'innodb');
+INSERT IGNORE INTO t1 VALUES (-127, 'innodb');
+INSERT INTO t1 VALUES (NULL, NULL);
+SHOW CREATE TABLE t1;
+SELECT * FROM t1;
+DROP TABLE t1;
+#
+# SMALLINT
+#
+CREATE TABLE t1 (c1 SMALLINT PRIMARY KEY AUTO_INCREMENT, c2 VARCHAR(10)) ENGINE=InnoDB;
+INSERT INTO t1 VALUES (1, NULL);
+INSERT INTO t1 VALUES (-1, 'innodb');
+INSERT INTO t1 VALUES (-32767, 'innodb');
+INSERT INTO t1 VALUES (NULL, NULL);
+SHOW CREATE TABLE t1;
+SELECT * FROM t1;
+DROP TABLE t1;
+
+CREATE TABLE t1 (c1 SMALLINT UNSIGNED PRIMARY KEY AUTO_INCREMENT, c2 VARCHAR(10)) ENGINE=InnoDB;
+INSERT INTO t1 VALUES (1, NULL);
+INSERT IGNORE INTO t1 VALUES (-1, 'innodb');
+INSERT IGNORE INTO t1 VALUES (-32757, 'innodb');
+INSERT INTO t1 VALUES (NULL, NULL);
+SHOW CREATE TABLE t1;
+SELECT * FROM t1;
+DROP TABLE t1;
+#
+# MEDIUMINT
+#
+CREATE TABLE t1 (c1 MEDIUMINT PRIMARY KEY AUTO_INCREMENT, c2 VARCHAR(10)) ENGINE=InnoDB;
+INSERT INTO t1 VALUES (1, NULL);
+INSERT INTO t1 VALUES (-1, 'innodb');
+INSERT INTO t1 VALUES (-8388607, 'innodb');
+INSERT INTO t1 VALUES (NULL, NULL);
+SHOW CREATE TABLE t1;
+SELECT * FROM t1;
+DROP TABLE t1;
+
+CREATE TABLE t1 (c1 MEDIUMINT UNSIGNED PRIMARY KEY AUTO_INCREMENT, c2 VARCHAR(10)) ENGINE=InnoDB;
+INSERT INTO t1 VALUES (1, NULL);
+INSERT IGNORE INTO t1 VALUES (-1, 'innodb');
+INSERT IGNORE INTO t1 VALUES (-8388607, 'innodb');
+INSERT INTO t1 VALUES (NULL, NULL);
+SHOW CREATE TABLE t1;
+SELECT * FROM t1;
+DROP TABLE t1;
+#
+# INT
+#
+CREATE TABLE t1 (c1 INT PRIMARY KEY AUTO_INCREMENT, c2 VARCHAR(10)) ENGINE=InnoDB;
+INSERT INTO t1 VALUES (1, NULL);
+INSERT INTO t1 VALUES (-1, 'innodb');
+INSERT INTO t1 VALUES (-2147483647, 'innodb');
+INSERT INTO t1 VALUES (NULL, NULL);
+SHOW CREATE TABLE t1;
+SELECT * FROM t1;
+DROP TABLE t1;
+
+CREATE TABLE t1 (c1 INT UNSIGNED PRIMARY KEY AUTO_INCREMENT, c2 VARCHAR(10)) ENGINE=InnoDB;
+INSERT INTO t1 VALUES (1, NULL);
+INSERT IGNORE INTO t1 VALUES (-1, 'innodb');
+INSERT IGNORE INTO t1 VALUES (-2147483647, 'innodb');
+INSERT INTO t1 VALUES (NULL, NULL);
+SHOW CREATE TABLE t1;
+SELECT * FROM t1;
+DROP TABLE t1;
+#
+# BIGINT
+#
+CREATE TABLE t1 (c1 BIGINT PRIMARY KEY AUTO_INCREMENT, c2 VARCHAR(10)) ENGINE=InnoDB;
+INSERT INTO t1 VALUES (1, NULL);
+INSERT INTO t1 VALUES (-1, 'innodb');
+INSERT INTO t1 VALUES (-9223372036854775807, 'innodb');
+INSERT INTO t1 VALUES (NULL, NULL);
+SHOW CREATE TABLE t1;
+SELECT * FROM t1;
+DROP TABLE t1;
+
+CREATE TABLE t1 (c1 BIGINT UNSIGNED PRIMARY KEY AUTO_INCREMENT, c2 VARCHAR(10)) ENGINE=InnoDB;
+INSERT INTO t1 VALUES (1, NULL);
+INSERT IGNORE INTO t1 VALUES (-1, 'innodb');
+INSERT IGNORE INTO t1 VALUES (-9223372036854775807, 'innodb');
+INSERT INTO t1 VALUES (NULL, NULL);
+SHOW CREATE TABLE t1;
+SELECT * FROM t1;
+DROP TABLE t1;
+#
+# End negative number check
+
+##
+# 47125: auto_increment start value is ignored if an index is created
+# and engine=innodb
+#
+CREATE TABLE t1 (c1 INT AUTO_INCREMENT, c2 INT, PRIMARY KEY(c1)) AUTO_INCREMENT=10 ENGINE=InnoDB;
+CREATE INDEX i1 on t1(c2);
+SHOW CREATE TABLE t1;
+INSERT INTO t1 (c2) values (0);
+SELECT * FROM t1;
+DROP TABLE t1;
+
+##
+# 49032: Use the correct function to read the AUTOINC column value
+#
+DROP TABLE IF EXISTS t1;
+CREATE TABLE t1(C1 DOUBLE AUTO_INCREMENT KEY, C2 CHAR(10)) ENGINE=InnoDB;
+INSERT INTO t1(C1, C2) VALUES (1, 'innodb'), (3, 'innodb');
+# Restart the server
+-- source include/restart_mysqld.inc
+INSERT INTO t1(C2) VALUES ('innodb');
+SHOW CREATE TABLE t1;
+DROP TABLE t1;
+CREATE TABLE t1(C1 FLOAT AUTO_INCREMENT KEY, C2 CHAR(10)) ENGINE=InnoDB;
+INSERT INTO t1(C1, C2) VALUES (1, 'innodb'), (3, 'innodb');
+# Restart the server
+-- source include/restart_mysqld.inc
+INSERT INTO t1(C2) VALUES ('innodb');
+SHOW CREATE TABLE t1;
+DROP TABLE t1;
+
+##
+# 47720: REPLACE INTO Autoincrement column with negative values
+#
+DROP TABLE IF EXISTS t1;
+CREATE TABLE t1 (c1 INT AUTO_INCREMENT PRIMARY KEY) ENGINE=InnoDB;
+INSERT INTO t1 SET c1 = 1;
+SHOW CREATE TABLE t1;
+INSERT INTO t1 SET c1 = 2;
+INSERT INTO t1 SET c1 = -1;
+SELECT * FROM t1;
+-- error ER_DUP_ENTRY,1062
+INSERT INTO t1 SET c1 = -1;
+SHOW CREATE TABLE t1;
+REPLACE INTO t1 VALUES (-1);
+SELECT * FROM t1;
+SHOW CREATE TABLE t1;
+DROP TABLE t1;
+
+##
+# 49497: Error 1467 (ER_AUTOINC_READ_FAILED) on inserting a negative value
+#
+DROP TABLE IF EXISTS t1;
+CREATE TABLE t1 (c1 INTEGER AUTO_INCREMENT, PRIMARY KEY (c1)) ENGINE=InnoDB;
+INSERT INTO t1 VALUES (-685113344), (1), (NULL), (NULL);
+SELECT * FROM t1;
+SHOW CREATE TABLE t1;
+DROP TABLE t1;
+CREATE TABLE t1 (c1 INTEGER AUTO_INCREMENT, PRIMARY KEY (c1)) ENGINE=InnoDB;
+INSERT INTO t1 VALUES (-685113344), (2), (NULL), (NULL);
+SELECT * FROM t1;
+SHOW CREATE TABLE t1;
+DROP TABLE t1;
+CREATE TABLE t1 (c1 INTEGER AUTO_INCREMENT, PRIMARY KEY (c1)) ENGINE=InnoDB;
+INSERT INTO t1 VALUES (NULL), (2), (-685113344), (NULL);
+INSERT INTO t1 VALUES (4), (5), (6), (NULL);
+SELECT * FROM t1;
+SHOW CREATE TABLE t1;
+DROP TABLE t1;
+CREATE TABLE t1 (c1 INTEGER AUTO_INCREMENT, PRIMARY KEY (c1)) ENGINE=InnoDB;
+INSERT INTO t1 VALUES (NULL), (2), (-685113344), (5);
+SELECT * FROM t1;
+SHOW CREATE TABLE t1;
+DROP TABLE t1;
+CREATE TABLE t1 (c1 INTEGER AUTO_INCREMENT, PRIMARY KEY (c1)) ENGINE=InnoDB;
+INSERT INTO t1 VALUES (1), (2), (-685113344), (NULL);
+SELECT * FROM t1;
+SHOW CREATE TABLE t1;
+DROP TABLE t1;
+
+##
+# 55277: Failing assertion: auto_inc > 0
+#
+DROP TABLE IF EXISTS t1;
+CREATE TABLE t1(c1 BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY) ENGINE=InnoDB;
+INSERT INTO t1 VALUES (NULL);
+INSERT INTO t1 VALUES (18446744073709551615);
+# Restart the server
+-- source include/restart_mysqld.inc
+SHOW CREATE TABLE t1;
+DROP TABLE t1;
+
+
+# Check if we handle offset > column max value properly
+SET @@SESSION.AUTO_INCREMENT_INCREMENT=1, @@SESSION.AUTO_INCREMENT_OFFSET=256;
+SHOW VARIABLES LIKE "auto_inc%";
+# TINYINT
+CREATE TABLE t1 (c1 TINYINT PRIMARY KEY AUTO_INCREMENT, c2 VARCHAR(10)) ENGINE=InnoDB;
+INSERT INTO t1 VALUES (1, NULL);
+SHOW CREATE TABLE t1;
+SELECT * FROM t1;
+DROP TABLE t1;
+
+# Check if we handle the case where a current value is greater than the max
+# of the column. IMO, this should not be allowed and the assertion that fails
+# is actually an invariant.
+SET @@SESSION.AUTO_INCREMENT_INCREMENT=1, @@SESSION.AUTO_INCREMENT_OFFSET=1;
+SHOW VARIABLES LIKE "auto_inc%";
+# TINYINT
+CREATE TABLE t1 (c1 INT UNSIGNED PRIMARY KEY AUTO_INCREMENT, c2 VARCHAR(10)) ENGINE=InnoDB;
+INSERT INTO t1 VALUES (2147483648, 'a');
+SHOW CREATE TABLE t1;
+SELECT * FROM t1;
+SET STATEMENT sql_mode = 'NO_ENGINE_SUBSTITUTION' FOR
+ALTER TABLE t1 CHANGE c1 c1 INT default 0;
+SHOW CREATE TABLE t1;
+INSERT INTO t1(c2) VALUES('b');
+SELECT * FROM t1;
+SHOW CREATE TABLE t1;
+DROP TABLE t1;
+
+--echo #
+--echo # Bug #14049391 INNODB MISCALCULATES AUTO-INCREMENT
+--echo # AFTER CHANGING AUTO_INCREMENT_INCREMEMENT
+--echo #
+CREATE TABLE t ( i INT AUTO_INCREMENT, KEY(i) ) ENGINE=InnoDB;
+SET auto_increment_increment = 300;
+INSERT INTO t VALUES (NULL), (NULL);
+SHOW CREATE TABLE t;
+SET auto_increment_increment = 50;
+INSERT INTO t VALUES (NULL);
+SELECT * FROM t;
+SHOW CREATE TABLE t;
+DROP TABLE t;
+SET auto_increment_increment = DEFAULT;
+
+
+--echo #
+--echo # MDEV-14008 Assertion failing: `!is_set() || (m_status == DA_OK_BULK && is_bulk_op())
+--echo #
+
+SET sql_mode=STRICT_ALL_TABLES;
+CREATE TABLE t1 (
+ c1 DOUBLE NOT NULL PRIMARY KEY AUTO_INCREMENT
+) ENGINE=InnoDB AUTO_INCREMENT=10000000000000000000;
+INSERT INTO t1 VALUES ();
+SELECT * FROM t1;
+DROP TABLE t1;
+
+CREATE TABLE t1 (a DOUBLE PRIMARY KEY AUTO_INCREMENT) ENGINE=InnoDB;
+INSERT INTO t1 VALUES (-1);
+SELECT * FROM t1;
+DROP TABLE t1;
+
+
+--echo #
+--echo # MDEV-15352 AUTO_INCREMENT breaks after updating a column value to a negative number
+--echo #
+
+SET @engine='INNODB';
+--source include/autoinc_mdev15353.inc
+
+--echo #
+--echo # MDEV-28416 Incorrect AUTO_INCREMENT may be issued
+--echo #
+
+SET @aii=@@auto_increment_increment;
+SET auto_increment_increment=300;
+CREATE TABLE t1 (a SERIAL) ENGINE=innodb;
+INSERT INTO t1 VALUES (18446744073709551613);
+SHOW CREATE TABLE t1;
+--error HA_ERR_AUTOINC_ERANGE
+INSERT INTO t1 VALUES (NULL);
+SHOW CREATE TABLE t1;
+DROP TABLE t1;
+SET auto_increment_increment=@aii;
+
+--echo # End of 10.2 tests
diff --git a/mysql-test/suite/innodb/t/innodb-bigblob.opt b/mysql-test/suite/innodb/t/innodb-bigblob.opt
new file mode 100644
index 00000000..39673297
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb-bigblob.opt
@@ -0,0 +1,3 @@
+--max-allowed-packet=128M
+--innodb-log-file-size=210M
+--skip-innodb-doublewrite
diff --git a/mysql-test/suite/innodb/t/innodb-bigblob.test b/mysql-test/suite/innodb/t/innodb-bigblob.test
new file mode 100644
index 00000000..799dfe42
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb-bigblob.test
@@ -0,0 +1,16 @@
+-- source include/have_innodb.inc
+-- source include/big_test.inc
+-- source include/not_embedded.inc
+
+--disable_query_log
+let $status_orig=`SELECT @@innodb_status_output`;
+--enable_query_log
+
+create table foo (id varchar(37) not null, content longblob) engine=INNODB;
+insert into foo (id, content) values('xyz', '');
+update foo set content=repeat('a', 43941888) where id='xyz';
+drop table foo;
+
+--disable_query_log
+EVAL SET GLOBAL innodb_status_output = $status_orig;
+--enable_query_log
diff --git a/mysql-test/suite/innodb/t/innodb-blob.test b/mysql-test/suite/innodb/t/innodb-blob.test
new file mode 100644
index 00000000..301966fb
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb-blob.test
@@ -0,0 +1,215 @@
+# Bug#13721257 RACE CONDITION IN UPDATES OR INSERTS OF WIDE RECORDS
+# Test what happens when a record is inserted or updated so that some
+# columns are stored off-page.
+
+--source include/have_innodb.inc
+# The 7000 in this test is a bit less than half the innodb_page_size.
+--source include/have_innodb_16k.inc
+
+--source include/have_debug.inc
+--source include/have_debug_sync.inc
+
+# Embedded server does not support restarting
+--source include/not_embedded.inc
+
+FLUSH TABLES;
+
+CREATE TABLE t1 (a INT PRIMARY KEY, b TEXT) ENGINE=InnoDB;
+CREATE TABLE t2 (a INT PRIMARY KEY) ENGINE=InnoDB;
+CREATE TABLE t3 (a INT PRIMARY KEY, b TEXT, c TEXT) ENGINE=InnoDB;
+
+INSERT INTO t1 VALUES (1,REPEAT('a',30000)),(2,REPEAT('b',40000));
+SET DEBUG_SYNC='before_row_upd_extern SIGNAL have_latch WAIT_FOR go1';
+BEGIN;
+# This will not block, because it will not store new BLOBs.
+UPDATE t1 SET a=a+2;
+ROLLBACK;
+BEGIN;
+--send
+UPDATE t1 SET b=CONCAT(b,'foo');
+
+connect (con1,localhost,root,,);
+SET DEBUG_SYNC='now WAIT_FOR have_latch';
+
+# this one should block due to the clustered index tree and leaf page latches
+--send
+SELECT a, RIGHT(b,20) FROM t1;
+
+connect (con2,localhost,root,,);
+
+# Check that the above SELECT is blocked
+let $wait_condition=
+ select count(*) = 1 from information_schema.processlist
+ where state in ('Sending data', 'Opening tables') and
+ info = 'SELECT a, RIGHT(b,20) FROM t1';
+--source include/wait_condition.inc
+
+SET DEBUG_SYNC='now SIGNAL go1';
+
+connection con1;
+reap;
+connection default;
+reap;
+SET DEBUG='+d,row_ins_extern_checkpoint';
+SET DEBUG_SYNC='before_row_ins_extern_latch SIGNAL rec_not_blob WAIT_FOR crash';
+ROLLBACK;
+BEGIN;
+--send
+INSERT INTO t1 VALUES (3,REPEAT('c',50000));
+
+connection con1;
+SET DEBUG_SYNC='now WAIT_FOR rec_not_blob';
+SET SESSION TRANSACTION ISOLATION LEVEL READ UNCOMMITTED;
+SELECT @@tx_isolation;
+
+# this one should see (3,NULL_BLOB)
+SELECT a, RIGHT(b,20) FROM t1;
+SELECT a FROM t1;
+
+# Request a crash, and restart the server.
+BEGIN;
+INSERT INTO t2 VALUES (42);
+
+--let $shutdown_timeout=0
+--source include/restart_mysqld.inc
+
+disconnect con1;
+disconnect con2;
+connection default;
+# This connection should notice the crash as well.
+--error 2013
+reap;
+
+--enable_reconnect
+--source include/wait_until_connected_again.inc
+--disable_reconnect
+
+CHECK TABLE t1;
+
+INSERT INTO t3 VALUES
+ (1,REPEAT('d',7000),REPEAT('e',100)),
+ (2,REPEAT('g',7000),REPEAT('h',100));
+SET DEBUG_SYNC='blob_write_middle SIGNAL go_sel WAIT_FOR go_upd';
+# This should move column b off-page.
+--send
+UPDATE t3 SET c=REPEAT('f',3000) WHERE a=1;
+
+--echo # Connection con1:
+connect (con1,localhost,root,,);
+SET DEBUG_SYNC='now WAIT_FOR go_sel';
+SET SESSION TRANSACTION ISOLATION LEVEL READ UNCOMMITTED;
+SELECT @@tx_isolation;
+SELECT a, RIGHT(b,20), RIGHT(c,20) FROM t3;
+set debug_sync='now SIGNAL go_upd';
+
+--echo # Connection default:
+connection default;
+--echo # reap UPDATE t3 SET c=REPEAT('f',3000) WHERE a=1;
+reap;
+
+--echo # Connection con1:
+connection con1;
+SELECT a, RIGHT(b,20), RIGHT(c,20) FROM t3;
+
+disconnect con1;
+
+connection default;
+CHECK TABLE t1,t2,t3;
+
+connect (con2,localhost,root,,);
+BEGIN;
+INSERT INTO t2 VALUES (347);
+connection default;
+
+# The row_upd_extern_checkpoint was removed in Bug#13721257,
+# because the mini-transaction of the B-tree modification would
+# remain open while we are writing the off-page columns and are
+# stuck in the DEBUG_SYNC. A checkpoint involves a flush, which
+# would wait for the buffer-fix to cease.
+SET DEBUG='+d,row_upd_extern_checkpoint';
+SET DEBUG_SYNC='before_row_upd_extern SIGNAL have_latch WAIT_FOR crash';
+# This should move column b off-page.
+--send
+UPDATE t3 SET c=REPEAT('i',3000) WHERE a=2;
+
+connection con2;
+SET DEBUG_SYNC='now WAIT_FOR have_latch';
+
+# Check that the above UPDATE is blocked
+SELECT info FROM information_schema.processlist
+WHERE state = 'debug sync point: before_row_upd_extern';
+
+connect (con3,localhost,root,,);
+SET GLOBAL innodb_flush_log_at_trx_commit=1;
+DELETE FROM t1;
+ROLLBACK;
+disconnect con3;
+
+connection con2;
+
+--let $shutdown_timeout=0
+--source include/restart_mysqld.inc
+
+disconnect con2;
+connection default;
+# This connection should notice the crash as well.
+--error 2013
+reap;
+
+--enable_reconnect
+--source include/wait_until_connected_again.inc
+--disable_reconnect
+
+CHECK TABLE t1,t2,t3;
+SELECT a, RIGHT(b,20), RIGHT(c,20) FROM t3;
+SELECT a FROM t3;
+
+connect (con2,localhost,root,,);
+BEGIN;
+INSERT INTO t2 VALUES (33101);
+connection default;
+
+# The row_upd_extern_checkpoint was removed in Bug#13721257,
+# because the mini-transaction of the B-tree modification would
+# remain open while we are writing the off-page columns and are
+# stuck in the DEBUG_SYNC. A checkpoint involves a flush, which
+# would wait for the buffer-fix to cease.
+SET DEBUG='+d,row_upd_extern_checkpoint';
+SET DEBUG_SYNC='after_row_upd_extern SIGNAL have_latch WAIT_FOR crash';
+# This should move column b off-page.
+--send
+UPDATE t3 SET c=REPEAT('j',3000) WHERE a=2;
+
+connection con2;
+SET DEBUG_SYNC='now WAIT_FOR have_latch';
+
+# Check that the above UPDATE is blocked
+SELECT info FROM information_schema.processlist
+WHERE state = 'debug sync point: after_row_upd_extern';
+
+--let $shutdown_timeout=0
+--source include/restart_mysqld.inc
+
+disconnect con2;
+connection default;
+# This connection should notice the crash as well.
+--error 2013
+reap;
+
+--enable_reconnect
+--source include/wait_until_connected_again.inc
+--disable_reconnect
+CHECK TABLE t1,t2,t3;
+SELECT a, RIGHT(b,20), RIGHT(c,20) FROM t3;
+SELECT a FROM t3;
+
+SELECT * FROM t2;
+
+DROP TABLE t1,t2,t3;
+
+CREATE TABLE t1(f1 INT PRIMARY KEY, f2 TEXT)ENGINE=InnoDB
+ ROW_FORMAT=REDUNDANT;
+SET @fill_amount = (@@innodb_page_size / 2 ) + 1 ;
+INSERT INTO t1 VALUES(1, REPEAT(2, @fill_amount));
+UPDATE t1 SET f1 = 2;
+DROP TABLE t1;
diff --git a/mysql-test/suite/innodb/t/innodb-bug-14068765.test b/mysql-test/suite/innodb/t/innodb-bug-14068765.test
new file mode 100644
index 00000000..c2446e0f
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb-bug-14068765.test
@@ -0,0 +1,59 @@
+-- source include/have_innodb.inc
+
+let MYSQLD_DATADIR =`SELECT @@datadir`;
+
+# Export/import on the same instance, with --innodb-file-per-table=1
+CREATE DATABASE testdb_wl5522;
+
+CREATE TABLE testdb_wl5522.t1(col1 bit(1) , col2 boolean,col3 tinyint , col4 smallint , col5 mediumint ,col6 int , col7 bigint , col8 float (14,3) ,col9 double (14,3), col10 VARCHAR(20) CHARACTER SET utf8 , col11 TEXT CHARACTER SET binary , col12 ENUM('a','b','c') CHARACTER SET binary ,col13 TEXT CHARACTER SET latin1 COLLATE latin1_general_cs ,col14 CHAR(20) , col15 VARBINARY (400) , col16 BINARY(40), col17 BLOB (400) , col18 int not null primary key,col19 DATE ,col20 DATETIME , col21 TIMESTAMP ,col22 TIME , col23 YEAR ) ENGINE = Innodb;
+
+
+CREATE INDEX idx1 ON testdb_wl5522.t1(col18);
+CREATE INDEX prefix_idx ON testdb_wl5522.t1(col14 (10));
+CREATE UNIQUE INDEX idx2 ON testdb_wl5522.t1(col12);
+CREATE UNIQUE INDEX idx3 ON testdb_wl5522.t1(col8);
+
+INSERT INTO testdb_wl5522.t1 VALUES (1,1,-128,32767,-8388608,2147483647,-9223372036854775808, 92233720368.222,-92233720368.222,'aaa', 'aaaaaaaaaa','b','bbbbb','ccccc',REPEAT('d',40),REPEAT('d',40),REPEAT('d',40), 1,'1000-01-01','3000-12-31 23:59:59.99','1990-01-01 00:00:01.00','01:59:59.00','1901');
+
+INSERT INTO testdb_wl5522.t1 VALUES (NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,3,NULL,NULL,NULL,NULL,NULL);
+
+--error ER_BAD_NULL_ERROR
+INSERT INTO testdb_wl5522.t1 VALUES (NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL);
+
+--error ER_DUP_ENTRY
+INSERT INTO testdb_wl5522.t1 VALUES (NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,1,NULL,NULL,NULL,NULL,NULL);
+
+FLUSH TABLES testdb_wl5522.t1 WITH READ LOCK;
+SELECT COUNT(*) FROM testdb_wl5522.t1;
+perl;
+do "$ENV{MTR_SUITE_DIR}/include/innodb-util.pl";
+ib_backup_tablespaces("testdb_wl5522", "t1");
+EOF
+UNLOCK TABLES;
+
+DROP TABLE testdb_wl5522.t1;
+
+CREATE TABLE testdb_wl5522.t1(col1 bit(1) , col2 boolean,col3 tinyint , col4 smallint , col5 mediumint ,col6 int , col7 bigint , col8 float (14,3) ,col9 double (14,3), col10 VARCHAR(20) CHARACTER SET utf8 , col11 TEXT CHARACTER SET binary , col12 ENUM('a','b','c') CHARACTER SET binary ,col13 TEXT CHARACTER SET latin1 COLLATE latin1_general_cs ,col14 CHAR(20) , col15 VARBINARY (400) , col16 BINARY(40), col17 BLOB (400) , col18 int not null primary key,col19 DATE ,col20 DATETIME , col21 TIMESTAMP ,col22 TIME , col23 YEAR ) ENGINE = Innodb;
+
+
+CREATE INDEX idx1 ON testdb_wl5522.t1(col18);
+CREATE INDEX prefix_idx ON testdb_wl5522.t1(col14 (10));
+CREATE UNIQUE INDEX idx2 ON testdb_wl5522.t1(col12);
+CREATE UNIQUE INDEX idx3 ON testdb_wl5522.t1(col8);
+
+ALTER TABLE testdb_wl5522.t1 DISCARD TABLESPACE;
+
+perl;
+do "$ENV{MTR_SUITE_DIR}/include/innodb-util.pl";
+ib_restore_tablespaces("testdb_wl5522", "t1");
+EOF
+
+ALTER TABLE testdb_wl5522.t1 IMPORT TABLESPACE;
+
+CHECK TABLE testdb_wl5522.t1;
+
+SELECT COUNT(*) FROM testdb_wl5522.t1;
+
+DROP TABLE testdb_wl5522.t1;
+
+DROP DATABASE testdb_wl5522;
diff --git a/mysql-test/suite/innodb/t/innodb-bug-14084530.test b/mysql-test/suite/innodb/t/innodb-bug-14084530.test
new file mode 100644
index 00000000..f27fbbe3
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb-bug-14084530.test
@@ -0,0 +1,39 @@
+-- source include/have_innodb.inc
+
+let MYSQLD_DATADIR =`SELECT @@datadir`;
+
+SET AUTOCOMMIT = 0;
+
+# Export/import on the same instance, with --innodb-file-per-table=1
+CREATE DATABASE testdb_wl5522;
+CREATE TABLE testdb_wl5522.t1 (c1 int ) engine = Innodb;
+
+BEGIN;
+INSERT INTO testdb_wl5522.t1 VALUES (1),(123),(331);
+ROLLBACK;
+
+SELECT c1 FROM testdb_wl5522.t1;
+
+FLUSH TABLES testdb_wl5522.t1 FOR EXPORT;
+perl;
+do "$ENV{MTR_SUITE_DIR}/include/innodb-util.pl";
+ib_backup_tablespaces("testdb_wl5522", "t1");
+EOF
+UNLOCK TABLES;
+
+DROP TABLE testdb_wl5522.t1;
+
+CREATE TABLE testdb_wl5522.t1 (c1 int ) ENGINE = Innodb;
+ALTER TABLE testdb_wl5522.t1 DISCARD TABLESPACE;
+
+perl;
+do "$ENV{MTR_SUITE_DIR}/include/innodb-util.pl";
+ib_discard_tablespaces("testdb_wl5522", "t1");
+ib_restore_tablespaces("testdb_wl5522", "t1");
+EOF
+
+ALTER TABLE testdb_wl5522.t1 IMPORT TABLESPACE;
+CHECK TABLE testdb_wl5522.t1;
+SELECT c1 FROM testdb_wl5522.t1;
+
+DROP DATABASE testdb_wl5522;
diff --git a/mysql-test/suite/innodb/t/innodb-consistent-master.opt b/mysql-test/suite/innodb/t/innodb-consistent-master.opt
new file mode 100644
index 00000000..cb48f1aa
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb-consistent-master.opt
@@ -0,0 +1 @@
+--loose-innodb_lock_wait_timeout=2
diff --git a/mysql-test/suite/innodb/t/innodb-consistent.test b/mysql-test/suite/innodb/t/innodb-consistent.test
new file mode 100644
index 00000000..25015de0
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb-consistent.test
@@ -0,0 +1,58 @@
+--source include/have_innodb.inc
+-- source include/not_embedded.inc
+
+--disable_warnings
+drop table if exists t1;
+--enable_warnings
+
+# REPLACE INTO ... SELECT and INSERT INTO ... SELECT should do
+# a consistent read of the source table.
+
+connect (a,localhost,root,,);
+connect (b,localhost,root,,);
+connection a;
+set session transaction isolation level read committed;
+create table t1(a int not null) engine=innodb DEFAULT CHARSET=latin1;
+create table t2 like t1;
+insert into t2 values (1),(2),(3),(4),(5),(6),(7);
+set autocommit=0;
+
+# REPLACE INTO ... SELECT case
+begin;
+# this should not result in any locks on t2.
+replace into t1 select * from t2;
+
+connection b;
+set session transaction isolation level read committed;
+set autocommit=0;
+# should not cause a lock wait.
+delete from t2 where a=5;
+commit;
+delete from t2;
+commit;
+connection a;
+commit;
+
+# INSERT INTO ... SELECT case
+begin;
+# this should not result in any locks on t2.
+insert into t1 select * from t2;
+
+connection b;
+set session transaction isolation level read committed;
+set autocommit=0;
+# should not cause a lock wait.
+delete from t2 where a=5;
+commit;
+delete from t2;
+commit;
+connection a;
+commit;
+
+select * from t1;
+drop table t1;
+drop table t2;
+
+connection default;
+disconnect a;
+disconnect b;
diff --git a/mysql-test/suite/innodb/t/innodb-corrupted-table.test b/mysql-test/suite/innodb/t/innodb-corrupted-table.test
new file mode 100644
index 00000000..a064f08d
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb-corrupted-table.test
@@ -0,0 +1,47 @@
+--source include/have_innodb.inc
+--source include/not_embedded.inc
+
+#
+# MDEV-9918: [ERROR] mysqld got signal 11 during ALTER TABLE `name` COLUMN ADD
+#
+
+call mtr.add_suppression("Table .* has a primary key in InnoDB data dictionary, but not in MariaDB");
+call mtr.add_suppression("InnoDB: Table .* contains .* indexes inside InnoDB");
+
+create table t1 (pk int, i int, key(i)) engine=InnoDB;
+insert into t1 values (1,1),(2,2);
+
+--let $datadir= `select @@datadir`
+
+flush tables;
+
+--echo # Save the .frm file without the PK
+
+--copy_file $datadir/test/t1.frm $MYSQLTEST_VARDIR/tmp/t1.frm
+
+alter table t1 add primary key (pk);
+
+--echo # Stop the server, replace the frm with the old one and restart the server
+
+--exec echo "wait" > $MYSQLTEST_VARDIR/tmp/mysqld.1.expect
+--shutdown_server
+--source include/wait_until_disconnected.inc
+
+--remove_file $datadir/test/t1.frm
+--copy_file $MYSQLTEST_VARDIR/tmp/t1.frm $datadir/test/t1.frm
+
+--exec echo "restart" > $MYSQLTEST_VARDIR/tmp/mysqld.1.expect
+--enable_reconnect
+--source include/wait_until_connected_again.inc
+
+--enable_prepare_warnings
+show create table t1;
+select * from t1;
+alter table t1 add j int;
+show warnings;
+show create table t1;
+alter table t1 add primary key (pk);
+show warnings;
+show create table t1;
+# Cleanup
+drop table t1;
diff --git a/mysql-test/suite/innodb/t/innodb-dict.test b/mysql-test/suite/innodb/t/innodb-dict.test
new file mode 100644
index 00000000..13472f01
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb-dict.test
@@ -0,0 +1,32 @@
+--source include/have_innodb.inc
+
+#
+# Fix MySQL Bug#20755615: InnoDB compares column names case sensitively,
+# while according to Storage Engine API column names should be compared
+# case insensitively. This can cause FRM and InnoDB data dictionary to
+# go out of sync:
+#
+
+CREATE TABLE t1 (D INT) ENGINE=innodb;
+INSERT INTO t1 VALUES (10);
+ALTER TABLE t1 MODIFY COLUMN d INT;
+ALTER TABLE t1 ADD INDEX my_d (d);
+SHOW CREATE TABLE t1;
+INSERT INTO t1 VALUES (1),(2),(3),(4),(5),(6),(7),(8),(9);
+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;
+EXPLAIN SELECT d FROM t1 WHERE d = 5;
+EXPLAIN SELECT D FROM t1 WHERE D = 5;
+ALTER TABLE t1 DROP INDEX my_d;
+ALTER TABLE t1 MODIFY COLUMN D INT;
+ANALYZE TABLE t1;
+ALTER TABLE t1 ADD INDEX my_d (D);
+EXPLAIN SELECT d FROM t1 WHERE d = 5;
+EXPLAIN SELECT D FROM t1 WHERE D = 5;
+SHOW CREATE TABLE t1;
+DROP TABLE t1;
diff --git a/mysql-test/suite/innodb/t/innodb-enlarge-blob.opt b/mysql-test/suite/innodb/t/innodb-enlarge-blob.opt
new file mode 100644
index 00000000..2f9bf78f
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb-enlarge-blob.opt
@@ -0,0 +1,4 @@
+--innodb-file-per-table
+--innodb-buffer-pool-size=32M
+--innodb-page-size=64k
+--innodb-strict-mode=OFF
diff --git a/mysql-test/suite/innodb/t/innodb-enlarge-blob.test b/mysql-test/suite/innodb/t/innodb-enlarge-blob.test
new file mode 100644
index 00000000..65a64d29
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb-enlarge-blob.test
@@ -0,0 +1,29 @@
+--source include/have_innodb.inc
+
+#
+# MDEV-13227: Assertion failure len < 16384 in file rem0rec.cc line 1285
+# Crashes with innodb_page_size=64K. Does not crash at <= 32K.
+#
+CREATE TABLE t1 (a LONGTEXT) ENGINE=INNODB ROW_FORMAT=REDUNDANT;
+SHOW WARNINGS;
+INSERT INTO t1 SET a=CONCAT('A', SPACE(8000), 'B');
+INSERT INTO t1 SELECT a FROM t1;
+UPDATE t1 SET a=CONCAT(a, RAND(), a);
+UPDATE t1 SET a=CONCAT(a, RAND(), a);
+# random data no output we are only interested if fails
+--disable_result_log
+SELECT * from t1;
+--enable_result_log
+DROP TABLE t1;
+
+CREATE TABLE t1 (a LONGTEXT) ENGINE=INNODB ROW_FORMAT=DYNAMIC;
+SHOW WARNINGS;
+INSERT INTO t1 SET a=CONCAT('A', SPACE(8000), 'B');
+INSERT INTO t1 SELECT a FROM t1;
+UPDATE t1 SET a=CONCAT(a, RAND(), a);
+UPDATE t1 SET a=CONCAT(a, RAND(), a);
+# random data no output we are only interested if fails
+--disable_result_log
+SELECT * from t1;
+--enable_result_log
+DROP TABLE t1;
diff --git a/mysql-test/suite/innodb/t/innodb-fk-virtual.test b/mysql-test/suite/innodb/t/innodb-fk-virtual.test
new file mode 100644
index 00000000..094fda35
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb-fk-virtual.test
@@ -0,0 +1,61 @@
+--source include/have_innodb.inc
+
+#
+# MDEV-11850: Can't create foreign key referencing a virtual column
+#
+
+create or replace table a (
+ cola int(10) primary key,
+ v_cola int(10) as (cola mod 10) virtual,
+ p_cola int(10) as (cola mod 10) persistent
+) engine=innodb;
+
+create index v_cola on a (v_cola);
+create index p_cola on a (p_cola);
+
+create or replace table b(
+cola int(10),
+v_cola int(10),
+p_cola int(10),
+c_cola int(10) as (cola + 2) virtual
+) engine=innodb;
+
+alter table b add constraint `p_cola_fk`
+foreign key (p_cola) references a (p_cola)
+on delete restrict
+on update restrict;
+
+show warnings;
+show create table b;
+
+alter table b add constraint `v_cola_fk`
+foreign key (v_cola) references a (v_cola)
+on delete restrict
+on update restrict;
+
+show warnings;
+show create table b;
+
+alter table b add constraint `c_cola_fk`
+foreign key (c_cola) references a (cola)
+on delete restrict
+on update restrict;
+
+show warnings;
+show create table b;
+
+#
+# Test that fk really works
+#
+
+insert into a(cola) values (12);
+select * from a;
+insert into b(cola, v_cola, p_cola) values (10,2,2);
+select * from b;
+--error 1452
+insert into b(cola, v_cola, p_cola) values (10,1,1);
+--error 1451
+delete from a;
+select * from a;
+select * from b;
+drop table b, a;
diff --git a/mysql-test/suite/innodb/t/innodb-fk-warnings.test b/mysql-test/suite/innodb/t/innodb-fk-warnings.test
new file mode 100644
index 00000000..8a0ed581
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb-fk-warnings.test
@@ -0,0 +1,133 @@
+--source include/have_innodb.inc
+
+#
+# MDEV-8524: Improve error messaging when there is duplicate key or foreign key names
+#
+CREATE TABLE t1 (
+ id int(11) NOT NULL PRIMARY KEY,
+ a int(11) NOT NULL,
+ b int(11) NOT NULL,
+ c int not null,
+ CONSTRAINT test FOREIGN KEY (b) REFERENCES t1 (id)
+) ENGINE=InnoDB DEFAULT CHARSET=latin1;
+
+#
+# Below create table fails because constraint name test
+# is reserved for above table.
+#
+--error ER_CANT_CREATE_TABLE
+CREATE TABLE t2 (
+ id int(11) NOT NULL PRIMARY KEY,
+ a int(11) NOT NULL,
+ b int(11) NOT NULL,
+ c int not null,
+ CONSTRAINT mytest FOREIGN KEY (c) REFERENCES t1(id),
+ CONSTRAINT test FOREIGN KEY (b) REFERENCES t2 (id)
+) ENGINE=InnoDB DEFAULT CHARSET=latin1;
+
+show warnings;
+
+drop table t1;
+
+#
+# MDEV-6697: Improve foreign keys warnings/errors
+#
+
+#
+# No index for referenced columns
+#
+create table t1(a int) engine=innodb;
+--error ER_CANT_CREATE_TABLE
+create table t2(a int, constraint a foreign key a (a) references t1(a)) engine=innodb;
+show warnings;
+drop table t1;
+
+create table t1(a int unique, b int) engine=innodb;
+--error ER_CANT_CREATE_TABLE
+create table t2(a int, b int, foreign key (a) references t1(a), foreign key (b) references t1(b)) engine=innodb;
+show warnings;
+drop table t1;
+
+create table t1(a int not null primary key, b int) engine=innodb;
+--error ER_CANT_CREATE_TABLE
+create table t2(a int, b int, constraint a foreign key a (a) references t1(a),
+constraint a foreign key a (a) references t1(b)) engine=innodb;
+show warnings;
+create table t2(a int, b int, constraint a foreign key a (a) references t1(a)) engine=innodb;
+--error ER_CANT_CREATE_TABLE
+alter table t2 add constraint b foreign key (b) references t2(b);
+show warnings;
+drop table t2, t1;
+
+#
+# Referenced table does not exists
+#
+
+create table t1 (f1 integer primary key) engine=innodb;
+--error ER_CANT_CREATE_TABLE
+alter table t1 add constraint c1 foreign key (f1) references t11(f1);
+show warnings;
+drop table t1;
+
+#
+# Foreign key on temporal tables
+#
+
+create temporary table t1(a int not null primary key, b int, key(b)) engine=innodb;
+# remove echos and uncomment the commented when MDEV-8569 is fixed
+--echo create temporary table t2(a int, foreign key(a) references t1(a)) engine=innodb;
+--echo ERROR HY000: Can't create table `test`.`t2` (errno: 150 "Foreign key constraint is incorrectly formed")
+--echo show warnings;
+--echo Level Code Message
+--echo Warning 150 Create table `mysqld.1`.`t2` with foreign key constraint failed. Referenced table `mysqld.1`.`t1` not found in the data dictionary close to foreign key(a) references t1(a)) engine=innodb.
+--echo Error 1005 Can't create table `test`.`t2` (errno: 150 "Foreign key constraint is incorrectly formed")
+--echo Warning 1215 Cannot add foreign key constraint
+--echo alter table t1 add foreign key(b) references t1(a);
+--echo ERROR HY000: Can't create table `test`.`#sql-temporary` (errno: 150 "Foreign key constraint is incorrectly formed")
+--echo show warnings;
+--echo Level Code Message
+--echo Warning 150 Alter table `mysqld.1`.`t1` with foreign key constraint failed. Referenced table `mysqld.1`.`t1` not found in the data dictionary close to foreign key(b) references t1(a).
+--echo Error 1005 Can't create table `test`.`#sql-temporary` (errno: 150 "Foreign key constraint is incorrectly formed")
+--echo Warning 1215 Cannot add foreign key constraint
+--error ER_CANT_CREATE_TABLE
+create temporary table t2(a int, foreign key(a) references t1(a)) engine=innodb;
+show warnings;
+--error ER_CANT_CREATE_TABLE
+alter table t1 add foreign key(b) references t1(a);
+show warnings;
+drop table t1;
+
+#
+# Column numbers do not match
+#
+create table t1(a int not null primary key, b int, key(b)) engine=innodb;
+--error 1239
+alter table t1 add foreign key(a,b) references t1(a);
+show warnings;
+drop table t1;
+create table t1(a int not null primary key, b int, key(b)) engine=innodb;
+--error 1239
+alter table t1 add foreign key(a) references t1(a,b);
+show warnings;
+drop table t1;
+
+#
+# ON UPDATE/DELETE SET NULL on NOT NULL column
+#
+create table t1 (f1 integer not null primary key) engine=innodb;
+--error ER_CANT_CREATE_TABLE
+alter table t1 add constraint c1 foreign key (f1) references t1(f1) on update set null;
+show warnings;
+--error ER_CANT_CREATE_TABLE
+create table t2(a int not null, foreign key(a) references t1(f1) on delete set null) engine=innodb;
+show warnings;
+drop table t1;
+
+#
+# Incorrect types
+#
+create table t1 (id int not null primary key, f1 int, f2 int, key(f1)) engine=innodb;
+--error ER_CANT_CREATE_TABLE
+create table t2(a char(20), key(a), foreign key(a) references t1(f1)) engine=innodb;
+show warnings;
+drop table t1;
diff --git a/mysql-test/suite/innodb/t/innodb-fk.test b/mysql-test/suite/innodb/t/innodb-fk.test
new file mode 100644
index 00000000..6d5307a1
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb-fk.test
@@ -0,0 +1,262 @@
+--source include/have_innodb.inc
+--source include/not_embedded.inc
+
+--echo #
+--echo # Bug #18806829 OPENING INNODB TABLES WITH MANY FOREIGN KEY
+--echo # REFERENCES IS SLOW/CRASHES SEMAPHORE
+--echo #
+
+create table t1 (f1 int primary key) engine=innodb;
+insert into t1 values (5);
+insert into t1 values (2882);
+insert into t1 values (10);
+
+let $fk_tables = 120;
+
+--disable_query_log
+let $i = $fk_tables;
+while ($i)
+{
+ eval create table fk_$i (f1 int primary key,
+ constraint pc$i foreign key (f1) references t1(f1)
+ on delete cascade on update cascade) engine=innodb;
+ eval insert into fk_$i values (5);
+ eval insert into fk_$i values (2882);
+ eval insert into fk_$i values (10);
+ dec $i;
+}
+--enable_query_log
+
+--source include/restart_mysqld.inc
+
+update t1 set f1 = 28 where f1 = 2882;
+
+select * from fk_120;
+select * from fk_1;
+select * from fk_50;
+
+--disable_query_log
+let $i = $fk_tables;
+while ($i)
+{
+ eval drop table fk_$i;
+ dec $i;
+}
+--enable_query_log
+
+drop table t1;
+
+--echo #
+--echo # Check if restrict is working fine.
+--echo #
+
+create table t1 (f1 int primary key) engine=innodb;
+
+let $fk_tables = 30;
+
+--disable_query_log
+let $i = $fk_tables;
+while ($i)
+{
+ eval create table fk_$i (f1 int primary key,
+ constraint pc$i foreign key (f1) references t1(f1)
+ on delete restrict on update restrict) engine=innodb;
+ eval insert into t1 values ($i);
+ eval insert into fk_$i values ($i);
+ dec $i;
+}
+--enable_query_log
+
+--source include/restart_mysqld.inc
+
+--error ER_ROW_IS_REFERENCED_2
+delete from t1 where f1 = 29;
+select * from fk_29;
+
+--disable_query_log
+let $i = $fk_tables;
+while ($i)
+{
+ eval drop table fk_$i;
+ dec $i;
+}
+--enable_query_log
+
+drop table t1;
+
+#
+# MDEV-7672: Crash creating an InnoDB table with foreign keys
+#
+
+CREATE TABLE t1 (
+ id int(11) NOT NULL AUTO_INCREMENT,
+ f1 int(11) DEFAULT NULL,
+ PRIMARY KEY (id),
+ CONSTRAINT fk1 FOREIGN KEY (f1) REFERENCES t1 (id) ON DELETE CASCADE
+) ENGINE=InnoDB;
+
+--error 1005
+CREATE TABLE t2 (
+ id int(11) NOT NULL AUTO_INCREMENT,
+ f2 int(11) NOT NULL,
+ f3 int(11) NOT NULL,
+ PRIMARY KEY (`id`),
+ CONSTRAINT fk2 FOREIGN KEY (f2) REFERENCES t1 (`id`) ON DELETE CASCADE,
+ CONSTRAINT fk3 FOREIGN KEY (f3) REFERENCES t3 (id) ON DELETE CASCADE
+) ENGINE=InnoDB;
+
+show warnings;
+
+CREATE TABLE t2 (
+ id int(11) NOT NULL AUTO_INCREMENT,
+ f2 int(11) NOT NULL,
+ f3 int(11) NOT NULL,
+ PRIMARY KEY (`id`),
+ CONSTRAINT fk2 FOREIGN KEY (f2) REFERENCES t1 (`id`) ON DELETE CASCADE
+) ENGINE=InnoDB;
+
+--error 1005
+ALTER TABLE t2 ADD CONSTRAINT fk3 FOREIGN KEY (f3) REFERENCES t3 (id) ON DELETE CASCADE;
+
+show warnings;
+
+drop table t2;
+drop table t1;
+
+#
+# MDEV-9142 :Adding Constraint with no database reference
+# results in ERROR 1046 (3D000) at line 13: No database selected
+#
+CREATE DATABASE kg_test1;
+CREATE DATABASE kg_test2;
+
+CREATE TABLE `kg_test1`.`group` (
+ Id INT(11) NOT NULL AUTO_INCREMENT PRIMARY KEY
+) ENGINE=InnoDB DEFAULT CHARSET=utf8;
+
+CREATE TABLE `kg_test1`.`person` (
+`Id` INT(11) NOT NULL AUTO_INCREMENT,
+`Name` VARCHAR(50) NOT NULL,
+PRIMARY KEY (`Id`),
+CONSTRAINT `fk_person_group` FOREIGN KEY (`Id`) REFERENCES `group` (`Id`)
+) ENGINE=INNODB DEFAULT CHARSET=utf8;
+
+show create table `kg_test1`.`person`;
+
+--error 1005
+CREATE TABLE `kg_test2`.`person2` (
+`Id` INT(11) NOT NULL AUTO_INCREMENT,
+`Name` VARCHAR(50) NOT NULL,
+PRIMARY KEY (`Id`),
+CONSTRAINT `fk_person_group` FOREIGN KEY (`Id`) REFERENCES `group` (`Id`)
+) ENGINE=INNODB DEFAULT CHARSET=utf8;
+
+CREATE TABLE `kg_test2`.`person2` (
+`Id` INT(11) NOT NULL AUTO_INCREMENT,
+`Name` VARCHAR(50) NOT NULL,
+PRIMARY KEY (`Id`),
+CONSTRAINT `fk_person_group` FOREIGN KEY (`Id`) REFERENCES `kg_test1`.`group` (`Id`)
+) ENGINE=INNODB DEFAULT CHARSET=utf8;
+
+show create table `kg_test2`.`person2`;
+
+SHOW WARNINGS;
+DROP DATABASE kg_test2;
+DROP DATABASE kg_test1;
+
+#
+# MDEV-7627: Some symbols in table name can cause to Error Code: 1050 when created FK
+#
+
+CREATE TABLE `#departaments` (
+ `id_depart` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
+ PRIMARY KEY (`id_depart`)
+) ENGINE=INNODB DEFAULT CHARSET=utf8;
+
+CREATE TABLE `#departaments_tree` (
+ `id_depart` INT(10) UNSIGNED NOT NULL,
+ `id_depart_in` INT(10) UNSIGNED NOT NULL,
+ PRIMARY KEY (`id_depart`,`id_depart_in`),
+ CONSTRAINT `#departaments_tree_ibfk_1` FOREIGN KEY (`id_depart`) REFERENCES `#departaments` (`id_depart`)
+) ENGINE=INNODB DEFAULT CHARSET=utf8;
+
+ALTER TABLE `#departaments_tree`
+ ADD FOREIGN KEY (`id_depart_in`) REFERENCES `#departaments`(`id_depart`);
+
+SHOW CREATE TABLE `#departaments_tree`;
+
+DROP TABLE `#departaments_tree`;
+DROP TABLE `#departaments`;
+
+CREATE TABLE `boroda` (
+ `id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
+ `a` INT(11) UNSIGNED DEFAULT NULL,
+ `b` INT(11) UNSIGNED DEFAULT NULL,
+ PRIMARY KEY (`id`),
+ KEY `a` (`a`),
+ CONSTRAINT `boroda_ibfk_1` FOREIGN KEY (`a`) REFERENCES `boroda` (`id`)
+) ENGINE=INNODB DEFAULT CHARSET=utf8;
+
+ALTER TABLE `boroda`
+ ADD FOREIGN KEY (`b`) REFERENCES `boroda`(`id`);
+
+ALTER TABLE `boroda` DROP FOREIGN KEY `boroda_ibfk_2`;
+
+RENAME TABLE `boroda` TO `#boroda`;
+
+ALTER TABLE `#boroda`
+ADD FOREIGN KEY (`b`) REFERENCES `#boroda`(`id`);
+
+SHOW CREATE TABLE `#boroda`;
+DROP TABLE `#boroda`;
+
+CREATE TABLE `boroda` (
+ `id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
+ `a` INT(11) UNSIGNED DEFAULT NULL,
+ `b` INT(11) UNSIGNED DEFAULT NULL,
+ PRIMARY KEY (`id`),
+ KEY `a` (`a`),
+ CONSTRAINT `boroda_ibfk_1` FOREIGN KEY (`a`) REFERENCES `boroda` (`id`)
+) ENGINE=INNODB DEFAULT CHARSET=utf8;
+
+RENAME TABLE `boroda` TO `bor#oda`;
+
+ALTER TABLE `bor#oda`
+ADD FOREIGN KEY (`b`) REFERENCES `bor#oda`(`id`);
+
+SHOW CREATE TABLE `bor#oda`;
+DROP TABLE `bor#oda`;
+
+--echo #
+--echo # MDEV-21127 Assertion `(size_t)(ptr - buf) < MAX_TEXT - 4' failed in key_text::key_text
+--echo #
+--error ER_CANT_CREATE_TABLE
+CREATE TABLE t1 (
+ a012345678901234567890123456789012345678901 char(255),
+ b char(255),
+ FOREIGN KEY ( a012345678901234567890123456789012345678901, b ) REFERENCES tx (ax, bx)
+) ENGINE=InnoDB;
+
+--error ER_CANT_CREATE_TABLE
+CREATE TABLE t1 (
+ a012345678901234567 int,
+ b int,
+ c0123456789012345678 int,
+ FOREIGN KEY (a012345678901234567,c0123456789012345678,b) REFERENCES tx (x1,x2,x3)
+) ENGINE=InnoDB;
+
+--echo #
+--echo # MDEV-25642 InnoDB rename table copy DDL fails
+--echo # while dropping the table
+--echo #
+call mtr.add_suppression("InnoDB: In ALTER TABLE `test`.`t1` has or is referenced in foreign key constraints which are not compatible with the new table definition.");
+
+CREATE TABLE t1 (a VARCHAR(10) NOT NULL PRIMARY KEY) ENGINE=InnoDB;
+CREATE TABLE t1_fk (a VARCHAR(40), KEY a (a), FULLTEXT KEY(a), CONSTRAINT fk FOREIGN KEY(a) REFERENCES t1 (a) ON UPDATE CASCADE) ENGINE=InnoDB;
+ALTER TABLE t1 RENAME TO tm1, ALGORITHM=COPY;
+SELECT * FROM INFORMATION_SCHEMA.INNODB_SYS_FOREIGN;
+# Enable SET FOREIGN_KEY_CHECKS after fixing MDEV-25885
+SET FOREIGN_KEY_CHECKS=0;
+CREATE TABLE t1 (c1 BIGINT NOT NULL, c2 BIGINT NOT NULL, PRIMARY KEY(c1), UNIQUE KEY(c2)) ENGINE=MEMORY;
+ALTER TABLE t1 ENGINE=InnoDB, ALGORITHM=COPY;
+DROP TABLE t1, tm1, t1_fk;
diff --git a/mysql-test/suite/innodb/t/innodb-fkcheck.test b/mysql-test/suite/innodb/t/innodb-fkcheck.test
new file mode 100644
index 00000000..5ff3533f
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb-fkcheck.test
@@ -0,0 +1,125 @@
+--source include/have_innodb.inc
+--source include/default_charset.inc
+
+#
+# MDEV-10083: Orphan ibd file when playing with foreign keys
+#
+--disable_query_log
+SET @start_global_fpt = @@global.innodb_file_per_table;
+SET @start_global_fkc = @@global.foreign_key_checks;
+--enable_query_log
+
+set global innodb_file_per_table = 1;
+
+--disable_warnings
+drop table if exists b;
+drop database if exists bug_fk;
+--enable_warnings
+
+let $MYSQLD_DATADIR = `select @@datadir`;
+
+create database bug_fk;
+use bug_fk;
+
+CREATE TABLE b (
+ b int unsigned NOT NULL,
+ d1 datetime NOT NULL,
+ PRIMARY KEY (b,d1)
+) ENGINE=InnoDB;
+
+CREATE TABLE c (
+ b int unsigned NOT NULL,
+ d1 datetime NOT NULL,
+ d2 datetime NOT NULL,
+ PRIMARY KEY (b,d1),
+ CONSTRAINT b_fk FOREIGN KEY (b) REFERENCES b (b)
+) ENGINE=InnoDB;
+
+show warnings;
+
+set foreign_key_checks = 0;
+
+DROP TABLE IF EXISTS b;
+
+show create table c;
+
+#
+# Note that column b has different type in parent table
+#
+CREATE TABLE b (
+ b bigint unsigned NOT NULL,
+ d1 date NOT NULL,
+ PRIMARY KEY (b,d1)
+) ENGINE=InnoDB;
+DROP TABLE b;
+
+set foreign_key_checks = 1;
+--error ER_CANT_CREATE_TABLE
+CREATE TABLE b (
+ b bigint unsigned NOT NULL,
+ d1 date NOT NULL,
+ PRIMARY KEY (b,d1)
+) ENGINE=InnoDB;
+
+show warnings;
+set foreign_key_checks = 0;
+
+DROP TABLE IF EXISTS d;
+
+CREATE TABLE d (
+ b bigint unsigned NOT NULL,
+ d1 date NOT NULL,
+ PRIMARY KEY (b,d1),
+ CONSTRAINT bd_fk FOREIGN KEY (b) REFERENCES b (b)
+) ENGINE=InnoDB;
+
+show warnings;
+
+set foreign_key_checks = 1;
+
+show create table c;
+show create table d;
+
+#
+# Table c column b used on foreign key has different type
+# compared referenced column b in table b, but this
+# create still produced b.ibd file. This is because
+# we row_drop_table_for_mysql was called and referenced
+# table is not allowed to be dropped even in case
+# when actual create is not successfull.
+#
+--error 1005
+CREATE TABLE b (
+ b bigint unsigned NOT NULL,
+ d1 date NOT NULL,
+ PRIMARY KEY (b,d1)
+) ENGINE=InnoDB;
+
+show warnings;
+
+--list_files $MYSQLD_DATADIR/bug_fk b*
+
+set foreign_key_checks=0;
+
+drop table c;
+drop table d;
+
+--list_files $MYSQLD_DATADIR/bug_fk b*
+
+create table b(id int) engine=innodb;
+show warnings;
+
+--list_files $MYSQLD_DATADIR/bug_fk b*
+
+#
+# Cleanup
+#
+--disable_query_log
+SET @@global.innodb_file_per_table = @start_global_fpt;
+SET @@global.foreign_key_checks = @start_global_fkc;
+--enable_query_log
+
+--disable_warnings
+drop table if exists b;
+drop database if exists bug_fk;
+--enable_warnings
diff --git a/mysql-test/suite/innodb/t/innodb-get-fk.test b/mysql-test/suite/innodb/t/innodb-get-fk.test
new file mode 100644
index 00000000..b4b170b8
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb-get-fk.test
@@ -0,0 +1,71 @@
+--source include/have_innodb.inc
+--source include/default_charset.inc
+# need to restart server
+--source include/not_embedded.inc
+--source include/no_valgrind_without_big.inc
+
+CREATE SCHEMA `repro`;
+
+CREATE TABLE `repro`.`crew` (
+`id` int(11) NOT NULL AUTO_INCREMENT,
+`code` varchar(50) NOT NULL,
+`name` varchar(50) NOT NULL,
+`created_at` timestamp NULL DEFAULT NULL,
+`updated_at` timestamp NULL DEFAULT NULL,
+PRIMARY KEY (`id`),
+KEY `code` (`code`)
+) ENGINE=InnoDB;
+
+CREATE TABLE `repro`.`pilot` (
+`id` int(11) NOT NULL AUTO_INCREMENT,
+`code` varchar(50) NOT NULL,
+`name` varchar(50) NOT NULL,
+`created_at` timestamp NULL DEFAULT NULL,
+`updated_at` timestamp NULL DEFAULT NULL,
+PRIMARY KEY (`id`),
+KEY `code` (`code`)
+) ENGINE=InnoDB;
+
+CREATE TABLE `repro`.`crew_role_assigned` (
+`id` int(11) NOT NULL AUTO_INCREMENT,
+`crew_id` int(11) NOT NULL,
+`role_code` varchar(50) NOT NULL,
+PRIMARY KEY (`id`),
+KEY `fk_crewRoleAssigned_roleCode` (`role_code`),
+CONSTRAINT `fk_crewRoleAssigned_crewId` FOREIGN KEY (`crew_id`) REFERENCES `repro`.`crew` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
+CONSTRAINT `fk_crewRoleAssigned_pilotId` FOREIGN KEY (`crew_id`) REFERENCES `repro`.`pilot` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
+) ENGINE=InnoDB COMMENT="This is a comment about tables";
+
+-- let $restart_parameters=--innodb-read-only
+-- source include/restart_mysqld.inc
+
+--error ER_OPEN_AS_READONLY
+ALTER TABLE `repro`.`crew_role_assigned` COMMENT = 'innodb_read_only';
+SHOW CREATE TABLE `repro`.`crew_role_assigned`;
+
+# These should be ignored in innodb_read_only mode.
+SET GLOBAL innodb_buffer_pool_load_now = ON;
+SET GLOBAL innodb_buffer_pool_dump_now = ON;
+SET GLOBAL innodb_buffer_pool_load_abort = ON;
+
+-- let $restart_parameters=
+-- source include/restart_mysqld.inc
+
+ALTER TABLE `repro`.`crew_role_assigned` COMMENT = "This is a new comment about tables";
+SHOW CREATE TABLE `repro`.`crew_role_assigned`;
+
+-- let $restart_parameters=--innodb-read-only
+-- source include/restart_mysqld.inc
+
+#
+# Below create table should contain also fk definitions
+#
+SHOW CREATE TABLE `repro`.`crew_role_assigned`;
+
+-- let $restart_parameters=
+-- source include/restart_mysqld.inc
+
+DROP TABLE `repro`.`crew_role_assigned`;
+DROP TABLE `repro`.`pilot`;
+DROP TABLE `repro`.`crew`;
+DROP SCHEMA `repro`;
diff --git a/mysql-test/suite/innodb/t/innodb-index-debug.opt b/mysql-test/suite/innodb/t/innodb-index-debug.opt
new file mode 100644
index 00000000..778b4443
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb-index-debug.opt
@@ -0,0 +1 @@
+--innodb-sort-buffer-size=64k
diff --git a/mysql-test/suite/innodb/t/innodb-index-debug.test b/mysql-test/suite/innodb/t/innodb-index-debug.test
new file mode 100644
index 00000000..736e1295
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb-index-debug.test
@@ -0,0 +1,179 @@
+-- source include/have_debug.inc
+-- source include/have_innodb.inc
+-- source include/count_sessions.inc
+-- source include/have_debug_sync.inc
+# This test is slow on buildbot.
+--source include/big_test.inc
+
+let $MYSQLD_DATADIR= `select @@datadir`;
+SET GLOBAL innodb_max_purge_lag_wait=0;
+connect (stop_purge,localhost,root);
+START TRANSACTION WITH CONSISTENT SNAPSHOT;
+connection default;
+
+#
+# Test for BUG# 12739098, check whether trx->error_status is reset on error.
+#
+CREATE TABLE t1(c1 INT NOT NULL, c2 INT, PRIMARY KEY(c1)) Engine=InnoDB;
+SHOW CREATE TABLE t1;
+INSERT INTO t1 VALUES (1,1),(2,2),(3,3),(4,4),(5,5);
+
+SET @saved_debug_dbug = @@SESSION.debug_dbug;
+SET DEBUG_DBUG='+d,ib_build_indexes_too_many_concurrent_trxs, ib_rename_indexes_too_many_concurrent_trxs, ib_drop_index_too_many_concurrent_trxs';
+--error ER_TOO_MANY_CONCURRENT_TRXS
+ALTER TABLE t1 ADD UNIQUE INDEX(c2);
+SET DEBUG_DBUG = @saved_debug_dbug;
+
+SHOW CREATE TABLE t1;
+DROP TABLE t1;
+
+#
+# Test for Bug#13861218 Records are not fully sorted during index creation
+#
+CREATE TABLE bug13861218 (c1 INT NOT NULL, c2 INT NOT NULL, INDEX(c2))
+ENGINE=InnoDB;
+INSERT INTO bug13861218 VALUES (8, 0), (4, 0), (0, 0);
+SET DEBUG_DBUG = '+d,ib_row_merge_buf_add_two';
+# Force creation of a PRIMARY KEY on c1 to see what happens on the index(c2).
+# No crash here, because n_uniq for c2 includes the clustered index fields
+CREATE UNIQUE INDEX ui ON bug13861218(c1);
+SET DEBUG_DBUG = @saved_debug_dbug;
+DROP TABLE bug13861218;
+
+CREATE TABLE bug13861218 (c1 INT NOT NULL, c2 INT UNIQUE) ENGINE=InnoDB;
+INSERT INTO bug13861218 VALUES (8, NULL), (4, NULL), (0, NULL);
+SET DEBUG_DBUG = '+d,ib_row_merge_buf_add_two';
+# Force creation of a PRIMARY KEY on c1 to see what happens on the index(c2).
+# assertion failure: ut_ad(cmp_dtuple_rec(dtuple, rec, rec_offsets) > 0)
+CREATE UNIQUE INDEX ui ON bug13861218(c1);
+SET DEBUG_DBUG = @saved_debug_dbug;
+DROP TABLE bug13861218;
+
+--echo #
+--echo # Bug #17657223 EXCESSIVE TEMPORARY FILE USAGE IN ALTER TABLE
+--echo #
+
+# Error during file creation in alter operation
+create table t480(a serial)engine=innodb;
+insert into t480
+values(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),
+(),(),(),(),(),(),(),();
+insert into t480 select 0 from t480;
+insert into t480 select 0 from t480;
+insert into t480 select 0 from t480;
+insert into t480 select 0 from t480;
+
+# Error during file write in alter operation.
+create table t1(f1 int auto_increment not null,
+ f2 char(200) not null, f3 char(200) not null,
+ primary key(f1,f2,f3), key(f1))engine=innodb;
+insert into t1 select NULL,'aaa','bbb' from t480;
+insert into t1 select NULL,'aaaa','bbbb' from t480;
+insert into t1 select NULL,'aaaaa','bbbbb' from t480;
+insert into t1 select NULL,'aaaaaa','bbbbbb' from t480;
+SET DEBUG_DBUG = '+d,row_merge_write_failure';
+--error ER_TEMP_FILE_WRITE_FAILURE
+alter table t1 drop primary key,add primary key(f2,f1);
+SET DEBUG_DBUG = @saved_debug_dbug;
+drop table t1;
+
+# Optimize table via inplace algorithm
+connect (con1,localhost,root);
+create table t1(k1 int auto_increment primary key,
+k2 char(200),k3 char(200))engine=innodb;
+insert into t1 values(NULL,'a','b'), (NULL,'aa','bb');
+SET DEBUG_SYNC= 'row_merge_after_scan
+SIGNAL opened WAIT_FOR flushed';
+send optimize table t1;
+connection default;
+SET DEBUG_SYNC= 'now WAIT_FOR opened';
+INSERT INTO t1 select NULL,'aaa','bbb' from t480;
+SET DEBUG_SYNC= 'now SIGNAL flushed';
+connection con1;
+--enable_info
+--echo /*con1 reap*/ Optimize table t1;
+reap;
+--disable_info
+SELECT COUNT(k1),k2,k3 FROM t1 GROUP BY k2,k3;
+drop table t1;
+
+# Log file creation failure.
+create table t1(k1 int auto_increment primary key,
+k2 char(200),k3 char(200))engine=innodb;
+INSERT INTO t1 VALUES(1, "test", "test");
+SET DEBUG_SYNC= 'row_merge_after_scan
+SIGNAL opened WAIT_FOR flushed';
+send ALTER TABLE t1 FORCE, ADD COLUMN k4 int;
+connection default;
+SET DEBUG_SYNC= 'now WAIT_FOR opened';
+SET debug = '+d,row_log_tmpfile_fail';
+INSERT INTO t1 select NULL,'aaa','bbb' from t480;
+INSERT INTO t1 select NULL,'aaaa','bbbb' from t480;
+SET DEBUG_SYNC= 'now SIGNAL flushed';
+SET DEBUG_DBUG = @saved_debug_dbug;
+connection con1;
+--echo /*con1 reap*/ ALTER TABLE t1 ADD COLUMN k4 int;
+--error ER_OUT_OF_RESOURCES
+reap;
+SELECT COUNT(k1),k2,k3 FROM t1 GROUP BY k2,k3;
+disconnect con1;
+connection default;
+show create table t1;
+drop table t1;
+drop table t480;
+--echo #
+--echo # MDEV-12827 Assertion failure when reporting duplicate key error
+--echo # in online table rebuild
+--echo #
+
+CREATE TABLE t1 (j INT UNIQUE, i INT) ENGINE=InnoDB;
+INSERT INTO t1 VALUES(2, 2);
+--connect (con1,localhost,root,,test)
+SET DEBUG_SYNC='row_log_table_apply1_before SIGNAL built WAIT_FOR log';
+--send
+ALTER TABLE t1 DROP j, ADD UNIQUE INDEX(i), FORCE;
+
+--connection default
+SET DEBUG_SYNC='now WAIT_FOR built';
+SET DEBUG_DBUG='+d,row_ins_row_level';
+INSERT INTO t1 (i) VALUES (0),(0);
+SET DEBUG_SYNC='now SIGNAL log';
+SET DEBUG_DBUG=@saved_debug_dbug;
+
+--connection con1
+--error ER_DUP_ENTRY
+reap;
+DELETE FROM t1;
+ALTER TABLE t1 ADD UNIQUE INDEX(i);
+SET DEBUG_SYNC='row_log_table_apply1_before SIGNAL built2 WAIT_FOR log2';
+--send
+ALTER TABLE t1 DROP j, FORCE;
+
+--connection default
+SET DEBUG_SYNC='now WAIT_FOR built2';
+INSERT INTO t1 (i) VALUES (0),(1);
+--error ER_DUP_ENTRY
+UPDATE t1 SET i=0;
+SET DEBUG_SYNC='now SIGNAL log2';
+
+--connection con1
+reap;
+--disconnect con1
+--disconnect stop_purge
+--connection default
+SET DEBUG_SYNC='RESET';
+DROP TABLE t1;
+
+SET DEBUG_SYNC='RESET';
+--source include/wait_until_count_sessions.inc
+
+--echo #
+--echo # BUG#21612714 ALTER TABLE SORTING SKIPPED WHEN CHANGE PK AND DROP
+--echo # LAST COLUMN OF OLD PK
+--echo #
+
+SET DEBUG_DBUG = '+d,innodb_alter_table_pk_assert_no_sort';
+
+--source suite/innodb/include/alter_table_pk_no_sort.inc
+
+SET DEBUG_DBUG = @saved_debug_dbug;
diff --git a/mysql-test/suite/innodb/t/innodb-index-online-delete.test b/mysql-test/suite/innodb/t/innodb-index-online-delete.test
new file mode 100644
index 00000000..ec5f9373
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb-index-online-delete.test
@@ -0,0 +1,36 @@
+--source include/have_innodb.inc
+--source include/have_debug_sync.inc
+
+# Save the initial number of concurrent sessions.
+--source include/count_sessions.inc
+
+connect (con1,localhost,root,,);
+
+connection default;
+
+CREATE TABLE t (a INT PRIMARY KEY, b INT NOT NULL) ENGINE=InnoDB;
+INSERT INTO t VALUES(1,2),(2,3);
+
+SET DEBUG_SYNC='alter_table_inplace_after_lock_downgrade SIGNAL do WAIT_FOR m';
+SET DEBUG_SYNC='innodb_after_inplace_alter_table SIGNAL scanned WAIT_FOR done';
+--send
+CREATE INDEX tb ON t(b);
+
+connection con1;
+SET DEBUG_SYNC='now WAIT_FOR do';
+SET DEBUG_SYNC='row_update_for_mysql_error SIGNAL m WAIT_FOR scanned';
+--error ER_DUP_ENTRY
+UPDATE t SET a=2 WHERE a=1;
+call mtr.add_suppression('InnoDB: record in index .*tb was not found on rollback, trying to insert');
+SET DEBUG_SYNC='now SIGNAL done';
+
+disconnect con1;
+
+connection default;
+reap;
+SET DEBUG_SYNC='RESET';
+DROP TABLE t;
+
+# 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/suite/innodb/t/innodb-index-online-fk.opt b/mysql-test/suite/innodb/t/innodb-index-online-fk.opt
new file mode 100644
index 00000000..345d5529
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb-index-online-fk.opt
@@ -0,0 +1,4 @@
+--loose-innodb-sys-tables
+--loose-innodb-sys-columns
+--loose-innodb-sys-foreign
+--loose-innodb-sys-foreign-cols
diff --git a/mysql-test/suite/innodb/t/innodb-index-online-fk.test b/mysql-test/suite/innodb/t/innodb-index-online-fk.test
new file mode 100644
index 00000000..5423516c
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb-index-online-fk.test
@@ -0,0 +1,484 @@
+--source include/have_innodb.inc
+--source include/have_debug.inc
+
+CREATE TABLE parent (a INT PRIMARY KEY, b INT NOT NULL) ENGINE = InnoDB;
+INSERT INTO parent VALUES(1,2),(2,3);
+
+CREATE INDEX tb ON parent(b);
+
+INSERT INTO parent VALUES(10,20),(20,30);
+
+CREATE TABLE child (a1 INT PRIMARY KEY, a2 INT) ENGINE = InnoDB;
+
+CREATE INDEX tb ON child(a2);
+
+INSERT INTO child VALUES(10,20);
+
+--error ER_ALTER_OPERATION_NOT_SUPPORTED_REASON
+ALTER TABLE child ADD FOREIGN KEY(a2) REFERENCES parent(b),
+ALGORITHM = INPLACE;
+
+SET foreign_key_checks = 0;
+
+ALTER TABLE child ADD CONSTRAINT fk_1 FOREIGN KEY (a2)
+REFERENCES parent(b) ON DELETE SET NULL ON UPDATE CASCADE,
+ALGORITHM = INPLACE;
+
+SELECT * FROM information_schema.INNODB_SYS_FOREIGN;
+
+SELECT * FROM information_schema.INNODB_SYS_FOREIGN_COLS;
+
+# duplicated foreign key name
+--error ER_DUP_CONSTRAINT_NAME
+ALTER TABLE child ADD CONSTRAINT fk_1 FOREIGN KEY (a2)
+REFERENCES parent(b) ON DELETE SET NULL ON UPDATE CASCADE,
+ALGORITHM = INPLACE;
+
+SET foreign_key_checks = 1;
+
+INSERT INTO child VALUES(1,2),(2,3);
+
+--error ER_NO_REFERENCED_ROW_2
+INSERT INTO child VALUES(4,4);
+
+SELECT * FROM parent;
+
+SET foreign_key_checks = 0;
+
+# This would fail. No corresponding index
+--error ER_FK_NO_INDEX_PARENT
+ALTER TABLE child ADD CONSTRAINT fk_20 FOREIGN KEY (a1, a2)
+REFERENCES parent(a, b) ON DELETE CASCADE ON UPDATE CASCADE,
+ALGORITHM = INPLACE;
+
+SHOW WARNINGS;
+
+SHOW ERRORS;
+
+CREATE INDEX idx1 on parent(a, b);
+
+ALTER TABLE child ADD CONSTRAINT fk_10 FOREIGN KEY (a1, a2)
+REFERENCES parent(a, b) ON DELETE CASCADE ON UPDATE CASCADE,
+ALGORITHM = INPLACE;
+
+# This should be successful, as we added the index
+ALTER TABLE child ADD CONSTRAINT fk_2 FOREIGN KEY (a1, a2)
+REFERENCES parent(a, b) ON DELETE CASCADE ON UPDATE CASCADE, ADD INDEX idx1(a1,a2),
+ALGORITHM = INPLACE;
+
+ALTER TABLE child ADD CONSTRAINT fk_3 FOREIGN KEY (a1, a2)
+REFERENCES parent(a, b) ON DELETE CASCADE ON UPDATE CASCADE;
+
+SELECT * FROM information_schema.INNODB_SYS_FOREIGN;
+
+SELECT * FROM information_schema.INNODB_SYS_FOREIGN_COLS;
+
+SET foreign_key_checks = 1;
+
+--error ER_NO_REFERENCED_ROW_2
+INSERT INTO child VALUES(5,4);
+
+SHOW CREATE TABLE child;
+
+DELETE FROM parent where a = 1;
+
+SELECT * FROM child;
+
+# Now test referenced table cannot be opened. This should work fine
+# when foreign_key_checks is set to 0
+
+SET foreign_key_checks = 0;
+
+# This is to test the scenario we cannot open the referenced table.
+# Since foreign_key_checks is set to 0, the foreign key should still
+# be added.
+SET @saved_debug_dbug = @@SESSION.debug_dbug;
+SET DEBUG_DBUG = '+d,innodb_test_open_ref_fail';
+ALTER TABLE child ADD CONSTRAINT fk_4 FOREIGN KEY (a1, a2)
+REFERENCES parent(a, b) ON DELETE CASCADE ON UPDATE CASCADE,
+ALGORITHM = INPLACE;
+SET DEBUG_DBUG = @saved_debug_dbug;
+
+SELECT * FROM information_schema.INNODB_SYS_FOREIGN;
+
+SELECT * FROM information_schema.INNODB_SYS_FOREIGN_COLS;
+
+SELECT t2.name, t1.name FROM information_schema.innodb_sys_columns t1, information_schema.innodb_sys_tables t2 WHERE t1.table_id = t2.table_id AND t2.name LIKE "%child" ORDER BY t1.name;
+
+SELECT NAME FROM information_schema.INNODB_SYS_TABLES;
+
+# this should succeed, since we disabled the foreign key check
+INSERT INTO child VALUES(5,4);
+
+SET foreign_key_checks = 1;
+
+--error ER_NO_REFERENCED_ROW_2
+INSERT INTO child VALUES(6,5);
+
+SET foreign_key_checks = 0;
+
+# Create some table with 'funny' characters, for testing the
+# error message
+CREATE TABLE `#parent` (a INT PRIMARY KEY, b INT NOT NULL) ENGINE = InnoDB;
+
+CREATE INDEX tb ON `#parent`(a, b);
+
+CREATE TABLE `#child` (a1 INT PRIMARY KEY, a2 INT) ENGINE = InnoDB;
+
+CREATE INDEX tb ON `#child`(a1, a2);
+
+# This is to test the scenario no foreign index, alter table should fail
+SET DEBUG_DBUG = '+d,innodb_test_no_foreign_idx';
+--error ER_FK_NO_INDEX_CHILD,
+ALTER TABLE `#child` ADD CONSTRAINT fk_40 FOREIGN KEY (a1, a2)
+REFERENCES `#parent`(a, b) ON DELETE CASCADE ON UPDATE CASCADE,
+ALGORITHM = INPLACE;
+SET DEBUG_DBUG = @saved_debug_dbug;
+
+SHOW ERRORS;
+
+SELECT * FROM information_schema.INNODB_SYS_FOREIGN;
+
+SELECT * FROM information_schema.INNODB_SYS_FOREIGN_COLS;
+
+# This is to test the scenario no index on referenced table,
+# alter table should fail
+SET DEBUG_DBUG = '+d,innodb_test_no_reference_idx';
+--error ER_FK_NO_INDEX_PARENT,
+ALTER TABLE child ADD CONSTRAINT fk_42 FOREIGN KEY (a1, a2)
+REFERENCES parent(a, b) ON DELETE CASCADE ON UPDATE CASCADE,
+ALGORITHM = INPLACE;
+SET DEBUG_DBUG = @saved_debug_dbug;
+
+SHOW ERRORS;
+
+# This is to test the scenario no index on referenced table,
+# alter table should fail
+SET DEBUG_DBUG = '+d,innodb_test_wrong_fk_option';
+--error ER_FK_INCORRECT_OPTION
+ALTER TABLE child ADD CONSTRAINT fk_42 FOREIGN KEY (a1, a2)
+REFERENCES parent(a, b) ON DELETE CASCADE ON UPDATE CASCADE,
+ALGORITHM = INPLACE;
+SET DEBUG_DBUG = @saved_debug_dbug;
+
+SELECT * FROM information_schema.INNODB_SYS_FOREIGN;
+
+SELECT * FROM information_schema.INNODB_SYS_FOREIGN_COLS;
+
+# This is to test the scenario cannot add fk to the system table,
+# alter table should fail
+SET DEBUG_DBUG = '+d,innodb_test_cannot_add_fk_system';
+--error ER_FK_FAIL_ADD_SYSTEM
+ALTER TABLE `#child` ADD CONSTRAINT fk_43 FOREIGN KEY (a1, a2)
+REFERENCES `#parent`(a, b) ON DELETE CASCADE ON UPDATE CASCADE,
+ALGORITHM = INPLACE;
+SET DEBUG_DBUG = @saved_debug_dbug;
+
+SHOW ERRORS;
+
+DROP TABLE `#child`;
+DROP TABLE `#parent`;
+
+# Now test add multiple foreign key constrain in a single clause
+SET foreign_key_checks = 0;
+
+ALTER TABLE child ADD CONSTRAINT fk_5 FOREIGN KEY (a2) REFERENCES parent(b)
+ON DELETE SET NULL ON UPDATE CASCADE,
+ADD CONSTRAINT fk_6 FOREIGN KEY (a1, a2)
+REFERENCES parent(a, b) ON DELETE CASCADE ON UPDATE CASCADE,
+ALGORITHM = INPLACE;
+
+SELECT * FROM information_schema.INNODB_SYS_FOREIGN;
+
+SELECT * FROM information_schema.INNODB_SYS_FOREIGN_COLS;
+
+DROP TABLE child;
+DROP TABLE parent;
+
+# Test a case where child's foreign key index is being dropped in the
+# same clause of adding the foreign key. In theory, MySQL will
+# automatically create a new index to meet the index requirement
+CREATE TABLE parent (a INT PRIMARY KEY, b INT NOT NULL) ENGINE = InnoDB;
+
+INSERT INTO parent VALUES(1,2),(2,3);
+
+CREATE INDEX tb ON parent(b);
+
+INSERT INTO parent VALUES(10,20),(20,30);
+
+CREATE TABLE child (a1 INT PRIMARY KEY, a2 INT) ENGINE = InnoDB;
+
+CREATE INDEX tb ON child(a2);
+
+INSERT INTO child VALUES(10,20);
+
+SET foreign_key_checks = 0;
+
+ALTER TABLE child DROP INDEX tb, ADD CONSTRAINT fk_4 FOREIGN KEY (a2)
+REFERENCES parent(b) ON DELETE CASCADE ON UPDATE CASCADE,
+ALGORITHM = INPLACE;
+
+SHOW CREATE TABLE child;
+
+SELECT * FROM information_schema.INNODB_SYS_FOREIGN;
+
+SELECT * FROM information_schema.INNODB_SYS_FOREIGN_COLS;
+
+SET foreign_key_checks = 1;
+
+DROP TABLE child;
+
+DROP TABLE parent;
+
+# Test ADD FOREIGN KEY together with renaming columns.
+CREATE TABLE parent (a INT PRIMARY KEY, b INT NOT NULL) ENGINE = InnoDB;
+
+INSERT INTO parent VALUES(1,2),(2,3);
+
+CREATE INDEX tb ON parent(b);
+
+INSERT INTO parent VALUES(10,20),(20,30);
+
+CREATE TABLE child (a1 INT PRIMARY KEY, a2 INT) ENGINE = InnoDB;
+
+CREATE INDEX tb ON child(a2);
+
+SET foreign_key_checks = 0;
+
+--error ER_KEY_COLUMN_DOES_NOT_EXIST
+ALTER TABLE child CHANGE a2 a3 INT,
+ADD CONSTRAINT fk_1 FOREIGN KEY (a2) REFERENCES parent(b)
+ON DELETE SET NULL ON UPDATE CASCADE,
+ALGORITHM = INPLACE;
+
+ALTER TABLE child CHANGE a2 a3 INT,
+ADD CONSTRAINT fk_1 FOREIGN KEY (a3) REFERENCES parent(b)
+ON DELETE SET NULL ON UPDATE CASCADE,
+ALGORITHM = INPLACE;
+
+DROP TABLE child;
+
+DROP TABLE parent;
+
+# Add test for add Primary key and FK on changing columns
+CREATE TABLE parent (a INT PRIMARY KEY, b INT NOT NULL) ENGINE = InnoDB;
+INSERT INTO parent VALUES(1,2),(2,3);
+
+CREATE INDEX tb ON parent(b);
+
+INSERT INTO parent VALUES(10,20),(20,30);
+
+CREATE TABLE child (a1 INT NOT NULL, a2 INT) ENGINE = InnoDB;
+
+CREATE INDEX tb ON child(a2);
+
+SET foreign_key_checks = 0;
+
+# Let's rebuild the table and add the FK, make the add FK failed.
+
+SET DEBUG_DBUG = '+d,innodb_test_cannot_add_fk_system';
+--error ER_FK_FAIL_ADD_SYSTEM
+ALTER TABLE child ADD PRIMARY KEY idx (a3), CHANGE a1 a3 INT,
+ADD CONSTRAINT fk_1 FOREIGN KEY (a2) REFERENCES parent(b)
+ON DELETE SET NULL ON UPDATE CASCADE,
+ALGORITHM = INPLACE;
+SET DEBUG_DBUG = @saved_debug_dbug;
+
+SELECT * FROM INFORMATION_SCHEMA.INNODB_SYS_FOREIGN;
+SELECT * FROM INFORMATION_SCHEMA.INNODB_SYS_FOREIGN_COLS;
+SELECT t2.name, t1.name FROM information_schema.innodb_sys_columns t1, information_schema.innodb_sys_tables t2 WHERE t1.table_id = t2.table_id AND t2.name LIKE "%child" ORDER BY t1.name;
+SELECT NAME FROM information_schema.INNODB_SYS_TABLES;
+
+# This should be successful. It will also check any left over
+# from previous failed operation (if dictionary entries not cleaned,
+# it will have dup key error.
+ALTER TABLE child ADD PRIMARY KEY idx (a3), CHANGE a1 a3 INT,
+ADD CONSTRAINT fk_1 FOREIGN KEY (a2) REFERENCES parent(b)
+ON DELETE SET NULL ON UPDATE CASCADE,
+ALGORITHM = INPLACE;
+
+SELECT * FROM INFORMATION_SCHEMA.INNODB_SYS_FOREIGN;
+SELECT * FROM INFORMATION_SCHEMA.INNODB_SYS_FOREIGN_COLS;
+SELECT t2.name, t1.name FROM information_schema.innodb_sys_columns t1, information_schema.innodb_sys_tables t2 WHERE t1.table_id = t2.table_id AND t2.name LIKE "%child" ORDER BY t1.name;
+SELECT NAME FROM information_schema.INNODB_SYS_TABLES;
+
+SHOW CREATE TABLE child;
+
+DROP TABLE child;
+
+CREATE TABLE child (a1 INT NOT NULL, a2 INT) ENGINE = InnoDB;
+
+# Now try primary index and FK
+ALTER TABLE child ADD PRIMARY KEY idx (a1),
+ADD CONSTRAINT fk_1 FOREIGN KEY (a2) REFERENCES parent(b)
+ON DELETE SET NULL ON UPDATE CASCADE,
+ALGORITHM = INPLACE;
+
+SELECT * from information_schema.INNODB_SYS_FOREIGN;
+SELECT * from information_schema.INNODB_SYS_FOREIGN_COLS;
+SELECT t2.name, t1.name FROM information_schema.innodb_sys_columns t1, information_schema.innodb_sys_tables t2 WHERE t1.table_id = t2.table_id AND t2.name LIKE "%child" ORDER BY t1.name;
+SELECT NAME FROM information_schema.INNODB_SYS_TABLES;
+
+SHOW CREATE TABLE child;
+
+DROP TABLE child;
+
+CREATE TABLE child (a1 INT NOT NULL, a2 INT) ENGINE = InnoDB;
+
+ALTER TABLE child CHANGE a1 a3 INT,
+ADD CONSTRAINT fk_1 FOREIGN KEY (a3) REFERENCES parent(b)
+ON DELETE SET NULL ON UPDATE CASCADE,
+ALGORITHM = INPLACE;
+
+SELECT * from information_schema.INNODB_SYS_FOREIGN;
+SELECT * from information_schema.INNODB_SYS_FOREIGN_COLS;
+SELECT t2.name, t1.name FROM information_schema.innodb_sys_columns t1, information_schema.innodb_sys_tables t2 WHERE t1.table_id = t2.table_id AND t2.name LIKE "%child" ORDER BY t1.name;
+SELECT NAME FROM information_schema.INNODB_SYS_TABLES;
+
+SHOW CREATE TABLE child;
+
+DROP TABLE child;
+
+CREATE TABLE child (a1 INT NOT NULL, a2 INT) ENGINE = InnoDB;
+# Now try all three
+--error ER_FK_INCORRECT_OPTION
+ALTER TABLE child ADD PRIMARY KEY idx (a3), CHANGE a1 a3 INT,
+ADD CONSTRAINT fk_1 FOREIGN KEY (a3) REFERENCES parent(b)
+ON DELETE SET NULL ON UPDATE CASCADE,
+ALGORITHM = INPLACE;
+
+DROP TABLE parent;
+DROP TABLE child;
+
+CREATE TABLE parent (a INT PRIMARY KEY, b INT NOT NULL, c INT) ENGINE = InnoDB;
+INSERT INTO parent VALUES(1,2,3),(2,3,4);
+
+CREATE INDEX tb ON parent(b);
+
+CREATE TABLE child (a1 INT NOT NULL, a2 INT, a3 INT) ENGINE = InnoDB;
+CREATE INDEX tb ON child(a2);
+
+ALTER TABLE child
+ADD CONSTRAINT fk_a FOREIGN KEY (a2) REFERENCES parent(b)
+ON DELETE SET NULL ON UPDATE CASCADE,
+ALGORITHM = INPLACE;
+
+ALTER TABLE child
+ADD CONSTRAINT fk_b FOREIGN KEY (a1) REFERENCES parent(a),
+ALGORITHM = INPLACE;
+
+ALTER TABLE child CHANGE a2 a2_new INT, CHANGE a1 a1_new INT;
+
+SHOW CREATE TABLE child;
+
+SELECT * from information_schema.INNODB_SYS_FOREIGN;
+SELECT * from information_schema.INNODB_SYS_FOREIGN_COLS;
+
+# The third add FK will fail
+--error ER_FK_NO_INDEX_PARENT
+ALTER TABLE child
+ADD CONSTRAINT fk_new_1 FOREIGN KEY (a1_new) REFERENCES parent(b),
+ADD CONSTRAINT fk_new_2 FOREIGN KEY (a2_new) REFERENCES parent(a),
+ADD CONSTRAINT fk_new_3 FOREIGN KEY (a3) REFERENCES parent(c),
+ALGORITHM = INPLACE;
+
+# It should still have only 2 FKs
+SHOW CREATE TABLE child;
+
+SELECT * from information_schema.INNODB_SYS_FOREIGN;
+
+SELECT * from information_schema.INNODB_SYS_FOREIGN_COLS;
+
+#Now let's make it successful
+ALTER TABLE child
+ADD CONSTRAINT fk_new_1 FOREIGN KEY (a1_new) REFERENCES parent(b),
+ADD CONSTRAINT fk_new_2 FOREIGN KEY (a2_new) REFERENCES parent(a),
+ADD CONSTRAINT fk_new_3 FOREIGN KEY (a3) REFERENCES parent(a),
+ALGORITHM = INPLACE;
+
+# It should still have 5 FKs
+SHOW CREATE TABLE child;
+
+SELECT * from information_schema.INNODB_SYS_FOREIGN;
+
+SELECT * from information_schema.INNODB_SYS_FOREIGN_COLS;
+
+DROP TABLE child;
+CREATE TABLE child (a1 INT NOT NULL, a2 INT, a3 INT) ENGINE = InnoDB;
+CREATE INDEX tb ON child(a2);
+
+# Let's try this 3rd fk failure with add primary index
+--error ER_FK_NO_INDEX_PARENT
+ALTER TABLE child ADD PRIMARY KEY idx (a1),
+ADD CONSTRAINT fk_new_1 FOREIGN KEY (a1) REFERENCES parent(b),
+ADD CONSTRAINT fk_new_2 FOREIGN KEY (a2) REFERENCES parent(a),
+ADD CONSTRAINT fk_new_3 FOREIGN KEY (a3) REFERENCES parent(c),
+ALGORITHM = INPLACE;
+
+# It should still have no FKs, no PRIMARY
+SHOW CREATE TABLE child;
+
+SELECT * from information_schema.INNODB_SYS_FOREIGN;
+
+SELECT * from information_schema.INNODB_SYS_FOREIGN_COLS;
+
+# make it successful
+ALTER TABLE child ADD PRIMARY KEY idx (a1),
+ADD CONSTRAINT fk_new_1 FOREIGN KEY (a1) REFERENCES parent(b),
+ADD CONSTRAINT fk_new_2 FOREIGN KEY (a2) REFERENCES parent(a),
+ADD CONSTRAINT fk_new_3 FOREIGN KEY (a3) REFERENCES parent(a),
+ALGORITHM = INPLACE;
+
+# It should have 3 FKs, a new PRIMARY
+SHOW CREATE TABLE child;
+
+SELECT * from information_schema.INNODB_SYS_FOREIGN;
+
+SELECT * from information_schema.INNODB_SYS_FOREIGN_COLS;
+
+SET foreign_key_checks = 1;
+
+DROP TABLE child;
+DROP TABLE parent;
+
+CREATE TABLE Parent (a INT PRIMARY KEY, b INT NOT NULL) ENGINE = InnoDB;
+INSERT INTO Parent VALUES(1,2),(2,3);
+
+CREATE INDEX tb ON Parent(b);
+
+INSERT INTO Parent VALUES(10,20),(20,30);
+
+CREATE TABLE Child (a1 INT PRIMARY KEY, a2 INT) ENGINE = InnoDB;
+
+CREATE INDEX tb ON Child(a2);
+
+INSERT INTO Child VALUES(10,20);
+
+SET foreign_key_checks = 0;
+
+ALTER TABLE Child ADD CONSTRAINT fk_1 FOREIGN KEY (a2)
+REFERENCES Parent(b) ON DELETE SET NULL ON UPDATE CASCADE,
+ALGORITHM = INPLACE;
+
+DROP TABLE Child;
+DROP TABLE Parent;
+
+# This is the test for bug 14594526 - FK: ASSERTION IN
+# DICT_TABLE_CHECK_FOR_DUP_INDEXES
+CREATE TABLE `t2`(a int,c int,d int) ENGINE=INNODB;
+CREATE TABLE `t3`(a int,c int,d int) ENGINE=INNODB;
+CREATE INDEX idx ON t3(a);
+
+ALTER TABLE `t2` ADD CONSTRAINT `fw` FOREIGN KEY (`c`) REFERENCES t3 (a);
+
+ALTER TABLE `t2` ADD CONSTRAINT `e` foreign key (`d`) REFERENCES t3(a);
+
+--error ER_FK_FAIL_ADD_SYSTEM
+ALTER TABLE `t3` ADD CONSTRAINT `e` foreign key (`c`) REFERENCES `t2`(`c`) ON UPDATE SET NULL;
+
+SELECT * FROM INFORMATION_SCHEMA.INNODB_SYS_FOREIGN;
+SELECT * FROM INFORMATION_SCHEMA.INNODB_SYS_FOREIGN_COLS;
+
+DROP TABLE t2;
+
+DROP TABLE t3;
diff --git a/mysql-test/suite/innodb/t/innodb-index-online-norebuild.opt b/mysql-test/suite/innodb/t/innodb-index-online-norebuild.opt
new file mode 100644
index 00000000..39b93371
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb-index-online-norebuild.opt
@@ -0,0 +1 @@
+--loose-innodb-sys-tables
diff --git a/mysql-test/suite/innodb/t/innodb-index-online-norebuild.test b/mysql-test/suite/innodb/t/innodb-index-online-norebuild.test
new file mode 100644
index 00000000..518b4efe
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb-index-online-norebuild.test
@@ -0,0 +1,71 @@
+--source include/have_innodb.inc
+
+--echo # INPLACE ALTER WITH INPLACE_IGNORE FLAG AND CHANGE CREATE OPTION
+
+--echo # CHANGE THE COLUMN DEFAULT (INPLACE_IGNORE)
+--echo # AND TABLE CHARSET(CHANGE CREATE)
+
+CREATE TABLE t1(
+ id INT PRIMARY KEY,
+ f1 INT NOT NULL DEFAULT 0)ENGINE=INNODB;
+
+INSERT INTO t1 VALUES(1, 2);
+
+let id_before_alter =`SELECT table_id FROM INFORMATION_SCHEMA.INNODB_SYS_TABLES WHERE name="test/t1"`;
+
+# Allow the following operation to report errors.
+SET SQL_MODE='STRICT_ALL_TABLES';
+ALTER TABLE t1 MODIFY COLUMN f1 INT NOT NULL DEFAULT 0,
+ DEFAULT CHARSET=latin1, ALGORITHM=INPLACE;
+
+let id_after_alter =`SELECT table_id FROM INFORMATION_SCHEMA.INNODB_SYS_TABLES WHERE name="test/t1"`;
+
+if ($id_before_alter != $id_after_alter)
+{
+ --echo "Table rebuild happened";
+}
+
+DROP TABLE t1;
+
+--echo # CHANGE THE COMMENT OF COLUMN(INPLACE IGNORE)
+--echo # AND TABLE CHARSET(CHANGE CREATE)
+
+CREATE TABLE t1(id INT COMMENT 'independence day')ENGINE=INNODB;
+
+INSERT INTO t1 values(1);
+
+let id_before_alter =`SELECT table_id FROM INFORMATION_SCHEMA.INNODB_SYS_TABLES WHERE name="test/t1"`;
+
+ALTER TABLE t1 MODIFY COLUMN id INT COMMENT 'identifier',
+ DEFAULT CHARSET=latin1, ALGORITHM=INPLACE;
+
+let id_after_alter =`SELECT table_id FROM INFORMATION_SCHEMA.INNODB_SYS_TABLES WHERE name="test/t1"`;
+
+if ($id_before_alter != $id_after_alter)
+{
+ --echo "Table rebuild happened";
+}
+
+DROP TABLE t1;
+
+--echo # RENAME THE TABLE(INPLACE IGNORE)
+--echo # AND CHANGE TABLE CHARSET(CHANGE CREATE)
+
+CREATE TABLE t1(
+ f1 INT NOT NULL,
+ f2 INT NOT NULL)ENGINE=INNODB;
+
+INSERT INTO t1 VALUES(1, 2);
+
+let id_before_alter =`SELECT table_id FROM INFORMATION_SCHEMA.INNODB_SYS_TABLES WHERE name="test/t1"`;
+
+ALTER TABLE t1 RENAME t2, DEFAULT CHARSET=latin1, ALGORITHM=INPLACE;
+
+let id_after_alter =`SELECT table_id FROM INFORMATION_SCHEMA.INNODB_SYS_TABLES WHERE name="test/t2"`;
+
+if ($id_before_alter != $id_after_alter)
+{
+ --echo "Table rebuild happened";
+}
+
+DROP TABLE t2;
diff --git a/mysql-test/suite/innodb/t/innodb-index-online-purge.test b/mysql-test/suite/innodb/t/innodb-index-online-purge.test
new file mode 100644
index 00000000..28ff9403
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb-index-online-purge.test
@@ -0,0 +1,73 @@
+--source include/have_innodb.inc
+--source include/have_debug_sync.inc
+
+# Save the initial number of concurrent sessions.
+--source include/count_sessions.inc
+
+connect (con1,localhost,root,,);
+
+connect (con2,localhost,root,,);
+connection default;
+
+CREATE TABLE t (a INT PRIMARY KEY, c TEXT) ENGINE=InnoDB;
+CREATE TABLE u (a INT PRIMARY KEY, b INT, c INT NOT NULL) ENGINE=InnoDB;
+
+INSERT INTO t VALUES (1,'aa');
+BEGIN;
+INSERT INTO u SET a=1, c=1;
+INSERT INTO u SELECT a+1,NULL,a+1 FROM u;
+INSERT INTO u SELECT a+2,NULL,a+2 FROM u;
+INSERT INTO u SELECT a+4,NULL,a+4 FROM u;
+INSERT INTO u SELECT a+8,NULL,a+8 FROM u;
+INSERT INTO u SELECT a+16,NULL,a+16 FROM u;
+INSERT INTO u SELECT a+32,NULL,a+32 FROM u;
+INSERT INTO u SELECT a+64,NULL,a+64 FROM u;
+INSERT INTO u SELECT a+128,NULL,a+64 FROM u;
+INSERT INTO u SELECT a+256,NULL,a+64 FROM u;
+COMMIT;
+
+BEGIN;
+DELETE FROM u;
+
+connection con2;
+SET DEBUG_SYNC='row_log_apply_before SIGNAL created_u WAIT_FOR dml_done_u';
+--send
+ALTER TABLE u ADD INDEX (c);
+
+connection default;
+# Check that the above SELECT is blocked
+let $wait_condition=
+ SELECT COUNT(*) = 1 from information_schema.processlist
+ WHERE state = 'Waiting for table metadata lock' AND
+ info = 'ALTER TABLE u ADD INDEX (c)';
+--source include/wait_condition.inc
+
+COMMIT;
+SET DEBUG_SYNC='now WAIT_FOR created_u';
+SELECT state FROM information_schema.processlist
+WHERE info='ALTER TABLE u ADD INDEX (c)';
+
+connection con1;
+SET DEBUG_SYNC='row_log_apply_before SIGNAL created_t WAIT_FOR dml_done_t';
+--send
+CREATE INDEX c1 ON t (c(1));
+connection default;
+SET DEBUG_SYNC='now WAIT_FOR created_t';
+UPDATE t SET c='ab';
+# Allow purge to kick in. TODO: Trigger this faster, somehow.
+SELECT SLEEP(10);
+SET DEBUG_SYNC='now SIGNAL dml_done_u';
+connection con2;
+reap;
+SET DEBUG_SYNC='now SIGNAL dml_done_t';
+disconnect con2;
+connection con1;
+reap;
+disconnect con1;
+connection default;
+SET DEBUG_SYNC='RESET';
+DROP TABLE t,u;
+
+# 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/suite/innodb/t/innodb-index-online.opt b/mysql-test/suite/innodb/t/innodb-index-online.opt
new file mode 100644
index 00000000..1837463f
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb-index-online.opt
@@ -0,0 +1,5 @@
+--loose-innodb-sort-buffer-size=64k
+--loose-innodb-online-alter-log-max-size=128k
+--loose-innodb-buffer-pool-size=5M
+--loose-innodb-sys-indexes
+--loose-innodb-sys-fields
diff --git a/mysql-test/suite/innodb/t/innodb-index-online.test b/mysql-test/suite/innodb/t/innodb-index-online.test
new file mode 100644
index 00000000..f8eb8957
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb-index-online.test
@@ -0,0 +1,524 @@
+--source include/innodb_page_size_small.inc
+--source include/innodb_encrypt_log.inc
+--source include/have_debug.inc
+--source include/have_debug_sync.inc
+--source include/no_valgrind_without_big.inc
+
+let $innodb_metrics_select=
+SELECT name, count FROM INFORMATION_SCHEMA.INNODB_METRICS WHERE subsystem = 'ddl';
+
+call mtr.add_suppression("InnoDB: Warning: Small buffer pool size");
+
+# DISCARD TABLESPACE needs file-per-table
+SET @global_innodb_file_per_table_orig = @@global.innodb_file_per_table;
+SET GLOBAL innodb_file_per_table = on;
+
+# Save the initial number of concurrent sessions.
+--source include/count_sessions.inc
+
+CREATE TABLE t1 (c1 INT PRIMARY KEY, c2 INT, c3 TEXT)
+ENGINE=InnoDB STATS_PERSISTENT=0;
+INSERT INTO t1 VALUES (1,1,''), (2,2,''), (3,3,''), (4,4,''), (5,5,'');
+
+SET GLOBAL innodb_monitor_enable = module_ddl;
+eval $innodb_metrics_select;
+
+SET DEBUG_SYNC = 'RESET';
+SET DEBUG_SYNC = 'write_row_noreplace SIGNAL have_handle WAIT_FOR go_ahead';
+--send
+INSERT INTO t1 VALUES(1,2,3);
+
+connect (con1,localhost,root,,);
+
+# This should block at the end because of the INSERT in connection default
+# is holding a metadata lock.
+SET DEBUG_SYNC = 'now WAIT_FOR have_handle';
+SET lock_wait_timeout = 1;
+--error ER_LOCK_WAIT_TIMEOUT
+ALTER TABLE t1 ADD UNIQUE INDEX(c2);
+SET DEBUG_SYNC = 'now SIGNAL go_ahead';
+
+connection default;
+--error ER_DUP_ENTRY
+reap;
+eval $innodb_metrics_select;
+
+connection con1;
+SET @saved_debug_dbug = @@SESSION.debug_dbug;
+SET DEBUG_DBUG = '+d,innodb_OOM_prepare_inplace_alter';
+--error ER_OUT_OF_RESOURCES
+ALTER TABLE t1 ADD UNIQUE INDEX(c2);
+SET DEBUG_DBUG = @saved_debug_dbug;
+SET DEBUG_DBUG = '+d,innodb_OOM_inplace_alter';
+--error ER_OUT_OF_RESOURCES
+CREATE UNIQUE INDEX c2 ON t1(c2);
+SET DEBUG_DBUG = @saved_debug_dbug;
+SET DEBUG_DBUG = '+d,innodb_OOM_prepare_add_index';
+--error ER_OUT_OF_RESOURCES
+ALTER TABLE t1 ADD KEY(c2), ADD KEY c3_10(c3(10)), ADD KEY c3_c2(c3(4),c2);
+SET DEBUG_DBUG = @saved_debug_dbug;
+CREATE UNIQUE INDEX c2 ON t1(c2);
+DROP INDEX c2 ON t1;
+
+connection default;
+SHOW CREATE TABLE t1;
+# Insert a duplicate entry (4) for the upcoming UNIQUE INDEX(c2).
+BEGIN;
+INSERT INTO t1 VALUES(7,4,2);
+
+connection con1;
+# This DEBUG_SYNC should not kick in yet, because the duplicate key will be
+# detected before we get a chance to apply the online log.
+SET DEBUG_SYNC = 'row_log_apply_before SIGNAL scanned WAIT_FOR rollback_done';
+# This will be a lock wait timeout on the meta-data lock,
+# because the transaction inserting (7,4,2) is still active.
+--error ER_LOCK_WAIT_TIMEOUT
+ALTER TABLE t1 ADD UNIQUE INDEX(c2);
+connection default;
+COMMIT;
+connection con1;
+--error ER_DUP_ENTRY
+ALTER TABLE t1 ADD UNIQUE INDEX(c2);
+connection default;
+DELETE FROM t1 WHERE c1 = 7;
+connection con1;
+# ADD FOREIGN KEY is not supported in-place
+--error ER_ALTER_OPERATION_NOT_SUPPORTED_REASON
+ALTER TABLE t1 ADD FOREIGN KEY(c2) REFERENCES t1(c2), ALGORITHM = INPLACE;
+# The previous DEBUG_SYNC should be ignored, because an exclusive lock
+# has been requested and the online log is not being allocated.
+ALTER TABLE t1 ADD UNIQUE INDEX(c2), LOCK = EXCLUSIVE, ALGORITHM = INPLACE;
+DROP INDEX c2 ON t1;
+# Now the previous DEBUG_SYNC should kick in.
+--send
+ALTER TABLE t1 ADD UNIQUE INDEX(c2);
+connection default;
+SET DEBUG_SYNC = 'now WAIT_FOR scanned';
+eval $innodb_metrics_select;
+
+# Insert a duplicate entry (4) for the already started UNIQUE INDEX(c2).
+BEGIN;
+INSERT INTO t1 VALUES(7,4,2);
+COMMIT;
+DELETE FROM t1 where c1 = 7;
+SET DEBUG_SYNC = 'now SIGNAL rollback_done';
+
+connection con1;
+# Because the modification log will be applied in order, there will be
+# a duplicate key error on the (7,4,2) even though we roll it back.
+--error ER_DUP_ENTRY
+reap;
+# Now, create the index without any concurrent DML, while no duplicate exists.
+SET DEBUG_SYNC = 'row_log_apply_after SIGNAL created WAIT_FOR dml_done';
+--send
+ALTER TABLE t1 ADD UNIQUE INDEX(c2);
+connection default;
+SET DEBUG_SYNC = 'now WAIT_FOR created';
+# At this point, the index has been created inside InnoDB but not yet
+# in the MySQL data dictionary.
+eval $innodb_metrics_select;
+# A duplicate key error should now be triggered by InnoDB, but reported
+# by the ALTER TABLE because the index does not 'officially' exist yet.
+INSERT INTO t1 VALUES(6,3,1);
+SET DEBUG_SYNC = 'now SIGNAL dml_done';
+connection con1;
+# This is due to the duplicate entry (6,3,1).
+--error ER_DUP_ENTRY
+reap;
+DELETE FROM t1 WHERE c1=6;
+ALTER TABLE t1 ADD UNIQUE INDEX(c2);
+eval $innodb_metrics_select;
+
+connection default;
+--error ER_DUP_ENTRY
+INSERT INTO t1 VALUES(6,3,1);
+--error ER_DUP_ENTRY
+INSERT INTO t1 VALUES(7,4,2);
+ALTER TABLE t1 STATS_PERSISTENT=1;
+ANALYZE TABLE t1;
+# Purge may or may not have cleaned up the DELETE FROM t1 WHERE c1 = 7;
+UPDATE mysql.innodb_index_stats SET stat_value = 5
+WHERE database_name = 'test' AND table_name= 't1' AND index_name = 'PRIMARY'
+AND stat_value = 6;
+--replace_column 4 LAST_UPDATE
+SELECT * FROM mysql.innodb_index_stats WHERE table_name IN ('t1');
+CREATE TABLE t1_c2_stats SELECT * FROM mysql.innodb_index_stats
+WHERE database_name = 'test' AND table_name = 't1' and index_name = 'c2';
+# in Embedded mode (./mtr --embedded-server) the t1_c2_stats table gets
+# created in MyISAM format by default even if we set
+# default_storage_engine='innodb'
+ALTER TABLE t1_c2_stats ENGINE=INNODB;
+DROP INDEX c2 ON t1;
+ANALYZE TABLE t1_c2_stats;
+--replace_column 4 LAST_UPDATE
+SELECT * FROM mysql.innodb_index_stats WHERE table_name IN ('t1', 't1_c2_stats');
+
+connection con1;
+let $ID= `SELECT @id := CONNECTION_ID()`;
+--error ER_QUERY_INTERRUPTED
+KILL QUERY @id;
+
+SET DEBUG_SYNC = 'row_log_apply_before SIGNAL c2d_created WAIT_FOR kill_done';
+--send
+CREATE INDEX c2d ON t1(c2);
+
+connection default;
+SET DEBUG_SYNC = 'now WAIT_FOR c2d_created';
+eval $innodb_metrics_select;
+let $ignore= `SELECT @id := $ID`;
+KILL QUERY @id;
+SET DEBUG_SYNC = 'now SIGNAL kill_done';
+
+connection con1;
+--error ER_QUERY_INTERRUPTED
+reap;
+eval $innodb_metrics_select;
+
+connection default;
+CHECK TABLE t1;
+INSERT INTO t1 SELECT 5 + c1, c2, c3 FROM t1;
+INSERT INTO t1 SELECT 10 + c1, c2, c3 FROM t1;
+INSERT INTO t1 SELECT 20 + c1, c2, c3 FROM t1;
+INSERT INTO t1 SELECT 40 + c1, c2, c3 FROM t1;
+# Purge may or may not have cleaned up the DELETE FROM t1 WHERE c1 = 7;
+--replace_result 81 80
+EXPLAIN SELECT COUNT(*) FROM t1 WHERE c2 > 3;
+ANALYZE TABLE t1;
+
+connection con1;
+# Forge some statistics for c2d, and see that they will be used
+UPDATE t1_c2_stats SET index_name = 'c2d';
+# Fake the statistics. The cardinality should be 5,80.
+UPDATE t1_c2_stats SET stat_value = 2 WHERE stat_name = 'n_diff_pfx01';
+INSERT INTO t1_c2_stats
+SELECT database_name, table_name, index_name, last_update, 'n_diff_pfx02', 80,
+sample_size, 'c2,c1' FROM t1_c2_stats
+WHERE stat_name = 'n_diff_pfx01' AND stat_description = 'c2';
+INSERT INTO mysql.innodb_index_stats SELECT * FROM t1_c2_stats;
+DROP TABLE t1_c2_stats;
+
+CREATE INDEX c2d ON t1(c2);
+# This should show the newly calculated stats by CREATE INDEX above,
+# not the faked cardinality=4 for c2d(c2).
+# Purge may or may not have cleaned up the DELETE FROM t1 WHERE c1 = 7;
+--replace_result 81 80
+SHOW INDEX FROM t1;
+EXPLAIN SELECT COUNT(*) FROM t1 WHERE c2 > 3;
+
+SHOW CREATE TABLE t1;
+
+connection default;
+SET @merge_encrypt_0=
+(SELECT variable_value FROM information_schema.global_status
+WHERE variable_name = 'innodb_encryption_n_merge_blocks_encrypted');
+SET @merge_decrypt_0=
+(SELECT variable_value FROM information_schema.global_status
+WHERE variable_name = 'innodb_encryption_n_merge_blocks_decrypted');
+SET @rowlog_encrypt_0=
+(SELECT variable_value FROM information_schema.global_status
+WHERE variable_name = 'innodb_encryption_n_rowlog_blocks_encrypted');
+connection con1;
+
+# Exceed the configured innodb_online_alter_log_max_size.
+# The actual limit is a multiple of innodb_sort_buf_size,
+# because that is the size of the in-memory log buffers.
+SET DEBUG_SYNC = 'row_log_apply_before SIGNAL c2e_created WAIT_FOR dml2_done';
+# Ensure that the ALTER TABLE will be executed even with some concurrent DML.
+SET lock_wait_timeout = 10;
+--send
+ALTER TABLE t1 CHANGE c2 c22 INT, DROP INDEX c2d, ADD INDEX c2e(c22, c3(10)), ALGORITHM = NOCOPY;
+
+# Generate some log (delete-mark, delete-unmark, insert etc.)
+# while the index creation is blocked. Some of this may run
+# in parallel with the clustered index scan.
+connection default;
+INSERT INTO t1 SELECT 80 + c1, c2, c3 FROM t1;
+INSERT INTO t1 SELECT 160 + c1, c2, c3 FROM t1;
+#UPDATE t1 SET c2 = c2 + 1;
+SET DEBUG_SYNC = 'now WAIT_FOR c2e_created';
+# At this point, the clustered index scan must have completed,
+# but the modification log keeps accumulating due to the DEBUG_SYNC.
+eval $innodb_metrics_select;
+let $c= 8;
+while ($c)
+{
+ UPDATE t1 SET c2 = c2 + 1;
+ UPDATE t1 SET c2 = c2 + 2;
+ dec $c;
+}
+# Incomplete index c2e should exist until the DDL thread notices the overflow.
+# (The output below strips TEMP_INDEX_PREFIX from the name.)
+eval $innodb_metrics_select;
+SELECT sf.name, sf.pos FROM INFORMATION_SCHEMA.INNODB_SYS_INDEXES si
+INNER JOIN INFORMATION_SCHEMA.INNODB_SYS_FIELDS sf
+ON si.index_id = sf.index_id WHERE si.name = '?c2e';
+
+SET @merge_encrypt_1=
+(SELECT variable_value FROM information_schema.global_status
+WHERE variable_name = 'innodb_encryption_n_merge_blocks_encrypted');
+SET @merge_decrypt_1=
+(SELECT variable_value FROM information_schema.global_status
+WHERE variable_name = 'innodb_encryption_n_merge_blocks_decrypted');
+SET @rowlog_encrypt_1=
+(SELECT variable_value FROM information_schema.global_status
+WHERE variable_name = 'innodb_encryption_n_rowlog_blocks_encrypted');
+
+SELECT
+(@merge_encrypt_1-@merge_encrypt_0)-
+(@merge_decrypt_1-@merge_decrypt_0) as sort_balance,
+@merge_encrypt_1>@merge_encrypt_0, @merge_decrypt_1>@merge_decrypt_0,
+@rowlog_encrypt_1>@rowlog_encrypt_0;
+
+# Release con1.
+SET DEBUG_SYNC = 'now SIGNAL dml2_done';
+
+connection con1;
+# If the following fails with the wrong error, it probably means that
+# you should rerun with a larger mtr --debug-sync-timeout.
+--error ER_INNODB_ONLINE_LOG_TOO_BIG
+reap;
+# The index c2e should have been dropped from the data dictionary
+# when the above error was noticed. It should still exist in the
+# cache with index->online_status = ONLINE_INDEX_ABORTED_DROPPED.
+eval $innodb_metrics_select;
+SELECT sf.name, sf.pos FROM INFORMATION_SCHEMA.INNODB_SYS_INDEXES si
+INNER JOIN INFORMATION_SCHEMA.INNODB_SYS_FIELDS sf
+ON si.index_id = sf.index_id WHERE si.name = 'c2e';
+
+# ddl_background_drop_indexes = 1 here, because the incomplete index c2e still
+# exists in the InnoDB data dictionary cache.
+eval $innodb_metrics_select;
+
+connection default;
+
+ALTER TABLE t1 COMMENT 'testing if c2e will be dropped';
+
+# Check that the 'zombie' index c2e was dropped.
+eval $innodb_metrics_select;
+
+SET @merge_encrypt_1=
+(SELECT variable_value FROM information_schema.global_status
+WHERE variable_name = 'innodb_encryption_n_merge_blocks_encrypted');
+SET @merge_decrypt_1=
+(SELECT variable_value FROM information_schema.global_status
+WHERE variable_name = 'innodb_encryption_n_merge_blocks_decrypted');
+SET @rowlog_encrypt_1=
+(SELECT variable_value FROM information_schema.global_status
+WHERE variable_name = 'innodb_encryption_n_rowlog_blocks_encrypted');
+SET @rowlog_decrypt_1=
+(SELECT variable_value FROM information_schema.global_status
+WHERE variable_name = 'innodb_encryption_n_rowlog_blocks_decrypted');
+
+connection con1;
+# Accumulate and apply some modification log.
+SET DEBUG_SYNC = 'row_log_apply_before SIGNAL c2f_created WAIT_FOR dml3_done';
+--send
+ALTER TABLE t1 ADD INDEX c2f(c22f), CHANGE c2 c22f INT;
+
+connection default;
+SET DEBUG_SYNC = 'now WAIT_FOR c2f_created';
+# Generate some log (delete-mark, delete-unmark, insert etc.)
+eval $innodb_metrics_select;
+let $c= 6;
+while ($c)
+{
+BEGIN;
+INSERT INTO t1 SELECT 320 + c1, c2, c3 FROM t1 WHERE c1 > 160;
+DELETE FROM t1 WHERE c1 > 320;
+COMMIT;
+BEGIN;
+UPDATE t1 SET c2 = c2 + 1;
+COMMIT;
+dec $c;
+}
+eval $innodb_metrics_select;
+# Release con1.
+SET DEBUG_SYNC = 'now SIGNAL dml3_done';
+
+connection con1;
+reap;
+
+eval $innodb_metrics_select;
+
+connection default;
+
+SET @merge_encrypt_2=
+(SELECT variable_value FROM information_schema.global_status
+WHERE variable_name = 'innodb_encryption_n_merge_blocks_encrypted');
+SET @merge_decrypt_2=
+(SELECT variable_value FROM information_schema.global_status
+WHERE variable_name = 'innodb_encryption_n_merge_blocks_decrypted');
+SET @rowlog_encrypt_2=
+(SELECT variable_value FROM information_schema.global_status
+WHERE variable_name = 'innodb_encryption_n_rowlog_blocks_encrypted');
+SET @rowlog_decrypt_2=
+(SELECT variable_value FROM information_schema.global_status
+WHERE variable_name = 'innodb_encryption_n_rowlog_blocks_decrypted');
+
+SELECT
+(@merge_encrypt_2-@merge_encrypt_1)-
+(@merge_decrypt_2-@merge_decrypt_1) as sort_balance,
+(@rowlog_encrypt_2-@rowlog_encrypt_1)-
+(@rowlog_decrypt_2-@rowlog_decrypt_1) as log_balance;
+SELECT
+@merge_encrypt_2-@merge_encrypt_1>0 as sort_encrypted,
+@merge_decrypt_2-@merge_decrypt_1>0 as sort_decrypted,
+@rowlog_encrypt_2-@rowlog_encrypt_1>0 as log_encrypted,
+@rowlog_decrypt_2-@rowlog_decrypt_1>0 as log_decrypted;
+
+connection con1;
+SELECT COUNT(c22f) FROM t1;
+CHECK TABLE t1;
+# Avoid a strange DEBUG_SYNC timeout on c3p5_created.
+SET GLOBAL innodb_max_purge_lag_wait=0;
+
+# Create a column prefix index.
+--error ER_DUP_ENTRY
+ALTER TABLE t1 ADD UNIQUE INDEX c3p5(c3(5));
+UPDATE t1 SET c3 = NULL WHERE c3 = '';
+SET lock_wait_timeout = 1;
+SET DEBUG_SYNC = 'row_log_apply_before SIGNAL c3p5_created WAIT_FOR ins_done';
+--send
+ALTER TABLE t1 ADD UNIQUE INDEX c3p5(c3(5));
+
+connection default;
+SET DEBUG_SYNC = 'now WAIT_FOR c3p5_created';
+
+# Check that the index was created.
+SELECT sf.name, sf.pos FROM INFORMATION_SCHEMA.INNODB_SYS_INDEXES si
+INNER JOIN INFORMATION_SCHEMA.INNODB_SYS_FIELDS sf
+ON si.index_id = sf.index_id WHERE si.name = '?c3p5';
+
+SET DEBUG_SYNC = 'ib_after_row_insert SIGNAL ins_done WAIT_FOR ddl_timed_out';
+--send
+INSERT INTO t1 VALUES(347,33101,NULL);
+
+connection con1;
+--error ER_LOCK_WAIT_TIMEOUT
+reap;
+SET DEBUG_SYNC = 'now SIGNAL ddl_timed_out';
+
+# InnoDB should have cleaned up the index c3p5 from the data dictionary,
+# but not yet from the dictionary cache.
+SELECT sf.name, sf.pos FROM INFORMATION_SCHEMA.INNODB_SYS_INDEXES si
+INNER JOIN INFORMATION_SCHEMA.INNODB_SYS_FIELDS sf
+ON si.index_id = sf.index_id WHERE si.name = 'c3p5';
+eval $innodb_metrics_select;
+
+connection default;
+reap;
+# Index c3p5 should still exist in the data dictionary cache.
+eval $innodb_metrics_select;
+
+--disable_parsing
+# Temporarily disabled by fix for bug#14213236. Should be either
+# removed or updated to take into account that locking for IMPORT/
+# DISCARD TABLESPACE happens on MDL layer. New test case is added
+# to validate this at MDL layer(i_main.alter_table.test)
+
+SET DEBUG_SYNC = 'row_log_apply_before SIGNAL c2g_created WAIT_FOR dml4_done';
+# The lock upgrade at the end of the ALTER will conflict with the DISCARD.
+SET lock_wait_timeout = 1;
+--send
+ALTER TABLE t1 DROP INDEX c2f, ADD INDEX c2g(c22f);
+
+connection con1;
+SET DEBUG_SYNC = 'now WAIT_FOR c2g_created';
+
+connect (con2,localhost,root,,);
+
+# This will conflict with the ALTER in connection default, above.
+SET lock_wait_timeout = 10;
+--send
+ALTER TABLE t1 DISCARD TABLESPACE;
+
+connection con1;
+let $wait_condition=
+ SELECT COUNT(*) = 1 FROM information_schema.processlist
+ WHERE state = 'Waiting for table level lock' and
+ info = 'ALTER TABLE t1 DISCARD TABLESPACE';
+--source include/wait_condition.inc
+
+SET DEBUG_SYNC = 'now SIGNAL dml4_done';
+disconnect con1;
+connection con2;
+reap;
+disconnect con2;
+connection default;
+--error ER_LOCK_WAIT_TIMEOUT
+reap;
+--enable_parsing
+#remove below con1 disconnect if above test case is enabled
+connection default;
+
+SHOW CREATE TABLE t1;
+ALTER TABLE t1 DROP INDEX c2d, DROP INDEX c2f;
+# The ALTER TABLE should have cleaned up c3p5 from the cache.
+eval $innodb_metrics_select;
+ALTER TABLE t1 ADD INDEX c2h(c22f), ALGORITHM = INPLACE;
+--error ER_DUP_KEYNAME
+ALTER TABLE t1 ADD INDEX c2h(c22f), ALGORITHM = COPY;
+
+SET DEBUG_SYNC = 'RESET';
+SET GLOBAL innodb_monitor_disable = module_ddl;
+
+DROP TABLE t1;
+
+--echo #
+--echo # MDEV-13205 assertion !dict_index_is_online_ddl(index) upon ALTER TABLE
+--echo #
+CREATE TABLE t1 (c VARCHAR(64)) ENGINE=InnoDB;
+INSERT INTO t1 VALUES('foo');
+SET DEBUG_SYNC = 'row_log_apply_before SIGNAL t1u_created WAIT_FOR dup_done';
+send ALTER TABLE t1 ADD UNIQUE(c);
+
+connection con1;
+SET DEBUG_SYNC = 'now WAIT_FOR t1u_created';
+INSERT INTO t1 VALUES('bar'),('bar');
+SET DEBUG_SYNC = 'now SIGNAL dup_done';
+
+connection default;
+--error ER_DUP_ENTRY
+reap;
+
+SET DEBUG_SYNC = 'RESET';
+disconnect con1;
+
+CREATE TABLE t2 (c VARCHAR(64)) ENGINE=InnoDB;
+--error ER_CANT_CREATE_TABLE
+ALTER TABLE t2 ADD FOREIGN KEY (c) REFERENCES t1 (c);
+DROP TABLE t2,t1;
+
+CREATE TABLE t1 (a INT PRIMARY KEY, b INT) ENGINE=InnoDB;
+INSERT INTO t1 VALUES(0,0);
+
+connect (con1,localhost,root,,);
+SET DEBUG_SYNC = 'row_log_apply_before SIGNAL created WAIT_FOR inserted';
+send ALTER TABLE t1 ADD INDEX(b);
+
+connection default;
+SET DEBUG_SYNC = 'now WAIT_FOR created';
+BEGIN;
+INSERT INTO t1 VALUES(1,1);
+ROLLBACK;
+SET DEBUG_SYNC = 'now SIGNAL inserted';
+
+connection con1;
+reap;
+disconnect con1;
+
+connection default;
+SELECT * FROM t1;
+CHECK TABLE t1;
+DROP TABLE t1;
+SET DEBUG_SYNC = 'RESET';
+
+# 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_file_per_table = @global_innodb_file_per_table_orig;
+--disable_warnings
+SET GLOBAL innodb_monitor_enable = default;
+SET GLOBAL innodb_monitor_disable = default;
+--enable_warnings
diff --git a/mysql-test/suite/innodb/t/innodb-index.opt b/mysql-test/suite/innodb/t/innodb-index.opt
new file mode 100644
index 00000000..1a01b401
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb-index.opt
@@ -0,0 +1 @@
+--skip-innodb-stats-persistent
diff --git a/mysql-test/suite/innodb/t/innodb-index.test b/mysql-test/suite/innodb/t/innodb-index.test
new file mode 100644
index 00000000..c80e3e6c
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb-index.test
@@ -0,0 +1,1234 @@
+-- source include/have_innodb.inc
+# Embedded server tests do not support restarting.
+-- source include/not_embedded.inc
+
+let $MYSQLD_DATADIR= `select @@datadir`;
+
+SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS;
+
+# Bug#13654923 BOGUS DEBUG ASSERTION IN INDEX CREATION FOR ZERO-LENGTH RECORD
+create table t1(a varchar(2) primary key) engine=innodb;
+insert into t1 values('');
+--enable_info
+create index t1a1 on t1(a(1));
+--disable_info
+drop table t1;
+
+create table t1(a int not null, b int, c char(10) not null, d varchar(20)) engine = innodb;
+insert into t1 values (5,5,'oo','oo'),(4,4,'tr','tr'),(3,4,'ad','ad'),(2,3,'ak','ak');
+commit;
+--error ER_DUP_KEYNAME
+alter table t1 add index b (b), add index b (b);
+--error ER_DUP_FIELDNAME
+alter table t1 add index (b,b);
+--enable_info
+alter table t1 add index d2 (d);
+--disable_info
+show create table t1;
+-- disable_result_log
+analyze table t1;
+-- enable_result_log
+explain select * from t1 force index(d2) order by d;
+select * from t1 force index (d2) order by d;
+--error ER_DUP_ENTRY
+alter table t1 add unique index (b);
+show create table t1;
+--enable_info
+alter table t1 add index (b);
+--disable_info
+show create table t1;
+
+--enable_info
+alter table t1 add unique index (c), add index (d);
+--disable_info
+show create table t1;
+analyze table t1;
+explain select * from t1 force index(c) order by c;
+--enable_info
+alter table t1 add primary key (a), drop index c;
+show create table t1;
+--error ER_MULTIPLE_PRI_KEY
+alter table t1 add primary key (c);
+--error ER_DUP_ENTRY
+alter table t1 drop primary key, add primary key (b);
+create unique index c on t1 (c);
+--disable_info
+show create table t1;
+analyze table t1;
+explain select * from t1 force index(c) order by c;
+select * from t1 force index(c) order by c;
+--enable_info
+alter table t1 drop index b, add index (b);
+--disable_info
+show create table t1;
+insert into t1 values(6,1,'ggg','ggg');
+select * from t1;
+select * from t1 force index(b) order by b;
+select * from t1 force index(c) order by c;
+select * from t1 force index(d) order by d;
+-- disable_result_log
+analyze table t1;
+-- enable_result_log
+explain select * from t1 force index(b) order by b;
+explain select * from t1 force index(c) order by c;
+explain select * from t1 force index(d) order by d;
+show create table t1;
+drop table t1;
+
+create table t1(a int not null, b int, c char(10), d varchar(20), primary key (a)) engine = innodb;
+insert into t1 values (1,1,'ab','ab'),(2,2,'ac','ac'),(3,3,'ad','ad'),(4,4,'afe','afe');
+commit;
+--enable_info
+alter table t1 add index (c(2));
+show create table t1;
+alter table t1 add unique index (d(10));
+show create table t1;
+--disable_info
+insert into t1 values(5,1,'ggg','ggg');
+-- disable_result_log
+analyze table t1;
+-- enable_result_log
+select * from t1;
+select * from t1 force index(c) order by c;
+select * from t1 force index(d) order by d;
+explain select * from t1 order by b;
+explain select * from t1 force index(c) order by c;
+explain select * from t1 force index(d) order by d;
+show create table t1;
+--enable_info
+alter table t1 drop index d;
+--disable_info
+insert into t1 values(8,9,'fff','fff');
+select * from t1;
+select * from t1 force index(c) order by c;
+-- disable_result_log
+analyze table t1;
+-- enable_result_log
+explain select * from t1 order by b;
+explain select * from t1 force index(c) order by c;
+explain select * from t1 order by d;
+show create table t1;
+drop table t1;
+
+create table t1(a int not null, b int, c char(10), d varchar(20), primary key (a)) engine = innodb;
+insert into t1 values (1,1,'ab','ab'),(2,2,'ac','ac'),(3,2,'ad','ad'),(4,4,'afe','afe');
+commit;
+--enable_info
+alter table t1 add unique index (b,c);
+--disable_info
+insert into t1 values(8,9,'fff','fff');
+select * from t1;
+select * from t1 force index(b) order by b;
+-- disable_result_log
+analyze table t1;
+-- enable_result_log
+explain select * from t1 force index(b) order by b;
+show create table t1;
+--enable_info
+alter table t1 add index (b,c);
+--disable_info
+insert into t1 values(11,11,'kkk','kkk');
+select * from t1;
+select * from t1 force index(b) order by b;
+-- disable_result_log
+analyze table t1;
+-- enable_result_log
+explain select * from t1 force index(b) order by b;
+show create table t1;
+--enable_info
+alter table t1 add unique index (c,d);
+--disable_info
+insert into t1 values(13,13,'yyy','aaa');
+select * from t1;
+select * from t1 force index(b) order by b;
+select * from t1 force index(c) order by c;
+-- disable_result_log
+analyze table t1;
+-- enable_result_log
+explain select * from t1 force index(b) order by b;
+explain select * from t1 force index(c) order by c;
+show create table t1;
+drop table t1;
+
+create table t1(a int not null, b int not null, c int, primary key (a), key (b)) engine = innodb;
+create table t3(a int not null, c int not null, d int, primary key (a), key (c)) engine = innodb;
+create table t4(a int not null, d int not null, e int, primary key (a), key (d)) engine = innodb;
+create table t2(a int not null, b int, c int, d int, e int,
+foreign key (b) references t1(b) on delete set null,
+foreign key (c) references t3(c), foreign key (d) references t4(d) on update set null)
+engine = innodb;
+--error ER_DROP_INDEX_FK
+alter table t1 drop index b;
+--error ER_DROP_INDEX_FK
+alter table t3 drop index c;
+--error ER_DROP_INDEX_FK
+alter table t4 drop index d;
+--error ER_DROP_INDEX_FK
+alter table t2 drop index b;
+--error ER_DROP_INDEX_FK
+alter table t2 drop index b, drop index c, drop index d;
+--error ER_FK_COLUMN_CANNOT_CHANGE
+alter table t2 MODIFY b INT NOT NULL, ALGORITHM=COPY;
+# NULL -> NOT NULL only allowed INPLACE if strict sql_mode is on.
+set @old_sql_mode = @@sql_mode;
+set @@sql_mode = 'STRICT_TRANS_TABLES';
+--error ER_FK_COLUMN_NOT_NULL
+alter table t2 MODIFY b INT NOT NULL, ALGORITHM=INPLACE;
+set @@sql_mode = @old_sql_mode;
+
+SET FOREIGN_KEY_CHECKS=0;
+--error ER_FK_COLUMN_CANNOT_DROP
+alter table t2 DROP COLUMN b, ALGORITHM=COPY;
+--error ER_FK_COLUMN_CANNOT_DROP
+alter table t2 DROP COLUMN b;
+--error ER_FK_COLUMN_CANNOT_DROP_CHILD
+alter table t1 DROP COLUMN b, ALGORITHM=COPY;
+--error ER_FK_COLUMN_CANNOT_DROP_CHILD
+alter table t1 DROP COLUMN b;
+SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS;
+
+--enable_info
+# Apparently, the following makes mysql_alter_table() drop index d.
+create unique index dc on t2 (d,c);
+create index dc on t1 (b,c);
+# This should preserve the foreign key constraints.
+--disable_info
+# NULL -> NOT NULL only allowed INPLACE if strict sql_mode is on.
+# And adding a PRIMARY KEY will also add NOT NULL implicitly!
+set @@sql_mode = 'STRICT_TRANS_TABLES';
+--enable_info
+--error ER_FK_COLUMN_NOT_NULL
+alter table t2 add primary key (alpha), change a alpha int,
+change b beta int not null, change c charlie int not null;
+--error ER_FK_COLUMN_NOT_NULL
+alter table t2 add primary key (alpha), change a alpha int,
+change c charlie int not null, change d delta int not null;
+alter table t2 add primary key (alpha), change a alpha int,
+change b beta int, modify c int not null;
+--disable_info
+set @@sql_mode = @old_sql_mode;
+insert into t1 values (1,1,1);
+insert into t3 values (1,1,1);
+insert into t4 values (1,1,1);
+insert into t2 values (1,1,1,1,1);
+commit;
+--enable_info
+alter table t4 add constraint dc foreign key (a) references t1(a);
+--disable_info
+show create table t4;
+# mysqltest first does replace_regex, then replace_result
+# Embedded server doesn't chdir to data directory
+--replace_result $MYSQLD_DATADIR ./ master-data/ ''
+# a foreign key 'test/dc' already exists
+--error ER_CANT_CREATE_TABLE
+alter table t3 add constraint dc foreign key (a) references t1(a);
+SET FOREIGN_KEY_CHECKS=0;
+--error ER_FK_FAIL_ADD_SYSTEM
+alter table t3 add constraint dc foreign key (a) references t1(a);
+SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS;
+show create table t3;
+--enable_info
+alter table t2 drop index b, add index (beta);
+--disable_info
+show create table t2;
+--error ER_ROW_IS_REFERENCED_2
+delete from t1;
+--error ER_CANT_DROP_FIELD_OR_KEY
+drop index dc on t4;
+--enable_info
+--error ER_CANT_DROP_FIELD_OR_KEY
+alter table t3 drop foreign key dc;
+alter table t4 drop foreign key dc;
+--disable_info
+select * from t2;
+delete from t1;
+select * from t2;
+
+drop table t2,t4,t3,t1;
+
+-- let charset = utf8
+-- source include/innodb-index.inc
+
+create table t1(a int not null, b int) engine = innodb;
+insert into t1 values (1,1),(1,1),(1,1),(1,1);
+--error ER_DUP_ENTRY
+alter table t1 add unique index (a);
+--error ER_DUP_ENTRY
+alter table t1 add unique index (b);
+--error ER_DUP_ENTRY
+alter table t1 add unique index (a), add unique index(b);
+show create table t1;
+drop table t1;
+
+create table t1(a int not null, c int not null,b int, primary key(a), unique key(c), key(b)) engine = innodb;
+alter table t1 drop index c, drop index b;
+show create table t1;
+drop table t1;
+
+create table t1(a int not null, b int, primary key(a)) engine = innodb;
+alter table t1 add index (b);
+show create table t1;
+drop table t1;
+
+create table t1(a int not null, b int, c char(10), d varchar(20), primary key (a)) engine = innodb;
+insert into t1 values (1,1,'ab','ab'),(2,2,'ac','ac'),(3,3,'ac','ac'),(4,4,'afe','afe'),(5,4,'affe','affe');
+--error ER_DUP_ENTRY
+alter table t1 add unique index (b), add unique index (c), add unique index (d);
+--error ER_DUP_ENTRY
+alter table t1 add unique index (c), add unique index (b), add index (d);
+show create table t1;
+drop table t1;
+
+create table t1(a int not null, b int not null, c int, primary key (a), key(c)) engine=innodb;
+insert into t1 values (5,1,5),(4,2,4),(3,3,3),(2,4,2),(1,5,1);
+--enable_info
+alter table t1 add unique index (b);
+--disable_info
+insert into t1 values (10,20,20),(11,19,19),(12,18,18),(13,17,17);
+show create table t1;
+check table t1;
+-- disable_result_log
+analyze table t1;
+-- enable_result_log
+explain select * from t1 force index(c) order by c;
+explain select * from t1 order by a;
+explain select * from t1 force index(b) order by b;
+select * from t1 order by a;
+select * from t1 force index(b) order by b;
+select * from t1 force index(c) order by c;
+drop table t1;
+
+create table t1(a int not null, b int not null) engine=innodb;
+insert into t1 values (1,1);
+--enable_info
+alter table t1 add primary key(b);
+--disable_info
+insert into t1 values (2,2);
+show create table t1;
+check table t1;
+select * from t1;
+analyze table t1;
+explain select * from t1;
+explain select * from t1 order by a;
+explain select * from t1 order by b;
+checksum table t1;
+drop table t1;
+
+create table t1(a int not null) engine=innodb;
+insert into t1 values (1);
+--enable_info
+alter table t1 add primary key(a);
+--disable_info
+insert into t1 values (2);
+show create table t1;
+check table t1;
+commit;
+select * from t1;
+analyze table t1;
+explain select * from t1;
+explain select * from t1 order by a;
+drop table t1;
+
+#
+# Test to check whether CREATE INDEX handles implicit foreign key
+# constraint modifications (Issue #70, Bug #38786)
+#
+SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0;
+SET FOREIGN_KEY_CHECKS=0;
+
+CREATE TABLE t1(
+ c1 BIGINT(12) NOT NULL,
+ PRIMARY KEY (c1)
+) ENGINE=InnoDB DEFAULT CHARSET=latin1;
+
+CREATE TABLE t2(
+ c1 BIGINT(16) NOT NULL,
+ c2 BIGINT(12) NOT NULL,
+ c3 BIGINT(12) NOT NULL,
+ PRIMARY KEY (c1)
+) ENGINE=InnoDB DEFAULT CHARSET=latin1;
+
+ALTER TABLE t2 ADD CONSTRAINT fk_t2_ca
+ FOREIGN KEY (c3) REFERENCES t1(c1);
+
+SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS;
+SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS;
+
+SHOW CREATE TABLE t2;
+
+CREATE INDEX i_t2_c3_c2 ON t2(c3, c2);
+
+SHOW CREATE TABLE t2;
+
+SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS;
+SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS;
+
+--error ER_NO_REFERENCED_ROW_2
+INSERT INTO t2 VALUES(0,0,0);
+INSERT INTO t1 VALUES(0);
+INSERT INTO t2 VALUES(0,0,0);
+
+DROP TABLE t2;
+
+CREATE TABLE t2(
+ c1 BIGINT(16) NOT NULL,
+ c2 BIGINT(12) NOT NULL,
+ c3 BIGINT(12) NOT NULL,
+ PRIMARY KEY (c1,c2,c3)
+) ENGINE=InnoDB DEFAULT CHARSET=latin1;
+
+SET FOREIGN_KEY_CHECKS=0;
+ALTER TABLE t2 ADD CONSTRAINT fk_t2_ca
+ FOREIGN KEY (c3) REFERENCES t1(c1);
+SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS;
+
+SHOW CREATE TABLE t2;
+
+CREATE INDEX i_t2_c3_c2 ON t2(c3, c2);
+
+SHOW CREATE TABLE t2;
+--error ER_NO_REFERENCED_ROW_2
+INSERT INTO t2 VALUES(0,0,1);
+INSERT INTO t2 VALUES(0,0,0);
+--error ER_ROW_IS_REFERENCED_2
+DELETE FROM t1;
+DELETE FROM t2;
+
+DROP TABLE t2;
+DROP TABLE t1;
+
+CREATE TABLE t1(
+ c1 BIGINT(12) NOT NULL,
+ c2 INT(4) NOT NULL,
+ PRIMARY KEY (c2,c1)
+) ENGINE=InnoDB DEFAULT CHARSET=latin1;
+
+CREATE TABLE t2(
+ c1 BIGINT(16) NOT NULL,
+ c2 BIGINT(12) NOT NULL,
+ c3 BIGINT(12) NOT NULL,
+ PRIMARY KEY (c1)
+) ENGINE=InnoDB DEFAULT CHARSET=latin1;
+
+SET FOREIGN_KEY_CHECKS=0;
+--enable_info
+
+# mysqltest first does replace_regex, then replace_result
+# Embedded server doesn't chdir to data directory
+--replace_result $MYSQLD_DATADIR ./ master-data/ ''
+--error ER_CANT_CREATE_TABLE
+ALTER TABLE t2 ADD CONSTRAINT fk_t2_ca
+ FOREIGN KEY (c3,c2) REFERENCES t1(c1,c1), ALGORITHM=COPY;
+--error ER_FK_NO_INDEX_PARENT
+ALTER TABLE t2 ADD CONSTRAINT fk_t2_ca
+ FOREIGN KEY (c3,c2) REFERENCES t1(c1,c1);
+# mysqltest first does replace_regex, then replace_result
+# Embedded server doesn't chdir to data directory
+--replace_result $MYSQLD_DATADIR ./ master-data/ ''
+--error ER_CANT_CREATE_TABLE
+ALTER TABLE t2 ADD CONSTRAINT fk_t2_ca
+ FOREIGN KEY (c3,c2) REFERENCES t1(c1,c2), ALGORITHM=COPY;
+--error ER_FK_NO_INDEX_PARENT
+ALTER TABLE t2 ADD CONSTRAINT fk_t2_ca
+ FOREIGN KEY (c3,c2) REFERENCES t1(c1,c2);
+
+--error ER_FK_INCORRECT_OPTION
+ALTER TABLE t2 ADD CONSTRAINT fk_t2_ca
+ FOREIGN KEY (c3,c2) REFERENCES t1(c2,c1), ALGORITHM=INPLACE;
+
+# mysqltest first does replace_regex, then replace_result
+# Embedded server doesn't chdir to data directory
+--replace_result $MYSQLD_DATADIR ./ master-data/ ''
+--error ER_CANT_CREATE_TABLE
+ALTER TABLE t2 ADD CONSTRAINT fk_t2_ca
+ FOREIGN KEY (c3,c2) REFERENCES t1(c2,c1), ALGORITHM=COPY;
+
+ALTER TABLE t1 MODIFY COLUMN c2 BIGINT(12) NOT NULL;
+# mysqltest first does replace_regex, then replace_result
+# Embedded server doesn't chdir to data directory
+--replace_result $MYSQLD_DATADIR ./ master-data/ ''
+--error ER_CANT_CREATE_TABLE
+ALTER TABLE t2 ADD CONSTRAINT fk_t2_ca
+ FOREIGN KEY (c3,c2) REFERENCES t1(c1,c2), ALGORITHM=COPY;
+--error ER_FK_NO_INDEX_PARENT
+ALTER TABLE t2 ADD CONSTRAINT fk_t2_ca
+ FOREIGN KEY (c3,c2) REFERENCES t1(c1,c2);
+
+ALTER TABLE t2 ADD CONSTRAINT fk_t2_ca
+ FOREIGN KEY (c3,c2) REFERENCES t1(c2,c1);
+
+SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS;
+
+SHOW CREATE TABLE t1;
+SHOW CREATE TABLE t2;
+CREATE INDEX i_t2_c2_c1 ON t2(c2, c1);
+SHOW CREATE TABLE t2;
+CREATE INDEX i_t2_c3_c1_c2 ON t2(c3, c1, c2);
+SHOW CREATE TABLE t2;
+CREATE INDEX i_t2_c3_c2 ON t2(c3, c2);
+SHOW CREATE TABLE t2;
+--disable_info
+
+DROP TABLE t2;
+DROP TABLE t1;
+
+connect (a,localhost,root,,);
+connect (b,localhost,root,,);
+connection a;
+CREATE TABLE t1 (a INT, b CHAR(1)) ENGINE=InnoDB;
+INSERT INTO t1 VALUES (3,'a'),(3,'b'),(1,'c'),(0,'d'),(1,'e');
+CREATE TABLE t2 (a INT, b CHAR(1)) ENGINE=InnoDB;
+CREATE TABLE t2i (a INT, b CHAR(1) NOT NULL) ENGINE=InnoDB;
+CREATE TABLE t2c (a INT, b CHAR(1) NOT NULL) ENGINE=InnoDB;
+INSERT INTO t2 SELECT * FROM t1;
+INSERT INTO t2i SELECT * FROM t1;
+INSERT INTO t2c SELECT * FROM t1;
+connection b;
+BEGIN;
+# This acquires a MDL lock on t1 until commit.
+SELECT * FROM t1;
+connection a;
+# This times out before of the MDL lock held by connection b.
+SET lock_wait_timeout=1;
+--error ER_LOCK_WAIT_TIMEOUT
+CREATE INDEX t1a ON t1(a);
+--enable_info
+CREATE INDEX t2a ON t2(a);
+--disable_info
+set @old_sql_mode = @@sql_mode;
+# NULL -> NOT NULL only allowed INPLACE if strict sql_mode is on.
+# And adding a PRIMARY KEY will also add NOT NULL implicitly!
+set @@sql_mode = 'STRICT_TRANS_TABLES';
+--enable_info
+ALTER TABLE t2i ADD PRIMARY KEY(a,b), ADD INDEX t2a(a), ALGORITHM=INPLACE;
+--disable_info
+set @@sql_mode = @old_sql_mode;
+--enable_info
+ALTER TABLE t2c ADD PRIMARY KEY(a,b), ADD INDEX t2a(a), ALGORITHM=COPY;
+--disable_info
+connection b;
+# t2i and t2c are too new for this transaction, because they were rebuilt
+--error ER_TABLE_DEF_CHANGED
+SELECT * FROM t2i;
+--error ER_TABLE_DEF_CHANGED
+SELECT * FROM t2i FORCE INDEX(t2a) ORDER BY a;
+--error ER_TABLE_DEF_CHANGED
+SELECT * FROM t2c;
+--error ER_TABLE_DEF_CHANGED
+SELECT * FROM t2c FORCE INDEX(t2a) ORDER BY a;
+# In t2, only the new index t2a is too new for this transaction.
+SELECT * FROM t2;
+--error ER_TABLE_DEF_CHANGED
+SELECT * FROM t2 FORCE INDEX(t2a) ORDER BY a;
+SELECT * FROM t2;
+COMMIT;
+# For a new transaction, all of t2, t2i, t2c are accessible.
+SELECT * FROM t2;
+SELECT * FROM t2 FORCE INDEX(t2a) ORDER BY a;
+SELECT * FROM t2i;
+SELECT * FROM t2i FORCE INDEX(t2a) ORDER BY a;
+SELECT * FROM t2c;
+SELECT * FROM t2c FORCE INDEX(t2a) ORDER BY a;
+connection default;
+disconnect a;
+disconnect b;
+
+--error ER_DUP_KEYNAME
+alter table t2 add index t2a(b);
+alter table t2 drop index t2a, add index t2a(b);
+show create table t2;
+show create table t2i;
+show create table t2c;
+
+--disable_info
+
+DROP TABLE t1,t2,t2c,t2i;
+
+CREATE TABLE t1 (c VARCHAR(1024),
+c1 CHAR(255) NOT NULL,c2 CHAR(255) NOT NULL,c3 CHAR(255) NOT NULL,
+c4 CHAR(255) NOT NULL,c5 CHAR(255) NOT NULL,c6 CHAR(255) NOT NULL,
+c7 CHAR(255) NOT NULL,c8 CHAR(255) NOT NULL,c9 CHAR(255) NOT NULL,
+ca CHAR(255) NOT NULL,cb CHAR(255) NOT NULL,cc CHAR(255) NOT NULL,
+cd CHAR(255) NOT NULL,ce CHAR(255) NOT NULL,cf CHAR(255) NOT NULL,
+d0 CHAR(255) NOT NULL,d1 CHAR(255) NOT NULL,d2 CHAR(255) NOT NULL,
+d3 CHAR(255) NOT NULL,d4 CHAR(255) NOT NULL,d5 CHAR(255) NOT NULL,
+d6 CHAR(255) NOT NULL,d7 CHAR(255) NOT NULL,d8 CHAR(255) NOT NULL,
+d9 CHAR(255) NOT NULL,da CHAR(255) NOT NULL,db CHAR(255) NOT NULL,
+dc CHAR(255) NOT NULL,dd CHAR(255) NOT NULL,de CHAR(255) NOT NULL,
+UNIQUE KEY(c))
+ENGINE=InnoDB ROW_FORMAT=DYNAMIC;
+INSERT INTO t1 VALUES
+(repeat('a',999),'','','','','','','','','','','','','','','','','','','','','','','','','','','','','',''),
+(CONCAT(repeat('a',999),'b'),'','','','','','','','','','','','','','','','','','','','','','','','','','','','','','');
+--error ER_INDEX_COLUMN_TOO_LONG
+ALTER TABLE t1 ROW_FORMAT=REDUNDANT, algorithm=inplace;
+--error ER_INDEX_COLUMN_TOO_LONG
+ALTER TABLE t1 ROW_FORMAT=REDUNDANT, algorithm=copy;
+SELECT COUNT(*) FROM t1;
+CHECK TABLE t1;
+DROP TABLE t1;
+
+--echo #
+--echo # Bug#19811005 ALTER TABLE ADD INDEX DOES NOT UPDATE INDEX_LENGTH
+--echo # IN I_S TABLES
+--echo #
+let $i_s_query=SELECT cast(DATA_LENGTH/@@innodb_page_size as int) D,
+cast(INDEX_LENGTH/@@innodb_page_size as int) I
+FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA='test';
+
+CREATE TABLE t1(a INT, b INT) ENGINE=INNODB, STATS_PERSISTENT=1;
+eval $i_s_query;
+--enable_info
+ALTER TABLE t1 ADD INDEX (a);
+--disable_info
+eval $i_s_query;
+--enable_info
+ALTER TABLE t1 ADD INDEX (b);
+--disable_info
+eval $i_s_query;
+DROP TABLE t1;
+
+--echo #
+--echo # Bug #17657223 EXCESSIVE TEMPORARY FILE USAGE IN ALTER TABLE
+--echo #
+
+SET GLOBAL innodb_monitor_enable = module_ddl;
+let $innodb_metrics_select=
+SELECT name, count_reset FROM INFORMATION_SCHEMA.INNODB_METRICS WHERE
+subsystem = 'ddl' and count_reset > 0;
+
+# Table with Blob data.
+create table t1(f1 int not null, f2 blob)engine=innodb;
+insert into t1 values(1, repeat('a',20000));
+--echo # Skip sort
+--echo # Reusing the same pk
+--enable_info
+alter table t1 force;
+--disable_info
+eval $innodb_metrics_select;
+SET GLOBAL innodb_monitor_reset = module_ddl;
+drop table t1;
+
+# Table with small data.
+create table t1(f1 int not null, f2 int not null,
+primary key(f1))engine=innodb;
+insert into t1 values(1,2), (3,4);
+--echo # Add Secondary index.
+--echo # Skip temp file usage due to small table size
+--enable_info
+alter table t1 add key(f2);
+--disable_info
+eval $innodb_metrics_select;
+SET GLOBAL innodb_monitor_reset = module_ddl;
+drop table t1;
+
+# Table with large data which is greater than sort buffer
+create table t480(a serial)engine=innodb;
+insert into t480
+values(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),
+(),(),(),(),(),(),(),();
+insert into t480 select 0 from t480;
+insert into t480 select 0 from t480;
+insert into t480 select 0 from t480;
+insert into t480 select 0 from t480;
+create table t1(f1 int auto_increment not null,
+ f2 char(200) not null, f3 char(200) not null,
+ f4 char(200) not null,primary key(f1))engine=innodb;
+insert into t1 select NULL,'aaa','bbb','ccc' from t480;
+insert into t1 select NULL,'aaaa','bbbb','cccc' from t480;
+insert into t1 select NULL,'aaaaa','bbbbb','ccccc' from t480;
+insert into t1 select NULL,'aaaaaa','bbbbbb','cccccc' from t480;
+insert into t1 select NULL,'aaaaaaa','bbbbbbb','ccccccc' from t480;
+insert into t1 select NULL,'aaaaaaaa','bbbbbbbb','cccccccc' from t480;
+select count(*) from t1;
+
+--echo # Skip sort
+--echo # Change PK from (f1) to (f1,f2,f3,f4)
+--enable_info
+alter table t1 drop primary key, add primary key(f1,f2,f3,f4);
+--disable_info
+eval $innodb_metrics_select;
+SET GLOBAL innodb_monitor_reset = module_ddl;
+
+
+# Temp file not used during clustered index rebuild
+# for the following alter table commands.
+
+--echo # Skip sort
+--echo # Change PK from (f1,f2,f3,f4) to (f1,f2,added_columns)
+--enable_info
+alter table t1 drop primary key,add column f5 int not null,
+add column f6 int not null,add primary key(f1,f2,f5,f6);
+--disable_info
+eval $innodb_metrics_select;
+SET GLOBAL innodb_monitor_reset = module_ddl;
+
+--echo # Skip sort
+--echo # Change PK from (f1,f2,f5,f6) to (f1,f2,f5)
+--error ER_KEY_COLUMN_DOES_NOT_EXIST
+alter table t1 drop column f6;
+--enable_info
+alter table t1 drop column f6, drop primary key, add primary key(f1,f2,f5);
+--disable_info
+eval $innodb_metrics_select;
+SET GLOBAL innodb_monitor_reset = module_ddl;
+
+--echo # Skip sort
+--echo # Reusing the same PK
+--enable_info
+alter table t1 add column f6 int;
+--disable_info
+eval $innodb_metrics_select;
+SET GLOBAL innodb_monitor_reset = module_ddl;
+
+--echo # Skip sort
+--echo # Reusing the same pk
+--enable_info
+alter table t1 drop column f6;
+--disable_info
+eval $innodb_metrics_select;
+SET GLOBAL innodb_monitor_reset = module_ddl;
+
+--echo # Must sort
+--echo # Change PK from (f1,f2,f5) to (f1,f5)
+--error ER_KEY_COLUMN_DOES_NOT_EXIST
+alter table t1 drop column f2;
+--enable_info
+alter table t1 drop column f2, drop primary key, add primary key(f1,f5);
+--disable_info
+eval $innodb_metrics_select;
+SET GLOBAL innodb_monitor_reset = module_ddl;
+
+--echo # Skip sort
+--echo # Reusing the same pk
+--enable_info
+alter table t1 add column f2n int after f1, drop primary key, add
+primary key (f1,f5,f2n);
+--disable_info
+eval $innodb_metrics_select;
+SET GLOBAL innodb_monitor_reset = module_ddl;
+
+--echo # Skip sort
+--echo # Reusing the same pk
+--enable_info
+alter table t1 change f5 f2n int not null,change f2n f5 int not null,
+add column f8 int not null;
+--disable_info
+eval $innodb_metrics_select;
+SET GLOBAL innodb_monitor_reset = module_ddl;
+
+--echo # Skip sort
+--echo # Change PK from (f1,f4,f2n) to (f1,f4,added_column,f2n)
+--enable_info
+alter table t1 add column f7 int, drop primary key,
+add primary key (f1,f5,f7,f2n);
+--disable_info
+eval $innodb_metrics_select;
+SET GLOBAL innodb_monitor_reset = module_ddl;
+
+--echo # Skip sort
+--echo # Reusing the same pk
+--enable_info
+alter table t1 force;
+--disable_info
+eval $innodb_metrics_select;
+SET GLOBAL innodb_monitor_reset = module_ddl;
+
+--echo # Skip sort
+--echo # Reusing the same pk
+--enable_info
+alter table t1 row_format=compact;
+--disable_info
+eval $innodb_metrics_select;
+SET GLOBAL innodb_monitor_reset = module_ddl;
+
+--echo # Skip sort
+--echo # Reusing the same pk
+--enable_info
+alter table t1 engine=innodb;
+--disable_info
+eval $innodb_metrics_select;
+SET GLOBAL innodb_monitor_reset = module_ddl;
+
+--echo # Skip sort
+--echo # Optimize table
+--enable_info
+optimize table t1;
+--disable_info
+eval $innodb_metrics_select;
+SET GLOBAL innodb_monitor_reset = module_ddl;
+
+--echo # Sort files used for adding secondary index
+--enable_info
+alter table t1 drop primary key, add primary key(f1,f5,f7), add index
+i(f3);
+--disable_info
+eval $innodb_metrics_select;
+SET GLOBAL innodb_monitor_reset = module_ddl;
+
+--echo # No sort files used for dropping secondary index
+--enable_info
+alter table t1 drop primary key, add primary key(f1,f5),drop index i;
+--disable_info
+eval $innodb_metrics_select;
+SET GLOBAL innodb_monitor_reset = module_ddl;
+
+--echo # Skip sort
+--echo # Change PK(f1,f5) to (f1,added_columns) and drop f5
+--enable_info
+alter table t1 drop primary key, add primary key(f1,f12),
+drop column f5, add column f12 int not null;
+--disable_info
+eval $innodb_metrics_select;
+SET GLOBAL innodb_monitor_reset = module_ddl;
+
+--echo # Must sort
+--echo # Change PK(f1,f12) to (f1,existing_columns)
+--enable_info
+alter table t1 drop primary key, add primary key(f1,f3);
+--disable_info
+eval $innodb_metrics_select;
+SET GLOBAL innodb_monitor_reset = module_ddl;
+
+--echo # Skip sort
+--echo # Change PK(f1,f3) to (f1,added_column,f3,added_column)
+--enable_info
+alter table t1 drop primary key, add column f3n int,
+add column f4n int, add primary key(f1,f3n,f3,f4n);
+--disable_info
+eval $innodb_metrics_select;
+SET GLOBAL innodb_monitor_reset = module_ddl;
+
+--echo # Adding Secondary index alone.
+--enable_info
+alter table t1 add key(f1);
+--disable_info
+eval $innodb_metrics_select;
+SET GLOBAL innodb_monitor_reset = module_ddl;
+
+--echo # Must sort
+--echo # Change PK(f1,f3) to (existing_column,f1)
+--enable_info
+alter table t1 drop primary key, add primary key(f4,f1);
+--disable_info
+eval $innodb_metrics_select;
+SET GLOBAL innodb_monitor_reset = module_ddl;
+
+--echo # Skip sort for PK.
+--echo # Change PK(f4,f1) to (added_columns,f4,f1)
+--echo # Secondary index rebuild happens
+--enable_info
+alter table t1 drop primary key, add column f5n int,
+add column f6n int, add primary key(f5n,f6n,f4,f1);
+--disable_info
+eval $innodb_metrics_select;
+SET GLOBAL innodb_monitor_reset = module_ddl;
+
+--echo # Skip sort for PK.
+--echo # Change PK(f5n,f6n,f4,f1) to
+--echo # (added_columns,f5n,added_column,f6n,f4,f1)
+--echo # Secondary index rebuild happens
+--enable_info
+alter table t1 drop primary key, add column f7n int,
+add column f8n int, add primary key(f7n,f5n,f8n,f6n,f4,f1);
+--disable_info
+eval $innodb_metrics_select;
+SET GLOBAL innodb_monitor_reset = module_ddl;
+
+SET GLOBAL innodb_monitor_disable = module_ddl;
+select count(*) from t1;
+drop table t1;
+--disable_warnings
+SET GLOBAL innodb_monitor_reset = default;
+SET GLOBAL innodb_monitor_enable = default;
+SET GLOBAL innodb_monitor_disable = default;
+--enable_warnings
+
+--echo # Bug#19163915 INNODB: DUPLICATE RECORDS COULD EXIST
+--echo # WHEN SKIPPING SORT FOR CLUSTER INDEX
+
+# last mtuple in previous buffer and first mtuple in next buffer
+# are equal.
+SELECT @@innodb_sort_buffer_size;
+create table t1(f1 int auto_increment not null,
+ f2 char(200) not null, f3 char(200) not null,
+ f4 char(200) not null,primary key(f1,f2,f3,f4));
+insert into t1 select NULL,'aaa','bbb','ccc' from t480;
+insert into t1 values(106, 'aaa','bbb','cccc');
+select count(*) from t1;
+--echo # Skip sort
+--echo # Change PK from (f1,f2,f3,f4) to (f1,f2,f3)
+--error ER_DUP_ENTRY
+alter table t1 drop primary key, add primary key(f1,f2,f3);
+select count(*) from t1;
+drop table t1;
+
+# Duplicates exist with in the buffer
+create table t1(f1 int auto_increment not null,
+ f2 char(200) not null, f3 char(200) not null,
+ f4 char(200) not null,primary key(f1,f2,f3,f4));
+insert into t1 select NULL,'aaa','bbb','ccc' from t480;
+insert into t1 values(108,'aaa','bbb','cccc');
+select count(*) from t1;
+--error ER_DUP_ENTRY
+alter table t1 drop primary key, add primary key(f1,f2,f3);
+select count(*) from t1;
+drop table t1, t480;
+
+--echo #
+--echo # Bug #19896922 SORTING SKIPPED WHEN PREFIX LENGTH OF THE PK
+--echo # FIELD IS CHANGED
+--echo #
+
+# Prefix length changes for the varchar column.
+create table t1(a int not null, b varchar(30) not null,
+ primary key (b(10), a)) engine = innodb;
+insert into t1 values(0,'khdHps6UxW8Lwaoxa604oK6zkb'),(1,'khdHps6UxW8L');
+select * from t1;
+alter table t1 drop primary key, add primary key (b(18),a);
+select * from t1;
+drop table t1;
+
+create table t1(a int not null, b varchar(30) not null,
+ primary key (b(10), a)) engine = innodb;
+insert into t1 values(0,'khdHps6UxW8Lwaoxa604oK6zkb'),(1,'khdHps6UtW8L');
+select * from t1;
+alter table t1 drop primary key, add primary key (b(8),a);
+select * from t1;
+drop table t1;
+
+
+--echo #
+--echo # Bug #21103101 SORTING SKIPPED WHEN DROPPING THE SINGLE
+--echo # COLUMN PRIMARY KEY
+--echo #
+
+# Drop primary key column.
+create table t1(f1 int not null, f2 int not null,
+ primary key (f1), unique key(f1, f2))engine=innodb;
+insert into t1 values(1,3), (2,2);
+--error ER_KEY_COLUMN_DOES_NOT_EXIST
+alter table t1 drop column f1;
+--error ER_KEY_COLUMN_DOES_NOT_EXIST
+alter table t1 drop column f1, drop primary key;
+# DROP PRIMARY KEY is implied for a single-column PRIMARY KEY
+alter table t1 drop column f1, drop key f1;
+drop table t1;
+
+# Drop Primary key when lock is none.
+create table t1(f1 int not null, f2 int not null,
+ primary key (f1), unique key(f1, f2))engine=innodb;
+insert into t1 values(1,3), (2,2);
+alter table t1 drop primary key, lock=none;
+--error ER_ALTER_OPERATION_NOT_SUPPORTED_REASON
+alter table t1 drop index f1, lock=none;
+drop table t1;
+
+--echo #
+--echo # BUG#21612714 ALTER TABLE SORTING SKIPPED WHEN CHANGE PK AND DROP
+--echo # LAST COLUMN OF OLD PK
+--echo #
+
+# no skip sort cases
+# pk(o1,o2) to pk(o1,o3), drop o2
+create table t1(o1 int, o2 int, o3 int not null, primary key(o1,o2)) engine = innodb;
+insert into t1 values(1,1,2),(1,2,1);
+alter table t1 drop primary key, add primary key(o1,o3), drop o2, lock=none;
+drop table t1;
+
+# pk(o1,o2) to pk(o3), drop o1, o2
+create table t1(o1 int, o2 int, o3 int not null, primary key(o1,o2)) engine = innodb;
+insert into t1 values(1,1,2),(1,2,1);
+alter table t1 drop o1, drop o2, add primary key(o3), lock=none;
+drop table t1;
+
+# pk(o1,o2) to pk(o1,o3)
+create table t1(o1 int, o2 int, o3 int not null, primary key(o1,o2)) engine = innodb;
+insert into t1 values(1,1,2),(1,2,1);
+alter table t1 drop primary key, add primary key(o1,o3), lock=none;
+drop table t1;
+
+# pk(o1,o2) to pk(o3)
+create table t1(o1 int, o2 int, o3 int not null, primary key(o1,o2)) engine = innodb;
+insert into t1 values(1,1,2),(1,2,1);
+alter table t1 drop primary key, add primary key(o3), lock=none;
+drop table t1;
+
+# pk(o1,o2) to pk(n1,o3)
+create table t1(o1 int, o2 int, o3 int not null, primary key(o1,o2)) engine = innodb;
+insert into t1 values(1,1,2),(1,2,1);
+alter table t1 add column n1 int not null, drop primary key, add primary key(n1,o3), lock=none;
+drop table t1;
+
+# pk(o1,o2) to pk(o3,n1)
+create table t1(o1 int, o2 int, o3 int not null, primary key(o1,o2)) engine = innodb;
+insert into t1 values(1,1,2),(2,2,1);
+alter table t1 add column n1 int not null, drop primary key, add primary key(o3,n1), lock=none;
+drop table t1;
+
+# pk(o1,o2) to pk(o2,o1)
+create table t1(o1 int, o2 int, o3 int not null, primary key(o1,o2)) engine = innodb;
+insert into t1 values(1,2,2),(2,1,1);
+alter table t1 drop primary key, add primary key(o2, o1), lock=none;
+drop table t1;
+
+# pk(o1,o2) to pk(o2)
+create table t1(o1 int, o2 int, o3 int not null, primary key(o1,o2)) engine = innodb;
+insert into t1 values(1,2,2),(2,1,1);
+alter table t1 drop primary key, add primary key(o2), lock=none;
+drop table t1;
+
+# pk(o1,o2) to pk(o2,o3)
+create table t1(o1 int, o2 int, o3 int not null, primary key(o1,o2)) engine = innodb;
+insert into t1 values(1,2,2),(2,1,1);
+alter table t1 drop primary key, add primary key(o2,o3), lock=none;
+drop table t1;
+
+# pk(o2,o1) to pk(o2,o3)
+create table t1(o1 int, o2 int, o3 int not null, primary key(o2,o1)) engine = innodb;
+insert into t1 values(1,1,2),(2,1,1);
+alter table t1 drop primary key, add primary key(o2,o3), lock=none;
+drop table t1;
+
+# pk(o1,o2) to pk(o1,o3,o2)
+create table t1(o1 int, o2 int, o3 int not null, primary key(o1,o2)) engine = innodb;
+insert into t1 values(1,1,2),(1,2,1);
+alter table t1 drop primary key, add primary key(o1,o3,o2), lock=none;
+drop table t1;
+
+# pk(o1,o2) to pk(o3,o1,o2)
+create table t1(o1 int, o2 int, o3 int not null, primary key(o1,o2)) engine = innodb;
+insert into t1 values(1,2,2),(2,1,1);
+alter table t1 drop primary key, add primary key(o3,o1,o2), lock=none;
+drop table t1;
+
+# pk(o1,o2,o3) to pk(o1,o3)
+create table t1(o1 int, o2 int, o3 int, primary key(o1,o2,o3)) engine = innodb;
+insert into t1 values(1,1,2),(1,2,1);
+alter table t1 drop primary key, add primary key(o1,o3), lock=none;
+drop table t1;
+
+# pk(o1,o2,o3) to pk(o2,o3) by drop o1
+create table t1(o1 int, o2 int, o3 int, primary key(o1,o2,o3)) engine = innodb;
+insert into t1 values(1,2,2),(2,1,1);
+--error ER_KEY_COLUMN_DOES_NOT_EXIST
+alter table t1 drop o1, lock=none;
+alter table t1 drop o1, drop primary key, add primary key(o2,o3), lock=none;
+drop table t1;
+
+# pk(o1,o2,o3) to pk(o1,o3) by drop o2
+create table t1(o1 int, o2 int, o3 int, primary key(o1,o2,o3)) engine = innodb;
+insert into t1 values(1,1,2),(1,2,1);
+--error ER_KEY_COLUMN_DOES_NOT_EXIST
+alter table t1 drop o2, lock=none;
+alter table t1 drop o2, drop primary key, add primary key(o1,o3), lock=none;
+drop table t1;
+
+# pk(o1,o2,o3) to pk(o3) by drop o1,o2
+create table t1(o1 int, o2 int, o3 int, primary key(o1,o2,o3)) engine = innodb;
+insert into t1 values(1,2,2),(2,1,1);
+--error ER_KEY_COLUMN_DOES_NOT_EXIST
+alter table t1 drop o1, drop o2, lock=none;
+alter table t1 drop o1, drop o2,drop primary key,add primary key(o3),lock=none;
+drop table t1;
+
+# no skip sort for prefix change
+# pk(o1(2),o2) to pk(o1(3),o2)
+create table t1(o1 varchar(10), o2 int, o3 int not null, primary key(o1(2), o2)) engine = innodb;
+insert into t1 values('abd', 1, 1), ('abc', 2, 2);
+alter table t1 drop primary key, add primary key(o1(3), o2), lock=none;
+drop table t1;
+
+# pk(o1(2),o2) to pk(o1,o2)
+create table t1(o1 varchar(10), o2 int, o3 int not null, primary key(o1(2), o2)) engine = innodb;
+insert into t1 values('abd', 1, 1), ('abc', 2, 2);
+alter table t1 drop primary key, add primary key(o1, o2), lock=none;
+drop table t1;
+
+# pk(o1(2),o2) to pk(o1(3),o3)
+create table t1(o1 varchar(10), o2 int, o3 int not null, primary key(o1(2), o2)) engine = innodb;
+insert into t1 values('abd', 1, 1), ('abc', 2, 2);
+alter table t1 drop primary key, add primary key(o1(3), o3), lock=none;
+drop table t1;
+
+# pk(o1(2),o2) to pk(o1,o3)
+create table t1(o1 varchar(10), o2 int, o3 int not null, primary key(o1(2), o2)) engine = innodb;
+insert into t1 values('abd', 1, 1), ('abc', 2, 2);
+alter table t1 drop primary key, add primary key(o1, o3), lock=none;
+drop table t1;
+
+# pk(o1(3),o2) to pk(o1(2),o2)
+create table t1(o1 varchar(10), o2 int, o3 int not null, primary key(o1(3), o2)) engine = innodb;
+insert into t1 values('abc', 2, 1), ('abd', 1, 2);
+alter table t1 drop primary key, add primary key(o1(2), o2), lock=none;
+drop table t1;
+
+# pk(o1,o2) to pk(o1(2),o2)
+create table t1(o1 varchar(10), o2 int, o3 int not null, primary key(o1, o2)) engine = innodb;
+insert into t1 values('abc', 2, 1), ('abd', 1, 2);
+alter table t1 drop primary key, add primary key(o1(2), o2), lock=none;
+drop table t1;
+
+# pk(o1(3),o2) to pk(o1(2),o3)
+create table t1(o1 varchar(10), o2 int, o3 int not null, primary key(o1(3), o2)) engine = innodb;
+insert into t1 values('abc', 2, 2), ('abd', 1, 1);
+alter table t1 drop primary key, add primary key(o1(2), o3), lock=none;
+drop table t1;
+
+# pk(o1,o2) to pk(o1(2),o3)
+create table t1(o1 varchar(10), o2 int, o3 int not null, primary key(o1, o2)) engine = innodb;
+insert into t1 values('abc', 2, 2), ('abd', 1, 1);
+alter table t1 drop primary key, add primary key(o1(2), o3), lock=none;
+drop table t1;
+
+# pk(o1,o2(2),o3) to pk(o1,o2(3))
+create table t1(o1 int, o2 varchar(10), o3 int, primary key(o1,o2(2),o3)) engine = innodb;
+insert into t1 values(1, 'abd', 1), (1, 'abc', 2);
+alter table t1 drop primary key, add primary key(o1,o2(3)), lock=none;
+drop table t1;
+
+# pk(o1,o2(2),o3) to pk(o1,o2)
+create table t1(o1 int, o2 varchar(10), o3 int, primary key(o1,o2(2),o3)) engine = innodb;
+insert into t1 values(1, 'abd', 1), (1, 'abc', 2);
+alter table t1 drop primary key, add primary key(o1,o2), lock=none;
+drop table t1;
+
+# pk(o1(3),o2(3)) to pk(o1(2),o2(3))
+create table t1(o1 varchar(10), o2 varchar(10), primary key(o1(3),o2(3))) engine = innodb;
+insert into t1 values('abc', 'acd'), ('abd', 'abd');
+alter table t1 drop primary key, add primary key(o1(2),o2(3)), lock=none;
+drop table t1;
+
+# pk(o1,o2) to pk(o1(2),o2)
+create table t1(o1 varchar(10), o2 varchar(10), primary key(o1,o2)) engine = innodb;
+insert into t1 values('abc', 'acd'), ('abd', 'abd');
+alter table t1 drop primary key, add primary key(o1(2),o2), lock=none;
+drop table t1;
+
+# pk(o1(3),o2(3)) to pk(o2(3),o1(3))
+create table t1(o1 varchar(10), o2 varchar(10), primary key(o1(3),o2(3))) engine = innodb;
+insert into t1 values('abd', 'acd'), ('acd', 'abd');
+alter table t1 drop primary key, add primary key(o2(3),o1(3)), lock=none;
+drop table t1;
+
+# pk(o1,o2) to pk(o2,o1)
+create table t1(o1 varchar(10), o2 varchar(10), primary key(o1,o2)) engine = innodb;
+insert into t1 values('abd', 'acd'), ('acd', 'abd');
+alter table t1 drop primary key, add primary key(o2,o1), lock=none;
+drop table t1;
+
+# no skip sort cases
+--source suite/innodb/include/alter_table_pk_no_sort.inc
+
+--echo #
+--echo # MDEV-15325 Incomplete validation of missing tablespace during recovery
+--echo #
+
+--source include/no_checkpoint_start.inc
+CREATE TABLE t1(f1 INT PRIMARY KEY)ENGINE=InnoDB;
+
+CREATE TABLE t2(f1 INT PRIMARY KEY)ENGINE=InnoDB;
+
+--let CLEANUP_IF_CHECKPOINT=DROP TABLE t1, t2;
+--source include/no_checkpoint_end.inc
+
+let SEARCH_FILE= $MYSQLTEST_VARDIR/log/mysqld.1.err;
+let $check_no_innodb=SELECT * FROM INFORMATION_SCHEMA.ENGINES
+WHERE engine = 'innodb'
+AND support IN ('YES', 'DEFAULT', 'ENABLED');
+
+--echo # Wrong space_id in a dirty file and a missing file
+
+--copy_file $MYSQLD_DATADIR/test/t1.ibd $MYSQLD_DATADIR/test/t0.ibd
+--move_file $MYSQLD_DATADIR/test/t2.ibd $MYSQLD_DATADIR/test/t1.ibd
+
+--source include/start_mysqld.inc
+--eval $check_no_innodb
+--source include/shutdown_mysqld.inc
+
+--echo # Restore t1 and t2
+
+--move_file $MYSQLD_DATADIR/test/t1.ibd $MYSQLD_DATADIR/test/t2.ibd
+--move_file $MYSQLD_DATADIR/test/t0.ibd $MYSQLD_DATADIR/test/t1.ibd
+
+--source include/start_mysqld.inc
+
+SELECT * FROM t1;
+SELECT * FROM t2;
+
+DROP TABLE t1, t2;
+
+--echo #
+--echo # MDEV-18186 assertion failure on missing InnoDB index
+--echo #
+
+--disable_query_log
+call mtr.add_suppression("Cannot find index i1 in InnoDB index dictionary");
+call mtr.add_suppression("InnoDB indexes are inconsistent with what defined");
+call mtr.add_suppression("Table test/t contains 0 indexes");
+call mtr.add_suppression("InnoDB could not find key no");
+--enable_query_log
+
+# Test an attempt to rename a nonexistent index inside InnoDB
+-- let $MYSQL_DATA_DIR = `SELECT @@datadir`
+CREATE TABLE t (a INT, INDEX i1 (a)) ENGINE=INNODB;
+-- copy_file $MYSQL_DATA_DIR/test/t.frm $MYSQL_DATA_DIR/test/t.fr_
+DROP TABLE t;
+CREATE TABLE t (a INT) ENGINE=INNODB;
+-- remove_file $MYSQL_DATA_DIR/test/t.frm
+-- move_file $MYSQL_DATA_DIR/test/t.fr_ $MYSQL_DATA_DIR/test/t.frm
+--enable_prepare_warnings
+SHOW CREATE TABLE t;
+--disable_prepare_warnings
+DROP TABLE t;
+
+--echo #
+--echo # MDEV-27374 InnoDB table becomes corrupt after renaming DESC-indexed column
+--echo #
+CREATE TABLE t1 (a VARCHAR(8), PRIMARY KEY(a DESC)) ENGINE=InnoDB;
+ALTER TABLE t1 RENAME COLUMN a TO b, ALGORITHM=INPLACE;
+SELECT TABLE_ID INTO @table_id FROM INFORMATION_SCHEMA.INNODB_SYS_TABLES WHERE NAME="test/t1";
+SELECT INDEX_ID INTO @index_id FROM INFORMATION_SCHEMA.INNODB_SYS_INDEXES WHERE TABLE_ID = @table_id;
+SELECT NAME FROM INFORMATION_SCHEMA.INNODB_SYS_FIELDS WHERE INDEX_ID=@index_id;
+DROP TABLE t1;
+
+--echo #
+--echo # MDEV-27432 ASC/DESC primary and unique keys cause index
+--echo # inconsistency between InnoDB and server
+--echo #
+CREATE TABLE t1 (id INT NOT NULL, UNIQUE(id DESC)) ENGINE=InnoDB;
+ALTER TABLE t1 ADD PRIMARY KEY (id), ALGORITHM=INPLACE;
+SHOW CREATE TABLE t1;
+DROP TABLE t1;
+
+--echo #
+--echo # MDEV-27445 Index inconsistency and assertion failure after
+--echo # renaming virtual column with DESC key
+--echo #
+CREATE TABLE t1(a INT, b INT AS (a), KEY(a, b DESC)) ENGINE=InnoDB;
+ALTER TABLE t1 RENAME COLUMN IF EXISTS b TO v;
+ALTER TABLE t1 FORCE;
+DROP TABLE t1;
+
+--echo #
+--echo # MDEV-27592 DESC primary index fails to set wide format
+--echo # while renaming the column
+--echo #
+CREATE TABLE t1 (id INT PRIMARY KEY, a CHAR(8), b INT, KEY(a DESC,b)) ENGINE=InnoDB;
+INSERT INTO t1 VALUES (1,'foo',10);
+ALTER TABLE t1 RENAME COLUMN b TO c, ALGORITHM=INPLACE;
+SELECT TABLE_ID INTO @table_id FROM INFORMATION_SCHEMA.INNODB_SYS_TABLES WHERE NAME="test/t1";
+SELECT INDEX_ID INTO @index_id FROM INFORMATION_SCHEMA.INNODB_SYS_INDEXES WHERE TABLE_ID = @table_id ORDER BY INDEX_ID DESC LIMIT 1;
+SELECT NAME FROM INFORMATION_SCHEMA.INNODB_SYS_FIELDS WHERE INDEX_ID=@index_id;
+DROP TABLE t1;
+
+--echo # End of 10.8 tests
+
+--disable_query_log
+
+call mtr.add_suppression("InnoDB: Tablespace .* was not found at .*t[12].ibd.");
+call mtr.add_suppression("InnoDB: Plugin initialization aborted");
+call mtr.add_suppression("Plugin 'InnoDB' init function returned error");
+call mtr.add_suppression("Plugin 'InnoDB' registration as a STORAGE ENGINE failed");
+
+--enable_query_log
diff --git a/mysql-test/suite/innodb/t/innodb-index_ucs2.opt b/mysql-test/suite/innodb/t/innodb-index_ucs2.opt
new file mode 100644
index 00000000..1a01b401
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb-index_ucs2.opt
@@ -0,0 +1 @@
+--skip-innodb-stats-persistent
diff --git a/mysql-test/suite/innodb/t/innodb-index_ucs2.test b/mysql-test/suite/innodb/t/innodb-index_ucs2.test
new file mode 100644
index 00000000..fff9a4da
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb-index_ucs2.test
@@ -0,0 +1,5 @@
+-- source include/have_innodb.inc
+-- source include/have_ucs2.inc
+
+-- let charset = ucs2
+-- source include/innodb-index.inc
diff --git a/mysql-test/suite/innodb/t/innodb-isolation.test b/mysql-test/suite/innodb/t/innodb-isolation.test
new file mode 100644
index 00000000..6d347dc7
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb-isolation.test
@@ -0,0 +1,357 @@
+
+#Note:- WL6742 has been removed from 5.7 (Bug 23046302),
+# but we are keeping this test since it tests
+# count(*) correctness for various isolation
+# levels.
+
+--echo #
+--echo # WL#6742 - Test the interaction of multiple transactions using
+--echo # different isolation levels to make sure that the value returned
+--echo # by count(*) always reflects the correct view of the table according
+--echo # to the transaction's selected isolation level.
+--echo #
+
+--source include/have_innodb.inc
+
+--disable_query_log
+let $MYSQLD_DATADIR= `select @@datadir`;
+let $initial_timeout=`select @@innodb_lock_wait_timeout`;
+--enable_query_log
+
+--echo #
+--echo # Traverse various indexes to get the right counts.
+--echo # This especially tests count(*) which is pushed down to InnoDB in WL#6742.
+--echo #
+CREATE TABLE t1 (
+ c1 INT AUTO_INCREMENT PRIMARY KEY,
+ c2 INT,
+ c3 INT,
+ c4 INT,
+ INDEX k2(c2)
+) Engine=InnoDB;
+let $1=10;
+while ($1 > 0) {
+ INSERT INTO t1(c2,c3,c4) VALUES (1, 1, 1);
+ dec $1;
+}
+
+CREATE TABLE t2 LIKE t1;
+--enable_info
+INSERT INTO t2 (SELECT * FROM t1);
+--disable_info
+
+--source suite/innodb/include/innodb_isolation_selects.inc
+
+--echo #
+--echo # Do some DML in the default connection and leave the transaction pending.
+--echo #
+SET SESSION TRANSACTION ISOLATION LEVEL REPEATABLE READ;
+BEGIN;
+--enable_info
+UPDATE t1 SET c2 = c2 * 3 WHERE c1 = 1;
+DELETE FROM t1 WHERE c1 = 6;
+--disable_info
+--source suite/innodb/include/innodb_isolation_selects.inc
+
+--echo #
+--echo # Start transactions of Repeatable Read, Read Committed, and Read Uncommitted
+--echo #
+--echo # Connection 1 REPEATABLE READ
+--echo #
+connect (con1,localhost,root,,);
+SET SESSION TRANSACTION ISOLATION LEVEL REPEATABLE READ;
+BEGIN;
+--source suite/innodb/include/innodb_isolation_selects.inc
+--enable_info
+UPDATE t1 SET c2 = c2 * 5 WHERE c1 = 2;
+DELETE FROM t1 WHERE c1 = 7;
+INSERT INTO t1(c2,c3,c4) VALUES (100, 1, 1);
+--disable_info
+--source suite/innodb/include/innodb_isolation_selects.inc
+
+--echo #
+--echo # Test a lock wait timeout during COUNT(*)
+--echo #
+SET innodb_lock_wait_timeout = 1;
+--error ER_LOCK_WAIT_TIMEOUT
+SELECT COUNT(*) FROM t1 FOR UPDATE;
+
+
+--echo #
+--echo # Connection 2 READ COMMITTED
+--echo #
+connect (con2,localhost,root,,);
+SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED;
+BEGIN;
+--source suite/innodb/include/innodb_isolation_selects.inc
+--enable_info
+UPDATE t1 SET c2 = c2 * 7 WHERE c1 = 3;
+DELETE FROM t1 WHERE c1 = 8;
+INSERT INTO t1(c2,c3,c4) VALUES (1000, 1, 1);
+--disable_info
+--source suite/innodb/include/innodb_isolation_selects.inc
+
+--echo #
+--echo # Connection 3 READ UNCOMMITTED
+--echo #
+connect (con3,localhost,root,,);
+SET SESSION TRANSACTION ISOLATION LEVEL READ UNCOMMITTED;
+BEGIN;
+--source suite/innodb/include/innodb_isolation_selects.inc
+--enable_info
+UPDATE t1 SET c2 = c2 * 11 WHERE c1 = 4;
+INSERT INTO t1(c2,c3,c4) VALUES (10000, 1, 1);
+DELETE FROM t1 WHERE c1 in(9);
+--disable_info
+--source suite/innodb/include/innodb_isolation_selects.inc
+
+--echo #
+--echo # Connection default REPEATABLE READ
+--echo #
+connection default;
+--source suite/innodb/include/innodb_isolation_selects.inc
+
+--echo #
+--echo # Commit the 3 extra connections
+--echo #
+--echo # Connection 1 REPEATABLE READ
+--echo #
+connection con1;
+--source suite/innodb/include/innodb_isolation_selects.inc
+
+--echo #
+--echo # Connection 2 READ COMMITTED
+--echo #
+connection con2;
+--source suite/innodb/include/innodb_isolation_selects.inc
+
+--echo #
+--echo # Connection 3 READ UNCOMMITTED
+--echo #
+connection con3;
+--source suite/innodb/include/innodb_isolation_selects.inc
+COMMIT;
+--source suite/innodb/include/innodb_isolation_selects.inc
+
+--echo #
+--echo # Connection 2 READ COMMITTED
+--echo #
+connection con2;
+--source suite/innodb/include/innodb_isolation_selects.inc
+COMMIT;
+--source suite/innodb/include/innodb_isolation_selects.inc
+
+--echo #
+--echo # Connection 1 REPEATABLE READ
+--echo #
+connection con1;
+--source suite/innodb/include/innodb_isolation_selects.inc
+
+--echo #
+--echo # Select the first 5 records FOR UPDATE using count(*) in a subquery.
+--echo # The second record is still pending so we get a lock timeout.
+--echo #
+SET innodb_lock_wait_timeout = 1;
+--error ER_LOCK_WAIT_TIMEOUT
+SELECT c1, c2 FROM t1 WHERE c1 < ((SELECT COUNT(*) FROM t1) / 2) FOR UPDATE;
+--error ER_LOCK_WAIT_TIMEOUT
+SELECT COUNT(*) FROM t1 FOR UPDATE;
+COMMIT;
+--source suite/innodb/include/innodb_isolation_selects.inc
+
+--echo #
+--echo # Show The EXPLAIN output for these queries;
+--echo #
+# column 9 is the row count provided by handler::info(). In InnoDB, this is
+# a statistical estimate. After the multi-transactional changes above,
+# Solaris reports 10 rows which is correct, but other OSes report 9.
+--replace_column 9 #
+EXPLAIN SELECT * FROM t1;
+--replace_column 9 #
+EXPLAIN SELECT COUNT(*) FROM t1;
+--replace_column 9 #
+EXPLAIN SELECT COUNT(c1) FROM t1;
+--replace_column 9 #
+EXPLAIN SELECT COUNT(c2) FROM t1;
+--replace_column 9 #
+EXPLAIN SELECT COUNT(c3) FROM t1;
+--replace_column 9 #
+EXPLAIN SELECT SUM(c1) FROM t1;
+--replace_column 9 #
+EXPLAIN SELECT SUM(c2) FROM t1;
+--replace_column 9 #
+EXPLAIN SELECT AVG(c1), MAX(c1), MIN(c2), AVG(c3), SUM(c4) FROM t1;
+--replace_column 9 #
+EXPLAIN SELECT c1, c2 FROM t1 WHERE c1 > ((SELECT COUNT(*) FROM t1) / 2);
+--replace_column 9 #
+EXPLAIN SELECT COUNT(c2) FROM t1 WHERE c1 > ((SELECT COUNT(*) FROM t1) / 2);
+--replace_column 9 #
+EXPLAIN SELECT COUNT(*) FROM t1 WHERE c1 > (SELECT AVG(c1) FROM t1);
+
+--echo #
+--echo # Make all indexes in t2 obsolete to the active repeatable read transaction
+--echo # in the default connection.
+--echo #
+ALTER TABLE t2 row_format=redundant;
+
+--echo #
+--echo # Connection default REPEATABLE READ
+--echo # Do more DML in the default REPEATABLE READ transaction in order to use recently committed records.
+--echo #
+connection default;
+--source suite/innodb/include/innodb_isolation_selects.inc
+--enable_info
+UPDATE t1 SET c4 = c2 * 10;
+--disable_info
+--source suite/innodb/include/innodb_isolation_selects.inc
+
+--echo #
+--echo # Table t2 has been altered to a new row format.
+--echo # The index should not be useable.
+--echo #
+--error ER_TABLE_DEF_CHANGED
+SELECT COUNT(*) FROM t2;
+--error ER_TABLE_DEF_CHANGED
+SELECT * FROM t2;
+
+COMMIT;
+SELECT COUNT(*) FROM t2;
+--source suite/innodb/include/innodb_isolation_selects.inc
+
+--echo #
+--echo # Connection 2
+--echo #
+connection con2;
+--source suite/innodb/include/innodb_isolation_selects.inc
+
+--echo #
+--echo # Try COUNT(*) on a DISCARDED table.
+--echo #
+connection default;
+CREATE TABLE t4 LIKE t1;
+INSERT INTO t4 (SELECT * FROM t1);
+SELECT COUNT(*) FROM t4;
+ALTER TABLE t4 DISCARD TABLESPACE;
+--error ER_TABLESPACE_DISCARDED
+SELECT COUNT(*) FROM t4;
+
+
+--echo #
+--echo # Test the interaction of a repeatable read transaction
+--echo # to changes that happen outside its view.
+--echo #
+
+CREATE TABLE t5 (a INT AUTO_INCREMENT PRIMARY KEY, b TEXT, aa INT, bb TEXT) Engine=InnoDB;
+INSERT INTO t5(b) VALUES ("inserted by client 1");
+INSERT INTO t5(b) VALUES ("inserted by client 1");
+INSERT INTO t5(b) VALUES ("inserted by client 1");
+INSERT INTO t5(b) VALUES ("inserted by client 1");
+UPDATE t5 SET aa=a, bb=b;
+CREATE TABLE t6 (a INT AUTO_INCREMENT PRIMARY KEY, b TEXT, aa INT, bb TEXT) Engine=InnoDB;
+INSERT INTO t6(b) VALUES ("inserted by client 1");
+INSERT INTO t6(b) VALUES ("inserted by client 1");
+INSERT INTO t6(b) VALUES ("inserted by client 1");
+INSERT INTO t6(b) VALUES ("inserted by client 1");
+UPDATE t6 SET aa=a, bb=b;
+CREATE TABLE t7 (a INT AUTO_INCREMENT PRIMARY KEY, b TEXT, aa INT, bb TEXT) Engine=InnoDB;
+INSERT INTO t7(b) VALUES ("inserted by client 1");
+INSERT INTO t7(b) VALUES ("inserted by client 1");
+INSERT INTO t7(b) VALUES ("inserted by client 1");
+INSERT INTO t7(b) VALUES ("inserted by client 1");
+UPDATE t7 SET aa=a, bb=b;
+BEGIN;
+SELECT * FROM t5;
+SELECT COUNT(*) FROM t5;
+SELECT * FROM t6;
+SELECT COUNT(*) FROM t6;
+SELECT * FROM t7;
+SELECT COUNT(*) FROM t7;
+
+--echo #
+--echo # Connection 1
+--echo #
+connection con1;
+INSERT INTO t5(b) VALUES ("inserted by client 2");
+UPDATE t5 SET a = 10 where a = 1;
+UPDATE t5 SET b = "updated by client 2" where a = 2;
+DELETE FROM t5 WHERE a = 3;
+SELECT * FROM t5;
+SELECT COUNT(*) FROM t5;
+INSERT INTO t6(b) VALUES ("inserted by client 2");
+UPDATE t6 SET a = 10 where a = 1;
+UPDATE t6 SET b = "updated by client 2" where a = 2;
+DELETE FROM t6 WHERE a = 3;
+SELECT * FROM t6;
+SELECT COUNT(*) FROM t6;
+INSERT INTO t7(b) VALUES ("inserted by client 2");
+UPDATE t7 SET a = 10 where a = 1;
+UPDATE t7 SET b = "updated by client 2" where a = 2;
+DELETE FROM t7 WHERE a = 3;
+SELECT * FROM t7;
+SELECT COUNT(*) FROM t7;
+
+--echo #
+--echo # Connection default
+--echo #
+connection default;
+SELECT * FROM t5;
+INSERT INTO t5(b) VALUES ("inserted by client 1");
+SELECT * FROM t5;
+UPDATE t5 SET a = a + 100;
+SELECT * FROM t5;
+SELECT COUNT(*) FROM t5;
+
+UPDATE t6 SET b = "updated by client 2";
+SELECT * FROM t6;
+SELECT * FROM t6 LOCK IN SHARE MODE;
+SELECT COUNT(*) FROM t6;
+
+DELETE FROM t7;
+SELECT * FROM t7;
+SELECT COUNT(*) FROM t7;
+
+COMMIT;
+SELECT * FROM t5;
+SELECT COUNT(*) FROM t5;
+SELECT * FROM t6;
+SELECT COUNT(*) FROM t6;
+SELECT * FROM t7;
+SELECT COUNT(*) FROM t7;
+
+--echo #
+--echo # Cleanup
+--echo #
+DROP TABLE t1,t2,t4,t5,t6,t7;
+disconnect con1;
+disconnect con2;
+disconnect con3;
+--disable_query_log
+eval set global innodb_lock_wait_timeout=$initial_timeout;
+--enable_query_log
+
+--echo #
+--echo # Bug #23596760: FORCE INDEX IS SKIPPED WHILE EXECUTING SELECT COUNT(*)
+--echo #
+
+CREATE TABLE t1(c1 INT NOT NULL PRIMARY KEY,
+ c2 INT NOT NULL DEFAULT 1,
+ c3 char(20) DEFAULT '',
+ KEY c2_idx (c2)) ENGINE=InnoDB STATS_PERSISTENT=0;
+
+INSERT INTO t1(c1) VALUES (1), (2), (3);
+INSERT INTO t1(c1) SELECT c1 + 10 FROM t1;
+INSERT INTO t1(c1) SELECT c1 + 100 FROM t1;
+
+CREATE TABLE t2 STATS_PERSISTENT=0 SELECT * FROM t1;
+
+let query1= SELECT COUNT(*) FROM t1;
+let query2= SELECT COUNT(*) FROM t1 FORCE INDEX(c2_idx);
+let query3= SELECT COUNT(*) FROM t1, t2;
+let query4= SELECT COUNT(*) FROM t1 FORCE INDEX(c2_idx), t2;
+
+eval EXPLAIN $query1;
+eval EXPLAIN $query2;
+eval EXPLAIN $query3;
+eval EXPLAIN $query4;
+
+DROP TABLE t1, t2;
diff --git a/mysql-test/suite/innodb/t/innodb-lock.test b/mysql-test/suite/innodb/t/innodb-lock.test
new file mode 100644
index 00000000..fbbb1035
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb-lock.test
@@ -0,0 +1,224 @@
+--source include/have_innodb.inc
+--source include/have_partition.inc
+
+#
+# Check and select innodb lock type
+#
+
+set global innodb_table_locks=1;
+
+select @@innodb_table_locks;
+
+#
+# Testing of explicit table locks with enforced table locks
+#
+
+set @@innodb_table_locks=1;
+
+connect (con1,localhost,root,,);
+create table t1 (id integer, x integer) engine=INNODB;
+insert into t1 values(0, 0);
+set autocommit=0;
+SELECT * from t1 where id = 0 FOR UPDATE;
+
+connect (con2,localhost,root,,);
+set autocommit=0;
+
+# The following statement should hang because con1 is locking the page
+--send
+lock table t1 write;
+--sleep 2
+
+connection con1;
+update t1 set x=1 where id = 0;
+select * from t1;
+commit;
+
+connection con2;
+reap;
+update t1 set x=2 where id = 0;
+commit;
+unlock tables;
+
+connection con1;
+select * from t1;
+commit;
+
+drop table t1;
+
+--echo #
+--echo # Old lock method (where LOCK TABLE was ignored by InnoDB) no longer
+--echo # works when LOCK TABLE ... WRITE is used due to fix for bugs #46272
+--echo # "MySQL 5.4.4, new MDL: unnecessary and bug #37346 "innodb does not
+--echo # detect deadlock between update and alter table".
+--echo # After WL#6671 "Improve scalability by not using thr_lock.c locks
+--echo # for InnoDB tables" was implemented it no longer works for LOCK TABLES
+--echo # ,,, READ as well.
+--echo # LOCK TABLES locks are now completely handled by MDL subsystem.
+--echo #
+
+set @@innodb_table_locks=0;
+
+create table t1 (id integer primary key, x integer) engine=INNODB;
+insert into t1 values(0, 0),(1,1),(2,2);
+commit;
+SELECT * from t1 where id = 0 FOR UPDATE;
+
+connection con2;
+set autocommit=0;
+set @@innodb_table_locks=0;
+
+--echo # The following statement should block because SQL-level lock
+--echo # is taken on t1 which will wait until concurrent transaction
+--echo # is commited.
+--echo # Sending:
+--send lock table t1 write;
+
+connection con1;
+--echo # Wait until LOCK TABLE is blocked on SQL-level 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 # We should be able to do UPDATEs and SELECTs within transaction.
+update t1 set x=1 where id = 0;
+select * from t1;
+--echo # Unblock LOCK TABLE.
+commit;
+
+connection con2;
+--echo # Reap LOCK TABLE.
+--reap
+unlock tables;
+
+connection con1;
+
+select * from t1 where id = 0 for update;
+
+connection con2;
+--echo # The following statement should block because SQL-level lock
+--echo # is taken on t1 which will wait until concurrent transaction
+--echo # is commited.
+--echo # Sending:
+--send lock table t1 read;
+
+connection con1;
+--echo # Wait until LOCK TABLE is blocked on SQL-level lock.
+let $wait_condition=
+ select count(*) = 1 from information_schema.processlist
+ where state = "Waiting for table metadata lock" and
+ info = "lock table t1 read";
+--source include/wait_condition.inc
+--echo # We should be able to do UPDATEs and SELECTs within transaction.
+update t1 set x=2 where id = 0;
+select * from t1;
+--echo # Unblock LOCK TABLE.
+commit;
+
+connection con2;
+--echo # Reap LOCK TABLE.
+--reap
+unlock tables;
+
+connection default;
+
+drop table t1;
+
+# End of 4.1 tests
+
+--echo #
+--echo #Bug#12842206 INNODB LOCKING REGRESSION FOR INSERT IGNORE
+--echo #fixed by re-fixing Bug#7975
+--echo #aka Bug#11759688 52020: InnoDB can still deadlock on just INSERT...
+--echo #
+
+connection default;
+CREATE TABLE t1 (a INT PRIMARY KEY, b INT NOT NULL) ENGINE=InnoDB;
+INSERT INTO t1 VALUES(3,1);
+
+BEGIN;
+# this used to wrongly acquire an X lock; now it takes an S lock
+INSERT IGNORE INTO t1 VALUES(3,14);
+
+connection con1;
+BEGIN;
+# this used to wrongly acquire an X lock; now it takes an S lock
+INSERT IGNORE INTO t1 VALUES(3,23);
+--send
+SELECT * FROM t1 FOR UPDATE;
+
+connection con2;
+# Check that the above SELECT is blocked
+let $wait_condition=
+ select count(*) = 1 from information_schema.processlist
+ where state = 'Sending data' and
+ info = 'SELECT * FROM t1 FOR UPDATE';
+--source include/wait_condition.inc
+disconnect con2;
+
+connection default;
+COMMIT;
+connection con1;
+reap;
+COMMIT;
+connection default;
+DROP TABLE t1;
+
+--echo #
+--echo # MDEV-11080 InnoDB: Failing assertion:
+--echo # table->n_waiting_or_granted_auto_inc_locks > 0
+--echo #
+
+CREATE TABLE t1 (pk INTEGER AUTO_INCREMENT PRIMARY KEY) ENGINE=InnoDB;
+INSERT INTO t1 VALUES (NULL),(NULL);
+CREATE TABLE t2 LIKE t1;
+
+BEGIN;
+
+connection con1;
+BEGIN;
+DELETE FROM t2;
+connection default;
+--send LOCK TABLE t2 READ;
+connection con1;
+SET innodb_lock_wait_timeout= 1, lock_wait_timeout= 2;
+--error 0,ER_LOCK_WAIT_TIMEOUT
+INSERT INTO t2 SELECT * FROM t1;
+COMMIT;
+
+connection default;
+reap;
+UNLOCK TABLES;
+DROP TABLE t1, t2;
+
+--echo #
+--echo # MDEV-16709 InnoDB: Error: trx already had an AUTO-INC lock
+--echo #
+
+CREATE TABLE t1 (pk INT AUTO_INCREMENT PRIMARY KEY) ENGINE=InnoDB
+PARTITION BY key (pk) PARTITIONS 2;
+# MDEV-515 takes X-lock on the table for the first insert.
+# So concurrent insert won't happen on the table
+INSERT INTO t1 VALUES(100);
+INSERT INTO t1 VALUES(101);
+
+CREATE TABLE t2 (a INT) ENGINE=InnoDB;
+INSERT INTO t2 VALUES (1),(2),(3),(4),(5),(6);
+
+CREATE TABLE t3 (b INT) ENGINE=InnoDB;
+INSERT INTO t3 VALUES (1),(2),(3),(4),(5),(6),(7),(8),(9);
+
+connection con1;
+send INSERT t1 SELECT NULL FROM t2;
+
+connection default;
+--error 0,ER_DUP_ENTRY,ER_LOCK_DEADLOCK
+INSERT t1 SELECT NULL FROM t3;
+
+connection con1;
+--error 0,ER_DUP_ENTRY,ER_LOCK_DEADLOCK
+reap;
+disconnect con1;
+connection default;
+DROP TABLE t1, t2, t3;
diff --git a/mysql-test/suite/innodb/t/innodb-lru-force-no-free-page.test b/mysql-test/suite/innodb/t/innodb-lru-force-no-free-page.test
new file mode 100644
index 00000000..d4f08b5a
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb-lru-force-no-free-page.test
@@ -0,0 +1,24 @@
+--source include/have_innodb.inc
+--source include/have_debug.inc
+--source include/not_embedded.inc
+
+call mtr.add_suppression("InnoDB: Difficult to find free blocks in the buffer pool");
+
+SET @saved_debug = @@SESSION.debug_dbug;
+SET SESSION debug_dbug="+d,ib_lru_force_no_free_page";
+
+CREATE TABLE t1 (j LONGBLOB) ENGINE = InnoDB;
+BEGIN;
+INSERT INTO t1 VALUES (repeat('abcdefghijklmnopqrstuvwxyz',200));
+COMMIT;
+
+SET debug_dbug = @saved_debug;
+
+DROP TABLE t1;
+
+#
+# There should be only one message
+#
+let SEARCH_FILE= $MYSQLTEST_VARDIR/log/mysqld.1.err;
+--let SEARCH_PATTERN=InnoDB: Difficult to find free blocks
+--source include/search_pattern_in_file.inc
diff --git a/mysql-test/suite/innodb/t/innodb-master.opt b/mysql-test/suite/innodb/t/innodb-master.opt
new file mode 100644
index 00000000..2e71d622
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb-master.opt
@@ -0,0 +1,6 @@
+--binlog-cache-size=32768 --loose-innodb-lock-wait-timeout=1
+--default-storage-engine=MyISAM
+--innodb-strict-mode=0
+--innodb-file-per-table=0
+--loose-innodb-track-changed-pages
+--loose-innodb-log-archive
diff --git a/mysql-test/suite/innodb/t/innodb-mdev-7408.opt b/mysql-test/suite/innodb/t/innodb-mdev-7408.opt
new file mode 100644
index 00000000..1c256483
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb-mdev-7408.opt
@@ -0,0 +1,2 @@
+--innodb_ft_default_stopword
+
diff --git a/mysql-test/suite/innodb/t/innodb-mdev-7408.test b/mysql-test/suite/innodb/t/innodb-mdev-7408.test
new file mode 100644
index 00000000..46f1afca
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb-mdev-7408.test
@@ -0,0 +1,18 @@
+--source include/have_innodb.inc
+
+call mtr.add_suppression("InnoDB: User stopword table .* does not exist.");
+
+select @@global.innodb_ft_server_stopword_table;
+CREATE TABLE `stop_it-IT` ENGINE = InnoDB SELECT * FROM information_schema.INNODB_FT_DEFAULT_STOPWORD;
+--error 1231
+SET @@global.innodb_ft_server_stopword_table = 'test/stop_it-IT';
+--error 0,1231
+SET @@global.innodb_ft_server_stopword_table = 'test/stop_it@002dIT';
+drop table `stop_it-IT`;
+
+CREATE TABLE stop_it ENGINE = InnoDB SELECT * FROM information_schema.INNODB_FT_DEFAULT_STOPWORD;
+SET @@global.innodb_ft_server_stopword_table = 'test/stop_it';
+
+SET @@global.innodb_ft_server_stopword_table = NULL;
+
+drop table stop_it;
diff --git a/mysql-test/suite/innodb/t/innodb-mdev-7513-master.opt b/mysql-test/suite/innodb/t/innodb-mdev-7513-master.opt
new file mode 100644
index 00000000..a2a7d5f6
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb-mdev-7513-master.opt
@@ -0,0 +1 @@
+--innodb-strict-mode=0
diff --git a/mysql-test/suite/innodb/t/innodb-mdev-7513.test b/mysql-test/suite/innodb/t/innodb-mdev-7513.test
new file mode 100644
index 00000000..b824cbcf
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb-mdev-7513.test
@@ -0,0 +1,219 @@
+-- source include/have_innodb.inc
+-- source include/not_embedded.inc
+
+# MDEV-7513: ib_warn_row_too_big dereferences null thd
+
+
+--disable_warnings
+CREATE TABLE t1 ( text1 TEXT,
+text2 TEXT,
+text3 TEXT,
+text4 TEXT,
+text5 TEXT,
+text6 TEXT,
+text7 TEXT,
+text8 TEXT,
+text9 TEXT,
+text10 TEXT,
+text11 TEXT,
+text12 TEXT,
+text13 TEXT,
+text14 TEXT,
+text15 TEXT,
+text16 TEXT,
+text17 TEXT,
+text18 TEXT,
+text19 TEXT,
+text20 TEXT,
+text21 TEXT,
+text22 TEXT,
+text23 TEXT,
+text24 TEXT,
+text25 TEXT,
+text26 TEXT,
+text27 TEXT,
+text28 TEXT,
+text29 TEXT,
+text30 TEXT,
+text31 TEXT,
+text32 TEXT,
+text33 TEXT,
+text34 TEXT,
+text35 TEXT,
+text36 TEXT,
+text37 TEXT,
+text38 TEXT,
+text39 TEXT,
+text40 TEXT,
+text41 TEXT,
+text42 TEXT,
+text43 TEXT,
+text44 TEXT,
+text45 TEXT,
+text46 TEXT,
+text47 TEXT,
+text48 TEXT,
+text49 TEXT,
+text50 TEXT,
+text51 TEXT,
+text52 TEXT,
+text53 TEXT,
+text54 TEXT,
+text55 TEXT,
+text56 TEXT,
+text57 TEXT,
+text58 TEXT,
+text59 TEXT,
+text60 TEXT,
+text61 TEXT,
+text62 TEXT,
+text63 TEXT,
+text64 TEXT,
+text65 TEXT,
+text66 TEXT,
+text67 TEXT,
+text68 TEXT,
+text69 TEXT,
+text70 TEXT,
+text71 TEXT,
+text72 TEXT,
+text73 TEXT,
+text74 TEXT,
+text75 TEXT,
+text76 TEXT,
+text77 TEXT,
+text78 TEXT,
+text79 TEXT,
+text80 TEXT,
+text81 TEXT,
+text82 TEXT,
+text83 TEXT,
+text84 TEXT,
+text85 TEXT,
+text86 TEXT,
+text87 TEXT,
+text88 TEXT,
+text89 TEXT,
+text90 TEXT,
+text91 TEXT,
+text92 TEXT,
+text93 TEXT,
+text94 TEXT,
+text95 TEXT,
+text96 TEXT,
+text97 TEXT,
+text98 TEXT,
+text99 TEXT,
+text100 TEXT,
+text101 TEXT,
+text102 TEXT,
+text103 TEXT,
+text104 TEXT,
+text105 TEXT,
+text106 TEXT,
+text107 TEXT,
+text108 TEXT,
+text109 TEXT,
+text110 TEXT,
+text111 TEXT,
+text112 TEXT,
+text113 TEXT,
+text114 TEXT,
+text115 TEXT,
+text116 TEXT,
+text117 TEXT,
+text118 TEXT,
+text119 TEXT,
+text120 TEXT,
+text121 TEXT,
+text122 TEXT,
+text123 TEXT,
+text124 TEXT,
+text125 TEXT,
+text126 TEXT,
+text127 TEXT,
+text128 TEXT,
+text129 TEXT,
+text130 TEXT,
+text131 TEXT,
+text132 TEXT,
+text133 TEXT,
+text134 TEXT,
+text135 TEXT,
+text136 TEXT,
+text137 TEXT,
+text138 TEXT,
+text139 TEXT,
+text140 TEXT,
+text141 TEXT,
+text142 TEXT,
+text143 TEXT,
+text144 TEXT,
+text145 TEXT,
+text146 TEXT,
+text147 TEXT,
+text148 TEXT,
+text149 TEXT,
+text150 TEXT,
+text151 TEXT,
+text152 TEXT,
+text153 TEXT,
+text154 TEXT,
+text155 TEXT,
+text156 TEXT,
+text157 TEXT,
+text158 TEXT,
+text159 TEXT,
+text160 TEXT,
+text161 TEXT,
+text162 TEXT,
+text163 TEXT,
+text164 TEXT,
+text165 TEXT,
+text166 TEXT,
+text167 TEXT,
+text168 TEXT,
+text169 TEXT,
+text170 TEXT,
+text171 TEXT,
+text172 TEXT,
+text173 TEXT,
+text174 TEXT,
+text175 TEXT,
+text176 TEXT,
+text177 TEXT,
+text178 TEXT,
+text179 TEXT,
+text180 TEXT,
+text181 TEXT,
+text182 TEXT,
+text183 TEXT,
+text184 TEXT,
+text185 TEXT,
+text186 TEXT,
+text187 TEXT,
+text188 TEXT,
+text189 TEXT,
+text190 TEXT,
+text191 TEXT,
+text192 TEXT,
+text193 TEXT,
+text194 TEXT,
+text195 TEXT,
+text196 TEXT,
+text197 TEXT
+) ENGINE = InnoDB;
+
+INSERT INTO t1 VALUES ('abcdef', 'abcdef', 'abcdef', 'abcdef', 'abcdef', 'abcdef', 'abcdef', 'abcdef', 'abcdef', 'abcdef', 'abcdef', 'abcdef', 'abcdef', 'abcdef', 'abcdef', 'abcdef', 'abcdef', 'abcdef', 'abcdef', 'abcdef', 'abcdef', 'abcdef', 'abcdef', 'abcdef', 'abcdef', 'abcdef', 'abcdef', 'abcdef', 'abcdef', 'abcdef', 'abcdef', 'abcdef', 'abcdef', 'abcdef', 'abcdef', 'abcdef', 'abcdef', 'abcdef', 'abcdef', 'abcdef', 'abcdef', 'abcdef', 'abcdef', 'abcdef', 'abcdef', 'abcdef', 'abcdef', 'abcdef', 'abcdef', 'abcdef', 'abcdef', 'abcdef', 'abcdef', 'abcdef', 'abcdef', 'abcdef', 'abcdef', 'abcdef', 'abcdef', 'abcdef', 'abcdef', 'abcdef', 'abcdef', 'abcdef', 'abcdef', 'abcdef', 'abcdef', 'abcdef', 'abcdef', 'abcdef', 'abcdef', 'abcdef', 'abcdef', 'abcdef', 'abcdef', 'abcdef', 'abcdef', 'abcdef', 'abcdef', 'abcdef', 'abcdef', 'abcdef', 'abcdef', 'abcdef', 'abcdef', 'abcdef', 'abcdef', 'abcdef', 'abcdef', 'abcdef', 'abcdef', 'abcdef', 'abcdef', 'abcdef', 'abcdef', 'abcdef', 'abcdef', 'abcdef', 'abcdef', 'abcdef', 'abcdef', 'abcdef', 'abcdef', 'abcdef', 'abcdef', 'abcdef', 'abcdef', 'abcdef', 'abcdef', 'abcdef', 'abcdef', 'abcdef', 'abcdef', 'abcdef', 'abcdef', 'abcdef', 'abcdef', 'abcdef', 'abcdef', 'abcdef', 'abcdef', 'abcdef', 'abcdef', 'abcdef', 'abcdef', 'abcdef', 'abcdef', 'abcdef', 'abcdef', 'abcdef', 'abcdef', 'abcdef', 'abcdef', 'abcdef', 'abcdef', 'abcdef', 'abcdef', 'abcdef', 'abcdef', 'abcdef', 'abcdef', 'abcdef', 'abcdef', 'abcdef', 'abcdef', 'abcdef', 'abcdef', 'abcdef', 'abcdef', 'abcdef', 'abcdef', 'abcdef', 'abcdef', 'abcdef', 'abcdef', 'abcdef', 'abcdef', 'abcdef', 'abcdef', 'abcdef', 'abcdef', 'abcdef', 'abcdef', 'abcdef', 'abcdef', 'abcdef', 'abcdef', 'abcdef', 'abcdef', 'abcdef', 'abcdef', 'abcdef', 'abcdef', 'abcdef', 'abcdef', 'abcdef', 'abcdef', 'abcdef', 'abcdef', 'abcdef', 'abcdef', 'abcdef', 'abcdef', 'abcdef', 'abcdef', 'abcdef', 'abcdef', 'abcdef', 'abcdef', 'abcdef', 'abcdef', 'abcdef', 'abcdef', 'abcdef', 'abcdef', 'abcdef', 'abcdef');
+--enable_warnings
+
+DELETE FROM t1 WHERE text1 = 'abcdef';
+
+--source include/restart_mysqld.inc
+
+--disable_warnings
+SELECT * from t1;
+--enable_warnings
+
+DROP TABLE t1;
+
diff --git a/mysql-test/suite/innodb/t/innodb-mdev7046.test b/mysql-test/suite/innodb/t/innodb-mdev7046.test
new file mode 100644
index 00000000..cad348b1
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb-mdev7046.test
@@ -0,0 +1,57 @@
+--source include/have_innodb.inc
+--source include/have_partition.inc
+# Test causes OS error printout
+--source include/not_windows.inc
+--source include/default_charset.inc
+
+--disable_query_log
+--disable_result_log
+--disable_warnings
+
+
+# Ignore OS errors
+call mtr.add_suppression("InnoDB: File ./test/t1");
+call mtr.add_suppression("InnoDB: Error number");
+call mtr.add_suppression("InnoDB: Cannot rename file '.*/test/t1#[Pp]#p1#[Ss][Pp]#p1sp0\\.ibd' to");
+call mtr.add_suppression("InnoDB: Operating system error number .* in a file operation.");
+
+# MDEV-7046: MySQL#74480 - Failing assertion: os_file_status(newpath, &exists, &type)
+# after Operating system error number 36 in a file operation
+
+USE test;
+create table t1(f1 INT,f2 INT,f3 CHAR (10),primary key(f1,f2)) partition by range(f1) subpartition by hash(f2) subpartitions 2 (partition p1 values less than (0),partition p2 values less than (2),partition p3 values less than (2147483647));
+--replace_regex /'.*t2_new.*'/'t2_new'/
+--error 7
+RENAME TABLE t1 TO `t2_new..............................................end`;
+alter table t1 engine=innodb;
+--replace_regex /'.*t2_new.*'/'t2_new'/
+--error 1025
+RENAME TABLE t1 TO `t2_new..............................................end`;
+--replace_regex /'.*t2_new.*'/'t2_new'/
+show warnings;
+drop table t1;
+
+# Starting with MariaDB 10.6, ensure that DDL recovery will have completed.
+SET GLOBAL innodb_max_purge_lag_wait=0;
+drop database test;
+create database test;
+use test;
+
+SET @@session.default_storage_engine=MYISAM;
+--error 0,1,1103
+CREATE TABLE t1(id INT,purchased DATE)PARTITION BY RANGE(YEAR(purchased)) SUBPARTITION BY HASH(TO_DAYS(purchased)) SUBPARTITIONS 2 (PARTITION p0 VALUES LESS THAN MAXVALUE (SUBPARTITION sp0 DATA DIRECTORY='/tmp/not-existing' INDEX DIRECTORY='/tmp/not-existing',SUBPARTITION sp1));
+drop table if exists t1;
+CREATE TABLE t1(id INT,purchased DATE)PARTITION BY RANGE(YEAR(purchased)) SUBPARTITION BY HASH(TO_DAYS(purchased)) SUBPARTITIONS 2 (PARTITION p0 VALUES LESS THAN MAXVALUE (SUBPARTITION sp0,SUBPARTITION sp1));
+ALTER TABLE t1 ENGINE=InnoDB;
+
+drop table t1;
+
+drop database test;
+create database test;
+use test;
+
+--enable_query_log
+--enable_result_log
+--enable_warnings
+
+show create database test;
diff --git a/mysql-test/suite/innodb/t/innodb-on-duplicate-update.test b/mysql-test/suite/innodb/t/innodb-on-duplicate-update.test
new file mode 100644
index 00000000..cc80198d
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb-on-duplicate-update.test
@@ -0,0 +1,63 @@
+--source include/have_innodb.inc
+
+#
+# MDEV-13206: INSERT ON DUPLICATE KEY UPDATE foreign key fail
+#
+set sql_mode='';
+set innodb_strict_mode=0;
+
+CREATE TABLE `v` (
+ `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
+ PRIMARY KEY (`id`)
+) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;
+
+INSERT v values (1);
+
+CREATE TABLE `vp` (
+ `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
+ `v_id` int(10) unsigned NOT NULL,
+ `p_id` int(10) unsigned NOT NULL,
+ `ppp` varchar(255) NOT NULL,
+ PRIMARY KEY (`id`),
+ UNIQUE KEY `IDX_vp_uniq` (`v_id`,`p_id`),
+ KEY `FK_vp_v` (`v_id`),
+ CONSTRAINT `FK_vp_v` FOREIGN KEY (`v_id`) REFERENCES `v` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
+) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;
+
+INSERT vp VALUES (12, 1, 100, 'text12');
+INSERT INTO `vp` (`id`,`ppp`) VALUES (12, 'test12-2') ON DUPLICATE KEY UPDATE `ppp` = VALUES(`ppp`);
+SELECT * FROM vp;
+DROP TABLE vp, v;
+
+CREATE TABLE t1 (i int PRIMARY KEY) ENGINE=InnoDB;
+INSERT into t1 values (1);
+
+CREATE TABLE t2 (
+ i int not null primary key,
+ vi int not null,
+ m int,
+ UNIQUE KEY (vi),
+ CONSTRAINT `cc` FOREIGN KEY (vi) REFERENCES t1 (i) ON DELETE CASCADE ON UPDATE CASCADE
+) ENGINE=InnoDB;
+
+INSERT into t2 VALUES (1, 1, 100);
+INSERT INTO t2 (i,m) VALUES (1, 2) ON DUPLICATE KEY UPDATE m=3;
+SELECT * FROM t2;
+
+DROP TABLE t2,t1;
+
+CREATE TABLE t1 (i int PRIMARY KEY) ENGINE=InnoDB;
+INSERT into t1 values (1);
+
+CREATE TABLE t2 (
+ i int not null primary key,
+ vi int not null,
+ m int,
+ KEY (vi),
+ CONSTRAINT `cc` FOREIGN KEY (vi) REFERENCES t1 (i) ON DELETE CASCADE ON UPDATE CASCADE
+) ENGINE=InnoDB;
+
+INSERT into t2 VALUES (1, 1, 100);
+INSERT INTO t2 (i,m) VALUES (1, 2) ON DUPLICATE KEY UPDATE m=3;
+SELECT * FROM t2;
+DROP TABLE t2, t1;
diff --git a/mysql-test/suite/innodb/t/innodb-online-alter-gis.test b/mysql-test/suite/innodb/t/innodb-online-alter-gis.test
new file mode 100644
index 00000000..df0ab2e8
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb-online-alter-gis.test
@@ -0,0 +1,68 @@
+--source include/have_innodb.inc
+
+create table t1(a int not null primary key, b geometry not null) engine=innodb;
+--error 1846
+ALTER ONLINE TABLE t1 ADD SPATIAL INDEX new(b), ALGORITHM=INSTANT;
+show warnings;
+show errors;
+ALTER ONLINE TABLE t1 ADD SPATIAL INDEX new(b), LOCK=SHARED, ALGORITHM=NOCOPY;
+show warnings;
+show errors;
+drop table t1;
+create table t1(a int not null, b geometry not null, d int,spatial key c(b), key d(d)) engine=innodb;
+show create table t1;
+--error 1846
+ALTER ONLINE TABLE t1 ADD PRIMARY KEY(a),DROP INDEX d;
+show warnings;
+show errors;
+ALTER ONLINE TABLE t1 ADD PRIMARY KEY(a),DROP INDEX d, LOCK=SHARED;
+show warnings;
+show errors;
+drop table t1;
+
+--echo #
+--echo # MDEV-14038 ALTER TABLE does not exit on error with InnoDB + bad default function
+--echo #
+
+CREATE TABLE t1 (a INT) ENGINE=InnoDB;
+--error ER_TRUNCATED_WRONG_VALUE_FOR_FIELD
+ALTER TABLE t1 ADD COLUMN b LINESTRING DEFAULT POINT(1,1);
+DESCRIBE t1;
+DROP TABLE t1;
+
+--echo #
+--echo # Bug #19077964 ASSERT PAGE_SIZE.EQUALS_TO SPACE_PAGE_SIZE
+--echo # BTR_COPY_BLOB_PREFIX
+--echo #
+
+--disable_query_log
+SET @save_innodb_read_only_compressed=@@GLOBAL.innodb_read_only_compressed;
+SET GLOBAL innodb_read_only_compressed=OFF;
+--enable_query_log
+CREATE TABLE t1(f1 INT PRIMARY KEY, f3 LINESTRING NOT NULL,
+ SPATIAL KEY(f3))ENGINE=InnoDB ROW_FORMAT=COMPRESSED
+ KEY_BLOCK_SIZE=1;
+SHOW CREATE TABLE t1;
+
+let $points = 80;
+let $x = 0;
+let $y = 0;
+let $linestr = (;
+
+while ($points)
+{
+ let $linestr = $linestr $x $y,;
+ dec $points;
+ inc $x;
+ inc $y;
+}
+
+let $linestr = $linestr 9999 9999);
+
+--eval INSERT INTO t1 VALUES (1, ST_linefromtext(concat('linestring', '$linestr')));
+
+ALTER TABLE t1 ROW_FORMAT = DYNAMIC, KEY_BLOCK_SIZE=0, ALGORITHM=INPLACE;
+--disable_query_log
+SET GLOBAL innodb_read_only_compressed=@save_innodb_read_only_compressed;
+--enable_query_log
+DROP TABLE t1;
diff --git a/mysql-test/suite/innodb/t/innodb-page_compression_none.test b/mysql-test/suite/innodb/t/innodb-page_compression_none.test
new file mode 100644
index 00000000..e4eaae8b
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb-page_compression_none.test
@@ -0,0 +1,26 @@
+-- source include/innodb_checksum_algorithm.inc
+
+--echo #
+--echo # MDEV-30825 innodb_compression_algorithm=0 (none) increments Innodb_num_pages_page_compression_error
+--echo #
+
+SET @save_compression_algorithm=@@GLOBAL.innodb_compression_algorithm;
+SET GLOBAL innodb_compression_algorithm=0;
+SELECT VARIABLE_VALUE INTO @compress_errors FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'Innodb_num_pages_page_compression_error';
+
+
+CREATE TABLE t (c INT) page_compressed=1 page_compression_level=4 ENGINE=InnoDB;
+INSERT INTO t VALUES (1);
+
+FLUSH TABLES t FOR EXPORT;
+UNLOCK TABLES;
+
+SELECT VARIABLE_VALUE - @compress_errors AS NUMBER_OF_ERRORS FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'Innodb_num_pages_page_compression_error';
+
+DROP TABLE t;
+SET GLOBAL innodb_compression_algorithm=@save_compression_algorithm;
+
+--echo #
+--echo # End of 10.4 tests
+--echo #
+
diff --git a/mysql-test/suite/innodb/t/innodb-read-view.test b/mysql-test/suite/innodb/t/innodb-read-view.test
new file mode 100644
index 00000000..425cbeb0
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb-read-view.test
@@ -0,0 +1,208 @@
+# DEBUG_SYNC must be compiled in.
+--source include/have_debug_sync.inc
+--source include/have_debug.inc
+
+# We need to test the use case:
+# a. Create a transaction T1 that will be promoted to RW.
+# b. Create a transaction T2 that will be promoted to RW.
+# a. Create a RO transaction T3
+# d. T3 does a select - creates a read view that doesn't include T1 and T2
+# e. T1 & T2 do some updates - this promotes T1 & T2 to RW transactions
+# f. T1 & T2 Commit
+# g. T3 Does a select - it should not see the changes of T1 & T2
+
+--source include/have_innodb.inc
+--source include/count_sessions.inc
+
+CREATE TABLE t1 (c1 INT , c2 CHAR(10), PRIMARY KEY (c1)) ENGINE = InnoDB;
+INSERT INTO t1 VALUES(0, "0");
+INSERT INTO t1 VALUES(1, "1");
+INSERT INTO t1 VALUES(2, "2");
+INSERT INTO t1 VALUES(3, "3");
+
+CREATE TABLE t2 (c1 INT , c2 CHAR(10), PRIMARY KEY (c1)) ENGINE = InnoDB;
+INSERT INTO t2 VALUES(0, "a");
+INSERT INTO t2 VALUES(1, "b");
+INSERT INTO t2 VALUES(2, "c");
+INSERT INTO t2 VALUES(3, "d");
+
+--connect (con1,localhost,root,,)
+--connect (con2,localhost,root,,)
+
+connection con1;
+--echo 'T1'
+SET AUTOCOMMIT=0;
+BEGIN;
+SELECT * FROM t2;
+
+connection default;
+--echo 'T2'
+SET AUTOCOMMIT=0;
+BEGIN;
+SELECT * FROM t1;
+
+connection con2;
+--echo 'T3'
+SET AUTOCOMMIT=0;
+SET SESSION TRANSACTION ISOLATION LEVEL REPEATABLE READ;
+BEGIN;
+SELECT * FROM t1;
+SELECT * FROM t2;
+
+connection con1;
+--echo 'T1'
+UPDATE t2 SET c1 = c1 + 100;
+SELECT * FROM t2;
+COMMIT;
+
+connection default;
+--echo 'T2'
+UPDATE t1 SET c1 = c1 + 100;
+SELECT * FROM t1;
+COMMIT;
+
+connection con2;
+--echo 'T3'
+SET DEBUG_SYNC='row_search_for_mysql_before_return WAIT_FOR waiting1';
+--send SELECT * FROM t1;
+
+connection default;
+--echo 'T2'
+SET DEBUG_SYNC='now SIGNAL waiting1';
+--echo 'Signalled T3'
+
+connection con2;
+--echo 'T3'
+reap;
+
+connection con2;
+--echo 'T3'
+SET DEBUG_SYNC='row_search_for_mysql_before_return WAIT_FOR waiting1';
+--send SELECT * FROM t2;
+
+connection default;
+--echo 'T2'
+SET DEBUG_SYNC='now SIGNAL waiting1';
+--echo 'Signalled T3'
+
+connection con2;
+--echo 'T3'
+reap;
+
+connection default;
+disconnect con1;
+disconnect con2;
+
+# We need to test the use case:
+# a. Create a transaction T1 that will be promoted to RW.
+# b. Create a transaction T2 that will be promoted to RW.
+# c. T2 does some updates - this promotes T2 to RW transactions
+# d. T2 Commits
+# e. Create a RO transaction T3
+# f. T3 does a select - creates a read view that doesn't include T1
+# g. T1 does some updates - this promotes T1 to RW transactions
+# h. T1 Commits
+# i. T3 Does a select - it should not see the changes made by T1 but should
+# see the changes by T2
+
+--connect (con1,localhost,root,,)
+--connect (con2,localhost,root,,)
+
+connection con1;
+--echo 'T1'
+SET AUTOCOMMIT=0;
+BEGIN;
+SELECT * FROM t1;
+
+connection default;
+--echo 'T2'
+SET AUTOCOMMIT=0;
+BEGIN;
+SELECT * FROM t2;
+UPDATE t2 SET c1 = c1 + 100;
+SELECT * FROM t2;
+COMMIT;
+
+connection con2;
+--echo 'T3'
+SET AUTOCOMMIT=0;
+SET SESSION TRANSACTION ISOLATION LEVEL REPEATABLE READ;
+BEGIN;
+SELECT * FROM t1;
+SELECT * FROM t2;
+
+connection con1;
+--echo 'T1'
+UPDATE t1 SET c1 = c1 + 100;
+SELECT * FROM t1;
+COMMIT;
+
+connection con2;
+--echo 'T3'
+SET DEBUG_SYNC='row_select_wait WAIT_FOR waiting1';
+--send SELECT * FROM t1;
+
+connection con1;
+--echo 'T2'
+SET DEBUG_SYNC='now SIGNAL waiting1';
+--echo 'Signalled T3'
+
+connection con2;
+--echo 'T3'
+reap;
+
+connection con2;
+--echo 'T3'
+SET DEBUG_SYNC='row_select_wait WAIT_FOR waiting1';
+--send SELECT * FROM t2;
+
+connection default;
+--echo 'T2'
+SET DEBUG_SYNC='now SIGNAL waiting1';
+--echo 'Signalled T3'
+
+connection con2;
+--echo 'T3'
+reap;
+
+connection default;
+disconnect con1;
+disconnect con2;
+
+DROP TABLE t1;
+DROP TABLE t2;
+
+--echo #
+--echo # Bug 21433768: NON-REPEATABLE READ WITH REPEATABLE READ ISOLATION
+--echo #
+
+--connect (con1,localhost,root,,)
+
+CREATE TABLE t1(col1 INT PRIMARY KEY, col2 INT) ENGINE = InnoDB;
+INSERT INTO t1 values (1, 0), (2, 0);
+SELECT * FROM t1 ORDER BY col1;
+
+START TRANSACTION;
+UPDATE t1 SET col2 = 100;
+SET DEBUG_SYNC = 'after_trx_committed_in_memory SIGNAL s1 WAIT_FOR s2';
+--send COMMIT;
+
+connection default;
+SET DEBUG_SYNC = 'now WAIT_FOR s1';
+UPDATE t1 SET col2 = col2 + 10 where col1 = 1;
+COMMIT;
+
+SELECT * FROM t1 ORDER BY col1;
+SET DEBUG_SYNC = 'now SIGNAL s2';
+
+connection con1;
+reap;
+disconnect con1;
+
+connection default;
+
+DROP TABLE t1;
+
+# Clean up resources used in this test case.
+SET DEBUG_SYNC= 'RESET';
+--source include/wait_until_count_sessions.inc
diff --git a/mysql-test/suite/innodb/t/innodb-replace-debug.test b/mysql-test/suite/innodb/t/innodb-replace-debug.test
new file mode 100644
index 00000000..823712a0
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb-replace-debug.test
@@ -0,0 +1,16 @@
+--source include/have_innodb.inc
+--source include/have_debug.inc
+
+--echo #
+--echo # Bug#17604730 ASSERTION: *CURSOR->INDEX->NAME == TEMP_INDEX_PREFIX
+--echo #
+
+create table t1 (f1 int primary key, f2 int, f3 int, unique key k1(f2),
+ key k2(f3)) engine=innodb;
+insert into t1 values (14, 24, 34);
+set @old_dbug= @@session.debug_dbug;
+SET debug_dbug = '+d,row_ins_sec_index_entry_timeout';
+replace into t1 values (14, 25, 34);
+select * from t1;
+drop table t1;
+SET debug_dbug = @old_dbug;
diff --git a/mysql-test/suite/innodb/t/innodb-replace.test b/mysql-test/suite/innodb/t/innodb-replace.test
new file mode 100644
index 00000000..8c3aacde
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb-replace.test
@@ -0,0 +1,22 @@
+-- source include/have_innodb.inc
+# embedded server ignores 'delayed', so skip this
+-- source include/not_embedded.inc
+
+--disable_warnings
+drop table if exists t1;
+--enable_warnings
+
+#
+# Bug #1078
+#
+create table t1 (c1 char(5) unique not null, c2 int, stamp timestamp) engine=innodb;
+select * from t1;
+--error ER_DELAYED_NOT_SUPPORTED
+replace delayed into t1 (c1, c2) values ( "text1","11");
+select * from t1;
+--error ER_DELAYED_NOT_SUPPORTED
+replace delayed into t1 (c1, c2) values ( "text1","12");
+select * from t1;
+drop table t1;
+
+# End of 4.1 tests
diff --git a/mysql-test/suite/innodb/t/innodb-rollback.test b/mysql-test/suite/innodb/t/innodb-rollback.test
new file mode 100644
index 00000000..1d3e05b0
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb-rollback.test
@@ -0,0 +1,17 @@
+--source include/have_innodb.inc
+
+#
+# MDEV-18632: wsrep_is_wsrep_xid: Conditional jump or move depends on uninitialised value
+#
+CREATE TABLE t1 (a INT) ENGINE=InnoDB;
+--connect (con1,localhost,root,,test)
+ALTER TABLE t1;
+--connect (con2,localhost,root,,test)
+--error ER_SP_DOES_NOT_EXIST
+SELECT f() FROM t1;
+
+# Cleanup
+--disconnect con2
+--disconnect con1
+--connection default
+DROP TABLE t1;
diff --git a/mysql-test/suite/innodb/t/innodb-semi-consistent-master.opt b/mysql-test/suite/innodb/t/innodb-semi-consistent-master.opt
new file mode 100644
index 00000000..cb48f1aa
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb-semi-consistent-master.opt
@@ -0,0 +1 @@
+--loose-innodb_lock_wait_timeout=2
diff --git a/mysql-test/suite/innodb/t/innodb-semi-consistent.test b/mysql-test/suite/innodb/t/innodb-semi-consistent.test
new file mode 100644
index 00000000..2551db99
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb-semi-consistent.test
@@ -0,0 +1,69 @@
+-- source include/not_embedded.inc
+-- source include/have_innodb.inc
+
+--disable_warnings
+drop table if exists t1,t2;
+--enable_warnings
+
+# basic tests of semi-consistent reads
+
+connect (a,localhost,root,,);
+connect (b,localhost,root,,);
+connection a;
+set binlog_format=mixed;
+set session transaction isolation level repeatable read;
+create table t1(a int not null) engine=innodb DEFAULT CHARSET=latin1;
+insert into t1 values (1),(2),(3),(4),(5),(6),(7);
+set autocommit=0;
+# this should lock the entire table
+select * from t1 where a=3 lock in share mode;
+connection b;
+set binlog_format=mixed;
+set session transaction isolation level repeatable read;
+set autocommit=0;
+-- error ER_LOCK_WAIT_TIMEOUT
+update t1 set a=10 where a=5;
+commit;
+connection a;
+commit;
+connection b;
+# perform a semi-consisent read (and unlock non-matching rows)
+set session transaction isolation level read committed;
+update t1 set a=10 where a=5;
+connection a;
+-- error ER_LOCK_WAIT_TIMEOUT
+select * from t1 where a=2 for update;
+# this should lock the records (1),(2)
+select * from t1 where a=2 limit 1 for update;
+connection b;
+# semi-consistent read will skip non-matching locked rows a=1, a=2
+update t1 set a=11 where a=6;
+-- error ER_LOCK_WAIT_TIMEOUT
+update t1 set a=12 where a=2;
+-- error ER_LOCK_WAIT_TIMEOUT
+update t1 set a=13 where a=1;
+connection a;
+commit;
+connection b;
+update t1 set a=14 where a=1;
+commit;
+connection a;
+select * from t1;
+drop table t1;
+
+connection default;
+disconnect a;
+disconnect b;
+
+# Bug 39320
+create table t1 (a int, b int) engine=myisam;
+create table t2 (c int, d int, key (c)) engine=innodb;
+insert into t1 values (1,1);
+insert into t2 values (1,2);
+connect (a,localhost,root,,);
+connection a;
+set session transaction isolation level read committed;
+delete from t1 using t1 join t2 on t1.a = t2.c where t2.d in (1);
+connection default;
+disconnect a;
+drop table t1, t2;
diff --git a/mysql-test/suite/innodb/t/innodb-stats-initialize-failure.test b/mysql-test/suite/innodb/t/innodb-stats-initialize-failure.test
new file mode 100644
index 00000000..ba37e820
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb-stats-initialize-failure.test
@@ -0,0 +1,41 @@
+# MDEV-6424: Mariadb server crashes with assertion failure in file ha_innodb.cc
+--source include/have_innodb.inc
+--source include/no_valgrind_without_big.inc
+
+# DEBUG_SYNC must be compiled in.
+--source include/have_debug_sync.inc
+
+call mtr.add_suppression("InnoDB: Warning: Index.*");
+# This caused crash earlier
+SET @saved_dbug = @@SESSION.debug_dbug;
+set DEBUG_DBUG='+d,ib_ha_innodb_stat_not_initialized';
+create table t1(a int not null primary key, b int, c int, key(b), key(c)) engine=innodb;
+
+delimiter //;
+create procedure innodb_insert_proc (repeat_count int)
+begin
+ declare current_num int;
+ set current_num = 0;
+ while current_num < repeat_count do
+ insert into t1 values(current_num, current_num, current_num);
+ set current_num = current_num + 1;
+ end while;
+end//
+delimiter ;//
+commit;
+
+set autocommit=0;
+call innodb_insert_proc(10000);
+commit;
+set autocommit=1;
+
+select count(1) from t1;
+select count(1) from t1 where a between 5 and 100;
+select count(1) from t1 where b between 5 and 256;
+select count(1) from t1 where c between 7 and 787;
+
+
+
+drop procedure innodb_insert_proc;
+drop table t1;
+SET debug_dbug= @saved_dbug;
diff --git a/mysql-test/suite/innodb/t/innodb-stats-modified-counter.opt b/mysql-test/suite/innodb/t/innodb-stats-modified-counter.opt
new file mode 100644
index 00000000..1cfd8e71
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb-stats-modified-counter.opt
@@ -0,0 +1 @@
+--loose-innodb-sys-tablestats --skip-innodb-stats-persistent
diff --git a/mysql-test/suite/innodb/t/innodb-stats-modified-counter.test b/mysql-test/suite/innodb/t/innodb-stats-modified-counter.test
new file mode 100644
index 00000000..b3e45002
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb-stats-modified-counter.test
@@ -0,0 +1,28 @@
+-- source include/have_innodb.inc
+
+#
+# MDEV-8297: information_schema.innodb_sys_tablestats.modified_counter doesn't change on UPDATE
+#
+
+set global innodb_stats_auto_recalc=off;
+
+CREATE TABLE t1 (i int) ENGINE=InnoDB;
+
+SELECT NAME, STATS_INITIALIZED, NUM_ROWS, MODIFIED_COUNTER FROM INFORMATION_SCHEMA.INNODB_SYS_TABLESTATS WHERE NAME = 'test/t1';
+
+INSERT INTO t1 VALUES (1);
+INSERT INTO t1 VALUES (2);
+
+SELECT NAME, STATS_INITIALIZED, NUM_ROWS, MODIFIED_COUNTER FROM INFORMATION_SCHEMA.INNODB_SYS_TABLESTATS WHERE NAME = 'test/t1';
+
+DELETE FROM t1 WHERE i = 1;
+
+SELECT NAME, STATS_INITIALIZED, NUM_ROWS, MODIFIED_COUNTER FROM INFORMATION_SCHEMA.INNODB_SYS_TABLESTATS WHERE NAME = 'test/t1';
+
+UPDATE t1 SET i = 4 WHERE i = 2;
+
+SELECT NAME, STATS_INITIALIZED, NUM_ROWS, MODIFIED_COUNTER FROM INFORMATION_SCHEMA.INNODB_SYS_TABLESTATS WHERE NAME = 'test/t1';
+
+DROP TABLE t1;
+
+set global innodb_stats_auto_recalc=default;
diff --git a/mysql-test/suite/innodb/t/innodb-stats-sample.test b/mysql-test/suite/innodb/t/innodb-stats-sample.test
new file mode 100644
index 00000000..34ca4c7b
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb-stats-sample.test
@@ -0,0 +1,75 @@
+--source include/have_innodb.inc
+--source include/no_valgrind_without_big.inc
+#
+# Test that mysqld does not crash when running ANALYZE TABLE with
+# different values of the parameter innodb_stats_transient_sample_pages.
+#
+
+# we care only that the following SQL commands do not produce errors
+# and do not crash the server
+-- disable_query_log
+-- enable_warnings
+
+SET @save_sample_pages = @@GLOBAL.innodb_stats_transient_sample_pages;
+SET @save_traditional = @@GLOBAL.innodb_stats_traditional;
+SET GLOBAL innodb_stats_transient_sample_pages=0;
+#use new method to calculate statistics
+SET GLOBAL innodb_stats_traditional=0;
+SHOW VARIABLES LIKE 'innodb_stats_transient_sample_pages';
+SHOW VARIABLES LIKE 'innodb_stats_traditional';
+-- disable_result_log
+
+CREATE TABLE innodb_analyze (
+ a INT,
+ b INT,
+ c char(50),
+ KEY(a),
+ KEY(b,a)
+) ENGINE=InnoDB;
+
+# test with empty table
+ANALYZE TABLE innodb_analyze;
+
+SET GLOBAL innodb_stats_transient_sample_pages=2;
+ANALYZE TABLE innodb_analyze;
+
+SET GLOBAL innodb_stats_transient_sample_pages=1;
+ANALYZE TABLE innodb_analyze;
+
+SET GLOBAL innodb_stats_transient_sample_pages=8000;
+ANALYZE TABLE innodb_analyze;
+
+delimiter //;
+create procedure innodb_insert_proc (repeat_count int)
+begin
+ declare current_num int;
+ set current_num = 0;
+ while current_num < repeat_count do
+ insert into innodb_analyze values(current_num, current_num*100,substring(MD5(RAND()), -44));
+ set current_num = current_num + 1;
+ end while;
+end//
+delimiter ;//
+commit;
+
+set autocommit=0;
+call innodb_insert_proc(7000);
+commit;
+set autocommit=1;
+
+SET GLOBAL innodb_stats_transient_sample_pages=1;
+ANALYZE TABLE innodb_analyze;
+
+SET GLOBAL innodb_stats_transient_sample_pages=8;
+ANALYZE TABLE innodb_analyze;
+
+SET GLOBAL innodb_stats_transient_sample_pages=16;
+ANALYZE TABLE innodb_analyze;
+
+SET GLOBAL innodb_stats_transient_sample_pages=8000;
+ANALYZE TABLE innodb_analyze;
+
+DROP PROCEDURE innodb_insert_proc;
+DROP TABLE innodb_analyze;
+SET GLOBAL innodb_stats_transient_sample_pages = @save_sample_pages;
+SET GLOBAL innodb_stats_traditional = @save_traditional;
diff --git a/mysql-test/suite/innodb/t/innodb-system-table-view.opt b/mysql-test/suite/innodb/t/innodb-system-table-view.opt
new file mode 100644
index 00000000..6bf2c4c9
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb-system-table-view.opt
@@ -0,0 +1,11 @@
+--innodb
+--innodb-sys-tablespaces
+--innodb-sys-tablestats
+--innodb-sys-tables
+--innodb-sys-columns
+--innodb-sys-indexes
+--innodb-sys-fields
+--innodb-sys-foreign
+--innodb-sys-foreign-cols
+--character_set_server="latin1"
+--collation_server="latin1_swedish_ci"
diff --git a/mysql-test/suite/innodb/t/innodb-system-table-view.test b/mysql-test/suite/innodb/t/innodb-system-table-view.test
new file mode 100644
index 00000000..659c42f0
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb-system-table-view.test
@@ -0,0 +1,146 @@
+# This is the test for Information Schema System Table View
+# that displays the InnoDB system table content through
+# information schema tables.
+
+--source include/innodb_page_size_small.inc
+
+LET $MYSQLD_DATADIR = `select @@datadir`;
+LET $INNODB_PAGE_SIZE = `select @@innodb_page_size`;
+
+# The IDs of mysql.innodb_table_stats and mysql.innodb_index_stats may
+# vary depending on whether the tables have been rebuilt
+# by previously run tests.
+SELECT table_id INTO @table_stats_id FROM information_schema.innodb_sys_tables
+WHERE name = 'mysql/innodb_table_stats';
+SELECT table_id INTO @index_stats_id FROM information_schema.innodb_sys_tables
+WHERE name = 'mysql/innodb_index_stats';
+
+SELECT * FROM INFORMATION_SCHEMA.INNODB_SYS_TABLES
+WHERE table_id NOT IN (@table_stats_id, @index_stats_id) ORDER BY table_id;
+
+SELECT table_id,pos,mtype,prtype,len,name
+FROM INFORMATION_SCHEMA.INNODB_SYS_COLUMNS
+WHERE table_id NOT IN (@table_stats_id, @index_stats_id)
+ORDER BY table_id, pos;
+
+--replace_column 1 # 3 # 6 # 7 #
+SELECT * FROM INFORMATION_SCHEMA.INNODB_SYS_INDEXES
+WHERE table_id NOT IN (@table_stats_id, @index_stats_id) ORDER BY index_id;
+
+SELECT index_id,pos,name FROM INFORMATION_SCHEMA.INNODB_SYS_FIELDS
+WHERE name NOT IN ('database_name', 'table_name', 'index_name', 'stat_name')
+ORDER BY index_id, pos;
+
+--sorted_result
+SELECT * FROM INFORMATION_SCHEMA.INNODB_SYS_FOREIGN;
+--sorted_result
+SELECT * FROM INFORMATION_SCHEMA.INNODB_SYS_FOREIGN_COLS;
+
+CREATE TABLE t_redundant (a INT KEY, b TEXT) ROW_FORMAT=REDUNDANT ENGINE=innodb;
+CREATE TABLE t_compact (a INT KEY, b TEXT) ROW_FORMAT=COMPACT ENGINE=innodb;
+CREATE TABLE t_compressed (a INT KEY, b TEXT) ROW_FORMAT=COMPRESSED ENGINE=innodb KEY_BLOCK_SIZE=2;
+CREATE TABLE t_dynamic (a INT KEY, b TEXT) ROW_FORMAT=DYNAMIC ENGINE=innodb;
+
+--source suite/innodb/include/show_i_s_tables.inc
+--source suite/innodb/include/show_i_s_tablespaces.inc
+
+DROP TABLE t_redundant, t_compact, t_compressed, t_dynamic;
+
+SELECT count(*) FROM INFORMATION_SCHEMA.INNODB_SYS_TABLESTATS;
+
+# Create a foreign key constraint, and verify the information
+# in INFORMATION_SCHEMA.INNODB_SYS_FOREIGN and
+# INFORMATION_SCHEMA.INNODB_SYS_FOREIGN_COLS
+CREATE TABLE parent (id INT NOT NULL,
+ PRIMARY KEY (id)) ENGINE=INNODB;
+
+CREATE TABLE child (id INT, parent_id INT,
+ INDEX par_ind (parent_id),
+ CONSTRAINT constraint_test
+ FOREIGN KEY (parent_id) REFERENCES parent(id)
+ ON DELETE CASCADE) ENGINE=INNODB;
+
+--sorted_result
+SELECT * FROM INFORMATION_SCHEMA.INNODB_SYS_FOREIGN;
+
+--sorted_result
+SELECT * FROM INFORMATION_SCHEMA.INNODB_SYS_FOREIGN_COLS;
+
+# Insert a row in the table "parent", and see whether that reflected in
+# INNODB_SYS_TABLESTATS
+INSERT INTO parent VALUES(1);
+
+--source include/wait_all_purged.inc
+
+--sorted_result
+SELECT name, num_rows, ref_count
+FROM INFORMATION_SCHEMA.INNODB_SYS_TABLESTATS
+WHERE name LIKE "%parent";
+
+--sorted_result
+SELECT NAME, FLAG, N_COLS FROM INFORMATION_SCHEMA.INNODB_SYS_TABLES
+ WHERE name NOT LIKE 'sys/%';
+
+--sorted_result
+SELECT name, n_fields
+from INFORMATION_SCHEMA.INNODB_SYS_INDEXES
+WHERE table_id In (SELECT table_id from
+ INFORMATION_SCHEMA.INNODB_SYS_TABLES
+ WHERE name LIKE "%parent%");
+
+--sorted_result
+SELECT name, n_fields
+from INFORMATION_SCHEMA.INNODB_SYS_INDEXES
+WHERE table_id In (SELECT table_id from
+ INFORMATION_SCHEMA.INNODB_SYS_TABLES
+ WHERE name LIKE "%child%");
+
+--sorted_result
+SELECT name, pos, mtype, len
+from INFORMATION_SCHEMA.INNODB_SYS_COLUMNS
+WHERE table_id In (SELECT table_id from
+ INFORMATION_SCHEMA.INNODB_SYS_TABLES
+ WHERE name LIKE "%child%");
+
+DROP TABLE child;
+
+DROP TABLE parent;
+
+# Create table with 2 columns in the foreign key constraint
+CREATE TABLE parent (id INT NOT NULL, newid INT NOT NULL,
+ PRIMARY KEY (id, newid)) ENGINE=INNODB;
+
+CREATE TABLE child (id INT, parent_id INT,
+ INDEX par_ind (parent_id),
+ CONSTRAINT constraint_test
+ FOREIGN KEY (id, parent_id) REFERENCES parent(id, newid)
+ ON DELETE CASCADE) ENGINE=INNODB;
+
+--sorted_result
+SELECT * FROM INFORMATION_SCHEMA.INNODB_SYS_FOREIGN;
+
+--sorted_result
+SELECT * FROM INFORMATION_SCHEMA.INNODB_SYS_FOREIGN_COLS;
+
+INSERT INTO parent VALUES(1, 9);
+
+# Nested query will open the table handle twice
+--sorted_result
+SELECT * FROM parent WHERE id IN (SELECT id FROM parent);
+
+--source include/wait_all_purged.inc
+
+--sorted_result
+SELECT name, num_rows, ref_count
+FROM INFORMATION_SCHEMA.INNODB_SYS_TABLESTATS
+WHERE name LIKE "%parent";
+
+DROP TABLE child;
+
+DROP TABLE parent;
+
+--echo #
+--echo # MDEV-29479 I_S.INNODB_SYS_TABLESPACES doesn't have
+--echo # temporary tablespace information
+--echo #
+SELECT SPACE FROM INFORMATION_SCHEMA.INNODB_SYS_TABLESPACES WHERE name like 'innodb_temporary';
diff --git a/mysql-test/suite/innodb/t/innodb-table-online-master.opt b/mysql-test/suite/innodb/t/innodb-table-online-master.opt
new file mode 100644
index 00000000..1eafb5ac
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb-table-online-master.opt
@@ -0,0 +1 @@
+--innodb-sort-buffer-size=64k --innodb-online-alter-log-max-size=512k --innodb-buffer-pool-size=5M
diff --git a/mysql-test/suite/innodb/t/innodb-table-online.test b/mysql-test/suite/innodb/t/innodb-table-online.test
new file mode 100644
index 00000000..ec4f4ef1
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb-table-online.test
@@ -0,0 +1,482 @@
+--source include/innodb_page_size_small.inc
+--source include/innodb_encrypt_log.inc
+--source include/have_debug.inc
+--source include/have_debug_sync.inc
+--source include/have_sequence.inc
+
+let $innodb_metrics_select=
+SELECT name, count FROM INFORMATION_SCHEMA.INNODB_METRICS WHERE subsystem = 'ddl';
+
+call mtr.add_suppression("InnoDB: Warning: Small buffer pool size");
+# these will be triggered by DISCARD TABLESPACE
+call mtr.add_suppression("InnoDB: Error: table 'test/t1'");
+call mtr.add_suppression("MariaDB is trying to open a table handle but the .ibd file for");
+
+# DISCARD TABLESPACE needs file-per-table
+SET @global_innodb_file_per_table_orig = @@global.innodb_file_per_table;
+SET GLOBAL innodb_file_per_table = on;
+
+# Save the initial number of concurrent sessions.
+--source include/count_sessions.inc
+
+CREATE TABLE t1 (c1 INT PRIMARY KEY, c2 INT NOT NULL, c3 CHAR(255) NOT NULL)
+ENGINE = InnoDB;
+INSERT INTO t1 VALUES (1,1,''), (2,2,''), (3,3,''), (4,4,''), (5,5,'');
+
+SET GLOBAL innodb_monitor_enable = module_ddl;
+eval $innodb_metrics_select;
+
+SET DEBUG_SYNC = 'RESET';
+SET DEBUG_SYNC = 'write_row_noreplace SIGNAL have_handle WAIT_FOR go_ahead';
+--send
+INSERT INTO t1 VALUES(1,2,3);
+
+connect (con1,localhost,root,,);
+
+# This should block at the end because of the INSERT in connection default
+# is holding a metadata lock.
+SET DEBUG_SYNC = 'now WAIT_FOR have_handle';
+SET lock_wait_timeout = 1;
+--error ER_LOCK_WAIT_TIMEOUT
+ALTER TABLE t1 ROW_FORMAT=REDUNDANT;
+SET DEBUG_SYNC = 'now SIGNAL go_ahead';
+
+connection default;
+--error ER_DUP_ENTRY
+reap;
+eval $innodb_metrics_select;
+
+connection con1;
+SET @saved_debug_dbug = @@SESSION.debug_dbug;
+SET DEBUG_DBUG = '+d,innodb_OOM_prepare_inplace_alter';
+--error ER_OUT_OF_RESOURCES
+ALTER TABLE t1 ROW_FORMAT=REDUNDANT, ALGORITHM=INPLACE, LOCK=NONE;
+SET SESSION DEBUG = @saved_debug_dbug;
+SET SESSION DEBUG = '+d,innodb_OOM_inplace_alter';
+--error ER_OUT_OF_RESOURCES
+ALTER TABLE t1 ROW_FORMAT=REDUNDANT, ALGORITHM=INPLACE, LOCK=NONE;
+SET SESSION DEBUG = @saved_debug_dbug;
+ALTER TABLE t1 ROW_FORMAT=REDUNDANT, ALGORITHM=INPLACE, LOCK=NONE;
+
+connection default;
+SHOW CREATE TABLE t1;
+# Insert a duplicate entry (4) for the upcoming UNIQUE INDEX(c2).
+BEGIN;
+INSERT INTO t1 VALUES(7,4,2);
+
+connection con1;
+# This DEBUG_SYNC should not kick in yet, because the duplicate key will be
+# detected before we get a chance to apply the online log.
+SET DEBUG_SYNC = 'row_log_table_apply1_before SIGNAL scanned WAIT_FOR insert_done';
+# This will be a lock wait timeout on the meta-data lock,
+# because the transaction inserting (7,4,2) is still active.
+--error ER_LOCK_WAIT_TIMEOUT
+ALTER TABLE t1 DROP PRIMARY KEY, ADD UNIQUE INDEX(c2);
+
+connection default;
+COMMIT;
+
+connection con1;
+--error ER_DUP_ENTRY
+ALTER TABLE t1 DROP PRIMARY KEY, ADD UNIQUE INDEX(c2);
+
+connection default;
+DELETE FROM t1 WHERE c1 = 7;
+
+connection con1;
+ALTER TABLE t1 DROP PRIMARY KEY, ADD UNIQUE INDEX(c2), ROW_FORMAT=COMPACT,
+LOCK = SHARED, ALGORITHM = INPLACE;
+
+# The previous DEBUG_SYNC should be ignored, because an exclusive lock
+# has been requested and the online log is not being allocated.
+ALTER TABLE t1 ADD UNIQUE INDEX(c2),
+LOCK = EXCLUSIVE, ALGORITHM = INPLACE;
+
+SHOW CREATE TABLE t1;
+# Now the previous DEBUG_SYNC should kick in.
+--send
+ALTER TABLE t1 DROP INDEX c2, ADD PRIMARY KEY(c1);
+
+connection default;
+SET DEBUG_SYNC = 'now WAIT_FOR scanned';
+eval $innodb_metrics_select;
+
+# Insert a duplicate entry (4) for the already started UNIQUE INDEX(c1).
+INSERT INTO t1 VALUES(4,7,2);
+SET DEBUG_SYNC = 'now SIGNAL insert_done';
+
+connection con1;
+# Because the modification log will be applied in order and we did
+# not roll back before the log apply, there will be a duplicate key
+# error on the (4,7,2).
+--error ER_DUP_ENTRY
+reap;
+DELETE FROM t1 WHERE c1=4 and c2=7;
+connection default;
+ROLLBACK;
+
+connection con1;
+SHOW CREATE TABLE t1;
+# Now, rebuild the table without any concurrent DML, while no duplicate exists.
+--error ER_CANT_DROP_FIELD_OR_KEY
+ALTER TABLE t1 DROP PRIMARY KEY, ADD UNIQUE INDEX(c2), ALGORITHM = INPLACE;
+ALTER TABLE t1 DROP INDEX c2, ADD PRIMARY KEY(c1), ALGORITHM = INPLACE;
+eval $innodb_metrics_select;
+
+connection default;
+--error ER_DUP_ENTRY
+INSERT INTO t1 VALUES(6,3,1);
+--error ER_DUP_ENTRY
+INSERT INTO t1 VALUES(7,4,2);
+DROP INDEX c2_2 ON t1;
+BEGIN;
+INSERT INTO t1 VALUES(7,4,2);
+ROLLBACK;
+
+connection con1;
+let $ID= `SELECT @id := CONNECTION_ID()`;
+--error ER_QUERY_INTERRUPTED
+KILL QUERY @id;
+
+SET DEBUG_SYNC = 'row_log_table_apply1_before SIGNAL rebuilt WAIT_FOR dml_done';
+SET DEBUG_SYNC = 'row_log_table_apply2_before SIGNAL applied WAIT_FOR kill_done';
+--send
+ALTER TABLE t1 ROW_FORMAT=REDUNDANT;
+
+connection default;
+SET DEBUG_SYNC = 'now WAIT_FOR rebuilt';
+eval $innodb_metrics_select;
+BEGIN;
+INSERT INTO t1 VALUES(7,4,2);
+ROLLBACK;
+SET DEBUG_SYNC = 'now SIGNAL dml_done WAIT_FOR applied';
+let $ignore= `SELECT @id := $ID`;
+KILL QUERY @id;
+SET DEBUG_SYNC = 'now SIGNAL kill_done';
+
+connection con1;
+--error ER_QUERY_INTERRUPTED
+reap;
+eval $innodb_metrics_select;
+
+connection default;
+CHECK TABLE t1;
+INSERT INTO t1 SELECT 5 + c1, c2, c3 FROM t1;
+INSERT INTO t1 SELECT 10 + c1, c2, c3 FROM t1;
+INSERT INTO t1 SELECT 20 + c1, c2, c3 FROM t1;
+INSERT INTO t1 SELECT 40 + c1, c2, c3 FROM t1;
+# Purge may or may not have cleaned up the DELETE FROM t1 WHERE c1 = 7;
+--replace_column 9 ROWS
+EXPLAIN SELECT COUNT(*) FROM t1 WHERE c2 > 3;
+ANALYZE TABLE t1;
+
+SET @merge_encrypt_0=
+(SELECT variable_value FROM information_schema.global_status
+WHERE variable_name = 'innodb_encryption_n_merge_blocks_encrypted');
+SET @merge_decrypt_0=
+(SELECT variable_value FROM information_schema.global_status
+WHERE variable_name = 'innodb_encryption_n_merge_blocks_decrypted');
+SET @rowlog_encrypt_0=
+(SELECT variable_value FROM information_schema.global_status
+WHERE variable_name = 'innodb_encryption_n_rowlog_blocks_encrypted');
+
+connection con1;
+SHOW CREATE TABLE t1;
+ALTER TABLE t1 ROW_FORMAT=REDUNDANT;
+
+# Exceed the configured innodb_online_alter_log_max_size.
+# The actual limit is a multiple of innodb_sort_buf_size,
+# because that is the size of the in-memory log buffers.
+SET DEBUG_SYNC = 'row_log_table_apply1_before SIGNAL rebuilt2 WAIT_FOR dml2_done';
+# Ensure that the ALTER TABLE will be executed even with some concurrent DML.
+SET lock_wait_timeout = 10;
+--send
+ALTER TABLE t1 ROW_FORMAT=COMPACT
+PAGE_COMPRESSED = YES PAGE_COMPRESSION_LEVEL = 1, ALGORITHM = INPLACE;
+
+# Generate some log (delete-mark, delete-unmark, insert etc.)
+# while the index creation is blocked.
+connection default;
+SET DEBUG_SYNC = 'now WAIT_FOR rebuilt2';
+INSERT INTO t1 SELECT 80 + c1, c2, c3 FROM t1;
+INSERT INTO t1 SELECT 160 + c1, c2, c3 FROM t1;
+UPDATE t1 SET c2 = c2 + 1;
+# At this point, the clustered index scan must have completed,
+# but the modification log keeps accumulating due to the DEBUG_SYNC.
+eval $innodb_metrics_select;
+let $c= 8;
+while ($c)
+{
+ UPDATE t1 SET c2 = c2 + 1;
+ UPDATE t1 SET c2 = c2 + 2;
+ dec $c;
+}
+# Temporary table should exist until the DDL thread notices the overflow.
+eval $innodb_metrics_select;
+
+SET @merge_encrypt_1=
+(SELECT variable_value FROM information_schema.global_status
+WHERE variable_name = 'innodb_encryption_n_merge_blocks_encrypted');
+SET @merge_decrypt_1=
+(SELECT variable_value FROM information_schema.global_status
+WHERE variable_name = 'innodb_encryption_n_merge_blocks_decrypted');
+SET @rowlog_encrypt_1=
+(SELECT variable_value FROM information_schema.global_status
+WHERE variable_name = 'innodb_encryption_n_rowlog_blocks_encrypted');
+
+SELECT
+(@merge_encrypt_1-@merge_encrypt_0)-
+(@merge_decrypt_1-@merge_decrypt_0) as sort_balance,
+@merge_encrypt_1>@merge_encrypt_0, @merge_decrypt_1>@merge_decrypt_0,
+@rowlog_encrypt_1>@rowlog_encrypt_0;
+
+# Release con1.
+SET DEBUG_SYNC = 'now SIGNAL dml2_done';
+
+connection con1;
+# If the following fails with the wrong error, it probably means that
+# you should rerun with a larger mtr --debug-sync-timeout.
+--error ER_INNODB_ONLINE_LOG_TOO_BIG
+reap;
+# The table should have been dropped from the data dictionary
+# when the above error was noticed.
+eval $innodb_metrics_select;
+
+SET @merge_encrypt_1=
+(SELECT variable_value FROM information_schema.global_status
+WHERE variable_name = 'innodb_encryption_n_merge_blocks_encrypted');
+SET @merge_decrypt_1=
+(SELECT variable_value FROM information_schema.global_status
+WHERE variable_name = 'innodb_encryption_n_merge_blocks_decrypted');
+SET @rowlog_encrypt_1=
+(SELECT variable_value FROM information_schema.global_status
+WHERE variable_name = 'innodb_encryption_n_rowlog_blocks_encrypted');
+SET @rowlog_decrypt_1=
+(SELECT variable_value FROM information_schema.global_status
+WHERE variable_name = 'innodb_encryption_n_rowlog_blocks_decrypted');
+
+SET GLOBAL innodb_max_purge_lag_wait=0;
+# Accumulate and apply some modification log.
+SET DEBUG_SYNC = 'row_log_table_apply1_before SIGNAL rebuilt3 WAIT_FOR dml3_done';
+--error ER_MULTIPLE_PRI_KEY
+ALTER TABLE t1 ADD PRIMARY KEY(c22f), CHANGE c2 c22f INT;
+--error ER_DUP_ENTRY
+ALTER TABLE t1 DROP PRIMARY KEY, ADD PRIMARY KEY(c22f), CHANGE c2 c22f INT;
+--send
+ALTER TABLE t1 DROP PRIMARY KEY, ADD PRIMARY KEY(c22f,c1,c4(5)),
+CHANGE c2 c22f INT, CHANGE c3 c3 CHAR(255) NULL, CHANGE c1 c1 INT AFTER c22f,
+ADD COLUMN c4 VARCHAR(6) DEFAULT 'Online', LOCK=NONE;
+
+connection default;
+SET DEBUG_SYNC = 'now WAIT_FOR rebuilt3';
+# Generate some log (delete-mark, delete-unmark, insert etc.)
+eval $innodb_metrics_select;
+BEGIN;
+INSERT INTO t1 SELECT 320 + c1, c2, c3 FROM t1 WHERE c1 > 240;
+DELETE FROM t1 WHERE c1 > 320;
+UPDATE t1 SET c2 = c2 + 1;
+COMMIT;
+eval $innodb_metrics_select;
+# Release con1.
+SET DEBUG_SYNC = 'now SIGNAL dml3_done';
+
+connection con1;
+reap;
+eval $innodb_metrics_select;
+SELECT COUNT(c22f) FROM t1;
+CHECK TABLE t1;
+
+SET @merge_encrypt_2=
+(SELECT variable_value FROM information_schema.global_status
+WHERE variable_name = 'innodb_encryption_n_merge_blocks_encrypted');
+SET @merge_decrypt_2=
+(SELECT variable_value FROM information_schema.global_status
+WHERE variable_name = 'innodb_encryption_n_merge_blocks_decrypted');
+SET @rowlog_encrypt_2=
+(SELECT variable_value FROM information_schema.global_status
+WHERE variable_name = 'innodb_encryption_n_rowlog_blocks_encrypted');
+SET @rowlog_decrypt_2=
+(SELECT variable_value FROM information_schema.global_status
+WHERE variable_name = 'innodb_encryption_n_rowlog_blocks_decrypted');
+
+SELECT
+(@merge_encrypt_2-@merge_encrypt_1)-
+(@merge_decrypt_2-@merge_decrypt_1) as sort_balance,
+(@rowlog_encrypt_2-@rowlog_encrypt_1)-
+(@rowlog_decrypt_2-@rowlog_decrypt_1) as log_balance;
+SELECT
+@merge_encrypt_2-@merge_encrypt_1>0 as sort_encrypted,
+@merge_decrypt_2-@merge_decrypt_1>0 as sort_decrypted,
+@rowlog_encrypt_2-@rowlog_encrypt_1>0 as log_encrypted,
+@rowlog_decrypt_2-@rowlog_decrypt_1>0 as log_decrypted;
+
+# Create a column prefix index.
+--error ER_DUP_ENTRY
+ALTER TABLE t1 DROP PRIMARY KEY, ADD PRIMARY KEY c3p5(c3(5));
+UPDATE t1 SET c3 = NULL WHERE c3 = '';
+SET lock_wait_timeout = 1;
+--error ER_KEY_COLUMN_DOES_NOT_EXIST
+ALTER TABLE t1 DROP COLUMN c22f, ADD PRIMARY KEY c3p5(c3(5));
+# NULL -> NOT NULL is only allowed INPLACE without IGNORE.
+# Adding a PRIMARY KEY will add NOT NULL implicitly!
+--error ER_ALTER_OPERATION_NOT_SUPPORTED_REASON
+ALTER IGNORE TABLE t1 DROP COLUMN c22f, DROP PRIMARY KEY, ADD PRIMARY KEY c3p5(c3(5)),
+ALGORITHM = INPLACE;
+
+UPDATE t1 SET c3=LEFT(CONCAT(c1,REPEAT('foo',c1)),255) WHERE c3 IS NULL;
+
+SET DEBUG_SYNC = 'row_log_table_apply1_before SIGNAL c3p5_created0 WAIT_FOR ins_done0';
+# NULL -> NOT NULL is allowed INPLACE.
+--send
+ALTER TABLE t1 MODIFY c3 CHAR(255) NOT NULL, DROP COLUMN c22f,
+DROP PRIMARY KEY, ADD PRIMARY KEY(c1,c4(5)),
+ADD COLUMN c5 CHAR(5) DEFAULT 'tired' FIRST;
+
+connection default;
+
+SET DEBUG_SYNC = 'now WAIT_FOR c3p5_created0';
+BEGIN;
+INSERT INTO t1 VALUES(347,33101,'Pikku kakkosen posti','YLETV2');
+INSERT INTO t1 VALUES(33101,347,NULL,'');
+COMMIT;
+SET DEBUG_SYNC = 'now SIGNAL ins_done0';
+
+connection con1;
+--error ER_INVALID_USE_OF_NULL
+reap;
+DELETE FROM t1 WHERE c1= 347 and c22f = 33101;
+ALTER TABLE t1 MODIFY c3 CHAR(255) NOT NULL;
+
+SET DEBUG_SYNC = 'row_log_table_apply1_before SIGNAL c3p5_created WAIT_FOR ins_done';
+--send
+ALTER TABLE t1 DROP PRIMARY KEY, DROP COLUMN c22f,
+ADD COLUMN c6 VARCHAR(1000) DEFAULT
+'I love tracking down hard-to-reproduce bugs.',
+ADD PRIMARY KEY c3p5(c3(5), c6(2));
+
+connection default;
+SET DEBUG_SYNC = 'now WAIT_FOR c3p5_created';
+SET DEBUG_SYNC = 'ib_after_row_insert SIGNAL ins_done WAIT_FOR ddl_timed_out';
+--error ER_BAD_NULL_ERROR
+INSERT INTO t1 VALUES(347,33101,NULL,'');
+--send
+INSERT INTO t1 VALUES(347,33101,'Pikku kakkosen posti','');
+
+connection con1;
+--error ER_LOCK_WAIT_TIMEOUT
+reap;
+SET DEBUG_SYNC = 'now SIGNAL ddl_timed_out';
+eval $innodb_metrics_select;
+
+connection default;
+reap;
+SELECT COUNT(*) FROM t1;
+ALTER TABLE t1 ROW_FORMAT=REDUNDANT;
+SELECT * FROM t1 LIMIT 10;
+
+connection con1;
+ALTER TABLE t1 DISCARD TABLESPACE;
+
+connection default;
+SHOW CREATE TABLE t1;
+SET GLOBAL innodb_monitor_disable = module_ddl;
+DROP TABLE t1;
+
+CREATE TABLE t1 (a INT PRIMARY KEY, b blob) ENGINE=InnoDB;
+INSERT INTO t1 VALUES(0,NULL);
+
+connection con1;
+SET DEBUG_SYNC = 'row_log_table_apply1_before SIGNAL created WAIT_FOR ins';
+send ALTER TABLE t1 FORCE;
+
+connection default;
+SET DEBUG_SYNC = 'now WAIT_FOR created';
+BEGIN;
+INSERT INTO t1 VALUES(1, repeat('a', 10000));
+ROLLBACK;
+SET DEBUG_SYNC = 'now SIGNAL ins';
+
+connection con1;
+reap;
+
+connection default;
+SELECT * FROM t1;
+DROP TABLE t1;
+SET DEBUG_SYNC = 'RESET';
+
+--echo #
+--echo # MDEV-29600 Memory leak in row_log_table_apply_update()
+--echo #
+
+CREATE TABLE t1 (pk INT PRIMARY KEY, f TEXT) ENGINE=InnoDB;
+INSERT INTO t1 SET pk=1;
+
+connection con1;
+SET DEBUG_SYNC = 'row_log_table_apply1_before SIGNAL created WAIT_FOR updated';
+send ALTER TABLE t1 FORCE;
+
+connection default;
+SET DEBUG_SYNC = 'now WAIT_FOR created';
+UPDATE t1 SET f = REPEAT('a', 20000);
+SET DEBUG_SYNC = 'now SIGNAL updated';
+
+connection con1;
+reap;
+
+connection default;
+DROP TABLE t1;
+--echo #
+--echo # MDEV-29977 Memory leak in row_log_table_apply_update
+--echo #
+CREATE TABLE t1(f1 longtext, f2 int, KEY(f1(1024)), KEY(f2, f1(20))) ENGINE=InnoDB;
+INSERT INTO t1 VALUES('a', 1);
+connection con1;
+set DEBUG_SYNC="innodb_inplace_alter_table_enter SIGNAL con_default WAIT_FOR con1_signal";
+send ALTER TABLE t1 FORCE;
+connection default;
+SET DEBUG_SYNC="now WAIT_FOR con_default";
+UPDATE t1 SET f1 = NULL;
+UPDATE t1 SET f1 = REPEAT('b', 9000);
+SET DEBUG_SYNC="now SIGNAL con1_signal";
+connection con1;
+reap;
+DROP TABLE t1;
+connection default;
+
+--echo #
+--echo # MDEV-28122 Optimize table crash while applying online log
+--echo #
+CREATE TABLE t1(f1 INT NOT NULL, f2 INT NOT NULL,
+ f3 CHAR(200), f4 CHAR(200),
+ f5 VARCHAR(87), PRIMARY KEY(f1))ENGINE=InnoDB;
+INSERT INTO t1 VALUES(6000, 6000, "InnoDB",
+ "MariaDB", repeat('a', 87));
+
+SET DEBUG_SYNC="inplace_after_index_build SIGNAL dml_start WAIT_FOR dml_commit";
+SEND ALTER TABLE t1 FORCE;
+
+connection con1;
+SET DEBUG_SYNC="now WAIT_FOR dml_start";
+BEGIN;
+INSERT INTO t1 SELECT seq, seq, "IDB", "MDB", repeat('a', 87) FROM seq_1_to_127;
+INSERT INTO t1 VALUES(128, 128, "IDB", "MDB", repeat('a', 86));
+INSERT INTO t1 VALUES(129, 129, "idb", "mdb", repeat('a', 2));
+COMMIT;
+SET DEBUG_SYNC="now SIGNAL dml_commit";
+
+connection default;
+reap;
+CHECK TABLE t1;
+DROP TABLE t1;
+SET DEBUG_SYNC=RESET;
+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_file_per_table = @global_innodb_file_per_table_orig;
+--disable_warnings
+SET GLOBAL innodb_monitor_enable = default;
+SET GLOBAL innodb_monitor_disable = default;
+--enable_warnings
diff --git a/mysql-test/suite/innodb/t/innodb-timeout.test b/mysql-test/suite/innodb/t/innodb-timeout.test
new file mode 100644
index 00000000..0f8bbbec
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb-timeout.test
@@ -0,0 +1,200 @@
+# Save the initial number of concurrent sessions.
+--source include/count_sessions.inc
+--source include/have_innodb.inc
+
+let $initial_timeout=`select @@innodb_lock_wait_timeout`;
+set global innodb_lock_wait_timeout=42;
+
+connect (a,localhost,root,,);
+connect (b,localhost,root,,);
+
+connection a;
+select @@innodb_lock_wait_timeout;
+set innodb_lock_wait_timeout=1;
+select @@innodb_lock_wait_timeout;
+
+connection b;
+let $connection_b_id=`SELECT CONNECTION_ID()`;
+select @@innodb_lock_wait_timeout;
+set global innodb_lock_wait_timeout=347;
+select @@innodb_lock_wait_timeout;
+set innodb_lock_wait_timeout=10;
+select @@innodb_lock_wait_timeout;
+
+connect (c,localhost,root,,);
+connection c;
+
+select @@innodb_lock_wait_timeout;
+
+disconnect c;
+--source include/wait_until_disconnected.inc
+
+connection a;
+--replace_result $connection_b_id <connection_b_id>
+eval SET @connection_b_id = $connection_b_id;
+create table t1(a int primary key)engine=innodb;
+begin;
+insert into t1 values(1),(2),(3);
+
+connection b;
+--send
+select * from t1 for update;
+
+# Observation on information_schema.processlist (2010-12 mysql-5.5)
+# -----------------------------------------------------------------
+# As soon as the server started the execution of the
+# connection a: --send select ... for update
+# High parallel load could delay this up to two seconds.
+# and before either
+# - the innodb_lock_wait_timeout was exceeded
+# -> connection b reap gets ER_LOCK_WAIT_TIMEOUT
+# or
+# - connection a commits, the lock disappears and the statement
+# of connection b finishes
+# -> connection b reap gets success + result set
+# we see within information_schema.processlist for connection b a row
+# command state info
+# Query Sending data select * from t1 for update
+# The highest time value seen was @@innodb_lock_wait_timeout + 1.
+# Please note that there is unfortunately nothing which says
+# that we are just waiting for a lock.
+
+connection a;
+# In order to ensure that the execution of
+# connection b: select * from t1 for update
+# has really started and is most probably waiting for the lock now we poll on
+# information_schema.processlist.
+# Also our current session innodb_lock_wait_timeout of 10 seconds should big
+# enough to prevent that connection b ends up with getting ER_LOCK_WAIT_TIMEOUT.
+#
+let $wait_timeout= 10;
+let $wait_condition= SELECT COUNT(*) = 1 FROM information_schema.processlist
+WHERE id = @connection_b_id AND INFO = 'select * from t1 for update';
+--source include/wait_condition.inc
+commit;
+
+connection b;
+reap;
+
+connection a;
+begin;
+insert into t1 values(4);
+
+connection b;
+set innodb_lock_wait_timeout=3;
+# 3 seconds should be big enough that the wait routine of connection a will
+# hit the time span where our next statement is visible within the
+# information_schema.processlist.
+--send
+select * from t1 for update;
+
+connection a;
+# Wait till the execution of the connection b statement was started.
+let $wait_timeout= 10;
+let $wait_condition= SELECT COUNT(*) = 1 FROM information_schema.processlist
+WHERE id = @connection_b_id AND INFO = 'select * from t1 for update';
+--source include/wait_condition.inc
+# Wait till the execution of the connection b statement has ended.
+let $wait_timeout= 10;
+let $wait_condition= SELECT COUNT(*) = 1 FROM information_schema.processlist
+WHERE id = @connection_b_id AND INFO IS NULL;
+--source include/wait_condition.inc
+# Give "commit" though this must be too late for the statement of connection b.
+commit;
+
+connection b;
+--error ER_LOCK_WAIT_TIMEOUT
+reap;
+
+disconnect b;
+--source include/wait_until_disconnected.inc
+
+connection a;
+disconnect a;
+--source include/wait_until_disconnected.inc
+
+connection default;
+drop table t1;
+--replace_result $initial_timeout <initial_timeout>
+eval set global innodb_lock_wait_timeout=$initial_timeout;
+
+--echo #
+--echo # MDEV-11379 - AliSQL: [Feature] Issue#8: SELECT FOR UPDATE WAIT
+--echo #
+CREATE TABLE t1 (c1 INT, c2 INT) ENGINE=InnoDB;
+INSERT INTO t1 (c1,c2) values (1,1),(2,2),(3,3),(4,4);
+
+# Not supported in view/sp
+--error ER_VIEW_SELECT_CLAUSE
+CREATE VIEW v1 AS SELECT * FROM t1 WHERE c1=4 FOR UPDATE NOWAIT;
+--error ER_VIEW_SELECT_CLAUSE
+CREATE VIEW v1 AS SELECT * FROM t1 WHERE c1=4 FOR UPDATE WAIT 0;
+--error ER_SP_BADSTATEMENT
+CREATE PROCEDURE p1() SELECT * FROM t1 WHERE c1=4 FOR UPDATE NOWAIT;
+--error ER_SP_BADSTATEMENT
+CREATE PROCEDURE p1() SELECT * FROM t1 WHERE c1=4 FOR UPDATE WAIT 0;
+
+connect(con1,localhost,root,,);
+LOCK TABLE t1 WRITE;
+
+connect(con2,localhost,root,,);
+# The following statement should hang because con1 is locking the table
+--error ER_LOCK_WAIT_TIMEOUT
+SELECT * FROM t1 WHERE c1=4 FOR UPDATE NOWAIT;
+--error ER_LOCK_WAIT_TIMEOUT
+SELECT * FROM t1 WHERE c1=4 FOR UPDATE WAIT 0;
+PREPARE stmt FROM 'SELECT * FROM t1 WHERE c1=4 FOR UPDATE NOWAIT';
+--error ER_LOCK_WAIT_TIMEOUT
+EXECUTE stmt;
+DEALLOCATE PREPARE stmt;
+PREPARE stmt FROM 'SELECT * FROM t1 WHERE c1=4 FOR UPDATE WAIT 0';
+--error ER_LOCK_WAIT_TIMEOUT
+EXECUTE stmt;
+DEALLOCATE PREPARE stmt;
+
+connection con1;
+INSERT INTO t1 VALUES(5,5);
+UNLOCK TABLES;
+set AUTOCOMMIT=0;
+--disable_result_log
+SELECT * FROM t1 WHERE c1=4 FOR UPDATE;
+--enable_result_log
+
+connection con2;
+set AUTOCOMMIT=0;
+SET INNODB_LOCK_WAIT_TIMEOUT=1;
+--error ER_LOCK_WAIT_TIMEOUT
+SELECT * FROM t1 WHERE c1=4 FOR UPDATE;
+--error ER_LOCK_WAIT_TIMEOUT
+SELECT * FROM t1 WHERE c1=4 FOR UPDATE NOWAIT;
+--error ER_LOCK_WAIT_TIMEOUT
+SELECT * FROM t1 WHERE c1=4 FOR UPDATE WAIT 0;
+
+connection con1;
+UPDATE t1 SET c2=5 WHERE c1=4;
+COMMIT;
+set AUTOCOMMIT=0;
+SELECT * FROM t1 WHERE c1=4 FOR UPDATE;
+
+connection con2;
+set AUTOCOMMIT=0;
+SET INNODB_LOCK_WAIT_TIMEOUT=1;
+--send
+--disable_result_log
+SELECT * FROM t1 WHERE c1=4 FOR UPDATE WAIT 10;
+
+connection con1;
+COMMIT;
+
+connection con2;
+--reap
+
+
+disconnect con1;
+disconnect con2;
+
+# clear
+connection default;
+DROP TABLE t1;
+
+--source include/wait_until_count_sessions.inc
diff --git a/mysql-test/suite/innodb/t/innodb-trim.test b/mysql-test/suite/innodb/t/innodb-trim.test
new file mode 100644
index 00000000..a077e6ac
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb-trim.test
@@ -0,0 +1,43 @@
+--source include/have_innodb.inc
+--source include/have_innodb_punchhole.inc
+--source include/no_valgrind_without_big.inc
+
+--disable_query_log
+--disable_warnings
+let $innodb_compression_algorithm_orig=`SELECT @@innodb_compression_algorithm`;
+--enable_warnings
+--enable_query_log
+
+# zlib
+set global innodb_compression_algorithm = 1;
+
+create table innodb_page_compressed (c1 int not null primary key auto_increment, b char(200), c char(200), d char(200)) engine=innodb page_compressed=1 page_compression_level=9;
+show warnings;
+
+delimiter //;
+create procedure innodb_insert_proc (repeat_count int)
+begin
+ declare current_num int;
+ set current_num = 0;
+ while current_num < repeat_count do
+ insert into innodb_page_compressed values (NULL,repeat('A',150),repeat('AB',75),repeat('B', 175));
+ set current_num = current_num + 1;
+ end while;
+end//
+delimiter ;//
+commit;
+
+set autocommit=0;
+call innodb_insert_proc(16000);
+commit;
+set autocommit=1;
+
+
+DROP PROCEDURE innodb_insert_proc;
+DROP TABLE innodb_page_compressed;
+
+--disable_query_log
+--disable_warnings
+EVAL SET GLOBAL innodb_compression_algorithm = $innodb_compression_algorithm_orig;
+--enable_warnings
+--enable_query_log
diff --git a/mysql-test/suite/innodb/t/innodb-truncate.test b/mysql-test/suite/innodb/t/innodb-truncate.test
new file mode 100644
index 00000000..4d39fcae
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb-truncate.test
@@ -0,0 +1,110 @@
+--source include/have_innodb.inc
+let $datadir=`select @@datadir`;
+--echo #
+--echo # TRUNCATE TABLE
+--echo #
+--echo # Truncating is disallowed for parent tables unless such table
+--echo # participates in self-referencing foreign keys only.
+--echo #
+CREATE TABLE t1 (pk INT PRIMARY KEY) ENGINE=INNODB;
+CREATE TABLE t2 (fk INT NOT NULL, FOREIGN KEY (fk) REFERENCES t1 (pk)) ENGINE=INNODB;
+--error ER_TRUNCATE_ILLEGAL_FK
+TRUNCATE TABLE t1;
+--echo # Truncation of child should succeed.
+TRUNCATE TABLE t2;
+DROP TABLE t2;
+DROP TABLE t1;
+CREATE TABLE t1 (pk INT PRIMARY KEY, fk INT,
+ FOREIGN KEY (fk) REFERENCES t1 (pk)) ENGINE=INNODB;
+--echo # Truncation of self-referencing table should succeed.
+TRUNCATE TABLE t1;
+DROP TABLE t1;
+
+--echo #
+--echo # Also, truncating such tables is allowed if foreign key
+--echo # checks are disabled.
+--echo #
+
+SET @old_foreign_key_checks = @@SESSION.foreign_key_checks;
+CREATE TABLE t1 (pk INT PRIMARY KEY) ENGINE=INNODB;
+CREATE TABLE t2 (fk INT NOT NULL, FOREIGN KEY (fk) REFERENCES t1 (pk)) ENGINE=INNODB;
+CREATE TABLE t3 (pk INT PRIMARY KEY, fk INT,
+ FOREIGN KEY (fk) REFERENCES t1 (pk)) ENGINE=INNODB;
+SET @@SESSION.foreign_key_checks = 0;
+TRUNCATE TABLE t1;
+TRUNCATE TABLE t2;
+TRUNCATE TABLE t3;
+SET @@SESSION.foreign_key_checks = 1;
+--error ER_TRUNCATE_ILLEGAL_FK
+TRUNCATE TABLE t1;
+TRUNCATE TABLE t2;
+TRUNCATE TABLE t3;
+LOCK TABLES t1 WRITE;
+SET @@SESSION.foreign_key_checks = 0;
+TRUNCATE TABLE t1;
+SET @@SESSION.foreign_key_checks = 1;
+--error ER_TRUNCATE_ILLEGAL_FK
+TRUNCATE TABLE t1;
+UNLOCK TABLES;
+DROP TABLE t3,t2,t1;
+SET @@SESSION.foreign_key_checks = @old_foreign_key_checks;
+
+--echo #
+--echo # Test that TRUNCATE resets auto-increment.
+--echo #
+
+CREATE TABLE t1 (a INT PRIMARY KEY NOT NULL AUTO_INCREMENT,
+ b INT, c INT, d INT, e INT, f INT, g INT, h INT, i INT, j INT, k INT,
+ l INT, m INT, n INT, o INT, p INT, q INT, r INT, s INT, t INT, u INT,
+ KEY(b),KEY(c),KEY(d),KEY(e),KEY(f),KEY(g),KEY(h),KEY(i),KEY(j),KEY(k),
+ KEY(l),KEY(m),KEY(n),KEY(o),KEY(p),KEY(q),KEY(r),KEY(s),KEY(t),KEY(u),
+ KEY(c,b),KEY(d,b),KEY(e,b),KEY(f,b),KEY(g,b),KEY(h,b),KEY(i,b),KEY(j,b),
+ KEY(k,b),KEY(l,b),KEY(m,b),KEY(n,b),KEY(o,b),KEY(p,b),KEY(q,b),KEY(r,b),
+ KEY(s,b),KEY(t,b),KEY(u,b),
+ KEY(d,c),KEY(e,c),KEY(f,c),KEY(g,c),KEY(h,c),KEY(i,c),KEY(j,c),
+ KEY(k,c),KEY(l,c),KEY(m,c),KEY(n,c),KEY(o,c),KEY(p,c),KEY(q,c),KEY(r,c),
+ KEY(s,c),KEY(t,c),KEY(u,c),
+ KEY(e,d),KEY(f,d),KEY(g,d),KEY(h,d),KEY(i,d),KEY(j,d)
+) ENGINE=InnoDB;
+INSERT INTO t1 () VALUES (), ();
+SELECT AUTO_INCREMENT FROM INFORMATION_SCHEMA.TABLES WHERE table_name = 't1';
+SELECT a FROM t1 ORDER BY a;
+TRUNCATE TABLE t1;
+SELECT AUTO_INCREMENT FROM INFORMATION_SCHEMA.TABLES WHERE table_name = 't1';
+INSERT INTO t1 () VALUES (), ();
+SELECT a FROM t1 ORDER BY a;
+DROP TABLE t1;
+
+#
+# MDEV-18923 Assertion `!lex_string_cmp(system_charset_info, fk_info->referenced_table, &table->s->table_name)' failed in fk_truncate_illegal_if_parent
+#
+call mtr.add_suppression('InnoDB: in RENAME TABLE table `test`.`t3`');
+SET FOREIGN_KEY_CHECKS= OFF;
+CREATE TABLE t1 (f2 INT, f4 INT, KEY(f2), FOREIGN KEY (f4) REFERENCES t3 (f4)) ENGINE=InnoDB;
+SET FOREIGN_KEY_CHECKS= ON;
+CREATE TABLE t2 (f2 INT, FOREIGN KEY(f2) REFERENCES t1 (f2)) ENGINE=InnoDB;
+--error ER_CANT_CREATE_TABLE
+CREATE TABLE t3 (a INT) ENGINE=InnoDB;
+--replace_result $datadir ./
+--error ER_ERROR_ON_RENAME
+ALTER TABLE t1 RENAME TO t3;
+ALTER TABLE t1 FORCE;
+--error ER_TRUNCATE_ILLEGAL_FK
+TRUNCATE TABLE t1;
+DROP TABLE t2, t1;
+
+--echo #
+--echo # MDEV-24861 Assertion `trx->rsegs.m_redo.rseg' failed
+--echo # in innodb_prepare_commit_versioned
+--echo #
+
+CREATE TABLE t1 (id INT PRIMARY KEY, f TEXT UNIQUE,
+ s BIGINT UNSIGNED AS ROW START, e BIGINT UNSIGNED AS ROW END,
+ PERIOD FOR SYSTEM_TIME(s,e))
+ENGINE=InnoDB WITH SYSTEM VERSIONING;
+CREATE TABLE t2 (id INT PRIMARY KEY) ENGINE=InnoDB;
+ALTER TABLE t1 FORCE;
+TRUNCATE TABLE t2;
+DROP TABLE t1, t2;
+
+--echo # End of 10.6 tests
diff --git a/mysql-test/suite/innodb/t/innodb-ucs2.test b/mysql-test/suite/innodb/t/innodb-ucs2.test
new file mode 100644
index 00000000..010d27ab
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb-ucs2.test
@@ -0,0 +1,230 @@
+--source include/have_innodb.inc
+-- source include/have_ucs2.inc
+
+--disable_warnings
+drop table if exists t1, t2;
+--enable_warnings
+
+#
+# BUG 14056 Column prefix index on UTF-8 primary key column causes: Can't find record..
+#
+
+create table t1 (
+ a int, b char(10), c char(10), filler char(10), primary key(a, b(2)), unique key (a, c(2))
+) character set utf8 engine = innodb;
+create table t2 (
+ a int, b char(10), c char(10), filler char(10), primary key(a, b(2)), unique key (a, c(2))
+) character set ucs2 engine = innodb;
+insert into t1 values (1,'abcdefg','abcdefg','one');
+insert into t1 values (2,'ijkilmn','ijkilmn','two');
+insert into t1 values (3,'qrstuvw','qrstuvw','three');
+insert into t1 values (4,_utf8 0xe880bd,_utf8 0xe880bd,'four');
+insert into t1 values (4,_utf8 0x5b,_utf8 0x5b,'five');
+insert into t1 values (4,_utf8 0xe880bde880bd,_utf8 0xe880bde880bd,'six');
+insert into t1 values (4,_utf8 0xe880bdD0B1e880bd,_utf8 0xe880bdD0B1e880bd,'seven');
+insert into t1 values (4,_utf8 0xD0B1,_utf8 0xD0B1,'eight');
+insert into t2 values (1,'abcdefg','abcdefg','one');
+insert into t2 values (2,'ijkilmn','ijkilmn','two');
+insert into t2 values (3,'qrstuvw','qrstuvw','three');
+insert into t2 values (4,_ucs2 0x00e400,_ucs2 0x00e400,'four');
+insert into t2 values (4,_ucs2 0x00640065,_ucs2 0x00640065,'five');
+insert into t2 values (4,_ucs2 0x00e400e50068,_ucs2 0x00e400e50068,'six');
+insert into t2 values (4,_ucs2 0x01fc,_ucs2 0x01fc,'seven');
+insert into t2 values (4,_ucs2 0x0120,_ucs2 0x0120,'eight');
+insert into t2 values (4,_ucs2 0x0563,_ucs2 0x0563,'ten');
+insert into t2 values (4,_ucs2 0x05630563,_ucs2 0x05630563,'eleven');
+insert into t2 values (4,_ucs2 0x0563001fc0563,_ucs2 0x0563001fc0563,'point');
+insert into t2 values (4,_ucs2 0x05612020,_ucs2 0x05612020,'taken');
+update t1 set filler = 'boo' where a = 1;
+update t2 set filler ='email' where a = 4;
+select a,hex(b),hex(c),filler from t1 order by filler;
+select a,hex(b),hex(c),filler from t2 order by filler;
+drop table t1;
+drop table t2;
+
+create table t1 (
+ a int, b varchar(10), c varchar(10), filler varchar(10), primary key(a, b(2)), unique key (a, c(2))
+) character set utf8 engine = innodb;
+create table t2 (
+ a int, b varchar(10), c varchar(10), filler varchar(10), primary key(a, b(2)), unique key (a, c(2))
+) character set ucs2 engine = innodb;
+insert into t1 values (1,'abcdefg','abcdefg','one');
+insert into t1 values (2,'ijkilmn','ijkilmn','two');
+insert into t1 values (3,'qrstuvw','qrstuvw','three');
+insert into t1 values (4,_utf8 0xe880bd,_utf8 0xe880bd,'four');
+insert into t1 values (4,_utf8 0x5b,_utf8 0x5b,'five');
+insert into t1 values (4,_utf8 0xe880bde880bd,_utf8 0xe880bde880bd,'six');
+insert into t1 values (4,_utf8 0xe880bdD0B1e880bd,_utf8 0xe880bdD0B1e880bd,'seven');
+insert into t1 values (4,_utf8 0xD0B1,_utf8 0xD0B1,'eight');
+insert into t2 values (1,'abcdefg','abcdefg','one');
+insert into t2 values (2,'ijkilmn','ijkilmn','two');
+insert into t2 values (3,'qrstuvw','qrstuvw','three');
+insert into t2 values (4,_ucs2 0x00e400,_ucs2 0x00e400,'four');
+insert into t2 values (4,_ucs2 0x00640065,_ucs2 0x00640065,'five');
+insert into t2 values (4,_ucs2 0x00e400e50068,_ucs2 0x00e400e50068,'six');
+insert into t2 values (4,_ucs2 0x01fc,_ucs2 0x01fc,'seven');
+insert into t2 values (4,_ucs2 0x0120,_ucs2 0x0120,'eight');
+insert into t2 values (4,_ucs2 0x0563,_ucs2 0x0563,'ten');
+insert into t2 values (4,_ucs2 0x05630563,_ucs2 0x05630563,'eleven');
+insert into t2 values (4,_ucs2 0x0563001fc0563,_ucs2 0x0563001fc0563,'point');
+insert into t2 values (4,_ucs2 0x05612020,_ucs2 0x05612020,'taken');
+update t1 set filler = 'boo' where a = 1;
+update t2 set filler ='email' where a = 4;
+select a,hex(b),hex(c),filler from t1 order by filler;
+select a,hex(b),hex(c),filler from t2 order by filler;
+drop table t1;
+drop table t2;
+
+create table t1 (
+ a int, b text(10), c text(10), filler text(10), primary key(a, b(2)), unique key (a, c(2))
+) character set utf8 engine = innodb;
+create table t2 (
+ a int, b text(10), c text(10), filler text(10), primary key(a, b(2)), unique key (a, c(2))
+) character set ucs2 engine = innodb;
+insert into t1 values (1,'abcdefg','abcdefg','one');
+insert into t1 values (2,'ijkilmn','ijkilmn','two');
+insert into t1 values (3,'qrstuvw','qrstuvw','three');
+insert into t1 values (4,_utf8 0xe880bd,_utf8 0xe880bd,'four');
+insert into t1 values (4,_utf8 0x5b,_utf8 0x5b,'five');
+insert into t1 values (4,_utf8 0xe880bde880bd,_utf8 0xe880bde880bd,'six');
+insert into t1 values (4,_utf8 0xe880bdD0B1e880bd,_utf8 0xe880bdD0B1e880bd,'seven');
+insert into t1 values (4,_utf8 0xD0B1,_utf8 0xD0B1,'eight');
+insert into t2 values (1,'abcdefg','abcdefg','one');
+insert into t2 values (2,'ijkilmn','ijkilmn','two');
+insert into t2 values (3,'qrstuvw','qrstuvw','three');
+insert into t2 values (4,_ucs2 0x00e400,_ucs2 0x00e400,'four');
+insert into t2 values (4,_ucs2 0x00640065,_ucs2 0x00640065,'five');
+insert into t2 values (4,_ucs2 0x00e400e50068,_ucs2 0x00e400e50068,'six');
+insert into t2 values (4,_ucs2 0x01fc,_ucs2 0x01fc,'seven');
+insert into t2 values (4,_ucs2 0x0120,_ucs2 0x0120,'eight');
+insert into t2 values (4,_ucs2 0x0563,_ucs2 0x0563,'ten');
+insert into t2 values (4,_ucs2 0x05630563,_ucs2 0x05630563,'eleven');
+insert into t2 values (4,_ucs2 0x0563001fc0563,_ucs2 0x0563001fc0563,'point');
+insert into t2 values (4,_ucs2 0x05612020,_ucs2 0x05612020,'taken');
+update t1 set filler = 'boo' where a = 1;
+update t2 set filler ='email' where a = 4;
+select a,hex(b),hex(c),filler from t1 order by filler;
+select a,hex(b),hex(c),filler from t2 order by filler;
+drop table t1;
+drop table t2;
+
+create table t1 (
+ a int, b blob(10), c blob(10), filler blob(10), primary key(a, b(2)), unique key (a, c(2))
+) character set utf8 engine = innodb;
+create table t2 (
+ a int, b blob(10), c blob(10), filler blob(10), primary key(a, b(2)), unique key (a, c(2))
+) character set ucs2 engine = innodb;
+insert into t1 values (1,'abcdefg','abcdefg','one');
+insert into t1 values (2,'ijkilmn','ijkilmn','two');
+insert into t1 values (3,'qrstuvw','qrstuvw','three');
+insert into t1 values (4,_utf8 0xe880bd,_utf8 0xe880bd,'four');
+insert into t1 values (4,_utf8 0x5b,_utf8 0x5b,'five');
+insert into t1 values (4,_utf8 0xD0B1,_utf8 0xD0B1,'eight');
+insert into t2 values (1,'abcdefg','abcdefg','one');
+insert into t2 values (2,'ijkilmn','ijkilmn','two');
+insert into t2 values (3,'qrstuvw','qrstuvw','three');
+insert into t2 values (4,_ucs2 0x00e400,_ucs2 0x00e400,'four');
+insert into t2 values (4,_ucs2 0x00640065,_ucs2 0x00640065,'five');
+insert into t2 values (4,_ucs2 0x00e400e50068,_ucs2 0x00e400e50068,'six');
+insert into t2 values (4,_ucs2 0x01fc,_ucs2 0x01fc,'seven');
+insert into t2 values (4,_ucs2 0x0120,_ucs2 0x0120,'eight');
+insert into t2 values (4,_ucs2 0x0563,_ucs2 0x0563,'ten');
+insert into t2 values (4,_ucs2 0x05612020,_ucs2 0x05612020,'taken');
+update t1 set filler = 'boo' where a = 1;
+update t2 set filler ='email' where a = 4;
+select a,hex(b),hex(c),filler from t1 order by filler;
+select a,hex(b),hex(c),filler from t2 order by filler;
+drop table t1;
+drop table t2;
+commit;
+
+#
+# Test cases for bug #15308 Problem of Order with Enum Column in Primary Key
+#
+CREATE TABLE t1 (
+ ind enum('0','1','2') NOT NULL default '0',
+ string1 varchar(250) NOT NULL,
+ PRIMARY KEY (ind)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8;
+CREATE TABLE t2 (
+ ind enum('0','1','2') NOT NULL default '0',
+ string1 varchar(250) NOT NULL,
+ PRIMARY KEY (ind)
+) ENGINE=InnoDB DEFAULT CHARSET=ucs2;
+
+INSERT INTO t1 VALUES ('1', ''),('2', '');
+INSERT INTO t2 VALUES ('1', ''),('2', '');
+SELECT hex(ind),hex(string1) FROM t1 ORDER BY string1;
+SELECT hex(ind),hex(string1) FROM t2 ORDER BY string1;
+drop table t1,t2;
+
+CREATE TABLE t1 (
+ ind set('0','1','2') NOT NULL default '0',
+ string1 varchar(250) NOT NULL,
+ PRIMARY KEY (ind)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8;
+CREATE TABLE t2 (
+ ind set('0','1','2') NOT NULL default '0',
+ string1 varchar(250) NOT NULL,
+ PRIMARY KEY (ind)
+) ENGINE=InnoDB DEFAULT CHARSET=ucs2;
+
+INSERT INTO t1 VALUES ('1', ''),('2', '');
+INSERT INTO t2 VALUES ('1', ''),('2', '');
+SELECT hex(ind),hex(string1) FROM t1 ORDER BY string1;
+SELECT hex(ind),hex(string1) FROM t2 ORDER BY string1;
+drop table t1,t2;
+
+CREATE TABLE t1 (
+ ind bit not null,
+ string1 varchar(250) NOT NULL,
+ PRIMARY KEY (ind)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8;
+CREATE TABLE t2 (
+ ind bit not null,
+ string1 varchar(250) NOT NULL,
+ PRIMARY KEY (ind)
+) ENGINE=InnoDB DEFAULT CHARSET=ucs2;
+insert into t1 values(0,''),(1,'');
+insert into t2 values(0,''),(1,'');
+select hex(ind),hex(string1) from t1 order by string1;
+select hex(ind),hex(string1) from t2 order by string1;
+drop table t1,t2;
+
+# tests for bug #14056 Column prefix index on UTF-8 primary key column causes 'Can't find record..'
+
+create table t2 (
+ a int, b char(10), filler char(10), primary key(a, b(2))
+) character set utf8 engine = innodb;
+
+insert into t2 values (1,'abcdefg','one');
+insert into t2 values (2,'ijkilmn','two');
+insert into t2 values (3, 'qrstuvw','three');
+update t2 set a=5, filler='booo' where a=1;
+drop table t2;
+create table t2 (
+ a int, b char(10), filler char(10), primary key(a, b(2))
+) character set ucs2 engine = innodb;
+
+insert into t2 values (1,'abcdefg','one');
+insert into t2 values (2,'ijkilmn','two');
+insert into t2 values (3, 'qrstuvw','three');
+update t2 set a=5, filler='booo' where a=1;
+drop table t2;
+
+create table t1(a int not null, b char(110),primary key(a,b(100))) engine=innodb default charset=utf8;
+insert into t1 values(1,'abcdefg'),(2,'defghijk');
+insert into t1 values(6,_utf8 0xD0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1);
+insert into t1 values(7,_utf8 0xD0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B2);
+select a,hex(b) from t1 order by b;
+update t1 set b = 'three' where a = 6;
+drop table t1;
+create table t1(a int not null, b text(110),primary key(a,b(100))) engine=innodb default charset=utf8;
+insert into t1 values(1,'abcdefg'),(2,'defghijk');
+insert into t1 values(6,_utf8 0xD0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1);
+insert into t1 values(7,_utf8 0xD0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B2);
+select a,hex(b) from t1 order by b;
+update t1 set b = 'three' where a = 6;
+drop table t1;
+
+--echo End of 5.0 tests
diff --git a/mysql-test/suite/innodb/t/innodb-update-insert.test b/mysql-test/suite/innodb/t/innodb-update-insert.test
new file mode 100644
index 00000000..d7a70661
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb-update-insert.test
@@ -0,0 +1,39 @@
+#
+# Copyright (c) 2014 Oracle and/or its affiliates. All rights reserved.
+#
+
+# This file contains test cases for checking the functionality "update by
+# delete + insert".
+
+--source include/have_innodb.inc
+
+--echo #
+--echo # Bug#14668683 ASSERT REC_GET_DELETED_FLAG(REC, PAGE_IS_COMP(PAGE))
+--echo #
+
+create table t1(f1 char(1) primary key, f2 int not null, f3 blob)
+engine=innodb;
+show create table t1;
+
+insert into t1 values ('a', 0, repeat('b',8102));
+select f1 from t1;
+update t1 set f1='A';
+select f1 from t1;
+drop table t1;
+
+--echo #
+--echo # Another test case
+--echo #
+create table t1 (f1 char(1), f2 longblob, f3 blob, primary key(f1))
+charset=utf8 engine=innodb;
+
+set statement sql_mode = '' for
+replace into t1 set f1=0xa3;
+select f1 from t1;
+update t1 set f1=0x6a;
+update t1 set f3=repeat(0xb1,8103);
+update t1 set f1=0x4a;
+update ignore t1 set f1=0x82;
+select f1 from t1;
+
+drop table t1;
diff --git a/mysql-test/suite/innodb/t/innodb-virtual-columns-debug.test b/mysql-test/suite/innodb/t/innodb-virtual-columns-debug.test
new file mode 100644
index 00000000..d4947ca4
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb-virtual-columns-debug.test
@@ -0,0 +1,27 @@
+--source include/have_innodb.inc
+--source include/have_debug.inc
+--source include/have_debug_sync.inc
+
+#
+# MDEV-17005 ASAN heap-use-after-free in innobase_get_computed_value
+#
+CREATE TABLE t1 (a INT, b INT AS (a), KEY(b)) ENGINE=InnoDB;
+
+INSERT INTO t1 () VALUES (),();
+--connect (con1,localhost,root,,test)
+ALTER TABLE t1 ADD COLUMN x INT as (a), add key(x), ALGORITHM=COPY;
+SET debug_sync= "ib_open_after_dict_open SIGNAL delete_open WAIT_FOR another_open";
+--send
+DELETE FROM t1;
+--connection default
+SET debug_sync= "now WAIT_FOR delete_open";
+SELECT a FROM t1;
+SET debug_sync= "now SIGNAL another_open";
+--connection con1
+--reap
+
+# Cleanup
+--disconnect con1
+--connection default
+SET debug_sync= "RESET";
+DROP TABLE t1;
diff --git a/mysql-test/suite/innodb/t/innodb-virtual-columns.test b/mysql-test/suite/innodb/t/innodb-virtual-columns.test
new file mode 100644
index 00000000..faf54264
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb-virtual-columns.test
@@ -0,0 +1,319 @@
+--source include/have_innodb.inc
+
+#
+# MDEV-7367: Updating a virtual column corrupts table which crashes server
+# MySQL table columns contains virtual columns but InnoDB table
+# definition does not.
+#
+CREATE TABLE IF NOT EXISTS gso_grad_supr (
+ term char(4) NOT NULL DEFAULT '',
+ uw_id int(8) UNSIGNED NOT NULL DEFAULT 0,
+ plan varchar(10) NOT NULL DEFAULT '',
+ wdraw_rsn varchar(4) NOT NULL DEFAULT '',
+ admit_term char(4) NOT NULL DEFAULT '',
+ CONSTRAINT gso_grad_supr_pky PRIMARY KEY (uw_id, term)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8;
+
+INSERT INTO `gso_grad_supr` VALUES ('1031',2,'CSM','','1009');
+INSERT INTO `gso_grad_supr` VALUES ('1035',2,'CSM','ACAD','1009');
+
+CREATE TABLE IF NOT EXISTS grad_degree (
+ student_id int(8) UNSIGNED NOT NULL,
+ plan varchar(10) NOT NULL,
+ admit_term char(4) NOT NULL,
+ wdraw_rsn varchar(4) NOT NULL DEFAULT '',
+ ofis_deg_status varchar(15) AS (
+ CASE
+ WHEN wdraw_rsn = '' THEN 'In progress'
+ WHEN wdraw_rsn = 'DCMP' OR wdraw_rsn = 'TRDC' THEN 'Completed'
+ ELSE 'Not Completed'
+ END) VIRTUAL,
+ deg_start_term char(4) NOT NULL DEFAULT '' COMMENT 'Educated guess at the beginning of the data',
+ deg_as_of_term char(4) NOT NULL COMMENT 'In most cases also end term',
+ CONSTRAINT grad_degree_stu_plan_admit_pky PRIMARY KEY (student_id, plan, admit_term)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8;
+
+SHOW CREATE TABLE grad_degree;
+
+CREATE INDEX grad_degree_wdraw_rsn_ndx ON grad_degree (wdraw_rsn);
+CREATE INDEX grad_degree_as_of_term_ndx ON grad_degree (deg_as_of_term);
+
+INSERT IGNORE grad_degree (
+ student_id,
+ plan,
+ admit_term,
+ wdraw_rsn,
+ deg_start_term,
+ deg_as_of_term
+)
+SELECT
+ ggs.uw_id AS c_student_id,
+ ggs.plan,
+ ggs.admit_term,
+ ggs.wdraw_rsn,
+ IF( (SELECT COUNT(*) FROM grad_degree AS gd WHERE gd.student_id = ggs.uw_id AND gd.admit_term = ggs.admit_term) > 0, ggs.term, ggs.admit_term ) AS c_deg_start_term,
+ ggs.term AS c_as_of_term
+FROM gso_grad_supr AS ggs
+LEFT OUTER JOIN
+ grad_degree AS gd
+ ON ( gd.student_id = ggs.uw_id AND gd.plan = ggs.plan AND gd.admit_term = ggs.admit_term )
+WHERE
+ ggs.term = 1031 AND
+ gd.student_id IS NULL
+;
+
+UPDATE grad_degree AS gd
+INNER JOIN
+ gso_grad_supr AS ggs
+ ON ( gd.student_id = ggs.uw_id AND gd.plan = ggs.plan AND gd.admit_term = ggs.admit_term )
+SET
+ gd.wdraw_rsn = ggs.wdraw_rsn,
+ gd.deg_as_of_term = 1035
+WHERE
+ gd.wdraw_rsn NOT IN ('DCMP', 'TRDC') AND
+ ggs.term = 1035
+;
+
+drop table grad_degree;
+
+#
+# Test with more virtual columns so that MySQL table has
+# more columns than InnoDB and index definition is out
+# of number of actual InnoDB columns.
+#
+CREATE TABLE IF NOT EXISTS grad_degree (
+ student_id int(8) UNSIGNED NOT NULL,
+ plan varchar(10) NOT NULL,
+ admit_term char(4) NOT NULL,
+ wdraw_rsn varchar(4) NOT NULL DEFAULT '',
+ ofis_deg_status varchar(15) AS (
+ CASE
+ WHEN wdraw_rsn = '' THEN 'In progress'
+ WHEN wdraw_rsn = 'DCMP' OR wdraw_rsn = 'TRDC' THEN 'Completed'
+ ELSE 'Not Completed'
+ END) VIRTUAL,
+ ofis_deg_status2 varchar(15) AS (
+ CASE
+ WHEN wdraw_rsn = '' THEN 'In progress2'
+ WHEN wdraw_rsn = 'DCMP' OR wdraw_rsn = 'TRDC' THEN 'Completed2'
+ ELSE 'Not Completed2'
+ END) VIRTUAL,
+ ofis_deg_status3 varchar(15) AS (
+ CASE
+ WHEN wdraw_rsn = '' THEN 'In progress3'
+ WHEN wdraw_rsn = 'DCMP' OR wdraw_rsn = 'TRDC' THEN 'Completed3'
+ ELSE 'Not Completed3'
+ END) VIRTUAL,
+ ofis_deg_status4 varchar(15) AS (
+ CASE
+ WHEN wdraw_rsn = '' THEN 'In progress4'
+ WHEN wdraw_rsn = 'DCMP' OR wdraw_rsn = 'TRDC' THEN 'Completed4'
+ ELSE 'Not Completed4'
+ END) VIRTUAL,
+ ofis_deg_status5 varchar(15) AS (
+ CASE
+ WHEN wdraw_rsn = '' THEN 'In progress5'
+ WHEN wdraw_rsn = 'DCMP' OR wdraw_rsn = 'TRDC' THEN 'Completed5'
+ ELSE 'Not Completed5'
+ END) VIRTUAL,
+ ofis_deg_status6 varchar(15) AS (
+ CASE
+ WHEN wdraw_rsn = '' THEN 'In progress6'
+ WHEN wdraw_rsn = 'DCMP' OR wdraw_rsn = 'TRDC' THEN 'Completed6'
+ ELSE 'Not Completed6'
+ END) VIRTUAL,
+ ofis_deg_status7 varchar(15) AS (
+ CASE
+ WHEN wdraw_rsn = '' THEN 'In progress7'
+ WHEN wdraw_rsn = 'DCMP' OR wdraw_rsn = 'TRDC' THEN 'Completed7'
+ ELSE 'Not Completed7'
+ END) VIRTUAL,
+ ofis_deg_status8 varchar(15) AS (
+ CASE
+ WHEN wdraw_rsn = '' THEN 'In progress8'
+ WHEN wdraw_rsn = 'DCMP' OR wdraw_rsn = 'TRDC' THEN 'Completed8'
+ ELSE 'Not Completed8'
+ END) VIRTUAL,
+ deg_start_term char(4) NOT NULL DEFAULT '' COMMENT 'Educated guess at the beginning of the data',
+ deg_as_of_term char(4) NOT NULL COMMENT 'In most cases also end term',
+ CONSTRAINT grad_degree_stu_plan_admit_pky PRIMARY KEY (student_id, plan, admit_term)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8;
+
+SHOW CREATE TABLE grad_degree;
+
+CREATE INDEX grad_degree_wdraw_rsn_ndx ON grad_degree (wdraw_rsn);
+CREATE INDEX grad_degree_as_of_term_ndx ON grad_degree (deg_as_of_term);
+
+INSERT IGNORE grad_degree (
+ student_id,
+ plan,
+ admit_term,
+ wdraw_rsn,
+ deg_start_term,
+ deg_as_of_term
+)
+SELECT
+ ggs.uw_id AS c_student_id,
+ ggs.plan,
+ ggs.admit_term,
+ ggs.wdraw_rsn,
+ IF( (SELECT COUNT(*) FROM grad_degree AS gd WHERE gd.student_id = ggs.uw_id AND gd.admit_term = ggs.admit_term) > 0, ggs.term, ggs.admit_term ) AS c_deg_start_term,
+ ggs.term AS c_as_of_term
+FROM gso_grad_supr AS ggs
+LEFT OUTER JOIN
+ grad_degree AS gd
+ ON ( gd.student_id = ggs.uw_id AND gd.plan = ggs.plan AND gd.admit_term = ggs.admit_term )
+WHERE
+ ggs.term = 1031 AND
+ gd.student_id IS NULL
+;
+
+UPDATE grad_degree AS gd
+INNER JOIN
+ gso_grad_supr AS ggs
+ ON ( gd.student_id = ggs.uw_id AND gd.plan = ggs.plan AND gd.admit_term = ggs.admit_term )
+SET
+ gd.wdraw_rsn = ggs.wdraw_rsn,
+ gd.deg_as_of_term = 1035
+WHERE
+ gd.wdraw_rsn NOT IN ('DCMP', 'TRDC') AND
+ ggs.term = 1035
+;
+
+#
+# Verify that indexes can be dropped
+#
+ALTER TABLE grad_degree DROP INDEX grad_degree_wdraw_rsn_ndx;
+
+#
+# Verify that we can drop columns
+#
+ALTER TABLE grad_degree DROP COLUMN deg_start_term;
+
+SHOW CREATE TABLE grad_degree;
+
+DROP TABLE grad_degree;
+
+#
+# Verify after dropping virtual columns
+#
+CREATE TABLE IF NOT EXISTS grad_degree (
+ student_id int(8) UNSIGNED NOT NULL,
+ plan varchar(10) NOT NULL,
+ admit_term char(4) NOT NULL,
+ wdraw_rsn varchar(4) NOT NULL DEFAULT '',
+ ofis_deg_status varchar(15) AS (
+ CASE
+ WHEN wdraw_rsn = '' THEN 'In progress'
+ WHEN wdraw_rsn = 'DCMP' OR wdraw_rsn = 'TRDC' THEN 'Completed'
+ ELSE 'Not Completed'
+ END) VIRTUAL,
+ ofis_deg_status2 varchar(15) AS (
+ CASE
+ WHEN wdraw_rsn = '' THEN 'In progress2'
+ WHEN wdraw_rsn = 'DCMP' OR wdraw_rsn = 'TRDC' THEN 'Completed2'
+ ELSE 'Not Completed2'
+ END) VIRTUAL,
+ ofis_deg_status3 varchar(15) AS (
+ CASE
+ WHEN wdraw_rsn = '' THEN 'In progress3'
+ WHEN wdraw_rsn = 'DCMP' OR wdraw_rsn = 'TRDC' THEN 'Completed3'
+ ELSE 'Not Completed3'
+ END) VIRTUAL,
+ ofis_deg_status4 varchar(15) AS (
+ CASE
+ WHEN wdraw_rsn = '' THEN 'In progress4'
+ WHEN wdraw_rsn = 'DCMP' OR wdraw_rsn = 'TRDC' THEN 'Completed4'
+ ELSE 'Not Completed4'
+ END) VIRTUAL,
+ ofis_deg_status5 varchar(15) AS (
+ CASE
+ WHEN wdraw_rsn = '' THEN 'In progress5'
+ WHEN wdraw_rsn = 'DCMP' OR wdraw_rsn = 'TRDC' THEN 'Completed5'
+ ELSE 'Not Completed5'
+ END) VIRTUAL,
+ ofis_deg_status6 varchar(15) AS (
+ CASE
+ WHEN wdraw_rsn = '' THEN 'In progress6'
+ WHEN wdraw_rsn = 'DCMP' OR wdraw_rsn = 'TRDC' THEN 'Completed6'
+ ELSE 'Not Completed6'
+ END) VIRTUAL,
+ ofis_deg_status7 varchar(15) AS (
+ CASE
+ WHEN wdraw_rsn = '' THEN 'In progress7'
+ WHEN wdraw_rsn = 'DCMP' OR wdraw_rsn = 'TRDC' THEN 'Completed7'
+ ELSE 'Not Completed7'
+ END) VIRTUAL,
+ ofis_deg_status8 varchar(15) AS (
+ CASE
+ WHEN wdraw_rsn = '' THEN 'In progress8'
+ WHEN wdraw_rsn = 'DCMP' OR wdraw_rsn = 'TRDC' THEN 'Completed8'
+ ELSE 'Not Completed8'
+ END) VIRTUAL,
+ deg_start_term char(4) NOT NULL DEFAULT '' COMMENT 'Educated guess at the beginning of the data',
+ deg_as_of_term char(4) NOT NULL COMMENT 'In most cases also end term',
+ CONSTRAINT grad_degree_stu_plan_admit_pky PRIMARY KEY (student_id, plan, admit_term)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8;
+
+SHOW CREATE TABLE grad_degree;
+
+CREATE INDEX grad_degree_wdraw_rsn_ndx ON grad_degree (wdraw_rsn);
+
+ALTER TABLE grad_degree DROP COLUMN ofis_deg_status2, DROP COLUMN ofis_deg_status3,
+DROP COLUMN ofis_deg_status4, DROP COLUMN ofis_deg_status5, DROP COLUMN ofis_deg_status6,
+DROP COLUMN ofis_deg_status7, DROP COLUMN ofis_deg_status8;
+
+CREATE INDEX grad_degree_as_of_term_ndx ON grad_degree (deg_as_of_term);
+
+INSERT IGNORE grad_degree (
+ student_id,
+ plan,
+ admit_term,
+ wdraw_rsn,
+ deg_start_term,
+ deg_as_of_term
+)
+SELECT
+ ggs.uw_id AS c_student_id,
+ ggs.plan,
+ ggs.admit_term,
+ ggs.wdraw_rsn,
+ IF( (SELECT COUNT(*) FROM grad_degree AS gd WHERE gd.student_id = ggs.uw_id AND gd.admit_term = ggs.admit_term) > 0, ggs.term, ggs.admit_term ) AS c_deg_start_term,
+ ggs.term AS c_as_of_term
+FROM gso_grad_supr AS ggs
+LEFT OUTER JOIN
+ grad_degree AS gd
+ ON ( gd.student_id = ggs.uw_id AND gd.plan = ggs.plan AND gd.admit_term = ggs.admit_term )
+WHERE
+ ggs.term = 1031 AND
+ gd.student_id IS NULL
+;
+
+UPDATE grad_degree AS gd
+INNER JOIN
+ gso_grad_supr AS ggs
+ ON ( gd.student_id = ggs.uw_id AND gd.plan = ggs.plan AND gd.admit_term = ggs.admit_term )
+SET
+ gd.wdraw_rsn = ggs.wdraw_rsn,
+ gd.deg_as_of_term = 1035
+WHERE
+ gd.wdraw_rsn NOT IN ('DCMP', 'TRDC') AND
+ ggs.term = 1035
+;
+
+select * from grad_degree;
+select * from gso_grad_supr;
+
+drop table grad_degree;
+drop table gso_grad_supr;
+
+CREATE TABLE t1 (a INT, b CHAR(12), c INT AS (a) VIRTUAL, FULLTEXT KEY(b)) ENGINE=InnoDB;
+INSERT INTO t1 (a,b) VALUES (1,'foo');
+SELECT * FROM t1;
+DROP TABLE t1;
+
+CREATE TABLE t1 (a INT, b CHAR(12), c INT AS (a) VIRTUAL) ENGINE=InnoDB;
+INSERT INTO t1 (a,b) VALUES (1,'foo');
+ALTER TABLE t1 ADD FULLTEXT KEY(b);
+SELECT * FROM t1;
+DROP TABLE t1;
diff --git a/mysql-test/suite/innodb/t/innodb-virtual-columns2.test b/mysql-test/suite/innodb/t/innodb-virtual-columns2.test
new file mode 100644
index 00000000..13ecffcc
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb-virtual-columns2.test
@@ -0,0 +1,74 @@
+--source include/have_innodb.inc
+
+#
+# MDEV-11724: InnoDB: Failing assertion: len <= col->len || ((col->mtype) == 5 || (col->mtype) == 16 || (col->mtype) == 14) || (((col->mtype) == 15 || (col->mtype) == 16) && len == 2 * 2 * sizeof(double)) || (col->len == 0 && col->mtype == 1)
+#
+
+CREATE TABLE t1 (
+ y YEAR NULL,
+ i SMALLINT NULL,
+ c VARCHAR(8) NOT NULL DEFAULT '',
+ vi SMALLINT AS (i) VIRTUAL,
+ INDEX(y)
+) ENGINE=InnoDB;
+
+SHOW CREATE TABLE t1;
+SELECT * FROM t1 WHERE y BETWEEN 2012 AND 2016 FOR UPDATE;
+INSERT INTO t1 (i) VALUES (1),(2);
+SELECT * FROM t1 WHERE y BETWEEN 2012 AND 2016 FOR UPDATE;
+DROP TABLE t1;
+
+#
+# MDEV-11725: InnoDB: Failing assertion: !rec || !cmp_dtuple_rec(tuple, rec, *offsets)
+#
+
+CREATE TABLE t1 (
+ y YEAR NULL,
+ i SMALLINT NULL,
+ vi SMALLINT AS (i) VIRTUAL,
+ INDEX(y)
+) ENGINE=InnoDB;
+
+SHOW CREATE TABLE t1;
+SELECT * FROM t1 WHERE y BETWEEN 2012 AND 2016 FOR UPDATE;
+INSERT INTO t1 (i) VALUES (1),(2);
+SELECT * FROM t1 WHERE y BETWEEN 2012 AND 2016 FOR UPDATE;
+DROP TABLE t1;
+
+#
+# MDEV-11726: Server crashes in mach_read_from_n_little_endian
+#
+
+CREATE TABLE t1 (
+ y YEAR NULL,
+ i SMALLINT NULL,
+ b BLOB NULL,
+ vi SMALLINT AS (i) VIRTUAL,
+ INDEX(y)
+) ENGINE=InnoDB;
+
+SHOW CREATE TABLE t1;
+SELECT * FROM t1 WHERE y BETWEEN 2012 AND 2016 FOR UPDATE;
+INSERT INTO t1 (i) VALUES (1),(2);
+SELECT * FROM t1 WHERE y BETWEEN 2012 AND 2016 FOR UPDATE;
+DROP TABLE t1;
+
+--echo #
+--echo # MDEV-23632 ALTER TABLE...ADD KEY creates corrupted index on virtual column
+--echo #
+
+CREATE TABLE t1(a INT PRIMARY KEY, b INT, g INT GENERATED ALWAYS AS(b)VIRTUAL) ENGINE=InnoDB;
+INSERT INTO t1 VALUES (1,1,default);
+ALTER TABLE t1 ADD COLUMN c INT;
+ALTER TABLE t1 ADD KEY(g);
+CHECK TABLE t1;
+SELECT g FROM t1 FORCE INDEX (g);
+DROP TABLE t1;
+
+CREATE TABLE t1(a INT, b INT, g INT GENERATED ALWAYS AS(b)VIRTUAL) ENGINE=InnoDB;
+INSERT INTO t1 VALUES (1,1,default);
+ALTER TABLE t1 ADD COLUMN c INT PRIMARY KEY; # Triggers `new_clustered`
+ALTER TABLE t1 ADD KEY(g);
+CHECK TABLE t1;
+SELECT g FROM t1 FORCE INDEX (g);
+DROP TABLE t1;
diff --git a/mysql-test/suite/innodb/t/innodb-wl5522-1.test b/mysql-test/suite/innodb/t/innodb-wl5522-1.test
new file mode 100644
index 00000000..dbd58835
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb-wl5522-1.test
@@ -0,0 +1,965 @@
+# Not supported in embedded
+--source include/not_embedded.inc
+
+-- source include/have_innodb.inc
+
+call mtr.add_suppression("InnoDB: Unable to import tablespace .* because it already exists. Please DISCARD the tablespace before IMPORT.");
+
+let MYSQLD_DATADIR =`SELECT @@datadir`;
+
+# Following testcases are created from JET cases (where import
+# export instance are differnt server )
+# Here test will be run on same import and export instance.
+
+CREATE DATABASE testdb_wl5522;
+
+# case 1
+CREATE TABLE testdb_wl5522.t1 (c1 INT ) ENGINE = Innodb;
+INSERT INTO testdb_wl5522.t1 VALUES (1),(123),(331);
+SELECT c1 FROM testdb_wl5522.t1;
+FLUSH TABLES testdb_wl5522.t1 FOR EXPORT;
+SELECT * FROM testdb_wl5522.t1 ORDER BY c1;
+
+perl;
+do "$ENV{MTR_SUITE_DIR}/include/innodb-util.pl";
+ib_backup_tablespaces("testdb_wl5522", "t1");
+EOF
+
+UNLOCK TABLES;
+
+DROP TABLE testdb_wl5522.t1;
+CREATE TABLE testdb_wl5522.t1 (c1 INT ) ENGINE = Innodb;
+ALTER TABLE testdb_wl5522.t1 DISCARD TABLESPACE;
+
+
+perl;
+do "$ENV{MTR_SUITE_DIR}/include/innodb-util.pl";
+ib_discard_tablespaces("testdb_wl5522", "t1");
+ib_restore_tablespaces("testdb_wl5522", "t1");
+EOF
+
+ALTER TABLE testdb_wl5522.t1 IMPORT TABLESPACE;
+SELECT * FROM testdb_wl5522.t1 ORDER BY c1;
+DROP TABLE testdb_wl5522.t1;
+
+# case 2
+CREATE TABLE testdb_wl5522.t1 (
+col1 BIT(1),
+col2 BOOLEAN,
+col3 TINYINT,
+col4 SMALLINT,
+col5 MEDIUMINT,
+col6 INT,
+col7 BIGINT,
+col8 FLOAT (14,3) ,
+col9 DOUBLE (14,3),
+col10 VARCHAR(20),
+col11 TEXT ,
+col12 ENUM('a','b','c'),
+col13 TEXT,
+col14 CHAR(20),
+col15 VARBINARY (400),
+col16 BINARY(40),
+col17 BLOB (400),
+col18 INT NOT NULL PRIMARY KEY,
+col19 DATE,
+col20 DATETIME,
+col21 TIMESTAMP,
+col22 TIME,
+col23 YEAR ) ENGINE = Innodb;
+
+CREATE INDEX idx1 ON testdb_wl5522.t1(col18);
+CREATE INDEX prefix_idx ON testdb_wl5522.t1(col14 (10));
+CREATE UNIQUE INDEX idx2 ON testdb_wl5522.t1(col12);
+CREATE UNIQUE INDEX idx3 ON testdb_wl5522.t1(col8);
+INSERT INTO testdb_wl5522.t1 VALUES
+(1,1,-128,32767,-8388608,2147483647,-9223372036854775808, 92233720368.222,
+-92233720368.222,'aaa', + 'aaaaaaaaaa','b','bbbbb','ccccc',
+REPEAT('d',40),REPEAT('d',40),REPEAT('d',40),1,'1000-01-01',
+'3000-12-31 23:59:59.99','1990-01-01 00:00:01.00',
+'01:59:59.00','1901');
+INSERT INTO testdb_wl5522.t1 VALUES
+(NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,
+NULL,NULL,NULL,3,NULL,NULL,NULL,NULL,NULL);
+--error 1048
+INSERT INTO testdb_wl5522.t1 VALUES (NULL,NULL,NULL,NULL,NULL,NULL,NULL,
+NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL);
+--error 1062
+INSERT INTO testdb_wl5522.t1 VALUES (NULL,NULL,NULL,NULL,NULL,NULL,NULL,
+NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,1,NULL,NULL,NULL,NULL,NULL);
+
+FLUSH TABLES testdb_wl5522.t1 WITH READ LOCK;
+SELECT COUNT(*) FROM testdb_wl5522.t1;
+
+perl;
+do "$ENV{MTR_SUITE_DIR}/include/innodb-util.pl";
+ib_backup_tablespaces("testdb_wl5522", "t1");
+EOF
+UNLOCK TABLES;
+
+DROP TABLE testdb_wl5522.t1;
+
+CREATE TABLE testdb_wl5522.t1 (
+col1 BIT(1),
+col2 BOOLEAN,
+col3 TINYINT,
+col4 SMALLINT,
+col5 MEDIUMINT,
+col6 INT,
+col7 BIGINT,
+col8 FLOAT (14,3) ,
+col9 DOUBLE (14,3),
+col10 VARCHAR(20),
+col11 TEXT,
+col12 ENUM('a','b','c'),
+col13 TEXT,
+col14 CHAR(20) ,
+col15 VARBINARY (400) ,
+col16 BINARY(40),
+col17 BLOB (400) ,
+col18 INT NOT NULL PRIMARY KEY,
+col19 DATE ,
+col20 DATETIME ,
+col21 TIMESTAMP ,
+col22 TIME,
+col23 YEAR ) ENGINE = Innodb;
+
+CREATE INDEX idx1 ON testdb_wl5522.t1(col18);
+CREATE INDEX prefix_idx ON testdb_wl5522.t1(col14 (10));
+CREATE UNIQUE INDEX idx2 ON testdb_wl5522.t1(col12);
+CREATE UNIQUE INDEX idx3 ON testdb_wl5522.t1(col8);
+
+ALTER TABLE testdb_wl5522.t1 DISCARD TABLESPACE;
+
+perl;
+do "$ENV{MTR_SUITE_DIR}/include/innodb-util.pl";
+ib_discard_tablespaces("testdb_wl5522", "t1");
+ib_restore_tablespaces("testdb_wl5522", "t1");
+EOF
+
+ALTER TABLE testdb_wl5522.t1 IMPORT TABLESPACE;
+CHECK TABLE testdb_wl5522.t1;
+
+SELECT COUNT(*) FROM testdb_wl5522.t1;
+
+DROP TABLE testdb_wl5522.t1;
+
+
+# case 3 - with blob objects
+
+CREATE TABLE testdb_wl5522.t1 (
+col_1_varbinary VARBINARY (4000) ,
+col_2_varchar VARCHAR (4000),
+col_3_text TEXT (4000),
+col_4_blob BLOB (4000),
+col_5_text TEXT (4000),
+col_6_varchar VARCHAR (4000),
+col_7_binary BINARY (255)
+) ROW_FORMAT=DYNAMIC ENGINE = Innodb;
+
+INSERT INTO testdb_wl5522.t1 VALUES(
+REPEAT('a', 4000),REPEAT('o', 4000),REPEAT('a', 4000), REPEAT('o', 4000),
+REPEAT('a', 4000),REPEAT('a', 4000),REPEAT('a', 255));
+
+SELECT col_1_varbinary = REPEAT("a", 4000),
+col_2_varchar = REPEAT("o", 4000) ,
+col_3_text = REPEAT("a", 4000) ,
+col_4_blob = REPEAT("o", 4000) ,
+col_5_text = REPEAT("a", 4000) ,
+col_6_varchar = REPEAT("a", 4000) ,
+col_7_binary = REPEAT("a", 255)
+FROM testdb_wl5522.t1;
+FLUSH TABLES testdb_wl5522.t1 FOR EXPORT;
+
+perl;
+do "$ENV{MTR_SUITE_DIR}/include/innodb-util.pl";
+ib_backup_tablespaces("testdb_wl5522", "t1");
+EOF
+
+UNLOCK TABLES;
+
+DROP TABLE testdb_wl5522.t1;
+
+CREATE TABLE testdb_wl5522.t1 (
+col_1_varbinary VARBINARY (4000) ,
+col_2_varchar VARCHAR (4000),
+col_3_text TEXT (4000),
+col_4_blob BLOB (4000),
+col_5_text TEXT (4000),
+col_6_varchar VARCHAR (4000),
+col_7_binary BINARY (255)
+) ROW_FORMAT=DYNAMIC ENGINE = Innodb;
+
+ALTER TABLE testdb_wl5522.t1 DISCARD TABLESPACE;
+
+perl;
+do "$ENV{MTR_SUITE_DIR}/include/innodb-util.pl";
+ib_discard_tablespaces("testdb_wl5522", "t1");
+ib_restore_tablespaces("testdb_wl5522", "t1");
+EOF
+
+ALTER TABLE testdb_wl5522.t1 IMPORT TABLESPACE;
+
+SELECT col_1_varbinary = REPEAT("a", 4000) ,
+col_2_varchar = REPEAT("o", 4000) ,
+col_3_text = REPEAT("a", 4000) ,
+col_4_blob = REPEAT("o", 4000) ,
+col_5_text = REPEAT("a", 4000) ,
+col_6_varchar = REPEAT("a", 4000) ,
+col_7_binary = REPEAT("a", 255)
+FROM testdb_wl5522.t1;
+
+DROP TABLE testdb_wl5522.t1;
+
+# case 4 - trasportable tablesace with autoincrement
+CREATE TABLE testdb_wl5522.t1 (
+col_1_int INT AUTO_INCREMENT,
+col_2_varchar VARCHAR (20),
+PRIMARY KEY (col_1_int)) ENGINE = Innodb;
+
+INSERT INTO testdb_wl5522.t1 VALUES (1,'a1'),(2,'a2'),(3,'a3');
+INSERT INTO testdb_wl5522.t1 (col_2_varchar) VALUES ('a4'),('a5'),('a6');
+
+SELECT * FROM testdb_wl5522.t1 ORDER BY col_1_int;
+FLUSH TABLES testdb_wl5522.t1 FOR EXPORT;
+
+perl;
+do "$ENV{MTR_SUITE_DIR}/include/innodb-util.pl";
+ib_backup_tablespaces("testdb_wl5522", "t1");
+EOF
+
+UNLOCK TABLES;
+
+DROP TABLE testdb_wl5522.t1;
+
+CREATE TABLE testdb_wl5522.t1 (
+col_1_int INT AUTO_INCREMENT,
+col_2_varchar VARCHAR (20),
+PRIMARY KEY (col_1_int)) ENGINE = Innodb;
+ALTER TABLE testdb_wl5522.t1 DISCARD TABLESPACE;
+
+
+perl;
+do "$ENV{MTR_SUITE_DIR}/include/innodb-util.pl";
+ib_discard_tablespaces("testdb_wl5522", "t1");
+ib_restore_tablespaces("testdb_wl5522", "t1");
+EOF
+
+ALTER TABLE testdb_wl5522.t1 IMPORT TABLESPACE;
+SELECT * FROM testdb_wl5522.t1 ORDER BY col_1_int;
+
+# error on inserting duplicate value
+--error 1062
+INSERT INTO testdb_wl5522.t1 VALUES (1,'a1');
+# insert new values
+INSERT INTO testdb_wl5522.t1(col_2_varchar) VALUES ('a101'),('a102'),('a103');
+SELECT * FROM testdb_wl5522.t1 ORDER BY col_1_int;
+# check table can be altered
+ALTER TABLE testdb_wl5522.t1 MODIFY col_1_int BIGINT;
+SELECT * FROM testdb_wl5522.t1 ORDER BY col_1_int;
+
+DROP TABLE testdb_wl5522.t1;
+
+# case 5 - check with primary and foreign key
+CREATE TABLE testdb_wl5522.t1 (
+col_1_int INT,col_2_varchar VARCHAR (20),
+PRIMARY KEY (col_2_varchar)) ENGINE = Innodb;
+
+CREATE TABLE testdb_wl5522.t1_fk (
+col_1_int INT,col_2_varchar VARCHAR (20),
+PRIMARY KEY (col_1_int),
+FOREIGN KEY (col_2_varchar) REFERENCES testdb_wl5522.t1(col_2_varchar)
+) ENGINE = Innodb;
+
+
+INSERT INTO testdb_wl5522.t1 VALUES (1,'a1'),(2,'a2'),(3,'a3'),(4,'a4'),(5,'a5');
+INSERT INTO testdb_wl5522.t1_fk VALUES (1,'a1'),(2,'a2'),(3,'a3');
+
+SELECT * FROM testdb_wl5522.t1;
+SELECT * FROM testdb_wl5522.t1_fk;
+FLUSH TABLES testdb_wl5522.t1,testdb_wl5522.t1_fk FOR EXPORT;
+
+perl;
+do "$ENV{MTR_SUITE_DIR}/include/innodb-util.pl";
+ib_backup_tablespaces("testdb_wl5522", "t1");
+ib_backup_tablespaces("testdb_wl5522", "t1_fk");
+EOF
+
+UNLOCK TABLES;
+
+DROP TABLE testdb_wl5522.t1_fk,testdb_wl5522.t1;
+
+CREATE TABLE testdb_wl5522.t1 (
+col_1_int INT,col_2_varchar VARCHAR (20),
+PRIMARY KEY (col_2_varchar)) ENGINE = Innodb;
+
+CREATE TABLE testdb_wl5522.t1_fk (
+col_1_int INT,col_2_varchar VARCHAR (20),
+PRIMARY KEY (col_1_int),
+FOREIGN KEY (col_2_varchar) REFERENCES testdb_wl5522.t1(col_2_varchar)
+) ENGINE = Innodb;
+
+# Alter table discrad table is not allowed with foreign_key_checks = 1
+SET foreign_key_checks = 0;
+ALTER TABLE testdb_wl5522.t1_fk DISCARD TABLESPACE;
+ALTER TABLE testdb_wl5522.t1 DISCARD TABLESPACE;
+SET foreign_key_checks = 1;
+
+
+perl;
+do "$ENV{MTR_SUITE_DIR}/include/innodb-util.pl";
+ib_discard_tablespaces("testdb_wl5522", "t1");
+ib_discard_tablespaces("testdb_wl5522", "t1_fk");
+ib_restore_tablespaces("testdb_wl5522", "t1");
+ib_restore_tablespaces("testdb_wl5522", "t1_fk");
+EOF
+
+ALTER TABLE testdb_wl5522.t1 IMPORT TABLESPACE;
+ALTER TABLE testdb_wl5522.t1_fk IMPORT TABLESPACE;
+SELECT * FROM testdb_wl5522.t1;
+SELECT * FROM testdb_wl5522.t1_fk;
+
+# Enter Invalid value: PK-FK relationship violation
+--error 1452
+INSERT INTO testdb_wl5522.t1_fk VALUES (100,'a100');
+
+SET AUTOCOMMIT = 0;
+INSERT INTO testdb_wl5522.t1_fk VALUES (4,'a4'),(5,'a5');
+ROLLBACK;
+SELECT * FROM testdb_wl5522.t1_fk;
+
+DROP TABLE testdb_wl5522.t1_fk,testdb_wl5522.t1;
+SET AUTOCOMMIT = 1;
+
+
+# case 6 - transporatbale tablespace with transactions
+CREATE TABLE testdb_wl5522.t1 (
+col_1_int int,col_2_varchar VARCHAR (20),
+PRIMARY KEY (col_2_varchar)) ENGINE = Innodb;
+SET AUTOCOMMIT = 0;
+INSERT INTO testdb_wl5522.t1 VALUES (1,'a1'),(2,'a2');
+SELECT * FROM testdb_wl5522.t1;
+COMMIT;
+INSERT INTO testdb_wl5522.t1 VALUES (3,'a3'),(4,'a4');
+ROLLBACK;
+INSERT INTO testdb_wl5522.t1 VALUES (5,'a5'),(6,'a6');
+COMMIT;
+SELECT * FROM testdb_wl5522.t1 ORDER BY col_1_int;
+FLUSH TABLES testdb_wl5522.t1 FOR EXPORT;
+
+perl;
+do "$ENV{MTR_SUITE_DIR}/include/innodb-util.pl";
+ib_backup_tablespaces("testdb_wl5522", "t1");
+EOF
+
+UNLOCK TABLES;
+
+DROP TABLE testdb_wl5522.t1;
+CREATE TABLE testdb_wl5522.t1 (
+col_1_int int,col_2_varchar VARCHAR (20),
+PRIMARY KEY (col_2_varchar)) ENGINE = Innodb;
+ALTER TABLE testdb_wl5522.t1 DISCARD TABLESPACE;
+SET AUTOCOMMIT = 0;
+
+perl;
+do "$ENV{MTR_SUITE_DIR}/include/innodb-util.pl";
+ib_discard_tablespaces("testdb_wl5522", "t1");
+ib_restore_tablespaces("testdb_wl5522", "t1");
+EOF
+
+ALTER TABLE testdb_wl5522.t1 IMPORT TABLESPACE;
+
+
+INSERT INTO testdb_wl5522.t1 VALUES (7,'a7'),(8,'a8');
+COMMIT;
+INSERT INTO testdb_wl5522.t1 VALUES (9,'a9'),(10,'a10');
+ROLLBACK;
+INSERT INTO testdb_wl5522.t1 VALUES (11,'a11'),(12,'a12');
+COMMIT;
+SELECT * FROM testdb_wl5522.t1 ORDER BY col_1_int;
+SET AUTOCOMMIT = 1;
+
+DROP TABLE testdb_wl5522.t1;
+
+#case 7 - transpotable tablespace with transaction(earlier failed with jet)
+
+CREATE TABLE testdb_wl5522.t1 ( i int ) ENGINE = Innodb;
+INSERT INTO testdb_wl5522.t1 VALUES (100),(200),(300);
+SELECT * FROM testdb_wl5522.t1 ORDER BY i;
+FLUSH TABLES testdb_wl5522.t1 FOR EXPORT;
+
+perl;
+do "$ENV{MTR_SUITE_DIR}/include/innodb-util.pl";
+ib_backup_tablespaces("testdb_wl5522", "t1");
+EOF
+
+UNLOCK TABLES;
+
+DROP TABLE testdb_wl5522.t1;
+CREATE TABLE testdb_wl5522.t1 ( i int ) ENGINE = Innodb;
+ALTER TABLE testdb_wl5522.t1 DISCARD TABLESPACE;
+
+
+perl;
+do "$ENV{MTR_SUITE_DIR}/include/innodb-util.pl";
+ib_discard_tablespaces("testdb_wl5522", "t1");
+ib_restore_tablespaces("testdb_wl5522", "t1");
+EOF
+
+ALTER TABLE testdb_wl5522.t1 IMPORT TABLESPACE;
+SELECT * FROM testdb_wl5522.t1 ORDER BY i;
+SET AUTOCOMMIT = 0;
+INSERT INTO testdb_wl5522.t1 VALUES (101),(102),(103);
+COMMIT;
+SELECT * FROM testdb_wl5522.t1 ORDER BY i;
+SET AUTOCOMMIT = 1;
+DROP TABLE testdb_wl5522.t1;
+
+
+# case 8 - negative cases
+CREATE TABLE testdb_wl5522.t1 ( i int ) ENGINE = Innodb;
+INSERT INTO testdb_wl5522.t1 VALUES (100),(200),(300);
+SELECT * FROM testdb_wl5522.t1 ORDER BY i;
+FLUSH TABLES testdb_wl5522.t1 FOR EXPORT;
+
+perl;
+do "$ENV{MTR_SUITE_DIR}/include/innodb-util.pl";
+ib_backup_tablespaces("testdb_wl5522", "t1");
+EOF
+
+UNLOCK TABLES;
+
+# try if we can flush again
+FLUSH TABLES testdb_wl5522.t1 FOR EXPORT;
+UNLOCK TABLES;
+
+DROP TABLE testdb_wl5522.t1;
+
+# create table with incorrect schema
+CREATE TABLE testdb_wl5522.t1 ( i bigint) ENGINE = Innodb;
+ALTER TABLE testdb_wl5522.t1 DISCARD TABLESPACE;
+
+perl;
+do "$ENV{MTR_SUITE_DIR}/include/innodb-util.pl";
+ib_discard_tablespaces("testdb_wl5522", "t1");
+ib_restore_tablespaces("testdb_wl5522", "t1");
+EOF
+
+# error as mismatch in column data type
+--error ER_TABLE_SCHEMA_MISMATCH
+ALTER TABLE testdb_wl5522.t1 IMPORT TABLESPACE;
+
+# explicilty delet idb file before creating table with correct schema
+perl;
+do "$ENV{MTR_SUITE_DIR}/include/innodb-util.pl";
+ib_unlink_tablespace("testdb_wl5522", "t1");
+EOF
+
+DROP TABLE testdb_wl5522.t1;
+
+CREATE TABLE testdb_wl5522.t1 ( i int ) ENGINE = Innodb;
+ALTER TABLE testdb_wl5522.t1 DISCARD TABLESPACE;
+
+perl;
+do "$ENV{MTR_SUITE_DIR}/include/innodb-util.pl";
+ib_discard_tablespaces("testdb_wl5522", "t1");
+ib_restore_tablespaces("testdb_wl5522", "t1");
+EOF
+
+# Import should succeed
+ALTER TABLE testdb_wl5522.t1 IMPORT TABLESPACE;
+# Try to import twice
+--error 1813
+ALTER TABLE testdb_wl5522.t1 IMPORT TABLESPACE;
+SELECT * FROM testdb_wl5522.t1 ORDER BY i;
+
+SET AUTOCOMMIT = 0;
+INSERT INTO testdb_wl5522.t1 VALUES (101),(102),(103);
+COMMIT;
+SELECT * FROM testdb_wl5522.t1 ORDER BY i;
+DROP TABLE testdb_wl5522.t1;
+CREATE TABLE testdb_wl5522.t1 (i int) ENGINE = Innodb;
+ALTER TABLE testdb_wl5522.t1 DISCARD TABLESPACE;
+# do not delete ibt file and try to import
+perl;
+do "$ENV{MTR_SUITE_DIR}/include/innodb-util.pl";
+ib_restore_tablespaces("testdb_wl5522", "t1");
+EOF
+#--error 1000
+ALTER TABLE testdb_wl5522.t1 IMPORT TABLESPACE;
+DROP TABLE testdb_wl5522.t1;
+SET AUTOCOMMIT = 1;
+
+
+# case 9 - empty table import
+CREATE TABLE testdb_wl5522.t1 (c1 INT ) ENGINE = Innodb;
+SET AUTOCOMMIT = 0;
+INSERT INTO testdb_wl5522.t1 VALUES (1),(123),(331);
+SELECT c1 FROM testdb_wl5522.t1;
+ROLLBACK;
+FLUSH TABLES testdb_wl5522.t1 FOR EXPORT;
+
+perl;
+do "$ENV{MTR_SUITE_DIR}/include/innodb-util.pl";
+ib_backup_tablespaces("testdb_wl5522", "t1");
+EOF
+
+UNLOCK TABLES;
+
+DROP TABLE testdb_wl5522.t1;
+CREATE TABLE testdb_wl5522.t1 (c1 INT ) ENGINE = Innodb;
+ALTER TABLE testdb_wl5522.t1 DISCARD TABLESPACE;
+
+
+perl;
+do "$ENV{MTR_SUITE_DIR}/include/innodb-util.pl";
+ib_discard_tablespaces("testdb_wl5522", "t1");
+ib_restore_tablespaces("testdb_wl5522", "t1");
+EOF
+
+ALTER TABLE testdb_wl5522.t1 IMPORT TABLESPACE;
+SELECT * FROM testdb_wl5522.t1 ORDER BY c1;
+DROP TABLE testdb_wl5522.t1;
+SET AUTOCOMMIT = 1;
+
+# case 10 - tt with prefix index
+
+CREATE TABLE testdb_wl5522.t1 (col_1 CHAR (255) ,
+col_2 VARCHAR (255), col_3 VARCHAR (255),
+col_4 VARCHAR (255),col_5 VARCHAR (255),
+col_6 text (255), col_7 text (255),
+col_8 text (255),col_9 text (255),
+col_10 BLOB (255),col_11 BLOB (255),
+col_12 BLOB (255), col_13 BLOB (255),
+col_14 BLOB (255) , col_15 int ) ENGINE = innodb;
+
+CREATE INDEX prefix_idx ON testdb_wl5522.t1(
+col_1 (50),col_2 (50),col_3 (50),
+col_4 (50),col_5 (50),col_6 (50),
+col_7 (50),col_8 (50),col_9 (50),
+col_10 (50),col_11 (50),col_12 (50),
+col_13(50));
+
+INSERT INTO testdb_wl5522.t1 VALUES (
+REPEAT("col1_00001",10),REPEAT("col2_00001",10),REPEAT("col3_00001",10),
+REPEAT("col4_00001",10),REPEAT("col5_00001",10),REPEAT("col6_00001",10),
+REPEAT("col7_00001",10),REPEAT("col8_00001",10),REPEAT("col9_00001",10),
+REPEAT("col10_00001",10),REPEAT("col11_00001",10),REPEAT("col12_00001",10),
+REPEAT("col13_00001",10),REPEAT("col14_00001",10),1);
+
+SELECT
+col_1 = REPEAT("col1_00001",10),
+col_2 = REPEAT("col2_00001",10),
+col_3 = REPEAT("col3_00001",10),
+col_4 = REPEAT("col4_00001",10),
+col_5 = REPEAT("col5_00001",10),
+col_6 = REPEAT("col6_00001",10),
+col_7 = REPEAT("col7_00001",10),
+col_8 = REPEAT("col8_00001",10),
+col_9 = REPEAT("col9_00001",10),
+col_10 = REPEAT("col10_00001",10),
+col_11 = REPEAT("col11_00001",10),
+col_12 = REPEAT("col12_00001",10),
+col_13 = REPEAT("col13_00001",10),
+col_14 = REPEAT("col14_00001",10),
+col_15
+FROM testdb_wl5522.t1;
+
+FLUSH TABLES testdb_wl5522.t1 FOR EXPORT;
+
+perl;
+do "$ENV{MTR_SUITE_DIR}/include/innodb-util.pl";
+ib_backup_tablespaces("testdb_wl5522", "t1");
+EOF
+
+UNLOCK TABLES;
+
+DROP TABLE testdb_wl5522.t1;
+
+CREATE TABLE testdb_wl5522.t1 (col_1 CHAR (255) ,
+col_2 VARCHAR (255), col_3 VARCHAR (255),
+col_4 VARCHAR (255),col_5 VARCHAR (255),
+col_6 text (255), col_7 text (255),
+col_8 text (255),col_9 text (255),
+col_10 BLOB (255),col_11 BLOB (255),
+col_12 BLOB (255), col_13 BLOB (255),
+col_14 BLOB (255) , col_15 int ) ENGINE = innodb;
+
+CREATE INDEX prefix_idx ON testdb_wl5522.t1(
+col_1 (50),col_2 (50),col_3 (50),
+col_4 (50),col_5 (50),col_6 (50),
+col_7 (50),col_8 (50),col_9 (50),
+col_10 (50),col_11 (50),col_12 (50),
+col_13(50));
+
+
+ALTER TABLE testdb_wl5522.t1 DISCARD TABLESPACE;
+
+
+perl;
+do "$ENV{MTR_SUITE_DIR}/include/innodb-util.pl";
+ib_discard_tablespaces("testdb_wl5522", "t1");
+ib_restore_tablespaces("testdb_wl5522", "t1");
+EOF
+
+ALTER TABLE testdb_wl5522.t1 IMPORT TABLESPACE;
+
+
+SELECT
+col_1 = REPEAT("col1_00001",10),
+col_2 = REPEAT("col2_00001",10),
+col_3 = REPEAT("col3_00001",10),
+col_4 = REPEAT("col4_00001",10),
+col_5 = REPEAT("col5_00001",10),
+col_6 = REPEAT("col6_00001",10),
+col_7 = REPEAT("col7_00001",10),
+col_8 = REPEAT("col8_00001",10),
+col_9 = REPEAT("col9_00001",10),
+col_10 = REPEAT("col10_00001",10),
+col_11 = REPEAT("col11_00001",10),
+col_12 = REPEAT("col12_00001",10),
+col_13 = REPEAT("col13_00001",10),
+col_14 = REPEAT("col14_00001",10),
+col_15
+FROM testdb_wl5522.t1;
+
+DROP TABLE testdb_wl5522.t1;
+
+
+# case 11 - tt with secondary index
+
+CREATE TABLE testdb_wl5522.t1 (col_1 CHAR (255) ,
+col_2 VARCHAR (255), col_3 VARCHAR (255),
+col_4 VARCHAR (255),col_5 VARCHAR (255),
+col_6 text (255), col_7 text (255),
+col_8 text (255),col_9 text (255),
+col_10 BLOB (255),col_11 BLOB (255),
+col_12 BLOB (255), col_13 BLOB (255),
+col_14 BLOB (255) , col_15 int ) ENGINE = innodb;
+
+CREATE INDEX idx1 ON testdb_wl5522.t1(col_1);
+CREATE INDEX idx2 ON testdb_wl5522.t1(col_2);
+CREATE INDEX idx3 ON testdb_wl5522.t1(col_3);
+CREATE INDEX idx4 ON testdb_wl5522.t1(col_4);
+CREATE INDEX idx5 ON testdb_wl5522.t1(col_5);
+CREATE INDEX idx6 ON testdb_wl5522.t1(col_6(255));
+CREATE INDEX idx7 ON testdb_wl5522.t1(col_7(255));
+CREATE INDEX idx8 ON testdb_wl5522.t1(col_8(255));
+CREATE INDEX idx9 ON testdb_wl5522.t1(col_9(255));
+CREATE INDEX idx10 ON testdb_wl5522.t1(col_10(255));
+CREATE INDEX idx11 ON testdb_wl5522.t1(col_11(255));
+CREATE INDEX idx12 ON testdb_wl5522.t1(col_12(255));
+CREATE INDEX idx13 ON testdb_wl5522.t1(col_13(255));
+CREATE INDEX idx14 ON testdb_wl5522.t1(col_14(255));
+
+INSERT INTO testdb_wl5522.t1 VALUES (
+REPEAT("col1_00001",10),REPEAT("col2_00001",10),REPEAT("col3_00001",10),
+REPEAT("col4_00001",10),REPEAT("col5_00001",10),REPEAT("col6_00001",10),
+REPEAT("col7_00001",10),REPEAT("col8_00001",10),REPEAT("col9_00001",10),
+REPEAT("col10_00001",10),REPEAT("col11_00001",10),REPEAT("col12_00001",10),
+REPEAT("col13_00001",10),REPEAT("col14_00001",10),1);
+
+SELECT
+col_1 = REPEAT("col1_00001",10),
+col_2 = REPEAT("col2_00001",10),
+col_3 = REPEAT("col3_00001",10),
+col_4 = REPEAT("col4_00001",10),
+col_5 = REPEAT("col5_00001",10),
+col_6 = REPEAT("col6_00001",10),
+col_7 = REPEAT("col7_00001",10),
+col_8 = REPEAT("col8_00001",10),
+col_9 = REPEAT("col9_00001",10),
+col_10 = REPEAT("col10_00001",10),
+col_11 = REPEAT("col11_00001",10),
+col_12 = REPEAT("col12_00001",10),
+col_13 = REPEAT("col13_00001",10),
+col_14 = REPEAT("col14_00001",10),
+col_15
+FROM testdb_wl5522.t1;
+
+FLUSH TABLES testdb_wl5522.t1 FOR EXPORT;
+
+perl;
+do "$ENV{MTR_SUITE_DIR}/include/innodb-util.pl";
+ib_backup_tablespaces("testdb_wl5522", "t1");
+EOF
+
+UNLOCK TABLES;
+
+DROP TABLE testdb_wl5522.t1;
+
+CREATE TABLE testdb_wl5522.t1 (col_1 CHAR (255) ,
+col_2 VARCHAR (255), col_3 VARCHAR (255),
+col_4 VARCHAR (255),col_5 VARCHAR (255),
+col_6 text (255), col_7 text (255),
+col_8 text (255),col_9 text (255),
+col_10 BLOB (255),col_11 BLOB (255),
+col_12 BLOB (255), col_13 BLOB (255),
+col_14 BLOB (255) , col_15 int ) ENGINE = innodb;
+
+CREATE INDEX idx1 ON testdb_wl5522.t1(col_1);
+CREATE INDEX idx2 ON testdb_wl5522.t1(col_2);
+CREATE INDEX idx3 ON testdb_wl5522.t1(col_3);
+CREATE INDEX idx4 ON testdb_wl5522.t1(col_4);
+CREATE INDEX idx5 ON testdb_wl5522.t1(col_5);
+CREATE INDEX idx6 ON testdb_wl5522.t1(col_6(255));
+CREATE INDEX idx7 ON testdb_wl5522.t1(col_7(255));
+CREATE INDEX idx8 ON testdb_wl5522.t1(col_8(255));
+CREATE INDEX idx9 ON testdb_wl5522.t1(col_9(255));
+CREATE INDEX idx10 ON testdb_wl5522.t1(col_10(255));
+CREATE INDEX idx11 ON testdb_wl5522.t1(col_11(255));
+CREATE INDEX idx12 ON testdb_wl5522.t1(col_12(255));
+CREATE INDEX idx13 ON testdb_wl5522.t1(col_13(255));
+CREATE INDEX idx14 ON testdb_wl5522.t1(col_14(255));
+
+ALTER TABLE testdb_wl5522.t1 DISCARD TABLESPACE;
+
+
+perl;
+do "$ENV{MTR_SUITE_DIR}/include/innodb-util.pl";
+ib_discard_tablespaces("testdb_wl5522", "t1");
+ib_restore_tablespaces("testdb_wl5522", "t1");
+EOF
+
+ALTER TABLE testdb_wl5522.t1 IMPORT TABLESPACE;
+
+SELECT
+col_1 = REPEAT("col1_00001",10),
+col_2 = REPEAT("col2_00001",10),
+col_3 = REPEAT("col3_00001",10),
+col_4 = REPEAT("col4_00001",10),
+col_5 = REPEAT("col5_00001",10),
+col_6 = REPEAT("col6_00001",10),
+col_7 = REPEAT("col7_00001",10),
+col_8 = REPEAT("col8_00001",10),
+col_9 = REPEAT("col9_00001",10),
+col_10 = REPEAT("col10_00001",10),
+col_11 = REPEAT("col11_00001",10),
+col_12 = REPEAT("col12_00001",10),
+col_13 = REPEAT("col13_00001",10),
+col_14 = REPEAT("col14_00001",10),
+col_15
+FROM testdb_wl5522.t1;
+
+# perform transaction on impoted table
+SET AUTOCOMMIT = 0;
+INSERT INTO testdb_wl5522.t1(col_15) VALUES (15000),(16000);
+SELECT col_15 FROM testdb_wl5522.t1 WHERE col_15 > 11000;
+ROLLBACK;
+SELECT col_15 FROM testdb_wl5522.t1 WHERE col_15 > 11000;
+INSERT INTO testdb_wl5522.t1(col_15) VALUES (15000),(16000);
+COMMIT;
+SELECT col_15 FROM testdb_wl5522.t1 WHERE col_15 > 11000;
+# dml
+ALTER TABLE testdb_wl5522.t1 DROP INDEX idx1;
+ALTER TABLE testdb_wl5522.t1 DROP INDEX idx6;
+ALTER TABLE testdb_wl5522.t1 DROP INDEX idx10;
+
+SELECT
+col_1 = REPEAT("col1_00001",10),
+col_2 = REPEAT("col2_00001",10),
+col_3 = REPEAT("col3_00001",10),
+col_4 = REPEAT("col4_00001",10),
+col_5 = REPEAT("col5_00001",10),
+col_6 = REPEAT("col6_00001",10),
+col_7 = REPEAT("col7_00001",10),
+col_8 = REPEAT("col8_00001",10),
+col_9 = REPEAT("col9_00001",10),
+col_10 = REPEAT("col10_00001",10),
+col_11 = REPEAT("col11_00001",10),
+col_12 = REPEAT("col12_00001",10),
+col_13 = REPEAT("col13_00001",10),
+col_14 = REPEAT("col14_00001",10),
+col_15
+FROM testdb_wl5522.t1;
+
+ALTER TABLE testdb_wl5522.t1 ADD INDEX idx1 (col_1);
+ALTER TABLE testdb_wl5522.t1 ADD INDEX idx6 (col_1(255));
+ALTER TABLE testdb_wl5522.t1 ADD INDEX idx10 (col_10(255));
+
+
+SELECT
+col_1 = REPEAT("col1_00001",10),
+col_2 = REPEAT("col2_00001",10),
+col_3 = REPEAT("col3_00001",10),
+col_4 = REPEAT("col4_00001",10),
+col_5 = REPEAT("col5_00001",10),
+col_6 = REPEAT("col6_00001",10),
+col_7 = REPEAT("col7_00001",10),
+col_8 = REPEAT("col8_00001",10),
+col_9 = REPEAT("col9_00001",10),
+col_10 = REPEAT("col10_00001",10),
+col_11 = REPEAT("col11_00001",10),
+col_12 = REPEAT("col12_00001",10),
+col_13 = REPEAT("col13_00001",10),
+col_14 = REPEAT("col14_00001",10),
+col_15
+FROM testdb_wl5522.t1;
+
+DROP TABLE testdb_wl5522.t1;
+SET AUTOCOMMIT = 1;
+
+# case 12 - tt with trigger / view
+
+CREATE TABLE testdb_wl5522.t1(col1 bit(1) ,
+col2 boolean,col3 tinyint , col4 smallint ,
+col5 mediumint ,col6 int , col7 bigint ,
+col8 float (14,3) ,col9 double (14,3),
+col10 VARCHAR(20) CHARACTER SET utf8 ,
+col11 TEXT CHARACTER SET binary ,
+col12 ENUM('a','b','c') CHARACTER SET binary,
+col13 TEXT CHARACTER SET latin1 COLLATE latin1_general_cs ,
+col14 CHAR(20) , col15 VARBINARY (400),
+col16 BINARY(40), col17 BLOB (400),
+col18 int not null primary key,
+col19 DATE ,col20 DATETIME , col21 TIMESTAMP ,
+col22 TIME , col23 YEAR ) ENGINE = Innodb;
+
+# table for trigger action
+CREATE TABLE testdb_wl5522.trigger_table ( i int ) ENGINE = Innodb;
+# define trigger
+CREATE TRIGGER testdb_wl5522.tri AFTER INSERT ON testdb_wl5522.t1
+FOR EACH ROW INSERT INTO testdb_wl5522.trigger_table VALUES(NEW.col18);
+# define view
+CREATE OR REPLACE VIEW testdb_wl5522.VW1 AS SELECT * FROM testdb_wl5522.t1;
+
+CREATE INDEX idx1 ON testdb_wl5522.t1(col18);
+CREATE INDEX prefix_idx ON testdb_wl5522.t1(col14 (10));
+CREATE UNIQUE INDEX idx2 ON testdb_wl5522.t1(col12);
+CREATE UNIQUE INDEX idx3 ON testdb_wl5522.t1(col8);
+
+
+INSERT INTO testdb_wl5522.t1 VALUES (
+1,1,-128,32767,-8388608,2147483647,-9223372036854775808,92233720368.222,
+-92233720368.222,'aaa','aaaaaaaaaa','b','bbbbb','ccccc',REPEAT('d',40),
+REPEAT('d',40),REPEAT('d',40),1,'1000-01-01','3000-12-31 23:59:59.99',
+'1990-01-01 00:00:01.00','01:59:59.00','1901');
+
+INSERT INTO testdb_wl5522.t1 VALUES (
+NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,
+NULL,NULL,3,NULL,NULL,NULL,NULL,NULL);
+
+
+--error 1048
+INSERT INTO testdb_wl5522.t1 VALUES (
+NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,
+NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL);
+
+--error 1062
+INSERT INTO testdb_wl5522.t1 VALUES (
+NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,
+NULL,NULL,1,NULL,NULL,NULL,NULL,NULL);
+
+SELECT COUNT(*) FROM testdb_wl5522.t1;
+SELECT * FROM testdb_wl5522.trigger_table;
+SELECT COUNT(*) FROM testdb_wl5522.VW1;
+FLUSH TABLES testdb_wl5522.t1 FOR EXPORT;
+
+perl;
+do "$ENV{MTR_SUITE_DIR}/include/innodb-util.pl";
+ib_backup_tablespaces("testdb_wl5522", "t1");
+EOF
+
+UNLOCK TABLES;
+
+# trigger is also dropped when table is dropped
+DROP TABLE testdb_wl5522.t1;
+
+CREATE TABLE testdb_wl5522.t1(col1 bit(1) ,
+col2 boolean,col3 tinyint , col4 smallint ,
+col5 mediumint ,col6 int , col7 bigint ,
+col8 float (14,3) ,col9 double (14,3),
+col10 VARCHAR(20) CHARACTER SET utf8 ,
+col11 TEXT CHARACTER SET binary ,
+col12 ENUM('a','b','c') CHARACTER SET binary,
+col13 TEXT CHARACTER SET latin1 COLLATE latin1_general_cs ,
+col14 CHAR(20) , col15 VARBINARY (400),
+col16 BINARY(40), col17 BLOB (400),
+col18 int not null primary key,
+col19 DATE ,col20 DATETIME , col21 TIMESTAMP ,
+col22 TIME , col23 YEAR ) ENGINE = Innodb;
+
+CREATE INDEX idx1 ON testdb_wl5522.t1(col18);
+CREATE INDEX prefix_idx ON testdb_wl5522.t1(col14 (10));
+CREATE UNIQUE INDEX idx2 ON testdb_wl5522.t1(col12);
+CREATE UNIQUE INDEX idx3 ON testdb_wl5522.t1(col8);
+
+
+ALTER TABLE testdb_wl5522.t1 DISCARD TABLESPACE;
+
+
+perl;
+do "$ENV{MTR_SUITE_DIR}/include/innodb-util.pl";
+ib_discard_tablespaces("testdb_wl5522", "t1");
+ib_restore_tablespaces("testdb_wl5522", "t1");
+EOF
+
+ALTER TABLE testdb_wl5522.t1 IMPORT TABLESPACE;
+
+SELECT COUNT(*) FROM testdb_wl5522.t1;
+SELECT * FROM testdb_wl5522.trigger_table;
+SELECT COUNT(*) FROM testdb_wl5522.VW1;
+
+# trigger table is not updated as trigger got dropped
+INSERT INTO testdb_wl5522.t1(col18) VALUES (5);
+# validate data in table not updated
+SELECT * FROM testdb_wl5522.trigger_table;
+
+UPDATE testdb_wl5522.t1 SET col18=10 WHERE col18=1;
+
+# view shows updated data
+SELECT COUNT(*) FROM testdb_wl5522.VW1;
+
+SELECT COUNT(*) FROM testdb_wl5522.t1 WHERE col18=10;
+ALTER TABLE testdb_wl5522.t1 ADD COLUMN col24 varbinary(40) default null;
+INSERT INTO testdb_wl5522.t1(col18,col24) VALUES (6,REPEAT('a',10));
+SELECT col24,col18 FROM testdb_wl5522.t1 WHERE col18 in (6,1,10) ORDER BY col18;
+ALTER TABLE testdb_wl5522.t1 DROP INDEX prefix_idx;
+SELECT col18,col14 FROM testdb_wl5522.t1 WHERE col14 like '_ccc%';
+ALTER TABLE testdb_wl5522.t1 ADD INDEX prefix_idx (col24(10));
+SELECT col18,col24 FROM testdb_wl5522.t1 WHERE col24 like '_a_a%';
+
+DROP TABLE testdb_wl5522.t1;
+
+DROP DATABASE testdb_wl5522;
+
+call mtr.add_suppression("Got error -1 when reading table '.*'");
+call mtr.add_suppression("InnoDB: Error: tablespace id and flags in file '.*'.*");
+call mtr.add_suppression("InnoDB: The table .* doesn't have a corresponding tablespace, it was discarded");
+
+# cleanup
+--remove_file $MYSQLTEST_VARDIR/tmp/t1.cfg
+--remove_file $MYSQLTEST_VARDIR/tmp/t1.ibd
+--remove_file $MYSQLTEST_VARDIR/tmp/t1_fk.cfg
+--remove_file $MYSQLTEST_VARDIR/tmp/t1_fk.ibd
+
+--echo #
+--echo # MDEV-27882 Innodb - recognise MySQL-8.0 innodb flags and give a specific error message
+--echo #
+--echo #
+
+CREATE TABLE `t1` (`i` int(11) NOT NULL, PRIMARY KEY (`i`) ) ENGINE=InnoDB;
+FLUSH TABLES t1 FOR EXPORT;
+
+# We use the cfg file of ours.
+perl;
+do "$ENV{MTR_SUITE_DIR}/include/innodb-util.pl";
+ib_backup_tablespaces("test", "t1");
+EOF
+
+UNLOCK TABLES;
+ALTER TABLE t1 DISCARD TABLESPACE;
+
+--move_file $MYSQLTEST_VARDIR/tmp/t1.cfg $MYSQLD_DATADIR/test/t1.cfg
+--copy_file std_data/mysql80/t1.ibd $MYSQLD_DATADIR/test/t1.ibd
+
+call mtr.add_suppression("InnoDB: unsupported MySQL tablespace");
+--error ER_UNSUPPORTED_EXTENSION
+ALTER TABLE t1 IMPORT TABLESPACE;
+
+DROP TABLE t1;
+--remove_file $MYSQLTEST_VARDIR/tmp/t1.ibd
+
+--echo #
+--echo # End of 10.3 tests
+--echo #
diff --git a/mysql-test/suite/innodb/t/innodb-wl5522-debug.test b/mysql-test/suite/innodb/t/innodb-wl5522-debug.test
new file mode 100644
index 00000000..e642a949
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb-wl5522-debug.test
@@ -0,0 +1,1401 @@
+# mysql-test-run.pl --embedded cannot restart the server.
+--source include/not_embedded.inc
+
+# Adding big test option for this test.
+--source include/big_test.inc
+
+# This test case needs to crash the server. Needs a debug server.
+--source include/have_debug.inc
+
+# Don't test this under valgrind, memory leaks will occur.
+--source include/not_valgrind.inc
+
+# Avoid CrashReporter popup on Mac
+--source include/not_crashrep.inc
+
+--source include/have_innodb.inc
+--source include/default_charset.inc
+--source include/have_sequence.inc
+
+let $restart_noprint=2;
+call mtr.add_suppression("InnoDB: Operating system error number .* in a file operation.");
+call mtr.add_suppression("InnoDB: Error number \\d+ means");
+call mtr.add_suppression("InnoDB: Cannot open datafile for read-only: .*");
+call mtr.add_suppression("InnoDB: Ignoring tablespace .* because it could not be opened.");
+call mtr.add_suppression("InnoDB: Tablespace for table .* is set as discarded.");
+call mtr.add_suppression("InnoDB: Cannot calculate statistics for table .*");
+call mtr.add_suppression("InnoDB: Page 0 at offset 0 looks corrupted in file");
+call mtr.add_suppression("InnoDB: Page for tablespace ");
+call mtr.add_suppression("InnoDB: Invalid FSP_SPACE_FLAGS=");
+call mtr.add_suppression("InnoDB: Unknown index id .* on page");
+call mtr.add_suppression("InnoDB: Cannot save statistics for table `test`\\.`t1` because the \\.ibd file is missing");
+call mtr.add_suppression("InnoDB: Database page corruption on disk or a failed read of file '.*ibdata1' page");
+call mtr.add_suppression("InnoDB: File '.*ibdata1' is corrupted");
+FLUSH TABLES;
+
+let MYSQLD_DATADIR =`SELECT @@datadir`;
+let $strerrfix=/ (\(.+\))//;
+SET GLOBAL innodb_file_per_table = 1;
+
+CREATE TABLE t1 (c1 INT) ENGINE = InnoDB;
+INSERT INTO t1 VALUES(1),(2),(3);
+
+--let $_expect_file_name= `select regexp_replace(@@tmpdir, '^.*/','')`
+--let $_expect_file_name= $MYSQLTEST_VARDIR/tmp/$_expect_file_name.expect
+
+--exec echo wait > $_expect_file_name
+SET SESSION debug_dbug="+d,ib_discard_before_commit_crash";
+--error 2013
+ALTER TABLE t1 DISCARD TABLESPACE;
+
+--source include/start_mysqld.inc
+
+DROP TABLE t1;
+
+SET GLOBAL innodb_file_per_table = 1;
+
+CREATE TABLE t1 (c1 INT) ENGINE = InnoDB;
+INSERT INTO t1 VALUES(1),(2),(3);
+
+--exec echo wait > $_expect_file_name
+SET SESSION debug_dbug="+d,ib_discard_after_commit_crash";
+--error 2013
+ALTER TABLE t1 DISCARD TABLESPACE;
+
+--source include/start_mysqld.inc
+
+DROP TABLE t1;
+
+SET GLOBAL innodb_file_per_table = 1;
+
+# Create the table that we will use for crash recovery (during IMPORT)
+CREATE TABLE t1 (c1 INT) ENGINE = Innodb;
+INSERT INTO t1 VALUES (1), (2), (3), (4);
+
+--replace_regex /, .*\).*t1.cfg/, Bad file descriptor) t1.cfg/
+
+FLUSH TABLES t1 FOR EXPORT;
+
+perl;
+do "$ENV{MTR_SUITE_DIR}/include/innodb-util.pl";
+ib_backup_tablespaces("test", "t1");
+EOF
+UNLOCK TABLES;
+
+DROP TABLE t1;
+
+CREATE TABLE t1 (c1 INT) ENGINE = Innodb;
+INSERT INTO t1 VALUES (1);
+
+ALTER TABLE t1 DISCARD TABLESPACE;
+
+--error ER_TABLESPACE_DISCARDED
+SELECT COUNT(*) FROM t1;
+
+# Restore files
+perl;
+do "$ENV{MTR_SUITE_DIR}/include/innodb-util.pl";
+ib_restore_tablespaces("test", "t1");
+EOF
+
+--error ER_TABLESPACE_DISCARDED
+SELECT * FROM t1;
+
+--exec echo wait > $_expect_file_name
+SET SESSION debug_dbug="+d,ib_import_before_commit_crash";
+--error 2013
+ALTER TABLE t1 IMPORT TABLESPACE;
+
+--source include/start_mysqld.inc
+
+# Check that the DD is consistent after recovery
+
+--error ER_TABLESPACE_DISCARDED
+SELECT COUNT(*) FROM t1;
+
+--exec echo wait > $_expect_file_name
+SET SESSION debug_dbug="+d,ib_import_before_checkpoint_crash";
+--error 2013
+ALTER TABLE t1 IMPORT TABLESPACE;
+
+# After the above test the results are non-deterministic,
+# delete the old tablespace files and drop the table,
+# recreate the table and do a proper import.
+perl;
+do "$ENV{MTR_SUITE_DIR}/include/innodb-util.pl";
+ib_unlink_tablespace("test", "t1");
+EOF
+
+--source include/start_mysqld.inc
+
+DROP TABLE t1;
+
+SET @file_per_table= @@innodb_file_per_table;
+SET GLOBAL innodb_file_per_table = 1;
+
+CREATE TABLE t1 (c1 INT) ENGINE = Innodb;
+
+ALTER TABLE t1 DISCARD TABLESPACE;
+
+perl;
+do "$ENV{MTR_SUITE_DIR}/include/innodb-util.pl";
+ib_restore_tablespaces("test", "t1");
+EOF
+
+ALTER TABLE t1 IMPORT TABLESPACE;
+CHECK TABLE t1;
+
+SELECT COUNT(*) FROM t1;
+
+INSERT INTO t1 VALUES(400), (500), (600);
+
+SELECT * FROM t1;
+
+DROP TABLE t1;
+
+# Test IO Write error(s), flush tables doesn't return an error message
+# so we have to make do with the error/warning pushed by the server
+CREATE TABLE t1 (c1 INT) ENGINE = Innodb;
+INSERT INTO t1 VALUES (1);
+
+SET @saved_debug_dbug = @@SESSION.debug_dbug;
+SET SESSION debug_dbug="+d,ib_export_io_write_failure_1";
+
+--replace_regex /, .*\).*t1.cfg/, Bad file descriptor) t1.cfg/
+
+FLUSH TABLES t1 FOR EXPORT;
+
+UNLOCK TABLES;
+
+SET SESSION debug_dbug=@saved_debug_dbug;
+
+DROP TABLE t1;
+
+
+CREATE TABLE t1 (c1 INT) ENGINE = Innodb;
+INSERT INTO t1 VALUES (1);
+
+SET SESSION debug_dbug="+d,ib_export_io_write_failure_2";
+
+--replace_regex /, .*\).*t1.cfg/, Bad file descriptor) t1.cfg/
+
+FLUSH TABLES t1 FOR EXPORT;
+
+UNLOCK TABLES;
+
+SET SESSION debug_dbug=@saved_debug_dbug;
+
+DROP TABLE t1;
+
+CREATE TABLE t1 (c1 INT) ENGINE = Innodb;
+INSERT INTO t1 VALUES (1);
+
+SET SESSION debug_dbug="+d,ib_export_io_write_failure_3";
+
+--replace_regex /, .*\).*t1.cfg/, Bad file descriptor) t1.cfg/
+
+FLUSH TABLES t1 FOR EXPORT;
+
+UNLOCK TABLES;
+
+SET SESSION debug_dbug=@saved_debug_dbug;
+
+DROP TABLE t1;
+
+CREATE TABLE t1 (c1 INT) ENGINE = Innodb;
+INSERT INTO t1 VALUES (1);
+
+SET SESSION debug_dbug="+d,ib_export_io_write_failure_4";
+
+--replace_regex /, .*\).*t1.cfg/, Bad file descriptor) t1.cfg/
+
+FLUSH TABLES t1 FOR EXPORT;
+
+UNLOCK TABLES;
+
+SET SESSION debug_dbug=@saved_debug_dbug;
+
+DROP TABLE t1;
+
+CREATE TABLE t1 (c1 INT) ENGINE = Innodb;
+INSERT INTO t1 VALUES (1);
+
+SET SESSION debug_dbug="+d,ib_export_io_write_failure_5";
+
+--replace_regex /, .*\).*t1.cfg/, Bad file descriptor) t1.cfg/
+
+FLUSH TABLES t1 FOR EXPORT;
+
+UNLOCK TABLES;
+
+SET SESSION debug_dbug=@saved_debug_dbug;
+
+DROP TABLE t1;
+
+
+CREATE TABLE t1 (c1 INT) ENGINE = Innodb;
+INSERT INTO t1 VALUES (1);
+
+SET SESSION debug_dbug="+d,ib_export_io_write_failure_6";
+
+--replace_regex /, .*\).*t1.cfg/, Bad file descriptor) t1.cfg/
+
+FLUSH TABLES t1 FOR EXPORT;
+
+UNLOCK TABLES;
+
+SET SESSION debug_dbug=@saved_debug_dbug;
+
+DROP TABLE t1;
+
+
+CREATE TABLE t1 (c1 INT) ENGINE = Innodb;
+INSERT INTO t1 VALUES (1);
+
+SET SESSION debug_dbug="+d,ib_export_io_write_failure_7";
+
+--replace_regex /, .*\).*t1.cfg/, Bad file descriptor) t1.cfg/
+
+FLUSH TABLES t1 FOR EXPORT;
+
+UNLOCK TABLES;
+
+SET SESSION debug_dbug=@saved_debug_dbug;
+
+DROP TABLE t1;
+
+
+CREATE TABLE t1 (c1 INT) ENGINE = Innodb;
+INSERT INTO t1 VALUES (1);
+
+SET SESSION debug_dbug="+d,ib_export_io_write_failure_8";
+
+--replace_regex /, .*\).*t1.cfg/, Bad file descriptor) t1.cfg/
+
+FLUSH TABLES t1 FOR EXPORT;
+
+UNLOCK TABLES;
+
+SET SESSION debug_dbug=@saved_debug_dbug;
+
+DROP TABLE t1;
+
+CREATE TABLE t1 (c1 INT) ENGINE = Innodb;
+INSERT INTO t1 VALUES (1);
+
+SET SESSION debug_dbug="+d,ib_export_io_write_failure_9";
+
+--replace_regex /, .*\).*t1.cfg/, Bad file descriptor) t1.cfg/
+
+FLUSH TABLES t1 FOR EXPORT;
+
+UNLOCK TABLES;
+
+SET SESSION debug_dbug=@saved_debug_dbug;
+
+DROP TABLE t1;
+
+
+CREATE TABLE t1 (c1 INT) ENGINE = Innodb;
+INSERT INTO t1 VALUES (1);
+
+SET SESSION debug_dbug="+d,ib_export_io_write_failure_10";
+
+--replace_regex /, .*\).*t1.cfg/, Bad file descriptor) t1.cfg/
+
+FLUSH TABLES t1 FOR EXPORT;
+
+UNLOCK TABLES;
+
+SET SESSION debug_dbug=@saved_debug_dbug;
+
+DROP TABLE t1;
+
+
+CREATE TABLE t1 (c1 INT) ENGINE = Innodb;
+INSERT INTO t1 VALUES (1);
+
+SET SESSION debug_dbug="+d,ib_export_io_write_failure_11";
+
+--replace_regex /, .*\).*t1.cfg/, Bad file descriptor) t1.cfg/
+
+FLUSH TABLES t1 FOR EXPORT;
+
+UNLOCK TABLES;
+
+SET SESSION debug_dbug=@saved_debug_dbug;
+
+DROP TABLE t1;
+
+
+CREATE TABLE t1 (c1 INT) ENGINE = Innodb;
+INSERT INTO t1 VALUES (1);
+
+SET SESSION debug_dbug="+d,ib_export_io_write_failure_12";
+
+--replace_regex /, .*\).*t1.cfg/, Bad file descriptor) t1.cfg/
+
+FLUSH TABLES t1 FOR EXPORT;
+
+UNLOCK TABLES;
+
+SET SESSION debug_dbug=@saved_debug_dbug;
+
+DROP TABLE t1;
+
+# Create a table and save the tablespace and .cfg file
+CREATE TABLE t1 (c1 INT) ENGINE = Innodb;
+INSERT INTO t1 VALUES (100), (200), (300);
+SELECT COUNT(*) FROM t1;
+FLUSH TABLES t1 FOR EXPORT;
+
+perl;
+do "$ENV{MTR_SUITE_DIR}/include/innodb-util.pl";
+ib_backup_tablespaces("test", "t1");
+EOF
+
+UNLOCK TABLES;
+
+DROP TABLE t1;
+
+# Test IO Read error(s)
+CREATE TABLE t1 (c1 INT) ENGINE = Innodb;
+INSERT INTO t1 VALUES (1);
+
+ALTER TABLE t1 DISCARD TABLESPACE;
+
+--error ER_TABLESPACE_DISCARDED
+SELECT COUNT(*) FROM t1;
+
+SET SESSION debug_dbug="+d,ib_import_io_read_error_1";
+
+perl;
+do "$ENV{MTR_SUITE_DIR}/include/innodb-util.pl";
+ib_restore_cfg_files("test", "t1");
+EOF
+
+--replace_regex $strerrfix
+
+--error ER_IO_READ_ERROR
+ALTER TABLE t1 IMPORT TABLESPACE;
+
+SET SESSION debug_dbug=@saved_debug_dbug;
+
+DROP TABLE t1;
+
+CREATE TABLE t1 (c1 INT) ENGINE = Innodb;
+INSERT INTO t1 VALUES (1);
+
+ALTER TABLE t1 DISCARD TABLESPACE;
+
+--error ER_TABLESPACE_DISCARDED
+SELECT COUNT(*) FROM t1;
+
+SET SESSION debug_dbug="+d,ib_import_io_read_error_2";
+
+perl;
+do "$ENV{MTR_SUITE_DIR}/include/innodb-util.pl";
+ib_restore_cfg_files("test", "t1");
+EOF
+
+--replace_regex $strerrfix
+
+--error ER_IO_READ_ERROR
+ALTER TABLE t1 IMPORT TABLESPACE;
+
+SET SESSION debug_dbug=@saved_debug_dbug;
+
+DROP TABLE t1;
+
+CREATE TABLE t1 (c1 INT) ENGINE = Innodb;
+INSERT INTO t1 VALUES (1);
+
+ALTER TABLE t1 DISCARD TABLESPACE;
+
+--error ER_TABLESPACE_DISCARDED
+SELECT COUNT(*) FROM t1;
+
+SET SESSION debug_dbug="+d,ib_import_io_read_error_3";
+
+perl;
+do "$ENV{MTR_SUITE_DIR}/include/innodb-util.pl";
+ib_restore_cfg_files("test", "t1");
+EOF
+
+--replace_regex $strerrfix
+
+--error ER_IO_READ_ERROR
+ALTER TABLE t1 IMPORT TABLESPACE;
+
+SET SESSION debug_dbug=@saved_debug_dbug;
+
+DROP TABLE t1;
+
+CREATE TABLE t1 (c1 INT) ENGINE = Innodb;
+INSERT INTO t1 VALUES (1);
+
+ALTER TABLE t1 DISCARD TABLESPACE;
+
+--error ER_TABLESPACE_DISCARDED
+SELECT COUNT(*) FROM t1;
+
+SET SESSION debug_dbug="+d,ib_import_io_read_error_4";
+
+perl;
+do "$ENV{MTR_SUITE_DIR}/include/innodb-util.pl";
+ib_restore_cfg_files("test", "t1");
+EOF
+
+--replace_regex $strerrfix
+
+--error ER_IO_READ_ERROR
+ALTER TABLE t1 IMPORT TABLESPACE;
+
+SET SESSION debug_dbug=@saved_debug_dbug;
+
+DROP TABLE t1;
+
+CREATE TABLE t1 (c1 INT) ENGINE = Innodb;
+INSERT INTO t1 VALUES (1);
+
+ALTER TABLE t1 DISCARD TABLESPACE;
+
+--error ER_TABLESPACE_DISCARDED
+SELECT COUNT(*) FROM t1;
+
+SET SESSION debug_dbug="+d,ib_import_io_read_error_5";
+
+perl;
+do "$ENV{MTR_SUITE_DIR}/include/innodb-util.pl";
+ib_restore_cfg_files("test", "t1");
+EOF
+
+--replace_regex $strerrfix
+
+--error ER_IO_READ_ERROR
+ALTER TABLE t1 IMPORT TABLESPACE;
+
+SET SESSION debug_dbug=@saved_debug_dbug;
+
+DROP TABLE t1;
+
+CREATE TABLE t1 (c1 INT) ENGINE = Innodb;
+INSERT INTO t1 VALUES (1);
+
+ALTER TABLE t1 DISCARD TABLESPACE;
+
+--error ER_TABLESPACE_DISCARDED
+SELECT COUNT(*) FROM t1;
+
+SET SESSION debug_dbug="+d,ib_import_io_read_error_6";
+
+perl;
+do "$ENV{MTR_SUITE_DIR}/include/innodb-util.pl";
+ib_restore_cfg_files("test", "t1");
+EOF
+
+--replace_regex $strerrfix
+
+--error ER_IO_READ_ERROR
+ALTER TABLE t1 IMPORT TABLESPACE;
+
+SET SESSION debug_dbug=@saved_debug_dbug;
+
+DROP TABLE t1;
+
+CREATE TABLE t1 (c1 INT) ENGINE = Innodb;
+INSERT INTO t1 VALUES (1);
+
+ALTER TABLE t1 DISCARD TABLESPACE;
+
+--error ER_TABLESPACE_DISCARDED
+SELECT COUNT(*) FROM t1;
+
+SET SESSION debug_dbug="+d,ib_import_io_read_error_7";
+
+perl;
+do "$ENV{MTR_SUITE_DIR}/include/innodb-util.pl";
+ib_restore_cfg_files("test", "t1");
+EOF
+
+--replace_regex $strerrfix
+
+--error ER_IO_READ_ERROR
+ALTER TABLE t1 IMPORT TABLESPACE;
+
+SET SESSION debug_dbug=@saved_debug_dbug;
+
+DROP TABLE t1;
+
+CREATE TABLE t1 (c1 INT) ENGINE = Innodb;
+INSERT INTO t1 VALUES (1);
+
+ALTER TABLE t1 DISCARD TABLESPACE;
+
+--error ER_TABLESPACE_DISCARDED
+SELECT COUNT(*) FROM t1;
+
+SET SESSION debug_dbug="+d,ib_import_io_read_error_8";
+
+perl;
+do "$ENV{MTR_SUITE_DIR}/include/innodb-util.pl";
+ib_restore_cfg_files("test", "t1");
+EOF
+
+--replace_regex $strerrfix
+
+--error ER_IO_READ_ERROR
+ALTER TABLE t1 IMPORT TABLESPACE;
+
+SET SESSION debug_dbug=@saved_debug_dbug;
+
+DROP TABLE t1;
+
+CREATE TABLE t1 (c1 INT) ENGINE = Innodb;
+INSERT INTO t1 VALUES (1);
+
+ALTER TABLE t1 DISCARD TABLESPACE;
+
+--error ER_TABLESPACE_DISCARDED
+SELECT COUNT(*) FROM t1;
+
+SET SESSION debug_dbug="+d,ib_import_io_read_error_9";
+
+perl;
+do "$ENV{MTR_SUITE_DIR}/include/innodb-util.pl";
+ib_restore_cfg_files("test", "t1");
+EOF
+
+--replace_regex $strerrfix
+
+--error ER_IO_READ_ERROR
+ALTER TABLE t1 IMPORT TABLESPACE;
+
+SET SESSION debug_dbug=@saved_debug_dbug;
+
+DROP TABLE t1;
+
+# Test string read failure
+CREATE TABLE t1 (c1 INT) ENGINE = Innodb;
+INSERT INTO t1 VALUES (1);
+
+ALTER TABLE t1 DISCARD TABLESPACE;
+
+--error ER_TABLESPACE_DISCARDED
+SELECT COUNT(*) FROM t1;
+
+SET SESSION debug_dbug="+d,ib_import_string_read_error";
+
+perl;
+do "$ENV{MTR_SUITE_DIR}/include/innodb-util.pl";
+ib_restore_cfg_files("test", "t1");
+EOF
+
+--replace_regex $strerrfix
+
+--error ER_IO_READ_ERROR
+ALTER TABLE t1 IMPORT TABLESPACE;
+
+SET SESSION debug_dbug=@saved_debug_dbug;
+
+DROP TABLE t1;
+
+# Test OOM error during import
+
+CREATE TABLE t1 (c1 INT) ENGINE = Innodb;
+INSERT INTO t1 VALUES (1);
+
+ALTER TABLE t1 DISCARD TABLESPACE;
+
+--error ER_TABLESPACE_DISCARDED
+SELECT COUNT(*) FROM t1;
+
+# Restore files
+perl;
+do "$ENV{MTR_SUITE_DIR}/include/innodb-util.pl";
+ib_restore_tablespaces("test", "t1");
+EOF
+
+SET SESSION debug_dbug="+d,ib_import_OOM_1";
+
+--replace_regex /'.*t1.cfg'/'t1.cfg'/
+
+--error ER_OUT_OF_RESOURCES
+ALTER TABLE t1 IMPORT TABLESPACE;
+
+SET SESSION debug_dbug=@saved_debug_dbug;
+
+DROP TABLE t1;
+
+
+perl;
+do "$ENV{MTR_SUITE_DIR}/include/innodb-util.pl";
+ib_unlink_tablespace("test", "t1");
+EOF
+
+
+CREATE TABLE t1 (c1 INT) ENGINE = Innodb;
+INSERT INTO t1 VALUES (1);
+
+ALTER TABLE t1 DISCARD TABLESPACE;
+
+--error ER_TABLESPACE_DISCARDED
+SELECT COUNT(*) FROM t1;
+
+# Restore files
+perl;
+do "$ENV{MTR_SUITE_DIR}/include/innodb-util.pl";
+ib_restore_tablespaces("test", "t1");
+EOF
+
+SET SESSION debug_dbug="+d,ib_import_OOM_2";
+
+--replace_regex /'.*t1.cfg'/'t1.cfg'/
+
+--error ER_OUT_OF_RESOURCES
+ALTER TABLE t1 IMPORT TABLESPACE;
+
+SET SESSION debug_dbug=@saved_debug_dbug;
+
+DROP TABLE t1;
+
+
+perl;
+do "$ENV{MTR_SUITE_DIR}/include/innodb-util.pl";
+ib_unlink_tablespace("test", "t1");
+EOF
+
+
+CREATE TABLE t1 (c1 INT) ENGINE = Innodb;
+INSERT INTO t1 VALUES (1);
+
+ALTER TABLE t1 DISCARD TABLESPACE;
+
+--error ER_TABLESPACE_DISCARDED
+SELECT COUNT(*) FROM t1;
+
+# Restore files
+perl;
+do "$ENV{MTR_SUITE_DIR}/include/innodb-util.pl";
+ib_restore_tablespaces("test", "t1");
+EOF
+
+SET SESSION debug_dbug="+d,ib_import_OOM_4";
+
+--replace_regex /'.*t1.cfg'/'t1.cfg'/
+
+--error ER_OUT_OF_RESOURCES
+ALTER TABLE t1 IMPORT TABLESPACE;
+
+SET SESSION debug_dbug=@saved_debug_dbug;
+
+DROP TABLE t1;
+
+
+perl;
+do "$ENV{MTR_SUITE_DIR}/include/innodb-util.pl";
+ib_unlink_tablespace("test", "t1");
+EOF
+
+
+CREATE TABLE t1 (c1 INT) ENGINE = Innodb;
+INSERT INTO t1 VALUES (1);
+
+ALTER TABLE t1 DISCARD TABLESPACE;
+
+--error ER_TABLESPACE_DISCARDED
+SELECT COUNT(*) FROM t1;
+
+# Restore files
+perl;
+do "$ENV{MTR_SUITE_DIR}/include/innodb-util.pl";
+ib_restore_tablespaces("test", "t1");
+EOF
+
+SET SESSION debug_dbug="+d,ib_import_OOM_5";
+
+--replace_regex /'.*t1.cfg'/'t1.cfg'/
+
+--error ER_OUT_OF_RESOURCES
+ALTER TABLE t1 IMPORT TABLESPACE;
+
+SET SESSION debug_dbug=@saved_debug_dbug;
+
+DROP TABLE t1;
+
+
+perl;
+do "$ENV{MTR_SUITE_DIR}/include/innodb-util.pl";
+ib_unlink_tablespace("test", "t1");
+EOF
+
+CREATE TABLE t1 (c1 INT) ENGINE = Innodb;
+INSERT INTO t1 VALUES (1);
+
+ALTER TABLE t1 DISCARD TABLESPACE;
+
+--error ER_TABLESPACE_DISCARDED
+SELECT COUNT(*) FROM t1;
+
+# Restore files
+perl;
+do "$ENV{MTR_SUITE_DIR}/include/innodb-util.pl";
+ib_restore_tablespaces("test", "t1");
+EOF
+
+SET SESSION debug_dbug="+d,ib_import_OOM_6";
+
+--replace_regex /'.*t1.cfg'/'t1.cfg'/
+
+--error ER_OUT_OF_RESOURCES
+ALTER TABLE t1 IMPORT TABLESPACE;
+
+SET SESSION debug_dbug=@saved_debug_dbug;
+
+DROP TABLE t1;
+
+perl;
+do "$ENV{MTR_SUITE_DIR}/include/innodb-util.pl";
+ib_unlink_tablespace("test", "t1");
+EOF
+
+CREATE TABLE t1 (c1 INT) ENGINE = Innodb;
+INSERT INTO t1 VALUES (1);
+
+ALTER TABLE t1 DISCARD TABLESPACE;
+
+--error ER_TABLESPACE_DISCARDED
+SELECT COUNT(*) FROM t1;
+
+# Restore files
+perl;
+do "$ENV{MTR_SUITE_DIR}/include/innodb-util.pl";
+ib_restore_tablespaces("test", "t1");
+EOF
+
+SET SESSION debug_dbug="+d,ib_import_OOM_7";
+
+--replace_regex /'.*t1.cfg'/'t1.cfg'/
+
+--error ER_OUT_OF_RESOURCES
+ALTER TABLE t1 IMPORT TABLESPACE;
+
+SET SESSION debug_dbug=@saved_debug_dbug;
+
+DROP TABLE t1;
+
+perl;
+do "$ENV{MTR_SUITE_DIR}/include/innodb-util.pl";
+ib_unlink_tablespace("test", "t1");
+EOF
+
+CREATE TABLE t1 (c1 INT) ENGINE = Innodb;
+INSERT INTO t1 VALUES (1);
+
+ALTER TABLE t1 DISCARD TABLESPACE;
+
+--error ER_TABLESPACE_DISCARDED
+SELECT COUNT(*) FROM t1;
+
+# Restore files
+perl;
+do "$ENV{MTR_SUITE_DIR}/include/innodb-util.pl";
+ib_restore_tablespaces("test", "t1");
+EOF
+
+SET SESSION debug_dbug="+d,ib_import_OOM_8";
+
+--replace_regex /'.*t1.cfg'/'t1.cfg'/
+
+--error ER_OUT_OF_RESOURCES
+ALTER TABLE t1 IMPORT TABLESPACE;
+
+SET SESSION debug_dbug=@saved_debug_dbug;
+
+DROP TABLE t1;
+
+perl;
+do "$ENV{MTR_SUITE_DIR}/include/innodb-util.pl";
+ib_unlink_tablespace("test", "t1");
+EOF
+
+CREATE TABLE t1 (c1 INT) ENGINE = Innodb;
+INSERT INTO t1 VALUES (1);
+
+ALTER TABLE t1 DISCARD TABLESPACE;
+
+--error ER_TABLESPACE_DISCARDED
+SELECT COUNT(*) FROM t1;
+
+# Restore files
+perl;
+do "$ENV{MTR_SUITE_DIR}/include/innodb-util.pl";
+ib_restore_tablespaces("test", "t1");
+EOF
+
+SET SESSION debug_dbug="+d,ib_import_OOM_9";
+
+--replace_regex /'.*t1.cfg'/'t1.cfg'/
+
+--error ER_OUT_OF_RESOURCES
+ALTER TABLE t1 IMPORT TABLESPACE;
+
+SET SESSION debug_dbug=@saved_debug_dbug;
+
+DROP TABLE t1;
+
+perl;
+do "$ENV{MTR_SUITE_DIR}/include/innodb-util.pl";
+ib_unlink_tablespace("test", "t1");
+EOF
+
+CREATE TABLE t1 (c1 INT) ENGINE = Innodb;
+INSERT INTO t1 VALUES (1);
+
+ALTER TABLE t1 DISCARD TABLESPACE;
+
+--error ER_TABLESPACE_DISCARDED
+SELECT COUNT(*) FROM t1;
+
+# Restore files
+perl;
+do "$ENV{MTR_SUITE_DIR}/include/innodb-util.pl";
+ib_restore_tablespaces("test", "t1");
+EOF
+
+SET SESSION debug_dbug="+d,ib_import_OOM_10";
+
+--replace_regex /'.*t1.cfg'/'t1.cfg'/
+
+--error ER_OUT_OF_RESOURCES
+ALTER TABLE t1 IMPORT TABLESPACE;
+
+SET SESSION debug_dbug=@saved_debug_dbug;
+
+DROP TABLE t1;
+
+perl;
+do "$ENV{MTR_SUITE_DIR}/include/innodb-util.pl";
+ib_unlink_tablespace("test", "t1");
+EOF
+
+####
+# Test handling of internal failure error
+CREATE TABLE t1 (c1 INT) ENGINE = Innodb;
+
+ALTER TABLE t1 DISCARD TABLESPACE;
+
+--error ER_TABLESPACE_DISCARDED
+SELECT COUNT(*) FROM t1;
+
+# Restore files
+perl;
+do "$ENV{MTR_SUITE_DIR}/include/innodb-util.pl";
+ib_restore_tablespaces("test", "t1");
+EOF
+
+# Test failure after reset of space id and LSN in the tablespace
+SET SESSION debug_dbug="+d,ib_import_internal_error";
+
+--replace_regex /'.*t1.cfg'/'t1.cfg'/
+
+--error ER_INTERNAL_ERROR
+ALTER TABLE t1 IMPORT TABLESPACE;
+
+SET SESSION debug_dbug=@saved_debug_dbug;
+
+# Restore files
+perl;
+do "$ENV{MTR_SUITE_DIR}/include/innodb-util.pl";
+ib_restore_tablespaces("test", "t1");
+EOF
+
+ALTER TABLE t1 IMPORT TABLESPACE;
+
+DROP TABLE t1;
+
+
+# Test failure after reset of space id and LSN in the tablespace
+CREATE TABLE t1 (c1 INT) ENGINE = Innodb;
+
+ALTER TABLE t1 DISCARD TABLESPACE;
+
+--error ER_TABLESPACE_DISCARDED
+SELECT COUNT(*) FROM t1;
+
+# Restore files
+perl;
+do "$ENV{MTR_SUITE_DIR}/include/innodb-util.pl";
+ib_restore_tablespaces("test", "t1");
+EOF
+
+# Test failure after reset of space id and LSN in the tablespace
+SET SESSION debug_dbug="+d,ib_import_reset_space_and_lsn_failure";
+
+--replace_regex /'.*t1.cfg'/'t1.cfg'/
+
+--error ER_INTERNAL_ERROR
+ALTER TABLE t1 IMPORT TABLESPACE;
+
+# Restore files
+perl;
+do "$ENV{MTR_SUITE_DIR}/include/innodb-util.pl";
+ib_restore_tablespaces("test", "t1");
+EOF
+
+SET SESSION debug_dbug=@saved_debug_dbug;
+
+# Test failure after attempting a tablespace open
+SET SESSION debug_dbug="+d,ib_import_open_tablespace_failure";
+
+--replace_result \\ /
+--error ER_GET_ERRMSG
+ALTER TABLE t1 IMPORT TABLESPACE;
+
+SET SESSION debug_dbug=@saved_debug_dbug;
+
+# Restore files
+perl;
+do "$ENV{MTR_SUITE_DIR}/include/innodb-util.pl";
+ib_restore_tablespaces("test", "t1");
+EOF
+
+# Test failure after ibuf check
+SET SESSION debug_dbug="+d,ib_import_check_bitmap_failure";
+
+# Need proper mapping of error codes :-(
+--error ER_NOT_KEYFILE
+ALTER TABLE t1 IMPORT TABLESPACE;
+
+SET SESSION debug_dbug=@saved_debug_dbug;
+
+# Restore files
+perl;
+do "$ENV{MTR_SUITE_DIR}/include/innodb-util.pl";
+ib_restore_tablespaces("test", "t1");
+EOF
+
+# Test failure after adjusting the cluster index root page
+SET SESSION debug_dbug="+d,ib_import_cluster_root_adjust_failure";
+
+--error ER_NOT_KEYFILE
+ALTER TABLE t1 IMPORT TABLESPACE;
+
+SET SESSION debug_dbug=@saved_debug_dbug;
+
+# Restore files
+perl;
+do "$ENV{MTR_SUITE_DIR}/include/innodb-util.pl";
+ib_restore_tablespaces("test", "t1");
+EOF
+
+# Test failure after importing the cluster index
+SET SESSION debug_dbug="+d,ib_import_cluster_failure";
+
+--error ER_NOT_KEYFILE
+ALTER TABLE t1 IMPORT TABLESPACE;
+
+SET SESSION debug_dbug=@saved_debug_dbug;
+
+# Restore files
+perl;
+do "$ENV{MTR_SUITE_DIR}/include/innodb-util.pl";
+ib_restore_tablespaces("test", "t1");
+EOF
+
+# Test failure after importing the secondary index(es)
+SET SESSION debug_dbug="+d,ib_import_sec_root_adjust_failure";
+
+--error ER_NOT_KEYFILE
+ALTER TABLE t1 IMPORT TABLESPACE;
+
+SET SESSION debug_dbug=@saved_debug_dbug;
+
+# Restore files
+perl;
+do "$ENV{MTR_SUITE_DIR}/include/innodb-util.pl";
+ib_restore_tablespaces("test", "t1");
+EOF
+
+ALTER TABLE t1 IMPORT TABLESPACE;
+DROP TABLE t1;
+
+#
+# Create a large table with delete marked records, disable purge during
+# the update so that we can test the IMPORT purge code.
+#
+CREATE TABLE t1 (
+ c1 BIGINT NOT NULL AUTO_INCREMENT PRIMARY KEY,
+ c2 BIGINT,
+ c3 VARCHAR(2048),
+ c4 VARCHAR(2048),
+ INDEX idx1(c2),
+ INDEX idx2(c3(512)),
+ INDEX idx3(c4(512))) Engine=InnoDB;
+
+# Stop purge so that it doesn't remove the delete marked entries.
+connect (purge_control,localhost,root);
+START TRANSACTION WITH CONSISTENT SNAPSHOT;
+connection default;
+
+INSERT INTO t1
+SELECT 1 + seq, 1 + (seq MOD 4),
+ REPEAT(SUBSTR('abcd', 1 + (seq MOD 4), 1), 2048),
+ REPEAT(SUBSTR('abcd', 1 + (seq MOD 4), 1), 2048)
+FROM seq_0_to_127;
+
+UPDATE t1 SET c2 = c2 + c1;
+UPDATE t1 SET c2 = c2 + c1;
+UPDATE t1 SET c2 = c2 + c1;
+UPDATE t1 SET c2 = c2 + c1;
+UPDATE t1 SET c2 = c2 + c1;
+UPDATE t1 SET c2 = c2 + c1;
+UPDATE t1 SET c2 = c2 + c1;
+UPDATE t1 SET c2 = c2 + c1;
+UPDATE t1 SET c2 = c2 + c1;
+UPDATE t1 SET c2 = c2 + c1;
+UPDATE t1 SET c2 = c2 + c1;
+UPDATE t1 SET c2 = c2 + c1;
+UPDATE t1 SET c2 = c2 + c1;
+UPDATE t1 SET c2 = c2 + c1;
+UPDATE t1 SET c2 = c2 + c1;
+UPDATE t1 SET c3 = REPEAT("c2", 1024);
+UPDATE t1 SET c4 = REPEAT("c4", 1024);
+
+SHOW CREATE TABLE t1;
+
+SELECT c1, c2 FROM t1;
+SELECT COUNT(*) FROM t1;
+SELECT SUM(c2) FROM t1;
+
+FLUSH TABLES t1 FOR EXPORT;
+
+perl;
+do "$ENV{MTR_SUITE_DIR}/include/innodb-util.pl";
+ib_backup_tablespaces("test", "t1");
+EOF
+
+UNLOCK TABLES;
+
+# Enable normal operation
+connection purge_control;
+COMMIT;
+disconnect purge_control;
+connection default;
+
+DROP TABLE t1;
+
+CREATE TABLE t1 (
+ c1 BIGINT NOT NULL AUTO_INCREMENT PRIMARY KEY,
+ c2 BIGINT,
+ c3 VARCHAR(2048),
+ c4 VARCHAR(2048),
+ INDEX idx1(c2),
+ INDEX idx2(c3(512)),
+ INDEX idx3(c4(512))) Engine=InnoDB;
+
+SELECT c1, c2 FROM t1;
+
+ALTER TABLE t1 DISCARD TABLESPACE;
+
+perl;
+do "$ENV{MTR_SUITE_DIR}/include/innodb-util.pl";
+ib_restore_tablespaces("test", "t1");
+EOF
+
+ALTER TABLE t1 IMPORT TABLESPACE;
+CHECK TABLE t1;
+
+SELECT c1,c2 FROM t1;
+SELECT COUNT(*) FROM t1;
+SELECT SUM(c2) FROM t1;
+
+SHOW CREATE TABLE t1;
+
+DROP TABLE t1;
+
+####
+# Create a table and save the tablespace and .cfg file, we need to create
+# a Btree that has several levels
+CREATE TABLE t1 (c1 INT, c2 VARCHAR(1024), c3 BLOB) ENGINE = Innodb;
+
+INSERT IGNORE INTO t1 VALUES
+ (100, REPEAT('Karanbir', 899), REPEAT('Ajeeth', 2731));
+
+INSERT INTO t1
+SELECT 100, REPEAT('Karanbir', 128), REPEAT('Ajeeth', 1200)
+FROM seq_1_to_256;
+FLUSH TABLES t1 FOR EXPORT;
+
+perl;
+do "$ENV{MTR_SUITE_DIR}/include/innodb-util.pl";
+ib_backup_tablespaces("test", "t1");
+EOF
+
+UNLOCK TABLES;
+
+DROP TABLE t1;
+
+CREATE TABLE t1 (c1 INT, c2 VARCHAR(1024), c3 BLOB) ENGINE = Innodb;
+
+ALTER TABLE t1 DISCARD TABLESPACE;
+
+--error ER_TABLESPACE_DISCARDED
+SELECT COUNT(*) FROM t1;
+
+# Restore files
+perl;
+do "$ENV{MTR_SUITE_DIR}/include/innodb-util.pl";
+ib_restore_tablespaces("test", "t1");
+EOF
+
+SET SESSION debug_dbug="+d,ib_import_trigger_corruption_1";
+
+--replace_regex /'.*t1.cfg'/'t1.cfg'/
+
+--error ER_INTERNAL_ERROR
+ALTER TABLE t1 IMPORT TABLESPACE;
+
+SET SESSION debug_dbug=@saved_debug_dbug;
+
+DROP TABLE t1;
+
+perl;
+do "$ENV{MTR_SUITE_DIR}/include/innodb-util.pl";
+ib_unlink_tablespace("test", "t1");
+EOF
+
+#
+
+CREATE TABLE t1 (c1 INT, c2 VARCHAR(1024), c3 BLOB) ENGINE = Innodb;
+
+ALTER TABLE t1 DISCARD TABLESPACE;
+
+--error ER_TABLESPACE_DISCARDED
+SELECT COUNT(*) FROM t1;
+
+# Restore files
+let INNODB_PAGE_SIZE=`select @@innodb_page_size`;
+
+perl;
+do "$ENV{MTR_SUITE_DIR}/include/innodb-util.pl";
+ib_restore_tablespaces("test", "t1");
+my $page;
+my $ps = $ENV{INNODB_PAGE_SIZE};
+my $file = "$ENV{MYSQLD_DATADIR}/test/t1.ibd";
+open(FILE, "+<$file") || die "Unable to open $file";
+binmode FILE;
+sysseek(FILE, 3*$ps, 0) || die "Unable to seek $file\n";
+die "Unable to read $file" unless sysread(FILE, $page, $ps) == $ps;
+substr($page,24,2)='42';
+sysseek(FILE, 3*$ps, 0) || die "Unable to rewind $file\n";
+syswrite(FILE, $page, $ps)==$ps || die "Unable to write $file\n";
+close(FILE) || die "Unable to close $file";
+EOF
+
+--replace_regex /'.*t1.cfg'/'t1.cfg'/
+
+--error ER_NOT_KEYFILE
+ALTER TABLE t1 IMPORT TABLESPACE;
+
+DROP TABLE t1;
+
+perl;
+do "$ENV{MTR_SUITE_DIR}/include/innodb-util.pl";
+ib_unlink_tablespace("test", "t1");
+EOF
+
+#
+CREATE TABLE t1 (c1 INT, c2 VARCHAR(1024), c3 BLOB) ENGINE = Innodb;
+
+ALTER TABLE t1 DISCARD TABLESPACE;
+
+--error ER_TABLESPACE_DISCARDED
+SELECT COUNT(*) FROM t1;
+
+# Restore files
+perl;
+do "$ENV{MTR_SUITE_DIR}/include/innodb-util.pl";
+ib_restore_tablespaces("test", "t1");
+EOF
+
+SET SESSION debug_dbug="+d,ib_import_trigger_corruption_2";
+
+--error ER_INNODB_INDEX_CORRUPT
+ALTER TABLE t1 IMPORT TABLESPACE;
+
+SET SESSION debug_dbug=@saved_debug_dbug;
+
+DROP TABLE t1;
+
+perl;
+do "$ENV{MTR_SUITE_DIR}/include/innodb-util.pl";
+ib_unlink_tablespace("test", "t1");
+EOF
+#
+
+CREATE TABLE t1 (c1 INT, c2 VARCHAR(1024), c3 BLOB) ENGINE = Innodb;
+
+ALTER TABLE t1 DISCARD TABLESPACE;
+
+--error ER_TABLESPACE_DISCARDED
+SELECT COUNT(*) FROM t1;
+
+# Restore files
+perl;
+do "$ENV{MTR_SUITE_DIR}/include/innodb-util.pl";
+ib_restore_tablespaces("test", "t1");
+EOF
+
+SET SESSION debug_dbug="+d,ib_import_trigger_corruption_3";
+
+--error ER_NOT_KEYFILE
+ALTER TABLE t1 IMPORT TABLESPACE;
+
+SET SESSION debug_dbug=@saved_debug_dbug;
+
+DROP TABLE t1;
+
+perl;
+do "$ENV{MTR_SUITE_DIR}/include/innodb-util.pl";
+ib_unlink_tablespace("test", "t1");
+EOF
+
+CREATE TABLE t1 (c1 INT, c2 VARCHAR(1024), c3 BLOB) ENGINE = Innodb;
+
+SET SESSION debug_dbug="+d,ib_import_create_index_failure_1";
+
+--error ER_RECORD_FILE_FULL
+ALTER TABLE t1 ADD INDEX idx(c1);
+
+SET SESSION debug_dbug=@saved_debug_dbug;
+
+ALTER TABLE t1 DISCARD TABLESPACE;
+
+--error ER_TABLESPACE_DISCARDED
+SELECT COUNT(*) FROM t1;
+
+ALTER TABLE t1 ADD INDEX idx(c1);
+
+DROP TABLE t1;
+
+perl;
+do "$ENV{MTR_SUITE_DIR}/include/innodb-util.pl";
+ib_unlink_tablespace("test", "t1");
+EOF
+
+#
+
+CREATE TABLE t1 (c1 INT, c2 VARCHAR(1024), c3 BLOB) ENGINE = Innodb;
+
+ALTER TABLE t1 DISCARD TABLESPACE;
+
+--error ER_TABLESPACE_DISCARDED
+SELECT COUNT(*) FROM t1;
+
+# Restore files
+perl;
+do "$ENV{MTR_SUITE_DIR}/include/innodb-util.pl";
+ib_restore_tablespaces("test", "t1");
+EOF
+
+SET SESSION debug_dbug="+d,fil_space_create_failure";
+
+--replace_result \\ /
+--error ER_GET_ERRMSG
+ALTER TABLE t1 IMPORT TABLESPACE;
+
+SET SESSION debug_dbug=@saved_debug_dbug;
+
+DROP TABLE t1;
+
+perl;
+do "$ENV{MTR_SUITE_DIR}/include/innodb-util.pl";
+ib_unlink_tablespace("test", "t1");
+EOF
+
+#
+
+CREATE TABLE t1 (c1 INT, c2 VARCHAR(1024), c3 BLOB) ENGINE = Innodb;
+
+ALTER TABLE t1 DISCARD TABLESPACE;
+
+--error ER_TABLESPACE_DISCARDED
+SELECT COUNT(*) FROM t1;
+
+# Restore files
+perl;
+do "$ENV{MTR_SUITE_DIR}/include/innodb-util.pl";
+ib_restore_tablespaces("test", "t1");
+EOF
+
+SET SESSION debug_dbug="+d,dict_tf_to_fsp_flags_failure";
+
+--replace_result \\ /
+--error ER_GET_ERRMSG
+ALTER TABLE t1 IMPORT TABLESPACE;
+
+SET SESSION debug_dbug=@saved_debug_dbug;
+
+DROP TABLE t1;
+
+perl;
+do "$ENV{MTR_SUITE_DIR}/include/innodb-util.pl";
+ib_unlink_tablespace("test", "t1");
+EOF
+
+#
+
+CREATE TABLE t1 (c1 INT, c2 VARCHAR(1024), c3 BLOB) ENGINE = Innodb;
+
+ALTER TABLE t1 DISCARD TABLESPACE;
+
+--error ER_TABLESPACE_DISCARDED
+SELECT COUNT(*) FROM t1;
+
+# Restore files
+perl;
+do "$ENV{MTR_SUITE_DIR}/include/innodb-util.pl";
+ib_restore_tablespaces("test", "t1");
+EOF
+
+SET SESSION debug_dbug="+d,fsp_flags_is_valid_failure";
+
+--replace_regex /'.*t1.cfg'/'t1.cfg'/
+
+--error ER_NOT_KEYFILE
+ALTER TABLE t1 IMPORT TABLESPACE;
+
+SET SESSION debug_dbug=@saved_debug_dbug;
+
+DROP TABLE t1;
+
+perl;
+do "$ENV{MTR_SUITE_DIR}/include/innodb-util.pl";
+ib_unlink_tablespace("test", "t1");
+EOF
+
+--disable_query_log
+call mtr.add_suppression("InnoDB: The log sequence numbers [0-9]+ and [0-9]+ in ibdata files do not match the log sequence number [0-9]+ in the ib_logfiles!");
+call mtr.add_suppression("'Resource temporarily unavailable'");
+call mtr.add_suppression("Got error -1 when reading table '.*'");
+call mtr.add_suppression("InnoDB: Table '.*' tablespace is set as discarded.");
+call mtr.add_suppression("InnoDB: Tablespace '.*' exists in the cache.*");
+call mtr.add_suppression("InnoDB: Freeing existing tablespace '.*' entry from the cache with id.*");
+call mtr.add_suppression("InnoDB: The table .* doesn't have a corresponding tablespace, it was discarded");
+call mtr.add_suppression(".*There was an error writing to the meta data file.*");
+call mtr.add_suppression("InnoDB: Trying to import a tablespace, but could not open the tablespace file");
+call mtr.add_suppression("Unsupported tablespace format");
+call mtr.add_suppression("Page is marked as free");
+call mtr.add_suppression("t1.ibd: Page .* at offset .* looks corrupted");
+call mtr.add_suppression("but tablespace with that id or name does not exist");
+call mtr.add_suppression("Could not find a valid tablespace file for '.*t1'");
+call mtr.add_suppression("while reading index meta-data, expected to read 44 bytes but read only 0 bytes");
+call mtr.add_suppression("Index for table 't1' is corrupt; try to repair it");
+--enable_query_log
+
+#cleanup
+--remove_file $MYSQLTEST_VARDIR/tmp/t1.cfg
+--remove_file $MYSQLTEST_VARDIR/tmp/t1.ibd
+
+SET GLOBAL INNODB_FILE_PER_TABLE=@file_per_table;
diff --git a/mysql-test/suite/innodb/t/innodb-wl5522.test b/mysql-test/suite/innodb/t/innodb-wl5522.test
new file mode 100644
index 00000000..8eedb636
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb-wl5522.test
@@ -0,0 +1,1116 @@
+# Not supported in embedded
+--source include/not_embedded.inc
+
+-- source include/have_innodb.inc
+-- source include/have_sequence.inc
+-- source include/innodb_checksum_algorithm.inc
+
+call mtr.add_suppression("InnoDB: Unable to import tablespace .* because it already exists. Please DISCARD the tablespace before IMPORT\\.");
+call mtr.add_suppression("Index for table 't2' is corrupt; try to repair it");
+call mtr.add_suppression("InnoDB: Cannot save statistics for table `test`\\.`t1` because the \\.ibd file is missing");
+
+FLUSH TABLES;
+
+let $MYSQLD_DATADIR = `SELECT @@datadir`;
+let $checksum_algorithm = `SELECT @@innodb_checksum_algorithm`;
+
+CREATE TABLE t1
+(a INT AUTO_INCREMENT PRIMARY KEY,
+ b char(22),
+ c varchar(255),
+ KEY (b))
+ENGINE = InnoDB;
+
+CREATE TEMPORARY TABLE t (b char(22),c varchar(255));
+INSERT INTO t VALUES
+('Apa', 'Filler........'),
+('Banan', 'Filler........'), ('Cavalry', '..asdasdfaeraf'),
+('Devotion', 'asdfuihknaskdf'), ('Evolution', 'lsjndofiabsoibeg');
+
+INSERT INTO t1 (b,c) SELECT b,c FROM t,seq_1_to_128;
+DROP TEMPORARY TABLE t;
+SELECT COUNT(*) FROM t1;
+SELECT * FROM t1 ORDER BY b,a DESC LIMIT 3;
+SELECT * FROM t1 ORDER BY a DESC LIMIT 3;
+
+CREATE TABLE t2(a INT PRIMARY KEY) ENGINE=InnoDB ROW_FORMAT=COMPACT;
+
+--list_files $MYSQLD_DATADIR/test
+--source include/restart_mysqld.inc
+FLUSH TABLE t1, t2 FOR EXPORT;
+--echo # List before copying files
+--list_files $MYSQLD_DATADIR/test
+--copy_file $MYSQLD_DATADIR/test/t1.cfg $MYSQLD_DATADIR/test/t1.cfg.sav
+--copy_file $MYSQLD_DATADIR/test/t1.ibd $MYSQLD_DATADIR/test/t1.ibd.sav
+--move_file $MYSQLD_DATADIR/test/t2.cfg $MYSQLD_DATADIR/test/t2.cfg.sav
+--copy_file $MYSQLD_DATADIR/test/t2.ibd $MYSQLD_DATADIR/test/t2.ibd.sav
+UNLOCK TABLES;
+INSERT INTO t1 (b, c) SELECT b,c FROM t1 ORDER BY a;
+SELECT COUNT(*) FROM t1;
+SELECT * FROM t1 ORDER BY b,a DESC LIMIT 3;
+SELECT * FROM t1 ORDER BY a DESC LIMIT 3;
+--echo # Restarting server
+-- source include/restart_mysqld.inc
+--echo # Done restarting server
+--echo # List before t1 DISCARD
+--list_files $MYSQLD_DATADIR/test
+ALTER TABLE t1 DISCARD TABLESPACE;
+--echo # List after t1 DISCARD
+--list_files $MYSQLD_DATADIR/test
+--copy_file $MYSQLD_DATADIR/test/t1.cfg.sav $MYSQLD_DATADIR/test/t1.cfg
+--copy_file $MYSQLD_DATADIR/test/t1.ibd.sav $MYSQLD_DATADIR/test/t1.ibd
+ALTER TABLE t1 IMPORT TABLESPACE;
+ALTER TABLE t1 ENGINE InnoDB;
+SELECT COUNT(*) FROM t1;
+SELECT * FROM t1 ORDER BY b,a DESC LIMIT 3;
+SELECT * FROM t1 ORDER BY a DESC LIMIT 3;
+--list_files $MYSQLD_DATADIR/test
+SELECT COUNT(*) FROM t1;
+SELECT * FROM t1 ORDER BY b,a DESC LIMIT 3;
+SELECT * FROM t1 ORDER BY a DESC LIMIT 3;
+DROP TABLE t1;
+--remove_file $MYSQLD_DATADIR/test/t1.cfg.sav
+--remove_file $MYSQLD_DATADIR/test/t1.ibd.sav
+
+ALTER TABLE t2 ROW_FORMAT=DYNAMIC;
+ALTER TABLE t2 DISCARD TABLESPACE;
+--echo # List after t2 DISCARD
+--list_files $MYSQLD_DATADIR/test
+--move_file $MYSQLD_DATADIR/test/t2.ibd.sav $MYSQLD_DATADIR/test/t2.ibd
+--move_file $MYSQLD_DATADIR/test/t2.cfg.sav $MYSQLD_DATADIR/test/t2.cfg
+--error ER_TABLE_SCHEMA_MISMATCH
+ALTER TABLE t2 IMPORT TABLESPACE;
+--remove_file $MYSQLD_DATADIR/test/t2.cfg
+
+let $error_code = ER_TABLE_SCHEMA_MISMATCH;
+
+if ($checksum_algorithm == "full_crc32") {
+ let $error_code = 0;
+}
+
+if ($checksum_algorithm == "strict_full_crc32") {
+ let $error_code = 0;
+}
+
+--replace_regex /(FSP_SPACE_FLAGS=0x)[0-9a-f]+(,.*0x)[0-9a-f]+(.*)/\1*\2*\3/
+--error $error_code
+ALTER TABLE t2 IMPORT TABLESPACE;
+DROP TABLE t2;
+
+SET GLOBAL innodb_file_per_table = 1;
+SELECT @@innodb_file_per_table;
+
+let MYSQLD_DATADIR =`SELECT @@datadir`;
+
+# Try importing when tablespace already exists
+CREATE TABLE t1(
+ c1 INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
+ c2 INT) ENGINE=InnoDB;
+
+INSERT INTO t1(c2) VALUES(1);
+--error ER_TABLESPACE_EXISTS
+ALTER TABLE t1 IMPORT TABLESPACE;
+SELECT * FROM t1;
+DROP TABLE t1;
+
+# Export/import on the same instance, with --innodb-file-per-table=1
+CREATE TABLE t1(
+ c1 INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
+ c2 INT) ENGINE=InnoDB;
+
+INSERT INTO t1 SELECT seq,1 FROM seq_1_to_16;
+
+--list_files $MYSQLD_DATADIR/test
+
+FLUSH TABLES t1 FOR EXPORT;
+perl;
+do "$ENV{MTR_SUITE_DIR}/include/innodb-util.pl";
+ib_backup_tablespaces("test", "t1");
+EOF
+
+--list_files $MYSQLD_DATADIR/test
+
+UNLOCK TABLES;
+
+DROP TABLE t1;
+
+CREATE TABLE t1(
+ c1 INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
+ c2 INT) ENGINE=InnoDB;
+
+ALTER TABLE t1 DISCARD TABLESPACE;
+--error ER_TABLESPACE_DISCARDED
+SELECT * FROM t1;
+
+perl;
+do "$ENV{MTR_SUITE_DIR}/include/innodb-util.pl";
+ib_discard_tablespaces("test", "t1");
+ib_restore_tablespaces("test", "t1");
+EOF
+
+--list_files $MYSQLD_DATADIR/test
+
+ALTER TABLE t1 IMPORT TABLESPACE;
+CHECK TABLE t1;
+
+SELECT COUNT(*) FROM t1;
+
+DROP TABLE t1;
+
+# Export/import on the same instance, with --innodb-file-per-table=1
+# Insert some more records to move the LSN forward and then drop the
+# table and restore
+CREATE TABLE t1(
+ c1 INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
+ c2 INT) ENGINE=InnoDB;
+
+INSERT INTO t1 SELECT seq,1 FROM seq_1_to_16;
+
+--list_files $MYSQLD_DATADIR/test
+FLUSH TABLES t1 FOR EXPORT;
+perl;
+do "$ENV{MTR_SUITE_DIR}/include/innodb-util.pl";
+ib_backup_tablespaces("test", "t1");
+EOF
+--list_files $MYSQLD_DATADIR/test
+UNLOCK TABLES;
+
+--list_files $MYSQLD_DATADIR/test
+
+# Move the LSN forward
+DROP TABLE t1;
+
+CREATE TABLE t1(
+ c1 INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
+ c2 INT) ENGINE=InnoDB;
+
+ALTER TABLE t1 DISCARD TABLESPACE;
+--error ER_TABLESPACE_DISCARDED
+SELECT * FROM t1;
+
+perl;
+do "$ENV{MTR_SUITE_DIR}/include/innodb-util.pl";
+ib_discard_tablespaces("test", "t1");
+ib_restore_tablespaces("test", "t1");
+EOF
+
+--list_files $MYSQLD_DATADIR/test
+
+ALTER TABLE t1 IMPORT TABLESPACE;
+CHECK TABLE t1;
+
+SELECT COUNT(*) FROM t1;
+
+DROP TABLE t1;
+
+# Export/import on the same instance, with --innodb-file-per-table=1
+# Insert some more records to move the LSN forward and then drop the
+# table and restore, this time the table has a secondary index too.
+CREATE TABLE t1(
+ c1 INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
+ c2 INT, INDEX(c2)) ENGINE=InnoDB;
+
+INSERT INTO t1 SELECT seq,1 FROM seq_1_to_16;
+
+FLUSH TABLES t1 FOR EXPORT;
+perl;
+do "$ENV{MTR_SUITE_DIR}/include/innodb-util.pl";
+ib_backup_tablespaces("test", "t1");
+EOF
+--list_files $MYSQLD_DATADIR/test
+UNLOCK TABLES;
+
+# Move the LSN forward
+DROP TABLE t1;
+
+CREATE TABLE t1(
+ c1 INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
+ c2 INT, INDEX(c2)) ENGINE=InnoDB;
+
+ALTER TABLE t1 DISCARD TABLESPACE;
+--error ER_TABLESPACE_DISCARDED
+SELECT * FROM t1;
+
+perl;
+do "$ENV{MTR_SUITE_DIR}/include/innodb-util.pl";
+ib_discard_tablespaces("test", "t1");
+ib_restore_tablespaces("test", "t1");
+EOF
+
+ALTER TABLE t1 IMPORT TABLESPACE;
+CHECK TABLE t1;
+
+SELECT COUNT(*) FROM t1 WHERE c2 = 1;
+
+DROP TABLE t1;
+
+# Export/import on the same instance, with --innodb-file-per-table=1
+# Insert some more records to move the LSN forward and then drop the
+# table and restore, this time the table has a secondary index too.
+# Rename the index on the create so that the IMPORT fails, drop index
+# Create with proper name and then do an IMPORT.
+CREATE TABLE t1(
+ c1 INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
+ c2 INT, INDEX idx(c2)) ENGINE=InnoDB;
+
+INSERT INTO t1 SELECT seq,1 FROM seq_1_to_16;
+
+FLUSH TABLES t1 FOR EXPORT;
+perl;
+do "$ENV{MTR_SUITE_DIR}/include/innodb-util.pl";
+ib_backup_tablespaces("test", "t1");
+EOF
+UNLOCK TABLES;
+
+# Move the LSN forward
+DROP TABLE t1;
+
+CREATE TABLE t1(
+ c1 INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
+ c2 INT, INDEX x(c2)) ENGINE=InnoDB;
+
+ALTER TABLE t1 DISCARD TABLESPACE;
+--error ER_TABLESPACE_DISCARDED
+SELECT * FROM t1;
+
+perl;
+do "$ENV{MTR_SUITE_DIR}/include/innodb-util.pl";
+ib_discard_tablespaces("test", "t1");
+ib_restore_tablespaces("test", "t1");
+EOF
+
+# This is really a name mismatch error, need better error codes.
+-- error ER_TABLE_SCHEMA_MISMATCH
+ALTER TABLE t1 IMPORT TABLESPACE;
+--error ER_TABLESPACE_DISCARDED
+select count(*) from t1;
+ALTER TABLE t1 DROP INDEX x;
+--error ER_CANT_DROP_FIELD_OR_KEY
+ALTER TABLE t1 DROP INDEX x, ALGORITHM=copy;
+ALTER TABLE t1 ADD INDEX idx(c2);
+
+perl;
+do "$ENV{MTR_SUITE_DIR}/include/innodb-util.pl";
+ib_restore_tablespaces("test", "t1");
+EOF
+
+ALTER TABLE t1 IMPORT TABLESPACE;
+CHECK TABLE t1;
+
+SELECT * FROM t1;
+
+perl;
+do "$ENV{MTR_SUITE_DIR}/include/innodb-util.pl";
+ib_cleanup("test", "t1");
+EOF
+
+DROP TABLE t1;
+
+#
+# Export/import on the same instance, with --innodb-file-per-table=0
+# This should fail because it is not supported
+SET GLOBAL innodb_file_per_table = 0;
+
+CREATE TABLE t1(
+ c1 INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
+ c2 INT) ENGINE=InnoDB;
+
+INSERT INTO t1 SELECT seq,1 FROM seq_1_to_16;
+SHOW CREATE TABLE t1;
+
+# This should fail, InnoDB should return a warning
+FLUSH TABLES t1 FOR EXPORT;
+
+UNLOCK TABLES;
+
+DROP TABLE t1;
+
+#
+# Tests that check for schema mismatch during IMPORT
+#
+
+SET GLOBAL innodb_file_per_table = 1;
+
+CREATE TABLE t1(
+ c1 INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
+ c2 INT, INDEX idx(c2)) ENGINE=InnoDB;
+
+INSERT INTO t1 SELECT seq,1 FROM seq_1_to_16;
+
+SHOW CREATE TABLE t1;
+
+FLUSH TABLES t1 FOR EXPORT;
+
+perl;
+do "$ENV{MTR_SUITE_DIR}/include/innodb-util.pl";
+ib_backup_tablespaces("test", "t1");
+EOF
+
+UNLOCK TABLES;
+
+DROP TABLE t1;
+
+# Table without the secondary index
+CREATE TABLE t1(
+ c1 INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
+ c2 INT) ENGINE=InnoDB;
+
+ALTER TABLE t1 DISCARD TABLESPACE;
+--error ER_TABLESPACE_DISCARDED
+SELECT * FROM t1;
+
+perl;
+do "$ENV{MTR_SUITE_DIR}/include/innodb-util.pl";
+ib_discard_tablespaces("test", "t1");
+ib_restore_tablespaces("test", "t1");
+EOF
+
+# This should fail because of a missing secondary index
+-- error ER_TABLE_SCHEMA_MISMATCH
+ALTER TABLE t1 IMPORT TABLESPACE;
+
+perl;
+do "$ENV{MTR_SUITE_DIR}/include/innodb-util.pl";
+ib_unlink_tablespace("test", "t1");
+EOF
+
+DROP TABLE t1;
+
+# Table with an additional column
+CREATE TABLE t1(
+ c1 INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
+ c2 INT,
+ c3 INT, INDEX idx(c2)) ENGINE=InnoDB;
+
+ALTER TABLE t1 DISCARD TABLESPACE;
+--error ER_TABLESPACE_DISCARDED
+SELECT * FROM t1;
+
+perl;
+do "$ENV{MTR_SUITE_DIR}/include/innodb-util.pl";
+ib_discard_tablespaces("test", "t1");
+ib_restore_tablespaces("test", "t1");
+EOF
+
+# This should fail because the table has an additional column
+-- error ER_TABLE_SCHEMA_MISMATCH
+ALTER TABLE t1 IMPORT TABLESPACE;
+
+perl;
+do "$ENV{MTR_SUITE_DIR}/include/innodb-util.pl";
+ib_unlink_tablespace("test", "t1");
+EOF
+
+DROP TABLE t1;
+
+# Change the column type of c2
+CREATE TABLE t1(
+ c1 INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
+ c2 BIGINT, INDEX idx(c2)) ENGINE=InnoDB;
+
+ALTER TABLE t1 DISCARD TABLESPACE;
+--error ER_TABLESPACE_DISCARDED
+SELECT * FROM t1;
+
+perl;
+do "$ENV{MTR_SUITE_DIR}/include/innodb-util.pl";
+ib_discard_tablespaces("test", "t1");
+ib_restore_tablespaces("test", "t1");
+EOF
+
+# This should fail because c2 is now a BIGINT and not INT
+-- error ER_TABLE_SCHEMA_MISMATCH
+ALTER TABLE t1 IMPORT TABLESPACE;
+
+perl;
+do "$ENV{MTR_SUITE_DIR}/include/innodb-util.pl";
+ib_unlink_tablespace("test", "t1");
+EOF
+
+DROP TABLE t1;
+
+# This should be OK.
+CREATE TABLE t1(
+ c1 INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
+ c2 INT, INDEX idx(c2)) ENGINE=InnoDB;
+
+ALTER TABLE t1 DISCARD TABLESPACE;
+--error ER_TABLESPACE_DISCARDED
+SELECT * FROM t1;
+
+perl;
+do "$ENV{MTR_SUITE_DIR}/include/innodb-util.pl";
+ib_discard_tablespaces("test", "t1");
+ib_restore_tablespaces("test", "t1");
+EOF
+
+ALTER TABLE t1 IMPORT TABLESPACE;
+CHECK TABLE t1;
+
+perl;
+do "$ENV{MTR_SUITE_DIR}/include/innodb-util.pl";
+ib_cleanup("test", "t1");
+EOF
+
+SHOW CREATE TABLE t1;
+SELECT * FROM t1;
+
+DROP TABLE t1;
+
+#
+# EXPORT ROW_FORMAT=REDUNDANT
+#
+CREATE TABLE t1(
+ c1 INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
+ c2 INT, INDEX idx(c2)) ENGINE=InnoDB ROW_FORMAT=REDUNDANT;
+
+INSERT INTO t1 SELECT seq,1 FROM seq_1_to_16;
+
+SHOW CREATE TABLE t1;
+
+FLUSH TABLES t1 FOR EXPORT;
+
+perl;
+do "$ENV{MTR_SUITE_DIR}/include/innodb-util.pl";
+ib_backup_tablespaces("test", "t1");
+EOF
+
+UNLOCK TABLES;
+
+DROP TABLE t1;
+
+CREATE TABLE t1(
+ c1 INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
+ c2 INT, INDEX idx(c2)) ENGINE=InnoDB ROW_FORMAT=REDUNDANT;
+
+ALTER TABLE t1 DISCARD TABLESPACE;
+--error ER_TABLESPACE_DISCARDED
+SELECT * FROM t1;
+
+perl;
+do "$ENV{MTR_SUITE_DIR}/include/innodb-util.pl";
+ib_discard_tablespaces("test", "t1");
+ib_restore_tablespaces("test", "t1");
+EOF
+
+ALTER TABLE t1 IMPORT TABLESPACE;
+CHECK TABLE t1;
+
+perl;
+do "$ENV{MTR_SUITE_DIR}/include/innodb-util.pl";
+ib_cleanup("test", "t1");
+EOF
+
+SHOW CREATE TABLE t1;
+SELECT * FROM t1;
+
+DROP TABLE t1;
+
+CREATE TABLE t1(
+ c1 INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
+ c2 INT, INDEX idx(c2)) ENGINE=InnoDB ROW_FORMAT=COMPACT;
+
+ALTER TABLE t1 DISCARD TABLESPACE;
+--error ER_TABLESPACE_DISCARDED
+SELECT * FROM t1;
+
+perl;
+do "$ENV{MTR_SUITE_DIR}/include/innodb-util.pl";
+ib_discard_tablespaces("test", "t1");
+ib_restore_tablespaces("test", "t1");
+EOF
+
+--error ER_TABLE_SCHEMA_MISMATCH
+ALTER TABLE t1 IMPORT TABLESPACE;
+
+perl;
+do "$ENV{MTR_SUITE_DIR}/include/innodb-util.pl";
+ib_unlink_tablespace("test", "t1");
+EOF
+
+DROP TABLE t1;
+
+CREATE TABLE t1(
+ c1 INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
+ c2 INT, INDEX idx(c2)) ENGINE=InnoDB ROW_FORMAT=DYNAMIC;
+
+ALTER TABLE t1 DISCARD TABLESPACE;
+--error ER_TABLESPACE_DISCARDED
+SELECT * FROM t1;
+
+perl;
+do "$ENV{MTR_SUITE_DIR}/include/innodb-util.pl";
+ib_discard_tablespaces("test", "t1");
+ib_restore_tablespaces("test", "t1");
+EOF
+
+--error ER_TABLE_SCHEMA_MISMATCH
+ALTER TABLE t1 IMPORT TABLESPACE;
+
+perl;
+do "$ENV{MTR_SUITE_DIR}/include/innodb-util.pl";
+ib_unlink_tablespace("test", "t1");
+EOF
+
+DROP TABLE t1;
+--disable_query_log
+SET @save_innodb_read_only_compressed=@@GLOBAL.innodb_read_only_compressed;
+SET GLOBAL innodb_read_only_compressed=OFF;
+--enable_query_log
+CREATE TABLE t1(
+ c1 INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
+ c2 INT, INDEX idx(c2)) ENGINE=InnoDB ROW_FORMAT=COMPRESSED;
+ALTER TABLE t1 DISCARD TABLESPACE;
+--error ER_TABLESPACE_DISCARDED
+SELECT * FROM t1;
+
+perl;
+do "$ENV{MTR_SUITE_DIR}/include/innodb-util.pl";
+ib_discard_tablespaces("test", "t1");
+ib_restore_tablespaces("test", "t1");
+EOF
+
+--error ER_TABLE_SCHEMA_MISMATCH
+ALTER TABLE t1 IMPORT TABLESPACE;
+
+perl;
+do "$ENV{MTR_SUITE_DIR}/include/innodb-util.pl";
+ib_unlink_tablespace("test", "t1");
+EOF
+
+DROP TABLE t1;
+
+# This should be OK.
+CREATE TABLE t1(
+ c1 INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
+ c2 INT, INDEX idx(c2)) ENGINE=InnoDB ROW_FORMAT=REDUNDANT;
+
+ALTER TABLE t1 DISCARD TABLESPACE;
+--error ER_TABLESPACE_DISCARDED
+SELECT * FROM t1;
+
+perl;
+do "$ENV{MTR_SUITE_DIR}/include/innodb-util.pl";
+ib_discard_tablespaces("test", "t1");
+ib_restore_tablespaces("test", "t1");
+EOF
+
+ALTER TABLE t1 IMPORT TABLESPACE;
+
+perl;
+do "$ENV{MTR_SUITE_DIR}/include/innodb-util.pl";
+ib_cleanup("test", "t1");
+EOF
+
+SHOW CREATE TABLE t1;
+SELECT * FROM t1;
+
+DROP TABLE t1;
+
+#
+# EXPORT ROW_FORMAT=COMPACT
+#
+CREATE TABLE t1(
+ c1 INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
+ c2 INT, INDEX idx(c2)) ENGINE=InnoDB ROW_FORMAT=COMPACT;
+
+INSERT INTO t1 SELECT seq,1 FROM seq_1_to_16;
+
+SHOW CREATE TABLE t1;
+
+FLUSH TABLES t1 FOR EXPORT;
+
+perl;
+do "$ENV{MTR_SUITE_DIR}/include/innodb-util.pl";
+ib_backup_tablespaces("test", "t1");
+EOF
+
+UNLOCK TABLES;
+
+DROP TABLE t1;
+
+CREATE TABLE t1(
+ c1 INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
+ c2 INT, INDEX idx(c2)) ENGINE=InnoDB ROW_FORMAT=COMPACT;
+
+ALTER TABLE t1 DISCARD TABLESPACE;
+--error ER_TABLESPACE_DISCARDED
+SELECT * FROM t1;
+
+perl;
+do "$ENV{MTR_SUITE_DIR}/include/innodb-util.pl";
+ib_discard_tablespaces("test", "t1");
+ib_restore_tablespaces("test", "t1");
+EOF
+
+ALTER TABLE t1 IMPORT TABLESPACE;
+CHECK TABLE t1;
+
+perl;
+do "$ENV{MTR_SUITE_DIR}/include/innodb-util.pl";
+ib_cleanup("test", "t1");
+EOF
+
+SHOW CREATE TABLE t1;
+SELECT * FROM t1;
+
+DROP TABLE t1;
+
+CREATE TABLE t1(
+ c1 INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
+ c2 INT, INDEX idx(c2)) ENGINE=InnoDB ROW_FORMAT=REDUNDANT;
+
+ALTER TABLE t1 DISCARD TABLESPACE;
+--error ER_TABLESPACE_DISCARDED
+SELECT * FROM t1;
+
+perl;
+do "$ENV{MTR_SUITE_DIR}/include/innodb-util.pl";
+ib_discard_tablespaces("test", "t1");
+ib_restore_tablespaces("test", "t1");
+EOF
+
+--error ER_TABLE_SCHEMA_MISMATCH
+ALTER TABLE t1 IMPORT TABLESPACE;
+
+perl;
+do "$ENV{MTR_SUITE_DIR}/include/innodb-util.pl";
+ib_unlink_tablespace("test", "t1");
+EOF
+
+DROP TABLE t1;
+
+CREATE TABLE t1(
+ c1 INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
+ c2 INT, INDEX idx(c2)) ENGINE=InnoDB ROW_FORMAT=DYNAMIC;
+
+ALTER TABLE t1 DISCARD TABLESPACE;
+--error ER_TABLESPACE_DISCARDED
+SELECT * FROM t1;
+
+perl;
+do "$ENV{MTR_SUITE_DIR}/include/innodb-util.pl";
+ib_discard_tablespaces("test", "t1");
+ib_restore_tablespaces("test", "t1");
+EOF
+
+--error ER_TABLE_SCHEMA_MISMATCH
+ALTER TABLE t1 IMPORT TABLESPACE;
+
+perl;
+do "$ENV{MTR_SUITE_DIR}/include/innodb-util.pl";
+ib_unlink_tablespace("test", "t1");
+EOF
+
+DROP TABLE t1;
+
+CREATE TABLE t1(
+ c1 INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
+ c2 INT, INDEX idx(c2)) ENGINE=InnoDB ROW_FORMAT=COMPRESSED;
+ALTER TABLE t1 DISCARD TABLESPACE;
+--error ER_TABLESPACE_DISCARDED
+SELECT * FROM t1;
+
+perl;
+do "$ENV{MTR_SUITE_DIR}/include/innodb-util.pl";
+ib_discard_tablespaces("test", "t1");
+ib_restore_tablespaces("test", "t1");
+EOF
+
+--error ER_TABLE_SCHEMA_MISMATCH
+ALTER TABLE t1 IMPORT TABLESPACE;
+
+perl;
+do "$ENV{MTR_SUITE_DIR}/include/innodb-util.pl";
+ib_unlink_tablespace("test", "t1");
+EOF
+
+DROP TABLE t1;
+
+# This should be OK.
+CREATE TABLE t1(
+ c1 INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
+ c2 INT, INDEX idx(c2)) ENGINE=InnoDB ROW_FORMAT=COMPACT;
+
+ALTER TABLE t1 DISCARD TABLESPACE;
+--error ER_TABLESPACE_DISCARDED
+SELECT * FROM t1;
+
+perl;
+do "$ENV{MTR_SUITE_DIR}/include/innodb-util.pl";
+ib_discard_tablespaces("test", "t1");
+ib_restore_tablespaces("test", "t1");
+EOF
+
+ALTER TABLE t1 IMPORT TABLESPACE;
+CHECK TABLE t1;
+
+perl;
+do "$ENV{MTR_SUITE_DIR}/include/innodb-util.pl";
+ib_cleanup("test", "t1");
+EOF
+
+SHOW CREATE TABLE t1;
+SELECT * FROM t1;
+
+DROP TABLE t1;
+
+#
+# EXPORT ROW_FORMAT=DYNAMIC
+#
+CREATE TABLE t1(
+ c1 INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
+ c2 INT, INDEX idx(c2)) ENGINE=InnoDB ROW_FORMAT=DYNAMIC;
+
+INSERT INTO t1 SELECT seq,1 FROM seq_1_to_16;
+
+SHOW CREATE TABLE t1;
+
+FLUSH TABLES t1 FOR EXPORT;
+
+perl;
+do "$ENV{MTR_SUITE_DIR}/include/innodb-util.pl";
+ib_backup_tablespaces("test", "t1");
+EOF
+
+UNLOCK TABLES;
+
+DROP TABLE t1;
+
+CREATE TABLE t1(
+ c1 INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
+ c2 INT, INDEX idx(c2)) ENGINE=InnoDB ROW_FORMAT=DYNAMIC;
+
+ALTER TABLE t1 DISCARD TABLESPACE;
+--error ER_TABLESPACE_DISCARDED
+SELECT * FROM t1;
+
+perl;
+do "$ENV{MTR_SUITE_DIR}/include/innodb-util.pl";
+ib_discard_tablespaces("test", "t1");
+ib_restore_tablespaces("test", "t1");
+EOF
+
+ALTER TABLE t1 IMPORT TABLESPACE;
+CHECK TABLE t1;
+
+perl;
+do "$ENV{MTR_SUITE_DIR}/include/innodb-util.pl";
+ib_cleanup("test", "t1");
+EOF
+
+SHOW CREATE TABLE t1;
+SELECT * FROM t1;
+
+DROP TABLE t1;
+
+CREATE TABLE t1(
+ c1 INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
+ c2 INT, INDEX idx(c2)) ENGINE=InnoDB ROW_FORMAT=COMPACT;
+
+ALTER TABLE t1 DISCARD TABLESPACE;
+--error ER_TABLESPACE_DISCARDED
+SELECT * FROM t1;
+
+perl;
+do "$ENV{MTR_SUITE_DIR}/include/innodb-util.pl";
+ib_discard_tablespaces("test", "t1");
+ib_restore_tablespaces("test", "t1");
+EOF
+
+--error ER_TABLE_SCHEMA_MISMATCH
+ALTER TABLE t1 IMPORT TABLESPACE;
+
+perl;
+do "$ENV{MTR_SUITE_DIR}/include/innodb-util.pl";
+ib_unlink_tablespace("test", "t1");
+EOF
+
+DROP TABLE t1;
+
+CREATE TABLE t1(
+ c1 INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
+ c2 INT, INDEX idx(c2)) ENGINE=InnoDB ROW_FORMAT=REDUNDANT;
+
+ALTER TABLE t1 DISCARD TABLESPACE;
+--error ER_TABLESPACE_DISCARDED
+SELECT * FROM t1;
+
+perl;
+do "$ENV{MTR_SUITE_DIR}/include/innodb-util.pl";
+ib_discard_tablespaces("test", "t1");
+ib_restore_tablespaces("test", "t1");
+EOF
+
+--error ER_TABLE_SCHEMA_MISMATCH
+ALTER TABLE t1 IMPORT TABLESPACE;
+
+perl;
+do "$ENV{MTR_SUITE_DIR}/include/innodb-util.pl";
+ib_unlink_tablespace("test", "t1");
+EOF
+
+DROP TABLE t1;
+
+CREATE TABLE t1(
+ c1 INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
+ c2 INT, INDEX idx(c2)) ENGINE=InnoDB ROW_FORMAT=COMPRESSED;
+ALTER TABLE t1 DISCARD TABLESPACE;
+--error ER_TABLESPACE_DISCARDED
+SELECT * FROM t1;
+
+perl;
+do "$ENV{MTR_SUITE_DIR}/include/innodb-util.pl";
+ib_discard_tablespaces("test", "t1");
+ib_restore_tablespaces("test", "t1");
+EOF
+
+--error ER_TABLE_SCHEMA_MISMATCH
+ALTER TABLE t1 IMPORT TABLESPACE;
+
+perl;
+do "$ENV{MTR_SUITE_DIR}/include/innodb-util.pl";
+ib_unlink_tablespace("test", "t1");
+EOF
+
+DROP TABLE t1;
+
+# This should be OK.
+CREATE TABLE t1(
+ c1 INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
+ c2 INT, INDEX idx(c2)) ENGINE=InnoDB ROW_FORMAT=DYNAMIC;
+
+ALTER TABLE t1 DISCARD TABLESPACE;
+--error ER_TABLESPACE_DISCARDED
+SELECT * FROM t1;
+
+perl;
+do "$ENV{MTR_SUITE_DIR}/include/innodb-util.pl";
+ib_discard_tablespaces("test", "t1");
+ib_restore_tablespaces("test", "t1");
+EOF
+
+ALTER TABLE t1 IMPORT TABLESPACE;
+CHECK TABLE t1;
+
+perl;
+do "$ENV{MTR_SUITE_DIR}/include/innodb-util.pl";
+ib_cleanup("test", "t1");
+EOF
+
+SHOW CREATE TABLE t1;
+SELECT * FROM t1;
+
+DROP TABLE t1;
+
+#
+# EXPORT ROW_FORMAT=COMPRESSED
+#
+CREATE TABLE t1(
+ c1 INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
+ c2 INT, INDEX idx(c2)) ENGINE=InnoDB ROW_FORMAT=COMPRESSED;
+
+INSERT INTO t1 SELECT seq,1 FROM seq_1_to_16;
+
+SHOW CREATE TABLE t1;
+
+FLUSH TABLES t1 FOR EXPORT;
+
+perl;
+do "$ENV{MTR_SUITE_DIR}/include/innodb-util.pl";
+ib_backup_tablespaces("test", "t1");
+EOF
+
+UNLOCK TABLES;
+
+DROP TABLE t1;
+
+CREATE TABLE t1(
+ c1 INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
+ c2 INT, INDEX idx(c2)) ENGINE=InnoDB ROW_FORMAT=COMPRESSED;
+
+ALTER TABLE t1 DISCARD TABLESPACE;
+--error ER_TABLESPACE_DISCARDED
+SELECT * FROM t1;
+
+perl;
+do "$ENV{MTR_SUITE_DIR}/include/innodb-util.pl";
+ib_discard_tablespaces("test", "t1");
+ib_restore_tablespaces("test", "t1");
+EOF
+
+ALTER TABLE t1 IMPORT TABLESPACE;
+CHECK TABLE t1;
+
+perl;
+do "$ENV{MTR_SUITE_DIR}/include/innodb-util.pl";
+ib_cleanup("test", "t1");
+EOF
+
+SHOW CREATE TABLE t1;
+SELECT * FROM t1;
+
+DROP TABLE t1;
+
+CREATE TABLE t1(
+ c1 INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
+ c2 INT, INDEX idx(c2)) ENGINE=InnoDB ROW_FORMAT=REDUNDANT;
+
+ALTER TABLE t1 DISCARD TABLESPACE;
+--error ER_TABLESPACE_DISCARDED
+SELECT * FROM t1;
+
+perl;
+do "$ENV{MTR_SUITE_DIR}/include/innodb-util.pl";
+ib_discard_tablespaces("test", "t1");
+ib_restore_tablespaces("test", "t1");
+EOF
+
+--error ER_TABLE_SCHEMA_MISMATCH
+ALTER TABLE t1 IMPORT TABLESPACE;
+
+perl;
+do "$ENV{MTR_SUITE_DIR}/include/innodb-util.pl";
+ib_unlink_tablespace("test", "t1");
+EOF
+
+DROP TABLE t1;
+
+CREATE TABLE t1(
+ c1 INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
+ c2 INT, INDEX idx(c2)) ENGINE=InnoDB ROW_FORMAT=COMPACT;
+
+ALTER TABLE t1 DISCARD TABLESPACE;
+--error ER_TABLESPACE_DISCARDED
+SELECT * FROM t1;
+
+perl;
+do "$ENV{MTR_SUITE_DIR}/include/innodb-util.pl";
+ib_discard_tablespaces("test", "t1");
+ib_restore_tablespaces("test", "t1");
+EOF
+
+--error ER_TABLE_SCHEMA_MISMATCH
+ALTER TABLE t1 IMPORT TABLESPACE;
+
+perl;
+do "$ENV{MTR_SUITE_DIR}/include/innodb-util.pl";
+ib_unlink_tablespace("test", "t1");
+EOF
+
+DROP TABLE t1;
+
+CREATE TABLE t1(
+ c1 INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
+ c2 INT, INDEX idx(c2)) ENGINE=InnoDB ROW_FORMAT=DYNAMIC;
+ALTER TABLE t1 DISCARD TABLESPACE;
+--error ER_TABLESPACE_DISCARDED
+SELECT * FROM t1;
+
+perl;
+do "$ENV{MTR_SUITE_DIR}/include/innodb-util.pl";
+ib_discard_tablespaces("test", "t1");
+ib_restore_tablespaces("test", "t1");
+EOF
+
+--error ER_TABLE_SCHEMA_MISMATCH
+ALTER TABLE t1 IMPORT TABLESPACE;
+
+perl;
+do "$ENV{MTR_SUITE_DIR}/include/innodb-util.pl";
+ib_unlink_tablespace("test", "t1");
+EOF
+
+DROP TABLE t1;
+
+
+CREATE TABLE t1(
+ c1 INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
+ c2 INT, INDEX idx(c2)) ENGINE=InnoDB
+ ROW_FORMAT=COMPRESSED KEY_BLOCK_SIZE=1;
+ALTER TABLE t1 DISCARD TABLESPACE;
+--error ER_TABLESPACE_DISCARDED
+SELECT * FROM t1;
+
+perl;
+do "$ENV{MTR_SUITE_DIR}/include/innodb-util.pl";
+ib_discard_tablespaces("test", "t1");
+ib_restore_tablespaces("test", "t1");
+EOF
+
+--error ER_TABLE_SCHEMA_MISMATCH
+ALTER TABLE t1 IMPORT TABLESPACE;
+
+perl;
+do "$ENV{MTR_SUITE_DIR}/include/innodb-util.pl";
+ib_unlink_tablespace("test", "t1");
+EOF
+
+DROP TABLE t1;
+
+# This should be OK.
+CREATE TABLE t1(
+ c1 INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
+ c2 INT, INDEX idx(c2)) ENGINE=InnoDB ROW_FORMAT=COMPRESSED;
+
+ALTER TABLE t1 DISCARD TABLESPACE;
+--error ER_TABLESPACE_DISCARDED
+SELECT * FROM t1;
+
+perl;
+do "$ENV{MTR_SUITE_DIR}/include/innodb-util.pl";
+ib_discard_tablespaces("test", "t1");
+ib_restore_tablespaces("test", "t1");
+EOF
+
+ALTER TABLE t1 IMPORT TABLESPACE;
+CHECK TABLE t1;
+
+perl;
+do "$ENV{MTR_SUITE_DIR}/include/innodb-util.pl";
+ib_cleanup("test", "t1");
+EOF
+
+SHOW CREATE TABLE t1;
+SELECT * FROM t1;
+
+DROP TABLE t1;
+--disable_query_log
+SET GLOBAL innodb_read_only_compressed=@save_innodb_read_only_compressed;
+--enable_query_log
+
+
+CREATE TABLE t1 ( id INT NOT NULL, i1 INT, i2 INT, i3 INT, PRIMARY KEY (id)) engine=innodb;
+CREATE TABLE t2 ( id INT NOT NULL, i1 INT, i2 INT, PRIMARY KEY (id)) engine=innodb;
+
+ALTER TABLE t2 DISCARD TABLESPACE;
+FLUSH TABLES t1 FOR EXPORT;
+
+--copy_file $MYSQLD_DATADIR/test/t1.ibd $MYSQLD_DATADIR/test/t2.ibd
+--copy_file $MYSQLD_DATADIR/test/t1.cfg $MYSQLD_DATADIR/test/t2.cfg
+
+UNLOCK TABLES;
+--error ER_TABLE_SCHEMA_MISMATCH
+ALTER TABLE t2 IMPORT TABLESPACE;
+
+DROP TABLE t1, t2;
+
+
+CREATE TABLE t1 ( id INT NOT NULL, i1 INT, i2 INT, PRIMARY KEY (id)) engine=innodb;
+CREATE TABLE t2 ( id INT NOT NULL, i1 INT, i2 INT, i3 INT, PRIMARY KEY (id)) engine=innodb;
+
+ALTER TABLE t2 DISCARD TABLESPACE;
+FLUSH TABLES t1 FOR EXPORT;
+
+--copy_file $MYSQLD_DATADIR/test/t1.ibd $MYSQLD_DATADIR/test/t2.ibd
+--copy_file $MYSQLD_DATADIR/test/t1.cfg $MYSQLD_DATADIR/test/t2.cfg
+
+UNLOCK TABLES;
+--error ER_TABLE_SCHEMA_MISMATCH
+ALTER TABLE t2 IMPORT TABLESPACE;
+DROP TABLE t1, t2;
+
+
+call mtr.add_suppression("Got error -1 when reading table '.*'");
+call mtr.add_suppression("InnoDB: Error: tablespace id and flags in file '.*'");
+call mtr.add_suppression("InnoDB: The table .* doesn't have a corresponding tablespace, it was discarded");
diff --git a/mysql-test/suite/innodb/t/innodb-wl5980-alter.opt b/mysql-test/suite/innodb/t/innodb-wl5980-alter.opt
new file mode 100644
index 00000000..aa400236
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb-wl5980-alter.opt
@@ -0,0 +1,3 @@
+--loose-innodb-sys-indexes
+--loose-innodb-sys-columns
+--loose-innodb-sys-fields
diff --git a/mysql-test/suite/innodb/t/innodb-wl5980-alter.test b/mysql-test/suite/innodb/t/innodb-wl5980-alter.test
new file mode 100644
index 00000000..09c54db6
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb-wl5980-alter.test
@@ -0,0 +1,710 @@
+--echo #
+--echo # This is a copy of innodb-alter.test except using remote tablespaces
+--echo # and showing those files.
+--echo #
+
+--source include/have_innodb.inc
+--source include/have_symlink.inc
+
+SET @innodb_file_per_table_orig=@@GLOBAL.innodb_file_per_table;
+LET $regexp=/FTS_[0-9a-f_]+([A-Z0-9_]+)\.([islbd]{3})/FTS_AUX_\1.\2/;
+
+# Set up some variables
+LET $MYSQL_DATA_DIR = `select @@datadir`;
+LET $data_directory_clause = DATA DIRECTORY='$MYSQL_TMP_DIR/alt_dir';
+
+SET default_storage_engine=InnoDB;
+SET GLOBAL innodb_file_per_table=ON;
+
+SET NAMES utf8mb4;
+
+--replace_result $MYSQL_TMP_DIR MYSQL_TMP_DIR
+eval CREATE TABLE t1 (
+ c1 INT PRIMARY KEY, c2 INT DEFAULT 1, ct TEXT,
+ INDEX(c2))
+ENGINE=InnoDB $data_directory_clause;
+
+INSERT INTO t1 SET c1=1;
+
+CREATE TABLE sys_tables SELECT * FROM INFORMATION_SCHEMA.INNODB_SYS_TABLES
+WHERE NAME LIKE 'test/t%';
+CREATE TABLE sys_indexes SELECT i.* FROM INFORMATION_SCHEMA.INNODB_SYS_INDEXES i
+INNER JOIN sys_tables st ON i.TABLE_ID=st.TABLE_ID;
+
+CREATE TABLE t1p LIKE t1;
+
+--replace_result $MYSQL_TMP_DIR MYSQL_TMP_DIR
+eval CREATE TABLE t1c (c1 INT PRIMARY KEY, c2 INT, c3 INT, INDEX(c2), INDEX(c3),
+ CONSTRAINT t1c2 FOREIGN KEY (c2) REFERENCES t1(c2),
+ CONSTRAINT t1c3 FOREIGN KEY (c3) REFERENCES t1p(c2))
+ENGINE=InnoDB $data_directory_clause;
+
+CREATE TABLE sys_foreign SELECT i.*
+FROM INFORMATION_SCHEMA.INNODB_SYS_FOREIGN i
+WHERE FOR_NAME LIKE 'test/t%';
+
+SELECT i.* FROM INFORMATION_SCHEMA.INNODB_SYS_FOREIGN_COLS i
+INNER JOIN sys_foreign sf ON i.ID = sf.ID;
+
+-- source suite/innodb/include/innodb_dict.inc
+
+--replace_result $MYSQL_TMP_DIR MYSQL_TMP_DIR
+SHOW CREATE TABLE t1;
+ALTER TABLE t1 ALTER c2 DROP DEFAULT;
+--replace_result $MYSQL_TMP_DIR MYSQL_TMP_DIR
+SHOW CREATE TABLE t1;
+
+--echo ### files in MYSQL_DATA_DIR/test
+--list_files_write_file $MYSQL_DATA_DIR.files.txt $MYSQL_DATA_DIR/test
+--replace_regex $regexp
+--cat_file $MYSQL_DATA_DIR.files.txt
+--remove_file $MYSQL_DATA_DIR.files.txt
+--echo ### files in MYSQL_TMP_DIR/alt_dir/test
+--list_files_write_file $MYSQL_DATA_DIR.files.txt $MYSQL_TMP_DIR/alt_dir/test
+--replace_regex $regexp
+--cat_file $MYSQL_DATA_DIR.files.txt
+--remove_file $MYSQL_DATA_DIR.files.txt
+
+-- source suite/innodb/include/innodb_dict.inc
+
+# These should be no-op.
+ALTER TABLE t1 CHANGE c2 c2 INT AFTER c1;
+ALTER TABLE t1 CHANGE c1 c1 INT FIRST;
+
+--echo ### files in MYSQL_DATA_DIR/test
+--list_files_write_file $MYSQL_DATA_DIR.files.txt $MYSQL_DATA_DIR/test
+--replace_regex $regexp
+--cat_file $MYSQL_DATA_DIR.files.txt
+--remove_file $MYSQL_DATA_DIR.files.txt
+--echo ### files in MYSQL_TMP_DIR/alt_dir/test
+--list_files_write_file $MYSQL_DATA_DIR.files.txt $MYSQL_TMP_DIR/alt_dir/test
+--replace_regex $regexp
+--cat_file $MYSQL_DATA_DIR.files.txt
+--remove_file $MYSQL_DATA_DIR.files.txt
+
+-- source suite/innodb/include/innodb_dict.inc
+
+ALTER TABLE t1 CHANGE C2 c3 INT;
+
+--echo ### files in MYSQL_DATA_DIR/test
+--list_files_write_file $MYSQL_DATA_DIR.files.txt $MYSQL_DATA_DIR/test
+--replace_regex $regexp
+--cat_file $MYSQL_DATA_DIR.files.txt
+--remove_file $MYSQL_DATA_DIR.files.txt
+--echo ### files in MYSQL_TMP_DIR/alt_dir/test
+--list_files_write_file $MYSQL_DATA_DIR.files.txt $MYSQL_TMP_DIR/alt_dir/test
+--replace_regex $regexp
+--cat_file $MYSQL_DATA_DIR.files.txt
+--remove_file $MYSQL_DATA_DIR.files.txt
+
+-- source suite/innodb/include/innodb_dict.inc
+
+ALTER TABLE t1 CHANGE c3 C INT;
+
+--echo ### files in MYSQL_DATA_DIR/test
+--list_files_write_file $MYSQL_DATA_DIR.files.txt $MYSQL_DATA_DIR/test
+--replace_regex $regexp
+--cat_file $MYSQL_DATA_DIR.files.txt
+--remove_file $MYSQL_DATA_DIR.files.txt
+--echo ### files in MYSQL_TMP_DIR/alt_dir/test
+--list_files_write_file $MYSQL_DATA_DIR.files.txt $MYSQL_TMP_DIR/alt_dir/test
+--replace_regex $regexp
+--cat_file $MYSQL_DATA_DIR.files.txt
+--remove_file $MYSQL_DATA_DIR.files.txt
+
+-- source suite/innodb/include/innodb_dict.inc
+
+ALTER TABLE t1 CHANGE C Cöŀumň_TWO INT;
+
+--echo ### files in MYSQL_DATA_DIR/test
+--list_files_write_file $MYSQL_DATA_DIR.files.txt $MYSQL_DATA_DIR/test
+--replace_regex $regexp
+--cat_file $MYSQL_DATA_DIR.files.txt
+--remove_file $MYSQL_DATA_DIR.files.txt
+--echo ### files in MYSQL_TMP_DIR/alt_dir/test
+--list_files_write_file $MYSQL_DATA_DIR.files.txt $MYSQL_TMP_DIR/alt_dir/test
+--replace_regex $regexp
+--cat_file $MYSQL_DATA_DIR.files.txt
+--remove_file $MYSQL_DATA_DIR.files.txt
+
+SELECT i.* FROM INFORMATION_SCHEMA.INNODB_SYS_FOREIGN_COLS i
+INNER JOIN sys_foreign sf ON i.ID = sf.ID;
+
+-- source suite/innodb/include/innodb_dict.inc
+
+-- error ER_BAD_FIELD_ERROR
+ALTER TABLE t1 CHANGE cöĿǖmň_two c3 INT;
+
+ALTER TABLE t1 CHANGE cÖĿUMŇ_two c3 INT, RENAME TO t3;
+
+--echo ### files in MYSQL_DATA_DIR/test
+--list_files_write_file $MYSQL_DATA_DIR.files.txt $MYSQL_DATA_DIR/test
+--replace_regex $regexp
+--cat_file $MYSQL_DATA_DIR.files.txt
+--remove_file $MYSQL_DATA_DIR.files.txt
+--echo ### files in MYSQL_TMP_DIR/alt_dir/test
+--list_files_write_file $MYSQL_DATA_DIR.files.txt $MYSQL_TMP_DIR/alt_dir/test
+--replace_regex $regexp
+--cat_file $MYSQL_DATA_DIR.files.txt
+--remove_file $MYSQL_DATA_DIR.files.txt
+
+SELECT st.NAME, i.NAME
+FROM sys_tables st INNER JOIN INFORMATION_SCHEMA.INNODB_SYS_TABLES i
+ON i.TABLE_ID=st.TABLE_ID;
+
+--replace_result $MYSQL_TMP_DIR MYSQL_TMP_DIR
+SHOW CREATE TABLE t3;
+--replace_result $MYSQL_TMP_DIR MYSQL_TMP_DIR
+SHOW CREATE TABLE t1c;
+
+# The maximum column name length should be 64 characters.
+--error ER_TOO_LONG_IDENT
+ALTER TABLE t3 CHANGE c3
+`12345678901234567890123456789012345678901234567890123456789012345` INT;
+ALTER TABLE t3 CHANGE c3
+`1234567890123456789012345678901234567890123456789012345678901234` INT;
+
+--echo ### files in MYSQL_DATA_DIR/test
+--list_files_write_file $MYSQL_DATA_DIR.files.txt $MYSQL_DATA_DIR/test
+--replace_regex $regexp
+--cat_file $MYSQL_DATA_DIR.files.txt
+--remove_file $MYSQL_DATA_DIR.files.txt
+--echo ### files in MYSQL_TMP_DIR/alt_dir/test
+--list_files_write_file $MYSQL_DATA_DIR.files.txt $MYSQL_TMP_DIR/alt_dir/test
+--replace_regex $regexp
+--cat_file $MYSQL_DATA_DIR.files.txt
+--remove_file $MYSQL_DATA_DIR.files.txt
+
+--replace_result $MYSQL_TMP_DIR MYSQL_TMP_DIR
+SHOW CREATE TABLE t3;
+
+# Test the length limit with non-ASCII utf-8 characters.
+--error ER_TOO_LONG_IDENT
+ALTER TABLE t3 CHANGE
+`1234567890123456789012345678901234567890123456789012345678901234`
+`倀倁倂倃倄倅倆倇倈倉倊個倌倍倎倏倐們倒倓倔倕倖倗倘候倚倛倜倝倞借倠倡倢倣値倥倦倧倨倩倪倫倬倭倮倯倰倱倲倳倴倵倶倷倸倹债倻值倽倾倿偀` INT;
+
+--error ER_TOO_LONG_IDENT
+ALTER TABLE t3 CHANGE
+`1234567890123456789012345678901234567890123456789012345678901234`
+`倀倁倂倃倄倅倆倇倈倉倊個倌倍倎倏倐們倒倓倔倕倖倗倘候倚倛倜倝倞借倠倡倢倣値倥倦倧倨倩倪倫倬倭倮倯倰倱倲倳倴倵倶倷倸倹债倻值倽倾倿ä` INT;
+
+ALTER TABLE t3 CHANGE
+`1234567890123456789012345678901234567890123456789012345678901234`
+`倀倁倂倃倄倅倆倇倈倉倊個倌倍倎倏倐們倒倓倔倕倖倗倘候倚倛倜倝倞借倠倡倢倣値倥倦倧倨倩倪倫倬倭倮倯倰倱倲倳倴倵倶倷倸倹债倻值倽倾ä` INT;
+
+--echo ### files in MYSQL_DATA_DIR/test
+--list_files_write_file $MYSQL_DATA_DIR.files.txt $MYSQL_DATA_DIR/test
+--replace_regex $regexp
+--cat_file $MYSQL_DATA_DIR.files.txt
+--remove_file $MYSQL_DATA_DIR.files.txt
+--echo ### files in MYSQL_TMP_DIR/alt_dir/test
+--list_files_write_file $MYSQL_DATA_DIR.files.txt $MYSQL_TMP_DIR/alt_dir/test
+--replace_regex $regexp
+--cat_file $MYSQL_DATA_DIR.files.txt
+--remove_file $MYSQL_DATA_DIR.files.txt
+
+# check that the rename is case-insensitive (note the upper-case ä at end)
+ALTER TABLE t3 CHANGE
+`倀倁倂倃倄倅倆倇倈倉倊個倌倍倎倏倐們倒倓倔倕倖倗倘候倚倛倜倝倞借倠倡倢倣値倥倦倧倨倩倪倫倬倭倮倯倰倱倲倳倴倵倶倷倸倹债倻值倽倾Ä`
+c3 INT;
+
+--echo ### files in MYSQL_DATA_DIR/test
+--list_files_write_file $MYSQL_DATA_DIR.files.txt $MYSQL_DATA_DIR/test
+--replace_regex $regexp
+--cat_file $MYSQL_DATA_DIR.files.txt
+--remove_file $MYSQL_DATA_DIR.files.txt
+--echo ### files in MYSQL_TMP_DIR/alt_dir/test
+--list_files_write_file $MYSQL_DATA_DIR.files.txt $MYSQL_TMP_DIR/alt_dir/test
+--replace_regex $regexp
+--cat_file $MYSQL_DATA_DIR.files.txt
+--remove_file $MYSQL_DATA_DIR.files.txt
+
+# test with 4-byte UTF-8 (should be disallowed)
+--error ER_INVALID_CHARACTER_STRING
+ALTER TABLE t3 CHANGE c3 𐌀𐌁𐌂𐌃𐌄𐌅𐌆𐌇𐌈𐌉𐌊𐌋𐌌𐌍𐌎𐌏𐌐𐌑𐌒𐌓𐌔𐌕𐌖𐌗𐌘𐌙𐌚𐌛𐌜 INT;
+
+--error ER_INVALID_CHARACTER_STRING
+ALTER TABLE t3 CHANGE c3 😲 INT;
+
+ALTER TABLE t3 RENAME TO t2;
+
+--echo ### files in MYSQL_DATA_DIR/test
+--list_files_write_file $MYSQL_DATA_DIR.files.txt $MYSQL_DATA_DIR/test
+--replace_regex $regexp
+--cat_file $MYSQL_DATA_DIR.files.txt
+--remove_file $MYSQL_DATA_DIR.files.txt
+--echo ### files in MYSQL_TMP_DIR/alt_dir/test
+--list_files_write_file $MYSQL_DATA_DIR.files.txt $MYSQL_TMP_DIR/alt_dir/test
+--replace_regex $regexp
+--cat_file $MYSQL_DATA_DIR.files.txt
+--remove_file $MYSQL_DATA_DIR.files.txt
+
+SELECT st.NAME, i.NAME
+FROM sys_tables st INNER JOIN INFORMATION_SCHEMA.INNODB_SYS_TABLES i
+ON i.TABLE_ID=st.TABLE_ID;
+
+--replace_result $MYSQL_TMP_DIR MYSQL_TMP_DIR
+SHOW CREATE TABLE t2;
+
+RENAME TABLE t2 TO t1;
+
+SELECT st.NAME, i.NAME
+FROM sys_tables st INNER JOIN INFORMATION_SCHEMA.INNODB_SYS_TABLES i
+ON i.TABLE_ID=st.TABLE_ID;
+
+--echo ### files in MYSQL_DATA_DIR/test
+--list_files_write_file $MYSQL_DATA_DIR.files.txt $MYSQL_DATA_DIR/test
+--replace_regex $regexp
+--cat_file $MYSQL_DATA_DIR.files.txt
+--remove_file $MYSQL_DATA_DIR.files.txt
+--echo ### files in MYSQL_TMP_DIR/alt_dir/test
+--list_files_write_file $MYSQL_DATA_DIR.files.txt $MYSQL_TMP_DIR/alt_dir/test
+--replace_regex $regexp
+--cat_file $MYSQL_DATA_DIR.files.txt
+--remove_file $MYSQL_DATA_DIR.files.txt
+
+-- source suite/innodb/include/innodb_dict.inc
+
+--error ER_DROP_INDEX_FK
+ALTER TABLE t1 DROP INDEX c2;
+
+--error ER_CANT_DROP_FIELD_OR_KEY
+ALTER TABLE t1 DROP INDEX c4;
+
+--error ER_CANT_DROP_FIELD_OR_KEY
+ALTER TABLE t1c DROP FOREIGN KEY c2;
+
+--error ER_CANT_DROP_FIELD_OR_KEY
+ALTER TABLE t1c DROP FOREIGN KEY t1c2, DROP FOREIGN KEY c2;
+
+--error ER_CANT_DROP_FIELD_OR_KEY
+ALTER TABLE t1c DROP FOREIGN KEY t1c2, DROP FOREIGN KEY c2, DROP INDEX c2;
+
+--error ER_DROP_INDEX_FK
+ALTER TABLE t1c DROP INDEX c2;
+
+--error ER_CANT_DROP_FIELD_OR_KEY
+ALTER TABLE t1c DROP FOREIGN KEY ẗ1C2;
+
+--replace_result $MYSQL_TMP_DIR MYSQL_TMP_DIR
+SHOW CREATE TABLE t1c;
+
+SET foreign_key_checks=0;
+DROP TABLE t1p;
+SET foreign_key_checks=1;
+
+--replace_result $MYSQL_TMP_DIR MYSQL_TMP_DIR
+SHOW CREATE TABLE t1c;
+
+--echo ### files in MYSQL_DATA_DIR/test
+--list_files_write_file $MYSQL_DATA_DIR.files.txt $MYSQL_DATA_DIR/test
+--replace_regex $regexp
+--cat_file $MYSQL_DATA_DIR.files.txt
+--remove_file $MYSQL_DATA_DIR.files.txt
+--echo ### files in MYSQL_TMP_DIR/alt_dir/test
+--list_files_write_file $MYSQL_DATA_DIR.files.txt $MYSQL_TMP_DIR/alt_dir/test
+--replace_regex $regexp
+--cat_file $MYSQL_DATA_DIR.files.txt
+--remove_file $MYSQL_DATA_DIR.files.txt
+
+-- source suite/innodb/include/innodb_dict.inc
+
+--replace_result $MYSQL_TMP_DIR MYSQL_TMP_DIR
+eval CREATE TABLE t1p (c1 INT PRIMARY KEY, c2 INT, INDEX(c2))
+ ENGINE=InnoDB $data_directory_clause;
+
+--error ER_DROP_INDEX_FK
+ALTER TABLE t1c DROP INDEX C2, DROP INDEX C3;
+--error ER_DROP_INDEX_FK
+ALTER TABLE t1c DROP INDEX C3;
+
+SET foreign_key_checks=0;
+ALTER TABLE t1c DROP INDEX C3;
+
+--echo ### files in MYSQL_DATA_DIR/test
+--list_files_write_file $MYSQL_DATA_DIR.files.txt $MYSQL_DATA_DIR/test
+--replace_regex $regexp
+--cat_file $MYSQL_DATA_DIR.files.txt
+--remove_file $MYSQL_DATA_DIR.files.txt
+--echo ### files in MYSQL_TMP_DIR/alt_dir/test
+--list_files_write_file $MYSQL_DATA_DIR.files.txt $MYSQL_TMP_DIR/alt_dir/test
+--replace_regex $regexp
+--cat_file $MYSQL_DATA_DIR.files.txt
+--remove_file $MYSQL_DATA_DIR.files.txt
+
+SET foreign_key_checks=1;
+
+--replace_result $MYSQL_TMP_DIR MYSQL_TMP_DIR
+SHOW CREATE TABLE t1c;
+
+-- source suite/innodb/include/innodb_dict.inc
+
+ALTER TABLE t1c DROP FOREIGN KEY t1C3;
+
+--echo ### files in MYSQL_DATA_DIR/test
+--list_files_write_file $MYSQL_DATA_DIR.files.txt $MYSQL_DATA_DIR/test
+--replace_regex $regexp
+--cat_file $MYSQL_DATA_DIR.files.txt
+--remove_file $MYSQL_DATA_DIR.files.txt
+--echo ### files in MYSQL_TMP_DIR/alt_dir/test
+--list_files_write_file $MYSQL_DATA_DIR.files.txt $MYSQL_TMP_DIR/alt_dir/test
+--replace_regex $regexp
+--cat_file $MYSQL_DATA_DIR.files.txt
+--remove_file $MYSQL_DATA_DIR.files.txt
+
+--replace_result $MYSQL_TMP_DIR MYSQL_TMP_DIR
+SHOW CREATE TABLE t1c;
+-- source suite/innodb/include/innodb_dict.inc
+
+ALTER TABLE t1c DROP INDEX c2, DROP FOREIGN KEY t1C2;
+
+--echo ### files in MYSQL_DATA_DIR/test
+--list_files_write_file $MYSQL_DATA_DIR.files.txt $MYSQL_DATA_DIR/test
+--replace_regex $regexp
+--cat_file $MYSQL_DATA_DIR.files.txt
+--remove_file $MYSQL_DATA_DIR.files.txt
+--echo ### files in MYSQL_TMP_DIR/alt_dir/test
+--list_files_write_file $MYSQL_DATA_DIR.files.txt $MYSQL_TMP_DIR/alt_dir/test
+--replace_regex $regexp
+--cat_file $MYSQL_DATA_DIR.files.txt
+--remove_file $MYSQL_DATA_DIR.files.txt
+
+--replace_result $MYSQL_TMP_DIR MYSQL_TMP_DIR
+SHOW CREATE TABLE t1c;
+
+-- source suite/innodb/include/innodb_dict.inc
+
+ALTER TABLE t1 DROP INDEX c2, CHANGE c3 c2 INT;
+
+--echo ### files in MYSQL_DATA_DIR/test
+--list_files_write_file $MYSQL_DATA_DIR.files.txt $MYSQL_DATA_DIR/test
+--replace_regex $regexp
+--cat_file $MYSQL_DATA_DIR.files.txt
+--remove_file $MYSQL_DATA_DIR.files.txt
+--echo ### files in MYSQL_TMP_DIR/alt_dir/test
+--list_files_write_file $MYSQL_DATA_DIR.files.txt $MYSQL_TMP_DIR/alt_dir/test
+--replace_regex $regexp
+--cat_file $MYSQL_DATA_DIR.files.txt
+--remove_file $MYSQL_DATA_DIR.files.txt
+
+-- source suite/innodb/include/innodb_dict.inc
+
+CREATE TABLE t1o LIKE t1;
+
+# This will implicitly add a DOC_ID column.
+# The LOCK=NONE should thus fail.
+--error ER_ALTER_OPERATION_NOT_SUPPORTED_REASON
+ALTER TABLE t1 ADD FULLTEXT INDEX (ct),
+CHANGE c1 pk INT, ALTER c2 SET DEFAULT 42, RENAME TO tt,
+ALGORITHM=INPLACE, LOCK=NONE;
+
+# Retry with LOCK=EXCLUSIVE.
+ALTER TABLE t1 ADD FULLTEXT INDEX (ct),
+CHANGE c1 pk INT, ALTER c2 SET DEFAULT 42, RENAME TO tt,
+ALGORITHM=INPLACE, LOCK=SHARED;
+
+--echo ### files in MYSQL_DATA_DIR/test
+--list_files_write_file $MYSQL_DATA_DIR.files.txt $MYSQL_DATA_DIR/test
+--replace_regex $regexp
+--cat_file $MYSQL_DATA_DIR.files.txt
+--remove_file $MYSQL_DATA_DIR.files.txt
+--echo ### files in MYSQL_TMP_DIR/alt_dir/test
+--list_files_write_file $MYSQL_DATA_DIR.files.txt $MYSQL_TMP_DIR/alt_dir/test
+--replace_regex $regexp
+--cat_file $MYSQL_DATA_DIR.files.txt
+--remove_file $MYSQL_DATA_DIR.files.txt
+
+# The output should be empty, because index->id was reassigned.
+-- source suite/innodb/include/innodb_dict.inc
+
+--replace_result $MYSQL_TMP_DIR MYSQL_TMP_DIR
+SHOW CREATE TABLE tt;
+
+# DB_ROW_ID, DB_TRX_ID, DB_ROLL_PTR are reserved InnoDB system column names.
+--error ER_WRONG_COLUMN_NAME
+ALTER TABLE t1o CHANGE c1 dB_row_Id INT, ALGORITHM=COPY;
+--error ER_WRONG_COLUMN_NAME
+ALTER TABLE t1o CHANGE c1 dB_row_Id INT, ALGORITHM=INPLACE;
+--error ER_WRONG_COLUMN_NAME
+ALTER TABLE t1o CHANGE c1 DB_TRX_ID INT;
+--error ER_WRONG_COLUMN_NAME
+ALTER TABLE t1o CHANGE c1 db_roll_ptr INT;
+
+# FTS_DOC_ID is the internal row identifier for full-text search.
+# It should be of type BIGINT UNSIGNED NOT NULL.
+--error ER_WRONG_COLUMN_NAME
+ALTER TABLE t1o ADD FULLTEXT INDEX(ct), CHANGE c1 FTS_DOC_ID INT,
+ALGORITHM=COPY;
+
+--error ER_INNODB_FT_WRONG_DOCID_COLUMN
+ALTER TABLE t1o ADD FULLTEXT INDEX(ct), CHANGE c1 FTS_DOC_ID INT,
+ALGORITHM=INPLACE;
+--error ER_WRONG_COLUMN_NAME
+ALTER TABLE t1o ADD FULLTEXT INDEX(ct), CHANGE c1 FTS_Doc_ID INT,
+ALGORITHM=INPLACE;
+--error ER_ALTER_OPERATION_NOT_SUPPORTED_REASON
+ALTER TABLE t1o ADD FULLTEXT INDEX(ct),
+CHANGE c1 FTS_DOC_ID BIGINT UNSIGNED NOT NULL,
+ALGORITHM=INPLACE;
+
+CREATE TABLE t1n LIKE t1o;
+
+ALTER TABLE t1n ADD FULLTEXT INDEX(ct);
+
+--echo ### files in MYSQL_DATA_DIR/test
+--list_files_write_file $MYSQL_DATA_DIR.files.txt $MYSQL_DATA_DIR/test
+--replace_regex $regexp
+--cat_file $MYSQL_DATA_DIR.files.txt
+--remove_file $MYSQL_DATA_DIR.files.txt
+--echo ### files in MYSQL_TMP_DIR/alt_dir/test
+--list_files_write_file $MYSQL_DATA_DIR.files.txt $MYSQL_TMP_DIR/alt_dir/test
+--replace_regex $regexp
+--cat_file $MYSQL_DATA_DIR.files.txt
+--remove_file $MYSQL_DATA_DIR.files.txt
+
+--error ER_WRONG_COLUMN_NAME
+ALTER TABLE t1n CHANGE c1 Fts_DOC_ID INT, ALGORITHM=INPLACE;
+--error ER_WRONG_COLUMN_NAME
+ALTER TABLE t1n CHANGE c1 Fts_DOC_ID INT, ALGORITHM=COPY;
+--error ER_BAD_FIELD_ERROR
+ALTER TABLE t1n CHANGE FTS_DOC_ID c11 INT, ALGORITHM=INPLACE;
+ALTER TABLE t1n CHANGE c1 FTS_DOC_ïD INT, ALGORITHM=INPLACE;
+
+--echo ### files in MYSQL_DATA_DIR/test
+--list_files_write_file $MYSQL_DATA_DIR.files.txt $MYSQL_DATA_DIR/test
+--replace_regex $regexp
+--cat_file $MYSQL_DATA_DIR.files.txt
+--remove_file $MYSQL_DATA_DIR.files.txt
+--echo ### files in MYSQL_TMP_DIR/alt_dir/test
+--list_files_write_file $MYSQL_DATA_DIR.files.txt $MYSQL_TMP_DIR/alt_dir/test
+--replace_regex $regexp
+--cat_file $MYSQL_DATA_DIR.files.txt
+--remove_file $MYSQL_DATA_DIR.files.txt
+
+ALTER TABLE t1n CHANGE FTS_DOC_ÏD c1 INT, ALGORITHM=INPLACE;
+
+--echo ### files in MYSQL_DATA_DIR/test
+--list_files_write_file $MYSQL_DATA_DIR.files.txt $MYSQL_DATA_DIR/test
+--replace_regex $regexp
+--cat_file $MYSQL_DATA_DIR.files.txt
+--remove_file $MYSQL_DATA_DIR.files.txt
+--echo ### files in MYSQL_TMP_DIR/alt_dir/test
+--list_files_write_file $MYSQL_DATA_DIR.files.txt $MYSQL_TMP_DIR/alt_dir/test
+--replace_regex $regexp
+--cat_file $MYSQL_DATA_DIR.files.txt
+--remove_file $MYSQL_DATA_DIR.files.txt
+
+ALTER TABLE t1n CHANGE c1 c2 INT, CHANGE c2 ct INT, CHANGE ct c1 TEXT,
+ALGORITHM=INPLACE;
+
+--echo ### files in MYSQL_DATA_DIR/test
+--list_files_write_file $MYSQL_DATA_DIR.files.txt $MYSQL_DATA_DIR/test
+--replace_regex $regexp
+--cat_file $MYSQL_DATA_DIR.files.txt
+--remove_file $MYSQL_DATA_DIR.files.txt
+--echo ### files in MYSQL_TMP_DIR/alt_dir/test
+--list_files_write_file $MYSQL_DATA_DIR.files.txt $MYSQL_TMP_DIR/alt_dir/test
+--replace_regex $regexp
+--cat_file $MYSQL_DATA_DIR.files.txt
+--remove_file $MYSQL_DATA_DIR.files.txt
+
+--replace_result $MYSQL_TMP_DIR MYSQL_TMP_DIR
+SHOW CREATE TABLE t1n;
+ALTER TABLE t1n CHANGE c2 c1 INT, CHANGE ct c2 INT, CHANGE c1 ct TEXT,
+ALGORITHM=COPY;
+
+--echo ### files in MYSQL_DATA_DIR/test
+--list_files_write_file $MYSQL_DATA_DIR.files.txt $MYSQL_DATA_DIR/test
+--replace_regex $regexp
+--cat_file $MYSQL_DATA_DIR.files.txt
+--remove_file $MYSQL_DATA_DIR.files.txt
+--echo ### files in MYSQL_TMP_DIR/alt_dir/test
+--list_files_write_file $MYSQL_DATA_DIR.files.txt $MYSQL_TMP_DIR/alt_dir/test
+--replace_regex $regexp
+--cat_file $MYSQL_DATA_DIR.files.txt
+--remove_file $MYSQL_DATA_DIR.files.txt
+
+--replace_result $MYSQL_TMP_DIR MYSQL_TMP_DIR
+SHOW CREATE TABLE t1n;
+
+--error ER_KEY_COLUMN_DOES_NOT_EXIST
+ALTER TABLE t1n ADD INDEX(c2), CHANGE c2 c4 INT, ALGORITHM=INPLACE;
+--error ER_KEY_COLUMN_DOES_NOT_EXIST
+ALTER TABLE t1n ADD INDEX(c2), CHANGE c2 c4 INT, ALGORITHM=COPY;
+
+ALTER TABLE t1n ADD INDEX(c4), CHANGE c2 c4 INT, ALGORITHM=INPLACE;
+
+--echo ### files in MYSQL_DATA_DIR/test
+--list_files_write_file $MYSQL_DATA_DIR.files.txt $MYSQL_DATA_DIR/test
+--replace_regex $regexp
+--cat_file $MYSQL_DATA_DIR.files.txt
+--remove_file $MYSQL_DATA_DIR.files.txt
+--echo ### files in MYSQL_TMP_DIR/alt_dir/test
+--list_files_write_file $MYSQL_DATA_DIR.files.txt $MYSQL_TMP_DIR/alt_dir/test
+--replace_regex $regexp
+--cat_file $MYSQL_DATA_DIR.files.txt
+--remove_file $MYSQL_DATA_DIR.files.txt
+
+--replace_result $MYSQL_TMP_DIR MYSQL_TMP_DIR
+SHOW CREATE TABLE t1n;
+ALTER TABLE t1n DROP INDEX c4;
+
+--echo ### files in MYSQL_DATA_DIR/test
+--list_files_write_file $MYSQL_DATA_DIR.files.txt $MYSQL_DATA_DIR/test
+--replace_regex $regexp
+--cat_file $MYSQL_DATA_DIR.files.txt
+--remove_file $MYSQL_DATA_DIR.files.txt
+--echo ### files in MYSQL_TMP_DIR/alt_dir/test
+--list_files_write_file $MYSQL_DATA_DIR.files.txt $MYSQL_TMP_DIR/alt_dir/test
+--replace_regex $regexp
+--cat_file $MYSQL_DATA_DIR.files.txt
+--remove_file $MYSQL_DATA_DIR.files.txt
+
+--error ER_DUP_FIELDNAME
+ALTER TABLE t1n CHANGE c4 c1 INT, ADD INDEX(c1), ALGORITHM=INPLACE;
+ALTER TABLE t1n CHANGE c4 c11 INT, ADD INDEX(c11), ALGORITHM=INPLACE;
+
+--echo ### files in MYSQL_DATA_DIR/test
+--list_files_write_file $MYSQL_DATA_DIR.files.txt $MYSQL_DATA_DIR/test
+--replace_regex $regexp
+--cat_file $MYSQL_DATA_DIR.files.txt
+--remove_file $MYSQL_DATA_DIR.files.txt
+--echo ### files in MYSQL_TMP_DIR/alt_dir/test
+--list_files_write_file $MYSQL_DATA_DIR.files.txt $MYSQL_TMP_DIR/alt_dir/test
+--replace_regex $regexp
+--cat_file $MYSQL_DATA_DIR.files.txt
+--remove_file $MYSQL_DATA_DIR.files.txt
+
+--replace_result $MYSQL_TMP_DIR MYSQL_TMP_DIR
+SHOW CREATE TABLE t1n;
+DROP TABLE t1n;
+
+ALTER TABLE t1o MODIFY c1 BIGINT UNSIGNED NOT NULL;
+
+--echo ### files in MYSQL_DATA_DIR/test
+--list_files_write_file $MYSQL_DATA_DIR.files.txt $MYSQL_DATA_DIR/test
+--replace_regex $regexp
+--cat_file $MYSQL_DATA_DIR.files.txt
+--remove_file $MYSQL_DATA_DIR.files.txt
+--echo ### files in MYSQL_TMP_DIR/alt_dir/test
+--list_files_write_file $MYSQL_DATA_DIR.files.txt $MYSQL_TMP_DIR/alt_dir/test
+--replace_regex $regexp
+--cat_file $MYSQL_DATA_DIR.files.txt
+--remove_file $MYSQL_DATA_DIR.files.txt
+
+ALTER TABLE t1o ADD FULLTEXT INDEX(ct),
+CHANGE c1 FTS_DOC_ID BIGINT UNSIGNED NOT NULL,
+ALGORITHM=INPLACE;
+
+--echo ### files in MYSQL_DATA_DIR/test
+--list_files_write_file $MYSQL_DATA_DIR.files.txt $MYSQL_DATA_DIR/test
+--replace_regex $regexp
+--cat_file $MYSQL_DATA_DIR.files.txt
+--remove_file $MYSQL_DATA_DIR.files.txt
+--echo ### files in MYSQL_TMP_DIR/alt_dir/test
+--list_files_write_file $MYSQL_DATA_DIR.files.txt $MYSQL_TMP_DIR/alt_dir/test
+--replace_regex $regexp
+--cat_file $MYSQL_DATA_DIR.files.txt
+--remove_file $MYSQL_DATA_DIR.files.txt
+
+# This would create a hidden FTS_DOC_ID column, which cannot be done online.
+--error ER_ALTER_OPERATION_NOT_SUPPORTED_REASON
+ALTER TABLE t1o CHANGE FTS_DOC_ID foo_id BIGINT UNSIGNED NOT NULL,
+LOCK=NONE;
+
+# This should not show duplicates.
+SELECT sc.pos FROM information_schema.innodb_sys_columns sc
+INNER JOIN information_schema.innodb_sys_tables st
+ON sc.TABLE_ID=st.TABLE_ID
+WHERE st.NAME='test/t1o' AND sc.NAME='FTS_DOC_ID';
+
+--replace_result $MYSQL_TMP_DIR MYSQL_TMP_DIR
+SHOW CREATE TABLE t1o;
+
+ALTER TABLE t1o CHANGE FTS_DOC_ID foo_id BIGINT UNSIGNED NOT NULL,
+DROP INDEX ct, LOCK=NONE;
+
+--echo ### files in MYSQL_DATA_DIR/test
+--list_files_write_file $MYSQL_DATA_DIR.files.txt $MYSQL_DATA_DIR/test
+--replace_regex $regexp
+--cat_file $MYSQL_DATA_DIR.files.txt
+--remove_file $MYSQL_DATA_DIR.files.txt
+--echo ### files in MYSQL_TMP_DIR/alt_dir/test
+--list_files_write_file $MYSQL_DATA_DIR.files.txt $MYSQL_TMP_DIR/alt_dir/test
+--replace_regex $regexp
+--cat_file $MYSQL_DATA_DIR.files.txt
+--remove_file $MYSQL_DATA_DIR.files.txt
+
+--replace_result $MYSQL_TMP_DIR MYSQL_TMP_DIR
+SHOW CREATE TABLE t1o;
+
+DROP TABLE t1c, t1p, sys_tables, sys_indexes, sys_foreign;
+
+# Check the internal schemata of tt, t1o.
+
+CREATE TABLE sys_tables SELECT * FROM INFORMATION_SCHEMA.INNODB_SYS_TABLES
+WHERE NAME='test/t1o';
+CREATE TABLE sys_indexes SELECT i.* FROM INFORMATION_SCHEMA.INNODB_SYS_INDEXES i
+INNER JOIN sys_tables st ON i.TABLE_ID=st.TABLE_ID;
+CREATE TABLE sys_foreign SELECT i.*
+FROM INFORMATION_SCHEMA.INNODB_SYS_FOREIGN i WHERE FOR_NAME='test/t1o';
+
+-- source suite/innodb/include/innodb_dict.inc
+
+# Ensure that there exists no hidden FTS_DOC_ID_INDEX on foo_id.
+
+ALTER TABLE t1o ADD UNIQUE INDEX FTS_DOC_ID_INDEX(foo_id);
+
+--echo ### files in MYSQL_DATA_DIR/test
+--list_files_write_file $MYSQL_DATA_DIR.files.txt $MYSQL_DATA_DIR/test
+--replace_regex $regexp
+--cat_file $MYSQL_DATA_DIR.files.txt
+--remove_file $MYSQL_DATA_DIR.files.txt
+--echo ### files in MYSQL_TMP_DIR/alt_dir/test
+--list_files_write_file $MYSQL_DATA_DIR.files.txt $MYSQL_TMP_DIR/alt_dir/test
+--replace_regex $regexp
+--cat_file $MYSQL_DATA_DIR.files.txt
+--remove_file $MYSQL_DATA_DIR.files.txt
+
+ALTER TABLE t1o CHANGE foo_id FTS_DOC_ID BIGINT UNSIGNED NOT NULL,
+ADD FULLTEXT INDEX(ct);
+
+--echo ### files in MYSQL_DATA_DIR/test
+--list_files_write_file $MYSQL_DATA_DIR.files.txt $MYSQL_DATA_DIR/test
+--replace_regex $regexp
+--cat_file $MYSQL_DATA_DIR.files.txt
+--remove_file $MYSQL_DATA_DIR.files.txt
+--echo ### files in MYSQL_TMP_DIR/alt_dir/test
+--list_files_write_file $MYSQL_DATA_DIR.files.txt $MYSQL_TMP_DIR/alt_dir/test
+--replace_regex $regexp
+--cat_file $MYSQL_DATA_DIR.files.txt
+--remove_file $MYSQL_DATA_DIR.files.txt
+
+--error ER_INNODB_FT_WRONG_DOCID_INDEX
+ALTER TABLE t1o CHANGE FTS_DOC_ID foo_id BIGINT UNSIGNED NOT NULL;
+
+DROP TABLE sys_indexes;
+CREATE TABLE sys_indexes SELECT i.* FROM INFORMATION_SCHEMA.INNODB_SYS_INDEXES i
+INNER JOIN sys_tables st ON i.TABLE_ID=st.TABLE_ID;
+
+-- source suite/innodb/include/innodb_dict.inc
+
+--echo #
+--echo # Cleanup
+--echo #
+
+DROP TABLE tt, t1o, sys_tables, sys_indexes, sys_foreign;
+
+--echo ### files in MYSQL_DATA_DIR/test
+--list_files_write_file $MYSQL_DATA_DIR.files.txt $MYSQL_DATA_DIR/test
+--replace_regex $regexp
+--cat_file $MYSQL_DATA_DIR.files.txt
+--remove_file $MYSQL_DATA_DIR.files.txt
+--echo ### files in MYSQL_TMP_DIR/alt_dir/test
+--replace_regex $regexp
+--list_files $MYSQL_TMP_DIR/alt_dir/test
+--rmdir $MYSQL_TMP_DIR/alt_dir/test
+--rmdir $MYSQL_TMP_DIR/alt_dir
+
+SET GLOBAL innodb_file_per_table = @innodb_file_per_table_orig;
diff --git a/mysql-test/suite/innodb/t/innodb-xa.test b/mysql-test/suite/innodb/t/innodb-xa.test
new file mode 100644
index 00000000..9eb5848b
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb-xa.test
@@ -0,0 +1,50 @@
+--source include/have_innodb.inc
+
+--error ER_XAER_NOTA
+xa rollback 'xid2';
+drop table if exists t1;
+create table t1(a int)engine=innodb;
+rollback;
+xa start 'xid2';
+insert into `t1` values (1);
+savepoint `sv1`;
+xa end 'xid2';
+--error ER_XAER_RMFAIL
+start transaction;
+xa prepare 'xid2';
+release savepoint `sv1`;
+xa commit 'xid2';
+drop table t1;
+
+-- echo #
+-- echo # MDEV-31928 Assertion xid ... < 128 failed in trx_undo_write_xid()
+-- echo #
+
+CREATE TABLE t (a INT PRIMARY KEY) ENGINE=INNODB;
+--error ER_PARSE_ERROR
+XA START 'gtrid_67890123456789012345678901234567890123456789012345678901234','bqual_6789012345678901234567890123456789012345678901234567890123',1234567890;
+--error ER_PARSE_ERROR
+XA START 'gtrid_6789012345678901234567890123456789012345678901234567890123','bqual_67890123456789012345678901234567890123456789012345678901234',1234567890;
+XA START 'gtrid_6789012345678901234567890123456789012345678901234567890123','bqual_6789012345678901234567890123456789012345678901234567890123',1234567890;
+
+INSERT INTO t VALUES(1);
+
+--error ER_PARSE_ERROR
+XA END 'gtrid_67890123456789012345678901234567890123456789012345678901234','bqual_6789012345678901234567890123456789012345678901234567890123',1234567890;
+--error ER_PARSE_ERROR
+XA END 'gtrid_6789012345678901234567890123456789012345678901234567890123','bqual_67890123456789012345678901234567890123456789012345678901234',1234567890;
+XA END 'gtrid_6789012345678901234567890123456789012345678901234567890123','bqual_6789012345678901234567890123456789012345678901234567890123',1234567890;
+--error ER_PARSE_ERROR
+XA PREPARE 'gtrid_67890123456789012345678901234567890123456789012345678901234','bqual_6789012345678901234567890123456789012345678901234567890123',1234567890;
+--error ER_PARSE_ERROR
+XA PREPARE 'gtrid_6789012345678901234567890123456789012345678901234567890123','bqual_67890123456789012345678901234567890123456789012345678901234',1234567890;
+XA PREPARE 'gtrid_6789012345678901234567890123456789012345678901234567890123','bqual_6789012345678901234567890123456789012345678901234567890123',1234567890;
+--error ER_PARSE_ERROR
+XA COMMIT 'gtrid_67890123456789012345678901234567890123456789012345678901234','bqual_6789012345678901234567890123456789012345678901234567890123',1234567890;
+--error ER_PARSE_ERROR
+XA COMMIT 'gtrid_6789012345678901234567890123456789012345678901234567890123','bqual_67890123456789012345678901234567890123456789012345678901234',1234567890;
+XA COMMIT 'gtrid_6789012345678901234567890123456789012345678901234567890123','bqual_6789012345678901234567890123456789012345678901234567890123',1234567890;
+
+DROP TABLE t;
+
+-- echo # End of 10.4 tests
diff --git a/mysql-test/suite/innodb/t/innodb.opt b/mysql-test/suite/innodb/t/innodb.opt
new file mode 100644
index 00000000..59e43fea
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb.opt
@@ -0,0 +1 @@
+--innodb-defragment=0 \ No newline at end of file
diff --git a/mysql-test/suite/innodb/t/innodb.test b/mysql-test/suite/innodb/t/innodb.test
new file mode 100644
index 00000000..30797d3a
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb.test
@@ -0,0 +1,2611 @@
+-- source include/have_innodb.inc
+-- source include/have_innodb_16k.inc
+
+let $MYSQLD_DATADIR= `select @@datadir`;
+
+let collation=utf8mb3_unicode_ci;
+--source include/have_collation.inc
+
+create temporary table t (a char(1) character set filename) engine=innodb;
+drop temporary table t;
+
+set optimizer_switch = 'mrr=on,mrr_sort_keys=on,index_condition_pushdown=on';
+
+# Save the original values of some variables in order to be able to
+# estimate how much they have changed during the tests. Previously this
+# test assumed that e.g. rows_deleted is 0 here and after deleting 23
+# rows it expected that rows_deleted will be 23. Now we do not make
+# assumptions about the values of the variables at the beginning, e.g.
+# rows_deleted should be 23 + "rows_deleted before the test". This allows
+# the test to be run multiple times without restarting the mysqld server.
+# See Bug#43309 Test main.innodb can't be run twice
+-- disable_query_log
+call mtr.add_suppression("Cannot add field .* in table .* because after adding it, the row size is");
+call mtr.add_suppression("\\[ERROR\\] InnoDB: in ALTER TABLE `test`.`t1`");
+call mtr.add_suppression("\\[ERROR\\] InnoDB: in RENAME TABLE table `test`.`t1`");
+
+--disable_warnings
+SET @innodb_row_lock_waits_orig = (SELECT variable_value FROM information_schema.global_status WHERE LOWER(variable_name) = 'innodb_row_lock_waits');
+SET @innodb_row_lock_current_waits_orig = (SELECT variable_value FROM information_schema.global_status WHERE LOWER(variable_name) = 'innodb_row_lock_current_waits');
+SET @innodb_row_lock_time_orig = (SELECT variable_value FROM information_schema.global_status WHERE LOWER(variable_name) = 'innodb_row_lock_time');
+SET @innodb_row_lock_time_max_orig = (SELECT variable_value FROM information_schema.global_status WHERE LOWER(variable_name) = 'innodb_row_lock_time_max');
+SET @innodb_row_lock_time_avg_orig = (SELECT variable_value FROM information_schema.global_status WHERE LOWER(variable_name) = 'innodb_row_lock_time_avg');
+--enable_warnings
+-- enable_query_log
+
+--disable_warnings
+drop table if exists t1,t2,t3,t4;
+drop database if exists mysqltest;
+--enable_warnings
+
+# Bug#58912 InnoDB unnecessarily avoids update-in-place on column prefixes
+CREATE TABLE bug58912 (a BLOB, b TEXT, PRIMARY KEY(a(1))) ENGINE=InnoDB;
+INSERT INTO bug58912 VALUES(REPEAT('a',8000),REPEAT('b',8000));
+UPDATE bug58912 SET a=REPEAT('a',7999);
+# The above statements used to trigger a failure during purge when
+# Bug#55284 was fixed while Bug#58912 was not. Defer the DROP TABLE,
+# so that purge gets a chance to run (and a double free of the
+# off-page column can be detected, if one is to occur.)
+
+#
+# Small basic test with ignore
+#
+
+create table t1 (id int unsigned not null auto_increment, code tinyint unsigned not null, name char(20) not null, primary key (id), key (code), unique (name)) engine=innodb;
+
+insert into t1 (code, name) values (1, 'Tim'), (1, 'Monty'), (2, 'David'), (2, 'Erik'), (3, 'Sasha'), (3, 'Jeremy'), (4, 'Matt');
+select id, code, name from t1 order by id;
+
+update ignore t1 set id = 8, name = 'Sinisa' where id < 3;
+select id, code, name from t1 order by id;
+update ignore t1 set id = id + 10, name = 'Ralph' where id < 4;
+select id, code, name from t1 order by id;
+
+drop table t1;
+
+#
+# A bit bigger test
+# The 'replace_column' statements are needed because the cardinality calculated
+# by innodb is not always the same between runs
+#
+
+CREATE TABLE t1 (
+ id int(11) NOT NULL auto_increment,
+ parent_id int(11) DEFAULT '0' NOT NULL,
+ level tinyint(4) DEFAULT '0' NOT NULL,
+ PRIMARY KEY (id),
+ KEY parent_id (parent_id),
+ KEY level (level)
+) engine=innodb stats_persistent=0;
+INSERT INTO t1 VALUES (1,0,0),(3,1,1),(4,1,1),(8,2,2),(9,2,2),(17,3,2),(22,4,2),(24,4,2),(28,5,2),(29,5,2),(30,5,2),(31,6,2),(32,6,2),(33,6,2),(203,7,2),(202,7,2),(20,3,2),(157,0,0),(193,5,2),(40,7,2),(2,1,1),(15,2,2),(6,1,1),(34,6,2),(35,6,2),(16,3,2),(7,1,1),(36,7,2),(18,3,2),(26,5,2),(27,5,2),(183,4,2),(38,7,2),(25,5,2),(37,7,2),(21,4,2),(19,3,2),(5,1,1),(179,5,2);
+update t1 set parent_id=parent_id+100;
+select * from t1 where parent_id=102;
+update t1 set id=id+1000;
+-- error ER_DUP_ENTRY,1022
+update t1 set id=1024 where id=1009;
+select * from t1;
+update ignore t1 set id=id+1; # This will change all rows
+select * from t1;
+update ignore t1 set id=1023 where id=1010;
+select * from t1 where parent_id=102;
+--replace_column 9 #
+explain select level from t1 where level=1;
+--replace_column 9 #
+explain select level,id from t1 where level=1;
+--replace_column 9 #
+explain select level,id,parent_id from t1 where level=1;
+select level,id from t1 where level=1;
+select level,id,parent_id from t1 where level=1;
+optimize table t1;
+--replace_column 7 #
+show keys from t1;
+drop table t1;
+
+#
+# Test replace
+#
+
+CREATE TABLE t1 (
+ gesuchnr int(11) DEFAULT '0' NOT NULL,
+ benutzer_id int(11) DEFAULT '0' NOT NULL,
+ PRIMARY KEY (gesuchnr,benutzer_id)
+) engine=innodb;
+
+replace into t1 (gesuchnr,benutzer_id) values (2,1);
+replace into t1 (gesuchnr,benutzer_id) values (1,1);
+replace into t1 (gesuchnr,benutzer_id) values (1,1);
+select * from t1;
+drop table t1;
+
+#
+# test delete using hidden_primary_key
+#
+
+create table t1 (a int) engine=innodb;
+insert into t1 values (1), (2);
+optimize table t1;
+delete from t1 where a = 1;
+select * from t1;
+check table t1;
+drop table t1;
+
+create table t1 (a int,b varchar(20)) engine=innodb;
+insert into t1 values (1,""), (2,"testing");
+delete from t1 where a = 1;
+select * from t1;
+create index skr on t1 (a);
+insert into t1 values (3,""), (4,"testing");
+analyze table t1;
+--replace_column 7 #
+show keys from t1;
+drop table t1;
+
+
+# Test of reading on secondary key with may be null
+
+create table t1 (a int,b varchar(20),key(a)) engine=innodb;
+insert into t1 values (1,""), (2,"testing");
+select * from t1 where a = 1;
+drop table t1;
+
+#
+# Test rollback
+#
+
+create table t1 (n int not null primary key) engine=innodb;
+set autocommit=0;
+insert into t1 values (4);
+rollback;
+select n, "after rollback" from t1;
+insert into t1 values (4);
+commit;
+select n, "after commit" from t1;
+commit;
+insert into t1 values (5);
+-- error ER_DUP_ENTRY
+insert into t1 values (4);
+commit;
+select n, "after commit" from t1;
+set autocommit=1;
+insert into t1 values (6);
+-- error ER_DUP_ENTRY
+insert into t1 values (4);
+select n from t1;
+set autocommit=0;
+#
+# savepoints
+#
+begin;
+savepoint `my_savepoint`;
+insert into t1 values (7);
+savepoint `savept2`;
+insert into t1 values (3);
+select n from t1;
+savepoint savept3;
+rollback to savepoint savept2;
+--error 1305
+rollback to savepoint savept3;
+rollback to savepoint savept2;
+release savepoint `my_savepoint`;
+select n from t1;
+-- error 1305
+rollback to savepoint `my_savepoint`;
+--error 1305
+rollback to savepoint savept2;
+insert into t1 values (8);
+savepoint sv;
+commit;
+savepoint sv;
+set autocommit=1;
+# nop
+rollback;
+drop table t1;
+
+#
+# Test for commit and FLUSH TABLES WITH READ LOCK
+#
+
+create table t1 (n int not null primary key) engine=innodb;
+start transaction;
+insert into t1 values (4);
+flush tables with read lock;
+#
+# Current code can't handle a read lock in middle of transaction
+#--error 1223;
+commit;
+unlock tables;
+commit;
+select * from t1;
+drop table t1;
+
+#
+# Testing transactions
+#
+
+create table t1 ( id int NOT NULL PRIMARY KEY, nom varchar(64)) engine=innodb;
+begin;
+insert into t1 values(1,'hamdouni');
+select id as afterbegin_id,nom as afterbegin_nom from t1;
+rollback;
+select id as afterrollback_id,nom as afterrollback_nom from t1;
+set autocommit=0;
+insert into t1 values(2,'mysql');
+select id as afterautocommit0_id,nom as afterautocommit0_nom from t1;
+rollback;
+select id as afterrollback_id,nom as afterrollback_nom from t1;
+set autocommit=1;
+drop table t1;
+
+#
+# Simple not autocommit test
+#
+
+CREATE TABLE t1 (id char(8) not null primary key, val int not null) engine=innodb;
+insert into t1 values ('pippo', 12);
+-- error ER_DUP_ENTRY
+insert into t1 values ('pippo', 12); # Gives error
+delete from t1;
+delete from t1 where id = 'pippo';
+select * from t1;
+
+insert into t1 values ('pippo', 12);
+set autocommit=0;
+delete from t1;
+rollback;
+select * from t1;
+delete from t1;
+commit;
+select * from t1;
+drop table t1;
+
+#
+# Test of active transactions
+#
+
+create table t1 (a integer) engine=innodb;
+start transaction;
+rename table t1 to t2;
+create table t1 (b integer) engine=innodb;
+insert into t1 values (1);
+rollback;
+drop table t1;
+rename table t2 to t1;
+drop table t1;
+set autocommit=1;
+
+#
+# The following simple tests failed at some point
+#
+
+CREATE TABLE t1 (ID INTEGER NOT NULL PRIMARY KEY, NAME VARCHAR(64)) ENGINE=innodb;
+INSERT INTO t1 VALUES (1, 'Jochen');
+select * from t1;
+drop table t1;
+
+CREATE TABLE t1 ( _userid VARCHAR(60) NOT NULL PRIMARY KEY) ENGINE=innodb;
+set autocommit=0;
+INSERT INTO t1 SET _userid='marc@anyware.co.uk';
+COMMIT;
+SELECT * FROM t1;
+SELECT _userid FROM t1 WHERE _userid='marc@anyware.co.uk';
+drop table t1;
+set autocommit=1;
+
+#
+# Test when reading on part of unique key
+#
+CREATE TABLE t1 (
+ user_id int(10) DEFAULT '0' NOT NULL,
+ name varchar(100),
+ phone varchar(100),
+ ref_email varchar(100) DEFAULT '' NOT NULL,
+ detail varchar(200),
+ PRIMARY KEY (user_id,ref_email)
+)engine=innodb;
+
+INSERT INTO t1 VALUES (10292,'sanjeev','29153373','sansh777@hotmail.com','xxx'),(10292,'shirish','2333604','shirish@yahoo.com','ddsds'),(10292,'sonali','323232','sonali@bolly.com','filmstar');
+select * from t1 where user_id=10292;
+INSERT INTO t1 VALUES (10291,'sanjeev','29153373','sansh777@hotmail.com','xxx'),(10293,'shirish','2333604','shirish@yahoo.com','ddsds');
+select * from t1 where user_id=10292;
+select * from t1 where user_id>=10292;
+select * from t1 where user_id>10292;
+select * from t1 where user_id<10292;
+drop table t1;
+
+#
+# Test that keys are created in right order
+#
+
+CREATE TABLE t1 (a int not null, b int not null,c int not null,
+key(a),primary key(a,b), unique(c),key(a),unique(b));
+--replace_column 7 #
+show index from t1;
+drop table t1;
+
+#
+# Test of ALTER TABLE and innodb tables
+#
+
+create table t1 (col1 int not null, col2 char(4) not null, primary key(col1));
+alter table t1 engine=innodb;
+insert into t1 values ('1','1'),('5','2'),('2','3'),('3','4'),('4','4');
+select * from t1;
+update t1 set col2='7' where col1='4';
+select * from t1;
+alter table t1 add co3 int not null;
+select * from t1;
+update t1 set col2='9' where col1='2';
+select * from t1;
+drop table t1;
+
+#
+# INSERT INTO innodb tables
+#
+
+create table t1 (a int not null , b int, primary key (a)) engine = innodb;
+create table t2 (a int not null , b int, primary key (a)) engine = myisam;
+insert into t1 VALUES (1,3) , (2,3), (3,3);
+select * from t1;
+insert into t2 select * from t1;
+select * from t2;
+delete from t1 where b = 3;
+select * from t1;
+insert into t1 select * from t2;
+select * from t1;
+select * from t2;
+drop table t1,t2;
+
+#
+# ORDER BY on not primary key
+#
+
+CREATE TABLE t1 (
+ user_name varchar(12),
+ password text,
+ subscribed char(1),
+ user_id int(11) DEFAULT '0' NOT NULL,
+ quota bigint(20),
+ weight double,
+ access_date date,
+ access_time time,
+ approved datetime,
+ dummy_primary_key int(11) NOT NULL auto_increment,
+ PRIMARY KEY (dummy_primary_key)
+) ENGINE=innodb;
+INSERT INTO t1 VALUES ('user_0','somepassword','N',0,0,0,'2000-09-07','23:06:59','2000-09-07 23:06:59',1);
+INSERT INTO t1 VALUES ('user_1','somepassword','Y',1,1,1,'2000-09-07','23:06:59','2000-09-07 23:06:59',2);
+INSERT INTO t1 VALUES ('user_2','somepassword','N',2,2,1.4142135623731,'2000-09-07','23:06:59','2000-09-07 23:06:59',3);
+INSERT INTO t1 VALUES ('user_3','somepassword','Y',3,3,1.7320508075689,'2000-09-07','23:06:59','2000-09-07 23:06:59',4);
+INSERT INTO t1 VALUES ('user_4','somepassword','N',4,4,2,'2000-09-07','23:06:59','2000-09-07 23:06:59',5);
+select user_name, password , subscribed, user_id, quota, weight, access_date, access_time, approved, dummy_primary_key from t1 order by user_name;
+drop table t1;
+
+#
+# Testing of tables without primary keys
+#
+
+CREATE TABLE t1 (
+ id int(11) NOT NULL auto_increment,
+ parent_id int(11) DEFAULT '0' NOT NULL,
+ level tinyint(4) DEFAULT '0' NOT NULL,
+ KEY (id),
+ KEY parent_id (parent_id),
+ KEY level (level)
+) engine=innodb;
+INSERT INTO t1 VALUES (1,0,0),(3,1,1),(4,1,1),(8,2,2),(9,2,2),(17,3,2),(22,4,2),(24,4,2),(28,5,2),(29,5,2),(30,5,2),(31,6,2),(32,6,2),(33,6,2),(203,7,2),(202,7,2),(20,3,2),(157,0,0),(193,5,2),(40,7,2),(2,1,1),(15,2,2),(6,1,1),(34,6,2),(35,6,2),(16,3,2),(7,1,1),(36,7,2),(18,3,2),(26,5,2),(27,5,2),(183,4,2),(38,7,2),(25,5,2),(37,7,2),(21,4,2),(19,3,2),(5,1,1);
+INSERT INTO t1 values (179,5,2);
+update t1 set parent_id=parent_id+100;
+select * from t1 where parent_id=102;
+update t1 set id=id+1000;
+update t1 set id=1024 where id=1009;
+select * from t1;
+update ignore t1 set id=id+1; # This will change all rows
+select * from t1;
+update ignore t1 set id=1023 where id=1010;
+select * from t1 where parent_id=102;
+--replace_column 9 #
+explain select level from t1 where level=1;
+select level,id from t1 where level=1;
+select level,id,parent_id from t1 where level=1;
+select level,id from t1 where level=1 order by id;
+delete from t1 where level=1;
+select * from t1;
+drop table t1;
+
+#
+# Test of index only reads
+#
+CREATE TABLE t1 (
+ sca_code char(6) NOT NULL,
+ cat_code char(6) NOT NULL,
+ sca_desc varchar(50),
+ lan_code char(2) NOT NULL,
+ sca_pic varchar(100),
+ sca_sdesc varchar(50),
+ sca_sch_desc varchar(16),
+ PRIMARY KEY (sca_code, cat_code, lan_code),
+ INDEX sca_pic (sca_pic)
+) engine = innodb ;
+
+INSERT INTO t1 ( sca_code, cat_code, sca_desc, lan_code, sca_pic, sca_sdesc, sca_sch_desc) VALUES ( 'PD', 'J', 'PENDANT', 'EN', NULL, NULL, 'PENDANT'),( 'RI', 'J', 'RING', 'EN', NULL, NULL, 'RING'),( 'QQ', 'N', 'RING', 'EN', 'not null', NULL, 'RING');
+select count(*) from t1 where sca_code = 'PD';
+select count(*) from t1 where sca_code <= 'PD';
+select count(*) from t1 where sca_pic is null;
+alter table t1 drop index sca_pic, add index sca_pic (cat_code, sca_pic);
+select count(*) from t1 where sca_code='PD' and sca_pic is null;
+select count(*) from t1 where cat_code='E';
+
+alter table t1 drop index sca_pic, add index (sca_pic, cat_code);
+select count(*) from t1 where sca_code='PD' and sca_pic is null;
+select count(*) from t1 where sca_pic >= 'n';
+select sca_pic from t1 where sca_pic is null;
+update t1 set sca_pic="test" where sca_pic is null;
+delete from t1 where sca_code='pd';
+drop table t1;
+
+#
+# Test of opening table twice and timestamps
+#
+set @a:=now();
+CREATE TABLE t1 (a int not null, b timestamp not null default
+current_timestamp on update current_timestamp, primary key (a)) engine=innodb;
+insert into t1 (a) values(1),(2),(3);
+select t1.a from t1 natural join t1 as t2 where t1.b >= @a order by t1.a;
+select a from t1 natural join t1 as t2 where b >= @a order by a;
+update t1 set a=5 where a=1;
+select a from t1;
+drop table t1;
+
+#
+# Test with variable length primary key
+#
+create table t1 (a varchar(100) not null, primary key(a), b int not null) engine=innodb;
+insert into t1 values("hello",1),("world",2);
+select * from t1 order by b desc;
+optimize table t1;
+--replace_column 7 #
+show keys from t1;
+drop table t1;
+
+#
+# Test of create index with NULL columns
+#
+create table t1 (i int, j int ) ENGINE=innodb;
+insert into t1 values (1,2);
+select * from t1 where i=1 and j=2;
+create index ax1 on t1 (i,j);
+select * from t1 where i=1 and j=2;
+drop table t1;
+
+#
+# Test min-max optimization
+#
+
+CREATE TABLE t1 (
+ a int3 unsigned NOT NULL,
+ b int1 unsigned NOT NULL,
+ UNIQUE (a, b)
+) ENGINE = innodb;
+
+INSERT INTO t1 VALUES (1, 1);
+SELECT MIN(B),MAX(b) FROM t1 WHERE t1.a = 1;
+drop table t1;
+
+#
+# Test INSERT DELAYED
+#
+
+CREATE TABLE t1 (a int unsigned NOT NULL) engine=innodb;
+# Can't test this in 3.23
+# INSERT DELAYED INTO t1 VALUES (1);
+INSERT INTO t1 VALUES (1);
+SELECT * FROM t1;
+DROP TABLE t1;
+
+
+#
+# Crash when using many tables (Test case by Jeremy D Zawodny)
+#
+
+create table t1 (a int primary key,b int, c int, d int, e int, f int, g int, h int, i int, j int, k int, l int, m int, n int, o int, p int, q int, r int, s int, t int, u int, v int, w int, x int, y int, z int, a1 int, a2 int, a3 int, a4 int, a5 int, a6 int, a7 int, a8 int, a9 int, b1 int, b2 int, b3 int, b4 int, b5 int, b6 int) engine = innodb;
+insert into t1 values (1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1);
+--replace_column 9 #
+--replace_result "Using where" "Using index condition"
+explain select * from t1 where a > 0 and a < 50;
+drop table t1;
+
+#
+# Test lock tables
+#
+
+create table t1 (id int NOT NULL,id2 int NOT NULL,id3 int NOT NULL,dummy1 char(30),primary key (id,id2),index index_id3 (id3)) engine=innodb;
+insert into t1 values (0,0,0,'ABCDEFGHIJ'),(2,2,2,'BCDEFGHIJK'),(1,1,1,'CDEFGHIJKL');
+LOCK TABLES t1 WRITE;
+--error ER_DUP_ENTRY
+insert into t1 values (99,1,2,'D'),(1,1,2,'D');
+select id from t1;
+select id from t1;
+UNLOCK TABLES;
+DROP TABLE t1;
+
+create table t1 (id int NOT NULL,id2 int NOT NULL,id3 int NOT NULL,dummy1 char(30),primary key (id,id2),index index_id3 (id3)) engine=innodb;
+insert into t1 values (0,0,0,'ABCDEFGHIJ'),(2,2,2,'BCDEFGHIJK'),(1,1,1,'CDEFGHIJKL');
+LOCK TABLES t1 WRITE;
+begin;
+--error ER_DUP_ENTRY
+insert into t1 values (99,1,2,'D'),(1,1,2,'D');
+select id from t1;
+insert ignore into t1 values (100,1,2,'D'),(1,1,99,'D');
+commit;
+select id,id3 from t1;
+UNLOCK TABLES;
+DROP TABLE t1;
+
+#
+# Test prefix key
+#
+create table t1 (a char(20), unique (a(5))) engine=innodb;
+drop table t1;
+create table t1 (a char(20), index (a(5))) engine=innodb;
+show create table t1;
+drop table t1;
+
+#
+# Test using temporary table and auto_increment
+#
+
+create temporary table t1 (a int not null auto_increment, primary key(a)) engine=innodb;
+insert into t1 values (NULL),(NULL),(NULL);
+delete from t1 where a=3;
+insert into t1 values (NULL);
+select * from t1;
+alter table t1 add b int;
+select * from t1;
+drop table t1;
+
+#Slashdot bug
+create table t1
+ (
+ id int auto_increment primary key,
+ name varchar(32) not null,
+ value text not null,
+ uid int not null,
+ unique key(name,uid)
+ ) engine=innodb;
+insert into t1 values (1,'one','one value',101),
+ (2,'two','two value',102),(3,'three','three value',103);
+set insert_id=5;
+replace into t1 (value,name,uid) values ('other value','two',102);
+delete from t1 where uid=102;
+set insert_id=5;
+replace into t1 (value,name,uid) values ('other value','two',102);
+set insert_id=6;
+replace into t1 (value,name,uid) values ('other value','two',102);
+select * from t1;
+drop table t1;
+
+#
+# Test DROP DATABASE
+#
+
+create database mysqltest;
+create table mysqltest.t1 (a int not null) engine= innodb;
+insert into mysqltest.t1 values(1);
+create table mysqltest.t2 (a int not null) engine= myisam;
+insert into mysqltest.t2 values(1);
+create table mysqltest.t3 (a int not null) engine= heap;
+insert into mysqltest.t3 values(1);
+commit;
+drop database mysqltest;
+# Don't check error message
+--error 1049
+show tables from mysqltest;
+
+#
+# Test truncate table with and without auto_commit
+#
+
+set autocommit=0;
+create table t1 (a int not null) engine= innodb;
+insert into t1 values(1),(2);
+truncate table t1;
+commit;
+truncate table t1;
+truncate table t1;
+select * from t1;
+insert into t1 values(1),(2);
+delete from t1;
+select * from t1;
+commit;
+drop table t1;
+set autocommit=1;
+
+create table t1 (a int not null) engine= innodb;
+insert into t1 values(1),(2);
+truncate table t1;
+insert into t1 values(1),(2);
+select * from t1;
+truncate table t1;
+insert into t1 values(1),(2);
+delete from t1;
+select * from t1;
+drop table t1;
+
+#
+# Test of how ORDER BY works when doing it on the whole table
+#
+
+create table t1 (a int not null, b int not null, c int not null, primary key (a),key(b)) engine=innodb;
+insert into t1 values (3,3,3),(1,1,1),(2,2,2),(4,4,4);
+--replace_column 9 #
+explain select * from t1 order by a;
+--replace_column 9 #
+explain select * from t1 order by b;
+--replace_column 9 #
+explain select * from t1 order by c;
+--replace_column 9 #
+explain select a from t1 order by a;
+--replace_column 9 #
+explain select b from t1 order by b;
+--replace_column 9 #
+explain select a,b from t1 order by b;
+--replace_column 9 #
+explain select a,b from t1;
+--replace_column 9 #
+explain select a,b,c from t1;
+drop table t1;
+
+#
+# Check describe
+#
+
+create table t1 (t int not null default 1, key (t)) engine=innodb;
+desc t1;
+drop table t1;
+
+#
+# Test of multi-table-delete
+#
+
+SET sql_mode = 'NO_ENGINE_SUBSTITUTION';
+
+CREATE TABLE t1 (
+ number bigint(20) NOT NULL default '0',
+ cname char(15) NOT NULL default '',
+ carrier_id smallint(6) NOT NULL default '0',
+ privacy tinyint(4) NOT NULL default '0',
+ last_mod_date timestamp NOT NULL,
+ last_mod_id smallint(6) NOT NULL default '0',
+ last_app_date timestamp NOT NULL,
+ last_app_id smallint(6) default '-1',
+ version smallint(6) NOT NULL default '0',
+ assigned_scps int(11) default '0',
+ status tinyint(4) default '0'
+) ENGINE=InnoDB;
+INSERT INTO t1 VALUES (4077711111,'SeanWheeler',90,2,20020111112846,500,00000000000000,-1,2,3,1);
+INSERT INTO t1 VALUES (9197722223,'berry',90,3,20020111112809,500,20020102114532,501,4,10,0);
+INSERT INTO t1 VALUES (650,'San Francisco',0,0,20011227111336,342,00000000000000,-1,1,24,1);
+INSERT INTO t1 VALUES (302467,'Sue\'s Subshop',90,3,20020109113241,500,20020102115111,501,7,24,0);
+INSERT INTO t1 VALUES (6014911113,'SudzCarwash',520,1,20020102115234,500,20020102115259,501,33,32768,0);
+INSERT INTO t1 VALUES (333,'tubs',99,2,20020109113440,501,20020109113440,500,3,10,0);
+CREATE TABLE t2 (
+ number bigint(20) NOT NULL default '0',
+ cname char(15) NOT NULL default '',
+ carrier_id smallint(6) NOT NULL default '0',
+ privacy tinyint(4) NOT NULL default '0',
+ last_mod_date timestamp NOT NULL,
+ last_mod_id smallint(6) NOT NULL default '0',
+ last_app_date timestamp NOT NULL,
+ last_app_id smallint(6) default '-1',
+ version smallint(6) NOT NULL default '0',
+ assigned_scps int(11) default '0',
+ status tinyint(4) default '0'
+) ENGINE=InnoDB;
+INSERT INTO t2 VALUES (4077711111,'SeanWheeler',0,2,20020111112853,500,00000000000000,-1,2,3,1);
+INSERT INTO t2 VALUES (9197722223,'berry',90,3,20020111112818,500,20020102114532,501,4,10,0);
+INSERT INTO t2 VALUES (650,'San Francisco',90,0,20020109113158,342,00000000000000,-1,1,24,1);
+INSERT INTO t2 VALUES (333,'tubs',99,2,20020109113453,501,20020109113453,500,3,10,0);
+select * from t1;
+select * from t2;
+delete t1, t2 from t1 left join t2 on t1.number=t2.number where (t1.carrier_id=90 and t1.number=t2.number) or (t2.carrier_id=90 and t1.number=t2.number) or (t1.carrier_id=90 and t2.number is null);
+select * from t1;
+select * from t2;
+select * from t2;
+drop table t1,t2;
+SET sql_mode = default;
+
+#
+# A simple test with some isolation levels
+# TODO: Make this into a test using replication to really test how
+# this works.
+#
+
+create table t1 (id int unsigned not null auto_increment, code tinyint unsigned not null, name char(20) not null, primary key (id), key (code), unique (name)) engine=innodb;
+
+BEGIN;
+SET SESSION TRANSACTION ISOLATION LEVEL SERIALIZABLE;
+SELECT @@tx_isolation,@@global.tx_isolation;
+insert into t1 (code, name) values (1, 'Tim'), (1, 'Monty'), (2, 'David');
+select id, code, name from t1 order by id;
+COMMIT;
+
+BEGIN;
+SET SESSION TRANSACTION ISOLATION LEVEL REPEATABLE READ;
+insert into t1 (code, name) values (2, 'Erik'), (3, 'Sasha');
+select id, code, name from t1 order by id;
+COMMIT;
+
+SET binlog_format='MIXED';
+BEGIN;
+SET SESSION TRANSACTION ISOLATION LEVEL READ UNCOMMITTED;
+insert into t1 (code, name) values (3, 'Jeremy'), (4, 'Matt');
+select id, code, name from t1 order by id;
+COMMIT;
+DROP TABLE t1;
+
+#
+# Test of multi-table-update
+#
+create table t1 (n int(10), d int(10)) engine=innodb;
+create table t2 (n int(10), d int(10)) engine=innodb;
+insert into t1 values(1,1),(1,2);
+insert into t2 values(1,10),(2,20);
+UPDATE t1,t2 SET t1.d=t2.d,t2.d=30 WHERE t1.n=t2.n;
+select * from t1;
+select * from t2;
+drop table t1,t2;
+
+#
+# Bug #29136 erred multi-delete on trans table does not rollback
+#
+
+# prepare
+--disable_warnings
+drop table if exists t1, t2;
+--enable_warnings
+CREATE TABLE t1 (a int, PRIMARY KEY (a));
+CREATE TABLE t2 (a int, PRIMARY KEY (a)) ENGINE=InnoDB;
+create trigger trg_del_t2 after delete on t2 for each row
+ insert into t1 values (1);
+insert into t1 values (1);
+insert into t2 values (1),(2);
+
+
+# exec cases A, B - see multi_update.test
+
+# A. send_error() w/o send_eof() branch
+
+--error ER_DUP_ENTRY
+delete t2 from t2;
+
+# check
+
+select count(*) from t2 /* must be 2 as restored after rollback caused by the error */;
+
+# cleanup bug#29136
+
+drop table t1, t2;
+
+
+#
+# Bug #29136 erred multi-delete on trans table does not rollback
+#
+
+# prepare
+--disable_warnings
+drop table if exists t1, t2;
+--enable_warnings
+CREATE TABLE t1 (a int, PRIMARY KEY (a));
+CREATE TABLE t2 (a int, PRIMARY KEY (a)) ENGINE=InnoDB;
+create trigger trg_del_t2 after delete on t2 for each row
+ insert into t1 values (1);
+insert into t1 values (1);
+insert into t2 values (1),(2);
+
+
+# exec cases A, B - see multi_update.test
+
+# A. send_error() w/o send_eof() branch
+
+--error ER_DUP_ENTRY
+delete t2 from t2;
+
+# check
+
+select count(*) from t2 /* must be 2 as restored after rollback caused by the error */;
+
+# cleanup bug#29136
+
+drop table t1, t2;
+
+
+#
+# Testing of IFNULL
+#
+create table t1 (a int, b int) engine=innodb;
+insert into t1 values(20,null);
+select t2.b, ifnull(t2.b,"this is null") from t1 as t2 left join t1 as t3 on
+t2.b=t3.a;
+select t2.b, ifnull(t2.b,"this is null") from t1 as t2 left join t1 as t3 on
+t2.b=t3.a order by 1;
+insert into t1 values(10,null);
+select t2.b, ifnull(t2.b,"this is null") from t1 as t2 left join t1 as t3 on
+t2.b=t3.a order by 1;
+drop table t1;
+
+#
+# Test of read_through not existing const_table
+#
+
+create table t1 (a varchar(10) not null) engine=myisam;
+create table t2 (b varchar(10) not null unique) engine=innodb;
+select t1.a from t1,t2 where t1.a=t2.b;
+drop table t1,t2;
+create table t1 (a int not null, b int, primary key (a)) engine = innodb;
+create table t2 (a int not null, b int, primary key (a)) engine = innodb;
+insert into t1 values (10, 20);
+insert into t2 values (10, 20);
+update t1, t2 set t1.b = 150, t2.b = t1.b where t2.a = t1.a and t1.a = 10;
+drop table t1,t2;
+
+#
+# Test of multi-table-delete with foreign key constraints
+#
+
+CREATE TABLE t1 (id INT NOT NULL, PRIMARY KEY (id)) ENGINE=INNODB;
+CREATE TABLE t2 (id INT PRIMARY KEY, t1_id INT, INDEX par_ind (t1_id), FOREIGN KEY (t1_id) REFERENCES t1(id) ON DELETE CASCADE ) ENGINE=INNODB;
+insert into t1 set id=1;
+insert into t2 set id=1, t1_id=1;
+delete t1,t2 from t1,t2 where t1.id=t2.t1_id;
+select * from t1;
+select * from t2;
+drop table t2,t1;
+CREATE TABLE t1(id INT NOT NULL, PRIMARY KEY (id)) ENGINE=INNODB;
+CREATE TABLE t2(id INT PRIMARY KEY, t1_id INT, INDEX par_ind (t1_id) ) ENGINE=INNODB;
+INSERT INTO t1 VALUES(1);
+INSERT INTO t2 VALUES(1, 1);
+SELECT * from t1;
+UPDATE t1,t2 SET t1.id=t1.id+1, t2.t1_id=t1.id+1;
+SELECT * from t1;
+UPDATE t1,t2 SET t1.id=t1.id+1 where t1.id!=t2.id;
+SELECT * from t1;
+DROP TABLE t1,t2;
+
+#
+# Test of range_optimizer
+#
+
+set autocommit=0;
+
+CREATE TABLE t1 (id CHAR(15) NOT NULL, value CHAR(40) NOT NULL, PRIMARY KEY(id)) ENGINE=InnoDB;
+
+CREATE TABLE t2 (id CHAR(15) NOT NULL, value CHAR(40) NOT NULL, PRIMARY KEY(id)) ENGINE=InnoDB;
+
+CREATE TABLE t3 (id1 CHAR(15) NOT NULL, id2 CHAR(15) NOT NULL, PRIMARY KEY(id1, id2)) ENGINE=InnoDB;
+
+INSERT INTO t3 VALUES("my-test-1", "my-test-2");
+COMMIT;
+
+INSERT INTO t1 VALUES("this-key", "will disappear");
+INSERT INTO t2 VALUES("this-key", "will also disappear");
+DELETE FROM t3 WHERE id1="my-test-1";
+
+SELECT * FROM t1;
+SELECT * FROM t2;
+SELECT * FROM t3;
+ROLLBACK;
+
+SELECT * FROM t1;
+SELECT * FROM t2;
+SELECT * FROM t3;
+SELECT * FROM t3 WHERE id1="my-test-1" LOCK IN SHARE MODE;
+COMMIT;
+set autocommit=1;
+DROP TABLE t1,t2,t3;
+
+#
+# Check update with conflicting key
+#
+
+CREATE TABLE t1 (a int not null primary key, b int not null, unique (b)) engine=innodb;
+INSERT INTO t1 values (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9);
+# We need the a < 1000 test here to quard against the halloween problems
+UPDATE t1 set a=a+100 where b between 2 and 3 and a < 1000;
+SELECT * from t1;
+drop table t1;
+
+CREATE TABLE t2 ( NEXT_T BIGINT NOT NULL PRIMARY KEY) ENGINE=MyISAM;
+CREATE TABLE t1 ( B_ID INTEGER NOT NULL PRIMARY KEY) ENGINE=InnoDB;
+SET AUTOCOMMIT=0;
+INSERT INTO t1 ( B_ID ) VALUES ( 1 );
+INSERT INTO t2 ( NEXT_T ) VALUES ( 1 );
+ROLLBACK;
+SELECT * FROM t1;
+drop table t1,t2;
+create table t1 ( pk int primary key, parent int not null, child int not null, index (parent) ) engine = innodb;
+insert into t1 values (1,0,4), (2,1,3), (3,2,1), (4,1,2);
+select distinct parent,child from t1 order by parent;
+drop table t1;
+
+#
+# Test that MySQL priorities clustered indexes
+#
+create table t1 (a int not null auto_increment primary key, b int, c int, key(c)) engine=innodb;
+create table t2 (a int not null auto_increment primary key, b int);
+insert into t1 (b) values (null),(null),(null),(null),(null),(null),(null);
+insert into t2 (a) select b from t1;
+insert into t1 (b) select b from t2;
+insert into t2 (a) select b from t1;
+insert into t1 (a) select b from t2;
+insert into t2 (a) select b from t1;
+insert into t1 (a) select b from t2;
+insert into t2 (a) select b from t1;
+insert into t1 (a) select b from t2;
+insert into t2 (a) select b from t1;
+insert into t1 (a) select b from t2;
+select count(*) from t1;
+--replace_column 9 # 10 #
+explain select * from t1 where c between 1 and 2500;
+update t1 set c=a;
+--replace_column 9 # 10 #
+explain select * from t1 where c between 1 and 2500;
+drop table t1,t2;
+
+#
+# Test of UPDATE ... ORDER BY
+#
+
+create table t1 (id int primary key auto_increment, fk int, index index_fk (fk)) engine=innodb;
+
+insert into t1 (id) values (null),(null),(null),(null),(null);
+update t1 set fk=69 where fk is null order by id limit 1;
+SELECT * from t1;
+drop table t1;
+
+create table t1 (a int not null, b int not null, key (a));
+insert into t1 values (1,1),(1,2),(1,3),(3,1),(3,2),(3,3),(3,1),(3,2),(3,3),(2,1),(2,2),(2,3);
+SET @tmp=0;
+update t1 set b=(@tmp:=@tmp+1) order by a;
+update t1 set b=99 where a=1 order by b asc limit 1;
+update t1 set b=100 where a=1 order by b desc limit 2;
+update t1 set a=a+10+b where a=1 order by b;
+select * from t1 order by a,b;
+drop table t1;
+
+#
+# Test of multi-table-updates (bug #1980).
+#
+
+create table t1 ( c char(8) not null ) engine=innodb;
+insert into t1 values ('0'),('1'),('2'),('3'),('4'),('5'),('6'),('7'),('8'),('9');
+insert into t1 values ('A'),('B'),('C'),('D'),('E'),('F');
+
+alter table t1 add b char(8) not null;
+alter table t1 add a char(8) not null;
+alter table t1 add primary key (a,b,c);
+update t1 set a=c, b=c;
+
+create table t2 (c char(8) not null, b char(8) not null, a char(8) not null, primary key(a,b,c)) engine=innodb;
+insert into t2 select * from t1;
+
+delete t1,t2 from t2,t1 where t1.a<'B' and t2.b=t1.b;
+drop table t1,t2;
+
+#
+# test autoincrement with TRUNCATE
+#
+
+SET AUTOCOMMIT=1;
+create table t1 (a integer auto_increment primary key) engine=innodb;
+insert into t1 (a) values (NULL),(NULL);
+truncate table t1;
+insert into t1 (a) values (NULL),(NULL);
+SELECT * from t1;
+drop table t1;
+
+#
+# Test dictionary handling with spaceand quoting
+#
+
+CREATE TABLE t1 (`id 1` INT NOT NULL, PRIMARY KEY (`id 1`)) ENGINE=INNODB;
+CREATE TABLE t2 (id INT PRIMARY KEY, t1_id INT, INDEX par_ind (t1_id), FOREIGN KEY (`t1_id`) REFERENCES `t1`(`id 1`) ON DELETE CASCADE ) ENGINE=INNODB;
+#show create table t2;
+drop table t2,t1;
+
+#
+# Test of multi updated and foreign keys
+#
+
+create table `t1` (`id` int( 11 ) not null ,primary key ( `id` )) engine = innodb;
+insert into `t1`values ( 1 ) ;
+create table `t2` (`id` int( 11 ) not null default '0',unique key `id` ( `id` ) ,constraint `t1_id_fk` foreign key ( `id` ) references `t1` (`id` )) engine = innodb;
+insert into `t2`values ( 1 ) ;
+create table `t3` (`id` int( 11 ) not null default '0',key `id` ( `id` ) ,constraint `t2_id_fk` foreign key ( `id` ) references `t2` (`id` )) engine = innodb;
+insert into `t3`values ( 1 ) ;
+--error ER_ROW_IS_REFERENCED_2
+delete t3,t2,t1 from t1,t2,t3 where t1.id =1 and t2.id = t1.id and t3.id = t2.id;
+--error ER_ROW_IS_REFERENCED_2
+update t1,t2,t3 set t3.id=5, t2.id=6, t1.id=7 where t1.id =1 and t2.id = t1.id and t3.id = t2.id;
+--error ER_BAD_FIELD_ERROR
+update t3 set t3.id=7 where t1.id =1 and t2.id = t1.id and t3.id = t2.id;
+drop table t3,t2,t1;
+
+# test ON UPDATE CASCADE
+CREATE TABLE t1 (
+ c1 VARCHAR(8), c2 VARCHAR(8),
+ PRIMARY KEY (c1, c2)
+) ENGINE=InnoDB;
+
+CREATE TABLE t2 (
+ c0 INT PRIMARY KEY,
+ c1 VARCHAR(8) UNIQUE,
+ FOREIGN KEY (c1) REFERENCES t1 (c1) ON UPDATE CASCADE
+) ENGINE=InnoDB;
+
+INSERT INTO t1 VALUES ('old', 'somevalu'), ('other', 'anyvalue');
+INSERT INTO t2 VALUES (10, 'old'), (20, 'other');
+--error ER_FOREIGN_DUPLICATE_KEY_WITH_CHILD_INFO
+UPDATE t1 SET c1 = 'other' WHERE c1 = 'old';
+DROP TABLE t2,t1;
+
+#
+# test for FK cascade depth limit
+#
+call mtr.add_suppression("Cannot delete/update rows with cascading foreign key constraints that exceed max depth of 15\\. Please drop excessive foreign constraints and try again");
+
+create table t1(
+ id int primary key,
+ pid int,
+ index(pid),
+ foreign key(pid) references t1(id) on delete cascade) engine=innodb;
+insert into t1 values(0,0),(1,0),(2,1),(3,2),(4,3),(5,4),(6,5),(7,6),
+(8,7),(9,8),(10,9),(11,10),(12,11),(13,12),(14,13),(15,14);
+--error ER_GET_ERRMSG,ER_ROW_IS_REFERENCED_2
+delete from t1 where id=0;
+delete from t1 where id=15;
+delete from t1 where id=0;
+
+drop table t1;
+
+#
+# Test timestamps
+#
+
+CREATE TABLE t1 (col1 int(1))ENGINE=InnoDB;
+CREATE TABLE t2 (col1 int(1),stamp TIMESTAMP,INDEX stamp_idx
+(stamp))ENGINE=InnoDB;
+insert into t1 values (1),(2),(3);
+# Note that timestamp 3 is wrong
+insert ignore into t2 values (1, 20020204130000),(2, 20020204130000),(4,20020204310000 ),(5,20020204230000);
+SELECT col1 FROM t1 UNION SELECT col1 FROM t2 WHERE stamp <
+'20020204120000' GROUP BY col1;
+drop table t1,t2;
+
+#
+# Test by Francois MASUREL
+#
+
+CREATE TABLE t1 (
+ `id` int(10) unsigned NOT NULL auto_increment,
+ `id_object` int(10) unsigned default '0',
+ `id_version` int(10) unsigned NOT NULL default '1',
+ `label` varchar(100) NOT NULL default '',
+ `description` text,
+ PRIMARY KEY (`id`),
+ KEY `id_object` (`id_object`),
+ KEY `id_version` (`id_version`)
+) ENGINE=InnoDB;
+
+INSERT INTO t1 VALUES("6", "3382", "9", "Test", NULL), ("7", "102", "5", "Le Pekin (Test)", NULL),("584", "1794", "4", "Test de resto", NULL),("837", "1822", "6", "Test 3", NULL),("1119", "3524", "1", "Societe Test", NULL),("1122", "3525", "1", "Fournisseur Test", NULL);
+
+CREATE TABLE t2 (
+ `id` int(10) unsigned NOT NULL auto_increment,
+ `id_version` int(10) unsigned NOT NULL default '1',
+ PRIMARY KEY (`id`),
+ KEY `id_version` (`id_version`)
+) ENGINE=InnoDB;
+
+INSERT INTO t2 VALUES("3524", "1"),("3525", "1"),("1794", "4"),("102", "5"),("1822", "6"),("3382", "9");
+
+SELECT t2.id, t1.`label` FROM t2 INNER JOIN
+(SELECT t1.id_object as id_object FROM t1 WHERE t1.`label` LIKE '%test%') AS lbl
+ON (t2.id = lbl.id_object) INNER JOIN t1 ON (t2.id = t1.id_object);
+drop table t1,t2;
+
+create table t1 (a int, b varchar(200), c text not null) checksum=1 engine=myisam;
+create table t2 (a int, b varchar(200), c text not null) checksum=0 engine=innodb;
+create table t3 (a int, b varchar(200), c text not null) checksum=1 engine=innodb;
+insert t1 values (1, "aaa", "bbb"), (NULL, "", "ccccc"), (0, NULL, "");
+insert t2 select * from t1;
+insert t3 select * from t1;
+checksum table t1, t2, t3, t4 quick;
+checksum table t1, t2, t3, t4;
+checksum table t1, t2, t3, t4 extended;
+#show table status;
+drop table t1,t2,t3;
+
+#
+# Test problem with referring to different fields in same table in UNION
+# (Bug #2552)
+#
+create table t1 (id int, name char(10) not null, name2 char(10) not null) engine=innodb;
+insert into t1 values(1,'first','fff'),(2,'second','sss'),(3,'third','ttt');
+select trim(name2) from t1 union all select trim(name) from t1 union all select trim(id) from t1;
+drop table t1;
+
+#
+# Bug2160
+#
+create table t1 (a int) engine=innodb;
+create table t2 like t1;
+drop table t1,t2;
+
+#
+# Test of automaticly created foreign keys
+#
+
+create table t1 (id int(11) not null, id2 int(11) not null, unique (id,id2)) engine=innodb;
+create table t2 (id int(11) not null, constraint t1_id_fk foreign key ( id ) references t1 (id)) engine = innodb;
+show create table t1;
+show create table t2;
+create index id on t2 (id);
+show create table t2;
+create index id2 on t2 (id);
+show create table t2;
+drop index id2 on t2;
+--error ER_DROP_INDEX_FK
+drop index id on t2;
+show create table t2;
+drop table t2;
+
+create table t2 (id int(11) not null, id2 int(11) not null, constraint t1_id_fk foreign key (id,id2) references t1 (id,id2)) engine = innodb;
+show create table t2;
+create unique index id on t2 (id,id2);
+show create table t2;
+drop table t2;
+
+# Check foreign key columns created in different order than key columns
+create table t2 (id int(11) not null, id2 int(11) not null, unique (id,id2),constraint t1_id_fk foreign key (id2,id) references t1 (id,id2)) engine = innodb;
+show create table t2;
+drop table t2;
+
+create table t2 (id int(11) not null, id2 int(11) not null, unique (id,id2), constraint t1_id_fk foreign key (id) references t1 (id)) engine = innodb;
+show create table t2;
+drop table t2;
+
+create table t2 (id int(11) not null, id2 int(11) not null, unique (id,id2),constraint t1_id_fk foreign key (id2,id) references t1 (id,id2)) engine = innodb;
+show create table t2;
+drop table t2;
+
+create table t2 (id int(11) not null auto_increment, id2 int(11) not null, constraint t1_id_fk foreign key (id) references t1 (id), primary key (id), index (id,id2)) engine = innodb;
+show create table t2;
+drop table t2;
+
+create table t2 (id int(11) not null auto_increment, id2 int(11) not null, constraint t1_id_fk foreign key (id) references t1 (id)) engine= innodb;
+show create table t2;
+alter table t2 add index id_test (id), add index id_test2 (id,id2);
+show create table t2;
+drop table t2;
+
+# Test error handling
+
+# Embedded server doesn't chdir to data directory
+--replace_result $MYSQLTEST_VARDIR . master-data/ ''
+--error ER_WRONG_FK_DEF
+create table t2 (id int(11) not null, id2 int(11) not null, constraint t1_id_fk foreign key (id2,id) references t1 (id)) engine = innodb;
+
+# bug#3749
+
+create table t2 (a int auto_increment primary key, b int, index(b), foreign key (b) references t1(id), unique(b)) engine=innodb;
+show create table t2;
+drop table t2;
+create table t2 (a int auto_increment primary key, b int, foreign key (b) references t1(id), foreign key (b) references t1(id), unique(b)) engine=innodb;
+show create table t2;
+drop table t2, t1;
+
+
+#
+# Bug #6126: Duplicate columns in keys gives misleading error message
+#
+--error 1060
+create table t1 (c char(10), index (c,c)) engine=innodb;
+--error 1060
+create table t1 (c1 char(10), c2 char(10), index (c1,c2,c1)) engine=innodb;
+--error 1060
+create table t1 (c1 char(10), c2 char(10), index (c1,c1,c2)) engine=innodb;
+--error 1060
+create table t1 (c1 char(10), c2 char(10), index (c2,c1,c1)) engine=innodb;
+create table t1 (c1 char(10), c2 char(10)) engine=innodb;
+--error 1060
+alter table t1 add key (c1,c1);
+--error 1060
+alter table t1 add key (c2,c1,c1);
+--error 1060
+alter table t1 add key (c1,c2,c1);
+--error 1060
+alter table t1 add key (c1,c1,c2);
+drop table t1;
+
+#
+# Bug #4082: integer truncation
+#
+
+create table t1(a int(1) , b int(1)) engine=innodb;
+insert into t1 values ('1111', '3333');
+select distinct concat(a, b) from t1;
+drop table t1;
+
+#
+# check null values #1
+#
+
+--disable_warnings
+CREATE TABLE t1 (a_id tinyint(4) NOT NULL default '0', PRIMARY KEY (a_id)) ENGINE=InnoDB DEFAULT CHARSET=latin1;
+INSERT INTO t1 VALUES (1),(2),(3);
+CREATE TABLE t2 (b_id tinyint(4) NOT NULL default '0',b_a tinyint(4) NOT NULL default '0', PRIMARY KEY (b_id), KEY (b_a),
+ CONSTRAINT fk_b_a FOREIGN KEY (b_a) REFERENCES t1 (a_id) ON DELETE CASCADE ON UPDATE NO ACTION) ENGINE=InnoDB DEFAULT CHARSET=latin1;
+--enable_warnings
+INSERT INTO t2 VALUES (1,1),(2,1),(3,1),(4,2),(5,2);
+SELECT * FROM (SELECT t1.*,GROUP_CONCAT(t2.b_id SEPARATOR ',') as b_list FROM (t1 LEFT JOIN (t2) on t1.a_id = t2.b_a) GROUP BY t1.a_id ) AS xyz;
+DROP TABLE t2;
+DROP TABLE t1;
+
+#
+# Bug#11816 - Truncate table doesn't work with temporary innodb tables
+# This is not an innodb bug, but we test it using innodb.
+#
+create temporary table t1 (a int) engine=innodb;
+insert into t1 values (4711);
+truncate t1;
+insert into t1 values (42);
+select * from t1;
+drop table t1;
+# Show that it works with permanent tables too.
+create table t1 (a int) engine=innodb;
+insert into t1 values (4711);
+truncate t1;
+insert into t1 values (42);
+select * from t1;
+drop table t1;
+
+#
+# Bug #13025 Server crash during filesort
+#
+
+create table t1 (a int not null, b int not null, c blob not null, d int not null, e int, primary key (a,b,c(255),d)) engine=innodb;
+insert into t1 values (2,2,"b",2,2),(1,1,"a",1,1),(3,3,"ab",3,3);
+-- disable_result_log
+analyze table t1;
+-- enable_result_log
+select * from t1 order by a,b,c,d;
+explain select * from t1 order by a,b,c,d;
+drop table t1;
+
+#
+# BUG#11039,#13218 Wrong key length in min()
+#
+
+create table t1 (a char(1), b char(1), key(a, b)) engine=innodb;
+insert into t1 values ('8', '6'), ('4', '7');
+select min(a) from t1;
+select min(b) from t1 where a='8';
+drop table t1;
+
+# End of 4.1 tests
+
+#
+# range optimizer problem
+#
+
+create table t1 (x bigint unsigned not null primary key) engine=innodb;
+insert into t1(x) values (0xfffffffffffffff0),(0xfffffffffffffff1);
+select * from t1;
+select count(*) from t1 where x>0;
+select count(*) from t1 where x=0;
+select count(*) from t1 where x<0;
+select count(*) from t1 where x < -16;
+select count(*) from t1 where x = -16;
+explain select count(*) from t1 where x > -16;
+select count(*) from t1 where x > -16;
+select * from t1 where x > -16;
+select count(*) from t1 where x = 18446744073709551601;
+drop table t1;
+
+
+# Test for testable InnoDB status variables. This test
+# uses previous ones(pages_created, rows_deleted, ...).
+SELECT IF(variable_value BETWEEN 488 AND 512, 'OK', variable_value) FROM information_schema.global_status WHERE LOWER(variable_name) = 'innodb_buffer_pool_pages_total';
+SELECT variable_value FROM information_schema.global_status WHERE LOWER(variable_name) = 'innodb_page_size';
+
+# Test for row locks InnoDB status variables.
+SELECT variable_value - @innodb_row_lock_waits_orig FROM information_schema.global_status WHERE LOWER(variable_name) = 'innodb_row_lock_waits';
+SELECT variable_value - @innodb_row_lock_current_waits_orig FROM information_schema.global_status WHERE LOWER(variable_name) = 'innodb_row_lock_current_waits';
+SELECT variable_value - @innodb_row_lock_time_orig FROM information_schema.global_status WHERE LOWER(variable_name) = 'innodb_row_lock_time';
+SELECT variable_value - @innodb_row_lock_time_max_orig FROM information_schema.global_status WHERE LOWER(variable_name) = 'innodb_row_lock_time_max';
+SELECT variable_value - @innodb_row_lock_time_avg_orig FROM information_schema.global_status WHERE LOWER(variable_name) = 'innodb_row_lock_time_avg';
+
+
+#
+# Test varchar
+#
+
+let $default=`select @@default_storage_engine`;
+set default_storage_engine=INNODB;
+source include/varchar.inc;
+
+#
+# Some errors/warnings on create
+#
+SET sql_mode = 'NO_ENGINE_SUBSTITUTION';
+# Embedded server doesn't chdir to data directory
+--replace_result $MYSQLTEST_VARDIR . master-data/ ''
+create table t1 (v varchar(65530), key(v));
+drop table t1;
+create table t1 (v varchar(65536));
+show create table t1;
+drop table t1;
+create table t1 (v varchar(65530) character set utf8);
+show create table t1;
+drop table t1;
+SET sql_mode = default;
+eval set default_storage_engine=$default;
+
+# InnoDB specific varchar tests
+create table t1 (v varchar(16384)) engine=innodb;
+drop table t1;
+
+#
+# BUG#11039 Wrong key length in min()
+#
+
+create table t1 (a char(1), b char(1), key(a, b)) engine=innodb;
+insert into t1 values ('8', '6'), ('4', '7');
+select min(a) from t1;
+select min(b) from t1 where a='8';
+drop table t1;
+
+#
+# Bug #11080 & #11005 Multi-row REPLACE fails on a duplicate key error
+#
+
+CREATE TABLE t1 ( `a` int(11) NOT NULL auto_increment, `b` int(11) default NULL,PRIMARY KEY (`a`),UNIQUE KEY `b` (`b`)) ENGINE=innodb;
+insert into t1 (b) values (1);
+replace into t1 (b) values (2), (1), (3);
+select * from t1;
+truncate table t1;
+insert into t1 (b) values (1);
+replace into t1 (b) values (2);
+replace into t1 (b) values (1);
+replace into t1 (b) values (3);
+select * from t1;
+drop table t1;
+
+create table t1 (rowid int not null auto_increment, val int not null,primary
+key (rowid), unique(val)) engine=innodb;
+replace into t1 (val) values ('1'),('2');
+replace into t1 (val) values ('1'),('2');
+--error ER_DUP_ENTRY
+insert into t1 (val) values ('1'),('2');
+select * from t1;
+drop table t1;
+
+#
+# Test that update does change internal auto-increment value
+#
+
+create table t1 (a int not null auto_increment primary key, val int) engine=InnoDB;
+insert into t1 (val) values (1);
+update t1 set a=2 where a=1;
+# This should insert 3, since the counter has been updated to 2 already
+insert into t1 (val) values (3);
+select * from t1;
+# We should get the following error because InnoDB does update the counter
+--error ER_DUP_ENTRY
+insert into t1 values (2, 2);
+select * from t1;
+drop table t1;
+#
+# Bug #10465
+#
+
+--disable_warnings
+CREATE TABLE t1 (GRADE DECIMAL(4) NOT NULL, PRIMARY KEY (GRADE)) ENGINE=INNODB;
+--enable_warnings
+INSERT INTO t1 (GRADE) VALUES (151),(252),(343);
+SELECT GRADE FROM t1 WHERE GRADE > 160 AND GRADE < 300;
+SELECT GRADE FROM t1 WHERE GRADE= 151;
+DROP TABLE t1;
+
+#
+# Bug #12340 multitable delete deletes only one record
+#
+create table t1 (f1 varchar(10), f2 varchar(10), primary key (f1,f2)) engine=innodb;
+create table t2 (f3 varchar(10), f4 varchar(10), key (f4)) engine=innodb;
+insert into t2 values ('aa','cc');
+insert into t1 values ('aa','bb'),('aa','cc');
+delete t1 from t1,t2 where f1=f3 and f4='cc';
+select * from t1;
+drop table t1,t2;
+
+#
+# Test that the slow TRUNCATE implementation resets autoincrement columns
+# (bug #11946)
+#
+
+CREATE TABLE t1 (
+id INTEGER NOT NULL AUTO_INCREMENT, PRIMARY KEY (id)
+) ENGINE=InnoDB;
+
+CREATE TABLE t2 (
+id INTEGER NOT NULL,
+FOREIGN KEY (id) REFERENCES t1 (id)
+) ENGINE=InnoDB;
+
+INSERT INTO t1 (id) VALUES (NULL);
+SELECT * FROM t1;
+--error ER_TRUNCATE_ILLEGAL_FK
+TRUNCATE t1;
+INSERT INTO t1 (id) VALUES (NULL);
+SELECT * FROM t1;
+
+# continued from above; test that doing a TRUNCATE resets AUTO_INCREMENT
+DELETE FROM t1;
+--error ER_TRUNCATE_ILLEGAL_FK
+TRUNCATE t1;
+INSERT INTO t1 (id) VALUES (NULL);
+SELECT * FROM t1;
+DROP TABLE t2;
+TRUNCATE t1;
+INSERT INTO t1 (id) VALUES (NULL);
+SELECT * FROM t1;
+DROP TABLE t1;
+
+# Test that foreign keys in temporary tables are not accepted (bug #12084)
+CREATE TABLE t1
+(
+ id INT PRIMARY KEY
+) ENGINE=InnoDB;
+
+--error ER_CANT_CREATE_TABLE
+CREATE TEMPORARY TABLE t2
+(
+ id INT NOT NULL PRIMARY KEY,
+ b INT,
+ FOREIGN KEY (b) REFERENCES test.t1(id)
+) ENGINE=InnoDB;
+DROP TABLE t1;
+
+#
+# Test that index column max sizes are honored (bug #13315)
+#
+
+# prefix index
+create table t1 (col1 varchar(2000), index (col1(767)))
+ character set = latin1 engine = innodb;
+
+# normal indexes
+create table t2 (col1 char(255), index (col1))
+ character set = latin1 engine = innodb;
+create table t3 (col1 binary(255), index (col1))
+ character set = latin1 engine = innodb;
+create table t4 (col1 varchar(767), index (col1))
+ character set = latin1 engine = innodb;
+create table t5 (col1 varchar(767) primary key)
+ character set = latin1 engine = innodb;
+create table t6 (col1 varbinary(767) primary key)
+ character set = latin1 engine = innodb;
+create table t7 (col1 text, index(col1(767)))
+ character set = latin1 engine = innodb;
+create table t8 (col1 blob, index(col1(767)))
+ character set = latin1 engine = innodb;
+
+# multi-column indexes are allowed to be longer
+create table t9 (col1 varchar(512), col2 varchar(512), index(col1, col2))
+ character set = latin1 engine = innodb;
+
+show create table t9;
+
+drop table t1, t2, t3, t4, t5, t6, t7, t8, t9;
+
+#
+# Test improved foreign key error messages (bug #3443)
+#
+
+CREATE TABLE t1
+(
+ id INT PRIMARY KEY
+) ENGINE=InnoDB;
+
+CREATE TABLE t2
+(
+ v INT,
+ CONSTRAINT c1 FOREIGN KEY (v) REFERENCES t1(id)
+) ENGINE=InnoDB;
+
+--error ER_NO_REFERENCED_ROW_2
+INSERT INTO t2 VALUES(2);
+
+INSERT INTO t1 VALUES(1);
+INSERT INTO t2 VALUES(1);
+
+--error ER_ROW_IS_REFERENCED_2
+DELETE FROM t1 WHERE id = 1;
+
+--error ER_ROW_IS_REFERENCED_2
+DROP TABLE t1;
+
+SET FOREIGN_KEY_CHECKS=0;
+DROP TABLE t1;
+SET FOREIGN_KEY_CHECKS=1;
+
+--error ER_NO_REFERENCED_ROW_2
+INSERT INTO t2 VALUES(3);
+
+DROP TABLE t2;
+#
+# Test that checksum table uses a consistent read Bug #12669
+#
+connect (a,localhost,root,,);
+connect (b,localhost,root,,);
+connection a;
+create table t1(a int not null) engine=innodb DEFAULT CHARSET=latin1;
+insert into t1 values (1),(2);
+set autocommit=0;
+checksum table t1;
+connection b;
+insert into t1 values(3);
+connection a;
+#
+# Here checksum should not see insert
+#
+checksum table t1;
+connection a;
+commit;
+checksum table t1;
+commit;
+drop table t1;
+#
+# autocommit = 1
+#
+connection a;
+create table t1(a int not null) engine=innodb DEFAULT CHARSET=latin1;
+insert into t1 values (1),(2);
+set autocommit=1;
+checksum table t1;
+connection b;
+set autocommit=1;
+insert into t1 values(3);
+connection a;
+#
+# Here checksum sees insert
+#
+checksum table t1;
+drop table t1;
+
+connection default;
+disconnect a;
+disconnect b;
+
+# tests for bugs #9802 and #13778
+
+# test that FKs between invalid types are not accepted
+
+set foreign_key_checks=0;
+create table t2 (a int primary key, b int, foreign key (b) references t1(a)) engine = innodb;
+create table t1(a char(10) primary key, b varchar(20)) engine = innodb;
+set foreign_key_checks=1;
+--error ER_NO_REFERENCED_ROW_2
+insert into t2 values (1,1);
+set foreign_key_checks=0;
+drop table t1;
+set foreign_key_checks=1;
+--error ER_NO_REFERENCED_ROW_2
+insert into t2 values (1,1);
+# Embedded server doesn't chdir to data directory
+--replace_result $MYSQLTEST_VARDIR . master-data/ ''
+--error ER_CANT_CREATE_TABLE
+create table t1(a char(10) primary key, b varchar(20)) engine = innodb;
+drop table t2;
+create table t1(a char(10) primary key, b varchar(20)) engine = innodb;
+drop table t1;
+
+# test that FKs between different charsets are not accepted in CREATE even
+# when f_k_c is 0
+
+set foreign_key_checks=0;
+create table t1(a varchar(10) primary key) engine = innodb DEFAULT CHARSET=latin1;
+# Embedded server doesn't chdir to data directory
+--replace_result $MYSQLTEST_VARDIR . master-data/ ''
+--error ER_CANT_CREATE_TABLE
+create table t2 (a varchar(10), foreign key (a) references t1(a)) engine = innodb DEFAULT CHARSET=utf8;
+set foreign_key_checks=1;
+drop table t1;
+
+# test that invalid datatype conversions with ALTER are not allowed
+
+set foreign_key_checks=0;
+create table t2 (a varchar(10), foreign key (a) references t1(a)) engine = innodb;
+create table t1(a varchar(10) primary key) engine = innodb;
+--error ER_FK_COLUMN_CANNOT_CHANGE_CHILD
+alter table t1 modify column a int;
+set foreign_key_checks=1;
+drop table t2,t1;
+
+# test that charset conversions with ALTER are allowed when f_k_c is 0
+
+set foreign_key_checks=0;
+create table t2 (a varchar(10), foreign key (a) references t1(a)) engine = innodb DEFAULT CHARSET=latin1;
+create table t1(a varchar(10) primary key) engine = innodb DEFAULT CHARSET=latin1;
+--error ER_FK_COLUMN_CANNOT_CHANGE_CHILD
+alter table t1 convert to character set utf8;
+set foreign_key_checks=1;
+drop table t2,t1;
+
+# test that RENAME does not allow invalid charsets when f_k_c is 0
+
+call mtr.add_suppression("\\[Warning\\] InnoDB: In ALTER TABLE `test`.`t1` has or is referenced in foreign key constraints which are not compatible with the new table definition.");
+set foreign_key_checks=0;
+create table t2 (a varchar(10), foreign key (a) references t1(a)) engine = innodb DEFAULT CHARSET=latin1;
+create table t3(a varchar(10) primary key) engine = innodb DEFAULT CHARSET=utf8;
+# Embedded server doesn't chdir to data directory
+--replace_result $MYSQLD_DATADIR ./ master-data/ ''
+-- error 1025
+rename table t3 to t1;
+set foreign_key_checks=1;
+drop table t2,t3;
+
+# test that foreign key errors are reported correctly (Bug #15550)
+
+create table t1(a int primary key) row_format=redundant engine=innodb;
+create table t2(a int primary key,constraint foreign key(a)references t1(a)) row_format=compact engine=innodb;
+create table t3(a int primary key) row_format=compact engine=innodb;
+create table t4(a int primary key,constraint foreign key(a)references t3(a)) row_format=redundant engine=innodb;
+
+insert into t1 values(1);
+insert into t3 values(1);
+-- error 1452
+insert into t2 values(2);
+-- error 1452
+insert into t4 values(2);
+insert into t2 values(1);
+insert into t4 values(1);
+-- error ER_ROW_IS_REFERENCED_2
+update t1 set a=2;
+-- error 1452
+update t2 set a=2;
+-- error ER_ROW_IS_REFERENCED_2
+update t3 set a=2;
+-- error 1452
+update t4 set a=2;
+-- error ER_TRUNCATE_ILLEGAL_FK
+truncate t1;
+-- error ER_TRUNCATE_ILLEGAL_FK
+truncate t3;
+truncate t2;
+truncate t4;
+-- error ER_TRUNCATE_ILLEGAL_FK
+truncate t1;
+-- error ER_TRUNCATE_ILLEGAL_FK
+truncate t3;
+
+drop table t4,t3,t2,t1;
+
+
+#
+# Test that we can create a large (>1K) key
+#
+create table t1 (a varchar(255) character set utf8,
+ b varchar(255) character set utf8,
+ c varchar(255) character set utf8,
+ d varchar(255) character set utf8,
+ key (a,b,c,d)) engine=innodb;
+drop table t1;
+--error ER_TOO_LONG_KEY
+create table t1 (a varchar(255) character set utf8,
+ b varchar(255) character set utf8,
+ c varchar(255) character set utf8,
+ d varchar(255) character set utf8,
+ e varchar(255) character set utf8,
+ key (a,b,c,d,e)) engine=innodb;
+
+
+# test the padding of BINARY types and collations (Bug #14189)
+SET sql_mode = 'NO_ENGINE_SUBSTITUTION';
+create table t1 (s1 varbinary(2),primary key (s1)) engine=innodb;
+create table t2 (s1 binary(2),primary key (s1)) engine=innodb;
+create table t3 (s1 varchar(2) binary,primary key (s1)) engine=innodb;
+create table t4 (s1 char(2) binary,primary key (s1)) engine=innodb;
+
+insert into t1 values (0x41),(0x4120),(0x4100);
+-- error ER_DUP_ENTRY
+insert into t2 values (0x41),(0x4120),(0x4100);
+insert into t2 values (0x41),(0x4120);
+-- error ER_DUP_ENTRY
+insert into t3 values (0x41),(0x4120),(0x4100);
+insert into t3 values (0x41),(0x4100);
+-- error ER_DUP_ENTRY
+insert into t4 values (0x41),(0x4120),(0x4100);
+insert into t4 values (0x41),(0x4100);
+select hex(s1) from t1;
+select hex(s1) from t2;
+select hex(s1) from t3;
+select hex(s1) from t4;
+drop table t1,t2,t3,t4;
+
+create table t1 (a int primary key,s1 varbinary(3) not null unique) engine=innodb;
+create table t2 (s1 binary(2) not null, constraint c foreign key(s1) references t1(s1) on update cascade) engine=innodb;
+
+insert into t1 values(1,0x4100),(2,0x41),(3,0x4120),(4,0x42);
+-- error 1452
+insert into t2 values(0x42);
+insert into t2 values(0x41);
+select hex(s1) from t2;
+update t1 set s1=0x123456 where a=2;
+select hex(s1) from t2;
+-- error ER_ROW_IS_REFERENCED_2
+update t1 set s1=0x12 where a=1;
+-- error ER_ROW_IS_REFERENCED_2
+update t1 set s1=0x12345678 where a=1;
+-- error ER_ROW_IS_REFERENCED_2
+update t1 set s1=0x123457 where a=1;
+update t1 set s1=0x1220 where a=1;
+select hex(s1) from t2;
+update t1 set s1=0x1200 where a=1;
+select hex(s1) from t2;
+update t1 set s1=0x4200 where a=1;
+select hex(s1) from t2;
+-- error ER_ROW_IS_REFERENCED_2
+delete from t1 where a=1;
+delete from t1 where a=2;
+update t2 set s1=0x4120;
+-- error ER_ROW_IS_REFERENCED_2
+delete from t1;
+delete from t1 where a!=3;
+select a,hex(s1) from t1;
+select hex(s1) from t2;
+
+drop table t2,t1;
+
+create table t1 (a int primary key,s1 varchar(2) binary not null unique) engine=innodb;
+create table t2 (s1 char(2) binary not null, constraint c foreign key(s1) references t1(s1) on update cascade) engine=innodb;
+
+insert into t1 values(1,0x4100),(2,0x41);
+insert into t2 values(0x41);
+select hex(s1) from t2;
+update t1 set s1=0x1234 where a=1;
+select hex(s1) from t2;
+update t1 set s1=0x12 where a=2;
+select hex(s1) from t2;
+delete from t1 where a=1;
+-- error ER_ROW_IS_REFERENCED_2
+delete from t1 where a=2;
+select a,hex(s1) from t1;
+select hex(s1) from t2;
+
+drop table t2,t1;
+# Ensure that <tablename>_ibfk_0 is not mistreated as a
+# generated foreign key identifier. (Bug #16387)
+
+CREATE TABLE t1(a INT, PRIMARY KEY(a)) ENGINE=InnoDB;
+CREATE TABLE t2(a INT) ENGINE=InnoDB;
+ALTER TABLE t2 ADD FOREIGN KEY (a) REFERENCES t1(a);
+ALTER TABLE t2 DROP FOREIGN KEY t2_ibfk_1;
+ALTER TABLE t2 ADD CONSTRAINT t2_ibfk_0 FOREIGN KEY (a) REFERENCES t1(a);
+ALTER TABLE t2 DROP FOREIGN KEY t2_ibfk_0;
+SHOW CREATE TABLE t2;
+DROP TABLE t2,t1;
+SET sql_mode = default;
+#
+# Test case for bug #16229: MySQL/InnoDB uses full explicit table locks in trigger processing
+#
+## the following cannot be tested after the introduction of metadata locks
+## because the create trigger command blocks and waits for connection b to
+## commit
+## begin disabled_mdl
+#connect (a,localhost,root,,);
+#connect (b,localhost,root,,);
+#connection a;
+#create table t1(a int not null, b int, c int, d int, primary key(a)) engine=innodb;
+#insert into t1(a) values (1),(2),(3);
+#commit;
+#connection b;
+#set autocommit = 0;
+#update t1 set b = 5 where a = 2;
+#connection a;
+#delimiter |;
+#create trigger t1t before insert on t1 for each row begin set NEW.b = NEW.a * 10 + 5, NEW.c = NEW.a / 10; end |
+#delimiter ;|
+#set autocommit = 0;
+#connection a;
+#insert into t1(a) values (10),(20),(30),(40),(50),(60),(70),(80),(90),(100),
+#(11),(21),(31),(41),(51),(61),(71),(81),(91),(101),
+#(12),(22),(32),(42),(52),(62),(72),(82),(92),(102),
+#(13),(23),(33),(43),(53),(63),(73),(83),(93),(103),
+#(14),(24),(34),(44),(54),(64),(74),(84),(94),(104);
+#connection b;
+#commit;
+#connection a;
+#commit;
+#drop trigger t1t;
+#drop table t1;
+#disconnect a;
+#disconnect b;
+##
+## Another trigger test
+##
+#connect (a,localhost,root,,);
+#connect (b,localhost,root,,);
+#connection a;
+#create table t1(a int not null, b int, c int, d int, primary key(a)) engine=innodb;
+#create table t2(a int not null, b int, c int, d int, primary key(a)) engine=innodb;
+#create table t3(a int not null, b int, c int, d int, primary key(a)) engine=innodb;
+#create table t4(a int not null, b int, c int, d int, primary key(a)) engine=innodb;
+#create table t5(a int not null, b int, c int, d int, primary key(a)) engine=innodb;
+#insert into t1(a) values (1),(2),(3);
+#insert into t2(a) values (1),(2),(3);
+#insert into t3(a) values (1),(2),(3);
+#insert into t4(a) values (1),(2),(3);
+#insert into t3(a) values (5),(7),(8);
+#insert into t4(a) values (5),(7),(8);
+#insert into t5(a) values (1),(2),(3),(4),(5),(6),(7),(8),(9),(10),(11),(12);
+#
+#delimiter |;
+#create trigger t1t before insert on t1 for each row begin
+# INSERT INTO t2 SET a = NEW.a;
+#end |
+#
+#create trigger t2t before insert on t2 for each row begin
+# DELETE FROM t3 WHERE a = NEW.a;
+#end |
+#
+#create trigger t3t before delete on t3 for each row begin
+# UPDATE t4 SET b = b + 1 WHERE a = OLD.a;
+#end |
+#
+#create trigger t4t before update on t4 for each row begin
+# UPDATE t5 SET b = b + 1 where a = NEW.a;
+#end |
+#delimiter ;|
+#commit;
+#set autocommit = 0;
+#update t1 set b = b + 5 where a = 1;
+#update t2 set b = b + 5 where a = 1;
+#update t3 set b = b + 5 where a = 1;
+#update t4 set b = b + 5 where a = 1;
+#insert into t5(a) values(20);
+#connection b;
+#set autocommit = 0;
+#insert into t1(a) values(7);
+#insert into t2(a) values(8);
+#delete from t2 where a = 3;
+#update t4 set b = b + 1 where a = 3;
+#commit;
+#drop trigger t1t;
+#drop trigger t2t;
+#drop trigger t3t;
+#drop trigger t4t;
+#drop table t1, t2, t3, t4, t5;
+#connection default;
+#disconnect a;
+#disconnect b;
+## end disabled_mdl
+
+#
+# Test that cascading updates leading to duplicate keys give the correct
+# error message (bug #9680)
+#
+
+CREATE TABLE t1 (
+ field1 varchar(8) NOT NULL DEFAULT '',
+ field2 varchar(8) NOT NULL DEFAULT '',
+ PRIMARY KEY (field1, field2)
+) ENGINE=InnoDB;
+
+CREATE TABLE t2 (
+ field1 varchar(8) NOT NULL DEFAULT '' PRIMARY KEY,
+ FOREIGN KEY (field1) REFERENCES t1 (field1)
+ ON DELETE CASCADE ON UPDATE CASCADE
+) ENGINE=InnoDB;
+
+INSERT INTO t1 VALUES ('old', 'somevalu');
+INSERT INTO t1 VALUES ('other', 'anyvalue');
+
+INSERT INTO t2 VALUES ('old');
+INSERT INTO t2 VALUES ('other');
+
+--error ER_FOREIGN_DUPLICATE_KEY_WITH_CHILD_INFO
+UPDATE t1 SET field1 = 'other' WHERE field2 = 'somevalu';
+
+DROP TABLE t2;
+DROP TABLE t1;
+
+#
+# Bug#18477 - MySQL/InnoDB Ignoring Foreign Keys in ALTER TABLE
+#
+create table t1 (
+ c1 bigint not null,
+ c2 bigint not null,
+ primary key (c1),
+ unique key (c2)
+) engine=innodb;
+#
+create table t2 (
+ c1 bigint not null,
+ primary key (c1)
+) engine=innodb;
+#
+alter table t1 add constraint c2_fk foreign key (c2)
+ references t2(c1) on delete cascade;
+show create table t1;
+#
+alter table t1 drop foreign key c2_fk;
+show create table t1;
+#
+drop table t1, t2;
+
+#
+# Bug #14360: problem with intervals
+#
+
+create table t1(a date) engine=innodb;
+create table t2(a date, key(a)) engine=innodb;
+insert into t1 values('2005-10-01');
+insert into t2 values('2005-10-01');
+select * from t1, t2
+ where t2.a between t1.a - interval 2 day and t1.a + interval 2 day;
+drop table t1, t2;
+
+create table t1 (id int not null, f_id int not null, f int not null,
+primary key(f_id, id)) engine=innodb;
+create table t2 (id int not null,s_id int not null,s varchar(200),
+primary key(id)) engine=innodb;
+INSERT INTO t1 VALUES (8, 1, 3);
+INSERT INTO t1 VALUES (1, 2, 1);
+INSERT INTO t2 VALUES (1, 0, '');
+INSERT INTO t2 VALUES (8, 1, '');
+commit;
+DELETE ml.* FROM t1 AS ml LEFT JOIN t2 AS mm ON (mm.id=ml.id)
+WHERE mm.id IS NULL;
+select ml.* from t1 as ml left join t2 as mm on (mm.id=ml.id)
+where mm.id is null lock in share mode;
+drop table t1,t2;
+
+#
+# Test case where X-locks on unused rows should be released in a
+# update (because READ COMMITTED isolation level)
+#
+
+connect (a,localhost,root,,);
+connect (b,localhost,root,,);
+connection a;
+create table t1(a int not null, b int, primary key(a)) engine=innodb;
+insert into t1 values(1,1),(2,2),(3,1),(4,2),(5,1),(6,2),(7,3);
+commit;
+SET binlog_format='MIXED';
+set autocommit = 0;
+SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED;
+update t1 set b = 5 where b = 1;
+connection b;
+SET binlog_format='MIXED';
+set autocommit = 0;
+SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED;
+#
+# X-lock to record (7,3) should be released in a update
+#
+select * from t1 where a = 7 and b = 3 for update;
+connection a;
+commit;
+connection b;
+commit;
+drop table t1;
+connection default;
+disconnect a;
+disconnect b;
+
+#
+# Test case where no locks should be released (because we are not
+# using READ COMMITTED isolation level)
+#
+
+connect (a,localhost,root,,);
+connect (b,localhost,root,,);
+connection a;
+create table t1(a int not null, b int, primary key(a)) engine=innodb;
+insert into t1 values(1,1),(2,2),(3,1),(4,2),(5,1),(6,2);
+commit;
+set autocommit = 0;
+select * from t1 lock in share mode;
+update t1 set b = 5 where b = 1;
+connection b;
+set autocommit = 0;
+#
+# S-lock to records (2,2),(4,2), and (6,2) should not be released in a update
+#
+--error ER_LOCK_WAIT_TIMEOUT
+select * from t1 where a = 2 and b = 2 for update;
+#
+# X-lock to record (1,1),(3,1),(5,1) should not be released in a update
+#
+--error ER_LOCK_WAIT_TIMEOUT
+connection a;
+commit;
+connection b;
+commit;
+connection default;
+disconnect a;
+disconnect b;
+drop table t1;
+
+#
+# Consistent read should be used in following selects
+#
+# 1) INSERT INTO ... SELECT
+# 2) UPDATE ... = ( SELECT ...)
+# 3) CREATE ... SELECT
+
+connect (a,localhost,root,,);
+connect (b,localhost,root,,);
+connection a;
+create table t1(a int not null, b int, primary key(a)) engine=innodb;
+insert into t1 values (1,2),(5,3),(4,2);
+create table t2(d int not null, e int, primary key(d)) engine=innodb;
+insert into t2 values (8,6),(12,1),(3,1);
+commit;
+set autocommit = 0;
+select * from t2 for update;
+connection b;
+SET binlog_format='MIXED';
+set autocommit = 0;
+SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED;
+insert into t1 select * from t2;
+update t1 set b = (select e from t2 where a = d);
+create table t3(d int not null, e int, primary key(d)) engine=innodb
+select * from t2;
+commit;
+connection a;
+commit;
+connection default;
+disconnect a;
+disconnect b;
+drop table t1, t2, t3;
+
+#
+# Consistent read should not be used if
+#
+# (a) isolation level is serializable OR
+# (b) select ... lock in share mode OR
+# (c) select ... for update
+#
+# in following queries:
+#
+# 1) INSERT INTO ... SELECT
+# 2) UPDATE ... = ( SELECT ...)
+# 3) CREATE ... SELECT
+
+connect (a,localhost,root,,);
+connect (b,localhost,root,,);
+connect (c,localhost,root,,);
+connect (d,localhost,root,,);
+connect (e,localhost,root,,);
+connect (f,localhost,root,,);
+connect (g,localhost,root,,);
+connect (h,localhost,root,,);
+connect (i,localhost,root,,);
+connect (j,localhost,root,,);
+connection a;
+create table t1(a int not null, b int, primary key(a)) engine=innodb;
+insert into t1 values (1,2),(5,3),(4,2);
+create table t2(a int not null, b int, primary key(a)) engine=innodb;
+insert into t2 values (8,6),(12,1),(3,1);
+create table t3(d int not null, b int, primary key(d)) engine=innodb;
+insert into t3 values (8,6),(12,1),(3,1);
+create table t5(a int not null, b int, primary key(a)) engine=innodb;
+insert into t5 values (1,2),(5,3),(4,2);
+create table t6(d int not null, e int, primary key(d)) engine=innodb;
+insert into t6 values (8,6),(12,1),(3,1);
+create table t8(a int not null, b int, primary key(a)) engine=innodb;
+insert into t8 values (1,2),(5,3),(4,2);
+create table t9(d int not null, e int, primary key(d)) engine=innodb;
+insert into t9 values (8,6),(12,1),(3,1);
+commit;
+set autocommit = 0;
+select * from t2 for update;
+connection b;
+SET binlog_format='MIXED';
+set autocommit = 0;
+SET SESSION TRANSACTION ISOLATION LEVEL SERIALIZABLE;
+--send
+insert into t1 select * from t2;
+connection c;
+SET binlog_format='MIXED';
+set autocommit = 0;
+SET SESSION TRANSACTION ISOLATION LEVEL SERIALIZABLE;
+--send
+update t3 set b = (select b from t2 where a = d);
+connection d;
+SET binlog_format='MIXED';
+set autocommit = 0;
+SET SESSION TRANSACTION ISOLATION LEVEL SERIALIZABLE;
+--send
+create table t4(a int not null, b int, primary key(a)) engine=innodb select * from t2;
+connection e;
+SET binlog_format='MIXED';
+set autocommit = 0;
+SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED;
+--send
+insert into t5 (select * from t2 lock in share mode);
+connection f;
+SET binlog_format='MIXED';
+set autocommit = 0;
+SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED;
+--send
+update t6 set e = (select b from t2 where a = d lock in share mode);
+connection g;
+SET binlog_format='MIXED';
+set autocommit = 0;
+SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED;
+--send
+create table t7(a int not null, b int, primary key(a)) engine=innodb select * from t2 lock in share mode;
+connection h;
+SET binlog_format='MIXED';
+set autocommit = 0;
+SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED;
+--send
+insert into t8 (select * from t2 for update);
+connection i;
+SET binlog_format='MIXED';
+set autocommit = 0;
+SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED;
+--send
+update t9 set e = (select b from t2 where a = d for update);
+connection j;
+SET binlog_format='MIXED';
+set autocommit = 0;
+SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED;
+--send
+create table t10(a int not null, b int, primary key(a)) engine=innodb select * from t2 for update;
+
+connection b;
+--error ER_LOCK_WAIT_TIMEOUT
+reap;
+
+connection c;
+--error ER_LOCK_WAIT_TIMEOUT
+reap;
+
+connection d;
+--error ER_LOCK_WAIT_TIMEOUT
+reap;
+
+connection e;
+--error ER_LOCK_WAIT_TIMEOUT
+reap;
+
+connection f;
+--error ER_LOCK_WAIT_TIMEOUT
+reap;
+
+connection g;
+--error ER_LOCK_WAIT_TIMEOUT
+reap;
+
+connection h;
+--error ER_LOCK_WAIT_TIMEOUT
+reap;
+
+connection i;
+--error ER_LOCK_WAIT_TIMEOUT
+reap;
+
+connection j;
+--error ER_LOCK_WAIT_TIMEOUT
+reap;
+
+connection a;
+commit;
+
+connection default;
+disconnect a;
+disconnect b;
+disconnect c;
+disconnect d;
+disconnect e;
+disconnect f;
+disconnect g;
+disconnect h;
+disconnect i;
+disconnect j;
+drop table t1, t2, t3, t5, t6, t8, t9;
+
+# bug 18934, "InnoDB crashes when table uses column names like DB_ROW_ID"
+--error ER_WRONG_COLUMN_NAME
+CREATE TABLE t1 (DB_ROW_ID int) engine=innodb;
+
+#
+# Bug #17152: Wrong result with BINARY comparison on aliased column
+#
+
+CREATE TABLE t1 (
+ a BIGINT(20) NOT NULL,
+ PRIMARY KEY (a)
+ ) ENGINE=INNODB DEFAULT CHARSET=UTF8;
+
+CREATE TABLE t2 (
+ a BIGINT(20) NOT NULL,
+ b VARCHAR(128) NOT NULL,
+ c TEXT NOT NULL,
+ PRIMARY KEY (a,b),
+ KEY idx_t2_b_c (b,c(100)),
+ CONSTRAINT t_fk FOREIGN KEY (a) REFERENCES t1 (a)
+ ON DELETE CASCADE
+ ) ENGINE=INNODB DEFAULT CHARSET=UTF8;
+
+INSERT INTO t1 VALUES (1);
+INSERT INTO t2 VALUES (1, 'bar', 'vbar');
+INSERT INTO t2 VALUES (1, 'BAR2', 'VBAR');
+INSERT INTO t2 VALUES (1, 'bar_bar', 'bibi');
+INSERT INTO t2 VALUES (1, 'customer_over', '1');
+
+SELECT * FROM t2 WHERE b = 'customer_over';
+SELECT * FROM t2 WHERE BINARY b = 'customer_over';
+SELECT DISTINCT p0.a FROM t2 p0 WHERE p0.b = 'customer_over';
+/* Bang: Empty result set, above was expected: */
+SELECT DISTINCT p0.a FROM t2 p0 WHERE BINARY p0.b = 'customer_over';
+SELECT p0.a FROM t2 p0 WHERE BINARY p0.b = 'customer_over';
+
+drop table t2, t1;
+
+#
+# Test optimize on table with open transaction
+#
+
+CREATE TABLE t1 ( a int ) ENGINE=innodb;
+BEGIN;
+INSERT INTO t1 VALUES (1);
+OPTIMIZE TABLE t1;
+DROP TABLE t1;
+
+#
+# Bug #24741 (existing cascade clauses disappear when adding foreign keys)
+#
+
+CREATE TABLE t1 (id int PRIMARY KEY, f int NOT NULL, INDEX(f)) ENGINE=InnoDB;
+
+CREATE TABLE t2 (id int PRIMARY KEY, f INT NOT NULL,
+ CONSTRAINT t2_t1 FOREIGN KEY (id) REFERENCES t1 (id)
+ ON DELETE CASCADE ON UPDATE CASCADE) ENGINE=InnoDB;
+
+ALTER TABLE t2 ADD FOREIGN KEY (f) REFERENCES t1 (f) ON
+DELETE CASCADE ON UPDATE CASCADE;
+
+SHOW CREATE TABLE t2;
+DROP TABLE t2, t1;
+
+#
+# Bug #25927: Prevent ALTER TABLE ... MODIFY ... NOT NULL on columns
+# for which there is a foreign key constraint ON ... SET NULL.
+#
+
+CREATE TABLE t1 (a INT, INDEX(a)) ENGINE=InnoDB;
+CREATE TABLE t2 (a INT, INDEX(a)) ENGINE=InnoDB;
+INSERT INTO t1 VALUES (1);
+INSERT INTO t2 VALUES (1);
+ALTER TABLE t2 ADD FOREIGN KEY (a) REFERENCES t1 (a) ON DELETE SET NULL;
+# NULL -> NOT NULL only allowed INPLACE if strict sql_mode is on.
+set @old_sql_mode = @@sql_mode;
+set @@sql_mode = 'STRICT_TRANS_TABLES';
+--error ER_FK_COLUMN_NOT_NULL
+ALTER TABLE t2 MODIFY a INT NOT NULL;
+set @@sql_mode = @old_sql_mode;
+DELETE FROM t1;
+DROP TABLE t2,t1;
+
+#
+# Bug #26835: table corruption after delete+insert
+#
+
+CREATE TABLE t1 (a VARCHAR(5) COLLATE utf8_unicode_ci PRIMARY KEY)
+ENGINE=InnoDB;
+INSERT INTO t1 VALUES (0xEFBCA4EFBCA4EFBCA4);
+DELETE FROM t1;
+INSERT INTO t1 VALUES ('DDD');
+SELECT * FROM t1;
+DROP TABLE t1;
+
+#
+# Bug #23313 (AUTO_INCREMENT=# not reported back for InnoDB tables)
+# Bug #21404 (AUTO_INCREMENT value reset when Adding FKEY (or ALTER?))
+#
+
+CREATE TABLE t1 (id int PRIMARY KEY AUTO_INCREMENT) ENGINE=InnoDB
+AUTO_INCREMENT=42;
+
+INSERT INTO t1 VALUES (0),(347),(0);
+SELECT * FROM t1;
+
+SHOW CREATE TABLE t1;
+
+CREATE TABLE t2 (id int PRIMARY KEY) ENGINE=InnoDB;
+INSERT INTO t2 VALUES(42),(347),(348);
+ALTER TABLE t1 ADD CONSTRAINT t1_t2 FOREIGN KEY (id) REFERENCES t2(id);
+SHOW CREATE TABLE t1;
+
+DROP TABLE t1,t2;
+
+#
+# Bug #21101 (Prints wrong error message if max row size is too large)
+#
+SET innodb_strict_mode=ON;
+--replace_result 8126 {checked_valid} 4030 {checked_valid} 1982 {checked_valid}
+--error ER_TOO_BIG_ROWSIZE
+CREATE TABLE t1 (
+ c01 CHAR(255), c02 CHAR(255), c03 CHAR(255), c04 CHAR(255),
+ c05 CHAR(255), c06 CHAR(255), c07 CHAR(255), c08 CHAR(255),
+ c09 CHAR(255), c10 CHAR(255), c11 CHAR(255), c12 CHAR(255),
+ c13 CHAR(255), c14 CHAR(255), c15 CHAR(255), c16 CHAR(255),
+ c17 CHAR(255), c18 CHAR(255), c19 CHAR(255), c20 CHAR(255),
+ c21 CHAR(255), c22 CHAR(255), c23 CHAR(255), c24 CHAR(255),
+ c25 CHAR(255), c26 CHAR(255), c27 CHAR(255), c28 CHAR(255),
+ c29 CHAR(255), c30 CHAR(255), c31 CHAR(255), c32 CHAR(255)
+ ) ENGINE = InnoDB;
+SET innodb_strict_mode=OFF;
+
+#
+# Bug #31860 InnoDB assumes AUTOINC values can only be positive.
+#
+DROP TABLE IF EXISTS t1;
+CREATE TABLE t1(
+ id BIGINT(20) NOT NULL AUTO_INCREMENT PRIMARY KEY
+ ) ENGINE=InnoDB;
+INSERT INTO t1 VALUES(-10);
+SELECT * FROM t1;
+#
+# NOTE: The server really needs to be restarted at this point
+# for the test to be useful.
+#
+# Without the fix InnoDB would trip over an assertion here.
+INSERT INTO t1 VALUES(NULL);
+# The next value should be 1 and not -9 or a -ve number
+SELECT * FROM t1;
+DROP TABLE t1;
+
+#
+# Bug #21409 Incorrect result returned when in READ-COMMITTED with
+# query_cache ON
+#
+CONNECT (c1,localhost,root,,);
+CONNECT (c2,localhost,root,,);
+CONNECTION c1;
+SET binlog_format='MIXED';
+SET TX_ISOLATION='read-committed';
+SET AUTOCOMMIT=0;
+DROP TABLE IF EXISTS t1, t2;
+CREATE TABLE t1 ( a int ) ENGINE=InnoDB;
+CREATE TABLE t2 LIKE t1;
+SELECT * FROM t2;
+CONNECTION c2;
+SET binlog_format='MIXED';
+SET TX_ISOLATION='read-committed';
+SET AUTOCOMMIT=0;
+INSERT INTO t1 VALUES (1);
+COMMIT;
+CONNECTION c1;
+SELECT * FROM t1 WHERE a=1;
+DISCONNECT c1;
+DISCONNECT c2;
+CONNECT (c1,localhost,root,,);
+CONNECT (c2,localhost,root,,);
+CONNECTION c1;
+SET binlog_format='MIXED';
+SET TX_ISOLATION='read-committed';
+SET AUTOCOMMIT=0;
+SELECT * FROM t2;
+CONNECTION c2;
+SET binlog_format='MIXED';
+SET TX_ISOLATION='read-committed';
+SET AUTOCOMMIT=0;
+INSERT INTO t1 VALUES (2);
+COMMIT;
+CONNECTION c1;
+# The result set below should be the same for both selects
+SELECT * FROM t1 WHERE a=2;
+SELECT * FROM t1 WHERE a=2;
+DROP TABLE t1;
+DROP TABLE t2;
+DISCONNECT c1;
+DISCONNECT c2;
+CONNECTION default;
+
+#
+# Bug #29157 UPDATE, changed rows incorrect
+#
+create table t1 (i int, j int) engine=innodb;
+insert into t1 (i, j) values (1, 1), (2, 2);
+--enable_info
+update t1 set j = 2;
+--disable_info
+drop table t1;
+
+#
+# Bug #32440 InnoDB free space info does not appear in SHOW TABLE STATUS or
+# I_S
+#
+create table t1 (id int) comment='this is a comment' engine=innodb;
+select table_comment, data_free > 0 as data_free_is_set
+ from information_schema.tables
+ where table_schema='test' and table_name = 't1';
+drop table t1;
+
+#
+# Bug 34920 test
+#
+CONNECTION default;
+CREATE TABLE t1 (
+ c1 INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
+ c2 VARCHAR(128) NOT NULL,
+ PRIMARY KEY(c1)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=100;
+
+CREATE TABLE t2 (
+ c1 INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
+ c2 INT(10) UNSIGNED DEFAULT NULL,
+ PRIMARY KEY(c1)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=200;
+
+SELECT AUTO_INCREMENT FROM INFORMATION_SCHEMA.TABLES WHERE table_name = 't2';
+ALTER TABLE t2 ADD CONSTRAINT t1_t2_1 FOREIGN KEY(c1) REFERENCES t1(c1);
+SELECT AUTO_INCREMENT FROM INFORMATION_SCHEMA.TABLES WHERE table_name = 't2';
+DROP TABLE t2;
+DROP TABLE t1;
+# End 34920 test
+#
+# Bug #29507 TRUNCATE shows to many rows effected
+#
+CONNECTION default;
+CREATE TABLE t1 (c1 int default NULL,
+ c2 int default NULL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1;
+
+--enable_info
+TRUNCATE TABLE t1;
+
+INSERT INTO t1 VALUES (1, 1), (2, 2), (3, 3), (4, 4), (5, 5);
+TRUNCATE TABLE t1;
+
+--disable_info
+DROP TABLE t1;
+#
+# Bug#35537 Innodb doesn't increment handler_update and handler_delete.
+#
+-- disable_query_log
+-- disable_result_log
+
+CONNECT (c1,localhost,root,,);
+
+DROP TABLE IF EXISTS bug35537;
+CREATE TABLE bug35537 (
+ c1 int
+) ENGINE=InnoDB;
+
+INSERT INTO bug35537 VALUES (1);
+
+-- enable_result_log
+
+SHOW SESSION STATUS LIKE 'Handler_update%';
+SHOW SESSION STATUS LIKE 'Handler_delete%';
+
+UPDATE bug35537 SET c1 = 2 WHERE c1 = 1;
+DELETE FROM bug35537 WHERE c1 = 2;
+
+SHOW SESSION STATUS LIKE 'Handler_update%';
+SHOW SESSION STATUS LIKE 'Handler_delete%';
+
+DROP TABLE bug35537;
+
+DISCONNECT c1;
+CONNECTION default;
+
+-- enable_query_log
+
+# Clean up after the Bug#55284/Bug#58912 test case.
+DROP TABLE bug58912;
+
+#
+# Test fix for bug 13117023. InnoDB increments HA_READ_KEY_COUNT (aka
+# HANDLER_READ_KEY) when it should not.
+#
+create table t1 (f1 integer primary key) engine=innodb;
+flush status;
+show status like "handler_read_key";
+select f1 from t1;
+show status like "handler_read_key";
+drop table t1;
+
+#
+# Test handling of writes to TEMPORARY tables for read-only transactions
+#
+CREATE TABLE t1 (c1 INT) ENGINE=InnoDB;
+CREATE TEMPORARY TABLE t2 (c1 INT) ENGINE=InnoDB;
+
+# Check that the rollback works
+START TRANSACTION READ ONLY;
+INSERT INTO t2 VALUES(0);
+--error ER_CANT_EXECUTE_IN_READ_ONLY_TRANSACTION
+INSERT INTO t1 VALUES(0);
+ROLLBACK;
+
+SELECT * FROM t1;
+SELECT * FROM t2;
+
+START TRANSACTION READ ONLY;
+--error ER_CANT_EXECUTE_IN_READ_ONLY_TRANSACTION
+INSERT INTO t1 VALUES(0);
+INSERT INTO t2 VALUES(1);
+COMMIT;
+
+SET TRANSACTION READ ONLY;
+START TRANSACTION;
+INSERT INTO t2 VALUES(3);
+--error ER_CANT_EXECUTE_IN_READ_ONLY_TRANSACTION
+INSERT INTO t1 VALUES(0);
+COMMIT;
+
+SELECT * FROM t1;
+SELECT * FROM t2;
+
+DROP TABLE t2;
+
+# This time with some indexes
+CREATE TEMPORARY TABLE t2 (
+ c1 INT AUTO_INCREMENT PRIMARY KEY,
+ c2 INT, INDEX idx(c2)) ENGINE=InnoDB;
+
+SHOW CREATE TABLE t2;
+
+# Check that the rollback works
+START TRANSACTION READ ONLY;
+INSERT INTO t2 VALUES(NULL,1),(NULL,2),(NULL,3);
+--error ER_CANT_EXECUTE_IN_READ_ONLY_TRANSACTION
+INSERT INTO t1 VALUES(0);
+ROLLBACK;
+
+SELECT * FROM t1;
+SELECT * FROM t2;
+
+START TRANSACTION READ ONLY;
+--error ER_CANT_EXECUTE_IN_READ_ONLY_TRANSACTION
+INSERT INTO t1 VALUES(0);
+INSERT INTO t2 VALUES(NULL,1),(NULL,2),(NULL,3);
+COMMIT;
+
+SET TRANSACTION READ ONLY;
+START TRANSACTION;
+INSERT INTO t2 VALUES(NULL,1),(NULL,2),(NULL,3);
+--error ER_CANT_EXECUTE_IN_READ_ONLY_TRANSACTION
+INSERT INTO t1 VALUES(0);
+COMMIT;
+
+SHOW CREATE TABLE t2;
+SELECT * FROM t1;
+SELECT * FROM t2;
+
+DROP TABLE t1;
+DROP TABLE t2;
+
+--echo #
+--echo # MDEV-24748 Extern field check missing
+--echo # in btr_index_rec_validate()
+--echo #
+CREATE TABLE t1 (pk INT, c1 char(255),
+c2 char(255), c3 char(255), c4 char(255),
+c5 char(255), c6 char(255), c7 char(255),
+c8 char(255), primary key (pk)
+) CHARACTER SET utf32 ENGINE=InnoDB;
+
+INSERT INTO t1 VALUES
+ (1, 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'),
+ (2, 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p');
+CHECK TABLE t1;
+ALTER TABLE t1 FORCE;
+# Cleanup
+DROP TABLE t1;
diff --git a/mysql-test/suite/innodb/t/innodb_28867993.test b/mysql-test/suite/innodb/t/innodb_28867993.test
new file mode 100644
index 00000000..4777a9ac
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb_28867993.test
@@ -0,0 +1,16 @@
+#
+# Bug#28867993: POSSIBLE ISSUE WITH MYSQL SERVER RESTART
+#
+
+source include/have_innodb.inc;
+create table t1 (a int) engine=innodb;
+insert t1 values (1),(2);
+create database ib_logfile2;
+--disable_query_log
+call mtr.add_suppression("InnoDB: Operating system error number ");
+call mtr.add_suppression("InnoDB: Error number .* means ");
+--enable_query_log
+source include/restart_mysqld.inc;
+select * from t1;
+drop table t1;
+drop database ib_logfile2;
diff --git a/mysql-test/suite/innodb/t/innodb_autoinc_lock_mode_zero-master.opt b/mysql-test/suite/innodb/t/innodb_autoinc_lock_mode_zero-master.opt
new file mode 100644
index 00000000..e27ee9b2
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb_autoinc_lock_mode_zero-master.opt
@@ -0,0 +1 @@
+--loose-innodb-autoinc-lock-mode=0
diff --git a/mysql-test/suite/innodb/t/innodb_autoinc_lock_mode_zero.test b/mysql-test/suite/innodb/t/innodb_autoinc_lock_mode_zero.test
new file mode 100644
index 00000000..07f096b2
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb_autoinc_lock_mode_zero.test
@@ -0,0 +1,43 @@
+--source include/have_innodb.inc
+# This test runs with old-style locking, as:
+# --innodb-autoinc-lock-mode=0
+
+--disable_warnings
+drop table if exists t1;
+--enable_warnings
+
+
+#
+# Search on unique key
+#
+
+CREATE TABLE t1 (
+ id int(11) NOT NULL auto_increment,
+ ggid varchar(32) binary DEFAULT '' NOT NULL,
+ email varchar(64) DEFAULT '' NOT NULL,
+ passwd varchar(32) binary DEFAULT '' NOT NULL,
+ PRIMARY KEY (id),
+ UNIQUE ggid (ggid)
+) ENGINE=innodb;
+
+insert into t1 (ggid,passwd) values ('test1','xxx');
+insert into t1 (ggid,passwd) values ('test2','yyy');
+-- error ER_DUP_ENTRY
+insert into t1 (ggid,passwd) values ('test2','this will fail');
+-- error ER_DUP_ENTRY
+insert into t1 (ggid,id) values ('this will fail',1);
+
+select * from t1 where ggid='test1';
+select * from t1 where passwd='xxx';
+select * from t1 where id=2;
+
+replace into t1 (ggid,id) values ('this will work',1);
+replace into t1 (ggid,passwd) values ('test2','this will work');
+-- error ER_DUP_ENTRY
+update t1 set id=100,ggid='test2' where id=1;
+select * from t1;
+select * from t1 where id=1;
+select * from t1 where id=999;
+drop table t1;
+
+--echo End of tests
diff --git a/mysql-test/suite/innodb/t/innodb_buffer_pool_dump_pct.test b/mysql-test/suite/innodb/t/innodb_buffer_pool_dump_pct.test
new file mode 100644
index 00000000..38109116
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb_buffer_pool_dump_pct.test
@@ -0,0 +1,95 @@
+# ************************************************************
+# wl6504: This testcase is to check the functionality of the
+# innodb_buffer_pool_dump_pct flag
+# step 1.Set innodb_buffer_pool_dump_pct=100 and take the dump
+# step 2.Set innodb_buffer_pool_dump_pct=1 and take the dump
+# step 3.Compare the size of both the dump files
+#*************************************************************
+--source include/have_innodb.inc
+--source include/have_innodb_16k.inc
+
+let MYSQLD_DATADIR = `SELECT @@datadir`;
+
+CREATE TABLE tab5 (col1 int auto_increment primary key,
+col2 VARCHAR(25), col3 varchar(25)) ENGINE=InnoDB;
+CREATE INDEX idx1 ON tab5(col2(10));
+CREATE INDEX idx2 ON tab5(col3(10));
+
+SET GLOBAL innodb_buffer_pool_dump_pct=100;
+
+#***********************************************************
+# SELECT *
+# FROM information_schema.global_status
+# WHERE variable_name = 'INNODB_BUFFER_POOL_DUMP_STATUS'
+# gives
+# a) VARIABLE_NAME VARIABLE_VALUE
+# INNODB_BUFFER_POOL_DUMP_STATUS not started
+# in case there was no innodb_buffer_pool_dump since server start.
+# b) Something like
+# VARIABLE_NAME VARIABLE_VALUE
+# INNODB_BUFFER_POOL_DUMP_STATUS Buffer pool(s) dump completed at 130711 13:43:24
+# in case there was a innodb_buffer_pool_dump since server start.
+# Attention:
+# - There is no guarantee that the current test is the first test which
+# made an innodb_buffer_pool_dump since server startup.
+# - The granularity of the timestamp is one second.
+# - There could have been some dump caused by some previous test
+# just a few milliseconds before.
+# In order to avoid conflict with previous tests, read the current value
+# of INNODB_BUFFER_POOL_DUMP_STATUS
+# and confirm that the timestamp is different after the dump
+#***********************************************************
+
+# Read the current value to compare with the new value.
+SELECT variable_value INTO @IBPDS
+FROM information_schema.global_status
+WHERE variable_name = 'INNODB_BUFFER_POOL_DUMP_STATUS';
+SET GLOBAL innodb_buffer_pool_dump_now=ON;
+
+# Sleep one second in order to ensure that the time stamp is
+# different at next dump
+--sleep 1
+
+let $wait_condition = SELECT count(*) = 1
+FROM information_schema.global_status
+WHERE variable_name = 'INNODB_BUFFER_POOL_DUMP_STATUS'
+AND variable_value != @IBPDS
+AND variable_value like 'Buffer pool(s) dump completed at%';
+--source include/wait_condition.inc
+
+--move_file $MYSQLD_DATADIR/ib_buffer_pool $MYSQLD_DATADIR/ib_buffer_pool100
+SET GLOBAL innodb_buffer_pool_dump_pct=1;
+SELECT @@global.innodb_buffer_pool_dump_pct;
+
+# Read the current value to compare with the new value.
+--disable_warnings
+SELECT variable_value INTO @IBPDS
+FROM information_schema.global_status
+WHERE variable_name = 'INNODB_BUFFER_POOL_DUMP_STATUS';
+--enable_warnings
+
+SET GLOBAL innodb_buffer_pool_dump_now=ON;
+
+# Sleep one second in order to ensure that the time stamp is
+# different at next dump
+--sleep 1
+
+let $wait_condition = SELECT count(*) = 1
+FROM information_schema.global_status
+WHERE variable_name = 'INNODB_BUFFER_POOL_DUMP_STATUS'
+AND variable_value != @IBPDS
+AND variable_value like 'Buffer pool(s) dump completed at%';
+--source include/wait_condition.inc
+
+--file_exists $MYSQLD_DATADIR/ib_buffer_pool
+
+perl;
+my $size1 = -s "$ENV{MYSQLD_DATADIR}/ib_buffer_pool";
+my $size100 = -s "$ENV{MYSQLD_DATADIR}/ib_buffer_pool100";
+die "$size100<=$size1\n" unless $size100 > $size1;
+EOF
+
+SET GLOBAL innodb_buffer_pool_dump_pct=DEFAULT;
+
+--remove_file $MYSQLD_DATADIR/ib_buffer_pool100
+DROP TABLE tab5;
diff --git a/mysql-test/suite/innodb/t/innodb_buffer_pool_fail.test b/mysql-test/suite/innodb/t/innodb_buffer_pool_fail.test
new file mode 100644
index 00000000..1d938e12
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb_buffer_pool_fail.test
@@ -0,0 +1,11 @@
+--source include/have_innodb.inc
+--source include/have_debug.inc
+call mtr.add_suppression("InnoDB: Cannot allocate memory for the buffer pool");
+call mtr.add_suppression("InnoDB: Plugin initialization aborted at srv0start.cc.*");
+call mtr.add_suppression("Plugin 'InnoDB' init function returned error.");
+call mtr.add_suppression("Plugin 'InnoDB' registration as a STORAGE ENGINE failed.");
+--echo #
+--echo # MDEV-25019 memory allocation failures during startup cause server failure in different, confusing ways
+--echo #
+let restart_parameters=--debug_dbug="+d,ib_buf_chunk_init_fails";
+--source include/restart_mysqld.inc
diff --git a/mysql-test/suite/innodb/t/innodb_buffer_pool_load_now.opt b/mysql-test/suite/innodb/t/innodb_buffer_pool_load_now.opt
new file mode 100644
index 00000000..948d874d
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb_buffer_pool_load_now.opt
@@ -0,0 +1,3 @@
+--innodb-buffer-pool-size=64M
+--skip-innodb-buffer-pool-load-at-startup
+--skip-innodb-buffer-pool-dump-at-shutdown
diff --git a/mysql-test/suite/innodb/t/innodb_buffer_pool_load_now.test b/mysql-test/suite/innodb/t/innodb_buffer_pool_load_now.test
new file mode 100644
index 00000000..baced6e9
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb_buffer_pool_load_now.test
@@ -0,0 +1,190 @@
+#Want to skip this test from daily Valgrind execution
+--source include/no_valgrind_without_big.inc
+#
+# Test for the functionality of InnoDB Buffer Pool dump/load.
+#
+
+# This case checks buffer pool dump/load works as expected
+# with innodb_buffer_pool_dump_now=ON
+# and innodb_buffer_pool_load_now=ON
+
+--source include/have_innodb.inc
+# include/restart_mysqld.inc does not work in embedded mode
+--source include/not_embedded.inc
+--source include/have_sequence.inc
+
+--let $file = `SELECT CONCAT(@@datadir, @@global.innodb_buffer_pool_filename)`
+
+--error 0,1
+--remove_file $file
+
+# Dump the whole buffer pool because if only a portion of it is dumped, we
+# cannot be sure how many of the ib_bp_test's pages will end up in the dump.
+SET GLOBAL innodb_buffer_pool_dump_pct=100;
+
+# Create a table and populate it with some data
+CREATE TABLE ib_bp_test
+(a INT AUTO_INCREMENT, b VARCHAR(64), c TEXT, PRIMARY KEY (a), KEY (b, c(128)))
+ENGINE=INNODB;
+
+SELECT PAGE_NUMBER FROM information_schema.innodb_buffer_page_lru
+WHERE table_name = '`test`.`ib_bp_test`';
+
+SELECT SPACE INTO @space FROM information_schema.innodb_buffer_page_lru
+WHERE table_name = '`test`.`ib_bp_test`' AND PAGE_NUMBER=3;
+
+let SPACE=`SELECT @space`;
+
+INSERT INTO ib_bp_test
+SELECT NULL, REPEAT('b', 64), REPEAT('c', 256) FROM seq_1_to_16382;
+
+SELECT COUNT(*) FROM information_schema.innodb_buffer_page_lru
+WHERE table_name = '`test`.`ib_bp_test`';
+
+# Dump
+SET GLOBAL innodb_buffer_pool_dump_now = ON;
+
+# Wait for the dump to complete
+--disable_warnings
+let $wait_condition =
+ SELECT SUBSTR(variable_value, 1, 33) = 'Buffer pool(s) dump completed at '
+ FROM information_schema.global_status
+ WHERE LOWER(variable_name) = 'innodb_buffer_pool_dump_status';
+--enable_warnings
+--source include/wait_condition.inc
+
+# Confirm the file has been created
+--file_exists $file
+
+# Add some garbage records to the dump file
+--let IBDUMPFILE = $file
+perl;
+my $fn = $ENV{'IBDUMPFILE'};
+open(my $fh, '>>', $fn) || die "perl open($fn): $!";
+print $fh "123456,0\n";
+print $fh "0,123456\n";
+print $fh "123456,123456\n";
+close($fh);
+EOF
+
+--move_file $file $file.now
+
+# Complete purge (and change buffer merge).
+SET GLOBAL innodb_fast_shutdown=0;
+--source include/shutdown_mysqld.inc
+
+# Make sure no dump after shutdown
+--error 1
+--file_exists $file
+
+--source include/start_mysqld.inc
+
+--move_file $file.now $file
+
+# See that we have no pages in the LRU
+SELECT PAGE_NUMBER FROM information_schema.innodb_buffer_page_lru
+WHERE table_name = '`test`.`ib_bp_test`';
+
+# Load the table so that entries in the I_S table do not appear as NULL
+select count(*) from ib_bp_test LIMIT 0;
+
+# Load
+SET GLOBAL innodb_buffer_pool_load_now = ON;
+
+# Wait for the load to complete
+--disable_warnings
+let $wait_condition =
+ SELECT SUBSTR(variable_value, 1, 33) = 'Buffer pool(s) load completed at '
+ FROM information_schema.global_status
+ WHERE LOWER(variable_name) = 'innodb_buffer_pool_load_status';
+--enable_warnings
+--source include/wait_condition.inc
+
+# Show the status, interesting if the above timed out
+--disable_warnings
+--replace_regex /[0-9]{6}[[:space:]]+[0-9]{1,2}:[0-9]{2}:[0-9]{2}/TIMESTAMP_NOW/
+SELECT variable_value
+FROM information_schema.global_status
+WHERE LOWER(variable_name) = 'innodb_buffer_pool_load_status';
+--enable_warnings
+
+SELECT COUNT(*) FROM information_schema.innodb_buffer_page_lru
+WHERE table_name = '`test`.`ib_bp_test`';
+
+# Add some total garbage to the dump file
+--let IBDUMPFILE = $file
+perl;
+my $fn = $ENV{'IBDUMPFILE'};
+open(my $fh, '>>', $fn) || die "perl open($fn): $!";
+print $fh "abcdefg\n";
+close($fh);
+EOF
+
+call mtr.add_suppression("InnoDB: Error parsing");
+
+# Load
+SET GLOBAL innodb_buffer_pool_load_now = ON;
+
+# Wait for the load to fail
+--disable_warnings
+let $wait_condition =
+ SELECT SUBSTR(variable_value, 1, 13) = 'Error parsing'
+ FROM information_schema.global_status
+ WHERE LOWER(variable_name) = 'innodb_buffer_pool_load_status';
+--enable_warnings
+--source include/wait_condition.inc
+
+--echo # Re-write some valid pages to the dump file, make sure the space
+--echo # should be valid but all the page no should be out of bound of the file
+--let IBDUMPFILE = $file
+perl;
+my $fn = $ENV{'IBDUMPFILE'};
+my $space = $ENV{'SPACE'};
+open(my $fh, '>', $fn) || die "perl open($fn): $!";
+print $fh "$space,10000\n";
+print $fh "$space,10001\n";
+print $fh "$space,10002\n";
+close($fh);
+EOF
+
+# We force the restart so that the table would be closed
+--source include/restart_mysqld.inc
+
+# Load directly, without accessing the table first
+SET GLOBAL innodb_buffer_pool_load_now = ON;
+
+# Wait for the load to complete
+--disable_warnings
+let $wait_condition =
+ SELECT SUBSTR(variable_value, 1, 33) = 'Buffer pool(s) load completed at '
+ FROM information_schema.global_status
+ WHERE LOWER(variable_name) = 'innodb_buffer_pool_load_status';
+--enable_warnings
+--source include/wait_condition.inc
+
+# Show the status, interesting if the above timed out
+--disable_warnings
+--replace_regex /[0-9]{6}[[:space:]]+[0-9]{1,2}:[0-9]{2}:[0-9]{2}/TIMESTAMP_NOW/
+SELECT variable_value
+FROM information_schema.global_status
+WHERE LOWER(variable_name) = 'innodb_buffer_pool_load_status';
+--enable_warnings
+
+DROP TABLE ib_bp_test;
+SET GLOBAL innodb_buffer_pool_dump_pct=default;
+
+--echo #
+--echo # Bug#21371070 [ERROR] INNODB: CANNOT ALLOCATE 0 BYTES: SUCCESS
+--echo #
+
+--let $file = `SELECT CONCAT(@@datadir, @@global.innodb_buffer_pool_filename)`
+
+# Remove the buffer pool file that exists already
+--error 0,1
+--remove_file $file
+
+# Create an empty buffer pool file
+write_file $file;
+EOF
+
+SET GLOBAL innodb_buffer_pool_load_now = ON;
diff --git a/mysql-test/suite/innodb/t/innodb_buffer_pool_resize.opt b/mysql-test/suite/innodb/t/innodb_buffer_pool_resize.opt
new file mode 100644
index 00000000..39543543
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb_buffer_pool_resize.opt
@@ -0,0 +1,2 @@
+--innodb-buffer-pool-size=8M
+--innodb-page-size=4k
diff --git a/mysql-test/suite/innodb/t/innodb_buffer_pool_resize.test b/mysql-test/suite/innodb/t/innodb_buffer_pool_resize.test
new file mode 100644
index 00000000..051f38a5
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb_buffer_pool_resize.test
@@ -0,0 +1,72 @@
+#
+# WL6117 : Resize the InnoDB Buffer Pool Online
+#
+
+--source include/have_innodb.inc
+--source include/big_test.inc
+
+let $wait_timeout = 180;
+let $wait_condition =
+ SELECT SUBSTR(variable_value, 1, 30) = 'Completed resizing buffer pool'
+ FROM information_schema.global_status
+ WHERE LOWER(variable_name) = 'innodb_buffer_pool_resize_status';
+
+--disable_query_log
+set @old_innodb_buffer_pool_size = @@innodb_buffer_pool_size;
+set @old_innodb_adaptive_hash_index = @@innodb_adaptive_hash_index;
+--enable_query_log
+
+set global innodb_adaptive_hash_index=ON;
+
+select @@innodb_buffer_pool_size;
+
+# Expand buffer pool
+set global innodb_buffer_pool_size = 10485760;
+
+--source include/wait_condition.inc
+
+select @@innodb_buffer_pool_size;
+
+# fill buffer pool
+--disable_query_log
+SET @save_innodb_read_only_compressed=@@GLOBAL.innodb_read_only_compressed;
+SET GLOBAL innodb_read_only_compressed=OFF;
+--enable_query_log
+create table t1 (id int not null, val int not null default '0', primary key (id)) ENGINE=InnoDB ROW_FORMAT=COMPRESSED;
+create or replace view view0 as select 1 union all select 1;
+
+set @`v_id` := 0;
+set @`v_val` := 0;
+
+# 2^18 == 262144 records
+replace into t1 select (@`v_id` := (@`v_id` + 4) mod 4294967296) as id, (@`v_val` := (@`v_val` + 4) mod 4294967296) as val from view0 v0, view0 v1, view0 v2, view0 v3, view0 v4, view0 v5, view0 v6, view0 v7, view0 v8, view0 v9, view0 v10, view0 v11, view0 v12, view0 v13, view0 v14, view0 v15, view0 v16, view0 v17;
+--disable_query_log
+SET GLOBAL innodb_read_only_compressed=@save_innodb_read_only_compressed;
+--enable_query_log
+
+# Shrink buffer pool
+set global innodb_buffer_pool_size = 64 * 1024 * 1024 + 512 * 1024;
+--source include/wait_condition.inc
+
+select @@innodb_buffer_pool_size;
+
+select count(val) from t1;
+
+set global innodb_adaptive_hash_index=OFF;
+
+# Expand buffer pool to 24MB
+set global innodb_buffer_pool_size = 25165824;
+--source include/wait_condition.inc
+
+select @@innodb_buffer_pool_size;
+
+select count(val) from t1;
+
+drop table t1;
+drop view view0;
+
+--disable_query_log
+set global innodb_adaptive_hash_index = @old_innodb_adaptive_hash_index;
+set global innodb_buffer_pool_size = @old_innodb_buffer_pool_size;
+--enable_query_log
+--source include/wait_condition.inc
diff --git a/mysql-test/suite/innodb/t/innodb_buffer_pool_resize_bigtest.opt b/mysql-test/suite/innodb/t/innodb_buffer_pool_resize_bigtest.opt
new file mode 100644
index 00000000..72f055d3
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb_buffer_pool_resize_bigtest.opt
@@ -0,0 +1,2 @@
+--innodb-buffer-pool-chunk-size=1M
+--loose-skip-innodb-disable-resize_buffer_pool_debug
diff --git a/mysql-test/suite/innodb/t/innodb_buffer_pool_resize_bigtest.test b/mysql-test/suite/innodb/t/innodb_buffer_pool_resize_bigtest.test
new file mode 100644
index 00000000..db5da292
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb_buffer_pool_resize_bigtest.test
@@ -0,0 +1,28 @@
+--source include/have_innodb.inc
+--source include/big_test.inc
+
+SET @save_size=@@innodb_buffer_pool_size;
+
+let $wait_timeout = 60;
+let $wait_condition =
+ SELECT SUBSTR(variable_value, 1, 30) = 'Completed resizing buffer pool'
+ FROM information_schema.global_status
+ WHERE variable_name = 'INNODB_BUFFER_POOL_RESIZE_STATUS';
+
+--echo #
+--echo # MDEV-27891: Delayed SIGSEGV in InnoDB buffer pool resize
+--echo # after or during DROP TABLE
+--echo #
+
+select @@innodb_buffer_pool_chunk_size;
+CREATE TABLE t1 (a INT PRIMARY KEY) ENGINE=InnoDB;
+SET GLOBAL innodb_buffer_pool_size=256*1024*1024;
+DROP TABLE t1;
+--source include/wait_condition.inc
+SET GLOBAL innodb_buffer_pool_size=@@innodb_buffer_pool_size + @@innodb_buffer_pool_chunk_size;
+--source include/wait_condition.inc
+
+--echo # End of 10.6 tests
+
+SET GLOBAL innodb_buffer_pool_size=@save_size;
+--source include/wait_condition.inc
diff --git a/mysql-test/suite/innodb/t/innodb_buffer_pool_resize_debug.opt b/mysql-test/suite/innodb/t/innodb_buffer_pool_resize_debug.opt
new file mode 100644
index 00000000..dca040ea
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb_buffer_pool_resize_debug.opt
@@ -0,0 +1 @@
+--innodb-buffer-pool-size=8M --innodb-buffer-pool-chunk-size=2M
diff --git a/mysql-test/suite/innodb/t/innodb_buffer_pool_resize_temporary.test b/mysql-test/suite/innodb/t/innodb_buffer_pool_resize_temporary.test
new file mode 100644
index 00000000..c49ae451
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb_buffer_pool_resize_temporary.test
@@ -0,0 +1,27 @@
+--source include/have_innodb.inc
+--source include/have_sequence.inc
+--source include/have_debug.inc
+
+SET @save_limit=@@GLOBAL.innodb_limit_optimistic_insert_debug;
+SET @save_size=@@GLOBAL.innodb_buffer_pool_size;
+SET GLOBAL innodb_limit_optimistic_insert_debug=2;
+
+SET GLOBAL innodb_buffer_pool_size=16777216;
+
+CREATE TEMPORARY TABLE t1 (a INT PRIMARY KEY) ENGINE=InnoDB;
+INSERT INTO t1 SELECT seq FROM seq_1_to_200;
+
+SET GLOBAL innodb_buffer_pool_size=8388608;
+
+let $wait_timeout = 60;
+let $wait_condition =
+ SELECT SUBSTR(variable_value, 1, 30) = 'Completed resizing buffer pool'
+ FROM information_schema.global_status
+ WHERE variable_name = 'INNODB_BUFFER_POOL_RESIZE_STATUS';
+--source include/wait_condition.inc
+
+SELECT COUNT(*),MIN(a),MAX(a) FROM t1;
+DROP TEMPORARY TABLE t1;
+
+SET GLOBAL innodb_limit_optimistic_insert_debug=@save_limit;
+SET GLOBAL innodb_buffer_pool_size=@save_size;
diff --git a/mysql-test/suite/innodb/t/innodb_buffer_pool_resize_with_chunks.opt b/mysql-test/suite/innodb/t/innodb_buffer_pool_resize_with_chunks.opt
new file mode 100644
index 00000000..ade197de
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb_buffer_pool_resize_with_chunks.opt
@@ -0,0 +1,3 @@
+--innodb-buffer-pool-size=16M
+--innodb-buffer-pool-chunk-size=4M
+--innodb-page-size=4k
diff --git a/mysql-test/suite/innodb/t/innodb_buffer_pool_resize_with_chunks.test b/mysql-test/suite/innodb/t/innodb_buffer_pool_resize_with_chunks.test
new file mode 100644
index 00000000..78db6bf0
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb_buffer_pool_resize_with_chunks.test
@@ -0,0 +1,61 @@
+#
+# WL6117 : Resize the InnoDB Buffer Pool Online
+# (innodb_buffer_pool_chunk_size used case)
+#
+
+--source include/have_innodb.inc
+--source include/big_test.inc
+
+let $wait_timeout = 180;
+let $wait_condition =
+ SELECT SUBSTR(variable_value, 1, 30) = 'Completed resizing buffer pool'
+ FROM information_schema.global_status
+ WHERE LOWER(variable_name) = 'innodb_buffer_pool_resize_status';
+
+--disable_query_log
+set @old_innodb_buffer_pool_size = @@innodb_buffer_pool_size;
+--enable_query_log
+
+select @@innodb_buffer_pool_chunk_size;
+
+# fill buffer pool
+--disable_query_log
+SET @save_innodb_read_only_compressed=@@GLOBAL.innodb_read_only_compressed;
+SET GLOBAL innodb_read_only_compressed=OFF;
+--enable_query_log
+create table t1 (id int not null, val int not null default '0', primary key (id)) ENGINE=InnoDB ROW_FORMAT=COMPRESSED;
+create or replace view view0 as select 1 union all select 1;
+
+set @`v_id` := 0;
+set @`v_val` := 0;
+
+# 2^18 == 262144 records
+replace into t1 select (@`v_id` := (@`v_id` + 4) mod 4294967296) as id, (@`v_val` := (@`v_val` + 4) mod 4294967296) as val from view0 v0, view0 v1, view0 v2, view0 v3, view0 v4, view0 v5, view0 v6, view0 v7, view0 v8, view0 v9, view0 v10, view0 v11, view0 v12, view0 v13, view0 v14, view0 v15, view0 v16, view0 v17;
+--disable_query_log
+SET GLOBAL innodb_read_only_compressed=@save_innodb_read_only_compressed;
+--enable_query_log
+
+# Shrink buffer pool to 7MB
+set global innodb_buffer_pool_size = 7340032;
+--source include/wait_condition.inc
+
+select count(val) from t1;
+
+# Expand buffer pool to 16MB
+set global innodb_buffer_pool_size = 16777216;
+--source include/wait_condition.inc
+
+select count(val) from t1;
+
+drop table t1;
+drop view view0;
+
+# Try to shrink buffer pool to smaller than chunk size
+set global innodb_buffer_pool_size = 2*1048576;
+--source include/wait_condition.inc
+select @@innodb_buffer_pool_size;
+
+--disable_query_log
+set global innodb_buffer_pool_size = @old_innodb_buffer_pool_size;
+--enable_query_log
+--source include/wait_condition.inc
diff --git a/mysql-test/suite/innodb/t/innodb_bug11754376.test b/mysql-test/suite/innodb/t/innodb_bug11754376.test
new file mode 100644
index 00000000..64547d40
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb_bug11754376.test
@@ -0,0 +1,15 @@
+#
+# Bug#11754376 45976: INNODB LOST FILES FOR TEMPORARY TABLES ON GRACEFUL SHUTDOWN
+#
+
+-- source include/have_debug.inc
+-- source include/have_innodb.inc
+
+CREATE TABLE bug11754376 (c INT) ENGINE=INNODB;
+
+# This will invoke test_normalize_table_name_low() in debug builds
+SET @saved_dbug = @@SESSION.debug_dbug;
+SET SESSION DEBUG_DBUG='+d,test_normalize_table_name_low';
+
+DROP TABLE bug11754376;
+SET debug_dbug= @saved_dbug;
diff --git a/mysql-test/suite/innodb/t/innodb_bug12400341.test b/mysql-test/suite/innodb/t/innodb_bug12400341.test
new file mode 100644
index 00000000..13eadc70
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb_bug12400341.test
@@ -0,0 +1,102 @@
+# Test for bug #12400341: INNODB CAN LEAVE ORPHAN IBD FILES AROUND
+
+-- source include/have_debug.inc
+-- source include/have_innodb.inc
+-- source include/have_innodb_16k.inc
+
+# Don't test under valgrind, undo slots of the previous test might exist still
+# and cause unstable result.
+--source include/not_valgrind.inc
+# undo slots of the previous test might exist still
+--source include/not_windows.inc
+
+call mtr.add_suppression("\\[Warning\\] InnoDB: Cannot find a free slot for an undo log. Do you have too");
+
+--disable_query_log
+set @old_innodb_trx_rseg_n_slots_debug = @@innodb_trx_rseg_n_slots_debug;
+set global innodb_trx_rseg_n_slots_debug = 32;
+--enable_query_log
+
+--disable_warnings
+drop database if exists mysqltest;
+--enable_warnings
+
+create database mysqltest;
+CREATE TABLE mysqltest.transtable (id int unsigned NOT NULL PRIMARY KEY, val int DEFAULT 0) ENGINE=InnoDB;
+
+--disable_query_log
+#
+# Insert in 1 transaction which needs over 1 page undo record to avoid the insert_undo cached,
+# because the cached insert_undo can be reused at "CREATE TABLE" statement later.
+#
+START TRANSACTION;
+let $c = 1024;
+while ($c)
+{
+ eval INSERT INTO mysqltest.transtable (id) VALUES ($c);
+ dec $c;
+}
+COMMIT;
+
+let $c = 32;
+while ($c)
+{
+ # if failed at here, it might be shortage of file descriptors limit.
+ connect (con$c,localhost,root,,);
+ dec $c;
+}
+--enable_query_log
+
+select count(*) from information_schema.processlist where command != 'Daemon';
+
+#
+# fill the all undo slots
+#
+--disable_query_log
+let $c = 32;
+while ($c)
+{
+ connection con$c;
+ START TRANSACTION;
+ eval UPDATE mysqltest.transtable SET val = 1 WHERE id = 33 - $c;
+ dec $c;
+}
+--enable_query_log
+
+connection default;
+
+--error ER_CANT_CREATE_TABLE
+CREATE TABLE mysqltest.testtable (id int unsigned not null primary key) ENGINE=InnoDB;
+
+select count(*) from information_schema.processlist where command != 'Daemon';
+
+--disable_query_log
+let $c = 32;
+while ($c)
+{
+ connection con$c;
+ ROLLBACK;
+ dec $c;
+}
+--enable_query_log
+
+connection default;
+select count(*) from information_schema.processlist where command != 'Daemon';
+
+--disable_query_log
+let $c = 32;
+while ($c)
+{
+ disconnect con$c;
+ dec $c;
+}
+--enable_query_log
+
+#
+# If the isolated .ibd file remained, the drop database should fail.
+#
+drop database mysqltest;
+
+--disable_query_log
+set global innodb_trx_rseg_n_slots_debug = @old_innodb_trx_rseg_n_slots_debug;
+--enable_query_log
diff --git a/mysql-test/suite/innodb/t/innodb_bug12661768.test b/mysql-test/suite/innodb/t/innodb_bug12661768.test
new file mode 100644
index 00000000..b1ba1b44
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb_bug12661768.test
@@ -0,0 +1,50 @@
+#
+# Bug#12661768 UPDATE IGNORE CRASHES SERVER IF TABLE IS INNODB AND IT IS
+# PARENT FOR OTHER ONE
+#
+
+-- source include/have_innodb.inc
+
+SET SESSION foreign_key_checks=0;
+
+# only interested that the "UPDATE IGNORE" at the end does not crash the server
+
+-- disable_query_log
+-- disable_result_log
+
+SET NAMES utf8;
+
+-- let $t1_name = bug12661768_1
+-- let $t2_name = bug12661768_2
+-- let $fk_name = ab_on_2
+-- let $key_str = 'bbb'
+
+eval DROP TABLE IF EXISTS `$t2_name`, `$t1_name`;
+
+eval CREATE TABLE `$t1_name` (
+ a INT,
+ b VARCHAR(512),
+ PRIMARY KEY (a, b)
+) ENGINE=INNODB;
+
+eval CREATE TABLE `$t2_name` (
+ id INT,
+ a INT,
+ b VARCHAR(512),
+ PRIMARY KEY (id),
+ UNIQUE KEY `$fk_name` (a, b),
+ FOREIGN KEY (a, b) REFERENCES `$t1_name` (a, b)
+ ON DELETE CASCADE ON UPDATE CASCADE
+) ENGINE=INNODB;
+
+eval INSERT INTO `$t1_name` VALUES (1, $key_str);
+eval INSERT INTO `$t2_name` VALUES (100, 1, $key_str), (101, 3, $key_str);
+
+SET SESSION foreign_key_checks=1;
+
+-- enable_result_log
+
+-- error ER_FOREIGN_DUPLICATE_KEY_WITH_CHILD_INFO
+eval UPDATE IGNORE `$t1_name` SET a = 3;
+
+eval DROP TABLE `$t2_name`, `$t1_name`;
diff --git a/mysql-test/suite/innodb/t/innodb_bug12902967.test b/mysql-test/suite/innodb/t/innodb_bug12902967.test
new file mode 100644
index 00000000..5bd32cdf
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb_bug12902967.test
@@ -0,0 +1,25 @@
+# Bug 12902967: Creating self referencing fk on same index unhandled,
+# confusing error
+#
+# Creating a self referencing foreign key on the same
+# column/index is an unhandled exception, it should throw a sensible
+# error but instead implies that your data dictionary may now be out
+# of sync:
+
+--source include/have_innodb.inc
+--source include/not_embedded.inc
+
+call mtr.add_suppression("In ALTER TABLE .* has or is referenced in foreign key constraints which are not compatible with the new table definition.");
+
+let error_log= $MYSQLTEST_VARDIR/log/mysqld.1.err;
+--source include/restart_mysqld.inc
+
+create table t1 (f1 integer primary key) engine innodb;
+
+# The below statement should produce error message in error log.
+# This error message should mention problem with foreign keys
+# rather than with data dictionary.
+--replace_regex /'\.\/test\/#sql-alter-[0-9a-f_\-]*'/'#sql-alter'/
+--error ER_ERROR_ON_RENAME
+alter table t1 add constraint c1 foreign key (f1) references t1(f1);
+drop table t1;
diff --git a/mysql-test/suite/innodb/t/innodb_bug13510739.test b/mysql-test/suite/innodb/t/innodb_bug13510739.test
new file mode 100644
index 00000000..f10bcd8e
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb_bug13510739.test
@@ -0,0 +1,20 @@
+#
+# Bug#13510739 63775: SERVER CRASH ON HANDLER READ NEXT AFTER DELETE RECORD.
+#
+
+-- source include/have_innodb.inc
+
+CREATE TABLE bug13510739 (c INTEGER NOT NULL, PRIMARY KEY (c)) ENGINE=INNODB;
+
+INSERT INTO bug13510739 VALUES (1), (2), (3), (4);
+
+DELETE FROM bug13510739 WHERE c=2;
+
+HANDLER bug13510739 OPEN;
+
+HANDLER bug13510739 READ `primary` = (2);
+
+# this one crashes the server if the bug is present
+HANDLER bug13510739 READ `primary` NEXT;
+
+DROP TABLE bug13510739;
diff --git a/mysql-test/suite/innodb/t/innodb_bug14007649.test b/mysql-test/suite/innodb/t/innodb_bug14007649.test
new file mode 100644
index 00000000..9b332b9b
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb_bug14007649.test
@@ -0,0 +1,62 @@
+--source include/have_innodb.inc
+--source include/have_debug.inc
+
+create table t1 (
+ rowid int,
+ f1 int,
+ f2 int,
+ key i1 (f1, f2),
+ key i2 (f2)) engine=innodb;
+
+show create table t1;
+insert into `t1` (rowid, f1, f2) values (1, 1, 10), (2, 1, NULL);
+
+connect (a,localhost,root,,);
+connect (b,localhost,root,,);
+
+connection a;
+start transaction with consistent snapshot;
+
+connection b;
+start transaction;
+update t1 set f2 = 4 where f1 = 1 and f2 is null;
+
+-- echo (b) Number of rows updated:
+--disable_ps2_protocol
+select row_count();
+--enable_ps2_protocol
+
+insert into t1 values (3, 1, null);
+
+-- echo (b) After update and insert query.
+select rowid, f1, f2 from t1;
+
+commit;
+
+connection a;
+
+-- echo (a) Before the update statement is executed.
+select rowid, f1, f2 from t1;
+
+SET SESSION debug_dbug="+d,bug14007649";
+update t1 set f2 = 6 where f1 = 1 and f2 is null;
+
+-- echo (a) Number of rows updated:
+--disable_ps2_protocol
+select row_count();
+--enable_ps2_protocol
+
+-- echo (a) After the update statement is executed.
+select rowid, f1, f2 from t1;
+
+commit;
+
+--echo "The trx with consistent snapshot ended."
+
+select rowid, f1, f2 from t1;
+
+connection default;
+disconnect a;
+disconnect b;
+
+drop table t1;
diff --git a/mysql-test/suite/innodb/t/innodb_bug14147491-master.opt b/mysql-test/suite/innodb/t/innodb_bug14147491-master.opt
new file mode 100644
index 00000000..614dd935
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb_bug14147491-master.opt
@@ -0,0 +1,4 @@
+--innodb_file_per_table=1
+--loose-skip-stack-trace
+--skip-core-file
+--loose-innodb_buffer_pool_load_at_startup=OFF
diff --git a/mysql-test/suite/innodb/t/innodb_bug14147491.test b/mysql-test/suite/innodb/t/innodb_bug14147491.test
new file mode 100644
index 00000000..10f3c98b
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb_bug14147491.test
@@ -0,0 +1,83 @@
+#
+# Test opening a corrupted table.
+#
+# Restarting is not supported under embedded
+-- source include/not_embedded.inc
+# Require InnoDB
+-- source include/have_innodb.inc
+-- source include/not_encrypted.inc
+
+--disable_query_log
+call mtr.add_suppression("InnoDB: Table `test`\\.`t1` is corrupted\\. Please drop the table and recreate\\.");
+call mtr.add_suppression("InnoDB: Database page corruption on disk or a failed read of file '.*test.t1\\.ibd' page");
+call mtr.add_suppression("InnoDB: We detected index corruption in an InnoDB type table");
+call mtr.add_suppression("Index for table 't1' is corrupt; try to repair it");
+call mtr.add_suppression("InnoDB: File '.*test/t1\\.ibd' is corrupted");
+--enable_query_log
+
+--echo # Ensure that purge will not crash on the table after we corrupt it.
+SET GLOBAL innodb_fast_shutdown=0;
+
+--echo # Create and populate the table to be corrupted
+
+set global innodb_file_per_table=ON;
+
+CREATE TABLE t1 (a INT AUTO_INCREMENT PRIMARY KEY, b TEXT) ENGINE=InnoDB;
+INSERT INTO t1 (b) VALUES ('corrupt me');
+--disable_query_log
+--let $i = 10
+while ($i)
+{
+ INSERT INTO t1 (b) VALUES (REPEAT('abcdefghijklmnopqrstuvwxyz', 100));
+ dec $i;
+}
+--enable_query_log
+INSERT INTO t1 (b) VALUES ('corrupt me');
+
+let $MYSQLD_DATADIR=`select @@datadir`;
+let t1_IBD = $MYSQLD_DATADIR/test/t1.ibd;
+
+--source include/shutdown_mysqld.inc
+
+--echo # Corrupt the table
+
+perl;
+use strict;
+use warnings;
+use Fcntl qw(:DEFAULT :seek);
+
+my $ibd_file = $ENV{'t1_IBD'};
+
+my $chunk;
+my $len;
+
+sysopen IBD_FILE, $ibd_file, O_RDWR || die "Unable to open $ibd_file";
+
+while ($len = sysread IBD_FILE, $chunk, 1024)
+{
+ if ($chunk =~ s/corrupt me/korrupt me/)
+ {
+ print "Munged a string.\n";
+ sysseek IBD_FILE, -$len, SEEK_CUR;
+ syswrite IBD_FILE, $chunk, $len;
+ }
+}
+
+close IBD_FILE;
+EOF
+
+--source include/start_mysqld.inc
+
+--echo # Now t1 is corrupted but we should not crash
+
+--error ER_GET_ERRNO,ER_NOT_KEYFILE,ER_INDEX_CORRUPT,ER_NO_SUCH_TABLE_IN_ENGINE
+SELECT * FROM t1;
+
+--error 126,ER_GET_ERRNO,ER_NOT_KEYFILE,ER_INDEX_CORRUPT,ER_NO_SUCH_TABLE_IN_ENGINE
+INSERT INTO t1(b) VALUES('abcdef');
+
+--error ER_GET_ERRNO,ER_NOT_KEYFILE,ER_INDEX_CORRUPT,ER_NO_SUCH_TABLE_IN_ENGINE
+UPDATE t1 set b = 'deadbeef' where a = 1;
+
+--echo # Cleanup, this must be possible
+DROP TABLE t1;
diff --git a/mysql-test/suite/innodb/t/innodb_bug14676111.opt b/mysql-test/suite/innodb/t/innodb_bug14676111.opt
new file mode 100644
index 00000000..77945d1e
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb_bug14676111.opt
@@ -0,0 +1 @@
+--innodb-sys-tablestats=1 \ No newline at end of file
diff --git a/mysql-test/suite/innodb/t/innodb_bug14676111.test b/mysql-test/suite/innodb/t/innodb_bug14676111.test
new file mode 100644
index 00000000..3abc574a
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb_bug14676111.test
@@ -0,0 +1,130 @@
+# Test for bug #14676111: WRONG PAGE_LEVEL WRITTEN FOR UPPER THAN FATHER PAGE AT BTR_LIFT_PAGE_UP()
+
+-- source include/have_innodb.inc
+-- source include/have_debug.inc
+-- source include/count_sessions.inc
+
+set @old_innodb_limit_optimistic_insert_debug = @@innodb_limit_optimistic_insert_debug;
+
+CREATE TABLE t1 (a INT PRIMARY KEY) ENGINE=InnoDB STATS_PERSISTENT=0;
+
+#
+# make 4 leveled straight tree
+#
+set global innodb_limit_optimistic_insert_debug = 2;
+insert into t1 values (1);
+--connect (con5,localhost,root)
+begin;
+insert into t1 values (5);
+#current tree form
+# (1, 5)
+
+--connect (con4,localhost,root)
+begin;
+insert into t1 values (4);
+#records in a page is limited to 2 artificially. root rise occurs
+#current tree form
+# (1, 5)
+#(1, 4) (5)
+
+--connection default
+insert into t1 values (3);
+#current tree form
+# (1, 5)
+# (1, 4) (5)
+#(1, 3) (4) (5)
+
+--connect (con2,localhost,root)
+begin;
+insert into t1 values (2);
+#current tree form
+# (1, 5)
+# (1, 4) (5)
+# (1, 3) (4) (5)
+#(1, 2) (3) (4) (5)
+
+--connection default
+analyze table t1;
+select CLUST_INDEX_SIZE from information_schema.INNODB_SYS_TABLESTATS where NAME = 'test/t1';
+
+--connection con4
+rollback;
+--disconnect con4
+--connection default
+
+#deleting 1 record of 2 records don't cause merge artificially.
+#current tree form
+# (1, 5)
+# (1) (5)
+# (1, 3) (5)
+#(1, 2) (3) (5)
+
+analyze table t1;
+select CLUST_INDEX_SIZE from information_schema.INNODB_SYS_TABLESTATS where NAME = 'test/t1';
+
+--connection con5
+rollback;
+--disconnect con5
+--connection default
+
+#deleting 1 record of 2 records don't cause merge artificially.
+#current tree form
+# (1)
+# (1)
+# (1, 3) <- lift up this level next, when deleting node ptr
+#(1, 2) (3) <- merged next
+
+analyze table t1;
+select CLUST_INDEX_SIZE from information_schema.INNODB_SYS_TABLESTATS where NAME = 'test/t1';
+
+#
+# cause merge at level 0
+#
+
+#disable the artificial limitation of records in a page
+set global innodb_limit_optimistic_insert_debug = 10000;
+--connection con2
+rollback;
+--disconnect con2
+--connection default
+
+#merge page occurs. and lift up occurs.
+#current tree form
+# (1)
+# (1)
+# (1, 3)
+
+analyze table t1;
+select CLUST_INDEX_SIZE from information_schema.INNODB_SYS_TABLESTATS where NAME = 'test/t1';
+
+begin;
+insert into t1 values (2);
+#current tree form
+# (1)
+# (1) <- lift up this level next, because it is not root
+# (1, 2, 3)
+rollback;
+
+#current tree form
+# (1)
+# (1, 3)
+
+analyze table t1;
+select CLUST_INDEX_SIZE from information_schema.INNODB_SYS_TABLESTATS where NAME = 'test/t1';
+
+begin;
+insert into t1 values (2);
+#current tree form
+# (1)
+# (1, 2, 3) <- lift up this level next, because the father is root
+rollback;
+#current tree form
+# (1, 3)
+
+analyze table t1;
+select CLUST_INDEX_SIZE from information_schema.INNODB_SYS_TABLESTATS where NAME = 'test/t1';
+
+drop table t1;
+
+set global innodb_limit_optimistic_insert_debug = @old_innodb_limit_optimistic_insert_debug;
+-- source include/wait_until_count_sessions.inc
diff --git a/mysql-test/suite/innodb/t/innodb_bug21704.test b/mysql-test/suite/innodb/t/innodb_bug21704.test
new file mode 100644
index 00000000..82e7c81d
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb_bug21704.test
@@ -0,0 +1,76 @@
+-- source include/have_innodb.inc
+
+--echo #
+--echo # Bug#21704: Renaming column does not update FK definition.
+--echo #
+
+--echo
+--echo # Test that it's not possible to rename columns participating in a
+--echo # foreign key (either in the referencing or referenced table).
+--echo
+
+CREATE TABLE t1 (a INT PRIMARY KEY, b INT) ROW_FORMAT=COMPACT ENGINE=INNODB;
+
+CREATE TABLE t2 (a INT PRIMARY KEY, b INT,
+ CONSTRAINT fk1 FOREIGN KEY (a) REFERENCES t1(a))
+ROW_FORMAT=COMPACT ENGINE=INNODB;
+
+CREATE TABLE t3 (a INT PRIMARY KEY, b INT, KEY(b), C INT,
+ CONSTRAINT fk2 FOREIGN KEY (b) REFERENCES t3 (a))
+ROW_FORMAT=COMPACT ENGINE=INNODB;
+
+INSERT INTO t1 VALUES (1,1),(2,2),(3,3);
+INSERT INTO t2 VALUES (1,1),(2,2),(3,3);
+INSERT INTO t3 VALUES (1,1,1),(2,2,2),(3,3,3);
+
+--echo
+--echo # Test renaming the column in the referenced table.
+--echo
+
+--enable_info
+ALTER TABLE t1 CHANGE a e INT;
+
+--echo # Ensure that online column rename works.
+
+ALTER TABLE t1 CHANGE b c INT;
+
+--echo
+--echo # Test renaming the column in the referencing table
+--echo
+
+ALTER TABLE t2 CHANGE a z INT;
+
+--echo # Ensure that online column rename works.
+
+ALTER TABLE t2 CHANGE b c INT;
+
+--echo
+--echo # Test with self-referential constraints
+--echo
+
+ALTER TABLE t3 CHANGE a f INT;
+
+ALTER TABLE t3 CHANGE b g INT;
+
+--echo # Ensure that online column rename works.
+
+ALTER TABLE t3 CHANGE c d INT;
+
+--echo
+--echo # Cleanup.
+--echo
+
+--disable_info
+SHOW CREATE TABLE t1;
+SHOW CREATE TABLE t2;
+SHOW CREATE TABLE t3;
+
+SELECT f.*, c.*
+FROM INFORMATION_SCHEMA.INNODB_SYS_FOREIGN_COLS c
+INNER JOIN INFORMATION_SCHEMA.INNODB_SYS_FOREIGN f
+ON c.ID=f.ID
+WHERE FOR_NAME LIKE 'test/t%';
+
+DROP TABLE t3;
+DROP TABLE t2;
+DROP TABLE t1;
diff --git a/mysql-test/suite/innodb/t/innodb_bug30113362.opt b/mysql-test/suite/innodb/t/innodb_bug30113362.opt
new file mode 100644
index 00000000..99bf0e5a
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb_bug30113362.opt
@@ -0,0 +1 @@
+--innodb-sys-tablestats
diff --git a/mysql-test/suite/innodb/t/innodb_bug30113362.test b/mysql-test/suite/innodb/t/innodb_bug30113362.test
new file mode 100644
index 00000000..789f1a49
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb_bug30113362.test
@@ -0,0 +1,244 @@
+#
+# Test for Bug#30113362 : BTR_CUR_WILL_MODIFY_TREE() IS INSUFFICIENT FOR HIGHER TREE LEVEL
+#
+
+--source include/have_innodb.inc
+--source include/have_debug.inc
+--source include/have_debug_sync.inc
+--source include/have_innodb_16k.inc
+# debug sync points times out when using valgrind
+--source include/not_valgrind.inc
+
+--disable_query_log
+SET @old_innodb_limit_optimistic_insert_debug = @@innodb_limit_optimistic_insert_debug;
+SET @old_innodb_adaptive_hash_index = @@innodb_adaptive_hash_index;
+SET @old_innodb_stats_persistent = @@innodb_stats_persistent;
+--enable_query_log
+
+# Save the initial number of concurrent sessions
+--source include/count_sessions.inc
+
+SET GLOBAL innodb_adaptive_hash_index = false;
+SET GLOBAL innodb_stats_persistent = false;
+
+connect (purge_control,localhost,root,,);
+START TRANSACTION WITH CONSISTENT SNAPSHOT;
+
+--connect (con2,localhost,root,,)
+
+CREATE TABLE t1 (
+ a00 CHAR(255) NOT NULL DEFAULT 'a',
+ a01 CHAR(255) NOT NULL DEFAULT 'a',
+ a02 CHAR(255) NOT NULL DEFAULT 'a',
+ b INT NOT NULL DEFAULT 0,
+ PRIMARY KEY(a00, a01, a02)
+) charset latin1 ENGINE = InnoDB COMMENT='MERGE_THRESHOLD=45';
+
+#
+# Prepare primary key index tree to be used for this test.
+#
+
+SET GLOBAL innodb_limit_optimistic_insert_debug = 3;
+
+delimiter |;
+CREATE PROCEDURE data_load_t1()
+BEGIN
+ DECLARE c1 INT DEFAULT 97;
+ DECLARE c2 INT DEFAULT 97;
+ DECLARE c3 INT DEFAULT 97;
+
+ WHILE c1 < 102 DO
+ WHILE c2 < 123 DO
+ WHILE c3 < 123 DO
+ INSERT INTO t1 (a00) VALUES (CHAR(c1,c2,c3));
+ SET c3 = c3 + 1;
+ END WHILE;
+ SET c3 = 97;
+ SET c2 = c2 + 1;
+ END WHILE;
+ SET c2 = 97;
+ SET c1 = c1 + 1;
+ END WHILE;
+END |
+delimiter ;|
+call data_load_t1();
+DROP PROCEDURE data_load_t1;
+
+# all node pages are sparse (max 3 node_ptrs)
+ANALYZE TABLE t1;
+SELECT CLUST_INDEX_SIZE FROM information_schema.INNODB_SYS_TABLESTATS WHERE NAME = 'test/t1';
+
+connection con2;
+DELETE FROM t1 WHERE a00 = 'cnm';
+COMMIT;
+BEGIN;
+INSERT INTO t1 SET a00 = 'cnm';
+# causes "domino falling" merges to upper level
+connection purge_control;
+COMMIT;
+connection con2;
+SET GLOBAL innodb_limit_optimistic_insert_debug = 0;
+ROLLBACK;
+
+# at this moment, in the tree,
+# ...
+# level 4: ...(ast,avw,ayz)(bcc,bff,bii,bll,boo,brr,buu,bxx,cba,ced,cqp,cts)(cwv,czy,ddb)...
+# ...
+
+--echo # Test start
+
+# (1) Similar case to the first reported corefile at bug#30113362
+# - Deleting 'bii' causes "domino falling" merges and the node_ptr becomes left_most of level 4.
+# So, the operation needs upper level pages' X-latch, though doesn't cause merge more.
+
+connection purge_control;
+START TRANSACTION WITH CONSISTENT SNAPSHOT;
+connection con2;
+DELETE FROM t1 WHERE a00 = 'bii';
+COMMIT;
+BEGIN;
+INSERT INTO t1 SET a00 = 'bii';
+SET DEBUG_SYNC = 'rollback_undo_pk SIGNAL roll1_wait WAIT_FOR roll2';
+SET DEBUG_SYNC = 'rollback_purge_clust SIGNAL rollback_waiting WAIT_FOR resume';
+send ROLLBACK;
+
+connection purge_control;
+SET DEBUG_SYNC = 'now WAIT_FOR roll1_wait';
+COMMIT;
+SET DEBUG_SYNC = 'now SIGNAL roll2';
+
+connect (con1,localhost,root,,);
+# FIXME: This occasionally times out!
+--disable_warnings
+SET DEBUG_SYNC = 'now WAIT_FOR rollback_waiting TIMEOUT 1';
+--enable_warnings
+SET DEBUG_SYNC = 'rw_s_lock_waiting SIGNAL lockwait1';
+send SELECT a00 FROM t1 WHERE a00 = 'bii';
+
+connection default;
+# FIXME: This occasionally times out!
+--disable_warnings
+SET DEBUG_SYNC = 'now WAIT_FOR lockwait1 TIMEOUT 1';
+--enable_warnings
+# bug#30113362 caused deadlock
+SET DEBUG_SYNC = 'now SIGNAL resume';
+
+connection con1;
+reap;
+connection con2;
+reap;
+connection default;
+
+ANALYZE TABLE t1;
+SELECT CLUST_INDEX_SIZE FROM information_schema.INNODB_SYS_TABLESTATS WHERE NAME = 'test/t1';
+
+# (2) Confirm blocking domain caused by DELETE modify_tree for tall index tree
+
+# at this moment, in the tree,
+# ...
+# level 4: ...(ajk,amn,apq)(ast,avw,ayz,bll,boo,brr,buu,bxx,cba,ced,cqp,cts)(cwv,czy,ddb)(dge,djh,dmk)(dpn,dsq,dvt)(dyw,ebz,efc)...
+# ...
+
+# makes >17 records in level4 [(2^(4-1))*2 + 1]. (causes never left_most records)
+DELETE FROM t1 WHERE a00 = 'dpn';
+COMMIT;
+INSERT INTO t1 SET a00 = 'dpn';
+ROLLBACK;
+
+# at this moment, in the tree,
+# (* before "]" and after "[" records are treated as left_most possible records)
+# ...
+# level 4: ...(ajk,amn,apq)(ast,avw,ayz,bll,boo,brr,buu,bxx],cba,ced,[cqp,cts,cwv,czy,ddb,dge,dsq,dvt)(dyw,ebz,efc)...
+# level 3: ...(cba,ccb,cdc)(ced,cfe,cgf,chg],cih,cji,[ckj,clk,con,cpo)(cqp,crq,csr)...
+# level 2: ...(ckj,cks,clb)(clk,clt],cmc,cml,cmu,cnd,[cnv,coe)(con,cow,cpf)...
+# level 1: ...(cmu,cmx,cna)(cnd],cng,cnj,cnp,[cns)(cnv,cny,cob)...
+# level 0: ...(cnd,cne,cnf)(cng,cnh,cni)(cnj,cnk,cnl,cnn,cno)(cnp,cnq,cnr)...
+
+# deletes just 'ced' node_ptr only from level 4. doesn't cause merge and never left_most.
+# adjusts MERGE_THRESHOLD to do so.
+ALTER TABLE t1 COMMENT='MERGE_THRESHOLD=35';
+
+connection purge_control;
+START TRANSACTION WITH CONSISTENT SNAPSHOT;
+
+connection con2;
+DELETE FROM t1 WHERE a00 = 'cnd';
+COMMIT;
+BEGIN;
+INSERT INTO t1 SET a00 = 'cnd';
+SET DEBUG_SYNC = 'rollback_undo_pk SIGNAL roll1_wait WAIT_FOR roll2';
+SET DEBUG_SYNC = 'rollback_purge_clust SIGNAL rollback_waiting WAIT_FOR resume EXECUTE 2';
+send ROLLBACK;
+
+connection purge_control;
+SET DEBUG_SYNC = 'now WAIT_FOR roll1_wait';
+START TRANSACTION WITH CONSISTENT SNAPSHOT;
+SET DEBUG_SYNC = 'now SIGNAL roll2';
+
+connection con1;
+# FIXME: For some reason, we will not always receive these signals!
+--disable_warnings
+# An optimistic row_undo_mod_remove_clust_low() will fail.
+SET DEBUG_SYNC = 'now WAIT_FOR rollback_waiting TIMEOUT 1';
+SET DEBUG_SYNC = 'now SIGNAL resume';
+# Wait for the pessimistic row_undo_mod_remove_clust_low() attempt.
+SET DEBUG_SYNC = 'now WAIT_FOR rollback_waiting TIMEOUT 1';
+--enable_warnings
+disconnect purge_control;
+
+# The expectation should be...
+# level 0: (#cnd#,cne,cnf): causes merge
+# level 1: (#cnd#],cng,cnj,cnp,[cns): left_most
+# level 2: (clk,clt],cmc,cml,cmu,#cnd#,[cnv,coe): causes merge
+# level 3: (ced,cfe,cgf,chg],cih,cji,[ckj,#clk#,con,cpo): left_most possible (not cause merge)
+# level 4: (ast,avw,ayz,bll,boo,brr,buu,bxx],cba,#ced#,[cqp,cts,cwv,czy,ddb,dge,dsq,dvt): no merge, not left_most possible
+# So, the top X-latch page is at level4. (ast~dvt)
+
+# blocking domain based on whether its ancestor is latched or not.
+# (*[]: ancestor is X-latched)
+# level 0: ...(asq,asr,ass) [(ast,asu,asv)...(dyt,dyu,dyv)] (dyw,dyx,dyy)...
+
+# Not blocked searches
+## In MariaDB, both these will block, because we use different DEBUG_SYNC
+## instrumentation (in rollback, not purge) and the root page (number 3)
+## is being latched in row_undo_mod_remove_clust_low().
+## SELECT a00 FROM t1 WHERE a00 = 'ass';
+## SELECT a00 FROM t1 WHERE a00 = 'dyx';
+
+## SET DEBUG_SYNC = 'rw_s_lock_waiting SIGNAL lockwait1';
+## send SELECT a00 FROM t1 WHERE a00 = 'ast';
+
+## connection con2;
+## SET DEBUG_SYNC = 'rw_s_lock_waiting SIGNAL lockwait2';
+## send SELECT a00 FROM t1 WHERE a00 = 'dyw';
+
+connection default;
+## SET DEBUG_SYNC = 'now WAIT_FOR lockwait1';
+## SET DEBUG_SYNC = 'now WAIT_FOR lockwait2';
+SET DEBUG_SYNC = 'now SIGNAL resume';
+
+## connection con1;
+## reap;
+disconnect con1;
+
+connection con2;
+reap;
+disconnect con2;
+
+connection default;
+ANALYZE TABLE t1;
+SELECT CLUST_INDEX_SIZE FROM information_schema.INNODB_SYS_TABLESTATS WHERE NAME = 'test/t1';
+
+
+# Cleanup
+SET DEBUG_SYNC = 'RESET';
+
+DROP TABLE t1;
+
+--disable_query_log
+SET GLOBAL innodb_limit_optimistic_insert_debug = @old_innodb_limit_optimistic_insert_debug;
+SET GLOBAL innodb_adaptive_hash_index = @old_innodb_adaptive_hash_index;
+SET GLOBAL innodb_stats_persistent = @old_innodb_stats_persistent;
+--enable_query_log
+
+--source include/wait_until_count_sessions.inc
diff --git a/mysql-test/suite/innodb/t/innodb_bug30423.test b/mysql-test/suite/innodb/t/innodb_bug30423.test
new file mode 100644
index 00000000..9d9975c0
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb_bug30423.test
@@ -0,0 +1,213 @@
+--source include/have_innodb.inc
+--source include/no_valgrind_without_big.inc
+# Test for Bug #30423, InnoDBs treatment of NULL in index stats causes
+# bad "rows examined" estimates.
+# Implemented InnoDB system variable "innodb_stats_method" with
+# "nulls_equal" (default), "nulls_unequal", and "nulls_ignored" options.
+
+let $innodb_stats_method_orig = `select @@innodb_stats_method`;
+
+# default setting for innodb_stats_method is "nulls_equal"
+set global innodb_stats_method = default;
+
+select @@innodb_stats_method;
+
+# create three tables, bug30243_1, bug30243_2 and bug30243_3.
+# The test scenario is adopted from original bug #30423 report.
+# table bug30243_1 and bug30243_3 have many NULL values
+
+-- disable_result_log
+-- disable_query_log
+
+DROP TABLE IF EXISTS bug30243_1;
+CREATE TABLE bug30243_1 (
+ org_id int(11) NOT NULL default '0',
+ UNIQUE KEY (org_id)
+) ENGINE=InnoDB DEFAULT CHARSET=latin1;
+
+LOCK TABLES bug30243_1 WRITE;
+INSERT INTO bug30243_1 VALUES (11),(15),(16),(17),(19),(20),(21),(23),(24),
+(25),(26),(27),(28),(29),(30),(31),(32),(33),(34),(35),(37),(38),(40),(41),
+(42),(43),(44),(45),(46),(47),(48),(49),(50),(51),(52),(53),(54),(55),(56),
+(57),(58),(59),(60),(61),(62),(63),(64),(65),(66),(67),(68),(69),(70),(71),
+(72),(73),(74),(75),(76),(77),(78),(79),(80),(81),(82),(83),(84),(85),(86),
+(87),(88),(89),(90),(91),(92),(93),(94),(95),(96),(97),(98),(99),(100),(101),
+(102),(103),(104),(105),(106),(107),(108),(109),(110),(111),(112),(113),(114),
+(115),(116),(117),(118),(119),(120),(121),(122),(123),(124),(125),(126),(127),
+(128),(129),(130),(131),(132),(133),(134),(135),(136),(137),(138),(139),(140),
+(141),(142),(143),(144),(145);
+UNLOCK TABLES;
+
+DROP TABLE IF EXISTS bug30243_3;
+CREATE TABLE bug30243_3 (
+ org_id int(11) default NULL,
+ KEY (org_id)
+) ENGINE=InnoDB DEFAULT CHARSET=latin1;
+
+INSERT INTO bug30243_3 VALUES (NULL);
+
+begin;
+let $i=14;
+while ($i)
+{
+ INSERT INTO bug30243_3 SELECT NULL FROM bug30243_3;
+ dec $i;
+}
+
+INSERT INTO bug30243_3 VALUES (34),(34),(35),(56),(58),(62),(62),(64),(65),(66),(80),(135),(137),(138),(139),(140),(142),(143),(144),(145);
+commit;
+
+DROP TABLE IF EXISTS bug30243_2;
+CREATE TABLE bug30243_2 (
+ org_id int(11) default NULL,
+ KEY `contacts$org_id` (org_id)
+) ENGINE=InnoDB DEFAULT CHARSET=latin1;
+
+INSERT INTO bug30243_2 VALUES (NULL);
+
+begin;
+let $i=16;
+while ($i)
+{
+ INSERT INTO bug30243_2 SELECT NULL FROM bug30243_2;
+ dec $i;
+}
+
+INSERT INTO bug30243_2 VALUES (11),(15),(16),(17),(20),(21),(23),(24),(25),
+(26),(27),(28),(29),(30),(31),(32),(33),(34),(37),(38),(40),(41),(42),(43),
+(44),(45),(46),(46),(46),(46),(46),(46),(46),(46),(46),(46),(46),(46),(46),
+(46),(46),(46),(46),(46),(46),(46),(46),(46),(46),(46),(46),(46),(46),(46),
+(46),(46),(46),(46),(46),(46),(46),(46),(46),(46),(46),(46),(46),(46),(46),
+(46),(46),(46),(46),(46),(46),(46),(46),(46),(46),(46),(46),(46),(46),(46),
+(46),(46),(46),(46),(46),(46),(46),(46),(46),(46),(46),(46),(46),(46),(46),
+(46),(46),(46),(46),(46),(46),(46),(46),(46),(46),(46),(46),(46),(46),(48),
+(48),(50),(51),(52),(52),(53),(54),(55),(57),(60),(61),(62),(62),(62),(62),
+(62),(63),(64),(64),(65),(66),(66),(67),(68),(69),(70),(71),(72),(73),(74),
+(75),(76),(77),(78),(79),(80),(80),(81),(82),(83),(84),(85),(86),(87),(88),
+(89),(90),(91),(92),(93),(94),(95),(96),(97),(98),(99),(100),(101),(102),
+(103),(104),(105),(106),(107),(108),(109),(110),(111),(112),(113),(114),
+(115),(116),(117),(118),(119),(120),(121),(122),(123),(124),(125),(126),
+(127),(128),(129),(130),(131),(132),(133),(133),(135),(135),(135),(135),
+(136),(136),(138),(138),(139),(139),(139),(140),(141),(141),(142),(143),
+(143),(145),(145);
+commit;
+
+
+-- enable_result_log
+-- enable_query_log
+
+# check tables's value
+select count(*) from bug30243_3 where org_id is not NULL;
+select count(*) from bug30243_3 where org_id is NULL;
+
+select count(*) from bug30243_2 where org_id is not NULL;
+select count(*) from bug30243_2 where org_id is NULL;
+
+select @@innodb_stats_method;
+
+analyze table bug30243_1;
+analyze table bug30243_2;
+analyze table bug30243_3;
+
+# Following query plan shows that we over estimate the rows per
+# unique value (since there are many NULLs).
+# Skip this query log since the stats estimate could vary from runs
+-- disable_query_log
+-- disable_result_log
+explain SELECT COUNT(*), 0
+ FROM bug30243_1 orgs
+ LEFT JOIN bug30243_3 sa_opportunities
+ ON orgs.org_id=sa_opportunities.org_id
+ LEFT JOIN bug30243_2 contacts
+ ON orgs.org_id=contacts.org_id ;
+-- enable_query_log
+-- enable_result_log
+
+# following set operation will fail
+#--error ER_WRONG_VALUE_FOR_VAR
+--error 1231
+set global innodb_stats_method = "NULL";
+
+set global innodb_stats_method = "nulls_ignored";
+
+select @@innodb_stats_method;
+
+# Regenerate the stats with "nulls_ignored" option
+
+analyze table bug30243_1;
+analyze table bug30243_2;
+analyze table bug30243_3;
+
+# Following query plan shows that we get the correct rows per
+# unique value (should be approximately 1 row per value)
+-- replace_column 9 ROWS
+explain SELECT COUNT(*), 0
+ FROM bug30243_1 orgs
+ LEFT JOIN bug30243_3 sa_opportunities
+ ON orgs.org_id=sa_opportunities.org_id
+ LEFT JOIN bug30243_2 contacts
+ ON orgs.org_id=contacts.org_id ;
+
+select @@innodb_stats_method;
+
+# Try the "nulls_unequal" option
+set global innodb_stats_method = "nulls_unequal";
+
+select @@innodb_stats_method;
+
+analyze table bug30243_1;
+analyze table bug30243_2;
+analyze table bug30243_3;
+
+# Following query plan shows that we get the correct rows per
+# unique value (~1)
+-- replace_column 9 ROWS
+explain SELECT COUNT(*), 0
+ FROM bug30243_1 orgs
+ LEFT JOIN bug30243_3 sa_opportunities
+ ON orgs.org_id=sa_opportunities.org_id
+ LEFT JOIN bug30243_2 contacts
+ ON orgs.org_id=contacts.org_id;
+
+
+# Create a table with all NULL values, make sure the stats calculation
+# does not crash with table of all NULL values
+-- disable_query_log
+CREATE TABLE table_bug30423 (
+ org_id int(11) default NULL,
+ KEY(org_id)
+) ENGINE=InnoDB DEFAULT CHARSET=latin1;
+
+INSERT INTO `table_bug30423` VALUES (NULL);
+
+begin;
+let $i=10;
+while ($i)
+{
+ INSERT INTO table_bug30423 SELECT NULL FROM table_bug30423;
+ dec $i;
+}
+commit;
+
+-- enable_query_log
+
+SELECT COUNT(*) FROM table_bug30423 WHERE org_id IS NULL;
+
+# calculate the statistics for the table for "nulls_ignored" and
+# "nulls_unequal" option
+set global innodb_stats_method = "nulls_unequal";
+analyze table table_bug30423;
+
+set global innodb_stats_method = "nulls_ignored";
+analyze table table_bug30423;
+
+
+eval set global innodb_stats_method = $innodb_stats_method_orig;
+
+drop table bug30243_2;
+
+drop table bug30243_1;
+
+drop table bug30243_3;
+
+drop table table_bug30423;
diff --git a/mysql-test/suite/innodb/t/innodb_bug30919-master.opt b/mysql-test/suite/innodb/t/innodb_bug30919-master.opt
new file mode 100644
index 00000000..58b254fe
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb_bug30919-master.opt
@@ -0,0 +1 @@
+--loose-innodb --loose-innodb_autoinc_lock_mode=0
diff --git a/mysql-test/suite/innodb/t/innodb_bug30919.test b/mysql-test/suite/innodb/t/innodb_bug30919.test
new file mode 100644
index 00000000..b80da124
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb_bug30919.test
@@ -0,0 +1,72 @@
+--source include/have_innodb.inc
+--source include/have_partition.inc
+--vertical_results
+let $engine_type= 'innodb';
+
+######## Creat Table Section #########
+use test;
+
+eval CREATE TABLE test.part_tbl(id MEDIUMINT NOT NULL AUTO_INCREMENT,
+ dt TIMESTAMP, user CHAR(255), uuidf LONGBLOB,
+ fkid MEDIUMINT, filler VARCHAR(255),
+ PRIMARY KEY(id)) ENGINE=$engine_type
+ PARTITION BY RANGE(id)
+ SUBPARTITION BY hash(id) subpartitions 2
+ (PARTITION pa3 values less than (42),
+ PARTITION pa6 values less than (60),
+ PARTITION pa7 values less than (70),
+ PARTITION pa8 values less than (80),
+ PARTITION pa9 values less than (90),
+ PARTITION pa10 values less than (100),
+ PARTITION pa11 values less than MAXVALUE);
+
+######## Create SPs, Functions, Views and Triggers Section ##############
+
+--enable_prepare_warnings
+
+delimiter |;
+
+CREATE PROCEDURE test.proc_part()
+BEGIN
+ DECLARE ins_count INT DEFAULT 1000;
+ DECLARE del_count INT;
+ DECLARE cur_user VARCHAR(255);
+ DECLARE local_uuid VARCHAR(255);
+ DECLARE local_time TIMESTAMP;
+
+ SET local_time= NOW();
+ SET cur_user= CURRENT_USER();
+ SET local_uuid= UUID();
+
+ WHILE ins_count > 0 DO
+ INSERT INTO test.part_tbl VALUES (NULL, NOW(), USER() , UUID(),
+ ins_count,'Going to test MBR for MySQL');
+ SET ins_count = ins_count - 1;
+ END WHILE;
+ SELECT MAX(id) FROM test.part_tbl INTO del_count;
+ WHILE del_count > 0 DO
+ DELETE FROM test.part_tbl WHERE id = del_count;
+ select count(*) as internal_count, del_count -- these two lines are for
+ FROM test.part_tbl; -- debug to show the problem
+ SET del_count = del_count - 2;
+ END WHILE;
+END|
+
+delimiter ;|
+
+--disable_prepare_warnings
+
+############ Finish Setup Section ###################
+
+############ Test Section ###################
+--horizontal_results
+
+CALL test.proc_part();
+
+select count(*) as Part from test.part_tbl;
+
+###### CLEAN UP SECTION ##############
+
+DROP PROCEDURE test.proc_part;
+DROP TABLE test.part_tbl;
+
diff --git a/mysql-test/suite/innodb/t/innodb_bug34300.test b/mysql-test/suite/innodb/t/innodb_bug34300.test
new file mode 100644
index 00000000..3ca03164
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb_bug34300.test
@@ -0,0 +1,38 @@
+--echo #
+--echo # Bug#34300 Tinyblob & tinytext fields corrupted after export/import and alter in 5.1
+--echo #
+
+-- source include/have_innodb.inc
+
+-- disable_query_log
+call mtr.add_suppression("InnoDB: Warning: a long semaphore wait:");
+call mtr.add_suppression("The age of the last checkpoint is");
+
+# set packet size and reconnect
+let $max_packet=`select @@global.max_allowed_packet`;
+-- enable_query_log
+
+SET @@global.max_allowed_packet=16777216;
+--connect (newconn, localhost, root,,)
+
+CREATE TABLE bug34300 (
+ f4 TINYTEXT,
+ f6 MEDIUMTEXT,
+ f8 TINYBLOB
+) ENGINE=InnoDB;
+
+INSERT INTO bug34300 VALUES ('xxx', repeat('a', 8459264), 'zzz');
+
+SELECT f4, f8 FROM bug34300;
+
+ALTER TABLE bug34300 ADD COLUMN (f10 INT);
+
+SELECT f4, f8 FROM bug34300;
+
+--echo # Cleanup
+DROP TABLE bug34300;
+
+-- disable_query_log
+EVAL SET @@global.max_allowed_packet=$max_packet;
+-- enable_query_log
+
diff --git a/mysql-test/suite/innodb/t/innodb_bug35220.test b/mysql-test/suite/innodb/t/innodb_bug35220.test
new file mode 100644
index 00000000..8ad6b307
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb_bug35220.test
@@ -0,0 +1,15 @@
+--source include/have_innodb.inc
+#
+# Bug#35220 ALTER TABLE too picky on reserved word "foreign"
+# http://bugs.mysql.com/35220
+#
+
+SET default_storage_engine=InnoDB;
+
+# we care only that the following SQL commands do not produce errors
+-- disable_query_log
+-- disable_result_log
+
+CREATE TABLE bug35220 (foreign_col INT, dummy_cant_delete_all_columns INT);
+ALTER TABLE bug35220 DROP foreign_col;
+DROP TABLE bug35220;
diff --git a/mysql-test/suite/innodb/t/innodb_bug38231.test b/mysql-test/suite/innodb/t/innodb_bug38231.test
new file mode 100644
index 00000000..0c139c33
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb_bug38231.test
@@ -0,0 +1,76 @@
+--source include/have_innodb.inc
+#
+# Bug#38231 Innodb crash in lock_reset_all_on_table() on TRUNCATE + LOCK / UNLOCK
+# http://bugs.mysql.com/38231
+#
+
+# skip this test in embedded mode because "TRUNCATE TABLE bug38231_1"
+# hangs in that mode waiting for "lock_wait_timeout" although it is
+# preceded by --send
+-- source include/not_embedded.inc
+
+SET default_storage_engine=InnoDB;
+
+# we care only that the following SQL commands do not crash the server
+-- disable_query_log
+-- disable_result_log
+
+DROP TABLE IF EXISTS bug38231_1;
+CREATE TABLE bug38231_1 (a INT);
+
+-- connect (lock_gain,localhost,root,,)
+-- connect (lock_wait1,localhost,root,,)
+-- connect (lock_wait2,localhost,root,,)
+-- connect (truncate_wait,localhost,root,,)
+
+-- connection lock_gain
+SET autocommit=0;
+LOCK TABLE bug38231_1 WRITE;
+
+-- connection lock_wait1
+SET autocommit=0;
+-- send
+LOCK TABLE bug38231_1 WRITE;
+
+-- connection lock_wait2
+SET autocommit=0;
+-- send
+LOCK TABLE bug38231_1 WRITE;
+
+-- connection truncate_wait
+-- send
+TRUNCATE TABLE bug38231_1;
+
+-- connection lock_gain
+# this crashes the server if the bug is present
+UNLOCK TABLES;
+
+# clean up
+
+# do not clean up - we do not know which of the three has been released
+# so the --reap command may hang because the command that is being executed
+# in that connection is still running/waiting
+#-- connection lock_wait1
+#-- reap
+#UNLOCK TABLES;
+#
+#-- connection lock_wait2
+#-- reap
+#UNLOCK TABLES;
+#
+#-- connection truncate_wait
+#-- reap
+
+-- connection default
+
+-- disconnect lock_gain
+-- disconnect lock_wait1
+-- disconnect lock_wait2
+-- disconnect truncate_wait
+
+DROP TABLE bug38231_1;
+
+-- enable_query_log
+-- enable_result_log
+
+-- connection default
diff --git a/mysql-test/suite/innodb/t/innodb_bug39438-master.opt b/mysql-test/suite/innodb/t/innodb_bug39438-master.opt
new file mode 100644
index 00000000..0746d13d
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb_bug39438-master.opt
@@ -0,0 +1 @@
+--loose-innodb-file-per-table=1
diff --git a/mysql-test/suite/innodb/t/innodb_bug39438.test b/mysql-test/suite/innodb/t/innodb_bug39438.test
new file mode 100644
index 00000000..635d65f0
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb_bug39438.test
@@ -0,0 +1,50 @@
+--source include/have_innodb.inc
+#
+# Bug#39438 Testcase for Bug#39436 crashes on 5.1 in fil_space_get_latch
+# http://bugs.mysql.com/39438
+#
+# This test must be run with innodb_file_per_table=1 because the crash
+# only occurs if that option is turned on and DISCARD TABLESPACE only
+# works with innodb_file_per_table.
+#
+
+SET default_storage_engine=InnoDB;
+
+# we care only that the following SQL commands do not crash the server
+-- disable_query_log
+-- disable_result_log
+
+DROP TABLE IF EXISTS bug39438;
+
+CREATE TABLE bug39438 (id INT) ENGINE=INNODB;
+
+# remove: XXX Uncomment the following ALTER and remove those lines after
+# remove: applying the patch.
+# remove: Obviously this test is useless without this ALTER command,
+# remove: but it causes warnings to be printed by mysqld and the whole
+# remove: mysql-test suite fails at the end (returns non-zero). Please
+# remove: apply this patch to the mysql source tree, remove those lines
+# remove: and uncomment the following ALTER. We do not care about the
+# remove: warnings, this test is to ensure mysqld does not crash.
+# remove: === modified file 'mysql-test/lib/mtr_report.pl'
+# remove: --- mysql-test/lib/mtr_report.pl 2008-08-12 10:26:23 +0000
+# remove: +++ mysql-test/lib/mtr_report.pl 2008-10-01 11:57:41 +0000
+# remove: @@ -412,7 +412,10 @@
+# remove:
+# remove: # When trying to set lower_case_table_names = 2
+# remove: # on a case sensitive file system. Bug#37402.
+# remove: - /lower_case_table_names was set to 2, even though your the file system '.*' is case sensitive. Now setting lower_case_table_names to 0 to avoid future problems./
+# remove: + /lower_case_table_names was set to 2, even though your the file system '.*' is case sensitive. Now setting lower_case_table_names to 0 to avoid future problems./ or
+# remove: +
+# remove: + # this test is expected to print warnings
+# remove: + ($testname eq 'main.innodb_bug39438')
+# remove: )
+# remove: {
+# remove: next; # Skip these lines
+# remove:
+#ALTER TABLE bug39438 DISCARD TABLESPACE;
+
+# this crashes the server if the bug is present
+SHOW TABLE STATUS;
+
+DROP TABLE bug39438;
diff --git a/mysql-test/suite/innodb/t/innodb_bug40360.test b/mysql-test/suite/innodb/t/innodb_bug40360.test
new file mode 100644
index 00000000..f5187d55
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb_bug40360.test
@@ -0,0 +1,16 @@
+--source include/have_innodb.inc
+#
+# Make sure http://bugs.mysql.com/40360 remains fixed.
+#
+
+-- source include/not_embedded.inc
+
+SET TX_ISOLATION='READ-COMMITTED';
+
+# This is the default since MySQL 5.1.29 SET BINLOG_FORMAT='STATEMENT';
+
+CREATE TABLE bug40360 (a INT) engine=innodb;
+
+INSERT INTO bug40360 VALUES (1);
+
+DROP TABLE bug40360;
diff --git a/mysql-test/suite/innodb/t/innodb_bug40565.test b/mysql-test/suite/innodb/t/innodb_bug40565.test
new file mode 100644
index 00000000..a5d14346
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb_bug40565.test
@@ -0,0 +1,10 @@
+--source include/have_innodb.inc
+# Bug #40565 Update Query Results in "1 Row Affected" But Should Be "Zero Rows"
+
+create table bug40565(value decimal(4,2)) engine=innodb;
+insert into bug40565 values (1), (null);
+--enable_info
+update bug40565 set value=NULL;
+update bug40565 set value=NULL;
+--disable_info
+drop table bug40565;
diff --git a/mysql-test/suite/innodb/t/innodb_bug41904.test b/mysql-test/suite/innodb/t/innodb_bug41904.test
new file mode 100644
index 00000000..4b45128d
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb_bug41904.test
@@ -0,0 +1,14 @@
+--source include/have_innodb.inc
+#
+# Make sure http://bugs.mysql.com/41904 remains fixed.
+#
+
+-- source include/not_embedded.inc
+
+CREATE TABLE bug41904 (id INT PRIMARY KEY, uniquecol CHAR(15)) ENGINE=InnoDB;
+
+INSERT INTO bug41904 VALUES (1,NULL), (2,NULL);
+
+CREATE UNIQUE INDEX ui ON bug41904 (uniquecol);
+
+DROP TABLE bug41904;
diff --git a/mysql-test/suite/innodb/t/innodb_bug42419.test b/mysql-test/suite/innodb/t/innodb_bug42419.test
new file mode 100644
index 00000000..ef350529
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb_bug42419.test
@@ -0,0 +1,80 @@
+--source include/have_innodb.inc
+#
+# Testcase for InnoDB
+# Bug#42419 Server crash with "Pure virtual method called" on two concurrent connections
+#
+
+--source include/not_embedded.inc
+
+let $innodb_lock_wait_timeout= query_get_value(SHOW VARIABLES LIKE 'innodb_lock_wait_timeout%', Value, 1);
+if ($innodb_lock_wait_timeout < 10)
+{
+ --echo # innodb_lock_wait_timeout must be >= 10 seconds
+ --echo # so that this test can work all time fine on an overloaded testing box
+ SHOW VARIABLES LIKE 'innodb_lock_wait_timeout';
+ exit;
+}
+
+# Save the initial number of concurrent sessions
+--source include/count_sessions.inc
+
+# First session
+connection default;
+
+
+--enable_warnings
+CREATE TABLE t1 (a INT AUTO_INCREMENT PRIMARY KEY, b INT) ENGINE = InnoDB;
+
+INSERT INTO t1 VALUES (1,1),(2,2),(3,3);
+COMMIT;
+SET AUTOCOMMIT = 0;
+
+CREATE TEMPORARY TABLE t1_tmp ( b INT );
+
+INSERT INTO t1_tmp (b) SELECT b FROM t1 WHERE a = 3;
+INSERT INTO t1_tmp (b) SELECT b FROM t1 WHERE a = 2;
+
+# Second session
+connect (user2,localhost,root,,,$MASTER_MYPORT,$MASTER_MYSOCK);
+
+SET AUTOCOMMIT = 0;
+
+CREATE TEMPORARY TABLE t2_tmp ( a int, new_a int );
+INSERT INTO t2_tmp VALUES (1,51),(2,52),(3,53);
+
+UPDATE t1 SET a = (SELECT new_a FROM t2_tmp WHERE t2_tmp.a = t1.a) WHERE a = 1;
+send
+UPDATE t1 SET a = (SELECT new_a FROM t2_tmp WHERE t2_tmp.a = t1.a) WHERE a = 2;
+
+# The last update will wait for a lock held by the first session
+
+# First session
+connection default;
+
+# Poll till the UPDATE of the second session waits for lock
+let $show_statement= SHOW PROCESSLIST;
+let $field= State;
+let $condition= = 'Updating';
+--source include/wait_show_condition.inc
+
+# If the testing box is overloadeded and innodb_lock_wait_timeout is too small
+# we might get here ER_LOCK_WAIT_TIMEOUT.
+--error ER_LOCK_DEADLOCK
+INSERT INTO t1_tmp (b) SELECT b FROM t1 WHERE a = 1;
+
+# Second session
+connection user2;
+--echo Reap the server message for connection user2 UPDATE t1 ...
+reap;
+
+# The server crashed when executing this UPDATE or the succeeding SQL command.
+UPDATE t1 SET a = (SELECT new_a FROM t2_tmp WHERE t2_tmp.a = t1.a) WHERE a = 3;
+
+connection default;
+disconnect user2;
+DROP TABLE t1;
+
+# Wait till all disconnects are completed
+--source include/wait_until_count_sessions.inc
+
+call mtr.add_suppression("Deadlock found when trying to get lock; try restarting transaction");
diff --git a/mysql-test/suite/innodb/t/innodb_bug44032.test b/mysql-test/suite/innodb/t/innodb_bug44032.test
new file mode 100644
index 00000000..00167496
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb_bug44032.test
@@ -0,0 +1,13 @@
+--source include/have_innodb.inc
+# Bug44032 no update-in-place of UTF-8 columns in ROW_FORMAT=REDUNDANT
+# (btr_cur_update_in_place not invoked when updating from/to NULL;
+# the update is performed by delete and insert instead)
+
+
+CREATE TABLE bug44032(c CHAR(3) CHARACTER SET UTF8) ROW_FORMAT=REDUNDANT
+ENGINE=InnoDB;
+INSERT INTO bug44032 VALUES('abc'),(0xEFBCA4EFBCA4EFBCA4);
+UPDATE bug44032 SET c='DDD' WHERE c=0xEFBCA4EFBCA4EFBCA4;
+UPDATE bug44032 SET c=NULL WHERE c='DDD';
+UPDATE bug44032 SET c='DDD' WHERE c IS NULL;
+DROP TABLE bug44032;
diff --git a/mysql-test/suite/innodb/t/innodb_bug44369.test b/mysql-test/suite/innodb/t/innodb_bug44369.test
new file mode 100644
index 00000000..caa4eed3
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb_bug44369.test
@@ -0,0 +1,17 @@
+--source include/have_innodb.inc
+# This is the test for bug 44369. We should
+# block table creation with columns match
+# some innodb internal reserved key words,
+# both case sensitively and insensitely.
+
+
+# This create table operation should fail.
+--error ER_WRONG_COLUMN_NAME
+create table bug44369 (DB_ROW_ID int) engine=innodb;
+
+# This create should fail as well
+--error ER_WRONG_COLUMN_NAME
+create table bug44369 (db_row_id int) engine=innodb;
+
+--error ER_WRONG_COLUMN_NAME
+create table bug44369 (db_TRX_Id int) engine=innodb;
diff --git a/mysql-test/suite/innodb/t/innodb_bug44571.test b/mysql-test/suite/innodb/t/innodb_bug44571.test
new file mode 100644
index 00000000..08f41ed8
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb_bug44571.test
@@ -0,0 +1,22 @@
+--source include/have_innodb.inc
+#
+# Bug#44571 InnoDB Plugin crashes on ADD INDEX
+# http://bugs.mysql.com/44571
+# Please also refer to related fix in
+# http://bugs.mysql.com/47621
+#
+
+CREATE TABLE bug44571 (foo INT) ENGINE=InnoDB;
+ALTER TABLE bug44571 CHANGE foo bar INT;
+# Create index with the old column name will fail,
+# because the CHANGE foo bar is successful. And
+# the column name change would communicate to
+# InnoDB with the fix from bug #47621
+-- error ER_KEY_COLUMN_DOES_NOT_EXIST
+ALTER TABLE bug44571 ADD INDEX bug44571b (foo);
+# The following create indexes should succeed,
+# indirectly confirm the CHANGE foo bar is successful.
+ALTER TABLE bug44571 ADD INDEX bug44571c (bar);
+DROP INDEX bug44571c ON bug44571;
+CREATE INDEX bug44571c ON bug44571 (bar);
+DROP TABLE bug44571;
diff --git a/mysql-test/suite/innodb/t/innodb_bug45357.test b/mysql-test/suite/innodb/t/innodb_bug45357.test
new file mode 100644
index 00000000..8294bfe6
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb_bug45357.test
@@ -0,0 +1,10 @@
+--source include/have_innodb.inc
+
+set session transaction isolation level read committed;
+
+create table bug45357(a int, b int,key(b))engine=innodb;
+insert into bug45357 values (25170,6122);
+update bug45357 set a=1 where b=30131;
+delete from bug45357 where b < 20996;
+delete from bug45357 where b < 7001;
+drop table bug45357;
diff --git a/mysql-test/suite/innodb/t/innodb_bug46000.test b/mysql-test/suite/innodb/t/innodb_bug46000.test
new file mode 100644
index 00000000..3dcfa85a
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb_bug46000.test
@@ -0,0 +1,32 @@
+--source include/have_innodb.inc
+# This is the test for bug 46000. We shall
+# block any index creation with the name of
+# "GEN_CLUST_INDEX", which is the reserved
+# name for innodb default primary index.
+
+
+# This 'create table' operation should fail because of
+# using the reserve name as its index name.
+--error ER_WRONG_NAME_FOR_INDEX
+create table bug46000(`id` int,key `GEN_CLUST_INDEX`(`id`))engine=innodb;
+
+# Mixed upper/lower case of the reserved key words
+--error ER_WRONG_NAME_FOR_INDEX
+create table bug46000(`id` int, key `GEN_clust_INDEX`(`id`))engine=innodb;
+
+show warnings;
+
+create table bug46000(id int) engine=innodb;
+
+# This 'create index' operation should fail.
+--error ER_WRONG_NAME_FOR_INDEX
+create index GEN_CLUST_INDEX on bug46000(id);
+
+show warnings;
+
+# This 'create index' operation should succeed, no
+# temp table left from last failed create index
+# operation.
+create index idx on bug46000(id);
+
+drop table bug46000;
diff --git a/mysql-test/suite/innodb/t/innodb_bug46676.test b/mysql-test/suite/innodb/t/innodb_bug46676.test
new file mode 100644
index 00000000..fdea70c6
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb_bug46676.test
@@ -0,0 +1,16 @@
+--source include/have_innodb.inc
+# This is the test for bug 46676: mysqld got exception 0xc0000005
+# It is reproducible with InnoDB plugin 1.0.4 + MySQL 5.1.37.
+# But no longer reproducible after MySQL 5.1.38 (with plugin 1.0.5).
+
+
+SET foreign_key_checks=0;
+CREATE TABLE t1 (id int, foreign key (id) references t2(id)) ENGINE=INNODB;
+CREATE TABLE t2 (id int, foreign key (id) references t1(id)) ENGINE=INNODB;
+SET foreign_key_checks=1;
+
+# Server crashes
+SELECT COUNT(*) FROM information_schema.key_column_usage WHERE REFERENCED_TABLE_NAME in ('t1', 't2');
+
+SET foreign_key_checks=0;
+DROP TABLE t1, t2;
diff --git a/mysql-test/suite/innodb/t/innodb_bug47621.test b/mysql-test/suite/innodb/t/innodb_bug47621.test
new file mode 100644
index 00000000..64a6ff76
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb_bug47621.test
@@ -0,0 +1,57 @@
+--source include/have_innodb.inc
+# This is the test for bug #47621, column rename operation should
+# not result in column definition inconsistency between MySQL and
+# InnoDB
+
+
+CREATE TABLE bug47621 (salesperson INT) ENGINE=InnoDB;
+
+# Change the column name
+ALTER TABLE bug47621 CHANGE salesperson sales_acct_id INT;
+
+# If there is inconsistency of column name definition
+# in MySQL or InnoDB, following create index would fail
+create index orgs on bug47621(sales_acct_id);
+
+# Change the column name back with the index defined on it.
+ALTER TABLE bug47621 CHANGE sales_acct_id salesperson INT;
+
+drop table bug47621;
+
+CREATE TABLE bug47621_sale (
+ salesperson INT,
+ PRIMARY KEY(salesperson)) engine = innodb;
+
+CREATE TABLE bug47621_shirt(
+ id SMALLINT,
+ owner INT,
+ FOREIGN KEY(owner)
+ references bug47621_sale(salesperson) ON DELETE RESTRICT)
+ engine = innodb;
+
+insert into bug47621_sale values(9);
+
+insert into bug47621_shirt values(1, 9);
+
+# Any rename operation on columns involved in a reference constraint will
+# fail, as it will be rejected by InnoDB row_rename_table_for_mysql().
+# In above example, any rename on column "salesperson" for table
+# "bug47621_sale", or on column "owner" for table "bug47621_shirt will
+# be blocked. We do not put such rename in the test since InnoDB error
+# message will be printed in the error log, and result in test failure.
+#
+# ALTER TABLE bug47621_sale CHANGE salesperson sales_acct_id INT;
+
+# Any rename on columns not involved in the foreign key constraint
+# could still proceed
+ALTER TABLE bug47621_shirt CHANGE id new_id INT;
+
+# Referencing table dropped, the rename operation on related columns
+# could proceed
+drop table bug47621_shirt;
+
+ALTER TABLE bug47621_sale CHANGE salesperson sales_acct_id INT;
+
+ALTER TABLE bug47621_sale ADD INDEX idx (sales_acct_id);
+
+drop table bug47621_sale;
diff --git a/mysql-test/suite/innodb/t/innodb_bug47622.test b/mysql-test/suite/innodb/t/innodb_bug47622.test
new file mode 100644
index 00000000..2ebf9a62
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb_bug47622.test
@@ -0,0 +1,55 @@
+--source include/have_innodb.inc
+# This is the test for bug 47622. There could be index
+# metadata sequence mismatch between MySQL and Innodb
+# after creating index through FIC interfaces.
+# We resolve the problem by sync the index sequence
+# up when opening the table.
+
+
+connect (a,localhost,root,,);
+connect (b,localhost,root,,);
+
+# Create a table with a non-unique index
+CREATE TABLE bug47622(
+ `rule_key` int(11) NOT NULL DEFAULT '0',
+ `seq` smallint(6) NOT NULL DEFAULT '0',
+ `action` smallint(6) NOT NULL DEFAULT '0',
+ `arg_id` smallint(6) DEFAULT NULL,
+ `else_ind` TINYINT NOT NULL,
+ KEY IDX_A (`arg_id`)
+) ENGINE=InnoDB;
+
+connection a;
+
+# A subsequent creating unique index should not trigger
+# any error message. Unique index would be ranked ahead
+# of regular index.
+ALTER TABLE bug47622 ADD UNIQUE IDX_B (rule_key,else_ind,seq,action,arg_id);
+
+drop index IDX_B on bug47622;
+
+# In another connection, create additional set of normal
+# index and unique index. Again, unique index would be ranked
+# ahead of regular index.
+connection b;
+create index idx on bug47622(seq, arg_id);
+
+ALTER TABLE bug47622 ADD UNIQUE IDX_X (rule_key,else_ind,seq,action);
+
+drop table bug47622;
+
+# Create a table with one Primary key and a non-unique key
+CREATE TABLE bug47622 (
+ `a` int(11) NOT NULL,
+ `b` int(11) DEFAULT NULL,
+ `c` char(10) DEFAULT NULL,
+ `d` varchar(20) DEFAULT NULL,
+ PRIMARY KEY (`a`),
+ KEY `b` (`b`)
+) ENGINE=InnoDB;
+
+# Add two index with one unique and one non-unique.
+# Index sequence is "PRIMARY", "c", "b" and "d"
+alter table bug47622 add unique index (c), add index (d);
+
+drop table bug47622;
diff --git a/mysql-test/suite/innodb/t/innodb_bug47777.test b/mysql-test/suite/innodb/t/innodb_bug47777.test
new file mode 100644
index 00000000..575d84b9
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb_bug47777.test
@@ -0,0 +1,24 @@
+--source include/have_innodb.inc
+# This is the test for bug 47777. GEOMETRY
+# data is treated as BLOB data in innodb.
+# Consequently, its key value generation/storing
+# should follow the process for the BLOB
+# datatype as well.
+
+
+create table bug47777(c2 linestring not null, primary key (c2(1))) engine=innodb;
+
+insert into bug47777 values (geomfromtext('linestring(1 2,3 4,5 6,7 8,9 10)'));
+
+# Verify correct row get inserted.
+select count(*) from bug47777 where c2 =geomfromtext('linestring(1 2,3 4,5 6,7 8,9 10)');
+
+# Update table bug47777 should be successful.
+update bug47777 set c2=GeomFromText('linestring(1 1)');
+
+# Verify the row get updated successfully. The original
+# c2 value should be changed to GeomFromText('linestring(1 1)').
+select count(*) from bug47777 where c2 =geomfromtext('linestring(1 2,3 4,5 6,7 8,9 10)');
+select count(*) from bug47777 where c2 = GeomFromText('linestring(1 1)');
+
+drop table bug47777;
diff --git a/mysql-test/suite/innodb/t/innodb_bug48024.test b/mysql-test/suite/innodb/t/innodb_bug48024.test
new file mode 100644
index 00000000..db828aa1
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb_bug48024.test
@@ -0,0 +1,22 @@
+# Bug #48024 Innodb doesn't work with multi-statements
+
+--source include/have_innodb.inc
+
+CREATE TABLE bug48024(a int PRIMARY KEY,b int NOT NULL,KEY(b)) ENGINE=InnoDB;
+CREATE TABLE bug48024_b(b int PRIMARY KEY) ENGINE=InnoDB;
+# Bug #53644 InnoDB thinks that /*/ starts and ends a comment
+ALTER TABLE bug48024 /*/ADD CONSTRAINT FOREIGN KEY(c) REFERENCES(a),/*/
+ADD CONSTRAINT FOREIGN KEY(b) REFERENCES bug48024_b(b);
+
+DROP TABLE bug48024,bug48024_b;
+
+# Work around Bug #53750 (failure in mysql-test-run --ps-protocol)
+-- disable_ps_protocol
+delimiter |;
+CREATE TABLE bug48024(a int PRIMARY KEY,b int NOT NULL,KEY(b)) ENGINE=InnoDB;
+CREATE TABLE bug48024_b(b int PRIMARY KEY) ENGINE=InnoDB;
+ALTER TABLE bug48024 /*/ADD CONSTRAINT FOREIGN KEY(c) REFERENCES(a),/*/
+ADD CONSTRAINT FOREIGN KEY(b) REFERENCES bug48024_b(b)|
+delimiter ;|
+
+DROP TABLE bug48024,bug48024_b;
diff --git a/mysql-test/suite/innodb/t/innodb_bug49164.test b/mysql-test/suite/innodb/t/innodb_bug49164.test
new file mode 100644
index 00000000..159475ba
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb_bug49164.test
@@ -0,0 +1,47 @@
+--source include/have_innodb.inc
+
+# Bug #49164 READ-COMMITTED reports "matched: 0" on compound PK
+# a duplicate of
+# Bug #52663 Lost update incrementing column value under READ COMMITTED
+
+connect (con1,localhost,root,,);
+connect (con2,localhost,root,,);
+
+connection con1;
+SET tx_isolation = 'READ-COMMITTED';
+
+CREATE TABLE bug49164 (a INT, b BIGINT, c TINYINT, PRIMARY KEY (a, b))
+ENGINE=InnoDB;
+
+insert into bug49164 values (1,1,1), (2,2,2), (3,3,3);
+
+begin;
+update bug49164 set c=7;
+select * from bug49164;
+rollback;
+select * from bug49164;
+begin;
+update bug49164 set c=7;
+
+connection con2;
+
+SET tx_isolation = 'READ-COMMITTED';
+begin;
+select * from bug49164;
+commit;
+begin;
+--send
+update bug49164 set c=6 where a=1 and b=1;
+
+connection con1;
+rollback;
+select * from bug49164;
+connection con2;
+reap;
+commit;
+connection con1;
+select * from bug49164;
+connection default;
+disconnect con1;
+disconnect con2;
+drop table bug49164;
diff --git a/mysql-test/suite/innodb/t/innodb_bug51378.test b/mysql-test/suite/innodb/t/innodb_bug51378.test
new file mode 100644
index 00000000..e11c3c00
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb_bug51378.test
@@ -0,0 +1,77 @@
+--source include/have_innodb.inc
+# This is the test for bug 51378. Unique index created
+# through "create index" and "alter table add unique index"
+# interfaces should not be treated as primary index if indexed
+# columns contain one or more column prefix(es) (only prefix/part of
+# the column is indexed)
+# On the other hand, if there is a unique index covers all
+# columns of a table, and they are non-null columns, and
+# full length of the column are indexed, then this index
+# will be created as primary index
+# Following queries test various scenario, no mismatch
+# error message should be printed.
+
+# Create a table contains a BLOB column
+create table bug51378 (
+ col1 int not null,
+ col2 blob not null,
+ col3 time not null) engine = innodb;
+
+# Create following unique indexes on 'col1' and 'col2(31)'
+# of the table, the index should not be treated as primary
+# key because it indexes only first 31 bytes of col2.
+# Thus it contains "column prefix", and will not be
+# upgraded to primary index.
+# There should not be mismatch message printed in the
+# errorlog
+create unique index idx on bug51378(col1, col2(31));
+
+alter table bug51378 add unique index idx2(col1, col2(31));
+
+# Unique index on 'col1' and 'col3' will be created as primary index,
+# since the index does not contain column prefix
+create unique index idx3 on bug51378(col1, col3);
+
+# Show create table would show idx3 created as unique index, internally,
+# idx3 is treated as primary index both by MySQL and Innodb
+SHOW CREATE TABLE bug51378;
+
+# "GEN_CLUST_INDEX" will be re-created as default primary index
+# after idx3 is dropped
+drop index idx3 on bug51378;
+
+SHOW CREATE TABLE bug51378;
+
+# Or we can add the primary key through alter table interfaces
+alter table bug51378 add primary key idx3(col1, col2(31));
+
+SHOW CREATE TABLE bug51378;
+
+drop table bug51378;
+
+# Or we can create such primary key through create table interfaces
+create table bug51378 (
+ col1 int not null,
+ col2 blob not null,
+ col3 time not null, primary key(col1, col2(31))) engine = innodb;
+
+# Unique index on one or more column prefix(es) will be created
+# as non-cluster index
+create unique index idx on bug51378(col1, col2(31));
+
+SHOW CREATE TABLE bug51378;
+
+drop table bug51378;
+
+# If a table has a NULLABLE column, unique index on it will not
+# be treated as primary index.
+create table bug51378 (
+ col1 int not null,
+ col2 int ) engine = innodb;
+
+# This will be created as non-cluster index since col2 is nullable
+create unique index idx on bug51378(col1, col2);
+
+SHOW CREATE TABLE bug51378;
+
+drop table bug51378;
diff --git a/mysql-test/suite/innodb/t/innodb_bug51920.test b/mysql-test/suite/innodb/t/innodb_bug51920.test
new file mode 100644
index 00000000..84977925
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb_bug51920.test
@@ -0,0 +1,45 @@
+--source include/have_innodb.inc
+#
+# Bug #51920: InnoDB connections in lock wait ignore KILL until timeout
+#
+-- source include/not_embedded.inc
+
+CREATE TABLE bug51920 (i INT) ENGINE=InnoDB;
+INSERT INTO bug51920 VALUES (1);
+
+BEGIN;
+SELECT * FROM bug51920 FOR UPDATE;
+
+connect (con1,localhost,root,,);
+
+connection con1;
+--send
+UPDATE bug51920 SET i=2;
+
+connection default;
+let $wait_condition =
+ SELECT COUNT(*)=1 FROM information_schema.processlist
+ WHERE INFO="UPDATE bug51920 SET i=2";
+-- source include/wait_condition.inc
+
+--enable_prepare_warnings
+SELECT ID FROM INFORMATION_SCHEMA.PROCESSLIST
+WHERE INFO="UPDATE bug51920 SET i=2"
+INTO @thread_id;
+--disable_prepare_warnings
+
+KILL @thread_id;
+let $wait_condition =
+ SELECT COUNT(*)=0 FROM information_schema.processlist WHERE ID=@thread_id;
+-- source include/wait_condition.inc
+
+#
+# Bug#19723: kill of active connection yields different error code
+# depending on platform.
+#
+connection con1;
+-- error 1317, 2006, 2013, ER_CONNECTION_KILLED, 2026
+reap;
+connection default;
+DROP TABLE bug51920;
+-- disconnect con1
diff --git a/mysql-test/suite/innodb/t/innodb_bug52199.test b/mysql-test/suite/innodb/t/innodb_bug52199.test
new file mode 100644
index 00000000..d78a53be
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb_bug52199.test
@@ -0,0 +1,10 @@
+--source include/have_innodb.inc
+
+let collation=utf32_bin;
+--source include/have_collation.inc
+
+CREATE TABLE bug52199 (a INT NOT NULL,
+b CHAR(125) CHARACTER SET utf32 COLLATE utf32_bin NOT NULL
+)ENGINE=InnoDB;
+CREATE UNIQUE INDEX idx ON bug52199(a);
+DROP TABLE bug52199;
diff --git a/mysql-test/suite/innodb/t/innodb_bug52663.test b/mysql-test/suite/innodb/t/innodb_bug52663.test
new file mode 100644
index 00000000..fcf97531
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb_bug52663.test
@@ -0,0 +1,34 @@
+--source include/have_innodb.inc
+
+set session transaction isolation level read committed;
+
+create table innodb_bug52663 (what varchar(5), id integer, count integer, primary key
+(what, id)) engine=innodb;
+insert into innodb_bug52663 values ('total', 0, 0);
+begin;
+
+connect (addconroot, localhost, root,,);
+connection addconroot;
+set session transaction isolation level read committed;
+begin;
+
+connection default;
+update innodb_bug52663 set count = count + 1 where what = 'total' and id = 0;
+select * from innodb_bug52663;
+
+connection addconroot;
+--error ER_LOCK_WAIT_TIMEOUT
+update innodb_bug52663 set count = count + 1 where what = 'total' and id = 0;
+select * from innodb_bug52663;
+
+connection default;
+commit;
+
+connection addconroot;
+update innodb_bug52663 set count = count + 1 where what = 'total' and id = 0;
+commit;
+select * from innodb_bug52663;
+
+connection default;
+select * from innodb_bug52663;
+drop table innodb_bug52663;
diff --git a/mysql-test/suite/innodb/t/innodb_bug53046.test b/mysql-test/suite/innodb/t/innodb_bug53046.test
new file mode 100644
index 00000000..a2021ee8
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb_bug53046.test
@@ -0,0 +1,44 @@
+--source include/have_innodb.inc
+#
+# http://bugs.mysql.com/53046
+# dict_update_statistics_low can still be run concurrently on same table
+#
+# This is a symbolic test, it would not fail if the bug is present.
+#
+
+CREATE TABLE bug53046_1 (c1 INT PRIMARY KEY) ENGINE=INNODB;
+CREATE TABLE bug53046_2 (c2 INT PRIMARY KEY,
+ FOREIGN KEY (c2) REFERENCES bug53046_1(c1)
+ ON UPDATE CASCADE ON DELETE CASCADE) ENGINE=INNODB;
+
+INSERT INTO bug53046_1 VALUES (1);
+let $i = 5;
+while ($i) {
+ eval INSERT INTO bug53046_1 SELECT c1+(SELECT MAX(c1) FROM bug53046_1)
+ FROM bug53046_1;
+ dec $i;
+}
+
+INSERT INTO bug53046_2 VALUES (1), (2);
+
+# CREATE TABLE innodb_table_monitor (a int) ENGINE=INNODB;
+# wait more than 1 minute and observe the mysqld output
+# DROP TABLE innodb_table_monitor;
+
+ANALYZE TABLE bug53046_1;
+
+# this prints create time and other nondeterministic data
+-- disable_result_log
+SHOW TABLE STATUS LIKE 'bug53046_1';
+-- enable_result_log
+
+UPDATE bug53046_1 SET c1 = c1 - 1;
+
+DELETE FROM bug53046_1;
+
+INSERT INTO bug53046_1 VALUES (1);
+INSERT INTO bug53046_2 VALUES (1);
+TRUNCATE TABLE bug53046_2;
+
+DROP TABLE bug53046_2;
+DROP TABLE bug53046_1;
diff --git a/mysql-test/suite/innodb/t/innodb_bug53290.test b/mysql-test/suite/innodb/t/innodb_bug53290.test
new file mode 100644
index 00000000..9d36d9bd
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb_bug53290.test
@@ -0,0 +1,23 @@
+-- source include/have_innodb.inc
+-- source include/no_valgrind_without_big.inc
+
+create table bug53290 (x bigint) engine=innodb;
+
+insert into bug53290 () values (),(),(),(),(),(),(),(),(),(),(),();
+insert into bug53290 select * from bug53290;
+insert into bug53290 select * from bug53290;
+insert into bug53290 select * from bug53290;
+insert into bug53290 select * from bug53290;
+insert into bug53290 select * from bug53290;
+insert into bug53290 select * from bug53290;
+insert into bug53290 select * from bug53290;
+insert into bug53290 select * from bug53290;
+insert into bug53290 select * from bug53290;
+insert into bug53290 select * from bug53290;
+insert into bug53290 select * from bug53290;
+insert into bug53290 select * from bug53290;
+insert into bug53290 select * from bug53290;
+
+alter table bug53290 add unique index `idx` (x);
+
+drop table bug53290;
diff --git a/mysql-test/suite/innodb/t/innodb_bug53592.test b/mysql-test/suite/innodb/t/innodb_bug53592.test
new file mode 100644
index 00000000..a809afeb
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb_bug53592.test
@@ -0,0 +1,84 @@
+# Testcase for Bug #53592 - "crash replacing duplicates into
+# table after fast alter table added unique key". The fix is to make
+# sure index number lookup should go through "index translation table".
+
+--source include/have_innodb.inc
+
+# Use FIC for index creation
+set old_alter_table=0;
+
+create table bug53592(a int) engine=innodb row_format=compact;
+
+alter table bug53592 add column b text charset utf8;
+
+alter table bug53592 add column c blob not null;
+
+# Create a non-unique nonclustered index
+create index bug53592_b on bug53592(b(81));
+
+# Create a unique index, this unique index should have smaller
+# index number than bug53592_b, since unique index ranks higher
+# than regular index does
+create unique index bug53592_c on bug53592(c(1));
+
+# This will trigger a dup key error and will require fetching
+# the index number through a index structure for the error reporting.
+# To get the correct index number, the code should go through index
+# translation table. Otherwise, it will get the wrong index
+# number and later trigger a server crash.
+set statement sql_mode = '' for
+replace into bug53592 values (),();
+
+check table bug53592;
+
+drop table bug53592;
+
+# Running the same set of test when "old_alter_table" is turned on
+set old_alter_table=1;
+
+create table bug53592(a int) engine=innodb row_format=compact;
+
+alter table bug53592 add column b text charset utf8;
+
+alter table bug53592 add column c blob not null;
+
+# Create a non-unique nonclustered index
+create index bug53592_b on bug53592(b(81));
+
+# Create a unique index
+create unique index bug53592_c on bug53592(c(1));
+
+# This will trigger a dup key error and will require fetching
+# the index number through a index structure for the error reporting.
+# To get the correct index number, the code should go through index
+# translation table. Otherwise, it will get the wrong index
+# number and later trigger a server crash.
+set statement sql_mode = '' for
+replace into bug53592 values (),();
+
+check table bug53592;
+drop table bug53592;
+
+# Test a dup key reported by foreign key constriant.
+CREATE TABLE bug53592_1(
+ col1 int, col2 int,
+ PRIMARY KEY (col1, col2)
+) ENGINE=InnoDB;
+
+CREATE TABLE bug53592_2 (
+ col int PRIMARY KEY,
+ FOREIGN KEY (col) REFERENCES bug53592_1 (col1)
+ ON DELETE CASCADE ON UPDATE CASCADE
+) ENGINE=InnoDB;
+
+INSERT INTO bug53592_1 VALUES (1, 2);
+INSERT INTO bug53592_1 VALUES (3, 4);
+
+INSERT INTO bug53592_2 VALUES (1);
+INSERT INTO bug53592_2 VALUES (3);
+
+--error ER_FOREIGN_DUPLICATE_KEY_WITH_CHILD_INFO
+UPDATE bug53592_1 SET col1 = 3 WHERE col2 = 2;
+
+drop table bug53592_2;
+drop table bug53592_1;
diff --git a/mysql-test/suite/innodb/t/innodb_bug53674-master.opt b/mysql-test/suite/innodb/t/innodb_bug53674-master.opt
new file mode 100644
index 00000000..01cf3e05
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb_bug53674-master.opt
@@ -0,0 +1 @@
+--binlog-format=mixed
diff --git a/mysql-test/suite/innodb/t/innodb_bug53674.test b/mysql-test/suite/innodb/t/innodb_bug53674.test
new file mode 100644
index 00000000..f89c3d47
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb_bug53674.test
@@ -0,0 +1,9 @@
+-- source include/have_log_bin.inc
+-- source include/have_innodb.inc
+
+create table bug53674(a int)engine=innodb;
+insert into bug53674 values (1),(2);
+start transaction;
+select * from bug53674 for update;
+select * from bug53674 where a=(select a from bug53674 where a > 1);
+drop table bug53674;
diff --git a/mysql-test/suite/innodb/t/innodb_bug53756-master.opt b/mysql-test/suite/innodb/t/innodb_bug53756-master.opt
new file mode 100644
index 00000000..590d44a6
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb_bug53756-master.opt
@@ -0,0 +1 @@
+--loose-skip-stack-trace --skip-core-file
diff --git a/mysql-test/suite/innodb/t/innodb_bug53756.test b/mysql-test/suite/innodb/t/innodb_bug53756.test
new file mode 100644
index 00000000..a676868a
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb_bug53756.test
@@ -0,0 +1,105 @@
+--source include/have_innodb.inc
+# This is the test case for bug #53756. Alter table operation could
+# leave a deleted record for the temp table (later renamed to the altered
+# table) in the SYS_TABLES secondary index, we should ignore this row and
+# find the first non-deleted row for the specified table_id when load table
+# metadata in the function dict_load_table_on_id() during crash recovery.
+
+#
+# The embedded server test does not support restarting.
+--source include/not_embedded.inc
+
+#
+# Create test data.
+#
+CREATE TABLE bug_53756 (pk INT, c1 INT) ENGINE=InnoDB;
+ALTER TABLE bug_53756 ADD PRIMARY KEY (pk);
+INSERT INTO bug_53756 VALUES(1, 11), (2, 22), (3, 33), (4, 44);
+
+--echo
+--echo # Select a less restrictive isolation level.
+SET GLOBAL TRANSACTION ISOLATION LEVEL READ COMMITTED;
+SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED;
+COMMIT;
+
+--echo
+--echo # Start a transaction in the default connection for isolation.
+START TRANSACTION;
+SELECT @@tx_isolation;
+SELECT * FROM bug_53756;
+
+--connect (con1,localhost,root,,)
+START TRANSACTION;
+SELECT @@tx_isolation;
+DELETE FROM bug_53756 WHERE pk=1;
+
+--connect (con2,localhost,root,,)
+START TRANSACTION;
+SELECT @@tx_isolation;
+DELETE FROM bug_53756 WHERE pk=2;
+
+--connect (con3,localhost,root,,)
+START TRANSACTION;
+SELECT @@tx_isolation;
+UPDATE bug_53756 SET c1=77 WHERE pk=3;
+
+--connect (con4,localhost,root,,)
+START TRANSACTION;
+SELECT @@tx_isolation;
+UPDATE bug_53756 SET c1=88 WHERE pk=4;
+
+--connect (con5,localhost,root,,)
+START TRANSACTION;
+SELECT @@tx_isolation;
+INSERT INTO bug_53756 VALUES(5, 55);
+
+--connect (con6,localhost,root,,)
+START TRANSACTION;
+SELECT @@tx_isolation;
+INSERT INTO bug_53756 VALUES(6, 66);
+
+--connection con1
+COMMIT;
+
+--connection con3
+COMMIT;
+
+--connection con4
+ROLLBACK;
+
+--connection con6
+ROLLBACK;
+
+--echo
+--echo # The connections 2 and 5 stay open.
+
+--echo
+--echo # Delete of row 1 was committed.
+--echo # Update of row 3 was committed.
+--echo # Due to isolation level read committed, these should be included.
+--echo # All other changes should not be included.
+--connection default
+SELECT * FROM bug_53756;
+
+START TRANSACTION;
+INSERT INTO bug_53756 VALUES (666,666);
+
+--let $shutdown_timeout=0
+--source include/restart_mysqld.inc
+--disconnect con1
+--disconnect con2
+--disconnect con3
+--disconnect con4
+--disconnect con5
+--disconnect con6
+
+--echo #
+--echo # Select recovered data.
+--echo # Delete of row 1 was committed.
+--echo # Update of row 3 was committed.
+--echo # These should be included.
+--echo # All other changes should not be included.
+--echo # Delete of row 2 and insert of row 5 should be rolled back
+SELECT * FROM bug_53756;
+
+DROP TABLE bug_53756;
diff --git a/mysql-test/suite/innodb/t/innodb_bug54044.test b/mysql-test/suite/innodb/t/innodb_bug54044.test
new file mode 100644
index 00000000..cfc6f3c3
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb_bug54044.test
@@ -0,0 +1,18 @@
+# This is the test for bug #54044. Special handle MYSQL_TYPE_NULL type
+# during create table, so it will not trigger assertion failure.
+
+--source include/have_innodb.inc
+
+# This 'create table' operation no longer uses the NULL datatype.
+
+CREATE TEMPORARY TABLE table_54044 ENGINE = INNODB
+ AS SELECT IF(NULL IS NOT NULL, NULL, NULL);
+SHOW CREATE TABLE table_54044;
+DROP TABLE table_54044;
+
+# This 'create table' should pass since it uses a Field_string of size 0.
+
+CREATE TABLE tmp ENGINE = INNODB
+ AS SELECT COALESCE(NULL, NULL, NULL), GREATEST(NULL, NULL), NULL;
+SHOW CREATE TABLE tmp;
+DROP TABLE tmp;
diff --git a/mysql-test/suite/innodb/t/innodb_bug56143.test b/mysql-test/suite/innodb/t/innodb_bug56143.test
new file mode 100644
index 00000000..fa04b2e4
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb_bug56143.test
@@ -0,0 +1,585 @@
+--source include/have_innodb.inc
+#
+# Bug#56143 too many foreign keys causes output of show create table to become invalid
+# http://bugs.mysql.com/56143
+#
+
+-- disable_query_log
+-- disable_result_log
+
+if ($VALGRIND_TEST)
+{
+ call mtr.add_suppression("InnoDB: Warning: a long semaphore wait:");
+}
+
+SET foreign_key_checks=0;
+
+DROP TABLE IF EXISTS bug56143_1;
+DROP TABLE IF EXISTS bug56143_2;
+
+CREATE TABLE bug56143_1 (a INT, KEY(a)) ENGINE=INNODB;
+
+CREATE TABLE `bug56143_2` (
+ `a` int(11) DEFAULT NULL,
+ KEY `a` (`a`),
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa1` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa10` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa100` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa101` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa102` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa103` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa104` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa105` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa106` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa107` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa108` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa109` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa11` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa110` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa111` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa112` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa113` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa114` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa115` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa116` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa117` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa118` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa119` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa12` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa120` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa121` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa122` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa123` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa124` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa125` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa126` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa127` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa128` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa129` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa13` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa130` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa131` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa132` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa133` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa134` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa135` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa136` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa137` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa138` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa139` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa14` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa140` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa141` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa142` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa143` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa144` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa145` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa146` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa147` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa148` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa149` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa15` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa150` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa151` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa152` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa153` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa154` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa155` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa156` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa157` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa158` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa159` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa16` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa160` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa161` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa162` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa163` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa164` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa165` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa166` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa167` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa168` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa169` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa17` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa170` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa171` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa172` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa173` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa174` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa175` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa176` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa177` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa178` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa179` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa18` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa180` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa181` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa182` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa183` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa184` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa185` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa186` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa187` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa188` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa189` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa19` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa190` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa191` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa192` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa193` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa194` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa195` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa196` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa197` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa198` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa199` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa2` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa20` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa200` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa201` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa202` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa203` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa204` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa205` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa206` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa207` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa208` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa209` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa21` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa210` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa211` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa212` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa213` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa214` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa215` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa216` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa217` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa218` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa219` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa22` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa220` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa221` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa222` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa223` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa224` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa225` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa226` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa227` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa228` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa229` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa23` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa230` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa231` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa232` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa233` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa234` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa235` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa236` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa237` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa238` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa239` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa24` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa240` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa241` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa242` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa243` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa244` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa245` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa246` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa247` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa248` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa249` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa25` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa250` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa251` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa252` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa253` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa254` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa255` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa256` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa257` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa258` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa259` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa26` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa260` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa261` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa262` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa263` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa264` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa265` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa266` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa267` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa268` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa269` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa27` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa270` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa271` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa272` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa273` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa274` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa275` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa276` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa277` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa278` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa279` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa28` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa280` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa281` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa282` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa283` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa284` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa285` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa286` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa287` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa288` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa289` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa29` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa290` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa291` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa292` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa293` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa294` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa295` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa296` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa297` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa298` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa299` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa3` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa30` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa300` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa301` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa302` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa303` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa304` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa305` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa306` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa307` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa308` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa309` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa31` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa310` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa311` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa312` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa313` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa314` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa315` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa316` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa317` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa318` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa319` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa32` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa320` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa321` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa322` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa323` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa324` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa325` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa326` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa327` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa328` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa329` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa33` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa330` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa331` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa332` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa333` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa334` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa335` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa336` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa337` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa338` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa339` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa34` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa340` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa341` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa342` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa343` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa344` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa345` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa346` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa347` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa348` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa349` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa35` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa350` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa351` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa352` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa353` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa354` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa355` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa356` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa357` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa358` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa359` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa36` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa360` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa361` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa362` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa363` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa364` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa365` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa366` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa367` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa368` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa369` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa37` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa370` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa371` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa372` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa373` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa374` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa375` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa376` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa377` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa378` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa379` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa38` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa380` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa381` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa382` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa383` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa384` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa385` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa386` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa387` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa388` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa389` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa39` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa390` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa391` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa392` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa393` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa394` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa395` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa396` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa397` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa398` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa399` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa4` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa40` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa400` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa401` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa402` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa403` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa404` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa405` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa406` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa407` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa408` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa409` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa41` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa410` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa411` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa412` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa413` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa414` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa415` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa416` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa417` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa418` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa419` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa42` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa420` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa421` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa422` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa423` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa424` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa425` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa426` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa427` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa428` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa429` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa43` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa430` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa431` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa432` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa433` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa434` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa435` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa436` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa437` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa438` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa439` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa44` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa440` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa441` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa442` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa443` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa444` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa445` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa446` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa447` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa448` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa449` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa45` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa450` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa451` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa452` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa453` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa454` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa455` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa456` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa457` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa458` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa459` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa46` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa460` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa461` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa462` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa463` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa464` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa465` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa466` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa467` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa468` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa469` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa47` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa470` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa471` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa472` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa473` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa474` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa475` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa476` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa477` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa478` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa479` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa48` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa480` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa481` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa482` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa483` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa484` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa485` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa486` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa487` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa488` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa489` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa49` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa490` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa491` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa492` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa493` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa494` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa495` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa496` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa497` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa498` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa499` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa5` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa50` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa500` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa501` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa502` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa503` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa504` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa505` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa506` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa507` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa508` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa509` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa51` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa510` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa511` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa512` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa513` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa514` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa515` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa516` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa517` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa518` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa519` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa52` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa520` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa521` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa522` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa523` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa524` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa525` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa526` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa527` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa528` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa529` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa53` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa530` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa531` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa532` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa533` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa534` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa535` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa536` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa537` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa538` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa539` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa54` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa540` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa541` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa542` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa543` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa544` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa545` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa546` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa547` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa548` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa549` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa55` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa550` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa56` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa57` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa58` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa59` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa6` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa60` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa61` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa62` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa63` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa64` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa65` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa66` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa67` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa68` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa69` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa7` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa70` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa71` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa72` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa73` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa74` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa75` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa76` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa77` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa78` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa79` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa8` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa80` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa81` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa82` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa83` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa84` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa85` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa86` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa87` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa88` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa89` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa9` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa90` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa91` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa92` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa93` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa94` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa95` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa96` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa97` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa98` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL,
+ CONSTRAINT `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa99` FOREIGN KEY (`a`) REFERENCES `bug56143_1` (`a`) ON UPDATE SET NULL
+) ENGINE=InnoDB;
+
+-- enable_query_log
+-- enable_result_log
+
+SHOW CREATE TABLE bug56143_2;
+
+-- disable_query_log
+-- disable_result_log
+DROP TABLE bug56143_1;
+DROP TABLE bug56143_2;
diff --git a/mysql-test/suite/innodb/t/innodb_bug56716.test b/mysql-test/suite/innodb/t/innodb_bug56716.test
new file mode 100644
index 00000000..47fdac3e
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb_bug56716.test
@@ -0,0 +1,9 @@
+--source include/have_innodb.inc
+#
+# Bug #56716 InnoDB locks a record gap without locking the table
+#
+CREATE TABLE bug56716 (a INT PRIMARY KEY,b INT,c INT,INDEX(b)) ENGINE=InnoDB;
+
+SELECT * FROM bug56716 WHERE b<=42 ORDER BY b DESC FOR UPDATE;
+
+DROP TABLE bug56716;
diff --git a/mysql-test/suite/innodb/t/innodb_bug56947.test b/mysql-test/suite/innodb/t/innodb_bug56947.test
new file mode 100644
index 00000000..ce64f1a8
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb_bug56947.test
@@ -0,0 +1,19 @@
+#
+# Bug #56947 valgrind reports a memory leak in innodb-plugin.innodb-index
+#
+-- source include/have_innodb.inc
+-- source include/have_debug.inc
+
+SET GLOBAL innodb_file_per_table=0;
+create table bug56947(a int not null) engine = innodb;
+
+SET @saved_dbug = @@SESSION.debug_dbug;
+SET DEBUG_DBUG='+d,ib_rebuild_cannot_rename';
+--replace_regex /"[^"]*"/"xxx"/
+--error ER_GET_ERRNO
+alter table bug56947 add unique index (a);
+check table bug56947;
+
+drop table bug56947;
+SET @@global.innodb_file_per_table=DEFAULT;
+SET debug_dbug= @saved_dbug;
diff --git a/mysql-test/suite/innodb/t/innodb_bug57252.test b/mysql-test/suite/innodb/t/innodb_bug57252.test
new file mode 100644
index 00000000..eafcaee1
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb_bug57252.test
@@ -0,0 +1,45 @@
+--source include/have_innodb.inc
+#
+# Bug#57252 disabling innobase_stats_on_metadata disables ANALYZE
+# http://bugs.mysql.com/57252
+#
+
+-- disable_query_log
+-- disable_result_log
+
+SET @innodb_stats_on_metadata_orig = @@innodb_stats_on_metadata;
+
+CREATE TABLE bug57252 (a INT, KEY akey (a)) ENGINE=INNODB STATS_PERSISTENT=0;
+
+BEGIN;
+let $i = 10;
+while ($i) {
+ eval INSERT INTO bug57252 VALUES ($i);
+ dec $i;
+}
+COMMIT;
+
+-- enable_result_log
+
+SET GLOBAL innodb_stats_on_metadata=0;
+
+# this calls ::info() without HA_STATUS_CONST and so
+# index->stat_n_diff_key_vals[] is not copied to the mysql-visible
+# rec_per_key
+SELECT cardinality FROM information_schema.statistics
+WHERE table_name='bug57252' AND index_name='akey';
+
+# this calls ::info() with HA_STATUS_CONST and so
+# index->stat_n_diff_key_vals[] is copied to the mysql-visible
+# rec_per_key at the end; when the bug is present dict_update_statistics()
+# is not called beforehand and so index->stat_n_diff_key_vals[] contains
+# an outdated data and thus we get an outdated data in the result when the
+# bug is present
+ANALYZE TABLE bug57252;
+
+SELECT cardinality FROM information_schema.statistics
+WHERE table_name='bug57252' AND index_name='akey';
+
+DROP TABLE bug57252;
+
+SET GLOBAL innodb_stats_on_metadata = @innodb_stats_on_metadata_orig;
diff --git a/mysql-test/suite/innodb/t/innodb_bug57255.test b/mysql-test/suite/innodb/t/innodb_bug57255.test
new file mode 100644
index 00000000..cf7982a6
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb_bug57255.test
@@ -0,0 +1,38 @@
+--source include/have_innodb.inc
+# Test Bug #57255. Cascade deletes that affect different rows should not
+# result in DB_FOREIGN_EXCEED_MAX_CASCADE error
+
+
+create table A(id int not null primary key) engine=innodb;
+
+create table B(id int not null auto_increment primary key, f1 int not null, foreign key(f1) references A(id) on delete cascade) engine=innodb;
+
+create table C(id int not null auto_increment primary key, f1 int not null, foreign key(f1) references B(id) on delete cascade) engine=innodb;
+
+insert into A values(1), (2);
+
+--disable_query_log
+begin;
+let $i=257;
+while ($i)
+{
+insert into B(f1) values(1);
+dec $i;
+}
+let $i=486;
+while ($i)
+{
+insert into C(f1) values(2);
+dec $i;
+}
+commit;
+--enable_query_log
+
+# Following Deletes should not report error
+DELETE FROM A where id = 1;
+DELETE FROM C where f1 = 2;
+DELETE FROM A where id = 1;
+
+DROP TABLE C;
+DROP TABLE B;
+DROP TABLE A;
diff --git a/mysql-test/suite/innodb/t/innodb_bug57904.test b/mysql-test/suite/innodb/t/innodb_bug57904.test
new file mode 100644
index 00000000..97e7ec93
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb_bug57904.test
@@ -0,0 +1,27 @@
+--source include/have_innodb.inc
+#
+# Bug #57904 Missing constraint from information schema REFERENTIAL_CONSTRAINTS table
+#
+CREATE TABLE product (category INT NOT NULL, id INT NOT NULL,
+ price DECIMAL, PRIMARY KEY(category, id)) ENGINE=INNODB;
+CREATE TABLE customer (id INT NOT NULL, PRIMARY KEY (id)) ENGINE=INNODB;
+CREATE TABLE product_order (no INT NOT NULL AUTO_INCREMENT,
+ product_category INT NOT NULL,
+ product_id INT NOT NULL,
+ customer_id INT NOT NULL,
+ PRIMARY KEY(no),
+ INDEX (product_category, product_id),
+ FOREIGN KEY (product_category, product_id)
+ REFERENCES product(category, id) ON UPDATE CASCADE ON DELETE RESTRICT,
+ INDEX (customer_id),
+ FOREIGN KEY (customer_id)
+ REFERENCES customer(id)
+ ) ENGINE=INNODB;
+
+query_vertical SELECT * FROM INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS
+WHERE table_name = 'product_order';
+
+DROP TABLE product_order;
+DROP TABLE product;
+DROP TABLE customer;
+
diff --git a/mysql-test/suite/innodb/t/innodb_bug59307.test b/mysql-test/suite/innodb/t/innodb_bug59307.test
new file mode 100644
index 00000000..c89050b9
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb_bug59307.test
@@ -0,0 +1,32 @@
+-- source include/have_innodb.inc
+# Bug #59307 uninitialized value in rw_lock_set_writer_id_and_recursion_flag()
+# when Valgrind instrumentation (HAVE_VALGRIND) is not enabled
+
+CREATE TABLE t1 (
+ t1_int INT,
+ t1_time TIME
+) ENGINE=innodb;
+
+CREATE TABLE t2 (
+ t2_int int PRIMARY KEY,
+ t2_int2 INT
+) ENGINE=INNODB;
+
+INSERT IGNORE INTO t2 VALUES ();
+INSERT INTO t1 VALUES ();
+
+SELECT *
+FROM t1 AS t1a
+WHERE NOT EXISTS
+ (SELECT *
+ FROM t1 AS t1b
+ WHERE t1b.t1_int NOT IN
+ (SELECT t2.t2_int
+ FROM t2
+ WHERE t1b.t1_time LIKE t1b.t1_int
+ OR t1b.t1_time <> t2.t2_int2
+ AND 6=7
+ )
+)
+;
+DROP TABLE t1,t2;
diff --git a/mysql-test/suite/innodb/t/innodb_bug59410.test b/mysql-test/suite/innodb/t/innodb_bug59410.test
new file mode 100644
index 00000000..30bb0642
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb_bug59410.test
@@ -0,0 +1,24 @@
+#
+# Bug#59410 read uncommitted: unlock row could not find a 3 mode lock on the record
+#
+-- source include/have_innodb.inc
+
+# only interested that the following do not produce something like
+# InnoDB: Error: unlock row could not find a 2 mode lock on the record
+# in the error log
+
+create table `bug59410_1`(`a` int)engine=innodb;
+insert into `bug59410_1` values (1),(2),(3);
+select 1 from `bug59410_1` where `a` <> any (
+select 1 from `bug59410_1` where `a` <> 1 for update)
+for update;
+drop table bug59410_1;
+
+create table bug59410_2(`a` char(1),`b` int)engine=innodb;
+insert into bug59410_2 values('0',0);
+set transaction isolation level read uncommitted;
+start transaction;
+set @a=(select b from bug59410_2 where
+(select 1 from bug59410_2 where a group by @a=b)
+group by @a:=b);
+drop table bug59410_2;
diff --git a/mysql-test/suite/innodb/t/innodb_bug59641.test b/mysql-test/suite/innodb/t/innodb_bug59641.test
new file mode 100644
index 00000000..36001133
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb_bug59641.test
@@ -0,0 +1,58 @@
+--source include/have_innodb.inc
+# Bug #59641 Prepared XA transaction causes shutdown hang after a crash
+
+-- source include/not_embedded.inc
+
+--disable_query_log
+call mtr.add_suppression("Found 3 prepared XA transactions");
+FLUSH TABLES;
+--enable_query_log
+
+CREATE TABLE t(a INT PRIMARY KEY, b INT)ENGINE=InnoDB;
+INSERT INTO t VALUES(2,2),(4,4),(8,8),(16,16),(32,32);
+COMMIT;
+XA START '123';
+INSERT INTO t VALUES(1,1);
+XA END '123';
+XA PREPARE '123';
+
+CONNECT (con1,localhost,root,,);
+
+XA START '456';
+INSERT INTO t VALUES(3,47),(5,67);
+UPDATE t SET b=2*b WHERE a BETWEEN 5 AND 8;
+XA END '456';
+XA PREPARE '456';
+
+CONNECT (con2,localhost,root,,);
+
+XA START '789';
+UPDATE t SET b=4*a WHERE a=32;
+XA END '789';
+XA PREPARE '789';
+
+CONNECT (con3,localhost,root,,);
+
+--let $shutdown_timeout=0
+--source include/restart_mysqld.inc
+SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED;
+--disable_ps2_protocol
+SELECT * FROM t;
+--enable_ps2_protocol
+COMMIT;
+
+--source include/restart_mysqld.inc
+
+SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED;
+--disable_ps2_protocol
+SELECT * FROM t;
+--enable_ps2_protocol
+COMMIT;
+--sorted_result
+XA RECOVER;
+XA ROLLBACK '123';
+XA ROLLBACK '456';
+XA COMMIT '789';
+SELECT * FROM t;
+
+DROP TABLE t;
diff --git a/mysql-test/suite/innodb/t/innodb_bug59733.test b/mysql-test/suite/innodb/t/innodb_bug59733.test
new file mode 100644
index 00000000..0b1bff51
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb_bug59733.test
@@ -0,0 +1,53 @@
+#
+# Bug #59733 Possible deadlock when buffered changes are to be discarded
+# in buf_page_create
+#
+-- source include/have_innodb.inc
+
+-- disable_query_log
+# The flag innodb_change_buffering_debug is only available in debug builds.
+# It instructs InnoDB to try to evict pages from the buffer pool when
+# change buffering is possible, so that the change buffer will be used
+# whenever possible.
+-- error 0,ER_UNKNOWN_SYSTEM_VARIABLE
+SET @innodb_change_buffering_debug_orig = @@innodb_change_buffering_debug;
+-- error 0,ER_UNKNOWN_SYSTEM_VARIABLE
+SET GLOBAL innodb_change_buffering_debug = 1;
+-- enable_query_log
+
+CREATE TABLE bug59733(a INT AUTO_INCREMENT PRIMARY KEY,b CHAR(1))ENGINE=InnoDB;
+
+# Create enough rows for the table, so that the insert buffer will be
+# used. There must be multiple index pages, because changes to the
+# root page are never buffered.
+
+INSERT INTO bug59733 VALUES(0,'x');
+INSERT INTO bug59733 SELECT 0,b FROM bug59733;
+INSERT INTO bug59733 SELECT 0,b FROM bug59733;
+INSERT INTO bug59733 SELECT 0,b FROM bug59733;
+INSERT INTO bug59733 SELECT 0,b FROM bug59733;
+INSERT INTO bug59733 SELECT 0,b FROM bug59733;
+INSERT INTO bug59733 SELECT 0,b FROM bug59733;
+INSERT INTO bug59733 SELECT 0,b FROM bug59733;
+INSERT INTO bug59733 SELECT 0,b FROM bug59733;
+INSERT INTO bug59733 SELECT 0,b FROM bug59733;
+INSERT INTO bug59733 SELECT 0,b FROM bug59733;
+INSERT INTO bug59733 SELECT 0,b FROM bug59733;
+
+# Create the secondary index for which changes will be buffered.
+CREATE INDEX b ON bug59733 (b);
+
+# This should be buffered, if innodb_change_buffering_debug = 1 is in effect.
+DELETE FROM bug59733 WHERE (a%100)=0;
+
+# Drop the index in order to get free pages with orphaned buffered changes.
+DROP INDEX b ON bug59733;
+
+# Create the index and attempt to reuse pages for which buffered changes exist.
+CREATE INDEX b ON bug59733 (b);
+
+DROP TABLE bug59733;
+
+-- disable_query_log
+-- error 0, ER_UNKNOWN_SYSTEM_VARIABLE
+SET GLOBAL innodb_change_buffering_debug = @innodb_change_buffering_debug_orig;
diff --git a/mysql-test/suite/innodb/t/innodb_bug60196-master.opt b/mysql-test/suite/innodb/t/innodb_bug60196-master.opt
new file mode 100644
index 00000000..ac4d3211
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb_bug60196-master.opt
@@ -0,0 +1 @@
+--lower-case-table-names=2
diff --git a/mysql-test/suite/innodb/t/innodb_bug60196.test b/mysql-test/suite/innodb/t/innodb_bug60196.test
new file mode 100644
index 00000000..7f1f5c40
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb_bug60196.test
@@ -0,0 +1,159 @@
+--source include/have_innodb.inc
+# Bug#60196 - Setting lowercase_table_names to 2 on Windows causing
+# Foreign Key problems after an engine is restarted.
+
+# This test case needs InnoDB, a lowercase file system,
+# lower-case-table-names=2, and cannot use the embedded server
+# because it restarts the server.
+--source include/not_embedded.inc
+--source include/have_lowercase2.inc
+--source include/have_case_insensitive_file_system.inc
+
+#
+# Create test data.
+#
+CREATE TABLE Bug_60196_FK1 (Primary_Key INT PRIMARY KEY) ENGINE=InnoDB;
+CREATE TABLE Bug_60196_FK2 (Primary_Key INT PRIMARY KEY) ENGINE=InnoDB;
+CREATE TABLE Bug_60196 (
+ FK1_Key INT NOT NULL,
+ FK2_Key INT NOT NULL,
+ PRIMARY KEY (FK2_Key, FK1_Key),
+ KEY FK1_Key (FK1_Key),
+ KEY FK2_Key (FK2_Key),
+ CONSTRAINT FK_FK1 FOREIGN KEY (FK1_Key)
+ REFERENCES Bug_60196_FK1 (Primary_Key)
+ ON DELETE CASCADE
+ ON UPDATE CASCADE,
+ CONSTRAINT FK_FK2 FOREIGN KEY (FK2_Key)
+ REFERENCES Bug_60196_FK2 (Primary_Key)
+ ON DELETE CASCADE
+ ON UPDATE CASCADE
+) ENGINE=InnoDB;
+INSERT INTO Bug_60196_FK1 VALUES (1), (2), (3), (4), (5);
+INSERT INTO Bug_60196_FK2 VALUES (1), (2), (3), (4), (5);
+INSERT INTO Bug_60196 VALUES (1, 1);
+INSERT INTO Bug_60196 VALUES (1, 2);
+INSERT INTO Bug_60196 VALUES (1, 3);
+--error ER_NO_REFERENCED_ROW_2
+INSERT INTO Bug_60196 VALUES (1, 99);
+--error ER_NO_REFERENCED_ROW_2
+INSERT INTO Bug_60196 VALUES (99, 1);
+
+SELECT * FROM bug_60196_FK1;
+SELECT * FROM bug_60196_FK2;
+--sorted_result
+SELECT * FROM bug_60196;
+
+--echo # Stop server
+
+# Write file to make mysql-test-run.pl wait for the server to stop
+-- exec echo "wait" > $MYSQLTEST_VARDIR/tmp/mysqld.1.expect
+
+# Send a shutdown request to the server
+-- shutdown_server
+
+# Call script that will poll the server waiting for it to disapear
+-- source include/wait_until_disconnected.inc
+
+--echo # Restart server.
+
+# Write file to make mysql-test-run.pl start up the server again
+--exec echo "restart" > $MYSQLTEST_VARDIR/tmp/mysqld.1.expect
+
+# Turn on reconnect
+--enable_reconnect
+
+# Call script that will poll the server waiting for it to be back online again
+--source include/wait_until_connected_again.inc
+
+# Turn off reconnect again
+--disable_reconnect
+
+--echo #
+--echo # Try to insert more to the example table with foreign keys.
+--echo # Bug60196 causes the foreign key file not to be found after
+--echo # the resstart above.
+--echo #
+SELECT * FROM Bug_60196;
+INSERT INTO Bug_60196 VALUES (2, 1);
+INSERT INTO Bug_60196 VALUES (2, 2);
+INSERT INTO Bug_60196 VALUES (2, 3);
+--sorted_result
+SELECT * FROM Bug_60196;
+
+--echo
+--echo # Clean up.
+DROP TABLE Bug_60196;
+DROP TABLE Bug_60196_FK1;
+DROP TABLE Bug_60196_FK2;
+
+
+# Bug#60309/12356829
+# MYSQL 5.5.9 FOR MAC OSX HAS BUG WITH FOREIGN KEY CONSTRAINTS
+# This testcase is different from that for Bug#60196 in that the
+# referenced table contains a secondary key. When the engine is
+# restarted, the referenced table is opened by the purge thread,
+# which does not notice that lower_case_table_names == 2.
+
+#
+# Create test data.
+#
+CREATE TABLE Bug_60309_FK (
+ ID INT PRIMARY KEY,
+ ID2 INT,
+ KEY K2(ID2)
+) ENGINE=InnoDB;
+CREATE TABLE Bug_60309 (
+ ID INT PRIMARY KEY,
+ FK_ID INT,
+ KEY (FK_ID),
+ CONSTRAINT FK FOREIGN KEY (FK_ID) REFERENCES Bug_60309_FK (ID)
+) ENGINE=InnoDB;
+
+INSERT INTO Bug_60309_FK (ID, ID2) VALUES (1, 1), (2, 2), (3, 3);
+INSERT INTO Bug_60309 VALUES (1, 1);
+--error ER_NO_REFERENCED_ROW_2
+INSERT INTO Bug_60309 VALUES (2, 99);
+
+SELECT * FROM Bug_60309_FK;
+SELECT * FROM Bug_60309;
+
+--echo # Stop server
+
+# Write file to make mysql-test-run.pl wait for the server to stop
+-- exec echo "wait" > $MYSQLTEST_VARDIR/tmp/mysqld.1.expect
+
+# Send a shutdown request to the server
+-- shutdown_server
+
+# Call script that will poll the server waiting for it to disapear
+-- source include/wait_until_disconnected.inc
+
+--echo # Restart server.
+
+# Write file to make mysql-test-run.pl start up the server again
+--exec echo "restart" > $MYSQLTEST_VARDIR/tmp/mysqld.1.expect
+
+# Turn on reconnect
+--enable_reconnect
+
+# Call script that will poll the server waiting for it to be back online again
+--source include/wait_until_connected_again.inc
+
+# Turn off reconnect again
+--disable_reconnect
+
+--echo #
+--echo # Try to insert more to the example table with foreign keys.
+--echo # Bug60309 causes the foreign key file not to be found after
+--echo # the resstart above.
+--echo #
+SELECT * FROM Bug_60309;
+INSERT INTO Bug_60309 VALUES (2, 2);
+INSERT INTO Bug_60309 VALUES (3, 3);
+SELECT * FROM Bug_60309;
+
+--echo
+--echo # Clean up.
+DROP TABLE Bug_60309;
+DROP TABLE Bug_60309_FK;
diff --git a/mysql-test/suite/innodb/t/innodb_bug60229.test b/mysql-test/suite/innodb/t/innodb_bug60229.test
new file mode 100644
index 00000000..aee0b96a
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb_bug60229.test
@@ -0,0 +1,43 @@
+#
+# Bug #13083023 - 60229: BROKEN COMPATIBILITY: ERROR WHILE CREATE TABLE
+# WITH FOREIGN KEY CONSTRAINT.
+
+#Server variable option 'lower_case_table_names' sets '0' as default value
+#in case sensitive filesystem. Using 'lower_case_table_names=0' in case of
+#insensitive filsystem is not allowed.
+-- source include/have_case_sensitive_file_system.inc
+-- source include/have_innodb.inc
+
+CREATE TABLE PERSON (
+ PERSON_ID VARCHAR(50) NOT NULL,
+ DOB VARCHAR(50) NOT NULL,
+ NAME NVARCHAR(255) NOT NULL,
+ CONSTRAINT PK_PERSON PRIMARY KEY (PERSON_ID, DOB)
+)Engine=InnoDB;
+
+
+CREATE TABLE PHOTO (
+ PERSON_ID VARCHAR(50) NOT NULL,
+ DOB VARCHAR(50) NOT NULL,
+ PHOTO_DETAILS VARCHAR(50) NULL,
+ CONSTRAINT PK_PHOTO PRIMARY KEY (PERSON_ID, DOB),
+ CONSTRAINT FK_PHOTO_2_PERSON FOREIGN KEY (PERSON_ID, DOB) REFERENCES PERSON (PERSON_ID, DOB)
+)Engine=InnoDB;
+
+
+CREATE TABLE ADDRESS (
+ PERSON_ID VARCHAR(50) NOT NULL,
+ DOB VARCHAR(50) NOT NULL,
+ ADDRESS_ID VARCHAR(50) NOT NULL,
+ ADDRESS_DETAILS NVARCHAR(250) NULL,
+ CONSTRAINT PK_ADDRESS PRIMARY KEY (PERSON_ID, DOB, ADDRESS_ID),
+ CONSTRAINT FK_ADDRESS_2_PERSON FOREIGN KEY (PERSON_ID, DOB) REFERENCES PERSON (PERSON_ID, DOB) ON DELETE CASCADE
+)Engine=InnoDB;
+
+INSERT INTO PERSON VALUES("10", "11011999", "John");
+INSERT INTO PHOTO VALUES("10", "11011999", "new photo");
+
+DROP TABLE PHOTO;
+DROP TABLE ADDRESS;
+DROP TABLE PERSON;
+
diff --git a/mysql-test/suite/innodb/t/innodb_bug68148.test b/mysql-test/suite/innodb/t/innodb_bug68148.test
new file mode 100644
index 00000000..ab4e0311
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb_bug68148.test
@@ -0,0 +1,38 @@
+-- source include/have_innodb.inc
+-- source include/not_embedded.inc
+
+#
+# Bug #68148: drop index on a foreign key column leads to missing table
+# MDEV-8845: Table disappear after modifying FK
+#
+
+set global innodb_file_per_table=1;
+
+CREATE TABLE ref_table1 (id int(11) NOT NULL, PRIMARY KEY(id)) ENGINE=InnoDB;
+
+CREATE TABLE ref_table2 (id int(11) NOT NULL, PRIMARY KEY(id)) ENGINE=InnoDB;
+
+CREATE TABLE `main` (
+ `id` int(11) NOT NULL AUTO_INCREMENT,
+ `ref_id1` int(11) NOT NULL,
+ `ref_id2` int(11) NOT NULL,
+ PRIMARY KEY (`id`),
+ UNIQUE KEY `idx_1` (`ref_id1`,`ref_id2`),
+ KEY `FK_set_out_analysis_route_id` (`ref_id2`),
+ CONSTRAINT `FK_1` FOREIGN KEY (`ref_id1`) REFERENCES `ref_table1` (`id`) ,
+ CONSTRAINT `FK_2` FOREIGN KEY (`ref_id2`) REFERENCES `ref_table2` (`id`)
+) ENGINE=InnoDB;
+
+SET FOREIGN_KEY_CHECKS=0;
+
+DROP INDEX `idx_1` ON `main`;
+SHOW TABLES;
+
+--source include/restart_mysqld.inc
+
+ALTER TABLE `main` ADD INDEX `idx_1` (`ref_id1`);
+SHOW CREATE TABLE `main`;
+
+DROP TABLE main, ref_table1, ref_table2;
+
+
diff --git a/mysql-test/suite/innodb/t/innodb_bug84958.test b/mysql-test/suite/innodb/t/innodb_bug84958.test
new file mode 100644
index 00000000..d4159dcc
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb_bug84958.test
@@ -0,0 +1,93 @@
+--echo #
+--echo # Bug #84958 InnoDB's MVCC has O(N^2) behaviors
+--echo # https://bugs.mysql.com/bug.php?id=84958
+--echo #
+--echo # Set up the test with a procedure and a function.
+--echo #
+
+--source include/have_innodb.inc
+
+DELIMITER ~~;
+CREATE PROCEDURE insert_n(start int, end int)
+BEGIN
+ DECLARE i INT DEFAULT start;
+ WHILE i <= end do
+ INSERT INTO t1 VALUES (1, 2, 3) ON DUPLICATE KEY UPDATE c = i;
+ SET i = i + 1;
+ END WHILE;
+END~~
+
+CREATE FUNCTION num_pages_get()
+RETURNS INT
+BEGIN
+ DECLARE ret INT;
+ SELECT variable_value INTO ret
+ FROM information_schema.global_status
+ WHERE variable_name = 'innodb_buffer_pool_read_requests';
+ RETURN ret;
+END~~
+DELIMITER ;~~
+
+--echo #
+--echo # Create a table with one record in it and start an RR transaction
+--echo #
+CREATE TABLE t1 (a INT, b INT, c INT, PRIMARY KEY(a,b), KEY (b,c))
+ENGINE=InnoDB STATS_PERSISTENT=0;
+--source include/wait_all_purged.inc
+BEGIN;
+SELECT * FROM t1;
+
+--echo #
+--echo # Create 100 newer record versions in con2 and con3
+--echo #
+connect (con2, localhost, root,,);
+connection con2;
+BEGIN;
+INSERT INTO t1 VALUES (1, 2, 3) ON DUPLICATE KEY UPDATE c = NULL;
+--send CALL insert_n(1, 50);
+
+connect (con3, localhost, root,,);
+connection con3;
+BEGIN;
+--send CALL insert_n(51, 100);
+
+connection con2;
+reap;
+COMMIT;
+connection con3;
+reap;
+INSERT INTO t1 VALUES (1, 2, 1) ON DUPLICATE KEY UPDATE c = NULL;
+COMMIT;
+
+connection default;
+
+--echo #
+--echo # Connect to default and record how many pages were accessed
+--echo # when selecting the record using the secondary key.
+--echo #
+--let $wait_all_purged=2
+--source include/wait_all_purged.inc
+SET @num_pages_1 = num_pages_get();
+SELECT * FROM t1 force index (b);
+SET @num_pages_2= num_pages_get();
+
+SELECT IF(@num_pages_2 - @num_pages_1 < 5000, 'OK', @num_pages_2 - @num_pages_1) num_pages_diff;
+
+--echo #
+--echo # Commit and show the final record.
+--echo #
+SELECT * FROM t1;
+SELECT * FROM t1 force index (b);
+COMMIT;
+SELECT * FROM t1 force index (b);
+SELECT * FROM t1;
+CHECK TABLE t1;
+
+--echo #
+--echo # Cleanup
+--echo #
+disconnect con2;
+disconnect con3;
+DROP TABLE t1;
+DROP PROCEDURE insert_n;
+DROP FUNCTION num_pages_get;
diff --git a/mysql-test/suite/innodb/t/innodb_bulk_create_index.test b/mysql-test/suite/innodb/t/innodb_bulk_create_index.test
new file mode 100644
index 00000000..534b4de8
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb_bulk_create_index.test
@@ -0,0 +1,46 @@
+######## suite/innodb/t/innodb_bulk_create_index.test #####
+# #
+# Testcase for worklog WL#7277: InnoDB: Bulk Load for Create Index #
+# The basic idea of bulk load is to build an index from bottom up #
+# (also known as sorted index build). #
+# Earlier index was create by repeatedly inserting records #
+# Test scenario : #
+# - Run bulk create index on 10K rows #
+# - Run bulk create index on table with various row types #
+# - Run DML and SELECT after bulk index creation #
+# Creation: #
+# 2014-06-19 Implemented this test as part of WL#7277 #
+# #
+######################################################################
+
+-- source include/not_embedded.inc
+-- source include/innodb_page_size_small.inc
+-- source include/big_test.inc
+
+# Test Row Format: REDUNDANT.
+let $row_format = REDUNDANT;
+-- source suite/innodb/include/innodb_bulk_create_index.inc
+
+# Test Row Format: COMPACT.
+let $row_format = COMPACT;
+-- source suite/innodb/include/innodb_bulk_create_index.inc
+
+# Test Row Format: DYNAMIC.
+let $row_format = DYNAMIC;
+-- source suite/innodb/include/innodb_bulk_create_index.inc
+
+# Test Row Format: COMPRESSED.
+let $row_format = COMPRESSED;
+-- source suite/innodb/include/innodb_bulk_create_index.inc
+
+# Test Fill Factor: 10
+let $row_format = COMPACT;
+SET GLOBAL innodb_fill_factor=10;
+-- source suite/innodb/include/innodb_bulk_create_index.inc
+
+# Test Fill Factor: 50
+let $row_format = COMPACT;
+SET GLOBAL innodb_fill_factor=50;
+-- source suite/innodb/include/innodb_bulk_create_index.inc
+
+SET GLOBAL innodb_fill_factor=default;
diff --git a/mysql-test/suite/innodb/t/innodb_bulk_create_index_debug.test b/mysql-test/suite/innodb/t/innodb_bulk_create_index_debug.test
new file mode 100644
index 00000000..34c9336e
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb_bulk_create_index_debug.test
@@ -0,0 +1,24 @@
+#
+# wl#7277: InnoDB: Bulk Load for Create Index
+#
+
+# Test Restart & Crash Recovery.
+-- source include/big_test.inc
+-- source include/innodb_page_size_small.inc
+let $restart_noprint=2;
+
+# Test Row Format: REDUNDANT.
+let $row_format = REDUNDANT;
+-- source suite/innodb/include/innodb_bulk_create_index_debug.inc
+
+# Test Row Format: COMPACT.
+let $row_format = COMPACT;
+-- source suite/innodb/include/innodb_bulk_create_index_debug.inc
+
+# Test Row Format: DYNAMIC.
+let $row_format = DYNAMIC;
+-- source suite/innodb/include/innodb_bulk_create_index_debug.inc
+
+# Test Row Format: COMPRESSED.
+let $row_format = COMPRESSED;
+-- source suite/innodb/include/innodb_bulk_create_index_debug.inc
diff --git a/mysql-test/suite/innodb/t/innodb_bulk_create_index_flush.opt b/mysql-test/suite/innodb/t/innodb_bulk_create_index_flush.opt
new file mode 100644
index 00000000..c61abdef
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb_bulk_create_index_flush.opt
@@ -0,0 +1 @@
+--innodb-log-optimize-ddl \ No newline at end of file
diff --git a/mysql-test/suite/innodb/t/innodb_bulk_create_index_replication.test b/mysql-test/suite/innodb/t/innodb_bulk_create_index_replication.test
new file mode 100644
index 00000000..5b4eaae7
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb_bulk_create_index_replication.test
@@ -0,0 +1,182 @@
+######## suite/innodb/t/innodb_wl7277_1.test #####
+# #
+# Testcase for worklog WL#7277: InnoDB: Bulk Load for Create Index #
+# The basic idea of bulk load is to build an index from bottom up #
+# (also known as sorted index build). #
+# Earlier index was create by repeatedly inserting records #
+# Test scenario : #
+# - Run bulk create index on replication setup #
+# - Run bulk create on partitioned table and see its replictaed #
+# to slave #
+# Creation: #
+# 2014-06-19 Implemented this test as part of WL#7277 #
+# #
+######################################################################
+
+--source include/not_embedded.inc
+-- source include/have_innodb.inc
+-- source include/have_partition.inc
+-- source include/master-slave.inc
+
+-- connection master
+# Create Insert Procedure
+DELIMITER |;
+CREATE PROCEDURE populate_t1(load_even INT)
+BEGIN
+ DECLARE i int DEFAULT 1;
+
+ START TRANSACTION;
+ WHILE (i <= 100) DO
+ IF i%2 = 0 AND load_even = 1 THEN
+ INSERT INTO t1 VALUES (i, i, CONCAT('a', i));
+ END IF;
+ IF i%2 != 0 AND load_even != 1 THEN
+ INSERT INTO t1 VALUES (i, i, CONCAT('a', i));
+ END IF;
+ SET i = i + 1;
+ END WHILE;
+ COMMIT;
+END|
+DELIMITER ;|
+
+CREATE TABLE t1(
+ class INT,
+ id INT,
+ title VARCHAR(100)
+) ENGINE=InnoDB ;
+
+
+
+
+-- disable_query_log
+# Load half records
+CALL populate_t1(1);
+-- enable_query_log
+
+SELECT COUNT(*) FROM t1;
+
+/* Create index. */
+CREATE INDEX idx_id ON t1(id);
+
+CREATE INDEX idx_title ON t1(title);
+
+
+/* Select by index. */
+EXPLAIN SELECT * FROM t1 WHERE id = 10;
+EXPLAIN SELECT * FROM t1 WHERE title = 'a10';
+
+SELECT * FROM t1 WHERE id = 10;
+SELECT * FROM t1 WHERE title = 'a10';
+
+SELECT * FROM t1 WHERE id = 20;
+SELECT * FROM t1 WHERE title = 'a20';
+
+SELECT * FROM t1 WHERE id = 30;
+SELECT * FROM t1 WHERE title = 'a30';
+
+SELECT * FROM t1 WHERE id = 101;
+SELECT * FROM t1 WHERE title = 'a101';
+
+/*Insert/Update/Delete. */
+DELETE FROM t1 WHERE id < 40 AND id > 30;
+INSERT INTO t1 VALUES(38, 38, 'b38');
+UPDATE t1 SET title = CONCAT('b', id) WHERE id < 30 AND id > 20;
+
+SELECT * FROM t1 WHERE id = 28;
+SELECT * FROM t1 WHERE title = 'a28';
+SELECT * FROM t1 WHERE title = 'b28';
+
+SELECT * FROM t1 WHERE id = 38;
+SELECT * FROM t1 WHERE title = 'a38';
+SELECT * FROM t1 WHERE title = 'b38';
+
+SELECT * FROM t1 WHERE id = 101;
+SELECT * FROM t1 WHERE title = 'a101';
+
+-- disable_query_log
+# Load half records (follow up load)
+CALL populate_t1(0);
+-- enable_query_log
+SELECT COUNT(*) FROM t1;
+
+
+SELECT * FROM t1 WHERE id = 10;
+SELECT * FROM t1 WHERE title = 'a10';
+
+SELECT * FROM t1 WHERE id = 20;
+SELECT * FROM t1 WHERE title = 'a20';
+
+SELECT * FROM t1 WHERE id = 30;
+SELECT * FROM t1 WHERE title = 'a30';
+
+SELECT * FROM t1 WHERE id = 101;
+SELECT * FROM t1 WHERE title = 'a101';
+
+# Create partition table
+CREATE TABLE t_part (
+ class INT ,
+ id INT ,
+ title VARCHAR(30)
+ ) ENGINE=InnoDB
+ PARTITION BY RANGE(id)
+ SUBPARTITION BY KEY(id)
+ SUBPARTITIONS 4
+ (
+ PARTITION p0 VALUES LESS THAN (5000),
+ PARTITION p1 VALUES LESS THAN (MAXVALUE)
+ );
+INSERT INTO t_part SELECT * FROM t1;
+ALTER TABLE t_part ADD INDEX `idx` (class,id,title(10));
+
+SELECT * FROM t_part WHERE id = 10;
+SELECT * FROM t_part WHERE title = 'a10';
+
+SELECT * FROM t_part WHERE id = 20;
+SELECT * FROM t_part WHERE title = 'a20';
+
+SELECT * FROM t_part WHERE id = 30;
+SELECT * FROM t_part WHERE title = 'a30';
+
+SELECT * FROM t_part WHERE id = 101;
+SELECT * FROM t_part WHERE title = 'a101';
+
+
+--source include/sync_slave_sql_with_master.inc
+-- connection slave
+SHOW CREATE TABLE t1;
+SHOW CREATE TABLE t_part;
+SELECT COUNT(*) FROM t1;
+SELECT COUNT(*) FROM t_part;
+
+SELECT * FROM t1 WHERE id = 10;
+SELECT * FROM t1 WHERE title = 'a10';
+
+SELECT * FROM t1 WHERE id = 20;
+SELECT * FROM t1 WHERE title = 'a20';
+
+SELECT * FROM t1 WHERE id = 30;
+SELECT * FROM t1 WHERE title = 'a30';
+
+SELECT * FROM t1 WHERE id = 101;
+SELECT * FROM t1 WHERE title = 'a101';
+
+
+
+SELECT * FROM t_part WHERE id = 10;
+SELECT * FROM t_part WHERE title = 'a10';
+
+SELECT * FROM t_part WHERE id = 20;
+SELECT * FROM t_part WHERE title = 'a20';
+
+SELECT * FROM t_part WHERE id = 30;
+SELECT * FROM t_part WHERE title = 'a30';
+
+SELECT * FROM t_part WHERE id = 101;
+SELECT * FROM t_part WHERE title = 'a101';
+
+
+-- connection master
+DROP PROCEDURE populate_t1;
+DROP TABLE t1;
+DROP TABLE t_part;
+--source include/rpl_end.inc
diff --git a/mysql-test/suite/innodb/t/innodb_bulk_create_index_small.test b/mysql-test/suite/innodb/t/innodb_bulk_create_index_small.test
new file mode 100644
index 00000000..d04dd59f
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb_bulk_create_index_small.test
@@ -0,0 +1,148 @@
+#
+# wl#7277: InnoDB: Bulk Load for Create Index
+#
+
+-- source include/innodb_page_size_small.inc
+
+# Create Insert Procedure
+DELIMITER |;
+CREATE PROCEDURE populate_t1()
+BEGIN
+ DECLARE i int DEFAULT 1;
+
+ START TRANSACTION;
+ WHILE (i <= 1000) DO
+ INSERT INTO t1 VALUES (i, i, CONCAT('a', i));
+ SET i = i + 1;
+ END WHILE;
+ COMMIT;
+END|
+DELIMITER ;|
+
+SELECT @@innodb_fill_factor;
+
+# Test Compact Table
+CREATE TABLE t1(
+ class INT,
+ id INT,
+ title VARCHAR(100)
+) ENGINE=InnoDB ROW_FORMAT=COMPACT;
+
+-- disable_query_log
+CALL populate_t1();
+-- enable_query_log
+
+SELECT COUNT(*) FROM t1;
+
+/* Create index. */
+CREATE INDEX idx_id ON t1(id);
+
+CREATE INDEX idx_title ON t1(title);
+
+/* Check table. */
+CHECK TABLE t1;
+
+/* Select by index. */
+EXPLAIN SELECT * FROM t1 WHERE id = 10;
+EXPLAIN SELECT * FROM t1 WHERE title = 'a10';
+
+SELECT * FROM t1 WHERE id = 10;
+SELECT * FROM t1 WHERE title = 'a10';
+
+SELECT * FROM t1 WHERE id = 500;
+SELECT * FROM t1 WHERE title = 'a500';
+
+SELECT * FROM t1 WHERE id = 1000;
+SELECT * FROM t1 WHERE title = 'a1000';
+
+SELECT * FROM t1 WHERE id = 1010;
+SELECT * FROM t1 WHERE title = 'a1010';
+
+DROP TABLE t1;
+
+# Test Blob
+CREATE TABLE t1(
+ a INT PRIMARY KEY,
+ b TEXT,
+ c TEXT) ENGINE=InnoDB ROW_FORMAT=COMPACT;
+
+INSERT INTO t1 VALUES
+ (1, REPEAT('a',10000), 'a'),
+ (2, REPEAT('b',20000), 'b'),
+ (3, REPEAT('c',40000), 'c'),
+ (4, REPEAT('d',60000), 'd');
+
+ALTER TABLE t1 DROP COLUMN c;
+
+CHECK TABLE t1;
+
+SELECT CHAR_LENGTH(b) FROM t1 WHERE a=4975;
+
+DROP TABLE t1;
+
+SET GLOBAL innodb_file_per_table=default;
+
+# Test Compressed Table
+SET GLOBAL innodb_file_per_table=1;
+
+CREATE TABLE t1(
+ class INT,
+ id INT,
+ title VARCHAR(100)
+) ENGINE=InnoDB ROW_FORMAT=COMPRESSED KEY_BLOCK_SIZE=4;
+
+-- disable_query_log
+CALL populate_t1();
+-- enable_query_log
+
+SELECT COUNT(*) FROM t1;
+
+/* Create index. */
+CREATE INDEX idx_id ON t1(id);
+
+CREATE INDEX idx_title ON t1(title);
+
+/* Check table. */
+CHECK TABLE t1;
+
+/* Select by index. */
+EXPLAIN SELECT * FROM t1 WHERE id = 10;
+EXPLAIN SELECT * FROM t1 WHERE title = 'a10';
+
+SELECT * FROM t1 WHERE id = 10;
+SELECT * FROM t1 WHERE title = 'a10';
+
+SELECT * FROM t1 WHERE id = 500;
+SELECT * FROM t1 WHERE title = 'a500';
+
+SELECT * FROM t1 WHERE id = 1000;
+SELECT * FROM t1 WHERE title = 'a1000';
+
+SELECT * FROM t1 WHERE id = 1010;
+SELECT * FROM t1 WHERE title = 'a1010';
+
+DROP TABLE t1;
+
+# Test Compression & Blob
+CREATE TABLE t1(
+ a INT PRIMARY KEY,
+ b TEXT,
+ c TEXT) ENGINE=InnoDB ROW_FORMAT=COMPRESSED KEY_BLOCK_SIZE=4;
+
+INSERT INTO t1 VALUES
+ (1, REPEAT('a',10000), 'a'),
+ (2, REPEAT('b',20000), 'b'),
+ (3, REPEAT('c',40000), 'c'),
+ (4, REPEAT('d',60000), 'd');
+
+ALTER TABLE t1 DROP COLUMN c;
+
+CHECK TABLE t1;
+
+SELECT CHAR_LENGTH(b) FROM t1 WHERE a=4975;
+
+DROP TABLE t1;
+
+SET GLOBAL innodb_file_per_table=default;
+
+DROP PROCEDURE populate_t1;
diff --git a/mysql-test/suite/innodb/t/innodb_corrupt_bit.opt b/mysql-test/suite/innodb/t/innodb_corrupt_bit.opt
new file mode 100644
index 00000000..683a276d
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb_corrupt_bit.opt
@@ -0,0 +1 @@
+--innodb-encryption-threads=0
diff --git a/mysql-test/suite/innodb/t/innodb_corrupt_bit.test b/mysql-test/suite/innodb/t/innodb_corrupt_bit.test
new file mode 100644
index 00000000..f1fd7f3c
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb_corrupt_bit.test
@@ -0,0 +1,99 @@
+#
+# Test for persistent corrupt bit for corrupted index and table
+#
+-- source include/have_innodb.inc
+--source include/not_embedded.inc
+# This test needs debug server
+-- source include/have_debug.inc
+
+--disable_query_log
+call mtr.add_suppression("Flagged corruption of.* in table .* in .*");
+--enable_query_log
+
+set names utf8;
+
+CREATE TABLE corrupt_bit_test_ā(
+ a INT AUTO_INCREMENT PRIMARY KEY,
+ b CHAR(100),
+ c INT,
+ z INT,
+ INDEX idx(b))
+ENGINE=InnoDB STATS_PERSISTENT=0;
+
+INSERT INTO corrupt_bit_test_ā VALUES(0,'x',1, 1);
+
+CREATE UNIQUE INDEX idxā ON corrupt_bit_test_ā(c, b);
+
+CREATE UNIQUE INDEX idxē ON corrupt_bit_test_ā(z, b);
+
+SELECT * FROM corrupt_bit_test_ā;
+
+INSERT INTO corrupt_bit_test_ā SELECT 0,b,c+1,z+1 FROM corrupt_bit_test_ā;
+
+select count(*) from corrupt_bit_test_ā;
+
+# This will flag all secondary indexes corrupted
+SET @save_dbug = @@SESSION.debug_dbug;
+SET debug_dbug = '+d,dict_set_index_corrupted';
+check table corrupt_bit_test_ā;
+SET @@SESSION.debug_dbug = @save_dbug;
+
+# Cannot create new indexes while corrupted indexes exist
+--error ER_INDEX_CORRUPT
+CREATE INDEX idx3 ON corrupt_bit_test_ā(b, c);
+--error ER_INDEX_CORRUPT
+CREATE INDEX idx4 ON corrupt_bit_test_ā(b, z);
+
+# This selection intend to use the corrupted index. Expect to fail
+-- error ER_INDEX_CORRUPT
+select c from corrupt_bit_test_ā;
+
+-- error ER_INDEX_CORRUPT
+select z from corrupt_bit_test_ā;
+
+show warnings;
+
+# Since corrupted index is a secondary index, we only disable such
+# index and allow other DML to proceed
+insert into corrupt_bit_test_ā values (10001, "a", 20001, 20001);
+
+# This does not use the corrupted index, expect to succeed
+select * from corrupt_bit_test_ā use index(primary) where a = 10001;
+
+# Some more DMLs
+begin;
+insert into corrupt_bit_test_ā values (10002, "a", 20002, 20002);
+delete from corrupt_bit_test_ā where a = 10001;
+insert into corrupt_bit_test_ā values (10001, "a", 20001, 20001);
+rollback;
+
+drop index idxā on corrupt_bit_test_ā;
+
+check table corrupt_bit_test_ā;
+
+set names utf8;
+
+-- error ER_INDEX_CORRUPT
+select z from corrupt_bit_test_ā;
+
+# Drop the corrupted index
+drop index idxē on corrupt_bit_test_ā;
+
+# Cannot create new indexes while a corrupt index exists.
+--error ER_INDEX_CORRUPT
+CREATE INDEX idx3 ON corrupt_bit_test_ā(b, c);
+--error ER_INDEX_CORRUPT
+CREATE INDEX idx4 ON corrupt_bit_test_ā(b, z);
+
+drop index idx on corrupt_bit_test_ā;
+
+# Now that there exist no corrupted indexes, we can create new indexes.
+CREATE INDEX idx3 ON corrupt_bit_test_ā(b, c);
+CREATE INDEX idx4 ON corrupt_bit_test_ā(b, z);
+
+
+# Now select back to normal
+select z from corrupt_bit_test_ā limit 10;
+
+# Drop table
+drop table corrupt_bit_test_ā;
diff --git a/mysql-test/suite/innodb/t/innodb_ctype_big5.test b/mysql-test/suite/innodb/t/innodb_ctype_big5.test
new file mode 100644
index 00000000..551d6add
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb_ctype_big5.test
@@ -0,0 +1,25 @@
+--source include/have_innodb.inc
+--source include/have_big5.inc
+
+SET DEFAULT_STORAGE_ENGINE=InnoDB;
+
+--echo #
+--echo # Start of 10.2 tests
+--echo #
+
+--echo #
+--echo # MDEV-9711 NO PAD Collatons
+--echo #
+
+SET NAMES big5;
+let $coll='big5_chinese_nopad_ci';
+let $coll_pad='big5_chinese_ci';
+--source include/ctype_pad.inc
+
+let $coll='big5_nopad_bin';
+let $coll_pad='big5_bin';
+--source include/ctype_pad.inc
+
+--echo #
+--echo # End of 10.2 tests
+--echo #
diff --git a/mysql-test/suite/innodb/t/innodb_ctype_latin1.test b/mysql-test/suite/innodb/t/innodb_ctype_latin1.test
new file mode 100644
index 00000000..1eb9864f
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb_ctype_latin1.test
@@ -0,0 +1,25 @@
+--source include/have_innodb.inc
+
+SET DEFAULT_STORAGE_ENGINE=InnoDB;
+
+--echo #
+--echo # Start of 10.2 tests
+--echo #
+
+--echo #
+--echo # MDEV-9711 NO PAD Collatons
+--echo #
+
+SET NAMES latin1;
+
+let $coll='latin1_swedish_nopad_ci';
+let $coll_pad='latin1_swedish_ci';
+--source include/ctype_pad.inc
+
+let $coll='latin1_nopad_bin';
+let $coll_pad='latin1_bin';
+--source include/ctype_pad.inc
+
+--echo #
+--echo # End of 10.2 tests
+--echo #
diff --git a/mysql-test/suite/innodb/t/innodb_ctype_ldml-master.opt b/mysql-test/suite/innodb/t/innodb_ctype_ldml-master.opt
new file mode 100644
index 00000000..25eed3eb
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb_ctype_ldml-master.opt
@@ -0,0 +1,3 @@
+--character-sets-dir=$MYSQL_TEST_DIR/std_data/ldml/
+--default-storage-engine=InnoDB
+
diff --git a/mysql-test/suite/innodb/t/innodb_ctype_ldml.test b/mysql-test/suite/innodb/t/innodb_ctype_ldml.test
new file mode 100644
index 00000000..90e7f89d
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb_ctype_ldml.test
@@ -0,0 +1,370 @@
+--source include/have_innodb.inc
+--source include/have_ucs2.inc
+--source include/have_utf8mb4.inc
+--source include/have_utf16.inc
+--source include/have_utf32.inc
+
+--disable_warnings
+drop table if exists t1;
+--enable_warnings
+
+# Index.xml has some intentional errors in collation definitions.
+# They are reported to the server error log. Let's suppress them.
+--disable_query_log
+call mtr.add_suppression("Syntax error at '\\[strength tertiary\\]'");
+call mtr.add_suppression("Can't reset before a primary ignorable character U\\+A48C");
+call mtr.add_suppression("Charset id.*trying to replace");
+--enable_query_log
+
+--echo In the following tests we change the order of letter "b"
+--echo making it equal to letter "a", and check that it works
+--echo with all Unicode character sets
+set names utf8;
+
+--replace_result $MYSQL_TEST_DIR MYSQL_TEST_DIR
+show variables like 'character_sets_dir%';
+
+show collation like 'utf8mb3_phone_ci';
+CREATE TABLE t1 (
+ name VARCHAR(64),
+ phone VARCHAR(64) CHARACTER SET utf8 COLLATE utf8_phone_ci
+);
+INSERT INTO t1 VALUES ('Svoj','+7 912 800 80 02');
+INSERT INTO t1 VALUES ('Hf','+7 (912) 800 80 04');
+INSERT INTO t1 VALUES ('Bar','+7-912-800-80-01');
+INSERT INTO t1 VALUES ('Ramil','(7912) 800 80 03');
+INSERT INTO t1 VALUES ('Sanja','+380 (912) 8008005');
+SELECT * FROM t1 ORDER BY phone;
+SELECT * FROM t1 WHERE phone='+7(912)800-80-01';
+SELECT * FROM t1 WHERE phone='79128008001';
+SELECT * FROM t1 WHERE phone='7 9 1 2 8 0 0 8 0 0 1';
+DROP TABLE t1;
+
+show collation like 'utf8mb3_test_ci';
+create table t1 (c1 char(1) character set utf8 collate utf8_test_ci);
+insert into t1 values ('a');
+select * from t1 where c1='b';
+drop table t1;
+
+show collation like 'ucs2_test_ci';
+create table t1 (c1 char(1) character set ucs2 collate ucs2_test_ci);
+insert into t1 values ('a');
+select * from t1 where c1='b';
+drop table t1;
+
+show collation like 'utf8mb4_test_ci';
+create table t1 (c1 char(1) character set utf8mb4 collate utf8mb4_test_ci);
+insert into t1 values ('a');
+select * from t1 where c1='b';
+drop table t1;
+
+show collation like 'utf16_test_ci';
+create table t1 (c1 char(1) character set utf16 collate utf16_test_ci);
+insert into t1 values ('a');
+select * from t1 where c1='b';
+drop table t1;
+
+show collation like 'utf32_test_ci';
+create table t1 (c1 char(1) character set utf32 collate utf32_test_ci);
+insert into t1 values ('a');
+select * from t1 where c1='b';
+drop table t1;
+
+###
+### TODO: activate this when utf8_unicode_520_ci is merged
+###
+### 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));
+
+
+--echo #
+--echo # Bug#45645 Mysql server close all connection and restart using lower function
+--echo #
+CREATE TABLE t1 (a VARCHAR(10)) CHARACTER SET utf8 COLLATE utf8_test_ci;
+INSERT INTO t1 (a) VALUES ('hello!');
+SELECT * FROM t1 WHERE LOWER(a)=LOWER('N');
+DROP TABLE t1;
+
+--echo #
+--echo # Bug#51976 LDML collations issue (cyrillic example)
+--echo #
+CREATE TABLE t1 (a VARCHAR(10) CHARACTER SET utf8 COLLATE utf8_test_ci);
+INSERT INTO t1 (a) VALUES ('Hello');
+SELECT a, UPPER(a), LOWER(a) FROM t1;
+DROP TABLE t1;
+
+--echo #
+--echo # Bug#43827 Server closes connections and restarts
+--echo #
+# Crash happened with a user-defined utf8 collation,
+# on attempt to insert a string longer than the column can store.
+CREATE TABLE t1 (c1 VARCHAR(10) CHARACTER SET utf8 COLLATE utf8_test_ci);
+INSERT IGNORE INTO t1 SELECT REPEAT('a',11);
+DROP TABLE t1;
+
+#
+# Vietnamese experimental collation
+#
+--echo Vietnamese experimental collation
+
+show collation like 'ucs2_vn_ci';
+create table t1 (c1 char(1) character set ucs2 collate ucs2_vn_ci);
+insert into t1 values (0x0061),(0x0041),(0x00E0),(0x00C0),(0x1EA3),(0x1EA2),
+ (0x00E3),(0x00C3),(0x00E1),(0x00C1),(0x1EA1),(0x1EA0);
+insert into t1 values (0x0103),(0x0102),(0x1EB1),(0x1EB0),(0x1EB3),(0x1EB2),
+ (0x1EB5),(0x1EB4),(0x1EAF),(0x1EAE),(0x1EB7),(0x1EB6);
+insert into t1 values (0x00E2),(0x00C2),(0x1EA7),(0x1EA6),(0x1EA9),(0x1EA8),
+ (0x1EAB),(0x1EAA),(0x1EA5),(0x1EA4),(0x1EAD),(0x1EAC);
+insert into t1 values ('b'),('B'),('c'),('C');
+insert into t1 values ('d'),('D'),(0x0111),(0x0110);
+insert into t1 values (0x0065),(0x0045),(0x00E8),(0x00C8),(0x1EBB),(0x1EBA),
+ (0x1EBD),(0x1EBC),(0x00E9),(0x00C9),(0x1EB9),(0x1EB8);
+insert into t1 values (0x00EA),(0x00CA),(0x1EC1),(0x1EC0),(0x1EC3),(0x1EC2),
+ (0x1EC5),(0x1EC4),(0x1EBF),(0x1EBE),(0x1EC7),(0x1EC6);
+insert into t1 values ('g'),('G'),('h'),('H');
+insert into t1 values (0x0069),(0x0049),(0x00EC),(0x00CC),(0x1EC9),(0x1EC8),
+ (0x0129),(0x0128),(0x00ED),(0x00CD),(0x1ECB),(0x1ECA);
+insert into t1 values ('k'),('K'),('l'),('L'),('m'),('M');
+insert into t1 values (0x006F),(0x004F),(0x00F2),(0x00D2),(0x1ECF),(0x1ECE),
+ (0x00F5),(0x00D5),(0x00F3),(0x00D3),(0x1ECD),(0x1ECC);
+insert into t1 values (0x00F4),(0x00D4),(0x1ED3),(0x1ED2),(0x1ED5),(0x1ED4),
+ (0x1ED7),(0x1ED6),(0x1ED1),(0x1ED0),(0x1ED9),(0x1ED8);
+insert into t1 values (0x01A1),(0x01A0),(0x1EDD),(0x1EDC),(0x1EDF),(0x1EDE),
+ (0x1EE1),(0x1EE0),(0x1EDB),(0x1EDA),(0x1EE3),(0x1EE2);
+insert into t1 values ('p'),('P'),('q'),('Q'),('r'),('R'),('s'),('S'),('t'),('T');
+insert into t1 values (0x0075),(0x0055),(0x00F9),(0x00D9),(0x1EE7),(0x1EE6),
+ (0x0169),(0x0168),(0x00FA),(0x00DA),(0x1EE5),(0x1EE4);
+insert into t1 values (0x01B0),(0x01AF),(0x1EEB),(0x1EEA),(0x1EED),(0x1EEC),
+ (0x1EEF),(0x1EEE),(0x1EE9),(0x1EE8),(0x1EF1),(0x1EF0);
+insert into t1 values ('v'),('V'),('x'),('X');
+insert into t1 values (0x0079),(0x0059),(0x1EF3),(0x1EF2),(0x1EF7),(0x1EF6),
+ (0x1EF9),(0x1EF8),(0x00FD),(0x00DD),(0x1EF5),(0x1EF4);
+select hex(c1) as h, c1 from t1 order by c1, h;
+select group_concat(hex(c1) order by hex(c1)) from t1 group by c1;
+select group_concat(c1 order by hex(c1) SEPARATOR '') from t1 group by c1;
+drop table t1;
+
+--echo Bug#46448 trailing spaces are not ignored when user collation maps space != 0x20
+set names latin1;
+show collation like 'latin1_test';
+select "foo" = "foo " collate latin1_test;
+
+-- echo The following tests check that two-byte collation IDs work
+# 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 and is_compiled<>'Yes' order by id;
+show collation like '%test%';
+
+# Test that two-byte collation ID is correctly transfered to the client side.
+show collation like 'ucs2_vn_ci';
+create table t1 (c1 char(1) character set ucs2 collate ucs2_vn_ci);
+
+show create table t1;
+
+insert into t1 values (0x0061);
+--enable_metadata
+set @@character_set_results=NULL;
+select * from t1;
+--disable_metadata
+drop table t1;
+
+#
+# Check maximum collation ID (2047 as of MySQL-6.0.9)
+#
+CREATE TABLE t1 (s1 char(10) character set utf8 collate utf8_maxuserid_ci);
+INSERT INTO t1 VALUES ('a'),('b');
+SELECT * FROM t1 WHERE s1='a' ORDER BY BINARY s1;
+DROP TABLE t1;
+
+
+#
+# Bug#47756 Setting 2byte collation ID with 'set names' crashes the server
+#
+SET NAMES utf8 COLLATE utf8_phone_ci;
+show collation like 'utf8mb3_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;
+
+--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');
+
+SELECT a, HEX(WEIGHT_STRING(a)) FROM t1 ORDER BY a, LENGTH(a), BINARY(a);
+DROP TABLE t1;
+
+
+--echo #
+--echo # End of WL#5624
+--echo #
diff --git a/mysql-test/suite/innodb/t/innodb_ctype_tis620.test b/mysql-test/suite/innodb/t/innodb_ctype_tis620.test
new file mode 100644
index 00000000..b0e9f42c
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb_ctype_tis620.test
@@ -0,0 +1,91 @@
+--source include/have_innodb.inc
+--source include/have_tis620.inc
+
+SET DEFAULT_STORAGE_ENGINE=InnoDB;
+
+--echo #
+--echo # Start of 10.2 tests
+--echo #
+
+--echo #
+--echo # MDEV-24901 SIGSEGV in fts_get_table_name, SIGSEGV in ib_vector_size, SIGSEGV in row_merge_fts_doc_tokenize, stack smashing Export
+--echo #
+
+CREATE TABLE t1(c TEXT CHARACTER SET tis620);
+SHOW CREATE TABLE t1;
+INSERT INTO t1 VALUES('100');
+ALTER TABLE t1 ADD FULLTEXT INDEX(c), ALGORITHM=INPLACE;
+DROP TABLE t1;
+
+CREATE TABLE t1(c TEXT CHARACTER SET tis620 COLLATE tis620_thai_nopad_ci);
+SHOW CREATE TABLE t1;
+INSERT INTO t1 VALUES('100');
+ALTER TABLE t1 ADD FULLTEXT INDEX(c), ALGORITHM=INPLACE;
+DROP TABLE t1;
+
+
+--echo #
+--echo # End of 10.2 tests
+--echo #
+
+--echo #
+--echo # Start of 10.4 tests
+--echo #
+
+--echo #
+--echo # MDEV-27670 Assertion `(cs->state & 0x20000) == 0' failed in my_strnncollsp_nchars_generic_8bit
+--echo #
+
+CREATE TABLE t1 (id INT PRIMARY KEY, a CHAR(8), KEY(a)) ENGINE=InnoDB COLLATE tis620_thai_nopad_ci;
+INSERT INTO t1 VALUES (1,'foo'),(2,'bar');
+DROP TABLE t1;
+
+--echo #
+--echo # MDEV-27768 MDEV-25440: Assertion `(cs->state & 0x20000) == 0' failed in my_strnncollsp_nchars_generic_8bit
+--echo #
+
+CREATE TABLE t1 (a INT KEY,b INT,c CHAR,KEY(b),KEY(c)) ROW_FORMAT=REDUNDANT COLLATE=tis620_thai_nopad_ci ENGINE=InnoDB;
+INSERT INTO t1 VALUES (3,4,4);
+DROP TABLE t1;
+
+CREATE TABLE t1 (C1 CHAR KEY,B1 BIT,B2 BIT,C2 CHAR DEFAULT'') ROW_FORMAT=DYNAMIC COLLATE=tis620_thai_nopad_ci ENGINE=InnoDB;
+SELECT HEX(c1),HEX (c2) FROM t1 WHERE c1>=''AND c1<''AND c2=''LIMIT 2;
+DROP TABLE t1;
+
+SET sql_mode='';
+CREATE TABLE t1 (a INT UNSIGNED,b INT,c CHAR(1),d BINARY (1),e VARCHAR(1),f VARBINARY(1),g BLOB,h BLOB,id INT,KEY(b),KEY(e)) ROW_FORMAT=REDUNDANT COLLATE=tis620_thai_nopad_ci ENGINE=InnoDB;
+INSERT INTO t1 VALUES (4386060749083099108,157,0,0,0,0,0,0,12);
+INSERT INTO t1 VALUES (104,15158706241929488558,0,0,0,0,0,0,13);
+SELECT GROUP_CONCAT(DISTINCT a,b ORDER BY c,b) FROM t1;
+DROP TABLE t1;
+SET sql_mode=DEFAULT;
+
+CREATE TABLE t1 (a CHAR(9),b CHAR(7)) COLLATE=tis620_thai_nopad_ci;
+INSERT INTO t1 VALUES (0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0);
+ALTER TABLE t1 ADD INDEX kb (b),ADD INDEX kab (a,b),ALGORITHM=INPLACE;
+DROP TABLE t1;
+
+SET sql_mode='';
+CREATE TABLE t1 (a INT UNSIGNED,b INT UNSIGNED,c CHAR(1),d CHAR(1),e VARCHAR(1),f VARCHAR(1),g BLOB,h BLOB,id INT,KEY(b),KEY(e)) ROW_FORMAT=REDUNDANT COLLATE=tis620_thai_nopad_ci;
+INSERT INTO t1 VALUES (15842995496588415350,5339224446865937973,0,0,0,0,0,0,4);
+INSERT INTO t1 VALUES (8118894032862615316,5299008984764990929,0,0,0,0,0,0,1);
+SELECT GROUP_CONCAT(DISTINCT a,c ORDER BY a) FROM t1;
+DROP TABLE t1;
+SET sql_mode=DEFAULT;
+
+CREATE TABLE t1 (a CHAR,b CHAR,KEY(a,b)) ROW_FORMAT=DYNAMIC COLLATE=tis620_thai_nopad_ci ENGINE=InnoDB;
+INSERT INTO t1 VALUES (0,0);
+DROP TABLE t1;
+
+CREATE TABLE t1 (a CHAR,b CHAR) COLLATE=tis620_thai_nopad_ci;
+INSERT INTO t1 VALUES (0,0);
+SELECT a,SUM(DISTINCT a),MIN(b) FROM t1 GROUP BY a;
+DROP TABLE t1;
+
+CREATE TABLE t1 (a CHAR,KEY(a)) ENGINE=InnoDB COLLATE=tis620_thai_nopad_ci;
+INSERT INTO t1 VALUES (0);
+DROP TABLE t1;
+
+--echo #
+--echo # End of 10.4 tests
+--echo #
diff --git a/mysql-test/suite/innodb/t/innodb_ctype_utf8.test b/mysql-test/suite/innodb/t/innodb_ctype_utf8.test
new file mode 100644
index 00000000..2e916baf
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb_ctype_utf8.test
@@ -0,0 +1,54 @@
+--source include/have_innodb.inc
+
+SET DEFAULT_STORAGE_ENGINE=InnoDB;
+
+--echo #
+--echo # Start of 10.2 tests
+--echo #
+
+--echo #
+--echo # MDEV-9711 NO PAD Collatons
+--echo #
+
+SET NAMES utf8;
+
+let $coll='utf8_general_nopad_ci';
+let $coll_pad='utf8_general_ci';
+--source include/ctype_pad.inc
+
+let $coll='utf8_nopad_bin';
+let $coll_pad='utf8_bin';
+--source include/ctype_pad.inc
+
+--echo #
+--echo # End of 10.2 tests
+--echo #
+
+
+--echo #
+--echo # Start of 10.4 tests
+--echo #
+
+SET NAMES utf8mb3 COLLATE utf8mb3_unicode_nopad_ci;
+--source include/ctype_nopad_prefix_unique.inc
+
+--source include/ctype_utf8mb3_uca_char.inc
+
+--echo #
+--echo # MDEV-30050 Inconsistent results of DISTINCT with NOPAD
+--echo #
+
+CREATE OR REPLACE TABLE t1 (c CHAR(100) COLLATE utf8mb3_unicode_nopad_ci);
+SHOW CREATE TABLE t1;
+INSERT INTO t1 VALUES ('ss'),('ß');
+SET big_tables=0;
+SELECT DISTINCT c FROM t1;
+SET big_tables=1;
+SELECT DISTINCT c FROM t1;
+DROP TABLE t1;
+SET big_tables=DEFAULT;
+
+
+--echo #
+--echo # End 10.4 tests
+--echo #
diff --git a/mysql-test/suite/innodb/t/innodb_default_row_format.combinations b/mysql-test/suite/innodb/t/innodb_default_row_format.combinations
new file mode 100644
index 00000000..d6041d72
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb_default_row_format.combinations
@@ -0,0 +1,6 @@
+[redundant]
+innodb_default_row_format=redundant
+[dynamic]
+innodb_default_row_format=dynamic
+[compact]
+innodb_default_row_format=compact
diff --git a/mysql-test/suite/innodb/t/innodb_default_row_format.inc b/mysql-test/suite/innodb/t/innodb_default_row_format.inc
new file mode 100644
index 00000000..15c61dc6
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb_default_row_format.inc
@@ -0,0 +1,2 @@
+# See also innodb_default_row_format.combinations
+--source include/have_innodb.inc
diff --git a/mysql-test/suite/innodb/t/innodb_defrag_binlog.opt b/mysql-test/suite/innodb/t/innodb_defrag_binlog.opt
new file mode 100644
index 00000000..8a432b8c
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb_defrag_binlog.opt
@@ -0,0 +1,5 @@
+--loose-innodb-buffer-pool-stats
+--loose-innodb-buffer-page
+--loose-innodb-buffer-page-lru
+--binlog-format=row
+--innodb-defragment=1 \ No newline at end of file
diff --git a/mysql-test/suite/innodb/t/innodb_defrag_binlog.test b/mysql-test/suite/innodb/t/innodb_defrag_binlog.test
new file mode 100644
index 00000000..db6849f8
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb_defrag_binlog.test
@@ -0,0 +1,21 @@
+--source include/have_innodb.inc
+--source include/master-slave.inc
+--source include/big_test.inc
+--source include/not_valgrind.inc
+--source include/not_embedded.inc
+
+--disable_warnings
+drop table if exists t1;
+--enable_warnings
+
+create table t1(a int not null primary key auto_increment, b varchar(256), key second(b)) engine=innodb;
+
+insert into t1 values (1, REPEAT("a", 256));
+insert into t1 values (2, REPEAT("a", 256));
+optimize table t1;
+
+drop table t1;
+
+--source include/show_binlog_events.inc
+
+--source include/rpl_end.inc
diff --git a/mysql-test/suite/innodb/t/innodb_defrag_concurrent.opt b/mysql-test/suite/innodb/t/innodb_defrag_concurrent.opt
new file mode 100644
index 00000000..3242c6cf
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb_defrag_concurrent.opt
@@ -0,0 +1,5 @@
+--loose-innodb-buffer-pool-stats
+--loose-innodb-buffer-page
+--loose-innodb-buffer-page-lru
+--innodb-log-buffer-size=3m
+--innodb-defragment=1 \ No newline at end of file
diff --git a/mysql-test/suite/innodb/t/innodb_defrag_concurrent.test b/mysql-test/suite/innodb/t/innodb_defrag_concurrent.test
new file mode 100644
index 00000000..1e4e14eb
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb_defrag_concurrent.test
@@ -0,0 +1,143 @@
+--source include/have_innodb.inc
+--source include/big_test.inc
+--source include/not_valgrind.inc
+--source include/not_embedded.inc
+--source include/have_sequence.inc
+
+SET @n_pages= @@GLOBAL.innodb_defragment_n_pages;
+SET @accuracy= @@GLOBAL.innodb_defragment_stats_accuracy;
+SET @sp= @@GLOBAL.innodb_stats_persistent;
+
+SET GLOBAL innodb_stats_persistent = 0;
+set global innodb_defragment_stats_accuracy = 80;
+
+# Create table.
+#
+# TODO: Currently we do not defragment spatial indexes,
+# because doing it properly would require
+# appropriate logic around the SSN (split
+# sequence number).
+#
+# Also do not defragment auxiliary tables related to FULLTEXT INDEX.
+#
+# Both types added to this test to make sure they do not cause
+# problems.
+#
+CREATE TABLE t1 (a INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
+b VARCHAR(256),
+c INT,
+g GEOMETRY NOT NULL,
+t VARCHAR(256),
+KEY second(a, b),
+KEY third(c),
+SPATIAL gk(g),
+FULLTEXT INDEX fti(t)) ENGINE=INNODB;
+
+connect (con1,localhost,root,,test,$MASTER_MYPORT,$MASTER_MYSOCK);
+connect (con2,localhost,root,,test,$MASTER_MYPORT,$MASTER_MYSOCK);
+connect (con3,localhost,root,,test,$MASTER_MYPORT,$MASTER_MYSOCK);
+connect (con4,localhost,root,,test,$MASTER_MYPORT,$MASTER_MYSOCK);
+
+connection default;
+
+SET @@global.innodb_defragment_n_pages = 20;
+
+CREATE TEMPORARY TABLE tt (a INT, KEY(a)) ENGINE=InnoDB ROW_FORMAT=REDUNDANT;
+INSERT INTO tt SELECT 0 FROM seq_1_to_180;
+INSERT INTO tt SELECT 5 FROM seq_1_to_160;
+INSERT INTO tt SELECT 1 FROM seq_1_to_1000;
+OPTIMIZE TABLE tt;
+
+let $data_size = 20000;
+let $delete_size = 2000;
+
+# Populate table.
+let $i = $data_size;
+--disable_query_log
+while ($i)
+{
+ eval
+ INSERT INTO t1 VALUES ($data_size + 1 - $i, REPEAT('A', 256), $i, Point($i,$i), 'This is a test message.');
+ dec $i;
+}
+--enable_query_log
+
+select count(*) from t1;
+select count(*) from t1 force index (second);
+select count(*) from t1 force index (third);
+
+# Delete some data
+--disable_query_log
+let $size = $delete_size;
+while ($size)
+{
+ let $j = 100 * $size;
+ eval delete from t1 where a between $j - 20 and $j;
+ dec $size;
+}
+--enable_query_log
+
+select count(*) from t1;
+select count(*) from t1 force index (second);
+select count(*) from t1 force index (third);
+
+# Above delete will free some pages and insert causes page split and these could cause defrag
+select count(stat_value) > 0 from mysql.innodb_index_stats where table_name like '%t1%' and stat_name in ('n_pages_freed');
+select count(stat_value) > 0 from mysql.innodb_index_stats where table_name like '%t1%' and stat_name in ('n_page_split');
+select count(stat_value) > 0 from mysql.innodb_index_stats where table_name like '%t1%' and stat_name in ('n_leaf_pages_defrag');
+
+connection con1;
+--send optimize table t1;
+
+connection default;
+--send INSERT INTO t1 VALUES (400000, REPEAT('A', 256),300000, Point(1,1),'More like a test but different.');
+
+connection con2;
+--send INSERT INTO t1 VALUES (500000, REPEAT('A', 256),400000, Point(1,1),'Totally different text book.');
+
+connection con3;
+--send DELETE FROM t1 where a between 1 and 100;
+
+connection con4;
+--send UPDATE t1 SET c = c + 1 where c between 2000 and 8000;
+
+connection con1;
+--disable_result_log
+--reap
+--enable_result_log
+
+connection con2;
+--reap
+
+connection con3;
+--reap
+
+connection con4;
+--reap
+
+connection default;
+--reap
+
+disconnect con1;
+disconnect con2;
+disconnect con3;
+disconnect con4;
+
+optimize table t1;
+check table t1 extended;
+
+select count(*) from t1;
+select count(*) from t1 force index (second);
+select count(*) from t1 force index (third);
+
+# Now pages are freed
+select count(stat_value) > 0 from mysql.innodb_index_stats where table_name like '%t1%' and stat_name in ('n_pages_freed');
+select count(stat_value) > 0 from mysql.innodb_index_stats where table_name like '%t1%' and stat_name in ('n_page_split');
+select count(stat_value) > 0 from mysql.innodb_index_stats where table_name like '%t1%' and stat_name in ('n_leaf_pages_defrag');
+
+drop table t1;
+
+# reset system
+SET GLOBAL innodb_defragment_n_pages = @n_pages;
+SET GLOBAL innodb_defragment_stats_accuracy = @accuracy;
+SET GLOBAL innodb_stats_persistent = @sp;
diff --git a/mysql-test/suite/innodb/t/innodb_defrag_stats.opt b/mysql-test/suite/innodb/t/innodb_defrag_stats.opt
new file mode 100644
index 00000000..d3525162
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb_defrag_stats.opt
@@ -0,0 +1 @@
+--innodb-defragment=1
diff --git a/mysql-test/suite/innodb/t/innodb_defrag_stats.test b/mysql-test/suite/innodb/t/innodb_defrag_stats.test
new file mode 100644
index 00000000..ef79d8d6
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb_defrag_stats.test
@@ -0,0 +1,88 @@
+--source include/have_innodb.inc
+--source include/not_valgrind.inc
+--source include/not_embedded.inc
+--source include/have_sequence.inc
+
+SET GLOBAL innodb_defragment_stats_accuracy = 20;
+
+DELETE FROM mysql.innodb_index_stats;
+
+--echo # Create table.
+CREATE TABLE t1 (a INT PRIMARY KEY AUTO_INCREMENT, b VARCHAR(256),
+ KEY SECOND(a, b)) ENGINE=INNODB STATS_PERSISTENT=0;
+
+INSERT INTO t1 SELECT 100*FLOOR(seq/70)+seq%70, REPEAT('A', 256)
+FROM seq_1_to_1024;
+
+--echo # Not enough page splits to trigger persistent stats write yet.
+SELECT * FROM mysql.innodb_index_stats;
+
+INSERT INTO t1 SELECT 100*FLOOR(seq/70)+seq%70, REPEAT('A', 256)
+FROM seq_1025_to_1433;
+
+BEGIN;
+let $num_delete = 20;
+while ($num_delete)
+{
+ eval INSERT INTO t1 SELECT 100*$num_delete+seq, REPEAT('A', 256)
+ FROM seq_70_to_99;
+ dec $num_delete;
+}
+ROLLBACK;
+
+SELECT @@GLOBAL.innodb_force_recovery<2 "have background defragmentation";
+
+# Wait for defrag_pool to be processed.
+
+let $wait_timeout=30;
+let $wait_condition = SELECT COUNT(*)>0 FROM mysql.innodb_index_stats;
+--source include/wait_condition.inc
+
+--sorted_result
+SELECT table_name, index_name, stat_name FROM mysql.innodb_index_stats;
+
+optimize table t1;
+
+--sorted_result
+SELECT table_name, index_name, stat_name FROM mysql.innodb_index_stats;
+
+set global innodb_defragment_stats_accuracy = 40;
+
+INSERT INTO t1 (b) SELECT b from t1;
+
+--sorted_result
+SELECT table_name, index_name, stat_name FROM mysql.innodb_index_stats;
+
+INSERT INTO t1 (b) SELECT b from t1;
+
+--sorted_result
+SELECT stat_name FROM mysql.innodb_index_stats WHERE table_name='t1';
+
+--echo # Table rename should cause stats rename.
+rename table t1 to t2;
+
+--sorted_result
+SELECT table_name, index_name, stat_name FROM mysql.innodb_index_stats;
+
+drop index SECOND on t2;
+
+--echo #
+--echo # MDEV-26636: Statistics must not be written for temporary tables
+--echo #
+SET GLOBAL innodb_defragment_stats_accuracy = 1;
+CREATE TEMPORARY TABLE t (a INT PRIMARY KEY, c CHAR(255) NOT NULL)
+ENGINE=InnoDB;
+INSERT INTO t SELECT seq, '' FROM seq_1_to_100;
+
+--source include/restart_mysqld.inc
+
+--sorted_result
+SELECT table_name, index_name, stat_name FROM mysql.innodb_index_stats;
+
+--echo # Clean up
+# Starting with 10.6, DROP TABLE will not touch persistent statistics
+# (not defragmentation statistics either) if the table has none!
+ALTER TABLE t2 STATS_PERSISTENT=1;
+DROP TABLE t2;
+
+SELECT * FROM mysql.innodb_index_stats;
diff --git a/mysql-test/suite/innodb/t/innodb_defrag_stats_many_tables.opt b/mysql-test/suite/innodb/t/innodb_defrag_stats_many_tables.opt
new file mode 100644
index 00000000..d3525162
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb_defrag_stats_many_tables.opt
@@ -0,0 +1 @@
+--innodb-defragment=1
diff --git a/mysql-test/suite/innodb/t/innodb_defrag_stats_many_tables.test b/mysql-test/suite/innodb/t/innodb_defrag_stats_many_tables.test
new file mode 100644
index 00000000..a0f43fa6
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb_defrag_stats_many_tables.test
@@ -0,0 +1,77 @@
+--source include/have_innodb.inc
+--source include/big_test.inc
+--source include/not_valgrind.inc
+--source include/not_embedded.inc
+
+--disable_warnings
+DROP TABLE if exists t1;
+--enable_warnings
+
+let $num_tables = 505;
+
+SET @start_table_definition_cache = @@global.table_definition_cache;
+SET @@global.table_definition_cache = 400;
+
+SET @start_flush_log_at_trx_commit = @@global.innodb_flush_log_at_trx_commit;
+SET @@global.innodb_flush_log_at_trx_commit=2;
+
+# set stats accuracy to be pretty high so stats sync is easily triggered.
+SET @start_innodb_defragment_stats_accuracy = @@global.innodb_defragment_stats_accuracy;
+SET @@global.innodb_defragment_stats_accuracy = 80;
+
+# Create table.
+CREATE TABLE t1 (a INT NOT NULL PRIMARY KEY AUTO_INCREMENT, b VARCHAR(256), KEY SECOND(a, b)) ENGINE=INNODB;
+
+# Populate data
+INSERT INTO t1 VALUES(1, REPEAT('A', 256));
+INSERT INTO t1 (b) SELECT b from t1;
+INSERT INTO t1 (b) SELECT b from t1;
+INSERT INTO t1 (b) SELECT b from t1;
+INSERT INTO t1 (b) SELECT b from t1;
+INSERT INTO t1 (b) SELECT b from t1;
+INSERT INTO t1 (b) SELECT b from t1;
+INSERT INTO t1 (b) SELECT b from t1;
+INSERT INTO t1 (b) SELECT b from t1;
+INSERT INTO t1 (b) SELECT b from t1;
+INSERT INTO t1 (b) SELECT b from t1;
+INSERT INTO t1 (b) SELECT b from t1;
+
+select stat_value > 0 from mysql.innodb_index_stats where table_name like '%t1%' and stat_name = 'n_page_split';
+
+# Create many tables to over flow the table definition cache
+
+--echo Create $num_tables table to overflow the table cache.
+--disable_query_log
+let $count = $num_tables;
+while ($count)
+{
+ EVAL CREATE TABLE t_$count (a INT NOT NULL PRIMARY KEY AUTO_INCREMENT) ENGINE=INNODB;
+ EVAL INSERT INTO t_$count VALUES (1), (2);
+ dec $count;
+}
+--enable_query_log
+--echo Sleep for a while to make sure t1 is evicted.
+select sleep(15);
+
+--echo Reload t1 to get defrag stats from persistent storage
+INSERT INTO t1 (b) SELECT b from t1;
+
+--echo make sure the stats thread will wake up and do the write even if there's a race condition between set and reset.
+select sleep(15);
+
+select stat_value > 0 from mysql.innodb_index_stats where table_name like '%t1%' and stat_name = 'n_page_split';
+
+
+# Clean up
+SET @@global.innodb_defragment_stats_accuracy = @start_innodb_defragment_stats_accuracy;
+SET @@global.table_definition_cache = @start_table_definition_cache;
+--disable_query_log
+let $count = $num_tables;
+while ($count)
+{
+ EVAL DROP TABLE t_$count;
+ dec $count;
+}
+set @@global.innodb_flush_log_at_trx_commit = @start_flush_log_at_trx_commit;
+--enable_query_log
+DROP TABLE t1;
diff --git a/mysql-test/suite/innodb/t/innodb_defragment.opt b/mysql-test/suite/innodb/t/innodb_defragment.opt
new file mode 100644
index 00000000..aea3d480
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb_defragment.opt
@@ -0,0 +1,5 @@
+--loose-innodb-buffer-pool-stats
+--loose-innodb-buffer-page
+--loose-innodb-buffer-page-lru
+--innodb-file-per-table
+--innodb-defragment=1 \ No newline at end of file
diff --git a/mysql-test/suite/innodb/t/innodb_defragment.test b/mysql-test/suite/innodb/t/innodb_defragment.test
new file mode 100644
index 00000000..51ef7837
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb_defragment.test
@@ -0,0 +1,157 @@
+--source include/have_innodb.inc
+--source include/big_test.inc
+--source include/not_embedded.inc
+# Valgrind is to slow for this test
+--source include/not_valgrind.inc
+
+set global innodb_defragment_stats_accuracy = 80;
+
+# Create table.
+CREATE TABLE t1 (a INT NOT NULL PRIMARY KEY AUTO_INCREMENT, b VARCHAR(256), KEY SECOND(a, b)) ENGINE=INNODB;
+
+## Test-1 defragment an empty table
+optimize table t1;
+
+## Test-2 defragment a single page table
+INSERT INTO t1 VALUES (100000, REPEAT('A', 256));
+INSERT INTO t1 VALUES (200000, REPEAT('A', 256));
+INSERT INTO t1 VALUES (300000, REPEAT('A', 256));
+INSERT INTO t1 VALUES (400000, REPEAT('A', 256));
+
+optimize table t1;
+
+## Test-3 defragment (somewhat) in parallel with delete queries
+let $data_size = 10000;
+let $delete_size = 100;
+
+delimiter //;
+create procedure defragment()
+begin
+ set @i = 0;
+ repeat
+ set @i = @i + 1;
+ optimize table t1;
+ until @i = 3 end repeat;
+end //
+delimiter ;//
+
+
+# Populate table.
+let $i = $data_size;
+--disable_query_log
+BEGIN;
+while ($i)
+{
+ eval
+ INSERT INTO t1 VALUES ($data_size + 1 - $i, REPEAT('A', 256));
+ dec $i;
+}
+COMMIT;
+--enable_query_log
+
+select count(stat_value) from mysql.innodb_index_stats where table_name like '%t1%' and stat_name in ('n_pages_freed');
+select count(stat_value) from mysql.innodb_index_stats where table_name like '%t1%' and stat_name in ('n_page_split');
+select count(stat_value) from mysql.innodb_index_stats where table_name like '%t1%' and stat_name in ('n_leaf_pages_defrag');
+
+select count(*) from t1;
+
+connect (con1,localhost,root,,test,$MASTER_MYPORT,$MASTER_MYSOCK);
+
+connection con1;
+--send call defragment()
+
+connection default;
+
+--disable_query_log
+let $size = $delete_size;
+while ($size)
+{
+ let $j = 100 * $size;
+ eval delete from t1 where a between $j - 20 and $j;
+ dec $size;
+}
+--enable_query_log
+
+connection con1;
+--disable_result_log
+--reap
+--enable_result_log
+
+connection default;
+disconnect con1;
+
+optimize table t1;
+
+--source include/restart_mysqld.inc
+select count(*) from t1;
+
+select count(stat_value) = 0 from mysql.innodb_index_stats where table_name like '%t1%' and stat_name in ('n_pages_freed');
+select count(stat_value) > 0 from mysql.innodb_index_stats where table_name like '%t1%' and stat_name in ('n_page_split');
+select count(stat_value) > 0 from mysql.innodb_index_stats where table_name like '%t1%' and stat_name in ('n_leaf_pages_defrag');
+
+select count(*) from t1 force index (second);
+
+select count(stat_value) = 0 from mysql.innodb_index_stats where table_name like '%t1%' and index_name = 'second' and stat_name in ('n_pages_freed');
+select count(stat_value) = 0 from mysql.innodb_index_stats where table_name like '%t1%' and index_name = 'second' and stat_name in ('n_page_split');
+select count(stat_value) = 0 from mysql.innodb_index_stats where table_name like '%t1%' and index_name = 'second' and stat_name in ('n_leaf_pages_defrag');
+
+## Test-4 defragment with larger n_pages
+
+# delete some more records
+--disable_query_log
+let $size = $delete_size;
+while ($size)
+{
+ let $j = 100 * $size;
+ eval delete from t1 where a between $j - 30 and $j - 20;
+ dec $size;
+}
+--enable_query_log
+
+SET @@global.innodb_defragment_n_pages = 3;
+
+# This will not reduce number of pages by a lot
+optimize table t1;
+
+--source include/restart_mysqld.inc
+
+select count(stat_value) < 3 from mysql.innodb_index_stats where table_name like '%t1%' and stat_name in ('n_pages_freed');
+select count(stat_value) < 3 from mysql.innodb_index_stats where table_name like '%t1%' and stat_name in ('n_page_split');
+select count(stat_value) < 3 from mysql.innodb_index_stats where table_name like '%t1%' and stat_name in ('n_leaf_pages_defrag');
+
+select count(*) from t1;
+
+# We didn't create large wholes with the previous deletion, so if innodb_defragment_n_pages = 3, we won't be able to free up many pages.
+
+select count(stat_value) < 3 from mysql.innodb_index_stats where table_name like '%t1%' and stat_name in ('n_pages_freed');
+select count(stat_value) < 3 from mysql.innodb_index_stats where table_name like '%t1%' and stat_name in ('n_page_split');
+select count(stat_value) < 3 from mysql.innodb_index_stats where table_name like '%t1%' and stat_name in ('n_leaf_pages_defrag');
+
+
+select count(*) from t1 force index (second);
+
+# Same holds for secondary index, not many pages are released.
+select count(stat_value) = 0 from mysql.innodb_index_stats where table_name like '%t1%' and index_name = 'second' and stat_name in ('n_pages_freed');
+select count(stat_value) = 0 from mysql.innodb_index_stats where table_name like '%t1%' and index_name = 'second' and stat_name in ('n_page_split');
+select count(stat_value) = 0 from mysql.innodb_index_stats where table_name like '%t1%' and index_name = 'second' and stat_name in ('n_leaf_pages_defrag');
+
+SET @@global.innodb_defragment_n_pages = 10;
+
+optimize table t1;
+
+--source include/restart_mysqld.inc
+
+select count(stat_value) > 1 from mysql.innodb_index_stats where table_name like '%t1%' and stat_name in ('n_pages_freed');
+select count(stat_value) > 1 from mysql.innodb_index_stats where table_name like '%t1%' and stat_name in ('n_page_split');
+select count(stat_value) > 1 from mysql.innodb_index_stats where table_name like '%t1%' and stat_name in ('n_leaf_pages_defrag');
+
+
+select count(*) from t1 force index (second);
+
+# Same holds for secondary index, not many pages are released.
+select count(stat_value) = 0 from mysql.innodb_index_stats where table_name like '%t1%' and index_name = 'second' and stat_name in ('n_pages_freed');
+select count(stat_value) = 0 from mysql.innodb_index_stats where table_name like '%t1%' and index_name = 'second' and stat_name in ('n_page_split');
+select count(stat_value) = 0 from mysql.innodb_index_stats where table_name like '%t1%' and index_name = 'second' and stat_name in ('n_leaf_pages_defrag');
+
+DROP PROCEDURE defragment;
+DROP TABLE t1;
diff --git a/mysql-test/suite/innodb/t/innodb_defragment_small.test b/mysql-test/suite/innodb/t/innodb_defragment_small.test
new file mode 100644
index 00000000..6259dac4
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb_defragment_small.test
@@ -0,0 +1,41 @@
+--source include/have_innodb.inc
+
+SET @innodb_defragment_orig=@@GLOBAL.innodb_defragment;
+SET @innodb_optimize_fulltext_orig=@@GLOBAL.innodb_optimize_fulltext_only;
+SET GLOBAL innodb_defragment = 1;
+SET GLOBAL innodb_optimize_fulltext_only = 0;
+
+--echo #
+--echo # MDEV-12198 innodb_defragment=1 crashes server on
+--echo # OPTIMIZE TABLE when FULLTEXT index exists
+--echo #
+
+CREATE TABLE t1 (a INT PRIMARY KEY, b VARCHAR(256),
+ KEY(a, b), FULLTEXT KEY(b)) ENGINE=INNODB;
+OPTIMIZE TABLE t1;
+
+INSERT INTO t1 VALUES (100000, REPEAT('A', 256));
+INSERT INTO t1 VALUES (200000, REPEAT('A', 256));
+INSERT INTO t1 VALUES (300000, REPEAT('A', 256));
+INSERT INTO t1 VALUES (400000, REPEAT('A', 256));
+
+OPTIMIZE TABLE t1;
+
+--echo #
+--echo # MDEV-15824 innodb_defragment=ON trumps
+--echo # innodb_optimize_fulltext_only=ON in OPTIMIZE TABLE
+--echo #
+
+SET GLOBAL innodb_optimize_fulltext_only = 1;
+OPTIMIZE TABLE t1;
+SET GLOBAL innodb_defragment = 0;
+OPTIMIZE TABLE t1;
+
+DROP TABLE t1;
+
+CREATE TABLE t1 (c POINT PRIMARY KEY, SPATIAL INDEX(c)) ENGINE=InnoDB;
+OPTIMIZE TABLE t1;
+DROP TABLE t1;
+
+SET GLOBAL innodb_defragment = @innodb_defragment_orig;
+SET GLOBAL innodb_optimize_fulltext_only = @innodb_optimize_fulltext_orig;
diff --git a/mysql-test/suite/innodb/t/innodb_force_pk.opt b/mysql-test/suite/innodb/t/innodb_force_pk.opt
new file mode 100644
index 00000000..93d63935
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb_force_pk.opt
@@ -0,0 +1 @@
+--innodb_force_primary_key=1
diff --git a/mysql-test/suite/innodb/t/innodb_force_pk.test b/mysql-test/suite/innodb/t/innodb_force_pk.test
new file mode 100644
index 00000000..7dcab8ea
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb_force_pk.test
@@ -0,0 +1,49 @@
+-- source include/have_innodb.inc
+
+let $force_pk=`select @@innodb_force_primary_key`;
+
+-- error 1173
+create table t1(a integer) engine=innodb;
+show warnings;
+-- error 1173
+create table t1(a integer unique key) engine=innodb;
+show warnings;
+-- error 1173
+create table t1(a integer not null, b integer,
+unique key(a,b)) engine=innodb;
+show warnings;
+create table t1(a integer not null primary key) engine=innodb;
+show create table t1;
+show warnings;
+drop table t1;
+create table t1(a integer not null unique key) engine=innodb;
+show create table t1;
+show warnings;
+drop table t1;
+
+set global innodb_force_primary_key = 0;
+create table t1(a integer) engine=innodb;
+show warnings;
+insert into t1 values (1),(2),(3);
+
+set global innodb_force_primary_key = 1;
+select * from t1;
+-- error 1173
+create table t2(a integer) engine=innodb;
+show warnings;
+drop table t1;
+
+#
+# MDEV-8582: innodb_force_primary_key option does not
+# force PK or unique key
+#
+--error 1173
+create table t1 (i int not null, key(i)) engine=innodb;
+create table t1 (i int not null, unique key(i)) engine=innodb;
+show warnings;
+show create table t1;
+drop table t1;
+
+--disable_query_log
+eval set global innodb_force_primary_key=$force_pk;
+--enable_query_log
diff --git a/mysql-test/suite/innodb/t/innodb_force_recovery.test b/mysql-test/suite/innodb/t/innodb_force_recovery.test
new file mode 100644
index 00000000..2368af76
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb_force_recovery.test
@@ -0,0 +1,161 @@
+# Not supported in embedded
+--source include/not_embedded.inc
+
+# This test case needs InnoDB.
+-- source include/have_innodb.inc
+
+--disable_query_log
+call mtr.add_suppression("InnoDB: Failed to find tablespace for table .* in the cache. Attempting to load the tablespace with space id");
+call mtr.add_suppression("InnoDB: Allocated tablespace ID \\d+ for test.t[12], old maximum was");
+call mtr.add_suppression("InnoDB: Allocated tablespace ID \\d+ for mysql.transaction_registry, old maximum was");
+--enable_query_log
+
+create table t1(f1 int not null, f2 int not null, index idx(f2))engine=innodb;
+create table t2(f1 int primary key, f2 int, index idx(f2))engine=innodb;
+insert into t1 values(1, 2);
+insert into t2 values(1, 2);
+
+SET GLOBAL innodb_fast_shutdown = 0;
+
+--let $restart_parameters= --innodb-force-recovery=4
+--source include/restart_mysqld.inc
+let $status=`SHOW ENGINE INNODB STATUS`;
+
+select * from t1;
+
+begin;
+insert into t1 values(2, 3);
+rollback;
+
+alter table t1 add f3 int not null, algorithm=copy;
+
+alter table t1 add f4 int not null, algorithm=inplace;
+
+drop index idx on t1;
+
+update t1 set f1=3 where f2=2;
+
+create table t3(f1 int not null)engine=innodb;
+drop table t3;
+
+rename table t1 to t3;
+rename table t3 to t1;
+truncate table t1;
+
+show tables;
+
+--let $restart_parameters= --innodb-force-recovery=5
+--source include/restart_mysqld.inc
+let $status=`SHOW ENGINE INNODB STATUS`;
+
+select * from t2;
+
+--error ER_READ_ONLY_MODE
+insert into t2 values(2, 3);
+
+--error ER_CANT_CREATE_TABLE
+alter table t2 add f3 int not null, algorithm=copy;
+
+--error ER_ALTER_OPERATION_NOT_SUPPORTED_REASON
+alter table t2 add f3 int not null, algorithm=inplace;
+
+--error ER_CANT_CREATE_TABLE
+drop index idx on t2;
+
+--error ER_READ_ONLY_MODE
+update t2 set f1=3 where f2=2;
+
+--error ER_CANT_CREATE_TABLE
+create table t3(f1 int not null)engine=innodb;
+
+--error ER_OPEN_AS_READONLY
+drop table t3;
+
+--error ER_ERROR_ON_RENAME
+rename table t2 to t3;
+
+--error ER_OPEN_AS_READONLY
+truncate table t2;
+
+--error ER_OPEN_AS_READONLY
+drop table t2;
+
+create schema db;
+drop schema db;
+show tables;
+
+--let $restart_parameters= --innodb-force-recovery=6
+--source include/restart_mysqld.inc
+let $status=`SHOW ENGINE INNODB STATUS`;
+
+select * from t2;
+
+--error ER_OPEN_AS_READONLY
+insert into t2 values(2, 3);
+
+--error ER_OPEN_AS_READONLY
+alter table t2 add f3 int not null, algorithm=copy;
+
+--error ER_ALTER_OPERATION_NOT_SUPPORTED_REASON
+alter table t2 add f3 int not null, algorithm=inplace;
+
+--error ER_OPEN_AS_READONLY
+drop index idx on t2;
+
+--error ER_OPEN_AS_READONLY
+update t2 set f1=3 where f2=2;
+
+--error ER_CANT_CREATE_TABLE
+create table t3(f1 int not null)engine=innodb;
+
+--error ER_OPEN_AS_READONLY
+drop table t1;
+
+--error ER_ERROR_ON_RENAME
+rename table t2 to t3;
+
+--error ER_OPEN_AS_READONLY
+truncate table t2;
+
+--error ER_OPEN_AS_READONLY
+drop table t2;
+show tables;
+
+--let $restart_parameters= --innodb-force-recovery=2
+--source include/restart_mysqld.inc
+let $status=`SHOW ENGINE INNODB STATUS`;
+
+select * from t2;
+begin;
+update t2 set f2=3;
+
+connect (con1,localhost,root,,);
+--echo # Force a redo log flush of the above uncommitted UPDATE
+SET GLOBAL innodb_flush_log_at_trx_commit=1;
+drop table t1;
+disconnect con1;
+
+connection default;
+--source include/kill_mysqld.inc
+
+--let $restart_parameters= --innodb-force-recovery=3
+--source include/start_mysqld.inc
+let $status=`SHOW ENGINE INNODB STATUS`;
+
+SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED;
+--disable_ps2_protocol
+select * from t2;
+--enable_ps2_protocol
+SET TRANSACTION ISOLATION LEVEL REPEATABLE READ;
+select * from t2;
+SET SESSION innodb_lock_wait_timeout=1;
+--error ER_LOCK_WAIT_TIMEOUT
+insert into t2 values(1,2);
+insert into t2 values(9,10);
+
+--let $restart_parameters=
+--source include/restart_mysqld.inc
+
+select * from t2;
+drop table t2;
+show tables;
diff --git a/mysql-test/suite/innodb/t/innodb_force_recovery_rollback.test b/mysql-test/suite/innodb/t/innodb_force_recovery_rollback.test
new file mode 100644
index 00000000..f1d14c45
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb_force_recovery_rollback.test
@@ -0,0 +1,35 @@
+--source include/have_innodb.inc
+--source include/have_sequence.inc
+
+# We will kill and restart the server.
+--source include/not_embedded.inc
+FLUSH TABLES;
+
+--echo #
+--echo # MDEV-21217 innodb_force_recovery=2 may wrongly abort the rollback
+--echo # of recovered transactions
+--echo #
+
+connect (con0,localhost,root);
+CREATE TABLE t0 (a INT PRIMARY KEY) ENGINE=InnoDB;
+# Create enough undo log so that the rollback may take enough time.
+BEGIN;
+INSERT INTO t0 SELECT * FROM seq_1_to_1000;
+
+connection default;
+# Persist the above incomplete transaction.
+SET GLOBAL innodb_flush_log_at_trx_commit=1;
+CREATE TABLE t1 (a INT PRIMARY KEY) ENGINE=InnoDB;
+
+--let $restart_parameters= --innodb-force-recovery=2
+--let $shutdown_timeout=0
+--source include/restart_mysqld.inc
+--let $restart_parameters=
+--let $shutdown_timeout=
+
+disconnect con0;
+connection default;
+# If the rollback was aborted, we would end up in a lock wait here.
+# The LIMIT 0 works around MDEV-22889 InnoDB occasionally breaks ACID
+SELECT * FROM t0 LIMIT 0 LOCK IN SHARE MODE;
+DROP TABLE t0,t1;
diff --git a/mysql-test/suite/innodb/t/innodb_gis.test b/mysql-test/suite/innodb/t/innodb_gis.test
new file mode 100644
index 00000000..c895d0a2
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb_gis.test
@@ -0,0 +1,22 @@
+--source include/have_innodb.inc
+SET default_storage_engine=innodb;
+--source include/gis_generic.inc
+--source include/gis_keys.inc
+
+#
+# Bug #15680 (SPATIAL key in innodb)
+#
+# MySQL 5.7 Introduces SPATIAL keys for InnoDB
+#--error ER_TABLE_CANT_HANDLE_SPKEYS
+create table t1 (g geometry not null, spatial gk(g)) engine=innodb;
+drop table t1;
+
+#
+# MDEV-12462 SPATIAL index fails to work with CONTAINS
+#
+
+create table t1(id int not null primary key, g1 geometry not null, spatial index(g1));
+insert into t1 values(1, polygonfromtext('POLYGON((0 0, 0 5, 5 5, 5 0, 0 0))'));
+explain select id from t1 where contains(g1, pointfromtext('POINT(1 1)'));
+select id from t1 where contains(g1, pointfromtext('POINT(1 1)'));
+drop table t1;
diff --git a/mysql-test/suite/innodb/t/innodb_information_schema.test b/mysql-test/suite/innodb/t/innodb_information_schema.test
new file mode 100644
index 00000000..88e2d360
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb_information_schema.test
@@ -0,0 +1,279 @@
+#
+# Test that user data is correctly "visualized" in
+# INFORMATION_SCHEMA.innodb_locks.lock_data
+#
+
+-- source include/have_innodb.inc
+
+# lock data that is part of result set for this testcase
+# is retreived using buf_page_try_get. i.e only show if page
+# happen to be in buffer pool, with key rotation threads
+# chances are substantial that pages have been evicted and lock_data
+# get NULL
+-- source include/not_encrypted.inc
+
+-- disable_query_log
+-- disable_result_log
+
+SET default_storage_engine=InnoDB;
+
+-- disable_warnings
+DROP TABLE IF EXISTS t_min, t_max;
+-- enable_warnings
+
+let $table_def =
+(
+ c01 TINYINT,
+ c02 TINYINT UNSIGNED,
+ c03 SMALLINT,
+ c04 SMALLINT UNSIGNED,
+ c05 MEDIUMINT,
+ c06 MEDIUMINT UNSIGNED,
+ c07 INT,
+ c08 INT UNSIGNED,
+ c09 BIGINT,
+ c10 BIGINT UNSIGNED,
+ PRIMARY KEY(c01, c02, c03, c04, c05, c06, c07, c08, c09, c10)
+);
+
+-- eval CREATE TABLE t_min $table_def;
+INSERT INTO t_min VALUES
+(-128, 0,
+ -32768, 0,
+ -8388608, 0,
+ -2147483648, 0,
+ -9223372036854775808, 0);
+
+-- eval CREATE TABLE t_max $table_def;
+INSERT INTO t_max VALUES
+(127, 255,
+ 32767, 65535,
+ 8388607, 16777215,
+ 2147483647, 4294967295,
+ 9223372036854775807, 18446744073709551615);
+
+CREATE TABLE ```t'\"_str` (
+ c1 VARCHAR(32),
+ c2 VARCHAR(32),
+ c3 VARCHAR(32),
+ c4 VARCHAR(32),
+ c5 VARCHAR(32),
+ c6 VARCHAR(32),
+ c7 VARCHAR(32),
+ PRIMARY KEY(c1, c2, c3, c4, c5, c6, c7)
+);
+INSERT INTO ```t'\"_str` VALUES
+('1', 'abc', '''abc', 'abc''', 'a''bc', 'a''bc''', '''abc''''');
+INSERT INTO ```t'\"_str` VALUES
+('2', 'abc', '"abc', 'abc"', 'a"bc', 'a"bc"', '"abc""');
+INSERT INTO ```t'\"_str` VALUES
+('3', 'abc', '\\abc', 'abc\\', 'a\\bc', 'a\\bc\\', '\\abc\\\\');
+INSERT INTO ```t'\"_str` VALUES
+('4', 'abc', 0x00616263, 0x61626300, 0x61006263, 0x6100626300, 0x610062630000);
+
+--source include/count_sessions.inc
+
+-- connect (con_lock,localhost,root,,)
+-- connect (con_min_trylock,localhost,root,,)
+-- connect (con_max_trylock,localhost,root,,)
+-- connect (con_str_insert_supremum,localhost,root,,)
+-- connect (con_str_lock_row1,localhost,root,,)
+-- connect (con_str_lock_row2,localhost,root,,)
+-- connect (con_str_lock_row3,localhost,root,,)
+-- connect (con_str_lock_row4,localhost,root,,)
+-- connect (con_verify_innodb_locks,localhost,root,,)
+
+-- connection con_lock
+SET autocommit=0;
+SELECT * FROM t_min FOR UPDATE;
+SELECT * FROM t_max FOR UPDATE;
+SELECT * FROM ```t'\"_str` FOR UPDATE;
+
+-- connection con_min_trylock
+-- send
+SELECT * FROM t_min FOR UPDATE;
+
+-- connection con_max_trylock
+-- send
+SELECT * FROM t_max FOR UPDATE;
+
+-- connection con_str_insert_supremum
+-- send
+INSERT INTO ```t'\"_str` VALUES
+('z', 'z', 'z', 'z', 'z', 'z', 'z');
+
+-- connection con_str_lock_row1
+-- send
+SELECT * FROM ```t'\"_str` WHERE c1 = '1' FOR UPDATE;
+
+-- connection con_str_lock_row2
+-- send
+SELECT * FROM ```t'\"_str` WHERE c1 = '2' FOR UPDATE;
+
+-- connection con_str_lock_row3
+-- send
+SELECT * FROM ```t'\"_str` WHERE c1 = '3' FOR UPDATE;
+
+-- connection con_str_lock_row4
+-- send
+SELECT * FROM ```t'\"_str` WHERE c1 = '4' FOR UPDATE;
+
+-- enable_result_log
+-- connection con_verify_innodb_locks
+# Wait for the above queries to execute before continuing.
+# Without this, it sometimes happens that the SELECT from innodb_locks
+# executes before some of them, resulting in less than expected number
+# of rows being selected from innodb_locks. If there is a bug and there
+# are no 14 rows in innodb_locks then this test will fail with timeout.
+# Notice that if we query INNODB_LOCKS more often than once per 0.1 sec
+# then its contents will never change because the cache from which it is
+# filled is updated only if it has not been read for 0.1 seconds. See
+# CACHE_MIN_IDLE_TIME_US in trx/trx0i_s.c.
+let $cnt=200;
+while ($cnt)
+{
+ let $success=`SELECT COUNT(*) = 14 FROM INFORMATION_SCHEMA.INNODB_LOCKS`;
+ if ($success)
+ {
+ let $cnt=0;
+ }
+ if (!$success)
+ {
+ real_sleep 0.2;
+ dec $cnt;
+ }
+}
+if (!$success)
+{
+ -- echo Timeout waiting for rows in INNODB_LOCKS to appear
+}
+
+--replace_column 6 #
+--sorted_result
+SELECT lock_mode, lock_type, lock_table, lock_index, lock_rec, lock_data
+FROM INFORMATION_SCHEMA.INNODB_LOCKS ORDER BY lock_data;
+
+SELECT lock_table,COUNT(*) FROM INFORMATION_SCHEMA.INNODB_LOCKS
+GROUP BY lock_table;
+
+set @save_sql_mode = @@sql_mode;
+SET SQL_MODE='ANSI_QUOTES';
+SELECT lock_table,COUNT(*) FROM INFORMATION_SCHEMA.INNODB_LOCKS
+GROUP BY lock_table;
+SET @@sql_mode=@save_sql_mode;
+-- disable_result_log
+
+-- connection default
+
+-- disconnect con_lock
+-- disconnect con_min_trylock
+-- disconnect con_max_trylock
+-- disconnect con_str_insert_supremum
+-- disconnect con_str_lock_row1
+-- disconnect con_str_lock_row2
+-- disconnect con_str_lock_row3
+-- disconnect con_str_lock_row4
+-- disconnect con_verify_innodb_locks
+
+DROP TABLE t_min, t_max, ```t'\"_str`;
+
+--source include/wait_until_count_sessions.inc
+
+#
+# Test that transaction data is correctly "visualized" in
+# INFORMATION_SCHEMA.INNODB_TRX
+#
+
+-- enable_result_log
+DESCRIBE INFORMATION_SCHEMA.INNODB_TRX;
+-- disable_result_log
+
+-- disable_warnings
+DROP TABLE IF EXISTS t1;
+-- enable_warnings
+
+CREATE TABLE t1 (
+ c01 INT,
+ c02 INT,
+ PRIMARY KEY (c01)
+) ENGINE = InnoDB;
+
+INSERT INTO t1 VALUES
+(1,2),(2,4),(3,6),(4,8);
+
+CREATE TABLE t2 (
+ c01 INT,
+ c02 INT,
+ PRIMARY KEY (c01),
+ FOREIGN KEY fk1 (c02) REFERENCES t1 (c01)
+) ENGINE = InnoDB;
+
+INSERT INTO t2 VALUES
+(1,1),(2,2),(3,3);
+
+-- connect (con_trx,localhost,root,,)
+-- connect (con_verify_innodb_trx,localhost,root,,)
+
+-- connection con_trx
+SET autocommit=0;
+INSERT INTO t1 VALUES (5,10);
+SELECT * FROM t1 FOR UPDATE;
+
+let $wait_condition=
+ SELECT COUNT(*) = 1 FROM INFORMATION_SCHEMA.INNODB_TRX;
+--source include/wait_condition.inc
+-- disable_query_log
+
+-- connection con_verify_innodb_trx
+-- enable_result_log
+SELECT trx_state, trx_weight, trx_tables_in_use, trx_tables_locked,
+trx_rows_locked, trx_rows_modified, trx_concurrency_tickets,
+trx_isolation_level, trx_unique_checks, trx_foreign_key_checks
+FROM INFORMATION_SCHEMA.INNODB_TRX;
+
+-- connection con_trx
+-- disable_result_log
+ROLLBACK;
+SET FOREIGN_KEY_CHECKS = 0;
+SET UNIQUE_CHECKS = 0;
+SET TRANSACTION ISOLATION LEVEL SERIALIZABLE;
+BEGIN;
+INSERT INTO t1 VALUES (6,12);
+
+let $wait_condition=
+ SELECT trx_unique_checks = 0 FROM INFORMATION_SCHEMA.INNODB_TRX;
+--source include/wait_condition.inc
+-- disable_query_log
+
+-- connection con_verify_innodb_trx
+-- enable_result_log
+SELECT trx_isolation_level, trx_unique_checks, trx_foreign_key_checks
+FROM INFORMATION_SCHEMA.INNODB_TRX;
+
+-- disable_result_log
+-- connection con_trx
+ROLLBACK;
+SET FOREIGN_KEY_CHECKS = 1;
+SET UNIQUE_CHECKS = 1;
+BEGIN;
+-- error 1452
+INSERT INTO t2 VALUES (4,10);
+
+let $wait_condition=
+ SELECT trx_unique_checks = 1 FROM INFORMATION_SCHEMA.INNODB_TRX;
+--source include/wait_condition.inc
+-- disable_query_log
+
+-- enable_result_log
+-- connection con_verify_innodb_trx
+SELECT trx_state, trx_isolation_level, trx_last_foreign_key_error
+FROM INFORMATION_SCHEMA.INNODB_TRX;
+-- disable_result_log
+
+-- connection default
+
+-- disconnect con_trx
+-- disconnect con_verify_innodb_trx
+
+DROP TABLE t2;
+DROP TABLE t1;
diff --git a/mysql-test/suite/innodb/t/innodb_information_schema_buffer.opt b/mysql-test/suite/innodb/t/innodb_information_schema_buffer.opt
new file mode 100644
index 00000000..9e43eb47
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb_information_schema_buffer.opt
@@ -0,0 +1,3 @@
+--loose-innodb-buffer-pool-stats
+--loose-innodb-buffer-page
+--loose-innodb-buffer-page-lru
diff --git a/mysql-test/suite/innodb/t/innodb_information_schema_buffer.test b/mysql-test/suite/innodb/t/innodb_information_schema_buffer.test
new file mode 100644
index 00000000..7f0d4f0a
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb_information_schema_buffer.test
@@ -0,0 +1,57 @@
+# Exercise the code path for INFORMATION_SCHEMA.INNODB_BUFFER_POOL_STATS
+# and INFORMATION_SCHEMA.INNODB_BUFFER_PAGE
+
+# This test assumes that buffer pool is idle
+# with key rotation threads buffer pages gets evicted this
+# testcase gets flaky
+-- source include/not_encrypted.inc
+
+-- source include/have_innodb.inc
+
+--replace_regex /([0-9]*\.)?[0-9]+/#/
+SELECT * FROM INFORMATION_SCHEMA.INNODB_BUFFER_POOL_STATS;
+
+# Create a table and check its page info behave correctly in the pool
+CREATE TABLE infoschema_buffer_test (col1 INT) ENGINE = INNODB;
+
+INSERT INTO infoschema_buffer_test VALUES(9);
+
+# We should be able to see this table in the buffer pool if we check
+# right away
+--sorted_result
+--replace_column 2 # 3 # 7 FIX 8 AHI 9 LSN 10 LSN 11 TIME 18 IO_FIX 19 OLD 20 #
+SELECT * FROM INFORMATION_SCHEMA.INNODB_BUFFER_PAGE
+WHERE TABLE_NAME LIKE '%infoschema_buffer_test%' AND PAGE_TYPE='index';
+
+# The NUMBER_RECORDS and DATA_SIZE should check with each insertion
+INSERT INTO infoschema_buffer_test VALUES(19);
+
+CREATE INDEX idx ON infoschema_buffer_test(col1);
+
+--sorted_result
+--replace_column 2 # 3 # 7 FIX 8 AHI 9 LSN 10 LSN 11 TIME 18 IO_FIX 19 OLD 20 #
+SELECT * FROM INFORMATION_SCHEMA.INNODB_BUFFER_PAGE
+WHERE TABLE_NAME LIKE '%infoschema_buffer_test%' AND PAGE_TYPE='index';
+
+# Check the buffer after dropping the table
+DROP TABLE infoschema_buffer_test;
+
+SELECT * FROM INFORMATION_SCHEMA.INNODB_BUFFER_PAGE
+WHERE TABLE_NAME LIKE '%infoschema_buffer_test%';
+
+CREATE TABLE infoschema_parent (id INT NOT NULL, PRIMARY KEY (id))
+ENGINE=INNODB;
+
+CREATE TABLE infoschema_child (id INT, parent_id INT, INDEX par_ind (parent_id),
+ FOREIGN KEY (parent_id)
+ REFERENCES infoschema_parent(id)
+ ON DELETE CASCADE)
+ENGINE=INNODB;
+
+--sorted_result
+--replace_column 2 # 3 # 7 FIX 8 AHI 9 LSN 10 LSN 11 TIME 18 IO_FIX 19 OLD 20 #
+SELECT * FROM INFORMATION_SCHEMA.INNODB_BUFFER_PAGE
+WHERE TABLE_NAME LIKE '%infoschema_child%';
+
+DROP TABLE infoschema_child;
+DROP TABLE infoschema_parent;
diff --git a/mysql-test/suite/innodb/t/innodb_information_schema_tables.opt b/mysql-test/suite/innodb/t/innodb_information_schema_tables.opt
new file mode 100644
index 00000000..4edc71b6
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb_information_schema_tables.opt
@@ -0,0 +1,28 @@
+--loose-innodb_trx
+--loose-innodb_locks
+--loose-innodb_lock_waits
+--loose-innodb_cmp
+--loose-innodb_cmp_reset
+--loose-innodb_cmp_per_index
+--loose-innodb_cmp_per_index_reset
+--loose-innodb_cmpmem
+--loose-innodb_cmpmem_reset
+--loose-innodb_buffer_page
+--loose-innodb_buffer_page_lru
+--loose-innodb_buffer_stats
+--loose-innodb_sys_tables
+--loose-innodb_sys_tablestats
+--loose-innodb_sys_indexes
+--loose-innodb_sys_columns
+--loose-innodb_sys_fields
+--loose-innodb_sys_foreign
+--loose-innodb_sys_foreign_cols
+--loose-innodb_changed_pages
+--loose-innodb_rseg
+--loose-innodb_sys_stats
+--loose-innodb_table_stats
+--loose-innodb_index_stats
+--loose-innodb_admin_command
+--loose-innodb_buffer_pool_pages
+--loose-innodb_buffer_pool_pages_index
+--loose-innodb_buffer_pool_pages_blob
diff --git a/mysql-test/suite/innodb/t/innodb_information_schema_tables.test b/mysql-test/suite/innodb/t/innodb_information_schema_tables.test
new file mode 100644
index 00000000..15b3bf4f
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb_information_schema_tables.test
@@ -0,0 +1,64 @@
+-- source include/have_innodb.inc
+-- source include/not_embedded.inc
+
+#
+# MDEV-7762 InnoDB: Failing assertion: block->page.buf_fix_count > 0 in buf0buf.ic line 730
+#
+# Make sure that all supported information_schema tables are readable
+# (actual result sets are not important).
+#
+CREATE TABLE t1 ENGINE=InnoDB AS SELECT * FROM mysql.help_topic;
+
+--disable_query_log
+--disable_result_log
+BEGIN;
+SELECT * FROM t1 FOR UPDATE;
+SELECT * FROM INFORMATION_SCHEMA.INNODB_TRX;
+SELECT * FROM INFORMATION_SCHEMA.INNODB_LOCKS;
+SELECT * FROM INFORMATION_SCHEMA.INNODB_LOCK_WAITS;
+SELECT * FROM INFORMATION_SCHEMA.INNODB_CMP;
+SELECT * FROM INFORMATION_SCHEMA.INNODB_CMP_RESET;
+SELECT * FROM INFORMATION_SCHEMA.INNODB_CMPMEM;
+SELECT * FROM INFORMATION_SCHEMA.INNODB_CMPMEM_RESET;
+SELECT * FROM INFORMATION_SCHEMA.INNODB_BUFFER_PAGE;
+SELECT * FROM INFORMATION_SCHEMA.INNODB_BUFFER_PAGE_LRU;
+--error 0,1109
+SELECT * FROM INFORMATION_SCHEMA.INNODB_BUFFER_STATS;
+--error 0,1109
+SELECT * FROM INFORMATION_SCHEMA.INNODB_SYS_TABLES;
+--error 0,1109
+SELECT * FROM INFORMATION_SCHEMA.INNODB_SYS_TABLESTATS;
+--error 0,1109
+SELECT * FROM INFORMATION_SCHEMA.INNODB_SYS_INDEXES;
+--error 0,1109
+SELECT * FROM INFORMATION_SCHEMA.INNODB_SYS_COLUMNS;
+--error 0,1109
+SELECT * FROM INFORMATION_SCHEMA.INNODB_SYS_FIELDS;
+--error 0,1109
+SELECT * FROM INFORMATION_SCHEMA.INNODB_SYS_FOREIGN;
+--error 0,1109
+SELECT * FROM INFORMATION_SCHEMA.INNODB_SYS_FOREIGN_COLS;
+--error 0,1109
+SELECT * FROM INFORMATION_SCHEMA.INNODB_RSEG;
+--error 0,1109
+SELECT * FROM INFORMATION_SCHEMA.INNODB_UNDO_LOGS;
+--error 0,1109
+SELECT * FROM INFORMATION_SCHEMA.INNODB_SYS_STATS;
+--error 0,1109
+SELECT * FROM INFORMATION_SCHEMA.INNODB_TABLE_STATS;
+--error 0,1109
+SELECT * FROM INFORMATION_SCHEMA.INNODB_INDEX_STATS;
+--error 0,1109
+SELECT * FROM INFORMATION_SCHEMA.INNODB_ADMIN_COMMAND;
+--error 0,1109
+SELECT * FROM INFORMATION_SCHEMA.INNODB_BUFFER_POOL_PAGES;
+--error 0,1109
+SELECT * FROM INFORMATION_SCHEMA.INNODB_BUFFER_POOL_PAGES_INDEX;
+--error 0,1109
+SELECT * FROM INFORMATION_SCHEMA.INNODB_BUFFER_POOL_PAGES_BLOB;
+--error 0,1109
+SELECT * FROM INFORMATION_SCHEMA.INNODB_CHANGED_PAGES;
+COMMIT;
+--enable_query_log
+--enable_result_log
+DROP TABLE t1;
diff --git a/mysql-test/suite/innodb/t/innodb_lock_wait_timeout_1-master.opt b/mysql-test/suite/innodb/t/innodb_lock_wait_timeout_1-master.opt
new file mode 100644
index 00000000..82dec8b2
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb_lock_wait_timeout_1-master.opt
@@ -0,0 +1 @@
+--loose-innodb_lock_wait_timeout=1
diff --git a/mysql-test/suite/innodb/t/innodb_lock_wait_timeout_1.test b/mysql-test/suite/innodb/t/innodb_lock_wait_timeout_1.test
new file mode 100644
index 00000000..ea31d4a1
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb_lock_wait_timeout_1.test
@@ -0,0 +1,244 @@
+--source include/have_innodb.inc
+
+--echo #
+--echo # Bug #40113: Embedded SELECT inside UPDATE or DELETE can timeout
+--echo # without error
+--echo #
+
+CREATE TABLE t1 (a int, b int, PRIMARY KEY (a,b)) ENGINE=InnoDB;
+
+INSERT INTO t1 (a,b) VALUES (1070109,99);
+
+CREATE TABLE t2 (b int, a int, PRIMARY KEY (b)) ENGINE=InnoDB;
+
+INSERT INTO t2 (b,a) VALUES (7,1070109);
+
+SELECT * FROM t1;
+
+BEGIN;
+
+SELECT b FROM t2 WHERE b=7 FOR UPDATE;
+
+CONNECT (addconroot, localhost, root,,);
+CONNECTION addconroot;
+
+BEGIN;
+
+--error ER_LOCK_WAIT_TIMEOUT
+SELECT b FROM t2 WHERE b=7 FOR UPDATE;
+
+--error ER_LOCK_WAIT_TIMEOUT
+INSERT IGNORE INTO t1 (a) VALUES ((SELECT a FROM t2 WHERE b=7));
+
+--error ER_LOCK_WAIT_TIMEOUT
+UPDATE t1 SET a='7000000' WHERE a=(SELECT a FROM t2 WHERE b=7);
+
+--error ER_LOCK_WAIT_TIMEOUT
+DELETE FROM t1 WHERE a=(SELECT a FROM t2 WHERE b=7);
+
+SELECT * FROM t1;
+
+CONNECTION default;
+DISCONNECT addconroot;
+
+DROP TABLE t2, t1;
+
+--echo # End of 5.0 tests
+
+--echo #
+--echo # Bug#46539 Various crashes on INSERT IGNORE SELECT + SELECT
+--echo # FOR UPDATE
+--echo #
+create table t1 (a int primary key auto_increment,
+ b int, index(b)) engine=innodb;
+insert into t1 (b) values (1), (2), (3), (4), (5), (6), (7), (8), (9), (10);
+set autocommit=0;
+begin;
+select * from t1 where b=5 for update;
+connect (con1, localhost, root,,);
+connection con1;
+--error ER_LOCK_WAIT_TIMEOUT
+insert ignore into t1 (b) select a as b from t1;
+connection default;
+--echo # Cleanup
+--echo #
+disconnect con1;
+commit;
+set autocommit=default;
+drop table t1;
+
+--echo #
+--echo # Bug #37183 insert ignore into .. select ... hangs
+--echo # after deadlock was encountered
+--echo #
+connect (con1,localhost,root,,);
+create table t1(id int primary key,v int)engine=innodb;
+insert into t1 values (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7);
+create table t2 like t1;
+
+--connection con1
+begin;
+update t1 set v=id*2 where id=1;
+
+--connection default
+begin;
+update t1 set v=id*2 where id=2;
+
+--connection con1
+--error 1205
+update t1 set v=id*2 where id=2;
+
+--connection default
+--error 1205
+insert ignore into t2 select * from t1 where id=1;
+rollback;
+
+--connection con1
+rollback;
+
+--connection default
+disconnect con1;
+drop table t1, t2;
+
+
+--echo #
+--echo # Bug#41756 Strange error messages about locks from InnoDB
+--echo #
+--echo # In the default transaction isolation mode,
+--echo # handler::unlock_row() in InnoDB does nothing.
+--echo # Thus in order to reproduce the condition that led to the
+--echo # warning, one needs to relax isolation by either
+--echo # setting a weaker tx_isolation value, or by turning on
+--echo # the unsafe replication switch.
+set @@session.tx_isolation="read-committed";
+
+--echo # Prepare data. We need a table with a unique index,
+--echo # for join_read_key to be used. The other column
+--echo # allows to control what passes WHERE clause filter.
+create table t1 (a int primary key, b int) engine=innodb;
+--echo # Let's make sure t1 has sufficient amount of rows
+--echo # to exclude JT_ALL access method when reading it,
+--echo # i.e. make sure that JT_EQ_REF(a) is always preferred.
+insert into t1 values (1,1), (2,null), (3,1), (4,1),
+ (5,1), (6,1), (7,1), (8,1), (9,1), (10,1),
+ (11,1), (12,1), (13,1), (14,1), (15,1),
+ (16,1), (17,1), (18,1), (19,1), (20,1);
+--echo #
+--echo # Demonstrate that for the SELECT statement
+--echo # used later in the test JT_EQ_REF access method is used.
+--echo #
+--vertical_results
+--replace_result "Using index condition; Using where" "Using where"
+explain
+select 1 from t1 natural join (select 2 as a, 1 as b union all
+ select 2 as a, 2 as b) as t2 for update;
+--horizontal_results
+--echo #
+--echo # Demonstrate that the reported SELECT statement
+--echo # no longer produces warnings.
+--echo #
+select 1 from t1 natural join (select 2 as a, 1 as b union all
+ select 2 as a, 2 as b) as t2 for update;
+commit;
+--echo #
+--echo # Demonstrate that due to lack of inter-sweep "reset" function,
+--echo # we keep some non-matching records locked, even though we know
+--echo # we could unlock them.
+--echo # To do that, show that if there is only one distinct value
+--echo # for a in t2 (a=2), we will keep record (2,null) in t1 locked.
+--echo # But if we add another value for "a" to t2, say 6,
+--echo # join_read_key cache will be pruned at least once,
+--echo # and thus record (2, null) in t1 will get unlocked.
+--echo #
+begin;
+select 1 from t1 natural join (select 2 as a, 1 as b union all
+ select 2 as a, 2 as b) as t2 for update;
+connect (con1,localhost,root,,);
+connection con1;
+--echo # We should be able to delete all records from t1 except (2, null),
+--echo # since they were not locked.
+begin;
+--echo # Delete in series of 3 records so that full scan
+--echo # is not used and we're not blocked on record (2,null)
+delete from t1 where a in (1,3,4);
+delete from t1 where a in (5,6,7);
+delete from t1 where a in (8,9,10);
+delete from t1 where a in (11,12,13);
+delete from t1 where a in (14,15,16);
+delete from t1 where a in (17,18);
+delete from t1 where a in (19,20);
+--echo #
+--echo # Record (2, null) is locked. This is actually unnecessary,
+--echo # because the previous select returned no rows.
+--echo # Just demonstrate the effect.
+--echo #
+--error ER_LOCK_WAIT_TIMEOUT
+delete from t1;
+rollback;
+connection default;
+--echo #
+--echo # Show that the original contents of t1 is intact:
+select * from t1;
+commit;
+--echo #
+--echo # Have a one more record in t2 to show that
+--echo # if join_read_key cache is purned, the current
+--echo # row under the cursor is unlocked (provided, this row didn't
+--echo # match the partial WHERE clause, of course).
+--echo # Sic: the result of this test dependent on the order of retrieval
+--echo # of records --echo # from the derived table, if !
+--echo # We use DELETE to disable the JOIN CACHE. This DELETE modifies no
+--echo # records. It also should leave no InnoDB row locks.
+--echo #
+begin;
+delete t1.* from t1 natural join (select 2 as a, 2 as b union all
+ select 0 as a, 0 as b) as t2;
+--echo # Demonstrate that nothing was deleted form t1
+select * from t1;
+connection con1;
+begin;
+--echo # Since there is another distinct record in the derived table
+--echo # the previous matching record in t1 -- (2,null) -- was unlocked.
+delete from t1;
+--echo # We will need the contents of the table again.
+rollback;
+select * from t1;
+commit;
+connection default;
+rollback;
+begin;
+--echo #
+--echo # Before this patch, we could wrongly unlock a record
+--echo # that was cached and later used in a join. Demonstrate that
+--echo # this is no longer the case.
+--echo # Sic: this test is also order-dependent (i.e. the
+--echo # the bug would show up only if the first record in the union
+--echo # is retreived and processed first.
+--echo #
+--echo # Verify that JT_EQ_REF is used.
+--vertical_results
+--replace_result "Using index condition; Using where" "Using where"
+explain
+select 1 from t1 natural join (select 3 as a, 2 as b union all
+ select 3 as a, 1 as b) as t2 for update;
+--horizontal_results
+--echo # Lock the record.
+select 1 from t1 natural join (select 3 as a, 2 as b union all
+ select 3 as a, 1 as b) as t2 for update;
+connection con1;
+--echo #
+--echo # We should not be able to delete record (3,1) from t1,
+--echo # (previously it was possible).
+--echo #
+--error ER_LOCK_WAIT_TIMEOUT
+delete from t1 where a=3;
+connection default;
+commit;
+
+disconnect con1;
+set @@session.tx_isolation=default;
+drop table t1;
+
+--echo #
+--echo # End of 5.1 tests
+--echo #
diff --git a/mysql-test/suite/innodb/t/innodb_multi_update.test b/mysql-test/suite/innodb/t/innodb_multi_update.test
new file mode 100644
index 00000000..74a7aea7
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb_multi_update.test
@@ -0,0 +1,39 @@
+--source include/have_innodb.inc
+
+#
+# Test multi update with different join methods
+#
+
+CREATE TABLE bug38999_1 (a int not null primary key, b int not null, key (b)) engine=innodb;
+CREATE TABLE bug38999_2 (a int not null primary key, b int not null, key (b)) engine=innodb;
+INSERT INTO bug38999_1 values (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10),(11,11),(12,12);
+INSERT INTO bug38999_2 values (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9);
+
+# Full join, without key
+update bug38999_1,bug38999_2 set bug38999_1.a=bug38999_1.a+100;
+select * from bug38999_1;
+
+# unique key
+update bug38999_1,bug38999_2 set bug38999_1.a=bug38999_1.a+100 where bug38999_1.a=101;
+select * from bug38999_1;
+
+# ref key
+update bug38999_1,bug38999_2 set bug38999_1.b=bug38999_1.b+10 where bug38999_1.b=2;
+select * from bug38999_1;
+
+# Range key (in bug38999_1)
+update bug38999_1,bug38999_2 set bug38999_1.b=bug38999_1.b+2,bug38999_2.b=bug38999_1.b+10 where bug38999_1.b between 3 and 5 and bug38999_1.a=bug38999_2.a+100;
+select * from bug38999_1;
+select * from bug38999_2;
+
+drop table bug38999_1,bug38999_2;
+
+--echo #
+--echo # Bug#54475 improper error handling causes cascading crashing failures in innodb
+--echo #
+CREATE TABLE t1(f1 INT) ENGINE=INNODB;
+INSERT INTO t1 VALUES(1);
+--error ER_OPERAND_COLUMNS
+UPDATE (SELECT ((SELECT 1 FROM t1), 1) FROM t1 WHERE (SELECT 1 FROM t1)) x, (SELECT 1) AS d SET d.f1 = 1;
+UPDATE (SELECT ((SELECT 1 FROM t1),1) = (1,1) FROM t1 WHERE (SELECT 1 FROM t1)) x, t1 AS d SET d.f1 = 1;
+DROP TABLE t1;
diff --git a/mysql-test/suite/innodb/t/innodb_mysql-master.opt b/mysql-test/suite/innodb/t/innodb_mysql-master.opt
new file mode 100644
index 00000000..17dd95cd
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb_mysql-master.opt
@@ -0,0 +1,2 @@
+--loose-innodb-lock-wait-timeout=2
+--default-storage-engine=MyISAM
diff --git a/mysql-test/suite/innodb/t/innodb_mysql.test b/mysql-test/suite/innodb/t/innodb_mysql.test
new file mode 100644
index 00000000..d495186d
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb_mysql.test
@@ -0,0 +1,1076 @@
+# t/innodb_mysql.test
+#
+# Last update:
+# 2006-07-26 ML test refactored (MySQL 5.1)
+# main testing code t/innodb_mysql.test -> include/mix1.inc
+#
+
+#Want to skip this test from daily Valgrind execution.
+--source include/no_valgrind_without_big.inc
+# Adding big test option for this test.
+--source include/big_test.inc
+
+-- source include/have_innodb.inc
+let $engine_type= InnoDB;
+let $other_engine_type= MEMORY;
+# InnoDB does support FOREIGN KEYs
+let $test_foreign_keys= 1;
+--source include/mix1.inc
+
+--disable_warnings
+drop table if exists t1, t2, t3;
+--enable_warnings
+--echo #
+--echo # BUG#35850: Performance regression in 5.1.23/5.1.24
+--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, pk int, key(a,b), primary key(pk)) engine=innodb;
+insert into t2 select @a:=A.a+10*(B.a + 10*C.a),@a, @a from t1 A, t1 B, t1 C;
+--echo # this must use key 'a', not PRIMARY:
+--replace_column 9 #
+explain select a from t2 where a=b;
+drop table t1, t2;
+
+--echo #
+--echo # Bug #40360: Binlog related errors with binlog off
+--echo #
+# This bug is triggered when the binlog format is STATEMENT and the
+# binary log is turned off. In this case, no error should be shown for
+# the statement since there are no replication issues.
+
+SET SESSION BINLOG_FORMAT=STATEMENT;
+SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED;
+query_vertical select @@session.sql_log_bin, @@session.binlog_format, @@session.tx_isolation;
+CREATE TABLE t1 ( a INT ) ENGINE=InnoDB;
+INSERT INTO t1 VALUES(1);
+DROP TABLE t1;
+
+--echo #
+--echo # Bug#37284 Crash in Field_string::type()
+--echo #
+--disable_warnings
+DROP TABLE IF EXISTS t1;
+--enable_warnings
+CREATE TABLE t1 (a char(50)) ENGINE=InnoDB;
+CREATE INDEX i1 on t1 (a(3));
+SELECT * FROM t1 WHERE a = 'abcde';
+DROP TABLE t1;
+
+--echo #
+--echo # Bug #37742: HA_EXTRA_KEYREAD flag is set when key contains only prefix of
+--echo # requested column
+--echo #
+
+CREATE TABLE foo (a int, b int, c char(10),
+ PRIMARY KEY (c(3)),
+ KEY b (b)
+) engine=innodb;
+
+CREATE TABLE foo2 (a int, b int, c char(10),
+ PRIMARY KEY (c),
+ KEY b (b)
+) engine=innodb;
+
+CREATE TABLE bar (a int, b int, c char(10),
+ PRIMARY KEY (c(3)),
+ KEY b (b)
+) engine=myisam;
+
+INSERT INTO foo VALUES
+ (1,2,'abcdefghij'), (2,3,''), (3,4,'klmnopqrst'),
+ (4,5,'uvwxyz'), (5,6,'meotnsyglt'), (4,5,'asfdewe');
+
+INSERT INTO bar SELECT * FROM foo;
+INSERT INTO foo2 SELECT * FROM foo;
+
+-- disable_result_log
+ANALYZE TABLE bar;
+ANALYZE TABLE foo;
+ANALYZE TABLE foo2;
+-- enable_result_log
+
+--query_vertical EXPLAIN SELECT c FROM bar WHERE b>2;
+--query_vertical EXPLAIN SELECT c FROM foo WHERE b>2;
+--query_vertical EXPLAIN SELECT c FROM foo2 WHERE b>2;
+
+--query_vertical EXPLAIN SELECT c FROM bar WHERE c>2;
+--query_vertical EXPLAIN SELECT c FROM foo WHERE c>2;
+--query_vertical EXPLAIN SELECT c FROM foo2 WHERE c>2;
+
+DROP TABLE foo, bar, foo2;
+
+
+--echo #
+--echo # Bug#41348: INSERT INTO tbl SELECT * FROM temp_tbl overwrites locking type of temp table
+--echo #
+
+--disable_warnings
+DROP TABLE IF EXISTS t1,t3,t2;
+DROP FUNCTION IF EXISTS f1;
+--enable_warnings
+
+DELIMITER |;
+CREATE FUNCTION f1() RETURNS VARCHAR(250)
+ BEGIN
+ return 'hhhhhhh' ;
+ END|
+DELIMITER ;|
+
+CREATE TABLE t1 (a VARCHAR(20), b VARCHAR(20), c VARCHAR(20)) ENGINE=INNODB;
+
+BEGIN WORK;
+
+CREATE TEMPORARY TABLE t2 (a VARCHAR(20), b VARCHAR(20), c varchar(20)) ENGINE=INNODB;
+CREATE TEMPORARY TABLE t3 LIKE t2;
+
+INSERT INTO t1 VALUES ('a','b',NULL),('c','d',NULL),('e','f',NULL);
+
+SET @stmt := CONCAT('INSERT INTO t2 SELECT tbl.a, tbl.b, f1()',' FROM t1 tbl');
+PREPARE stmt1 FROM @stmt;
+
+SET @stmt := CONCAT('INSERT INTO t3', ' SELECT * FROM t2');
+PREPARE stmt3 FROM @stmt;
+
+EXECUTE stmt1;
+
+COMMIT;
+
+DEALLOCATE PREPARE stmt1;
+DEALLOCATE PREPARE stmt3;
+
+DROP TABLE t1,t3,t2;
+DROP FUNCTION f1;
+
+--echo #
+--echo # Bug#37016: TRUNCATE TABLE removes some rows but not all
+--echo #
+
+--disable_warnings
+DROP TABLE IF EXISTS t1,t2;
+--enable_warnings
+
+CREATE TABLE t1 (id INT NOT NULL, PRIMARY KEY (id)) ENGINE=INNODB;
+CREATE TABLE t2 (id INT PRIMARY KEY,
+ t1_id INT, INDEX par_ind (t1_id),
+ FOREIGN KEY (t1_id) REFERENCES t1(id)) ENGINE=INNODB;
+INSERT INTO t1 VALUES (1),(2);
+INSERT INTO t2 VALUES (3,2);
+
+SET AUTOCOMMIT = 0;
+
+START TRANSACTION;
+--error ER_TRUNCATE_ILLEGAL_FK
+TRUNCATE TABLE t1;
+SELECT * FROM t1;
+COMMIT;
+SELECT * FROM t1;
+
+START TRANSACTION;
+--error ER_TRUNCATE_ILLEGAL_FK
+TRUNCATE TABLE t1;
+SELECT * FROM t1;
+ROLLBACK;
+SELECT * FROM t1;
+
+SET AUTOCOMMIT = 1;
+
+START TRANSACTION;
+SELECT * FROM t1;
+COMMIT;
+
+--error ER_TRUNCATE_ILLEGAL_FK
+TRUNCATE TABLE t1;
+SELECT * FROM t1;
+DELETE FROM t2 WHERE id = 3;
+
+START TRANSACTION;
+SELECT * FROM t1;
+--error ER_TRUNCATE_ILLEGAL_FK
+TRUNCATE TABLE t1;
+ROLLBACK;
+SELECT * FROM t1;
+TRUNCATE TABLE t2;
+
+DROP TABLE t2;
+DROP TABLE t1;
+
+--echo #
+--echo # Bug#40127 Multiple table DELETE IGNORE hangs on foreign key constraint violation on 5.0
+--echo #
+CREATE TABLE t1 (
+ id INT UNSIGNED NOT NULL AUTO_INCREMENT,
+ PRIMARY KEY (id)
+) ENGINE=InnoDB;
+
+CREATE TABLE t2 (
+ id INT UNSIGNED NOT NULL AUTO_INCREMENT,
+ aid INT UNSIGNED NOT NULL,
+ PRIMARY KEY (id),
+ FOREIGN KEY (aid) REFERENCES t1 (id)
+) ENGINE=InnoDB;
+
+CREATE TABLE t3 (
+ bid INT UNSIGNED NOT NULL,
+ FOREIGN KEY (bid) REFERENCES t2 (id)
+) ENGINE=InnoDB;
+
+CREATE TABLE t4 (
+ a INT
+) ENGINE=InnoDB;
+
+CREATE TABLE t5 (
+ a INT
+) ENGINE=InnoDB;
+
+INSERT INTO t1 (id) VALUES (1);
+INSERT INTO t2 (id, aid) VALUES (1, 1),(2,1),(3,1),(4,1);
+INSERT INTO t3 (bid) VALUES (1);
+
+INSERT INTO t4 VALUES (1),(2),(3),(4),(5);
+INSERT INTO t5 VALUES (1);
+
+DELETE t5 FROM t4 LEFT JOIN t5 ON t4.a= t5.a;
+
+--error ER_ROW_IS_REFERENCED_2
+DELETE t2, t1 FROM t2 INNER JOIN t1 ON (t2.aid = t1.id) WHERE t2.id = 1;
+--error ER_ROW_IS_REFERENCED_2
+DELETE t2, t1 FROM t2 INNER JOIN t1 ON (t2.aid = t1.id) WHERE t2.id = 1;
+
+DELETE IGNORE t2, t1 FROM t2 INNER JOIN t1 ON (t2.aid = t1.id) WHERE t2.id = 1;
+
+DROP TABLE t3;
+DROP TABLE t2;
+DROP TABLE t1;
+DROP TABLES t4,t5;
+
+--echo # Bug#40127 Multiple table DELETE IGNORE hangs on foreign key constraint violation on 5.0
+--echo # Testing for any side effects of IGNORE on AFTER DELETE triggers used with
+--echo # transactional tables.
+--echo #
+CREATE TABLE t1 (i INT NOT NULL PRIMARY KEY) ENGINE=InnoDB;
+CREATE TABLE t2 (a VARCHAR(100)) ENGINE=InnoDB;
+CREATE TABLE t3 (i INT NOT NULL PRIMARY KEY) ENGINE=InnoDB;
+CREATE TABLE t4 (i INT NOT NULL PRIMARY KEY, t1i INT,
+ FOREIGN KEY (t1i) REFERENCES t1(i))
+ ENGINE=InnoDB;
+delimiter ||;
+CREATE TRIGGER trg AFTER DELETE ON t1 FOR EACH ROW
+BEGIN
+ SET @b:='EXECUTED TRIGGER';
+ INSERT INTO t2 VALUES (@b);
+ SET @a:= error_happens_here;
+END||
+delimiter ;||
+
+SET @b:="";
+SET @a:="";
+INSERT INTO t1 VALUES (1),(2),(3),(4);
+INSERT INTO t3 SELECT * FROM t1;
+--echo ** An error in a trigger causes rollback of the statement.
+--error ER_BAD_FIELD_ERROR
+DELETE t1 FROM t3 LEFT JOIN t1 ON t1.i=t3.i;
+SELECT @a,@b;
+SELECT * FROM t2;
+SELECT * FROM t1 LEFT JOIN t3 ON t1.i=t3.i;
+
+--echo ** Same happens with the IGNORE option
+--error ER_BAD_FIELD_ERROR
+DELETE IGNORE t1 FROM t3 LEFT JOIN t1 ON t1.i=t3.i;
+SELECT * FROM t2;
+SELECT * FROM t1 LEFT JOIN t3 ON t1.i=t3.i;
+
+--echo **
+--echo ** The following is an attempt to demonstrate
+--echo ** error handling inside a row iteration.
+--echo **
+DROP TRIGGER trg;
+DELETE FROM t1;
+DELETE FROM t2;
+DELETE FROM t3;
+
+INSERT INTO t1 VALUES (1),(2),(3),(4);
+INSERT INTO t3 VALUES (1),(2),(3),(4);
+INSERT INTO t4 VALUES (3,3),(4,4);
+
+delimiter ||;
+CREATE TRIGGER trg AFTER DELETE ON t1 FOR EACH ROW
+BEGIN
+ SET @b:= CONCAT('EXECUTED TRIGGER FOR ROW ',CAST(OLD.i AS CHAR));
+ INSERT INTO t2 VALUES (@b);
+END||
+delimiter ;||
+
+--echo ** DELETE is prevented by foreign key constrains but errors are silenced.
+--echo ** The AFTER trigger isn't fired.
+DELETE IGNORE t1 FROM t3 LEFT JOIN t1 ON t1.i=t3.i;
+--echo ** Tables are modified by best effort:
+SELECT * FROM t1 LEFT JOIN t3 ON t1.i=t3.i;
+--echo ** The AFTER trigger was only executed on successful rows:
+SELECT * FROM t2;
+
+DROP TRIGGER trg;
+
+--echo **
+--echo ** Induce an error midway through an AFTER-trigger
+--echo **
+DELETE FROM t4;
+DELETE FROM t1;
+DELETE FROM t3;
+INSERT INTO t1 VALUES (1),(2),(3),(4);
+INSERT INTO t3 VALUES (1),(2),(3),(4);
+delimiter ||;
+CREATE TRIGGER trg AFTER DELETE ON t1 FOR EACH ROW
+BEGIN
+ SET @a:= @a+1;
+ IF @a > 2 THEN
+ INSERT INTO t4 VALUES (5,5);
+ END IF;
+END||
+delimiter ;||
+
+SET @a:=0;
+--echo ** Errors in the trigger causes the statement to abort.
+--error ER_NO_REFERENCED_ROW_2
+DELETE IGNORE t1 FROM t3 LEFT JOIN t1 ON t1.i=t3.i;
+SELECT * FROM t1 LEFT JOIN t3 ON t1.i=t3.i;
+SELECT * FROM t4;
+
+DROP TRIGGER trg;
+DROP TABLE t4;
+DROP TABLE t1;
+DROP TABLE t2;
+DROP TABLE t3;
+
+--echo #
+--echo # Bug#43580: Issue with Innodb on multi-table update
+--echo #
+CREATE TABLE t1 (a INT, b INT, KEY (a)) ENGINE = INNODB;
+CREATE TABLE t2 (a INT KEY, b INT, KEY (b)) ENGINE = INNODB;
+
+CREATE TABLE t3 (a INT, b INT KEY, KEY (a)) ENGINE = INNODB;
+CREATE TABLE t4 (a INT KEY, b INT, KEY (b)) ENGINE = INNODB;
+
+INSERT INTO t1 VALUES (1, 1), (2, 2), (3, 3), (4, 4), (5, 5), (6, 6);
+INSERT INTO t2 VALUES (1, 1), (2, 2), (3, 3), (4, 4), (5, 5);
+
+INSERT INTO t3 VALUES (1, 101), (2, 102), (3, 103), (4, 104), (5, 105), (6, 106);
+INSERT INTO t4 VALUES (1, 1), (2, 2), (3, 3), (4, 4), (5, 5);
+
+# Because t1.a changes and t2.b changes based on t1.a, the result
+# depends on join order, so STRAIGHT_JOIN is used to have it repeatable.
+UPDATE t2 straight_join t1 SET t1.a = t1.a + 100, t2.b = t1.a + 10
+WHERE t1.a BETWEEN 2 AND 4 AND t2.a = t1.b;
+--sorted_result
+SELECT * FROM t2;
+
+# Because t1.a changes and t2.b changes based on t1.a, the result
+# depends on join order, so STRAIGHT_JOIN is used to have it repeatable.
+UPDATE t4 straight_join t3 SET t3.a = t3.a + 100, t4.b = t3.a + 10
+WHERE t3.a BETWEEN 2 AND 4 AND t4.a = t3.b - 100;
+--sorted_result
+SELECT * FROM t4;
+
+DROP TABLE t1, t2, t3, t4;
+
+--echo #
+--echo # Bug#44886: SIGSEGV in test_if_skip_sort_order() -
+--echo # uninitialized variable used as subscript
+--echo #
+
+CREATE TABLE t1 (a INT, b INT, c INT, d INT, PRIMARY KEY (b), KEY (a,c))
+ ENGINE=InnoDB;
+INSERT INTO t1 VALUES (1,1,1,0);
+
+CREATE TABLE t2 (a INT, b INT, e INT, KEY (e)) ENGINE=InnoDB;
+INSERT INTO t2 VALUES (1,1,2);
+
+CREATE TABLE t3 (a INT, b INT) ENGINE=MyISAM;
+INSERT INTO t3 VALUES (1, 1);
+
+SELECT * FROM t1, t2, t3
+ WHERE t1.a = t3.a AND (t1.b = t3.b OR t1.d) AND t2.b = t1.b AND t2.e = 2
+ GROUP BY t1.b;
+
+DROP TABLE t1, t2, t3;
+
+--echo #
+--echo # Bug #45828: Optimizer won't use partial primary key if another
+--echo # index can prevent filesort
+--echo #
+
+# Create the table
+CREATE TABLE `t1` (
+ c1 int NOT NULL,
+ c2 int NOT NULL,
+ c3 int NOT NULL,
+ PRIMARY KEY (c1,c2),
+ KEY (c3)
+) ENGINE=InnoDB;
+
+# populate with data
+INSERT INTO t1 VALUES (5,2,1246276747);
+INSERT INTO t1 VALUES (2,1,1246281721);
+INSERT INTO t1 VALUES (7,3,1246281756);
+INSERT INTO t1 VALUES (4,2,1246282139);
+INSERT INTO t1 VALUES (3,1,1246282230);
+INSERT INTO t1 VALUES (1,0,1246282712);
+INSERT INTO t1 VALUES (8,3,1246282765);
+INSERT INTO t1 SELECT c1+10,c2+10,c3+10 FROM t1;
+INSERT INTO t1 SELECT c1+100,c2+100,c3+100 from t1;
+INSERT INTO t1 SELECT c1+1000,c2+1000,c3+1000 from t1;
+INSERT INTO t1 SELECT c1+10000,c2+10000,c3+10000 from t1;
+INSERT INTO t1 SELECT c1+100000,c2+100000,c3+100000 from t1;
+INSERT INTO t1 SELECT c1+1000000,c2+1000000,c3+1000000 from t1;
+ANALYZE TABLE t1;
+# query and no rows will match the c1 condition, whereas all will match c3
+SELECT * FROM t1 WHERE c1 = 99999999 AND c3 > 1 ORDER BY c3;
+
+# SHOULD use the pk.
+# index on c3 will be used instead of primary key
+EXPLAIN SELECT * FROM t1 WHERE c1 = 99999999 AND c3 > 1 ORDER BY c3;
+
+# if we force the primary key, we can see the estimate is 1
+EXPLAIN SELECT * FROM t1 FORCE INDEX (PRIMARY) WHERE c1 = 99999999 AND c3 > 1 ORDER BY c3;
+
+
+CREATE TABLE t2 (
+ c1 int NOT NULL,
+ c2 int NOT NULL,
+ c3 int NOT NULL,
+ KEY (c1,c2),
+ KEY (c3)
+) ENGINE=InnoDB;
+
+# SHOULD use the pk.
+# if we switch it from a primary key to a regular index, it works correctly as well
+explain SELECT * FROM t2 WHERE c1 = 99999999 AND c3 > 1 ORDER BY c3;
+
+DROP TABLE t1,t2;
+
+
+--echo #
+--echo # 36259: Optimizing with ORDER BY
+--echo #
+
+CREATE TABLE t1 (
+ a INT NOT NULL AUTO_INCREMENT,
+ b INT NOT NULL,
+ c INT NOT NULL,
+ d VARCHAR(5),
+ e INT NOT NULL,
+ PRIMARY KEY (a), KEY i2 (b,c,d)
+) ENGINE=InnoDB;
+
+INSERT INTO t1 (b,c,d,e) VALUES (1,1,'a',1), (2,2,'b',2);
+INSERT INTO t1 (b,c,d,e) SELECT RAND()*10000, RAND()*10000, d, e FROM t1;
+INSERT INTO t1 (b,c,d,e) SELECT RAND()*10000, RAND()*10000, d, e FROM t1;
+INSERT INTO t1 (b,c,d,e) SELECT RAND()*10000, RAND()*10000, d, e FROM t1;
+INSERT INTO t1 (b,c,d,e) SELECT RAND()*10000, RAND()*10000, d, e FROM t1;
+INSERT INTO t1 (b,c,d,e) SELECT RAND()*10000, RAND()*10000, d, e FROM t1;
+INSERT INTO t1 (b,c,d,e) SELECT RAND()*10000, RAND()*10000, d, e FROM t1;
+-- disable_result_log
+ANALYZE TABLE t1;
+-- enable_result_log
+EXPLAIN SELECT * FROM t1 WHERE b=1 AND c=1 ORDER BY a;
+EXPLAIN SELECT * FROM t1 FORCE INDEX(i2) WHERE b=1 and c=1 ORDER BY a;
+# With 4k pages, the 'rows' column in the output below is either 120 or 138,
+# not 128 as it is with 8k and 16k. Bug#12602606
+--replace_result 128 {checked} 120 {checked} 138 {checked}
+EXPLAIN SELECT * FROM t1 FORCE INDEX(PRIMARY) WHERE b=1 AND c=1 ORDER BY a;
+
+DROP TABLE t1;
+
+--echo #
+--echo # Bug #47963: Wrong results when index is used
+--echo #
+CREATE TABLE t1(
+ a VARCHAR(5) NOT NULL,
+ b VARCHAR(5) NOT NULL,
+ c DATETIME NOT NULL,
+ KEY (c)
+) ENGINE=InnoDB;
+INSERT INTO t1 VALUES('TEST', 'TEST', '2009-10-09 00:00:00');
+SELECT * FROM t1 WHERE a = 'TEST' AND
+ c >= '2009-10-09 00:00:00' AND c <= '2009-10-09 00:00:00';
+SELECT * FROM t1 WHERE a = 'TEST' AND
+ c >= '2009-10-09 00:00:00.0' AND c <= '2009-10-09 00:00:00.0';
+SELECT * FROM t1 WHERE a = 'TEST' AND
+ c >= '2009-10-09 00:00:00.0' AND c <= '2009-10-09 00:00:00';
+SELECT * FROM t1 WHERE a = 'TEST' AND
+ c >= '2009-10-09 00:00:00' AND c <= '2009-10-09 00:00:00.0';
+SELECT * FROM t1 WHERE a = 'TEST' AND
+ c >= '2009-10-09 00:00:00.000' AND c <= '2009-10-09 00:00:00.000';
+SELECT * FROM t1 WHERE a = 'TEST' AND
+ c >= '2009-10-09 00:00:00.00' AND c <= '2009-10-09 00:00:00.001';
+SELECT * FROM t1 WHERE a = 'TEST' AND
+ c >= '2009-10-09 00:00:00.001' AND c <= '2009-10-09 00:00:00.00';
+EXPLAIN SELECT * FROM t1 WHERE a = 'TEST' AND
+ c >= '2009-10-09 00:00:00.001' AND c <= '2009-10-09 00:00:00.00';
+DROP TABLE t1;
+
+--echo #
+--echo # Bug #46175: NULL read_view and consistent read assertion
+--echo #
+
+CREATE TABLE t1(a CHAR(13),KEY(a)) ENGINE=innodb;
+CREATE TABLE t2(b DATETIME,KEY(b)) ENGINE=innodb;
+INSERT INTO t1 VALUES (),();
+INSERT INTO t2 VALUES (),();
+CREATE OR REPLACE VIEW v1 AS SELECT 1 FROM t2
+ WHERE b =(SELECT a FROM t1 LIMIT 1);
+
+CONNECT (con1, localhost, root,,);
+CONNECTION default;
+
+DELIMITER |;
+CREATE PROCEDURE p1(num INT)
+BEGIN
+ DECLARE i INT DEFAULT 0;
+ REPEAT
+ SHOW CREATE VIEW v1;
+ SET i:=i+1;
+ UNTIL i>num END REPEAT;
+END|
+DELIMITER ;|
+
+--echo # Should not crash
+--disable_query_log
+--disable_result_log
+--send CALL p1(1000)
+CONNECTION con1;
+--echo # Should not crash
+CALL p1(1000);
+
+CONNECTION default;
+--reap
+--enable_query_log
+--enable_result_log
+
+DISCONNECT con1;
+DROP PROCEDURE p1;
+DROP VIEW v1;
+DROP TABLE t1,t2;
+
+
+--echo #
+--echo # Bug #49324: more valgrind errors in test_if_skip_sort_order
+--echo #
+CREATE TABLE t1 (a INT PRIMARY KEY) ENGINE=innodb ;
+--echo # should not cause valgrind warnings
+SELECT 1 FROM t1 JOIN t1 a USING(a) GROUP BY t1.a,t1.a;
+DROP TABLE t1;
+
+--echo #
+--echo # Bug#50843: Filesort used instead of clustered index led to
+--echo # performance degradation.
+--echo #
+create table t1(f1 int not null primary key, f2 int) engine=innodb;
+create table t2(f1 int not null, key (f1)) engine=innodb;
+insert into t1 values (1,1),(2,2),(3,3);
+insert into t2 values (1),(2),(3);
+-- disable_result_log
+analyze table t1;
+analyze table t2;
+-- enable_result_log
+explain select t1.* from t1 left join t2 using(f1) group by t1.f1;
+drop table t1,t2;
+--echo #
+
+
+--echo #
+--echo # Bug #39653: find_shortest_key in sql_select.cc does not consider
+--echo # clustered primary keys
+--echo #
+
+CREATE TABLE t1 (a INT PRIMARY KEY, b INT, c INT, d INT, e INT, f INT,
+ KEY (b,c)) ENGINE=INNODB;
+
+INSERT INTO t1 VALUES (1,1,1,1,1,1), (2,2,2,2,2,2), (3,3,3,3,3,3),
+ (4,4,4,4,4,4), (5,5,5,5,5,5), (6,6,6,6,6,6),
+ (7,7,7,7,7,7), (8,8,8,8,8,8), (9,9,9,9,9,9),
+ (11,11,11,11,11,11);
+
+ANALYZE TABLE t1;
+
+--query_vertical EXPLAIN SELECT COUNT(*) FROM t1
+
+DROP TABLE t1;
+
+--echo #
+--echo # Bug #49838: DROP INDEX and ADD UNIQUE INDEX for same index may
+--echo # corrupt definition at engine
+--echo #
+
+CREATE TABLE t1 (a INT NOT NULL, b INT NOT NULL, KEY k (a,b))
+ ENGINE=InnoDB;
+
+ALTER TABLE t1 DROP INDEX k, ADD UNIQUE INDEX k (a,b);
+
+--query_vertical SHOW INDEXES FROM t1;
+
+DROP TABLE t1;
+
+
+--echo #
+--echo # Bug #47453: InnoDB incorrectly changes TIMESTAMP columns when
+--echo # JOINed during an UPDATE
+--echo #
+
+CREATE TABLE t1 (d INT) ENGINE=InnoDB;
+CREATE TABLE t2 (a INT, b INT,
+ c TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
+ ON UPDATE CURRENT_TIMESTAMP) ENGINE=InnoDB;
+
+--echo # set up our data elements
+INSERT INTO t1 (d) VALUES (1);
+INSERT INTO t2 (a,b) VALUES (1,1);
+SELECT SECOND(c) INTO @bug47453 FROM t2;
+
+SELECT SECOND(c)-@bug47453 FROM t1 JOIN t2 ON d=a;
+UPDATE t1 JOIN t2 ON d=a SET b=1 WHERE a=1;
+SELECT SECOND(c)-@bug47453 FROM t1 JOIN t2 ON d=a;
+
+SELECT SLEEP(1);
+
+UPDATE t1 JOIN t2 ON d=a SET b=1 WHERE a=1;
+
+--echo # should be 0
+SELECT SECOND(c)-@bug47453 FROM t1 JOIN t2 ON d=a;
+
+DROP TABLE t1, t2;
+
+--echo #
+--echo # Bug #53334: wrong result for outer join with impossible ON condition
+--echo # (see the same test case for MyISAM in join.test)
+--echo #
+
+CREATE TABLE t1 (id INT PRIMARY KEY);
+CREATE TABLE t2 (id INT);
+
+INSERT INTO t1 VALUES (75);
+INSERT INTO t1 VALUES (79);
+INSERT INTO t1 VALUES (78);
+INSERT INTO t1 VALUES (77);
+REPLACE INTO t1 VALUES (76);
+REPLACE INTO t1 VALUES (76);
+INSERT INTO t1 VALUES (104);
+INSERT INTO t1 VALUES (103);
+INSERT INTO t1 VALUES (102);
+INSERT INTO t1 VALUES (101);
+INSERT INTO t1 VALUES (105);
+INSERT INTO t1 VALUES (106);
+INSERT INTO t1 VALUES (107);
+
+INSERT INTO t2 VALUES (107),(75),(1000);
+
+SELECT t1.id,t2.id FROM t2 LEFT JOIN t1 ON t1.id>=74 AND t1.id<=0
+ WHERE t2.id=75 AND t1.id IS NULL;
+EXPLAIN SELECT t1.id,t2.id FROM t2 LEFT JOIN t1 ON t1.id>=74 AND t1.id<=0
+ WHERE t2.id=75 AND t1.id IS NULL;
+
+DROP TABLE t1,t2;
+
+--echo #
+--echo # Bug#38999 valgrind warnings for update statement in function compare_record()
+--echo #
+
+CREATE TABLE t1 (a INT PRIMARY KEY) ENGINE=InnoDB;
+CREATE TABLE t2 (a INT PRIMARY KEY) ENGINE=InnoDB;
+INSERT INTO t1 values (1),(2),(3),(4),(5);
+INSERT INTO t2 values (1);
+
+SELECT * FROM t1 WHERE a = 2;
+UPDATE t1,t2 SET t1.a = t1.a + 100 WHERE t1.a = 1;
+
+DROP TABLE t1,t2;
+
+--echo #
+--echo # Bug #53830: !table || (!table->read_set || bitmap_is_set(table->read_set, field_index))
+--echo #
+
+CREATE TABLE t1 (a INT, b INT, c INT, d INT,
+ PRIMARY KEY(a,b,c), KEY(b,d))
+ ENGINE=InnoDB;
+INSERT INTO t1 VALUES (0, 77, 1, 3);
+
+UPDATE t1 SET d = 0 WHERE b = 77 AND c = 25;
+
+DROP TABLE t1;
+
+--echo #
+--echo # Bug#50389 Using intersect does not return all rows
+--echo #
+
+CREATE TABLE t1 (
+ f1 INT(10) NOT NULL,
+ f2 INT(10),
+ f3 INT(10),
+ f4 TINYINT(4),
+ f5 VARCHAR(50),
+ PRIMARY KEY (f1),
+ KEY idx1 (f2,f5,f4),
+ KEY idx2 (f2,f4)
+) ENGINE=InnoDB;
+
+LOAD DATA INFILE '../../std_data/intersect-bug50389.tsv' INTO TABLE t1;
+
+-- disable_result_log
+ANALYZE TABLE t1;
+-- enable_result_log
+
+set @tmp_innodb_mysql= @@optimizer_switch;
+set optimizer_switch='extended_keys=off';
+
+SELECT * FROM t1 WHERE f1 IN
+(3305028,3353871,3772880,3346860,4228206,3336022,
+ 3470988,3305175,3329875,3817277,3856380,3796193,
+ 3784744,4180925,4559596,3963734,3856391,4494153)
+AND f5 = 'abcdefghijklmnopwrst' AND f2 = 1221457 AND f4 = 0 ;
+
+EXPLAIN SELECT * FROM t1 WHERE f1 IN
+(3305028,3353871,3772880,3346860,4228206,3336022,
+ 3470988,3305175,3329875,3817277,3856380,3796193,
+ 3784744,4180925,4559596,3963734,3856391,4494153)
+AND f5 = 'abcdefghijklmnopwrst' AND f2 = 1221457 AND f4 = 0 ;
+set optimizer_switch=@tmp_innodb_mysql;
+
+DROP TABLE t1;
+
+--echo #
+--echo # Bug#51431 Wrong sort order after import of dump file
+--echo #
+
+CREATE TABLE t1 (
+ f1 INT(11) NOT NULL,
+ f2 int(11) NOT NULL,
+ f3 int(11) NOT NULL,
+ f4 tinyint(1) NOT NULL,
+ PRIMARY KEY (f1),
+ UNIQUE KEY (f2, f3),
+ KEY (f4)
+) ENGINE=InnoDB STATS_PERSISTENT=0;
+
+INSERT INTO t1 VALUES
+(1,1,991,1), (2,1,992,1), (3,1,993,1), (4,1,994,1), (5,1,995,1),
+(6,1,996,1), (7,1,997,1), (8,1,998,1), (10,1,999,1), (11,1,9910,1),
+(16,1,9911,1), (17,1,9912,1), (18,1,9913,1), (19,1,9914,1), (20,1,9915,1),
+(21,1,9916,1), (22,1,9917,1), (23,1,9918,1), (24,1,9919,1), (25,1,9920,1),
+(26,1,9921,1), (27,1,9922,1);
+
+FLUSH TABLES;
+
+SELECT * FROM t1 WHERE f2 = 1 AND f4 = TRUE
+ORDER BY f1 DESC LIMIT 5;
+EXPLAIN SELECT * FROM t1 WHERE f2 = 1 AND f4 = TRUE
+ORDER BY f1 DESC LIMIT 5;
+
+DROP TABLE t1;
+
+
+--echo #
+--echo # Bug#54117 crash in thr_multi_unlock, temporary table
+--echo #
+
+CREATE TEMPORARY TABLE t1(a INT) ENGINE = InnoDB;
+
+LOCK TABLES t1 READ;
+ALTER TABLE t1 COMMENT 'test';
+UNLOCK TABLES;
+
+DROP TABLE t1;
+
+--echo #
+--echo # Bug#55656: mysqldump can be slower after bug #39653 fix
+--echo #
+
+CREATE TABLE t1 (a INT , b INT, c INT, d INT,
+ KEY (b), PRIMARY KEY (a,b)) ENGINE=INNODB STATS_PERSISTENT=0;
+INSERT INTO t1 VALUES (1,1,1,1), (2,2,2,2), (3,3,3,3);
+--query_vertical EXPLAIN SELECT COUNT(*) FROM t1
+
+DROP INDEX b ON t1;
+CREATE INDEX b ON t1(a,b);
+--query_vertical EXPLAIN SELECT COUNT(*) FROM t1
+
+DROP INDEX b ON t1;
+CREATE INDEX b ON t1(a,b,c);
+--query_vertical EXPLAIN SELECT COUNT(*) FROM t1
+
+DROP INDEX b ON t1;
+CREATE INDEX b ON t1(a,b,c,d);
+--query_vertical EXPLAIN SELECT COUNT(*) FROM t1
+
+DROP TABLE t1;
+
+--echo #
+--echo # Bug#55826: create table .. select crashes with when KILL_BAD_DATA
+--echo # is returned
+--echo #
+
+CREATE TABLE t1(a INT) ENGINE=innodb;
+INSERT INTO t1 VALUES (0);
+SET SQL_MODE='STRICT_ALL_TABLES';
+--error ER_TRUNCATED_WRONG_VALUE
+CREATE TABLE t2
+ SELECT LEAST((SELECT '' FROM t1),NOW()) FROM `t1`;
+DROP TABLE t1;
+SET SQL_MODE=DEFAULT;
+
+--echo #
+--echo # Bug#56862 Execution of a query that uses index merge returns a wrong result
+--echo #
+
+CREATE TABLE t1 (
+ pk int NOT NULL AUTO_INCREMENT PRIMARY KEY,
+ a int,
+ b int,
+ INDEX idx(a))
+ENGINE=INNODB;
+
+INSERT INTO t1(a,b) VALUES
+ (11, 1100), (2, 200), (1, 100), (14, 1400), (5, 500),
+ (3, 300), (17, 1700), (4, 400), (12, 1200), (8, 800),
+ (6, 600), (18, 1800), (9, 900), (10, 1000), (7, 700),
+ (13, 1300), (15, 1500), (19, 1900), (16, 1600), (20, 2000);
+INSERT INTO t1(a,b) SELECT a+20, b+2000 FROM t1;
+INSERT INTO t1(a,b) SELECT a+40, b+4000 FROM t1;
+INSERT INTO t1(a,b) SELECT a+80, b+8000 FROM t1;
+INSERT INTO t1(a,b) SELECT a,b FROM t1;
+INSERT INTO t1(a,b) SELECT a,b FROM t1;
+INSERT INTO t1(a,b) SELECT a,b FROM t1;
+INSERT INTO t1(a,b) SELECT a,b FROM t1;
+INSERT INTO t1(a,b) SELECT a,b FROM t1;
+INSERT INTO t1(a,b) SELECT a,b FROM t1;
+INSERT INTO t1(a,b) SELECT a,b FROM t1;
+INSERT INTO t1(a,b) SELECT a,b FROM t1;
+INSERT INTO t1 VALUES (1000000, 0, 0);
+
+set @optimizer_switch_saved=@@optimizer_switch;
+SET SESSION optimizer_switch='derived_merge=off';
+SET SESSION sort_buffer_size = 1024*36;
+
+--replace_column 9 #
+EXPLAIN
+SELECT COUNT(*) FROM
+ (SELECT * FROM t1 FORCE INDEX (idx,PRIMARY)
+ WHERE a BETWEEN 2 AND 7 OR pk=1000000) AS t;
+
+SELECT COUNT(*) FROM
+ (SELECT * FROM t1 FORCE INDEX (idx,PRIMARY)
+ WHERE a BETWEEN 2 AND 7 OR pk=1000000) AS t;
+
+set @@optimizer_switch=@optimizer_switch_saved;
+SET SESSION sort_buffer_size = DEFAULT;
+
+DROP TABLE t1;
+
+--echo #
+--echo # Test for bug #39932 "create table fails if column for FK is in different
+--echo # case than in corr index".
+--echo #
+--disable_warnings
+drop tables if exists t1, t2;
+--enable_warnings
+create table t1 (pk int primary key) engine=InnoDB;
+# Even although the below statement uses uppercased field names in
+# foreign key definition it still should be able to find explicitly
+# created supporting index. So it should succeed and should not
+# create any additional supporting indexes.
+create table t2 (fk int, key x (fk),
+ constraint x foreign key (FK) references t1 (PK)) engine=InnoDB;
+show create table t2;
+drop table t2, t1;
+
+
+--echo #
+--echo # Test for bug #11762012 - "54553: INNODB ASSERTS IN HA_INNOBASE::
+--echo # UPDATE_ROW, TEMPORARY TABLE, TABLE LOCK".
+--echo #
+--disable_warnings
+DROP TABLE IF EXISTS t1;
+--enable_warnings
+CREATE TEMPORARY TABLE t1 (c int) ENGINE = InnoDB;
+INSERT INTO t1 VALUES (1);
+LOCK TABLES t1 READ;
+--echo # Even though temporary table was locked for READ we
+--echo # still allow writes to it to be compatible with MyISAM.
+--echo # This is possible since due to fact that temporary tables
+--echo # are specific to connection and therefore locking for them
+--echo # is irrelevant.
+UPDATE t1 SET c = 5;
+UNLOCK TABLES;
+DROP TEMPORARY TABLE t1;
+
+--echo # End of 5.1 tests
+
+
+--echo #
+--echo # Bug#49604 "6.0 processing compound WHERE clause incorrectly
+--echo # with Innodb - extra rows"
+--echo #
+
+CREATE TABLE t1 (
+ c1 INT NOT NULL,
+ c2 INT,
+ PRIMARY KEY (c1),
+ KEY k1 (c2)
+) ENGINE=InnoDB;
+
+INSERT INTO t1 VALUES (12,1);
+INSERT INTO t1 VALUES (15,1);
+INSERT INTO t1 VALUES (16,1);
+INSERT INTO t1 VALUES (22,1);
+INSERT INTO t1 VALUES (20,2);
+
+CREATE TABLE t2 (
+ c1 INT NOT NULL,
+ c2 INT,
+ PRIMARY KEY (c1)
+) ENGINE=InnoDB;
+
+INSERT INTO t2 VALUES (1,2);
+INSERT INTO t2 VALUES (2,9);
+
+SELECT STRAIGHT_JOIN t2.c2, t1.c2, t2.c1
+FROM t1 JOIN t2 ON t1.c2 = t2.c1
+WHERE t2.c1 IN (2, 1, 6) OR t2.c1 NOT IN (1);
+
+DROP TABLE t1, t2;
+
+
+--echo #
+--echo # Bug#44613 SELECT statement inside FUNCTION takes a shared lock
+--echo #
+
+--disable_warnings
+DROP TABLE IF EXISTS t1;
+DROP FUNCTION IF EXISTS f1;
+--enable_warnings
+
+CREATE TABLE t1(x INT PRIMARY KEY, y INT) ENGINE=innodb;
+INSERT INTO t1 VALUES (1, 0), (2, 0);
+
+CREATE FUNCTION f1(z INT) RETURNS INT READS SQL DATA
+ RETURN (SELECT x FROM t1 WHERE x = z);
+
+START TRANSACTION;
+SELECT f1(1);
+
+--disable_query_log
+connect (con2, localhost, root);
+--enable_query_log
+START TRANSACTION;
+SELECT f1(1);
+# This next statement used to block.
+UPDATE t1 SET y = 1 WHERE x = 1;
+
+COMMIT;
+
+disconnect con2;
+--source include/wait_until_disconnected.inc
+connection default;
+COMMIT;
+DROP TABLE t1;
+DROP FUNCTION f1;
+--echo #
+--echo # Bug#42744: Crash when using a join buffer to join a table with a blob
+--echo # column and an additional column used for duplicate elimination.
+--echo #
+
+CREATE TABLE t1 (a tinyblob) ENGINE=InnoDB;
+CREATE TABLE t2 (a int PRIMARY KEY, b tinyblob) ENGINE=InnoDB;
+INSERT INTO t1 VALUES ('1'), (NULL);
+INSERT INTO t2 VALUES (1, '1');
+
+EXPLAIN
+SELECT t2.b FROM t1,t2 WHERE t1.a IN (SELECT 1 FROM t2);
+
+SELECT t2.b FROM t1,t2 WHERE t1.a IN (SELECT 1 FROM t2);
+
+DROP TABLE t1,t2;
+
+--echo #
+--echo # Bug#48093: 6.0 Server not processing equivalent IN clauses properly
+--echo # with Innodb tables
+--echo #
+
+CREATE TABLE t1 (
+ i int(11) DEFAULT NULL,
+ v1 varchar(1) DEFAULT NULL,
+ v2 varchar(20) DEFAULT NULL,
+ KEY i (i),
+ KEY v (v1,i)
+) ENGINE=innodb;
+
+INSERT INTO t1 VALUES (1,'f','no');
+INSERT INTO t1 VALUES (2,'u','yes-u');
+INSERT INTO t1 VALUES (2,'h','yes-h');
+INSERT INTO t1 VALUES (3,'d','no');
+
+--echo
+SELECT v2
+FROM t1
+WHERE v1 IN ('f', 'd', 'h', 'u' ) AND i = 2;
+
+--echo
+--echo # Should not use index_merge
+EXPLAIN
+SELECT v2
+FROM t1
+WHERE v1 IN ('f', 'd', 'h', 'u' ) AND i = 2;
+
+DROP TABLE t1;
+
+--echo #
+--echo # Bug#54606 innodb fast alter table + pack_keys=0
+--echo # prevents adding new indexes
+--echo #
+
+--disable_warnings
+DROP TABLE IF EXISTS t1;
+--enable_warnings
+
+CREATE TABLE t1 (a INT, b CHAR(9), c INT, key(b))
+ ENGINE=InnoDB
+ PACK_KEYS=0;
+CREATE INDEX a ON t1 (a);
+CREATE INDEX c on t1 (c);
+
+DROP TABLE t1;
+
+
+--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 OPTIMIZE table works for temporary InnoDB tables.
+--disable_warnings
+DROP TABLE IF EXISTS t1;
+--enable_warnings
+CREATE TEMPORARY TABLE t1 (a INT) ENGINE=InnoDB;
+OPTIMIZE TABLE t1;
+DROP TABLE t1;
+
+
+--echo #
+--echo # Bug#11762345 54927: DROPPING AND ADDING AN INDEX IN ONE
+--echo # COMMAND CAN FAIL IN INNODB PLUGIN 1.0
+--echo #
+
+--disable_warnings
+DROP TABLE IF EXISTS t1;
+--enable_warnings
+
+CREATE TABLE t1 (id int, a int, b int, PRIMARY KEY (id),
+ INDEX a (a)) ENGINE=innodb;
+
+ALTER TABLE t1 DROP INDEX a, ADD INDEX a (b, a);
+# This used to fail
+ALTER TABLE t1 DROP INDEX a, ADD INDEX (a, b);
+
+DROP TABLE t1;
+
+
+--echo End of 6.0 tests
diff --git a/mysql-test/suite/innodb/t/innodb_mysql_rbk-master.opt b/mysql-test/suite/innodb/t/innodb_mysql_rbk-master.opt
new file mode 100644
index 00000000..0de61885
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb_mysql_rbk-master.opt
@@ -0,0 +1 @@
+--loose-innodb_lock_wait_timeout=1 --loose-innodb_rollback_on_timeout=1
diff --git a/mysql-test/suite/innodb/t/innodb_mysql_rbk.test b/mysql-test/suite/innodb/t/innodb_mysql_rbk.test
new file mode 100644
index 00000000..85a97697
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb_mysql_rbk.test
@@ -0,0 +1,35 @@
+--source include/have_innodb.inc
+
+#
+# Bug #41453: Assertion `m_status == DA_ERROR' failed in
+# Diagnostics_area::sql_errno
+#
+
+CREATE TABLE t1(a INT, b INT NOT NULL, PRIMARY KEY (a)) ENGINE=innodb
+DEFAULT CHARSET=latin1;
+INSERT INTO t1 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7);
+CONNECT (con1,localhost,root,,);
+CONNECT (con2,localhost,root,,);
+
+CONNECTION con1;
+START TRANSACTION;
+SELECT * FROM t1 WHERE b=3 LIMIT 1 FOR UPDATE;
+CONNECTION con2;
+START TRANSACTION;
+--error ER_LOCK_WAIT_TIMEOUT
+UPDATE t1 SET b=b+12 WHERE a > 2 ORDER BY a;
+ROLLBACK;
+
+CONNECTION con1;
+START TRANSACTION;
+SELECT * FROM t1 WHERE b=3 LIMIT 1 FOR UPDATE;
+CONNECTION con2;
+START TRANSACTION;
+--error ER_LOCK_WAIT_TIMEOUT
+UPDATE t1 SET b=10 WHERE a > 1 ORDER BY a;
+SELECT * FROM t1 WHERE b = 10;
+
+CONNECTION default;
+DISCONNECT con1;
+DISCONNECT con2;
+DROP TABLE t1;
diff --git a/mysql-test/suite/innodb/t/innodb_notembedded.test b/mysql-test/suite/innodb/t/innodb_notembedded.test
new file mode 100644
index 00000000..79f5606e
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb_notembedded.test
@@ -0,0 +1,50 @@
+--source include/have_innodb.inc
+-- source include/not_embedded.inc
+
+--disable_warnings
+drop table if exists t1;
+--enable_warnings
+
+SET @old_log_bin_trust_function_creators= @@global.log_bin_trust_function_creators;
+
+connect (a,localhost,root,,);
+connect (b,localhost,root,,);
+
+
+#
+# BUG#11238 - in prelocking mode SELECT .. FOR UPDATE is changed to
+# non-blocking SELECT
+#
+SET GLOBAL log_bin_trust_function_creators = 1;
+create table t1 (col1 integer primary key, col2 integer) engine=innodb;
+insert t1 values (1,100);
+delimiter |;
+create function f1 () returns integer begin
+declare var1 int;
+select col2 into var1 from t1 where col1=1 for update;
+return var1;
+end|
+delimiter ;|
+start transaction;
+select f1();
+connection b;
+send update t1 set col2=0 where col1=1;
+connection default;
+select * from t1;
+connection a;
+rollback;
+connection b;
+reap;
+rollback;
+
+# Cleanup
+connection a;
+disconnect a;
+--source include/wait_until_disconnected.inc
+connection b;
+disconnect b;
+--source include/wait_until_disconnected.inc
+connection default;
+drop table t1;
+drop function f1;
+SET @@global.log_bin_trust_function_creators= @old_log_bin_trust_function_creators;
diff --git a/mysql-test/suite/innodb/t/innodb_page_compressed.combinations b/mysql-test/suite/innodb/t/innodb_page_compressed.combinations
new file mode 100644
index 00000000..498c85ee
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb_page_compressed.combinations
@@ -0,0 +1,11 @@
+[bzip2]
+plugin-load-add=$PROVIDER_BZIP2_SO
+[lz4]
+plugin-load-add=$PROVIDER_LZ4_SO
+[lzma]
+plugin-load-add=$PROVIDER_LZMA_SO
+[lzo]
+plugin-load-add=$PROVIDER_LZO_SO
+[snappy]
+plugin-load-add=$PROVIDER_SNAPPY_SO
+[zlib]
diff --git a/mysql-test/suite/innodb/t/innodb_page_compressed.test b/mysql-test/suite/innodb/t/innodb_page_compressed.test
new file mode 100644
index 00000000..74cd33e2
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb_page_compressed.test
@@ -0,0 +1,86 @@
+-- source include/have_innodb.inc
+
+SET @save_algorithm = @@GLOBAL.innodb_compression_algorithm;
+let $alg=`select regexp_replace('$MTR_COMBINATIONS', 'innodb,\|,innodb', '')`;
+
+if (!`select '$alg' = 'zlib'`)
+{
+ if (!`SELECT COUNT(*) FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE LOWER(variable_name) = 'innodb_have_$alg' AND variable_value = 'ON'`)
+ {
+ --skip Test requires InnoDB compiled with $alg
+ }
+ --disable_query_log
+ eval SET GLOBAL innodb_compression_algorithm=$alg;
+ --enable_query_log
+}
+
+create table innodb_normal (c1 int not null auto_increment primary key, b char(200)) engine=innodb;
+create table innodb_page_compressed1 (c1 int not null auto_increment primary key, b char(200)) engine=innodb page_compressed=1 page_compression_level=1;
+create table innodb_page_compressed2 (c1 int not null auto_increment primary key, b char(200)) engine=innodb page_compressed=1 page_compression_level=2;
+create table innodb_page_compressed3 (c1 int not null auto_increment primary key, b char(200)) engine=innodb page_compressed=1 page_compression_level=3;
+create table innodb_page_compressed4 (c1 int not null auto_increment primary key, b char(200)) engine=innodb page_compressed=1 page_compression_level=4;
+create table innodb_page_compressed5 (c1 int not null auto_increment primary key, b char(200)) engine=innodb page_compressed=1 page_compression_level=5;
+create table innodb_page_compressed6 (c1 int not null auto_increment primary key, b char(200)) engine=innodb page_compressed=1 page_compression_level=6;
+create table innodb_page_compressed7 (c1 int not null auto_increment primary key, b char(200)) engine=innodb page_compressed=1 page_compression_level=7;
+create table innodb_page_compressed8 (c1 int not null auto_increment primary key, b char(200)) engine=innodb page_compressed=1 page_compression_level=8;
+create table innodb_page_compressed9 (c1 int not null auto_increment primary key, b char(200)) engine=innodb page_compressed=1 page_compression_level=9;
+
+connect (prevent_purge,localhost,root);
+START TRANSACTION WITH CONSISTENT SNAPSHOT;
+connection default;
+
+begin;
+insert into innodb_normal SET b=REPEAT('Aa',50);
+insert into innodb_page_compressed1 SET b=REPEAT('Aa',50);
+insert into innodb_page_compressed2 SET b=REPEAT('Aa',50);
+insert into innodb_page_compressed3 SET b=REPEAT('Aa',50);
+insert into innodb_page_compressed4 SET b=REPEAT('Aa',50);
+insert into innodb_page_compressed5 SET b=REPEAT('Aa',50);
+insert into innodb_page_compressed6 SET b=REPEAT('Aa',50);
+insert into innodb_page_compressed7 SET b=REPEAT('Aa',50);
+insert into innodb_page_compressed8 SET b=REPEAT('Aa',50);
+insert into innodb_page_compressed9 SET b=REPEAT('Aa',50);
+commit;
+
+FLUSH TABLES innodb_normal,
+innodb_page_compressed1, innodb_page_compressed2, innodb_page_compressed3,
+innodb_page_compressed4, innodb_page_compressed5, innodb_page_compressed6,
+innodb_page_compressed7, innodb_page_compressed8, innodb_page_compressed9
+FOR EXPORT;
+
+--let $MYSQLD_DATADIR=`select @@datadir`
+--let SEARCH_PATTERN=AaAaAaAa
+--let SEARCH_FILE=$MYSQLD_DATADIR/test/innodb_normal.ibd
+--source include/search_pattern_in_file.inc
+--let SEARCH_FILE=$MYSQLD_DATADIR/test/innodb_page_compressed1.ibd
+--source include/search_pattern_in_file.inc
+--let SEARCH_FILE=$MYSQLD_DATADIR/test/innodb_page_compressed2.ibd
+--source include/search_pattern_in_file.inc
+--let SEARCH_FILE=$MYSQLD_DATADIR/test/innodb_page_compressed3.ibd
+--source include/search_pattern_in_file.inc
+--let SEARCH_FILE=$MYSQLD_DATADIR/test/innodb_page_compressed4.ibd
+--source include/search_pattern_in_file.inc
+--let SEARCH_FILE=$MYSQLD_DATADIR/test/innodb_page_compressed5.ibd
+--source include/search_pattern_in_file.inc
+--let SEARCH_FILE=$MYSQLD_DATADIR/test/innodb_page_compressed6.ibd
+--source include/search_pattern_in_file.inc
+--let SEARCH_FILE=$MYSQLD_DATADIR/test/innodb_page_compressed7.ibd
+--source include/search_pattern_in_file.inc
+--let SEARCH_FILE=$MYSQLD_DATADIR/test/innodb_page_compressed8.ibd
+--source include/search_pattern_in_file.inc
+--let SEARCH_FILE=$MYSQLD_DATADIR/test/innodb_page_compressed9.ibd
+--source include/search_pattern_in_file.inc
+
+UNLOCK TABLES;
+
+drop table innodb_normal;
+drop table innodb_page_compressed1;
+drop table innodb_page_compressed2;
+drop table innodb_page_compressed3;
+drop table innodb_page_compressed4;
+drop table innodb_page_compressed5;
+drop table innodb_page_compressed6;
+drop table innodb_page_compressed7;
+drop table innodb_page_compressed8;
+drop table innodb_page_compressed9;
+SET GLOBAL innodb_compression_algorithm=@save_algorithm;
diff --git a/mysql-test/suite/innodb/t/innodb_prefix_index_restart_server.test b/mysql-test/suite/innodb/t/innodb_prefix_index_restart_server.test
new file mode 100644
index 00000000..1fb7c6d0
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb_prefix_index_restart_server.test
@@ -0,0 +1,95 @@
+--source include/have_innodb.inc
+######## suite/innodb/t/innodb_prefix_iindex_restart_server.test #####
+# #
+# Testcase for worklog WL#5743: Lift the limit of index key prefixes #
+# Test scenario : Stop the server in between when prefix index are #
+# created and see if state is preserved after restart #
+# #
+# Creation: #
+# 2011-06-02 Implemented this test as part of WL#5743 #
+# #
+######################################################################
+
+# Embedded server tests do not support restarting
+--source include/not_embedded.inc
+
+#------------------------------------------------------------------------------
+# Stop the server in between when prefix index are created and see if state is
+# correct when server is restarted.
+# Server is restarted at differnt points.
+
+CREATE TABLE worklog5743 (
+col_1_text TEXT(4000) , col_2_text TEXT(4000) ,
+PRIMARY KEY (col_1_text(3072))
+) ROW_FORMAT=DYNAMIC, engine = innodb;
+INSERT INTO worklog5743 VALUES(REPEAT("a", 3500) , REPEAT("o", 3500));
+SELECT col_1_text = REPEAT("a", 3500) , col_2_text = REPEAT("o", 3500) FROM
+worklog5743;
+
+--connect (con1,localhost,root,,)
+SELECT col_1_text = REPEAT("a", 3500) , col_2_text = REPEAT("o", 3500) FROM
+worklog5743;
+SELECT COUNT(*) FROM worklog5743;
+
+
+--connect (con2,localhost,root,,)
+START TRANSACTION;
+INSERT INTO worklog5743 VALUES(REPEAT("b", 3500) , REPEAT("o", 3500));
+
+
+--connection con1
+SELECT col_1_text = REPEAT("a", 3500) , col_2_text = REPEAT("o", 3500) FROM
+worklog5743;
+SELECT COUNT(*) FROM worklog5743;
+START TRANSACTION;
+
+
+--connection default
+# Restart the server
+SET GLOBAL innodb_fast_shutdown=3;
+-- source include/restart_mysqld.inc
+SELECT COUNT(*) FROM worklog5743;
+SELECT col_1_text = REPEAT("a", 3500) , col_2_text = REPEAT("o", 3500) FROM
+worklog5743;
+
+--disconnect con1
+--disconnect con2
+
+--connect (con1,localhost,root,,)
+SELECT col_1_text = REPEAT("a", 3500) , col_2_text = REPEAT("o", 3500) FROM
+worklog5743;
+SELECT COUNT(*) FROM worklog5743;
+START TRANSACTION;
+INSERT INTO worklog5743 VALUES(REPEAT("b", 3500) , REPEAT("o", 3500));
+DELETE FROM worklog5743 WHERE col_1_text = REPEAT("b", 3500);
+SELECT col_1_text = REPEAT("a", 3500) , col_2_text = REPEAT("o", 3500) FROM
+worklog5743;
+
+--connection default
+# Restart the server
+SET GLOBAL innodb_fast_shutdown=3;
+-- source include/restart_mysqld.inc
+SELECT COUNT(*) FROM worklog5743;
+SELECT col_1_text = REPEAT("a", 3500) , col_2_text = REPEAT("o", 3500) FROM
+worklog5743;
+
+--disconnect con1
+
+--connect (con2,localhost,root,,)
+SELECT col_1_text = REPEAT("a", 3500) , col_2_text = REPEAT("o", 3500) FROM
+worklog5743;
+SELECT COUNT(*) FROM worklog5743;
+START TRANSACTION;
+UPDATE worklog5743 SET col_1_text = REPEAT("b", 3500) WHERE col_1_text = REPEAT("a", 3500);
+SELECT col_1_text = REPEAT("b", 3500) , col_2_text = REPEAT("o", 3500) FROM
+worklog5743;
+
+--connection default
+# Restart the server
+SET GLOBAL innodb_fast_shutdown=3;
+-- source include/restart_mysqld.inc
+SELECT COUNT(*) FROM worklog5743;
+SELECT col_1_text = REPEAT("a", 3500) , col_2_text = REPEAT("o", 3500) FROM
+worklog5743;
+
+DROP TABLE worklog5743;
diff --git a/mysql-test/suite/innodb/t/innodb_query_cache.test b/mysql-test/suite/innodb/t/innodb_query_cache.test
new file mode 100644
index 00000000..7dbdf986
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb_query_cache.test
@@ -0,0 +1,47 @@
+-- source include/have_innodb.inc
+-- source include/have_query_cache.inc
+-- source include/not_embedded.inc
+
+--echo #
+--echo # MDEV-16087 Inconsistent SELECT results when query cache is enabled
+--echo #
+
+set GLOBAL query_cache_type=ON;
+set LOCAL query_cache_type=ON;
+
+create table t1 (id bigint(20) auto_increment, primary key (id)) ENGINE=InnoDB;
+create table t2 (id bigint(20) auto_increment, primary key (id)) ENGINE=InnoDB;
+create table t3 (id bigint(20) auto_increment, primary key (id)) ENGINE=InnoDB;
+
+connect (con1,localhost,root);
+START TRANSACTION WITH CONSISTENT SNAPSHOT;
+select * from t2;
+
+connection default;
+insert into t3 () values ();
+
+connection con1;
+insert into t1 () values ();
+select * from t3;
+
+connect (con2,localhost,root);
+START TRANSACTION WITH CONSISTENT SNAPSHOT;
+select * from t3;
+select * from t3;
+select sql_no_cache * from t3;
+
+rollback;
+
+connection con1;
+
+rollback;
+
+disconnect con1;
+disconnect con2;
+connection default;
+
+drop table t1;
+drop table t2;
+drop table t3;
+
+set GLOBAL query_cache_type=default;
diff --git a/mysql-test/suite/innodb/t/innodb_rename_index.test b/mysql-test/suite/innodb/t/innodb_rename_index.test
new file mode 100644
index 00000000..5ae09fb1
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb_rename_index.test
@@ -0,0 +1,538 @@
+--source include/have_innodb.inc
+
+#
+# Test "ALTER TABLE ... RENAME INDEX" in InnoDB
+#
+
+let create =
+CREATE TABLE t (
+ a INT,
+ b INT,
+ c INT,
+ d INT,
+ e INT,
+ f INT,
+ PRIMARY KEY (a),
+ INDEX i1 (b),
+ INDEX i2 (c),
+ INDEX i3 (d),
+ INDEX i4 (e)
+) ENGINE=INNODB;
+
+let insert = INSERT INTO t SET a = 1;
+
+let show_table =
+SHOW CREATE TABLE t;
+
+let show_sys =
+SELECT
+t.name AS table_name,
+i.name AS index_name,
+f.name AS column_name
+FROM
+information_schema.innodb_sys_tables t,
+information_schema.innodb_sys_indexes i,
+information_schema.innodb_sys_fields f
+WHERE
+t.name LIKE '%/t' AND
+t.table_id = i.table_id AND
+i.index_id = f.index_id
+ORDER BY 1, 2, 3;
+
+-- eval $create
+
+# Add a row, so that affected rows would be nonzero for ALGORITHM=COPY.
+# ALGORITHM=INPLACE will report 0 affected row in the result file.
+# We will have enable_info/disable_info around every successful ALTER
+# to enable the affected rows: output in the result file.
+-- eval $insert
+
+-- error ER_WRONG_NAME_FOR_INDEX
+ALTER TABLE t RENAME INDEX i1 TO GEN_CLUST_INDEX;
+
+# Test all combinations of ADD w, DROP x, RENAME y TO z.
+#
+# Use the following names for wxyz (with 1 to 4 of wxyz being the same):
+# aaaa abcd aabb abab abba abcc acbc accb cacb cabc ccab aaab aaba abaa baaa
+#
+# Some cases should trivially succeed or fail. Test them in isolation:
+# no-op: y=z (RENAME y TO y)
+# rules out the combinations ..\(.\)\1
+# a.k.a. aaaa aabb abcc abaa baaa
+
+# We use the index names i1 to i4 for existing indexes abcd.
+# Non-existing index names will be aa,bb,cc,dd.
+# Index creation on non-existing columns will not be tested.
+
+ALTER TABLE t RENAME INDEX i1 TO i1;
+-- error ER_KEY_DOES_NOT_EXISTS
+ALTER TABLE t RENAME INDEX aa TO aa;
+
+-- echo # combination: aaaa
+# drop/add existing, null rename and drop the same
+-- error ER_KEY_DOES_NOT_EXISTS
+ALTER TABLE t ADD INDEX i4(f), DROP INDEX i4, RENAME INDEX i4 TO i4;
+
+-- echo # combination: aabb
+-- error ER_CANT_DROP_FIELD_OR_KEY
+ALTER TABLE t ADD INDEX aa(f), DROP INDEX aa, RENAME INDEX i2 TO i2;
+-- error ER_CANT_DROP_FIELD_OR_KEY
+ALTER TABLE t ADD INDEX aa(f), DROP INDEX aa, RENAME INDEX bb TO bb;
+-- error ER_KEY_DOES_NOT_EXISTS
+ALTER TABLE t ADD INDEX i1(f), DROP INDEX i1, RENAME INDEX bb TO bb;
+
+-- enable_info
+ALTER TABLE t ADD INDEX i1(f), DROP INDEX i1, RENAME INDEX i2 TO i2;
+-- disable_info
+-- eval $show_table
+-- eval $show_sys
+DROP TABLE t;
+-- eval $create
+-- eval $insert
+
+-- echo # combination: abcc
+
+-- error ER_CANT_DROP_FIELD_OR_KEY
+ALTER TABLE t ADD INDEX aa(f), DROP INDEX bb, RENAME INDEX cc TO cc;
+-- error ER_CANT_DROP_FIELD_OR_KEY
+ALTER TABLE t ADD INDEX aa(f), DROP INDEX bb, RENAME INDEX i3 TO i3;
+-- error ER_KEY_DOES_NOT_EXISTS
+ALTER TABLE t ADD INDEX aa(f), DROP INDEX i2, RENAME INDEX cc TO cc;
+
+# rename existing (succeeds)
+-- enable_info
+ALTER TABLE t ADD INDEX aa(f), DROP INDEX i2, RENAME INDEX i3 TO i3;
+-- disable_info
+-- eval $show_table
+-- eval $show_sys
+DROP TABLE t;
+-- eval $create
+-- eval $insert
+
+-- echo # combination: abaa
+
+-- error ER_KEY_DOES_NOT_EXISTS
+ALTER TABLE t ADD INDEX aa(f), DROP INDEX i1, RENAME INDEX aa TO aa;
+-- error ER_DUP_KEYNAME
+ALTER TABLE t ADD INDEX i1(f), DROP INDEX i2, RENAME INDEX i1 TO i1;
+-- error ER_CANT_DROP_FIELD_OR_KEY
+ALTER TABLE t ADD INDEX i1(f), DROP INDEX bb, RENAME INDEX i1 TO i1;
+-- error ER_CANT_DROP_FIELD_OR_KEY
+ALTER TABLE t ADD INDEX aa(f), DROP INDEX bb, RENAME INDEX aa TO aa;
+
+-- echo # combination: baaa
+
+-- error ER_KEY_DOES_NOT_EXISTS
+ALTER TABLE t ADD INDEX i2(f), DROP INDEX i1, RENAME INDEX i1 TO i1;
+-- error ER_KEY_DOES_NOT_EXISTS
+ALTER TABLE t ADD INDEX bb(f), DROP INDEX i1, RENAME INDEX i1 TO i1;
+-- error ER_CANT_DROP_FIELD_OR_KEY
+ALTER TABLE t ADD INDEX i2(f), DROP INDEX aa, RENAME INDEX aa TO aa;
+-- error ER_CANT_DROP_FIELD_OR_KEY
+ALTER TABLE t ADD INDEX bb(f), DROP INDEX aa, RENAME INDEX aa TO aa;
+
+# refuse: w=z (ADD w, RENAME y TO w)
+# rules out the combinations \(.\)..\1
+# a.k.a. aaaa abba cabc aaba abaa
+# the case w=y (ADD w, RENAME w to z) may succeed, as seen below
+
+-- error ER_KEY_DOES_NOT_EXISTS
+ALTER TABLE t ADD INDEX aa(f), RENAME INDEX aa TO bb;
+-- error ER_KEY_DOES_NOT_EXISTS
+ALTER TABLE t ADD INDEX aa(f), RENAME INDEX bb TO aa;
+-- error ER_DUP_KEYNAME
+ALTER TABLE t ADD INDEX aa(f), RENAME INDEX i2 TO aa;
+
+# rename existing, add one with the same name
+-- enable_info
+ALTER TABLE t ADD INDEX i1(f), RENAME INDEX i1 TO bb;
+-- disable_info
+-- eval $show_table
+-- eval $show_sys
+DROP TABLE t;
+-- eval $create
+-- eval $insert
+
+-- echo # combination: abba
+
+-- error ER_KEY_DOES_NOT_EXISTS
+ALTER TABLE t ADD INDEX i1(f), DROP INDEX i2, RENAME INDEX i2 TO i1;
+-- error ER_KEY_DOES_NOT_EXISTS
+ALTER TABLE t ADD INDEX aa(f), DROP INDEX i2, RENAME INDEX i2 TO aa;
+-- error ER_CANT_DROP_FIELD_OR_KEY
+ALTER TABLE t ADD INDEX i1(f), DROP INDEX bb, RENAME INDEX bb TO i1;
+-- error ER_CANT_DROP_FIELD_OR_KEY
+ALTER TABLE t ADD INDEX aa(f), DROP INDEX bb, RENAME INDEX bb TO aa;
+
+-- echo # combination: cabc
+
+-- error ER_DUP_KEYNAME
+ALTER TABLE t ADD INDEX i3(f), DROP INDEX i1, RENAME INDEX i2 TO i3;
+-- error ER_CANT_DROP_FIELD_OR_KEY
+ALTER TABLE t ADD INDEX i3(f), DROP INDEX aa, RENAME INDEX i2 TO i3;
+-- error ER_KEY_DOES_NOT_EXISTS
+ALTER TABLE t ADD INDEX i3(f), DROP INDEX i1, RENAME INDEX bb TO i3;
+-- error ER_CANT_DROP_FIELD_OR_KEY
+ALTER TABLE t ADD INDEX i3(f), DROP INDEX aa, RENAME INDEX bb TO i3;
+
+-- error ER_DUP_KEYNAME
+ALTER TABLE t ADD INDEX cc(f), DROP INDEX i1, RENAME INDEX i2 TO cc;
+-- error ER_CANT_DROP_FIELD_OR_KEY
+ALTER TABLE t ADD INDEX cc(f), DROP INDEX aa, RENAME INDEX i2 TO cc;
+-- error ER_KEY_DOES_NOT_EXISTS
+ALTER TABLE t ADD INDEX cc(f), DROP INDEX i1, RENAME INDEX bb TO cc;
+-- error ER_CANT_DROP_FIELD_OR_KEY
+ALTER TABLE t ADD INDEX cc(f), DROP INDEX aa, RENAME INDEX bb TO cc;
+
+# refuse: x=y (DROP x, RENAME x TO z)
+# rules out the combinations .\(.\)\1.
+# a.k.a. aaaa abba accb aaab baaa
+
+# rename and drop the same
+-- error ER_KEY_DOES_NOT_EXISTS
+ALTER TABLE t DROP INDEX i1, RENAME INDEX i1 TO bb;
+# drop non-existing
+-- error ER_CANT_DROP_FIELD_OR_KEY
+ALTER TABLE t DROP INDEX aa, RENAME INDEX i2 TO aa;
+-- error ER_CANT_DROP_FIELD_OR_KEY
+ALTER TABLE t DROP INDEX aa, RENAME INDEX aa TO i2;
+
+# this one will succeed (drop, replace with an existing one)
+-- enable_info
+ALTER TABLE t DROP INDEX i1, RENAME INDEX i4 TO i1;
+-- disable_info
+-- eval $show_table
+-- eval $show_sys
+DROP TABLE t;
+-- eval $create
+-- eval $insert
+
+-- echo # combination: accb
+
+-- error ER_KEY_DOES_NOT_EXISTS
+ALTER TABLE t ADD INDEX i1(f), DROP INDEX i3, RENAME INDEX i3 TO i2;
+-- error ER_KEY_DOES_NOT_EXISTS
+ALTER TABLE t ADD INDEX i1(f), DROP INDEX i3, RENAME INDEX i3 TO bb;
+-- error ER_CANT_DROP_FIELD_OR_KEY
+ALTER TABLE t ADD INDEX i1(f), DROP INDEX cc, RENAME INDEX cc TO i2;
+-- error ER_CANT_DROP_FIELD_OR_KEY
+ALTER TABLE t ADD INDEX i1(f), DROP INDEX cc, RENAME INDEX cc TO bb;
+-- error ER_CANT_DROP_FIELD_OR_KEY
+ALTER TABLE t ADD INDEX aa(f), DROP INDEX cc, RENAME INDEX cc TO i2;
+-- error ER_CANT_DROP_FIELD_OR_KEY
+ALTER TABLE t ADD INDEX aa(f), DROP INDEX cc, RENAME INDEX cc TO bb;
+
+-- echo # combination: aaab
+
+-- error ER_KEY_DOES_NOT_EXISTS
+ALTER TABLE t ADD INDEX i1(f), DROP INDEX i1, RENAME INDEX i1 TO i2;
+-- error ER_KEY_DOES_NOT_EXISTS
+ALTER TABLE t ADD INDEX i1(f), DROP INDEX i1, RENAME INDEX i1 TO bb;
+-- error ER_KEY_DOES_NOT_EXISTS
+ALTER TABLE t ADD INDEX i1(f), DROP INDEX i1, RENAME INDEX i1 TO i2;
+-- error ER_CANT_DROP_FIELD_OR_KEY
+ALTER TABLE t ADD INDEX aa(f), DROP INDEX aa, RENAME INDEX aa TO bb;
+
+# Remaining combinations: abcd abab acbc cacb ccab
+
+-- echo # combination: abcd
+
+-- error ER_KEY_DOES_NOT_EXISTS
+ALTER TABLE t ADD INDEX i1(f), DROP INDEX i2, RENAME INDEX cc TO i4;
+-- error ER_KEY_DOES_NOT_EXISTS
+ALTER TABLE t ADD INDEX i1(f), DROP INDEX i2, RENAME INDEX cc TO dd;
+-- error ER_KEY_DOES_NOT_EXISTS
+ALTER TABLE t ADD INDEX aa(f), DROP INDEX i2, RENAME INDEX cc TO i4;
+-- error ER_KEY_DOES_NOT_EXISTS
+ALTER TABLE t ADD INDEX aa(f), DROP INDEX i2, RENAME INDEX cc TO dd;
+
+# add existing, rename to existing
+-- error ER_DUP_KEYNAME
+ALTER TABLE t ADD INDEX i1(f), DROP INDEX i2, RENAME INDEX i3 TO i4;
+# add existing
+-- error ER_DUP_KEYNAME
+ALTER TABLE t ADD INDEX i1(f), DROP INDEX i2, RENAME INDEX i3 TO dd;
+# rename to existing
+-- error ER_DUP_KEYNAME
+ALTER TABLE t ADD INDEX aa(f), DROP INDEX i2, RENAME INDEX i3 TO i4;
+
+-- enable_info
+ALTER TABLE t ADD INDEX aa(f), DROP INDEX i2, RENAME INDEX i3 TO dd;
+-- disable_info
+-- eval $show_table
+-- eval $show_sys
+DROP TABLE t;
+-- eval $create
+-- eval $insert
+
+-- echo # combination: abab
+
+-- enable_info
+ALTER TABLE t ADD INDEX i1(f), DROP INDEX i2, RENAME INDEX i1 TO i2;
+-- disable_info
+-- eval $show_table
+-- eval $show_sys
+DROP TABLE t;
+-- eval $create
+-- eval $insert
+
+-- error ER_CANT_DROP_FIELD_OR_KEY
+ALTER TABLE t ADD INDEX i1(f), DROP INDEX bb, RENAME INDEX i1 TO bb;
+-- error ER_KEY_DOES_NOT_EXISTS
+ALTER TABLE t ADD INDEX aa(f), DROP INDEX i2, RENAME INDEX aa TO i2;
+-- error ER_CANT_DROP_FIELD_OR_KEY
+ALTER TABLE t ADD INDEX aa(f), DROP INDEX bb, RENAME INDEX aa TO bb;
+
+-- echo # combination: acbc
+
+-- error ER_CANT_DROP_FIELD_OR_KEY
+ALTER TABLE t ADD INDEX i1(f), DROP INDEX cc, RENAME INDEX i2 TO cc;
+-- error ER_CANT_DROP_FIELD_OR_KEY
+ALTER TABLE t ADD INDEX aa(f), DROP INDEX cc, RENAME INDEX i2 TO cc;
+-- error ER_CANT_DROP_FIELD_OR_KEY
+ALTER TABLE t ADD INDEX i1(f), DROP INDEX cc, RENAME INDEX bb TO cc;
+-- error ER_CANT_DROP_FIELD_OR_KEY
+ALTER TABLE t ADD INDEX aa(f), DROP INDEX cc, RENAME INDEX bb TO cc;
+-- error ER_KEY_DOES_NOT_EXISTS
+ALTER TABLE t ADD INDEX i1(f), DROP INDEX i3, RENAME INDEX bb TO i3;
+-- error ER_KEY_DOES_NOT_EXISTS
+ALTER TABLE t ADD INDEX aa(f), DROP INDEX i3, RENAME INDEX bb TO i3;
+
+# add existing
+-- error ER_DUP_KEYNAME
+ALTER TABLE t ADD INDEX i1(f), DROP INDEX i3, RENAME INDEX i2 TO i3;
+
+-- enable_info
+ALTER TABLE t ADD INDEX aa(f), DROP INDEX i3, RENAME INDEX i2 TO i3;
+-- disable_info
+-- eval $show_table
+-- eval $show_sys
+DROP TABLE t;
+-- eval $create
+-- eval $insert
+
+-- echo # combination: cacb
+
+-- error ER_KEY_DOES_NOT_EXISTS
+ALTER TABLE t ADD INDEX cc(f), DROP INDEX i1, RENAME INDEX cc TO i2;
+-- error ER_CANT_DROP_FIELD_OR_KEY
+ALTER TABLE t ADD INDEX cc(f), DROP INDEX aa, RENAME INDEX cc TO i2;
+-- error ER_CANT_DROP_FIELD_OR_KEY
+ALTER TABLE t ADD INDEX cc(f), DROP INDEX aa, RENAME INDEX cc TO bb;
+-- error ER_KEY_DOES_NOT_EXISTS
+ALTER TABLE t ADD INDEX cc(f), DROP INDEX i1, RENAME INDEX cc TO bb;
+
+-- error ER_DUP_KEYNAME
+ALTER TABLE t ADD INDEX i3(f), DROP INDEX i1, RENAME INDEX i3 TO i2;
+-- error ER_CANT_DROP_FIELD_OR_KEY
+ALTER TABLE t ADD INDEX i3(f), DROP INDEX aa, RENAME INDEX i3 TO i2;
+-- error ER_CANT_DROP_FIELD_OR_KEY
+ALTER TABLE t ADD INDEX i3(f), DROP INDEX aa, RENAME INDEX i3 TO bb;
+
+-- enable_info
+ALTER TABLE t ADD INDEX i3(f), DROP INDEX i1, RENAME INDEX i3 TO bb;
+-- disable_info
+-- eval $show_table
+-- eval $show_sys
+DROP TABLE t;
+-- eval $create
+-- eval $insert
+
+-- echo # combination: ccab
+
+-- error ER_CANT_DROP_FIELD_OR_KEY
+ALTER TABLE t ADD INDEX cc(f), DROP INDEX cc, RENAME INDEX i1 TO i2;
+-- error ER_CANT_DROP_FIELD_OR_KEY
+ALTER TABLE t ADD INDEX cc(f), DROP INDEX cc, RENAME INDEX i1 TO bb;
+-- error ER_CANT_DROP_FIELD_OR_KEY
+ALTER TABLE t ADD INDEX cc(f), DROP INDEX cc, RENAME INDEX aa TO i2;
+-- error ER_CANT_DROP_FIELD_OR_KEY
+ALTER TABLE t ADD INDEX cc(f), DROP INDEX cc, RENAME INDEX aa TO bb;
+-- error ER_CANT_DROP_FIELD_OR_KEY
+ALTER TABLE t ADD INDEX i3(f), DROP INDEX cc, RENAME INDEX aa TO i2;
+-- error ER_CANT_DROP_FIELD_OR_KEY
+ALTER TABLE t ADD INDEX i3(f), DROP INDEX cc, RENAME INDEX aa TO bb;
+
+-- error ER_DUP_KEYNAME
+ALTER TABLE t ADD INDEX i3(f), DROP INDEX i3, RENAME INDEX i1 TO i2;
+
+-- enable_info
+ALTER TABLE t ADD INDEX i3(f), DROP INDEX i3, RENAME INDEX i1 TO bb;
+-- disable_info
+-- eval $show_table
+-- eval $show_sys
+DROP TABLE t;
+-- eval $create
+-- eval $insert
+
+# A simple successful ALTER
+-- enable_info
+ALTER TABLE t RENAME INDEX i1 TO x;
+-- disable_info
+-- eval $show_table
+-- eval $show_sys
+DROP TABLE t;
+-- eval $create
+-- eval $insert
+
+-- error ER_DUP_KEYNAME
+ALTER TABLE t RENAME INDEX i1 TO i2;
+
+-- error ER_KEY_DOES_NOT_EXISTS
+ALTER TABLE t RENAME INDEX foo TO i1;
+
+# Test ADD INDEX, RENAME INDEX
+
+-- enable_info
+ALTER TABLE t ADD INDEX i9 (f), RENAME INDEX i1 TO i8;
+-- disable_info
+-- eval $show_table
+-- eval $show_sys
+DROP TABLE t;
+-- eval $create
+-- eval $insert
+
+-- enable_info
+ALTER TABLE t ADD INDEX i1 (f), RENAME INDEX i1 TO i9;
+-- disable_info
+-- eval $show_table
+-- eval $show_sys
+DROP TABLE t;
+-- eval $create
+-- eval $insert
+
+-- error ER_DUP_KEYNAME
+ALTER TABLE t ADD INDEX foo (f), RENAME INDEX i1 TO foo;
+
+# Test ADD INDEX, RENAME INDEX, DROP INDEX
+
+-- error ER_KEY_DOES_NOT_EXISTS
+ALTER TABLE t ADD INDEX i1 (f), RENAME INDEX i1 TO foo, DROP INDEX i1;
+
+-- error ER_CANT_DROP_FIELD_OR_KEY
+ALTER TABLE t ADD INDEX i1 (f), RENAME INDEX i1 TO foo, DROP INDEX foo;
+
+-- error ER_CANT_DROP_FIELD_OR_KEY
+# "ALTER TABLE t ADD INDEX foo (d), DROP INDEX foo;" alone fails with the
+# same error code, but we have that test here anyway
+ALTER TABLE t ADD INDEX foo (f), RENAME INDEX foo TO bar, DROP INDEX foo;
+
+# Test RENAME INDEX, RENAME INDEX
+
+-- error ER_DUP_KEYNAME
+ALTER TABLE t RENAME INDEX i1 TO x, RENAME INDEX i2 TO x;
+
+-- error ER_KEY_DOES_NOT_EXISTS
+ALTER TABLE t RENAME INDEX i1 TO x, RENAME INDEX i1 TO y;
+
+-- error ER_KEY_DOES_NOT_EXISTS
+ALTER TABLE t RENAME INDEX i1 TO x, RENAME INDEX i1 TO x;
+
+# show that the table did not change after all the erroneous ALTERs
+-- eval $show_table
+-- eval $show_sys
+
+DROP TABLE t;
+
+# now test the rebuild case (new clustered index)
+
+CREATE TABLE t (
+ c1 INT NOT NULL,
+ c2 INT NOT NULL,
+ c3 INT,
+ c4 INT,
+ PRIMARY KEY (c1),
+ INDEX i1 (c3),
+ INDEX i2 (c4)
+) ENGINE=INNODB;
+
+INSERT INTO t SET c1=1, c2=2;
+
+-- enable_info
+ALTER TABLE t DROP PRIMARY KEY, ADD PRIMARY KEY (c2), RENAME INDEX i1 TO x;
+-- disable_info
+
+-- eval $show_table
+-- eval $show_sys
+
+-- enable_info
+ALTER TABLE t RENAME INDEX i2 TO y, ROW_FORMAT=REDUNDANT;
+-- disable_info
+
+-- eval $show_table
+-- eval $show_sys
+
+DROP TABLE t;
+
+# a case where the PK does not exist prior to the ALTER TABLE command
+
+CREATE TABLE t (
+ c1 INT NOT NULL,
+ c2 INT,
+ c3 INT,
+ INDEX i1 (c2),
+ INDEX i2 (c3)
+) ENGINE=INNODB;
+
+INSERT INTO t SET c1=1;
+
+-- enable_info
+ALTER TABLE t ADD PRIMARY KEY (c1), RENAME INDEX i1 TO x;
+-- disable_info
+-- eval $show_table
+-- eval $show_sys
+
+DROP TABLE t;
+
+# Test repeated RENAMEs with alternating names
+
+CREATE TABLE t (a INT, INDEX iiiii (a)) ENGINE=INNODB;
+INSERT INTO t SET a=NULL;
+-- enable_info
+ALTER TABLE t RENAME INDEX iiiii TO i;
+ALTER TABLE t RENAME INDEX i TO iiiii;
+ALTER TABLE t RENAME INDEX iiiii TO i;
+ALTER TABLE t RENAME INDEX i TO iiiii;
+-- disable_info
+DROP TABLE t;
+
+# Below is a shell script to generate the full set of ALTER TABLE
+# DROP/ADD/RENAME combinations. The generated .sql file is 3.3MB and
+# executes in about 7 minutes.
+#
+##!/bin/sh
+#
+#create="
+#CREATE TABLE t (
+# a INT,
+# b INT,
+# c INT,
+# d INT,
+# PRIMARY KEY (a),
+# INDEX i1 (b),
+# INDEX i2 (c)
+#) ENGINE=INNODB;
+#"
+#
+#echo "DROP TABLE IF EXISTS t;"
+#for r in "" ", DROP PRIMARY KEY, ADD PRIMARY KEY (a)" ", ROW_FORMAT=REDUNDANT" ; do
+# for i1 in i1 i1noexist; do
+# for i2 in i2 i2noexist; do
+# for i3 in i3 i3noexist; do
+# for i4 in i4 i4noexist; do
+# for a in $i1 $i2 $i3 $i4; do
+# for b in $i1 $i2 $i3 $i4; do
+# for c in $i1 $i2 $i3 $i4; do
+# for d in $i1 $i2 $i3 $i4; do
+# echo "$create"
+# echo "ALTER TABLE t ADD INDEX $a (d), RENAME INDEX $b TO $c, DROP INDEX $d $r;"
+# echo "DROP TABLE t;"
+# done
+# done
+# done
+# done
+# done
+# done
+# done
+# done
+#done
diff --git a/mysql-test/suite/innodb/t/innodb_row_lock_time_ms.test b/mysql-test/suite/innodb/t/innodb_row_lock_time_ms.test
new file mode 100644
index 00000000..4a100821
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb_row_lock_time_ms.test
@@ -0,0 +1,42 @@
+--source include/have_innodb.inc
+--source include/count_sessions.inc
+
+CREATE TABLE `t`(`id` INT, PRIMARY KEY(`id`)) ENGINE=InnoDB STATS_PERSISTENT=0;
+
+INSERT INTO t VALUES (1);
+
+SET GLOBAL innodb_monitor_reset = "module_innodb";
+
+BEGIN;
+SELECT * FROM t FOR UPDATE;
+
+--connect(con1,localhost,root,,)
+SET innodb_lock_wait_timeout = 1;
+--error ER_LOCK_WAIT_TIMEOUT
+SELECT * FROM t FOR UPDATE;
+--disconnect con1
+
+--connection default
+COMMIT;
+
+SELECT variable_value > 100 FROM information_schema.global_status
+ WHERE LOWER(variable_name) = 'innodb_row_lock_time';
+SELECT variable_value > 100 FROM information_schema.global_status
+ WHERE LOWER(variable_name) = 'innodb_row_lock_time_max';
+SELECT variable_value > 100 FROM information_schema.global_status
+ WHERE LOWER(variable_name) = 'innodb_row_lock_time_avg';
+
+SELECT count_reset > 100 FROM INFORMATION_SCHEMA.INNODB_METRICS
+ WHERE NAME="lock_row_lock_time";
+SELECT count_reset > 100 FROM INFORMATION_SCHEMA.INNODB_METRICS
+ WHERE NAME="lock_row_lock_time_max";
+SELECT count_reset > 100 FROM INFORMATION_SCHEMA.INNODB_METRICS
+ WHERE NAME="lock_row_lock_time_avg";
+
+DROP TABLE t;
+
+--disable_warnings
+SET GLOBAL innodb_monitor_reset=default;
+--enable_warnings
+
+--source include/wait_until_count_sessions.inc
diff --git a/mysql-test/suite/innodb/t/innodb_scrub.opt b/mysql-test/suite/innodb/t/innodb_scrub.opt
new file mode 100644
index 00000000..f9984508
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb_scrub.opt
@@ -0,0 +1 @@
+--innodb-immediate-scrub-data-uncompressed=ON
diff --git a/mysql-test/suite/innodb/t/innodb_scrub.test b/mysql-test/suite/innodb/t/innodb_scrub.test
new file mode 100644
index 00000000..8fe460da
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb_scrub.test
@@ -0,0 +1,45 @@
+-- source include/have_innodb.inc
+-- source include/no_valgrind_without_big.inc
+
+let $MYSQLD_DATADIR=`select @@datadir`;
+CREATE TABLE t1(f1 int auto_increment primary key,
+ f2 varchar(256),
+ f3 text) engine = innodb;
+let $numinserts = 500;
+--disable_query_log
+begin;
+while ($numinserts)
+{
+ dec $numinserts;
+ eval INSERT INTO t1(f2,f3) VALUES ('repairman', repeat('unicycle', 1000));
+}
+commit;
+--enable_query_log
+FLUSH TABLE t1 FOR EXPORT;
+UNLOCK TABLES;
+
+let SEARCH_PATTERN= unicycle|repairman;
+let SEARCH_FILE= $MYSQLD_DATADIR/test/t1.ibd;
+-- source include/search_pattern_in_file.inc
+DELETE FROM t1;
+-- source include/wait_all_purged.inc
+FLUSH TABLE t1 FOR EXPORT;
+UNLOCK TABLES;
+-- source include/search_pattern_in_file.inc
+DROP TABLE t1;
+
+--echo #
+--echo # MDEV-30527 Assertion !m_freed_pages in mtr_t::start()
+--echo # on DROP TEMPORARY TABLE
+--echo #
+SET @scrub= @@GLOBAL.innodb_immediate_scrub_data_uncompressed;
+SET GLOBAL innodb_immediate_scrub_data_uncompressed= 1;
+SET @fpt=@@GLOBAL.innodb_file_per_table;
+SET GLOBAL innodb_file_per_table=0;
+CREATE TABLE t ENGINE=InnoDB AS SELECT 1;
+DROP TABLE t;
+SET GLOBAL innodb_file_per_table=@fpt;
+CREATE TEMPORARY TABLE tmp ENGINE=InnoDB AS SELECT 1;
+DROP TABLE tmp;
+SET GLOBAL INNODB_IMMEDIATE_SCRUB_DATA_UNCOMPRESSED= @scrub;
+--echo # End of 10.6 tests
diff --git a/mysql-test/suite/innodb/t/innodb_skip_innodb_is_tables.opt b/mysql-test/suite/innodb/t/innodb_skip_innodb_is_tables.opt
new file mode 100644
index 00000000..f34d0232
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb_skip_innodb_is_tables.opt
@@ -0,0 +1,61 @@
+--loose-skip-innodb
+--loose-innodb_trx
+--loose-innodb_locks
+--loose-innodb_lock_waits
+--loose-innodb_cmp
+--loose-innodb_cmp_reset
+--loose-innodb_cmp_per_index
+--loose-innodb_cmp_per_index_reset
+--loose-innodb_cmpmem
+--loose-innodb_cmpmem_reset
+--loose-innodb_metrics
+--loose-innodb_ft_default_stopword
+--loose-innodb_ft_deleted
+--loose-innodb_ft_being_deleted
+--loose-innodb_ft_index_cache
+--loose-innodb_ft_index_table
+--loose-innodb_ft_config
+--loose-innodb_buffer_page
+--loose-innodb_buffer_page_lru
+--loose-innodb_buffer_stats
+--loose-innodb_sys_tables
+--loose-innodb_sys_tablestats
+--loose-innodb_sys_indexes
+--loose-innodb_sys_columns
+--loose-innodb_sys_fields
+--loose-innodb_sys_foreign
+--loose-innodb_sys_foreign_cols
+--loose-innodb_sys_tablespaces
+--loose-innodb_sys_datafiles
+--loose-innodb_changed_pages
+--loose-innodb_tablespaces_encryption
+--loose-innodb_trx
+--loose-innodb_locks
+--loose-innodb_lock_waits
+--loose-innodb_cmp
+--loose-innodb_cmp_reset
+--loose-innodb_cmp_per_index
+--loose-innodb_cmp_per_index_reset
+--loose-innodb_cmpmem
+--loose-innodb_cmpmem_reset
+--loose-innodb_metrics
+--loose-innodb_ft_default_stopword
+--loose-innodb_ft_deleted
+--loose-innodb_ft_being_deleted
+--loose-innodb_ft_index_cache
+--loose-innodb_ft_index_table
+--loose-innodb_ft_config
+--loose-innodb_buffer_page
+--loose-innodb_buffer_page_lru
+--loose-innodb_buffer_stats
+--loose-innodb_sys_tables
+--loose-innodb_sys_tablestats
+--loose-innodb_sys_indexes
+--loose-innodb_sys_columns
+--loose-innodb_sys_fields
+--loose-innodb_sys_foreign
+--loose-innodb_sys_foreign_cols
+--loose-innodb_sys_tablespaces
+--loose-innodb_sys_datafiles
+--loose-innodb_changed_pages
+--loose-innodb_tablespaces_encryption
diff --git a/mysql-test/suite/innodb/t/innodb_skip_innodb_is_tables.test b/mysql-test/suite/innodb/t/innodb_skip_innodb_is_tables.test
new file mode 100644
index 00000000..e3885f18
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb_skip_innodb_is_tables.test
@@ -0,0 +1,29 @@
+--source include/not_embedded.inc
+
+select * from information_schema.innodb_trx;
+select * from information_schema.innodb_locks;
+select * from information_schema.innodb_lock_waits;
+select * from information_schema.innodb_cmp;
+select * from information_schema.innodb_cmp_reset;
+select * from information_schema.innodb_cmp_per_index;
+select * from information_schema.innodb_cmp_per_index_reset;
+select * from information_schema.innodb_cmpmem;
+select * from information_schema.innodb_cmpmem_reset;
+select * from information_schema.innodb_metrics;
+select * from information_schema.innodb_ft_default_stopword;
+select * from information_schema.innodb_ft_deleted;
+select * from information_schema.innodb_ft_being_deleted;
+select * from information_schema.innodb_ft_index_cache;
+select * from information_schema.innodb_ft_index_table;
+select * from information_schema.innodb_ft_config;
+select * from information_schema.innodb_buffer_page;
+select * from information_schema.innodb_buffer_page_lru;
+select * from information_schema.innodb_sys_tables;
+select * from information_schema.innodb_sys_tablestats;
+select * from information_schema.innodb_sys_indexes;
+select * from information_schema.innodb_sys_columns;
+select * from information_schema.innodb_sys_fields;
+select * from information_schema.innodb_sys_foreign;
+select * from information_schema.innodb_sys_foreign_cols;
+select * from information_schema.innodb_sys_tablespaces;
+select * from information_schema.innodb_tablespaces_encryption;
diff --git a/mysql-test/suite/innodb/t/innodb_stats.test b/mysql-test/suite/innodb/t/innodb_stats.test
new file mode 100644
index 00000000..1a962e35
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb_stats.test
@@ -0,0 +1,65 @@
+#
+# Test the persistent stats feature
+#
+
+-- source include/have_innodb.inc
+
+-- disable_warnings
+-- disable_query_log
+
+DROP TABLE IF EXISTS test_innodb_stats;
+
+set @save_use_stat_tables= @@use_stat_tables;
+set @@use_stat_tables= NEVER;
+
+CREATE TABLE test_innodb_stats (
+ a INT,
+ KEY a_key (a)
+) ENGINE=INNODB STATS_PERSISTENT=1;
+
+-- enable_warnings
+-- enable_query_log
+
+# test empty table
+-- let $insert = SELECT 'dummy INSERT, the table should be empty'
+-- source suite/innodb/include/innodb_stats.inc
+
+# test table with 1 row
+-- let $insert = INSERT INTO test_innodb_stats (a) VALUES (1)
+-- source suite/innodb/include/innodb_stats.inc
+
+# test table with 2 eq rows
+-- let $insert = INSERT INTO test_innodb_stats (a) VALUES (1), (1)
+-- source suite/innodb/include/innodb_stats.inc
+
+# test table with 3 eq rows
+-- let $insert = INSERT INTO test_innodb_stats (a) VALUES (1), (1), (1)
+-- source suite/innodb/include/innodb_stats.inc
+
+# test table with 10 eq rows
+-- let $insert = INSERT INTO test_innodb_stats (a) VALUES (1), (1), (1), (1), (1), (1), (1), (1), (1), (1)
+-- source suite/innodb/include/innodb_stats.inc
+
+# test table with 2 diff rows
+-- let $insert = INSERT INTO test_innodb_stats (a) VALUES (1), (2)
+-- source suite/innodb/include/innodb_stats.inc
+
+# test table with 2 diff rows, 3 rows in total
+-- let $insert = INSERT INTO test_innodb_stats (a) VALUES (1), (1), (2)
+-- source suite/innodb/include/innodb_stats.inc
+
+# test table with 3 diff rows
+-- let $insert = INSERT INTO test_innodb_stats (a) VALUES (1), (2), (3)
+-- source suite/innodb/include/innodb_stats.inc
+
+# test table with 3 diff rows, 5 rows in total
+-- let $insert = INSERT INTO test_innodb_stats (a) VALUES (1), (1), (2), (3), (3)
+-- source suite/innodb/include/innodb_stats.inc
+
+# test table with 5 diff rows, 10 rows in total
+-- let $insert = INSERT INTO test_innodb_stats (a) VALUES (1), (2), (3), (4), (5), (1), (2), (3), (4), (5)
+-- source suite/innodb/include/innodb_stats.inc
+
+-- disable_query_log
+DROP TABLE test_innodb_stats;
+set @@use_stat_tables= @save_use_stat_tables;
diff --git a/mysql-test/suite/innodb/t/innodb_stats_create_on_corrupted.test b/mysql-test/suite/innodb/t/innodb_stats_create_on_corrupted.test
new file mode 100644
index 00000000..2ca5ee9f
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb_stats_create_on_corrupted.test
@@ -0,0 +1,60 @@
+#
+# Test creating a persistent stats table on nonexistent or corrupted
+# persistent storage
+#
+
+-- source include/have_innodb.inc
+# Various sizes printed in this test depend on the page size and the
+# functionality tested here is not related to the page size, so we only
+# test with 16k page size.
+-- source include/have_innodb_16k.inc
+-- source include/not_embedded.inc
+
+call mtr.add_suppression("InnoDB: Table .*innodb_index_stats.* not found");
+call mtr.add_suppression("InnoDB: Fetch of persistent statistics requested for table .*");
+call mtr.add_suppression("InnoDB: Table mysql\\.innodb_index_stats has length mismatch in the column name stat_description\\. Please run mariadb-upgrade");
+call mtr.add_suppression("InnoDB: Column stat_description in table mysql\\.innodb_index_stats is VARCHAR");
+
+-- vertical_results
+
+# corrupt the persistent storage
+ALTER TABLE mysql.innodb_index_stats RENAME TO mysql.innodb_index_stats_;
+
+CREATE TABLE test_ps_create_on_corrupted
+(a INT, PRIMARY KEY (a))
+ENGINE=INNODB STATS_PERSISTENT=1;
+
+# check the stats (should have been generated using the old transient stats
+# method)
+SELECT seq_in_index, column_name, cardinality
+FROM information_schema.statistics WHERE table_name = 'test_ps_create_on_corrupted'
+ORDER BY index_name, seq_in_index;
+
+SELECT table_rows, avg_row_length, max_data_length, index_length
+FROM information_schema.tables WHERE table_name = 'test_ps_create_on_corrupted';
+
+# restore the persistent storage
+ALTER TABLE mysql.innodb_index_stats_ RENAME TO mysql.innodb_index_stats;
+
+SET old_mode='';
+ALTER TABLE mysql.innodb_index_stats
+MODIFY stat_description VARCHAR(1024) COLLATE utf8_bin;
+CREATE TABLE t (a INT) ENGINE=InnoDB STATS_PERSISTENT=1;
+ALTER TABLE mysql.innodb_index_stats
+MODIFY stat_description VARCHAR(1024) COLLATE utf8mb3_bin NOT NULL;
+
+DROP TABLE t;
+
+--source include/restart_mysqld.inc
+
+-- vertical_results
+
+# check again
+SELECT seq_in_index, column_name, cardinality
+FROM information_schema.statistics WHERE table_name = 'test_ps_create_on_corrupted'
+ORDER BY index_name, seq_in_index;
+
+SELECT table_rows, avg_row_length, max_data_length, index_length
+FROM information_schema.tables WHERE table_name = 'test_ps_create_on_corrupted';
+
+DROP TABLE test_ps_create_on_corrupted;
diff --git a/mysql-test/suite/innodb/t/innodb_stats_create_table.test b/mysql-test/suite/innodb/t/innodb_stats_create_table.test
new file mode 100644
index 00000000..e7ae09bd
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb_stats_create_table.test
@@ -0,0 +1,66 @@
+#
+# Test CREATE TABLE ... STATS_PERSISTENT=0|1|default
+#
+
+-- source include/have_innodb.inc
+
+set @save_innodb_stats_persistent= @@innodb_stats_persistent;
+
+set global innodb_stats_persistent=default;
+
+-- vertical_results
+
+# confirm that nothing is present before the test
+SELECT COUNT(*) FROM mysql.innodb_table_stats WHERE
+database_name = 'test' AND
+table_name = 'test_ps_create_table';
+
+##
+
+CREATE TABLE test_ps_create_table (a INT, PRIMARY KEY (a))
+ENGINE=INNODB STATS_PERSISTENT=0;
+
+# nothing should be present
+SELECT COUNT(*) FROM mysql.innodb_table_stats WHERE
+database_name = 'test' AND
+table_name = 'test_ps_create_table';
+
+DROP TABLE test_ps_create_table;
+
+##
+
+CREATE TABLE test_ps_create_table (a INT, PRIMARY KEY (a))
+ENGINE=INNODB;
+
+# 1 row should be present if the default of --innodb-stats-persistent is 1
+SELECT COUNT(*) FROM mysql.innodb_table_stats WHERE
+database_name = 'test' AND
+table_name = 'test_ps_create_table';
+
+DROP TABLE test_ps_create_table;
+
+##
+
+CREATE TABLE test_ps_create_table (a INT, PRIMARY KEY (a))
+ENGINE=INNODB STATS_PERSISTENT=default;
+
+# 1 row should be present if the default of --innodb-stats-persistent is 1
+SELECT COUNT(*) FROM mysql.innodb_table_stats WHERE
+database_name = 'test' AND
+table_name = 'test_ps_create_table';
+
+DROP TABLE test_ps_create_table;
+
+##
+
+CREATE TABLE test_ps_create_table (a INT, PRIMARY KEY (a))
+ENGINE=INNODB STATS_PERSISTENT=1;
+
+# 1 row should be present
+SELECT COUNT(*) FROM mysql.innodb_table_stats WHERE
+database_name = 'test' AND
+table_name = 'test_ps_create_table';
+
+DROP TABLE test_ps_create_table;
+
+set global innodb_stats_persistent= @save_innodb_stats_persistent;
diff --git a/mysql-test/suite/innodb/t/innodb_stats_drop_locked.test b/mysql-test/suite/innodb/t/innodb_stats_drop_locked.test
new file mode 100644
index 00000000..6532816b
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb_stats_drop_locked.test
@@ -0,0 +1,65 @@
+#
+# Test the persistent stats feature when DROPping a table or an
+# index when the corresponding rows in the stats tables are locked
+#
+
+-- source include/have_innodb.inc
+
+CREATE DATABASE unlocked;
+CREATE TABLE unlocked.t1(a INT PRIMARY KEY) ENGINE=INNODB STATS_PERSISTENT=0;
+CREATE DATABASE locked;
+CREATE TABLE locked.t1(a INT PRIMARY KEY) ENGINE=INNODB STATS_PERSISTENT=1;
+
+CREATE TABLE innodb_stats_drop_locked (c INT, KEY c_key (c))
+ENGINE=INNODB STATS_PERSISTENT=1;
+ANALYZE TABLE innodb_stats_drop_locked;
+
+BEGIN;
+SELECT table_name FROM mysql.innodb_table_stats
+WHERE table_name='innodb_stats_drop_locked'
+FOR UPDATE;
+SELECT table_name FROM mysql.innodb_index_stats
+WHERE table_name='innodb_stats_drop_locked'
+FOR UPDATE;
+
+-- connect (con1,localhost,root,,)
+SET innodb_lock_wait_timeout=1;
+
+--error ER_LOCK_WAIT_TIMEOUT
+ALTER TABLE innodb_stats_drop_locked DROP INDEX c_key;
+
+# the index should be gone
+SHOW CREATE TABLE innodb_stats_drop_locked;
+
+--error ER_LOCK_WAIT_TIMEOUT
+DROP TABLE innodb_stats_drop_locked;
+
+DROP DATABASE unlocked;
+--error ER_LOCK_WAIT_TIMEOUT
+DROP DATABASE locked;
+-- disconnect con1
+-- connection default
+COMMIT;
+
+DROP DATABASE locked;
+
+# the stats should be there
+
+SELECT table_name FROM mysql.innodb_table_stats
+WHERE table_name='innodb_stats_drop_locked';
+
+SELECT table_name FROM mysql.innodb_index_stats
+WHERE table_name='innodb_stats_drop_locked';
+
+ALTER TABLE innodb_stats_drop_locked DROP INDEX c_key;
+
+SELECT table_name FROM mysql.innodb_index_stats
+WHERE table_name='innodb_stats_drop_locked';
+
+DROP TABLE innodb_stats_drop_locked;
+
+SELECT table_name FROM mysql.innodb_table_stats
+WHERE table_name='innodb_stats_drop_locked';
+
+SELECT table_name FROM mysql.innodb_index_stats
+WHERE table_name='innodb_stats_drop_locked';
diff --git a/mysql-test/suite/innodb/t/innodb_stats_fetch.test b/mysql-test/suite/innodb/t/innodb_stats_fetch.test
new file mode 100644
index 00000000..549ad65f
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb_stats_fetch.test
@@ -0,0 +1,83 @@
+#
+# Test fetching from stats tables after manual update (ie FLUSH TABLE
+# can be used to forcibly (re)fetch the stats from disk)
+#
+
+-- source include/have_innodb.inc
+# Various sizes printed in this test depend on the page size and the
+# functionality tested here is not related to the page size, so we only
+# test with 16k page size.
+-- source include/have_innodb_16k.inc
+
+-- vertical_results
+
+set @save_use_stat_tables = @@use_stat_tables;
+set @@use_stat_tables = COMPLEMENTARY;
+
+CREATE TABLE test_ps_fetch
+(a INT, b INT, c INT, d INT, PRIMARY KEY (a, b), INDEX idx (c, d))
+ENGINE=INNODB STATS_PERSISTENT=1;
+
+ANALYZE TABLE test_ps_fetch;
+
+SELECT n_rows, clustered_index_size, sum_of_other_index_sizes
+FROM mysql.innodb_table_stats WHERE table_name = 'test_ps_fetch';
+
+SELECT index_name, stat_name, stat_value, sample_size, stat_description
+FROM mysql.innodb_index_stats WHERE table_name = 'test_ps_fetch'
+ORDER BY index_name, stat_name;
+
+SELECT index_name, seq_in_index, column_name, cardinality
+FROM information_schema.statistics WHERE table_name = 'test_ps_fetch'
+ORDER BY index_name, seq_in_index;
+
+SELECT
+table_rows, avg_row_length, max_data_length, index_length
+FROM information_schema.tables WHERE table_name = 'test_ps_fetch';
+
+UPDATE mysql.innodb_table_stats SET
+n_rows = 1000,
+clustered_index_size = 5
+WHERE
+table_name = 'test_ps_fetch';
+
+UPDATE mysql.innodb_index_stats SET
+stat_value = 20
+WHERE
+table_name = 'test_ps_fetch' AND
+index_name = 'PRIMARY' AND
+stat_name = 'n_diff_pfx01';
+
+UPDATE mysql.innodb_index_stats SET
+stat_value = 90
+WHERE
+table_name = 'test_ps_fetch' AND
+index_name = 'PRIMARY' AND
+stat_name = 'n_diff_pfx02';
+
+UPDATE mysql.innodb_index_stats SET
+stat_value = 3
+WHERE
+table_name = 'test_ps_fetch' AND
+index_name = 'idx' AND
+stat_name = 'n_diff_pfx01';
+
+UPDATE mysql.innodb_index_stats SET
+stat_value = 11
+WHERE
+table_name = 'test_ps_fetch' AND
+index_name = 'idx' AND
+stat_name = 'n_diff_pfx02';
+
+FLUSH TABLE test_ps_fetch;
+
+SELECT seq_in_index, column_name, cardinality
+FROM information_schema.statistics WHERE table_name = 'test_ps_fetch'
+ORDER BY index_name, seq_in_index;
+
+SELECT
+table_rows, avg_row_length, max_data_length, index_length
+FROM information_schema.tables WHERE table_name = 'test_ps_fetch';
+
+DROP TABLE test_ps_fetch;
+set @@use_stat_tables = @save_use_stat_tables;
diff --git a/mysql-test/suite/innodb/t/innodb_stats_fetch_corrupted.test b/mysql-test/suite/innodb/t/innodb_stats_fetch_corrupted.test
new file mode 100644
index 00000000..acc88800
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb_stats_fetch_corrupted.test
@@ -0,0 +1,58 @@
+#
+# Test fetching from stats tables that are corrupted
+#
+
+-- source include/have_innodb.inc
+# Various sizes printed in this test depend on the page size and the
+# functionality tested here is not related to the page size, so we only
+# test with 16k page size.
+-- source include/have_innodb_16k.inc
+# server restart
+-- source include/not_embedded.inc
+
+call mtr.add_suppression("InnoDB: Column stat_value in table mysql\\.innodb_index_stats is BIGINT UNSIGNED but should be BIGINT UNSIGNED NOT NULL");
+call mtr.add_suppression("InnoDB: Fetch of persistent statistics requested for table");
+
+-- vertical_results
+
+CREATE TABLE test_ps_fetch_corrupted
+(a INT, PRIMARY KEY (a))
+ENGINE=INNODB STATS_PERSISTENT=1;
+
+# write stats to mysql.innodb_table_stats
+ANALYZE TABLE test_ps_fetch_corrupted;
+
+# check that indeed stats were written by ANALYZE above
+SELECT n_rows, clustered_index_size, sum_of_other_index_sizes
+FROM mysql.innodb_table_stats WHERE table_name = 'test_ps_fetch_corrupted';
+
+# corrupt the persistent storage
+ALTER TABLE mysql.innodb_index_stats MODIFY stat_value BIGINT UNSIGNED NULL;
+
+# reopen the table, this will attept to read from the persistent storage
+FLUSH TABLE test_ps_fetch_corrupted;
+
+# check the stats (should have been generated using the old transient stats
+# method)
+SELECT seq_in_index, column_name, cardinality
+FROM information_schema.statistics WHERE table_name = 'test_ps_fetch_corrupted'
+ORDER BY index_name, seq_in_index;
+
+SELECT table_rows, avg_row_length, max_data_length, index_length
+FROM information_schema.tables WHERE table_name = 'test_ps_fetch_corrupted';
+
+# restore the persistent storage
+ALTER TABLE mysql.innodb_index_stats MODIFY stat_value BIGINT UNSIGNED NOT NULL;
+FLUSH TABLE test_ps_fetch_corrupted;
+
+SELECT seq_in_index, column_name, cardinality
+FROM information_schema.statistics WHERE table_name = 'test_ps_fetch_corrupted'
+ORDER BY index_name, seq_in_index;
+
+SELECT table_rows, avg_row_length, max_data_length, index_length
+FROM information_schema.tables WHERE table_name = 'test_ps_fetch_corrupted';
+
+DROP TABLE test_ps_fetch_corrupted;
+
+# force server restart to clean up log from above error
+--source include/restart_mysqld.inc
diff --git a/mysql-test/suite/innodb/t/innodb_stats_fetch_nonexistent.test b/mysql-test/suite/innodb/t/innodb_stats_fetch_nonexistent.test
new file mode 100644
index 00000000..b06abd30
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb_stats_fetch_nonexistent.test
@@ -0,0 +1,38 @@
+#
+# Test fetching from stats tables while there are no stats
+#
+
+-- source include/have_innodb.inc
+
+call mtr.add_suppression("InnoDB: Error: Fetch of persistent statistics requested for table *");
+
+-- vertical_results
+
+CREATE TABLE test_ps_fetch_nonexistent
+(a INT, PRIMARY KEY (a))
+ENGINE=INNODB STATS_PERSISTENT=1;
+
+# write stats to mysql.innodb_table_stats
+ANALYZE TABLE test_ps_fetch_nonexistent;
+
+# check that indeed stats were written by ANALYZE above
+SELECT COUNT(*)
+FROM mysql.innodb_table_stats WHERE table_name = 'test_ps_fetch_nonexistent';
+
+# delete the stats
+DELETE FROM mysql.innodb_index_stats WHERE table_name = 'test_ps_fetch_nonexistent';
+DELETE FROM mysql.innodb_table_stats WHERE table_name = 'test_ps_fetch_nonexistent';
+
+# reopen the table, this will attept to read the stats
+FLUSH TABLE test_ps_fetch_nonexistent;
+
+# check the stats (should have been generated using the old transient stats
+# method)
+SELECT seq_in_index, column_name, cardinality
+FROM information_schema.statistics WHERE table_name = 'test_ps_fetch_nonexistent'
+ORDER BY index_name, seq_in_index;
+
+SELECT table_rows, avg_row_length, max_data_length, index_length
+FROM information_schema.tables WHERE table_name = 'test_ps_fetch_nonexistent';
+
+DROP TABLE test_ps_fetch_nonexistent;
diff --git a/mysql-test/suite/innodb/t/innodb_stats_persistent.test b/mysql-test/suite/innodb/t/innodb_stats_persistent.test
new file mode 100644
index 00000000..a8a311a6
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb_stats_persistent.test
@@ -0,0 +1,84 @@
+--source include/have_innodb.inc
+--source include/have_sequence.inc
+
+SET @saved_include_delete_marked = @@GLOBAL.innodb_stats_include_delete_marked;
+SET GLOBAL innodb_stats_include_delete_marked = ON;
+SET @saved_traditional = @@GLOBAL.innodb_stats_traditional;
+SET GLOBAL innodb_stats_traditional=false;
+SET @saved_modified_counter = @@GLOBAL.innodb_stats_modified_counter;
+SET GLOBAL innodb_stats_modified_counter=1;
+
+CREATE TABLE t1 (id SERIAL, val INT UNSIGNED NOT NULL, KEY(val))
+ENGINE=INNODB STATS_PERSISTENT=1,STATS_AUTO_RECALC=1;
+CREATE TABLE t2 LIKE t1;
+
+INSERT INTO t1 (val) SELECT 4 FROM seq_1_to_16;
+ANALYZE TABLE t1;
+
+connect(con1, localhost, root,,);
+START TRANSACTION;
+DELETE FROM t1;
+send SELECT COUNT(*) FROM t1;
+
+connection default;
+--echo # With innodb_stats_include_delete_marked=ON,
+--echo # DELETE must not affect statistics before COMMIT.
+EXPLAIN SELECT * FROM t1 WHERE val=4;
+
+connection con1;
+reap;
+ROLLBACK;
+SELECT COUNT(*) FROM t1;
+EXPLAIN SELECT * FROM t1 WHERE val=4;
+
+BEGIN;
+DELETE FROM t1;
+COMMIT;
+SELECT COUNT(*) FROM t1;
+
+connection default;
+BEGIN;
+INSERT INTO t2 (val) SELECT 4 FROM seq_1_to_16;
+
+--echo # The INSERT will show up before COMMIT.
+EXPLAIN SELECT * FROM t2 WHERE val=4;
+SELECT COUNT(*) FROM t2;
+--echo # The ROLLBACK of the INSERT must affect the statistics.
+ROLLBACK;
+SELECT COUNT(*) FROM t2;
+
+connection con1;
+EXPLAIN SELECT * FROM t2 WHERE val=4;
+--source include/wait_all_purged.inc
+--echo # After COMMIT and purge, the DELETE must show up.
+EXPLAIN SELECT * FROM t1 WHERE val=4;
+
+SET GLOBAL innodb_stats_include_delete_marked = OFF;
+BEGIN;
+INSERT INTO t1 (val) SELECT 4 FROM seq_1_to_16;
+EXPLAIN SELECT * FROM t1 WHERE val=4;
+ROLLBACK;
+EXPLAIN SELECT * FROM t1 WHERE val=4;
+BEGIN;
+INSERT INTO t1 (val) SELECT 4 FROM seq_1_to_16;
+COMMIT;
+EXPLAIN SELECT * FROM t1 WHERE val=4;
+BEGIN;
+DELETE FROM t1;
+SELECT COUNT(*) FROM t1;
+--echo # With innodb_stats_include_delete_marked=OFF,
+--echo # DELETE must affect statistics even before COMMIT.
+--echo # However, if there was a WHERE condition,
+--echo # ha_innobase::records_in_range() would count the delete-marked records.
+EXPLAIN SELECT * FROM t1;
+ROLLBACK;
+EXPLAIN SELECT * FROM t1;
+SELECT COUNT(*) FROM t1;
+disconnect con1;
+
+connection default;
+
+DROP TABLE t1,t2;
+SET GLOBAL innodb_stats_include_delete_marked = @saved_include_delete_marked;
+SET GLOBAL innodb_stats_traditional = @saved_traditional;
+SET GLOBAL innodb_stats_modified_counter = @saved_modified_counter;
diff --git a/mysql-test/suite/innodb/t/innodb_stats_persistent_debug.test b/mysql-test/suite/innodb/t/innodb_stats_persistent_debug.test
new file mode 100644
index 00000000..7b16fa15
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb_stats_persistent_debug.test
@@ -0,0 +1,32 @@
+--source include/have_innodb.inc
+--source include/have_debug.inc
+
+--echo #
+--echo # MDEV-13534 InnoDB STATS_PERSISTENT fails to ignore
+--echo # garbage delete-mark flag on node pointer pages
+--echo #
+
+CREATE TABLE t(a INT UNSIGNED PRIMARY KEY)
+ENGINE=InnoDB STATS_PERSISTENT=1 STATS_SAMPLE_PAGES=1;
+
+BEGIN;
+# Create an index tree of height 3.
+# This is adapted from innodb.innodb_bug14676111.
+
+SET @save_debug = @@GLOBAL.innodb_limit_optimistic_insert_debug;
+SET GLOBAL innodb_limit_optimistic_insert_debug=2;
+
+INSERT t VALUES(1),(5);
+DELETE FROM t;
+INSERT t VALUES(4);
+DELETE FROM t;
+INSERT t VALUES(3);
+DELETE FROM t;
+SET GLOBAL innodb_limit_optimistic_insert_debug = @save_debug;
+
+connect(con1, localhost, root,,);
+ANALYZE TABLE t;
+disconnect con1;
+
+connection default;
+DROP TABLE t;
diff --git a/mysql-test/suite/innodb/t/innodb_stats_rename_table.test b/mysql-test/suite/innodb/t/innodb_stats_rename_table.test
new file mode 100644
index 00000000..5c1fe0f2
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb_stats_rename_table.test
@@ -0,0 +1,42 @@
+#
+# Test that RENAME TABLE renames the entries in
+# mysql.innodb_table_stats and mysql.innodb_index_stats
+#
+
+-- source include/have_innodb.inc
+
+-- vertical_results
+
+# confirm that nothing is present before the test
+SELECT table_name, n_rows
+FROM mysql.innodb_table_stats
+WHERE table_name IN ('stats_rename_old', 'stats_rename_new');
+
+SELECT table_name, index_name, stat_name, stat_value
+FROM mysql.innodb_index_stats
+WHERE table_name IN ('stats_rename_old', 'stats_rename_new');
+
+CREATE TABLE stats_rename_old (a INT, PRIMARY KEY (a))
+ENGINE=INNODB STATS_PERSISTENT=1;
+
+# confirm that CREATE inserted a zeroed entries
+SELECT table_name, n_rows
+FROM mysql.innodb_table_stats
+WHERE table_name IN ('stats_rename_old', 'stats_rename_new');
+
+SELECT table_name, index_name, stat_name, stat_value
+FROM mysql.innodb_index_stats
+WHERE table_name IN ('stats_rename_old', 'stats_rename_new');
+
+RENAME TABLE stats_rename_old TO stats_rename_new;
+
+# confirm that rows were updated correspondingly
+SELECT table_name, n_rows
+FROM mysql.innodb_table_stats
+WHERE table_name IN ('stats_rename_old', 'stats_rename_new');
+
+SELECT table_name, index_name, stat_name, stat_value
+FROM mysql.innodb_index_stats
+WHERE table_name IN ('stats_rename_old', 'stats_rename_new');
+
+DROP TABLE stats_rename_new;
diff --git a/mysql-test/suite/innodb/t/innodb_stats_rename_table_if_exists.test b/mysql-test/suite/innodb/t/innodb_stats_rename_table_if_exists.test
new file mode 100644
index 00000000..3f0b5c03
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb_stats_rename_table_if_exists.test
@@ -0,0 +1,75 @@
+#
+# Test what happens during RENAME TABLE if there are already rows in the stats
+# tables for the new table. This cannot happen normally, one have to insert
+# manually like what we do here.
+#
+# The RENAME should succeed and existent rows should be overwritten.
+#
+
+-- source include/have_innodb.inc
+
+-- vertical_results
+
+CREATE TABLE stats_rename1 (a INT PRIMARY KEY, b INT UNIQUE)
+ENGINE=INNODB STATS_PERSISTENT=1;
+
+BEGIN;
+INSERT INTO mysql.innodb_table_stats
+SELECT
+database_name,
+'stats_rename2' AS table_name,
+last_update,
+123 AS n_rows,
+clustered_index_size,
+sum_of_other_index_sizes
+FROM mysql.innodb_table_stats
+WHERE table_name = 'stats_rename1';
+
+INSERT INTO mysql.innodb_index_stats
+SELECT
+database_name,
+'stats_rename2' AS table_name,
+index_name,
+last_update,
+stat_name,
+567 AS stat_value,
+sample_size,
+stat_description
+FROM mysql.innodb_index_stats
+WHERE table_name = 'stats_rename1';
+COMMIT;
+
+SELECT table_name, n_rows
+FROM mysql.innodb_table_stats
+WHERE table_name IN ('stats_rename1', 'stats_rename2');
+
+SELECT table_name, index_name, stat_name, stat_value
+FROM mysql.innodb_index_stats
+WHERE table_name IN ('stats_rename1', 'stats_rename2');
+
+--error ER_DUP_KEY
+RENAME TABLE stats_rename1 TO stats_rename2;
+BEGIN;
+DELETE FROM mysql.innodb_table_stats WHERE table_name='stats_rename2';
+DELETE FROM mysql.innodb_index_stats WHERE table_name='stats_rename2';
+COMMIT;
+RENAME TABLE stats_rename1 TO stats_rename2;
+
+UPDATE mysql.innodb_index_stats SET index_name='c'
+WHERE table_name='stats_rename2' AND index_name='PRIMARY';
+--error ER_DUP_KEY
+ALTER TABLE stats_rename2 CHANGE b d INT, RENAME INDEX b TO c;
+UPDATE mysql.innodb_index_stats SET index_name='PRIMARY'
+WHERE table_name='stats_rename2' AND index_name='c';
+
+ALTER TABLE stats_rename2 CHANGE b d INT, RENAME INDEX b TO c;
+
+SELECT table_name, n_rows
+FROM mysql.innodb_table_stats
+WHERE table_name IN ('stats_rename1', 'stats_rename2');
+
+SELECT table_name, index_name, stat_name, stat_value
+FROM mysql.innodb_index_stats
+WHERE table_name IN ('stats_rename1', 'stats_rename2');
+
+DROP TABLE stats_rename2;
diff --git a/mysql-test/suite/innodb/t/innodb_status_variables.test b/mysql-test/suite/innodb/t/innodb_status_variables.test
new file mode 100644
index 00000000..6746a945
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb_status_variables.test
@@ -0,0 +1,7 @@
+--source include/have_innodb.inc
+SELECT variable_name FROM information_schema.global_status
+WHERE variable_name LIKE 'INNODB_%'
+AND variable_name NOT IN
+('INNODB_ADAPTIVE_HASH_HASH_SEARCHES','INNODB_ADAPTIVE_HASH_NON_HASH_SEARCHES',
+ 'INNODB_MEM_ADAPTIVE_HASH',
+ 'INNODB_BUFFERED_AIO_SUBMITTED','INNODB_BUFFER_POOL_PAGES_LATCHED');
diff --git a/mysql-test/suite/innodb/t/innodb_sys_var_valgrind.test b/mysql-test/suite/innodb/t/innodb_sys_var_valgrind.test
new file mode 100644
index 00000000..4383e268
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb_sys_var_valgrind.test
@@ -0,0 +1,52 @@
+--source include/have_innodb.inc
+
+--echo #
+--echo # Bug #29717909 MEMORY LIFETIME OF VARIABLES BETWEEN CHECK AND UPDATE INCORRECTLY MANAGED
+--echo #
+
+#Test innodb_ft_server_stopword_table (global variable)
+select @@innodb_ft_server_stopword_table;
+create table user_stopword_1(value varchar(30)) engine = innodb;
+create table user_stopword_2(value varchar(30)) engine = innodb;
+
+set @blah = 'test/user_stopword_1';
+SET GLOBAL innodb_ft_server_stopword_table= @blah;
+select @@innodb_ft_server_stopword_table;
+
+set @blah = 'test/user_stopword_2';
+SET GLOBAL innodb_ft_server_stopword_table= @blah;
+select @@innodb_ft_server_stopword_table;
+
+SET GLOBAL innodb_ft_server_stopword_table= NULL;
+select @@innodb_ft_server_stopword_table;
+
+SET GLOBAL innodb_ft_server_stopword_table= default;
+select @@innodb_ft_server_stopword_table;
+
+drop table user_stopword_1, user_stopword_2;
+
+#Test innodb_ft_aux_table (global variable)
+CREATE TABLE t1 ( id INT UNSIGNED AUTO_INCREMENT NOT NULL PRIMARY KEY,
+opening_line TEXT(500), author VARCHAR(200), title VARCHAR(200), FULLTEXT idx
+(opening_line)) ENGINE=InnoDB;
+
+CREATE TABLE t2 ( id INT UNSIGNED AUTO_INCREMENT NOT NULL PRIMARY KEY,
+opening_line TEXT(500), author VARCHAR(200), title VARCHAR(200), FULLTEXT idx
+(opening_line)) ENGINE=InnoDB;
+
+select @@innodb_ft_aux_table;
+
+set @blah = 'test/t1';
+SET GLOBAL innodb_ft_aux_table = @blah;
+select @@innodb_ft_aux_table;
+
+set @blah = 'test/t2';
+SET GLOBAL innodb_ft_aux_table = @blah;
+
+SET GLOBAL innodb_ft_aux_table = NULL;
+select @@innodb_ft_aux_table;
+
+SET GLOBAL innodb_ft_aux_table =default;
+select @@innodb_ft_aux_table;
+
+drop table t1,t2;
diff --git a/mysql-test/suite/innodb/t/innodb_timeout_rollback-master.opt b/mysql-test/suite/innodb/t/innodb_timeout_rollback-master.opt
new file mode 100644
index 00000000..a451be2e
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb_timeout_rollback-master.opt
@@ -0,0 +1 @@
+--loose-innodb_lock_wait_timeout=2 --loose-innodb_rollback_on_timeout
diff --git a/mysql-test/suite/innodb/t/innodb_timeout_rollback.test b/mysql-test/suite/innodb/t/innodb_timeout_rollback.test
new file mode 100644
index 00000000..44e8acdd
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb_timeout_rollback.test
@@ -0,0 +1,4 @@
+
+--source include/innodb_rollback_on_timeout.inc
+
+--echo End of 5.0 tests
diff --git a/mysql-test/suite/innodb/t/innodb_trx_weight.test b/mysql-test/suite/innodb/t/innodb_trx_weight.test
new file mode 100644
index 00000000..819f05f3
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb_trx_weight.test
@@ -0,0 +1,106 @@
+#
+# Ensure that the number of locks (SELECT FOR UPDATE for example) is
+# added to the number of altered rows when choosing the smallest
+# transaction to kill as a victim when a deadlock is detected.
+# Also transactions what had edited non-transactional tables should
+# be heavier than ones that had not.
+#
+
+-- source include/have_innodb.inc
+
+SET default_storage_engine=InnoDB;
+
+# we do not really care about what gets printed, we are only
+# interested in getting the deadlock resolved according to our
+# expectations
+-- disable_query_log
+-- disable_result_log
+
+# we want to use "-- eval statement1; statement2" which does not work with
+# prepared statements. Because this test should not behave differently with
+# or without prepared statements we disable them so the test does not fail
+# if someone runs ./mysql-test-run.pl --ps-protocol
+-- disable_ps_protocol
+
+# we will create a simple deadlock with t1, t2 and two connections
+CREATE TABLE t1 (a INT);
+CREATE TABLE t2 (a INT);
+
+# auxiliary table with a bulk of rows which will be locked by a
+# transaction to increase its weight
+CREATE TABLE t3 (a INT);
+
+# auxiliary empty table which will be inserted by a
+# transaction to increase its weight
+CREATE TABLE t4 (a INT);
+
+# auxiliary non-transactional table which will be edited by a
+# transaction to tremendously increase its weight
+CREATE TABLE t5_nontrans (a INT) ENGINE=MyISAM;
+
+INSERT INTO t1 VALUES (1);
+INSERT INTO t2 VALUES (1);
+# insert a lot of rows in t3
+INSERT INTO t3 VALUES (1);
+INSERT INTO t3 SELECT * FROM t3;
+INSERT INTO t3 SELECT * FROM t3;
+INSERT INTO t3 SELECT * FROM t3;
+INSERT INTO t3 SELECT * FROM t3;
+INSERT INTO t3 SELECT * FROM t3;
+INSERT INTO t3 SELECT * FROM t3;
+INSERT INTO t3 SELECT * FROM t3;
+INSERT INTO t3 SELECT * FROM t3;
+INSERT INTO t3 SELECT * FROM t3;
+INSERT INTO t3 SELECT * FROM t3;
+INSERT INTO t3 SELECT * FROM t3;
+
+# test locking weight
+
+-- let $con1_extra_sql =
+-- let $con1_extra_sql_present = 0
+-- let $con2_extra_sql = SELECT * FROM t3 FOR UPDATE
+-- let $con2_extra_sql_present = 1
+-- let $con1_should_be_rolledback = 1
+-- source include/innodb_trx_weight.inc
+
+-- let $con1_extra_sql = INSERT INTO t4 VALUES (1), (1)
+-- let $con1_extra_sql_present = 1
+-- let $con2_extra_sql = SELECT * FROM t3 FOR UPDATE
+-- let $con2_extra_sql_present = 1
+-- let $con1_should_be_rolledback = 1
+-- source include/innodb_trx_weight.inc
+
+-- let $con1_extra_sql = INSERT INTO t4 VALUES (1), (1), (1), (1), (1), (1)
+-- let $con1_extra_sql_present = 1
+-- let $con2_extra_sql = SELECT * FROM t3 FOR UPDATE
+-- let $con2_extra_sql_present = 1
+-- let $con1_should_be_rolledback = 1
+-- source include/innodb_trx_weight.inc
+
+# test weight when non-transactional tables are edited
+
+-- let $con1_extra_sql = INSERT INTO t4 VALUES (1), (1), (1)
+-- let $con1_extra_sql_present = 1
+-- let $con2_extra_sql =
+-- let $con2_extra_sql_present = 0
+-- let $con1_should_be_rolledback = 0
+-- source include/innodb_trx_weight.inc
+
+-- let $con1_extra_sql = INSERT INTO t4 VALUES (1), (1), (1)
+-- let $con1_extra_sql_present = 1
+-- let $con2_extra_sql = INSERT INTO t5_nontrans VALUES (1)
+-- let $con2_extra_sql_present = 1
+-- let $con1_should_be_rolledback = 1
+-- source include/innodb_trx_weight.inc
+
+-- let $con1_extra_sql = INSERT INTO t4 VALUES (1), (1), (1)
+-- let $con1_extra_sql = $con1_extra_sql; INSERT INTO t5_nontrans VALUES (1)
+-- let $con1_extra_sql_present = 1
+-- let $con2_extra_sql = INSERT INTO t5_nontrans VALUES (1)
+-- let $con2_extra_sql_present = 1
+-- let $con1_should_be_rolledback = 0
+-- source include/innodb_trx_weight.inc
+
+DROP TABLE t1, t2, t3, t4, t5_nontrans;
+
+call mtr.add_suppression("Deadlock found when trying to get lock; try restarting transaction");
diff --git a/mysql-test/suite/innodb/t/innodb_uninstall.opt b/mysql-test/suite/innodb/t/innodb_uninstall.opt
new file mode 100644
index 00000000..918855a7
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb_uninstall.opt
@@ -0,0 +1,3 @@
+--ignore-builtin-innodb
+--loose-innodb
+
diff --git a/mysql-test/suite/innodb/t/innodb_uninstall.test b/mysql-test/suite/innodb/t/innodb_uninstall.test
new file mode 100644
index 00000000..1b65db8a
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb_uninstall.test
@@ -0,0 +1,66 @@
+--source include/not_embedded.inc
+--source include/not_windows.inc
+
+if (!$HA_INNODB_SO) {
+ --skip Need InnoDB plugin
+}
+
+#
+# MDEV-8474: InnoDB sets per-connection data unsafely
+# Below test caused hang
+#
+# When mysqld is built with wsrep patch (WITH_WSREP=ON),
+# the following install command emits a warning about
+# server unable to enable tc-log at runtime.
+disable_warnings;
+install plugin innodb soname 'ha_innodb';
+enable_warnings;
+
+create table t1(a int not null primary key) engine=innodb;
+
+connect (con1, localhost, root);
+connection con1;
+begin;
+insert into t1 values(1);
+
+connection default;
+flush tables;
+send uninstall plugin innodb;
+
+connection con1;
+select sleep(1);
+disconnect con1;
+
+connection default;
+reap;
+
+--source include/restart_mysqld.inc
+
+#
+# Another test that caused hang.
+#
+
+connect (con1, localhost, root);
+connection con1;
+disable_warnings;
+install plugin innodb soname 'ha_innodb';
+enable_warnings;
+
+drop table t1;
+create table t2(a int not null primary key) engine=innodb;
+insert into t2 values(1);
+drop table t2;
+
+connection default;
+send uninstall plugin innodb;
+
+connection con1;
+select sleep(1);
+disconnect con1;
+
+connection default;
+reap;
+
+--source include/restart_mysqld.inc
+
+
diff --git a/mysql-test/suite/innodb/t/insert-before-delete.test b/mysql-test/suite/innodb/t/insert-before-delete.test
new file mode 100644
index 00000000..2547b94e
--- /dev/null
+++ b/mysql-test/suite/innodb/t/insert-before-delete.test
@@ -0,0 +1,72 @@
+--source include/have_innodb.inc
+--source include/have_debug.inc
+--source include/have_debug_sync.inc
+--source include/count_sessions.inc
+
+--connect (pause_purge,localhost,root)
+START TRANSACTION WITH CONSISTENT SNAPSHOT;
+
+--connection default
+CREATE TABLE t (pk int PRIMARY KEY, sk INT UNIQUE) ENGINE=InnoDB;
+INSERT INTO t VALUES (10, 100);
+
+--connect (con1,localhost,root)
+BEGIN; # trx 0
+SELECT * FROM t WHERE sk = 100 FOR UPDATE;
+
+--connect (con2,localhost,root)
+SET DEBUG_SYNC="lock_wait_start SIGNAL insert_wait_started";
+# trx 1 is locked on try to read the record in secondary index during duplicates
+# check. It's the first in waiting queue, that's why it will be woken up firstly
+# when trx 0 commits.
+--send INSERT INTO t VALUES (5, 100) # trx 1
+
+--connect (con3,localhost,root)
+# MDEV-30225 is fixed only for RR
+SET TRANSACTION ISOLATION LEVEL REPEATABLE READ;
+SET DEBUG_SYNC="now WAIT_FOR insert_wait_started";
+SET DEBUG_SYNC="lock_wait_start SIGNAL delete_started_waiting";
+# trx 2 can delete (5, 100) on master, but not on slave, as on slave trx 1
+# can insert (5, 100) after trx 2 positioned it's cursor. Trx 2 lock is placed
+# in waiting queue after trx 1 lock, but its persistent cursor position was
+# stored on (100, 10) record in secondary index before suspending. After trx 1
+# is committed, trx 2 will restore persistent cursor position on (100, 10). As
+# (100, 5) secondary index record was inserted before (100, 10) in logical
+# order, and (100, 10) record is delete-marked, trx 2 just continues scanning.
+#
+# Note. There can be several records with the same key in unique secondary
+# index, but only one of them must be non-delete-marked. That's why when we do
+# point query, cursor position is set in the first record in logical order, and
+# then records are iterated until either non-delete-marked record is found or
+# all records with the same unique fields are iterated.
+--send DELETE FROM t WHERE sk = 100 # trx 2
+
+--connection con1
+SET DEBUG_SYNC="now WAIT_FOR delete_started_waiting";
+DELETE FROM t WHERE sk=100; # trx 0
+COMMIT;
+--disconnect con1
+
+--connection con2
+--reap
+--disconnect con2
+
+--connection con3
+# If the bug is fixed, deadlock error will be there, as trx 2 owns
+# next-key lock waiting for trx 1, and trx 1 requests
+# insert-intention lock, conflicting with trx 2 next-key lock.
+--error ER_LOCK_DEADLOCK
+--reap
+--disconnect con3
+
+--connection default
+# If the bug is not fixed, we will see the row inserted by trx 1 here. This can
+# cause duplicate key error on slave, when some other trx tries in insert row
+# with the same secondary key, as was inserted by trx 1, and not deleted by trx
+# 2.
+SELECT * FROM t;
+
+--disconnect pause_purge
+SET DEBUG_SYNC="RESET";
+DROP TABLE t;
+--source include/wait_until_count_sessions.inc
diff --git a/mysql-test/suite/innodb/t/insert_debug.test b/mysql-test/suite/innodb/t/insert_debug.test
new file mode 100644
index 00000000..c370c402
--- /dev/null
+++ b/mysql-test/suite/innodb/t/insert_debug.test
@@ -0,0 +1,49 @@
+--source include/have_innodb.inc
+--source include/have_debug.inc
+--source include/have_partition.inc
+
+--echo #
+--echo # Bug#19904003 INNODB_LIMIT_OPTIMISTIC_INSERT_DEBUG=1
+--echo # CAUSES INFINITE PAGE SPLIT
+--echo #
+
+SET GLOBAL innodb_change_buffering_debug=1;
+SET GLOBAL innodb_limit_optimistic_insert_debug=1;
+CREATE TABLE t1(c1 INT PRIMARY KEY) ENGINE=InnoDB
+PARTITION BY HASH (c1) PARTITIONS 15;
+DROP TABLE t1;
+
+SET GLOBAL innodb_change_buffering_debug=0;
+SET GLOBAL innodb_limit_optimistic_insert_debug=0;
+
+--echo #
+--echo # Bug#25082593 FOREIGN KEY VALIDATION DOESN'T NEED
+--echo # TO ACQUIRE GAP LOCK IN READ COMMITTED
+--echo #
+
+SET GLOBAL innodb_limit_optimistic_insert_debug=2;
+
+CREATE TABLE t1(col1 INT PRIMARY KEY) ENGINE=INNODB;
+
+CREATE TABLE t2(col1 INT PRIMARY KEY, col2 INT NOT NULL,
+FOREIGN KEY(col2) REFERENCES t1(col1)) ENGINE=INNODB;
+
+INSERT INTO t1 VALUES(1), (3), (4);
+
+connect (con1,localhost,root);
+
+SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED;
+START TRANSACTION;
+INSERT INTO t2 VALUES(1, 3);
+
+connection default;
+START TRANSACTION;
+
+INSERT INTO t1 VALUES(2);
+
+disconnect con1;
+
+SET GLOBAL innodb_limit_optimistic_insert_debug=0;
+
+DROP TABLE t2;
+DROP TABLE t1;
diff --git a/mysql-test/suite/innodb/t/insert_into_empty.opt b/mysql-test/suite/innodb/t/insert_into_empty.opt
new file mode 100644
index 00000000..c856c2d2
--- /dev/null
+++ b/mysql-test/suite/innodb/t/insert_into_empty.opt
@@ -0,0 +1 @@
+--innodb_sort_buffer_size=65536
diff --git a/mysql-test/suite/innodb/t/insert_into_empty.test b/mysql-test/suite/innodb/t/insert_into_empty.test
new file mode 100644
index 00000000..baba5a14
--- /dev/null
+++ b/mysql-test/suite/innodb/t/insert_into_empty.test
@@ -0,0 +1,497 @@
+--source include/have_innodb.inc
+--source include/innodb_page_size.inc
+--source include/have_sequence.inc
+--source include/maybe_debug.inc
+--source include/have_partition.inc
+
+# Enable MDEV-515 table-level undo logging for insert into empty table
+SET foreign_key_checks=0, unique_checks=0;
+
+--echo #
+--echo # MDEV-24715 Assertion !node->table->skip_alter_undo
+--echo #
+CREATE TABLE t (a INT UNIQUE) ENGINE=InnoDB
+REPLACE SELECT 1 AS a, 2 AS b UNION SELECT 1 AS a, 3 AS c;
+SELECT * FROM t;
+DROP TABLE t;
+
+CREATE TEMPORARY TABLE t (a INT UNIQUE) ENGINE=InnoDB
+REPLACE SELECT 1 AS a, 2 AS b UNION SELECT 1 AS a, 3 AS c;
+SELECT * FROM t;
+DROP TEMPORARY TABLE t;
+
+--echo #
+--echo # MDEV-24720 AHI removal during bulk index rollback
+--echo #
+SET @save_ahi = @@global.innodb_adaptive_hash_index;
+SET GLOBAL innodb_adaptive_hash_index = 1;
+CREATE TABLE t1(f1 INT NOT NULL)ENGINE=InnoDB;
+BEGIN;
+INSERT INTO t1 SELECT * FROM seq_1_to_65536;
+ROLLBACK;
+CHECK TABLE t1;
+--echo #
+--echo # MDEV-24832 Root page AHI Removal fails fails during
+--echo # bulk index rollback
+--echo #
+BEGIN;
+INSERT INTO t1 SELECT * FROM seq_1_to_500;
+ROLLBACK;
+DROP TABLE t1;
+SET GLOBAL innodb_adaptive_hash_index = @save_ahi;
+
+--echo #
+--echo # MDEV-24951 Assertion m.first->second.valid(trx->undo_no) failed
+--echo # in trx_undo_report_row_operation
+--echo #
+
+CREATE TEMPORARY TABLE t (c INT) ENGINE=InnoDB;
+CREATE TEMPORARY TABLE t2 (c INT) ENGINE=InnoDB;
+SET tx_read_only=1;
+BEGIN;
+INSERT INTO t2 VALUES(0);
+INSERT INTO t VALUES(0);
+ROLLBACK;
+BEGIN;
+INSERT INTO t2 VALUES(0);
+INSERT INTO t VALUES(0);
+COMMIT;
+INSERT INTO t VALUES(0);
+
+--error ER_CANT_EXECUTE_IN_READ_ONLY_TRANSACTION
+DROP TEMPORARY TABLE t,t2;
+SET tx_read_only=0;
+DROP TEMPORARY TABLE t,t2;
+
+--echo #
+--echo # MDEV-24818 Optimize multiple INSERT into empty table
+--echo #
+
+CREATE TABLE t1(f1 INT PRIMARY KEY) ENGINE=InnoDB;
+BEGIN;
+INSERT INTO t1 VALUES (5),(6),(7);
+--error ER_DUP_ENTRY
+INSERT INTO t1 VALUES (4),(5),(6);
+COMMIT;
+SELECT * FROM t1;
+BEGIN;
+INSERT INTO t1 VALUES (5),(6),(7);
+SAVEPOINT a;
+--error ER_DUP_ENTRY
+INSERT INTO t1 VALUES (4),(5),(6);
+ROLLBACK TO SAVEPOINT a;
+COMMIT;
+SELECT * FROM t1;
+DROP TABLE t1;
+
+# Repeat the same with the MDEV-515 test disabled
+SET foreign_key_checks=1;
+
+CREATE TABLE t1(f1 INT PRIMARY KEY) ENGINE=InnoDB;
+BEGIN;
+INSERT INTO t1 VALUES (5),(6),(7);
+--error ER_DUP_ENTRY
+INSERT INTO t1 VALUES (4),(5),(6);
+COMMIT;
+SELECT * FROM t1;
+BEGIN;
+--error ER_DUP_ENTRY
+INSERT INTO t1 VALUES (5),(6),(7);
+SAVEPOINT a;
+--error ER_DUP_ENTRY
+INSERT INTO t1 VALUES (4),(5),(6);
+ROLLBACK TO SAVEPOINT a;
+COMMIT;
+SELECT * FROM t1;
+DROP TABLE t1;
+
+SET foreign_key_checks=0;
+
+--echo #
+--echo # MDEV-25315 Crash in SHOW ENGINE INNODB STATUS
+--echo #
+
+CREATE TABLE t1 (a INT PRIMARY KEY) ENGINE=InnoDB;
+CREATE TABLE t2 (a INT PRIMARY KEY) ENGINE=InnoDB;
+
+INSERT INTO t1 VALUES(1);
+BEGIN;
+--error ER_DUP_ENTRY
+INSERT INTO t1 VALUES(1);
+INSERT INTO t2 VALUES(0);
+--error ER_DUP_ENTRY
+INSERT INTO t1 VALUES(2), (2);
+--disable_result_log
+SHOW ENGINE InnoDB STATUS;
+--enable_result_log
+COMMIT;
+DROP TABLE t1,t2;
+
+--echo #
+--echo # MDEV-25297 Assertion: trx->roll_limit <= trx->undo_no
+--echo # in ROLLBACK TO SAVEPOINT
+--echo #
+
+CREATE TABLE t1 (c INT PRIMARY KEY) ENGINE=InnoDB;
+CREATE TABLE t2 (c INT PRIMARY KEY) ENGINE=InnoDB;
+BEGIN;
+INSERT INTO t1 VALUES(0);
+SAVEPOINT x;
+INSERT INTO t2 VALUES(0);
+--error ER_DUP_ENTRY
+INSERT INTO t1 VALUES(0);
+--error ER_ERROR_DURING_ROLLBACK
+ROLLBACK TO SAVEPOINT x;
+COMMIT;
+SELECT * FROM t1;
+SELECT * FROM t2;
+DROP TABLE t1,t2;
+
+--echo #
+--echo # MDEV-25487 Assertion failed in lock_rec_move
+--echo #
+
+CREATE TABLE t1 (a INT KEY) ENGINE=InnoDB;
+
+--error 0,1193
+SET @save_limit = @@GLOBAL.innodb_limit_optimistic_insert_debug;
+--error 0,1193
+SET GLOBAL innodb_limit_optimistic_insert_debug = 2;
+
+BEGIN;
+SELECT * FROM t1 LOCK IN SHARE MODE;
+INSERT INTO t1 VALUES (0),(1),(2);
+--error ER_WRONG_VALUE_COUNT_ON_ROW
+INSERT INTO t1 VALUES (0,1);
+--error ER_DUP_ENTRY
+INSERT INTO t1 VALUES (2);
+COMMIT;
+
+--error 0,ER_UNKNOWN_SYSTEM_VARIABLE
+SET GLOBAL innodb_limit_optimistic_insert_debug = @save_limit;
+
+SELECT * FROM t1;
+
+DROP TABLE t1;
+
+--echo #
+--echo # MDEV-25534 Assertion lock_table_has...LOCK_IX
+--echo #
+CREATE TABLE t1 (a INT PRIMARY KEY) ENGINE=InnoDB;
+SET autocommit=0;
+LOCK TABLE t1 WRITE;
+INSERT INTO t1 VALUES (1);
+COMMIT;
+CREATE TEMPORARY TABLE t0 (a INT PRIMARY KEY) ENGINE=InnoDB;
+INSERT INTO t0 VALUES (1);
+INSERT INTO t1 VALUES (2);
+COMMIT;
+SET autocommit=1;
+DROP TABLE t1;
+DROP TEMPORARY TABLE t0;
+
+--echo #
+--echo # MDEV-25496 Assertion 'trx->bulk_insert' failed
+--echo # in trx_undo_report_row_operation on INSERT
+--echo #
+CREATE TABLE t (i INT) ENGINE=InnoDB PARTITION BY HASH (i) PARTITIONS 2;
+INSERT INTO t VALUES (0);
+INSERT INTO t VALUES (1),(0),(1);
+DROP TABLE t;
+
+--echo #
+--echo # MDEV-28327 InnoDB persistent statistics fail to update
+--echo # after bulk insert
+--echo #
+CREATE TABLE t1 (a INT PRIMARY KEY)ENGINE=InnoDB
+STATS_PERSISTENT=1 STATS_AUTO_RECALC=1;
+INSERT INTO t1 SELECT * FROM seq_1_to_4096;
+--echo # Wait till statistics update after bulk insert operation
+let $wait_condition= select n_rows > 100 from mysql.innodb_table_stats
+where table_name="t1";
+source include/wait_condition.inc;
+# At innodb_page_size=4k this will be only 4075, not 4096. Add some slack.
+# This is related to MDEV-24621 and possibly MDEV-26740.
+SELECT n_rows>=4000 FROM mysql.innodb_table_stats WHERE TABLE_NAME="t1";
+DROP TABLE t1;
+
+
+--echo #
+--echo # MDEV-27214 Import with disabled keys corrupts meta-data like rows, indexes, ...
+--echo #
+
+CREATE TABLE `t1` (
+ `id` int(11) NOT NULL,
+ `a` int(11) DEFAULT NULL,
+ PRIMARY KEY (`id`)
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+STATS_PERSISTENT=1 STATS_AUTO_RECALC=1;
+INSERT INTO `t1` VALUES (1,2),(2,3),(3,4);
+--echo # Wait till statistics update after bulk insert operation
+let $wait_condition= select n_rows > 0 from mysql.innodb_table_stats
+where database_name='test' and table_name='t1';
+source include/wait_condition.inc;
+SELECT TABLE_ROWS, AVG_ROW_LENGTH>0 FROM INFORMATION_SCHEMA.TABLES
+WHERE TABLE_NAME='t1' AND TABLE_SCHEMA='test';
+DROP TABLE t1;
+
+--echo #
+--echo # MDEV-29975 InnoDB fails to release savepoint during bulk insert
+--echo #
+CREATE TABLE t (c INT KEY) ENGINE=InnoDB;
+begin;
+--error ER_WRONG_VALUE_COUNT_ON_ROW
+INSERT INTO t VALUES (0,0);
+SAVEPOINT a;
+--error ER_ERROR_DURING_COMMIT
+INSERT INTO t VALUES (0),(0);
+SAVEPOINT a;
+commit;
+SELECT * FROM t;
+DROP TABLE t;
+
+--echo #
+--echo # MDEV-29545 InnoDB: Can't find record during replace stmt
+--echo #
+CREATE TABLE t1(c1 INT PRIMARY KEY)ENGINE=InnoDB;
+BEGIN;
+INSERT INTO t1 VALUES(3331);
+
+connect(con1,localhost,root,,,);
+BEGIN;
+SELECT c1 FROM t1;
+
+connection default;
+COMMIT;
+
+connection con1;
+REPLACE INTO t1 VALUES(1984), (1984);
+COMMIT;
+connection default;
+disconnect con1;
+SELECT * FROM t1;
+DROP TABLE t1;
+--echo # End of 10.6 tests
+
+--echo #
+--echo # MDEV-26947 UNIQUE column checks fail in InnoDB resulting
+--echo # in table corruption
+--echo #
+
+CREATE TABLE t (c1 INT KEY,c2 INT UNIQUE) ENGINE=InnoDB;
+BEGIN;
+--error ER_ERROR_DURING_COMMIT
+INSERT INTO t VALUES (1,0),(2,0);
+CHECK TABLE t;
+COMMIT;
+DROP TABLE t;
+
+CREATE TABLE t (i INT UNIQUE)ENGINE=InnoDB;
+--error ER_ERROR_DURING_COMMIT
+INSERT INTO t VALUES (0),(0);
+CHECK TABLE t;
+DROP TABLE t;
+
+CREATE TABLE t (c INT PRIMARY KEY,c2 CHAR(1) UNIQUE)ENGINE=InnoDB;
+BEGIN;
+--error ER_ERROR_DURING_COMMIT
+INSERT INTO t VALUES(1, ''),(2, '');
+SELECT * FROM t;
+DELETE FROM t;
+COMMIT;
+DROP TABLE t;
+
+--echo #
+--echo # MDEV-26956 LeakSanitizer/Valgrind errors in
+--echo # trx_mod_table_time_t::start_bulk_insert
+--echo # upon adding system versioning
+--echo #
+CREATE TABLE t1(id INT, s DATE, e DATE, PERIOD FOR p(s,e),
+ PRIMARY KEY(id, p WITHOUT OVERLAPS)) ENGINE=InnoDB;
+ALTER TABLE t1 ADD COLUMN row_start BIGINT UNSIGNED AS ROW START,
+ ADD COLUMN row_end BIGINT UNSIGNED AS ROW END,
+ ADD PERIOD FOR SYSTEM_TIME(row_start,row_end), WITH SYSTEM VERSIONING;
+DROP TABLE t1;
+
+--echo #
+--echo # MDEV-27316 Assertion `!(index)->is_spatial()' failed.
+--echo #
+CREATE TABLE t (c POINT NOT NULL, SPATIAL INDEX(c)) ENGINE=InnoDB;
+INSERT INTO t VALUES (POINT(1, 1));
+SELECT COUNT(*) FROM t WHERE MBRWithin(t.c, POINT(1,1));
+DROP TABLE t;
+
+--echo #
+--echo # MDEV-27318 Assertion data_size < srv_sort_buf_size failed in row_merge_bulk_buf_add
+--echo #
+CREATE TABLE t1(f1 MEDIUMTEXT)ENGINE=InnoDB;
+INSERT INTO t1 VALUES(REPEAT(1, 8459264));
+SELECT length(f1) FROM t1;
+DROP TABLE t1;
+
+--echo #
+--echo # MDEV-27858 Assertion `page_dir_get_n_heap(new_page) == 2U' failed in PageBulk::init
+--echo #
+CREATE TABLE t1 (c INT) ENGINE=InnoDB;
+CREATE TABLE t2 (c INT) ENGINE=InnoDB;
+INSERT INTO t2 VALUES (1);
+LOCK TABLES t1 WRITE,t2 WRITE;
+INSERT INTO t1 VALUES (1);
+INSERT INTO t2 VALUES (1);
+DROP TABLE t2, t1;
+
+--echo #
+--echo # MDEV-28138 MariaDB Assertion Failed in mtr_buf_t::has_space
+--echo #
+CREATE TABLE t1(
+ f1 SERIAL,
+ f2 LINESTRING NOT NULL DEFAULT LineFromText('LINESTRING(1 1,2 2,3 3)'),
+SPATIAL INDEX(f2))ENGINE=InnoDB;
+--error ER_DUP_ENTRY
+INSERT INTO t1(f1) VALUES(0), (1), (2);
+DROP TABLE t1;
+
+--echo #
+--echo # MDEV-28237 Assertion `0' failed in row_upd_sec_index_entry on DELETE
+--echo #
+CREATE TABLE t1 (c0 YEAR UNIQUE) ENGINE=InnoDB;
+--error ER_ERROR_DURING_COMMIT
+INSERT INTO t1 VALUES (0),(0),(0),(0),(0),(0),(0);
+DELETE FROM t1;
+DROP TABLE t1;
+
+--echo #
+--echo # MDEV-28037 Assertion `trx->bulk_insert' failed in innodb_prepare_commit_versioned
+--echo #
+CREATE TABLE t1 (c INT) ENGINE=InnoDB;
+CREATE TABLE t2 (c INT) ENGINE=InnoDB;
+CREATE TRIGGER tr AFTER INSERT ON t1 FOR EACH ROW UPDATE t2 SET c=1;
+INSERT INTO t1 VALUES (0);
+SELECT * FROM t1;
+SELECT * FROM t2;
+DROP TABLE t2, t1;
+
+--echo #
+--echo # MDEV-28242 Assertion `!check_foreigns' failed in
+--echo # trx_t::check_bulk_buffer
+--echo #
+CREATE TABLE t1 (c INT)ENGINE=InnoDB;
+BEGIN;
+INSERT INTO t1 VALUES(1), (1);
+SET SESSION foreign_key_checks=TRUE;
+SHOW CREATE TABLE t1;
+CREATE TABLE t2(d INT)ENGINE=InnoDB;
+DROP TABLE t2, t1;
+
+--echo #
+--echo # MDEV-28400 Leak in trx_mod_time_t::start_bulk_insert
+--echo #
+
+SET SESSION foreign_key_checks=0;
+CREATE TABLE t1 (a INT) ENGINE=InnoDB PARTITION BY HASH(a) PARTITIONS 2;
+INSERT INTO t1 VALUES (1),(2);
+ALTER TABLE t1 REBUILD PARTITION p0;
+# Cleanup
+DROP TABLE t1;
+
+--echo #
+--echo # MDEV-29570 InnoDB fails to clean bulk buffer when server
+--echo # does rollback operation
+--echo #
+CREATE TABLE t1 (pk INT PRIMARY KEY) ENGINE=InnoDB
+ PARTITION BY RANGE (pk) (
+ PARTITION pn VALUES LESS THAN (20));
+--error ER_NO_PARTITION_FOR_GIVEN_VALUE
+INSERT INTO t1 VALUES (1),(21);
+# Cleanup
+DROP TABLE t1;
+
+--echo #
+--echo # MDEV-29761 Bulk insert fails to rollback
+--echo # during insert..select
+--echo #
+CREATE TABLE t1 (f1 INT)ENGINE=InnoDB;
+CREATE TABLE t2 (f1 INT, UNIQUE INDEX(f1)) ENGINE=InnoDB;
+CREATE TRIGGER tr AFTER INSERT ON t1 FOR EACH ROW INSERT INTO t2 VALUES(1);
+BEGIN;
+INSERT t1 SELECT 1 FROM seq_1_to_2;
+COMMIT;
+SELECT * FROM t1;
+SELECT * FROM t2;
+CHECK TABLE t1;
+CHECK TABLE t2;
+DROP TABLE t1, t2;
+
+--echo #
+--echo # MDEV-29801 Inconsistent ER_TOO_BIG_ROWSIZE during bulk
+--echo # insert operation
+--echo #
+call mtr.add_suppression("InnoDB: Cannot add field `(c0[36]|c11)` in table");
+
+SET @format= @@innodb_default_row_format;
+CREATE TABLE t1 (pk int primary key, c01 text, c02 text, c03 text,
+ c04 text, c05 text, c06 text, c07 text, c08 text,
+ c09 text, c10 text, c11 text, c12 text) ENGINE=InnoDB;
+SET GLOBAL INNODB_DEFAULT_ROW_FORMAT= COMPACT;
+--replace_result 1982 8126 4030 8126
+ALTER TABLE t1 FORCE;
+let $page_size= `SELECT @@innodb_page_size`;
+let $error_code = 0;
+
+if ($page_size == 4096) {
+ let $error_code = ER_TOO_BIG_ROWSIZE;
+}
+
+--error $error_code
+INSERT IGNORE INTO t1 VALUES
+(1, REPEAT('x',4805), REPEAT('t',2211), REPEAT('u',974), REPEAT('e',871), REPEAT('z',224), REPEAT('j',978), REPEAT('n',190), REPEAT('t',888), REPEAT('x',32768), REPEAT('e',968), REPEAT('b',913), REPEAT('x',12107)),
+(2, REPEAT('x',4805), REPEAT('t',2211), REPEAT('u',974), REPEAT('e',871), REPEAT('z',224), REPEAT('j',978), REPEAT('n',190), REPEAT('t',888), REPEAT('x',32768), REPEAT('e',968), REPEAT('b',913), REPEAT('x',12107));
+CHECK TABLE t1;
+DROP TABLE t1;
+SET GLOBAL INNODB_DEFAULT_ROW_FORMAT= @format;
+
+--echo #
+--echo # MDEV-30321 blob data corrupted by row_merge_write_blob_to_tmp_file()
+--echo #
+
+CREATE TABLE t1 (
+ `id` int(11) NOT NULL,
+ `data` LONGBLOB NOT NULL,
+ PRIMARY KEY (`id`)
+) ENGINE=InnoDB;
+
+INSERT INTO t1 VALUES
+ (1, REPEAT('X', @@innodb_sort_buffer_size)),
+ (2, REPEAT('X', @@innodb_sort_buffer_size));
+
+SELECT COUNT(*) AS nb_corrupted_rows FROM t1 WHERE data != REPEAT('X', @@innodb_sort_buffer_size);
+DROP TABLE t1;
+
+--echo # End of 10.7 tests
+
+--echo #
+--echo # MDEV-30426 Assertion !rec_offs_nth_extern(offsets2, n)
+--echo # during bulk insert
+--echo #
+CREATE TABLE t1(f1 TEXT NOT NULL, f2 TEXT NOT NULL,
+ f3 TEXT NOT NULL, f4 TEXT NOT NULL,
+ f5 TEXT NOT NULL, f6 TEXT NOT NULL,
+ PRIMARY KEY(f6(10)))ENGINE=InnoDB;
+BEGIN;
+--error ER_ERROR_DURING_COMMIT
+INSERT INTO t1 VALUES
+ (repeat('a', 200), repeat('b', 200), repeat('c', 200),
+ repeat('d', 200), repeat('e', 200), repeat('f', 200)),
+ (repeat('b', 20000), repeat('c', 16000), repeat('d', 12000),
+ repeat('e', 12000), repeat('f', 12000), repeat('f', 12000));
+COMMIT;
+DROP TABLE t1;
+--echo # End of 10.8 tests
+
+--echo #
+--echo # MDEV-31537 Bulk insert operation aborts the server
+--echo # for redundant table
+--echo #
+CREATE TABLE t (a CHAR CHARACTER SET utf8) ENGINE=InnoDB ROW_FORMAT=REDUNDANT;
+INSERT t SELECT left(seq,1) FROM seq_1_to_43691;
+DROP TABLE t;
diff --git a/mysql-test/suite/innodb/t/insert_into_empty_debug.test b/mysql-test/suite/innodb/t/insert_into_empty_debug.test
new file mode 100644
index 00000000..4d2b99bd
--- /dev/null
+++ b/mysql-test/suite/innodb/t/insert_into_empty_debug.test
@@ -0,0 +1,36 @@
+--source include/have_innodb.inc
+--source include/have_debug.inc
+--source include/have_debug_sync.inc
+
+# Encounter aborted online index during rollback of bulk insert
+
+CREATE TABLE t1(f1 INT NOT NULL, f2 INT NOT NULL,
+ PRIMARY KEY(f1))ENGINE=InnoDB;
+INSERT INTO t1 VALUES(1, 2), (2, 2);
+
+SET DEBUG_SYNC="innodb_rollback_inplace_alter_table SIGNAL dml_start WAIT_FOR dml_commit";
+send ALTER TABLE t1 ADD UNIQUE KEY(f2);
+
+connect(con1,localhost,root,,,);
+SET DEBUG_SYNC="now WAIT_FOR dml_start";
+BEGIN;
+DELETE FROM t1;
+SET DEBUG_SYNC="now SIGNAL dml_commit";
+
+connection default;
+--error ER_DUP_ENTRY
+reap;
+connection con1;
+COMMIT;
+TRUNCATE TABLE t1;
+SET unique_checks=0, foreign_key_checks=0;
+BEGIN;
+INSERT INTO t1 VALUES(1, 2);
+ROLLBACK;
+
+connection default;
+SELECT * FROM t1;
+SHOW CREATE TABLE t1;
+disconnect con1;
+DROP TABLE t1;
+SET DEBUG_SYNC=RESET;
diff --git a/mysql-test/suite/innodb/t/insert_into_empty_notembedded.test b/mysql-test/suite/innodb/t/insert_into_empty_notembedded.test
new file mode 100644
index 00000000..078ca020
--- /dev/null
+++ b/mysql-test/suite/innodb/t/insert_into_empty_notembedded.test
@@ -0,0 +1,60 @@
+--source include/not_embedded.inc
+--source include/have_innodb.inc
+--source include/innodb_page_size.inc
+--source include/maybe_debug.inc
+
+--echo #
+--echo # Start of 10.6 tests
+--echo #
+
+--echo #
+--echo # MDEV-27214 Import with disabled keys corrupts meta-data like rows, indexes, ...
+--echo #
+
+CREATE DATABASE db1;
+CREATE TABLE db1.t1 (id int, a int,PRIMARY KEY (id)) ENGINE=InnoDB
+STATS_PERSISTENT=1 STATS_AUTO_RECALC=1;
+INSERT INTO db1.t1 VALUES (1,2),(2,3),(3,4);
+--let $file = $MYSQLTEST_VARDIR/tmp/dump.sql
+--exec $MYSQL_DUMP db1 t1 >$file
+DROP DATABASE IF EXISTS db1;
+
+CREATE DATABASE db1;
+--exec $MYSQL db1 < $file
+--remove_file $file
+--echo # Wait till statistics update after bulk insert operation
+let $wait_condition= select n_rows > 0 from mysql.innodb_table_stats
+where database_name='db1' and table_name='t1';
+source include/wait_condition.inc;
+SELECT TABLE_ROWS, AVG_ROW_LENGTH>0 FROM INFORMATION_SCHEMA.TABLES
+WHERE TABLE_NAME='t1' AND TABLE_SCHEMA='db1';
+
+OPTIMIZE TABLE db1.t1;
+--echo # Wait till statistics update after bulk insert operation
+let $wait_condition= select n_rows > 0 from mysql.innodb_table_stats
+where database_name='db1' and table_name='t1';
+source include/wait_condition.inc;
+SELECT TABLE_ROWS, AVG_ROW_LENGTH>0 FROM INFORMATION_SCHEMA.TABLES
+WHERE TABLE_NAME='t1' AND TABLE_SCHEMA='db1';
+DROP DATABASE db1;
+
+--echo #
+--echo # End of 10.6 tests
+--echo #
+
+SET foreign_key_checks=0, unique_checks=0;
+--echo #
+--echo # MDEV-30796 Auto_increment values not updated after bulk
+--echo # insert operation
+--echo #
+CREATE TABLE t1(f1 INT NOT NULL AUTO_INCREMENT,
+ f2 INT NOT NULL, PRIMARY KEY(f1))ENGINE=InnoDB;
+INSERT INTO t1 VALUES(1, 2), (25, 3), (2, 4);
+SHOW CREATE TABLE t1;
+--source include/restart_mysqld.inc
+SHOW CREATE TABLE t1;
+INSERT INTO t1(f2) VALUES(5);
+SELECT max(f1) FROM t1;
+DROP TABLE t1;
+
+--echo # End of 10.9 tests
diff --git a/mysql-test/suite/innodb/t/instant_alter.opt b/mysql-test/suite/innodb/t/instant_alter.opt
new file mode 100644
index 00000000..1f0d2d43
--- /dev/null
+++ b/mysql-test/suite/innodb/t/instant_alter.opt
@@ -0,0 +1 @@
+--innodb-sys-tablestats --skip-innodb-stats-persistent
diff --git a/mysql-test/suite/innodb/t/instant_alter.test b/mysql-test/suite/innodb/t/instant_alter.test
new file mode 100644
index 00000000..5b6d3f87
--- /dev/null
+++ b/mysql-test/suite/innodb/t/instant_alter.test
@@ -0,0 +1,966 @@
+--source include/innodb_page_size.inc
+--source include/have_sequence.inc
+
+let $datadir=`select @@datadir`;
+
+--echo #
+--echo # MDEV-11369: Instant ADD COLUMN for InnoDB
+--echo #
+
+SET @saved_allowance = @@GLOBAL.innodb_instant_alter_column_allowed;
+SET GLOBAL innodb_instant_alter_column_allowed = DEFAULT;
+
+call mtr.add_suppression("Cannot add field `.*` in table `test`.`.*` because after adding it, the row size is");
+
+let $format= `SELECT CASE WHEN @@GLOBAL.innodb_page_size>16384
+THEN 'DYNAMIC' ELSE 'COMPRESSED' END`;
+CREATE TABLE t(a INT UNIQUE)ENGINE=InnoDB ROW_FORMAT=COMPACT;
+eval ALTER TABLE t ADD e INT, ROW_FORMAT=$format;
+INSERT INTO t SET a=1;
+SET @old_instant=
+(SELECT variable_value FROM information_schema.global_status
+WHERE variable_name = 'innodb_instant_alter_column');
+--enable_info
+ALTER TABLE t ADD b INT NOT NULL, ALGORITHM=COPY;
+ALTER TABLE t ADD c INT NOT NULL, FORCE;
+--disable_info
+SELECT variable_value-@old_instant instants
+FROM information_schema.global_status
+WHERE variable_name = 'innodb_instant_alter_column';
+--enable_info
+ALTER TABLE t ADD d INT NOT NULL;
+--disable_info
+SELECT * FROM t;
+SHOW CREATE TABLE t;
+SELECT variable_value-@old_instant instants
+FROM information_schema.global_status
+WHERE variable_name = 'innodb_instant_alter_column';
+SELECT variable_value-@old_instant instants
+FROM information_schema.global_status
+WHERE variable_name = 'innodb_instant_alter_column';
+DROP TABLE t;
+
+connect analyze, localhost, root;
+connection default;
+SET timestamp = 42;
+SET time_zone='+03:00';
+
+SET @old_instant=
+(SELECT variable_value FROM information_schema.global_status
+WHERE variable_name = 'innodb_instant_alter_column');
+
+let $format= 3;
+let $redundant_4k= `SELECT @@GLOBAL.innodb_page_size=4096`;
+while ($format) {
+let $engine= `SELECT CONCAT('ENGINE=InnoDB ROW_FORMAT=',CASE $format
+WHEN 1 THEN 'DYNAMIC'
+WHEN 2 THEN 'COMPACT'
+ELSE 'REDUNDANT' END)`;
+
+eval CREATE TABLE t1
+(id INT PRIMARY KEY, c2 INT UNIQUE,
+ c3 POINT NOT NULL DEFAULT ST_GeomFromText('POINT(3 4)'),
+ SPATIAL INDEX(c3)) $engine;
+
+INSERT INTO t1 (id, c2) values(1,1);
+SELECT id,c2,ST_AsText(c3) c3 FROM t1;
+
+--enable_info
+ALTER TABLE t1 ADD COLUMN (
+ d1 INT, d2 INT UNSIGNED DEFAULT 10, d3 VARCHAR(20) NOT NULL DEFAULT 'abcde',
+ d4 TIMESTAMP NOT NULL DEFAULT current_timestamp());
+ALTER TABLE t1 ADD INDEX(d3);
+--disable_info
+
+BEGIN;
+UPDATE t1 SET d3='';
+ROLLBACK;
+SELECT id,c2,ST_AsText(c3) c3, d1, d2, d3, d4 FROM t1;
+INSERT INTO t1 (id) VALUES(2),(3),(4),(5),(6);
+
+--enable_info
+ALTER TABLE t1 CHANGE d1 d1 INT DEFAULT 5, CHANGE d2 d2 INT DEFAULT 15,
+CHANGE d3 d3 VARCHAR(20) NOT NULL DEFAULT 'fghij',
+CHANGE d4 dfour TIMESTAMP NOT NULL DEFAULT now();
+--disable_info
+
+UPDATE t1 SET d3='foo' WHERE id = 2;
+UPDATE t1 SET d3=DEFAULT WHERE id = 4;
+INSERT INTO t1 SET id = 7;
+SELECT id,c2,ST_AsText(c3) c3, d1, d2, d3, dfour FROM t1;
+CHECK TABLE t1;
+
+# add virtual columns
+--enable_info
+ALTER TABLE t1 ADD COLUMN e1 INT AS (id * 3);
+ALTER TABLE t1 ADD COLUMN e2 VARCHAR(30) AS (d3);
+ALTER TABLE t1 ADD COLUMN e3 INT AS (id * 2);
+
+# instant alter
+ALTER TABLE t1 CHANGE d3 d3 VARCHAR(20) NOT NULL DEFAULT 'foobar',
+ADD COLUMN (d5 CHAR(20) DEFAULT 'hijkl', d6 INT DEFAULT -12345, d7 INT),
+DROP INDEX d3;
+--disable_info
+
+INSERT INTO t1 SET id = 8;
+
+# Updating a column by extending an existing record
+UPDATE t1 SET d3 = 'yyyyy' WHERE id = 1;
+
+# Updating an already materialized column
+UPDATE t1 SET d3 = 'xxxxx' WHERE id = 2;
+
+# transaction rollback
+BEGIN;
+UPDATE t1 SET d3 = 'xxxxx' WHERE id = 3;
+SELECT id, c2, ST_AsText(c3) c3, d1, d2, d3, dfour, e1, e2, e3, d5, d6, d7 FROM t1 WHERE id = 3;
+ROLLBACK;
+SELECT id, c2, ST_AsText(c3) c3, d1, d2, d3, dfour, e1, e2, e3, d5, d6, d7 FROM t1 WHERE id = 3;
+
+# NULL to NULL, no change
+BEGIN;
+UPDATE t1 SET d7 = NULL WHERE ID = 5;
+ROLLBACK;
+BEGIN;
+UPDATE t1 SET d7 = NULL, d6 = 10 WHERE id = 5;
+SELECT id, c2, ST_AsText(c3) c3, d1, d2, d3, dfour, e1, e2, e3, d5, d6, d7 FROM t1 WHERE id = 5;
+ROLLBACK;
+SELECT id, c2, ST_AsText(c3) c3, d1, d2, d3, dfour, e1, e2, e3, d5, d6, d7 FROM t1 WHERE id = 5;
+
+# add virtual stored columns; not instant
+--enable_info
+ALTER TABLE t1 ADD COLUMN (f1 VARCHAR(20) AS (concat('x', e2)) STORED);
+
+# instant add
+ALTER TABLE t1 ADD COLUMN (d8 VARCHAR(20) DEFAULT 'omnopq');
+--disable_info
+
+SELECT id, c2, ST_AsText(c3) c3, d1, d2, d3, dfour, e1, e2, e3, d5, d6, d7, f1, d8 FROM t1;
+SHOW CREATE TABLE t1;
+
+--enable_info
+ALTER TABLE t1
+CHANGE c2 c2 INT DEFAULT 42,
+CHANGE d1 d1 INT DEFAULT 1,
+CHANGE d2 d2 INT DEFAULT 20,
+CHANGE d3 d3 VARCHAR(20) NOT NULL DEFAULT 'boofar';
+--disable_info
+INSERT INTO t1 SET id=9;
+--enable_info
+ALTER TABLE t1 DROP c3;
+--disable_info
+
+SHOW CREATE TABLE t1;
+SELECT * FROM t1;
+
+eval CREATE TABLE t2
+(id INT primary key, c1 VARCHAR(4000),
+ p GEOMETRY NOT NULL DEFAULT ST_GeomFromText('LINESTRING(0 0,0 1,1 1)'),
+ SPATIAL INDEX(p))
+$engine;
+
+BEGIN;
+INSERT INTO t2 SET id=1, c1=REPEAT('a', 4000);
+INSERT INTO t2 SET id=2, c1=REPEAT('a', 4000), p=ST_GeomFromText('POINT(1 1)');
+COMMIT;
+
+--enable_info
+ALTER TABLE t2 ADD COLUMN d1 VARCHAR(2000) DEFAULT REPEAT('asdf',500);
+--disable_info
+SELECT id, c1, ST_AsText(p) p, d1 FROM t2;
+
+# inplace update, rollback
+BEGIN;
+UPDATE t2 SET c1 = repeat(id, 4000);
+
+connection analyze;
+ANALYZE TABLE t2;
+SELECT clust_index_size FROM INFORMATION_SCHEMA.INNODB_SYS_TABLESTATS
+WHERE name = 'test/t2';
+connection default;
+
+ROLLBACK;
+connection analyze;
+ANALYZE TABLE t2;
+SELECT clust_index_size FROM INFORMATION_SCHEMA.INNODB_SYS_TABLESTATS
+WHERE name = 'test/t2';
+connection default;
+
+# non-inplace update. Rollback MUST NOT materialize off-page columns.
+BEGIN;
+UPDATE t2 SET d1 = repeat(id, 200);
+connection analyze;
+ANALYZE TABLE t2;
+SELECT clust_index_size FROM INFORMATION_SCHEMA.INNODB_SYS_TABLESTATS
+WHERE name = 'test/t2';
+connection default;
+ROLLBACK;
+connection analyze;
+ANALYZE TABLE t2;
+SELECT clust_index_size FROM INFORMATION_SCHEMA.INNODB_SYS_TABLESTATS
+WHERE name = 'test/t2';
+connection default;
+
+if ($redundant_4k)
+{
+--error ER_TOO_BIG_ROWSIZE
+ALTER TABLE t2 DROP p;
+SET innodb_strict_mode = OFF;
+}
+--enable_info
+ALTER TABLE t2 DROP p;
+--disable_info
+if ($redundant_4k)
+{
+SET innodb_strict_mode = ON;
+}
+SELECT * FROM t2;
+
+# datetime
+eval CREATE TABLE t3
+(id INT PRIMARY KEY, c2 INT UNSIGNED NOT NULL UNIQUE,
+ c3 POLYGON NOT NULL DEFAULT ST_PolyFromText('POLYGON((1 1,2 2,3 3,1 1))'),
+ SPATIAL INDEX(c3))
+$engine;
+INSERT INTO t3(id,c2) VALUES(1,1),(2,2),(3,3);
+SELECT id, c2, ST_AsText(c3) c3 FROM t3;
+--enable_info
+ALTER TABLE t3 ADD COLUMN
+(c4 DATETIME DEFAULT current_timestamp(),
+ c5 TIMESTAMP NOT NULL DEFAULT current_timestamp(),
+ c6 POINT);
+SELECT id, c2, ST_AsText(c3) c3, c4, c5, c6 FROM t3;
+ALTER TABLE t3 ADD COLUMN c7 TIME NOT NULL DEFAULT current_timestamp();
+ALTER TABLE t3 ADD COLUMN c8 DATE NOT NULL DEFAULT current_timestamp();
+--disable_info
+SELECT id, c2, ST_AsText(c3) c3, c4, c5, c6, c7, c8 FROM t3;
+
+--enable_info
+ALTER TABLE t3 ADD COLUMN t TEXT CHARSET utf8
+DEFAULT 'The quick brown fox jumps over the lazy dog';
+
+if ($redundant_4k)
+{
+--error ER_TOO_BIG_ROWSIZE
+ALTER TABLE t3 ADD COLUMN b BLOB NOT NULL;
+SET innodb_strict_mode = OFF;
+}
+ALTER TABLE t3 ADD COLUMN b BLOB NOT NULL;
+--error ER_NO_DEFAULT_FOR_FIELD
+INSERT INTO t3 SET id=4;
+INSERT INTO t3 SET id=4, c2=0, b=0xf09f98b1;
+
+SET innodb_strict_mode = OFF;
+ALTER TABLE t3 CHANGE t phrase TEXT DEFAULT 0xc3a4c3a448,
+CHANGE b b BLOB NOT NULL DEFAULT 'binary line of business';
+--disable_info
+INSERT INTO t3 SET id=5, c2=9;
+SELECT id, c2, ST_AsText(c3) c3, c4, c5, c6, c7, c8, phrase, b FROM t3;
+--enable_info
+ALTER TABLE t3 DROP c3, DROP c7;
+--disable_info
+SELECT * FROM t3;
+
+eval CREATE TABLE t4
+(id INT, foo INT DEFAULT 0, c1 VARCHAR(4000),
+ p GEOMETRY NOT NULL DEFAULT ST_GeomFromText('LINESTRING(0 0,0 1,1 1)'),
+ PRIMARY KEY(id,foo))
+$engine;
+
+INSERT INTO t4 (id,c1) VALUES (1, REPEAT('a', 4000)), (2, REPEAT('a', 4000));
+ALTER TABLE t4 ADD COLUMN d1 INT;
+
+BEGIN;
+UPDATE t4 SET c1 = repeat('1', 4000), foo=1 WHERE id=1;
+INSERT INTO t4 (id,c1) VALUES (1, REPEAT('a', 4000));
+UPDATE t4 SET c1 = repeat('2', 4000), foo=1 WHERE id=2;
+ROLLBACK;
+
+BEGIN;
+UPDATE t4 SET d1 = 1,foo=2 WHERE id=1;
+INSERT INTO t4 (id,foo,c1) VALUES (1, 1, REPEAT('1', 4000));
+COMMIT;
+
+eval CREATE TABLE big
+(id INT PRIMARY KEY, c1 VARCHAR(4000), c2 VARCHAR(4000), c3 VARCHAR(1000),
+ p POINT NOT NULL DEFAULT ST_GeomFromText('POINT(0 0)'), SPATIAL INDEX(p))
+$engine;
+BEGIN;
+INSERT INTO big
+SET id=1, c1=REPEAT('a', 200), c2=REPEAT('b', 200), c3=REPEAT('c', 159);
+SET @i:=1;
+INSERT INTO big SELECT @i:=@i+1, c1, c2, c3, p FROM big;
+INSERT INTO big SELECT @i:=@i+1, c1, c2, c3, p FROM big;
+INSERT INTO big SELECT @i:=@i+1, c1, c2, c3, p FROM big;
+INSERT INTO big SELECT @i:=@i+1, c1, c2, c3, p FROM big;
+INSERT INTO big SELECT @i:=@i+1, c1, c2, c3, p FROM big;
+COMMIT;
+connection analyze;
+ANALYZE TABLE big;
+SELECT clust_index_size FROM INFORMATION_SCHEMA.INNODB_SYS_TABLESTATS
+WHERE name = 'test/big';
+connection default;
+--enable_info
+ALTER TABLE big ADD COLUMN
+(d1 INT DEFAULT 0, d2 VARCHAR(20) DEFAULT 'abcde',
+ d3 TIMESTAMP NOT NULL DEFAULT current_timestamp ON UPDATE current_timestamp);
+--disable_info
+CHECKSUM TABLE big;
+BEGIN;
+INSERT INTO big(id, c1, c2, c3) SELECT @i:=@i+1, c1, c2, c3 FROM big;
+INSERT INTO big(id, c1, c2, c3) SELECT @i:=@i+1, c1, c2, c3 FROM big;
+CHECKSUM TABLE big;
+connection analyze;
+ANALYZE TABLE big;
+SELECT clust_index_size FROM INFORMATION_SCHEMA.INNODB_SYS_TABLESTATS
+WHERE name = 'test/big';
+connection default;
+ROLLBACK;
+CHECKSUM TABLE big;
+connection analyze;
+ANALYZE TABLE big;
+SELECT clust_index_size FROM INFORMATION_SCHEMA.INNODB_SYS_TABLESTATS
+WHERE name = 'test/big';
+connection default;
+
+--source include/wait_all_purged.inc
+DROP TABLE t1,t2,t3,t4,big;
+
+# MDEV-14837 Duplicate primary keys are allowed after ADD COLUMN / UPDATE
+eval CREATE TABLE t1 (a VARCHAR(1) PRIMARY KEY) $engine;
+INSERT INTO t1 SET a='a';
+ALTER TABLE t1 ADD COLUMN b INT NOT NULL DEFAULT 0;
+UPDATE t1 SET b = 1;
+--error ER_DUP_ENTRY
+INSERT INTO t1 SET a='a';
+SELECT * FROM t1;
+DROP TABLE t1;
+
+# MDEV-16065 Assertion failed in btr_pcur_restore_position_func on UPDATE
+eval CREATE TABLE t1 (a INT, b VARCHAR(8), PRIMARY KEY(b,a)) $engine;
+INSERT INTO t1 VALUES (1,'foo');
+ALTER TABLE t1 ADD COLUMN c INT;
+UPDATE t1 SET c = 1;
+UPDATE t1 SET c = 2;
+DROP TABLE t1;
+
+# MDEV-16830 Crash in ALTER TABLE DROP FOREIGN KEY
+eval CREATE TABLE t1 (a INT PRIMARY KEY) $engine;
+eval CREATE TABLE t2 (b INT PRIMARY KEY, FOREIGN KEY(b) REFERENCES t1(a))
+$engine;
+INSERT INTO t1 SET a=1;
+INSERT INTO t2 SET b=1;
+ALTER TABLE t2 ADD COLUMN a INT, DROP FOREIGN KEY t2_ibfk_1;
+ALTER TABLE t2 ADD INDEX(a);
+--error ER_ALTER_OPERATION_NOT_SUPPORTED_REASON
+ALTER TABLE t1 ADD COLUMN b INT, ADD FOREIGN KEY(a) REFERENCES t2(a),
+ALGORITHM=INSTANT;
+SET foreign_key_checks=0;
+ALTER TABLE t1 ADD COLUMN b INT, ADD FOREIGN KEY(a) REFERENCES t2(a),
+ALGORITHM=INSTANT;
+ALTER TABLE t2 ADD CONSTRAINT fk FOREIGN KEY(b) REFERENCES t1(a),
+ALGORITHM=INSTANT;
+SET foreign_key_checks=1;
+ALTER TABLE t2 COMMENT 'domestic keys only', DROP FOREIGN KEY fk;
+ALTER TABLE t1 DROP FOREIGN KEY t1_ibfk_1;
+ALTER TABLE t1 ADD COLUMN big BLOB NOT NULL
+DEFAULT REPEAT('a', @@GLOBAL.innodb_page_size * .75);
+CHECK TABLE t2, t1;
+DROP TABLE t2, t1;
+
+#
+# MDEV-17483 Insert on delete-marked record can wrongly inherit old values
+# for instantly added column
+#
+
+eval CREATE TABLE t1 (a INT PRIMARY KEY) $engine;
+INSERT INTO t1 SET a = 1;
+ALTER TABLE t1 ADD COLUMN b TEXT;
+BEGIN;
+UPDATE t1 SET b = REPEAT('1', 32768);
+UPDATE t1 SET a = 2;
+INSERT INTO t1 SET a = 1;
+SELECT a,LENGTH(b) FROM t1;
+DELETE FROM t1;
+COMMIT;
+--source include/wait_all_purged.inc
+DROP TABLE t1;
+
+#
+# MDEV-20066 Wrong value on instantly added column after DELETE and UPDATE
+#
+
+eval CREATE TABLE t1(a INT PRIMARY KEY) $engine;
+INSERT INTO t1 VALUES (7);
+
+ALTER TABLE t1 ADD COLUMN c INT NOT NULL DEFAULT 0;
+ALTER TABLE t1 ADD INDEX (c);
+
+BEGIN;
+DELETE FROM t1;
+INSERT INTO t1 VALUES (4,0),(7,77);
+COMMIT;
+BEGIN;
+DELETE FROM t1 WHERE a=7;
+UPDATE t1 SET a=7;
+COMMIT;
+SELECT * FROM t1 FORCE INDEX(PRIMARY);
+SELECT * FROM t1 FORCE INDEX(c);
+DELETE FROM t1;
+CHECK TABLE t1;
+DROP TABLE t1;
+
+# MDEV-21172 Memory leak during ADD PRIMARY KEY
+
+SET innodb_strict_mode = ON;
+eval CREATE TABLE t1 (a INT, b VARCHAR(500), c TEXT, UNIQUE(a,b)) $engine;
+ALTER TABLE t1 ADD d TEXT;
+--error 0,ER_TOO_BIG_ROWSIZE
+ALTER TABLE t1 ADD PRIMARY KEY (b,a);
+# Exploit MDEV-17468 to force the table definition to be reloaded
+ALTER TABLE t1 ADD va INT AS (a) VIRTUAL;
+DROP TABLE t1;
+SET innodb_strict_mode = OFF;
+
+# MDEV-20950 innodb_instant_alter_column_allowed
+eval CREATE TABLE t1 (a INT PRIMARY KEY) $engine;
+INSERT INTO t1 SET a=42;
+SET GLOBAL innodb_instant_alter_column_allowed = never;
+--error ER_ALTER_OPERATION_NOT_SUPPORTED_REASON
+ALTER TABLE t1 ADD b TEXT, ALGORITHM=INSTANT;
+SET GLOBAL innodb_instant_alter_column_allowed = add_last;
+ALTER TABLE t1 ADD b TEXT, ALGORITHM=INSTANT;
+SET GLOBAL innodb_instant_alter_column_allowed = never;
+--error ER_ALTER_OPERATION_NOT_SUPPORTED_REASON
+ALTER TABLE t1 MODIFY a INT DEFAULT 1, ALGORITHM=INSTANT;
+--enable_info
+ALTER TABLE t1 MODIFY a INT DEFAULT 0;
+--disable_info
+ALTER TABLE t1 MODIFY a INT DEFAULT NULL, ALGORITHM=INSTANT;
+--error ER_ALTER_OPERATION_NOT_SUPPORTED_REASON
+ALTER TABLE t1 DROP b, ALGORITHM=INSTANT;
+--error ER_ALTER_OPERATION_NOT_SUPPORTED_REASON
+ALTER TABLE t1 MODIFY b TEXT FIRST, ALGORITHM=INSTANT;
+SET GLOBAL innodb_instant_alter_column_allowed = add_last;
+--error ER_ALTER_OPERATION_NOT_SUPPORTED_REASON
+ALTER TABLE t1 MODIFY b TEXT FIRST, ALGORITHM=INSTANT;
+--error ER_ALTER_OPERATION_NOT_SUPPORTED_REASON
+ALTER TABLE t1 ADD d TEXT AFTER a, ALGORITHM=INSTANT;
+SET GLOBAL innodb_instant_alter_column_allowed = add_drop_reorder;
+ALTER TABLE t1 MODIFY b TEXT FIRST, ALGORITHM=INSTANT;
+SET GLOBAL innodb_instant_alter_column_allowed = add_last;
+--error ER_ALTER_OPERATION_NOT_SUPPORTED_REASON
+ALTER TABLE t1 MODIFY a INT DEFAULT 1, ALGORITHM=INSTANT;
+--error ER_ALTER_OPERATION_NOT_SUPPORTED_REASON
+ALTER TABLE t1 ADD d TEXT AFTER a, ALGORITHM=INSTANT;
+--error ER_ALTER_OPERATION_NOT_SUPPORTED_REASON
+ALTER TABLE t1 MODIFY a INT DEFAULT 0, ALGORITHM=INSTANT;
+--enable_info
+ALTER TABLE t1 MODIFY a INT DEFAULT 0;
+--disable_info
+ALTER TABLE t1 MODIFY a INT DEFAULT NULL, ALGORITHM=INSTANT;
+DROP TABLE t1;
+SET GLOBAL innodb_instant_alter_column_allowed = DEFAULT;
+
+# MDEV-15562 Instant DROP/ADD/reorder columns
+
+eval CREATE TABLE t1 (a INT, b INT UNIQUE) $engine;
+INSERT INTO t1 (a) VALUES (NULL), (NULL);
+ALTER TABLE t1 DROP a, ADD COLUMN a INT;
+DELETE FROM t1;
+BEGIN;INSERT INTO t1 SET a=NULL;ROLLBACK;
+DELETE FROM t1;
+DROP TABLE t1;
+
+eval CREATE TABLE t1 (a INT PRIMARY KEY, t VARCHAR(33101) NOT NULL) $engine;
+INSERT INTO t1 VALUES(347,'');
+ALTER TABLE t1 DROP COLUMN t, ALGORITHM=INSTANT;
+SELECT * FROM t1;
+DROP TABLE t1;
+
+eval CREATE TABLE t1 (a INT) $engine;
+INSERT INTO t1() VALUES();
+ALTER TABLE t1 ADD COLUMN b INT FIRST, ADD COLUMN c INT AFTER b;
+SELECT * FROM t1;
+DROP TABLE t1;
+
+eval CREATE TABLE t1 (t TEXT) $engine;
+SET @t=REPEAT('x',@@innodb_page_size / 2);
+INSERT INTO t1 VALUES (@t),(@t),(@t),(@t),(@t),(@t),(NULL),(@t),(@t),(@t),(@t);
+ALTER TABLE t1 ADD COLUMN a INT FIRST;
+UPDATE t1 SET a = 0;
+DROP TABLE t1;
+
+eval CREATE TABLE t1 (t TEXT) $engine;
+INSERT INTO t1 SET t = @x;
+ALTER TABLE t1 DROP COLUMN t, ADD COLUMN i INT NOT NULL DEFAULT 1;
+ALTER TABLE t1 ADD COLUMN t TEXT;
+SELECT * FROM t1;
+DROP TABLE t1;
+
+#
+# MDEV-17735 Assertion failure in row_parse_int() on first ADD/DROP COLUMN
+# when an AUTO_INCREMENT column is not in PRIMARY KEY
+#
+eval CREATE TABLE t1 (a INT AUTO_INCREMENT, b INT, KEY(a)) $engine;
+INSERT INTO t1 SET a=NULL;
+ALTER TABLE t1 DROP COLUMN b;
+ALTER TABLE t1 ADD COLUMN c INT NOT NULL DEFAULT 42;
+INSERT INTO t1 SET a=NULL;
+UPDATE t1 SET a=a+2;
+SELECT * FROM t1;
+DROP TABLE t1;
+
+eval CREATE TABLE t1 (i INT) $engine;
+INSERT INTO t1 SET i=1;
+ALTER TABLE t1 ADD COLUMN b BIT FIRST;
+ALTER TABLE t1 ADD COLUMN v INT AS (i) VIRTUAL;
+SELECT * FROM t1;
+DROP TABLE t1;
+
+# MDEV-17721 Corrupted data dictionary after instant DROP COLUMN
+eval CREATE TABLE t1 (ts TIMESTAMP) $engine;
+ALTER TABLE t1 ADD COLUMN f VARCHAR(8), ADD COLUMN dt DATETIME;
+ALTER TABLE t1 ADD COLUMN b BIT, DROP COLUMN f, ADD COLUMN t TIME FIRST;
+ALTER TABLE t1 ADD COLUMN ts2 TIMESTAMP;
+DROP TABLE t1;
+
+eval CREATE TABLE t1 (f1 INT, f2 INT, f3 INT) $engine;
+INSERT INTO t1 VALUES (4,4,4);
+ALTER TABLE t1 DROP f1, DROP f2, ADD f4 INT, ADD f5 INT;
+DELETE FROM t1;
+ALTER TABLE t1 DROP COLUMN f4;
+DROP TABLE t1;
+
+eval CREATE TABLE t1 (f1 INT, f2 INT, f3 INT) $engine;
+ALTER TABLE t1 DROP f2, ADD COLUMN f4 INT;
+ALTER TABLE t1 DROP f4;
+ALTER TABLE t1 DROP f1;
+DROP TABLE t1;
+
+# MDEV-17901 Crash after instant DROP COLUMN of AUTO_INCREMENT column
+eval CREATE TABLE t1 (id INT NOT NULL AUTO_INCREMENT, f INT, KEY(id)) $engine;
+ALTER TABLE t1 DROP COLUMN id;
+INSERT INTO t1 () VALUES (),();
+SELECT * FROM t1;
+# Adding AUTO_INCREMENT column will always require rebuild.
+ALTER TABLE t1 ADD COLUMN id INT NOT NULL AUTO_INCREMENT FIRST, ADD KEY(id);
+SELECT * FROM t1;
+DROP TABLE t1;
+
+# MDEV-18149 Crash after DROP COLUMN of AUTO_INCREMENT column on nonempty table
+eval CREATE TABLE t1 (id INT NOT NULL AUTO_INCREMENT, f INT, KEY(id)) $engine;
+INSERT INTO t1 SET f=NULL;
+ALTER TABLE t1 DROP COLUMN id;
+INSERT INTO t1 SET f=NULL;
+SELECT * FROM t1;
+DROP TABLE t1;
+
+# MDEV-18076/MDEV-18077 Crash on AUTO_INCREMENT column after instant DROP
+eval CREATE TABLE t1(f INT, k INT NOT NULL AUTO_INCREMENT, KEY(k)) $engine;
+ALTER TABLE t1 DROP COLUMN f;
+INSERT INTO t1 VALUES (1);
+DROP TABLE t1;
+
+eval CREATE TABLE t1(pk INT PRIMARY KEY, f INT, k INT AUTO_INCREMENT, KEY(k))
+$engine;
+ALTER TABLE t1 DROP COLUMN f;
+INSERT INTO t1 (pk) VALUES (1);
+DROP TABLE t1;
+
+# MDEV-17763 Assertion `len == 20U' failed in rec_convert_dtuple_to_rec_comp
+# upon DROP COLUMN
+eval CREATE TABLE t1 (
+ pk INT PRIMARY KEY,
+ f1 INT,
+ f2 CHAR(255),
+ f3 BIGINT,
+ f4 INT,
+ f5 CHAR(255),
+ f6 CHAR(255),
+ f7 CHAR(255) NOT NULL,
+ f8 INT,
+ f9 CHAR(10)
+) $engine;
+
+INSERT INTO t1 VALUES
+ (1, 1, 'a', 1, 1, 'a', 'a', 'a', 1, 'a'),
+ (2, 2, 'b', 2, 2, 'b', 'b', 'b', 2, 'b'),
+ (3, 3, 'c', 3, 3, 'c', 'c', 'c', 3, 'c'),
+ (4, 4, 'd', 4, 4, 'd', 'd', 'd', 4, 'd'),
+ (5, 5, 'e', 5, 5, 'e', 'e', 'e', 5, 'e'),
+ (6, 6, 'f', 6, 6, 'f', 'f', 'f', 6, 'f'),
+ (7, 7, 'g', 7, 7, 'g', 'g', 'g', 7, 'g'),
+ (8, 8, 'h', 8, 8, 'h', 'h', 'h', 8, 'h'),
+ (9, 9, 'i', 9, 9, 'i', 'i', 'i', 9, 'i'),
+ (10, 0, 'j', 0, 0, 'j', 'j', 'j', 0, 'j'),
+ (11, 1, 'k', 1, 1, 'k', 'k', 'k', 1, 'k'),
+ (12, 2, 'l', 2, 2, 'l', 'l', 'l', 2, 'l'),
+ (13, 3, 'm', 3, 3, 'm', 'm', 'm', 3, 'm'),
+ (14, 4, 'n', 4, 4, 'n', 'n', 'n', 4, 'n'),
+ (15, 5, 'o', 5, 5, 'o', 'o', 'o', 5, 'o');
+
+DELETE FROM t1 WHERE pk=1;
+--source include/wait_all_purged.inc
+INSERT INTO t1 VALUES
+ (1, 1, 'a', 1, 1, 'a', 'a', 'a', 1, 'a');
+ALTER TABLE t1 DROP COLUMN f1;
+DROP TABLE t1;
+
+# MDEV-17820 Assertion failures on DROP COLUMN
+eval CREATE TABLE t1 (
+ pk INT PRIMARY KEY,
+ f1 INT, f2 CHAR(32) NOT NULL,
+ f3 INT NOT NULL, f4 INT NOT NULL, f5 INT, f6 CHAR(32) NOT NULL,
+ f7 CHAR(32), f8 CHAR(32)
+) $engine;
+
+INSERT INTO t1 VALUES
+ (1,9,'',2,88,88,'','',''),(2,48,'',8,68,92,'','',''),
+ (3,41,'',56,84,37,'','',''),(4,NULL,'',6,6,NULL,'','',''),
+ (5,52,'',37,44,20,'','',''),(6,44,'',53,4,NULL,'','',''),
+ (7,24,'',54,8,54,'','',''),(8,80,'',3,52,20,'','',''),
+ (9,71,'',34,32,NULL,'','',''),(10,14,'',6,64,88,'','',''),
+ (11,48,'',8,25,42,'','',''),(12,16,'',8,7,NULL,'','',''),
+ (13,NULL,'',22,0,95,'','',''),(14,4,'',72,48,NULL,'','',''),
+ (15,4,'',5,64,2,'','',''),(16,NULL,'',9,40,30,'','',''),
+ (17,92,'',48,2,NULL,'','',''),(18,36,'',48,51,7,'','',''),
+ (19,NULL,'',80,96,NULL,'','',''),(20,96,'',9,80,NULL,'','',''),
+ (21,50,'',16,40,NULL,'','',''),(22,NULL,'',7,84,8,'','',''),
+ (23,28,'',93,80,NULL,'','',''),(24,31,'',40,38,NULL,'','',''),
+ (25,85,'',8,5,88,'','',''),(26,66,'',8,32,4,'','',''),
+ (51,52,'',6,92,15,'','',''),(52,77,'',24,24,28,'','',''),
+ (53,8,'',75,31,NULL,'','',''),(54,48,'',5,8,1,'','',''),
+ (55,90,'',56,12,5,'','',''),(56,92,'',4,9,88,'','',''),
+ (57,83,'',23,40,72,'','',''),(58,7,'',4,40,32,'','',''),
+ (59,28,'',2,3,32,'','',''),(60,16,'',80,4,NULL,'','',''),
+ (61,44,'',88,24,NULL,'','',''),(62,4,'',5,25,3,'','',''),
+ (63,NULL,'',7,24,76,'','',''),(64,0,'',13,40,73,'','',''),
+ (101,NULL,'',1,49,75,'','',''),(102,34,'',10,17,20,'','',''),
+ (103,8,'',2,2,NULL,'','',''),(104,12,'',44,48,52,'','',''),
+ (105,8,'',4,19,38,'','',''),(106,20,'',6,80,9,'','',''),
+ (107,72,'',72,16,56,'','',''),(108,76,'',98,24,21,'','',''),
+ (109,67,'',16,91,NULL,'','',''),(110,72,'',72,3,48,'','',''),
+ (151,8,'',3,86,NULL,'','',''),(152,NULL,'',52,72,0,'','',''),
+ (153,NULL,'',46,30,92,'','',''),(154,80,'',1,40,48,'','',''),
+ (155,24,'',68,68,8,'','',''),(156,85,'',85,72,60,'','',''),
+ (157,7,'',7,12,6,'','',''),(158,NULL,'',48,48,80,'','',''),
+ (159,12,'',0,36,0,'','',''),(160,2,'',6,52,NULL,'','',''),
+ (201,0,'',1,3,NULL,'','',''),(202,NULL,'',3,53,14,'','',''),
+ (203,84,'',6,20,NULL,'','',''),(204,38,'',25,13,88,'','',''),
+ (205,1,'',2,69,5,'','',''),(206,7,'',60,22,NULL,'','',''),
+ (207,NULL,'',5,4,NULL,'','',''),(251,7,'',0,4,40,'','',''),
+ (252,4,'',16,8,NULL,'','',''),(253,14,'',60,12,99,'','',''),
+ (254,84,'',68,16,5,'','',''),(255,3,'',70,36,61,'','',''),
+ (256,7,'',18,48,NULL,'','',''),(257,NULL,'',68,53,NULL,'','',''),
+ (258,29,'',52,16,64,'','',''),(259,NULL,'',80,92,40,'','',''),
+ (301,68,'',1,48,48,'','',''),(302,2,'',1,1,32,'','',''),
+ (303,44,'',60,96,16,'','',''),(304,32,'',52,64,32,'','',''),
+ (305,88,'',37,72,NULL,'','',''),(306,5,'',35,60,20,'','',''),
+ (307,35,'',4,48,NULL,'','',''),(308,4,'',92,44,80,'','',''),
+ (351,48,'',60,4,40,'','',''),(352,7,'',9,61,13,'','',''),
+ (353,0,'',5,93,53,'','',''),(354,7,'',1,20,NULL,'','',''),
+ (355,84,'',5,48,96,'','',''),(356,NULL,'',39,92,36,'','',''),
+ (357,88,'',9,76,44,'','',''),(358,66,'',34,67,80,'','',''),
+ (359,8,'',8,52,NULL,'','',''),(360,3,'',53,83,NULL,'','',''),
+ (361,23,'',44,9,48,'','',''),(362,4,'',0,54,48,'','',''),
+ (363,75,'',66,76,52,'','','');
+
+ALTER TABLE t1 ADD COLUMN x VARCHAR(255) DEFAULT ' foobar ';
+UPDATE t1 SET f1 = 0;
+ALTER TABLE t1 DROP COLUMN x;
+DROP TABLE t1;
+
+eval CREATE TABLE t1 (f1 VARCHAR(1), f2 VARCHAR(2)) $engine;
+ALTER TABLE t1 MODIFY f2 VARCHAR (8) FIRST;
+DROP TABLE t1;
+
+# MDEV-18035 Failing assertion on DELETE
+eval CREATE TABLE t1 (a INT UNIQUE, b INT UNIQUE, PRIMARY KEY(a,b)) $engine;
+ALTER TABLE t1 DROP PRIMARY KEY;
+ALTER TABLE t1 CHANGE COLUMN a a INT;
+DELETE FROM t1 WHERE a = NULL OR a IS NULL;
+DROP TABLE t1;
+
+# MDEV-18048 Failing assertion on ALTER
+eval CREATE TABLE t1 (a INT, b INT, c INT NOT NULL, d INT,
+e INT, f INT, g INT, h INT, j INT) $engine;
+ALTER TABLE t1 MODIFY COLUMN c INT, MODIFY COLUMN a INT AFTER b;
+DROP TABLE t1;
+
+# MDEV-18649 Failing assertion on ALTER for ROW_FORMAT=REDUNDANT
+eval CREATE TABLE t1 (a INT NOT NULL, b INT NOT NULL) $engine;
+INSERT INTO t1 VALUES (0,0);
+ALTER TABLE t1 MODIFY a INT AFTER b;
+# Exploit MDEV-17468 to force the table definition to be reloaded
+ALTER TABLE t1 ADD COLUMN v INT AS (a) VIRTUAL;
+ALTER TABLE t1 MODIFY b INT NOT NULL AFTER a;
+DROP TABLE t1;
+
+# MDEV-18033/MDEV-18034 Failing assertion on ALTER
+eval CREATE TABLE t1 (a INT NOT NULL) $engine;
+INSERT INTO t1 VALUES (1);
+ALTER TABLE t1 ADD COLUMN b INT;
+ALTER TABLE t1 MODIFY COLUMN a INT NULL;
+DROP TABLE t1;
+
+# MDEV-18160/MDEV-18162 Failing assertion on ALTER
+eval CREATE TABLE t1 (a INT PRIMARY KEY, b INT, c INT) $engine;
+INSERT INTO t1 SET a=1;
+ALTER TABLE t1 DROP c;
+ALTER TABLE t1 DROP b, ADD v INT AS (a);
+DROP TABLE t1;
+
+eval CREATE TABLE t1 (a INT PRIMARY KEY, b INT, c INT, d INT) $engine;
+INSERT INTO t1 SET a=1;
+ALTER TABLE t1 DROP c;
+ALTER TABLE t1 DROP b, ADD v INT AS (a);
+DROP TABLE t1;
+
+# MDEV-18218 Assertion `0' failed in btr_page_reorganize_low upon DROP COLUMN
+eval CREATE TABLE t1 (pk INT PRIMARY KEY, i INT, b BLOB NOT NULL) $engine;
+INSERT INTO t1 VALUES (1,10,REPEAT('foobar',2000));
+ALTER TABLE t1 DROP COLUMN b;
+INSERT INTO t1 VALUES (2,20);
+# this evicts and reloads the table definition until MDEV-17468 is fixed
+ALTER TABLE t1 ADD COLUMN vpk INT AS (pk);
+# this would load wrong metadata from the previous DROP COLUMN b, causing a crash
+ALTER TABLE t1 DROP COLUMN i;
+DROP TABLE t1;
+
+# MDEV-18315 Assertion instant.fields[i].col->same_format(*fields[i].col)
+# failed in dict_index_t::instant_add_field
+eval CREATE TABLE t1 (a INT, b INT) $engine;
+INSERT INTO t1 VALUES (1,1);
+ALTER TABLE t1 ADD f DATE AFTER a;
+ALTER TABLE t1 DROP b, DROP f;
+DROP TABLE t1;
+
+# MDEV-18316 Assertion is_added() failed in dict_col_t::instant_value
+eval CREATE TABLE t1 (a INT, b INT) $engine;
+INSERT INTO t1 VALUES (1,1);
+ALTER TABLE t1 ADD COLUMN f INT AFTER a;
+ALTER TABLE t1 DROP b, DROP f;
+DROP TABLE t1;
+
+# MDEV-18579 Assertion !ctx->online || num_fts_index == 0
+eval CREATE TABLE t1(t TEXT NOT NULL, FULLTEXT(t)) $engine;
+ALTER TABLE t1 MODIFY COLUMN t TEXT;
+DROP TABLE t1;
+
+# MDEV-18598 Assertions and wrong results after MDEV-15563 extending INT
+eval CREATE TABLE t1 (f TINYINT, g SMALLINT UNSIGNED) $engine;
+INSERT INTO t1 VALUES(127,6502),(-128,33101);
+--enable_info
+ALTER TABLE t1 MODIFY f SMALLINT DEFAULT 12345,
+MODIFY g BIGINT UNSIGNED DEFAULT 1234567;
+--disable_info
+SELECT * FROM t1;
+DROP TABLE t1;
+
+eval CREATE TABLE t1 (f BIT(8)) $engine;
+INSERT INTO t1 VALUES (b'10000000'),(b'00000001');
+--enable_info
+ALTER TABLE t1 MODIFY f BIT(16);
+--disable_info
+INSERT INTO t1 VALUES (b'1000000010101111'),(b'10000000');
+SELECT HEX(f) FROM t1;
+--error ER_WARN_DATA_OUT_OF_RANGE
+ALTER TABLE t1 MODIFY f SMALLINT;
+--enable_info
+ALTER TABLE t1 MODIFY f SMALLINT UNSIGNED;
+--disable_info
+SELECT * FROM t1;
+--error ER_DATA_TOO_LONG
+ALTER TABLE t1 MODIFY f BIT;
+--error ER_DATA_TOO_LONG
+ALTER TABLE t1 MODIFY f BIT(15);
+DELETE FROM t1 LIMIT 3;
+--enable_info
+ALTER TABLE t1 MODIFY f BIT(15);
+ALTER TABLE t1 MODIFY f BIT(8);
+--disable_info
+SELECT HEX(f) FROM t1;
+DROP TABLE t1;
+
+eval CREATE TABLE t1 (b BIT NOT NULL) $engine DEFAULT CHARSET utf16;
+INSERT INTO t1 SET b=b'1';
+--enable_info
+ALTER TABLE t1 CHANGE b c BIT NOT NULL;
+--disable_info
+SELECT HEX(c) FROM t1;
+DROP TABLE t1;
+
+eval CREATE TABLE t1 (c VARCHAR(10) NOT NULL DEFAULT 'scary') $engine;
+INSERT INTO t1() VALUES();
+--enable_info
+ALTER TABLE t1 ADD f TINYINT NOT NULL DEFAULT -42;
+ALTER TABLE t1 MODIFY f MEDIUMINT NOT NULL DEFAULT 64802,
+MODIFY c VARCHAR(20) NOT NULL DEFAULT 'gory',
+ADD d DATETIME;
+--disable_info
+INSERT INTO t1() VALUES();
+INSERT INTO t1 (c,f,d) VALUES ('fury', -8388608, now());
+SELECT * FROM t1;
+DROP TABLE t1;
+
+eval CREATE TABLE t1 (t TINYINT PRIMARY KEY, m MEDIUMINT UNIQUE) $engine;
+SELECT table_id INTO @table_id1 FROM INFORMATION_SCHEMA.INNODB_SYS_TABLESTATS
+WHERE name = 'test/t1';
+INSERT INTO t1 VALUES (-42, -123456);
+--enable_info
+ALTER TABLE t1 CHANGE t s SMALLINT;
+SELECT table_id INTO @table_id2 FROM INFORMATION_SCHEMA.INNODB_SYS_TABLESTATS
+WHERE name = 'test/t1';
+--error ER_ALTER_OPERATION_NOT_SUPPORTED_REASON
+ALTER TABLE t1 CHANGE m i INT, ALGORITHM=INSTANT;
+ALTER TABLE t1 CHANGE m i INT;
+SELECT table_id INTO @table_id3 FROM INFORMATION_SCHEMA.INNODB_SYS_TABLESTATS
+WHERE name = 'test/t1';
+--disable_info
+SELECT @table_id1 = @table_id2, @table_id2 = @table_id3;
+INSERT IGNORE INTO t1 VALUES (0, -123456);
+REPLACE INTO t1 VALUES(-42, 123456);
+INSERT IGNORE INTO t1 VALUES(32768, 2147483648);
+SELECT * FROM t1;
+DROP TABLE t1;
+
+eval CREATE TABLE t1 (a SERIAL, b INT, c TINYINT UNIQUE) $engine;
+INSERT INTO t1 (c) VALUES(1),(2),(3);
+--enable_info
+ALTER TABLE t1 MODIFY c BIGINT;
+--disable_info
+UPDATE t1 SET b=1 WHERE c=2;
+UPDATE t1 SET c=4 WHERE a=3;
+UPDATE t1 SET b=2 WHERE c>3;
+--error ER_DUP_ENTRY
+UPDATE t1 SET c=c+1;
+SELECT * FROM t1;
+DROP TABLE t1;
+
+# MDEV-18719 Assertion (c.prtype ^ o->prtype) & ... failed on ALTER TABLE
+eval CREATE TABLE t1 (a INT PRIMARY KEY, b VARCHAR(1)) $engine;
+INSERT INTO t1 VALUES(1,'a');
+ALTER TABLE t1 MODIFY b VARCHAR(256), ADD COLUMN c INT;
+INSERT INTO t1 VALUES(2,'bah',3);
+SELECT * FROM t1;
+DROP TABLE t1;
+
+# MDEV-21088 Table cannot be loaded after instant ADD/DROP COLUMN
+eval CREATE TABLE t1(a CHAR(5) CHARACTER SET utf8 PRIMARY KEY) $engine;
+INSERT INTO t1 VALUES('barf');
+ALTER TABLE t1 ADD b INT FIRST, ALGORITHM=INSTANT;
+# this evicts and reloads the table definition until MDEV-17468 is fixed
+ALTER TABLE t1 ADD vb INT AS (b);
+SELECT * FROM t1;
+DROP TABLE t1;
+
+# MDEV-21148 Assertion failure index->n_core_fields + n_add >= index->n_fields
+eval CREATE TABLE t1 (a INT, b TEXT, PRIMARY KEY(b(9))) $engine;
+ALTER TABLE t1 ADD COLUMN c TEXT FIRST;
+ALTER TABLE t1 ADD COLUMN d TEXT GENERATED ALWAYS AS (SUBSTR(b,1,499)) FIRST;
+DROP TABLE t1;
+
+eval CREATE TABLE t1(a CHAR(5), b INT, c CHAR(1), d CHAR(1), PRIMARY KEY(a,b))
+DEFAULT CHARACTER SET utf8 $engine;
+INSERT INTO t1 SET a='fubar',b=42;
+ALTER TABLE t1 DROP c, DROP d, ALGORITHM=INSTANT;
+# this evicts and reloads the table definition until MDEV-17468 is fixed
+ALTER TABLE t1 ADD vb INT AS (b);
+SELECT * FROM t1;
+DROP TABLE t1;
+
+eval CREATE TABLE t1 (a INT, b INT, PRIMARY KEY(a,b)) $engine;
+ALTER TABLE t1 MODIFY b INT FIRST;
+DROP TABLE t1;
+
+# MDEV-21744 Assertion `!rec_offs_nth_sql_null(offsets, n)' failed
+eval CREATE TABLE t1 (pk INT PRIMARY KEY) $engine;
+INSERT INTO t1 SET pk=1;
+ALTER TABLE t1 ADD COLUMN b INT;
+BEGIN;
+UPDATE t1 SET pk=2;
+UPDATE t1 SET pk=1;
+connection analyze;
+SELECT * FROM t1;
+connection default;
+DROP TABLE t1;
+
+dec $format;
+let $redundant_4k= 0;
+}
+disconnect analyze;
+
+--echo #
+--echo # MDEV-22465: DROP COLUMN is wrongly claimed to be ALGORITHM=INSTANT
+--echo #
+
+CREATE TABLE t1(a INT PRIMARY KEY, b INT UNIQUE) ENGINE=InnoDB;
+--error ER_ALTER_OPERATION_NOT_SUPPORTED_REASON
+ALTER TABLE t1 DROP b, ALGORITHM=INSTANT;
+ALTER TABLE t1 DROP b, ALGORITHM=NOCOPY;
+DROP TABLE t1;
+
+SELECT variable_value-@old_instant instants
+FROM information_schema.global_status
+WHERE variable_name = 'innodb_instant_alter_column';
+SET GLOBAL innodb_instant_alter_column_allowed = @saved_allowance;
+
+--echo #
+--echo # MDEV-18266: Changing an index comment unnecessarily rebuilds index
+--echo #
+
+CREATE TABLE t1(a INT, b INT) ENGINE=INNODB;
+CREATE INDEX i1 ON t1(a) COMMENT 'comment1';
+ALTER TABLE t1 DROP INDEX i1, ADD INDEX i1(a) COMMENT 'comment2', ALGORITHM=INSTANT;
+SHOW CREATE TABLE t1;
+DROP TABLE t1;
+
+--echo #
+--echo # MDEV-25057 Assertion `n_fields < dtuple_get_n_fields(entry)'
+--echo # failed in dtuple_convert_big_rec
+--echo #
+CREATE TABLE t1 (pk INT PRIMARY KEY AUTO_INCREMENT,
+ a CHAR(255) NOT NULL,
+ b CHAR(255) NOT NULL, c INT) ENGINE=InnoDB CHARSET utf32;
+ALTER TABLE t1 DROP c;
+INSERT INTO t1(a, b) SELECT '', '' FROM seq_1_to_16;
+SELECT COUNT(*) FROM t1;
+# Cleanup
+DROP TABLE t1;
+
+--echo #
+--echo # MDEV-25630 Rollback of instant operation adds wrong
+--echo # column to secondary index
+--echo #
+CREATE TABLE t1 (f1 INT, f2 INT, f3 INT, f4 INT,
+ PRIMARY KEY(f1, f4),
+ KEY(f2))ENGINE=InnoDB;
+CREATE TABLE t2 (f1 INT, f2 INT, PRIMARY KEY(f1),
+ FOREIGN KEY fk (f2) REFERENCES t2(f1)
+ )ENGINE=InnoDB;
+
+ALTER TABLE t1 ADD f5 INT;
+SET FOREIGN_KEY_CHECKS=0;
+--error ER_FK_FAIL_ADD_SYSTEM
+ALTER TABLE t1 DROP COLUMN f3, ADD FOREIGN KEY fk (f1)
+ REFERENCES x(x);
+ALTER TABLE t1 DROP COLUMN f5;
+SHOW CREATE TABLE t1;
+DROP TABLE t1, t2;
+
+
+--echo #
+--echo # MDEV-28822 Table from older version requires table rebuild when adding column to table with multi-column index
+--echo #
+
+CREATE TABLE mdev28822_100427_innodb (
+ id int not null primary key,
+ msg varchar(10),
+ index(id, msg)
+) ENGINE=InnoDB ROW_FORMAT=DYNAMIC;
+FLUSH TABLES;
+remove_file $datadir/test/mdev28822_100427_innodb.frm;
+copy_file std_data/mysql_upgrade/mdev28822_100427_innodb.frm $datadir/test/mdev28822_100427_innodb.frm;
+ALTER TABLE mdev28822_100427_innodb ADD i1 INTEGER, ALGORITHM=INSTANT;
+DROP TABLE mdev28822_100427_innodb;
diff --git a/mysql-test/suite/innodb/t/instant_alter_bugs.test b/mysql-test/suite/innodb/t/instant_alter_bugs.test
new file mode 100644
index 00000000..81d36849
--- /dev/null
+++ b/mysql-test/suite/innodb/t/instant_alter_bugs.test
@@ -0,0 +1,529 @@
+--source include/have_innodb.inc
+
+--echo #
+--echo # MDEV-17821 Assertion `!page_rec_is_supremum(rec)' failed
+--echo # in btr_pcur_store_position
+--echo #
+
+CREATE TABLE t1 (pk INT PRIMARY KEY, c INT) ENGINE=InnoDB;
+INSERT INTO t1 VALUES (1,2);
+ALTER TABLE t1 ADD COLUMN f VARCHAR(255);
+ALTER TABLE t1 DROP COLUMN f;
+DELETE FROM t1;
+HANDLER t1 OPEN;
+HANDLER t1 READ `PRIMARY` <= (3);
+DROP TABLE t1;
+
+CREATE TABLE t1 (
+ pk INT AUTO_INCREMENT,
+ f1 CHAR(32),
+ f2 CHAR(32),
+ f3 CHAR(32),
+ f4 INT,
+ f5 CHAR(32),
+ f6 INT,
+ f7 INT,
+ f8 INT,
+ PRIMARY KEY (pk),
+ UNIQUE (f6)
+) ENGINE=InnoDB;
+
+INSERT INTO t1 (f1,f2,f3,f4,f5,f6,f7,f8) VALUES
+ ('reality', 'llt', 'within', -1996816384, 'j', 160, 7, -1822687232),
+ ('h', 'j', 'j', 251, 'civilian', NULL, 211, NULL),
+ ('ltq', 'b', 'mud', 111, 'v', 90, 0, NULL),
+ ('toxic', 'breakfast', 'series', 2, 'x', NULL, 118, 2),
+ ('h', 'n', 'vision', 84, 'n', NULL, 197, 103),
+ ('h', 'tq', 'q', 6, 'bet', -1927151616, -446038016, 3),
+ ('pocket', 'qjt', 'jtl', 0, 'blink', NULL, 12, 0),
+ ('k', 'uv', 'exist', 37, 'g', 149, -1610219520, NULL),
+ ('parent', 'motion', 'u', 70, 'promote', NULL, 178, NULL),
+ ('get', 'convict', 'liquid', -780337152, 'd', NULL, 4, NULL),
+ ('vp', 'px', 'xi', -631111680, 'support', NULL, 8, NULL),
+ ('ck', 'z', 'minority', 8, 'k', NULL, 864878592, NULL),
+ ('kxx', 'g', 'container', 1, 'cholesterol', NULL, 4, 1404436480),
+ ('xxv', 'rail', 'j', 219, 'serious', NULL, -816119808, 62),
+ ('x', 'v', 'vr', 146, 'm', 16, 170, -1765867520),
+ ('age', 'm', 'q', -1251278848, 'rte', 6, 224, NULL),
+ ('discrimination', 't', 'q', 31, 'exl', 0, 2, 244),
+ ('water', 'x', 'ldb', 98, 'r', 235, 4, 63),
+ ('d', 'db', 'p', 248, 'so-called', 102, -255524864, 198),
+ ('last', 'bz', 'us', 0, 'experienced', 137, 240, 134),
+ ('q', 'z', 'attract', 67, 'code', 67, 75, 1758920704),
+ ('yellow', 'c', 'u', 6, 'v', 1731985408, 528154624, 2),
+ ('cognitive', 'he', 'protective', 590020608, 'sentence', NULL, 4, 102),
+ ('eih', 'l', 'ih', 1266024448, 'traditionally', NULL, 190, NULL),
+ ('pine', 'i', 'y', 6, 'glimpse', 214, 7, -1486880768),
+ ('jo', 'everyone', 'ol', 0, 'lj', NULL, 1, 0),
+ ('blood', 'f', 'scientist', 54, 'j', 1341128704, 168, NULL),
+ ('z', 'brief', 'ambassador', 115, 'ygp', 82, 129, NULL),
+ ('gp', 'severe', 'consist', 7, 'p', -1829961728, 602669056, 154),
+ ('admit', 'poetry', 'x', 116, 'enemy', 174, -2128543744, -407764992),
+ ('s', 'norm', 'decide', 2055667712, 'rtz', NULL, 99, -1233715200),
+ ('tzg', 'f', 'beg', 2016280576, 'w', NULL, -643825664, 137),
+ ('zgg', 'x', 'f', 148, 'y', -987496448, -708116480, 8),
+ ('attorney', 'perfectly', 's', 49, 'z', -1865285632, 56, -1518534656),
+ ('concentrate', 's', 'k', -1028849664, 'tir', 83, -1592459264, 1820065792),
+ ('t', 'sacrifice', 'ir', -2143879168, 'recipe', 156, 217, NULL),
+ ('wdf', 'd', 'f', 137, 'empty', NULL, 188, NULL),
+ ('o', 'customer', 'qd', -2135293952, 'z', 1527840768, 227, -1174929408),
+ ('d', 'qow', 'o', 1472266240, 'whe', NULL, 7, 197),
+ ('deny', 'reputation', 'dutch', 59, 'v', 124, 2, 191),
+ ('m', 'liver', 'fv', 0, 'policy', 781582336, 198574080, 177),
+ ('vk', 'kx', 'immigrant', -1452736512, 'x', 163, 76, 6) ,
+ ('j', 'ru', 'r', 67, 'joke', NULL, 3, NULL),
+ ('o', 'u', 'a', -569442304, 'uz', NULL, 933298176, NULL),
+ ('g', 'zb', 'c', -1694760960, 'fish', 18, -390463488, 1),
+ ('bb', 'o', 'b', 6, 'z', 9, 12, NULL),
+ ('compelling', 'xe', 'debut', 89, 'e', -734724096, 119, 175),
+ ('md', 'r', 'object', 1046478848, 'frequently', 915537920, 0, 1506410496),
+ ('dwn', 'wnz', 'x', 1767571456, 'nz', 241, -882180096, 9),
+ ('zvf', 'vfo', 'g', -844824576, 'w', NULL, 1, 9),
+ ('w', 'pose', 'r', 1029308416, 'a', -48627712, 1756168192, NULL),
+ ('o', 'jwp', 'patient', 172, 'i', 297140224, 45809664, 3),
+ ('w', 'p', 'american', 450297856, 'z', 20, 4, 186),
+ ('ridiculous', 'helpful', 'vy', -2022899712, 'conspiracy', NULL, 162, -264634368),
+ ('t', 'g', 'spite', 289931264, 'y', 4, 13, NULL),
+ ('performer', 'i', 'tomato', -1519386624, 'mz', 8, 87, 106),
+ ('m', 'z', 'hang', 3, 'crowded', -537919488, 1, 2),
+ ('fu', 'uot', 'j', 1, 'o', 179, 220, -2084569088),
+ ('ts', 'n', 'su', 1, 'o', 198, 9, 68),
+ ('ball', 'halfway', 'uf', 40, 'l', 145948672, 9, 149),
+ ('hunting', 'n', 'teenager', 0, 'neat', 209, 2044461056, 68),
+ ('independent', 'along', 'fpn', 5, 'pn', 3, 1353252864, 217),
+ ('p', 'presumably', 'n', -1977548800, 'balanced', 1909260288, 197, NULL),
+ ('pink', 'h', 'tear', 8, 'n', 254, 8, 1006305280),
+ ('tyy', 'n', 'yyr', 1107820544, 'yr', NULL, 0, 219),
+ ('u', 'retirement', 'thread', -2083192832, 'rx', -678232064, 209, 1048969216),
+ ('xk', 'kb', 'z', 9, 'ba', 218, 7, 8),
+ ('a', 'plenty', 'forget', 36, 'c', 215, 2027094016, NULL),
+ ('i', 'compromise', 'n', -1090256896, 'o', 10, 66, 1872887808),
+ ('x', 'disappointment', 'cognitive', 753860608, 'ua', 77, 123, 10),
+ ('e', 'added', 'aub', 2, 'u', NULL, 9, 92),
+ ('bc', 'h', 'n', 146, 'master', NULL, 1003945984, NULL),
+ ('execution', 'f', 'cgp', 574423040, 'gp', 2, -518782976, -1189085184),
+ ('pv', 'bad', 'v', 132, 'r', 195, 6, 5),
+ ('modify', 'participation', 'vol', 237, 'j', -842924032, 88, -747765760),
+ ('substantially', 'i', 'congressional', 2, 'edit', NULL, 1003159552, NULL),
+ ('tell', 'forty', 'v', -910098432, 'd', 43, 3, NULL),
+ ('crawl', 'ad', 'respect', -1851195392, 'p', 72, -1709047808, 1343225856),
+ ('w', 'reception', 'fiber', 56, 's', NULL, 2, -993787904),
+ ('successful', 'instruct', 'dug', 2, 'u', 7, -411500544, NULL),
+ ('appointment', 'pregnant', 'weird', 2, 'r', NULL, -897384448, 76),
+ ('g', 'j', 'thin', 663617536, 'oan', 1, 7, NULL),
+ ('secretary', 'a', 'o', 103, 'nj', 1977745408, -1291124736, -1314521088),
+ ('g', 'jq', 'q', 1875116032, 'blame', NULL, 1, 4),
+ ('oj', 'j', 'breast', 150, 'c', NULL, 3, NULL),
+ ('rd', 'm', 'comprehensive', 1723334656, 't', NULL, 155, -312344576) ,
+ ('a', 'd', 'criminal', -1155137536, 'airplane', 242, -662896640, 1),
+ ('fast', 'i', 'k', -386662400, 'zxe', NULL, 7, 119),
+ ('xe', 'mouse', 'c', -205717504, 'ew', NULL, -729612288, 86),
+ ('hang', 'j', 'o', 3, 'hungry', NULL, 200, 49),
+ ('expense', 'z', 'sum', 2, 'gob', -472055808, -538181632, NULL),
+ ('nest', 'o', 'k', 116, 'weak', NULL, 223, NULL);
+--error ER_DUP_ENTRY
+INSERT INTO t1 (f1,f2,f3,f4,f5,f6,f7,f8) VALUES ('impact', 'b', 'h', 185, 'fj', 7, 7, 3);
+
+ALTER TABLE t1 ADD COLUMN filler VARCHAR(255) DEFAULT '';
+--disable_ps2_protocol
+SELECT * INTO OUTFILE 'load.data' FROM t1;
+--enable_ps2_protocol
+UPDATE IGNORE t1 SET pk = 0;
+LOAD DATA INFILE 'load.data' REPLACE INTO TABLE t1;
+HANDLER t1 OPEN AS h;
+HANDLER h READ `PRIMARY` PREV WHERE 0;
+
+# Cleanup
+HANDLER h CLOSE;
+DROP TABLE t1;
+
+--echo #
+--echo # MDEV-19630 ALTER TABLE ... ADD COLUMN damages foreign keys
+--echo # which are pointed to the table being altered
+--echo #
+CREATE TABLE t1(f1 int not null, primary key(f1))engine=innodb;
+CREATE TABLE t2(f1 INT AUTO_INCREMENT NOT NULL, f2 INT NOT NULL,
+ status ENUM ('a', 'b', 'c'), INDEX idx1(f2),
+ PRIMARY KEY(f1),
+ FOREIGN KEY (f2) REFERENCES t1(f1))ENGINE=InnoDB;
+
+ALTER TABLE t1 CHANGE f1 f1_id INT NOT NULL, ADD f3 VARCHAR(255) DEFAULT NULL;
+ALTER TABLE t1 CHANGE f1_id f1 INT NOT NULL;
+
+SHOW CREATE TABLE t1;
+SHOW CREATE TABLE t2;
+
+ALTER TABLE t2 CHANGE status status VARCHAR(20) DEFAULT NULL;
+DROP TABLE t2, t1;
+
+--let $datadir= `select @@datadir`
+--remove_file $datadir/test/load.data
+
+--echo #
+--echo # MDEV-20938 Double free of dict_foreign_t during instant ALTER TABLE
+--echo #
+
+CREATE TABLE t1 (id INT UNSIGNED PRIMARY KEY) ENGINE=InnoDB;
+CREATE TABLE t2 (a INT UNSIGNED PRIMARY KEY, b INT UNSIGNED UNIQUE,
+ FOREIGN KEY fk1 (b) REFERENCES t1 (id)) ENGINE=InnoDB;
+ALTER TABLE t2
+ DROP FOREIGN KEY fk1,
+ CHANGE b d INT UNSIGNED,
+ ADD c INT;
+DROP TABLE t2, t1;
+
+--echo #
+--echo # MDEV-22446 InnoDB aborts while adding instant column
+--echo # for discarded tablespace
+--echo #
+
+let MYSQLD_DATADIR =`SELECT @@datadir`;
+CREATE TABLE t1(c1 INT NOT NULL, c2 INT NOT NULL DEFAULT 0)ENGINE=InnoDB;
+INSERT INTO t1(c1) VALUES(1);
+
+ALTER TABLE t1 ADD COLUMN c3 INT DEFAULT 10;
+--replace_regex /, .*\).*t1.cfg/, Bad file descriptor) t1.cfg/
+FLUSH TABLES t1 FOR EXPORT;
+
+perl;
+do "$ENV{MTR_SUITE_DIR}/include/innodb-util.pl";
+ib_backup_tablespaces("test", "t1");
+EOF
+UNLOCK TABLES;
+DROP TABLE t1;
+
+# Restore of instant table
+CREATE TABLE t1(c1 INT NOT NULL)Engine=InnoDB;
+ALTER TABLE t1 DISCARD TABLESPACE;
+FLUSH TABLES;
+ALTER TABLE t1 ADD COLUMN c2 INT NOT NULL;
+ALTER TABLE t1 ADD COLUMN c3 INT DEFAULT 10;
+# Restore files
+perl;
+do "$ENV{MTR_SUITE_DIR}/include/innodb-util.pl";
+ib_restore_tablespaces("test", "t1");
+EOF
+ALTER TABLE t1 IMPORT TABLESPACE;
+SHOW CREATE TABLE t1;
+SELECT * FROM t1;
+DROP TABLE t1;
+
+
+--echo #
+--echo # MDEV-23801 Assertion index->table->instant... failed
+--echo # in btr_pcur_store_position()
+--echo #
+
+CREATE TABLE t (
+ pk int auto_increment,
+ c01 char(255) not null default repeat('a',255),
+ c02 char(255) default repeat('a',255),
+ c03 char(255) default repeat('a',255),
+ c04 char(255) default repeat('a',255),
+ c05 char(255) not null default repeat('a',255),
+ c06 char(255) default repeat('a',255),
+ c07 char(255) default repeat('a',255),
+ c08 char(255) not null default repeat('a',255),
+ c09 char(255) default repeat('a',255),
+ c10 char(255) default repeat('a',255),
+ c11 char(255) default repeat('a',255),
+ c12 char(255) not null default repeat('a',255),
+ primary key (pk)
+) ENGINE=InnoDB CHARACTER SET ucs2;
+
+INSERT INTO t () VALUES ();
+ALTER TABLE t ADD c INT;
+
+BEGIN;
+INSERT INTO t () VALUES (),();
+ROLLBACK;
+DELETE FROM t;
+
+--source include/wait_all_purged.inc
+
+CREATE TABLE tt ENGINE=InnoDB AS SELECT c FROM t;
+DROP TABLE t, tt;
+
+--echo # End of 10.3 tests
+
+--disable_query_log
+SET @save_innodb_read_only_compressed=@@GLOBAL.innodb_read_only_compressed;
+SET GLOBAL innodb_read_only_compressed=OFF;
+--enable_query_log
+create table t (
+ a varchar(9),
+ b int,
+ c int,
+ row_start bigint unsigned generated always as row start invisible,
+ row_end bigint unsigned generated always as row end invisible,
+ period for system_time (row_start, row_end)
+) engine=innodb row_format=compressed with system versioning;
+insert into t values (repeat('a', 9), 1, 1);
+set @@system_versioning_alter_history = keep;
+alter table t modify a varchar(10), algorithm=instant;
+alter table t change b bb int, algorithm=instant;
+alter table t modify c int without system versioning, algorithm=instant;
+set @@system_versioning_alter_history = error;
+--disable_query_log
+SET GLOBAL innodb_read_only_compressed=@save_innodb_read_only_compressed;
+--enable_query_log
+check table t;
+drop table t;
+
+--echo #
+--echo # MDEV-18219 Assertion `index->n_core_null_bytes <= ...' failed
+--echo # in rec_init_offsets after instant DROP COLUMN
+--echo #
+CREATE TABLE t1 (a INT, b INT NOT NULL) ENGINE=InnoDB;
+INSERT INTO t1 VALUES
+(0,9),(2,7),(3,1),(3,4),(8,4),(3,7),(6,1),(3,8),(1,2),(4,1),(0,8),(5,3),
+(1,3),(1,6),(2,1),(8,7),(6,0),(1,9),(9,4),(0,6),(9,3),(0,9),(9,4),(2,4),
+(2,7),(7,8),(8,2),(2,5),(6,1),(4,5),(5,3),(6,8),(4,9),(5,7),(7,5),(5,1),
+(8,8),(5,7),(3,8),(0,1),(8,4),(8,3),(9,7),(4,8),(1,1),(0,4),(2,6),(8,5),
+(8,8),(8,7),(6,7),(1,7),(9,6),(3,6),(1,9),(0,3),(5,3),(2,4),(0,6),(2,0),
+(6,5),(1,6),(2,4),(9,1),(3,0),(6,4),(1,3),(0,8),(3,5),(3,1),(8,9),(9,9),
+(7,9),(4,5),(2,2),(3,8),(0,8),(7,1),(2,0),(1,5),(7,3),(4,4),(3,9),(7,2),
+(6,2),(0,4),(2,0),(1,5),(5,7),(4,5),(3,7),(6,0),(2,1),(5,0),(1,0),(2,0),
+(8,4),(5,7),(3,5),(0,5),(7,6),(5,9),(1,2),(4,2),(8,5),(8,7),(2,8),(1,8),
+(4,3),(1,6),(7,8),(3,7),(4,6),(1,1),(3,0),(1,6),(2,0),(3,4),(4,8),(3,9),
+(8,0),(4,9),(4,0),(3,9),(6,4),(7,4),(5,8),(4,7),(7,3),(5,9),(2,3),(7,3),
+(0,4),(5,9),(9,8),(4,2),(3,6),(2,6),(1,8),(7,0),(0,0),(2,3),(1,2),(3,3),
+(2,7),(6,0),(9,0),(6,9),(4,6),(9,8),(0,7),(9,1),(9,6),(4,3),(7,7),(7,7),
+(4,1),(4,7),(7,3),(2,8),(5,8),(8,9),(3,9),(7,7),(0,8),(4,9),(3,2),(5,0),
+(1,7),(0,3),(2,9),(9,7),(7,5),(6,9),(8,5),(3,6),(1,1),(2,8),(7,9),(4,9),
+(6,6),(5,9),(5,3),(9,8),(3,3),(5,6),(0,9),(3,9),(7,9),(7,3),(5,2),(1,4),
+(4,4),(8,2),(2,2),(8,3),(9,1),(4,9),(9,8),(1,8),(1,8),(9,1),(1,1),(3,0),
+(4,6),(9,3),(3,3),(5,2),(0,1),(3,4),(3,2),(1,3),(4,4),(7,0),(4,6),(7,2),
+(4,5),(8,7),(7,8),(8,1),(3,5),(0,6),(3,5),(2,1),(4,4),(3,4),(2,1),(4,1);
+INSERT INTO t1 SELECT * FROM t1;
+ALTER TABLE t1 DROP a;
+# Exploit MDEV-17468 to force the table definition to be reloaded
+ALTER TABLE t1 ADD vb INT AS (b) VIRTUAL;
+DROP TABLE t1;
+
+--echo #
+--echo # MDEV-19030 Assertion index->n_core_null_bytes <= ... failed
+--echo # in rec_init_offsets after instant DROP COLUMN
+--echo #
+CREATE TABLE t1 (a INT, b INT NOT NULL DEFAULT 0) ENGINE=InnoDB;
+INSERT INTO t1 () VALUES (),(),(),();
+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;
+ALTER TABLE t1 FORCE;
+INSERT INTO t1 SELECT * FROM t1;
+ALTER TABLE t1 DROP a, ADD a SMALLINT NOT NULL;
+INSERT INTO t1 SELECT * FROM t1;
+INSERT INTO t1 SELECT * FROM t1;
+# Exploit MDEV-17468 to force the table definition to be reloaded
+ALTER TABLE t1 ADD vb INT AS (b) VIRTUAL;
+DROP TABLE t1;
+
+--echo #
+--echo # MDEV-18623 Assertion after DROP FULLTEXT INDEX and removing NOT NULL
+--echo #
+CREATE TABLE t1 (c TEXT NOT NULL, FULLTEXT INDEX ftidx(c)) ENGINE=InnoDB
+ROW_FORMAT=REDUNDANT;
+ALTER TABLE t1 DROP INDEX ftidx;
+--error ER_ALTER_OPERATION_NOT_SUPPORTED
+ALTER TABLE t1 MODIFY c TEXT NULL, ALGORITHM=INSTANT;
+ALTER TABLE t1 MODIFY c TEXT NULL;
+DROP TABLE t1;
+
+--echo #
+--echo # MDEV-20048 dtuple_get_nth_field(): Assertion 'n < tuple->n_fields'
+--echo # failed on ROLLBACK after instant DROP COLUMN
+--echo #
+CREATE TABLE t1 (a INT PRIMARY KEY) ENGINE=InnoDB;
+INSERT INTO t1 VALUES (1);
+ALTER TABLE t1 ADD b TEXT, ALGORITHM=INSTANT;
+SET @b = REPEAT('b', @@innodb_page_size / 2 + 1);
+INSERT INTO t1 VALUES(2, @b), (3, @b);
+BEGIN;
+DELETE FROM t1 WHERE a=2;
+
+# Stop purge so that it doesn't remove the delete-marked entry.
+connect (purge_control,localhost,root);
+START TRANSACTION WITH CONSISTENT SNAPSHOT;
+connection default;
+
+COMMIT;
+
+ALTER TABLE t1 DROP b, ALGORITHM=INSTANT;
+BEGIN;
+INSERT INTO t1 VALUES (2);
+
+connection purge_control;
+SELECT * FROM t1;
+disconnect purge_control;
+connection default;
+ROLLBACK;
+
+SELECT * FROM t1;
+DROP TABLE t1;
+
+
+--echo #
+--echo # MDEV-20479: assertion failure in dict_table_get_nth_col() after INSTANT DROP COLUMN
+--echo #
+
+CREATE TABLE t1 (a INT PRIMARY KEY) ENGINE=InnoDB;
+ALTER TABLE t1 ADD COLUMN (b INT, c INT, d INT, e INT NOT NULL DEFAULT 0);
+ALTER TABLE t1 ADD UNIQUE INDEX(e);
+ALTER TABLE t1 DROP b, DROP c, DROP d, DROP e;
+DROP TABLE t1;
+
+--echo #
+--echo # MDEV-20565 Assertion on CHANGE COLUMN...SYSTEM VERSIONING
+--echo #
+set @@system_versioning_alter_history = keep;
+CREATE TABLE t (a INT WITHOUT SYSTEM VERSIONING, b INT) ENGINE=InnoDB
+WITH SYSTEM VERSIONING;
+ALTER TABLE t CHANGE COLUMN a alpha INT WITH SYSTEM VERSIONING,
+ALGORITHM=INSTANT;
+DROP TABLE t;
+
+CREATE TABLE t (alpha INT, b INT) ENGINE=InnoDB WITH SYSTEM VERSIONING;
+ALTER TABLE t CHANGE COLUMN alpha a INT WITHOUT SYSTEM VERSIONING,
+ALGORITHM=INSTANT;
+DROP TABLE t;
+set @@system_versioning_alter_history = error;
+
+--echo #
+--echo # MDEV-20117 Assertion 0 failed in row_sel_get_clust_rec_for_mysql
+--echo #
+
+# This is not repeating the bug itself, but demonstrating that both
+# parts of the fix are needed.
+# To repeat the original bug, we should be somehow able to empty
+# the table of user records while purgeable undo log records exist.
+CREATE TABLE t (b INT PRIMARY KEY) ENGINE=InnoDB;
+INSERT INTO t SET b=1;
+ALTER TABLE t ADD COLUMN a INT FIRST, ALGORITHM=INSTANT;
+DELETE FROM t;
+ALTER TABLE t ADD COLUMN c INT, ALGORITHM=INSTANT;
+# If page_cur_delete_rec() emptied the page (and wrongly reset the
+# page type) during the previous ALTER TABLE, the following would hit
+# an assertion failure because of root page type mismatch.
+ALTER TABLE t DROP COLUMN c, ALGORITHM=INSTANT;
+SELECT * FROM t;
+DROP TABLE t;
+
+# The following is nondeterministically repeating the bug in a
+# different scenario: the table is empty at the time the ALTER TABLE
+# is invoked, apparently because purge already processed the records
+# for the DELETE, but not the record for the UPDATE.
+CREATE TABLE t1 (a INT PRIMARY KEY, b INT, c INT, d INT, e INT) ENGINE=InnoDB;
+INSERT INTO t1 SET a=1;
+INSERT INTO t1 SET a=2;
+BEGIN;
+UPDATE t1 SET b=1;
+DELETE FROM t1;
+COMMIT;
+
+ALTER TABLE t1 DROP b, DROP c, DROP d, DROP e;
+--source include/wait_all_purged.inc
+SELECT * FROM t1;
+DROP TABLE t1;
+
+--echo #
+--echo # MDEV-20190 Instant operation fails when add column and collation
+--echo # change on non-indexed column
+--echo #
+
+CREATE TABLE t1 (a CHAR)ENGINE=INNODB;
+ALTER TABLE t1 DEFAULT COLLATE= latin1_general_cs;
+ALTER TABLE t1 ADD COLUMN b INT NOT NULL, MODIFY a CHAR, ALGORITHM=INSTANT;
+SHOW CREATE TABLE t1;
+DROP TABLE t1;
+
+CREATE TABLE t1 (a CHAR NOT NULL) ENGINE=InnoDB ROW_FORMAT=REDUNDANT;
+ALTER TABLE t1 DEFAULT COLLATE = latin1_general_cs;
+ALTER TABLE t1 MODIFY a CHAR, ALGORITHM=INSTANT;
+SHOW CREATE TABLE t1;
+DROP TABLE t1;
+
+CREATE TABLE t1 (a CHAR NOT NULL) CHARSET latin2 COLLATE latin2_bin
+ENGINE=InnoDB ROW_FORMAT=REDUNDANT;
+ALTER TABLE t1 DEFAULT COLLATE = latin2_general_ci;
+ALTER TABLE t1 MODIFY a CHAR, ALGORITHM=INSTANT;
+SHOW CREATE TABLE t1;
+DROP TABLE t1;
+
+--echo #
+--echo # MDEV-21645 SIGSEGV in innobase_get_computed_value
+--echo #
+CREATE TABLE t1 (a INT PRIMARY KEY, b INT, va INTEGER GENERATED ALWAYS AS (a))
+ENGINE=InnoDB;
+INSERT INTO t1 SET a=1, b=NULL;
+ALTER TABLE t1 MODIFY COLUMN b INT FIRST;
+ALTER TABLE t1 ADD UNIQUE INDEX (va);
+DROP TABLE t1;
+
+--echo #
+--echo # MDEV-22651 Assertion dict_col_get_fixed_size...
+--echo # in dict_table_t::init_instant()
+--echo #
+--source include/have_innodb.inc
+CREATE TABLE t (i INT PRIMARY KEY) ENGINE=InnoDB;
+INSERT INTO t SET i=1;
+ALTER TABLE t ADD e CHAR(255) CHARACTER SET UTF32 FIRST, ALGORITHM=INSTANT;
+DROP TABLE t;
+
+--echo #
+--echo # MDEV-23499 Assertion c.same_type(*o) failed
+--echo #
+CREATE TABLE t (pk SERIAL, b TEXT CHARACTER SET utf8) ENGINE=InnoDB;
+ALTER TABLE t MODIFY b TEXT CHARACTER SET utf8mb4 FIRST;
+DROP TABLE t;
+
+--echo #
+--echo # MDEV-23672 Assertion `v.v_indexes.empty()' failed in dict_table_t::instant_column
+--echo #
+create table t1 (
+ col_int integer,
+ col_text text not null,
+ col_int_g integer generated always as (col_int) unique,
+ col_text_g text generated always as (substr(col_text,1,499)) )
+engine innodb row_format = redundant;
+insert into t1 (col_int,col_text) values (0, 'a'), (null, 'b');
+alter table t1 modify column col_text text null, algorithm = instant;
+insert into t1 (col_int,col_text) values (1, null), (null, null);
+update t1 set col_text= 'd';
+select * from t1;
+check table t1;
+drop table t1;
+
+--echo #
+--echo # MDEV-24072 Assertion 'ib_table.n_v_cols' failed
+--echo # in instant_alter_column_possible()
+--echo #
+CREATE TABLE t (a BLOB) ENGINE=InnoDB;
+INSERT INTO t VALUES ('a');
+--error ER_TRUNCATED_WRONG_VALUE
+ALTER TABLE t ADD c INT GENERATED ALWAYS AS (a+1) VIRTUAL, ADD KEY(c);
+--enable_info
+ALTER TABLE t ADD d INT;
+--disable_info
+DROP TABLE t;
+
+--echo #
+--echo # MDEV-28060 Online DDL fails while checking for instant
+--echo # alter condition
+--echo #
+CREATE TABLE t1(f1 CHAR(10) NOT NULL)ROW_FORMAT=REDUNDANT,ENGINE=InnoDB;
+ALTER TABLE t1 ADD COLUMN(f2 INT NOT NULL, f3 INT NOT NULL,
+ f4 INT NOT NULL, f5 INT NOT NULL),
+ CHANGE COLUMN f1 f1 CHAR(10) DEFAULT NULL;
+DROP TABLE t1;
+
+--echo #
+--echo # MDEV-26420 Buffer overflow on instant ADD/DROP of generated column
+--echo #
+CREATE TABLE t1 (i int AS (0) STORED, j INT) ENGINE=InnoDB;
+ALTER TABLE t1 ADD COLUMN i INT GENERATED ALWAYS AS (1), DROP COLUMN i;
+DROP TABLE t1;
+
+--echo # End of 10.4 tests
diff --git a/mysql-test/suite/innodb/t/instant_alter_charset.test b/mysql-test/suite/innodb/t/instant_alter_charset.test
new file mode 100644
index 00000000..5be4f7a5
--- /dev/null
+++ b/mysql-test/suite/innodb/t/instant_alter_charset.test
@@ -0,0 +1,890 @@
+--source include/innodb_row_format.inc
+
+--let $row_format= `SELECT @@GLOBAL.innodb_default_row_format`
+set names utf8;
+
+create table no_rebuild (
+ a char(150) charset utf8mb3 collate utf8mb3_general_ci
+) engine=innodb;
+create table rebuild (
+ a varchar(150) charset ascii
+) engine=innodb;
+
+set @id = (select table_id from information_schema.innodb_sys_tables
+ where name = 'test/no_rebuild');
+select name, prtype, len from information_schema.innodb_sys_columns
+ where table_id = @id;
+select c.prtype, c.len from information_schema.innodb_sys_columns as c inner join information_schema.innodb_sys_tables t on c.table_id = t.table_id
+ where t.name = 'test/rebuild' and c.name = 'a';
+alter table no_rebuild
+ change a a char(150) charset utf8mb3 collate utf8mb3_spanish_ci,
+ algorithm=inplace;
+--error ER_ALTER_OPERATION_NOT_SUPPORTED_REASON
+alter table rebuild
+ change a a varchar(150) charset latin1 not null default 'asdf',
+ algorithm=inplace;
+alter table rebuild
+ change a a varchar(150) charset latin1 not null default 'asdf',
+ algorithm=copy;
+select name, prtype, len from information_schema.innodb_sys_columns
+ where table_id = @id;
+select c.prtype, c.len from information_schema.innodb_sys_columns as c inner join information_schema.innodb_sys_tables t on c.table_id = t.table_id
+ where t.name = 'test/rebuild' and c.name = 'a';
+
+drop table no_rebuild, rebuild;
+
+create table supported_types (
+ id int primary key auto_increment,
+ a varchar(150) charset ascii,
+ b text(150) charset ascii,
+ c text charset ascii,
+ d tinytext charset ascii,
+ e mediumtext charset ascii,
+ f longtext charset ascii
+) engine=innodb;
+
+alter table supported_types
+ convert to charset ascii collate ascii_bin,
+ algorithm=instant;
+
+drop table supported_types;
+
+create table various_cases (
+ a char(150) charset ascii,
+ b varchar(150) as (a) virtual,
+ c char(150) as (a) persistent
+) engine=innodb;
+
+alter table various_cases
+ change a a char(150) charset ascii collate ascii_bin,
+ algorithm=inplace;
+
+--error ER_ALTER_OPERATION_NOT_SUPPORTED_REASON
+alter table various_cases
+ change a a varchar(222),
+ algorithm=inplace;
+
+alter table various_cases
+ change b b varchar(150) as (a) virtual,
+ algorithm=inplace;
+
+--error ER_ALTER_OPERATION_NOT_SUPPORTED
+alter table various_cases
+ change c c char(150) as (a) persistent,
+ algorithm=inplace;
+
+# Can not grow storage in bytes from CHAR
+--error ER_ALTER_OPERATION_NOT_SUPPORTED_REASON
+alter table various_cases
+ modify a char(150) charset utf8mb4,
+ algorithm=instant;
+
+drop table various_cases;
+
+
+create table all_texts (
+ a tinytext charset ascii,
+ b text charset ascii,
+ c mediumtext charset ascii,
+ d longtext charset ascii,
+ footer int
+) engine=innodb;
+
+alter table all_texts
+ convert to charset ascii collate ascii_bin,
+ algorithm=instant;
+
+drop table all_texts;
+
+
+create table all_binaries (
+ a tinyblob,
+ b blob,
+ c mediumblob,
+ d longblob,
+ e varbinary(150),
+ f binary(150)
+) engine=innodb;
+
+--error ER_ALTER_OPERATION_NOT_SUPPORTED_REASON
+alter table all_binaries modify a tinytext, algorithm=instant;
+--error ER_ALTER_OPERATION_NOT_SUPPORTED_REASON
+alter table all_binaries modify b text, algorithm=instant;
+--error ER_ALTER_OPERATION_NOT_SUPPORTED_REASON
+alter table all_binaries modify c mediumtext, algorithm=instant;
+--error ER_ALTER_OPERATION_NOT_SUPPORTED_REASON
+alter table all_binaries modify d longtext, algorithm=instant;
+--error ER_ALTER_OPERATION_NOT_SUPPORTED_REASON
+alter table all_binaries modify e varchar(150), algorithm=instant;
+--error ER_ALTER_OPERATION_NOT_SUPPORTED_REASON
+alter table all_binaries modify f char(150), algorithm=instant;
+
+drop table all_binaries;
+
+create table all_strings (
+ a tinytext,
+ b text,
+ c mediumtext,
+ d longtext,
+ e varchar(150),
+ f char(150)
+) engine=innodb;
+
+--error ER_ALTER_OPERATION_NOT_SUPPORTED_REASON
+alter table all_strings modify a tinyblob, algorithm=instant;
+--error ER_ALTER_OPERATION_NOT_SUPPORTED_REASON
+alter table all_strings modify b blob, algorithm=instant;
+--error ER_ALTER_OPERATION_NOT_SUPPORTED_REASON
+alter table all_strings modify c mediumblob, algorithm=instant;
+--error ER_ALTER_OPERATION_NOT_SUPPORTED_REASON
+alter table all_strings modify d longblob, algorithm=instant;
+--error ER_ALTER_OPERATION_NOT_SUPPORTED_REASON
+alter table all_strings modify e varbinary(150), algorithm=instant;
+--error ER_ALTER_OPERATION_NOT_SUPPORTED_REASON
+alter table all_strings modify f binary(150), algorithm=instant;
+
+--error ER_ALTER_OPERATION_NOT_SUPPORTED_REASON
+alter table all_strings modify a tinytext charset binary, algorithm=instant;
+--error ER_ALTER_OPERATION_NOT_SUPPORTED_REASON
+alter table all_strings modify b text charset binary, algorithm=instant;
+--error ER_ALTER_OPERATION_NOT_SUPPORTED_REASON
+alter table all_strings modify c mediumtext charset binary, algorithm=instant;
+--error ER_ALTER_OPERATION_NOT_SUPPORTED_REASON
+alter table all_strings modify d longtext charset binary, algorithm=instant;
+--error ER_ALTER_OPERATION_NOT_SUPPORTED_REASON
+alter table all_strings modify e varchar(150) charset binary, algorithm=instant;
+--error ER_ALTER_OPERATION_NOT_SUPPORTED_REASON
+alter table all_strings modify f char(150) charset binary, algorithm=instant;
+
+drop table all_strings;
+
+create table key_part_change (
+ a char(150) charset ascii,
+ b char(150) charset ascii,
+ c char(150) charset ascii,
+ unique key ab (a,b)
+) engine=innodb;
+
+--error ER_ALTER_OPERATION_NOT_SUPPORTED_REASON
+alter table key_part_change
+ modify a char(150) charset utf8mb4,
+ drop index ab,
+ add unique key ab(a,c),
+ algorithm=instant;
+
+drop table key_part_change;
+
+create table key_part_change_and_rename (
+ a char(100) charset ascii,
+ b char(100) charset ascii,
+ unique key ab (a,b)
+) engine=innodb;
+
+--error ER_ALTER_OPERATION_NOT_SUPPORTED_REASON
+alter table key_part_change_and_rename
+ change a b char(100) charset utf8mb4,
+ change b a char(100) charset utf8mb4,
+ drop index ab,
+ add unique key ab(a,b),
+ algorithm=instant;
+
+drop table key_part_change_and_rename;
+
+create table enum_and_set (
+ a enum('one', 'two') charset utf8mb3,
+ b set('three', 'four') charset utf8mb3
+) engine=innodb;
+
+--error ER_ALTER_OPERATION_NOT_SUPPORTED_REASON
+alter table enum_and_set
+ modify a enum('one', 'two') charset utf8mb4,
+ algorithm=instant;
+
+--error ER_ALTER_OPERATION_NOT_SUPPORTED_REASON
+alter table enum_and_set
+ modify b enum('three', 'four') charset utf8mb4,
+ algorithm=instant;
+
+drop table enum_and_set;
+
+create table compressed (
+ a varchar(255) compressed charset utf8mb3
+) engine=innodb;
+
+insert into compressed values ('AAA'), ('bbb'), ('CCC');
+
+alter table compressed
+ modify a varchar(255) compressed charset utf8mb4,
+ algorithm=instant;
+
+select * from compressed;
+check table compresed;
+
+drop table compressed;
+
+create table key_part_bug (
+ id int primary key auto_increment,
+ a varchar(150) charset utf8mb3 unique key
+) engine=innodb;
+
+alter table key_part_bug
+ modify a varchar(150) charset utf8mb4,
+ algorithm=instant;
+
+drop table key_part_bug;
+
+
+create table latin1_swedish_special_case (
+ copy1 varchar(150) charset ascii collate ascii_general_ci,
+ copy2 char(150) charset ascii collate ascii_general_ci,
+ instant1 varchar(150) charset ascii collate ascii_general_ci,
+ instant2 char(150) charset ascii collate ascii_general_ci
+) engine=innodb;
+
+select c.name, c.prtype, c.mtype, c.len from information_schema.innodb_sys_columns as c inner join information_schema.innodb_sys_tables t on c.table_id = t.table_id
+ where t.name = 'test/latin1_swedish_special_case';
+alter table latin1_swedish_special_case
+ modify copy1 varchar(150) charset latin1 collate latin1_swedish_ci,
+ modify copy2 char(150) charset latin1 collate latin1_swedish_ci,
+ algorithm=copy;
+--error ER_ALTER_OPERATION_NOT_SUPPORTED_REASON
+alter table latin1_swedish_special_case
+ modify instant1 varchar(150) charset latin1 collate latin1_swedish_ci,
+ modify instant2 char(150) charset latin1 collate latin1_swedish_ci,
+ algorithm=instant;
+alter table latin1_swedish_special_case
+ modify instant1 varchar(150) charset latin1 collate latin1_swedish_ci,
+ modify instant2 char(150) charset latin1 collate latin1_swedish_ci,
+ algorithm=copy;
+select c.name, c.prtype, c.mtype, c.len from information_schema.innodb_sys_columns as c inner join information_schema.innodb_sys_tables t on c.table_id = t.table_id
+ where t.name = 'test/latin1_swedish_special_case';
+alter table latin1_swedish_special_case
+ modify copy1 varchar(150) charset latin1 collate latin1_general_ci,
+ modify copy2 char(150) charset latin1 collate latin1_general_ci,
+ algorithm=copy;
+alter table latin1_swedish_special_case
+ modify instant1 varchar(150) charset latin1 collate latin1_general_ci,
+ modify instant2 char(150) charset latin1 collate latin1_general_ci,
+ algorithm=instant;
+select c.name, c.prtype, c.mtype, c.len from information_schema.innodb_sys_columns as c inner join information_schema.innodb_sys_tables t on c.table_id = t.table_id
+ where t.name = 'test/latin1_swedish_special_case';
+
+drop table latin1_swedish_special_case;
+
+create table regression (a varchar(100) charset utf8mb3 primary key, b int) engine=innodb;
+alter table regression convert to character set utf8mb4;
+drop table regression;
+
+# ROW_FORMAT=DYNAMIC limitation:
+# size in bytes cannot be increased from less of equal that 255 to more than 255
+create table boundary_255 (
+ a varchar(50) charset ascii,
+ b varchar(200) charset ascii,
+ c varchar(300) charset ascii
+) engine=innodb;
+
+--error ER_ALTER_OPERATION_NOT_SUPPORTED_REASON
+alter table boundary_255
+ modify a varchar(50) charset utf8mb3,
+ algorithm=instant;
+alter table boundary_255
+ modify a varchar(50) charset utf8mb3,
+ algorithm=copy;
+
+--error ER_ALTER_OPERATION_NOT_SUPPORTED_REASON
+alter table boundary_255
+ modify b varchar(200) charset utf8mb3,
+ algorithm=instant;
+
+--error ER_ALTER_OPERATION_NOT_SUPPORTED_REASON
+alter table boundary_255
+ modify c varchar(300) charset utf8mb3,
+ algorithm=instant;
+
+drop table boundary_255;
+
+create table boundary_255 (
+ a varchar(70) charset utf8mb3
+) engine=innodb;
+
+if ($row_format == 'redundant') {
+alter table boundary_255
+ modify a varchar(70) charset utf8mb4,
+ algorithm=instant;
+}
+if ($row_format != 'redundant') {
+--error ER_ALTER_OPERATION_NOT_SUPPORTED_REASON
+alter table boundary_255
+ modify a varchar(70) charset utf8mb4,
+ algorithm=instant;
+}
+
+drop table boundary_255;
+
+
+create table t (
+ a char(10) collate utf8mb3_general_ci,
+ b char(70) collate utf8mb3_general_ci,
+ c char(100) collate utf8mb3_general_ci,
+
+ aa char(10) collate utf8mb3_general_ci unique,
+ bb char(70) collate utf8mb3_general_ci unique,
+ cc char(100) collate utf8mb3_general_ci unique,
+
+ d char(10) collate utf8mb3_general_ci,
+ dd char(10) collate utf8mb3_general_ci unique
+) engine=innodb;
+insert into t values
+ (repeat('a', 10), repeat('a', 70), repeat('a', 100),
+ repeat('a', 10), repeat('a', 70), repeat('a', 100),
+ repeat('a', 10), repeat('a', 10)
+);
+if ($row_format != 'redundant') {
+alter table t modify a char(10) collate utf8mb4_general_ci, algorithm=instant;
+check table t;
+alter table t modify b char(70) collate utf8mb4_general_ci, algorithm=instant;
+check table t;
+alter table t modify c char(100) collate utf8mb4_general_ci, algorithm=instant;
+check table t;
+
+alter table t modify aa char(10) collate utf8mb4_general_ci, algorithm=instant;
+check table t;
+alter table t modify bb char(70) collate utf8mb4_general_ci, algorithm=instant;
+check table t;
+alter table t modify cc char(100) collate utf8mb4_general_ci, algorithm=instant;
+check table t;
+
+alter table t modify d char(10) collate utf8mb4_spanish_ci, algorithm=instant;
+--error ER_ALTER_OPERATION_NOT_SUPPORTED_REASON
+alter table t modify dd char(10) collate utf8mb4_spanish_ci, algorithm=instant;
+}
+if ($row_format == 'redundant') {
+--error ER_ALTER_OPERATION_NOT_SUPPORTED_REASON
+alter table t modify a char(10) collate utf8mb4_general_ci, algorithm=instant;
+--error ER_ALTER_OPERATION_NOT_SUPPORTED_REASON
+alter table t modify b char(70) collate utf8mb4_general_ci, algorithm=instant;
+--error ER_ALTER_OPERATION_NOT_SUPPORTED_REASON
+alter table t modify c char(100) collate utf8mb4_general_ci, algorithm=instant;
+
+--error ER_ALTER_OPERATION_NOT_SUPPORTED_REASON
+alter table t modify aa char(10) collate utf8mb4_general_ci, algorithm=instant;
+--error ER_ALTER_OPERATION_NOT_SUPPORTED_REASON
+alter table t modify bb char(70) collate utf8mb4_general_ci, algorithm=instant;
+--error ER_ALTER_OPERATION_NOT_SUPPORTED_REASON
+alter table t modify cc char(100) collate utf8mb4_general_ci, algorithm=instant;
+
+--error ER_ALTER_OPERATION_NOT_SUPPORTED_REASON
+alter table t modify d char(10) collate utf8mb4_spanish_ci, algorithm=instant;
+--error ER_ALTER_OPERATION_NOT_SUPPORTED_REASON
+alter table t modify dd char(10) collate utf8mb4_spanish_ci, algorithm=instant;
+}
+select * from t;
+drop table t;
+
+
+create table fully_compatible (
+ id int auto_increment unique key,
+ from_charset char(255),
+ from_collate char(255),
+ to_charset char(255),
+ to_collate char(255)
+);
+
+insert into fully_compatible (from_charset, from_collate, to_charset, to_collate) values
+ ('utf8mb3', 'utf8mb3_general_ci', 'utf8mb4', 'utf8mb4_general_ci'),
+ ('utf8mb3', 'utf8mb3_bin', 'utf8mb4', 'utf8mb4_bin'),
+ ('utf8mb3', 'utf8mb3_unicode_ci', 'utf8mb4', 'utf8mb4_unicode_ci'),
+ ('utf8mb3', 'utf8mb3_icelandic_ci', 'utf8mb4', 'utf8mb4_icelandic_ci'),
+ ('utf8mb3', 'utf8mb3_latvian_ci', 'utf8mb4', 'utf8mb4_latvian_ci'),
+ ('utf8mb3', 'utf8mb3_romanian_ci', 'utf8mb4', 'utf8mb4_romanian_ci'),
+ ('utf8mb3', 'utf8mb3_slovenian_ci', 'utf8mb4', 'utf8mb4_slovenian_ci'),
+ ('utf8mb3', 'utf8mb3_polish_ci', 'utf8mb4', 'utf8mb4_polish_ci'),
+ ('utf8mb3', 'utf8mb3_estonian_ci', 'utf8mb4', 'utf8mb4_estonian_ci'),
+ ('utf8mb3', 'utf8mb3_spanish_ci', 'utf8mb4', 'utf8mb4_spanish_ci'),
+ ('utf8mb3', 'utf8mb3_swedish_ci', 'utf8mb4', 'utf8mb4_swedish_ci'),
+ ('utf8mb3', 'utf8mb3_turkish_ci', 'utf8mb4', 'utf8mb4_turkish_ci'),
+ ('utf8mb3', 'utf8mb3_czech_ci', 'utf8mb4', 'utf8mb4_czech_ci'),
+ ('utf8mb3', 'utf8mb3_danish_ci', 'utf8mb4', 'utf8mb4_danish_ci'),
+ ('utf8mb3', 'utf8mb3_lithuanian_ci', 'utf8mb4', 'utf8mb4_lithuanian_ci'),
+ ('utf8mb3', 'utf8mb3_slovak_ci', 'utf8mb4', 'utf8mb4_slovak_ci'),
+ ('utf8mb3', 'utf8mb3_spanish2_ci', 'utf8mb4', 'utf8mb4_spanish2_ci'),
+ ('utf8mb3', 'utf8mb3_roman_ci', 'utf8mb4', 'utf8mb4_roman_ci'),
+ ('utf8mb3', 'utf8mb3_persian_ci', 'utf8mb4', 'utf8mb4_persian_ci'),
+ ('utf8mb3', 'utf8mb3_esperanto_ci', 'utf8mb4', 'utf8mb4_esperanto_ci'),
+ ('utf8mb3', 'utf8mb3_hungarian_ci', 'utf8mb4', 'utf8mb4_hungarian_ci'),
+ ('utf8mb3', 'utf8mb3_sinhala_ci', 'utf8mb4', 'utf8mb4_sinhala_ci'),
+ ('utf8mb3', 'utf8mb3_german2_ci', 'utf8mb4', 'utf8mb4_german2_ci'),
+ ('utf8mb3', 'utf8mb3_croatian_mysql561_ci', 'utf8mb4', 'utf8mb4_croatian_mysql561_ci'),
+ ('utf8mb3', 'utf8mb3_unicode_520_ci', 'utf8mb4', 'utf8mb4_unicode_520_ci'),
+ ('utf8mb3', 'utf8mb3_vietnamese_ci', 'utf8mb4', 'utf8mb4_vietnamese_ci'),
+ ('utf8mb3', 'utf8mb3_croatian_ci', 'utf8mb4', 'utf8mb4_croatian_ci'),
+ ('utf8mb3', 'utf8mb3_myanmar_ci', 'utf8mb4', 'utf8mb4_myanmar_ci'),
+ ('utf8mb3', 'utf8mb3_thai_520_w2', 'utf8mb4', 'utf8mb4_thai_520_w2'),
+ ('utf8mb3', 'utf8mb3_general_nopad_ci', 'utf8mb4', 'utf8mb4_general_nopad_ci'),
+ ('utf8mb3', 'utf8mb3_nopad_bin', 'utf8mb4', 'utf8mb4_nopad_bin'),
+ ('utf8mb3', 'utf8mb3_unicode_nopad_ci', 'utf8mb4', 'utf8mb4_unicode_nopad_ci'),
+ ('utf8mb3', 'utf8mb3_unicode_520_nopad_ci', 'utf8mb4', 'utf8mb4_unicode_520_nopad_ci')
+;
+
+let $data_size = `select count(*) from fully_compatible`;
+let $counter = 1;
+
+while ($counter <= $data_size) {
+ let $from_charset = `select from_charset from fully_compatible where id = $counter`;
+ let $from_collate = `select from_collate from fully_compatible where id = $counter`;
+ let $to_charset = `select to_charset from fully_compatible where id = $counter`;
+ let $to_collate = `select to_collate from fully_compatible where id = $counter`;
+
+ eval create table tmp (
+ a varchar(50) charset $from_charset collate $from_collate,
+ b varchar(50) charset $from_charset collate $from_collate primary key
+ ) engine=innodb;
+
+ insert into tmp values ('AAA', 'AAA'), ('bbb', 'bbb');
+
+ eval alter table tmp
+ change a a varchar(50) charset $to_charset collate $to_collate,
+ modify b varchar(50) charset $to_charset collate $to_collate,
+ algorithm=instant;
+
+ check table tmp;
+
+ drop table tmp;
+
+ inc $counter;
+}
+
+drop table fully_compatible;
+
+
+create table compatible_without_index (
+ id int auto_increment unique key,
+ from_charset char(255),
+ from_collate char(255),
+ to_charset char(255),
+ to_collate char(255)
+);
+
+insert into compatible_without_index (from_charset, from_collate, to_charset, to_collate) values
+
+ ('utf8mb3', 'utf8mb3_general_ci', 'utf8mb4', 'utf8mb4_vietnamese_ci'),
+ ('utf8mb3', 'utf8mb3_bin', 'utf8mb4', 'utf8mb4_vietnamese_ci'),
+ ('utf8mb3', 'utf8mb3_general_nopad_ci', 'utf8mb4', 'utf8mb4_vietnamese_ci'),
+ ('utf8mb3', 'utf8mb3_nopad_bin', 'utf8mb4', 'utf8mb4_vietnamese_ci'),
+
+ ('ascii', 'ascii_general_ci', 'ascii', 'ascii_bin'),
+ ('utf8mb3', 'utf8mb3_roman_ci', 'utf8mb3', 'utf8mb3_lithuanian_ci'),
+ ('utf8mb4', 'utf8mb4_thai_520_w2', 'utf8mb4', 'utf8mb4_persian_ci'),
+ ('utf8mb3', 'utf8mb3_myanmar_ci', 'utf8mb4', 'utf8mb4_german2_ci'),
+ ('utf8mb3', 'utf8mb3_general_ci', 'utf8mb3', 'utf8mb3_unicode_ci'),
+ ('latin1', 'latin1_general_cs', 'latin1', 'latin1_general_ci'),
+
+ ('utf16', 'utf16_general_ci', 'utf16', 'utf16_german2_ci')
+;
+
+let $data_size = `select count(*) from compatible_without_index`;
+let $counter = 1;
+
+while ($counter <= $data_size) {
+ let $from_charset = `select from_charset from compatible_without_index where id = $counter`;
+ let $from_collate = `select from_collate from compatible_without_index where id = $counter`;
+ let $to_charset = `select to_charset from compatible_without_index where id = $counter`;
+ let $to_collate = `select to_collate from compatible_without_index where id = $counter`;
+
+ eval create table tmp (
+ a varchar(50) charset $from_charset collate $from_collate,
+ b varchar(50) charset $from_charset collate $from_collate unique key,
+ c varchar(50) charset $from_charset collate $from_collate primary key
+ ) engine=innodb;
+
+ eval alter table tmp
+ change a a varchar(50) charset $to_charset collate $to_collate,
+ algorithm=instant;
+
+ --error ER_ALTER_OPERATION_NOT_SUPPORTED_REASON
+ eval alter table tmp
+ modify b varchar(50) charset $to_charset collate $to_collate,
+ algorithm=instant;
+
+ --error ER_ALTER_OPERATION_NOT_SUPPORTED_REASON
+ eval alter table tmp
+ modify c varchar(50) charset $to_charset collate $to_collate,
+ algorithm=instant;
+
+ drop table tmp;
+
+ inc $counter;
+}
+
+drop table compatible_without_index;
+
+
+create table fully_incompatible (
+ id int auto_increment unique key,
+ from_charset char(255),
+ from_collate char(255),
+ to_charset char(255),
+ to_collate char(255)
+);
+
+insert into fully_incompatible (from_charset, from_collate, to_charset, to_collate) values
+ ('ascii', 'ascii_general_ci', 'utf8mb3', 'utf8mb3_general_ci'),
+ ('ascii', 'ascii_general_ci', 'utf8mb4', 'utf8mb4_general_ci'),
+ ('ascii', 'ascii_general_ci', 'latin1', 'latin1_general_ci'),
+ ('ascii', 'ascii_bin', 'latin1', 'latin1_bin'),
+ ('ascii', 'ascii_nopad_bin', 'latin1', 'latin1_nopad_bin'),
+ ('ascii', 'ascii_general_ci', 'latin2', 'latin2_general_ci'),
+ ('ascii', 'ascii_general_ci', 'latin7', 'latin7_general_ci'),
+ ('ascii', 'ascii_bin', 'koi8u', 'koi8u_bin'),
+ ('ascii', 'ascii_bin', 'ujis', 'ujis_bin'),
+ ('ascii', 'ascii_bin', 'big5', 'big5_bin'),
+ ('ascii', 'ascii_bin', 'gbk', 'gbk_bin'),
+
+ ('ascii', 'ascii_general_ci', 'utf8mb3', 'utf8mb3_swedish_ci'),
+ ('ascii', 'ascii_bin', 'latin1', 'latin1_swedish_ci'),
+ ('ascii', 'ascii_general_nopad_ci', 'latin1', 'latin1_swedish_ci'),
+ ('ascii', 'ascii_nopad_bin', 'latin1', 'latin1_swedish_ci'),
+
+ ('ascii', 'ascii_general_ci', 'koi8u', 'koi8u_bin'),
+ ('ascii', 'ascii_general_nopad_ci', 'koi8u', 'koi8u_bin'),
+ ('ascii', 'ascii_nopad_bin', 'koi8u', 'koi8u_bin'),
+
+ ('ascii', 'ascii_general_ci', 'latin1', 'latin1_swedish_ci'),
+ ('ascii', 'ascii_bin', 'utf8mb3', 'utf8mb3_swedish_ci'),
+ ('ascii', 'ascii_general_nopad_ci', 'utf8mb3', 'utf8mb3_swedish_ci'),
+ ('ascii', 'ascii_nopad_bin', 'utf8mb3', 'utf8mb3_swedish_ci'),
+
+ ('ascii', 'ascii_general_ci', 'utf8mb4', 'utf8mb4_danish_ci'),
+ ('ascii', 'ascii_bin', 'utf8mb4', 'utf8mb4_danish_ci'),
+ ('ascii', 'ascii_general_nopad_ci', 'utf8mb4', 'utf8mb4_danish_ci'),
+ ('ascii', 'ascii_nopad_bin', 'utf8mb4', 'utf8mb4_danish_ci'),
+
+ ('ascii', 'ascii_general_ci', 'gbk', 'gbk_chinese_ci'),
+ ('ascii', 'ascii_general_ci', 'gbk', 'gbk_chinese_nopad_ci'),
+
+ ('ascii', 'ascii_general_ci', 'ujis', 'ujis_japanese_ci'),
+ ('ascii', 'ascii_general_ci', 'big5', 'big5_chinese_ci'),
+ ('ascii', 'ascii_general_ci', 'latin2', 'latin2_croatian_ci'),
+ ('ascii', 'ascii_general_ci', 'latin7', 'latin7_estonian_cs'),
+
+ ('ucs2', 'ucs2_general_ci', 'utf16', 'utf16_general_ci'),
+ ('ucs2', 'ucs2_unicode_ci', 'utf16', 'utf16_unicode_ci'),
+ ('ucs2', 'ucs2_icelandic_ci', 'utf16', 'utf16_icelandic_ci'),
+ ('ucs2', 'ucs2_latvian_ci', 'utf16', 'utf16_latvian_ci'),
+ ('ucs2', 'ucs2_romanian_ci', 'utf16', 'utf16_romanian_ci'),
+ ('ucs2', 'ucs2_slovenian_ci', 'utf16', 'utf16_slovenian_ci'),
+ ('ucs2', 'ucs2_polish_ci', 'utf16', 'utf16_polish_ci'),
+ ('ucs2', 'ucs2_estonian_ci', 'utf16', 'utf16_estonian_ci'),
+ ('ucs2', 'ucs2_spanish_ci', 'utf16', 'utf16_spanish_ci'),
+ ('ucs2', 'ucs2_general_ci', 'utf16', 'utf16_general_ci'),
+ ('ucs2', 'ucs2_myanmar_ci', 'utf16', 'utf16_thai_520_w2'),
+ ('ucs2', 'ucs2_general_ci', 'utf16', 'utf16_unicode_nopad_ci'),
+ ('ucs2', 'ucs2_general_mysql500_ci', 'utf16', 'utf16_spanish2_ci'),
+
+ ('utf8mb4', 'utf8mb4_general_ci', 'utf8mb3', 'utf8mb3_general_ci'),
+ ('utf8mb4', 'utf8mb4_general_ci', 'ascii', 'ascii_general_ci'),
+ ('utf8mb3', 'utf8mb3_general_ci', 'ascii', 'ascii_general_ci'),
+ ('utf8mb3', 'utf8mb3_general_ci', 'latin1', 'latin1_general_ci'),
+ ('utf16', 'utf16_general_ci', 'utf32', 'utf32_general_ci'),
+ ('latin1', 'latin1_general_ci', 'ascii', 'ascii_general_ci'),
+ ('ascii', 'ascii_general_ci', 'swe7', 'swe7_swedish_ci'),
+ ('eucjpms', 'eucjpms_japanese_nopad_ci', 'geostd8', 'geostd8_general_ci'),
+ ('latin1', 'latin1_general_ci', 'utf16', 'utf16_general_ci')
+;
+
+let $data_size = `select count(*) from fully_incompatible`;
+let $counter = 1;
+
+while ($counter <= $data_size) {
+ let $from_charset = `select from_charset from fully_incompatible where id = $counter`;
+ let $from_collate = `select from_collate from fully_incompatible where id = $counter`;
+ let $to_charset = `select to_charset from fully_incompatible where id = $counter`;
+ let $to_collate = `select to_collate from fully_incompatible where id = $counter`;
+
+ eval create table tmp (
+ a varchar(150) charset $from_charset collate $from_collate,
+ b text(150) charset $from_charset collate $from_collate,
+ unique key b_idx (b(150))
+ ) engine=innodb;
+
+ --error ER_ALTER_OPERATION_NOT_SUPPORTED_REASON
+ eval alter table tmp
+ change a a varchar(150) charset $to_charset collate $to_collate,
+ algorithm=instant;
+
+ --error ER_ALTER_OPERATION_NOT_SUPPORTED_REASON
+ eval alter table tmp
+ modify b text charset $to_charset collate $to_collate,
+ algorithm=instant;
+
+ drop table tmp;
+
+ inc $counter;
+}
+
+drop table fully_incompatible;
+
+--echo #
+--echo # MDEV-19284 INSTANT ALTER with ucs2-to-utf16 conversion produces bad data
+--echo #
+
+CREATE TABLE t1 (a VARCHAR(10) CHARACTER SET ucs2, PRIMARY KEY(a)) ENGINE=InnoDB;
+INSERT INTO t1 VALUES ('a'),(0xD800);
+--error ER_TRUNCATED_WRONG_VALUE_FOR_FIELD
+ALTER TABLE t1 ALGORITHM=COPY, MODIFY a VARCHAR(10) CHARACTER SET utf16;
+--error ER_ALTER_OPERATION_NOT_SUPPORTED_REASON
+ALTER TABLE t1 ALGORITHM=INSTANT, MODIFY a VARCHAR(10) CHARACTER SET utf16;
+--enable_info ONCE
+ALTER IGNORE TABLE t1 MODIFY a VARCHAR(10) CHARACTER SET utf16;
+SELECT HEX(a) FROM t1;
+DROP TABLE t1;
+
+--echo #
+--echo # MDEV-19285 INSTANT ALTER from ascii_general_ci to latin1_general_ci produces corrupt data
+--echo #
+
+CREATE TABLE t1 (a VARCHAR(10) CHARACTER SET ascii COLLATE ascii_general_ci, PRIMARY KEY(a)) ENGINE=InnoDB;
+INSERT INTO t1 VALUES ('a'),(0xC0),('b');
+--error ER_TRUNCATED_WRONG_VALUE_FOR_FIELD
+ALTER TABLE t1 ALGORITHM=COPY, MODIFY a VARCHAR(10) CHARACTER SET latin1 COLLATE latin1_general_ci;
+--error ER_ALTER_OPERATION_NOT_SUPPORTED_REASON
+ALTER TABLE t1 ALGORITHM=INSTANT, MODIFY a VARCHAR(10) CHARACTER SET latin1 COLLATE latin1_general_ci;
+--enable_info ONCE
+ALTER IGNORE TABLE t1 MODIFY a VARCHAR(10) CHARACTER SET latin1 COLLATE latin1_general_ci;
+SELECT HEX(a) FROM t1;
+DROP TABLE t1;
+
+
+
+--echo #
+--echo # MDEV-19524 Server crashes in Bitmap<64u>::is_clear_all / Field_longstr::csinfo_change_allows_instant_alter
+--echo #
+
+CREATE TABLE t1 (a VARCHAR(1), UNIQUE(a)) ENGINE=InnoDB;
+--error ER_ALTER_OPERATION_NOT_SUPPORTED_REASON
+ALTER TABLE t1 MODIFY a INT, ADD b INT, ADD UNIQUE (b), ALGORITHM=INSTANT;
+DROP TABLE t1;
+
+
+--echo #
+--echo # MDEV-17301 Change of COLLATE unnecessarily requires ALGORITHM=COPY
+--echo #
+
+create table t (
+ a char(10) collate latin1_general_ci primary key,
+ b char(10) collate latin1_general_ci,
+ c char(10) collate latin1_general_ci,
+ unique key b_key(b)
+) engine=innodb;
+
+insert into t values
+ ('aaa', 'aaa', 'aaa'), ('ccc', 'ccc', 'ccc'), ('bbb', 'bbb', 'bbb');
+
+--error ER_ALTER_OPERATION_NOT_SUPPORTED_REASON
+alter table t modify a char(10) collate latin1_general_cs, algorithm=inplace;
+
+--error ER_ALTER_OPERATION_NOT_SUPPORTED_REASON
+alter table t modify b char(10) collate latin1_general_cs, algorithm=instant;
+alter table t modify b char(10) collate latin1_general_cs, algorithm=nocopy;
+check table t;
+
+alter table t modify c char(10) collate latin1_general_cs, algorithm=instant;
+check table t;
+
+drop table t;
+
+create table t (
+ a varchar(10) collate latin1_general_ci primary key,
+ b varchar(10) collate latin1_general_ci,
+ c varchar(10) collate latin1_general_ci,
+ unique key b_key(b)
+) engine=innodb;
+
+insert into t values
+ ('aaa', 'aaa', 'aaa'), ('ccc', 'ccc', 'ccc'), ('bbb', 'bbb', 'bbb');
+
+--error ER_ALTER_OPERATION_NOT_SUPPORTED_REASON
+alter table t modify a varchar(10) collate latin1_general_cs, algorithm=inplace;
+
+--error ER_ALTER_OPERATION_NOT_SUPPORTED_REASON
+alter table t modify b varchar(10) collate latin1_general_cs, algorithm=instant;
+alter table t modify b varchar(10) collate latin1_general_cs, algorithm=nocopy;
+check table t;
+
+alter table t modify c varchar(10) collate latin1_general_cs, algorithm=instant;
+check table t;
+
+drop table t;
+
+--echo #
+--echo # MDEV-20726: InnoDB: Assertion failure in file data0type.cc line 67
+--echo #
+
+CREATE TABLE t (
+ id int(10) unsigned NOT NULL PRIMARY KEY,
+ a text CHARSET utf8mb3,
+ KEY a_idx(a(1))
+) ENGINE=InnoDB;
+
+INSERT INTO t VALUES (1, 'something in the air');
+ALTER TABLE t MODIFY a text CHARSET utf8mb4;
+
+DROP TABLE t;
+
+
+--echo #
+--echo # MDEV-22899: Assertion `field->col->is_binary() || field->prefix_len % field->col->mbmaxlen == 0' failed in dict_index_add_to_cache
+--echo #
+
+CREATE TABLE t1 (
+ a text CHARACTER SET utf8 DEFAULT NULL,
+ KEY a_key (a(1))
+) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
+INSERT INTO t1 VALUES ();
+ALTER TABLE t1 MODIFY a text DEFAULT NULL;
+DROP TABLE t1;
+
+CREATE TABLE t1 (
+ a text CHARACTER SET utf8 DEFAULT NULL,
+ b int,
+ KEY a_key (b, a(1))
+) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
+INSERT INTO t1 VALUES ();
+ALTER TABLE t1 MODIFY a text DEFAULT NULL;
+DROP TABLE t1;
+
+CREATE TABLE t1 (
+ a char(200) CHARACTER SET utf8 DEFAULT NULL,
+ KEY a_key (a(1))
+) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
+INSERT INTO t1 VALUES ();
+ALTER TABLE t1 MODIFY a text DEFAULT NULL;
+DROP TABLE t1;
+
+CREATE TABLE t1 (
+ a char(200) CHARACTER SET utf8 DEFAULT NULL,
+ b int,
+ KEY a_key (b, a(1))
+) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
+INSERT INTO t1 VALUES ();
+ALTER TABLE t1 MODIFY a text DEFAULT NULL;
+DROP TABLE t1;
+
+CREATE TABLE t1 (
+ a varchar(200) CHARACTER SET utf8 DEFAULT NULL,
+ KEY a_key (a(1))
+) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
+INSERT INTO t1 VALUES ();
+ALTER TABLE t1 MODIFY a text DEFAULT NULL;
+DROP TABLE t1;
+
+CREATE TABLE t1 (
+ a varchar(200) CHARACTER SET utf8 DEFAULT NULL,
+ b int,
+ KEY a_key (b, a(1))
+) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
+INSERT INTO t1 VALUES ();
+ALTER TABLE t1 MODIFY a text DEFAULT NULL;
+DROP TABLE t1;
+
+CREATE TABLE t1 (
+ a varchar(2000) CHARACTER SET utf8 DEFAULT NULL,
+ KEY a_key (a(1))
+) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
+INSERT INTO t1 VALUES ();
+ALTER TABLE t1 MODIFY a text DEFAULT NULL;
+DROP TABLE t1;
+
+CREATE TABLE t1 (
+ a varchar(2000) CHARACTER SET utf8 DEFAULT NULL,
+ b int,
+ KEY a_key (b, a(1))
+) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
+INSERT INTO t1 VALUES ();
+ALTER TABLE t1 MODIFY a text DEFAULT NULL;
+DROP TABLE t1;
+
+--echo #
+--echo # MDEV-23245 Still getting assertion failure in file data0type.cc line 67
+--echo #
+
+CREATE TABLE Foo
+(
+ Bar char(2) CHARACTER SET utf8,
+ KEY Bar (Bar(1))
+) ENGINE = InnoDB;
+ALTER TABLE Foo MODIFY Bar char(2) CHARACTER SET utf8mb4;
+INSERT INTO Foo VALUES ('a');
+DROP TABLE Foo;
+
+CREATE TABLE Foo
+(
+ Bar varchar(2) CHARACTER SET utf8,
+ KEY Bar (Bar(1))
+) ENGINE = InnoDB;
+ALTER TABLE Foo MODIFY Bar varchar(2) CHARACTER SET utf8mb4;
+INSERT INTO Foo VALUES ('a');
+DROP TABLE Foo;
+
+CREATE TABLE Foo
+(
+ Bar text CHARACTER SET utf8,
+ KEY Bar (Bar(1))
+) ENGINE = InnoDB;
+ALTER TABLE Foo MODIFY Bar text CHARACTER SET utf8mb4;
+INSERT INTO Foo VALUES ('a');
+DROP TABLE Foo;
+
+CREATE TABLE t1 (a VARCHAR(2) CHARACTER SET utf8mb3 COLLATE utf8mb3_unicode_ci,
+PRIMARY KEY (a(1)))
+ENGINE=InnoDB;
+SHOW CREATE TABLE t1;
+ALTER TABLE t1 MODIFY a VARCHAR(2)
+CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
+INSERT INTO t1 VALUES ('a');
+DROP TABLE t1;
+
+
+--echo #
+--echo # MDEV-22775 [HY000][1553] Changing name of primary key column with foreign key constraint fails.
+--echo #
+
+create table t1 (id int primary key) engine=innodb default charset=utf8;
+create table t2 (input_id int primary key, id int not null,
+ key a (id),
+ constraint a foreign key (id) references t1 (id)
+)engine=innodb default charset=utf8;
+alter table t1 change id id2 int;
+drop table t2;
+drop table t1;
+
+
+--echo #
+--echo # MDEV-25951 MariaDB crash after ALTER TABLE convert to utf8mb4
+--echo #
+
+CREATE TABLE t1 (id INT PRIMARY KEY, a VARCHAR(32), KEY (a(7))) ENGINE=INNODB DEFAULT CHARSET=UTF8;
+INSERT INTO t1 VALUES (1, 'a1'), (2, 'a1');
+
+--error ER_DUP_ENTRY
+ALTER TABLE t1
+ CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_520_ci,
+ ADD UNIQUE INDEX test_key (a);
+
+ALTER TABLE t1 CONVERT TO CHARACTER SET UTF8MB4 COLLATE UTF8MB4_UNICODE_520_CI;
+CHECK TABLE t1;
+SELECT * FROM t1;
+DROP TABLE t1;
+
+CREATE TABLE t1 (id INT PRIMARY KEY, a CHAR(32), KEY (a(7))) ENGINE=INNODB DEFAULT CHARSET=UTF8;
+INSERT INTO t1 VALUES (1, 'a1'), (2, 'a1');
+
+--error ER_DUP_ENTRY
+ALTER TABLE t1
+ CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_520_ci,
+ ADD UNIQUE INDEX test_key (a);
+
+ALTER TABLE t1 CONVERT TO CHARACTER SET UTF8MB4 COLLATE UTF8MB4_UNICODE_520_CI;
+CHECK TABLE t1;
+SELECT * FROM t1;
+DROP TABLE t1;
diff --git a/mysql-test/suite/innodb/t/instant_alter_crash.test b/mysql-test/suite/innodb/t/instant_alter_crash.test
new file mode 100644
index 00000000..b687664d
--- /dev/null
+++ b/mysql-test/suite/innodb/t/instant_alter_crash.test
@@ -0,0 +1,258 @@
+--source include/have_innodb.inc
+# The embedded server tests do not support restarting.
+--source include/not_embedded.inc
+--source include/have_debug.inc
+--source include/have_debug_sync.inc
+
+FLUSH TABLES;
+
+let INNODB_PAGE_SIZE=`select @@innodb_page_size`;
+let MYSQLD_DATADIR=`select @@datadir`;
+
+--echo #
+--echo # MDEV-11369: Instant ADD COLUMN for InnoDB
+--echo #
+
+CREATE TABLE t1(id INT PRIMARY KEY, c2 INT UNIQUE)
+ENGINE=InnoDB ROW_FORMAT=REDUNDANT;
+CREATE TABLE t2 LIKE t1;
+INSERT INTO t1 VALUES(0,2);
+INSERT INTO t2 VALUES(2,1);
+ALTER TABLE t2 ADD COLUMN (c3 TEXT NOT NULL DEFAULT 'De finibus bonorum');
+BEGIN;
+INSERT INTO t2 VALUES(3,4,'accusantium doloremque laudantium');
+
+connect ddl, localhost, root;
+SET DEBUG_SYNC='innodb_alter_inplace_before_commit SIGNAL ddl WAIT_FOR ever';
+--send
+ALTER TABLE t1 ADD COLUMN (c3 TEXT NOT NULL DEFAULT ' et malorum');
+
+connection default;
+SET DEBUG_SYNC='now WAIT_FOR ddl';
+SET GLOBAL innodb_flush_log_at_trx_commit=1;
+COMMIT;
+
+--source include/kill_mysqld.inc
+disconnect ddl;
+--source include/start_mysqld.inc
+
+SELECT * FROM t1;
+SELECT * FROM t2;
+BEGIN;
+DELETE FROM t1;
+ROLLBACK;
+--source include/wait_all_purged.inc
+
+INSERT INTO t2 VALUES
+(16,1551,'Omnium enim rerum'),(128,1571,' principia parva sunt');
+
+BEGIN;
+UPDATE t1 SET c2=c2+1;
+
+connect ddl, localhost, root;
+SET DEBUG_SYNC='innodb_alter_inplace_before_commit SIGNAL ddl WAIT_FOR ever';
+--send
+ALTER TABLE t2 DROP COLUMN c3, ADD COLUMN c5 TEXT DEFAULT 'naturam abhorrere';
+
+connection default;
+SET DEBUG_SYNC='now WAIT_FOR ddl';
+SET GLOBAL innodb_flush_log_at_trx_commit=1;
+COMMIT;
+
+--source include/kill_mysqld.inc
+disconnect ddl;
+--source include/start_mysqld.inc
+
+SELECT * FROM t1;
+SELECT * FROM t2;
+BEGIN;
+INSERT INTO t1 SET id=1;
+DELETE FROM t2;
+ROLLBACK;
+--source include/wait_all_purged.inc
+
+INSERT INTO t2 VALUES (64,42,'De finibus bonorum'), (347,33101,' et malorum');
+BEGIN;
+DELETE FROM t1;
+
+connect ddl, localhost, root;
+ALTER TABLE t2 DROP COLUMN c3;
+SET DEBUG_SYNC='innodb_alter_inplace_before_commit SIGNAL ddl WAIT_FOR ever';
+--send
+ALTER TABLE t2 ADD COLUMN (c4 TEXT NOT NULL DEFAULT ' et malorum');
+
+connection default;
+SET DEBUG_SYNC='now WAIT_FOR ddl';
+SET GLOBAL innodb_flush_log_at_trx_commit=1;
+COMMIT;
+
+--source include/kill_mysqld.inc
+disconnect ddl;
+--source include/start_mysqld.inc
+
+let SEARCH_FILE= $MYSQLTEST_VARDIR/log/mysqld.1.err;
+let SEARCH_PATTERN= \[Note\] InnoDB: Rolled back recovered transaction ;
+-- source include/search_pattern_in_file.inc
+
+SELECT * FROM t1;
+SELECT * FROM t2;
+BEGIN;
+INSERT INTO t1 SET id=1;
+DELETE FROM t2;
+ROLLBACK;
+--source include/wait_all_purged.inc
+
+FLUSH TABLE t1,t2 FOR EXPORT;
+
+# At this point, t1 is empty and t2 contains a 'default row'.
+
+# The following is based on innodb.table_flags and innodb.dml_purge:
+--perl
+use strict;
+my $ps= $ENV{INNODB_PAGE_SIZE};
+foreach my $table ('t1','t2') {
+my $file= "$ENV{MYSQLD_DATADIR}/test/$table.ibd";
+open(FILE, "<", $file) || die "Unable to open $file\n";
+my $page;
+sysseek(FILE, 3*$ps, 0) || die "Unable to seek $file";
+die "Unable to read $file" unless sysread(FILE, $page, $ps) == $ps;
+print "$table clustered index root page";
+print "(type ", unpack("n", substr($page,24,2)), "):\n";
+print "N_RECS=", unpack("n", substr($page,38+16,2));
+print "; LEVEL=", unpack("n", substr($page,38+26,2)), "\n";
+my @fields=("id","DB_TRX_ID","DB_ROLL_PTR", "c2","c3","c4");
+for (my $offset= 0x65; $offset;
+ $offset= unpack("n", substr($page,$offset-2,2)))
+{
+ print "header=0x", unpack("H*",substr($page,$offset-6,6)), " (";
+ my $n_fields= unpack("n", substr($page,$offset-4,2)) >> 1 & 0x3ff;
+ my $start= 0;
+ my $name;
+ if (unpack("C", substr($page,$offset-3,1)) & 1) {
+ for (my $i= 0; $i < $n_fields; $i++) {
+ my $end= unpack("C", substr($page, $offset-7-$i, 1));
+ print ",\n " if $i;
+ print "$fields[$i]=";
+ if ($end & 0x80) {
+ print "NULL(", ($end & 0x7f) - $start, " bytes)"
+ } else {
+ print "0x", unpack("H*", substr($page,$offset+$start,$end-$start))
+ }
+ $start= $end & 0x7f;
+ }
+ } else {
+ for (my $i= 0; $i < $n_fields; $i++) {
+ my $end= unpack("n", substr($page, $offset-8-2*$i, 2));
+ print ",\n " if $i;
+ if ($i > 2 && !(~unpack("C",substr($page,$offset-6,1)) & 0x30)) {
+ if ($i == 3) {
+ print "BLOB=";
+ $start += 8; # skip the space_id,page_number
+ } else {
+ print "$fields[$i - 1]=";
+ }
+ } else {
+ print "$fields[$i]=";
+ }
+ if ($end & 0x8000) {
+ print "NULL(", ($end & 0x7fff) - $start, " bytes)"
+ } else {
+ print "0x", unpack("H*", substr($page,$offset+$start,($end-$start) & 0x3fff))
+ }
+ $start= $end & 0x3fff;
+ }
+ }
+ print ")\n";
+}
+close(FILE) || die "Unable to close $file\n";
+}
+EOF
+
+UNLOCK TABLES;
+
+DELETE FROM t2;
+--source include/wait_all_purged.inc
+
+--echo #
+--echo # MDEV-24323 Crash on recovery after kill during instant ADD COLUMN
+--echo #
+BEGIN;
+INSERT INTO t1 VALUES(0,0);
+
+connect ddl, localhost, root;
+CREATE TABLE t3(id INT PRIMARY KEY, c2 INT, v2 INT AS(c2) VIRTUAL, UNIQUE(v2))
+ENGINE=InnoDB;
+INSERT INTO t3 SET id=1,c2=1;
+
+SET DEBUG_SYNC='innodb_alter_inplace_before_commit SIGNAL ddl WAIT_FOR ever';
+--send
+ALTER TABLE t3 ADD COLUMN c3 TEXT NOT NULL DEFAULT 'sic transit gloria mundi';
+
+connection default;
+SET DEBUG_SYNC='now WAIT_FOR ddl';
+SET GLOBAL innodb_flush_log_at_trx_commit=1;
+COMMIT;
+
+--source include/kill_mysqld.inc
+disconnect ddl;
+--source include/start_mysqld.inc
+
+SHOW CREATE TABLE t1;
+SHOW CREATE TABLE t2;
+SHOW CREATE TABLE t3;
+DROP TABLE t2,t3;
+
+--echo #
+--echo # MDEV-29440 InnoDB instant ALTER TABLE recovery wrongly uses
+--echo # READ COMMITTED isolation level instead of READ UNCOMMITTED
+--echo #
+CREATE TABLE t2(a INT UNSIGNED PRIMARY KEY) ENGINE=InnoDB;
+INSERT INTO t2 VALUES (1),(2),(3),(4),(5),(6);
+
+BEGIN;
+DELETE FROM t1;
+
+connect ddl, localhost, root;
+SET DEBUG_SYNC='innodb_alter_inplace_before_commit SIGNAL ddl WAIT_FOR ever';
+--send
+ALTER TABLE t2 ADD COLUMN b TINYINT UNSIGNED NOT NULL DEFAULT 42 FIRST;
+
+connection default;
+SET DEBUG_SYNC='now WAIT_FOR ddl';
+SET GLOBAL innodb_flush_log_at_trx_commit=1;
+COMMIT;
+
+--source include/kill_mysqld.inc
+disconnect ddl;
+--source include/start_mysqld.inc
+
+CHECK TABLE t2;
+DROP TABLE t1,t2;
+
+--list_files $MYSQLD_DATADIR/test
+
+--echo #
+--echo # MDEV-26198 Assertion `0' failed in row_log_table_apply_op during
+--echo # ADD PRIMARY KEY or OPTIMIZE TABLE
+--echo #
+CREATE TABLE t1(f1 year default null, f2 year default null,
+ f3 text, f4 year default null, f5 year default null,
+ f6 year default null, f7 year default null,
+ f8 year default null)ENGINE=InnoDB ROW_FORMAT=REDUNDANT;
+INSERT INTO t1 VALUES(1, 1, 1, 1, 1, 1, 1, 1);
+ALTER TABLE t1 ADD COLUMN f9 year default null, ALGORITHM=INPLACE;
+set DEBUG_SYNC="row_log_table_apply1_before SIGNAL con1_insert WAIT_FOR con1_finish";
+send ALTER TABLE t1 ROW_FORMAT=REDUNDANT, ADD COLUMN f10 YEAR DEFAULT NULL, ALGORITHM=INPLACE;
+
+connect(con1,localhost,root,,,);
+SET DEBUG_SYNC="now WAIT_FOR con1_insert";
+INSERT IGNORE INTO t1 (f3) VALUES ( 'b' );
+INSERT IGNORE INTO t1 (f3) VALUES ( 'l' );
+SET DEBUG_SYNC="now SIGNAL con1_finish";
+
+connection default;
+reap;
+disconnect con1;
+SET DEBUG_SYNC=RESET;
+CHECK TABLE t1;
+DROP TABLE t1;
diff --git a/mysql-test/suite/innodb/t/instant_alter_debug.combinations b/mysql-test/suite/innodb/t/instant_alter_debug.combinations
new file mode 100644
index 00000000..5f98b128
--- /dev/null
+++ b/mysql-test/suite/innodb/t/instant_alter_debug.combinations
@@ -0,0 +1,6 @@
+[redundant]
+innodb_default_row_format=redundant
+innodb_stats_persistent=off
+[dynamic]
+innodb_default_row_format=dynamic
+innodb_stats_persistent=off
diff --git a/mysql-test/suite/innodb/t/instant_alter_debug.test b/mysql-test/suite/innodb/t/instant_alter_debug.test
new file mode 100644
index 00000000..d9ef7b06
--- /dev/null
+++ b/mysql-test/suite/innodb/t/instant_alter_debug.test
@@ -0,0 +1,609 @@
+--source include/have_innodb.inc
+--source include/have_debug.inc
+--source include/have_debug_sync.inc
+--source include/have_sequence.inc
+
+SET @old_instant=
+(SELECT variable_value FROM information_schema.global_status
+WHERE variable_name = 'innodb_instant_alter_column');
+
+CREATE TABLE t1 (
+ pk INT AUTO_INCREMENT PRIMARY KEY,
+ c1 INT,
+ c2 VARCHAR(255),
+ c3 VARCHAR(255),
+ c4 INT,
+ c5 INT,
+ c6 INT,
+ c7 VARCHAR(255),
+ c8 TIMESTAMP NULL
+) ENGINE=InnoDB;
+INSERT INTO t1 VALUES (NULL,1,NULL,'foo',NULL,1,NULL,NULL,'2011-11-11 00:00:00');
+ALTER TABLE t1 ADD COLUMN f INT;
+REPLACE INTO t1 (c7) VALUES ('bar');
+
+CREATE TABLE t2 (i INT PRIMARY KEY) ENGINE=InnoDB;
+INSERT INTO t2 VALUES (-1),(1);
+ALTER TABLE t2 ADD COLUMN j INT;
+BEGIN;
+DELETE FROM t2;
+ROLLBACK;
+TRUNCATE TABLE t2;
+INSERT INTO t2 VALUES (1,2);
+
+CREATE TABLE t3 (pk INT AUTO_INCREMENT PRIMARY KEY) ENGINE=InnoDB;
+INSERT INTO t3 () VALUES ();
+ALTER TABLE t3 ADD COLUMN f INT;
+UPDATE t3 SET pk = DEFAULT;
+SELECT * FROM t3;
+
+CREATE TABLE t4 (pk INT PRIMARY KEY) ENGINE=InnoDB;
+INSERT INTO t4 VALUES (0);
+ALTER TABLE t4 ADD COLUMN b INT;
+SELECT COUNT(*)>0 FROM INFORMATION_SCHEMA.COLUMNS
+LEFT JOIN t4 ON (NUMERIC_SCALE = pk);
+ALTER TABLE t4 ADD COLUMN c INT;
+
+CREATE TABLE t5 (i INT, KEY(i)) ENGINE=InnoDB;
+INSERT INTO t5 VALUES (-42);
+ALTER TABLE t5 ADD UNIQUE ui(i);
+ALTER TABLE t5 ADD COLUMN i2 INT, DROP INDEX i;
+
+CREATE TABLE t6 (i INT NOT NULL) ENGINE=InnoDB;
+INSERT INTO t6 VALUES (0);
+ALTER TABLE t6 ADD COLUMN j INT;
+TRUNCATE TABLE t6;
+INSERT INTO t6 VALUES (1,2);
+
+CREATE TABLE t7 (i INT) ENGINE=InnoDB;
+INSERT INTO t7 VALUES (1),(2),(3),(4),(5);
+ALTER TABLE t7 ADD t TEXT DEFAULT '';
+
+CREATE TABLE t8 (i INT) ENGINE=InnoDB ROW_FORMAT=REDUNDANT;
+INSERT INTO t8 VALUES (NULL);
+ALTER TABLE t8 ADD c CHAR(3);
+SET DEBUG_SYNC='row_log_table_apply1_before SIGNAL rebuilt WAIT_FOR dml';
+--send
+ALTER TABLE t8 FORCE;
+connect (dml,localhost,root,,);
+SET DEBUG_SYNC='now WAIT_FOR rebuilt';
+BEGIN;
+INSERT INTO t8 SET i=1;
+UPDATE t8 SET i=ISNULL(i);
+ROLLBACK;
+SET DEBUG_SYNC='now SIGNAL dml';
+connection default;
+reap;
+SET DEBUG_SYNC='RESET';
+
+CREATE TABLE t9 (
+ pk INT AUTO_INCREMENT PRIMARY KEY,
+ c1 BIGINT UNSIGNED,
+ c2 TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP,
+ c3 BIGINT,
+ c4 VARCHAR(257) CHARACTER SET utf8,
+ c5 TINYINT UNSIGNED,
+ c6 TINYINT,
+ c7 VARCHAR(257) CHARACTER SET latin1,
+ c8 VARCHAR(257) CHARACTER SET binary
+) ENGINE=InnoDB;
+INSERT INTO t9 () VALUES ();
+ALTER TABLE t9 ADD COLUMN IF NOT EXISTS t TIMESTAMP NULL;
+SET DEBUG_SYNC='row_log_table_apply1_before SIGNAL rebuilt WAIT_FOR dml';
+--send
+OPTIMIZE TABLE t9;
+connection dml;
+SET DEBUG_SYNC='now WAIT_FOR rebuilt';
+BEGIN;
+INSERT INTO t9 () VALUES (),();
+UPDATE t9 SET t=current_timestamp();
+ROLLBACK;
+SET DEBUG_SYNC='now SIGNAL dml';
+disconnect dml;
+connection default;
+reap;
+SET DEBUG_SYNC='RESET';
+
+CREATE TABLE t10 (pk INT DEFAULT 0 KEY) ENGINE=InnoDB;
+INSERT INTO t10 (pk) VALUES (1);
+ALTER TABLE t10 ADD c INT;
+TRUNCATE TABLE t10;
+INSERT INTO t10 VALUES (1,1),(2,2);
+ALTER TABLE t10 FORCE;
+
+CREATE TABLE t11 (
+ c01 enum('a','b'),
+ c02 bit,
+ c03 blob,
+ c04 enum('c','d'),
+ c05 blob,
+ c06 decimal,
+ c07 char(1),
+ c08 int,
+ c09 char(1),
+ c10 set('e','f'),
+ c11 char(1),
+ c12 float,
+ c13 bit,
+ c14 char(1),
+ c15 int,
+ c16 float,
+ c17 decimal,
+ c18 char(1) CHARACTER SET utf8 not null default '',
+ c19 float,
+ c20 set('g','h'),
+ c21 char(1),
+ c22 int,
+ c23 int,
+ c24 int,
+ c25 set('i','j'),
+ c26 decimal,
+ c27 float,
+ c28 char(1),
+ c29 int,
+ c30 enum('k','l'),
+ c31 decimal,
+ c32 char(1),
+ c33 decimal,
+ c34 bit,
+ c35 enum('m','n'),
+ c36 set('o','p'),
+ c37 enum('q','r'),
+ c38 blob,
+ c39 decimal,
+ c40 blob not null default '',
+ c41 char(1),
+ c42 int,
+ c43 float,
+ c44 float,
+ c45 enum('s','t'),
+ c46 decimal,
+ c47 set('u','v'),
+ c48 enum('w','x'),
+ c49 set('y','z'),
+ c50 float
+) ENGINE=InnoDB;
+INSERT INTO t11 () VALUES ();
+ALTER TABLE t11 ADD COLUMN f INT;
+INSERT INTO t11 () VALUES ();
+UPDATE t11 SET c22 = 1;
+
+--source include/wait_all_purged.inc
+DROP TABLE t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,t11;
+
+--echo #
+--echo # MDEV-15060 Assertion in row_log_table_apply_op after instant ADD
+--echo # when the table is emptied during subsequent ALTER TABLE
+--echo #
+
+CREATE TABLE t1 (a INT) ENGINE=InnoDB;
+INSERT INTO t1 VALUES (NULL);
+ALTER TABLE t1 ADD COLUMN b INT NOT NULL;
+connect stop_purge,localhost,root;
+START TRANSACTION WITH CONSISTENT SNAPSHOT;
+connect ddl,localhost,root,,test;
+DELETE FROM t1;
+INSERT INTO t1 VALUES(1, 2);
+SET DEBUG_SYNC='row_log_table_apply1_before SIGNAL copied WAIT_FOR logged';
+send ALTER TABLE t1 FORCE;
+connection default;
+SET DEBUG_SYNC='now WAIT_FOR copied';
+
+BEGIN;
+INSERT INTO t1 SET b=1;
+ROLLBACK;
+connection stop_purge;
+COMMIT;
+connection default;
+
+# Wait for purge to empty the table.
+let $wait_all_purged=1;
+--source include/wait_all_purged.inc
+let $wait_all_purged=0;
+
+SET DEBUG_SYNC='now SIGNAL logged';
+connection ddl;
+reap;
+connection default;
+DROP TABLE t1;
+SET DEBUG_SYNC='RESET';
+
+--echo #
+--echo # MDEV-16131 Assertion failed in dict_index_t::instant_field_value()
+--echo #
+CREATE TABLE t1 (a INT PRIMARY KEY) ENGINE=InnoDB;
+INSERT INTO t1 SET a=0;
+ALTER TABLE t1 ADD COLUMN b INT NOT NULL DEFAULT 2, ADD COLUMN c INT;
+
+DELIMITER $$;
+BEGIN NOT ATOMIC
+ DECLARE c TEXT DEFAULT(SELECT CONCAT('ALTER TABLE t1 ADD (c',
+ GROUP_CONCAT(seq SEPARATOR ' INT, c'), ' INT), ALGORITHM=INSTANT;') FROM seq_1_to_130);
+ EXECUTE IMMEDIATE c;
+END;
+$$
+DELIMITER ;$$
+
+connection stop_purge;
+START TRANSACTION WITH CONSISTENT SNAPSHOT;
+
+connection default;
+DELETE FROM t1;
+
+connection ddl;
+SET DEBUG_SYNC='row_log_table_apply1_before SIGNAL copied WAIT_FOR logged';
+send ALTER TABLE t1 FORCE;
+
+connection default;
+SET DEBUG_SYNC = 'now WAIT_FOR copied';
+connection stop_purge;
+COMMIT;
+connection default;
+let $wait_all_purged = 1;
+--source include/wait_all_purged.inc
+let $wait_all_purged = 0;
+INSERT INTO t1 SET a=1;
+INSERT INTO t1 SET a=2,b=3,c=4;
+SET DEBUG_SYNC = 'now SIGNAL logged';
+
+connection ddl;
+reap;
+
+connection default;
+SET DEBUG_SYNC = RESET;
+SELECT a, b, c FROM t1;
+ALTER TABLE t1 DROP b, ALGORITHM=INSTANT;
+connection stop_purge;
+START TRANSACTION WITH CONSISTENT SNAPSHOT;
+
+connection default;
+DELETE FROM t1;
+
+connection ddl;
+SET DEBUG_SYNC='row_log_table_apply1_before SIGNAL copied WAIT_FOR logged';
+send ALTER TABLE t1 ADD COLUMN b INT NOT NULL DEFAULT 2 AFTER a, FORCE;
+
+connection default;
+SET DEBUG_SYNC = 'now WAIT_FOR copied';
+disconnect stop_purge;
+let $wait_all_purged = 1;
+--source include/wait_all_purged.inc
+let $wait_all_purged = 0;
+INSERT INTO t1 SET a=1;
+INSERT INTO t1 SET a=2,c=4;
+SET DEBUG_SYNC = 'now SIGNAL logged';
+
+connection ddl;
+reap;
+UPDATE t1 SET b = b + 1 WHERE a = 2;
+
+connection default;
+SET DEBUG_SYNC = RESET;
+SELECT a, b, c FROM t1;
+
+--echo #
+--echo # MDEV-15872 Crash in online ALTER TABLE...ADD PRIMARY KEY
+--echo # after instant ADD COLUMN ... NULL
+--echo #
+ALTER TABLE t1 ADD COLUMN d INT, ALGORITHM=INSTANT;
+UPDATE t1 SET d=1;
+
+connection ddl;
+SET DEBUG_SYNC='row_log_table_apply1_before SIGNAL copied WAIT_FOR logged';
+send ALTER TABLE t1 DROP PRIMARY KEY, ADD PRIMARY KEY (a,d);
+
+connection default;
+SET DEBUG_SYNC = 'now WAIT_FOR copied';
+BEGIN;
+INSERT INTO t1 SET a=3;
+ROLLBACK;
+SET DEBUG_SYNC = 'now SIGNAL logged';
+
+connection ddl;
+reap;
+disconnect ddl;
+
+connection default;
+SET DEBUG_SYNC = RESET;
+SELECT a, b, c, d FROM t1;
+DROP TABLE t1;
+
+--echo #
+--echo # MDEV-19916 Corruption after instant ADD/DROP and shrinking the tree
+--echo #
+CREATE TABLE t1 (a INT PRIMARY KEY) ENGINE=InnoDB;
+
+# Create an index tree with 2 levels of node pointer pages.
+
+SET @old_limit = @@innodb_limit_optimistic_insert_debug;
+SET GLOBAL innodb_limit_optimistic_insert_debug = 2;
+INSERT INTO t1 VALUES (1),(5),(4),(3),(2);
+SET GLOBAL innodb_limit_optimistic_insert_debug = @old_limit;
+
+ALTER TABLE t1 ADD COLUMN b INT, ALGORITHM=INSTANT;
+
+SET @old_defragment = @@innodb_defragment;
+SET GLOBAL innodb_defragment = 1;
+OPTIMIZE TABLE t1;
+SET GLOBAL innodb_defragment = @old_defragment;
+
+# Exploit MDEV-17468 to force the table definition to be reloaded
+ALTER TABLE t1 ADD vb INT AS (b) VIRTUAL;
+CHECK TABLE t1;
+SELECT * FROM t1;
+DROP TABLE t1;
+
+--echo #
+--echo # MDEV-21045 AddressSanitizer: use-after-poison in mem_heap_dup / row_log_table_get_pk_col
+--echo #
+CREATE TABLE t1 (a TEXT) ENGINE = InnoDB ROW_FORMAT=REDUNDANT;
+INSERT INTO t1 (a) VALUES ('foo');
+
+ALTER TABLE t1 ADD COLUMN b INT DEFAULT 0,algorithm=instant;
+
+--connect (con2,localhost,root,,test)
+SET DEBUG_SYNC='innodb_inplace_alter_table_enter SIGNAL onlinealter WAIT_FOR update';
+--send
+ALTER TABLE t1 ADD PRIMARY KEY (b);
+
+--connection default
+SET DEBUG_SYNC='now WAIT_FOR onlinealter';
+UPDATE t1 SET b = 1;
+SET DEBUG_SYNC='now SIGNAL update';
+
+--connection con2
+--reap
+
+--connection default
+DROP TABLE t1;
+
+--echo #
+--echo # MDEV-21658 Error on online ADD PRIMARY KEY after instant DROP/reorder
+--echo #
+
+CREATE TABLE t1 (a INT, b INT, c INT, col INT) ENGINE=InnoDB;
+INSERT INTO t1 () VALUES ();
+ALTER TABLE t1 DROP b, DROP c, DROP col;
+ALTER TABLE t1 ADD COLUMN col INT;
+ALTER TABLE t1 DROP a, DROP col, ADD COLUMN b INT;
+
+--connection con2
+SET SQL_MODE= '';
+SET DEBUG_SYNC = 'row_log_table_apply1_before SIGNAL scanned WAIT_FOR dml';
+send ALTER TABLE t1 ADD PRIMARY KEY(b);
+
+--connection default
+SET DEBUG_SYNC = 'now WAIT_FOR scanned';
+UPDATE t1 SET b = 1;
+SET DEBUG_SYNC = 'now SIGNAL dml';
+--connection con2
+reap;
+--connection default
+SELECT * FROM t1;
+
+SET DEBUG_SYNC='RESET';
+--disconnect con2
+DROP TABLE t1;
+
+--echo #
+--echo # MDEV-24653 Assertion block->page.id.page_no() == index->page failed
+--echo # in innobase_add_instant_try()
+--echo #
+
+SET @saved_limit = @@GLOBAL.innodb_limit_optimistic_insert_debug;
+SET GLOBAL innodb_limit_optimistic_insert_debug = 2;
+
+CREATE TABLE t1 (a INT PRIMARY KEY) ENGINE=InnoDB;
+INSERT INTO t1 VALUES (1),(2),(3),(4);
+ALTER TABLE t1 ADD COLUMN b INT;
+DELETE FROM t1;
+--source include/wait_all_purged.inc
+ALTER TABLE t1 ADD COLUMN c INT;
+
+SELECT * FROM t1;
+DROP TABLE t1;
+SET GLOBAL innodb_limit_optimistic_insert_debug = @saved_limit;
+
+--echo #
+--echo # MDEV-24796 Assertion page_has_next... failed
+--echo # in btr_pcur_store_position()
+--echo #
+
+CREATE TABLE t1 (c INT KEY) ENGINE=InnoDB;
+INSERT INTO t1 VALUES(1),(2);
+SET GLOBAL innodb_limit_optimistic_insert_debug=2;
+ALTER TABLE t1 ADD COLUMN d INT;
+DELETE FROM t1;
+--source include/wait_all_purged.inc
+SELECT * FROM t1 WHERE c<>1 ORDER BY c DESC;
+DROP TABLE t1;
+
+SET GLOBAL innodb_limit_optimistic_insert_debug = @saved_limit;
+
+--echo #
+--echo # MDEV-24620 ASAN heap-buffer-overflow in btr_pcur_restore_position()
+--echo #
+
+CREATE TABLE t1 (a VARCHAR(1) PRIMARY KEY) ENGINE=InnoDB;
+INSERT INTO t1 VALUES (1);
+connect (stop_purge,localhost,root,,);
+START TRANSACTION WITH CONSISTENT SNAPSHOT;
+
+connection default;
+ALTER TABLE t1 ADD c INT;
+BEGIN;
+DELETE FROM t1;
+
+connect (dml,localhost,root,,test);
+SET DEBUG_SYNC='row_mysql_handle_errors SIGNAL s1 WAIT_FOR s2';
+send UPDATE t1 SET c=1;
+
+connection default;
+SET DEBUG_SYNC='now WAIT_FOR s1';
+COMMIT;
+
+connection stop_purge;
+COMMIT;
+disconnect stop_purge;
+
+connection default;
+let $wait_all_purged = 1;
+--source include/wait_all_purged.inc
+let $wait_all_purged = 0;
+SET DEBUG_SYNC='now SIGNAL s2';
+
+connection dml;
+reap;
+disconnect dml;
+
+connection default;
+--source include/wait_all_purged.inc
+SET DEBUG_SYNC=RESET;
+DROP TABLE t1;
+
+--echo # End of 10.3 tests
+
+--echo #
+--echo # MDEV-17899 Assertion failures on rollback of instant ADD/DROP
+--echo # MDEV-18098 Crash after rollback of instant DROP COLUMN
+--echo #
+
+SET @save_dbug = @@SESSION.debug_dbug;
+SET debug_dbug='+d,ib_commit_inplace_fail_1';
+CREATE TABLE t1 (a int, b int) ENGINE=InnoDB;
+INSERT INTO t1 VALUES (1,2);
+--error ER_INTERNAL_ERROR
+ALTER TABLE t1 DROP COLUMN b;
+--error ER_INTERNAL_ERROR
+ALTER TABLE t1 DROP COLUMN b;
+--error ER_INTERNAL_ERROR
+ALTER TABLE t1 ADD COLUMN c INT;
+SELECT * FROM t1;
+DROP TABLE t1;
+
+CREATE TABLE t1 (a int, b int) ENGINE=InnoDB;
+--error ER_INTERNAL_ERROR
+ALTER TABLE t1 ADD COLUMN c INT;
+BEGIN;
+INSERT INTO t1 VALUES(1, 1);
+ROLLBACK;
+--error ER_INTERNAL_ERROR
+ALTER TABLE t1 DROP COLUMN b;
+INSERT INTO t1 values (1,1);
+SELECT * FROM t1;
+DROP TABLE t1;
+
+SET debug_dbug = @save_dbug;
+
+--echo #
+--echo # MDEV-24512 Assertion failed in rec_is_metadata()
+--echo # in btr_discard_only_page_on_level()
+--echo #
+
+SET @save_limit= @@GLOBAL.innodb_limit_optimistic_insert_debug;
+SET GLOBAL innodb_limit_optimistic_insert_debug=2;
+CREATE TABLE t1 (c CHAR(1) UNIQUE) ENGINE=InnoDB;
+
+ALTER TABLE t1 ADD c2 INT NOT NULL DEFAULT 0 FIRST;
+--error ER_DUP_ENTRY
+INSERT INTO t1 (c) VALUES ('x'),('d'),('r'),('f'),('y'),('u'),('m'),('d');
+SET GLOBAL innodb_limit_optimistic_insert_debug=@save_limit;
+SELECT * FROM t1;
+DROP TABLE t1;
+
+--echo #
+--echo # MDEV-25236 Online log apply fails for ROW_FORMAT=REDUNDANT tables
+--echo #
+
+CREATE TABLE t1
+(a INT NOT NULL, b INT, c INT, d INT, e INT, f INT, g INT, h INT, i TEXT)
+ENGINE=InnoDB;
+INSERT INTO t1 VALUES(1, 2, 3, 4, 5, 6, 7, 8, "test");
+ALTER TABLE t1 MODIFY a INT NULL;
+
+SET DEBUG_SYNC='innodb_inplace_alter_table_enter SIGNAL alter WAIT_FOR go';
+send ALTER TABLE t1 ADD PRIMARY KEY (a);
+connect(con1,localhost,root,,);
+set DEBUG_SYNC='now WAIT_FOR alter';
+BEGIN;
+INSERT INTO t1 SET a=0, i=REPEAT('1', 10000);
+ROLLBACK;
+set DEBUG_SYNC='now SIGNAL go';
+connection default;
+reap;
+
+SELECT * FROM t1;
+DROP TABLE t1;
+SET DEBUG_SYNC=RESET;
+
+--echo #
+--echo # MDEV-27962 Instant DDL downgrades the MDL when table is empty
+--echo #
+CREATE TABLE t1(f1 INT NOT NULL, f2 INT NOT NULL)ENGINE=InnoDB;
+SET DEBUG_SYNC="alter_table_inplace_after_lock_downgrade SIGNAL try_insert WAIT_FOR alter_progress";
+send ALTER TABLE t1 ADD INDEX(f1), ADD INDEX(f2);
+connection con1;
+SET SESSION lock_wait_timeout=1;
+SET DEBUG_SYNC="now WAIT_FOR try_insert";
+--error ER_LOCK_WAIT_TIMEOUT
+INSERT INTO t1 VALUES(1, 2);
+SET DEBUG_SYNC="now SIGNAL alter_progress";
+disconnect con1;
+connection default;
+reap;
+DROP TABLE t1;
+SET DEBUG_SYNC=reset;
+
+--echo # End of 10.4 tests
+
+--echo #
+--echo # MDEV-22867 Assertion instant.n_core_fields == n_core_fields
+--echo # in dict_index_t::instant_add_field
+--echo #
+
+CREATE TABLE t1 (a INT PRIMARY KEY, b INT UNIQUE) ENGINE=InnoDB;
+INSERT INTO t1 SET a=1;
+
+connect (prevent_purge,localhost,root,,);
+START TRANSACTION WITH CONSISTENT SNAPSHOT;
+connection default;
+ALTER TABLE t1 ADD COLUMN c INT;
+DELETE FROM t1;
+
+connect (con2,localhost,root,,test);
+# FIXME: If this is implemented then also i->online_log must be checked in
+# dict_index_t::must_avoid_clear_instant_add(). See the comment there.
+--error ER_ALTER_OPERATION_NOT_SUPPORTED
+ALTER TABLE t1 DROP b, ADD INDEX(c), ALGORITHM=NOCOPY;
+SET DEBUG_SYNC='innodb_inplace_alter_table_enter SIGNAL ddl WAIT_FOR emptied';
+send ALTER TABLE t1 DROP b;
+
+connection default;
+SET DEBUG_SYNC='now WAIT_FOR ddl';
+BEGIN;
+INSERT INTO t1 SET a=1;
+
+connection prevent_purge;
+COMMIT;
+disconnect prevent_purge;
+
+connection default;
+ROLLBACK;
+SELECT * FROM t1;
+SET DEBUG_SYNC='now SIGNAL emptied';
+
+connection con2;
+reap;
+disconnect con2;
+connection default;
+ALTER TABLE t1 DROP c;
+INSERT INTO t1 VALUES (2),(3),(4);
+CHECK TABLE t1;
+DROP TABLE t1;
+SET DEBUG_SYNC=RESET;
+
+--echo # End of 10.5 tests
+
+SELECT variable_value-@old_instant instants
+FROM information_schema.global_status
+WHERE variable_name = 'innodb_instant_alter_column';
diff --git a/mysql-test/suite/innodb/t/instant_alter_extend.combinations b/mysql-test/suite/innodb/t/instant_alter_extend.combinations
new file mode 100644
index 00000000..1465bf59
--- /dev/null
+++ b/mysql-test/suite/innodb/t/instant_alter_extend.combinations
@@ -0,0 +1,5 @@
+[latin1]
+character-set-server=latin1
+
+[utf8]
+character-set-server=utf8
diff --git a/mysql-test/suite/innodb/t/instant_alter_extend.test b/mysql-test/suite/innodb/t/instant_alter_extend.test
new file mode 100644
index 00000000..7258ba6d
--- /dev/null
+++ b/mysql-test/suite/innodb/t/instant_alter_extend.test
@@ -0,0 +1,258 @@
+--source include/have_innodb.inc
+--source include/innodb_row_format.inc
+--source include/maybe_debug.inc
+
+-- echo #
+-- echo # MDEV-15563: Instant ROW_FORMAT=REDUNDANT column type change&extension
+-- echo # (reverted in MDEV-18627)
+-- echo #
+
+# Use character-set-server in test db
+create database best;
+use best;
+
+set default_storage_engine=innodb;
+set @bigval= repeat('0123456789', 30);
+
+delimiter ~~;
+create procedure check_table(table_name varchar(255))
+begin
+ select table_id into @table_id
+ from information_schema.innodb_sys_tables
+ where name = concat('best/', table_name);
+ select name, mtype, hex(prtype) as prtype, len
+ from information_schema.innodb_sys_columns
+ where table_id = @table_id;
+end~~
+delimiter ;~~
+
+
+--echo # VARCHAR -> CHAR, VARBINARY -> BINARY conversion
+set @bigval= repeat('0123456789', 20);
+
+create table t (a varchar(300));
+--error ER_ALTER_OPERATION_NOT_SUPPORTED_REASON
+alter table t modify a char(255), algorithm=instant;
+alter table t modify a char(255), algorithm=copy;
+
+create or replace table t (a varchar(200));
+insert into t values (@bigval);
+insert into t values ('z');
+if ($have_debug) {
+--disable_query_log
+# This should not be reachable.
+set @save_debug= @@SESSION.debug_dbug;
+set debug_dbug= '+d,ib_instant_error';
+--enable_query_log
+}
+--enable_info
+alter table t modify a char(200);
+--disable_info
+select count(a) from t where a = @bigval;
+select a, length(a) from t where a = 'z';
+
+check table t extended;
+call check_table('t');
+
+--echo # CHAR enlargement
+--enable_info
+alter table t modify a char(220);
+--disable_info
+select count(a) from t where a = @bigval;
+select a, length(a) from t where a = 'z';
+
+check table t extended;
+call check_table('t');
+
+--enable_info
+ALTER TABLE t CHANGE COLUMN a a CHAR(230) BINARY;
+ALTER TABLE t ADD COLUMN b INT FIRST;
+ALTER TABLE t DROP b;
+--disable_info
+
+check table t extended;
+call check_table('t');
+
+--echo # Convert from VARCHAR to a bigger CHAR
+--enable_info
+alter table t modify a varchar(200);
+alter table t modify a char(255);
+--disable_info
+select count(a) from t where a = @bigval;
+select a, length(a) from t where a = 'z';
+
+select * from t;
+check table t extended;
+call check_table('t');
+
+--echo # BINARY/VARBINARY test
+create or replace table t (a varbinary(300));
+insert into t values(NULL);
+--enable_info
+alter table t modify a binary(255);
+--disable_info
+
+create or replace table t (a varbinary(200));
+insert into t values (@bigval);
+insert into t values ('z');
+--enable_info
+alter table t modify a binary(200);
+--disable_info
+select count(a) from t where a = @bigval;
+select length(a) from t where left(a, 1) = 'z';
+
+check table t extended;
+call check_table('t');
+
+--echo # BINARY enlargement
+--enable_info
+alter table t modify a binary(220);
+--disable_info
+
+check table t extended;
+call check_table('t');
+
+--echo # Convert from VARBINARY to a bigger BINARY
+--enable_info
+alter table t modify a varbinary(220);
+alter table t modify a binary(255);
+--disable_info
+select count(a) from t where a = @bigval;
+select a, length(a) from t where a = 'z';
+
+select * from t;
+check table t extended;
+call check_table('t');
+
+
+--echo # Integer conversions
+create or replace table t (x tinyint);
+insert into t values (127);
+--enable_info
+alter table t modify x smallint;
+--disable_info
+select * from t;
+check table t extended;
+call check_table('t');
+
+update t set x= 32767;
+--enable_info
+alter table t modify x mediumint;
+--disable_info
+select * from t;
+check table t extended;
+call check_table('t');
+
+update t set x= 8388607;
+--enable_info
+alter table t modify x int;
+--disable_info
+select * from t;
+check table t extended;
+call check_table('t');
+
+update t set x= 2147483647;
+--enable_info
+alter table t modify x bigint;
+--disable_info
+select * from t;
+check table t extended;
+call check_table('t');
+
+if ($have_debug) {
+--disable_query_log
+# This should not be reachable.
+set debug_dbug= @save_debug;
+--enable_query_log
+}
+
+--echo # Check IMPORT TABLESPACE
+--let $MYSQLD_DATADIR= `select @@datadir`
+create or replace table t2 (x int);
+alter table t2 discard tablespace;
+
+create or replace table t1 (x tinyint);
+insert into t1 set x= 42;
+alter table t1 modify x int;
+flush tables t1 for export;
+--move_file $MYSQLD_DATADIR/best/t1.cfg $MYSQLD_DATADIR/best/t2.cfg
+--copy_file $MYSQLD_DATADIR/best/t1.ibd $MYSQLD_DATADIR/best/t2.ibd
+unlock tables;
+
+alter table t2 import tablespace;
+
+select * from t2;
+check table t2 extended;
+call check_table('t2');
+
+--echo # Check innobase_col_to_mysql() len < flen
+create or replace table t1 (x mediumint);
+insert into t1 values (1);
+insert into t1 values (1);
+--enable_info
+alter table t1 add column y int first, modify x int;
+--error ER_DUP_ENTRY
+alter table t1 add column z int first, add primary key (x);
+--disable_info
+
+--echo # Check assertion in wrong instant operation
+create or replace table t1 (a varchar(26) not null) default character set utf8mb4;
+insert into t1 values ('abcdef'), (repeat('x',26));
+--enable_info
+alter ignore table t1 modify a varchar(25) not null;
+--disable_info
+select * from t1;
+
+--echo # Check row_mysql_store_col_in_innobase_format()
+create or replace table t1(x int primary key, a varchar(20));
+insert into t1 (x) values (1);
+update t1 set a= 'foo' where x = 2;
+
+--echo #
+--echo # MDEV-18124 PK on inplace-enlarged type fails
+--echo #
+create or replace table t1 (x int, y int);
+insert into t1 (x, y) values (11, 22);
+--enable_info
+alter table t1 modify x bigint;
+alter table t1 add primary key (x);
+--disable_info
+select * from t1;
+check table t1;
+
+create or replace table t1 (a varchar(10), y int);
+insert into t1 (a, y) values ("0123456789", 33);
+--enable_info
+alter table t1 modify a char(15);
+alter table t1 add primary key (a);
+--disable_info
+select * from t1;
+check table t1;
+
+create or replace table t1 (x int primary key, y int);
+insert into t1 (x, y) values (44, 55);
+--enable_info
+alter table t1 modify x bigint;
+--disable_info
+select * from t1;
+check table t1;
+
+create or replace table t1 (x int primary key, y int);
+insert into t1 values (66, 77);
+--enable_info
+alter table t1 add column z int;
+alter table t1 drop column y;
+--disable_info
+select * from t1;
+check table t1;
+
+create or replace table t1 (x integer, a varchar(20));
+--enable_info
+insert into t1 (x, a) values (73, 'a');
+alter table t1 add index idx3 (a);
+alter table t1 modify a char(20);
+--disable_info
+select * from t1;
+check table t1;
+
+drop database best;
diff --git a/mysql-test/suite/innodb/t/instant_alter_import.test b/mysql-test/suite/innodb/t/instant_alter_import.test
new file mode 100644
index 00000000..3a811def
--- /dev/null
+++ b/mysql-test/suite/innodb/t/instant_alter_import.test
@@ -0,0 +1,235 @@
+--source include/have_innodb.inc
+--source include/have_sequence.inc
+--source include/innodb_checksum_algorithm.inc
+
+call mtr.add_suppression("Operating system error number .* in a file operation.");
+call mtr.add_suppression("The error means the system cannot find the path specified.");
+call mtr.add_suppression("File ./test/t1.ibd was not found");
+
+--disable_query_log
+call mtr.add_suppression("Table `test`.`t2` contains unrecognizable instant ALTER metadata");
+call mtr.add_suppression("Index for table 't2' is corrupt; try to repair it");
+--enable_query_log
+
+set default_storage_engine=innodb;
+
+--echo #
+--echo # MDEV-18295 IMPORT TABLESPACE fails with instant-altered tables
+--echo #
+
+create table t2 (x int, z int default 41);
+alter table t2 discard tablespace;
+
+create table t1 (x int);
+insert into t1 values (1);
+alter table t1 add z int default 42, algorithm instant;
+select * from t1;
+flush tables t1 for export;
+--let $MYSQLD_DATADIR= `select @@datadir`
+--move_file $MYSQLD_DATADIR/test/t1.cfg $MYSQLD_DATADIR/test/t2.cfg
+--copy_file $MYSQLD_DATADIR/test/t1.ibd $MYSQLD_DATADIR/test/t2.ibd
+unlock tables;
+
+--echo # The metadata has to be updated to instant ADD COLUMN.
+alter table t2 import tablespace;
+
+select * from t2;
+insert into t2 set x=2;
+select * from t2;
+
+alter table t1 discard tablespace;
+flush tables t2 for export;
+--move_file $MYSQLD_DATADIR/test/t2.cfg $MYSQLD_DATADIR/test/t1.cfg
+--copy_file $MYSQLD_DATADIR/test/t2.ibd $MYSQLD_DATADIR/test/t1.ibd
+unlock tables;
+
+--echo # Both the metadata and the data file used instant ADD COLUMN.
+alter table t1 import tablespace;
+select * from t1;
+
+drop table t2;
+create table t2 select * from t1;
+
+alter table t1 discard tablespace;
+flush tables t2 for export;
+--move_file $MYSQLD_DATADIR/test/t2.cfg $MYSQLD_DATADIR/test/t1.cfg
+--copy_file $MYSQLD_DATADIR/test/t2.ibd $MYSQLD_DATADIR/test/t1.ibd
+unlock tables;
+--copy_file $MYSQLD_DATADIR/test/t1.cfg $MYSQLD_DATADIR/test/t1b.cfg
+--copy_file $MYSQLD_DATADIR/test/t1.ibd $MYSQLD_DATADIR/test/t1b.ibd
+
+--echo # The instant ADD COLUMN has to be removed from the metadata.
+alter table t1 import tablespace;
+select * from t1;
+
+--echo # Remove metadata for instant DROP COLUMN, then import
+alter table t1 drop x, add column x int first, algorithm instant;
+select * from t1;
+alter table t1 discard tablespace;
+
+--move_file $MYSQLD_DATADIR/test/t1b.cfg $MYSQLD_DATADIR/test/t1.cfg
+--move_file $MYSQLD_DATADIR/test/t1b.ibd $MYSQLD_DATADIR/test/t1.ibd
+alter table t1 import tablespace;
+select * from t1;
+
+--echo # Import a data file that contains instant DROP COLUMN metadata
+alter table t2 drop x;
+alter table t1 drop x, force;
+alter table t1 discard tablespace;
+
+flush tables t2 for export;
+--move_file $MYSQLD_DATADIR/test/t2.cfg $MYSQLD_DATADIR/test/t1.cfg
+--copy_file $MYSQLD_DATADIR/test/t2.ibd $MYSQLD_DATADIR/test/t1.ibd
+unlock tables;
+
+alter table t1 import tablespace;
+select * from t1;
+--remove_file $MYSQLD_DATADIR/test/t1.ibd
+
+drop table t2;
+drop table t1;
+
+
+--let $MYSQLD_DATADIR= `SELECT @@datadir`
+
+CREATE TABLE t1 (id INT PRIMARY KEY AUTO_INCREMENT, i1 INT) ENGINE=INNODB;
+
+CREATE TABLE t2 (id INT PRIMARY KEY AUTO_INCREMENT, i1 INT, i2 INT) ENGINE=INNODB;
+ALTER TABLE t2 DROP COLUMN i2, ALGORITHM=INSTANT;
+ALTER TABLE t2 DISCARD TABLESPACE;
+
+FLUSH TABLE t1 FOR EXPORT;
+
+--copy_file $MYSQLD_DATADIR/test/t1.ibd $MYSQLD_DATADIR/test/t2.ibd
+--copy_file $MYSQLD_DATADIR/test/t1.cfg $MYSQLD_DATADIR/test/t2.cfg
+
+UNLOCK TABLES;
+ALTER TABLE t2 IMPORT TABLESPACE;
+
+DROP TABLE t2, t1;
+
+
+CREATE TABLE t1 (id INT PRIMARY KEY, i2 INT, i1 INT) ENGINE=INNODB;
+
+INSERT INTO t1 VALUES (1, 1, 1);
+ALTER TABLE t1 MODIFY COLUMN i2 INT AFTER i1, ALGORITHM=INSTANT;
+
+CREATE TABLE t2 LIKE t1;
+ALTER TABLE t2 DISCARD TABLESPACE;
+
+
+FLUSH TABLE t1 FOR EXPORT;
+
+--copy_file $MYSQLD_DATADIR/test/t1.ibd $MYSQLD_DATADIR/test/t2.ibd
+--copy_file $MYSQLD_DATADIR/test/t1.cfg $MYSQLD_DATADIR/test/t2.cfg
+
+UNLOCK TABLES;
+ALTER TABLE t2 IMPORT TABLESPACE;
+
+SELECT * FROM t2;
+
+DROP TABLE t2, t1;
+
+
+CREATE TABLE t1 (id INT PRIMARY KEY, i2 INT, i1 INT) ENGINE=INNODB;
+
+INSERT INTO t1 VALUES (1, 1, 1);
+ALTER TABLE t1 DROP COLUMN i2, ALGORITHM=INSTANT;
+
+CREATE TABLE t2 LIKE t1;
+ALTER TABLE t2 DISCARD TABLESPACE;
+
+
+FLUSH TABLE t1 FOR EXPORT;
+
+--copy_file $MYSQLD_DATADIR/test/t1.ibd $MYSQLD_DATADIR/test/t2.ibd
+--copy_file $MYSQLD_DATADIR/test/t1.cfg $MYSQLD_DATADIR/test/t2.cfg
+
+UNLOCK TABLES;
+ALTER TABLE t2 IMPORT TABLESPACE;
+
+SELECT * FROM t2;
+
+DROP TABLE t2, t1;
+
+
+CREATE TABLE t1 (id INT PRIMARY KEY, i2 INT, i1 INT)
+ ENGINE=INNODB PAGE_COMPRESSED=1;
+
+INSERT INTO t1 VALUES (1, 1, 1);
+ALTER TABLE t1 DROP COLUMN i2, ALGORITHM=INSTANT;
+
+CREATE TABLE t2 LIKE t1;
+ALTER TABLE t2 DISCARD TABLESPACE;
+
+FLUSH TABLE t1 FOR EXPORT;
+
+--copy_file $MYSQLD_DATADIR/test/t1.ibd $MYSQLD_DATADIR/test/t2.ibd
+--copy_file $MYSQLD_DATADIR/test/t1.cfg $MYSQLD_DATADIR/test/t2.cfg
+
+UNLOCK TABLES;
+ALTER TABLE t2 IMPORT TABLESPACE;
+
+DROP TABLE t2, t1;
+
+
+CREATE TABLE t1 (id INT PRIMARY KEY AUTO_INCREMENT, i2 INT, i1 INT) ENGINE=INNODB;
+
+INSERT INTO t1 (i2) SELECT 4 FROM seq_1_to_1024;
+ALTER TABLE t1 DROP COLUMN i2, ALGORITHM=INSTANT;
+
+CREATE TABLE t2 LIKE t1;
+ALTER TABLE t2 DISCARD TABLESPACE;
+
+FLUSH TABLE t1 FOR EXPORT;
+
+--copy_file $MYSQLD_DATADIR/test/t1.ibd $MYSQLD_DATADIR/test/t2.ibd
+--copy_file $MYSQLD_DATADIR/test/t1.cfg $MYSQLD_DATADIR/test/t2.cfg
+
+UNLOCK TABLES;
+ALTER TABLE t2 IMPORT TABLESPACE;
+
+DROP TABLE t2, t1;
+
+
+CREATE TABLE t1 ( id INT NOT NULL, i1 INT, i2 INT, PRIMARY KEY (id)) engine=innodb;
+CREATE TABLE t2 ( id INT NOT NULL, i1 INT, i2 INT, PRIMARY KEY (id)) engine=innodb;
+
+ALTER TABLE test.t1 add COLUMN i3 INT AFTER i1;
+
+ALTER TABLE t2 DISCARD TABLESPACE;
+FLUSH TABLES t1 FOR EXPORT;
+
+--copy_file $MYSQLD_DATADIR/test/t1.ibd $MYSQLD_DATADIR/test/t2.ibd
+--copy_file $MYSQLD_DATADIR/test/t1.cfg $MYSQLD_DATADIR/test/t2.cfg
+
+UNLOCK TABLES;
+--error ER_NOT_KEYFILE
+ALTER TABLE t2 IMPORT TABLESPACE;
+
+DROP TABLE t1, t2;
+
+--echo #
+--echo # MDEV-28919 Assertion `(((core_null) + 7) >> 3) ==
+--echo # oindex.n_core_null_bytes || !not_redundant()' failed
+--echo #
+call mtr.add_suppression(" InnoDB: Tablespace for table `test`.`t` is set as discarded");
+CREATE TABLE t (a INTEGER, b INTEGER as (a) VIRTUAL,
+ c INTEGER)engine=innodb;
+ALTER TABLE t DISCARD TABLESPACE;
+FLUSH TABLES;
+# Table does reload
+ALTER TABLE t DROP COLUMN b, algorithm=instant;
+ALTER TABLE t DROP COLUMN c, algorithm=instant;
+
+CREATE TABLE t1(a INTEGER)ENGINE=InnoDB;
+INSERT INTO t1 VALUES(1);
+FLUSH TABLE t1 FOR EXPORT;
+--let $MYSQLD_DATADIR= `select @@datadir`
+--move_file $MYSQLD_DATADIR/test/t1.cfg $MYSQLD_DATADIR/test/t.cfg
+--copy_file $MYSQLD_DATADIR/test/t1.ibd $MYSQLD_DATADIR/test/t.ibd
+unlock tables;
+ALTER TABLE t IMPORT tablespace;
+check table t;
+select * from t;
+DROP TABLE t, t1;
diff --git a/mysql-test/suite/innodb/t/instant_alter_index_rename.test b/mysql-test/suite/innodb/t/instant_alter_index_rename.test
new file mode 100644
index 00000000..9772c859
--- /dev/null
+++ b/mysql-test/suite/innodb/t/instant_alter_index_rename.test
@@ -0,0 +1,233 @@
+--source include/have_innodb.inc
+--source include/have_debug.inc
+--source include/have_sequence.inc
+
+delimiter |;
+create function get_index_id(tbl_id int, index_name char(100))
+ returns int
+begin
+ declare res int;
+ select index_id into res from information_schema.innodb_sys_indexes where
+ name=index_name and table_id = tbl_id;
+ return res;
+end|
+
+delimiter ;|
+
+create table t (
+ pk int primary key,
+ a int,
+ b int,
+ c int,
+ unique index a_key (a),
+ key c_key (c)
+) engine=innodb stats_persistent=1;
+
+insert into t values (1, 1, 1, 1);
+
+set @table_id = (select table_id from information_schema.innodb_sys_tables where name='test/t');
+
+set @a_key_id = get_index_id(@table_id, 'a_key');
+set @c_key_id = get_index_id(@table_id, 'c_key');
+set @primary_id = get_index_id(@table_id, 'primary');
+
+select distinct(index_name) from mysql.innodb_index_stats where table_name = 't';
+alter table t
+ drop index a_key,
+ add unique index a_key_strikes_back (a);
+select distinct(index_name) from mysql.innodb_index_stats where table_name = 't';
+
+check table t;
+select @a_key_id = get_index_id(@table_id, 'a_key_strikes_back'),
+ @c_key_id = get_index_id(@table_id, 'c_key'),
+ @primary_id = get_index_id(@table_id, 'primary');
+
+set @a_key_strikes_back_id = get_index_id(@table_id, 'a_key_strikes_back');
+set @c_key_id = get_index_id(@table_id, 'c_key');
+set @primary_id = get_index_id(@table_id, 'primary');
+
+alter table t
+ drop index a_key_strikes_back,
+ add unique index a_key_returns (a),
+ drop primary key,
+ add primary key (pk),
+ add unique index b_key (b);
+
+check table t;
+select @a_key_strikes_back_id = get_index_id(@table_id, 'a_key_returns'),
+ @c_key_id = get_index_id(@table_id, 'c_key'),
+ @primary_id = get_index_id(@table_id, 'primary');
+
+set @a_key_returns_id = get_index_id(@table_id, 'a_key_returns');
+set @b_key_id = get_index_id(@table_id, 'b_key');
+set @c_key_id = get_index_id(@table_id, 'c_key');
+set @primary_id = get_index_id(@table_id, 'primary');
+
+alter table t
+ drop key c_key,
+ add key c_key2 (c);
+
+check table t;
+select @a_key_returns_id = get_index_id(@table_id, 'a_key_returns'),
+ @b_key_id = get_index_id(@table_id, 'b_key'),
+ @c_key_id = get_index_id(@table_id, 'c_key2'),
+ @primary_id = get_index_id(@table_id, 'primary');
+
+drop table t;
+
+create table errors (
+ a int,
+ unique key a_key (a),
+ b int
+) engine=innodb;
+
+--error ER_CANT_DROP_FIELD_OR_KEY
+alter table errors
+ drop key a_key,
+ drop key a_key,
+ add unique key a_key2 (a);
+
+--error ER_CANT_DROP_FIELD_OR_KEY
+alter table errors
+ drop key a_key,
+ drop key a_key2,
+ add unique key a_key2 (a);
+
+--error ER_CANT_DROP_FIELD_OR_KEY
+alter table errors
+ add key b_key (b),
+ drop key b_key,
+ add key bb_key (b);
+
+--error ER_CANT_DROP_FIELD_OR_KEY
+alter table errors
+ drop key a_key,
+ add key a_key2 (a),
+ drop key a_key,
+ add key a_key2 (a);
+
+drop table errors;
+
+--disable_query_log
+call mtr.add_suppression("Flagged corruption of `a_key` in table `test`.`corrupted` in dict_set_index_corrupted");
+--enable_query_log
+
+create table corrupted (
+ a int,
+ key a_key (a)
+) engine=innodb;
+
+insert into corrupted values (1);
+
+select * from corrupted;
+
+SET @save_dbug = @@SESSION.debug_dbug;
+SET debug_dbug = '+d,dict_set_index_corrupted';
+check table corrupted;
+SET debug_dbug = @save_dbug;
+
+--error ER_INDEX_CORRUPT
+select * from corrupted;
+
+--error ER_INDEX_CORRUPT
+alter table corrupted
+ drop key a_key,
+ add key a_key2 (a);
+
+alter table corrupted
+ drop key a_key;
+
+select * from corrupted;
+
+check table corrupted;
+
+drop table corrupted;
+
+create table t (
+ a int,
+ unique key a_key (a)
+) engine=innodb stats_persistent=1;
+
+SET @save_dbug = @@SESSION.debug_dbug;
+SET debug_dbug = '+d,ib_rename_index_fail1';
+-- error ER_LOCK_DEADLOCK
+alter table t
+ drop key a_key,
+ add unique key a_key2 (a),
+ algorithm=instant;
+SET debug_dbug = @save_dbug;
+
+--error ER_WRONG_NAME_FOR_INDEX
+alter table t
+ drop key a_key,
+ add unique key `GEN_CLUST_INDEX` (a),
+ algorithm=instant;
+
+show create table t;
+
+drop table t;
+
+
+create table rename_column_and_index (
+ a int,
+ unique index a_key(a)
+) engine=innodb;
+
+insert into rename_column_and_index values (1), (3);
+
+alter table rename_column_and_index
+ change a aa int,
+ drop key a_key,
+ add unique key aa_key(aa),
+ algorithm=instant;
+
+show create table rename_column_and_index;
+check table rename_column_and_index;
+drop table rename_column_and_index;
+
+
+--echo #
+--echo # MDEV-19189: ASAN memcpy-param-overlap in fill_alter_inplace_info upon adding indexes
+--echo #
+
+CREATE TABLE t1 (f1 INT, f2 INT, f3 INT);
+ALTER TABLE t1 ADD FOREIGN KEY f (f2) REFERENCES xx(f2);
+ALTER TABLE t1 ADD FOREIGN KEY (f2) REFERENCES t1(f2), ADD KEY (f3), ADD KEY (f1);
+DROP TABLE t1;
+
+--echo #
+--echo # MDEV-21669 InnoDB: Table ... contains <n> indexes inside InnoDB, which is different from the number of indexes <n> defined in the MariaDB
+--echo #
+CREATE TABLE t1 (col_int INTEGER, col_char CHAR(20), col_varchar VARCHAR(500)) ENGINE=InnoDB;
+SET @table_id = (SELECT table_id FROM information_schema.innodb_sys_tables WHERE name='test/t1');
+ALTER TABLE t1 ADD KEY idx3 (col_varchar(9)), ADD KEY idX2 (col_char(9));
+SET @idx3_key_id = get_index_id(@table_id, 'iDx3');
+ALTER TABLE t1 DROP KEY iDx3, ADD KEY Idx3 (col_varchar(9));
+SELECT @idx3_key_id = get_index_id(@table_id, 'Idx3');
+CHECK TABLE t1 EXTENDED ;
+DROP TABLE t1;
+
+DROP FUNCTION get_index_id;
+
+--echo #
+--echo # MDEV-23356 InnoDB: Failing assertion: field->col->mtype == type, crash or ASAN failures in row_sel_convert_mysql_key_to_innobase, InnoDB indexes are inconsistent after INDEX changes
+--echo #
+
+CREATE TABLE t1 (a INT, b INT, c CHAR(8),
+ KEY ind1(c), KEY ind2(b)) ENGINE=InnoDB STATS_PERSISTENT=1;
+
+INSERT INTO t1 SELECT 1, 1, 'a' FROM seq_1_to_100;
+
+SELECT table_name, index_name, stat_name FROM mysql.innodb_index_stats;
+
+ALTER TABLE t1 DROP INDEX ind2, ADD INDEX ind3(b),
+ DROP INDEX ind1, ADD INDEX ind2(c);
+
+SELECT table_name, index_name, stat_name FROM mysql.innodb_index_stats;
+
+ALTER TABLE t1 DROP b, FORCE;
+SELECT table_name, index_name, stat_name FROM mysql.innodb_index_stats;
+
+UPDATE t1 SET a = 1 WHERE c = 'foo';
+DROP TABLE t1;
+SELECT table_name, index_name, stat_name FROM mysql.innodb_index_stats;
diff --git a/mysql-test/suite/innodb/t/instant_alter_inject.test b/mysql-test/suite/innodb/t/instant_alter_inject.test
new file mode 100644
index 00000000..2a74998f
--- /dev/null
+++ b/mysql-test/suite/innodb/t/instant_alter_inject.test
@@ -0,0 +1,46 @@
+--source include/have_innodb.inc
+--source include/have_debug.inc
+--source include/have_partition.inc
+
+CREATE TABLE t1(a INT PRIMARY KEY, b INT, KEY(b)) ENGINE=InnoDB
+ROW_FORMAT=REDUNDANT PARTITION BY KEY() PARTITIONS 3;
+INSERT INTO t1 (a) VALUES (1),(2),(3),(4),(5);
+SET @saved_dbug= @@SESSION.debug_dbug;
+SET DEBUG_DBUG='+d,ib_commit_inplace_fail_2';
+--error ER_INTERNAL_ERROR
+ALTER TABLE t1 ADD COLUMN c CHAR(3) DEFAULT 'lie';
+SET DEBUG_DBUG= @saved_dbug;
+CHECK TABLE t1;
+BEGIN;
+UPDATE t1 SET b=a+1;
+INSERT INTO t1 VALUES (0,1);
+ROLLBACK;
+SELECT * FROM t1;
+ALTER TABLE t1 ADD COLUMN c CHAR(3) DEFAULT 'lie';
+SET DEBUG_DBUG='+d,ib_commit_inplace_fail_1';
+--error ER_INTERNAL_ERROR
+ALTER TABLE t1 ADD COLUMN d INT NOT NULL DEFAULT -42;
+SET DEBUG_DBUG= @saved_dbug;
+CHECK TABLE t1;
+BEGIN;
+DELETE FROM t1;
+INSERT INTO t1 VALUES (1,2,'foo');
+ROLLBACK;
+
+SHOW CREATE TABLE t1;
+DROP TABLE t1;
+
+CREATE TABLE t2(a INT, KEY(a)) ENGINE=InnoDB;
+INSERT INTO t2 VALUES (1);
+SET DEBUG_DBUG='+d,ib_commit_inplace_fail_1';
+--error ER_INTERNAL_ERROR
+ALTER TABLE t2 ADD COLUMN b INT;
+SET DEBUG_DBUG= @saved_dbug;
+CHECK TABLE t2;
+BEGIN;
+DELETE FROM t2;
+INSERT INTO t2 VALUES (1);
+ROLLBACK;
+
+SHOW CREATE TABLE t2;
+DROP TABLE t2;
diff --git a/mysql-test/suite/innodb/t/instant_alter_limit.test b/mysql-test/suite/innodb/t/instant_alter_limit.test
new file mode 100644
index 00000000..b7fb3ee5
--- /dev/null
+++ b/mysql-test/suite/innodb/t/instant_alter_limit.test
@@ -0,0 +1,76 @@
+--source include/innodb_page_size.inc
+
+SET @old_instant=
+(SELECT variable_value FROM information_schema.global_status
+WHERE variable_name = 'innodb_instant_alter_column');
+
+CREATE TABLE t(a INT PRIMARY KEY, b INT, c INT, d INT, e INT)
+ENGINE=InnoDB;
+INSERT INTO t VALUES(1,2,3,4,5);
+SET innodb_strict_mode = OFF;
+--disable_query_log
+call mtr.add_suppression("\\[Warning\\] InnoDB: Cannot add .* in table `test`\\.`t` because after adding it, the row size");
+let $n=253;
+while ($n) {
+dec $n;
+ALTER TABLE t DROP b, DROP c, DROP d, DROP e,
+ADD COLUMN b INT FIRST, ADD COLUMN c INT, ADD COLUMN d INT AFTER b,
+ADD COLUMN e INT AFTER c, ALGORITHM=INSTANT;
+}
+--enable_query_log
+SELECT * FROM t;
+--error ER_ALTER_OPERATION_NOT_SUPPORTED
+ALTER TABLE t DROP b, DROP c, DROP d, DROP e,
+ADD COLUMN b INT, ALGORITHM=INSTANT;
+ALTER TABLE t CHANGE COLUMN b beta INT AFTER a, ALGORITHM=INSTANT;
+ALTER TABLE t DROP e, DROP c, DROP d, ALGORITHM=INSTANT;
+SELECT * FROM t;
+ALTER TABLE t DROP COLUMN beta, ALGORITHM=INSTANT;
+--error ER_ALTER_OPERATION_NOT_SUPPORTED
+ALTER TABLE t ADD COLUMN b INT NOT NULL, ALGORITHM=INSTANT;
+
+SELECT variable_value-@old_instant instants
+FROM information_schema.global_status
+WHERE variable_name = 'innodb_instant_alter_column';
+
+ALTER TABLE t ADD COLUMN b INT NOT NULL;
+
+SELECT variable_value-@old_instant instants
+FROM information_schema.global_status
+WHERE variable_name = 'innodb_instant_alter_column';
+
+SELECT * FROM t;
+ALTER TABLE t ADD COLUMN (c CHAR(255) NOT NULL, d BIGINT NOT NULL),
+ALGORITHM=INSTANT;
+
+--disable_query_log
+let $n=253;
+while ($n) {
+dec $n;
+ALTER TABLE t DROP b, DROP c, DROP d,
+ADD COLUMN (b INT NOT NULL, c CHAR(255) NOT NULL, d BIGINT NOT NULL);
+}
+--enable_query_log
+
+UPDATE t SET b=b+1,d=d+1,c='foo';
+SELECT * FROM t;
+
+SELECT variable_value-@old_instant instants
+FROM information_schema.global_status
+WHERE variable_name = 'innodb_instant_alter_column';
+
+DROP TABLE t;
+
+--echo #
+--echo # MDEV-21787 Alter table failure tries to access uninitialized column
+--echo #
+CREATE TABLE t1(f1 INT PRIMARY KEY, f2 TEXT GENERATED ALWAYS AS (SUBSTR(f4, 1, 400)), f3 VARCHAR(500), f4 TEXT)ENGINE=InnoDB ROW_FORMAT=Compact;
+ALTER TABLE t1 ADD UNIQUE KEY (f2(9));
+let $error_code = 0;
+let $innodb_page_size = `SELECT @@INNODB_PAGE_SIZE`;
+if ($innodb_page_size == 4k) {
+ let $error_code= ER_TOO_BIG_ROWSIZE;
+}
+--error $error_code
+ALTER TABLE t1 ADD COLUMN f5 TEXT, ALGORITHM=INPLACE;
+DROP TABLE t1;
diff --git a/mysql-test/suite/innodb/t/instant_alter_null.test b/mysql-test/suite/innodb/t/instant_alter_null.test
new file mode 100644
index 00000000..34f47ed9
--- /dev/null
+++ b/mysql-test/suite/innodb/t/instant_alter_null.test
@@ -0,0 +1,67 @@
+--source include/have_innodb.inc
+
+--disable_query_log
+SET @save_innodb_read_only_compressed=@@GLOBAL.innodb_read_only_compressed;
+SET GLOBAL innodb_read_only_compressed=OFF;
+--enable_query_log
+
+create table t (a int NOT NULL) engine=innodb row_format= compressed;
+--error ER_ALTER_OPERATION_NOT_SUPPORTED
+alter table t modify a int NULL, algorithm=instant;
+
+--disable_query_log
+SET GLOBAL innodb_read_only_compressed=@save_innodb_read_only_compressed;
+--enable_query_log
+
+drop table t;
+
+create table t (a int NOT NULL) engine=innodb row_format= dynamic;
+--error ER_ALTER_OPERATION_NOT_SUPPORTED
+alter table t modify a int NULL, algorithm=instant;
+drop table t;
+
+create table t (a int NOT NULL) engine=innodb row_format= compact;
+--error ER_ALTER_OPERATION_NOT_SUPPORTED
+alter table t modify a int NULL, algorithm=instant;
+drop table t;
+
+create table t (
+ id int primary key,
+ a int NOT NULL default 0,
+ b int NOT NULL default 0,
+ c int NOT NULL default 0,
+ index idx (a,b,c)
+) engine=innodb row_format=redundant;
+
+--error ER_BAD_NULL_ERROR
+insert into t (id, a) values (0, NULL);
+--error ER_BAD_NULL_ERROR
+insert into t (id, b) values (0, NULL);
+--error ER_BAD_NULL_ERROR
+insert into t (id, c) values (0, NULL);
+
+insert into t values (1,1,1,1);
+
+set @id = (select table_id from information_schema.innodb_sys_tables
+where name = 'test/t');
+
+--replace_column 1 TABLE_ID
+select * from information_schema.innodb_sys_columns where table_id=@id;
+
+alter table t modify a int NULL, algorithm=instant;
+insert into t values (2, NULL, 2, 2);
+
+alter table t modify b int NULL, algorithm=nocopy;
+insert into t values (3, NULL, NULL, 3);
+
+alter table t modify c int NULL, algorithm=inplace;
+insert into t values (4, NULL, NULL, NULL);
+
+--replace_column 1 TABLE_ID
+select * from information_schema.innodb_sys_columns where table_id=@id;
+
+select * from t;
+
+check table t;
+
+drop table t;
diff --git a/mysql-test/suite/innodb/t/instant_alter_purge.test b/mysql-test/suite/innodb/t/instant_alter_purge.test
new file mode 100644
index 00000000..445cae4d
--- /dev/null
+++ b/mysql-test/suite/innodb/t/instant_alter_purge.test
@@ -0,0 +1,34 @@
+--source include/have_innodb.inc
+--source include/maybe_debug.inc
+if ($have_debug) {
+--source include/have_debug_sync.inc
+}
+
+--source include/wait_all_purged.inc
+
+--echo #
+--echo # MDEV-17793 Crash in purge after instant DROP and emptying the table
+--echo #
+
+connect (prevent_purge,localhost,root);
+START TRANSACTION WITH CONSISTENT SNAPSHOT;
+
+connection default;
+CREATE TABLE t1 (f1 INT, f2 INT) ENGINE=InnoDB;
+INSERT INTO t1 () VALUES ();
+ALTER TABLE t1 DROP f2, ADD COLUMN f2 INT;
+ALTER TABLE t1 DROP f1;
+DELETE FROM t1;
+
+connection prevent_purge;
+COMMIT;
+START TRANSACTION WITH CONSISTENT SNAPSHOT;
+connection default;
+
+ALTER TABLE t1 ADD COLUMN extra TINYINT UNSIGNED NOT NULL DEFAULT 42;
+SET GLOBAL innodb_max_purge_lag_wait=1;
+ALTER TABLE t1 DROP extra;
+disconnect prevent_purge;
+let $wait_all_purged= 0;
+--source include/wait_all_purged.inc
+DROP TABLE t1;
diff --git a/mysql-test/suite/innodb/t/instant_alter_rollback.test b/mysql-test/suite/innodb/t/instant_alter_rollback.test
new file mode 100644
index 00000000..a4608001
--- /dev/null
+++ b/mysql-test/suite/innodb/t/instant_alter_rollback.test
@@ -0,0 +1,70 @@
+--source include/have_innodb.inc
+--source innodb_default_row_format.inc
+# The embedded server tests do not support restarting.
+--source include/not_embedded.inc
+
+# Flush any open myisam tables from previous tests
+FLUSH TABLES;
+
+--echo #
+--echo # MDEV-11369: Instant ADD COLUMN for InnoDB
+--echo # MDEV-15562: Instant DROP COLUMN or changing the order of columns
+--echo #
+
+connect to_be_killed, localhost, root;
+
+SET @old_instant=
+(SELECT variable_value FROM information_schema.global_status
+WHERE variable_name = 'innodb_instant_alter_column');
+CREATE TABLE empty (id INT PRIMARY KEY, c2 INT UNIQUE) ENGINE=InnoDB;
+CREATE TABLE once LIKE empty;
+CREATE TABLE twice LIKE empty;
+CREATE TABLE thrice LIKE empty;
+INSERT INTO once SET id=1,c2=1;
+INSERT INTO twice SET id=1,c2=1;
+INSERT INTO thrice SET id=1,c2=1;
+ALTER TABLE empty ADD COLUMN (d1 INT DEFAULT 15);
+ALTER TABLE once ADD COLUMN (d1 INT DEFAULT 20);
+ALTER TABLE twice ADD COLUMN (d1 INT DEFAULT 20);
+ALTER TABLE thrice ADD COLUMN (d1 INT DEFAULT 20);
+ALTER TABLE twice ADD COLUMN
+(d2 INT NOT NULL DEFAULT 10,
+ d3 VARCHAR(15) NOT NULL DEFAULT 'var och en char');
+ALTER TABLE thrice ADD COLUMN
+(d2 INT NOT NULL DEFAULT 10,
+ d3 TEXT NOT NULL DEFAULT 'con');
+ALTER TABLE thrice DROP c2, DROP d3, CHANGE d2 d3 INT NOT NULL FIRST;
+
+SELECT variable_value-@old_instant instants
+FROM information_schema.global_status
+WHERE variable_name = 'innodb_instant_alter_column';
+
+BEGIN;
+
+INSERT INTO empty set id=0,c2=42;
+UPDATE once set c2=c2+1;
+UPDATE twice set c2=c2+1;
+UPDATE thrice set d3=d3+1;
+INSERT INTO twice SET id=2,c2=0,d3='';
+INSERT INTO thrice SET id=2,d3=0;
+DELETE FROM empty;
+DELETE FROM once;
+DELETE FROM twice;
+DELETE FROM thrice;
+
+connection default;
+SET GLOBAL innodb_flush_log_at_trx_commit=1;
+CREATE TABLE foo(a INT PRIMARY KEY) ENGINE=InnoDB;
+
+--source include/kill_mysqld.inc
+disconnect to_be_killed;
+--source include/start_mysqld.inc
+
+DROP TABLE foo;
+--source include/wait_all_purged.inc
+
+SELECT * FROM empty;
+SELECT * FROM once;
+SELECT * FROM twice;
+SELECT * FROM thrice;
+DROP TABLE empty, once, twice, thrice;
diff --git a/mysql-test/suite/innodb/t/instant_alter_upgrade.test b/mysql-test/suite/innodb/t/instant_alter_upgrade.test
new file mode 100644
index 00000000..d73fe187
--- /dev/null
+++ b/mysql-test/suite/innodb/t/instant_alter_upgrade.test
@@ -0,0 +1,16 @@
+--source include/have_innodb.inc
+--source include/innodb_row_format.inc
+
+--echo #
+--echo # MDEV-26577 InnoDB: Failing assertion: dict_tf2_is_valid(flags, flags2)
+--echo # during ADD COLUMN
+--echo #
+
+CREATE TABLE t1(a INT PRIMARY KEY) ENGINE=InnoDB ROW_FORMAT=COMPRESSED;
+CREATE TABLE t2(a INT PRIMARY KEY) ENGINE=InnoDB;
+FLUSH TABLES;
+--let $datadir=`select @@datadir`
+--remove_file $datadir/test/t2.frm
+--copy_file $datadir/test/t1.frm $datadir/test/t2.frm
+ALTER TABLE t2 ADD COLUMN b INT;
+DROP TABLE t1,t2;
diff --git a/mysql-test/suite/innodb/t/instant_auto_inc.test b/mysql-test/suite/innodb/t/instant_auto_inc.test
new file mode 100644
index 00000000..4aea81c1
--- /dev/null
+++ b/mysql-test/suite/innodb/t/instant_auto_inc.test
@@ -0,0 +1,13 @@
+--source include/have_innodb.inc
+
+create table t(id int primary key, a int) engine=InnoDB;
+insert into t (id, a) values (1, 1);
+alter table t modify column id int auto_increment;
+check table t;
+insert into t (a) values (2);
+alter table t modify column id int, algorithm=instant;
+check table t;
+insert into t (id, a) values (3, 3);
+select * from t;
+check table t;
+drop table t;
diff --git a/mysql-test/suite/innodb/t/instant_drop.test b/mysql-test/suite/innodb/t/instant_drop.test
new file mode 100644
index 00000000..566ac02b
--- /dev/null
+++ b/mysql-test/suite/innodb/t/instant_drop.test
@@ -0,0 +1,108 @@
+--source include/have_innodb.inc
+
+create table t1(f1 int not null, f2 int not null, f3 int not null)engine=innodb;
+insert into t1 values(1, 2, 3),(4, 5, 6);
+alter table t1 drop column f2, algorithm=instant;
+select * from t1;
+insert into t1 values(1,2);
+select * from t1;
+alter table t1 add column f4 int not null default 5, algorithm=instant;
+select * from t1;
+alter table t1 drop column f1, algorithm=instant;
+select * from t1;
+insert into t1 values(7, 9);
+select * from t1;
+alter table t1 add column f5 blob default repeat('aaa', 950), drop column f4, algorithm=instant;
+select * from t1;
+select f3 from t1;
+update t1 set f3 = 10 where f3 > 2;
+select * from t1;
+delete from t1 where f3 = 10;
+show create table t1;
+select f3 from t1;
+update t1 set f5 = 'world';
+select * from t1;
+drop table t1;
+
+create table t1(f1 int, f2 int not null, index idx(f2))engine=innodb;
+insert into t1 values(1, 2);
+alter table t1 drop column f1, add column f3 varchar(100) default 'thiru', algorithm=instant;
+select * from t1 force index (idx);
+alter table t1 drop column f3, algorithm=instant;
+select * from t1;
+begin;
+insert into t1 values(10);
+select * from t1;
+update t1 set f2 = 100;
+select * from t1;
+delete from t1 where f2 = 100;
+select * from t1;
+rollback;
+select * from t1;
+show create table t1;
+drop table t1;
+
+create table t1(f1 int, f2 int not null)engine=innodb;
+insert into t1 values(1, 2);
+alter table t1 drop column f2, algorithm=instant;
+insert into t1 values(NULL);
+select * from t1;
+drop table t1;
+
+create table t1(f1 int not null, f2 int not null)engine=innodb;
+insert into t1 values(1, 2);
+alter table t1 add column f5 int default 10, algorithm=instant;
+alter table t1 add column f3 int not null default 100, algorithm=instant;
+alter table t1 add column f4 int default 100, drop column f3, algorithm=instant;
+insert into t1 values(2, 3, 20, 100);
+select * from t1;
+drop table t1;
+
+create table t1(f1 int not null, f2 int not null) engine=innodb;
+insert into t1 values(1, 1);
+alter table t1 drop column f2, add column f3 int default 3, algorithm=instant;
+select * from t1;
+update t1 set f3 = 19;
+select * from t1;
+alter table t1 drop column f1, add column f5 tinyint default 10 first,
+algorithm=instant;
+insert into t1 values(4, 10);
+select * from t1;
+
+create table t2(f1 int, f2 int not null) engine=innodb;
+insert into t2(f1, f2) values(1, 2);
+alter table t2 drop column f2, add column f4 varchar(100) default repeat('a', 20), add column f5 int default 10, algorithm=instant;
+select * from t2;
+show create table t2;
+alter table t2 add column f6 char(100) default repeat('a', 99), algorithm=instant;
+
+create table t3(f1 int, f2 int not null)engine=innodb;
+insert into t3 values(1, 2);
+alter table t3 drop column f2, add column f3 int default 1, add column f4 int default 4, algorithm=instant;
+
+create table t4(a varchar(1), b int, c int, primary key(a,b))engine=innodb;
+insert into t4 values('4',5,6);
+alter table t4 drop column c;
+
+--source include/restart_mysqld.inc
+select * from t1;
+alter table t1 add column f6 int default 9,drop column f5, algorithm = instant;
+insert into t1 values(4, 9);
+alter table t1 force, algorithm=inplace;
+select * from t1;
+
+select * from t2;
+alter table t2 force, algorithm=inplace;
+select * from t2;
+show create table t2;
+
+select * from t3;
+alter table t3 add column f5 char(100) default repeat('a', 99), algorithm=instant;
+
+select * from t4;
+alter table t4 add column d varchar(5) default 'fubar';
+insert into t4 values('',0,'snafu');
+--source include/restart_mysqld.inc
+select * from t3;
+select * from t4;
+drop table t1,t2,t3,t4;
diff --git a/mysql-test/suite/innodb/t/leaf_page_corrupted_during_recovery.combinations b/mysql-test/suite/innodb/t/leaf_page_corrupted_during_recovery.combinations
new file mode 100644
index 00000000..72938059
--- /dev/null
+++ b/mysql-test/suite/innodb/t/leaf_page_corrupted_during_recovery.combinations
@@ -0,0 +1,5 @@
+[strict_crc32]
+--innodb-checksum-algorithm=strict_crc32
+
+[strict_full_crc32]
+--innodb-checksum-algorithm=strict_full_crc32
diff --git a/mysql-test/suite/innodb/t/leaf_page_corrupted_during_recovery.opt b/mysql-test/suite/innodb/t/leaf_page_corrupted_during_recovery.opt
new file mode 100644
index 00000000..ba4fa744
--- /dev/null
+++ b/mysql-test/suite/innodb/t/leaf_page_corrupted_during_recovery.opt
@@ -0,0 +1,2 @@
+--skip-innodb-doublewrite
+--skip-innodb-buffer-pool-load-at-startup
diff --git a/mysql-test/suite/innodb/t/leaf_page_corrupted_during_recovery.test b/mysql-test/suite/innodb/t/leaf_page_corrupted_during_recovery.test
new file mode 100644
index 00000000..21d53365
--- /dev/null
+++ b/mysql-test/suite/innodb/t/leaf_page_corrupted_during_recovery.test
@@ -0,0 +1,60 @@
+--source include/have_innodb.inc
+--source include/have_debug.inc
+
+--disable_query_log
+call mtr.add_suppression("InnoDB: Database page corruption on disk or a failed read of file '.*test.t1\\.ibd' page");
+call mtr.add_suppression("\\[ERROR\\] InnoDB: Failed to read page 19 from file '.*test.t1\\.ibd': Page read from tablespace is corrupted\\.");
+call mtr.add_suppression("InnoDB: (Unable to apply log to|Discarding log for) corrupted page .*, page number=19\\]");
+call mtr.add_suppression("\\[ERROR\\] InnoDB: Plugin initialization aborted at srv0start\\.cc.* with error Data structure corruption");
+call mtr.add_suppression("\\[ERROR\\] Plugin 'InnoDB' (init function|registration)");
+call mtr.add_suppression("\\[ERROR\\] InnoDB: We detected index corruption");
+call mtr.add_suppression("\\[ERROR\\] (mysqld|mariadbd).*: Index for table 't1' is corrupt; try to repair it");
+call mtr.add_suppression("InnoDB: btr_pcur_open_low level: 0 table: `test`\\.`t1` index: `PRIMARY`");
+call mtr.add_suppression("InnoDB: File '.*test/t1\\.ibd' is corrupted");
+call mtr.add_suppression("InnoDB: In page .* of index `PRIMARY` of table `test`\\.`t1`");
+--enable_query_log
+CREATE TABLE t1 (pk INT PRIMARY KEY, c CHAR(255))ENGINE=InnoDB STATS_PERSISTENT=0;
+
+SET GLOBAL INNODB_LIMIT_OPTIMISTIC_INSERT_DEBUG = 2;
+
+INSERT INTO t1 VALUES(1, 'sql'), (2, 'server'), (3, 'mariadb'),
+ (4, 'mariadb'), (5, 'test1'), (6, 'test2'), (7, 'test3'),
+ (8, 'test4'), (9, 'test5'), (10, 'test6'), (11, 'test7'),
+ (12, 'test8');
+
+let $restart_noprint=2;
+--source include/restart_mysqld.inc
+
+let INNODB_PAGE_SIZE=`select @@innodb_page_size`;
+let MYSQLD_DATADIR=`select @@datadir`;
+
+SELECT COUNT(*) FROM t1;
+--source ../include/no_checkpoint_start.inc
+UPDATE t1 SET c='best8' WHERE pk=12;
+
+--let CLEANUP_IF_CHECKPOINT=DROP TABLE t1;
+--source ../include/no_checkpoint_end.inc
+--echo # Corrupt the pages
+
+perl;
+my $file = "$ENV{MYSQLD_DATADIR}/test/t1.ibd";
+open(FILE, "+<$file") || die "Unable to open $file";
+binmode FILE;
+seek (FILE, $ENV{INNODB_PAGE_SIZE} * 19 + 38, SEEK_SET) or die "seek";
+print FILE "junk";
+close FILE or die "close";
+EOF
+
+--source include/start_mysqld.inc
+--error ER_UNKNOWN_STORAGE_ENGINE
+SELECT * FROM t1 WHERE PK = 1;
+
+# Force recovery to ignore the corrupted page.
+let $restart_parameters=--innodb-force-recovery=1;
+--source include/restart_mysqld.inc
+SELECT * FROM t1 WHERE PK = 1;
+--error ER_NOT_KEYFILE
+SELECT * FROM t1 WHERE pk = 12;
+CHECK TABLE t1;
+
+DROP TABLE t1;
diff --git a/mysql-test/suite/innodb/t/lock_delete_updated.test b/mysql-test/suite/innodb/t/lock_delete_updated.test
new file mode 100644
index 00000000..1f7b1314
--- /dev/null
+++ b/mysql-test/suite/innodb/t/lock_delete_updated.test
@@ -0,0 +1,32 @@
+--source include/have_innodb.inc
+--source include/count_sessions.inc
+--source include/have_debug.inc
+--source include/have_debug_sync.inc
+
+CREATE TABLE t(a INT PRIMARY KEY) ENGINE=InnoDB;
+INSERT INTO t VALUES (3);
+
+BEGIN;
+UPDATE t SET a = 2;
+
+connect con1,localhost,root;
+SET DEBUG_SYNC="lock_wait_start SIGNAL del_locked";
+send DELETE FROM t;
+
+connection default;
+SET DEBUG_SYNC="now WAIT_FOR del_locked";
+UPDATE t SET a = 1;
+COMMIT;
+
+connection con1;
+error ER_LOCK_DEADLOCK;
+reap;
+disconnect con1;
+
+connection default;
+--echo # The above DELETE must delete all the rows in the table, so the
+--echo # following SELECT must show 0 rows.
+SELECT count(*) FROM t;
+SET DEBUG_SYNC="reset";
+DROP TABLE t;
+--source include/wait_until_count_sessions.inc
diff --git a/mysql-test/suite/innodb/t/lock_deleted.test b/mysql-test/suite/innodb/t/lock_deleted.test
new file mode 100644
index 00000000..8dbad90d
--- /dev/null
+++ b/mysql-test/suite/innodb/t/lock_deleted.test
@@ -0,0 +1,72 @@
+--source include/have_innodb.inc
+--source include/have_debug.inc
+--source include/have_debug_sync.inc
+
+--source include/count_sessions.inc
+
+connect(stop_purge, localhost, root,,);
+START TRANSACTION WITH CONSISTENT SNAPSHOT;
+connect(delete, localhost, root,,);
+connection default;
+
+CREATE TABLE t1(a INT PRIMARY KEY, b INT UNIQUE) ENGINE=InnoDB;
+INSERT INTO t1 VALUES(1,1);
+DELETE FROM t1;
+
+let $i=2;
+while ($i) {
+let $iso= `SELECT CASE $i WHEN 1 THEN 'UNCOMMITTED' ELSE 'COMMITTED' END`;
+
+SET DEBUG_SYNC='row_ins_sec_index_unique SIGNAL inserted WAIT_FOR locked';
+BEGIN;
+send INSERT INTO t1 VALUES(1,1);
+
+connection delete;
+SET DEBUG_SYNC='now WAIT_FOR inserted';
+SET DEBUG_SYNC='innodb_row_search_for_mysql_exit SIGNAL locked';
+eval SET SESSION TRANSACTION ISOLATION LEVEL READ $iso;
+BEGIN;
+send DELETE FROM t1 WHERE b=1;
+
+connection default;
+reap;
+connection delete;
+reap;
+COMMIT;
+
+connection default;
+SET DEBUG_SYNC='RESET';
+ROLLBACK;
+
+dec $i;
+}
+
+SET DEBUG_SYNC='row_ins_sec_index_unique SIGNAL inserted WAIT_FOR locked';
+BEGIN;
+SET innodb_lock_wait_timeout=1;
+send INSERT INTO t1 VALUES(1,1);
+
+connection delete;
+SET DEBUG_SYNC='now WAIT_FOR inserted';
+SET DEBUG_SYNC='innodb_row_search_for_mysql_exit SIGNAL locked';
+SET SESSION TRANSACTION ISOLATION LEVEL REPEATABLE READ;
+BEGIN;
+send DELETE FROM t1 WHERE b=1;
+
+connection default;
+--error ER_LOCK_WAIT_TIMEOUT
+reap;
+COMMIT;
+SET DEBUG_SYNC='RESET';
+
+connection delete;
+reap;
+COMMIT;
+
+disconnect delete;
+disconnect stop_purge;
+
+connection default;
+DROP TABLE t1;
+
+--source include/wait_until_count_sessions.inc
diff --git a/mysql-test/suite/innodb/t/lock_insert_into_empty.test b/mysql-test/suite/innodb/t/lock_insert_into_empty.test
new file mode 100644
index 00000000..91d2bcdd
--- /dev/null
+++ b/mysql-test/suite/innodb/t/lock_insert_into_empty.test
@@ -0,0 +1,63 @@
+--source include/have_innodb.inc
+
+CREATE TABLE t1 (a INT PRIMARY KEY) ENGINE=InnoDB;
+CREATE TABLE t2 (a INT PRIMARY KEY) ENGINE=InnoDB;
+
+INSERT INTO t1 VALUES(0);
+BEGIN;
+DELETE FROM t1;
+--error ER_DUP_ENTRY
+INSERT INTO t2 VALUES(1),(1);
+
+BEGIN;
+SELECT * FROM t2 LOCK IN SHARE MODE;
+
+connect (con1,localhost,root,,);
+SET innodb_lock_wait_timeout=0;
+--error ER_LOCK_WAIT_TIMEOUT
+INSERT INTO t2 VALUES(2);
+connection default;
+ROLLBACK;
+connection con1;
+INSERT INTO t2 VALUES(3);
+COMMIT;
+disconnect con1;
+connection default;
+
+SELECT * FROM t1;
+SELECT * FROM t2;
+DROP TABLE t1, t2;
+
+--echo #
+--echo # MDEV-24700 Assertion "lock not found"==0 in lock_table_x_unlock()
+--echo #
+SET FOREIGN_KEY_CHECKS=OFF;
+CREATE TABLE t1 (id INT PRIMARY KEY, f INT REFERENCES nonexistent(x))
+ENGINE=InnoDB;
+SET FOREIGN_KEY_CHECKS=ON;
+BEGIN;
+INSERT IGNORE INTO t1 VALUES (1,11);
+--error ER_NO_REFERENCED_ROW_2
+REPLACE INTO t1 VALUES (1,12);
+COMMIT;
+
+DROP TABLE t1;
+
+--echo #
+--echo # MDEV-25942 Assertion failed in trx_t::drop_table()
+--echo #
+
+CREATE TABLE t1 (k INT PRIMARY KEY) ENGINE=InnoDB;
+INSERT INTO t1 SET k=1;
+START TRANSACTION;
+INSERT INTO t1 SET k=2;
+
+--connect (con1,localhost,root,,test)
+SET innodb_lock_wait_timeout=0;
+--error ER_LOCK_WAIT_TIMEOUT
+CREATE TABLE t2 (pk INT AUTO_INCREMENT PRIMARY KEY) ENGINE=InnoDB
+AS SELECT k FROM t1;
+--disconnect con1
+--connection default
+
+DROP TABLE t1;
diff --git a/mysql-test/suite/innodb/t/lock_move_wait_lock_race.test b/mysql-test/suite/innodb/t/lock_move_wait_lock_race.test
new file mode 100644
index 00000000..3a04c712
--- /dev/null
+++ b/mysql-test/suite/innodb/t/lock_move_wait_lock_race.test
@@ -0,0 +1,58 @@
+--source include/have_innodb.inc
+--source include/count_sessions.inc
+--source include/have_debug.inc
+--source include/have_debug_sync.inc
+
+CREATE TABLE t (pk int PRIMARY KEY, c varchar(10)) ENGINE=InnoDB;
+INSERT INTO t VALUES (10, "0123456789");
+
+--connection default
+BEGIN;
+SELECT * FROM t WHERE c = 10 FOR UPDATE;
+
+--connect(trx2, localhost,root,,)
+BEGIN;
+SET DEBUG_SYNC="lock_wait_start SIGNAL trx2_start_waiting";
+SET DEBUG_SYNC="lock_wait_end SIGNAL trx2_wait_end WAIT_FOR trx2_cont_upd";
+SET DEBUG_SYNC="lock_rec_store_on_page_infimum_end SIGNAL trx2_moved_locks WAIT_FOR trx2_cont";
+#################
+# We need to update clustered record without changing ordering fields and
+# changing the size of non-ordering fields to cause locks moving from deleted
+# record to infimum.
+###
+--send UPDATE t SET c = NULL WHERE pk = 10
+
+
+--connect(trx3, localhost,root,,)
+SET DEBUG_SYNC="now WAIT_FOR trx2_start_waiting";
+#################
+# The condition wariable waiting in lock_wait() must be finished by timeout
+###
+SET innodb_lock_wait_timeout=1;
+BEGIN;
+SET DEBUG_SYNC="lock_wait_start SIGNAL trx3_start_waiting WAIT_FOR trx3_cont_waiting";
+SET DEBUG_SYNC="lock_sys_t_cancel_enter SIGNAL trx3_cancel_enter WAIT_FOR trx3_cont_cancel_waiting";
+--send UPDATE t SET c = "abcdefghij" WHERE pk = 10
+
+--connection default
+SET DEBUG_SYNC="now WAIT_FOR trx3_start_waiting";
+COMMIT;
+SET DEBUG_SYNC="now WAIT_FOR trx2_wait_end";
+SET DEBUG_SYNC="now SIGNAL trx3_cont_waiting";
+SET DEBUG_SYNC="now WAIT_FOR trx3_cancel_enter";
+SET DEBUG_SYNC="now SIGNAL trx2_cont_upd";
+SET DEBUG_SYNC="now WAIT_FOR trx2_moved_locks";
+#################
+# If the bug is not fixed, there will be assertion failure here, because trx2
+# moved trx3 lock from deleted record to infimum when trx3 tried to cancel the
+# lock.
+###
+SET DEBUG_SYNC="now SIGNAL trx3_cont_cancel_waiting";
+SET DEBUG_SYNC="now SIGNAL trx2_cont";
+
+--disconnect trx2
+--disconnect trx3
+--connection default
+SET DEBUG_SYNC="RESET";
+DROP TABLE t;
+--source include/wait_until_count_sessions.inc
diff --git a/mysql-test/suite/innodb/t/lock_update_split_rc.test b/mysql-test/suite/innodb/t/lock_update_split_rc.test
new file mode 100644
index 00000000..38910e53
--- /dev/null
+++ b/mysql-test/suite/innodb/t/lock_update_split_rc.test
@@ -0,0 +1,76 @@
+--source include/have_innodb.inc
+--source include/have_debug.inc
+--source include/count_sessions.inc
+
+CREATE TABLE t (
+ `a` INT NOT NULL,
+ `b` INT NOT NULL,
+ PRIMARY KEY (`a`)
+) ENGINE=InnoDB;
+
+--disable_query_log
+SET @old_innodb_limit_optimistic_insert_debug = @@innodb_limit_optimistic_insert_debug;
+--enable_query_log
+
+SET GLOBAL innodb_limit_optimistic_insert_debug = 3;
+
+INSERT INTO t VALUES(10, 0);
+INSERT INTO t VALUES(20, 0);
+INSERT INTO t VALUES(30, 0);
+
+SET TRANSACTION ISOLATION LEVEL READ COMMITTED;
+XA START '1';
+REPLACE INTO t VALUES(10, 1);
+REPLACE INTO t VALUES(20, 1);
+
+# We need the following sync point because mysql_insert() resets
+# trx->duplicates with the following condition:
+#
+# if (duplic == DUP_REPLACE &&
+# (!table->triggers || !table->triggers->has_delete_triggers()))
+# table->file->extra(HA_EXTRA_WRITE_CANNOT_REPLACE);
+#
+# and ha_innobase::extra() resets trx_t::duplicates, but we need
+# lock_update_split_right() to be invoked when trx->duplicates is set to
+# repeat the bug. So the transaction will hang just after
+# row_insert_for_mysql() call until another transaction inserts new row and
+# splits the page.
+SET DEBUG_SYNC= 'ib_after_row_insert SIGNAL inserted WAIT_FOR cont';
+--send REPLACE INTO t VALUES(30, 1)
+
+connect (con1,localhost,root);
+SET TRANSACTION ISOLATION LEVEL READ COMMITTED;
+XA START '2';
+SET DEBUG_SYNC= 'now WAIT_FOR inserted';
+# The following statement will cause page split and (20, ...) will be split
+# record. As the previous REPLACE set non-gap X-lock on it,
+# lock_update_split_right() and lock_rec_inherit_to_gap() will 'inherit' the
+# lock from the very first (20, ...) new right page record to the supremum of
+# the old left page, what should not be for READ COMMITTED isolation level
+INSERT INTO t VALUES(40, 2);
+SET DEBUG_SYNC= 'now SIGNAL cont';
+
+--connection default
+--reap
+XA END '1';
+# This will cause the assertion failure, because the supremum of the left page
+# has X-lock.
+XA PREPARE '1';
+--connection default
+XA COMMIT '1';
+
+--connection con1
+XA END '2';
+XA PREPARE '2';
+XA COMMIT '2';
+--disconnect con1
+
+--connection default
+SET DEBUG_SYNC= "RESET";
+DROP TABLE t;
+
+--disable_query_log
+SET GLOBAL innodb_limit_optimistic_insert_debug = @old_innodb_limit_optimistic_insert_debug;
+--enable_query_log
+
+--source include/wait_until_count_sessions.inc
diff --git a/mysql-test/suite/innodb/t/log_corruption.test b/mysql-test/suite/innodb/t/log_corruption.test
new file mode 100644
index 00000000..b4466c5e
--- /dev/null
+++ b/mysql-test/suite/innodb/t/log_corruption.test
@@ -0,0 +1,642 @@
+--source include/have_innodb.inc
+--source include/have_innodb_16k.inc
+--source include/no_valgrind_without_big.inc
+
+--disable_query_log
+call mtr.add_suppression("InnoDB: Upgrade after a crash is not supported");
+call mtr.add_suppression("InnoDB: Plugin initialization aborted");
+call mtr.add_suppression("Plugin 'InnoDB' init function returned error");
+call mtr.add_suppression("Plugin 'InnoDB' registration as a STORAGE ENGINE failed");
+call mtr.add_suppression("InnoDB: Unsupported redo log format");
+call mtr.add_suppression("InnoDB: No valid checkpoint was found");
+call mtr.add_suppression("InnoDB: Invalid log header checksum");
+call mtr.add_suppression("InnoDB: Missing MLOG_CHECKPOINT");
+call mtr.add_suppression("InnoDB: MLOG_FILE_NAME incorrect");
+call mtr.add_suppression("InnoDB: ############### CORRUPT LOG RECORD FOUND");
+call mtr.add_suppression("InnoDB: Log scan aborted at LSN");
+call mtr.add_suppression("InnoDB: Missing MLOG_FILE_NAME or MLOG_FILE_DELETE before MLOG_CHECKPOINT for tablespace 42\\r?$");
+call mtr.add_suppression("InnoDB: Obtaining redo log encryption key version 1 failed");
+call mtr.add_suppression("InnoDB: Decrypting checkpoint failed");
+call mtr.add_suppression("InnoDB: Log file .*ib_logfile1 is of different size 2097152 bytes than other log files (1048576|4194304) bytes!");
+call mtr.add_suppression("InnoDB: The change buffer is corrupted");
+--enable_query_log
+
+let bugdir= $MYSQLTEST_VARDIR/tmp/log_corruption;
+--mkdir $bugdir
+--let SEARCH_FILE = $MYSQLTEST_VARDIR/log/mysqld.1.err
+
+let $check_no_innodb=SELECT * FROM INFORMATION_SCHEMA.ENGINES
+WHERE engine = 'innodb'
+AND support IN ('YES', 'DEFAULT', 'ENABLED');
+
+write_file $bugdir/ib_buffer_pool;
+EOF
+
+--let $dirs= --innodb-data-home-dir=$bugdir --innodb-log-group-home-dir=$bugdir
+
+perl;
+do "$ENV{MTR_SUITE_DIR}/../innodb/include/crc32.pl";
+# Create a dummy system tablespace file using the default innodb_page_size=16k
+die unless open OUT, ">", "$ENV{bugdir}/ibdata1";
+binmode OUT;
+
+# We calculate innodb_checksum_algorithm=crc32 for the pages.
+# The following bytes are excluded:
+# bytes 0..3 (the checksum is stored there)
+# bytes 26..37 (encryption key version, post-encryption checksum, tablespace id)
+# bytes $page_size-8..$page_size-1 (checksum, LSB of FIL_PAGE_LSN)
+my $polynomial = 0x82f63b78; # CRC-32C
+
+# Tablespace header page with valid FSP_SIZE=768 pages.
+# Also, write a dummy FSEG_MAGIC_N at offset 60 to keep fseg_inode_try_get()
+# happy when fseg_n_reserved_pages() is following an invalid pointer
+# from the all-zero change buffer header page (page 3).
+## FIL_PAGE_OFFSET
+my $head = pack("Nx[18]", 0);
+## FSP_PAGE_SIZE, # FSEG_MAGIC_N
+my $body = pack("x[8]Nx[10]Nx[16312]", 768, 97937874);
+my $ck = mycrc32($head, 0, $polynomial) ^ mycrc32($body, 0, $polynomial);
+print OUT pack("N",$ck).$head.pack("x[12]").$body.pack("Nx[4]",$ck);
+# Dummy pages 1..6.
+$body = pack("x[16338]");
+for (my($page) = 1; $page < 7; $page++)
+{
+ ## FIL_PAGE_OFFSET
+ $head = pack("Nx[18]", $page);
+ $ck = mycrc32($head, 0, $polynomial) ^ mycrc32($body, 0, $polynomial);
+ print OUT pack("N",$ck).$head.pack("x[16350]Nx[4]",$ck);
+}
+# Dictionary header page (page 7).
+## FIL_PAGE_OFFSET
+$head = pack("Nx[18]", 7);
+## DICT_HDR_TABLES,DICT_HDR_INDEXES
+$body = pack("x[32]Nx[8]Nx[16290]", 8, 9);
+$ck = mycrc32($head, 0, $polynomial) ^ mycrc32($body, 0, $polynomial);
+print OUT pack("N",$ck).$head.pack("x[12]").$body.pack("Nx[4]",$ck);
+
+# Empty SYS_TABLES page (page 8).
+## FIL_PAGE_OFFSET, FIL_PAGE_PREV, FIL_PAGE_NEXT, FIL_PAGE_TYPE
+$head = pack("NNNx[8]n", 8, ~0, ~0, 17855);
+## PAGE_N_DIR_SLOTS, PAGE_HEAP_TOP, PAGE_INDEX_ID == DICT_TABLES_ID
+$body = pack("nnx[31]Cx[20]", 2, 124, 1);
+$body .= pack("nxnn", 0x801, 3, 116) . "infimum";
+$body .= pack("xnxnxx", 0x901, 0x803) . "supremum";
+$body .= pack("x[16248]nn", 116, 101);
+$ck = mycrc32($head, 0, $polynomial) ^ mycrc32($body, 0, $polynomial);
+print OUT pack("N",$ck).$head.pack("x[12]").$body.pack("Nx[4]",$ck);
+
+# Empty SYS_INDEXES page (page 9).
+## FIL_PAGE_OFFSET, FIL_PAGE_PREV, FIL_PAGE_NEXT, FIL_PAGE_TYPE
+$head = pack("NNNx[8]n", 9, ~0, ~0, 17855);
+## PAGE_N_DIR_SLOTS, PAGE_HEAP_TOP, PAGE_INDEX_ID == DICT_INDEXES_ID
+$body = pack("nnx[31]Cx[20]", 2, 124, 3);
+$body .= pack("nxnn", 0x801, 3, 116) . "infimum";
+$body .= pack("xnxnxx", 0x901, 0x803) . "supremum";
+$body .= pack("x[16248]nn", 116, 101);
+$ck = mycrc32($head, 0, $polynomial) ^ mycrc32($body, 0, $polynomial);
+print OUT pack("N",$ck).$head.pack("x[12]").$body.pack("Nx[4]",$ck);
+
+print OUT chr(0) x (759 * 16384);
+close OUT or die;
+
+# Create a redo log from before MariaDB 10.2.2/MySQL 5.7.9
+die unless open OUT, ">", "$ENV{bugdir}/ib_logfile0";
+binmode OUT;
+print OUT pack("x[9]nx[5]", 0x1286), " ", chr(0) x 492;
+print OUT pack("x[13]nCNnxxNNx[256]", 0x1286, 12, 0x80c, 0xf0, ~0, ~0);
+print OUT pack("H*x[1240]", "590DBAACFE922582");
+print OUT pack("H*x[5]", "800009440022000c0000000138");
+print OUT pack("H*x[475]H*", "12860cb7809781e80006626f677573", "089C0ADA");
+print OUT chr(0) x 2094592;
+close OUT or die;
+EOF
+
+--echo # redo log from before MariaDB 10.2.2/MySQL 5.7.9
+--let $restart_parameters= $dirs
+--source include/restart_mysqld.inc
+eval $check_no_innodb;
+--source include/shutdown_mysqld.inc
+
+let SEARCH_PATTERN=InnoDB: Upgrade after a crash is not supported. This redo log was created before MariaDB 10\\.2\\.2\\.;
+--source include/search_pattern_in_file.inc
+
+--echo # redo log from before MariaDB 10.2.2, with corrupted log checkpoint
+--move_file $bugdir/ib_logfile0 $bugdir/ib_logfile
+perl;
+# Create a dummy second redo log file
+die unless open OUT, ">", "$ENV{bugdir}/ib_logfile0";
+binmode OUT;
+print OUT chr(0) x 1048576;
+close OUT or die;
+EOF
+--source include/start_mysqld.inc
+eval $check_no_innodb;
+--source include/shutdown_mysqld.inc
+
+let SEARCH_PATTERN=InnoDB: Upgrade after a crash is not supported. This redo log was created before MariaDB 10\\.2\\.2, and we did not find a valid checkpoint;
+--source include/search_pattern_in_file.inc
+
+--echo # redo log from before MariaDB 10.2.2, with corrupted log block
+--remove_file $bugdir/ib_logfile0
+--move_file $bugdir/ib_logfile $bugdir/ib_logfile0
+# Create a dummy second redo log file that does not contain payload.
+--copy_file $bugdir/ib_logfile0 $bugdir/ib_logfile1
+
+perl;
+die unless open OUT, "+<", "$ENV{bugdir}/ib_logfile0";
+binmode OUT;
+die unless seek(OUT, 0x800, 0);
+print OUT pack("Nx[508]", 0xc0deba5e);
+close OUT or die;
+EOF
+
+--source include/start_mysqld.inc
+eval $check_no_innodb;
+--source include/shutdown_mysqld.inc
+--source include/search_pattern_in_file.inc
+
+--echo # empty redo log from before MariaDB 10.2.2
+perl;
+die unless open OUT, "+<", "$ENV{bugdir}/ib_logfile0";
+binmode OUT;
+die unless seek(OUT, 0x800, 0);
+print OUT pack("NnnNx[496]N", 0x80000944, 12, 12, 0, 0xb2a);
+close OUT or die;
+EOF
+--let $restart_parameters= $dirs --innodb-force-recovery=5 --innodb-log-file-size=4m
+--source include/start_mysqld.inc
+SELECT COUNT(*) FROM INFORMATION_SCHEMA.ENGINES
+WHERE engine = 'innodb'
+AND support IN ('YES', 'DEFAULT', 'ENABLED');
+--source include/shutdown_mysqld.inc
+--let SEARCH_PATTERN= InnoDB: Upgrading redo log:
+--source include/search_pattern_in_file.inc
+--let $restart_parameters= $dirs
+
+--echo # Corrupted multi-file redo log from before MariaDB 10.2.2
+--move_file $bugdir/ib_logfile0 $bugdir/ib_logfile
+perl;
+die unless open OUT, ">", "$ENV{bugdir}/ib_logfile0";
+binmode OUT;
+print OUT pack("x[9]nx[5]", 0x1286), " ", chr(0) x 492;
+print OUT pack("x[13]nCNnxxNNx[256]", 0x1286, 12, 0x20000c, 0xf0, ~0, ~0);
+print OUT pack("H*x[1240]", "B41DCAC4525D1217");
+print OUT pack("H*x[5]", "800009440022000c0000000138");
+print OUT pack("H*x[475]H*", "12860cb7809781e80006626f677573", "089C0ADA");
+print OUT chr(0) x 1046016;
+close OUT or die;
+
+die unless open OUT, ">", "$ENV{bugdir}/ib_logfile1";
+binmode OUT;
+die unless seek(OUT, 0xFF800, 0);
+print OUT chr(0) x 2048;
+close OUT or die;
+EOF
+
+--let $restart_parameters= $dirs --innodb-force-recovery=5 --innodb-log-file-size=4m
+--source include/start_mysqld.inc
+SELECT COUNT(*) FROM INFORMATION_SCHEMA.ENGINES
+WHERE engine = 'innodb'
+AND support IN ('YES', 'DEFAULT', 'ENABLED');
+--source include/shutdown_mysqld.inc
+let SEARCH_PATTERN=InnoDB: Upgrade after a crash is not supported. This redo log was created before MariaDB 10\\.2\\.2, and it appears corrupted;
+--source include/search_pattern_in_file.inc
+
+--echo # Empty multi-file redo log (wrong offset) from before MariaDB 10.2.2
+perl;
+die unless open OUT, "+<", "$ENV{bugdir}/ib_logfile1";
+binmode OUT;
+die unless seek(OUT, 0xFF800, 0);
+print OUT pack("NnnNx[496]N", 0x80000944, 12, 12, 0, 0xb2a);
+print OUT chr(0) x 1536;
+close OUT or die;
+EOF
+
+--let $restart_parameters= $dirs --innodb-force-recovery=5 --innodb-log-file-size=4m
+--source include/start_mysqld.inc
+SELECT COUNT(*) FROM INFORMATION_SCHEMA.ENGINES
+WHERE engine = 'innodb'
+AND support IN ('YES', 'DEFAULT', 'ENABLED');
+--source include/shutdown_mysqld.inc
+--let SEARCH_PATTERN= Upgrade after a crash is not supported. This redo log was created before MariaDB 10\\.2\\.2, and we did not find a valid checkpoint\\.
+--source include/search_pattern_in_file.inc
+
+--echo # Multi-file redo log with size mismatch from after MariaDB 10.2.2
+perl;
+do "$ENV{MTR_SUITE_DIR}/../innodb/include/crc32.pl";
+my $polynomial = 0x82f63b78; # CRC-32C
+
+die unless open OUT, "+<", "$ENV{bugdir}/ib_logfile0";
+binmode OUT;
+$_= pack("Nx[5]nx[5]", 1, 0x1286) . "BogoDB 1.2.3.4" . chr(0) x 478;
+print OUT $_, pack("N", mycrc32($_, 0, $polynomial));
+# checkpoint page 1 and all-zero checkpoint 2
+$_= pack("x[13]nCNNx[484]", 0x1286, 12, 0, 0x20080c);
+print OUT $_, pack("N", mycrc32($_, 0, $polynomial));
+print OUT chr(0) x 1024;
+close OUT or die;
+die unless open OUT, ">", "$ENV{bugdir}/ib_logfile1";
+binmode OUT;
+die unless seek(OUT, 0xFF800, 0);
+print OUT chr(0) x 2048;
+close OUT or die;
+EOF
+
+--echo # Corrupted multi-file redo log from after MariaDB 10.2.2
+--let $restart_parameters= $dirs --innodb-force-recovery=5 --innodb-log-file-size=4m
+--source include/start_mysqld.inc
+SELECT COUNT(*) FROM INFORMATION_SCHEMA.ENGINES
+WHERE engine = 'innodb'
+AND support IN ('YES', 'DEFAULT', 'ENABLED');
+--source include/shutdown_mysqld.inc
+--source include/search_pattern_in_file.inc
+--let SEARCH_PATTERN=InnoDB: No valid checkpoint was found; the log was created with BogoDB 1\\.2\\.3\\.4\\.
+--source include/search_pattern_in_file.inc
+
+perl;
+die unless open OUT, ">", "$ENV{bugdir}/ib_logfile1";
+binmode OUT;
+die unless seek(OUT, 0x1FFFFF, 0);
+print OUT chr(0);
+close OUT or die;
+EOF
+
+--let $restart_parameters= $dirs --innodb-force-recovery=5 --innodb-log-file-size=4m
+--source include/start_mysqld.inc
+SELECT COUNT(*) FROM INFORMATION_SCHEMA.ENGINES
+WHERE engine = 'innodb'
+AND support IN ('YES', 'DEFAULT', 'ENABLED');
+--source include/shutdown_mysqld.inc
+--let SEARCH_PATTERN=InnoDB: Log file .*ib_logfile1 is of different size 2097152 bytes than other log files 1048576 bytes!
+--source include/search_pattern_in_file.inc
+--let SEARCH_PATTERN=InnoDB: No valid checkpoint was found; the log was created with BogoDB 1\\.2\\.3\\.4\\.
+--source include/search_pattern_in_file.inc
+
+--echo # Empty multi-file redo log from after MariaDB 10.2.2
+perl;
+do "$ENV{MTR_SUITE_DIR}/../innodb/include/crc32.pl";
+my $polynomial = 0x82f63b78; # CRC-32C
+
+die unless open OUT, "+<", "$ENV{bugdir}/ib_logfile1";
+binmode OUT;
+die unless seek(OUT, 0x800, 0); # the first 2048 bytes are unused!
+$_= pack("Nnnx[500]", 0x80000944, 12, 12);
+print OUT $_, pack("N", mycrc32($_, 0, $polynomial));
+close OUT or die;
+EOF
+
+--let $restart_parameters= $dirs --innodb-force-recovery=5 --innodb-log-file-size=4m
+--source include/start_mysqld.inc
+SELECT COUNT(*) FROM INFORMATION_SCHEMA.ENGINES
+WHERE engine = 'innodb'
+AND support IN ('YES', 'DEFAULT', 'ENABLED');
+--source include/shutdown_mysqld.inc
+--source include/search_pattern_in_file.inc
+--let $restart_parameters= $dirs
+
+--remove_file $bugdir/ib_logfile0
+--move_file $bugdir/ib_logfile $bugdir/ib_logfile0
+
+--echo # redo log from "after" MariaDB 10.2.2, but with invalid header checksum
+perl;
+die unless open OUT, "+<", "$ENV{bugdir}/ib_logfile0";
+binmode OUT;
+print OUT pack("N",2);
+close OUT or die;
+EOF
+--source include/start_mysqld.inc
+eval $check_no_innodb;
+--source include/shutdown_mysqld.inc
+--let SEARCH_PATTERN=InnoDB: Log file .*ib_logfile1 is of different size 2097152 bytes than other log files 4194304 bytes!
+--source include/search_pattern_in_file.inc
+let SEARCH_PATTERN=InnoDB: Invalid log header checksum;
+--source include/search_pattern_in_file.inc
+
+--echo # distant future redo log format, with valid header checksum
+perl;
+die unless open OUT, "+<", "$ENV{bugdir}/ib_logfile0";
+binmode OUT;
+print OUT pack("Nx[5]nx[5]", ~0, 0x1286);
+print OUT "malicious intentions, or perhaps not";
+print OUT pack("x[456]N", 0x8a1bb475);
+close OUT or die;
+EOF
+--source include/start_mysqld.inc
+eval $check_no_innodb;
+--source include/shutdown_mysqld.inc
+let SEARCH_PATTERN=InnoDB: Unsupported redo log format. The redo log was created with malicious intentions, or perhaps\.;
+--source include/search_pattern_in_file.inc
+
+--echo # valid header, but old-format checkpoint blocks
+perl;
+die unless open OUT, "+<", "$ENV{bugdir}/ib_logfile0";
+binmode OUT;
+# header block
+print OUT pack("Nx[5]nx[5]", 1, 0x1286);
+print OUT "malicious intentions, or perhaps not";
+print OUT pack("x[456]N", 0xd42d53a2);
+# old-format checkpoint block 1
+print OUT pack("x[13]nCNnxxNNx[256]", 0x1286, 12, 0x80c, 0xf0, ~0, ~0);
+print OUT pack("H*x[1240]", "590DBAACFE922582");
+print OUT pack("H*x[5]", "800009440022000c0000000138");
+print OUT pack("H*x[475]H*", "12860cb7809781e80006626f677573", "089C0ADA");
+close OUT or die;
+EOF
+--source include/start_mysqld.inc
+eval $check_no_innodb;
+--source include/shutdown_mysqld.inc
+--let SEARCH_PATTERN=InnoDB: No valid checkpoint was found; the log was created with malicious intentions, or perhaps\\.
+--source include/search_pattern_in_file.inc
+
+--echo # valid header, valid checkpoint 1, all-zero (invalid) checkpoint 2, invalid block checksum
+perl;
+die unless open OUT, "+<", "$ENV{bugdir}/ib_logfile0";
+binmode OUT;
+die unless seek(OUT, 0x210, 0);
+print OUT pack("NNx[264]", 0, 0x80c);
+print OUT pack("NNx[212]N", 0x590dbaac, 0xfe922582, 0xc72d49c4);
+close OUT or die;
+die unless open OUT, ">", "$ENV{bugdir}/ib_logfile1";
+print OUT pack("x[4194304]");
+close OUT or die;
+EOF
+# Anything below innodb_force_recovery=6 must find a valid redo log.
+# Missing tablespace files are tolerated already with innodb_force_recovery=1.
+--let $restart_parameters= $dirs --innodb-force-recovery=5
+--source include/start_mysqld.inc
+eval $check_no_innodb;
+--source include/shutdown_mysqld.inc
+let SEARCH_PATTERN=InnoDB: Invalid log header checksum;
+--source include/search_pattern_in_file.inc
+let SEARCH_PATTERN=InnoDB: Upgrade after a crash is not supported\. The redo log was created with malicious intentions, or perhaps, and it appears corrupted\.;
+--source include/search_pattern_in_file.inc
+
+--echo # same, but with current-version header
+perl;
+die unless open OUT, "+<", "$ENV{bugdir}/ib_logfile0";
+binmode OUT;
+print OUT pack("Nx[5]nx[5]", 103, 0x1286), "MariaDB 10.3.1";
+print OUT pack("x[478]N", 0x85021a0f);
+close OUT or die;
+EOF
+--source include/start_mysqld.inc
+eval $check_no_innodb;
+--source include/shutdown_mysqld.inc
+
+let SEARCH_PATTERN=InnoDB: Invalid log header checksum;
+--source include/search_pattern_in_file.inc
+--echo # --innodb-force-recovery=6 (skip the entire redo log)
+--let $restart_parameters= $dirs --innodb-force-recovery=6
+--source include/start_mysqld.inc
+eval $check_no_innodb;
+--source include/shutdown_mysqld.inc
+--let SEARCH_PATTERN=\\[Note\\] InnoDB: log sequence number 0.*; transaction id 0
+--source include/search_pattern_in_file.inc
+
+--echo # valid header, valid checkpoint 1, all-zero (invalid) checkpoint 2, invalid block number
+perl;
+die unless open OUT, "+<", "$ENV{bugdir}/ib_logfile0";
+binmode OUT;
+# header block
+print OUT pack("Nx[5]nx[5]", 103, 0x1286), "MariaDB 10.3.1";
+print OUT pack("x[478]N", 0x85021a0f);
+# checkpoint page 1 and all-zero checkpoint 2
+print OUT pack("x[13]nCNNx[264]", 0x1286, 12, 0, 0x80c);
+print OUT pack("H*x[212]Nx[1024]", "590DBAACFE922582", 0xc72d49c4);
+# redo log data
+print OUT pack("H*x[5]", "C0DEBA5E0022000c0000000138");
+print OUT pack("H*x[475]H*", "12860cb7809781e80006626f677573", "089C0ADA");
+close OUT or die;
+EOF
+--copy_file $bugdir/ib_logfile0 $bugdir/ib_logfile
+# Anything below innodb_force_recovery=6 must find an invalid redo log.
+# Missing tablespace files are tolerated already with innodb_force_recovery=1.
+--let $restart_parameters= $dirs --innodb-force-recovery=5
+--source include/start_mysqld.inc
+eval $check_no_innodb;
+--source include/shutdown_mysqld.inc
+--echo # --innodb-force-recovery=6 (skip the entire redo log)
+--let $restart_parameters= $dirs --innodb-force-recovery=6
+--source include/start_mysqld.inc
+eval $check_no_innodb;
+--source include/shutdown_mysqld.inc
+
+--echo # Test a corrupted MLOG_FILE_NAME record.
+--echo # valid header, valid checkpoint 1, all-zero (invalid) checkpoint 2
+--remove_file $bugdir/ib_logfile0
+--move_file $bugdir/ib_logfile $bugdir/ib_logfile0
+perl;
+die unless open OUT, "+<", "$ENV{bugdir}/ib_logfile0";
+binmode OUT;
+die unless seek(OUT, 0x800, 0);
+print OUT pack("N", 0x80000944);
+die unless seek(OUT, 0x9fc, 0);
+print OUT pack("N", 0xc86474db);
+close OUT or die;
+EOF
+--let $restart_parameters= $dirs
+--source include/start_mysqld.inc
+eval $check_no_innodb;
+--source include/shutdown_mysqld.inc
+let SEARCH_PATTERN=\\[ERROR\\] InnoDB: Upgrade after a crash is not supported\. The redo log was created with MariaDB 10\.3\.1\.;
+--source include/search_pattern_in_file.inc
+
+--echo # Test a corrupted MLOG_FILE_NAME record.
+--echo # valid header, invalid checkpoint 1, valid checkpoint 2, invalid block
+perl;
+die unless open OUT, "+<", "$ENV{bugdir}/ib_logfile0";
+binmode OUT;
+# header block
+print OUT pack("Nx[5]nx[5]", 103, 0x1286), "MariaDB 10.3.1";
+print OUT pack("x[478]N", 0x85021a0f);
+# invalid (all-zero) checkpoint page 1 and an empty log page
+print OUT chr(0) x 1024;
+# valid checkpoint block 2
+print OUT pack("x[13]nCNNx[264]", 0x1286, 12, 0, 0x80c);
+print OUT pack("H*x[212]N", "590DBAACFE922582", 0xc72d49c4);
+# log page
+print OUT pack("H*", "800009440022000c00000001");
+# MLOG_CHECKPOINT record
+print OUT pack("H*", "38000000000012860c");
+# MLOG_FILE_NAME record
+print OUT pack("H*", "b7809781e80006"), "bigot";
+# padding and wrong log block checksum
+print OUT pack("x[475]N", 150151);
+close OUT or die;
+EOF
+--source include/start_mysqld.inc
+eval $check_no_innodb;
+--source include/shutdown_mysqld.inc
+let SEARCH_PATTERN=InnoDB: Invalid log header checksum
+--source include/search_pattern_in_file.inc
+let SEARCH_PATTERN=\\[ERROR\\] InnoDB: Upgrade after a crash is not supported\. The redo log was created with MariaDB 10\.3\.1, and it appears corrupted\.;
+--source include/search_pattern_in_file.inc
+--echo # valid header, invalid checkpoint 1, valid checkpoint 2, invalid log record
+perl;
+die unless open OUT, "+<", "$ENV{bugdir}/ib_logfile0";
+binmode OUT;
+die unless seek(OUT, 0x9fc, 0);
+print OUT pack("N", 2454333373);
+close OUT or die;
+EOF
+
+--source include/start_mysqld.inc
+eval $check_no_innodb;
+--source include/shutdown_mysqld.inc
+let SEARCH_PATTERN=\\[ERROR\\] InnoDB: Upgrade after a crash is not supported\. The redo log was created with MariaDB 10\.3\.1\.;
+--source include/search_pattern_in_file.inc
+
+--echo # 10.2 missing MLOG_FILE_NAME or MLOG_FILE_DELETE before MLOG_CHECKPOINT
+perl;
+die unless open OUT, "+<", "$ENV{bugdir}/ib_logfile0";
+binmode OUT;
+# header block
+print OUT pack("Nx[5]nx[5]", 1, 0x1286);
+print OUT "ibbackup was here!!!1!";
+print OUT pack("x[470]N", 0x52b54540);
+# invalid (all-zero) checkpoint page 1 and an empty log page
+print OUT chr(0) x 1024;
+# valid checkpoint block 2
+print OUT pack("x[12]NNNx[264]", 0x12860c, 0, 0x80c);
+# pointer to the MLOG_CHECKPOINT record, and checkpoint page checksum
+print OUT pack("H*x[204]NNN", "590DBAACFE922582", 0x128612, 0, 0x101741b);
+# log page
+print OUT pack("H*", "800009440022000c00000001");
+# MLOG_1BYTE record for missing tablespace 42 page 123
+print OUT pack("CCCnC", 128 | 1, 42, 123, 4567, 89);
+# MLOG_CHECKPOINT record
+print OUT pack("CNN", 56, 0, 0x12860c);
+# padding (MLOG_DUMMY_RECORD) and block checksum
+print OUT " " x 481, pack("N", 0x644e6db8);
+close OUT or die;
+EOF
+
+--source include/start_mysqld.inc
+eval $check_no_innodb;
+--source include/shutdown_mysqld.inc
+let SEARCH_PATTERN=\\[ERROR\\] InnoDB: Upgrade after a crash is not supported\. The redo log was created with ibbackup was here!!!1!\.;
+--source include/search_pattern_in_file.inc
+
+--echo # 10.3 missing MLOG_FILE_NAME or MLOG_FILE_DELETE before MLOG_CHECKPOINT
+perl;
+die unless open OUT, "+<", "$ENV{bugdir}/ib_logfile0";
+binmode OUT;
+print OUT pack("Nx[5]nx[5]", 103, 0x1286), "MariaDB 10.3.1";
+print OUT pack("x[478]N", 0x85021a0f);
+close OUT or die;
+EOF
+
+--source include/start_mysqld.inc
+eval $check_no_innodb;
+--source include/shutdown_mysqld.inc
+let SEARCH_PATTERN=\\[ERROR\\] InnoDB: Upgrade after a crash is not supported\. The redo log was created with MariaDB 10\.3\.1\.;
+--source include/search_pattern_in_file.inc
+
+--echo # Empty 10.3 redo log
+perl;
+die unless open OUT, "+<", "$ENV{bugdir}/ib_logfile0";
+binmode OUT;
+die unless seek(OUT, 0x800, 0);
+print OUT pack("NnnNx[496]N", 0x80000944, 12, 12, 1, 0x46c8a2a2);
+close OUT or die;
+EOF
+
+--let $restart_parameters= $dirs --innodb-force-recovery=5 --innodb-log-file-size=4m
+--source include/start_mysqld.inc
+SELECT COUNT(*) FROM INFORMATION_SCHEMA.ENGINES
+WHERE engine = 'innodb'
+AND support IN ('YES', 'DEFAULT', 'ENABLED');
+--source include/shutdown_mysqld.inc
+--let SEARCH_PATTERN= InnoDB: log sequence number 1213964\\b.*; transaction id 0
+--source include/search_pattern_in_file.inc
+
+--echo # Empty 10.2 redo log
+perl;
+die unless open OUT, "+<", "$ENV{bugdir}/ib_logfile0";
+binmode OUT;
+# header block
+print OUT pack("Nx[5]nx[5]", 1, 0x1286);
+print OUT "ibbackup was here!!!1!";
+print OUT pack("x[470]N", 0x52b54540);
+# In encryption.innodb_log_corruption the previous step would
+# replace the block with an encrypted one and update the checkpoint.
+# Restore them.
+# invalid (all-zero) checkpoint page 1 and an empty log page
+print OUT chr(0) x 1024;
+# valid checkpoint block 2
+print OUT pack("x[12]NNNx[264]", 0x12860c, 0, 0x80c);
+# pointer to the MLOG_CHECKPOINT record, and checkpoint page checksum
+print OUT pack("H*x[204]NNN", "590DBAACFE922582", 0x128612, 0, 0x101741b);
+# log page
+print OUT pack("NnnNx[496]N", 0x80000944, 12, 12, 1, 0x46c8a2a2);
+close OUT or die;
+EOF
+
+--source include/start_mysqld.inc
+SELECT COUNT(*) FROM INFORMATION_SCHEMA.ENGINES
+WHERE engine = 'innodb'
+AND support IN ('YES', 'DEFAULT', 'ENABLED');
+--source include/shutdown_mysqld.inc
+--let SEARCH_PATTERN= InnoDB: Upgrading redo log:
+--source include/search_pattern_in_file.inc
+
+--echo # Empty 10.5 redo log
+perl;
+die unless open OUT, "+<", "$ENV{bugdir}/ib_logfile0";
+binmode OUT;
+# header block
+print OUT pack("Nx[5]nx[5]", 0x50485953, 0x1286);
+print OUT "ibbackup was here!!!1!";
+print OUT pack("x[470]N", 0x677700cf);
+# invalid (all-zero) checkpoint page 1 and an empty log page
+print OUT chr(0) x 1024;
+# valid checkpoint block 2
+print OUT pack("x[12]NNNx[264]", 0x12860c, 0, 0x120c);
+# pointer to the FILE_CHECKPOINT record, and checkpoint page checksum
+print OUT pack("H*x[204]NNN", "590DBAACFE922582", 0x128612, 0, 0x3b4ce62d);
+# log page
+print OUT pack("x[2560]NnnNx[496]N", 0x80000944, 12, 12, 1, 0x46c8a2a2);
+close OUT or die;
+EOF
+
+--source include/start_mysqld.inc
+SELECT COUNT(*) FROM INFORMATION_SCHEMA.ENGINES
+WHERE engine = 'innodb'
+AND support IN ('YES', 'DEFAULT', 'ENABLED');
+--source include/shutdown_mysqld.inc
+--let SEARCH_PATTERN= InnoDB: Upgrading redo log:
+--source include/search_pattern_in_file.inc
+
+--echo # Minimal MariaDB 10.1.21 encrypted redo log
+perl;
+die unless open OUT, "+<", "$ENV{bugdir}/ib_logfile0";
+binmode OUT;
+# header and empty checkpoint page 1 (not encrypted)
+print OUT pack("x[9]nx[5]A[4]x[46]Cx[1469]", 0x186e, "", 2);
+# checkpoint page 2 (not encrypted)
+print OUT pack("NNNNNNNN", 0, 1, 0, 0x186e16, 0x816, 0x1000000, ~0, ~0);
+print OUT pack("x[6]Cx[249]", 0x20);
+print OUT pack("H*x[12]nNNn", "FDE012DE6D3BD6AC", 0x201, 1, 1, 0xEFC);
+print OUT pack("H*x[162]",
+ "75774015174BE4723904C88E110E3B50FF5C634167DB058D02A415D2A4A3");
+# log block (encrypted)
+print OUT pack("H*", "80000c380016000c000000015cf22e8aff355642045605c22b97f7cba94cc9932b6032b9c828ef85269024127d3863193b44e52d22eccdd0a8b197ce837f6b530c3042a022738bbac803adc5e7607333409b35c1f6351601a9da83d9b0bc3f389fb288d2bd6a0783066e3b07cae0e276fe83aa522d3f2b59b9549e2338031674383bbef87d7a42f415870fa33685afd3894a9d8214d60b5cde0c776489f45ad0c759e0495bc5d0c91018750070ed21ec1a41bcb9054007851df28e1da15fb662ab219bd558f1569b22671c943bfb0c12e97b604feb0d96a53c05c868e2eea9d4692cd0b6f4625a52adc8251ac955957e33d8c32eb964e416b246b950321a71d5b2e8e95c26e00333abe24ca827cd2eb95cff7b21dce639073f526614816fa2151afdb967aa049b4625cd70881fbd73827c1eb6f70447dcb7755055fa939a2c8ec38fc24f135c22f9f9691bd34a91be7047e5fd68d2e68b0d072cb69c253e14c7111b950b9d6df327f3ffb2a0dc6eff045d64baeb3c75c4ae4aeb41235757f40291540148d79deaff983851247134d7513a550ed7e21bf2e209d8dec51b252f0e9ba6fa33cc2ad0b28d05c04442dac9d233d0ca93d8ef0b81ba82e7396ffaec979b2df97f7249a20d8cb8036b582c245f27e64ac12c8b1d46248b670936893c7c737ba8a4ecf623689c18d79755865626993a43d607611d0736d1c626ebf88946");
+close OUT or die;
+EOF
+
+--let $restart_parameters= $dirs --innodb-force-recovery=5
+--source include/start_mysqld.inc
+if (!$no_cleanup) {
+eval $check_no_innodb;
+--source include/shutdown_mysqld.inc
+--let SEARCH_PATTERN= InnoDB: Obtaining redo log encryption key version 1 failed
+--source include/search_pattern_in_file.inc
+--let SEARCH_PATTERN= InnoDB: Decrypting checkpoint failed
+--source include/search_pattern_in_file.inc
+
+--list_files $bugdir
+--remove_files_wildcard $bugdir
+--rmdir $bugdir
+--let $restart_parameters=
+--source include/start_mysqld.inc
+}
diff --git a/mysql-test/suite/innodb/t/log_data_file_size.opt b/mysql-test/suite/innodb/t/log_data_file_size.opt
new file mode 100644
index 00000000..d9a364a3
--- /dev/null
+++ b/mysql-test/suite/innodb/t/log_data_file_size.opt
@@ -0,0 +1,2 @@
+--loose-innodb-sys-indexes
+--innodb-data-file-path=ibdata1:1M:autoextend
diff --git a/mysql-test/suite/innodb/t/log_data_file_size.test b/mysql-test/suite/innodb/t/log_data_file_size.test
new file mode 100644
index 00000000..fe75b9ab
--- /dev/null
+++ b/mysql-test/suite/innodb/t/log_data_file_size.test
@@ -0,0 +1,80 @@
+--source include/innodb_page_size.inc
+--source include/not_embedded.inc
+
+let INNODB_PAGE_SIZE=`select @@innodb_page_size`;
+let MYSQLD_DATADIR=`select @@datadir`;
+let MYSQLD_IS_DEBUG=`select version() like '%debug%'`;
+--source include/no_checkpoint_start.inc
+SET GLOBAL innodb_file_per_table=0;
+CREATE TABLE t(a INT)ENGINE=InnoDB;
+let INNODB_ROOT_PAGE= `SELECT page_no FROM INFORMATION_SCHEMA.INNODB_SYS_INDEXES WHERE name='GEN_CLUST_INDEX'`;
+SET GLOBAL innodb_file_per_table=1;
+
+CREATE TABLE ibd4(a INT UNIQUE)ENGINE=InnoDB;
+CREATE TABLE ibd4f(a INT UNIQUE)ENGINE=InnoDB;
+CREATE TABLE ibd5(a INT UNIQUE, b INT UNIQUE)ENGINE=InnoDB;
+
+let $drop_tables= DROP TABLE t,ibd4,ibd4f,ibd5;
+--let CLEANUP_IF_CHECKPOINT= $drop_tables;
+--source ../include/no_checkpoint_end.inc
+
+perl;
+use Fcntl 'SEEK_CUR', 'SEEK_END';
+
+my $page_size = $ENV{'INNODB_PAGE_SIZE'};
+my $restart;
+open(FILE, "+<", "$ENV{'MYSQLD_DATADIR'}ibdata1") or die;
+if ($ENV{'MYSQLD_IS_DEBUG'})
+{
+ # It is impractical to ensure that CREATE TABLE t will extend ibdata1.
+ # We rely on innodb_system_tablespace_extend_debug=1
+ # to recover from this fault injection if no size change was redo-logged.
+ my $root = $ENV{'INNODB_ROOT_PAGE'};
+ my $size = sysseek(FILE, 0, SEEK_END) / $page_size;
+ seek(FILE, $page_size * ($root + 1), SEEK_SET) or die;
+ my $empty_tail= 1;
+ while(<FILE>) { unless (/\0*/gso) { $empty_tail= 0; last } }
+ if ($empty_tail)
+ {
+ $restart = "--innodb-data-file-size-debug=$size";
+ truncate(FILE, $page_size * $root);
+ }
+}
+# Clear the doublewrite buffer entries for our tables.
+sysseek(FILE, 6 * $page_size - 190, 0)||die "Unable to seek ibdata1\n";
+sysread(FILE, $_, 12) == 12||die "Unable to read TRX_SYS\n";
+my($magic,$d1,$d2)=unpack "NNN", $_;
+die "magic=$magic, $d1, $d2\n" unless $magic == 536853855 && $d2 >= $d1 + 64;
+sysseek(FILE, $d1 * $page_size, 0)||die "Unable to seek ibdata1\n";
+# Find the pages in the doublewrite buffer
+for (my $d = $d1; $d < $d2 + 64; $d++) {
+ sysread(FILE, $_, $page_size)==$page_size||die "Cannot read doublewrite\n";
+ my($space_id,$offset)=unpack "x[4]Nx[26]N",$_;
+ next unless $space_id && $offset > 3;
+ sysseek(FILE, $d * $page_size, 0)||die "Unable to seek ibdata1\n";
+ syswrite(FILE, chr(0) x $page_size)==$page_size||die;
+}
+close FILE;
+open(FILE, ">$ENV{MYSQLTEST_VARDIR}/log/start_mysqld.txt") || die;
+print FILE "--let \$restart_parameters=$restart\n" if $restart;
+print FILE "--let \$restart_noprint=2\n";
+print FILE "--source include/start_mysqld.inc\n";
+close FILE;
+open(FILE, "+<", "$ENV{'MYSQLD_DATADIR'}test/ibd4.ibd") or die;
+truncate(FILE, $page_size * 4);
+close FILE;
+open(FILE, "+<", "$ENV{'MYSQLD_DATADIR'}test/ibd4f.ibd") or die;
+truncate(FILE, $page_size * 4 + 1234);
+# Work around MDEV-12699 and ensure that the truncated page is all-zero.
+sysseek(FILE, $page_size * 4, 0);
+syswrite(FILE, chr(0) x 1234);
+close FILE;
+open(FILE, "+<", "$ENV{'MYSQLD_DATADIR'}test/ibd5.ibd") or die;
+truncate(FILE, $page_size * 5);
+close FILE;
+EOF
+
+--source $MYSQLTEST_VARDIR/log/start_mysqld.txt
+--remove_file $MYSQLTEST_VARDIR/log/start_mysqld.txt
+
+eval $drop_tables;
diff --git a/mysql-test/suite/innodb/t/log_file.test b/mysql-test/suite/innodb/t/log_file.test
new file mode 100644
index 00000000..805a4b4c
--- /dev/null
+++ b/mysql-test/suite/innodb/t/log_file.test
@@ -0,0 +1,219 @@
+--echo # Testcase for the following bugs
+--echo # Bug#16691130 - ASSERT WHEN INNODB_LOG_GROUP_HOME_DIR DOES NOT EXIST
+--echo # Bug#16418661 - CHANGING NAME IN FOR INNODB_DATA_FILE_PATH SHOULD NOT SUCCEED WITH LOG FILES
+
+--source include/have_innodb.inc
+--source include/no_valgrind_without_big.inc
+
+--disable_query_log
+call mtr.add_suppression("InnoDB: Could not create undo tablespace.*undo002");
+call mtr.add_suppression("InnoDB: InnoDB Database creation was aborted");
+call mtr.add_suppression("Plugin 'InnoDB' init function returned error");
+call mtr.add_suppression("Plugin 'InnoDB' registration as a STORAGE ENGINE failed");
+call mtr.add_suppression("InnoDB: Operating system error number \d+ in a file operation");
+call mtr.add_suppression("InnoDB: The error means the system cannot find the path specified");
+call mtr.add_suppression("InnoDB: File /path/to/non-existent/ib_logfile101 was not found");
+call mtr.add_suppression("InnoDB: Cannot create .path.to.non-existent.ib_logfile101");
+call mtr.add_suppression("InnoDB: The data file '.*ibdata1' was not found but one of the other data files '.*ibdata2' exists");
+call mtr.add_suppression("InnoDB: Tablespace size stored in header is \d+ pages, but the sum of data file sizes is \d+ pages");
+call mtr.add_suppression("InnoDB: Cannot start InnoDB. The tail of the system tablespace is missing");
+call mtr.add_suppression("InnoDB: undo tablespace '.*undo001' exists\. Creating system tablespace with existing undo tablespaces is not supported\. Please delete all undo tablespaces before creating new system tablespace\.");
+call mtr.add_suppression("");
+call mtr.add_suppression("");
+--enable_query_log
+
+let bugdir= $MYSQLTEST_VARDIR/tmp/log_file;
+--mkdir $bugdir
+
+let SEARCH_FILE= $MYSQLTEST_VARDIR/log/mysqld.1.err;
+let $check_no_innodb=SELECT * FROM INFORMATION_SCHEMA.ENGINES
+WHERE engine = 'innodb'
+AND support IN ('YES', 'DEFAULT', 'ENABLED');
+
+let $check_yes_innodb=SELECT COUNT(*) `1` FROM INFORMATION_SCHEMA.ENGINES
+WHERE engine='innodb'
+AND support IN ('YES', 'DEFAULT', 'ENABLED');
+
+--let $ibp=--innodb-log-group-home-dir=$bugdir
+--let $ibp=$ibp --innodb-data-home-dir=$bugdir --innodb-undo-directory=$bugdir
+--let $ibp=$ibp --innodb-undo-logs=20 --innodb-undo-tablespaces=3
+--let $ibp=$ibp --innodb-data-file-path=ibdata1:16M;ibdata2:10M:autoextend
+
+--echo # Start mysqld without the possibility to create innodb_undo_tablespaces
+--let $restart_parameters= $ibp
+--mkdir $bugdir/undo002
+--source include/restart_mysqld.inc
+eval $check_no_innodb;
+--source include/shutdown_mysqld.inc
+
+let SEARCH_PATTERN=\[ERROR\] InnoDB: Could not create undo tablespace '.*undo002';
+--source include/search_pattern_in_file.inc
+
+--echo # Remove undo001,undo002,ibdata1,ibdata2,ib_logfile101
+--remove_file $bugdir/undo001
+--rmdir $bugdir/undo002
+--remove_file $bugdir/ibdata1
+--remove_file $bugdir/ibdata2
+--remove_file $bugdir/ib_logfile101
+--list_files $bugdir
+
+--echo # Start mysqld with non existent innodb_log_group_home_dir
+--let $restart_parameters= $ibp --innodb_log_group_home_dir=/path/to/non-existent/
+--source include/start_mysqld.inc
+eval $check_no_innodb;
+--source include/shutdown_mysqld.inc
+let SEARCH_PATTERN=Cannot create /path/to/non-existent/ib_logfile101;
+--source include/search_pattern_in_file.inc
+
+--list_files $bugdir
+
+--echo # Successfully let InnoDB create tablespaces
+--let $restart_parameters= $ibp
+--source include/start_mysqld.inc
+eval $check_yes_innodb;
+--source include/shutdown_mysqld.inc
+
+--echo # Backup tmp/logfile/*
+--copy_file $bugdir/ibdata1 $bugdir/bak_ibdata1
+--copy_file $bugdir/ibdata2 $bugdir/bak_ibdata2
+--copy_file $bugdir/ib_logfile0 $bugdir/bak_ib_logfile0
+--copy_file $bugdir/undo001 $bugdir/bak_undo001
+--copy_file $bugdir/undo002 $bugdir/bak_undo002
+--copy_file $bugdir/undo003 $bugdir/bak_undo003
+
+--echo # 1. With ibdata2, Without ibdata1
+--remove_file $bugdir/ibdata1
+
+--source include/start_mysqld.inc
+eval $check_no_innodb;
+--source include/shutdown_mysqld.inc
+let SEARCH_PATTERN=The data file '.*ibdata1' was not found but one of the other data files '.*ibdata2' exists;
+--source include/search_pattern_in_file.inc
+
+# clean up & Restore
+--source ../include/log_file_cleanup.inc
+
+--echo # 2. With ibdata1, without ibdata2
+--remove_file $bugdir/ibdata2
+--source include/start_mysqld.inc
+eval $check_no_innodb;
+--source include/shutdown_mysqld.inc
+let SEARCH_PATTERN=InnoDB: Tablespace size stored in header is \d+ pages, but the sum of data file sizes is \d+ pages;
+--source include/search_pattern_in_file.inc
+let SEARCH_PATTERN=InnoDB: Cannot start InnoDB. The tail of the system tablespace is missing;
+--source include/search_pattern_in_file.inc
+
+# clean up & Restore
+--source ../include/log_file_cleanup.inc
+
+--echo # 3. Without ibdata1 & ibdata2
+--remove_file $bugdir/ibdata1
+--remove_file $bugdir/ibdata2
+--list_files $bugdir
+--source include/start_mysqld.inc
+eval $check_no_innodb;
+--source include/shutdown_mysqld.inc
+let SEARCH_PATTERN=InnoDB: undo tablespace .*undo001.* exists\. Creating system tablespace with existing undo tablespaces is not supported\. Please delete all undo tablespaces before creating new system tablespace\.;
+--source include/search_pattern_in_file.inc
+
+# clean up & Restore
+--source ../include/log_file_cleanup.inc
+
+--echo # 4. Without ibdata*, ib_logfile* and with undo00*
+--remove_files_wildcard $bugdir ibdata*
+--remove_files_wildcard $bugdir ib_logfile*
+--list_files $bugdir
+--source include/start_mysqld.inc
+eval $check_no_innodb;
+--source include/shutdown_mysqld.inc
+
+# clean up & Restore
+--source ../include/log_file_cleanup.inc
+
+--echo # 5. Without ibdata*,ib_logfile* files & Without undo002
+--remove_files_wildcard $bugdir ibdata*
+--remove_files_wildcard $bugdir ib_logfile*
+--remove_file $bugdir/undo002
+--list_files $bugdir
+--source include/start_mysqld.inc
+eval $check_no_innodb;
+--source include/shutdown_mysqld.inc
+
+# clean up & Restore
+--source ../include/log_file_cleanup.inc
+
+--echo # 6. Without ibdata*,ib_logfile* files & Without undo001, undo002
+# and with undo003
+--remove_files_wildcard $bugdir ibdata*
+--remove_files_wildcard $bugdir ib_logfile*
+--remove_file $bugdir/undo001
+--remove_file $bugdir/undo002
+--list_files $bugdir
+--source include/start_mysqld.inc
+eval $check_no_innodb;
+--source include/shutdown_mysqld.inc
+let SEARCH_PATTERN=undo tablespace .*undo003.* exists\. Creating system tablespace with existing undo tablespaces is not supported\. Please delete all undo tablespaces before creating new system tablespace\.;
+--source include/search_pattern_in_file.inc
+
+# clean up & Restore
+--source ../include/log_file_cleanup.inc
+
+--echo # 7. With ibdata files & Without undo002
+--remove_file $bugdir/undo002
+--list_files $bugdir
+--source include/start_mysqld.inc
+eval $check_no_innodb;
+--source include/shutdown_mysqld.inc
+let SEARCH_PATTERN=InnoDB: Failed to open the undo tablespace;
+--source include/search_pattern_in_file.inc
+# clean up & Restore
+--source ../include/log_file_cleanup.inc
+
+--echo # 8. With ibdata files & Without undo001, undo002
+--remove_file $bugdir/undo001
+--remove_file $bugdir/undo002
+--list_files $bugdir
+--source include/start_mysqld.inc
+eval $check_no_innodb;
+--source include/shutdown_mysqld.inc
+let SEARCH_PATTERN=InnoDB: Failed to open the undo tablespace;
+--source include/search_pattern_in_file.inc
+
+# clean up & Restore
+--source ../include/log_file_cleanup.inc
+
+--echo # 9. Without ibdata*, without undo*
+--remove_files_wildcard $bugdir ibdata*
+--remove_files_wildcard $bugdir undo00*
+--list_files $bugdir
+--source include/start_mysqld.inc
+eval $check_no_innodb;
+--source include/shutdown_mysqld.inc
+let SEARCH_PATTERN=redo log file .*ib_logfile0.* exists\. Creating system tablespace with existing redo log file is not recommended\. Please delete redo log file before creating new system tablespace\.;
+--source include/search_pattern_in_file.inc
+
+# clean up & Restore
+--source ../include/log_file_cleanup.inc
+
+--echo # 10. With ibdata*, without ib_logfile0
+--remove_file $bugdir/ib_logfile0
+
+--source include/start_mysqld.inc
+eval $check_no_innodb;
+--source include/shutdown_mysqld.inc
+
+--source ../include/log_file_cleanup.inc
+
+--echo # 11. With ibdata*
+--list_files $bugdir
+--source include/start_mysqld.inc
+eval $check_yes_innodb;
+--source include/shutdown_mysqld.inc
+
+--let $restart_parameters=
+--source include/start_mysqld.inc
+
+--echo # Cleanup
+--list_files $bugdir
+--remove_files_wildcard $bugdir
+--rmdir $bugdir
diff --git a/mysql-test/suite/innodb/t/log_file_name.test b/mysql-test/suite/innodb/t/log_file_name.test
new file mode 100644
index 00000000..eb616d7f
--- /dev/null
+++ b/mysql-test/suite/innodb/t/log_file_name.test
@@ -0,0 +1,217 @@
+# WL#7142 InnoDB: Simplify tablespace discovery during crash recovery
+# Test the detection of duplicate tablespaces.
+
+--source include/have_innodb.inc
+--source include/no_valgrind_without_big.inc
+
+# Embedded server does not support crashing
+--source include/not_embedded.inc
+
+SET GLOBAL innodb_file_per_table=ON;
+FLUSH TABLES;
+
+CREATE TABLE t1(a INT PRIMARY KEY) ENGINE=InnoDB;
+
+--source include/restart_mysqld.inc
+--source include/no_checkpoint_start.inc
+CREATE TABLE t3(a INT PRIMARY KEY) ENGINE=InnoDB;
+
+BEGIN;
+INSERT INTO t3 VALUES (33101),(347);
+INSERT INTO t1 VALUES (42),(9),(101);
+RENAME TABLE t1 TO t2;
+UPDATE t2 SET a=347 where a=42;
+COMMIT;
+
+--let CLEANUP_IF_CHECKPOINT=DROP TABLE t2,t3;
+--source include/no_checkpoint_end.inc
+
+--echo # Fault 0 (no real fault): Orphan file with duplicate space_id.
+--copy_file $MYSQLD_DATADIR/test/t2.ibd $MYSQLD_DATADIR/test/t0.ibd
+
+--echo # Fault 1: Two dirty files with the same space_id.
+--copy_file $MYSQLD_DATADIR/test/t2.ibd $MYSQLD_DATADIR/test/t1.ibd
+
+let SEARCH_FILE= $MYSQLTEST_VARDIR/log/mysqld.1.err;
+let $check_no_innodb=SELECT * FROM INFORMATION_SCHEMA.ENGINES
+WHERE engine = 'innodb'
+AND support IN ('YES', 'DEFAULT', 'ENABLED');
+
+# This could fail to refuse InnoDB startup, in case there was a log
+# checkpoint after the INSERT. That is what we checked above.
+--source include/start_mysqld.inc
+eval $check_no_innodb;
+let SEARCH_PATTERN= InnoDB: Ignoring data file '.*t2.ibd' with space ID \d+. Another data file called .*t1.ibd exists with the same space ID;
+--source include/search_pattern_in_file.inc
+
+--source include/shutdown_mysqld.inc
+
+--remove_file $MYSQLD_DATADIR/test/t1.ibd
+
+# This could fail to refuse InnoDB startup, in case there was a log
+# checkpoint after the CREATE TABLE t3. That is what we checked above.
+--echo # Fault 2: Wrong space_id in a dirty file, and a missing file.
+--move_file $MYSQLD_DATADIR/test/t3.ibd $MYSQLD_DATADIR/test/t1.ibd
+
+--source include/start_mysqld.inc
+eval $check_no_innodb;
+
+let SEARCH_PATTERN= InnoDB: Tablespace \d+ was not found at.*t3.ibd;
+--source include/search_pattern_in_file.inc
+
+--source include/shutdown_mysqld.inc
+
+--move_file $MYSQLD_DATADIR/test/t1.ibd $MYSQLD_DATADIR/test/t3.ibd
+
+--echo # Fault 3: Wrong space_id in a dirty file, and no missing file.
+# Swap t2.ibd and t3.ibd.
+--move_file $MYSQLD_DATADIR/test/t3.ibd $MYSQLD_DATADIR/test/t.ibd
+--move_file $MYSQLD_DATADIR/test/t2.ibd $MYSQLD_DATADIR/test/t3.ibd
+--move_file $MYSQLD_DATADIR/test/t.ibd $MYSQLD_DATADIR/test/t2.ibd
+
+--source include/start_mysqld.inc
+eval $check_no_innodb;
+
+let SEARCH_PATTERN= InnoDB: Ignoring data file '.*t[23].ibd' with space ID;
+--source include/search_pattern_in_file.inc
+
+let SEARCH_PATTERN= InnoDB: Tablespace \d+ was not found at .*t1.ibd;
+--source include/search_pattern_in_file.inc
+let SEARCH_PATTERN= InnoDB: Tablespace \d+ was not found at .*t3.ibd;
+--source include/search_pattern_in_file.inc
+let SEARCH_PATTERN= InnoDB: Set innodb_force_recovery=1 to ignore this and to permanently lose all changes to the tablespace;
+--source include/search_pattern_in_file.inc
+
+--source include/shutdown_mysqld.inc
+
+# Swap back t3.ibd, but hide t2.ibd (which the redo log also knows as t1.ibd).
+--move_file $MYSQLD_DATADIR/test/t3.ibd $MYSQLD_DATADIR/test/t.ibd
+--move_file $MYSQLD_DATADIR/test/t2.ibd $MYSQLD_DATADIR/test/t3.ibd
+
+--echo # Fault 4: Missing data file
+
+--source include/start_mysqld.inc
+eval $check_no_innodb;
+--source include/shutdown_mysqld.inc
+
+let SEARCH_PATTERN= InnoDB: Tablespace \d+ was not found at .*t[12].ibd.
+.*InnoDB: Set innodb_force_recovery=1 to ignore this and to permanently lose all changes to the tablespace;
+--source include/search_pattern_in_file.inc
+
+--echo # Fault 5: Wrong type of data file
+
+--mkdir $MYSQLD_DATADIR/test/t2.ibd
+
+--source include/start_mysqld.inc
+eval $check_no_innodb;
+--source include/shutdown_mysqld.inc
+# On Windows, this error message is not output when t2.ibd is a directory!
+#let SEARCH_PATTERN= \[Note\] InnoDB: Cannot read first page of .*t2.ibd;
+#--source include/search_pattern_in_file.inc
+
+--rmdir $MYSQLD_DATADIR/test/t2.ibd
+
+# Create a short file.
+--write_file $MYSQLD_DATADIR/test/t2.ibd
+EOF
+
+--source include/start_mysqld.inc
+eval $check_no_innodb;
+--source include/shutdown_mysqld.inc
+
+let SEARCH_PATTERN= \[Note\] InnoDB: Cannot read first page of .*t2.ibd;
+--source include/search_pattern_in_file.inc
+let SEARCH_PATTERN= .*\[ERROR\] InnoDB: Cannot apply log to \\[page id: space=[1-9][0-9]*, page number=3\\] of corrupted file './test/t2\\.ibd';
+--source include/search_pattern_in_file.inc
+
+# Restore t2.ibd
+--remove_file $MYSQLD_DATADIR/test/t2.ibd
+--move_file $MYSQLD_DATADIR/test/t.ibd $MYSQLD_DATADIR/test/t2.ibd
+
+--source include/start_mysqld.inc
+
+SELECT * FROM t2;
+SELECT * FROM t3;
+SHOW TABLES;
+DROP TABLE t2,t3;
+
+--error ER_CANT_CREATE_TABLE
+CREATE TABLE t0(a INT PRIMARY KEY) ENGINE=InnoDB;
+--error ER_CANT_CREATE_TABLE
+CREATE TABLE t0(a INT PRIMARY KEY) ENGINE=InnoDB;
+--remove_file $MYSQLD_DATADIR/test/t0.ibd
+CREATE TABLE t0(a INT PRIMARY KEY) ENGINE=InnoDB;
+DROP TABLE t0;
+
+--disable_query_log
+# The following are for the orphan file t0.ibd or for the directory t2.ibd:
+call mtr.add_suppression("InnoDB: Operating system error number [0-9]* in a file operation");
+call mtr.add_suppression("InnoDB: Error number \\d+ means");
+call mtr.add_suppression("InnoDB: Cannot create file '.*t0.ibd'");
+call mtr.add_suppression("InnoDB: The file '.*t0\.ibd' already exists");
+call mtr.add_suppression("InnoDB: Cannot open datafile for read-write: '.*t2\.ibd'");
+# The following are for aborted startup without --innodb-force-recovery:
+call mtr.add_suppression("InnoDB: Tablespace .* was not found at .*test");
+call mtr.add_suppression("InnoDB: Cannot read first page of '.*test.[tu]2.ibd': I/O error");
+call mtr.add_suppression("InnoDB: Cannot apply log to \\[page id: space=[1-9][0-9]*, page number=3\\] of corrupted file './test/t2\\.ibd'");
+call mtr.add_suppression("InnoDB: Datafile '.*test.*ibd' is corrupted");
+call mtr.add_suppression("InnoDB: Cannot replay file rename. Remove either file and try again");
+call mtr.add_suppression("InnoDB: Cannot rename.*because the target file exists");
+call mtr.add_suppression("InnoDB: Log scan aborted at LSN");
+# The following are for the --innodb-force-recovery=1 with broken u* tables:
+call mtr.add_suppression("InnoDB: The size of the file .*u[12]\\.ibd is only [1-9][0-9]* bytes, should be at least 65536");
+call mtr.add_suppression("InnoDB: The size of tablespace file '.*test/u[12].ibd' is only");
+call mtr.add_suppression("InnoDB: The error means the system cannot find the path specified");
+call mtr.add_suppression("InnoDB: .*you must create directories");
+call mtr.add_suppression("InnoDB: Cannot open datafile for read-only: '.*u[1-5]\.ibd'");
+call mtr.add_suppression("InnoDB: Could not find a valid tablespace file for `test/u[1-5]`");
+call mtr.add_suppression("InnoDB: Ignoring tablespace for test/u[1-3] because it could not be opened\\.");
+call mtr.add_suppression("InnoDB: Failed to find tablespace for table .* in the cache. Attempting to load the tablespace with space id");
+call mtr.add_suppression("InnoDB: Plugin initialization aborted");
+call mtr.add_suppression("Plugin 'InnoDB' \(init function returned error\|registration as a STORAGE ENGINE failed\)");
+call mtr.add_suppression("InnoDB: Table test/u[123] in the InnoDB data dictionary has tablespace id [1-9][0-9]*, but tablespace with that id or name does not exist\\. Have you deleted or moved \\.ibd files\\?");
+call mtr.add_suppression("InnoDB: Cannot replay rename of tablespace.*");
+FLUSH TABLES;
+--enable_query_log
+
+--source include/no_checkpoint_start.inc
+
+CREATE TABLE u1(a INT PRIMARY KEY) ENGINE=InnoDB;
+CREATE TABLE u2(a INT PRIMARY KEY) ENGINE=InnoDB;
+CREATE TABLE u3(a INT PRIMARY KEY) ENGINE=InnoDB;
+CREATE TABLE u4(a INT PRIMARY KEY) ENGINE=InnoDB;
+INSERT INTO u4 VALUES(1);
+RENAME TABLE u4 TO u5;
+RENAME TABLE u5 TO u6;
+INSERT INTO u6 VALUES(2);
+
+--let CLEANUP_IF_CHECKPOINT=DROP TABLE u1,u2,u3,u6;
+--source include/no_checkpoint_end.inc
+
+--echo # Fault 6: All-zero data file and innodb_force_recovery
+
+--remove_file $MYSQLD_DATADIR/test/u1.ibd
+--remove_file $MYSQLD_DATADIR/test/u2.ibd
+--remove_file $MYSQLD_DATADIR/test/u3.ibd
+
+# InnoDB: Header page consists of zero bytes
+--perl
+die unless open(FILE, ">$ENV{MYSQLD_DATADIR}/test/u1.ibd");
+print FILE "\0" x 16384;
+close(FILE);
+EOF
+
+--exec echo "" > $MYSQLD_DATADIR/test/u2.ibd
+
+--copy_file $MYSQLD_DATADIR/test/u6.ibd $MYSQLD_DATADIR/test/u4.ibd
+
+--let $restart_parameters= --innodb-force-recovery=1
+--source include/start_mysqld.inc
+DROP TABLE u1,u2,u3,u6;
+
+--remove_file $MYSQLD_DATADIR/test/u4.ibd
+
+--echo # List of files:
+--list_files $MYSQLD_DATADIR/test
+
+SHOW TABLES;
diff --git a/mysql-test/suite/innodb/t/log_file_size.test b/mysql-test/suite/innodb/t/log_file_size.test
new file mode 100644
index 00000000..261b024f
--- /dev/null
+++ b/mysql-test/suite/innodb/t/log_file_size.test
@@ -0,0 +1,175 @@
+# Test resizing the InnoDB redo log.
+--source include/innodb_page_size_small.inc
+# Embedded server tests do not support restarting
+--source include/not_embedded.inc
+# DBUG_EXECUTE_IF is needed
+--source include/have_debug.inc
+# This test is slow on buildbot.
+--source include/big_test.inc
+
+--disable_query_log
+call mtr.add_suppression("syntax error in innodb_log_group_home_dir");
+call mtr.add_suppression("Plugin 'InnoDB' init function returned error");
+call mtr.add_suppression("Plugin 'InnoDB' registration as a STORAGE ENGINE failed");
+call mtr.add_suppression("InnoDB: Plugin initialization aborted");
+call mtr.add_suppression("InnoDB: innodb_read_only prevents crash recovery");
+call mtr.add_suppression("InnoDB: Log file .*ib_logfile1.* size");
+call mtr.add_suppression("InnoDB: File .*ib_logfile0 (is too small|was not found)");
+call mtr.add_suppression("InnoDB: Expecting only ib_logfile0");
+FLUSH TABLES;
+--enable_query_log
+let MYSQLD_DATADIR= `select @@datadir`;
+CREATE TABLE t1(a INT PRIMARY KEY) ENGINE=InnoDB;
+
+--source include/shutdown_mysqld.inc
+perl;
+do "$ENV{MTR_SUITE_DIR}/include/crc32.pl";
+my $file = "$ENV{MYSQLD_DATADIR}ib_logfile0";
+open(FILE, "<$file") || die "Unable to open $file\n";
+seek(FILE, 4096, 0) || die "Unable to seek $file\n";
+die unless read(FILE, $_, 8) == 8;
+my ($lsn_hi,$lsn_lo) = unpack("NN", $_);
+seek(FILE, 8192, 0) || die "Unable to seek $file\n";
+die unless read(FILE, $_, 8) == 8;
+my ($cp2hi,$cp2lo) = unpack("NN", $_);
+if ($cp2hi < $lsn_hi) {}
+elsif ($cp2hi > $lsn_hi || $cp2lo > $lsn_lo)
+{ $lsn_hi=$cp2hi;$lsn_lo=$cp2lo; }
+close(FILE);
+open(FILE, ">", $file) or die "Unable to open $file\n";
+binmode FILE;
+my $polynomial = 0x82f63b78; # CRC-32C
+my ($header, $checkpoint, $log);
+$header = "Phys" . pack("x[4]NN", $lsn_hi, $lsn_lo) .
+ "some Perl code" . pack("x[478]");
+$header .= pack("Nx[3584]", mycrc32($header, 0, $polynomial));
+$checkpoint = pack("NNNNx[44]", $lsn_hi, $lsn_lo, $lsn_hi, $lsn_lo);
+$checkpoint .= pack("Nx[8128]", mycrc32($checkpoint, 0, $polynomial));
+$log = pack("CxxNN", 0xfa, $lsn_hi, $lsn_lo);
+$log .= pack("CN", 1, mycrc32($log, 0, $polynomial));
+print FILE $header, $checkpoint, $log;
+close(FILE) or die "Unable to close $file\n";
+EOF
+
+let $check_no_innodb=SELECT * FROM INFORMATION_SCHEMA.ENGINES
+WHERE engine = 'innodb'
+AND support IN ('YES', 'DEFAULT', 'ENABLED');
+
+--let $restart_parameters= --innodb-log-file-size=4m
+--source include/start_mysqld.inc
+
+let SEARCH_FILE= $MYSQLTEST_VARDIR/log/mysqld.1.err;
+CHECK TABLE t1;
+
+--let $restart_parameters= --innodb-log-file-size=20M
+--source include/restart_mysqld.inc
+
+BEGIN;
+INSERT INTO t1 VALUES (42);
+
+let $restart_parameters = --innodb-log-file-size=12M;
+let $shutdown_timeout=0;
+--source include/restart_mysqld.inc
+
+SELECT * FROM t1;
+
+INSERT INTO t1 VALUES (42);
+BEGIN;
+DELETE FROM t1;
+
+let $restart_parameters = --innodb-log-file-size=5M;
+--source include/restart_mysqld.inc
+let $shutdown_timeout=;
+
+SELECT * FROM t1;
+
+INSERT INTO t1 VALUES (0),(123);
+
+let SEARCH_ABORT = NOT FOUND;
+
+BEGIN;
+DELETE FROM t1 WHERE a>0;
+
+--echo # Persist the state of the above incomplete transaction by
+--echo # causing a redo log write for another transaction.
+--connect(con1, localhost, root)
+SET GLOBAL innodb_flush_log_at_trx_commit=1;
+DELETE FROM t1 WHERE a=0;
+--disconnect con1
+--connection default
+
+--source include/kill_mysqld.inc
+
+--let $restart_parameters= --innodb-log-group-home-dir=foo\;bar
+--source include/start_mysqld.inc
+--error ER_UNKNOWN_STORAGE_ENGINE
+SELECT * FROM t1;
+let SEARCH_PATTERN= syntax error in innodb_log_group_home_dir;
+--source include/search_pattern_in_file.inc
+
+--let $restart_parameters= --debug=d,innodb_log_abort_1
+--source include/restart_mysqld.inc
+--error ER_UNKNOWN_STORAGE_ENGINE
+SELECT * FROM t1;
+let SEARCH_PATTERN= InnoDB: Starting crash recovery from checkpoint LSN=.*;
+--source include/search_pattern_in_file.inc
+
+--let $restart_parameters= --innodb-read-only
+--source include/restart_mysqld.inc
+
+--error ER_UNKNOWN_STORAGE_ENGINE
+SELECT * FROM t1;
+let SEARCH_PATTERN= InnoDB: innodb_read_only prevents crash recovery;
+--source include/search_pattern_in_file.inc
+
+--let $restart_parameters= --debug=d,innodb_log_abort_5
+--source include/restart_mysqld.inc
+--error ER_UNKNOWN_STORAGE_ENGINE
+SELECT * FROM t1;
+let SEARCH_PATTERN= redo log from 5\\.000MiB to [0-9.]*[KMGT]iB;
+--source include/search_pattern_in_file.inc
+
+--let $restart_parameters= --innodb-read-only
+--source include/restart_mysqld.inc
+--error ER_UNKNOWN_STORAGE_ENGINE
+SELECT * FROM t1;
+let SEARCH_PATTERN= InnoDB: innodb_read_only prevents crash recovery;
+--source include/search_pattern_in_file.inc
+
+# Trigger an error in recovery.
+
+--move_file $MYSQLD_DATADIR/ib_logfile0 $MYSQLD_DATADIR/ib_logfile101
+--write_file $MYSQLD_DATADIR/ib_logfile0
+garbage
+EOF
+
+--let $restart_parameters=
+--source include/restart_mysqld.inc
+--error ER_UNKNOWN_STORAGE_ENGINE
+SELECT * FROM t1;
+let SEARCH_PATTERN= InnoDB: File .*ib_logfile0 is too small;
+--source include/search_pattern_in_file.inc
+--move_file $MYSQLD_DATADIR/ib_logfile0 $MYSQLD_DATADIR/ib_logfile1
+--move_file $MYSQLD_DATADIR/ib_logfile101 $MYSQLD_DATADIR/ib_logfile0
+
+--source include/restart_mysqld.inc
+--error ER_UNKNOWN_STORAGE_ENGINE
+SELECT * FROM t1;
+let SEARCH_PATTERN= InnoDB: Expecting only ib_logfile0;
+--source include/search_pattern_in_file.inc
+
+--remove_file $MYSQLD_DATADIR/ib_logfile1
+--move_file $MYSQLD_DATADIR/ib_logfile0 $MYSQLD_DATADIR/ib_logfile101
+
+--source include/restart_mysqld.inc
+--error ER_UNKNOWN_STORAGE_ENGINE
+let SEARCH_PATTERN= InnoDB: File .*ib_logfile0 was not found;
+--source include/search_pattern_in_file.inc
+--move_file $MYSQLD_DATADIR/ib_logfile101 $MYSQLD_DATADIR/ib_logfile0
+
+--source include/restart_mysqld.inc
+SELECT * FROM t1;
+DROP TABLE t1;
+
+--let SEARCH_PATTERN= InnoDB: Resizing redo log from 5\\.000MiB to [0-9.]*[KMGT]iB; LSN=\\d+\\b
+--source include/search_pattern_in_file.inc
diff --git a/mysql-test/suite/innodb/t/log_file_size_online.combinations b/mysql-test/suite/innodb/t/log_file_size_online.combinations
new file mode 100644
index 00000000..846aff4c
--- /dev/null
+++ b/mysql-test/suite/innodb/t/log_file_size_online.combinations
@@ -0,0 +1,11 @@
+[encrypted]
+--plugin-load-add=$FILE_KEY_MANAGEMENT_SO
+--loose-file-key-management
+--loose-file-key-management-filename=$MYSQL_TEST_DIR/std_data/logkey.txt
+--innodb-encrypt-log=ON
+--innodb-log-file-size=5M
+
+[slow]
+--innodb-flush-sync=OFF
+--innodb-encrypt-log=OFF
+--innodb-log-file-size=5M
diff --git a/mysql-test/suite/innodb/t/log_file_size_online.test b/mysql-test/suite/innodb/t/log_file_size_online.test
new file mode 100644
index 00000000..65551f13
--- /dev/null
+++ b/mysql-test/suite/innodb/t/log_file_size_online.test
@@ -0,0 +1,44 @@
+--source include/have_innodb.inc
+--source include/have_sequence.inc
+--source include/no_valgrind_without_big.inc
+
+let SEARCH_FILE = $MYSQLTEST_VARDIR/log/mysqld.1.err;
+
+SET GLOBAL innodb_log_file_size=4194304;
+SHOW VARIABLES LIKE 'innodb_log_file_size';
+SELECT global_value FROM information_schema.system_variables
+WHERE variable_name = 'innodb_log_file_size';
+
+CREATE TABLE t (
+ a INT PRIMARY KEY AUTO_INCREMENT,
+ b CHAR(255) NOT NULL)
+ENGINE=INNODB;
+
+INSERT INTO t SELECT NULL, REPEAT('a', 255) FROM seq_1_to_20000;
+
+--let $restart_parameters=--innodb-log-file-size=4194304
+--source include/restart_mysqld.inc
+
+SELECT COUNT(*) FROM t;
+
+SHOW VARIABLES LIKE 'innodb_log_file_size';
+let SEARCH_PATTERN = InnoDB: Resized log to 4\\.000MiB;
+--source include/search_pattern_in_file.inc
+
+UPDATE t SET b='' WHERE a<10;
+
+SET GLOBAL innodb_log_file_size=5242880;
+SHOW VARIABLES LIKE 'innodb_log_file_size';
+SELECT global_value FROM information_schema.system_variables
+WHERE variable_name = 'innodb_log_file_size';
+
+--let $restart_parameters=
+--source include/restart_mysqld.inc
+
+SELECT * FROM t WHERE a<10;
+
+SHOW VARIABLES LIKE 'innodb_log_file_size';
+let SEARCH_PATTERN = InnoDB: Resized log to 5\\.000MiB;
+--source include/search_pattern_in_file.inc
+
+DROP TABLE t;
diff --git a/mysql-test/suite/innodb/t/log_upgrade.test b/mysql-test/suite/innodb/t/log_upgrade.test
new file mode 100644
index 00000000..faf88c41
--- /dev/null
+++ b/mysql-test/suite/innodb/t/log_upgrade.test
@@ -0,0 +1,120 @@
+--source include/have_innodb.inc
+--source include/have_innodb_16k.inc
+# Some operating systems or file systems do not support sparse files.
+# For example, tmpfs on FreeBSD does not support them.
+# On Microsoft Windows, sparse files have to be created in a special way.
+--source include/big_test.inc
+# include/shutdown_mysqld.inc does not work in ./mtr --embedded
+--source include/not_embedded.inc
+
+call mtr.add_suppression("InnoDB: The change buffer is corrupted");
+
+--source include/shutdown_mysqld.inc
+
+let bugdir= $MYSQLTEST_VARDIR/tmp/log_upgrade;
+--mkdir $bugdir
+--let SEARCH_FILE = $MYSQLTEST_VARDIR/log/mysqld.1.err
+
+--let $dirs= --innodb-data-home-dir=$bugdir --innodb-log-group-home-dir=$bugdir
+
+--echo #
+--echo # MDEV-24412 InnoDB: Upgrade after a crash is not supported
+--echo #
+
+perl;
+do "$ENV{MTR_SUITE_DIR}/../innodb/include/crc32.pl";
+my $polynomial = 0x82f63b78; # CRC-32C
+
+# Create a dummy system tablespace file using the default innodb_page_size=16k
+die unless open OUT, ">", "$ENV{bugdir}/ibdata1";
+binmode OUT;
+
+# We calculate innodb_checksum_algorithm=crc32 for the pages.
+# The following bytes are excluded:
+# bytes 0..3 (the checksum is stored there)
+# bytes 26..37 (encryption key version, post-encryption checksum, tablespace id)
+# bytes $page_size-8..$page_size-1 (checksum, LSB of FIL_PAGE_LSN)
+
+# Tablespace header page with valid FSP_SIZE=768 pages.
+# Also, write a dummy FSEG_MAGIC_N at offset 60 to keep fseg_inode_try_get()
+# happy when fseg_n_reserved_pages() is following an invalid pointer
+# from the all-zero change buffer header page (page 3).
+## FIL_PAGE_OFFSET
+my $head = pack("Nx[18]", 0);
+## FSP_PAGE_SIZE, # FSEG_MAGIC_N
+my $body = pack("x[8]Nx[10]Nx[16312]", 768, 97937874);
+my $ck = mycrc32($head, 0, $polynomial) ^ mycrc32($body, 0, $polynomial);
+print OUT pack("N",$ck).$head.pack("x[12]").$body.pack("Nx[4]",$ck);
+# Dummy pages 1..6.
+print OUT chr(0) x (6 * 16384);
+# Dictionary header page (page 7).
+## FIL_PAGE_OFFSET
+$head = pack("Nx[18]", 7);
+## DICT_HDR_TABLES,DICT_HDR_INDEXES
+$body = pack("x[32]Nx[8]Nx[16290]", 8, 9);
+$ck = mycrc32($head, 0, $polynomial) ^ mycrc32($body, 0, $polynomial);
+print OUT pack("N",$ck).$head.pack("x[12]").$body.pack("Nx[4]",$ck);
+
+# Empty SYS_TABLES page (page 8).
+## FIL_PAGE_OFFSET, FIL_PAGE_PREV, FIL_PAGE_NEXT, FIL_PAGE_TYPE
+$head = pack("NNNx[8]n", 8, ~0, ~0, 17855);
+## PAGE_N_DIR_SLOTS, PAGE_HEAP_TOP, PAGE_INDEX_ID == DICT_TABLES_ID
+$body = pack("nnx[31]Cx[20]", 2, 124, 1);
+$body .= pack("nxnn", 0x801, 3, 116) . "infimum";
+$body .= pack("xnxnxx", 0x901, 0x803) . "supremum";
+$body .= pack("x[16248]nn", 116, 101);
+$ck = mycrc32($head, 0, $polynomial) ^ mycrc32($body, 0, $polynomial);
+print OUT pack("N",$ck).$head.pack("x[12]").$body.pack("Nx[4]",$ck);
+
+# Empty SYS_INDEXES page (page 9).
+## FIL_PAGE_OFFSET, FIL_PAGE_PREV, FIL_PAGE_NEXT, FIL_PAGE_TYPE
+$head = pack("NNNx[8]n", 9, ~0, ~0, 17855);
+## PAGE_N_DIR_SLOTS, PAGE_HEAP_TOP, PAGE_INDEX_ID == DICT_INDEXES_ID
+$body = pack("nnx[31]Cx[20]", 2, 124, 3);
+$body .= pack("nxnn", 0x801, 3, 116) . "infimum";
+$body .= pack("xnxnxx", 0x901, 0x803) . "supremum";
+$body .= pack("x[16248]nn", 116, 101);
+$ck = mycrc32($head, 0, $polynomial) ^ mycrc32($body, 0, $polynomial);
+print OUT pack("N",$ck).$head.pack("x[12]").$body.pack("Nx[4]",$ck);
+
+die unless seek(OUT, 768 * 16384 - 1, 0);
+print OUT chr(0);
+close OUT or die;
+
+die unless open OUT, ">", "$ENV{bugdir}/ib_logfile0";
+binmode OUT;
+$_= pack("Nx[5]nx[5]", 1, 0x1286) . "BogoDB 4.3.2.1" . chr(0) x 478;
+print OUT $_, pack("N", mycrc32($_, 0, $polynomial));
+# checkpoint page 1 and all-zero checkpoint 2
+$_= pack("x[13]nCNNx[484]", 0x1286, 12, 2, 0x80c);
+print OUT $_, pack("N", mycrc32($_, 0, $polynomial));
+die unless seek(OUT, 0x1FFFFFFFF, 0);
+print OUT chr(0);
+close OUT or die;
+die unless open OUT, ">", "$ENV{bugdir}/ib_logfile1";
+binmode OUT;
+die unless seek(OUT, 0x800, 0); # the first 2048 bytes are unused!
+$_= pack("Nnnx[500]", 0x80000944, 12, 12);
+print OUT $_, pack("N", mycrc32($_, 0, $polynomial));
+die unless seek(OUT, 0x1FFFFFFFF, 0);
+print OUT chr(0);
+close OUT or die;
+EOF
+
+--let $restart_parameters= $dirs --innodb-force-recovery=5 --innodb-log-file-size=4m
+--source include/start_mysqld.inc
+SELECT COUNT(*) FROM INFORMATION_SCHEMA.ENGINES
+WHERE engine = 'innodb'
+AND support IN ('YES', 'DEFAULT', 'ENABLED');
+--source include/shutdown_mysqld.inc
+--let SEARCH_PATTERN= InnoDB: Upgrading redo log:
+--source include/search_pattern_in_file.inc
+--let $restart_parameters= $dirs
+
+--list_files $bugdir
+--remove_files_wildcard $bugdir
+--rmdir $bugdir
+--let $restart_parameters=
+--source include/start_mysqld.inc
+
+--echo # End of 10.5 tests
diff --git a/mysql-test/suite/innodb/t/max_record_size.test b/mysql-test/suite/innodb/t/max_record_size.test
new file mode 100644
index 00000000..f21ff923
--- /dev/null
+++ b/mysql-test/suite/innodb/t/max_record_size.test
@@ -0,0 +1,1422 @@
+--source include/have_innodb.inc
+--source include/innodb_page_size.inc
+--source include/innodb_row_format.inc
+
+--let $row_format= `SELECT @@GLOBAL.innodb_default_row_format`
+--let $page_size= `SELECT @@GLOBAL.innodb_page_size`
+
+call mtr.add_suppression("Cannot add field `.*` in table `test`.`t1` because after adding it, the row size is");
+
+
+if ($page_size == 4096) {
+CREATE TABLE t1 (
+ c1 CHAR(255), c2 CHAR(255), c3 CHAR(255), c4 CHAR(255),
+ c5 CHAR(255), c6 CHAR(255), c7 CHAR(255)
+) ENGINE=INNODB;
+DROP TABLE t1;
+--error ER_TOO_BIG_ROWSIZE
+CREATE TABLE t1 (
+ c1 CHAR(255), c2 CHAR(255), c3 CHAR(255), c4 CHAR(255),
+ c5 CHAR(255), c6 CHAR(255), c7 CHAR(255), c8 CHAR(255)
+) ENGINE=INNODB;
+
+CREATE TABLE t1 (
+ c1 VARCHAR(255), c2 VARCHAR(255), c3 VARCHAR(255), c4 VARCHAR(255),
+ c5 VARCHAR(255), c6 VARCHAR(255), c7 VARCHAR(255)
+) ENGINE=INNODB;
+DROP TABLE t1;
+--error ER_TOO_BIG_ROWSIZE
+CREATE TABLE t1 (
+ c1 VARCHAR(255), c2 VARCHAR(255), c3 VARCHAR(255), c4 VARCHAR(255),
+ c5 VARCHAR(255), c6 VARCHAR(255), c7 VARCHAR(255), c8 VARCHAR(255)
+) ENGINE=INNODB;
+}
+
+
+if ($page_size == 8192) {
+CREATE TABLE t1 (
+ c1 CHAR(255), c2 CHAR(255), c3 CHAR(255), c4 CHAR(255),
+ c5 CHAR(255), c6 CHAR(255), c7 CHAR(255), c8 CHAR(255),
+ c9 CHAR(255), c10 CHAR(255), c11 CHAR(255), c12 CHAR(255),
+ c13 CHAR(255), c14 CHAR(255), c15 CHAR(255)
+) ENGINE=INNODB;
+DROP TABLE t1;
+--error ER_TOO_BIG_ROWSIZE
+CREATE TABLE t1 (
+ c1 CHAR(255), c2 CHAR(255), c3 CHAR(255), c4 CHAR(255),
+ c5 CHAR(255), c6 CHAR(255), c7 CHAR(255), c8 CHAR(255),
+ c9 CHAR(255), c10 CHAR(255), c11 CHAR(255), c12 CHAR(255),
+ c13 CHAR(255), c14 CHAR(255), c15 CHAR(255), c16 CHAR(255)
+) ENGINE=INNODB;
+
+CREATE TABLE t1 (
+ c1 VARCHAR(255), c2 VARCHAR(255), c3 VARCHAR(255), c4 VARCHAR(255),
+ c5 VARCHAR(255), c6 VARCHAR(255), c7 VARCHAR(255), c8 VARCHAR(255),
+ c9 VARCHAR(255), c10 VARCHAR(255), c11 VARCHAR(255), c12 VARCHAR(255),
+ c13 VARCHAR(255), c14 VARCHAR(255), c15 VARCHAR(255)
+) ENGINE=INNODB;
+DROP TABLE t1;
+--error ER_TOO_BIG_ROWSIZE
+CREATE TABLE t1 (
+ c1 VARCHAR(255), c2 VARCHAR(255), c3 VARCHAR(255), c4 VARCHAR(255),
+ c5 VARCHAR(255), c6 VARCHAR(255), c7 VARCHAR(255), c8 VARCHAR(255),
+ c9 VARCHAR(255), c10 VARCHAR(255), c11 VARCHAR(255), c12 VARCHAR(255),
+ c13 VARCHAR(255), c14 VARCHAR(255), c15 VARCHAR(255), c16 VARCHAR(255)
+) ENGINE=INNODB;
+}
+
+
+if ($page_size == 16384) {
+CREATE TABLE t1 (
+ c1 CHAR(255), c2 CHAR(255), c3 CHAR(255), c4 CHAR(255),
+ c5 CHAR(255), c6 CHAR(255), c7 CHAR(255), c8 CHAR(255),
+ c9 CHAR(255), c10 CHAR(255), c11 CHAR(255), c12 CHAR(255),
+ c13 CHAR(255), c14 CHAR(255), c15 CHAR(255), c16 CHAR(255),
+ c17 CHAR(255), c18 CHAR(255), c19 CHAR(255), c20 CHAR(255),
+ c21 CHAR(255), c22 CHAR(255), c23 CHAR(255), c24 CHAR(255),
+ c25 CHAR(255), c26 CHAR(255), c27 CHAR(255), c28 CHAR(255),
+ c29 CHAR(255), c30 CHAR(255), c31 CHAR(255)
+) ENGINE=INNODB;
+DROP TABLE t1;
+--error ER_TOO_BIG_ROWSIZE
+CREATE TABLE t1 (
+ c1 CHAR(255), c2 CHAR(255), c3 CHAR(255), c4 CHAR(255),
+ c5 CHAR(255), c6 CHAR(255), c7 CHAR(255), c8 CHAR(255),
+ c9 CHAR(255), c10 CHAR(255), c11 CHAR(255), c12 CHAR(255),
+ c13 CHAR(255), c14 CHAR(255), c15 CHAR(255), c16 CHAR(255),
+ c17 CHAR(255), c18 CHAR(255), c19 CHAR(255), c20 CHAR(255),
+ c21 CHAR(255), c22 CHAR(255), c23 CHAR(255), c24 CHAR(255),
+ c25 CHAR(255), c26 CHAR(255), c27 CHAR(255), c28 CHAR(255),
+ c29 CHAR(255), c30 CHAR(255), c31 CHAR(255), c32 CHAR(255)
+) ENGINE=INNODB;
+
+CREATE TABLE t1 (
+ c1 VARCHAR(255), c2 VARCHAR(255), c3 VARCHAR(255), c4 VARCHAR(255),
+ c5 VARCHAR(255), c6 VARCHAR(255), c7 VARCHAR(255), c8 VARCHAR(255),
+ c9 VARCHAR(255), c10 VARCHAR(255), c11 VARCHAR(255), c12 VARCHAR(255),
+ c13 VARCHAR(255), c14 VARCHAR(255), c15 VARCHAR(255), c16 VARCHAR(255),
+ c17 VARCHAR(255), c18 VARCHAR(255), c19 VARCHAR(255), c20 VARCHAR(255),
+ c21 VARCHAR(255), c22 VARCHAR(255), c23 VARCHAR(255), c24 VARCHAR(255),
+ c25 VARCHAR(255), c26 VARCHAR(255), c27 VARCHAR(255), c28 VARCHAR(255),
+ c29 VARCHAR(255), c30 VARCHAR(255), c31 VARCHAR(255)
+) ENGINE=INNODB;
+DROP TABLE t1;
+--error ER_TOO_BIG_ROWSIZE
+CREATE TABLE t1 (
+ c1 VARCHAR(255), c2 VARCHAR(255), c3 VARCHAR(255), c4 VARCHAR(255),
+ c5 VARCHAR(255), c6 VARCHAR(255), c7 VARCHAR(255), c8 VARCHAR(255),
+ c9 VARCHAR(255), c10 VARCHAR(255), c11 VARCHAR(255), c12 VARCHAR(255),
+ c13 VARCHAR(255), c14 VARCHAR(255), c15 VARCHAR(255), c16 VARCHAR(255),
+ c17 VARCHAR(255), c18 VARCHAR(255), c19 VARCHAR(255), c20 VARCHAR(255),
+ c21 VARCHAR(255), c22 VARCHAR(255), c23 VARCHAR(255), c24 VARCHAR(255),
+ c25 VARCHAR(255), c26 VARCHAR(255), c27 VARCHAR(255), c28 VARCHAR(255),
+ c29 VARCHAR(255), c30 VARCHAR(255), c31 VARCHAR(255), c32 VARCHAR(255)
+) ENGINE=INNODB;
+}
+
+
+if ($page_size == 32768) {
+CREATE TABLE t1 (
+ c1 CHAR(255), c2 CHAR(255), c3 CHAR(255), c4 CHAR(255),
+ c5 CHAR(255), c6 CHAR(255), c7 CHAR(255), c8 CHAR(255),
+ c9 CHAR(255), c10 CHAR(255), c11 CHAR(255), c12 CHAR(255),
+ c13 CHAR(255), c14 CHAR(255), c15 CHAR(255), c16 CHAR(255),
+ c17 CHAR(255), c18 CHAR(255), c19 CHAR(255), c20 CHAR(255),
+ c21 CHAR(255), c22 CHAR(255), c23 CHAR(255), c24 CHAR(255),
+ c25 CHAR(255), c26 CHAR(255), c27 CHAR(255), c28 CHAR(255),
+ c29 CHAR(255), c30 CHAR(255), c31 CHAR(255), c32 CHAR(255),
+ c33 CHAR(255), c34 CHAR(255), c35 CHAR(255), c36 CHAR(255),
+ c37 CHAR(255), c38 CHAR(255), c39 CHAR(255), c40 CHAR(255),
+ c41 CHAR(255), c42 CHAR(255), c43 CHAR(255), c44 CHAR(255),
+ c45 CHAR(255), c46 CHAR(255), c47 CHAR(255), c48 CHAR(255),
+ c49 CHAR(255), c50 CHAR(255), c51 CHAR(255), c52 CHAR(255),
+ c53 CHAR(255), c54 CHAR(255), c55 CHAR(255), c56 CHAR(255),
+ c57 CHAR(255), c58 CHAR(255), c59 CHAR(255), c60 CHAR(255),
+ c61 CHAR(255), c62 CHAR(255), c63 CHAR(255)
+) ENGINE=INNODB;
+DROP TABLE t1;
+--error ER_TOO_BIG_ROWSIZE
+CREATE TABLE t1 (
+ c1 CHAR(255), c2 CHAR(255), c3 CHAR(255), c4 CHAR(255),
+ c5 CHAR(255), c6 CHAR(255), c7 CHAR(255), c8 CHAR(255),
+ c9 CHAR(255), c10 CHAR(255), c11 CHAR(255), c12 CHAR(255),
+ c13 CHAR(255), c14 CHAR(255), c15 CHAR(255), c16 CHAR(255),
+ c17 CHAR(255), c18 CHAR(255), c19 CHAR(255), c20 CHAR(255),
+ c21 CHAR(255), c22 CHAR(255), c23 CHAR(255), c24 CHAR(255),
+ c25 CHAR(255), c26 CHAR(255), c27 CHAR(255), c28 CHAR(255),
+ c29 CHAR(255), c30 CHAR(255), c31 CHAR(255), c32 CHAR(255),
+ c33 CHAR(255), c34 CHAR(255), c35 CHAR(255), c36 CHAR(255),
+ c37 CHAR(255), c38 CHAR(255), c39 CHAR(255), c40 CHAR(255),
+ c41 CHAR(255), c42 CHAR(255), c43 CHAR(255), c44 CHAR(255),
+ c45 CHAR(255), c46 CHAR(255), c47 CHAR(255), c48 CHAR(255),
+ c49 CHAR(255), c50 CHAR(255), c51 CHAR(255), c52 CHAR(255),
+ c53 CHAR(255), c54 CHAR(255), c55 CHAR(255), c56 CHAR(255),
+ c57 CHAR(255), c58 CHAR(255), c59 CHAR(255), c60 CHAR(255),
+ c61 CHAR(255), c62 CHAR(255), c63 CHAR(255), c64 CHAR(255)
+) ENGINE=INNODB;
+
+CREATE TABLE t1 (
+ c1 VARCHAR(255), c2 VARCHAR(255), c3 VARCHAR(255), c4 VARCHAR(255),
+ c5 VARCHAR(255), c6 VARCHAR(255), c7 VARCHAR(255), c8 VARCHAR(255),
+ c9 VARCHAR(255), c10 VARCHAR(255), c11 VARCHAR(255), c12 VARCHAR(255),
+ c13 VARCHAR(255), c14 VARCHAR(255), c15 VARCHAR(255), c16 VARCHAR(255),
+ c17 VARCHAR(255), c18 VARCHAR(255), c19 VARCHAR(255), c20 VARCHAR(255),
+ c21 VARCHAR(255), c22 VARCHAR(255), c23 VARCHAR(255), c24 VARCHAR(255),
+ c25 VARCHAR(255), c26 VARCHAR(255), c27 VARCHAR(255), c28 VARCHAR(255),
+ c29 VARCHAR(255), c30 VARCHAR(255), c31 VARCHAR(255), c32 VARCHAR(255),
+ c33 VARCHAR(255), c34 VARCHAR(255), c35 VARCHAR(255), c36 VARCHAR(255),
+ c37 VARCHAR(255), c38 VARCHAR(255), c39 VARCHAR(255), c40 VARCHAR(255),
+ c41 VARCHAR(255), c42 VARCHAR(255), c43 VARCHAR(255), c44 VARCHAR(255),
+ c45 VARCHAR(255), c46 VARCHAR(255), c47 VARCHAR(255), c48 VARCHAR(255),
+ c49 VARCHAR(255), c50 VARCHAR(255), c51 VARCHAR(255), c52 VARCHAR(255),
+ c53 VARCHAR(255), c54 VARCHAR(255), c55 VARCHAR(255), c56 VARCHAR(255),
+ c57 VARCHAR(255), c58 VARCHAR(255), c59 VARCHAR(255), c60 VARCHAR(255),
+ c61 VARCHAR(255), c62 VARCHAR(255), c63 VARCHAR(255)
+) ENGINE=INNODB;
+DROP TABLE t1;
+--error ER_TOO_BIG_ROWSIZE
+CREATE TABLE t1 (
+ c1 VARCHAR(255), c2 VARCHAR(255), c3 VARCHAR(255), c4 VARCHAR(255),
+ c5 VARCHAR(255), c6 VARCHAR(255), c7 VARCHAR(255), c8 VARCHAR(255),
+ c9 VARCHAR(255), c10 VARCHAR(255), c11 VARCHAR(255), c12 VARCHAR(255),
+ c13 VARCHAR(255), c14 VARCHAR(255), c15 VARCHAR(255), c16 VARCHAR(255),
+ c17 VARCHAR(255), c18 VARCHAR(255), c19 VARCHAR(255), c20 VARCHAR(255),
+ c21 VARCHAR(255), c22 VARCHAR(255), c23 VARCHAR(255), c24 VARCHAR(255),
+ c25 VARCHAR(255), c26 VARCHAR(255), c27 VARCHAR(255), c28 VARCHAR(255),
+ c29 VARCHAR(255), c30 VARCHAR(255), c31 VARCHAR(255), c32 VARCHAR(255),
+ c33 VARCHAR(255), c34 VARCHAR(255), c35 VARCHAR(255), c36 VARCHAR(255),
+ c37 VARCHAR(255), c38 VARCHAR(255), c39 VARCHAR(255), c40 VARCHAR(255),
+ c41 VARCHAR(255), c42 VARCHAR(255), c43 VARCHAR(255), c44 VARCHAR(255),
+ c45 VARCHAR(255), c46 VARCHAR(255), c47 VARCHAR(255), c48 VARCHAR(255),
+ c49 VARCHAR(255), c50 VARCHAR(255), c51 VARCHAR(255), c52 VARCHAR(255),
+ c53 VARCHAR(255), c54 VARCHAR(255), c55 VARCHAR(255), c56 VARCHAR(255),
+ c57 VARCHAR(255), c58 VARCHAR(255), c59 VARCHAR(255), c60 VARCHAR(255),
+ c61 VARCHAR(255), c62 VARCHAR(255), c63 VARCHAR(255), c64 VARCHAR(255)
+) ENGINE=INNODB;
+}
+
+
+if ($row_format == 'redundant') { if ($page_size == 65536) {
+CREATE TABLE t1 (
+ c1 CHAR(255), c2 CHAR(255), c3 CHAR(255), c4 CHAR(255),
+ c5 CHAR(255), c6 CHAR(255), c7 CHAR(255), c8 CHAR(255),
+ c9 CHAR(255), c10 CHAR(255), c11 CHAR(255), c12 CHAR(255),
+ c13 CHAR(255), c14 CHAR(255), c15 CHAR(255), c16 CHAR(255),
+ c17 CHAR(255), c18 CHAR(255), c19 CHAR(255), c20 CHAR(255),
+ c21 CHAR(255), c22 CHAR(255), c23 CHAR(255), c24 CHAR(255),
+ c25 CHAR(255), c26 CHAR(255), c27 CHAR(255), c28 CHAR(255),
+ c29 CHAR(255), c30 CHAR(255), c31 CHAR(255), c32 CHAR(255),
+ c33 CHAR(255), c34 CHAR(255), c35 CHAR(255), c36 CHAR(255),
+ c37 CHAR(255), c38 CHAR(255), c39 CHAR(255), c40 CHAR(255),
+ c41 CHAR(255), c42 CHAR(255), c43 CHAR(255), c44 CHAR(255),
+ c45 CHAR(255), c46 CHAR(255), c47 CHAR(255), c48 CHAR(255),
+ c49 CHAR(255), c50 CHAR(255), c51 CHAR(255), c52 CHAR(255),
+ c53 CHAR(255), c54 CHAR(255), c55 CHAR(255), c56 CHAR(255),
+ c57 CHAR(255), c58 CHAR(255), c59 CHAR(255), c60 CHAR(255),
+ c61 CHAR(255), c62 CHAR(255), c63 CHAR(255)
+) ENGINE=INNODB;
+DROP TABLE t1;
+--error ER_TOO_BIG_ROWSIZE
+CREATE TABLE t1 (
+c1 CHAR(255), c2 CHAR(255), c3 CHAR(255), c4 CHAR(255),
+ c5 CHAR(255), c6 CHAR(255), c7 CHAR(255), c8 CHAR(255),
+ c9 CHAR(255), c10 CHAR(255), c11 CHAR(255), c12 CHAR(255),
+ c13 CHAR(255), c14 CHAR(255), c15 CHAR(255), c16 CHAR(255),
+ c17 CHAR(255), c18 CHAR(255), c19 CHAR(255), c20 CHAR(255),
+ c21 CHAR(255), c22 CHAR(255), c23 CHAR(255), c24 CHAR(255),
+ c25 CHAR(255), c26 CHAR(255), c27 CHAR(255), c28 CHAR(255),
+ c29 CHAR(255), c30 CHAR(255), c31 CHAR(255), c32 CHAR(255),
+ c33 CHAR(255), c34 CHAR(255), c35 CHAR(255), c36 CHAR(255),
+ c37 CHAR(255), c38 CHAR(255), c39 CHAR(255), c40 CHAR(255),
+ c41 CHAR(255), c42 CHAR(255), c43 CHAR(255), c44 CHAR(255),
+ c45 CHAR(255), c46 CHAR(255), c47 CHAR(255), c48 CHAR(255),
+ c49 CHAR(255), c50 CHAR(255), c51 CHAR(255), c52 CHAR(255),
+ c53 CHAR(255), c54 CHAR(255), c55 CHAR(255), c56 CHAR(255),
+ c57 CHAR(255), c58 CHAR(255), c59 CHAR(255), c60 CHAR(255),
+ c61 CHAR(255), c62 CHAR(255), c63 CHAR(255), c64 CHAR(255)
+) ENGINE=INNODB;
+
+CREATE TABLE t1 (
+ c1 VARCHAR(255), c2 VARCHAR(255), c3 VARCHAR(255), c4 VARCHAR(255),
+ c5 VARCHAR(255), c6 VARCHAR(255), c7 VARCHAR(255), c8 VARCHAR(255),
+ c9 VARCHAR(255), c10 VARCHAR(255), c11 VARCHAR(255), c12 VARCHAR(255),
+ c13 VARCHAR(255), c14 VARCHAR(255), c15 VARCHAR(255), c16 VARCHAR(255),
+ c17 VARCHAR(255), c18 VARCHAR(255), c19 VARCHAR(255), c20 VARCHAR(255),
+ c21 VARCHAR(255), c22 VARCHAR(255), c23 VARCHAR(255), c24 VARCHAR(255),
+ c25 VARCHAR(255), c26 VARCHAR(255), c27 VARCHAR(255), c28 VARCHAR(255),
+ c29 VARCHAR(255), c30 VARCHAR(255), c31 VARCHAR(255), c32 VARCHAR(255),
+ c33 VARCHAR(255), c34 VARCHAR(255), c35 VARCHAR(255), c36 VARCHAR(255),
+ c37 VARCHAR(255), c38 VARCHAR(255), c39 VARCHAR(255), c40 VARCHAR(255),
+ c41 VARCHAR(255), c42 VARCHAR(255), c43 VARCHAR(255), c44 VARCHAR(255),
+ c45 VARCHAR(255), c46 VARCHAR(255), c47 VARCHAR(255), c48 VARCHAR(255),
+ c49 VARCHAR(255), c50 VARCHAR(255), c51 VARCHAR(255), c52 VARCHAR(255),
+ c53 VARCHAR(255), c54 VARCHAR(255), c55 VARCHAR(255), c56 VARCHAR(255),
+ c57 VARCHAR(255), c58 VARCHAR(255), c59 VARCHAR(255), c60 VARCHAR(255),
+ c61 VARCHAR(255), c62 VARCHAR(255), c63 VARCHAR(255)
+) ENGINE=INNODB;
+DROP TABLE t1;
+--error ER_TOO_BIG_ROWSIZE
+CREATE TABLE t1 (
+ c1 VARCHAR(255), c2 VARCHAR(255), c3 VARCHAR(255), c4 VARCHAR(255),
+ c5 VARCHAR(255), c6 VARCHAR(255), c7 VARCHAR(255), c8 VARCHAR(255),
+ c9 VARCHAR(255), c10 VARCHAR(255), c11 VARCHAR(255), c12 VARCHAR(255),
+ c13 VARCHAR(255), c14 VARCHAR(255), c15 VARCHAR(255), c16 VARCHAR(255),
+ c17 VARCHAR(255), c18 VARCHAR(255), c19 VARCHAR(255), c20 VARCHAR(255),
+ c21 VARCHAR(255), c22 VARCHAR(255), c23 VARCHAR(255), c24 VARCHAR(255),
+ c25 VARCHAR(255), c26 VARCHAR(255), c27 VARCHAR(255), c28 VARCHAR(255),
+ c29 VARCHAR(255), c30 VARCHAR(255), c31 VARCHAR(255), c32 VARCHAR(255),
+ c33 VARCHAR(255), c34 VARCHAR(255), c35 VARCHAR(255), c36 VARCHAR(255),
+ c37 VARCHAR(255), c38 VARCHAR(255), c39 VARCHAR(255), c40 VARCHAR(255),
+ c41 VARCHAR(255), c42 VARCHAR(255), c43 VARCHAR(255), c44 VARCHAR(255),
+ c45 VARCHAR(255), c46 VARCHAR(255), c47 VARCHAR(255), c48 VARCHAR(255),
+ c49 VARCHAR(255), c50 VARCHAR(255), c51 VARCHAR(255), c52 VARCHAR(255),
+ c53 VARCHAR(255), c54 VARCHAR(255), c55 VARCHAR(255), c56 VARCHAR(255),
+ c57 VARCHAR(255), c58 VARCHAR(255), c59 VARCHAR(255), c60 VARCHAR(255),
+ c61 VARCHAR(255), c62 VARCHAR(255), c63 VARCHAR(255), c64 VARCHAR(255)
+) ENGINE=INNODB;
+} }
+
+
+if ($row_format != 'redundant') { if ($page_size == 65536) {
+CREATE TABLE t1 (
+ c1 CHAR(255), c2 CHAR(255), c3 CHAR(255), c4 CHAR(255),
+ c5 CHAR(255), c6 CHAR(255), c7 CHAR(255), c8 CHAR(255),
+ c9 CHAR(255), c10 CHAR(255), c11 CHAR(255), c12 CHAR(255),
+ c13 CHAR(255), c14 CHAR(255), c15 CHAR(255), c16 CHAR(255),
+ c17 CHAR(255), c18 CHAR(255), c19 CHAR(255), c20 CHAR(255),
+ c21 CHAR(255), c22 CHAR(255), c23 CHAR(255), c24 CHAR(255),
+ c25 CHAR(255), c26 CHAR(255), c27 CHAR(255), c28 CHAR(255),
+ c29 CHAR(255), c30 CHAR(255), c31 CHAR(255), c32 CHAR(255),
+ c33 CHAR(255), c34 CHAR(255), c35 CHAR(255), c36 CHAR(255),
+ c37 CHAR(255), c38 CHAR(255), c39 CHAR(255), c40 CHAR(255),
+ c41 CHAR(255), c42 CHAR(255), c43 CHAR(255), c44 CHAR(255),
+ c45 CHAR(255), c46 CHAR(255), c47 CHAR(255), c48 CHAR(255),
+ c49 CHAR(255), c50 CHAR(255), c51 CHAR(255), c52 CHAR(255),
+ c53 CHAR(255), c54 CHAR(255), c55 CHAR(255), c56 CHAR(255),
+ c57 CHAR(255), c58 CHAR(255), c59 CHAR(255), c60 CHAR(255),
+ c61 CHAR(255), c62 CHAR(255), c63 CHAR(255), c64 CHAR(255),
+ c65 CHAR(255), c66 CHAR(255), c67 CHAR(255), c68 CHAR(255),
+ c69 CHAR(255), c70 CHAR(255), c71 CHAR(255), c72 CHAR(255),
+ c73 CHAR(255), c74 CHAR(255), c75 CHAR(255), c76 CHAR(255),
+ c77 CHAR(255), c78 CHAR(255), c79 CHAR(255), c80 CHAR(255),
+ c81 CHAR(255), c82 CHAR(255), c83 CHAR(255), c84 CHAR(255),
+ c85 CHAR(255), c86 CHAR(255), c87 CHAR(255), c88 CHAR(255),
+ c89 CHAR(255), c90 CHAR(255), c91 CHAR(255), c92 CHAR(255),
+ c93 CHAR(255), c94 CHAR(255), c95 CHAR(255), c96 CHAR(255),
+ c97 CHAR(255), c98 CHAR(255), c99 CHAR(255), c100 CHAR(255),
+ c101 CHAR(255), c102 CHAR(255), c103 CHAR(255), c104 CHAR(255),
+ c105 CHAR(255), c106 CHAR(255), c107 CHAR(255), c108 CHAR(255),
+ c109 CHAR(255), c110 CHAR(255), c111 CHAR(255), c112 CHAR(255),
+ c113 CHAR(255), c114 CHAR(255), c115 CHAR(255), c116 CHAR(255),
+ c117 CHAR(255), c118 CHAR(255), c119 CHAR(255), c120 CHAR(255),
+ c121 CHAR(255), c122 CHAR(255), c123 CHAR(255), c124 CHAR(255),
+ c125 CHAR(255), c126 CHAR(255), c127 CHAR(255), c128 CHAR(255)
+) ENGINE=INNODB;
+DROP TABLE t1;
+--error ER_TOO_BIG_ROWSIZE
+CREATE TABLE t1 (
+ c1 CHAR(255), c2 CHAR(255), c3 CHAR(255), c4 CHAR(255),
+ c5 CHAR(255), c6 CHAR(255), c7 CHAR(255), c8 CHAR(255),
+ c9 CHAR(255), c10 CHAR(255), c11 CHAR(255), c12 CHAR(255),
+ c13 CHAR(255), c14 CHAR(255), c15 CHAR(255), c16 CHAR(255),
+ c17 CHAR(255), c18 CHAR(255), c19 CHAR(255), c20 CHAR(255),
+ c21 CHAR(255), c22 CHAR(255), c23 CHAR(255), c24 CHAR(255),
+ c25 CHAR(255), c26 CHAR(255), c27 CHAR(255), c28 CHAR(255),
+ c29 CHAR(255), c30 CHAR(255), c31 CHAR(255), c32 CHAR(255),
+ c33 CHAR(255), c34 CHAR(255), c35 CHAR(255), c36 CHAR(255),
+ c37 CHAR(255), c38 CHAR(255), c39 CHAR(255), c40 CHAR(255),
+ c41 CHAR(255), c42 CHAR(255), c43 CHAR(255), c44 CHAR(255),
+ c45 CHAR(255), c46 CHAR(255), c47 CHAR(255), c48 CHAR(255),
+ c49 CHAR(255), c50 CHAR(255), c51 CHAR(255), c52 CHAR(255),
+ c53 CHAR(255), c54 CHAR(255), c55 CHAR(255), c56 CHAR(255),
+ c57 CHAR(255), c58 CHAR(255), c59 CHAR(255), c60 CHAR(255),
+ c61 CHAR(255), c62 CHAR(255), c63 CHAR(255), c64 CHAR(255),
+ c65 CHAR(255), c66 CHAR(255), c67 CHAR(255), c68 CHAR(255),
+ c69 CHAR(255), c70 CHAR(255), c71 CHAR(255), c72 CHAR(255),
+ c73 CHAR(255), c74 CHAR(255), c75 CHAR(255), c76 CHAR(255),
+ c77 CHAR(255), c78 CHAR(255), c79 CHAR(255), c80 CHAR(255),
+ c81 CHAR(255), c82 CHAR(255), c83 CHAR(255), c84 CHAR(255),
+ c85 CHAR(255), c86 CHAR(255), c87 CHAR(255), c88 CHAR(255),
+ c89 CHAR(255), c90 CHAR(255), c91 CHAR(255), c92 CHAR(255),
+ c93 CHAR(255), c94 CHAR(255), c95 CHAR(255), c96 CHAR(255),
+ c97 CHAR(255), c98 CHAR(255), c99 CHAR(255), c100 CHAR(255),
+ c101 CHAR(255), c102 CHAR(255), c103 CHAR(255), c104 CHAR(255),
+ c105 CHAR(255), c106 CHAR(255), c107 CHAR(255), c108 CHAR(255),
+ c109 CHAR(255), c110 CHAR(255), c111 CHAR(255), c112 CHAR(255),
+ c113 CHAR(255), c114 CHAR(255), c115 CHAR(255), c116 CHAR(255),
+ c117 CHAR(255), c118 CHAR(255), c119 CHAR(255), c120 CHAR(255),
+ c121 CHAR(255), c122 CHAR(255), c123 CHAR(255), c124 CHAR(255),
+ c125 CHAR(255), c126 CHAR(255), c127 CHAR(255), c128 CHAR(255),
+ c129 CHAR(255)
+) ENGINE=INNODB;
+
+CREATE TABLE t1 (
+ c1 VARCHAR(255), c2 VARCHAR(255), c3 VARCHAR(255), c4 VARCHAR(255),
+ c5 VARCHAR(255), c6 VARCHAR(255), c7 VARCHAR(255), c8 VARCHAR(255),
+ c9 VARCHAR(255), c10 VARCHAR(255), c11 VARCHAR(255), c12 VARCHAR(255),
+ c13 VARCHAR(255), c14 VARCHAR(255), c15 VARCHAR(255), c16 VARCHAR(255),
+ c17 VARCHAR(255), c18 VARCHAR(255), c19 VARCHAR(255), c20 VARCHAR(255),
+ c21 VARCHAR(255), c22 VARCHAR(255), c23 VARCHAR(255), c24 VARCHAR(255),
+ c25 VARCHAR(255), c26 VARCHAR(255), c27 VARCHAR(255), c28 VARCHAR(255),
+ c29 VARCHAR(255), c30 VARCHAR(255), c31 VARCHAR(255), c32 VARCHAR(255),
+ c33 VARCHAR(255), c34 VARCHAR(255), c35 VARCHAR(255), c36 VARCHAR(255),
+ c37 VARCHAR(255), c38 VARCHAR(255), c39 VARCHAR(255), c40 VARCHAR(255),
+ c41 VARCHAR(255), c42 VARCHAR(255), c43 VARCHAR(255), c44 VARCHAR(255),
+ c45 VARCHAR(255), c46 VARCHAR(255), c47 VARCHAR(255), c48 VARCHAR(255),
+ c49 VARCHAR(255), c50 VARCHAR(255), c51 VARCHAR(255), c52 VARCHAR(255),
+ c53 VARCHAR(255), c54 VARCHAR(255), c55 VARCHAR(255), c56 VARCHAR(255),
+ c57 VARCHAR(255), c58 VARCHAR(255), c59 VARCHAR(255), c60 VARCHAR(255),
+ c61 VARCHAR(255), c62 VARCHAR(255), c63 VARCHAR(255), c64 VARCHAR(255),
+ c65 VARCHAR(255), c66 VARCHAR(255), c67 VARCHAR(255), c68 VARCHAR(255),
+ c69 VARCHAR(255), c70 VARCHAR(255), c71 VARCHAR(255), c72 VARCHAR(255),
+ c73 VARCHAR(255), c74 VARCHAR(255), c75 VARCHAR(255), c76 VARCHAR(255),
+ c77 VARCHAR(255), c78 VARCHAR(255), c79 VARCHAR(255), c80 VARCHAR(255),
+ c81 VARCHAR(255), c82 VARCHAR(255), c83 VARCHAR(255), c84 VARCHAR(255),
+ c85 VARCHAR(255), c86 VARCHAR(255), c87 VARCHAR(255), c88 VARCHAR(255),
+ c89 VARCHAR(255), c90 VARCHAR(255), c91 VARCHAR(255), c92 VARCHAR(255),
+ c93 VARCHAR(255), c94 VARCHAR(255), c95 VARCHAR(255), c96 VARCHAR(255),
+ c97 VARCHAR(255), c98 VARCHAR(255), c99 VARCHAR(255), c100 VARCHAR(255),
+ c101 VARCHAR(255), c102 VARCHAR(255), c103 VARCHAR(255), c104 VARCHAR(255),
+ c105 VARCHAR(255), c106 VARCHAR(255), c107 VARCHAR(255), c108 VARCHAR(255),
+ c109 VARCHAR(255), c110 VARCHAR(255), c111 VARCHAR(255), c112 VARCHAR(255),
+ c113 VARCHAR(255), c114 VARCHAR(255), c115 VARCHAR(255), c116 VARCHAR(255),
+ c117 VARCHAR(255), c118 VARCHAR(255), c119 VARCHAR(255), c120 VARCHAR(255),
+ c121 VARCHAR(255), c122 VARCHAR(255), c123 VARCHAR(255), c124 VARCHAR(255),
+ c125 VARCHAR(255), c126 VARCHAR(255), c127 VARCHAR(255)
+) ENGINE=INNODB;
+DROP TABLE t1;
+--error ER_TOO_BIG_ROWSIZE
+CREATE TABLE t1 (
+ c1 VARCHAR(255), c2 VARCHAR(255), c3 VARCHAR(255), c4 VARCHAR(255),
+ c5 VARCHAR(255), c6 VARCHAR(255), c7 VARCHAR(255), c8 VARCHAR(255),
+ c9 VARCHAR(255), c10 VARCHAR(255), c11 VARCHAR(255), c12 VARCHAR(255),
+ c13 VARCHAR(255), c14 VARCHAR(255), c15 VARCHAR(255), c16 VARCHAR(255),
+ c17 VARCHAR(255), c18 VARCHAR(255), c19 VARCHAR(255), c20 VARCHAR(255),
+ c21 VARCHAR(255), c22 VARCHAR(255), c23 VARCHAR(255), c24 VARCHAR(255),
+ c25 VARCHAR(255), c26 VARCHAR(255), c27 VARCHAR(255), c28 VARCHAR(255),
+ c29 VARCHAR(255), c30 VARCHAR(255), c31 VARCHAR(255), c32 VARCHAR(255),
+ c33 VARCHAR(255), c34 VARCHAR(255), c35 VARCHAR(255), c36 VARCHAR(255),
+ c37 VARCHAR(255), c38 VARCHAR(255), c39 VARCHAR(255), c40 VARCHAR(255),
+ c41 VARCHAR(255), c42 VARCHAR(255), c43 VARCHAR(255), c44 VARCHAR(255),
+ c45 VARCHAR(255), c46 VARCHAR(255), c47 VARCHAR(255), c48 VARCHAR(255),
+ c49 VARCHAR(255), c50 VARCHAR(255), c51 VARCHAR(255), c52 VARCHAR(255),
+ c53 VARCHAR(255), c54 VARCHAR(255), c55 VARCHAR(255), c56 VARCHAR(255),
+ c57 VARCHAR(255), c58 VARCHAR(255), c59 VARCHAR(255), c60 VARCHAR(255),
+ c61 VARCHAR(255), c62 VARCHAR(255), c63 VARCHAR(255), c64 VARCHAR(255),
+ c65 VARCHAR(255), c66 VARCHAR(255), c67 VARCHAR(255), c68 VARCHAR(255),
+ c69 VARCHAR(255), c70 VARCHAR(255), c71 VARCHAR(255), c72 VARCHAR(255),
+ c73 VARCHAR(255), c74 VARCHAR(255), c75 VARCHAR(255), c76 VARCHAR(255),
+ c77 VARCHAR(255), c78 VARCHAR(255), c79 VARCHAR(255), c80 VARCHAR(255),
+ c81 VARCHAR(255), c82 VARCHAR(255), c83 VARCHAR(255), c84 VARCHAR(255),
+ c85 VARCHAR(255), c86 VARCHAR(255), c87 VARCHAR(255), c88 VARCHAR(255),
+ c89 VARCHAR(255), c90 VARCHAR(255), c91 VARCHAR(255), c92 VARCHAR(255),
+ c93 VARCHAR(255), c94 VARCHAR(255), c95 VARCHAR(255), c96 VARCHAR(255),
+ c97 VARCHAR(255), c98 VARCHAR(255), c99 VARCHAR(255), c100 VARCHAR(255),
+ c101 VARCHAR(255), c102 VARCHAR(255), c103 VARCHAR(255), c104 VARCHAR(255),
+ c105 VARCHAR(255), c106 VARCHAR(255), c107 VARCHAR(255), c108 VARCHAR(255),
+ c109 VARCHAR(255), c110 VARCHAR(255), c111 VARCHAR(255), c112 VARCHAR(255),
+ c113 VARCHAR(255), c114 VARCHAR(255), c115 VARCHAR(255), c116 VARCHAR(255),
+ c117 VARCHAR(255), c118 VARCHAR(255), c119 VARCHAR(255), c120 VARCHAR(255),
+ c121 VARCHAR(255), c122 VARCHAR(255), c123 VARCHAR(255), c124 VARCHAR(255),
+ c125 VARCHAR(255), c126 VARCHAR(255), c127 VARCHAR(255), c128 VARCHAR(255)
+) ENGINE=INNODB;
+} }
+
+
+if ($row_format != 'dynamic') { if ($page_size == 4096) {
+CREATE TABLE t1 (
+ c1 VARCHAR(788), c2 VARCHAR(788)
+) ENGINE=INNODB;
+DROP TABLE t1;
+--error ER_TOO_BIG_ROWSIZE
+CREATE TABLE t1 (
+ c1 VARCHAR(788), c2 VARCHAR(788), c3 VARCHAR(788)
+) ENGINE=INNODB;
+
+CREATE TABLE t1 (
+ c1 TEXT, c2 TEXT
+) ENGINE=INNODB;
+DROP TABLE t1;
+--error ER_TOO_BIG_ROWSIZE
+CREATE TABLE t1 (
+ c1 TEXT, c2 TEXT, c3 TEXT
+) ENGINE=INNODB;
+} }
+
+
+if ($row_format != 'dynamic') { if ($page_size == 8192) {
+CREATE TABLE t1 (
+ c1 VARCHAR(788), c2 VARCHAR(788), c3 VARCHAR(788), c4 VARCHAR(788),
+ c5 VARCHAR(788)
+) ENGINE=INNODB;
+DROP TABLE t1;
+--error ER_TOO_BIG_ROWSIZE
+CREATE TABLE t1 (
+ c1 VARCHAR(788), c2 VARCHAR(788), c3 VARCHAR(788), c4 VARCHAR(788),
+ c5 VARCHAR(788), c6 VARCHAR(788)
+) ENGINE=INNODB;
+
+CREATE TABLE t1 (
+ c1 TEXT, c2 TEXT, c3 TEXT, c4 TEXT, c5 TEXT
+) ENGINE=INNODB;
+DROP TABLE t1;
+--error ER_TOO_BIG_ROWSIZE
+CREATE TABLE t1 (
+ c1 TEXT, c2 TEXT, c3 TEXT, c4 TEXT, c5 TEXT, c6 TEXT
+) ENGINE=INNODB;
+} }
+
+
+if ($row_format != 'dynamic') { if ($page_size == 16384) {
+CREATE TABLE t1 (
+ c1 VARCHAR(788), c2 VARCHAR(788), c3 VARCHAR(788), c4 VARCHAR(788),
+ c5 VARCHAR(788), c6 VARCHAR(788), c7 VARCHAR(788), c8 VARCHAR(788),
+ c9 VARCHAR(788), c10 VARCHAR(788)
+) ENGINE=INNODB;
+DROP TABLE t1;
+--error ER_TOO_BIG_ROWSIZE
+CREATE TABLE t1 (
+ c1 VARCHAR(788), c2 VARCHAR(788), c3 VARCHAR(788), c4 VARCHAR(788),
+ c5 VARCHAR(788), c6 VARCHAR(788), c7 VARCHAR(788), c8 VARCHAR(788),
+ c9 VARCHAR(788), c10 VARCHAR(788), c11 VARCHAR(788)
+) ENGINE=INNODB;
+
+CREATE TABLE t1 (
+ c1 TEXT, c2 TEXT, c3 TEXT, c4 TEXT, c5 TEXT, c6 TEXT, c7 TEXT,
+ c8 TEXT, c9 TEXT, c10 TEXT
+) ENGINE=INNODB;
+DROP TABLE t1;
+--error ER_TOO_BIG_ROWSIZE
+CREATE TABLE t1 (
+ c1 TEXT, c2 TEXT, c3 TEXT, c4 TEXT, c5 TEXT, c6 TEXT, c7 TEXT,
+ c8 TEXT, c9 TEXT, c10 TEXT, c11 TEXT
+) ENGINE=INNODB;
+} }
+
+
+if ($row_format != 'dynamic') { if ($page_size == 32768) {
+CREATE TABLE t1 (
+ c1 VARCHAR(788), c2 VARCHAR(788), c3 VARCHAR(788), c4 VARCHAR(788),
+ c5 VARCHAR(788), c6 VARCHAR(788), c7 VARCHAR(788), c8 VARCHAR(788),
+ c9 VARCHAR(788), c10 VARCHAR(788), c11 VARCHAR(788), c12 VARCHAR(788),
+ c13 VARCHAR(788), c14 VARCHAR(788), c15 VARCHAR(788), c16 VARCHAR(788),
+ c17 VARCHAR(788), c18 VARCHAR(788), c19 VARCHAR(788), c20 VARCHAR(788)
+) ENGINE=INNODB;
+DROP TABLE t1;
+--error ER_TOO_BIG_ROWSIZE
+CREATE TABLE t1 (
+ c1 VARCHAR(788), c2 VARCHAR(788), c3 VARCHAR(788), c4 VARCHAR(788),
+ c5 VARCHAR(788), c6 VARCHAR(788), c7 VARCHAR(788), c8 VARCHAR(788),
+ c9 VARCHAR(788), c10 VARCHAR(788), c11 VARCHAR(788), c12 VARCHAR(788),
+ c13 VARCHAR(788), c14 VARCHAR(788), c15 VARCHAR(788), c16 VARCHAR(788),
+ c17 VARCHAR(788), c18 VARCHAR(788), c19 VARCHAR(788), c20 VARCHAR(788),
+ c21 VARCHAR(788)
+) ENGINE=INNODB;
+
+CREATE TABLE t1 (
+ c1 TEXT, c2 TEXT, c3 TEXT, c4 TEXT, c5 TEXT, c6 TEXT, c7 TEXT,
+ c8 TEXT, c9 TEXT, c10 TEXT, c11 TEXT, c12 TEXT, c13 TEXT, c14 TEXT,
+ c15 TEXT, c16 TEXT, c17 TEXT, c18 TEXT, c19 TEXT, c20 TEXT
+) ENGINE=INNODB;
+DROP TABLE t1;
+--error ER_TOO_BIG_ROWSIZE
+CREATE TABLE t1 (
+ c1 TEXT, c2 TEXT, c3 TEXT, c4 TEXT, c5 TEXT, c6 TEXT, c7 TEXT,
+ c8 TEXT, c9 TEXT, c10 TEXT, c11 TEXT, c12 TEXT, c13 TEXT, c14 TEXT,
+ c15 TEXT, c16 TEXT, c17 TEXT, c18 TEXT, c19 TEXT, c20 TEXT, c21 TEXT
+) ENGINE=INNODB;
+} }
+
+
+if ($row_format == 'redundant') { if ($page_size == 65536) {
+CREATE TABLE t1 (
+ c1 VARCHAR(788), c2 VARCHAR(788), c3 VARCHAR(788), c4 VARCHAR(788),
+ c5 VARCHAR(788), c6 VARCHAR(788), c7 VARCHAR(788), c8 VARCHAR(788),
+ c9 VARCHAR(788), c10 VARCHAR(788), c11 VARCHAR(788), c12 VARCHAR(788),
+ c13 VARCHAR(788), c14 VARCHAR(788), c15 VARCHAR(788), c16 VARCHAR(788),
+ c17 VARCHAR(788), c18 VARCHAR(788), c19 VARCHAR(788), c20 VARCHAR(788)
+) ENGINE=INNODB;
+DROP TABLE t1;
+--error ER_TOO_BIG_ROWSIZE
+CREATE TABLE t1 (
+ c1 VARCHAR(788), c2 VARCHAR(788), c3 VARCHAR(788), c4 VARCHAR(788),
+ c5 VARCHAR(788), c6 VARCHAR(788), c7 VARCHAR(788), c8 VARCHAR(788),
+ c9 VARCHAR(788), c10 VARCHAR(788), c11 VARCHAR(788), c12 VARCHAR(788),
+ c13 VARCHAR(788), c14 VARCHAR(788), c15 VARCHAR(788), c16 VARCHAR(788),
+ c17 VARCHAR(788), c18 VARCHAR(788), c19 VARCHAR(788), c20 VARCHAR(788),
+ c21 VARCHAR(788)
+) ENGINE=INNODB;
+
+CREATE TABLE t1 (
+ c1 TEXT, c2 TEXT, c3 TEXT, c4 TEXT, c5 TEXT, c6 TEXT, c7 TEXT,
+ c8 TEXT, c9 TEXT, c10 TEXT, c11 TEXT, c12 TEXT, c13 TEXT, c14 TEXT,
+ c15 TEXT, c16 TEXT, c17 TEXT, c18 TEXT, c19 TEXT, c20 TEXT
+) ENGINE=INNODB;
+DROP TABLE t1;
+--error ER_TOO_BIG_ROWSIZE
+CREATE TABLE t1 (
+ c1 TEXT, c2 TEXT, c3 TEXT, c4 TEXT, c5 TEXT, c6 TEXT, c7 TEXT,
+ c8 TEXT, c9 TEXT, c10 TEXT, c11 TEXT, c12 TEXT, c13 TEXT, c14 TEXT,
+ c15 TEXT, c16 TEXT, c17 TEXT, c18 TEXT, c19 TEXT, c20 TEXT, c21 TEXT
+) ENGINE=INNODB;
+} }
+
+
+if ($row_format == 'compact') { if ($page_size == 65536) {
+CREATE TABLE t1 (
+ c1 VARCHAR(788), c2 VARCHAR(788), c3 VARCHAR(788), c4 VARCHAR(788),
+ c5 VARCHAR(788), c6 VARCHAR(788), c7 VARCHAR(788), c8 VARCHAR(788),
+ c9 VARCHAR(788), c10 VARCHAR(788), c11 VARCHAR(788), c12 VARCHAR(788),
+ c13 VARCHAR(788), c14 VARCHAR(788), c15 VARCHAR(788), c16 VARCHAR(788),
+ c17 VARCHAR(788), c18 VARCHAR(788), c19 VARCHAR(788), c20 VARCHAR(788),
+ c21 VARCHAR(788), c22 VARCHAR(788), c23 VARCHAR(788), c24 VARCHAR(788),
+ c25 VARCHAR(788), c26 VARCHAR(788), c27 VARCHAR(788), c28 VARCHAR(788),
+ c29 VARCHAR(788), c30 VARCHAR(788), c31 VARCHAR(788), c32 VARCHAR(788),
+ c33 VARCHAR(788), c34 VARCHAR(788), c35 VARCHAR(788), c36 VARCHAR(788),
+ c37 VARCHAR(788), c38 VARCHAR(788), c39 VARCHAR(788), c40 VARCHAR(788),
+ c41 VARCHAR(788)
+) ENGINE=INNODB;
+DROP TABLE t1;
+--error ER_TOO_BIG_ROWSIZE
+CREATE TABLE t1 (
+ c1 VARCHAR(788), c2 VARCHAR(788), c3 VARCHAR(788), c4 VARCHAR(788),
+ c5 VARCHAR(788), c6 VARCHAR(788), c7 VARCHAR(788), c8 VARCHAR(788),
+ c9 VARCHAR(788), c10 VARCHAR(788), c11 VARCHAR(788), c12 VARCHAR(788),
+ c13 VARCHAR(788), c14 VARCHAR(788), c15 VARCHAR(788), c16 VARCHAR(788),
+ c17 VARCHAR(788), c18 VARCHAR(788), c19 VARCHAR(788), c20 VARCHAR(788),
+ c21 VARCHAR(788), c22 VARCHAR(788), c23 VARCHAR(788), c24 VARCHAR(788),
+ c25 VARCHAR(788), c26 VARCHAR(788), c27 VARCHAR(788), c28 VARCHAR(788),
+ c29 VARCHAR(788), c30 VARCHAR(788), c31 VARCHAR(788), c32 VARCHAR(788),
+ c33 VARCHAR(788), c34 VARCHAR(788), c35 VARCHAR(788), c36 VARCHAR(788),
+ c37 VARCHAR(788), c38 VARCHAR(788), c39 VARCHAR(788), c40 VARCHAR(788),
+ c41 VARCHAR(788), c42 VARCHAR(788)
+) ENGINE=INNODB;
+
+CREATE TABLE t1 (
+ c1 TEXT, c2 TEXT, c3 TEXT, c4 TEXT, c5 TEXT, c6 TEXT, c7 TEXT,
+ c8 TEXT, c9 TEXT, c10 TEXT, c11 TEXT, c12 TEXT, c13 TEXT, c14 TEXT,
+ c15 TEXT, c16 TEXT, c17 TEXT, c18 TEXT, c19 TEXT, c20 TEXT, c21 TEXT,
+ c22 TEXT, c23 TEXT, c24 TEXT, c25 TEXT, c26 TEXT, c27 TEXT, c28 TEXT,
+ c29 TEXT, c30 TEXT, c31 TEXT, c32 TEXT, c33 TEXT, c34 TEXT, c35 TEXT,
+ c36 TEXT, c37 TEXT, c38 TEXT, c39 TEXT, c40 TEXT, c41 TEXT
+) ENGINE=INNODB;
+DROP TABLE t1;
+--error ER_TOO_BIG_ROWSIZE
+CREATE TABLE t1 (
+ c1 TEXT, c2 TEXT, c3 TEXT, c4 TEXT, c5 TEXT, c6 TEXT, c7 TEXT,
+ c8 TEXT, c9 TEXT, c10 TEXT, c11 TEXT, c12 TEXT, c13 TEXT, c14 TEXT,
+ c15 TEXT, c16 TEXT, c17 TEXT, c18 TEXT, c19 TEXT, c20 TEXT, c21 TEXT,
+ c22 TEXT, c23 TEXT, c24 TEXT, c25 TEXT, c26 TEXT, c27 TEXT, c28 TEXT,
+ c29 TEXT, c30 TEXT, c31 TEXT, c32 TEXT, c33 TEXT, c34 TEXT, c35 TEXT,
+ c36 TEXT, c37 TEXT, c38 TEXT, c39 TEXT, c40 TEXT, c41 TEXT, c42 TEXT
+) ENGINE=INNODB;
+} }
+
+
+if ($row_format == 'dynamic') {
+CREATE TABLE t1 (
+ c1 VARCHAR(788), c2 VARCHAR(788), c3 VARCHAR(788), c4 VARCHAR(788),
+ c5 VARCHAR(788), c6 VARCHAR(788), c7 VARCHAR(788), c8 VARCHAR(788),
+ c9 VARCHAR(788), c10 VARCHAR(788), c11 VARCHAR(788), c12 VARCHAR(788),
+ c13 VARCHAR(788), c14 VARCHAR(788), c15 VARCHAR(788), c16 VARCHAR(788),
+ c17 VARCHAR(788), c18 VARCHAR(788), c19 VARCHAR(788), c20 VARCHAR(788),
+ c21 VARCHAR(788), c22 VARCHAR(788), c23 VARCHAR(788), c24 VARCHAR(788),
+ c25 VARCHAR(788), c26 VARCHAR(788), c27 VARCHAR(788), c28 VARCHAR(788),
+ c29 VARCHAR(788), c30 VARCHAR(788), c31 VARCHAR(788), c32 VARCHAR(788),
+ c33 VARCHAR(788), c34 VARCHAR(788), c35 VARCHAR(788), c36 VARCHAR(788),
+ c37 VARCHAR(788), c38 VARCHAR(788), c39 VARCHAR(788), c40 VARCHAR(788),
+ c41 VARCHAR(788), c42 VARCHAR(788), c43 VARCHAR(788), c44 VARCHAR(788),
+ c45 VARCHAR(788), c46 VARCHAR(788), c47 VARCHAR(788), c48 VARCHAR(788),
+ c49 VARCHAR(788), c50 VARCHAR(788), c51 VARCHAR(788), c52 VARCHAR(788),
+ c53 VARCHAR(788), c54 VARCHAR(788), c55 VARCHAR(788), c56 VARCHAR(788),
+ c57 VARCHAR(788), c58 VARCHAR(788), c59 VARCHAR(788), c60 VARCHAR(788),
+ c61 VARCHAR(788), c62 VARCHAR(788), c63 VARCHAR(788), c64 VARCHAR(788),
+ c65 VARCHAR(788), c66 VARCHAR(788), c67 VARCHAR(788), c68 VARCHAR(788),
+ c69 VARCHAR(788), c70 VARCHAR(788), c71 VARCHAR(788), c72 VARCHAR(788),
+ c73 VARCHAR(788), c74 VARCHAR(788), c75 VARCHAR(788), c76 VARCHAR(788),
+ c77 VARCHAR(788), c78 VARCHAR(788), c79 VARCHAR(788), c80 VARCHAR(788),
+ c81 VARCHAR(788), c82 VARCHAR(788)
+) ENGINE=INNODB;
+DROP TABLE t1;
+--error ER_TOO_BIG_ROWSIZE
+CREATE TABLE t1 (
+ c1 VARCHAR(788), c2 VARCHAR(788), c3 VARCHAR(788), c4 VARCHAR(788),
+ c5 VARCHAR(788), c6 VARCHAR(788), c7 VARCHAR(788), c8 VARCHAR(788),
+ c9 VARCHAR(788), c10 VARCHAR(788), c11 VARCHAR(788), c12 VARCHAR(788),
+ c13 VARCHAR(788), c14 VARCHAR(788), c15 VARCHAR(788), c16 VARCHAR(788),
+ c17 VARCHAR(788), c18 VARCHAR(788), c19 VARCHAR(788), c20 VARCHAR(788),
+ c21 VARCHAR(788), c22 VARCHAR(788), c23 VARCHAR(788), c24 VARCHAR(788),
+ c25 VARCHAR(788), c26 VARCHAR(788), c27 VARCHAR(788), c28 VARCHAR(788),
+ c29 VARCHAR(788), c30 VARCHAR(788), c31 VARCHAR(788), c32 VARCHAR(788),
+ c33 VARCHAR(788), c34 VARCHAR(788), c35 VARCHAR(788), c36 VARCHAR(788),
+ c37 VARCHAR(788), c38 VARCHAR(788), c39 VARCHAR(788), c40 VARCHAR(788),
+ c41 VARCHAR(788), c42 VARCHAR(788), c43 VARCHAR(788), c44 VARCHAR(788),
+ c45 VARCHAR(788), c46 VARCHAR(788), c47 VARCHAR(788), c48 VARCHAR(788),
+ c49 VARCHAR(788), c50 VARCHAR(788), c51 VARCHAR(788), c52 VARCHAR(788),
+ c53 VARCHAR(788), c54 VARCHAR(788), c55 VARCHAR(788), c56 VARCHAR(788),
+ c57 VARCHAR(788), c58 VARCHAR(788), c59 VARCHAR(788), c60 VARCHAR(788),
+ c61 VARCHAR(788), c62 VARCHAR(788), c63 VARCHAR(788), c64 VARCHAR(788),
+ c65 VARCHAR(788), c66 VARCHAR(788), c67 VARCHAR(788), c68 VARCHAR(788),
+ c69 VARCHAR(788), c70 VARCHAR(788), c71 VARCHAR(788), c72 VARCHAR(788),
+ c73 VARCHAR(788), c74 VARCHAR(788), c75 VARCHAR(788), c76 VARCHAR(788),
+ c77 VARCHAR(788), c78 VARCHAR(788), c79 VARCHAR(788), c80 VARCHAR(788),
+ c81 VARCHAR(788), c82 VARCHAR(788), c83 VARCHAR(788)
+) ENGINE=INNODB;
+}
+
+
+if ($row_format == 'dynamic') { if ($page_size == 4096) {
+CREATE TABLE t1 (
+ c1 TEXT, c2 TEXT, c3 TEXT, c4 TEXT, c5 TEXT, c6 TEXT, c7 TEXT,
+ c8 TEXT, c9 TEXT, c10 TEXT, c11 TEXT, c12 TEXT, c13 TEXT, c14 TEXT,
+ c15 TEXT, c16 TEXT, c17 TEXT, c18 TEXT, c19 TEXT, c20 TEXT, c21 TEXT,
+ c22 TEXT, c23 TEXT, c24 TEXT, c25 TEXT, c26 TEXT, c27 TEXT, c28 TEXT,
+ c29 TEXT, c30 TEXT, c31 TEXT, c32 TEXT, c33 TEXT, c34 TEXT, c35 TEXT,
+ c36 TEXT, c37 TEXT, c38 TEXT, c39 TEXT, c40 TEXT, c41 TEXT, c42 TEXT,
+ c43 TEXT, c44 TEXT, c45 TEXT, c46 TEXT, c47 TEXT, c48 TEXT, c49 TEXT,
+ c50 TEXT, c51 TEXT, c52 TEXT, c53 TEXT, c54 TEXT, c55 TEXT, c56 TEXT,
+ c57 TEXT, c58 TEXT, c59 TEXT, c60 TEXT, c61 TEXT, c62 TEXT, c63 TEXT,
+ c64 TEXT, c65 TEXT, c66 TEXT, c67 TEXT, c68 TEXT, c69 TEXT, c70 TEXT,
+ c71 TEXT, c72 TEXT, c73 TEXT, c74 TEXT, c75 TEXT, c76 TEXT, c77 TEXT,
+ c78 TEXT, c79 TEXT, c80 TEXT, c81 TEXT, c82 TEXT, c83 TEXT, c84 TEXT,
+ c85 TEXT, c86 TEXT, c87 TEXT, c88 TEXT, c89 TEXT, c90 TEXT, c91 TEXT,
+ c92 TEXT
+) ENGINE=INNODB;
+DROP TABLE t1;
+--error ER_TOO_BIG_ROWSIZE
+CREATE TABLE t1 (
+ c1 TEXT, c2 TEXT, c3 TEXT, c4 TEXT, c5 TEXT, c6 TEXT, c7 TEXT,
+ c8 TEXT, c9 TEXT, c10 TEXT, c11 TEXT, c12 TEXT, c13 TEXT, c14 TEXT,
+ c15 TEXT, c16 TEXT, c17 TEXT, c18 TEXT, c19 TEXT, c20 TEXT, c21 TEXT,
+ c22 TEXT, c23 TEXT, c24 TEXT, c25 TEXT, c26 TEXT, c27 TEXT, c28 TEXT,
+ c29 TEXT, c30 TEXT, c31 TEXT, c32 TEXT, c33 TEXT, c34 TEXT, c35 TEXT,
+ c36 TEXT, c37 TEXT, c38 TEXT, c39 TEXT, c40 TEXT, c41 TEXT, c42 TEXT,
+ c43 TEXT, c44 TEXT, c45 TEXT, c46 TEXT, c47 TEXT, c48 TEXT, c49 TEXT,
+ c50 TEXT, c51 TEXT, c52 TEXT, c53 TEXT, c54 TEXT, c55 TEXT, c56 TEXT,
+ c57 TEXT, c58 TEXT, c59 TEXT, c60 TEXT, c61 TEXT, c62 TEXT, c63 TEXT,
+ c64 TEXT, c65 TEXT, c66 TEXT, c67 TEXT, c68 TEXT, c69 TEXT, c70 TEXT,
+ c71 TEXT, c72 TEXT, c73 TEXT, c74 TEXT, c75 TEXT, c76 TEXT, c77 TEXT,
+ c78 TEXT, c79 TEXT, c80 TEXT, c81 TEXT, c82 TEXT, c83 TEXT, c84 TEXT,
+ c85 TEXT, c86 TEXT, c87 TEXT, c88 TEXT, c89 TEXT, c90 TEXT, c91 TEXT,
+ c92 TEXT, c93 TEXT
+) ENGINE=INNODB;
+} }
+
+
+if ($row_format == 'dynamic') { if ($page_size == 8192) {
+CREATE TABLE t1 (
+ c1 TEXT, c2 TEXT, c3 TEXT, c4 TEXT, c5 TEXT, c6 TEXT, c7 TEXT,
+ c8 TEXT, c9 TEXT, c10 TEXT, c11 TEXT, c12 TEXT, c13 TEXT, c14 TEXT,
+ c15 TEXT, c16 TEXT, c17 TEXT, c18 TEXT, c19 TEXT, c20 TEXT, c21 TEXT,
+ c22 TEXT, c23 TEXT, c24 TEXT, c25 TEXT, c26 TEXT, c27 TEXT, c28 TEXT,
+ c29 TEXT, c30 TEXT, c31 TEXT, c32 TEXT, c33 TEXT, c34 TEXT, c35 TEXT,
+ c36 TEXT, c37 TEXT, c38 TEXT, c39 TEXT, c40 TEXT, c41 TEXT, c42 TEXT,
+ c43 TEXT, c44 TEXT, c45 TEXT, c46 TEXT, c47 TEXT, c48 TEXT, c49 TEXT,
+ c50 TEXT, c51 TEXT, c52 TEXT, c53 TEXT, c54 TEXT, c55 TEXT, c56 TEXT,
+ c57 TEXT, c58 TEXT, c59 TEXT, c60 TEXT, c61 TEXT, c62 TEXT, c63 TEXT,
+ c64 TEXT, c65 TEXT, c66 TEXT, c67 TEXT, c68 TEXT, c69 TEXT, c70 TEXT,
+ c71 TEXT, c72 TEXT, c73 TEXT, c74 TEXT, c75 TEXT, c76 TEXT, c77 TEXT,
+ c78 TEXT, c79 TEXT, c80 TEXT, c81 TEXT, c82 TEXT, c83 TEXT, c84 TEXT,
+ c85 TEXT, c86 TEXT, c87 TEXT, c88 TEXT, c89 TEXT, c90 TEXT, c91 TEXT,
+ c92 TEXT, c93 TEXT, c94 TEXT, c95 TEXT, c96 TEXT, c97 TEXT, c98 TEXT,
+ c99 TEXT, c100 TEXT, c101 TEXT, c102 TEXT, c103 TEXT, c104 TEXT, c105 TEXT,
+ c106 TEXT, c107 TEXT, c108 TEXT, c109 TEXT, c110 TEXT, c111 TEXT, c112 TEXT,
+ c113 TEXT, c114 TEXT, c115 TEXT, c116 TEXT, c117 TEXT, c118 TEXT, c119 TEXT,
+ c120 TEXT, c121 TEXT, c122 TEXT, c123 TEXT, c124 TEXT, c125 TEXT, c126 TEXT,
+ c127 TEXT, c128 TEXT, c129 TEXT, c130 TEXT, c131 TEXT, c132 TEXT, c133 TEXT,
+ c134 TEXT, c135 TEXT, c136 TEXT, c137 TEXT, c138 TEXT, c139 TEXT, c140 TEXT,
+ c141 TEXT, c142 TEXT, c143 TEXT, c144 TEXT, c145 TEXT, c146 TEXT, c147 TEXT,
+ c148 TEXT, c149 TEXT, c150 TEXT, c151 TEXT, c152 TEXT, c153 TEXT, c154 TEXT,
+ c155 TEXT, c156 TEXT, c157 TEXT, c158 TEXT, c159 TEXT, c160 TEXT, c161 TEXT,
+ c162 TEXT, c163 TEXT, c164 TEXT, c165 TEXT, c166 TEXT, c167 TEXT, c168 TEXT,
+ c169 TEXT, c170 TEXT, c171 TEXT, c172 TEXT, c173 TEXT, c174 TEXT, c175 TEXT,
+ c176 TEXT, c177 TEXT, c178 TEXT, c179 TEXT, c180 TEXT, c181 TEXT, c182 TEXT,
+ c183 TEXT, c184 TEXT, c185 TEXT, c186 TEXT, c187 TEXT, c188 TEXT, c189 TEXT
+) ENGINE=INNODB;
+DROP TABLE t1;
+--error ER_TOO_BIG_ROWSIZE
+CREATE TABLE t1 (
+ c1 TEXT, c2 TEXT, c3 TEXT, c4 TEXT, c5 TEXT, c6 TEXT, c7 TEXT,
+ c8 TEXT, c9 TEXT, c10 TEXT, c11 TEXT, c12 TEXT, c13 TEXT, c14 TEXT,
+ c15 TEXT, c16 TEXT, c17 TEXT, c18 TEXT, c19 TEXT, c20 TEXT, c21 TEXT,
+ c22 TEXT, c23 TEXT, c24 TEXT, c25 TEXT, c26 TEXT, c27 TEXT, c28 TEXT,
+ c29 TEXT, c30 TEXT, c31 TEXT, c32 TEXT, c33 TEXT, c34 TEXT, c35 TEXT,
+ c36 TEXT, c37 TEXT, c38 TEXT, c39 TEXT, c40 TEXT, c41 TEXT, c42 TEXT,
+ c43 TEXT, c44 TEXT, c45 TEXT, c46 TEXT, c47 TEXT, c48 TEXT, c49 TEXT,
+ c50 TEXT, c51 TEXT, c52 TEXT, c53 TEXT, c54 TEXT, c55 TEXT, c56 TEXT,
+ c57 TEXT, c58 TEXT, c59 TEXT, c60 TEXT, c61 TEXT, c62 TEXT, c63 TEXT,
+ c64 TEXT, c65 TEXT, c66 TEXT, c67 TEXT, c68 TEXT, c69 TEXT, c70 TEXT,
+ c71 TEXT, c72 TEXT, c73 TEXT, c74 TEXT, c75 TEXT, c76 TEXT, c77 TEXT,
+ c78 TEXT, c79 TEXT, c80 TEXT, c81 TEXT, c82 TEXT, c83 TEXT, c84 TEXT,
+ c85 TEXT, c86 TEXT, c87 TEXT, c88 TEXT, c89 TEXT, c90 TEXT, c91 TEXT,
+ c92 TEXT, c93 TEXT, c94 TEXT, c95 TEXT, c96 TEXT, c97 TEXT, c98 TEXT,
+ c99 TEXT, c100 TEXT, c101 TEXT, c102 TEXT, c103 TEXT, c104 TEXT, c105 TEXT,
+ c106 TEXT, c107 TEXT, c108 TEXT, c109 TEXT, c110 TEXT, c111 TEXT, c112 TEXT,
+ c113 TEXT, c114 TEXT, c115 TEXT, c116 TEXT, c117 TEXT, c118 TEXT, c119 TEXT,
+ c120 TEXT, c121 TEXT, c122 TEXT, c123 TEXT, c124 TEXT, c125 TEXT, c126 TEXT,
+ c127 TEXT, c128 TEXT, c129 TEXT, c130 TEXT, c131 TEXT, c132 TEXT, c133 TEXT,
+ c134 TEXT, c135 TEXT, c136 TEXT, c137 TEXT, c138 TEXT, c139 TEXT, c140 TEXT,
+ c141 TEXT, c142 TEXT, c143 TEXT, c144 TEXT, c145 TEXT, c146 TEXT, c147 TEXT,
+ c148 TEXT, c149 TEXT, c150 TEXT, c151 TEXT, c152 TEXT, c153 TEXT, c154 TEXT,
+ c155 TEXT, c156 TEXT, c157 TEXT, c158 TEXT, c159 TEXT, c160 TEXT, c161 TEXT,
+ c162 TEXT, c163 TEXT, c164 TEXT, c165 TEXT, c166 TEXT, c167 TEXT, c168 TEXT,
+ c169 TEXT, c170 TEXT, c171 TEXT, c172 TEXT, c173 TEXT, c174 TEXT, c175 TEXT,
+ c176 TEXT, c177 TEXT, c178 TEXT, c179 TEXT, c180 TEXT, c181 TEXT, c182 TEXT,
+ c183 TEXT, c184 TEXT, c185 TEXT, c186 TEXT, c187 TEXT, c188 TEXT, c189 TEXT,
+ c190 TEXT
+) ENGINE=INNODB;
+} }
+
+
+if ($row_format == 'dynamic') { if ($page_size == 16384) {
+CREATE TABLE t1 (
+ c1 TEXT, c2 TEXT, c3 TEXT, c4 TEXT, c5 TEXT, c6 TEXT, c7 TEXT,
+ c8 TEXT, c9 TEXT, c10 TEXT, c11 TEXT, c12 TEXT, c13 TEXT, c14 TEXT,
+ c15 TEXT, c16 TEXT, c17 TEXT, c18 TEXT, c19 TEXT, c20 TEXT, c21 TEXT,
+ c22 TEXT, c23 TEXT, c24 TEXT, c25 TEXT, c26 TEXT, c27 TEXT, c28 TEXT,
+ c29 TEXT, c30 TEXT, c31 TEXT, c32 TEXT, c33 TEXT, c34 TEXT, c35 TEXT,
+ c36 TEXT, c37 TEXT, c38 TEXT, c39 TEXT, c40 TEXT, c41 TEXT, c42 TEXT,
+ c43 TEXT, c44 TEXT, c45 TEXT, c46 TEXT, c47 TEXT, c48 TEXT, c49 TEXT,
+ c50 TEXT, c51 TEXT, c52 TEXT, c53 TEXT, c54 TEXT, c55 TEXT, c56 TEXT,
+ c57 TEXT, c58 TEXT, c59 TEXT, c60 TEXT, c61 TEXT, c62 TEXT, c63 TEXT,
+ c64 TEXT, c65 TEXT, c66 TEXT, c67 TEXT, c68 TEXT, c69 TEXT, c70 TEXT,
+ c71 TEXT, c72 TEXT, c73 TEXT, c74 TEXT, c75 TEXT, c76 TEXT, c77 TEXT,
+ c78 TEXT, c79 TEXT, c80 TEXT, c81 TEXT, c82 TEXT, c83 TEXT, c84 TEXT,
+ c85 TEXT, c86 TEXT, c87 TEXT, c88 TEXT, c89 TEXT, c90 TEXT, c91 TEXT,
+ c92 TEXT, c93 TEXT, c94 TEXT, c95 TEXT, c96 TEXT, c97 TEXT, c98 TEXT,
+ c99 TEXT, c100 TEXT, c101 TEXT, c102 TEXT, c103 TEXT, c104 TEXT, c105 TEXT,
+ c106 TEXT, c107 TEXT, c108 TEXT, c109 TEXT, c110 TEXT, c111 TEXT, c112 TEXT,
+ c113 TEXT, c114 TEXT, c115 TEXT, c116 TEXT, c117 TEXT, c118 TEXT, c119 TEXT,
+ c120 TEXT, c121 TEXT, c122 TEXT, c123 TEXT, c124 TEXT, c125 TEXT, c126 TEXT,
+ c127 TEXT, c128 TEXT, c129 TEXT, c130 TEXT, c131 TEXT, c132 TEXT, c133 TEXT,
+ c134 TEXT, c135 TEXT, c136 TEXT, c137 TEXT, c138 TEXT, c139 TEXT, c140 TEXT,
+ c141 TEXT, c142 TEXT, c143 TEXT, c144 TEXT, c145 TEXT, c146 TEXT, c147 TEXT,
+ c148 TEXT, c149 TEXT, c150 TEXT, c151 TEXT, c152 TEXT, c153 TEXT, c154 TEXT,
+ c155 TEXT, c156 TEXT, c157 TEXT, c158 TEXT, c159 TEXT, c160 TEXT, c161 TEXT,
+ c162 TEXT, c163 TEXT, c164 TEXT, c165 TEXT, c166 TEXT, c167 TEXT, c168 TEXT,
+ c169 TEXT, c170 TEXT, c171 TEXT, c172 TEXT, c173 TEXT, c174 TEXT, c175 TEXT,
+ c176 TEXT, c177 TEXT, c178 TEXT, c179 TEXT, c180 TEXT, c181 TEXT, c182 TEXT,
+ c183 TEXT, c184 TEXT, c185 TEXT, c186 TEXT, c187 TEXT, c188 TEXT, c189 TEXT,
+ c190 TEXT, c191 TEXT, c192 TEXT, c193 TEXT, c194 TEXT, c195 TEXT, c196 TEXT,
+ c197 TEXT, c198 TEXT, c199 TEXT, c200 TEXT, c201 TEXT, c202 TEXT, c203 TEXT,
+ c204 TEXT, c205 TEXT, c206 TEXT, c207 TEXT, c208 TEXT, c209 TEXT, c210 TEXT,
+ c211 TEXT, c212 TEXT, c213 TEXT, c214 TEXT, c215 TEXT, c216 TEXT, c217 TEXT,
+ c218 TEXT, c219 TEXT, c220 TEXT, c221 TEXT, c222 TEXT, c223 TEXT, c224 TEXT,
+ c225 TEXT, c226 TEXT, c227 TEXT, c228 TEXT, c229 TEXT, c230 TEXT, c231 TEXT,
+ c232 TEXT, c233 TEXT, c234 TEXT, c235 TEXT, c236 TEXT, c237 TEXT, c238 TEXT,
+ c239 TEXT, c240 TEXT, c241 TEXT, c242 TEXT, c243 TEXT, c244 TEXT, c245 TEXT,
+ c246 TEXT, c247 TEXT, c248 TEXT, c249 TEXT, c250 TEXT, c251 TEXT, c252 TEXT,
+ c253 TEXT, c254 TEXT, c255 TEXT, c256 TEXT, c257 TEXT, c258 TEXT, c259 TEXT,
+ c260 TEXT, c261 TEXT, c262 TEXT, c263 TEXT, c264 TEXT, c265 TEXT, c266 TEXT,
+ c267 TEXT, c268 TEXT, c269 TEXT, c270 TEXT, c271 TEXT, c272 TEXT, c273 TEXT,
+ c274 TEXT, c275 TEXT, c276 TEXT, c277 TEXT, c278 TEXT, c279 TEXT, c280 TEXT,
+ c281 TEXT, c282 TEXT, c283 TEXT, c284 TEXT, c285 TEXT, c286 TEXT, c287 TEXT,
+ c288 TEXT, c289 TEXT, c290 TEXT, c291 TEXT, c292 TEXT, c293 TEXT, c294 TEXT,
+ c295 TEXT, c296 TEXT, c297 TEXT, c298 TEXT, c299 TEXT, c300 TEXT, c301 TEXT,
+ c302 TEXT, c303 TEXT, c304 TEXT, c305 TEXT, c306 TEXT, c307 TEXT, c308 TEXT,
+ c309 TEXT, c310 TEXT, c311 TEXT, c312 TEXT, c313 TEXT, c314 TEXT, c315 TEXT,
+ c316 TEXT, c317 TEXT, c318 TEXT, c319 TEXT, c320 TEXT, c321 TEXT, c322 TEXT,
+ c323 TEXT, c324 TEXT, c325 TEXT, c326 TEXT, c327 TEXT, c328 TEXT, c329 TEXT,
+ c330 TEXT, c331 TEXT, c332 TEXT, c333 TEXT, c334 TEXT, c335 TEXT, c336 TEXT,
+ c337 TEXT, c338 TEXT, c339 TEXT, c340 TEXT, c341 TEXT, c342 TEXT, c343 TEXT,
+ c344 TEXT, c345 TEXT, c346 TEXT, c347 TEXT, c348 TEXT, c349 TEXT, c350 TEXT,
+ c351 TEXT, c352 TEXT, c353 TEXT, c354 TEXT, c355 TEXT, c356 TEXT, c357 TEXT,
+ c358 TEXT, c359 TEXT, c360 TEXT, c361 TEXT, c362 TEXT, c363 TEXT, c364 TEXT,
+ c365 TEXT, c366 TEXT, c367 TEXT, c368 TEXT, c369 TEXT, c370 TEXT, c371 TEXT,
+ c372 TEXT, c373 TEXT, c374 TEXT, c375 TEXT, c376 TEXT, c377 TEXT, c378 TEXT,
+ c379 TEXT, c380 TEXT, c381 TEXT, c382 TEXT, c383 TEXT
+) ENGINE=INNODB;
+DROP TABLE t1;
+--error ER_TOO_BIG_ROWSIZE
+CREATE TABLE t1 (
+ c1 TEXT, c2 TEXT, c3 TEXT, c4 TEXT, c5 TEXT, c6 TEXT, c7 TEXT,
+ c8 TEXT, c9 TEXT, c10 TEXT, c11 TEXT, c12 TEXT, c13 TEXT, c14 TEXT,
+ c15 TEXT, c16 TEXT, c17 TEXT, c18 TEXT, c19 TEXT, c20 TEXT, c21 TEXT,
+ c22 TEXT, c23 TEXT, c24 TEXT, c25 TEXT, c26 TEXT, c27 TEXT, c28 TEXT,
+ c29 TEXT, c30 TEXT, c31 TEXT, c32 TEXT, c33 TEXT, c34 TEXT, c35 TEXT,
+ c36 TEXT, c37 TEXT, c38 TEXT, c39 TEXT, c40 TEXT, c41 TEXT, c42 TEXT,
+ c43 TEXT, c44 TEXT, c45 TEXT, c46 TEXT, c47 TEXT, c48 TEXT, c49 TEXT,
+ c50 TEXT, c51 TEXT, c52 TEXT, c53 TEXT, c54 TEXT, c55 TEXT, c56 TEXT,
+ c57 TEXT, c58 TEXT, c59 TEXT, c60 TEXT, c61 TEXT, c62 TEXT, c63 TEXT,
+ c64 TEXT, c65 TEXT, c66 TEXT, c67 TEXT, c68 TEXT, c69 TEXT, c70 TEXT,
+ c71 TEXT, c72 TEXT, c73 TEXT, c74 TEXT, c75 TEXT, c76 TEXT, c77 TEXT,
+ c78 TEXT, c79 TEXT, c80 TEXT, c81 TEXT, c82 TEXT, c83 TEXT, c84 TEXT,
+ c85 TEXT, c86 TEXT, c87 TEXT, c88 TEXT, c89 TEXT, c90 TEXT, c91 TEXT,
+ c92 TEXT, c93 TEXT, c94 TEXT, c95 TEXT, c96 TEXT, c97 TEXT, c98 TEXT,
+ c99 TEXT, c100 TEXT, c101 TEXT, c102 TEXT, c103 TEXT, c104 TEXT, c105 TEXT,
+ c106 TEXT, c107 TEXT, c108 TEXT, c109 TEXT, c110 TEXT, c111 TEXT, c112 TEXT,
+ c113 TEXT, c114 TEXT, c115 TEXT, c116 TEXT, c117 TEXT, c118 TEXT, c119 TEXT,
+ c120 TEXT, c121 TEXT, c122 TEXT, c123 TEXT, c124 TEXT, c125 TEXT, c126 TEXT,
+ c127 TEXT, c128 TEXT, c129 TEXT, c130 TEXT, c131 TEXT, c132 TEXT, c133 TEXT,
+ c134 TEXT, c135 TEXT, c136 TEXT, c137 TEXT, c138 TEXT, c139 TEXT, c140 TEXT,
+ c141 TEXT, c142 TEXT, c143 TEXT, c144 TEXT, c145 TEXT, c146 TEXT, c147 TEXT,
+ c148 TEXT, c149 TEXT, c150 TEXT, c151 TEXT, c152 TEXT, c153 TEXT, c154 TEXT,
+ c155 TEXT, c156 TEXT, c157 TEXT, c158 TEXT, c159 TEXT, c160 TEXT, c161 TEXT,
+ c162 TEXT, c163 TEXT, c164 TEXT, c165 TEXT, c166 TEXT, c167 TEXT, c168 TEXT,
+ c169 TEXT, c170 TEXT, c171 TEXT, c172 TEXT, c173 TEXT, c174 TEXT, c175 TEXT,
+ c176 TEXT, c177 TEXT, c178 TEXT, c179 TEXT, c180 TEXT, c181 TEXT, c182 TEXT,
+ c183 TEXT, c184 TEXT, c185 TEXT, c186 TEXT, c187 TEXT, c188 TEXT, c189 TEXT,
+ c190 TEXT, c191 TEXT, c192 TEXT, c193 TEXT, c194 TEXT, c195 TEXT, c196 TEXT,
+ c197 TEXT, c198 TEXT, c199 TEXT, c200 TEXT, c201 TEXT, c202 TEXT, c203 TEXT,
+ c204 TEXT, c205 TEXT, c206 TEXT, c207 TEXT, c208 TEXT, c209 TEXT, c210 TEXT,
+ c211 TEXT, c212 TEXT, c213 TEXT, c214 TEXT, c215 TEXT, c216 TEXT, c217 TEXT,
+ c218 TEXT, c219 TEXT, c220 TEXT, c221 TEXT, c222 TEXT, c223 TEXT, c224 TEXT,
+ c225 TEXT, c226 TEXT, c227 TEXT, c228 TEXT, c229 TEXT, c230 TEXT, c231 TEXT,
+ c232 TEXT, c233 TEXT, c234 TEXT, c235 TEXT, c236 TEXT, c237 TEXT, c238 TEXT,
+ c239 TEXT, c240 TEXT, c241 TEXT, c242 TEXT, c243 TEXT, c244 TEXT, c245 TEXT,
+ c246 TEXT, c247 TEXT, c248 TEXT, c249 TEXT, c250 TEXT, c251 TEXT, c252 TEXT,
+ c253 TEXT, c254 TEXT, c255 TEXT, c256 TEXT, c257 TEXT, c258 TEXT, c259 TEXT,
+ c260 TEXT, c261 TEXT, c262 TEXT, c263 TEXT, c264 TEXT, c265 TEXT, c266 TEXT,
+ c267 TEXT, c268 TEXT, c269 TEXT, c270 TEXT, c271 TEXT, c272 TEXT, c273 TEXT,
+ c274 TEXT, c275 TEXT, c276 TEXT, c277 TEXT, c278 TEXT, c279 TEXT, c280 TEXT,
+ c281 TEXT, c282 TEXT, c283 TEXT, c284 TEXT, c285 TEXT, c286 TEXT, c287 TEXT,
+ c288 TEXT, c289 TEXT, c290 TEXT, c291 TEXT, c292 TEXT, c293 TEXT, c294 TEXT,
+ c295 TEXT, c296 TEXT, c297 TEXT, c298 TEXT, c299 TEXT, c300 TEXT, c301 TEXT,
+ c302 TEXT, c303 TEXT, c304 TEXT, c305 TEXT, c306 TEXT, c307 TEXT, c308 TEXT,
+ c309 TEXT, c310 TEXT, c311 TEXT, c312 TEXT, c313 TEXT, c314 TEXT, c315 TEXT,
+ c316 TEXT, c317 TEXT, c318 TEXT, c319 TEXT, c320 TEXT, c321 TEXT, c322 TEXT,
+ c323 TEXT, c324 TEXT, c325 TEXT, c326 TEXT, c327 TEXT, c328 TEXT, c329 TEXT,
+ c330 TEXT, c331 TEXT, c332 TEXT, c333 TEXT, c334 TEXT, c335 TEXT, c336 TEXT,
+ c337 TEXT, c338 TEXT, c339 TEXT, c340 TEXT, c341 TEXT, c342 TEXT, c343 TEXT,
+ c344 TEXT, c345 TEXT, c346 TEXT, c347 TEXT, c348 TEXT, c349 TEXT, c350 TEXT,
+ c351 TEXT, c352 TEXT, c353 TEXT, c354 TEXT, c355 TEXT, c356 TEXT, c357 TEXT,
+ c358 TEXT, c359 TEXT, c360 TEXT, c361 TEXT, c362 TEXT, c363 TEXT, c364 TEXT,
+ c365 TEXT, c366 TEXT, c367 TEXT, c368 TEXT, c369 TEXT, c370 TEXT, c371 TEXT,
+ c372 TEXT, c373 TEXT, c374 TEXT, c375 TEXT, c376 TEXT, c377 TEXT, c378 TEXT,
+ c379 TEXT, c380 TEXT, c381 TEXT, c382 TEXT, c383 TEXT, c384 TEXT
+) ENGINE=INNODB;
+} }
+
+
+if ($row_format == 'dynamic') { if ($page_size == 32768) {
+CREATE TABLE t1 (
+ c1 TEXT, c2 TEXT, c3 TEXT, c4 TEXT, c5 TEXT, c6 TEXT, c7 TEXT,
+ c8 TEXT, c9 TEXT, c10 TEXT, c11 TEXT, c12 TEXT, c13 TEXT, c14 TEXT,
+ c15 TEXT, c16 TEXT, c17 TEXT, c18 TEXT, c19 TEXT, c20 TEXT, c21 TEXT,
+ c22 TEXT, c23 TEXT, c24 TEXT, c25 TEXT, c26 TEXT, c27 TEXT, c28 TEXT,
+ c29 TEXT, c30 TEXT, c31 TEXT, c32 TEXT, c33 TEXT, c34 TEXT, c35 TEXT,
+ c36 TEXT, c37 TEXT, c38 TEXT, c39 TEXT, c40 TEXT, c41 TEXT, c42 TEXT,
+ c43 TEXT, c44 TEXT, c45 TEXT, c46 TEXT, c47 TEXT, c48 TEXT, c49 TEXT,
+ c50 TEXT, c51 TEXT, c52 TEXT, c53 TEXT, c54 TEXT, c55 TEXT, c56 TEXT,
+ c57 TEXT, c58 TEXT, c59 TEXT, c60 TEXT, c61 TEXT, c62 TEXT, c63 TEXT,
+ c64 TEXT, c65 TEXT, c66 TEXT, c67 TEXT, c68 TEXT, c69 TEXT, c70 TEXT,
+ c71 TEXT, c72 TEXT, c73 TEXT, c74 TEXT, c75 TEXT, c76 TEXT, c77 TEXT,
+ c78 TEXT, c79 TEXT, c80 TEXT, c81 TEXT, c82 TEXT, c83 TEXT, c84 TEXT,
+ c85 TEXT, c86 TEXT, c87 TEXT, c88 TEXT, c89 TEXT, c90 TEXT, c91 TEXT,
+ c92 TEXT, c93 TEXT, c94 TEXT, c95 TEXT, c96 TEXT, c97 TEXT, c98 TEXT,
+ c99 TEXT, c100 TEXT, c101 TEXT, c102 TEXT, c103 TEXT, c104 TEXT, c105 TEXT,
+ c106 TEXT, c107 TEXT, c108 TEXT, c109 TEXT, c110 TEXT, c111 TEXT, c112 TEXT,
+ c113 TEXT, c114 TEXT, c115 TEXT, c116 TEXT, c117 TEXT, c118 TEXT, c119 TEXT,
+ c120 TEXT, c121 TEXT, c122 TEXT, c123 TEXT, c124 TEXT, c125 TEXT, c126 TEXT,
+ c127 TEXT, c128 TEXT, c129 TEXT, c130 TEXT, c131 TEXT, c132 TEXT, c133 TEXT,
+ c134 TEXT, c135 TEXT, c136 TEXT, c137 TEXT, c138 TEXT, c139 TEXT, c140 TEXT,
+ c141 TEXT, c142 TEXT, c143 TEXT, c144 TEXT, c145 TEXT, c146 TEXT, c147 TEXT,
+ c148 TEXT, c149 TEXT, c150 TEXT, c151 TEXT, c152 TEXT, c153 TEXT, c154 TEXT,
+ c155 TEXT, c156 TEXT, c157 TEXT, c158 TEXT, c159 TEXT, c160 TEXT, c161 TEXT,
+ c162 TEXT, c163 TEXT, c164 TEXT, c165 TEXT, c166 TEXT, c167 TEXT, c168 TEXT,
+ c169 TEXT, c170 TEXT, c171 TEXT, c172 TEXT, c173 TEXT, c174 TEXT, c175 TEXT,
+ c176 TEXT, c177 TEXT, c178 TEXT, c179 TEXT, c180 TEXT, c181 TEXT, c182 TEXT,
+ c183 TEXT, c184 TEXT, c185 TEXT, c186 TEXT, c187 TEXT, c188 TEXT, c189 TEXT,
+ c190 TEXT, c191 TEXT, c192 TEXT, c193 TEXT, c194 TEXT, c195 TEXT, c196 TEXT,
+ c197 TEXT, c198 TEXT, c199 TEXT, c200 TEXT, c201 TEXT, c202 TEXT, c203 TEXT,
+ c204 TEXT, c205 TEXT, c206 TEXT, c207 TEXT, c208 TEXT, c209 TEXT, c210 TEXT,
+ c211 TEXT, c212 TEXT, c213 TEXT, c214 TEXT, c215 TEXT, c216 TEXT, c217 TEXT,
+ c218 TEXT, c219 TEXT, c220 TEXT, c221 TEXT, c222 TEXT, c223 TEXT, c224 TEXT,
+ c225 TEXT, c226 TEXT, c227 TEXT, c228 TEXT, c229 TEXT, c230 TEXT, c231 TEXT,
+ c232 TEXT, c233 TEXT, c234 TEXT, c235 TEXT, c236 TEXT, c237 TEXT, c238 TEXT,
+ c239 TEXT, c240 TEXT, c241 TEXT, c242 TEXT, c243 TEXT, c244 TEXT, c245 TEXT,
+ c246 TEXT, c247 TEXT, c248 TEXT, c249 TEXT, c250 TEXT, c251 TEXT, c252 TEXT,
+ c253 TEXT, c254 TEXT, c255 TEXT, c256 TEXT, c257 TEXT, c258 TEXT, c259 TEXT,
+ c260 TEXT, c261 TEXT, c262 TEXT, c263 TEXT, c264 TEXT, c265 TEXT, c266 TEXT,
+ c267 TEXT, c268 TEXT, c269 TEXT, c270 TEXT, c271 TEXT, c272 TEXT, c273 TEXT,
+ c274 TEXT, c275 TEXT, c276 TEXT, c277 TEXT, c278 TEXT, c279 TEXT, c280 TEXT,
+ c281 TEXT, c282 TEXT, c283 TEXT, c284 TEXT, c285 TEXT, c286 TEXT, c287 TEXT,
+ c288 TEXT, c289 TEXT, c290 TEXT, c291 TEXT, c292 TEXT, c293 TEXT, c294 TEXT,
+ c295 TEXT, c296 TEXT, c297 TEXT, c298 TEXT, c299 TEXT, c300 TEXT, c301 TEXT,
+ c302 TEXT, c303 TEXT, c304 TEXT, c305 TEXT, c306 TEXT, c307 TEXT, c308 TEXT,
+ c309 TEXT, c310 TEXT, c311 TEXT, c312 TEXT, c313 TEXT, c314 TEXT, c315 TEXT,
+ c316 TEXT, c317 TEXT, c318 TEXT, c319 TEXT, c320 TEXT, c321 TEXT, c322 TEXT,
+ c323 TEXT, c324 TEXT, c325 TEXT, c326 TEXT, c327 TEXT, c328 TEXT, c329 TEXT,
+ c330 TEXT, c331 TEXT, c332 TEXT, c333 TEXT, c334 TEXT, c335 TEXT, c336 TEXT,
+ c337 TEXT, c338 TEXT, c339 TEXT, c340 TEXT, c341 TEXT, c342 TEXT, c343 TEXT,
+ c344 TEXT, c345 TEXT, c346 TEXT, c347 TEXT, c348 TEXT, c349 TEXT, c350 TEXT,
+ c351 TEXT, c352 TEXT, c353 TEXT, c354 TEXT, c355 TEXT, c356 TEXT, c357 TEXT,
+ c358 TEXT, c359 TEXT, c360 TEXT, c361 TEXT, c362 TEXT, c363 TEXT, c364 TEXT,
+ c365 TEXT, c366 TEXT, c367 TEXT, c368 TEXT, c369 TEXT, c370 TEXT, c371 TEXT,
+ c372 TEXT, c373 TEXT, c374 TEXT, c375 TEXT, c376 TEXT, c377 TEXT, c378 TEXT,
+ c379 TEXT, c380 TEXT, c381 TEXT, c382 TEXT, c383 TEXT, c384 TEXT, c385 TEXT,
+ c386 TEXT, c387 TEXT, c388 TEXT, c389 TEXT, c390 TEXT, c391 TEXT, c392 TEXT,
+ c393 TEXT, c394 TEXT, c395 TEXT, c396 TEXT, c397 TEXT, c398 TEXT, c399 TEXT,
+ c400 TEXT, c401 TEXT, c402 TEXT, c403 TEXT, c404 TEXT, c405 TEXT, c406 TEXT,
+ c407 TEXT, c408 TEXT, c409 TEXT, c410 TEXT, c411 TEXT, c412 TEXT, c413 TEXT,
+ c414 TEXT, c415 TEXT, c416 TEXT, c417 TEXT, c418 TEXT, c419 TEXT, c420 TEXT,
+ c421 TEXT, c422 TEXT, c423 TEXT, c424 TEXT, c425 TEXT, c426 TEXT, c427 TEXT,
+ c428 TEXT, c429 TEXT, c430 TEXT, c431 TEXT, c432 TEXT, c433 TEXT, c434 TEXT,
+ c435 TEXT, c436 TEXT, c437 TEXT, c438 TEXT, c439 TEXT, c440 TEXT, c441 TEXT,
+ c442 TEXT, c443 TEXT, c444 TEXT, c445 TEXT, c446 TEXT, c447 TEXT, c448 TEXT,
+ c449 TEXT, c450 TEXT, c451 TEXT, c452 TEXT, c453 TEXT, c454 TEXT, c455 TEXT,
+ c456 TEXT, c457 TEXT, c458 TEXT, c459 TEXT, c460 TEXT, c461 TEXT, c462 TEXT,
+ c463 TEXT, c464 TEXT, c465 TEXT, c466 TEXT, c467 TEXT, c468 TEXT, c469 TEXT,
+ c470 TEXT, c471 TEXT, c472 TEXT, c473 TEXT, c474 TEXT, c475 TEXT, c476 TEXT,
+ c477 TEXT, c478 TEXT, c479 TEXT, c480 TEXT, c481 TEXT, c482 TEXT, c483 TEXT,
+ c484 TEXT, c485 TEXT, c486 TEXT, c487 TEXT, c488 TEXT, c489 TEXT, c490 TEXT,
+ c491 TEXT, c492 TEXT, c493 TEXT, c494 TEXT, c495 TEXT, c496 TEXT, c497 TEXT,
+ c498 TEXT, c499 TEXT, c500 TEXT, c501 TEXT, c502 TEXT, c503 TEXT, c504 TEXT,
+ c505 TEXT, c506 TEXT, c507 TEXT, c508 TEXT, c509 TEXT, c510 TEXT, c511 TEXT,
+ c512 TEXT, c513 TEXT, c514 TEXT, c515 TEXT, c516 TEXT, c517 TEXT, c518 TEXT,
+ c519 TEXT, c520 TEXT, c521 TEXT, c522 TEXT, c523 TEXT, c524 TEXT, c525 TEXT,
+ c526 TEXT, c527 TEXT, c528 TEXT, c529 TEXT, c530 TEXT, c531 TEXT, c532 TEXT,
+ c533 TEXT, c534 TEXT, c535 TEXT, c536 TEXT, c537 TEXT, c538 TEXT, c539 TEXT,
+ c540 TEXT, c541 TEXT, c542 TEXT, c543 TEXT, c544 TEXT, c545 TEXT, c546 TEXT,
+ c547 TEXT, c548 TEXT, c549 TEXT, c550 TEXT, c551 TEXT, c552 TEXT, c553 TEXT,
+ c554 TEXT, c555 TEXT, c556 TEXT, c557 TEXT, c558 TEXT, c559 TEXT, c560 TEXT,
+ c561 TEXT, c562 TEXT, c563 TEXT, c564 TEXT, c565 TEXT, c566 TEXT, c567 TEXT,
+ c568 TEXT, c569 TEXT, c570 TEXT, c571 TEXT, c572 TEXT, c573 TEXT, c574 TEXT,
+ c575 TEXT, c576 TEXT, c577 TEXT, c578 TEXT, c579 TEXT, c580 TEXT, c581 TEXT,
+ c582 TEXT, c583 TEXT, c584 TEXT, c585 TEXT, c586 TEXT, c587 TEXT, c588 TEXT,
+ c589 TEXT, c590 TEXT, c591 TEXT, c592 TEXT, c593 TEXT, c594 TEXT, c595 TEXT,
+ c596 TEXT, c597 TEXT, c598 TEXT, c599 TEXT, c600 TEXT, c601 TEXT, c602 TEXT,
+ c603 TEXT, c604 TEXT, c605 TEXT, c606 TEXT, c607 TEXT, c608 TEXT, c609 TEXT,
+ c610 TEXT, c611 TEXT, c612 TEXT, c613 TEXT, c614 TEXT, c615 TEXT, c616 TEXT,
+ c617 TEXT, c618 TEXT, c619 TEXT, c620 TEXT, c621 TEXT, c622 TEXT, c623 TEXT,
+ c624 TEXT, c625 TEXT, c626 TEXT, c627 TEXT, c628 TEXT, c629 TEXT, c630 TEXT,
+ c631 TEXT, c632 TEXT, c633 TEXT, c634 TEXT, c635 TEXT, c636 TEXT, c637 TEXT,
+ c638 TEXT, c639 TEXT, c640 TEXT, c641 TEXT, c642 TEXT, c643 TEXT, c644 TEXT,
+ c645 TEXT, c646 TEXT, c647 TEXT, c648 TEXT, c649 TEXT, c650 TEXT, c651 TEXT,
+ c652 TEXT, c653 TEXT, c654 TEXT, c655 TEXT, c656 TEXT, c657 TEXT, c658 TEXT,
+ c659 TEXT, c660 TEXT, c661 TEXT, c662 TEXT, c663 TEXT, c664 TEXT, c665 TEXT,
+ c666 TEXT, c667 TEXT, c668 TEXT, c669 TEXT, c670 TEXT, c671 TEXT, c672 TEXT,
+ c673 TEXT, c674 TEXT, c675 TEXT, c676 TEXT, c677 TEXT, c678 TEXT, c679 TEXT,
+ c680 TEXT, c681 TEXT, c682 TEXT, c683 TEXT, c684 TEXT, c685 TEXT, c686 TEXT,
+ c687 TEXT, c688 TEXT, c689 TEXT, c690 TEXT, c691 TEXT, c692 TEXT, c693 TEXT,
+ c694 TEXT, c695 TEXT, c696 TEXT, c697 TEXT, c698 TEXT, c699 TEXT, c700 TEXT,
+ c701 TEXT, c702 TEXT, c703 TEXT, c704 TEXT, c705 TEXT, c706 TEXT, c707 TEXT,
+ c708 TEXT, c709 TEXT, c710 TEXT, c711 TEXT, c712 TEXT, c713 TEXT, c714 TEXT,
+ c715 TEXT, c716 TEXT, c717 TEXT, c718 TEXT, c719 TEXT, c720 TEXT, c721 TEXT,
+ c722 TEXT, c723 TEXT, c724 TEXT, c725 TEXT, c726 TEXT, c727 TEXT, c728 TEXT,
+ c729 TEXT, c730 TEXT, c731 TEXT, c732 TEXT, c733 TEXT, c734 TEXT, c735 TEXT,
+ c736 TEXT, c737 TEXT, c738 TEXT, c739 TEXT, c740 TEXT, c741 TEXT, c742 TEXT,
+ c743 TEXT, c744 TEXT, c745 TEXT, c746 TEXT, c747 TEXT, c748 TEXT, c749 TEXT,
+ c750 TEXT, c751 TEXT, c752 TEXT, c753 TEXT, c754 TEXT, c755 TEXT, c756 TEXT,
+ c757 TEXT, c758 TEXT, c759 TEXT, c760 TEXT, c761 TEXT, c762 TEXT, c763 TEXT,
+ c764 TEXT, c765 TEXT, c766 TEXT, c767 TEXT, c768 TEXT, c769 TEXT, c770 TEXT,
+ c771 TEXT
+) ENGINE=INNODB;
+DROP TABLE t1;
+--error ER_TOO_BIG_ROWSIZE
+CREATE TABLE t1 (
+ c1 TEXT, c2 TEXT, c3 TEXT, c4 TEXT, c5 TEXT, c6 TEXT, c7 TEXT,
+ c8 TEXT, c9 TEXT, c10 TEXT, c11 TEXT, c12 TEXT, c13 TEXT, c14 TEXT,
+ c15 TEXT, c16 TEXT, c17 TEXT, c18 TEXT, c19 TEXT, c20 TEXT, c21 TEXT,
+ c22 TEXT, c23 TEXT, c24 TEXT, c25 TEXT, c26 TEXT, c27 TEXT, c28 TEXT,
+ c29 TEXT, c30 TEXT, c31 TEXT, c32 TEXT, c33 TEXT, c34 TEXT, c35 TEXT,
+ c36 TEXT, c37 TEXT, c38 TEXT, c39 TEXT, c40 TEXT, c41 TEXT, c42 TEXT,
+ c43 TEXT, c44 TEXT, c45 TEXT, c46 TEXT, c47 TEXT, c48 TEXT, c49 TEXT,
+ c50 TEXT, c51 TEXT, c52 TEXT, c53 TEXT, c54 TEXT, c55 TEXT, c56 TEXT,
+ c57 TEXT, c58 TEXT, c59 TEXT, c60 TEXT, c61 TEXT, c62 TEXT, c63 TEXT,
+ c64 TEXT, c65 TEXT, c66 TEXT, c67 TEXT, c68 TEXT, c69 TEXT, c70 TEXT,
+ c71 TEXT, c72 TEXT, c73 TEXT, c74 TEXT, c75 TEXT, c76 TEXT, c77 TEXT,
+ c78 TEXT, c79 TEXT, c80 TEXT, c81 TEXT, c82 TEXT, c83 TEXT, c84 TEXT,
+ c85 TEXT, c86 TEXT, c87 TEXT, c88 TEXT, c89 TEXT, c90 TEXT, c91 TEXT,
+ c92 TEXT, c93 TEXT, c94 TEXT, c95 TEXT, c96 TEXT, c97 TEXT, c98 TEXT,
+ c99 TEXT, c100 TEXT, c101 TEXT, c102 TEXT, c103 TEXT, c104 TEXT, c105 TEXT,
+ c106 TEXT, c107 TEXT, c108 TEXT, c109 TEXT, c110 TEXT, c111 TEXT, c112 TEXT,
+ c113 TEXT, c114 TEXT, c115 TEXT, c116 TEXT, c117 TEXT, c118 TEXT, c119 TEXT,
+ c120 TEXT, c121 TEXT, c122 TEXT, c123 TEXT, c124 TEXT, c125 TEXT, c126 TEXT,
+ c127 TEXT, c128 TEXT, c129 TEXT, c130 TEXT, c131 TEXT, c132 TEXT, c133 TEXT,
+ c134 TEXT, c135 TEXT, c136 TEXT, c137 TEXT, c138 TEXT, c139 TEXT, c140 TEXT,
+ c141 TEXT, c142 TEXT, c143 TEXT, c144 TEXT, c145 TEXT, c146 TEXT, c147 TEXT,
+ c148 TEXT, c149 TEXT, c150 TEXT, c151 TEXT, c152 TEXT, c153 TEXT, c154 TEXT,
+ c155 TEXT, c156 TEXT, c157 TEXT, c158 TEXT, c159 TEXT, c160 TEXT, c161 TEXT,
+ c162 TEXT, c163 TEXT, c164 TEXT, c165 TEXT, c166 TEXT, c167 TEXT, c168 TEXT,
+ c169 TEXT, c170 TEXT, c171 TEXT, c172 TEXT, c173 TEXT, c174 TEXT, c175 TEXT,
+ c176 TEXT, c177 TEXT, c178 TEXT, c179 TEXT, c180 TEXT, c181 TEXT, c182 TEXT,
+ c183 TEXT, c184 TEXT, c185 TEXT, c186 TEXT, c187 TEXT, c188 TEXT, c189 TEXT,
+ c190 TEXT, c191 TEXT, c192 TEXT, c193 TEXT, c194 TEXT, c195 TEXT, c196 TEXT,
+ c197 TEXT, c198 TEXT, c199 TEXT, c200 TEXT, c201 TEXT, c202 TEXT, c203 TEXT,
+ c204 TEXT, c205 TEXT, c206 TEXT, c207 TEXT, c208 TEXT, c209 TEXT, c210 TEXT,
+ c211 TEXT, c212 TEXT, c213 TEXT, c214 TEXT, c215 TEXT, c216 TEXT, c217 TEXT,
+ c218 TEXT, c219 TEXT, c220 TEXT, c221 TEXT, c222 TEXT, c223 TEXT, c224 TEXT,
+ c225 TEXT, c226 TEXT, c227 TEXT, c228 TEXT, c229 TEXT, c230 TEXT, c231 TEXT,
+ c232 TEXT, c233 TEXT, c234 TEXT, c235 TEXT, c236 TEXT, c237 TEXT, c238 TEXT,
+ c239 TEXT, c240 TEXT, c241 TEXT, c242 TEXT, c243 TEXT, c244 TEXT, c245 TEXT,
+ c246 TEXT, c247 TEXT, c248 TEXT, c249 TEXT, c250 TEXT, c251 TEXT, c252 TEXT,
+ c253 TEXT, c254 TEXT, c255 TEXT, c256 TEXT, c257 TEXT, c258 TEXT, c259 TEXT,
+ c260 TEXT, c261 TEXT, c262 TEXT, c263 TEXT, c264 TEXT, c265 TEXT, c266 TEXT,
+ c267 TEXT, c268 TEXT, c269 TEXT, c270 TEXT, c271 TEXT, c272 TEXT, c273 TEXT,
+ c274 TEXT, c275 TEXT, c276 TEXT, c277 TEXT, c278 TEXT, c279 TEXT, c280 TEXT,
+ c281 TEXT, c282 TEXT, c283 TEXT, c284 TEXT, c285 TEXT, c286 TEXT, c287 TEXT,
+ c288 TEXT, c289 TEXT, c290 TEXT, c291 TEXT, c292 TEXT, c293 TEXT, c294 TEXT,
+ c295 TEXT, c296 TEXT, c297 TEXT, c298 TEXT, c299 TEXT, c300 TEXT, c301 TEXT,
+ c302 TEXT, c303 TEXT, c304 TEXT, c305 TEXT, c306 TEXT, c307 TEXT, c308 TEXT,
+ c309 TEXT, c310 TEXT, c311 TEXT, c312 TEXT, c313 TEXT, c314 TEXT, c315 TEXT,
+ c316 TEXT, c317 TEXT, c318 TEXT, c319 TEXT, c320 TEXT, c321 TEXT, c322 TEXT,
+ c323 TEXT, c324 TEXT, c325 TEXT, c326 TEXT, c327 TEXT, c328 TEXT, c329 TEXT,
+ c330 TEXT, c331 TEXT, c332 TEXT, c333 TEXT, c334 TEXT, c335 TEXT, c336 TEXT,
+ c337 TEXT, c338 TEXT, c339 TEXT, c340 TEXT, c341 TEXT, c342 TEXT, c343 TEXT,
+ c344 TEXT, c345 TEXT, c346 TEXT, c347 TEXT, c348 TEXT, c349 TEXT, c350 TEXT,
+ c351 TEXT, c352 TEXT, c353 TEXT, c354 TEXT, c355 TEXT, c356 TEXT, c357 TEXT,
+ c358 TEXT, c359 TEXT, c360 TEXT, c361 TEXT, c362 TEXT, c363 TEXT, c364 TEXT,
+ c365 TEXT, c366 TEXT, c367 TEXT, c368 TEXT, c369 TEXT, c370 TEXT, c371 TEXT,
+ c372 TEXT, c373 TEXT, c374 TEXT, c375 TEXT, c376 TEXT, c377 TEXT, c378 TEXT,
+ c379 TEXT, c380 TEXT, c381 TEXT, c382 TEXT, c383 TEXT, c384 TEXT, c385 TEXT,
+ c386 TEXT, c387 TEXT, c388 TEXT, c389 TEXT, c390 TEXT, c391 TEXT, c392 TEXT,
+ c393 TEXT, c394 TEXT, c395 TEXT, c396 TEXT, c397 TEXT, c398 TEXT, c399 TEXT,
+ c400 TEXT, c401 TEXT, c402 TEXT, c403 TEXT, c404 TEXT, c405 TEXT, c406 TEXT,
+ c407 TEXT, c408 TEXT, c409 TEXT, c410 TEXT, c411 TEXT, c412 TEXT, c413 TEXT,
+ c414 TEXT, c415 TEXT, c416 TEXT, c417 TEXT, c418 TEXT, c419 TEXT, c420 TEXT,
+ c421 TEXT, c422 TEXT, c423 TEXT, c424 TEXT, c425 TEXT, c426 TEXT, c427 TEXT,
+ c428 TEXT, c429 TEXT, c430 TEXT, c431 TEXT, c432 TEXT, c433 TEXT, c434 TEXT,
+ c435 TEXT, c436 TEXT, c437 TEXT, c438 TEXT, c439 TEXT, c440 TEXT, c441 TEXT,
+ c442 TEXT, c443 TEXT, c444 TEXT, c445 TEXT, c446 TEXT, c447 TEXT, c448 TEXT,
+ c449 TEXT, c450 TEXT, c451 TEXT, c452 TEXT, c453 TEXT, c454 TEXT, c455 TEXT,
+ c456 TEXT, c457 TEXT, c458 TEXT, c459 TEXT, c460 TEXT, c461 TEXT, c462 TEXT,
+ c463 TEXT, c464 TEXT, c465 TEXT, c466 TEXT, c467 TEXT, c468 TEXT, c469 TEXT,
+ c470 TEXT, c471 TEXT, c472 TEXT, c473 TEXT, c474 TEXT, c475 TEXT, c476 TEXT,
+ c477 TEXT, c478 TEXT, c479 TEXT, c480 TEXT, c481 TEXT, c482 TEXT, c483 TEXT,
+ c484 TEXT, c485 TEXT, c486 TEXT, c487 TEXT, c488 TEXT, c489 TEXT, c490 TEXT,
+ c491 TEXT, c492 TEXT, c493 TEXT, c494 TEXT, c495 TEXT, c496 TEXT, c497 TEXT,
+ c498 TEXT, c499 TEXT, c500 TEXT, c501 TEXT, c502 TEXT, c503 TEXT, c504 TEXT,
+ c505 TEXT, c506 TEXT, c507 TEXT, c508 TEXT, c509 TEXT, c510 TEXT, c511 TEXT,
+ c512 TEXT, c513 TEXT, c514 TEXT, c515 TEXT, c516 TEXT, c517 TEXT, c518 TEXT,
+ c519 TEXT, c520 TEXT, c521 TEXT, c522 TEXT, c523 TEXT, c524 TEXT, c525 TEXT,
+ c526 TEXT, c527 TEXT, c528 TEXT, c529 TEXT, c530 TEXT, c531 TEXT, c532 TEXT,
+ c533 TEXT, c534 TEXT, c535 TEXT, c536 TEXT, c537 TEXT, c538 TEXT, c539 TEXT,
+ c540 TEXT, c541 TEXT, c542 TEXT, c543 TEXT, c544 TEXT, c545 TEXT, c546 TEXT,
+ c547 TEXT, c548 TEXT, c549 TEXT, c550 TEXT, c551 TEXT, c552 TEXT, c553 TEXT,
+ c554 TEXT, c555 TEXT, c556 TEXT, c557 TEXT, c558 TEXT, c559 TEXT, c560 TEXT,
+ c561 TEXT, c562 TEXT, c563 TEXT, c564 TEXT, c565 TEXT, c566 TEXT, c567 TEXT,
+ c568 TEXT, c569 TEXT, c570 TEXT, c571 TEXT, c572 TEXT, c573 TEXT, c574 TEXT,
+ c575 TEXT, c576 TEXT, c577 TEXT, c578 TEXT, c579 TEXT, c580 TEXT, c581 TEXT,
+ c582 TEXT, c583 TEXT, c584 TEXT, c585 TEXT, c586 TEXT, c587 TEXT, c588 TEXT,
+ c589 TEXT, c590 TEXT, c591 TEXT, c592 TEXT, c593 TEXT, c594 TEXT, c595 TEXT,
+ c596 TEXT, c597 TEXT, c598 TEXT, c599 TEXT, c600 TEXT, c601 TEXT, c602 TEXT,
+ c603 TEXT, c604 TEXT, c605 TEXT, c606 TEXT, c607 TEXT, c608 TEXT, c609 TEXT,
+ c610 TEXT, c611 TEXT, c612 TEXT, c613 TEXT, c614 TEXT, c615 TEXT, c616 TEXT,
+ c617 TEXT, c618 TEXT, c619 TEXT, c620 TEXT, c621 TEXT, c622 TEXT, c623 TEXT,
+ c624 TEXT, c625 TEXT, c626 TEXT, c627 TEXT, c628 TEXT, c629 TEXT, c630 TEXT,
+ c631 TEXT, c632 TEXT, c633 TEXT, c634 TEXT, c635 TEXT, c636 TEXT, c637 TEXT,
+ c638 TEXT, c639 TEXT, c640 TEXT, c641 TEXT, c642 TEXT, c643 TEXT, c644 TEXT,
+ c645 TEXT, c646 TEXT, c647 TEXT, c648 TEXT, c649 TEXT, c650 TEXT, c651 TEXT,
+ c652 TEXT, c653 TEXT, c654 TEXT, c655 TEXT, c656 TEXT, c657 TEXT, c658 TEXT,
+ c659 TEXT, c660 TEXT, c661 TEXT, c662 TEXT, c663 TEXT, c664 TEXT, c665 TEXT,
+ c666 TEXT, c667 TEXT, c668 TEXT, c669 TEXT, c670 TEXT, c671 TEXT, c672 TEXT,
+ c673 TEXT, c674 TEXT, c675 TEXT, c676 TEXT, c677 TEXT, c678 TEXT, c679 TEXT,
+ c680 TEXT, c681 TEXT, c682 TEXT, c683 TEXT, c684 TEXT, c685 TEXT, c686 TEXT,
+ c687 TEXT, c688 TEXT, c689 TEXT, c690 TEXT, c691 TEXT, c692 TEXT, c693 TEXT,
+ c694 TEXT, c695 TEXT, c696 TEXT, c697 TEXT, c698 TEXT, c699 TEXT, c700 TEXT,
+ c701 TEXT, c702 TEXT, c703 TEXT, c704 TEXT, c705 TEXT, c706 TEXT, c707 TEXT,
+ c708 TEXT, c709 TEXT, c710 TEXT, c711 TEXT, c712 TEXT, c713 TEXT, c714 TEXT,
+ c715 TEXT, c716 TEXT, c717 TEXT, c718 TEXT, c719 TEXT, c720 TEXT, c721 TEXT,
+ c722 TEXT, c723 TEXT, c724 TEXT, c725 TEXT, c726 TEXT, c727 TEXT, c728 TEXT,
+ c729 TEXT, c730 TEXT, c731 TEXT, c732 TEXT, c733 TEXT, c734 TEXT, c735 TEXT,
+ c736 TEXT, c737 TEXT, c738 TEXT, c739 TEXT, c740 TEXT, c741 TEXT, c742 TEXT,
+ c743 TEXT, c744 TEXT, c745 TEXT, c746 TEXT, c747 TEXT, c748 TEXT, c749 TEXT,
+ c750 TEXT, c751 TEXT, c752 TEXT, c753 TEXT, c754 TEXT, c755 TEXT, c756 TEXT,
+ c757 TEXT, c758 TEXT, c759 TEXT, c760 TEXT, c761 TEXT, c762 TEXT, c763 TEXT,
+ c764 TEXT, c765 TEXT, c766 TEXT, c767 TEXT, c768 TEXT, c769 TEXT, c770 TEXT,
+ c771 TEXT, c772 TEXT
+) ENGINE=INNODB;
+} }
+
+
+if ($row_format == 'dynamic') { if ($page_size == 65536) {
+CREATE TABLE t1 (
+ c1 TEXT, c2 TEXT, c3 TEXT, c4 TEXT, c5 TEXT, c6 TEXT, c7 TEXT,
+ c8 TEXT, c9 TEXT, c10 TEXT, c11 TEXT, c12 TEXT, c13 TEXT, c14 TEXT,
+ c15 TEXT, c16 TEXT, c17 TEXT, c18 TEXT, c19 TEXT, c20 TEXT, c21 TEXT,
+ c22 TEXT, c23 TEXT, c24 TEXT, c25 TEXT, c26 TEXT, c27 TEXT, c28 TEXT,
+ c29 TEXT, c30 TEXT, c31 TEXT, c32 TEXT, c33 TEXT, c34 TEXT, c35 TEXT,
+ c36 TEXT, c37 TEXT, c38 TEXT, c39 TEXT, c40 TEXT, c41 TEXT, c42 TEXT,
+ c43 TEXT, c44 TEXT, c45 TEXT, c46 TEXT, c47 TEXT, c48 TEXT, c49 TEXT,
+ c50 TEXT, c51 TEXT, c52 TEXT, c53 TEXT, c54 TEXT, c55 TEXT, c56 TEXT,
+ c57 TEXT, c58 TEXT, c59 TEXT, c60 TEXT, c61 TEXT, c62 TEXT, c63 TEXT,
+ c64 TEXT, c65 TEXT, c66 TEXT, c67 TEXT, c68 TEXT, c69 TEXT, c70 TEXT,
+ c71 TEXT, c72 TEXT, c73 TEXT, c74 TEXT, c75 TEXT, c76 TEXT, c77 TEXT,
+ c78 TEXT, c79 TEXT, c80 TEXT, c81 TEXT, c82 TEXT, c83 TEXT, c84 TEXT,
+ c85 TEXT, c86 TEXT, c87 TEXT, c88 TEXT, c89 TEXT, c90 TEXT, c91 TEXT,
+ c92 TEXT, c93 TEXT, c94 TEXT, c95 TEXT, c96 TEXT, c97 TEXT, c98 TEXT,
+ c99 TEXT, c100 TEXT, c101 TEXT, c102 TEXT, c103 TEXT, c104 TEXT, c105 TEXT,
+ c106 TEXT, c107 TEXT, c108 TEXT, c109 TEXT, c110 TEXT, c111 TEXT, c112 TEXT,
+ c113 TEXT, c114 TEXT, c115 TEXT, c116 TEXT, c117 TEXT, c118 TEXT, c119 TEXT,
+ c120 TEXT, c121 TEXT, c122 TEXT, c123 TEXT, c124 TEXT, c125 TEXT, c126 TEXT,
+ c127 TEXT, c128 TEXT, c129 TEXT, c130 TEXT, c131 TEXT, c132 TEXT, c133 TEXT,
+ c134 TEXT, c135 TEXT, c136 TEXT, c137 TEXT, c138 TEXT, c139 TEXT, c140 TEXT,
+ c141 TEXT, c142 TEXT, c143 TEXT, c144 TEXT, c145 TEXT, c146 TEXT, c147 TEXT,
+ c148 TEXT, c149 TEXT, c150 TEXT, c151 TEXT, c152 TEXT, c153 TEXT, c154 TEXT,
+ c155 TEXT, c156 TEXT, c157 TEXT, c158 TEXT, c159 TEXT, c160 TEXT, c161 TEXT,
+ c162 TEXT, c163 TEXT, c164 TEXT, c165 TEXT, c166 TEXT, c167 TEXT, c168 TEXT,
+ c169 TEXT, c170 TEXT, c171 TEXT, c172 TEXT, c173 TEXT, c174 TEXT, c175 TEXT,
+ c176 TEXT, c177 TEXT, c178 TEXT, c179 TEXT, c180 TEXT, c181 TEXT, c182 TEXT,
+ c183 TEXT, c184 TEXT, c185 TEXT, c186 TEXT, c187 TEXT, c188 TEXT, c189 TEXT,
+ c190 TEXT, c191 TEXT, c192 TEXT, c193 TEXT, c194 TEXT, c195 TEXT, c196 TEXT,
+ c197 TEXT, c198 TEXT, c199 TEXT, c200 TEXT, c201 TEXT, c202 TEXT, c203 TEXT,
+ c204 TEXT, c205 TEXT, c206 TEXT, c207 TEXT, c208 TEXT, c209 TEXT, c210 TEXT,
+ c211 TEXT, c212 TEXT, c213 TEXT, c214 TEXT, c215 TEXT, c216 TEXT, c217 TEXT,
+ c218 TEXT, c219 TEXT, c220 TEXT, c221 TEXT, c222 TEXT, c223 TEXT, c224 TEXT,
+ c225 TEXT, c226 TEXT, c227 TEXT, c228 TEXT, c229 TEXT, c230 TEXT, c231 TEXT,
+ c232 TEXT, c233 TEXT, c234 TEXT, c235 TEXT, c236 TEXT, c237 TEXT, c238 TEXT,
+ c239 TEXT, c240 TEXT, c241 TEXT, c242 TEXT, c243 TEXT, c244 TEXT, c245 TEXT,
+ c246 TEXT, c247 TEXT, c248 TEXT, c249 TEXT, c250 TEXT, c251 TEXT, c252 TEXT,
+ c253 TEXT, c254 TEXT, c255 TEXT, c256 TEXT, c257 TEXT, c258 TEXT, c259 TEXT,
+ c260 TEXT, c261 TEXT, c262 TEXT, c263 TEXT, c264 TEXT, c265 TEXT, c266 TEXT,
+ c267 TEXT, c268 TEXT, c269 TEXT, c270 TEXT, c271 TEXT, c272 TEXT, c273 TEXT,
+ c274 TEXT, c275 TEXT, c276 TEXT, c277 TEXT, c278 TEXT, c279 TEXT, c280 TEXT,
+ c281 TEXT, c282 TEXT, c283 TEXT, c284 TEXT, c285 TEXT, c286 TEXT, c287 TEXT,
+ c288 TEXT, c289 TEXT, c290 TEXT, c291 TEXT, c292 TEXT, c293 TEXT, c294 TEXT,
+ c295 TEXT, c296 TEXT, c297 TEXT, c298 TEXT, c299 TEXT, c300 TEXT, c301 TEXT,
+ c302 TEXT, c303 TEXT, c304 TEXT, c305 TEXT, c306 TEXT, c307 TEXT, c308 TEXT,
+ c309 TEXT, c310 TEXT, c311 TEXT, c312 TEXT, c313 TEXT, c314 TEXT, c315 TEXT,
+ c316 TEXT, c317 TEXT, c318 TEXT, c319 TEXT, c320 TEXT, c321 TEXT, c322 TEXT,
+ c323 TEXT, c324 TEXT, c325 TEXT, c326 TEXT, c327 TEXT, c328 TEXT, c329 TEXT,
+ c330 TEXT, c331 TEXT, c332 TEXT, c333 TEXT, c334 TEXT, c335 TEXT, c336 TEXT,
+ c337 TEXT, c338 TEXT, c339 TEXT, c340 TEXT, c341 TEXT, c342 TEXT, c343 TEXT,
+ c344 TEXT, c345 TEXT, c346 TEXT, c347 TEXT, c348 TEXT, c349 TEXT, c350 TEXT,
+ c351 TEXT, c352 TEXT, c353 TEXT, c354 TEXT, c355 TEXT, c356 TEXT, c357 TEXT,
+ c358 TEXT, c359 TEXT, c360 TEXT, c361 TEXT, c362 TEXT, c363 TEXT, c364 TEXT,
+ c365 TEXT, c366 TEXT, c367 TEXT, c368 TEXT, c369 TEXT, c370 TEXT, c371 TEXT,
+ c372 TEXT, c373 TEXT, c374 TEXT, c375 TEXT, c376 TEXT, c377 TEXT, c378 TEXT,
+ c379 TEXT, c380 TEXT, c381 TEXT, c382 TEXT, c383 TEXT, c384 TEXT, c385 TEXT,
+ c386 TEXT, c387 TEXT, c388 TEXT, c389 TEXT, c390 TEXT, c391 TEXT, c392 TEXT,
+ c393 TEXT, c394 TEXT, c395 TEXT, c396 TEXT, c397 TEXT, c398 TEXT, c399 TEXT,
+ c400 TEXT, c401 TEXT, c402 TEXT, c403 TEXT, c404 TEXT, c405 TEXT, c406 TEXT,
+ c407 TEXT, c408 TEXT, c409 TEXT, c410 TEXT, c411 TEXT, c412 TEXT, c413 TEXT,
+ c414 TEXT, c415 TEXT, c416 TEXT, c417 TEXT, c418 TEXT, c419 TEXT, c420 TEXT,
+ c421 TEXT, c422 TEXT, c423 TEXT, c424 TEXT, c425 TEXT, c426 TEXT, c427 TEXT,
+ c428 TEXT, c429 TEXT, c430 TEXT, c431 TEXT, c432 TEXT, c433 TEXT, c434 TEXT,
+ c435 TEXT, c436 TEXT, c437 TEXT, c438 TEXT, c439 TEXT, c440 TEXT, c441 TEXT,
+ c442 TEXT, c443 TEXT, c444 TEXT, c445 TEXT, c446 TEXT, c447 TEXT, c448 TEXT,
+ c449 TEXT, c450 TEXT, c451 TEXT, c452 TEXT, c453 TEXT, c454 TEXT, c455 TEXT,
+ c456 TEXT, c457 TEXT, c458 TEXT, c459 TEXT, c460 TEXT, c461 TEXT, c462 TEXT,
+ c463 TEXT, c464 TEXT, c465 TEXT, c466 TEXT, c467 TEXT, c468 TEXT, c469 TEXT,
+ c470 TEXT, c471 TEXT, c472 TEXT, c473 TEXT, c474 TEXT, c475 TEXT, c476 TEXT,
+ c477 TEXT, c478 TEXT, c479 TEXT, c480 TEXT, c481 TEXT, c482 TEXT, c483 TEXT,
+ c484 TEXT, c485 TEXT, c486 TEXT, c487 TEXT, c488 TEXT, c489 TEXT, c490 TEXT,
+ c491 TEXT, c492 TEXT, c493 TEXT, c494 TEXT, c495 TEXT, c496 TEXT, c497 TEXT,
+ c498 TEXT, c499 TEXT, c500 TEXT, c501 TEXT, c502 TEXT, c503 TEXT, c504 TEXT,
+ c505 TEXT, c506 TEXT, c507 TEXT, c508 TEXT, c509 TEXT, c510 TEXT, c511 TEXT,
+ c512 TEXT, c513 TEXT, c514 TEXT, c515 TEXT, c516 TEXT, c517 TEXT, c518 TEXT,
+ c519 TEXT, c520 TEXT, c521 TEXT, c522 TEXT, c523 TEXT, c524 TEXT, c525 TEXT,
+ c526 TEXT, c527 TEXT, c528 TEXT, c529 TEXT, c530 TEXT, c531 TEXT, c532 TEXT,
+ c533 TEXT, c534 TEXT, c535 TEXT, c536 TEXT, c537 TEXT, c538 TEXT, c539 TEXT,
+ c540 TEXT, c541 TEXT, c542 TEXT, c543 TEXT, c544 TEXT, c545 TEXT, c546 TEXT,
+ c547 TEXT, c548 TEXT, c549 TEXT, c550 TEXT, c551 TEXT, c552 TEXT, c553 TEXT,
+ c554 TEXT, c555 TEXT, c556 TEXT, c557 TEXT, c558 TEXT, c559 TEXT, c560 TEXT,
+ c561 TEXT, c562 TEXT, c563 TEXT, c564 TEXT, c565 TEXT, c566 TEXT, c567 TEXT,
+ c568 TEXT, c569 TEXT, c570 TEXT, c571 TEXT, c572 TEXT, c573 TEXT, c574 TEXT,
+ c575 TEXT, c576 TEXT, c577 TEXT, c578 TEXT, c579 TEXT, c580 TEXT, c581 TEXT,
+ c582 TEXT, c583 TEXT, c584 TEXT, c585 TEXT, c586 TEXT, c587 TEXT, c588 TEXT,
+ c589 TEXT, c590 TEXT, c591 TEXT, c592 TEXT, c593 TEXT, c594 TEXT, c595 TEXT,
+ c596 TEXT, c597 TEXT, c598 TEXT, c599 TEXT, c600 TEXT, c601 TEXT, c602 TEXT,
+ c603 TEXT, c604 TEXT, c605 TEXT, c606 TEXT, c607 TEXT, c608 TEXT, c609 TEXT,
+ c610 TEXT, c611 TEXT, c612 TEXT, c613 TEXT, c614 TEXT, c615 TEXT, c616 TEXT,
+ c617 TEXT, c618 TEXT, c619 TEXT, c620 TEXT, c621 TEXT, c622 TEXT, c623 TEXT,
+ c624 TEXT, c625 TEXT, c626 TEXT, c627 TEXT, c628 TEXT, c629 TEXT, c630 TEXT,
+ c631 TEXT, c632 TEXT, c633 TEXT, c634 TEXT, c635 TEXT, c636 TEXT, c637 TEXT,
+ c638 TEXT, c639 TEXT, c640 TEXT, c641 TEXT, c642 TEXT, c643 TEXT, c644 TEXT,
+ c645 TEXT, c646 TEXT, c647 TEXT, c648 TEXT, c649 TEXT, c650 TEXT, c651 TEXT,
+ c652 TEXT, c653 TEXT, c654 TEXT, c655 TEXT, c656 TEXT, c657 TEXT, c658 TEXT,
+ c659 TEXT, c660 TEXT, c661 TEXT, c662 TEXT, c663 TEXT, c664 TEXT, c665 TEXT,
+ c666 TEXT, c667 TEXT, c668 TEXT, c669 TEXT, c670 TEXT, c671 TEXT, c672 TEXT,
+ c673 TEXT, c674 TEXT, c675 TEXT, c676 TEXT, c677 TEXT, c678 TEXT, c679 TEXT,
+ c680 TEXT, c681 TEXT, c682 TEXT, c683 TEXT, c684 TEXT, c685 TEXT, c686 TEXT,
+ c687 TEXT, c688 TEXT, c689 TEXT, c690 TEXT, c691 TEXT, c692 TEXT, c693 TEXT,
+ c694 TEXT, c695 TEXT, c696 TEXT, c697 TEXT, c698 TEXT, c699 TEXT, c700 TEXT,
+ c701 TEXT, c702 TEXT, c703 TEXT, c704 TEXT, c705 TEXT, c706 TEXT, c707 TEXT,
+ c708 TEXT, c709 TEXT, c710 TEXT, c711 TEXT, c712 TEXT, c713 TEXT, c714 TEXT,
+ c715 TEXT, c716 TEXT, c717 TEXT, c718 TEXT, c719 TEXT, c720 TEXT, c721 TEXT,
+ c722 TEXT, c723 TEXT, c724 TEXT, c725 TEXT, c726 TEXT, c727 TEXT, c728 TEXT,
+ c729 TEXT, c730 TEXT, c731 TEXT, c732 TEXT, c733 TEXT, c734 TEXT, c735 TEXT,
+ c736 TEXT, c737 TEXT, c738 TEXT, c739 TEXT, c740 TEXT, c741 TEXT, c742 TEXT,
+ c743 TEXT, c744 TEXT, c745 TEXT, c746 TEXT, c747 TEXT, c748 TEXT, c749 TEXT,
+ c750 TEXT, c751 TEXT, c752 TEXT, c753 TEXT, c754 TEXT, c755 TEXT, c756 TEXT,
+ c757 TEXT, c758 TEXT, c759 TEXT, c760 TEXT, c761 TEXT, c762 TEXT, c763 TEXT,
+ c764 TEXT, c765 TEXT, c766 TEXT, c767 TEXT, c768 TEXT, c769 TEXT, c770 TEXT,
+ c771 TEXT, c772 TEXT, c773 TEXT, c774 TEXT, c775 TEXT, c776 TEXT, c777 TEXT,
+ c778 TEXT, c779 TEXT, c780 TEXT, c781 TEXT, c782 TEXT, c783 TEXT, c784 TEXT,
+ c785 TEXT, c786 TEXT, c787 TEXT, c788 TEXT, c789 TEXT, c790 TEXT, c791 TEXT,
+ c792 TEXT, c793 TEXT, c794 TEXT, c795 TEXT, c796 TEXT, c797 TEXT, c798 TEXT,
+ c799 TEXT, c800 TEXT, c801 TEXT, c802 TEXT, c803 TEXT, c804 TEXT, c805 TEXT,
+ c806 TEXT, c807 TEXT, c808 TEXT, c809 TEXT, c810 TEXT, c811 TEXT, c812 TEXT,
+ c813 TEXT, c814 TEXT, c815 TEXT, c816 TEXT, c817 TEXT, c818 TEXT, c819 TEXT,
+ c820 TEXT, c821 TEXT, c822 TEXT, c823 TEXT, c824 TEXT, c825 TEXT, c826 TEXT,
+ c827 TEXT, c828 TEXT, c829 TEXT, c830 TEXT, c831 TEXT, c832 TEXT, c833 TEXT,
+ c834 TEXT, c835 TEXT, c836 TEXT, c837 TEXT, c838 TEXT, c839 TEXT, c840 TEXT,
+ c841 TEXT, c842 TEXT, c843 TEXT, c844 TEXT, c845 TEXT, c846 TEXT, c847 TEXT,
+ c848 TEXT, c849 TEXT, c850 TEXT, c851 TEXT, c852 TEXT, c853 TEXT, c854 TEXT,
+ c855 TEXT, c856 TEXT, c857 TEXT, c858 TEXT, c859 TEXT, c860 TEXT, c861 TEXT,
+ c862 TEXT, c863 TEXT, c864 TEXT, c865 TEXT, c866 TEXT, c867 TEXT, c868 TEXT,
+ c869 TEXT, c870 TEXT, c871 TEXT, c872 TEXT, c873 TEXT, c874 TEXT, c875 TEXT,
+ c876 TEXT, c877 TEXT, c878 TEXT, c879 TEXT, c880 TEXT, c881 TEXT, c882 TEXT,
+ c883 TEXT, c884 TEXT, c885 TEXT, c886 TEXT, c887 TEXT, c888 TEXT, c889 TEXT,
+ c890 TEXT, c891 TEXT, c892 TEXT, c893 TEXT, c894 TEXT, c895 TEXT, c896 TEXT,
+ c897 TEXT, c898 TEXT, c899 TEXT, c900 TEXT, c901 TEXT, c902 TEXT, c903 TEXT,
+ c904 TEXT, c905 TEXT, c906 TEXT, c907 TEXT, c908 TEXT, c909 TEXT, c910 TEXT,
+ c911 TEXT, c912 TEXT, c913 TEXT, c914 TEXT, c915 TEXT, c916 TEXT, c917 TEXT,
+ c918 TEXT, c919 TEXT, c920 TEXT, c921 TEXT, c922 TEXT, c923 TEXT, c924 TEXT,
+ c925 TEXT, c926 TEXT, c927 TEXT, c928 TEXT, c929 TEXT, c930 TEXT, c931 TEXT,
+ c932 TEXT, c933 TEXT, c934 TEXT, c935 TEXT, c936 TEXT, c937 TEXT, c938 TEXT,
+ c939 TEXT, c940 TEXT, c941 TEXT, c942 TEXT, c943 TEXT, c944 TEXT, c945 TEXT,
+ c946 TEXT, c947 TEXT, c948 TEXT, c949 TEXT, c950 TEXT, c951 TEXT, c952 TEXT,
+ c953 TEXT, c954 TEXT, c955 TEXT, c956 TEXT, c957 TEXT, c958 TEXT, c959 TEXT,
+ c960 TEXT, c961 TEXT, c962 TEXT, c963 TEXT, c964 TEXT, c965 TEXT, c966 TEXT,
+ c967 TEXT, c968 TEXT, c969 TEXT, c970 TEXT, c971 TEXT, c972 TEXT, c973 TEXT,
+ c974 TEXT, c975 TEXT, c976 TEXT, c977 TEXT, c978 TEXT, c979 TEXT, c980 TEXT,
+ c981 TEXT, c982 TEXT, c983 TEXT, c984 TEXT, c985 TEXT, c986 TEXT, c987 TEXT,
+ c988 TEXT, c989 TEXT, c990 TEXT, c991 TEXT, c992 TEXT, c993 TEXT, c994 TEXT,
+ c995 TEXT, c996 TEXT, c997 TEXT, c998 TEXT, c999 TEXT, c1000 TEXT, c1001 TEXT,
+ c1002 TEXT, c1003 TEXT, c1004 TEXT, c1005 TEXT, c1006 TEXT, c1007 TEXT, c1008 TEXT,
+ c1009 TEXT, c1010 TEXT, c1011 TEXT, c1012 TEXT, c1013 TEXT, c1014 TEXT, c1015 TEXT,
+ c1016 TEXT, c1017 TEXT
+) ENGINE=INNODB;
+DROP TABLE t1;
+--error ER_CANT_CREATE_TABLE
+CREATE TABLE t1 (
+ c1 TEXT, c2 TEXT, c3 TEXT, c4 TEXT, c5 TEXT, c6 TEXT, c7 TEXT,
+ c8 TEXT, c9 TEXT, c10 TEXT, c11 TEXT, c12 TEXT, c13 TEXT, c14 TEXT,
+ c15 TEXT, c16 TEXT, c17 TEXT, c18 TEXT, c19 TEXT, c20 TEXT, c21 TEXT,
+ c22 TEXT, c23 TEXT, c24 TEXT, c25 TEXT, c26 TEXT, c27 TEXT, c28 TEXT,
+ c29 TEXT, c30 TEXT, c31 TEXT, c32 TEXT, c33 TEXT, c34 TEXT, c35 TEXT,
+ c36 TEXT, c37 TEXT, c38 TEXT, c39 TEXT, c40 TEXT, c41 TEXT, c42 TEXT,
+ c43 TEXT, c44 TEXT, c45 TEXT, c46 TEXT, c47 TEXT, c48 TEXT, c49 TEXT,
+ c50 TEXT, c51 TEXT, c52 TEXT, c53 TEXT, c54 TEXT, c55 TEXT, c56 TEXT,
+ c57 TEXT, c58 TEXT, c59 TEXT, c60 TEXT, c61 TEXT, c62 TEXT, c63 TEXT,
+ c64 TEXT, c65 TEXT, c66 TEXT, c67 TEXT, c68 TEXT, c69 TEXT, c70 TEXT,
+ c71 TEXT, c72 TEXT, c73 TEXT, c74 TEXT, c75 TEXT, c76 TEXT, c77 TEXT,
+ c78 TEXT, c79 TEXT, c80 TEXT, c81 TEXT, c82 TEXT, c83 TEXT, c84 TEXT,
+ c85 TEXT, c86 TEXT, c87 TEXT, c88 TEXT, c89 TEXT, c90 TEXT, c91 TEXT,
+ c92 TEXT, c93 TEXT, c94 TEXT, c95 TEXT, c96 TEXT, c97 TEXT, c98 TEXT,
+ c99 TEXT, c100 TEXT, c101 TEXT, c102 TEXT, c103 TEXT, c104 TEXT, c105 TEXT,
+ c106 TEXT, c107 TEXT, c108 TEXT, c109 TEXT, c110 TEXT, c111 TEXT, c112 TEXT,
+ c113 TEXT, c114 TEXT, c115 TEXT, c116 TEXT, c117 TEXT, c118 TEXT, c119 TEXT,
+ c120 TEXT, c121 TEXT, c122 TEXT, c123 TEXT, c124 TEXT, c125 TEXT, c126 TEXT,
+ c127 TEXT, c128 TEXT, c129 TEXT, c130 TEXT, c131 TEXT, c132 TEXT, c133 TEXT,
+ c134 TEXT, c135 TEXT, c136 TEXT, c137 TEXT, c138 TEXT, c139 TEXT, c140 TEXT,
+ c141 TEXT, c142 TEXT, c143 TEXT, c144 TEXT, c145 TEXT, c146 TEXT, c147 TEXT,
+ c148 TEXT, c149 TEXT, c150 TEXT, c151 TEXT, c152 TEXT, c153 TEXT, c154 TEXT,
+ c155 TEXT, c156 TEXT, c157 TEXT, c158 TEXT, c159 TEXT, c160 TEXT, c161 TEXT,
+ c162 TEXT, c163 TEXT, c164 TEXT, c165 TEXT, c166 TEXT, c167 TEXT, c168 TEXT,
+ c169 TEXT, c170 TEXT, c171 TEXT, c172 TEXT, c173 TEXT, c174 TEXT, c175 TEXT,
+ c176 TEXT, c177 TEXT, c178 TEXT, c179 TEXT, c180 TEXT, c181 TEXT, c182 TEXT,
+ c183 TEXT, c184 TEXT, c185 TEXT, c186 TEXT, c187 TEXT, c188 TEXT, c189 TEXT,
+ c190 TEXT, c191 TEXT, c192 TEXT, c193 TEXT, c194 TEXT, c195 TEXT, c196 TEXT,
+ c197 TEXT, c198 TEXT, c199 TEXT, c200 TEXT, c201 TEXT, c202 TEXT, c203 TEXT,
+ c204 TEXT, c205 TEXT, c206 TEXT, c207 TEXT, c208 TEXT, c209 TEXT, c210 TEXT,
+ c211 TEXT, c212 TEXT, c213 TEXT, c214 TEXT, c215 TEXT, c216 TEXT, c217 TEXT,
+ c218 TEXT, c219 TEXT, c220 TEXT, c221 TEXT, c222 TEXT, c223 TEXT, c224 TEXT,
+ c225 TEXT, c226 TEXT, c227 TEXT, c228 TEXT, c229 TEXT, c230 TEXT, c231 TEXT,
+ c232 TEXT, c233 TEXT, c234 TEXT, c235 TEXT, c236 TEXT, c237 TEXT, c238 TEXT,
+ c239 TEXT, c240 TEXT, c241 TEXT, c242 TEXT, c243 TEXT, c244 TEXT, c245 TEXT,
+ c246 TEXT, c247 TEXT, c248 TEXT, c249 TEXT, c250 TEXT, c251 TEXT, c252 TEXT,
+ c253 TEXT, c254 TEXT, c255 TEXT, c256 TEXT, c257 TEXT, c258 TEXT, c259 TEXT,
+ c260 TEXT, c261 TEXT, c262 TEXT, c263 TEXT, c264 TEXT, c265 TEXT, c266 TEXT,
+ c267 TEXT, c268 TEXT, c269 TEXT, c270 TEXT, c271 TEXT, c272 TEXT, c273 TEXT,
+ c274 TEXT, c275 TEXT, c276 TEXT, c277 TEXT, c278 TEXT, c279 TEXT, c280 TEXT,
+ c281 TEXT, c282 TEXT, c283 TEXT, c284 TEXT, c285 TEXT, c286 TEXT, c287 TEXT,
+ c288 TEXT, c289 TEXT, c290 TEXT, c291 TEXT, c292 TEXT, c293 TEXT, c294 TEXT,
+ c295 TEXT, c296 TEXT, c297 TEXT, c298 TEXT, c299 TEXT, c300 TEXT, c301 TEXT,
+ c302 TEXT, c303 TEXT, c304 TEXT, c305 TEXT, c306 TEXT, c307 TEXT, c308 TEXT,
+ c309 TEXT, c310 TEXT, c311 TEXT, c312 TEXT, c313 TEXT, c314 TEXT, c315 TEXT,
+ c316 TEXT, c317 TEXT, c318 TEXT, c319 TEXT, c320 TEXT, c321 TEXT, c322 TEXT,
+ c323 TEXT, c324 TEXT, c325 TEXT, c326 TEXT, c327 TEXT, c328 TEXT, c329 TEXT,
+ c330 TEXT, c331 TEXT, c332 TEXT, c333 TEXT, c334 TEXT, c335 TEXT, c336 TEXT,
+ c337 TEXT, c338 TEXT, c339 TEXT, c340 TEXT, c341 TEXT, c342 TEXT, c343 TEXT,
+ c344 TEXT, c345 TEXT, c346 TEXT, c347 TEXT, c348 TEXT, c349 TEXT, c350 TEXT,
+ c351 TEXT, c352 TEXT, c353 TEXT, c354 TEXT, c355 TEXT, c356 TEXT, c357 TEXT,
+ c358 TEXT, c359 TEXT, c360 TEXT, c361 TEXT, c362 TEXT, c363 TEXT, c364 TEXT,
+ c365 TEXT, c366 TEXT, c367 TEXT, c368 TEXT, c369 TEXT, c370 TEXT, c371 TEXT,
+ c372 TEXT, c373 TEXT, c374 TEXT, c375 TEXT, c376 TEXT, c377 TEXT, c378 TEXT,
+ c379 TEXT, c380 TEXT, c381 TEXT, c382 TEXT, c383 TEXT, c384 TEXT, c385 TEXT,
+ c386 TEXT, c387 TEXT, c388 TEXT, c389 TEXT, c390 TEXT, c391 TEXT, c392 TEXT,
+ c393 TEXT, c394 TEXT, c395 TEXT, c396 TEXT, c397 TEXT, c398 TEXT, c399 TEXT,
+ c400 TEXT, c401 TEXT, c402 TEXT, c403 TEXT, c404 TEXT, c405 TEXT, c406 TEXT,
+ c407 TEXT, c408 TEXT, c409 TEXT, c410 TEXT, c411 TEXT, c412 TEXT, c413 TEXT,
+ c414 TEXT, c415 TEXT, c416 TEXT, c417 TEXT, c418 TEXT, c419 TEXT, c420 TEXT,
+ c421 TEXT, c422 TEXT, c423 TEXT, c424 TEXT, c425 TEXT, c426 TEXT, c427 TEXT,
+ c428 TEXT, c429 TEXT, c430 TEXT, c431 TEXT, c432 TEXT, c433 TEXT, c434 TEXT,
+ c435 TEXT, c436 TEXT, c437 TEXT, c438 TEXT, c439 TEXT, c440 TEXT, c441 TEXT,
+ c442 TEXT, c443 TEXT, c444 TEXT, c445 TEXT, c446 TEXT, c447 TEXT, c448 TEXT,
+ c449 TEXT, c450 TEXT, c451 TEXT, c452 TEXT, c453 TEXT, c454 TEXT, c455 TEXT,
+ c456 TEXT, c457 TEXT, c458 TEXT, c459 TEXT, c460 TEXT, c461 TEXT, c462 TEXT,
+ c463 TEXT, c464 TEXT, c465 TEXT, c466 TEXT, c467 TEXT, c468 TEXT, c469 TEXT,
+ c470 TEXT, c471 TEXT, c472 TEXT, c473 TEXT, c474 TEXT, c475 TEXT, c476 TEXT,
+ c477 TEXT, c478 TEXT, c479 TEXT, c480 TEXT, c481 TEXT, c482 TEXT, c483 TEXT,
+ c484 TEXT, c485 TEXT, c486 TEXT, c487 TEXT, c488 TEXT, c489 TEXT, c490 TEXT,
+ c491 TEXT, c492 TEXT, c493 TEXT, c494 TEXT, c495 TEXT, c496 TEXT, c497 TEXT,
+ c498 TEXT, c499 TEXT, c500 TEXT, c501 TEXT, c502 TEXT, c503 TEXT, c504 TEXT,
+ c505 TEXT, c506 TEXT, c507 TEXT, c508 TEXT, c509 TEXT, c510 TEXT, c511 TEXT,
+ c512 TEXT, c513 TEXT, c514 TEXT, c515 TEXT, c516 TEXT, c517 TEXT, c518 TEXT,
+ c519 TEXT, c520 TEXT, c521 TEXT, c522 TEXT, c523 TEXT, c524 TEXT, c525 TEXT,
+ c526 TEXT, c527 TEXT, c528 TEXT, c529 TEXT, c530 TEXT, c531 TEXT, c532 TEXT,
+ c533 TEXT, c534 TEXT, c535 TEXT, c536 TEXT, c537 TEXT, c538 TEXT, c539 TEXT,
+ c540 TEXT, c541 TEXT, c542 TEXT, c543 TEXT, c544 TEXT, c545 TEXT, c546 TEXT,
+ c547 TEXT, c548 TEXT, c549 TEXT, c550 TEXT, c551 TEXT, c552 TEXT, c553 TEXT,
+ c554 TEXT, c555 TEXT, c556 TEXT, c557 TEXT, c558 TEXT, c559 TEXT, c560 TEXT,
+ c561 TEXT, c562 TEXT, c563 TEXT, c564 TEXT, c565 TEXT, c566 TEXT, c567 TEXT,
+ c568 TEXT, c569 TEXT, c570 TEXT, c571 TEXT, c572 TEXT, c573 TEXT, c574 TEXT,
+ c575 TEXT, c576 TEXT, c577 TEXT, c578 TEXT, c579 TEXT, c580 TEXT, c581 TEXT,
+ c582 TEXT, c583 TEXT, c584 TEXT, c585 TEXT, c586 TEXT, c587 TEXT, c588 TEXT,
+ c589 TEXT, c590 TEXT, c591 TEXT, c592 TEXT, c593 TEXT, c594 TEXT, c595 TEXT,
+ c596 TEXT, c597 TEXT, c598 TEXT, c599 TEXT, c600 TEXT, c601 TEXT, c602 TEXT,
+ c603 TEXT, c604 TEXT, c605 TEXT, c606 TEXT, c607 TEXT, c608 TEXT, c609 TEXT,
+ c610 TEXT, c611 TEXT, c612 TEXT, c613 TEXT, c614 TEXT, c615 TEXT, c616 TEXT,
+ c617 TEXT, c618 TEXT, c619 TEXT, c620 TEXT, c621 TEXT, c622 TEXT, c623 TEXT,
+ c624 TEXT, c625 TEXT, c626 TEXT, c627 TEXT, c628 TEXT, c629 TEXT, c630 TEXT,
+ c631 TEXT, c632 TEXT, c633 TEXT, c634 TEXT, c635 TEXT, c636 TEXT, c637 TEXT,
+ c638 TEXT, c639 TEXT, c640 TEXT, c641 TEXT, c642 TEXT, c643 TEXT, c644 TEXT,
+ c645 TEXT, c646 TEXT, c647 TEXT, c648 TEXT, c649 TEXT, c650 TEXT, c651 TEXT,
+ c652 TEXT, c653 TEXT, c654 TEXT, c655 TEXT, c656 TEXT, c657 TEXT, c658 TEXT,
+ c659 TEXT, c660 TEXT, c661 TEXT, c662 TEXT, c663 TEXT, c664 TEXT, c665 TEXT,
+ c666 TEXT, c667 TEXT, c668 TEXT, c669 TEXT, c670 TEXT, c671 TEXT, c672 TEXT,
+ c673 TEXT, c674 TEXT, c675 TEXT, c676 TEXT, c677 TEXT, c678 TEXT, c679 TEXT,
+ c680 TEXT, c681 TEXT, c682 TEXT, c683 TEXT, c684 TEXT, c685 TEXT, c686 TEXT,
+ c687 TEXT, c688 TEXT, c689 TEXT, c690 TEXT, c691 TEXT, c692 TEXT, c693 TEXT,
+ c694 TEXT, c695 TEXT, c696 TEXT, c697 TEXT, c698 TEXT, c699 TEXT, c700 TEXT,
+ c701 TEXT, c702 TEXT, c703 TEXT, c704 TEXT, c705 TEXT, c706 TEXT, c707 TEXT,
+ c708 TEXT, c709 TEXT, c710 TEXT, c711 TEXT, c712 TEXT, c713 TEXT, c714 TEXT,
+ c715 TEXT, c716 TEXT, c717 TEXT, c718 TEXT, c719 TEXT, c720 TEXT, c721 TEXT,
+ c722 TEXT, c723 TEXT, c724 TEXT, c725 TEXT, c726 TEXT, c727 TEXT, c728 TEXT,
+ c729 TEXT, c730 TEXT, c731 TEXT, c732 TEXT, c733 TEXT, c734 TEXT, c735 TEXT,
+ c736 TEXT, c737 TEXT, c738 TEXT, c739 TEXT, c740 TEXT, c741 TEXT, c742 TEXT,
+ c743 TEXT, c744 TEXT, c745 TEXT, c746 TEXT, c747 TEXT, c748 TEXT, c749 TEXT,
+ c750 TEXT, c751 TEXT, c752 TEXT, c753 TEXT, c754 TEXT, c755 TEXT, c756 TEXT,
+ c757 TEXT, c758 TEXT, c759 TEXT, c760 TEXT, c761 TEXT, c762 TEXT, c763 TEXT,
+ c764 TEXT, c765 TEXT, c766 TEXT, c767 TEXT, c768 TEXT, c769 TEXT, c770 TEXT,
+ c771 TEXT, c772 TEXT, c773 TEXT, c774 TEXT, c775 TEXT, c776 TEXT, c777 TEXT,
+ c778 TEXT, c779 TEXT, c780 TEXT, c781 TEXT, c782 TEXT, c783 TEXT, c784 TEXT,
+ c785 TEXT, c786 TEXT, c787 TEXT, c788 TEXT, c789 TEXT, c790 TEXT, c791 TEXT,
+ c792 TEXT, c793 TEXT, c794 TEXT, c795 TEXT, c796 TEXT, c797 TEXT, c798 TEXT,
+ c799 TEXT, c800 TEXT, c801 TEXT, c802 TEXT, c803 TEXT, c804 TEXT, c805 TEXT,
+ c806 TEXT, c807 TEXT, c808 TEXT, c809 TEXT, c810 TEXT, c811 TEXT, c812 TEXT,
+ c813 TEXT, c814 TEXT, c815 TEXT, c816 TEXT, c817 TEXT, c818 TEXT, c819 TEXT,
+ c820 TEXT, c821 TEXT, c822 TEXT, c823 TEXT, c824 TEXT, c825 TEXT, c826 TEXT,
+ c827 TEXT, c828 TEXT, c829 TEXT, c830 TEXT, c831 TEXT, c832 TEXT, c833 TEXT,
+ c834 TEXT, c835 TEXT, c836 TEXT, c837 TEXT, c838 TEXT, c839 TEXT, c840 TEXT,
+ c841 TEXT, c842 TEXT, c843 TEXT, c844 TEXT, c845 TEXT, c846 TEXT, c847 TEXT,
+ c848 TEXT, c849 TEXT, c850 TEXT, c851 TEXT, c852 TEXT, c853 TEXT, c854 TEXT,
+ c855 TEXT, c856 TEXT, c857 TEXT, c858 TEXT, c859 TEXT, c860 TEXT, c861 TEXT,
+ c862 TEXT, c863 TEXT, c864 TEXT, c865 TEXT, c866 TEXT, c867 TEXT, c868 TEXT,
+ c869 TEXT, c870 TEXT, c871 TEXT, c872 TEXT, c873 TEXT, c874 TEXT, c875 TEXT,
+ c876 TEXT, c877 TEXT, c878 TEXT, c879 TEXT, c880 TEXT, c881 TEXT, c882 TEXT,
+ c883 TEXT, c884 TEXT, c885 TEXT, c886 TEXT, c887 TEXT, c888 TEXT, c889 TEXT,
+ c890 TEXT, c891 TEXT, c892 TEXT, c893 TEXT, c894 TEXT, c895 TEXT, c896 TEXT,
+ c897 TEXT, c898 TEXT, c899 TEXT, c900 TEXT, c901 TEXT, c902 TEXT, c903 TEXT,
+ c904 TEXT, c905 TEXT, c906 TEXT, c907 TEXT, c908 TEXT, c909 TEXT, c910 TEXT,
+ c911 TEXT, c912 TEXT, c913 TEXT, c914 TEXT, c915 TEXT, c916 TEXT, c917 TEXT,
+ c918 TEXT, c919 TEXT, c920 TEXT, c921 TEXT, c922 TEXT, c923 TEXT, c924 TEXT,
+ c925 TEXT, c926 TEXT, c927 TEXT, c928 TEXT, c929 TEXT, c930 TEXT, c931 TEXT,
+ c932 TEXT, c933 TEXT, c934 TEXT, c935 TEXT, c936 TEXT, c937 TEXT, c938 TEXT,
+ c939 TEXT, c940 TEXT, c941 TEXT, c942 TEXT, c943 TEXT, c944 TEXT, c945 TEXT,
+ c946 TEXT, c947 TEXT, c948 TEXT, c949 TEXT, c950 TEXT, c951 TEXT, c952 TEXT,
+ c953 TEXT, c954 TEXT, c955 TEXT, c956 TEXT, c957 TEXT, c958 TEXT, c959 TEXT,
+ c960 TEXT, c961 TEXT, c962 TEXT, c963 TEXT, c964 TEXT, c965 TEXT, c966 TEXT,
+ c967 TEXT, c968 TEXT, c969 TEXT, c970 TEXT, c971 TEXT, c972 TEXT, c973 TEXT,
+ c974 TEXT, c975 TEXT, c976 TEXT, c977 TEXT, c978 TEXT, c979 TEXT, c980 TEXT,
+ c981 TEXT, c982 TEXT, c983 TEXT, c984 TEXT, c985 TEXT, c986 TEXT, c987 TEXT,
+ c988 TEXT, c989 TEXT, c990 TEXT, c991 TEXT, c992 TEXT, c993 TEXT, c994 TEXT,
+ c995 TEXT, c996 TEXT, c997 TEXT, c998 TEXT, c999 TEXT, c1000 TEXT, c1001 TEXT,
+ c1002 TEXT, c1003 TEXT, c1004 TEXT, c1005 TEXT, c1006 TEXT, c1007 TEXT, c1008 TEXT,
+ c1009 TEXT, c1010 TEXT, c1011 TEXT, c1012 TEXT, c1013 TEXT, c1014 TEXT, c1015 TEXT,
+ c1016 TEXT, c1017 TEXT, c1018 TEXT
+) ENGINE=INNODB;
+} }
diff --git a/mysql-test/suite/innodb/t/mdev-117.test b/mysql-test/suite/innodb/t/mdev-117.test
new file mode 100644
index 00000000..b29b2cd5
--- /dev/null
+++ b/mysql-test/suite/innodb/t/mdev-117.test
@@ -0,0 +1,34 @@
+#
+# verify that DELETE IGNORE does not ignore deadlocks
+#
+
+--source include/have_innodb.inc
+
+SET GLOBAL innodb_lock_wait_timeout=3;
+
+CREATE TABLE t1 (col_int_key INT, KEY (col_int_key)) ENGINE=InnoDB;
+INSERT INTO t1 VALUES (6);
+
+--connect (con1,localhost,root,,test)
+SET SESSION TRANSACTION ISOLATION LEVEL SERIALIZABLE;
+SET AUTOCOMMIT=OFF;
+SELECT col_int_key FROM t1;
+
+--connection default
+--send DELETE IGNORE FROM t1;
+
+--connection con1
+--error 0,ER_LOCK_DEADLOCK,ER_LOCK_WAIT_TIMEOUT
+DELETE FROM t1 WHERE col_int_key IN (1, 40000000);
+
+--connection default
+--disable_warnings
+--error 0,ER_LOCK_DEADLOCK,ER_LOCK_WAIT_TIMEOUT
+--reap
+--enable_warnings
+
+--disconnect con1
+drop table t1;
+SET GLOBAL innodb_lock_wait_timeout=default;
+
+call mtr.add_suppression("Deadlock found when trying to get lock; try restarting transaction");
diff --git a/mysql-test/suite/innodb/t/mdev-14846.opt b/mysql-test/suite/innodb/t/mdev-14846.opt
new file mode 100644
index 00000000..c8fe0561
--- /dev/null
+++ b/mysql-test/suite/innodb/t/mdev-14846.opt
@@ -0,0 +1 @@
+--loose-innodb_lock_waits
diff --git a/mysql-test/suite/innodb/t/mdev-14846.test b/mysql-test/suite/innodb/t/mdev-14846.test
new file mode 100644
index 00000000..b1f32302
--- /dev/null
+++ b/mysql-test/suite/innodb/t/mdev-14846.test
@@ -0,0 +1,71 @@
+--source include/have_innodb.inc
+--source include/count_sessions.inc
+--source include/have_debug_sync.inc
+
+CREATE TABLE t1 (
+ pk INT,
+ f1 VARCHAR(10) NOT NULL,
+ f2 VARCHAR(10) NULL,
+ f3 INT UNSIGNED NULL,
+ KEY (f1),
+ PRIMARY KEY (pk)
+) ENGINE=InnoDB;
+
+CREATE OR REPLACE ALGORITHM=MERGE VIEW v4 AS SELECT * FROM t1;
+INSERT INTO t1 VALUES (1,'k','g',6),(2,'y','r',0),(3,'t','q',1),(4,'a','r',NULL),(5,'z','t',NULL);
+
+CREATE TABLE t2 (f VARCHAR(10) NULL) ENGINE=InnoDB;
+INSERT INTO t2 VALUES (NULL),('g'),('e'),('g');
+
+CREATE TABLE t3 (
+ f1 VARCHAR(10) NOT NULL,
+ f2 VARCHAR(10) NULL,
+ f3 INT UNSIGNED NULL
+) ENGINE=InnoDB;
+
+INSERT INTO t3 VALUES ('k','n',9),('y','b',8),('m','w',6);
+
+CREATE TABLE t4 (f INT NULL) ENGINE=InnoDB;
+INSERT INTO t4 VALUES (8),(9);
+UPDATE t1 SET t1.pk = -109 WHERE t1.f1 IN ( SELECT 'a' FROM t4 WHERE f >= 1 );
+SET DEBUG_SYNC='now SIGNAL con1_dml';
+
+--connect (con1,localhost,root,,test)
+SET DEBUG_SYNC='now WAIT_FOR con1_dml';
+begin;
+SELECT * FROM t1 for update; # Holds x lock of all records in the table t1
+SET DEBUG_SYNC='now SIGNAL default_dml';
+SET DEBUG_SYNC='now SIGNAL con2_dml';
+
+--connection default
+SET DEBUG_SYNC='now WAIT_FOR default_dml';
+--send UPDATE t3 AS alias1 LEFT JOIN t3 AS alias2 ON ( alias1.f1 <> alias1.f2 ) SET alias1.f3 = 59 WHERE ( EXISTS ( SELECT t1.f3 FROM t1 WHERE t1.f1 = alias1.f1 ) ) OR alias2.f1 = 'h'
+# It holds the lock of all record in t3 and tries to acquire record lock for the table t1.
+
+--connect (con2,localhost,root,,test)
+set debug_sync='now WAIT_FOR con2_dml';
+let $wait_condition=
+select count(*) > 0 from information_schema.innodb_lock_waits;
+--source include/wait_condition.inc
+SET DEBUG_SYNC='now SIGNAL con1_dml2';
+disconnect con2;
+
+# Cleanup
+--connection con1
+SET DEBUG_SYNC='now WAIT_FOR con1_dml2';
+UPDATE v4, t1 SET t1.pk = 76 WHERE t1.f2 IN ( SELECT t2.f FROM t2 INNER JOIN t3 );
+# It holds the record lock on table t1 and tries to acquire record lock on t3.
+# leads to deadlock (con1 trx is waiting for default trx and vice versa)
+
+--connection default
+--error ER_LOCK_DEADLOCK
+--reap
+
+connection con1;
+COMMIT;
+disconnect con1;
+
+--connection default
+DROP VIEW v4;
+DROP TABLE t1, t2, t3, t4;
+set debug_sync= reset;
diff --git a/mysql-test/suite/innodb/t/mdev-15707.opt b/mysql-test/suite/innodb/t/mdev-15707.opt
new file mode 100644
index 00000000..fec3463c
--- /dev/null
+++ b/mysql-test/suite/innodb/t/mdev-15707.opt
@@ -0,0 +1 @@
+--innodb --innodb-buffer-pool-size=5MB --innodb-read-io-threads=1 --innodb-doublewrite=0 --innodb-flush-log-at-trx-commit=0 \ No newline at end of file
diff --git a/mysql-test/suite/innodb/t/mdev-15707.test b/mysql-test/suite/innodb/t/mdev-15707.test
new file mode 100644
index 00000000..a0446ef4
--- /dev/null
+++ b/mysql-test/suite/innodb/t/mdev-15707.test
@@ -0,0 +1,30 @@
+--source include/windows.inc
+# This test is slow on buildbot.
+--source include/big_test.inc
+
+# Deadlock in conjunction with the innodb change buffering.
+
+# When innodb change buffering kicks in, i.e secondary non-unique index
+# does not fit into the bufferpool, then, on Windows, innodb
+# background threads could deadlock whenever index page is
+# read, and the page needs load/merge change buffer.
+# The test tries to reproduce this situation, by creating index
+# that does not fit into bufferpool, and doing a large update.
+
+CREATE TABLE t1(
+a INT AUTO_INCREMENT PRIMARY KEY,
+b CHAR(255),
+INDEX(b))
+ENGINE=InnoDB;
+
+INSERT INTO t1(b) SELECT UUID();
+BEGIN;
+let $i=`select cast(log2(@@innodb_buffer_pool_size/255) as int)`;
+while ($i)
+{
+ INSERT INTO t1(b) SELECT UUID() FROM t1;
+ dec $i;
+}
+COMMIT;
+UPDATE t1 SET b=UUID();
+DROP TABLE t1; \ No newline at end of file
diff --git a/mysql-test/suite/innodb/t/missing_tablespaces.test b/mysql-test/suite/innodb/t/missing_tablespaces.test
new file mode 100644
index 00000000..7aeb0a26
--- /dev/null
+++ b/mysql-test/suite/innodb/t/missing_tablespaces.test
@@ -0,0 +1,37 @@
+--source include/have_innodb.inc
+
+#Restarting not supported in embedded
+--source include/not_embedded.inc
+#Windows has trouble creating files/directories with long names
+--source include/not_windows.inc
+--source include/no_valgrind_without_big.inc
+
+--echo #
+--echo # Bug#19419026 WHEN A TABLESPACE IS NOT FOUND, DO NOT REPORT "TABLE NOT FOUND"
+--echo #
+
+#Create database and tablename with all special characters
+
+CREATE DATABASE `..................................................`;
+USE `..................................................`;
+CREATE TABLE `..................................................` (ID INT)
+ENGINE=INNODB;
+
+let $restart_noprint=2;
+--source include/shutdown_mysqld.inc
+
+--remove_file $MYSQLTEST_VARDIR/mysqld.1/data/@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e/@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e.ibd
+
+--source include/start_mysqld.inc
+
+--disable_query_log
+call mtr.add_suppression("\\[ERROR\\] InnoDB: Operating system error number 2 in a file operation.");
+call mtr.add_suppression("\\[ERROR\\] InnoDB: Error number \\d+ means");
+call mtr.add_suppression("\\[ERROR\\] InnoDB: Cannot open datafile for read-only");
+call mtr.add_suppression("\\[Warning\\] InnoDB: Ignoring tablespace .* because it could not be opened");
+--enable_query_log
+
+--error ER_GET_ERRNO
+select * from `..................................................`;
+DROP TABLE `..................................................`;
+DROP DATABASE `..................................................`;
diff --git a/mysql-test/suite/innodb/t/mon_lock_wait_current_count.test b/mysql-test/suite/innodb/t/mon_lock_wait_current_count.test
new file mode 100644
index 00000000..9255d608
--- /dev/null
+++ b/mysql-test/suite/innodb/t/mon_lock_wait_current_count.test
@@ -0,0 +1,97 @@
+# Check if lock_row_lock_current_waits counter in
+# information_schema.innodb_metrics does not become negative after disabling,
+# resetting and enabling.
+
+--source include/have_innodb.inc
+--source include/have_debug.inc
+--source include/count_sessions.inc
+
+--connect (prevent_purge,localhost,root,,)
+START TRANSACTION WITH CONSISTENT SNAPSHOT;
+
+--connection default
+# lock_row_lock_time_avg is filled under lock_sys.wait_mutex lock, which
+# will be held by connection 2, that is why the following SELECT
+# from information_schema.innodb_metrics will be blocked.
+#
+# And setting innodb_monitor_disable=all causes innodb monitor enabling
+# status changing. The status will not be restored to default value even
+# after
+# -----------------------
+# SET GLOBAL innodb_monitor_reset_all=default;
+# SET GLOBAL innodb_monitor_enable=default;
+# -----------------------
+# execution. See MDEV-32553 for details.
+#
+# All monitors disabling, i.e. "innodb_monitor_disable=all" causes
+# innodb.monitor test failure due to MDEV-32553. 10.5 is not affected, as
+# innodb.monitor differs there.
+#
+# Disable not all monitors at the beggining of the test,
+# but only the monitor, which causes hanging, i.e. lock_row_lock_time_avg.
+SET GLOBAL innodb_monitor_disable='lock_row_lock_time_avg';
+# 'lock_row_lock_current_waits' should be enabled by default;
+CREATE TABLE `t` (a INT PRIMARY KEY) engine=InnoDB STATS_PERSISTENT=0;
+INSERT INTO t VALUES (5);
+SELECT name, count FROM information_schema.innodb_metrics
+ WHERE name ='lock_row_lock_current_waits';
+
+--connect (con1,localhost,root,,)
+BEGIN;
+SELECT * FROM t FOR UPDATE;
+
+--connect (con2,localhost,root,,)
+SET DEBUG_SYNC="lock_wait_before_suspend SIGNAL blocked WAIT_FOR cont";
+BEGIN;
+--send SELECT * FROM t FOR UPDATE
+
+--connection default
+SET DEBUG_SYNC="now WAIT_FOR blocked";
+SELECT name, count FROM information_schema.innodb_metrics
+ WHERE name ='lock_row_lock_current_waits';
+SET GLOBAL innodb_monitor_disable='lock_row_lock_current_waits';
+SET GLOBAL innodb_monitor_reset_all='lock_row_lock_current_waits';
+SET GLOBAL innodb_monitor_enable='lock_row_lock_current_waits';
+######################################
+# Equals to zero if the bug is not fixed, as MONITOR_DISPLAY_CURRENT is not
+# set for this counter and its value is reset during previous
+# "SET GLOBAL innodb_monitor_reset_all='lock_row_lock_current_waits'" execution.
+#####
+SELECT name, count FROM information_schema.innodb_metrics
+ WHERE name ='lock_row_lock_current_waits';
+SET DEBUG_SYNC="now SIGNAL cont";
+
+--disconnect con1
+
+--connection con2
+--reap
+COMMIT;
+--disconnect con2
+
+--connection default
+SET DEBUG_SYNC="reset";
+######################################
+# Equals to -1 if the bug is not fixed. I.e.
+# innodb_counter_value[MONITOR_OVLD_ROW_LOCK_CURRENT_WAIT].mon_start_value is
+# set to 1 during
+# "set global innodb_monitor_disable='lock_row_lock_current_waits'" execution,
+# and the value is counted as
+# (value = 0) - (mon_value_reset = 0) - (mon_start_value = 1) +
+# (mon_last_value = 0) = -1. See MONITOR_SET_DIFF() macro in
+# srv_mon_process_existing_counter() for details.
+#####
+SELECT name, count FROM information_schema.innodb_metrics
+ WHERE name ='lock_row_lock_current_waits';
+DROP TABLE `t`;
+SET GLOBAL innodb_monitor_disable='lock_row_lock_current_waits';
+SET GLOBAL innodb_monitor_reset_all='lock_row_lock_current_waits';
+SET GLOBAL innodb_monitor_enable='lock_row_lock_current_waits';
+# TODO: remove it when MDEV-32553 is fixed
+SET GLOBAL innodb_monitor_enable='lock_row_lock_time_avg';
+--disable_warnings
+SET GLOBAL innodb_monitor_disable=default;
+SET GLOBAL innodb_monitor_reset_all=default;
+SET GLOBAL innodb_monitor_enable=default;
+--enable_warnings
+--disconnect prevent_purge
+--source include/wait_until_count_sessions.inc
diff --git a/mysql-test/suite/innodb/t/monitor.test b/mysql-test/suite/innodb/t/monitor.test
new file mode 100644
index 00000000..77483d62
--- /dev/null
+++ b/mysql-test/suite/innodb/t/monitor.test
@@ -0,0 +1,469 @@
+# This test used to be duplicated in the following:
+# sys_vars.innodb_monitor_reset_basic
+# sys_vars.innodb_monitor_reset_all_basic
+# sys_vars.innodb_monitor_disable_basic
+# sys_vars.innodb_monitor_enable_basic
+
+--source include/have_innodb.inc
+# Test turn on/off the monitor counter with "all" option
+# By default, they will be off.
+select name, if(enabled,'enabled','disabled') status
+from information_schema.innodb_metrics;
+
+set global innodb_monitor_disable = All;
+select name from information_schema.innodb_metrics where enabled;
+
+# Turn on all monitor counters
+set global innodb_monitor_enable = all;
+
+# status should all change to "enabled"
+select name from information_schema.innodb_metrics where not enabled;
+
+# Test wrong argument to the global configure option
+--error ER_WRONG_VALUE_FOR_VAR
+set global innodb_monitor_enable = aaa;
+
+# We require a valid monitor counter/module name. There is no default
+# counter name or module. A warning will be printed asking user to
+# specify a valid counter name.
+#--disable_warnings
+#set global innodb_monitor_enable = default;
+#--enable_warnings
+
+# Turn off all monitor counters, option name should be case
+# insensitive
+set global innodb_monitor_disable = All;
+
+# status should all change to "disabled"
+select name from information_schema.innodb_metrics where enabled;
+
+# Reset all counter values
+set global innodb_monitor_reset_all = all;
+
+# count should all change to 0
+select name from information_schema.innodb_metrics where count!=0;
+
+# Test wildcard match, turn on all counters contain string "lock"
+set global innodb_monitor_enable = "%lock%";
+
+# All lock related counter should be enabled
+select name from information_schema.innodb_metrics
+where enabled != (name like "%lock%");
+
+# Disable them
+set global innodb_monitor_disable = "%lock%";
+
+# All lock related counter should be disabled
+select name, if(enabled,'enabled','disabled') status
+from information_schema.innodb_metrics
+where name like "%lock%";
+
+# No match for "%lock*"
+--error ER_WRONG_VALUE_FOR_VAR
+set global innodb_monitor_enable = "%lock*";
+
+# All counters will be turned on with wildcard match string with all "%"
+set global innodb_monitor_enable="%%%%%%%%%%%%%%%%%%%%%%%%%%%";
+
+select name from information_schema.innodb_metrics where not enabled;
+
+# Turn off all counters
+set global innodb_monitor_disable="%%%%%";
+
+select name from information_schema.innodb_metrics where enabled;
+
+# One more round testing. All counters will be turned on with
+# single wildcard character "%"
+set global innodb_monitor_enable="%";
+
+select name from information_schema.innodb_metrics where not enabled;
+
+# Turn off all the counters with "%_%"
+set global innodb_monitor_disable="%_%";
+
+select name from information_schema.innodb_metrics where enabled;
+
+# Turn on all counters start with "log"
+set global innodb_monitor_enable="log%%%%";
+
+select name from information_schema.innodb_metrics
+where enabled != (name like "log%");
+
+# Turn on counters "os_data_fsync" with wildcard match "os_%a_fs_ncs", "_"
+# is single character wildcard match word
+set global innodb_monitor_enable="os_%a_fs_ncs";
+
+# Turn on counters whose name contains "os" and "pending" with
+# wildcard match "os%pending%"
+set global innodb_monitor_enable="os%pending%";
+
+select name, if(enabled,'enabled','disabled') status
+from information_schema.innodb_metrics
+where name like "os%";
+
+# Empty string is an invalid option
+--error ER_WRONG_VALUE_FOR_VAR
+set global innodb_monitor_enable="";
+
+--error ER_WRONG_VALUE_FOR_VAR
+set global innodb_monitor_enable="_";
+
+SET global innodb_monitor_disable = module_metadata;
+SET global innodb_monitor_reset_all = module_metadata;
+
+# Only turn on "table_open" counter
+set global innodb_monitor_enable = metadata_table_handles_opened;
+
+# Create a new table to test "metadata_table_handles_opened" counter
+create table monitor_test(col int) engine = innodb;
+
+# This will open the monitor_test table
+select * from monitor_test;
+
+# "metadata_table_handles_opened" should increment by 1
+select name, max_count, min_count, count,
+ max_count_reset, min_count_reset, count_reset,
+ if(enabled,'enabled','disabled') status
+from information_schema.innodb_metrics
+where name = "metadata_table_handles_opened";
+
+# Reset the counter value while counter is still on (started)
+# This will reset value "count_reset" but not
+# "count"
+set global innodb_monitor_reset = metadata_table_handles_opened;
+
+select name, max_count, min_count, count,
+ max_count_reset, min_count_reset, count_reset,
+ if(enabled,'enabled','disabled') status
+from information_schema.innodb_metrics
+where name = "metadata_table_handles_opened";
+
+# re-create table again to increment "metadata_table_handles_opened" again
+drop table monitor_test;
+
+# Create a new table to test "metadata_table_handles_opened" counter
+create table monitor_test(col int) engine = innodb;
+
+select * from monitor_test;
+
+# "metadata_table_handles_opened" should increment
+select name, max_count, min_count, count,
+ max_count_reset, min_count_reset, count_reset,
+ if(enabled,'enabled','disabled') status
+from information_schema.innodb_metrics
+where name = "metadata_table_handles_opened";
+
+# Cannot reset all monitor value while the counter is on
+set global innodb_monitor_reset_all = metadata_table_handles_opened;
+
+select name, max_count, min_count, count,
+ max_count_reset, min_count_reset, count_reset,
+ if(enabled,'enabled','disabled') status
+from information_schema.innodb_metrics
+where name = "metadata_table_handles_opened";
+
+# Turn off the counter "metadata_table_handles_opened"
+set global innodb_monitor_disable = metadata_table_handles_opened;
+
+# Reset the counter value while counter is off (disabled)
+set global innodb_monitor_reset = metadata_table_handles_opened;
+
+select name, max_count, min_count, count,
+ max_count_reset, min_count_reset, count_reset,
+ if(enabled,'enabled','disabled') status
+from information_schema.innodb_metrics
+where name = "metadata_table_handles_opened";
+
+# re-create table again. Since monitor is off, "metadata_table_handles_opened"
+# should not be incremented
+drop table monitor_test;
+
+# Create a new table to test "metadata_table_handles_opened" counter
+create table monitor_test(col int) engine = innodb;
+
+# "metadata_table_handles_opened" should increment
+select * from monitor_test;
+
+select name, max_count, min_count, count,
+ max_count_reset, min_count_reset, count_reset,
+ if(enabled,'enabled','disabled') status
+from information_schema.innodb_metrics
+where name = "metadata_table_handles_opened";
+
+# Reset all the counters, include those counter *_since_start
+set global innodb_monitor_reset_all = metadata_table_handles_opened;
+
+select name, max_count, min_count, count,
+ max_count_reset, min_count_reset, count_reset,
+ if(enabled,'enabled','disabled') status
+from information_schema.innodb_metrics
+where name = "metadata_table_handles_opened";
+
+# Turn on "table_open" counter again
+set global innodb_monitor_enable = metadata_table_handles_opened;
+
+# Test metadata_table_handles_opened again to see if it is working correctly
+# after above round of turning on/off/reset
+drop table monitor_test;
+
+# Create a new table to test "metadata_table_handles_opened" counter
+create table monitor_test(col int) engine = innodb stats_persistent=0;
+
+select * from monitor_test;
+
+# "metadata_table_handles_opened" should increment
+select name, max_count, min_count, count,
+ max_count_reset, min_count_reset, count_reset,
+ if(enabled,'enabled','disabled') status
+from information_schema.innodb_metrics
+where name like "metadata%";
+
+# Reset counters only in "module_metadata" module
+set global innodb_monitor_disable = module_metadata;
+
+set global innodb_monitor_reset = module_metadata;
+
+select name, max_count, min_count, count,
+ max_count_reset, min_count_reset, count_reset,
+ if(enabled,'enabled','disabled') status
+from information_schema.innodb_metrics
+where name like "metadata%";
+
+set global innodb_monitor_reset_all = module_metadata;
+
+select name, max_count, min_count, count,
+ max_count_reset, min_count_reset, count_reset,
+ if(enabled,'enabled','disabled') status
+from information_schema.innodb_metrics
+where name like "metadata%";
+
+# Test Transaction Module
+set global innodb_monitor_enable = module_trx;
+
+begin;
+insert into monitor_test values(9);
+commit;
+
+begin;
+insert into monitor_test values(9);
+rollback;
+
+select name, max_count, min_count, count,
+ max_count_reset, min_count_reset, count_reset,
+ if(enabled,'enabled','disabled') status
+from information_schema.innodb_metrics
+where name='trx_rollbacks';
+
+set global innodb_monitor_disable = module_trx;
+
+drop table monitor_test;
+
+set global innodb_monitor_enable = file_num_open_files;
+
+# Counters are unpredictable when innodb-file-per-table is on
+--replace_column 2 # 3 # 4 # 5 # 6 # 7 #
+select name, max_count, min_count, count,
+ max_count_reset, min_count_reset, count_reset,
+ if(enabled,'enabled','disabled') status
+from information_schema.innodb_metrics
+where name like "file_num_open_files";
+
+set global innodb_monitor_disable = file_num_open_files;
+
+# Test ICP module counters
+set global innodb_monitor_enable = "icp%";
+
+create table monitor_test(a char(3), b int, c char(2),
+primary key (a(1), c(1)), key(b)) engine = innodb;
+
+insert into monitor_test values("13", 2, "aa");
+
+--disable_ps2_protocol
+select a from monitor_test where b < 1 for update;
+
+# should have icp_attempts = 1 and icp_out_of_range = 1
+select name, count from information_schema.innodb_metrics
+where name like "icp%";
+
+# should have icp_attempts = 2 and icp_match = 1
+select a from monitor_test where b < 3 for update;
+
+select name, count from information_schema.innodb_metrics
+where name like "icp%";
+--enable_ps2_protocol
+
+drop table monitor_test;
+set global innodb_monitor_disable = All;
+set global innodb_monitor_reset_all = all;
+
+# Test for bug #13966091
+select 1 from `information_schema`.`INNODB_METRICS`
+where case (1) when (1) then (AVG_COUNT_RESET) else (1) end;
+
+-- disable_warnings
+set global innodb_monitor_enable = default;
+set global innodb_monitor_disable = default;
+set global innodb_monitor_reset = default;
+set global innodb_monitor_reset_all = default;
+-- enable_warnings
+
+--echo #
+--echo # Bug#22576241 SETTING INNODB_MONITOR_ENABLE TO ALL DOES NOT ENABLE ALL
+--echo # MONITORS
+--echo #
+CREATE TABLE t1 (a INT PRIMARY KEY) ENGINE=InnoDB STATS_PERSISTENT=0;
+
+let $innodb_monitor_enable = `SELECT @@innodb_monitor_enable`;
+
+SELECT NAME, COUNT > 0 FROM INFORMATION_SCHEMA.INNODB_METRICS WHERE NAME
+LIKE 'buffer_page_written_index_leaf';
+
+SET GLOBAL innodb_monitor_enable='module_buffer_page';
+INSERT INTO t1 VALUES (1), (2), (3), (4); FLUSH TABLES t1 FOR EXPORT;
+UNLOCK TABLES;
+SELECT NAME, COUNT > 0 FROM INFORMATION_SCHEMA.INNODB_METRICS WHERE NAME
+LIKE 'buffer_page_written_index_leaf';
+
+SET GLOBAL innodb_monitor_disable='module_buffer_page';
+SET GLOBAL innodb_monitor_reset_all='module_buffer_page';
+SELECT NAME, COUNT > 0 FROM INFORMATION_SCHEMA.INNODB_METRICS WHERE NAME
+LIKE 'buffer_page_written_index_leaf';
+
+SET GLOBAL innodb_monitor_enable='%';
+--error ER_WRONG_VALUE_FOR_VAR
+SET GLOBAL innodb_monitor_reset_all= '%', innodb_compression_algorithm= foo;
+INSERT INTO t1 VALUES (5), (6), (7), (8); FLUSH TABLES t1 FOR EXPORT;
+UNLOCK TABLES;
+SELECT NAME, COUNT > 0 FROM INFORMATION_SCHEMA.INNODB_METRICS WHERE NAME
+LIKE 'buffer_page_written_index_leaf';
+
+SET GLOBAL innodb_monitor_disable='%';
+SET GLOBAL innodb_monitor_reset_all='%';
+SELECT NAME, COUNT > 0 FROM INFORMATION_SCHEMA.INNODB_METRICS WHERE NAME
+LIKE 'buffer_page_written_index_leaf';
+
+SET GLOBAL innodb_monitor_enable='ALL';
+INSERT INTO t1 VALUES (9), (10), (11), (12); FLUSH TABLES t1 FOR EXPORT;
+UNLOCK TABLES;
+SELECT NAME, COUNT > 0 FROM INFORMATION_SCHEMA.INNODB_METRICS WHERE NAME
+LIKE 'buffer_page_written_index_leaf';
+
+DROP TABLE t1;
+
+CREATE TABLE fl0 (
+ id INT NOT NULL PRIMARY KEY
+) ENGINE = InnoDB;
+
+CREATE TABLE fl1 (
+ id INT NOT NULL PRIMARY KEY,
+ fl0_id INT,
+ CONSTRAINT `fkl0`
+ FOREIGN KEY (fl0_id) REFERENCES fl0 (id)
+ ON DELETE CASCADE
+ ON UPDATE RESTRICT
+) ENGINE = InnoDB;
+
+CREATE TABLE fl2 (
+ id INT NOT NULL PRIMARY KEY,
+ fl1_id INT,
+ CONSTRAINT `fkl1`
+ FOREIGN KEY (fl1_id) REFERENCES fl1 (id)
+ ON DELETE CASCADE
+ ON UPDATE SET NULL
+) ENGINE = InnoDB;
+
+INSERT INTO fl0 VALUES (1000);
+INSERT INTO fl1 VALUES (500, 1000), (1500, 1000);
+INSERT INTO fl2 VALUES (200, 500), (800, 500), (1200, 1500), (1800, 1500);
+
+CREATE TABLE t1(id INT PRIMARY KEY, a INT, b CHAR(1), UNIQUE KEY u(a,b))
+ENGINE=InnoDB;
+
+SET @start = (SELECT COUNT FROM INFORMATION_SCHEMA.INNODB_METRICS WHERE NAME
+= 'lock_rec_lock_created');
+
+BEGIN;
+INSERT INTO t1 VALUES(1,1,'a'),(2,9999,'b'),(3,10000,'c'),(4,4,'d');
+DELETE FROM t1 WHERE a = 9999 AND b='b';
+COMMIT;
+
+# After MDEV-30225 is fixed, the above DELETE creates next-key lock during
+# secondary index unique search. That's why the result of the following must
+# be 1.
+SET @end = (SELECT COUNT FROM INFORMATION_SCHEMA.INNODB_METRICS WHERE NAME
+= 'lock_rec_lock_created');
+SELECT @end - @start;
+
+--echo # Records must not be S/X-locked if a table is X-locked.
+SET @start = @end;
+# Tables will not be locked if autocommit is not 0.
+# See OPTION_NOT_AUTOCOMMIT in ha_innobase::external_lock().
+SET autocommit = 0;
+BEGIN;
+LOCK TABLE t1 WRITE;
+SELECT * FROM t1;
+SELECT * FROM t1 WHERE a>=10000;
+SELECT * FROM t1 FOR UPDATE;
+SELECT * FROM t1 WHERE a>=10000 FOR UPDATE;
+UPDATE t1 SET b = 'b' WHERE id = 4;
+UPDATE t1 SET b = 'b' WHERE a = 10000;
+REPLACE INTO t1 VALUES (4,3,'a');
+INSERT INTO t1 VALUES (3,1,'e') ON DUPLICATE KEY UPDATE b = 'b';
+INSERT INTO t1 VALUES (5,5,'e');
+DELETE FROM t1 WHERE a = 1 AND b='a';
+DELETE FROM t1;
+COMMIT;
+UNLOCK TABLES;
+SET @end = (SELECT COUNT FROM INFORMATION_SCHEMA.INNODB_METRICS WHERE NAME = 'lock_rec_lock_created');
+SELECT @end - @start;
+
+--echo # Records must not be S-locked if a table is S-locked.
+SET @start = @end;
+BEGIN;
+LOCK TABLE t1 WRITE;
+INSERT INTO t1 VALUES(1,1,'a'),(2,9999,'b'),(3,10000,'c'),(4,4,'d');
+DELETE FROM t1 WHERE a = 9999 AND b='b';
+COMMIT;
+UNLOCK TABLES;
+BEGIN;
+LOCK TABLE t1 READ;
+SELECT * FROM t1 LOCK IN SHARE MODE;
+SELECT * FROM t1 WHERE a>=10000 LOCK IN SHARE MODE;
+COMMIT;
+UNLOCK TABLES;
+SET @end = (SELECT COUNT FROM INFORMATION_SCHEMA.INNODB_METRICS WHERE NAME = 'lock_rec_lock_created');
+SELECT @end - @start;
+
+--echo # Records must not be S-locked for foreign keys enforcement
+SET @start = @end;
+BEGIN;
+LOCK TABLE fl0 READ, fl1 READ, fl2 WRITE;
+INSERT INTO fl2 VALUES (300, 500), (700, 500), (1300, 1500), (1700, 1500);
+SELECT * FROM fl1 LOCK IN SHARE MODE;
+COMMIT;
+UNLOCK TABLES;
+SET @end = (SELECT COUNT FROM INFORMATION_SCHEMA.INNODB_METRICS WHERE NAME = 'lock_rec_lock_created');
+SELECT @end - @start;
+
+--echo # Records must not be X-locked for foreign keys cascade
+SET @start = @end;
+BEGIN;
+LOCK TABLE fl0 READ, fl1 WRITE, fl2 WRITE;
+DELETE FROM fl1 WHERE id = 1500;
+UPDATE fl1 SET id = 2500 WHERE id = 500;
+COMMIT;
+UNLOCK TABLES;
+SET @end = (SELECT COUNT FROM INFORMATION_SCHEMA.INNODB_METRICS WHERE NAME = 'lock_rec_lock_created');
+SELECT @end - @start;
+
+SET autocommit = default;
+DROP TABLE t1;
+DROP TABLE fl2;
+DROP TABLE fl1;
+DROP TABLE fl0;
+
+--disable_warnings
+SET GLOBAL innodb_monitor_enable=default;
+SET GLOBAL innodb_monitor_disable=default;
+SET GLOBAL innodb_monitor_reset_all=default;
+--enable_warnings
diff --git a/mysql-test/suite/innodb/t/multi_repair-7404.test b/mysql-test/suite/innodb/t/multi_repair-7404.test
new file mode 100644
index 00000000..0775cd8b
--- /dev/null
+++ b/mysql-test/suite/innodb/t/multi_repair-7404.test
@@ -0,0 +1,18 @@
+#
+# MDEV-7404 REPAIR multiple tables crash in MDL_ticket::has_stronger_or_equal_type
+#
+
+--source include/have_partition.inc
+--source include/have_innodb.inc
+create table `t1`(`a` int) engine=innodb partition by key (`a`);
+create table `t2`(`b` int) engine=innodb;
+create table `t3`(`c` int) engine=innodb;
+insert t1 values (1);
+insert t2 values (2);
+insert t3 values (3);
+repair table `t1`,`t2`,`t3`;
+select * from t1;
+select * from t2;
+select * from t3;
+drop table t1, t2, t3;
+
diff --git a/mysql-test/suite/innodb/t/mvcc.test b/mysql-test/suite/innodb/t/mvcc.test
new file mode 100644
index 00000000..7c37718c
--- /dev/null
+++ b/mysql-test/suite/innodb/t/mvcc.test
@@ -0,0 +1,72 @@
+--source include/have_innodb.inc
+--source include/have_sequence.inc
+
+SET @save_per_table= @@GLOBAL.innodb_file_per_table;
+SET GLOBAL innodb_file_per_table= 1;
+
+let MYSQLD_DATADIR =`SELECT @@datadir`;
+
+--echo #
+--echo # MDEV-15249 Crash in MVCC read after IMPORT TABLESPACE
+--echo #
+
+CREATE TABLE t1 (a INT PRIMARY KEY) ENGINE=InnoDB;
+INSERT INTO t1 VALUES(0);
+FLUSH TABLES t1 WITH READ LOCK;
+perl;
+do "$ENV{MTR_SUITE_DIR}/include/innodb-util.pl";
+ib_backup_tablespace("test", "t1");
+EOF
+UNLOCK TABLES;
+
+START TRANSACTION WITH CONSISTENT SNAPSHOT;
+
+connect (con1,localhost,root,,);
+ALTER TABLE t1 FORCE, ALGORITHM=COPY;
+
+connection default;
+--error ER_TABLE_DEF_CHANGED
+SELECT * FROM t1;
+COMMIT;
+START TRANSACTION WITH CONSISTENT SNAPSHOT;
+
+connection con1;
+
+ALTER TABLE t1 DISCARD TABLESPACE;
+
+perl;
+do "$ENV{MTR_SUITE_DIR}/include/innodb-util.pl";
+ib_restore_tablespace("test", "t1");
+EOF
+
+ALTER TABLE t1 IMPORT TABLESPACE;
+disconnect con1;
+
+connection default;
+--echo # FIXME: Block this with ER_TABLE_DEF_CHANGED
+SELECT * FROM t1;
+COMMIT;
+SELECT * FROM t1;
+
+DROP TABLE t1;
+
+--echo #
+--echo # MDEV-23198 Crash in REPLACE
+--echo #
+
+DELIMITER $$;
+BEGIN NOT ATOMIC
+ DECLARE c TEXT DEFAULT(SELECT CONCAT('CREATE TABLE t1(id INT PRIMARY KEY, c',
+ GROUP_CONCAT(seq SEPARATOR ' INT, c'),
+ ' INT NOT NULL UNIQUE) ENGINE=InnoDB')
+ FROM seq_1_to_294);
+ EXECUTE IMMEDIATE c;
+END;
+$$
+DELIMITER ;$$
+
+INSERT INTO t1 SET id=1,c294=1;
+REPLACE t1 SET id=1,c294=1;
+DROP TABLE t1;
+
+SET GLOBAL innodb_file_per_table= @save_per_table;
diff --git a/mysql-test/suite/innodb/t/mvcc_secondary.test b/mysql-test/suite/innodb/t/mvcc_secondary.test
new file mode 100644
index 00000000..93c91c40
--- /dev/null
+++ b/mysql-test/suite/innodb/t/mvcc_secondary.test
@@ -0,0 +1,26 @@
+--source include/innodb_page_size_small.inc
+
+--echo #
+--echo # MDEV-25459 MVCC read from index on CHAR or VARCHAR wrongly omits rows
+--echo #
+
+CREATE TABLE t1 (
+ pk int PRIMARY KEY, c varchar(255) UNIQUE,
+ d char(255), e varchar(255), f char(255), g char(255)
+) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARACTER SET ucs2;
+
+INSERT INTO t1 VALUES
+(1,REPEAT('c',248),REPEAT('a',106),REPEAT('b',220),REPEAT('x',14),'');
+
+BEGIN;
+UPDATE t1 SET c=REPEAT('d',170);
+
+connect (con1,localhost,root,,);
+SELECT pk FROM t1 FORCE INDEX (c);
+connection default;
+COMMIT;
+connection con1;
+SELECT pk FROM t1 FORCE INDEX (c);
+disconnect con1;
+connection default;
+DROP TABLE t1;
diff --git a/mysql-test/suite/innodb/t/no_pad.test b/mysql-test/suite/innodb/t/no_pad.test
new file mode 100644
index 00000000..1be1972c
--- /dev/null
+++ b/mysql-test/suite/innodb/t/no_pad.test
@@ -0,0 +1,10 @@
+--source include/have_innodb.inc
+
+CREATE TABLE t1 (a CHAR(8), id INT, PRIMARY KEY (a,id)) COLLATE utf8_nopad_bin
+ENGINE=InnoDB ROW_FORMAT=REDUNDANT;
+
+INSERT INTO t1 VALUES ('',1);
+ALTER TABLE t1 ROW_FORMAT=DYNAMIC;
+INSERT INTO t1 VALUES ('',2);
+ALTER TABLE t1 ROW_FORMAT=REDUNDANT;
+DROP TABLE t1;
diff --git a/mysql-test/suite/innodb/t/online_table_rebuild.opt b/mysql-test/suite/innodb/t/online_table_rebuild.opt
new file mode 100644
index 00000000..fa341828
--- /dev/null
+++ b/mysql-test/suite/innodb/t/online_table_rebuild.opt
@@ -0,0 +1,2 @@
+--innodb_online_alter_log_max_size=64k
+--innodb_sort_buffer_size=64k
diff --git a/mysql-test/suite/innodb/t/online_table_rebuild.test b/mysql-test/suite/innodb/t/online_table_rebuild.test
new file mode 100644
index 00000000..02e9639e
--- /dev/null
+++ b/mysql-test/suite/innodb/t/online_table_rebuild.test
@@ -0,0 +1,87 @@
+--source include/have_innodb.inc
+--source include/have_debug.inc
+--source include/have_debug_sync.inc
+--source include/have_sequence.inc
+
+CREATE TABLE t1(f1 INT NOT NULL, f2 CHAR(200), f3 CHAR(200))ENGINE=InnoDB;
+INSERT INTO t1 VALUES(3, "innodb", "alter log");
+
+# InnoDB fails with DUPLICATE KEY error in commit phase
+
+SET DEBUG_SYNC="inplace_after_index_build SIGNAL dml_start WAIT_FOR dml_commit";
+send ALTER TABLE t1 ADD PRIMARY KEY(f3(10)), ADD UNIQUE KEY(f2(10));
+CONNECT(con1,localhost,root,,,);
+SET DEBUG_SYNC="now WAIT_FOR dml_start";
+BEGIN;
+INSERT INTO t1 VALUES(1, repeat('b', 100), repeat('c', 100));
+INSERT INTO t1 VALUES(2, repeat('b', 100), repeat('a', 100));
+COMMIT;
+SET DEBUG_SYNC="now SIGNAL dml_commit";
+
+connection default;
+--error ER_DUP_ENTRY
+reap;
+
+# ONLINE_LOG_TOO_BIG error during commit phase
+
+connection default;
+
+SET DEBUG_SYNC="inplace_after_index_build SIGNAL dml_start WAIT_FOR dml_commit";
+SEND ALTER TABLE t1 ADD PRIMARY KEY(f1);
+
+connection con1;
+SET DEBUG_SYNC="now WAIT_FOR dml_start";
+INSERT INTO t1 SELECT 10, repeat('a', 100), repeat('b', 100) FROM seq_1_to_4800;
+SET DEBUG_SYNC="now SIGNAL dml_commit";
+
+connection default;
+--error ER_INNODB_ONLINE_LOG_TOO_BIG
+reap;
+DELETE FROM t1;
+INSERT INTO t1 VALUES(1, repeat('a', 100), repeat('b', 100));
+ALTER TABLE t1 ADD PRIMARY KEY(f1);
+
+# Update operation leads to duplicate key error
+
+set DEBUG_SYNC="innodb_inplace_alter_table_enter SIGNAL dml_start WAIT_FOR dml_commit";
+SEND ALTER TABLE t1 DROP PRIMARY KEY, ADD PRIMARY KEY(f3(10));
+
+connection con1;
+SET DEBUG_SYNC="now WAIT_FOR dml_start";
+BEGIN;
+INSERT INTO t1 VALUES(2, repeat('b', 100), repeat('c', 100));
+UPDATE t1 set f3=repeat('c', 100) where f1=1;
+COMMIT;
+SET DEBUG_SYNC="now SIGNAL dml_commit";
+
+connection default;
+--error ER_DUP_ENTRY
+reap;
+SHOW CREATE TABLE t1;
+DROP TABLE t1;
+
+--echo #
+--echo # MDEV-30183 Assertion `!memcmp(rec_trx_id, old_pk_trx_id->data,
+--echo # 6 + 7)' failed in row_log_table_apply_update
+--echo #
+set @old_sql_mode = @@sql_mode;
+set @@sql_mode="";
+CREATE TABLE t1(col_int int, col_varchar varchar(500))ENGINE=InnoDB;
+INSERT INTO t1(col_int) values(2560);
+set debug_sync="row_log_table_apply1_before SIGNAL con1_begin WAIT_FOR con1_commit";
+send ALTER TABLE t1 ADD PRIMARY KEY ( col_varchar);
+
+connection con1;
+SET DEBUG_SYNC="now WAIT_FOR con1_begin";
+UPDATE t1 SET col_int = 2178;
+INSERT INTO t1(col_int) VALUES(3016);
+UPDATE t1 set col_int=2802;
+SET DEBUG_SYNC="now SIGNAL con1_commit";
+
+connection default;
+--error ER_DUP_ENTRY
+reap;
+DROP TABLE t1;
+SET @@sql_mode = @old_sql_mode;
+disconnect con1;
+SET DEBUG_SYNC=reset;
diff --git a/mysql-test/suite/innodb/t/page_cleaner.test b/mysql-test/suite/innodb/t/page_cleaner.test
new file mode 100644
index 00000000..f597619a
--- /dev/null
+++ b/mysql-test/suite/innodb/t/page_cleaner.test
@@ -0,0 +1,30 @@
+--source include/have_innodb.inc
+--source include/have_sequence.inc
+
+SET @save_pct= @@GLOBAL.innodb_max_dirty_pages_pct;
+SET @save_pct_lwm= @@GLOBAL.innodb_max_dirty_pages_pct_lwm;
+
+SET GLOBAL innodb_max_dirty_pages_pct_lwm=0.0;
+SET GLOBAL innodb_max_dirty_pages_pct=0.0;
+
+let $wait_condition =
+SELECT variable_value = 0
+FROM information_schema.global_status
+WHERE variable_name = 'INNODB_BUFFER_POOL_PAGES_DIRTY';
+--source include/wait_condition.inc
+
+SET GLOBAL innodb_max_dirty_pages_pct=90.0;
+
+CREATE TABLE t ENGINE=InnoDB SELECT * FROM seq_1_to_10000;
+
+SELECT variable_value>0 FROM information_schema.global_status
+WHERE variable_name = 'INNODB_BUFFER_POOL_PAGES_DIRTY';
+
+SET GLOBAL innodb_max_dirty_pages_pct=0.0;
+
+# Without the MDEV-24917 fix, we would time out here.
+--source include/wait_condition.inc
+DROP TABLE t;
+
+SET GLOBAL innodb_max_dirty_pages_pct = @save_pct;
+SET GLOBAL innodb_max_dirty_pages_pct_lwm = @save_pct_lwm;
diff --git a/mysql-test/suite/innodb/t/page_id_innochecksum.test b/mysql-test/suite/innodb/t/page_id_innochecksum.test
new file mode 100644
index 00000000..902d2aba
--- /dev/null
+++ b/mysql-test/suite/innodb/t/page_id_innochecksum.test
@@ -0,0 +1,70 @@
+--source include/have_innodb.inc
+--source include/not_embedded.inc
+--source include/innodb_checksum_algorithm.inc
+--echo # Set the environmental variables
+let MYSQLD_BASEDIR= `SELECT @@basedir`;
+let MYSQLD_DATADIR= `SELECT @@datadir`;
+let INNODB_PAGE_SIZE=`select @@innodb_page_size`;
+
+create table t1(f1 int not null)engine=innodb;
+insert into t1 values(1), (2), (3);
+let $resultlog=$MYSQLTEST_VARDIR/tmp/result.log;
+
+let $restart_noprint=2;
+--source include/shutdown_mysqld.inc
+--echo # Change the page offset
+perl;
+use strict;
+use warnings;
+use Fcntl qw(:DEFAULT :seek);
+do "$ENV{MTR_SUITE_DIR}/../innodb/include/crc32.pl";
+
+my $page_size = $ENV{INNODB_PAGE_SIZE};
+
+sysopen IBD_FILE, "$ENV{MYSQLD_DATADIR}/test/t1.ibd", O_RDWR
+|| die "Cannot open t1.ibd\n";
+sysread(IBD_FILE, $_, 58) || die "Cannot read t1.ibd\n";
+my ($space,$flags) = unpack("x[34]Nx[16]N", $_);
+my $full_crc32 = $flags & 0x10;
+sysseek(IBD_FILE, $page_size * 3, SEEK_SET) || die "Cannot seek t1.ibd\n";
+
+my $page= pack("NNx[18]NNN", 0, 4, 1, 0, $space).(chr(0) x ($page_size - 38));
+
+# Calculate innodb_checksum_algorithm=crc32 or full_crc32.
+my $polynomial = 0x82f63b78; # CRC-32C
+if ($full_crc32)
+{
+ my $ck = mycrc32(substr($page, 0, $page_size-4), 0, $polynomial);
+ substr($page, $page_size-4, 4) = pack("N", $ck);
+}
+else
+{
+ # The following bytes are excluded:
+ # 0..3 (the checksum is stored there)
+ # 26..37 (encryption key version, post-encryption checksum, tablespace id)
+ # $page_size-8..$page_size-1 (checksum, LSB of FIL_PAGE_LSN)
+ my $ck= pack("N",mycrc32(substr($page, 4, 22), 0, $polynomial) ^
+ mycrc32(substr($page, 38, $page_size-38-8), 0, $polynomial));
+ substr($page,0,4)=$ck;
+ substr($page,$page_size-8,4)=$ck;
+}
+
+die unless syswrite(IBD_FILE, $page, $page_size) == $page_size;
+close IBD_FILE;
+EOF
+
+--error 1
+exec $INNOCHECKSUM -l $resultlog $MYSQLD_DATADIR/test/t1.ibd;
+
+let SEARCH_FILE = $MYSQLTEST_VARDIR/tmp/result.log;
+let SEARCH_PATTERN=page id mismatch;
+--source include/search_pattern_in_file.inc
+
+--remove_file $resultlog
+let $restart_parameters=--innodb-force-recovery=1;
+--source include/start_mysqld.inc
+--source include/wait_all_purged.inc
+drop table t1;
+call mtr.add_suppression("InnoDB: Failed to read page 3 from file '.*test/t1\\.ibd': Page read from tablespace is corrupted\\.");
+let $restart_parameters=;
+--source include/restart_mysqld.inc
diff --git a/mysql-test/suite/innodb/t/page_reorganize.test b/mysql-test/suite/innodb/t/page_reorganize.test
new file mode 100644
index 00000000..c4e0160c
--- /dev/null
+++ b/mysql-test/suite/innodb/t/page_reorganize.test
@@ -0,0 +1,64 @@
+--source include/have_innodb.inc
+--source include/have_innodb_16k.inc
+--source include/have_debug.inc
+
+--source include/count_sessions.inc
+
+--echo #
+--echo # Bug# 20005279 ASSERT !OTHER_LOCK, LOCK_MOVE_REORGANIZE_PAGE()
+--echo #
+
+create table t1 (f1 int auto_increment primary key,
+ f2 char(255)) engine=innodb;
+
+let $inc = 50;
+
+start transaction;
+--disable_query_log
+
+while ($inc)
+{
+ insert into t1(f2) values (repeat('~', 50));
+ dec $inc;
+}
+
+--enable_query_log
+commit;
+
+start transaction;
+select f1, f2 from t1 where f1 = 20 for update;
+
+connect (con1,localhost,root,,);
+--send
+select f1 from t1 where f1 = 20 for update;
+
+connection default;
+
+let $wait_condition=
+ select count(*) = 1 from information_schema.processlist
+ where INFO = 'select f1 from t1 where f1 = 20 for update';
+
+--source include/wait_condition.inc
+
+SET @save_dbug = @@debug_dbug;
+SET DEBUG_DBUG = '+d,do_page_reorganize,do_lock_reverse_page_reorganize';
+insert into t1(f2) values (repeat('+', 100));
+SET DEBUG = @save_dbug;
+commit;
+
+connection con1;
+reap;
+disconnect con1;
+connection default;
+
+drop table t1;
+
+--echo #
+--echo # MDEV-27993 Assertion failed in btr_page_reorganize_low()
+--echo #
+CREATE TABLE t1(a INT PRIMARY KEY, b INT UNIQUE) ENGINE=InnoDB;
+SET DEBUG_DBUG = '+d,do_page_reorganize';
+INSERT INTO t1 VALUES(0,0);
+DROP TABLE t1;
+
+--source include/wait_until_count_sessions.inc
diff --git a/mysql-test/suite/innodb/t/partition_locking.test b/mysql-test/suite/innodb/t/partition_locking.test
new file mode 100644
index 00000000..13457c1d
--- /dev/null
+++ b/mysql-test/suite/innodb/t/partition_locking.test
@@ -0,0 +1,178 @@
+# Test of SKIP LOCKED and NOWAIT on partitioned tables.
+# Must have same results as not partitioned tables.
+--source include/have_innodb.inc
+--source include/have_partition.inc
+
+set @start_read_only= @@global.read_only;
+set @start_autocommit= @@global.autocommit;
+set default_storage_engine= innodb;
+set @@global.autocommit= 0;
+
+CREATE USER test@localhost;
+grant CREATE, SELECT, UPDATE, INSERT on *.* to test@localhost;
+CREATE USER test2@localhost;
+grant CREATE, SELECT, UPDATE on *.* to test2@localhost;
+
+CREATE TABLE t1 (
+a char(2) NOT NULL,
+b char(2) NOT NULL,
+c int(10) unsigned NOT NULL,
+d varchar(255) DEFAULT NULL,
+e varchar(1000) DEFAULT NULL,
+PRIMARY KEY (a, b, c),
+KEY (a),
+KEY (a, b)
+) charset latin1 PARTITION BY KEY (a) PARTITIONS 20;
+
+INSERT INTO t1 (a, b, c, d, e) VALUES
+('07', '03', 343, '1', '07_03_343'),
+('01', '04', 343, '2', '01_04_343'),
+('01', '06', 343, '3', '01_06_343'),
+('01', '07', 343, '4', '01_07_343'),
+('01', '08', 343, '5', '01_08_343'),
+('01', '09', 343, '6', '01_09_343'),
+('03', '03', 343, '7', '03_03_343'),
+('03', '06', 343, '8', '03_06_343'),
+('03', '07', 343, '9', '03_07_343'),
+('04', '03', 343, '10', '04_03_343'),
+('04', '06', 343, '11', '04_06_343'),
+('05', '03', 343, '12', '05_03_343'),
+('11', '03', 343, '13', '11_03_343'),
+('11', '04', 343, '14', '11_04_343')
+;
+
+CREATE TABLE t2 (a int, name VARCHAR(50), purchased DATE)
+PARTITION BY RANGE (a)
+(PARTITION p0 VALUES LESS THAN (3),
+ PARTITION p1 VALUES LESS THAN (7),
+ PARTITION p2 VALUES LESS THAN (9),
+ PARTITION p3 VALUES LESS THAN (11));
+INSERT INTO t2 VALUES
+(1, 'desk organiser', '2003-10-15'),
+(2, 'CD player', '1993-11-05'),
+(3, 'TV set', '1996-03-10'),
+(4, 'bookcase', '1982-01-10'),
+(5, 'exercise bike', '2004-05-09'),
+(6, 'sofa', '1987-06-05'),
+(7, 'popcorn maker', '2001-11-22'),
+(8, 'acquarium', '1992-08-04'),
+(9, 'study desk', '1984-09-16'),
+(10, 'lava lamp', '1998-12-25');
+
+CREATE TABLE t3 SELECT * FROM t1;
+ALTER TABLE t3 ADD PRIMARY KEY (d);
+ALTER TABLE t3 ADD KEY (a);
+ALTER TABLE t3 ADD KEY (a, b);
+ANALYZE TABLE t3;
+#SELECT * FROM t3;
+
+--echo ########################################################################
+connect (con1,localhost,test,,test);
+BEGIN;
+SELECT d,a,b,c FROM t1 partition (p0);
+SELECT d,a,b,c FROM t1 partition (p1);
+SELECT d,a,b,c FROM t1 partition (p2);
+SELECT d,a,b,c FROM t1 partition (p3);
+SELECT d,a,b,c FROM t1 partition (p4);
+SELECT d,a,b,c FROM t1 partition (p5);
+SELECT d,a,b,c FROM t1 partition (p6);
+SELECT d,a,b,c FROM t1 partition (p7);
+SELECT d,a,b,c FROM t1 partition (p8);
+SELECT d,a,b,c FROM t1 partition (p9);
+SELECT d,a,b,c FROM t1 partition (p10);
+SELECT d,a,b,c FROM t1 partition (p11);
+SELECT d,a,b,c FROM t1 partition (p12);
+SELECT d,a,b,c FROM t1 partition (p13);
+SELECT d,a,b,c FROM t1 partition (p14);
+SELECT d,a,b,c FROM t1 partition (p15);
+SELECT d,a,b,c FROM t1 partition (p16);
+SELECT d,a,b,c FROM t1 partition (p17);
+SELECT d,a,b,c FROM t1 partition (p18);
+SELECT d,a,b,c FROM t1 partition (p19);
+
+SELECT * FROM t1 WHERE a='01' FOR UPDATE ;
+SELECT * FROM t3 FORCE INDEX(a) WHERE a='01' FOR UPDATE ;
+
+connect (con2,localhost,test,,test);
+BEGIN;
+SET SESSION innodb_lock_wait_timeout=1;
+
+--echo #
+--echo # SHARE ...
+--error ER_LOCK_WAIT_TIMEOUT
+SELECT * FROM t1 LOCK IN SHARE MODE;
+--error ER_LOCK_WAIT_TIMEOUT
+SELECT * FROM t1 LOCK IN SHARE MODE NOWAIT;
+SELECT * FROM t1 ORDER BY d LOCK IN SHARE MODE SKIP LOCKED;
+SELECT a,count(b) FROM t1 GROUP BY a ORDER BY a LOCK IN SHARE MODE SKIP LOCKED;
+SELECT d,a,b,c FROM t1 partition (p1,p9,p11,p17) ORDER BY d
+ LOCK IN SHARE MODE SKIP LOCKED;
+SELECT d,a,b,c FROM t1 ORDER BY d LOCK IN SHARE MODE SKIP LOCKED;
+ANALYZE TABLE t3;
+SELECT d,a,b,c FROM t3 ORDER BY d LOCK IN SHARE MODE SKIP LOCKED;
+explain SELECT d,a,b,c FROM t3 ORDER BY d
+ LOCK IN SHARE MODE SKIP LOCKED;
+
+--echo #
+--echo # UPDATE ...
+--error ER_LOCK_WAIT_TIMEOUT
+SELECT * FROM t1 FOR UPDATE;
+--error ER_LOCK_WAIT_TIMEOUT
+SELECT * FROM t1 FOR UPDATE NOWAIT;
+SELECT * FROM t1 ORDER BY a FOR UPDATE SKIP LOCKED;
+SELECT a,count(b) FROM t1 GROUP BY a ORDER BY a FOR UPDATE SKIP LOCKED;
+SELECT d,a,b,c FROM t1 partition (p1,p9,p11,p17) ORDER BY d
+ FOR UPDATE SKIP LOCKED;
+SELECT d,a,b,c FROM t1 ORDER BY d FOR UPDATE SKIP LOCKED;
+SELECT d,a,b,c FROM t3 ORDER BY d FOR UPDATE SKIP LOCKED;
+
+connection con1;
+COMMIT;
+
+connection con1;
+BEGIN;
+SELECT * FROM t1 WHERE a='01' LOCK IN SHARE MODE ;
+SELECT * FROM t3 FORCE INDEX(a) WHERE a='01' LOCK IN SHARE MODE ;
+
+connection con2;
+BEGIN;
+SET SESSION innodb_lock_wait_timeout=1;
+
+--echo #
+--echo # SHARE ...
+SELECT * FROM t1 LOCK IN SHARE MODE;
+SELECT * FROM t1 LOCK IN SHARE MODE NOWAIT;
+SELECT * FROM t1 ORDER BY d LOCK IN SHARE MODE SKIP LOCKED;
+SELECT a,count(b) FROM t1 GROUP BY a ORDER BY a LOCK IN SHARE MODE SKIP LOCKED;
+SELECT d,a,b,c FROM t1 partition (p1,p9,p11,p17) ORDER BY d
+ LOCK IN SHARE MODE SKIP LOCKED;
+SELECT d,a,b,c FROM t1 ORDER BY d LOCK IN SHARE MODE SKIP LOCKED;
+ANALYZE TABLE t3;
+SELECT d,a,b,c FROM t3 ORDER BY d LOCK IN SHARE MODE SKIP LOCKED;
+explain SELECT d,a,b,c FROM t3 ORDER BY d
+ LOCK IN SHARE MODE SKIP LOCKED;
+
+--echo #
+--echo # UPDATE ...
+--error ER_LOCK_WAIT_TIMEOUT
+SELECT * FROM t1 FOR UPDATE;
+--error ER_LOCK_WAIT_TIMEOUT
+SELECT * FROM t1 FOR UPDATE NOWAIT;
+SELECT * FROM t1 ORDER BY a FOR UPDATE SKIP LOCKED;
+SELECT a,count(b) FROM t1 GROUP BY a ORDER BY a FOR UPDATE SKIP LOCKED;
+SELECT d,a,b,c FROM t1 partition (p1,p9,p11,p17) ORDER BY d
+ FOR UPDATE SKIP LOCKED;
+SELECT d,a,b,c FROM t1 ORDER BY d FOR UPDATE SKIP LOCKED;
+SELECT d,a,b,c FROM t3 ORDER BY d FOR UPDATE SKIP LOCKED;
+
+connection default;
+disconnect con1;
+disconnect con2;
+
+DROP TABLE t1, t2, t3;
+
+DROP USER test@localhost;
+DROP USER test2@localhost;
+set @@global.read_only= @start_read_only;
+set @@global.autocommit= @start_autocommit;
+set default_storage_engine= default;
diff --git a/mysql-test/suite/innodb/t/purge.test b/mysql-test/suite/innodb/t/purge.test
new file mode 100644
index 00000000..97c0fb86
--- /dev/null
+++ b/mysql-test/suite/innodb/t/purge.test
@@ -0,0 +1,113 @@
+--source include/have_innodb.inc
+--source include/have_innodb_16k.inc
+
+--echo # Bug #12429576 - Test an assertion failure on purge.
+CREATE TABLE t1_purge (
+A int,
+B blob, C blob, D blob, E blob,
+F blob, G blob, H blob,
+PRIMARY KEY (B(767), C(767), D(767), E(767), A),
+INDEX (A)
+) ENGINE=InnoDB ROW_FORMAT=DYNAMIC;
+
+INSERT INTO t1_purge VALUES (1,
+REPEAT('b', 766), REPEAT('c', 766), REPEAT('d', 766), REPEAT('e', 766),
+REPEAT('f', 766), REPEAT('g', 766), REPEAT('h', 766));
+
+CREATE TABLE t2_purge (
+A int PRIMARY KEY,
+B blob, C blob, D blob, E blob,
+F blob, G blob, H blob, I blob,
+J blob, K blob, L blob,
+INDEX (B(767))) ENGINE=InnoDB ROW_FORMAT=DYNAMIC;
+
+INSERT INTO t2_purge VALUES (1,
+REPEAT('b', 766), REPEAT('c', 766), REPEAT('d', 766), REPEAT('e', 766),
+REPEAT('f', 766), REPEAT('g', 766), REPEAT('h', 766), REPEAT('i', 766),
+REPEAT('j', 766), REPEAT('k', 766), REPEAT('l', 766));
+
+CREATE TABLE t3_purge (
+A int,
+B varchar(800), C varchar(800), D varchar(800), E varchar(800),
+F varchar(800), G varchar(800), H varchar(800),
+PRIMARY KEY (B(767), C(767), D(767), E(767), A),
+INDEX (A)
+) ENGINE=InnoDB ROW_FORMAT=DYNAMIC;
+
+INSERT INTO t3_purge SELECT * FROM t1_purge;
+
+CREATE TABLE t4_purge (
+A int PRIMARY KEY,
+B varchar(800), C varchar(800), D varchar(800), E varchar(800),
+F varchar(800), G varchar(800), H varchar(800), I varchar(800),
+J varchar(800), K varchar(800), L varchar(800),
+INDEX (B(767))) ENGINE=InnoDB ROW_FORMAT=DYNAMIC;
+
+INSERT INTO t4_purge SELECT * FROM t2_purge;
+
+# This would trigger the failure (Bug #12429576)
+# if purge gets a chance to run before DROP TABLE t1_purge, ....
+DELETE FROM t1_purge;
+DELETE FROM t2_purge;
+DELETE FROM t3_purge;
+DELETE FROM t4_purge;
+# We need to activate the purge thread before DROP TABLE.
+
+# Bug#12637786 - Assertion hit; ut_ad(dict_index_is_clust(index));
+# A secondary index tuple is found to be too long to fit into a page.
+# This test is not in innodb_8k or innodb_4k since the bug is not about
+# page size. It just tests the condition that caused the assertion.
+SET @r=REPEAT('a',500);
+CREATE TABLE t12637786(a int,
+ v1 varchar(500), v2 varchar(500), v3 varchar(500),
+ v4 varchar(500), v5 varchar(500), v6 varchar(500),
+ v7 varchar(500), v8 varchar(500), v9 varchar(500),
+ v10 varchar(500), v11 varchar(500), v12 varchar(500),
+ v13 varchar(500), v14 varchar(500), v15 varchar(500),
+ v16 varchar(500), v17 varchar(500), v18 varchar(500)
+) ENGINE=InnoDB ROW_FORMAT=DYNAMIC;
+CREATE INDEX idx1 ON t12637786(a,v1);
+INSERT INTO t12637786 VALUES(9,@r,@r,@r,@r,@r,@r,@r,@r,@r,@r,@r,@r,@r,@r,@r,@r,@r,@r);
+UPDATE t12637786 SET a=1000;
+DELETE FROM t12637786;
+# We need to activate the purge thread before DROP TABLE
+# to make sure it is able to clean up the old versions.
+
+--echo # Bug#12963823 - Test that the purge thread does not crash when
+# the number of indexes has changed since the UNDO record was logged.
+# This test is not in innodb_8k or innodb_4k since the bug is not about
+# page size. It just tests the condition that caused the crash.
+CREATE TABLE t12963823(a blob,b blob,c blob,d blob,e blob,f blob,g blob,h blob,
+ i blob,j blob,k blob,l blob,m blob,n blob,o blob,p blob)
+ ENGINE=innodb ROW_FORMAT=dynamic;
+SET @r = REPEAT('a', 767);
+INSERT INTO t12963823 VALUES (@r,@r,@r,@r, @r,@r,@r,@r, @r,@r,@r,@r, @r,@r,@r,@r);
+CREATE INDEX ndx_a ON t12963823 (a(500));
+CREATE INDEX ndx_b ON t12963823 (b(500));
+CREATE INDEX ndx_c ON t12963823 (c(500));
+CREATE INDEX ndx_d ON t12963823 (d(500));
+CREATE INDEX ndx_e ON t12963823 (e(500));
+CREATE INDEX ndx_f ON t12963823 (f(500));
+CREATE INDEX ndx_k ON t12963823 (k(500));
+CREATE INDEX ndx_l ON t12963823 (l(500));
+
+SET @r = REPEAT('b', 500);
+UPDATE t12963823 set a=@r,b=@r,c=@r,d=@r;
+UPDATE t12963823 set e=@r,f=@r,g=@r,h=@r;
+UPDATE t12963823 set i=@r,j=@r,k=@r,l=@r;
+UPDATE t12963823 set m=@r,n=@r,o=@r,p=@r;
+ALTER TABLE t12963823 DROP INDEX ndx_a;
+ALTER TABLE t12963823 DROP INDEX ndx_b;
+CREATE INDEX ndx_g ON t12963823 (g(500));
+CREATE INDEX ndx_h ON t12963823 (h(500));
+CREATE INDEX ndx_i ON t12963823 (i(500));
+CREATE INDEX ndx_j ON t12963823 (j(500));
+CREATE INDEX ndx_m ON t12963823 (m(500));
+CREATE INDEX ndx_n ON t12963823 (n(500));
+CREATE INDEX ndx_o ON t12963823 (o(500));
+CREATE INDEX ndx_p ON t12963823 (p(500));
+SHOW CREATE TABLE t12963823;
+# We need to activate the purge thread before DROP TABLE.
+
+-- source include/wait_all_purged.inc
+DROP TABLE t1_purge, t2_purge, t3_purge, t4_purge, t12637786, t12963823;
diff --git a/mysql-test/suite/innodb/t/purge_secondary.opt b/mysql-test/suite/innodb/t/purge_secondary.opt
new file mode 100644
index 00000000..2821c983
--- /dev/null
+++ b/mysql-test/suite/innodb/t/purge_secondary.opt
@@ -0,0 +1,4 @@
+--innodb-sys-tablestats
+--innodb_buffer_pool_size=5M
+--innodb_monitor_enable=module_buffer
+--skip-innodb-stats-persistent
diff --git a/mysql-test/suite/innodb/t/purge_secondary.test b/mysql-test/suite/innodb/t/purge_secondary.test
new file mode 100644
index 00000000..4e664109
--- /dev/null
+++ b/mysql-test/suite/innodb/t/purge_secondary.test
@@ -0,0 +1,172 @@
+--source include/have_innodb.inc
+--source include/have_sequence.inc
+
+--disable_query_log
+call mtr.add_suppression("InnoDB: Difficult to find free blocks in the buffer pool");
+--enable_query_log
+
+CREATE TABLE t1 (
+ a SERIAL, b CHAR(255) NOT NULL DEFAULT '', c BOOLEAN DEFAULT false,
+ l LINESTRING NOT NULL DEFAULT ST_linefromtext('linestring(448 -689,
+ 453 -684,451 -679,453 -677,458 -681,463 -681,468 -678,470 -676,470 -678,
+ 468 -675,472 -675,472 -675,474 -674,479 -676,477 -675,473 -676,475 1324,
+ 479 1319,484 1322,483 1323,486 1323,491 1328,492 1325,496 1325,498 1325,
+ 501 1330,498 1331,500 1331,504 1330,508 1329,512 1332,513 1337,518 1339,
+ 518 1339,513 1344,513 1344,512 1346,514 1351,515 1353,519 1358,518 1362,
+ 522 1365,525 1360,526 1362,527 1362,528 1367,525 1371,528 1366,532 1369,
+ 536 1374,539 1377,543 1379,539 1381,541 1382,543 1383,546 1388,549 1393,
+ 554 1393,554 1395,554 1392,550 1394,550 1392,546 1394,549 1397,550 1393,
+ 549 1394,554 1390,554 1391,549 1396,551 1396,547 1400,547 1402,551 1407,
+ 554 1412,554 1415,558 1418,463 -681,465 -677,465 -675,470 -670,470 -665,
+ 470 -660,470 -659,473 -656,476 -656,481 -655,482 -652,486 -654,486 -652,
+ 486 -648,491 -646,490 -651,494 -646,493 -644,493 -644,490 -644,491 2356,
+ 495 2359,495 2364,500 2359,503 5359,504 5364,509 5368,504 5367,499 5368,
+ 498 5371,498 5369,500 5370,504 5370,508 5370,511 5370,507 5374,508 5378,
+ 511 5382,507 5387,509 5389,512 5388,515 5393,520 5396,517 5397,517 5402,
+ 515 5404,520 5402,521 5405,525 5405,526 5408,530 7408,535 7413,533 7415,
+ 529 7412,532 7416,4532 7416,4534 7421,4533 7417,4536 7413,4536 7418,
+ 4540 3418,4545 3418,4549 3415,4551 3419,4554 3421,4559 3423,4559 3426,
+ 4557 3424,4561 3428,4558 3428,4563 3431,4565 3435,4569 3439,4569 3439,
+ 4569 3444,4567 3444,4572 3446,4577 3447,4581 3444,4581 3448,4584 3448,
+ 4579 3447,4580 3450,4583 3449,4583 3453,4587 3455,4588 3458,4593 3463,
+ 4598 3465,4601 3468,4598 3464,4598 3460,4593 5460,4595 5461,4600 5464,
+ 4600 5465,4601 5466,4606 5466,4608 5466,4605 5464,4608 5467,4607 5468,
+ 4609 5465,4614 5461,4618 5463,4621 5467,4623 5470,4622 5470,4622 5470,
+ 4625 6470,4627 6471,4627 6472,4627 6473,6627 6474,6625 6474,6628 6477,
+ 6633 6481,6633 6480,6637 6475,7637 6479,7638 6482,7643 6487,7644 6492,
+ 7647 6492,7648 6495,7646 6498,7650 6499,7646 6494,7644 6499,7644 6497,
+ 7644 6499,7647 6502,7649 6504,7650 6501,7647 6503,7649 6504,7650 6508,
+ 7651 6503,7652 6508,7655 6508,7650 6511,7655 6515,7658 6513,7663 6513,
+ 7665 6514,7669 6512,7667 6510,7664 6510,472 -675,477 -670,479 -666,
+ 482 -663,484 -668,484 -666,485 -664,481 -664,479 -659,482 -659,484 -658,
+ 483 -659,488 2341,493 2339,489 2338,491 2342,491 2346,494 2346,490 2348,
+ 493 2348,498 2349,498 2350,499 2349,502 2350,503 2348,506 2348,506 2348,
+ 507 2353,507 2355,504 2359,504 2364,504 2361,499 2365,502 2360,502 2358,
+ 503 2357,504 2353,504 2357,500 2356,497 2355,498 2355,500 2359,502 2361,
+ 505 2364,508 2364,506 2368,506 2370,504 2373,499 2373,496 2372,493 2377,
+ 497 2380,495 2383,496 7383,493 7386,497 7391,494 7387,495 7389,498 7392,
+ 498 7392,495 7395,493 7398,498 7401,498 7403,503 7400,498 8400,501 8401,
+ 503 8401,503 8401,501 10401,496 10396,491 10401,492 10399,493 10403,
+ 496 10403,491 10403,493 10407,489 10410,493 10407,489 10403,498 7403,
+ 497 7399,496 7403,500 7405,500 7407,503 7411,508 7415,511 7415,511 7420,
+ 515 7420,520 7423,523 7423,520 7427,523 7427,523 7427,522 7432,525 4432,
+ 527 4434,530 4437,534 4441,529 4446,529 4441,534 4436,537 4436,535 4437,
+ 532 4437,534 4432,535 4429,538 4430,542 4427,542 4431,538 4431,541 4431,
+ 541 4433,543 4433,545 4432,549 4428,552 4426,556 4427,557 4423,560 4427,
+ 561 4428,558 4430,559 4434,559 4432,561 4434,561 4437,563 4435,559 4430,
+ 561 4435,4561 4437,4566 4441,4568 4446,4568 4450,4569 4455,4565 4458,
+ 4561 4463,4561 9463,4564 9463,4565 9461,9565 9463,9560 9467,9560 9466,
+ 9555 9469,9555 9471,9559 9469,9557 9473,9553 9478,9555 9480,9557 9481,
+ 9557 9481,9557 9483,9562 9487,9558 9487,9558 9490,9561 9493,9562 9493,
+ 9557 9493,9560 9496,9555 9501,9553 9503,9553 9506,9557 9510,9558 9511,
+ 9561 9514,9563 9512,9568 9514,9567 9514,9567 13514,9570 13517,9566 13521,
+ 9571 13521,9571 13526,9573 13521,9571 13521,9576 10521,9580 10526,9582 10525,
+ 9584 10528,9584 10531,9584 10533,9589 10533,9588 10537,9588 10541,9589 10542,
+ 9593 10544,9595 10540,9597 10541,9600 10545,9601 15545,9603 15549,9605 15553,
+ 9601 15558,9601 15553,9605 15551,9605 15550,9605 15554,9607 15556,9605 15556,
+ 9604 15561,9607 15559,9603 15559,9603 15562,9604 15563,9608 15566,9612 15570,
+ 9617 15565,9622 15568,9627 15566,9628 15564,9629 15564,9633 15569,9636 15569,
+ 9634 15571,9634 15572,9636 15574,9634 15570,9629 15570,9631 15567,9629 15570,
+ 9626 15574,9626 15575,498 7401,502 7401,506 7397,506 7395,502 7398,497 7401,
+ 502 7402,505 7397,508 7400,504 7404,3504 7409,3505 7405,3508 7410,3511 7413,
+ 3511 7416,3511 7419,3511 7419,3513 7421,3517 7424,3519 7426,3520 11426,
+ 3523 11421,3527 11418,3530 11415,3530 11416,3533 11418,7533 11415,7531 11415,
+ 7531 11417,7536 11420,7541 11424,7543 11425,7543 11427,7543 11429,7540 11429,
+ 7542 11425,7541 11420,7542 11421,7542 11422,7540 11424,7540 11423,7543 11422,
+ 7546 11426,7550 11431,7553 11436,7555 16436,7553 16438,7558 16438,7559 16438,
+ 7560 16439,7565 16437,7560 16435,7563 16435,7566 16440,7566 16444,7564 16447,
+ 7559 16443,7561 16443,7566 16448,7570 16451,7574 16456,7578 16459,
+ 12578 16459,12578 20459,12577 20456,12581 20454,12585 20456,12585 20456,
+ 12585 20456,12583 20456,12579 20459,12580 20461,12580 20462,12580 20460,
+ 12585 20465,12586 20467,12590 20470,12590 20470,12589 20471,12584 20471,
+ 12589 20471,9589 20472,9594 20472,9595 20472,9596 20477,9598 20482,
+ 9603 20480,9608 20484,9613 20484,9610 20486,9608 20488,9608 20489,9610 20489,
+ 9614 20486,9619 20481,9620 20481,9618 21481,9621 21483,9626 21483,9628 21485,
+ 9623 21487,9622 21490,9626 21493,9621 21495,9626 21498,9622 21499,9624 21504,
+ 9625 21499,9629 21501,9633 21498,9637 21495,9639 21498,9644 21501,9557 9481,
+ 9560 9485,9561 9490,9563 9488,9560 9486,9558 9488,9561 9492,9563 9495,
+ 9567 9492,9567 9488,9564 9490,9559 9495,9559 9498,9557 9502,9562 9506,
+ 9564 9509,9569 9512,9569 9516,9569 9518,9569 9515,9571 9513,9571 9512,
+ 9573 9513,9578 9516,9581 9516,9585 11516,9585 11521,9590 10521,9586 10524,
+ 9589 10529,9589 10527,9589 10527,9594 10532,9594 10534,9598 10536,9598 10540,
+ 9600 10542,9604 10538,9607 10538,9609 10543,9613 10538,9613 10533,9613 10537,
+ 9610 10537,9614 10542,9609 10542,9610 10543,9610 10548,9611 10553,9616 7553,
+ 9620 7553,9621 7557,9618 7559,9618 7554,9622 7557,9622 7561,9622 7556,
+ 9622 7560,9619 7560,9620 7565,9622 7563,9627 7566,9630 7570,9630 7571,
+ 9632 7573,9637 7576,9639 7578,9640 7576,9640 7579,9640 7575,9642 7570,
+ 9646 7570,9651 7574,9653 7577,9652 7572,9653 7576,9653 7576,9651 7581,
+ 9656 7585,9660 7586,9659 7591,9657 7594,9661 7598,9664 7602,9668 12602,
+ 9673 12604,9676 12606,9679 12602,9682 12605,9677 12610,9674 12606,9674 12601,
+ 9674 12603,9672 9603,9668 9605,9671 9606,9668 9611,9668 9606,9671 9611,
+ 9675 9615,9677 9620,9678 9622,9679 9624,9684 9626,9685 9627,9685 9622,
+ 9685 9626,9689 9628,9694 9633,9699 9637,9699 9637,9704 9636,9708 9637,
+ 9709 9638,9707 9639,9705 9642,9707 9647,9710 9649,9711 9653,9716 9649,
+ 9716 9648,9720 9650,9721 9648,9723 9648,9726 4648,12726 4653,12731 4655,
+ 12734 4660,12730 4661,12733 4664,12733 4665,12735 4670,12737 4674,12741 4674,
+ 12738 4675,12740 4675,12737 4675,12742 4678,12743 4681,12746 4677)'),
+ INDEX(b,c), SPATIAL INDEX `sidx`(l)
+) ENGINE=InnoDB ROW_FORMAT=REDUNDANT;
+INSERT INTO t1 () VALUES (),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),();
+SELECT LENGTH(l) FROM t1;
+INSERT INTO t1 (a) SELECT NULL FROM t1;
+INSERT INTO t1 (a) SELECT NULL FROM t1;
+CHECK TABLE t1;
+UPDATE t1 SET c=true, l=ST_linefromtext('linestring(0 0,1 1,2 2)');
+DELETE FROM t1;
+CHECK TABLE t1;
+
+source include/wait_all_purged.inc;
+
+ANALYZE TABLE t1;
+SELECT OTHER_INDEX_SIZE FROM INFORMATION_SCHEMA.INNODB_SYS_TABLESTATS
+WHERE NAME='test/t1';
+
+# Work around MDEV-13942, Dropping the spatial index to avoid the possible hang
+ALTER TABLE t1 DROP INDEX `sidx`;
+
+INSERT INTO t1 (a) SELECT * FROM seq_1_to_544;
+ALTER TABLE t1 FORCE, ALGORITHM=INPLACE;
+ALTER TABLE t1 FORCE, ALGORITHM=INPLACE;
+
+SELECT (variable_value > 0) FROM information_schema.global_status
+WHERE LOWER(variable_name) LIKE 'INNODB_BUFFER_POOL_PAGES_FLUSHED';
+
+--echo # Note: The OTHER_INDEX_SIZE does not cover any SPATIAL INDEX.
+--echo # To test that all indexes were emptied, replace DROP TABLE
+--echo # with the following, and examine the root pages in t1.ibd:
+--echo # FLUSH TABLES t1 FOR EXPORT;
+--echo # UNLOCK TABLES;
+
+DROP TABLE t1;
+
+--echo #
+--echo # MDEV-29666 InnoDB fails to purge secondary index records
+--echo # when indexed virtual columns exist
+--echo #
+
+CREATE TABLE t1 (a INT, b INT, a1 INT AS(a) VIRTUAL,
+INDEX(a1),INDEX(b)) ENGINE=InnoDB;
+INSERT INTO t1 SET a=1, b=1;
+
+UPDATE t1 SET a=2, b=3;
+let DATADIR=`select @@datadir`;
+let PAGE_SIZE=`select @@innodb_page_size`;
+
+source include/wait_all_purged.inc;
+FLUSH TABLE t1 FOR EXPORT;
+
+perl;
+my $ps = $ENV{PAGE_SIZE};
+my $file = "$ENV{DATADIR}/test/t1.ibd";
+open(FILE, "<", $file) or die "Unable to open $file\n";
+die "Unable to read $file\n" unless
+ sysread(FILE, $_, 6*$ps) == 6*$ps;
+close(FILE);
+print "page 4: N_RECS=0x", unpack("H*", substr($_, 4 * $ps + 54, 2)), "\n";
+print "page 5: N_RECS=0x", unpack("H*", substr($_, 5 * $ps + 54, 2)), "\n";
+EOF
+
+UNLOCK TABLES;
+DROP TABLE t1;
+
+--echo # End of 10.3 tests
diff --git a/mysql-test/suite/innodb/t/purge_thread_shutdown.test b/mysql-test/suite/innodb/t/purge_thread_shutdown.test
new file mode 100644
index 00000000..53b375b8
--- /dev/null
+++ b/mysql-test/suite/innodb/t/purge_thread_shutdown.test
@@ -0,0 +1,43 @@
+source include/have_innodb.inc;
+source include/not_embedded.inc;
+source include/have_debug.inc;
+
+connect con1, localhost, root;
+create table t1 (a int) engine=innodb;
+insert t1 values (1),(2),(3),(4);
+delete from t1 where a=1;
+
+select user,state from information_schema.processlist order by 2;
+
+set global debug_dbug='+d,only_kill_system_threads';
+set global innodb_fast_shutdown=0;
+
+--let $_expect_file_name= `select regexp_replace(@@tmpdir, '^.*/','')`
+--let $_expect_file_name= $MYSQLTEST_VARDIR/tmp/$_expect_file_name.expect
+exec echo "wait" > $_expect_file_name;
+send shutdown;
+
+connection default;
+disconnect con1;
+
+sleep 5;
+select user,state from information_schema.processlist order by 2;
+set global innodb_fast_shutdown=1;
+
+let $wait_condition=select count(*) = 0 from information_schema.processlist where user='system user';
+source include/wait_condition.inc;
+select user,state from information_schema.processlist order by 2;
+
+delete from t1 where a=3;
+error ER_WRONG_VALUE_FOR_VAR;
+set global innodb_fast_shutdown=0;
+
+# Get id with space prefix to ensure that replace_result doesn't replace
+# the error code
+let $me=`select concat(' ', connection_id())`;
+replace_result $me ID;
+error ER_CONNECTION_KILLED, 2026;
+eval kill $me;
+
+source include/start_mysqld.inc;
+drop table t1;
diff --git a/mysql-test/suite/innodb/t/read_only_recover_committed.test b/mysql-test/suite/innodb/t/read_only_recover_committed.test
new file mode 100644
index 00000000..50863f0c
--- /dev/null
+++ b/mysql-test/suite/innodb/t/read_only_recover_committed.test
@@ -0,0 +1,99 @@
+--source include/have_innodb.inc
+--source include/have_debug.inc
+--source include/have_debug_sync.inc
+--source include/no_valgrind_without_big.inc
+# need to restart server
+--source include/not_embedded.inc
+--source include/no_valgrind_without_big.inc
+
+--disable_query_log
+# Ignore messages from the innodb_force_recovery=5 startup.
+call mtr.add_suppression("\\[ERROR\\] InnoDB: Failed to find tablespace for table `test`\\.`t` in the cache");
+call mtr.add_suppression("\\[Warning\\] InnoDB: Allocated tablespace ID.* for test/t, old maximum was 0");
+FLUSH TABLES;
+--enable_query_log
+
+--connect(con1, localhost, root)
+CREATE TABLE t(a INT PRIMARY KEY) ENGINE=InnoDB;
+INSERT INTO t VALUES(1);
+BEGIN;
+# Generate insert_undo log.
+INSERT INTO t VALUES(2);
+# Generate update_undo log.
+UPDATE t SET a=20 WHERE a=2;
+--connect(con2, localhost, root)
+--echo # Normal MariaDB shutdown would roll back the above transaction.
+--echo # We want the transaction to remain open, so we will kill the server
+--echo # after ensuring that any non-transactional files are clean.
+FLUSH TABLES;
+--echo # Create another transaction that will be recovered as COMMITTED.
+BEGIN;
+# Generate multiple pages of both insert_undo and update_undo, so that
+# the state TRX_UNDO_CACHE will not be chosen.
+--disable_query_log
+let $n= 10000;
+while ($n) {
+dec $n;
+eval INSERT INTO t VALUES(-$n);
+eval DELETE FROM t WHERE a=-$n;
+}
+--enable_query_log
+SET DEBUG_SYNC='after_trx_committed_in_memory SIGNAL committed WAIT_FOR ever';
+send COMMIT;
+
+connection default;
+SET DEBUG_SYNC='now WAIT_FOR committed';
+--echo # Ensure that the above transactions become durable.
+SET GLOBAL innodb_flush_log_at_trx_commit=1;
+BEGIN;
+INSERT INTO t VALUES(-10000);
+DELETE FROM t WHERE a=-10000;
+COMMIT;
+--let $restart_parameters= --innodb-force-recovery=3
+--let $shutdown_timeout= 0
+--source include/restart_mysqld.inc
+--let $shutdown_timeout= 30
+--disconnect con1
+--disconnect con2
+SELECT * FROM t;
+SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED;
+--disable_ps2_protocol
+SELECT * FROM t;
+--enable_ps2_protocol
+# refused on MySQL 5.6, MariaDB 10.0, 10.1, but not MariaDB 10.2+
+UPDATE t SET a=3 WHERE a=1;
+--let $restart_parameters= --innodb-read-only
+--source include/restart_mysqld.inc
+SET GLOBAL innodb_status_output= @@GLOBAL.innodb_status_output;
+--echo # Starting with MariaDB 10.2, innodb_read_only implies READ UNCOMMITTED.
+--echo # In earlier versions, this would return the last committed version
+--echo # (only a=3; no record for a=20)!
+SELECT * FROM t;
+SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED;
+SELECT * FROM t;
+--let $restart_parameters= --innodb-force-recovery=5
+--source include/restart_mysqld.inc
+--echo #
+--echo # MDEV-15418 innodb_force_recovery=5 displays bogus warnings
+--echo # about too new transaction identifier
+--echo #
+--echo # With the fix, innodb_force_recovery=5 implies READ UNCOMMITTED.
+SELECT * FROM t;
+SET TRANSACTION ISOLATION LEVEL SERIALIZABLE;
+SELECT * FROM t;
+SET TRANSACTION ISOLATION LEVEL READ COMMITTED;
+SELECT * FROM t;
+
+--echo #
+--echo # MDEV-27332 SIGSEGV in fetch_data_into_cache
+--echo #
+BEGIN;
+SELECT trx_state FROM information_schema.innodb_trx;
+COMMIT;
+--let $restart_parameters=
+--source include/restart_mysqld.inc
+SELECT * FROM t;
+DROP TABLE t;
+let SEARCH_FILE= $MYSQLTEST_VARDIR/log/mysqld.1.err;
+--let SEARCH_PATTERN= Rolled back recovered transaction [^0]
+--source include/search_pattern_in_file.inc
diff --git a/mysql-test/suite/innodb/t/read_only_recovery.test b/mysql-test/suite/innodb/t/read_only_recovery.test
new file mode 100644
index 00000000..47146213
--- /dev/null
+++ b/mysql-test/suite/innodb/t/read_only_recovery.test
@@ -0,0 +1,45 @@
+--source include/have_innodb.inc
+# need to restart server
+--source include/not_embedded.inc
+
+--connect(con1, localhost, root)
+CREATE TABLE t(a INT PRIMARY KEY) ENGINE=InnoDB;
+INSERT INTO t VALUES(1);
+BEGIN;
+# Generate insert_undo log.
+INSERT INTO t VALUES(2);
+# Generate update_undo log.
+DELETE FROM t WHERE a=2;
+--connection default
+--echo # Normal MariaDB shutdown would roll back the above transaction.
+--echo # We want the transaction to remain open, so we will kill the server
+--echo # after ensuring that any non-transactional files are clean.
+FLUSH TABLES;
+--echo # Ensure that the above incomplete transaction becomes durable.
+SET GLOBAL innodb_flush_log_at_trx_commit=1;
+BEGIN;
+INSERT INTO t VALUES(0);
+DELETE FROM t WHERE a=0;
+COMMIT;
+--let $restart_parameters= --innodb-force-recovery=3
+--let $shutdown_timeout= 0
+--source include/restart_mysqld.inc
+--let $shutdown_timeout= 30
+--disconnect con1
+SELECT * FROM t;
+SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED;
+SELECT * FROM t;
+UPDATE t SET a=3 WHERE a=1;
+--let $restart_parameters= --innodb-read-only
+--source include/restart_mysqld.inc
+--echo # Starting with MariaDB 10.2, innodb_read_only implies READ UNCOMMITTED.
+--echo # In earlier versions, this would return the last committed version
+--echo # (empty table)!
+SELECT * FROM t;
+SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED;
+SELECT * FROM t;
+SET GLOBAL innodb_max_purge_lag_wait=0;
+--let $restart_parameters=
+--source include/restart_mysqld.inc
+SELECT * FROM t;
+DROP TABLE t;
diff --git a/mysql-test/suite/innodb/t/readahead.test b/mysql-test/suite/innodb/t/readahead.test
new file mode 100644
index 00000000..d7063442
--- /dev/null
+++ b/mysql-test/suite/innodb/t/readahead.test
@@ -0,0 +1,25 @@
+--source include/have_innodb.inc
+--source include/have_innodb_max_16k.inc
+# Embedded server tests do not support restarting
+--source include/not_embedded.inc
+
+--echo # Bug#25330449 ASSERT SIZE==SPACE->SIZE DURING BUF_READ_AHEAD_RANDOM
+
+let $MYSQLD_DATADIR=`SELECT @@datadir`;
+--disable_query_log
+SET GLOBAL innodb_read_only_compressed=OFF;
+--enable_query_log
+CREATE TABLE t1 (a INT PRIMARY KEY) ENGINE=INNODB ROW_FORMAT=COMPRESSED;
+
+--source include/shutdown_mysqld.inc
+--remove_file $MYSQLD_DATADIR/ib_buffer_pool
+
+--write_file $MYSQLD_DATADIR/ib_buffer_pool
+EOF
+
+--source include/start_mysqld.inc
+SET @saved = @@GLOBAL.innodb_random_read_ahead;
+SET GLOBAL innodb_random_read_ahead = 1;
+
+DROP TABLE t1;
+SET GLOBAL innodb_random_read_ahead = @saved;
diff --git a/mysql-test/suite/innodb/t/recovery_memory.opt b/mysql-test/suite/innodb/t/recovery_memory.opt
new file mode 100644
index 00000000..7207fd27
--- /dev/null
+++ b/mysql-test/suite/innodb/t/recovery_memory.opt
@@ -0,0 +1 @@
+--innodb_buffer_pool_size=1073741824
diff --git a/mysql-test/suite/innodb/t/recovery_memory.test b/mysql-test/suite/innodb/t/recovery_memory.test
new file mode 100644
index 00000000..145b39d5
--- /dev/null
+++ b/mysql-test/suite/innodb/t/recovery_memory.test
@@ -0,0 +1,51 @@
+--source include/have_innodb.inc
+--source include/big_test.inc
+--source include/have_sequence.inc
+--source include/maybe_debug.inc
+call mtr.add_suppression("InnoDB: The change buffer is corrupted");
+call mtr.add_suppression("InnoDB: Plugin initialization aborted at srv0start.cc");
+call mtr.add_suppression("Plugin 'InnoDB' init function returned error");
+call mtr.add_suppression("Plugin 'InnoDB' registration as a STORAGE ENGINE failed.");
+CREATE TABLE t1(c TEXT, KEY(c(3072)))ENGINE=InnoDB;
+DELIMITER |;
+
+CREATE PROCEDURE dorepeat()
+ LOOP
+ INSERT INTO t1 VALUES ('abc');
+ UPDATE t1 SET c='cba';
+ END LOOP
+|
+
+DELIMITER ;|
+connect(con1,localhost,root,,,);
+send CALL dorepeat();
+connection default;
+sleep 10;
+let $shutdown_timeout=0;
+let $restart_parameters=--innodb_buffer_pool_size=5242880;
+--source include/restart_mysqld.inc
+DROP TABLE t1;
+DROP PROCEDURE dorepeat;
+
+--echo #
+--echo # MDEV-30552 InnoDB recovery crashes when error
+--echo # handling scenario
+--echo #
+if ($have_debug) {
+SET DEBUG_DBUG="+d,ib_log_checkpoint_avoid_hard";
+let $restart_parameters=--innodb_buffer_pool_size=5242880 --debug_dbug="+d,ibuf_init_corrupt";
+}
+if (!$have_debug) {
+--echo SET DEBUG_DBUG="+d,ib_log_checkpoint_avoid_hard";
+let $restart_parameters=--innodb_buffer_pool_size=5242880;
+}
+CREATE TABLE t1(f1 INT NOT NULL)ENGINE=InnoDB;
+INSERT INTO t1 SELECT * FROM seq_1_to_65536;
+let $restart_noprint=1;
+let $shutdown_timeout=0;
+--source include/restart_mysqld.inc
+let $restart_noprint=0;
+let $restart_parameters=;
+--source include/restart_mysqld.inc
+SHOW CREATE TABLE t1;
+DROP TABLE t1;
diff --git a/mysql-test/suite/innodb/t/recovery_shutdown.test b/mysql-test/suite/innodb/t/recovery_shutdown.test
new file mode 100644
index 00000000..968ea628
--- /dev/null
+++ b/mysql-test/suite/innodb/t/recovery_shutdown.test
@@ -0,0 +1,73 @@
+--source include/have_innodb.inc
+--source include/not_embedded.inc
+--source include/no_valgrind_without_big.inc
+--source include/have_sequence.inc
+
+# Flush any open myisam tables from previous tests
+FLUSH TABLES;
+call mtr.add_suppression("Found 1 prepared XA transactions");
+
+--echo #
+--echo # MDEV-13797 InnoDB may hang if shutdown is initiated soon after startup
+--echo # while rolling back recovered incomplete transactions
+--echo #
+
+let $size = 100;
+let $trx = 8;
+
+let $c = $trx;
+connect (con$c,localhost,root,,);
+eval CREATE TABLE t$c (a SERIAL, b INT UNIQUE, c INT UNIQUE) ENGINE=InnoDB;
+XA START 'x';
+eval INSERT INTO t$c (a) SELECT NULL FROM seq_1_to_$size;
+eval UPDATE t$c SET a=a+$size, b=a;
+eval DELETE FROM t$c;
+XA END 'x';
+XA PREPARE 'x';
+dec $c;
+while ($c)
+{
+connect (con$c,localhost,root,,);
+eval CREATE TABLE t$c (a SERIAL, b INT UNIQUE, c INT UNIQUE) ENGINE=InnoDB;
+BEGIN;
+eval INSERT INTO t$c (a) SELECT NULL FROM seq_1_to_$size;
+eval UPDATE t$c SET a=a+$size, b=a;
+eval DELETE FROM t$c;
+dec $c;
+}
+
+INSERT INTO t1(a) SELECT NULL FROM seq_1_to_1600;
+
+--connection default
+SET GLOBAL innodb_flush_log_at_trx_commit=1;
+CREATE TABLE MDEV_29559 (a TINYINT UNSIGNED PRIMARY KEY, KEY(a)) ENGINE=InnoDB;
+INSERT INTO MDEV_29559 VALUES (0x69);
+
+FLUSH TABLES;
+
+--let $shutdown_timeout=0
+--source include/restart_mysqld.inc
+--let $shutdown_timeout=60
+
+# Perform a slow shutdown in order to roll back all recovered transactions
+# and to avoid locking conflicts with the DROP TABLE below.
+XA RECOVER;
+--disable_query_log
+SET GLOBAL innodb_fast_shutdown=0;
+--source include/restart_mysqld.inc
+
+--disable_query_log
+let $c = $trx;
+disconnect con$c;
+XA ROLLBACK 'x';
+eval DROP TABLE t$c;
+dec $c;
+while ($c)
+{
+disconnect con$c;
+eval DROP TABLE t$c;
+dec $c;
+}
+--enable_query_log
+
+DROP TABLE MDEV_29559;
diff --git a/mysql-test/suite/innodb/t/rename_table.opt b/mysql-test/suite/innodb/t/rename_table.opt
new file mode 100644
index 00000000..1852495a
--- /dev/null
+++ b/mysql-test/suite/innodb/t/rename_table.opt
@@ -0,0 +1,2 @@
+--innodb
+--innodb-sys-tablespaces
diff --git a/mysql-test/suite/innodb/t/rename_table.test b/mysql-test/suite/innodb/t/rename_table.test
new file mode 100644
index 00000000..654f8809
--- /dev/null
+++ b/mysql-test/suite/innodb/t/rename_table.test
@@ -0,0 +1,61 @@
+--source include/have_innodb.inc
+--source include/not_embedded.inc
+
+call mtr.add_suppression("InnoDB: In RENAME TABLE table `test`.`t4` is referenced in foreign key constraints which are not compatible with the new table definition.");
+
+CREATE DATABASE test_jfg;
+CREATE DATABASE test_jfg2;
+CREATE TABLE test_jfg.test (a int unsigned PRIMARY KEY) ENGINE=InnoDB;
+RENAME TABLE test_jfg.test TO test_jfg2.test;
+
+SELECT REPLACE(filename,'\\','/') path
+FROM INFORMATION_SCHEMA.INNODB_SYS_TABLESPACES WHERE filename LIKE '%test%';
+
+DROP DATABASE test_jfg;
+
+--source include/restart_mysqld.inc
+
+DROP DATABASE test_jfg2;
+
+CREATE DATABASE abc_def;
+CREATE DATABASE abc_def2;
+
+CREATE TABLE abc_def.test (a int unsigned PRIMARY KEY) ENGINE=InnoDB;
+RENAME TABLE abc_def.test TO abc_def2.test1;
+
+SELECT REPLACE(filename,'\\','/') path
+FROM INFORMATION_SCHEMA.INNODB_SYS_TABLESPACES WHERE filename LIKE '%test%';
+
+DROP DATABASE abc_def;
+
+--source include/restart_mysqld.inc
+
+DROP DATABASE abc_def2;
+
+call mtr.add_suppression("InnoDB: (Operating system error|Error number \\d+ means|Cannot rename file)");
+
+CREATE TABLE t1 (a INT) ENGINE=InnoDB;
+--replace_result "\\" "/"
+--error ER_ERROR_ON_RENAME
+RENAME TABLE t1 TO non_existing_db.t1;
+
+--let SEARCH_PATTERN= \[ERROR\] InnoDB: Cannot rename file '.*t1\.ibd' to '.*non_existing_db
+let SEARCH_FILE= $MYSQLTEST_VARDIR/log/mysqld.1.err;
+--source include/search_pattern_in_file.inc
+
+# Cleanup
+DROP TABLE t1;
+
+--echo #
+--echo # MDEV-25509 Atomic DDL: Assertion `err != DB_DUPLICATE_KEY'
+--echo # fails after previous error upon multi-RENAME
+--echo #
+SET FOREIGN_KEY_CHECKS= OFF;
+CREATE TABLE t1 (pk INT PRIMARY KEY, f INT, FOREIGN KEY (f) REFERENCES t4 (x)) ENGINE=InnoDB;
+ALTER TABLE t1 DROP KEY f;
+CREATE TABLE t2 (a INT) ENGINE=InnoDB;
+--error ER_ERROR_ON_RENAME
+RENAME TABLE t1 TO t3, t3 TO t4;
+RENAME TABLE t2 TO t3;
+DROP TABLE t3, t1;
+SET FOREIGN_KEY_CHECKS=DEFAULT;
diff --git a/mysql-test/suite/innodb/t/restart.opt b/mysql-test/suite/innodb/t/restart.opt
new file mode 100644
index 00000000..ce43e89c
--- /dev/null
+++ b/mysql-test/suite/innodb/t/restart.opt
@@ -0,0 +1,2 @@
+--loose-innodb_disable_resize_buffer_pool_debug=0
+--innodb-buffer-pool-chunk-size=1M
diff --git a/mysql-test/suite/innodb/t/restart.test b/mysql-test/suite/innodb/t/restart.test
new file mode 100644
index 00000000..8507f182
--- /dev/null
+++ b/mysql-test/suite/innodb/t/restart.test
@@ -0,0 +1,171 @@
+--source include/innodb_page_size.inc
+--source include/not_embedded.inc
+--source include/have_symlink.inc
+--source include/not_as_root.inc
+
+let datadir= `select @@datadir`;
+let page_size= `select @@innodb_page_size`;
+let tmp_in_vardir=$MYSQLTEST_VARDIR/tmp;
+
+--echo #
+--echo # MDEV-15333 MariaDB (still) slow start
+--echo #
+
+# Ensure that on normal startup, no data files are read.
+# Note: just like in MySQL, all .ibd files will still be
+# opened at least once.
+
+--echo # FIXME: Unlike MySQL, maybe MariaDB should not read the .ibd files
+--echo # of tables with .isl file or DATA DIRECTORY attribute.
+call mtr.add_suppression("\\[ERROR\\] InnoDB: MySQL-8\\.0 tablespace in ");
+call mtr.add_suppression("\\[ERROR\\] InnoDB: Restart in MySQL for migration/recovery\\.");
+
+--echo # FIXME: This is much more noisy than MariaDB 10.1!
+call mtr.add_suppression("\\[ERROR\\] InnoDB: Tablespace flags are invalid in datafile: .*test.t[rcd]\\.ibd");
+call mtr.add_suppression("\\[ERROR\\] InnoDB: Operating system error number .* in a file operation\\.");
+call mtr.add_suppression("\\[ERROR\\] InnoDB: The error means the system cannot find the path specified\\.");
+call mtr.add_suppression("\\[Warning\\] InnoDB: Ignoring tablespace for test/td because it could not be opened\\.");
+
+CREATE TABLE tr(a INT)ENGINE=InnoDB ROW_FORMAT=REDUNDANT;
+CREATE TABLE tc(a INT)ENGINE=InnoDB ROW_FORMAT=COMPACT
+PAGE_COMPRESSED=1 PAGE_COMPRESSION_LEVEL=9;
+--replace_result $tmp_in_vardir MYSQL_TMP_DIR
+eval CREATE TABLE td(a INT)ENGINE=InnoDB ROW_FORMAT=DYNAMIC
+STATS_PERSISTENT=0 DATA DIRECTORY='$tmp_in_vardir';
+
+--source include/shutdown_mysqld.inc
+
+--move_file $datadir/test/tr.ibd $datadir/test/tr0.ibd
+--move_file $datadir/test/tc.ibd $datadir/test/tc0.ibd
+--move_file $tmp_in_vardir/test/td.ibd $datadir/test/td0.ibd
+# TODO: test that MariaDB does not even attempt to open the files
+#--mkdir $datadir/test/tr.ibd
+#--mkdir $datadir/test/tc.ibd
+#--mkdir $tmp_in_vardir/test/td.ibd
+
+perl;
+die unless open OUT, ">", "$ENV{datadir}/test/tr.ibd";
+print OUT "foo " x $ENV{page_size};
+close OUT or die;
+die unless open OUT, ">", "$ENV{datadir}/test/tc.ibd";
+print OUT "bar " x $ENV{page_size};
+close OUT or die;
+die unless open OUT, ">", "$ENV{tmp_in_vardir}/test/td.ibd";
+print OUT "Xyz " x $ENV{page_size};
+close OUT or die;
+die unless open ISL, "+<", "$ENV{datadir}/test/td.isl";
+$_=<ISL>;
+if (m|^[a-zA-Z]:|)
+{
+ tr|/|\\|;
+ seek(ISL, 0, SEEK_SET) or die;
+ print ISL or die;
+}
+close ISL or die;
+EOF
+
+--let $restart_parameters= --skip-innodb-buffer-pool-load-at-startup
+--source include/start_mysqld.inc
+--let $restart_parameters=
+
+SELECT COUNT(*) FROM INFORMATION_SCHEMA.ENGINES
+WHERE engine = 'innodb'
+AND support IN ('YES', 'DEFAULT', 'ENABLED');
+
+--source include/shutdown_mysqld.inc
+
+# TODO: test that MariaDB does not even attempt to open the files
+#--rmdir $datadir/test/tr.ibd
+#--rmdir $datadir/test/tc.ibd
+#--rmdir $tmp_in_vardir/test/td.ibd
+--remove_file $datadir/test/tr.ibd
+--remove_file $datadir/test/tc.ibd
+--remove_file $tmp_in_vardir/test/td.ibd
+
+--move_file $datadir/test/tr0.ibd $datadir/test/tr.ibd
+--move_file $datadir/test/tc0.ibd $datadir/test/tc.ibd
+--move_file $datadir/test/td0.ibd $tmp_in_vardir/test/td.ibd
+
+--source include/start_mysqld.inc
+SELECT * FROM tr;
+SELECT * FROM tc;
+SELECT * FROM td;
+DROP TABLE tr,tc,td;
+
+--echo #
+--echo # MDEV-27467 innodb to enfore the minimum innodb_buffer_pool_size in SET (resize) the same as startup
+--echo #
+
+let $wait_timeout = 180;
+let $wait_condition =
+ SELECT SUBSTR(variable_value, 1, 30) = 'Completed resizing buffer pool'
+ FROM information_schema.global_status
+ WHERE LOWER(variable_name) = 'innodb_buffer_pool_resize_status';
+
+SELECT @@innodb_buffer_pool_size INTO @innodb_buffer_pool_size_orig;
+SELECT CEILING((256 + 64) * @@innodb_page_size / 1048576) * 1048576 INTO @min_pool_size;
+--error ER_WRONG_VALUE_FOR_VAR
+EXECUTE IMMEDIATE 'SET GLOBAL innodb_buffer_pool_size = ?' USING (@min_pool_size -1);
+
+SHOW WARNINGS;
+
+EXECUTE IMMEDIATE 'SET GLOBAL innodb_buffer_pool_size = ?' USING (@min_pool_size);
+
+--source include/wait_condition.inc
+
+SET GLOBAL innodb_buffer_pool_size = @innodb_buffer_pool_size_orig;
+
+--echo #
+--echo # MDEV-27882 Innodb - recognise MySQL-8.0 innodb flags and give a specific error message
+--echo #
+
+--let MYSQLD_DATADIR= `SELECT @@datadir`
+
+--source include/shutdown_mysqld.inc
+
+--move_file $MYSQLD_DATADIR/ibdata1 $MYSQLD_DATADIR/ibdata1.bak
+--copy_file std_data/mysql80/ibdata1_$page_size $MYSQLD_DATADIR/ibdata1
+
+perl;
+use IO::Handle;
+my $size = 9 * 1048576;
+if ($ENV{MTR_COMBINATION_32K}) {
+ $size *= 2;
+}
+if ($ENV{MTR_COMBINATION_64K}) {
+ $size *= 4;
+}
+$size -= $ENV{page_size};
+die unless open(FILE, ">>", "$ENV{MYSQLD_DATADIR}/ibdata1");
+binmode FILE;
+
+print FILE chr(0) x $size;
+close(FILE);
+EOF
+
+--let ibdata_size='9M'
+if ($MTR_COMBINATION_32K)
+{
+--let ibdata_size='18M'
+}
+if ($MTR_COMBINATION_64K)
+{
+--let ibdata_size='36M'
+}
+
+--error 1
+exec $MYSQLD --no-defaults --skip-networking --innodb_data_file_path=ibdata1:$ibdata_size --innodb-page-size=$page_size --datadir=$MYSQLD_DATADIR --log-error=$tmp_in_vardir/attempted_start.err;
+
+let SEARCH_FILE= $tmp_in_vardir/attempted_start.err;
+let SEARCH_PATTERN= InnoDB: MySQL-8\.0 tablespace in \./ibdata1;
+source include/search_pattern_in_file.inc;
+
+--remove_file $tmp_in_vardir/attempted_start.err
+--remove_file $MYSQLD_DATADIR/ibdata1
+--move_file $MYSQLD_DATADIR/ibdata1.bak $MYSQLD_DATADIR/ibdata1
+
+--source include/start_mysqld.inc
+
+--echo #
+--echo # End of 10.3 tests
+--echo #
diff --git a/mysql-test/suite/innodb/t/row_format_redundant.opt b/mysql-test/suite/innodb/t/row_format_redundant.opt
new file mode 100644
index 00000000..c44c611e
--- /dev/null
+++ b/mysql-test/suite/innodb/t/row_format_redundant.opt
@@ -0,0 +1 @@
+--innodb-checksum-algorithm=crc32
diff --git a/mysql-test/suite/innodb/t/row_format_redundant.test b/mysql-test/suite/innodb/t/row_format_redundant.test
new file mode 100644
index 00000000..fa3a104a
--- /dev/null
+++ b/mysql-test/suite/innodb/t/row_format_redundant.test
@@ -0,0 +1,166 @@
+--source include/have_innodb.inc
+# Embedded mode doesn't allow restarting
+--source include/not_embedded.inc
+--source include/have_sequence.inc
+
+--disable_query_log
+call mtr.add_suppression("InnoDB: Table `mysql`\\.`innodb_table_stats` not found");
+call mtr.add_suppression("InnoDB: Table test/t1 in InnoDB data dictionary contains invalid flags. SYS_TABLES\\.TYPE=1 SYS_TABLES\\.MIX_LEN=511\\r?$");
+call mtr.add_suppression("InnoDB: Parent table of FTS auxiliary table test/FTS_.* not found");
+call mtr.add_suppression("InnoDB: Cannot open table test/t1 from the internal data dictionary");
+call mtr.add_suppression("InnoDB: Table `test`.`t1` does not exist in the InnoDB internal data dictionary though MariaDB is trying to (rename|drop)");
+FLUSH TABLES;
+--enable_query_log
+
+let INNODB_PAGE_SIZE=`select @@innodb_page_size`;
+
+let bugdir= $MYSQLTEST_VARDIR/tmp/row_format_redundant;
+--mkdir $bugdir
+--let SEARCH_FILE = $MYSQLTEST_VARDIR/log/mysqld.1.err
+
+--let $d=--innodb-data-home-dir=$bugdir --innodb-log-group-home-dir=$bugdir
+--let $d=$d --innodb-data-file-path=ibdata1:1M:autoextend
+--let $d=$d --innodb-undo-tablespaces=0 --innodb-stats-persistent=0
+--let $restart_parameters= $d
+# Ensure that any DDL records from previous tests have been purged.
+SET GLOBAL innodb_fast_shutdown=0;
+--source include/restart_mysqld.inc
+
+SET GLOBAL innodb_file_per_table=1;
+
+--echo #
+--echo # Bug#21644827 - FTS, ASSERT !SRV_READ_ONLY_MODE || M_IMPL.M_LOG_MODE ==
+--echo # MTR_LOG_NO_REDO
+--echo #
+
+SET GLOBAL innodb_file_per_table=ON;
+create table t1 (a int not null, d varchar(15) not null, b
+varchar(198) not null, c char(156)) engine=InnoDB
+row_format=redundant;
+
+create temporary table t like t1;
+
+insert into t values(123, 'abcdef', 'jghikl', 'mnop');
+insert into t values(456, 'abcdef', 'jghikl', 'mnop');
+insert into t values(789, 'abcdef', 'jghikl', 'mnop');
+insert into t values(134, 'kasdfsdsadf', 'adfjlasdkfjasd', 'adfsadflkasdasdfljasdf');
+
+insert into t1 select a,d,b,c from t, seq_1_to_1024;
+
+SET GLOBAL innodb_file_per_table=OFF;
+create table t2 (a int not null, d varchar(15) not null, b
+varchar(198) not null, c char(156), fulltext ftsic(c)) engine=InnoDB
+row_format=redundant;
+
+insert into t2 select a,d,b,c from t, seq_1_to_1024;
+
+create table t3 (a int not null, d varchar(15) not null, b varchar(198),
+c varchar(150), index k1(c(99), b(56)), index k2(b(5), c(10))) engine=InnoDB
+row_format=redundant;
+
+insert into t3 values(444, 'dddd', 'bbbbb', 'aaaaa');
+insert into t3 values(555, 'eeee', 'ccccc', 'aaaaa');
+
+# read-only restart requires the change buffer to be empty; therefore we
+# do a slow shutdown.
+SET GLOBAL innodb_fast_shutdown=0;
+--let $restart_parameters= $d --innodb-read-only
+--source include/restart_mysqld.inc
+
+SELECT COUNT(*) FROM t1;
+SELECT COUNT(*) FROM t2;
+SELECT COUNT(*) FROM t3;
+
+--error ER_OPEN_AS_READONLY
+TRUNCATE TABLE t1;
+--error ER_OPEN_AS_READONLY
+TRUNCATE TABLE t2;
+--error ER_OPEN_AS_READONLY
+TRUNCATE TABLE t3;
+
+--let $restart_parameters= $d --skip-innodb-fast-shutdown
+--source include/restart_mysqld.inc
+
+TRUNCATE TABLE t1;
+TRUNCATE TABLE t2;
+TRUNCATE TABLE t3;
+
+--source include/shutdown_mysqld.inc
+--perl
+use strict;
+do "$ENV{MTR_SUITE_DIR}/include/crc32.pl";
+my $ps= $ENV{INNODB_PAGE_SIZE};
+my $file= "$ENV{bugdir}/ibdata1";
+open(FILE, "+<", $file) || die "Unable to open $file\n";
+die "Unable to read $file" unless sysread(FILE, $_, $ps) == $ps;
+my $full_crc32 = unpack("N",substr($_,54,4)) & 0x10; # FIL_SPACE_FLAGS;
+sysseek(FILE, 0, 0) || die "Unable to seek $file";
+# Read DICT_HDR_TABLES, the root page number of CLUST_IND (SYS_TABLES.NAME).
+sysseek(FILE, 7*$ps+38+32, 0) || die "Unable to seek $file";
+die "Unable to read $file" unless sysread(FILE, $_, 4) == 4;
+my $sys_tables_root = unpack("N", $_);
+my $page;
+sysseek(FILE, $sys_tables_root*$ps, 0) || die "Unable to seek $file";
+die "Unable to read $file" unless sysread(FILE, $page, $ps) == $ps;
+for (my $offset= 0x65; $offset;
+ $offset= unpack("n", substr($page,$offset-2,2)))
+{
+ my $n_fields= unpack("n", substr($page,$offset-4,2)) >> 1 & 0x3ff;
+ my $start= 0;
+ my $end= unpack("C", substr($page, $offset-7, 1));
+ my $name= substr($page,$offset+$start,$end-$start);
+ for (my $i= 0; $i < $n_fields; $i++) {
+ my $end= unpack("C", substr($page, $offset-7-$i, 1));
+ # Corrupt SYS_TABLES.MIX_LEN (ignored for ROW_FORMAT=REDUNDANT)
+ if ($i == 7 && $name =~ '^test/t[123]')
+ {
+ print "corrupted SYS_TABLES.MIX_LEN for $name\n";
+ substr($page,$offset+$start,$end-$start)= pack("N", 511);
+ }
+ $start= $end & 0x7f;
+ }
+}
+my $polynomial = 0x82f63b78; # CRC-32C
+if ($full_crc32) {
+ my $ck = mycrc32(substr($page, 0, $ps-4), 0, $polynomial);
+ substr($page, $ps-4, 4) = pack("N", $ck);
+} else {
+ my $ck= pack("N",mycrc32(substr($page, 4, 22), 0, $polynomial) ^
+ mycrc32(substr($page, 38, $ps - 38 - 8), 0, $polynomial));
+ substr($page,0,4)=$ck;
+ substr($page,$ps-8,4)=$ck;
+}
+
+sysseek(FILE, $sys_tables_root*$ps, 0) || die "Unable to seek $file";
+syswrite(FILE, $page, $ps)==$ps || die "Unable to write $file\n";
+close(FILE) || die "Unable to close $file\n";
+EOF
+
+--source include/start_mysqld.inc
+--error ER_NO_SUCH_TABLE_IN_ENGINE
+TRUNCATE TABLE t1;
+TRUNCATE TABLE t2;
+TRUNCATE TABLE t3;
+--error ER_NO_SUCH_TABLE_IN_ENGINE
+SELECT COUNT(*) FROM t1;
+SELECT COUNT(*) FROM t2;
+SELECT COUNT(*) FROM t3;
+--error ER_ERROR_ON_RENAME
+RENAME TABLE t1 TO tee_one;
+DROP TABLE t1;
+DROP TABLE t2,t3;
+
+--let SEARCH_PATTERN= \[ERROR\] InnoDB: Table test/t1 in InnoDB data dictionary contains invalid flags\. SYS_TABLES\.TYPE=1 SYS_TABLES\.MIX_LEN=511\b
+--source include/search_pattern_in_file.inc
+
+--let $restart_parameters=
+--source include/restart_mysqld.inc
+
+--list_files $bugdir
+--remove_files_wildcard $bugdir
+--rmdir $bugdir
+
+# Remove the data file, because DROP TABLE skipped it for the "corrupted" table
+--let MYSQLD_DATADIR=`select @@datadir`
+--remove_file $MYSQLD_DATADIR/test/t1.ibd
+--list_files $MYSQLD_DATADIR/test
diff --git a/mysql-test/suite/innodb/t/row_lock.test b/mysql-test/suite/innodb/t/row_lock.test
new file mode 100644
index 00000000..361bce46
--- /dev/null
+++ b/mysql-test/suite/innodb/t/row_lock.test
@@ -0,0 +1,50 @@
+#
+# Test of wrong call to unlock_row
+# MDEV-5629 Failing assertion: state == TRX_STATE_NOT_STARTED on
+# concurrent CREATE OR REPLACE and transactional UPDATE
+#
+
+--source include/have_innodb.inc
+
+CREATE TABLE t1 (a INT, b INT) ENGINE=InnoDB;
+INSERT INTO t1 VALUES (1,1),(2,2);
+
+CREATE TABLE t2 (c INT, d INT) ENGINE=InnoDB;
+INSERT INTO t2 VALUES (1,1), (2,2);
+
+CREATE TABLE t3 (e INT) ENGINE=InnoDB;
+CREATE TABLE t4 ENGINE=InnoDB AS SELECT * FROM t2;
+
+--connect (con11,localhost,root,,test)
+
+BEGIN;
+UPDATE t1 SET a = 0 WHERE a = ( SELECT e FROM t3 );
+
+--connect (con12,localhost,root,,test)
+
+--send
+UPDATE t4 SET d = 1 WHERE d in ( SELECT a FROM t1 ) ORDER BY c LIMIT 6;
+
+--connection con11
+
+# Wait for con12 to start waiting for con11
+let $wait_condition=
+ select count(*) = 1 from information_schema.innodb_trx
+ where trx_state = "lock wait" and
+ trx_query like "%SELECT a FROM t1%";
+--source include/wait_condition.inc
+
+UPDATE t4 SET d = 9;
+
+--connection con12
+--error ER_LOCK_DEADLOCK
+--reap
+--connection con11
+commit;
+--connection default
+--disconnect con12
+--disconnect con11
+drop table t1,t2,t3,t4;
+
+call mtr.add_suppression("Deadlock found when trying to get lock; try restarting transaction");
+call mtr.add_suppression("Sort aborted.*");
diff --git a/mysql-test/suite/innodb/t/row_size_error_log_warnings_3.test b/mysql-test/suite/innodb/t/row_size_error_log_warnings_3.test
new file mode 100644
index 00000000..dab9bcfa
--- /dev/null
+++ b/mysql-test/suite/innodb/t/row_size_error_log_warnings_3.test
@@ -0,0 +1,87 @@
+--source include/have_innodb.inc
+--source include/have_sequence.inc
+--source include/innodb_page_size_small.inc
+--source include/have_normal_bzip.inc
+
+call mtr.add_suppression("InnoDB: Cannot add field .* in table .* because after adding it, the row size is .* which is greater than maximum allowed size (.*) for a record on index leaf page.");
+
+SET innodb_strict_mode = 0;
+SET @@global.log_warnings = 3;
+
+# Check the Warning | 139 | Row size too large (> 16318)
+--replace_regex /> [0-9]+/> NNNN/
+CREATE TABLE t1 (
+ col_1 TEXT
+ ,col_2 TEXT
+ ,col_3 TEXT
+ ,col_4 TEXT
+ ,col_5 TEXT
+ ,col_6 TEXT
+ ,col_7 TEXT
+ ,col_8 TEXT
+ ,col_9 TEXT
+ ,col_10 TEXT
+ ,col_11 TEXT
+) ENGINE=INNODB ROW_FORMAT=COMPACT;
+--enable_warnings
+--replace_regex /> [0-9]+/> NNNN/
+TRUNCATE TABLE t1;
+--replace_regex /> [0-9]+/> NNNN/
+OPTIMIZE TABLE t1;
+--replace_regex /> [0-9]+/> NNNN/
+ALTER TABLE t1 FORCE;
+SET innodb_strict_mode = ON;
+--replace_regex /> [0-9]+/> NNNN/
+TRUNCATE TABLE t1;
+--replace_regex /> [0-9]+/> NNNN/
+OPTIMIZE TABLE t1;
+--replace_regex /> [0-9]+/> NNNN/
+ALTER TABLE t1 FORCE;
+DROP TABLE t1;
+--disable_warnings
+
+SET @@global.log_warnings = 2;
+
+--echo #
+--echo # MDEV-20194 Warnings inconsistently issued upon CHECK on
+--echo # table from older versions
+--echo #
+set global innodb_compression_level=1;
+CREATE TABLE t1(
+ f1 INT, f2 CHAR(200), f3 CHAR(200),
+ f4 CHAR(200), f5 CHAR(200), f6 CHAR(200),
+ f7 CHAR(200), f8 CHAR(200), f9 CHAR(106),
+ PRIMARY KEY(f1, f2(20), f3(20), f4(20))
+ ) ROW_FORMAT=COMPRESSED, ENGINE=InnoDB;
+
+INSERT INTO t1 SELECT seq, repeat('a', 200), repeat('b', 200),
+ repeat('c', 200), repeat('d', 200),
+ repeat('d', 200), repeat('e', 200),
+ repeat('f', 200), repeat('g', 106) FROM seq_1_to_20;
+DROP TABLE t1;
+set global innodb_compression_level=default;
+
+# Maximum field in the index
+
+--error ER_TOO_MANY_KEY_PARTS
+CREATE TABLE t1(f1 char(200), f2 char(200), f3 char(200),
+ f4 char(200), f5 char(200), f6 char(200),
+ f7 char(200), f8 char(200), f9 char(200),
+ f10 char(200), f11 char(200), f12 char(200),
+ f13 char(200), f14 char(200), f15 char(200),
+ f16 char(200), f17 char(200), f18 char(200),
+ f19 char(200), f20 char(200), f21 char(200),
+ f22 char(200), f23 char(200), f24 char(200),
+ f25 char(200), f26 char(200), f27 char(200),
+ f28 char(200), f29 char(200), f30 char(200),
+ f31 char(200), f32 char(200), f33 char(200),
+ primary key(f1(10), f2(10), f3(10), f4(10),
+ f5(10), f6(10), f7(10), f8(10),
+ f9(10), f10(10), f11(10), f12(10),
+ f13(10), f14(10), f15(10), f16(10),
+ f17(10), f18(10), f19(10), f20(10),
+ f21(10), f22(10), f23(10), f24(10),
+ f25(10), f26(10), f27(10), f28(10),
+ f29(10), f30(10), f31(10), f32(10),
+ f33(10)))
+ ENGINE=InnoDB;
diff --git a/mysql-test/suite/innodb/t/scrub.test b/mysql-test/suite/innodb/t/scrub.test
new file mode 100644
index 00000000..1c386379
--- /dev/null
+++ b/mysql-test/suite/innodb/t/scrub.test
@@ -0,0 +1,18 @@
+--source include/have_innodb.inc
+--source include/have_sequence.inc
+--source include/not_embedded.inc
+
+SET GLOBAL
+ innodb_file_per_table=OFF,
+ innodb_immediate_scrub_data_uncompressed=ON;
+CREATE TABLE t1(f1 INT NOT NULL, f2 INT NOT NULL,
+ f3 INT NOT NULL, INDEX(f1),
+ INDEX(f2), INDEX(f3))ENGINE=InnoDB;
+INSERT INTO t1 SELECT seq, seq, seq FROM seq_1_to_16384;
+INSERT INTO t1 SELECT seq, seq, seq FROM seq_1_to_16384;
+INSERT INTO t1 SELECT seq, seq, seq FROM seq_1_to_16384;
+DROP TABLE t1;
+SET GLOBAL innodb_max_purge_lag_wait=0;
+# The crash recovery would occasionally fail.
+let $shutdown_timeout=0;
+--source include/restart_mysqld.inc
diff --git a/mysql-test/suite/innodb/t/scrub_debug.test b/mysql-test/suite/innodb/t/scrub_debug.test
new file mode 100644
index 00000000..a1f0b38e
--- /dev/null
+++ b/mysql-test/suite/innodb/t/scrub_debug.test
@@ -0,0 +1,28 @@
+--source include/have_innodb.inc
+--source include/have_sequence.inc
+--source include/have_debug.inc
+
+SET @save_debug=@@GLOBAL.INNODB_LIMIT_OPTIMISTIC_INSERT_DEBUG;
+SET @save_scrub=@@GLOBAL.INNODB_IMMEDIATE_SCRUB_DATA_UNCOMPRESSED;
+
+SET GLOBAL INNODB_IMMEDIATE_SCRUB_DATA_UNCOMPRESSED=1;
+SET GLOBAL INNODB_LIMIT_OPTIMISTIC_INSERT_DEBUG=2;
+let $MYSQLD_DATADIR=`select @@datadir`;
+CREATE TABLE t1(f1 INT AUTO_INCREMENT PRIMARY KEY,
+ f2 VARCHAR(256) GENERATED ALWAYS as('repairman'),
+ INDEX idx(f2))ENGINE= InnoDB;
+INSERT INTO t1(f1) SELECT seq FROM seq_1_to_50;
+FLUSH TABLE t1 FOR EXPORT;
+let SEARCH_PATTERN= repairman;
+let SEARCH_FILE= $MYSQLD_DATADIR/test/t1.ibd;
+-- source include/search_pattern_in_file.inc
+UNLOCK TABLES;
+
+ALTER TABLE t1 DROP INDEX idx;
+-- source include/wait_all_purged.inc
+FLUSH TABLE t1 FOR EXPORT;
+-- source include/search_pattern_in_file.inc
+UNLOCK TABLES;
+DROP TABLE t1;
+SET GLOBAL INNODB_LIMIT_OPTIMISTIC_INSERT_DEBUG=@save_debug;
+SET GLOBAL INNODB_IMMEDIATE_SCRUB_DATA_UNCOMPRESSED=@save_scrub;
diff --git a/mysql-test/suite/innodb/t/skip_locked_nowait.test b/mysql-test/suite/innodb/t/skip_locked_nowait.test
new file mode 100644
index 00000000..ea744ca5
--- /dev/null
+++ b/mysql-test/suite/innodb/t/skip_locked_nowait.test
@@ -0,0 +1,208 @@
+#
+# wl#8919 Implement NOWAIT and SKIP LOCKED
+#
+--source include/have_innodb.inc
+
+
+connect (con1,localhost,root,,);
+SET SESSION innodb_lock_wait_timeout=1;
+
+connection default;
+SET SESSION innodb_lock_wait_timeout=1;
+
+--echo # Case 1: Test primary index
+CREATE TABLE t1(
+ seat_id INT,
+ state INT,
+ PRIMARY KEY(seat_id)
+) ENGINE=InnoDB;
+
+INSERT INTO t1 VALUES(1,0), (2,0), (3,0), (4,0);
+
+BEGIN;
+SELECT * FROM t1 WHERE state = 0 LIMIT 2 LOCK IN SHARE MODE;
+
+connection con1;
+BEGIN;
+
+SELECT * FROM t1 WHERE state = 0 LIMIT 2 LOCK IN SHARE MODE;
+
+SELECT * FROM t1 WHERE state = 0 LIMIT 2 LOCK IN SHARE MODE SKIP LOCKED;
+
+--error ER_LOCK_WAIT_TIMEOUT
+SELECT * FROM t1 WHERE state = 0 LIMIT 2 FOR UPDATE;
+
+--error ER_LOCK_WAIT_TIMEOUT
+SELECT * FROM t1 WHERE state = 0 LIMIT 2 FOR UPDATE NOWAIT;
+SELECT * FROM t1 WHERE state = 0 LIMIT 2 FOR UPDATE SKIP LOCKED;
+
+--error ER_LOCK_WAIT_TIMEOUT
+SELECT * FROM t1 WHERE seat_id > 0 LIMIT 2 FOR UPDATE NOWAIT;
+SELECT * FROM t1 WHERE seat_id > 0 LIMIT 2 FOR UPDATE SKIP LOCKED;
+
+COMMIT;
+
+connection default;
+SELECT * FROM t1 WHERE state = 0 LIMIT 2 FOR UPDATE;
+
+connection con1;
+--error ER_LOCK_WAIT_TIMEOUT
+SELECT * FROM t1 WHERE state = 0 LIMIT 2 LOCK IN SHARE MODE;
+
+--error ER_LOCK_WAIT_TIMEOUT
+SELECT * FROM t1 WHERE state = 0 LIMIT 2 LOCK IN SHARE MODE NOWAIT;
+SELECT * FROM t1 WHERE state = 0 LIMIT 2 LOCK IN SHARE MODE SKIP LOCKED;
+
+--error ER_LOCK_WAIT_TIMEOUT
+SELECT * FROM t1 WHERE state = 0 LIMIT 2 FOR UPDATE;
+
+--error ER_LOCK_WAIT_TIMEOUT
+SELECT * FROM t1 WHERE state = 0 LIMIT 2 FOR UPDATE NOWAIT;
+SELECT * FROM t1 WHERE state = 0 LIMIT 2 FOR UPDATE SKIP LOCKED;
+
+--error ER_LOCK_WAIT_TIMEOUT
+SELECT * FROM t1 WHERE seat_id > 0 LIMIT 2 FOR UPDATE NOWAIT;
+SELECT * FROM t1 WHERE seat_id > 0 LIMIT 2 FOR UPDATE SKIP LOCKED;
+
+COMMIT;
+
+connection default;
+COMMIT;
+
+DROP TABLE t1;
+
+--echo # Case 2: Test primary index & secondary index
+CREATE TABLE t1(
+ seat_id INT,
+ row_id INT,
+ state INT,
+ PRIMARY KEY(seat_id),
+ KEY(row_id)
+) ENGINE=InnoDB;
+
+INSERT INTO t1 VALUES(1,1,0), (2,1,0), (3,2,0), (4,2,0);
+
+--echo # Test secondary key
+# Case 2a: secondary blocks secondary/primary
+BEGIN;
+SELECT * FROM t1 WHERE state = 0 AND row_id = 1 LIMIT 1 FOR UPDATE NOWAIT;
+
+connection con1;
+BEGIN;
+--error ER_LOCK_WAIT_TIMEOUT
+SELECT * FROM t1 WHERE state = 0 AND row_id = 1 LIMIT 1 FOR UPDATE NOWAIT;
+SELECT * FROM t1 WHERE state = 0 AND row_id = 1 LIMIT 1 FOR UPDATE SKIP LOCKED;
+
+--error ER_LOCK_WAIT_TIMEOUT
+SELECT * FROM t1 WHERE state = 0 AND row_id > 0 LIMIT 1 FOR UPDATE NOWAIT;
+SELECT * FROM t1 WHERE state = 0 AND row_id > 0 LIMIT 1 FOR UPDATE SKIP LOCKED;
+
+--error ER_LOCK_WAIT_TIMEOUT
+SELECT * FROM t1 WHERE state = 0 FOR UPDATE NOWAIT;
+SELECT * FROM t1 WHERE state = 0 FOR UPDATE SKIP LOCKED;
+
+COMMIT;
+
+connection default;
+COMMIT;
+
+# Case 2b: primary blocks secondary/primary
+BEGIN;
+SELECT * FROM t1 WHERE seat_id = 1 FOR UPDATE NOWAIT;
+
+connection con1;
+BEGIN;
+--error ER_LOCK_WAIT_TIMEOUT
+SELECT * FROM t1 WHERE state = 0 AND row_id = 1 LIMIT 1 FOR UPDATE NOWAIT;
+SELECT * FROM t1 WHERE state = 0 AND row_id = 1 LIMIT 1 FOR UPDATE SKIP LOCKED;
+
+--error ER_LOCK_WAIT_TIMEOUT
+SELECT * FROM t1 WHERE state = 0 FOR UPDATE NOWAIT;
+SELECT * FROM t1 WHERE state = 0 FOR UPDATE SKIP LOCKED;
+
+COMMIT;
+
+connection default;
+COMMIT;
+
+DROP TABLE t1;
+
+--echo # Case 3: Test primary index & spatial index
+CREATE TABLE t1(
+ seat_id INT,
+ pos POINT NOT NULL,
+ state INT,
+ PRIMARY KEY(seat_id),
+ SPATIAL KEY(pos)
+) ENGINE=InnoDB;
+
+INSERT INTO t1 VALUES
+(1,ST_PointFromText('POINT(1 0)'),0),
+(2,ST_PointFromText('POINT(1 1)'),0),
+(3,ST_PointFromText('POINT(2 0)'),0),
+(4,ST_PointFromText('POINT(2 1)'),0),
+(5,ST_PointFromText('POINT(3 0)'),0),
+(6,ST_PointFromText('POINT(3 1)'),0);
+
+# Case 3a: secondary blocks secondary/primary
+BEGIN;
+SET @g = ST_GeomFromText('POLYGON((0 0,0 2,2 2,0 2,0 0))');
+# the first 4 records in the rtree index page are locked
+SELECT seat_id, state, ST_AsText(pos) FROM t1 FORCE INDEX (pos)
+WHERE state = 0 AND MBRWithin(pos, @g) FOR UPDATE NOWAIT;
+
+connection con1;
+BEGIN;
+SET @g = ST_GeomFromText('POLYGON((0 0,0 4,4 4,0 4,0 0))');
+--error ER_LOCK_WAIT_TIMEOUT
+SELECT seat_id, state, ST_AsText(pos) FROM t1 FORCE INDEX (pos)
+WHERE state = 0 AND MBRWithin(pos, @g) FOR UPDATE NOWAIT;
+
+# TODO Needs fixing
+#SELECT seat_id, state, ST_AsText(pos) FROM t1 FORCE INDEX (pos)
+#WHERE state = 0 AND MBRWithin(pos, @g) FOR UPDATE SKIP LOCKED;
+
+--error ER_LOCK_WAIT_TIMEOUT
+SELECT seat_id, state, ST_AsText(pos) FROM t1
+WHERE state = 0 FOR UPDATE NOWAIT;
+
+SELECT seat_id, state, ST_AsText(pos) FROM t1
+WHERE state = 0 FOR UPDATE SKIP LOCKED;
+
+COMMIT;
+
+connection default;
+COMMIT;
+
+# Case 3b: primary blockes secondary/primary
+connection con1;
+SET @g = ST_GeomFromText('POLYGON((0 0,0 3,3 3,0 3,0 0))');
+SELECT seat_id, state, ST_AsText(pos) FROM t1 FORCE INDEX (pos)
+WHERE state = 0 AND MBRWithin(pos, @g) FOR UPDATE;
+
+connection default;
+BEGIN;
+SELECT seat_id, state, ST_AsText(pos) FROM t1
+WHERE seat_id = 4 FOR UPDATE NOWAIT;
+
+connection con1;
+--error ER_LOCK_WAIT_TIMEOUT
+SELECT seat_id, state, ST_AsText(pos) FROM t1 FORCE INDEX (pos)
+WHERE state = 0 AND MBRWithin(pos, @g) FOR UPDATE NOWAIT;
+
+SELECT seat_id, state, ST_AsText(pos) FROM t1 FORCE INDEX (pos)
+WHERE state = 0 AND MBRWithin(pos, @g) FOR UPDATE SKIP LOCKED;
+
+--error ER_LOCK_WAIT_TIMEOUT
+SELECT seat_id, state, ST_AsText(pos) FROM t1
+WHERE state = 0 FOR UPDATE NOWAIT;
+
+SELECT seat_id, state, ST_AsText(pos) FROM t1
+WHERE state = 0 FOR UPDATE SKIP LOCKED;
+
+connection default;
+COMMIT;
+
+DROP TABLE t1;
+
+disconnect con1;
diff --git a/mysql-test/suite/innodb/t/skip_symbolic_links.opt b/mysql-test/suite/innodb/t/skip_symbolic_links.opt
new file mode 100644
index 00000000..c7844699
--- /dev/null
+++ b/mysql-test/suite/innodb/t/skip_symbolic_links.opt
@@ -0,0 +1 @@
+--skip-symbolic-links
diff --git a/mysql-test/suite/innodb/t/skip_symbolic_links.test b/mysql-test/suite/innodb/t/skip_symbolic_links.test
new file mode 100644
index 00000000..b5274d22
--- /dev/null
+++ b/mysql-test/suite/innodb/t/skip_symbolic_links.test
@@ -0,0 +1,51 @@
+--source include/have_innodb.inc
+--source include/not_windows.inc
+
+SELECT @@have_symlink;
+--replace_result $MYSQL_TMP_DIR MYSQL_TMP_DIR
+eval CREATE TABLE t1(a INT) ENGINE=InnoDB DATA DIRECTORY '$MYSQL_TMP_DIR';
+DROP TABLE t1;
+CREATE TABLE t1(a INT) ENGINE=InnoDB;
+
+--replace_result $MYSQL_TMP_DIR MYSQL_TMP_DIR
+eval ALTER TABLE t1 DATA DIRECTORY '$MYSQL_TMP_DIR';
+SHOW CREATE TABLE t1;
+
+DROP TABLE t1;
+
+--let $restart_parameters=--symbolic-links
+--source include/restart_mysqld.inc
+
+--replace_result $MYSQL_TMP_DIR MYSQL_TMP_DIR
+eval CREATE TABLE t1(a INT PRIMARY KEY, b INT) ENGINE=InnoDB
+DATA DIRECTORY '$MYSQL_TMP_DIR';
+--replace_result $MYSQL_TMP_DIR MYSQL_TMP_DIR
+eval CREATE TABLE t2(a INT PRIMARY KEY, b INT) ENGINE=InnoDB
+DATA DIRECTORY '$MYSQL_TMP_DIR';
+
+TRUNCATE TABLE t1;
+TRUNCATE TABLE t2;
+
+--let $restart_parameters=
+--source include/restart_mysqld.inc
+
+# Native ALTER will retain DATA DIRECTORY
+ALTER TABLE t1 FORCE, ALGORITHM=INPLACE;
+ALTER TABLE t2 FORCE, ALGORITHM=COPY;
+OPTIMIZE TABLE t1;
+--list_files $MYSQL_TMP_DIR/test
+DROP TABLE t2;
+
+RENAME TABLE t1 TO t2;
+ALTER TABLE t2 ADD UNIQUE INDEX(b), RENAME TO t3;
+
+ALTER TABLE t3 RENAME TO t2;
+ALTER TABLE t2 DROP INDEX b, RENAME TO t1;
+ALTER TABLE t1 CHANGE b c INT;
+ALTER TABLE t1 CHANGE c b INT NOT NULL;
+
+--list_files $MYSQL_TMP_DIR/test
+# TRUNCATE TABLE will discard DATA DIRECTORY.
+TRUNCATE TABLE t1;
+--list_files $MYSQL_TMP_DIR/test
+DROP TABLE t1;
diff --git a/mysql-test/suite/innodb/t/snapshot.test b/mysql-test/suite/innodb/t/snapshot.test
new file mode 100644
index 00000000..8e3dc76f
--- /dev/null
+++ b/mysql-test/suite/innodb/t/snapshot.test
@@ -0,0 +1,18 @@
+
+--source include/have_log_bin.inc
+--source include/have_binlog_format_row.inc
+--source include/have_innodb.inc
+
+START TRANSACTION WITH CONSISTENT SNAPSHOT;
+
+--connect (con1,localhost,root,,test)
+CREATE TABLE IF NOT EXISTS t1 (pk INT PRIMARY KEY, i INT, KEY(i)) ENGINE=InnoDB;
+
+--connection default
+--error 1412
+UPDATE t1 SET i = 0;
+--error 1412
+UPDATE t1 SET pk = 0;
+commit;
+
+drop table t1;
diff --git a/mysql-test/suite/innodb/t/sp_temp_table.test b/mysql-test/suite/innodb/t/sp_temp_table.test
new file mode 100644
index 00000000..f355dfd1
--- /dev/null
+++ b/mysql-test/suite/innodb/t/sp_temp_table.test
@@ -0,0 +1,103 @@
+--source include/have_innodb.inc
+--source include/big_test.inc
+
+--echo #
+--echo # Bug #19306524 FAILING ASSERTION WITH TEMP TABLE FOR A PROCEDURE
+--echo # CALLED FROM A FUNCTION
+--echo #
+
+call mtr.add_suppression("MariaDB is trying to drop table");
+
+DELIMITER $$;
+CREATE PROCEDURE cachedata(
+ IN obj_id BIGINT UNSIGNED,
+ IN start DATETIME,
+ IN end DATETIME
+)
+
+cachedata:BEGIN
+ DECLARE cache_count BIGINT;
+
+ SET @timestamp := NOW();
+
+ CREATE TEMPORARY TABLE IF NOT EXISTS cachedata (
+ timestamp DATETIME,
+ object_id BIGINT UNSIGNED NOT NULL,
+ start DATETIME,
+ end DATETIME,
+ seqno BIGINT AUTO_INCREMENT,
+ value FLOAT,
+ PRIMARY KEY (seqno),
+ INDEX (timestamp),
+ INDEX (object_id, start, end)
+ ) ENGINE=INNODB;
+
+ DELETE FROM cachedata WHERE
+ timestamp < DATE_SUB(@timestamp, INTERVAL 15 SECOND);
+
+ SELECT count(*) INTO cache_count FROM cachedata WHERE
+ object_id = obj_id
+ AND start = start
+ AND end = end;
+
+ IF cache_count > 0 THEN LEAVE cachedata;
+ END IF;
+
+ INSERT INTO cachedata (timestamp, object_id, start, end, value) VALUES
+ (@timestamp, obj_id, start, end, 1234),
+ (@timestamp, obj_id, start, end, 4567),
+ (@timestamp, obj_id, start, end, 8901),
+ (@timestamp, obj_id, start, end, 1234),
+ (@timestamp, obj_id, start, end, 4567),
+ (@timestamp, obj_id, start, end, 8901),
+ (@timestamp, obj_id, start, end, 1234),
+ (@timestamp, obj_id, start, end, 4567),
+ (@timestamp, obj_id, start, end, 8901),
+ (@timestamp, obj_id, start, end, 1234),
+ (@timestamp, obj_id, start, end, 4567),
+ (@timestamp, obj_id, start, end, 8901),
+ (@timestamp, obj_id, start, end, 2345),
+ (@timestamp, obj_id, start, end, 1234),
+ (@timestamp, obj_id, start, end, 4567),
+ (@timestamp, obj_id, start, end, 8901),
+ (@timestamp, obj_id, start, end, 2345),
+ (@timestamp, obj_id, start, end, 1234),
+ (@timestamp, obj_id, start, end, 4567),
+ (@timestamp, obj_id, start, end, 8901),
+ (@timestamp, obj_id, start, end, 2345);
+
+END$$
+
+
+CREATE FUNCTION get_cache(
+ obj_id BIGINT UNSIGNED,
+ start DATETIME,
+ end DATETIME
+)
+ RETURNS FLOAT
+ READS SQL DATA
+BEGIN
+ DECLARE result FLOAT;
+
+ CALL cachedata(obj_id, start, end);
+
+ SELECT SUM(value) INTO result FROM cachedata WHERE
+ object_id = obj_id
+ AND start = start
+ AND end = end;
+
+ RETURN result;
+END$$
+
+DELIMITER ;$$
+
+let $i = 30;
+while ($i)
+{
+ SELECT get_cache(1, '2014-01-01', '2014-02-01');
+ select sleep(1);
+ dec $i;
+}
+
+DROP FUNCTION get_cache;
+DROP PROCEDURE cachedata;
diff --git a/mysql-test/suite/innodb/t/sql_mode_pad_char_to_full_length.test b/mysql-test/suite/innodb/t/sql_mode_pad_char_to_full_length.test
new file mode 100644
index 00000000..ba286c74
--- /dev/null
+++ b/mysql-test/suite/innodb/t/sql_mode_pad_char_to_full_length.test
@@ -0,0 +1,18 @@
+--source include/have_innodb.inc
+
+SET default_storage_engine=InnoDB;
+
+--echo #
+--echo # Start of 10.4 tests
+--echo #
+
+--echo #
+--echo # MDEV-28190 sql_mode makes MDEV-371 virtual column expressions nondeterministic
+--echo #
+
+--source include/sql_mode_pad_char_to_full_length.inc
+
+
+--echo #
+--echo # End of 10.4 tests
+--echo #
diff --git a/mysql-test/suite/innodb/t/stat_tables.test b/mysql-test/suite/innodb/t/stat_tables.test
new file mode 100644
index 00000000..ad421587
--- /dev/null
+++ b/mysql-test/suite/innodb/t/stat_tables.test
@@ -0,0 +1,84 @@
+source include/have_innodb.inc;
+
+#
+# MDEV-20354 All but last insert ignored in InnoDB tables when table locked
+#
+rename table mysql.table_stats to mysql.table_stats_save;
+flush tables;
+set use_stat_tables= PREFERABLY;
+create table t1 (a int) engine=InnoDB;
+start transaction;
+insert t1 values (1);
+insert t1 values (2);
+commit;
+select * from t1;
+drop table t1;
+rename table mysql.table_stats_save to mysql.table_stats;
+flush tables;
+
+--echo #
+--echo # MDEV-26753 Assertion state == TRX_STATE_PREPARED ||... failed
+--echo #
+CREATE TABLE t1(a INT PRIMARY KEY) ENGINE=InnoDB;
+XA START 'test';
+SELECT COUNT(*)>0 FROM mysql.innodb_index_stats LOCK IN SHARE MODE;
+INSERT INTO t1 VALUES (1),(2);
+UPDATE mysql.innodb_table_stats SET last_update=NULL WHERE table_name='t1';
+XA END 'test';
+XA ROLLBACK 'test';
+DROP TABLE t1;
+
+--echo #
+--echo # MDEV-30483 After upgrade to 10.6 from Mysql 5.7 seeing "InnoDB: Column last_update in table mysql.innodb_table_stats is BINARY(4) NOT NULL but should be INT UNSIGNED NOT NULL"
+--echo #
+
+# The following tests demonstrate that these columns:
+# - innodb_table_stats.last_update
+# - innodb_index_stats.last_update
+# have sane values close to NOW(), rather than any garbage,
+# with all TIMESTAMP formats.
+
+--echo #
+--echo # Testing a non-default format: Field_timestamp0 - UINT4 based
+--echo #
+
+SET @@global.mysql56_temporal_format=0;
+ALTER TABLE mysql.innodb_table_stats MODIFY last_update TIMESTAMP NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp();
+ALTER TABLE mysql.innodb_index_stats MODIFY last_update TIMESTAMP NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp();
+SHOW COLUMNS FROM mysql.innodb_table_stats LIKE 'last_update';
+SHOW COLUMNS FROM mysql.innodb_index_stats LIKE 'last_update';
+CREATE TABLE t1 (a INT PRIMARY KEY) ENGINE=InnoDB STATS_PERSISTENT=1;
+
+SELECT TIMESTAMPDIFF(DAY,last_update,now())<=1 FROM mysql.innodb_table_stats
+WHERE database_name='test' AND table_name='t1';
+SELECT TIMESTAMPDIFF(DAY,last_update,now())<=1 FROM mysql.innodb_index_stats
+WHERE database_name='test' AND table_name='t1' AND stat_name='size';
+DROP TABLE t1;
+
+--echo #
+--echo # Now as the table t1 is dropped, expect no statistics
+--echo #
+
+SELECT * FROM mysql.innodb_table_stats
+WHERE database_name='test' AND table_name='t1';
+SELECT * FROM mysql.innodb_index_stats
+WHERE database_name='test' AND table_name='t1' AND stat_name='size';
+
+--echo #
+--echo # Testing with the default format: Field_timestampf - BINARY(4) based with the UNSIGNED_FLAG
+--echo #
+
+SET @@global.mysql56_temporal_format=1;
+ALTER TABLE mysql.innodb_table_stats MODIFY last_update TIMESTAMP NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp();
+ALTER TABLE mysql.innodb_index_stats MODIFY last_update TIMESTAMP NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp();
+SHOW COLUMNS FROM mysql.innodb_table_stats LIKE 'last_update';
+SHOW COLUMNS FROM mysql.innodb_index_stats LIKE 'last_update';
+CREATE TABLE t1 (a INT PRIMARY KEY) ENGINE=InnoDB STATS_PERSISTENT=1;
+SELECT TIMESTAMPDIFF(DAY,last_update,now())<=1 FROM mysql.innodb_table_stats
+WHERE database_name='test' AND table_name='t1';
+SELECT TIMESTAMPDIFF(DAY,last_update,now())<=1 FROM mysql.innodb_index_stats
+WHERE database_name='test' AND table_name='t1' AND stat_name='size';
+DROP TABLE t1;
+
+
+--echo # End of 10.6 tests
diff --git a/mysql-test/suite/innodb/t/stats_persistent.test b/mysql-test/suite/innodb/t/stats_persistent.test
new file mode 100644
index 00000000..8561298c
--- /dev/null
+++ b/mysql-test/suite/innodb/t/stats_persistent.test
@@ -0,0 +1,28 @@
+--source include/have_innodb.inc
+--source include/have_debug.inc
+--source include/have_debug_sync.inc
+--source include/count_sessions.inc
+
+--echo #
+--echo # MDEV-23991 dict_table_stats_lock() has unnecessarily long scope
+--echo #
+CREATE TABLE t1(a INT) ENGINE=INNODB STATS_PERSISTENT=1;
+
+SET DEBUG_SYNC='dict_stats_update_persistent SIGNAL stop WAIT_FOR go';
+--send ANALYZE TABLE t1
+
+--connect(con1, localhost, root)
+SET DEBUG_SYNC='now WAIT_FOR stop';
+
+--replace_column 1 SUM
+SELECT SUM(DATA_LENGTH+INDEX_LENGTH) FROM information_schema.TABLES WHERE ENGINE='InnoDB';
+
+SET DEBUG_SYNC='now SIGNAL go';
+--disconnect con1
+
+--connection default
+--reap
+SET DEBUG_SYNC= 'RESET';
+DROP TABLE t1;
+
+--source include/wait_until_count_sessions.inc
diff --git a/mysql-test/suite/innodb/t/stored_fk.test b/mysql-test/suite/innodb/t/stored_fk.test
new file mode 100644
index 00000000..571ca030
--- /dev/null
+++ b/mysql-test/suite/innodb/t/stored_fk.test
@@ -0,0 +1,98 @@
+--source include/have_innodb.inc
+
+create table t1(f1 int primary key) engine=innodb;
+
+--echo # Create statement with FK on base column of stored column
+--error ER_GENERATED_COLUMN_FUNCTION_IS_NOT_ALLOWED
+create table t2(f1 int not null, f2 int as (f1) stored,
+ foreign key(f1) references t1(f1) on update cascade)engine=innodb;
+
+--error ER_GENERATED_COLUMN_FUNCTION_IS_NOT_ALLOWED
+create table t2(f1 int not null, f2 int as (f1) virtual, f3 int as (f2) stored,
+ foreign key(f1) references t1(f1) on update cascade)engine=innodb;
+
+--echo # adding new stored column during alter table copy operation.
+create table t2(f1 int not null, f2 int as (f1) virtual,
+ foreign key(f1) references t1(f1) on update cascade)engine=innodb;
+
+--error ER_GENERATED_COLUMN_FUNCTION_IS_NOT_ALLOWED
+alter table t2 add column f3 int as (f1) stored, add column f4 int as (f1) virtual;
+show create table t2;
+drop table t2;
+
+--echo # adding foreign key constraint for base columns during alter copy.
+create table t2(f1 int not null, f2 int as (f1) stored) engine=innodb;
+--error ER_GENERATED_COLUMN_FUNCTION_IS_NOT_ALLOWED
+alter table t2 add foreign key(f1) references t1(f1) on update cascade, algorithm=copy;
+show create table t2;
+drop table t2;
+
+--echo # adding foreign key constraint for base columns during online alter.
+create table t2(f1 int not null, f2 int as (f1) stored) engine=innodb;
+set foreign_key_checks = 0;
+--error ER_GENERATED_COLUMN_FUNCTION_IS_NOT_ALLOWED
+alter table t2 add foreign key(f1) references t1(f1) on update cascade, algorithm=inplace;
+drop table t2;
+
+--echo # adding stored column via online alter.
+create table t2(f1 int not null,
+ foreign key(f1) references t1(f1) on update cascade)engine=innodb;
+--error ER_GENERATED_COLUMN_FUNCTION_IS_NOT_ALLOWED
+alter table t2 add column f2 int as (f1) stored, algorithm=inplace;
+drop table t2, t1;
+
+--echo #
+--echo # BUG#26731689 FK ON TABLE WITH GENERATED COLS: ASSERTION POS < N_DEF
+--echo #
+
+CREATE TABLE s (a INT, b INT GENERATED ALWAYS AS (0) STORED, c INT,
+ d INT GENERATED ALWAYS AS (0) VIRTUAL, e INT) ENGINE=innodb;
+
+CREATE TABLE t (a INT) ENGINE=innodb;
+
+# This would fail. No corresponding index
+--error ER_FK_NO_INDEX_PARENT
+ALTER TABLE s ADD CONSTRAINT c FOREIGN KEY (e) REFERENCES t(a) ON UPDATE SET null;
+
+ALTER TABLE t ADD PRIMARY KEY(a);
+
+ALTER TABLE s ADD CONSTRAINT c FOREIGN KEY (e) REFERENCES t(a) ON UPDATE SET null;
+
+DROP TABLE s,t;
+
+CREATE TABLE s (a INT GENERATED ALWAYS AS (0) VIRTUAL,
+ b INT GENERATED ALWAYS AS (0) STORED, c INT) ENGINE=innodb;
+
+CREATE TABLE t (a INT) ENGINE=innodb;
+
+# This would fail. No corresponding index
+--error ER_FK_NO_INDEX_PARENT
+ALTER TABLE s ADD CONSTRAINT c FOREIGN KEY (c) REFERENCES t(a) ON UPDATE SET null;
+
+ALTER TABLE t ADD PRIMARY KEY(a);
+
+ALTER TABLE s ADD CONSTRAINT c FOREIGN KEY (c) REFERENCES t(a) ON UPDATE SET null;
+
+DROP TABLE s,t;
+
+CREATE TABLE s (a INT, b INT GENERATED ALWAYS AS (0) STORED) ENGINE=innodb;
+
+CREATE TABLE t (a INT PRIMARY KEY) ENGINE=innodb;
+
+ALTER TABLE s ADD CONSTRAINT c FOREIGN KEY (a) REFERENCES t(a) ON UPDATE SET null;
+
+DROP TABLE s,t;
+
+CREATE TABLE s (a INT, b INT) ENGINE=innodb;
+
+CREATE TABLE t (a INT) ENGINE=innodb;
+
+# This would fail. No corresponding index
+--error ER_FK_NO_INDEX_PARENT
+ALTER TABLE s ADD CONSTRAINT c FOREIGN KEY (a) REFERENCES t(a) ON UPDATE SET null;
+
+ALTER TABLE t ADD PRIMARY KEY(a);
+
+ALTER TABLE s ADD CONSTRAINT c FOREIGN KEY (a) REFERENCES t(a) ON UPDATE SET null;
+
+DROP TABLE s,t;
diff --git a/mysql-test/suite/innodb/t/strict_mode.test b/mysql-test/suite/innodb/t/strict_mode.test
new file mode 100644
index 00000000..34ccce5e
--- /dev/null
+++ b/mysql-test/suite/innodb/t/strict_mode.test
@@ -0,0 +1,422 @@
+--source include/have_innodb.inc
+--source include/not_embedded.inc
+
+--echo #
+--echo # Bug #17852083 PRINT A WARNING WHEN DDL HAS AN ERROR IN
+--echo # INNODB_STRICT_MODE = 1
+--echo #
+
+call mtr.add_suppression("InnoDB: Cannot add field .* in table");
+
+set innodb_strict_mode = 0;
+
+create table t1 (id int auto_increment primary key,
+v varchar(32),
+col1 text,
+col2 text,
+col3 text,
+col4 text,
+col5 text,
+col6 text,
+col7 text,
+col8 text,
+col9 text,
+col10 text,
+col11 text,
+col12 text,
+col13 text,
+col14 text,
+col15 text,
+col16 text,
+col17 text,
+col18 text,
+col19 text,
+col20 text,
+col21 text,
+col22 text,
+col23 text,
+col24 text,
+col25 text,
+col26 text,
+col27 text,
+col28 text,
+col29 text,
+col30 text,
+col31 text,
+col32 text,
+col33 text,
+col34 text,
+col35 text,
+col36 text,
+col37 text,
+col38 text,
+col39 text,
+col40 text,
+col41 text,
+col42 text,
+col43 text,
+col44 text,
+col45 text ,
+col46 text,
+col47 text,
+col48 text,
+col49 text,
+col50 text,
+col51 text,
+col52 text,
+col53 text,
+col54 text,
+col55 text,
+col56 text,
+col57 text,
+col58 text,
+col59 text,
+col60 text,
+col61 text,
+col62 text,
+col63 text,
+col64 text,
+col65 text,
+col66 text,
+col67 text,
+col68 text ,
+col69 text,
+col70 text,
+col71 text,
+col72 text,
+col73 text,
+col74 text,
+col75 text,
+col76 text,
+col77 text,
+col78 text,
+col79 text,
+col80 text,
+col81 text,
+col82 text,
+col83 text,
+col84 text,
+col85 text,
+col86 text,
+col87 text,
+col88 text,
+col89 text,
+col90 text,
+col91 text,
+col92 text,
+col93 text,
+col94 text,
+col95 text,
+col96 text,
+col97 text,
+col98 text,
+col99 text,
+col100 text,
+col101 text,
+col102 text,
+col103 text,
+col104 text,
+col105 text,
+col106 text,
+col107 text,
+col108 text,
+col109 text,
+col110 text,
+col111 text,
+col112 text,
+col113 text,
+col114 text,
+col115 text,
+col116 text,
+col117 text,
+col118 text,
+col119 text,
+col120 text,
+col121 text,
+col122 text,
+col123 text,
+col124 text,
+col125 text,
+col126 text ,
+col127 text,
+col128 text,
+col129 text,
+col130 text,
+col131 text,
+col132 text,
+col133 text,
+col134 text,
+col135 text,
+col136 text,
+col137 text,
+col138 text,
+col139 text,
+col140 text,
+col141 text,
+col142 text,
+col143 text,
+col144 text,
+col145 text,
+col146 text,
+col147 text ,
+col148 text,
+col149 text,
+col150 text,
+col151 text,
+col152 text,
+col153 text,
+col154 text,
+col155 text,
+col156 text,
+col157 text,
+col158 text,
+col159 text,
+col160 text,
+col161 text,
+col162 text,
+col163 text,
+col164 text,
+col165 text,
+col166 text,
+col167 text,
+col168 text,
+col169 text,
+col170 text,
+col171 text,
+col172 text ,
+col173 text,
+col174 text,
+col175 text,
+col176 text,
+col177 text,
+col178 text,
+col179 text,
+col180 text,
+col181 text,
+col182 text,
+col183 text,
+col184 text,
+col185 text,
+col186 text,
+col187 text,
+col188 text,
+col189 text,
+col190 text,
+col191 text,
+col192 text,
+col193 text,
+col194 text,
+col195 text,
+col196 text,
+col197 text,
+col198 text,
+col199 text,
+col200 text,
+col201 text,
+col202 text,
+col203 text,
+col204 text,
+col205 text,
+col206 text,
+col207 text,
+col208 text,
+col209 text,
+col210 text,
+col211 text,
+col212 text,
+col213 text,
+col214 text,
+col215 text,
+col216 text,
+col217 text,
+col218 text,
+col219 text,
+col220 text,
+col221 text,
+col222 text,
+col223 text,
+col224 text,
+col225 text,
+col226 text,
+col227 text,
+col228 text,
+col229 text,
+col230 text,
+col231 text,
+col232 text,
+col233 text,
+col234 text,
+col235 text,
+col236 text,
+col237 text,
+col238 text,
+col239 text,
+col240 text,
+col241 text,
+col242 text,
+col243 text,
+col244 text,
+col245 text,
+col246 text,
+col247 text,
+col248 text,
+col249 text,
+col250 text,
+col251 text,
+col252 text,
+col253 text,
+col254 text,
+col255 text,
+col256 text,
+col257 text,
+col258 text,
+col259 text,
+col260 text,
+col261 text,
+col262 text,
+col263 text,
+col264 text,
+col265 text,
+col266 text,
+col267 text,
+col268 text,
+col269 text,
+col270 text,
+col271 text,
+col272 text,
+col273 text,
+col274 text,
+col275 text,
+col276 text,
+col277 text,
+col278 text,
+col279 text,
+col280 text,
+col281 text,
+col282 text,
+col283 text,
+col284 text,
+col285 text,
+col286 text,
+col287 text,
+col288 text,
+col289 text,
+col290 text,
+col291 text,
+col292 text,
+col293 text,
+col294 text,
+col295 text,
+col296 text,
+col297 text,
+col298 text,
+col299 text,
+col300 text,
+col301 text,
+col302 text,
+col303 text,
+col304 text,
+col305 text,
+col306 text,
+col307 text,
+col308 text,
+col309 text,
+col310 text,
+col311 text,
+col312 text,
+col313 text,
+col314 text,
+col315 text,
+col316 text,
+col317 text,
+col318 text,
+col319 text,
+col320 text,
+col321 text,
+col322 text,
+col323 text,
+col324 text,
+col325 text,
+col326 text,
+col327 text,
+col328 text,
+col329 text,
+col330 text,
+col331 text,
+col332 text,
+col333 text,
+col334 text,
+col335 text,
+col336 text,
+col337 text,
+col338 text,
+col339 text,
+col340 text,
+col341 text,
+col342 text,
+col343 text,
+col344 text,
+col345 text,
+col346 text,
+col347 text,
+col348 text,
+col349 text,
+col350 text,
+col351 text,
+col352 text,
+col353 text,
+col354 text,
+col355 text,
+col356 text,
+col357 text,
+col358 text,
+col359 text,
+col360 text,
+col361 text,
+col362 text,
+col363 text,
+col364 text,
+col365 text,
+col366 text,
+col367 text,
+col368 text,
+col369 text,
+col370 text,
+col371 text,
+col372 text,
+col373 text,
+col374 text,
+col375 text,
+col376 text,
+col377 text,
+col378 text,
+col379 text,
+col380 text,
+col381 text,
+col382 text,
+col383 text
+) ENGINE=InnoDB;
+
+set innodb_strict_mode = 1;
+--error ER_TOO_BIG_ROWSIZE
+alter table t1 engine=InnoDB;
+
+drop table t1;
+
+--echo #
+--echo # MDEV-32128 wrong table name in innodb's "row too big" errors
+--echo #
+--error ER_TOO_BIG_ROWSIZE
+create temporary table t1 (
+ c1 char(255), c2 char(255), c3 char(255), c4 char(255),
+ c5 char(255), c6 char(255), c7 char(255), c8 char(255),
+ c9 char(255), c10 char(255), c11 char(255), c12 char(255),
+ c13 char(255), c14 char(255), c15 char(255), c16 char(255),
+ c17 char(255), c18 char(255), c19 char(255), c20 char(255),
+ c21 char(255), c22 char(255), c23 char(255), c24 char(255),
+ c25 char(255), c26 char(255), c27 char(255), c28 char(255),
+ c29 char(255), c30 char(255), c31 char(255), c32 char(255)
+) engine=innodb;
+let SEARCH_FILE=$MYSQLTEST_VARDIR/log/mysqld.1.err;
+let SEARCH_PATTERN=Cannot add field `c32` in table `test`.`t1` because;
+source include/search_pattern_in_file.inc;
diff --git a/mysql-test/suite/innodb/t/system_tables.test b/mysql-test/suite/innodb/t/system_tables.test
new file mode 100644
index 00000000..17262879
--- /dev/null
+++ b/mysql-test/suite/innodb/t/system_tables.test
@@ -0,0 +1,12 @@
+--source include/have_innodb.inc
+
+#
+# MDEV-10775 System table in InnoDB format allowed in MariaDB could lead to crash
+#
+alter table mysql.time_zone_name engine=InnoDB;
+create table envois3 (starttime datetime) engine=InnoDB;
+insert envois3 values ('2008-08-11 22:43:00');
+--source include/restart_mysqld.inc
+select convert_tz(starttime,'UTC','Europe/Moscow') starttime from envois3;
+drop table envois3;
+alter table mysql.time_zone_name engine=Aria;
diff --git a/mysql-test/suite/innodb/t/table_definition_cache_debug.opt b/mysql-test/suite/innodb/t/table_definition_cache_debug.opt
new file mode 100644
index 00000000..c2db7e1d
--- /dev/null
+++ b/mysql-test/suite/innodb/t/table_definition_cache_debug.opt
@@ -0,0 +1 @@
+--innodb-open-files=30
diff --git a/mysql-test/suite/innodb/t/table_definition_cache_debug.test b/mysql-test/suite/innodb/t/table_definition_cache_debug.test
new file mode 100644
index 00000000..8950691e
--- /dev/null
+++ b/mysql-test/suite/innodb/t/table_definition_cache_debug.test
@@ -0,0 +1,71 @@
+--source include/have_innodb.inc
+--source include/have_debug.inc
+--source include/have_debug_sync.inc
+# This test is slow on buildbot.
+--source include/big_test.inc
+
+call mtr.add_suppression("InnoDB: innodb_open_files=.* is exceeded");
+
+SET @save_tdc= @@GLOBAL.table_definition_cache;
+SET @save_toc= @@GLOBAL.table_open_cache;
+
+# InnoDB plugin essentially ignores table_definition_cache size
+# and hard-wires it to 400, which also is the minimum allowed value.
+SET GLOBAL table_definition_cache= 400;
+SET GLOBAL table_open_cache= 1024;
+
+CREATE TABLE to_be_evicted(a INT PRIMARY KEY, b INT NOT NULL) ENGINE=InnoDB;
+INSERT INTO to_be_evicted VALUES(1,2),(2,1);
+
+connect(ddl,localhost,root,,);
+SET DEBUG_SYNC = 'row_log_apply_before SIGNAL scanned WAIT_FOR got_duplicate';
+--send
+ALTER TABLE to_be_evicted ADD UNIQUE INDEX(b);
+
+connection default;
+SET DEBUG_SYNC = 'now WAIT_FOR scanned';
+
+# During the ADD UNIQUE INDEX, start a transaction that inserts a duplicate
+# and then hogs the table lock, so that the unique index cannot be dropped.
+BEGIN;
+INSERT INTO to_be_evicted VALUES(3, 2);
+COMMIT;
+SET DEBUG_SYNC = 'now SIGNAL got_duplicate';
+
+connection ddl;
+--error ER_DUP_ENTRY
+reap;
+
+disconnect ddl;
+connection default;
+# Release the table lock.
+COMMIT;
+SET DEBUG_SYNC = RESET;
+
+# Allow cache eviction.
+FLUSH TABLES;
+--disable_query_log
+
+# Pollute the cache with many tables, so that our table will be evicted.
+let $N=1000;
+let $loop=$N;
+while ($loop)
+{
+ eval CREATE TABLE t_$loop(id INT)ENGINE=InnoDB;
+ dec $loop;
+}
+
+# Hopefully let InnoDB evict the tables.
+sleep 10;
+
+let $loop=$N;
+while ($loop)
+{
+ eval DROP TABLE t_$loop;
+ dec $loop;
+}
+
+SET GLOBAL table_definition_cache= @save_tdc;
+SET GLOBAL table_open_cache= @save_toc;
+
+DROP TABLE to_be_evicted;
diff --git a/mysql-test/suite/innodb/t/table_flags.combinations b/mysql-test/suite/innodb/t/table_flags.combinations
new file mode 100644
index 00000000..72938059
--- /dev/null
+++ b/mysql-test/suite/innodb/t/table_flags.combinations
@@ -0,0 +1,5 @@
+[strict_crc32]
+--innodb-checksum-algorithm=strict_crc32
+
+[strict_full_crc32]
+--innodb-checksum-algorithm=strict_full_crc32
diff --git a/mysql-test/suite/innodb/t/table_flags.opt b/mysql-test/suite/innodb/t/table_flags.opt
new file mode 100644
index 00000000..bca67495
--- /dev/null
+++ b/mysql-test/suite/innodb/t/table_flags.opt
@@ -0,0 +1,2 @@
+--innodb-checksum-algorithm=crc32
+--skip-innodb-read-only-compressed
diff --git a/mysql-test/suite/innodb/t/table_flags.test b/mysql-test/suite/innodb/t/table_flags.test
new file mode 100644
index 00000000..34204ae1
--- /dev/null
+++ b/mysql-test/suite/innodb/t/table_flags.test
@@ -0,0 +1,253 @@
+--source include/innodb_page_size.inc
+# Embedded server tests do not support restarting
+--source include/not_embedded.inc
+# Slow shutdown may take more than 120 seconds under Valgrind,
+# causing the server to be (silently) killed.
+# Due to that, crash recovery could "heal" the damage that our
+# Perl code is inflicting, and the SELECT statements could succeed
+# instead of failing with ER_NO_SUCH_TABLE_IN_ENGINE.
+--source include/not_valgrind.inc
+
+--disable_query_log
+call mtr.add_suppression("InnoDB: Table `mysql`\\.`innodb_table_stats` not found");
+call mtr.add_suppression("InnoDB: incorrect flags in SYS_TABLES");
+call mtr.add_suppression("InnoDB: Table test/t[cp] in InnoDB data dictionary contains invalid flags\\. SYS_TABLES\\.TYPE=(129|289|3873|1232[31]) SYS_TABLES\\.N_COLS=2147483649\\r?$");
+call mtr.add_suppression("InnoDB: Table test/tr in InnoDB data dictionary contains invalid flags\\. SYS_TABLES\\.TYPE=65 SYS_TABLES\\.MIX_LEN=4294967295\\r?$");
+call mtr.add_suppression("InnoDB: Refusing to load '\\..test.td\\.ibd' \\(id=3, flags=0x([2e]1)\\); dictionary contains id=3, flags=0x100\\1\\r?$");
+call mtr.add_suppression("InnoDB: Refusing to load '\\..test.td\\.ibd' \\(id=3, flags=0x(1[2ae]1)\\); dictionary contains id=3, flags=0x10\\1\\r?$");
+call mtr.add_suppression("InnoDB: Ignoring tablespace for `test`.`td` because it could not be opened\\.");
+# FIXME: Remove the following spam due to invalid flags for test.td
+call mtr.add_suppression("InnoDB: Operating system error number .* in a file operation");
+call mtr.add_suppression("InnoDB: The error means the system cannot find the path specified");
+call mtr.add_suppression("InnoDB: adjusting FSP_SPACE_FLAGS of file ");
+call mtr.add_suppression("InnoDB: Parent table of FTS auxiliary table .* not found.");
+FLUSH TABLES;
+--enable_query_log
+
+let INNODB_PAGE_SIZE=`select @@innodb_page_size`;
+let MYSQLD_DATADIR=`select @@datadir`;
+
+let bugdir= $MYSQLTEST_VARDIR/tmp/table_flags;
+--mkdir $bugdir
+--let SEARCH_FILE = $MYSQLTEST_VARDIR/log/mysqld.1.err
+
+--let $d=--innodb-data-home-dir=$bugdir --innodb-log-group-home-dir=$bugdir
+--let $d=$d --innodb-data-file-path=ibdata1:1M:autoextend
+--let $d=$d --innodb-undo-tablespaces=0
+--let $d=$d --skip-innodb-fast-shutdown
+--let $restart_noprint=1
+--let $restart_parameters=$d --innodb-stats-persistent=0
+--source include/restart_mysqld.inc
+
+SET GLOBAL innodb_file_per_table=1;
+CREATE TABLE tr(a INT PRIMARY KEY)ENGINE=InnoDB ROW_FORMAT=REDUNDANT;
+CREATE TABLE tc(a INT PRIMARY KEY)ENGINE=InnoDB ROW_FORMAT=COMPACT;
+CREATE TABLE td(a INT PRIMARY KEY)ENGINE=InnoDB ROW_FORMAT=DYNAMIC;
+SET innodb_strict_mode=OFF;
+CREATE TABLE tz(a INT PRIMARY KEY)ENGINE=InnoDB ROW_FORMAT=COMPRESSED
+KEY_BLOCK_SIZE=1;
+SET innodb_strict_mode=ON;
+# PAGE_COMPRESSED is supported starting with MariaDB 10.1.0
+CREATE TABLE tp(a INT PRIMARY KEY)ENGINE=InnoDB ROW_FORMAT=DYNAMIC
+PAGE_COMPRESSED=1 PAGE_COMPRESSION_LEVEL=9;
+
+--source include/shutdown_mysqld.inc
+--perl
+use strict;
+do "$ENV{MTR_SUITE_DIR}/include/crc32.pl";
+my $ps= $ENV{INNODB_PAGE_SIZE};
+my $file= "$ENV{bugdir}/ibdata1";
+open(FILE, "+<", $file) || die "Unable to open $file\n";
+die "Unable to read $file" unless sysread(FILE, $_, 58) == 58;
+my $full_crc32 = unpack("N",substr($_,54,4)) & 0x10; # FIL_SPACE_FLAGS
+# Read DICT_HDR_TABLES, the root page number of CLUST_IND (SYS_TABLES.NAME).
+sysseek(FILE, 7*$ps+38+32, 0) || die "Unable to seek $file";
+die "Unable to read $file" unless sysread(FILE, $_, 4) == 4;
+my $sys_tables_root = unpack("N", $_);
+my $page;
+print "SYS_TABLES clustered index root page ($sys_tables_root):\n";
+sysseek(FILE, $sys_tables_root*$ps, 0) || die "Unable to seek $file";
+die "Unable to read $file" unless sysread(FILE, $page, $ps) == $ps;
+open(BACKUP, ">$ENV{bugdir}/sys_tables.bin") || die "Unable to open backup\n";
+syswrite(BACKUP, $page, $ps)==$ps || die "Unable to write backup\n";
+close(BACKUP) || die "Unable to close backup\n";
+print "N_RECS=", unpack("n", substr($page,38+16,2));
+print "; LEVEL=", unpack("n", substr($page,38+26,2));
+print "; INDEX_ID=0x", unpack("H*", substr($page,38+28,8)), "\n";
+my @fields=("NAME","DB_TRX_ID","DB_ROLL_PTR",
+ "ID","N_COLS","TYPE","MIX_ID","MIX_LEN","CLUSTER_NAME","SPACE");
+for (my $offset= 0x65; $offset;
+ $offset= unpack("n", substr($page,$offset-2,2)))
+{
+ print "header=0x", unpack("H*",substr($page,$offset-6,6)), " (";
+ my $n_fields= unpack("n", substr($page,$offset-4,2)) >> 1 & 0x3ff;
+ my $start= 0;
+ my $name;
+ for (my $i= 0; $i < $n_fields; $i++) {
+ my $end= unpack("C", substr($page, $offset-7-$i, 1));
+ print ",\n " if $i;
+ print "$fields[$i]=";
+ if ($end & 0x80) {
+ print "NULL(", ($end & 0x7f) - $start, " bytes)"
+ } elsif ($n_fields > 1 && $i == 0) {
+ $name= substr($page,$offset+$start,$end-$start);
+ print "'$name'"
+ } else {
+ print "0x", unpack("H*", substr($page,$offset+$start,$end-$start))
+ }
+ # Corrupt SYS_TABLES.TYPE
+ if ($i == 5)
+ {
+ my $flags= 0;
+ if ($name eq 'test/tr') {
+ $flags= 0x40 # DATA_DIR (largely ignored by 10.1+)
+ } elsif ($name eq 'test/tc') {
+ $flags= 0x80 # 10.1 PAGE_COMPRESSED
+ } elsif ($name eq 'test/td') {
+ $flags= 0xf00 # PAGE_COMPRESSION_LEVEL=15 (0..9 is valid)
+ # As part of the MDEV-12873 fix, because the
+ # PAGE_COMPRESSED=YES flag was not set, we will assume that
+ # this table was actually created with 10.2.2..10.2.6
+ # using PAGE_COMPRESSED=YES PAGE_COMPRESSION_LEVEL=7.
+ } elsif ($name eq 'test/tz') {
+ $flags= 0x3000 # 10.1 ATOMIC_WRITES=3 (0..2 is valid)
+ } elsif ($name eq 'test/tp') {
+ $flags= 0x880 # 10.1 PAGE_COMPRESSED, PAGE_COMPRESSION_LEVEL=8
+ # (in 10.2.2 through 10.2.6, this is interpreted as
+ # PAGE_COMPRESSION_LEVEL=4 without PAGE_COMPRESSED
+ # but with SHARED_SPACE, which should be invalid)
+ }
+
+ substr($page,$offset+$start,$end-$start)= pack(
+ "N", $flags ^
+ unpack("N", substr($page,$offset+$start,$end-$start)))
+ if $flags;
+ }
+ # Corrupt SYS_TABLES.MIX_LEN (ignored for ROW_FORMAT=REDUNDANT)
+ if ($i == 7 && $name eq 'test/tr')
+ {
+ substr($page,$offset+$start,$end-$start)= chr(255) x 4;
+ }
+ $start= $end & 0x7f;
+ }
+ print ")\n";
+}
+my $polynomial = 0x82f63b78; # CRC-32C
+if ($full_crc32)
+{
+ my $ck = mycrc32(substr($page, 0, $ps-4), 0, $polynomial);
+ substr($page, $ps-4, 4) = pack("N", $ck);
+}
+else
+{
+ my $ck= pack("N",mycrc32(substr($page, 4, 22), 0, $polynomial) ^
+ mycrc32(substr($page, 38, $ps - 38 - 8), 0, $polynomial));
+ substr($page,0,4)=$ck;
+ substr($page,$ps-8,4)=$ck;
+}
+sysseek(FILE, $sys_tables_root*$ps, 0) || die "Unable to seek $file";
+syswrite(FILE, $page, $ps)==$ps || die "Unable to write $file\n";
+close(FILE) || die "Unable to close $file\n";
+EOF
+--source include/start_mysqld.inc
+
+--error ER_NO_SUCH_TABLE_IN_ENGINE
+SHOW CREATE TABLE tr;
+--error ER_NO_SUCH_TABLE_IN_ENGINE
+SHOW CREATE TABLE tc;
+--error ER_NO_SUCH_TABLE_IN_ENGINE
+SELECT * FROM tc;
+SHOW CREATE TABLE td;
+SELECT * FROM td;
+# This table was converted to NO_ROLLBACK due to the SYS_TABLES.TYPE change.
+SHOW CREATE TABLE tz;
+BEGIN;
+INSERT INTO tz VALUES(42);
+ROLLBACK;
+SELECT * FROM tz;
+--error ER_NO_SUCH_TABLE_IN_ENGINE
+SHOW CREATE TABLE tp;
+
+--source include/shutdown_mysqld.inc
+
+let SEARCH_FILE= $MYSQLTEST_VARDIR/log/mysqld.1.err;
+--let SEARCH_PATTERN= InnoDB: Table test/t[cp] in InnoDB data dictionary contains invalid flags\. SYS_TABLES\.TYPE=(129|289|3873|1232[13]) SYS_TABLES\.N_COLS=2147483649
+--source include/search_pattern_in_file.inc
+--let SEARCH_PATTERN= InnoDB: Table test/tr in InnoDB data dictionary contains invalid flags\. SYS_TABLES\.TYPE=65 SYS_TABLES\.MIX_LEN=4294967295\b
+--source include/search_pattern_in_file.inc
+
+# Restore the backup of the corrupted SYS_TABLES clustered index root page
+--perl
+use strict;
+my $ps= $ENV{INNODB_PAGE_SIZE};
+my $file= "$ENV{bugdir}/ibdata1";
+open(FILE, "+<", $file) || die "Unable to open $file\n";
+open(BACKUP, "<$ENV{bugdir}/sys_tables.bin") || die "Unable to open backup\n";
+# Read DICT_HDR_TABLES, the root page number of CLUST_IND (SYS_TABLES.NAME).
+sysseek(FILE, 7*$ps+38+32, 0) || die "Unable to seek $file";
+die "Unable to read $file\n" unless sysread(FILE, $_, 4) == 4;
+my $sys_tables_root = unpack("N", $_);
+print "Restoring SYS_TABLES clustered index root page ($sys_tables_root)\n";
+sysseek(FILE, $sys_tables_root*$ps, 0) || die "Unable to seek $file";
+die "Unable to read backup\n" unless sysread(BACKUP, $_, $ps) == $ps;
+die "Unable to restore backup\n" unless syswrite(FILE, $_, $ps) == $ps;
+close(BACKUP);
+close(FILE) || die "Unable to close $file\n";
+EOF
+--source include/start_mysqld.inc
+
+SHOW CREATE TABLE tr;
+SHOW CREATE TABLE tc;
+SHOW CREATE TABLE td;
+SHOW CREATE TABLE tz;
+SHOW CREATE TABLE tp;
+
+BEGIN;
+INSERT INTO tr VALUES(1);
+INSERT INTO tc VALUES(1);
+INSERT INTO td VALUES(1);
+# We cannot access tz, because due to our fiddling of the NO_ROLLBACK flag,
+# it now has a record with DB_TRX_ID=0, which is invalid for
+# transactional tables until MDEV-12288 is implemented.
+# INSERT INTO tz VALUES(1);
+INSERT INTO tp VALUES(1);
+ROLLBACK;
+
+SELECT * FROM tr;
+SELECT * FROM tc;
+SELECT * FROM td;
+# SELECT * FROM tz;
+SELECT * FROM tp;
+
+DROP TABLE tr,tc,td,tz,tp;
+
+--let $restart_parameters=
+--source include/restart_mysqld.inc
+
+--error 0,1
+--remove_file $bugdir/ibtmp1
+--error 0,1
+--remove_file $bugdir/ib_buffer_pool
+
+--list_files $bugdir
+--remove_files_wildcard $bugdir
+--rmdir $bugdir
+
+call mtr.add_suppression("ERROR HY000: Can't create table `test`.`t1`");
+--error ER_CANT_CREATE_TABLE
+CREATE TABLE t1(f1 INT, f2 VARCHAR(1), KEY k1(f2),
+ FULLTEXT KEY(f2),
+ FOREIGN KEY (f2) REFERENCES t1(f3))ENGINE=InnoDB;
+
+--echo #
+--echo # MDEV-23199 page_compression flag is missing
+--echo # for full_crc32 tablespace
+--echo #
+
+CREATE TABLE t1(f1 BIGINT PRIMARY KEY)ENGINE=InnoDB;
+INSERT INTO t1 VALUES(1);
+ALTER TABLE t1 PAGE_COMPRESSED = 1;
+INSERT INTO t1 VALUES(2);
+let $shutdown_timeout = 0;
+--source include/restart_mysqld.inc
+DROP TABLE t1;
diff --git a/mysql-test/suite/innodb/t/table_index_statistics.inc b/mysql-test/suite/innodb/t/table_index_statistics.inc
new file mode 100644
index 00000000..01f8af06
--- /dev/null
+++ b/mysql-test/suite/innodb/t/table_index_statistics.inc
@@ -0,0 +1,61 @@
+# include file to test index and table statstics for specific storage engine
+# requires includer set the default strorage engine for the session
+
+# Bug 602047 (wrong rows_read value)
+
+FLUSH INDEX_STATISTICS;
+FLUSH TABLE_STATISTICS;
+
+SET @userstat_old= @@userstat;
+SET GLOBAL userstat=ON;
+
+--disable_ps2_protocol
+CREATE TABLE t1 (id int(10), PRIMARY KEY (id));
+INSERT INTO t1 VALUES (1),(2),(3),(4),(5),(6),(7),(8),(9),(10);
+SELECT COUNT(*) FROM t1;
+SELECT ROWS_READ FROM INFORMATION_SCHEMA.TABLE_STATISTICS WHERE TABLE_NAME='t1';
+SELECT ROWS_READ FROM INFORMATION_SCHEMA.INDEX_STATISTICS WHERE TABLE_NAME='t1';
+
+# Test that FLUSH clears one table but not another
+
+FLUSH TABLE_STATISTICS;
+
+SELECT ROWS_READ FROM INFORMATION_SCHEMA.TABLE_STATISTICS WHERE TABLE_NAME='t1';
+SELECT ROWS_READ FROM INFORMATION_SCHEMA.INDEX_STATISTICS WHERE TABLE_NAME='t1';
+
+# Test that FLUSH clears both tables now
+
+FLUSH INDEX_STATISTICS;
+
+SELECT ROWS_READ FROM INFORMATION_SCHEMA.INDEX_STATISTICS WHERE TABLE_NAME='t1';
+
+# Test that stats are collected after the FLUSH again
+
+SELECT COUNT(*) FROM t1;
+SELECT ROWS_READ FROM INFORMATION_SCHEMA.TABLE_STATISTICS WHERE TABLE_NAME='t1';
+SELECT ROWS_READ FROM INFORMATION_SCHEMA.INDEX_STATISTICS WHERE TABLE_NAME='t1';
+--enable_ps2_protocol
+
+DROP TABLE t1;
+
+# Bug 1183625 (handler::update_global_table_stats crash).
+
+CREATE TABLE t2 (c1 INT UNSIGNED);
+
+ALTER TABLE t2 MODIFY c1 FLOAT;
+
+SELECT * FROM INFORMATION_SCHEMA.TABLE_STATISTICS WHERE TABLE_NAME='t2';
+
+DROP TABLE t2;
+
+# Bug 1183625 (handler::update_global_table_stats crash).
+
+CREATE TABLE t2 (c1 INT UNSIGNED);
+
+ALTER TABLE t2 MODIFY c1 FLOAT;
+
+SELECT * FROM INFORMATION_SCHEMA.TABLE_STATISTICS WHERE TABLE_NAME='t2';
+
+DROP TABLE t2;
+
+SET GLOBAL userstat= @userstat_old;
diff --git a/mysql-test/suite/innodb/t/table_index_statistics.test b/mysql-test/suite/innodb/t/table_index_statistics.test
new file mode 100644
index 00000000..697f4d64
--- /dev/null
+++ b/mysql-test/suite/innodb/t/table_index_statistics.test
@@ -0,0 +1,8 @@
+--source include/have_innodb.inc
+
+SET @default_storage_engine_old = @@session.default_storage_engine;
+SET SESSION default_storage_engine = INNODB;
+
+--source ./table_index_statistics.inc
+
+SET SESSION default_storage_engine = @default_storage_engine_old;
diff --git a/mysql-test/suite/innodb/t/temp_table.test b/mysql-test/suite/innodb/t/temp_table.test
new file mode 100644
index 00000000..0fdcb6c6
--- /dev/null
+++ b/mysql-test/suite/innodb/t/temp_table.test
@@ -0,0 +1,54 @@
+--source include/have_innodb.inc
+
+####################################################################
+# TC to test temp-table DML optimization changes for correctness #
+# Sceanrio covered: #
+# 1. bulk-insert with rollback + commit: this will ensure btree #
+# node split with rollback and commit. #
+####################################################################
+
+#-------------------------------------------------------------------
+#
+# 1. bulk-insert with rollback + commit: this will ensure btree #
+# node split with rollback and commit. #
+#
+create temporary table t1
+ (keyc int, c1 char(100), c2 char(100),
+ primary key(keyc), index sec_index(c1)
+ ) engine = innodb;
+create temporary table t2
+ (keyc int, c1 char(100), c2 char(100),
+ primary key(keyc), index sec_index(c1)
+ ) engine = innodb;
+--source suite/innodb/include/dml_ops.inc
+drop temporary table t1,t2;
+#
+--error ER_UNSUPPORTED_COMPRESSED_TABLE
+create temporary table t1
+ (keyc int, c1 char(100), c2 char(100),
+ primary key(keyc), index sec_index(c1)
+ ) engine = innodb key_block_size = 4;
+create temporary table t1
+ (keyc int, c1 char(100), c2 char(100),
+ primary key(keyc), index sec_index(c1)
+ ) engine = innodb;
+set innodb_strict_mode=off;
+--disable_warnings
+create temporary table t2
+ (keyc int, c1 char(100), c2 char(100),
+ primary key(keyc), index sec_index(c1)
+ ) engine = innodb key_block_size = 8;
+set innodb_strict_mode=on;
+--enable_warnings
+--source suite/innodb/include/dml_ops.inc
+drop temporary table t1, t2;
+#
+create temporary table t1
+ (keyc int, c1 char(100), c2 char(100),
+ primary key(keyc), index sec_index(c1)
+ ) engine = innodb;
+create temporary table t2
+ (keyc int, c1 char(100), c2 char(100),
+ primary key(keyc), index sec_index(c1)
+ ) engine = innodb;
+--source suite/innodb/include/dml_ops.inc
diff --git a/mysql-test/suite/innodb/t/temp_table_savepoint.test b/mysql-test/suite/innodb/t/temp_table_savepoint.test
new file mode 100644
index 00000000..fd1d06b4
--- /dev/null
+++ b/mysql-test/suite/innodb/t/temp_table_savepoint.test
@@ -0,0 +1,215 @@
+--source include/have_innodb.inc
+--source include/innodb_row_format.inc
+
+####################################################################
+# TC to test temp-table DML optimization changes for correctness #
+# Sceanrio covered in single testcase : #
+# - Tables with row format(redundant,dynamic,compact) #
+# - Table with primary,composite,prefix,secondary index #
+# - Insert/delete/update with transactioons #
+# - Transaction with commit,rollback,savepoint statements #
+# - Concurrency by execution of two clients creating tables with #
+# same names #
+# - Inserting data using #
+# - Insert into .. , Load data infile..,insert ignore #
+# - Insert into .. on duplicate update #
+# - Check basic delete and update [ignore] #
+# - Check constraints like duplicate key,default value #
+# - Alter add column , add primary key #
+# - with prepare and execute statement #
+####################################################################
+
+# Create procedure to perform
+# 1. Create temp table with row types , index , sufficent data types
+# 2. Perform DML with transaction
+delimiter |;
+create procedure populate_tables()
+ begin
+ declare n int default 20;
+ declare inner_loop int default 100;
+
+ create temporary table t5(c1 int not null,
+ c2 int not null,
+ c3 char(255) not null,
+ c4 text(6000) not null,
+ c5 blob(6000) not null,
+ c6 varchar(2000) not null,
+ c7 varchar(2000) not null,
+ c8 datetime,
+ c9 decimal(6,3),
+ primary key (c1),
+ index (c3,c4(50),c5(50)),
+ index (c2))
+ engine=innodb;
+
+ create temporary table t6 ( a int ) engine = innodb;
+ insert into t6 values (50),(100),(150),(190);
+
+ while (n > 0) do
+ start transaction;
+ insert ignore into t5 values(n,n,repeat(concat(' tc3_',n),30),
+ repeat(concat(' tc4_',n),800),repeat(concat(' tc_',n),800),
+ repeat(concat(' tc6_',n),800),repeat(concat(' tc7_',n),800),
+ now(),(100.55+n));
+
+ if (n > 10) then
+ commit;
+ else
+ delete from t5 where c1 > 10 ;
+
+ rollback;
+ start transaction;
+ update t5 set c1 = c1 + 1000 where c1 > 10;
+ rollback;
+ end if;
+
+ start transaction;
+ insert ignore into t5 values(n+inner_loop,n+inner_loop,repeat(concat(' tc3_',n+inner_loop),30),
+ repeat(concat(' tc4_',n+inner_loop),800),repeat(concat(' tc_',n+inner_loop),800),
+ repeat(concat(' tc6_',n+inner_loop),245),repeat(concat(' tc7_',n+inner_loop),245),
+ now(),(100.55+n+inner_loop));
+
+ delete from t5 where c1 between 100 and 110;
+
+ update t5 set c1 = c1+1 where c1>110;
+
+ savepoint a;
+
+ insert ignore into t5 values(300+n+inner_loop,n+inner_loop,repeat(concat(' tc3_',n+inner_loop),30),
+ repeat(concat(' tc4_',n+inner_loop),800),repeat(concat(' tc_',n+inner_loop),800),
+ repeat(concat(' tc6_',n+inner_loop),245),repeat(concat(' tc7_',n+inner_loop),245),
+ now(),(100.55+n+inner_loop));
+ savepoint b;
+
+ insert into t5 values(400+n+inner_loop,n+inner_loop,repeat(concat(' tc3_',n+inner_loop),30),
+ repeat(concat(' tc4_',n+inner_loop),800),repeat(concat(' tc_',n+inner_loop),800),
+ repeat(concat(' tc6_',n+inner_loop),245),repeat(concat(' tc7_',n+inner_loop),245),
+ now(),(100.55+n+inner_loop));
+ savepoint c;
+ rollback to b;
+ rollback to a;
+ commit;
+ commit;
+ rollback;
+ set n = n - 1;
+ end while;
+end|
+delimiter ;|
+
+# Create two client for concurrent execution
+connect (con1,localhost,root,,);
+--send call populate_tables();
+
+connect (con2,localhost,root,,);
+--send call populate_tables();
+
+connection con1;
+--reap
+# 20 rows expected
+select c1 from t5;
+
+connection con2;
+--reap
+# 20 rows expected
+select c1 from t5;
+
+connection con1;
+
+set autocommit = 0;
+# Check duplicate key constraint + insert ignore
+--error ER_DUP_ENTRY
+insert into t5 values (20,1,'a','a','a','a','a',now(),100.55);
+insert ignore into t5 values (20,1,'a','a','a','a','a',now(),100.55);
+
+# check rollback due to duplicate value in second record of insert
+--error ER_DUP_ENTRY
+insert into t5 values (1,1,'a','a','a','a','a',now(),100.55),
+(20,1,'a','a','a','a','a',now(),100.55);
+
+set autocommit = 1;
+
+select c1,c2 from t5 where c1 in (20,1);
+
+#replace statement
+replace into t5 values (20,1,'a','a','a','a','a',now(),100.55);
+# verify row is replaced from (20,20) to (20,1)
+select c1,c2,c3,c4,c5,c6,c7,c9 from t5 where c1 = 20;
+
+# Update ignore. statement is ignored as 20 value exists
+update ignore t5 set c1 = 20 where c1 = 140 ;
+# see record 140 is present as last update ignored
+select count(*) from t5 where c1 = 140;
+
+--replace_result $MYSQLTEST_VARDIR VARDIR
+--disable_ps2_protocol
+eval select * into outfile "$MYSQLTEST_VARDIR/tmp/t5.outfile" from t5;
+--enable_ps2_protocol
+
+
+create temporary table temp_1 engine = innodb as select * from t5 where 1=2;
+select count(*) from temp_1;
+
+--replace_result $MYSQLTEST_VARDIR VARDIR
+eval load data infile '$MYSQLTEST_VARDIR/tmp/t5.outfile' into table temp_1;
+select count(*) from temp_1;
+--remove_file $MYSQLTEST_VARDIR/tmp/t5.outfile
+
+# Alter table to add column and primary key
+alter table temp_1 add column c10 int default 99 ,
+add column c11 varchar(100) default 'test';
+alter table temp_1 add primary key (c1);
+insert into temp_1 (c1,c2,c3,c4,c5,c6,c7,c8,c9) values (-1,-1,'a','a','a','a','a',now(),100.55);
+select c1,c2,c3,c4,c5,c6,c7,c9,c10,c11 from temp_1 where c1 < 0;
+select count(*) from temp_1 where c10 = 99 and c11 like 'test';
+# insert on duplicate key update
+insert into temp_1 (c1,c2,c3,c4,c5,c6,c7,c8,c9) values (-1,-1,'a','a','a','a','a',now(),100.55)
+on duplicate key update c1=-2,c2=-2;
+select c1,c2,c3,c4,c5,c6,c7,c9,c10,c11 from temp_1 where c1 < 0;
+
+disconnect con1;
+disconnect con2;
+connection default;
+drop procedure populate_tables;
+
+# case 2 - with prepare and execute
+let $prep_loop= 5;
+create temporary table prep_1(c1 int not null,
+ c2 int not null,
+ c3 char(255) not null,
+ c4 text(6000) not null,
+ c5 blob(6000) not null,
+ c6 varchar(2000) not null,
+ c7 varchar(2000) not null,
+ c8 datetime,
+ c9 decimal(6,3),
+ index (c3,c4(50),c5(50)),
+ index (c2))
+engine=innodb;
+PREPARE stm FROM "insert into prep_1 values(?,?,repeat(concat(' tc3_',?),30),repeat(concat(' tc4_',?),800),repeat(concat(' tc_',?),800),repeat(concat(' tc6_',?),245),repeat(concat(' tc7_',?),245),now(),(100.55+?))";
+set @var = 5;
+set @var_static = 5;
+while ($prep_loop>0)
+{
+ eval EXECUTE stm USING @var,@var,@var,@var,@var,@var,@var,@var;
+ eval EXECUTE stm USING @var_static,@var_static,@var_static,@var_static,@var_static,@var_static,@var_static,@var_static;
+ dec $prep_loop;
+ set @var = @var - 1;
+}
+select c1,left(c3,15) from prep_1 order by c1 ;
+select count(*) from prep_1;
+
+PREPARE stm_1 FROM "UPDATE prep_1 SET c1 = c1 + 1";
+EXECUTE stm_1;
+EXECUTE stm_1;
+select c1,left(c3,15) from prep_1 order by c1 ;
+select count(*) from prep_1;
+
+PREPARE stm_2 FROM "DELETE FROM prep_1 ORDER BY c1 LIMIT 1";
+EXECUTE stm_2;
+EXECUTE stm_2;
+select c1,left(c3,15) from prep_1 order by c1 ;
+select count(*) from prep_1;
+
+drop prepare stm;
+drop prepare stm_1;
+drop prepare stm_2;
diff --git a/mysql-test/suite/innodb/t/temporary_table.test b/mysql-test/suite/innodb/t/temporary_table.test
new file mode 100644
index 00000000..b09ff7c7
--- /dev/null
+++ b/mysql-test/suite/innodb/t/temporary_table.test
@@ -0,0 +1,638 @@
+#
+# InnoDB temporary table test case, including
+# WL#6560: InnoDB: separate tablespace for innodb-temp-tables.
+# WL#7899: InnoDB: Map compressed temporary tables to uncompressed
+#
+
+--source include/have_innodb.inc
+--source include/innodb_page_size.inc
+# Embedded server does not restart of server
+--source include/not_embedded.inc
+--source include/no_valgrind_without_big.inc
+
+--disable_query_log
+call mtr.add_suppression("Can't create/write to file '' \\\(Errcode: 20 \"Not a directory\"\\\)");
+call mtr.add_suppression("Can't create/write to file '/dev/null/.*/ib");
+call mtr.add_suppression("InnoDB: Unable to create temporary file");
+call mtr.add_suppression("last file in setting innodb_temp_data_file_path");
+call mtr.add_suppression("The table 't1' is full");
+call mtr.add_suppression("Plugin 'InnoDB' init function returned error");
+call mtr.add_suppression("Plugin 'InnoDB' registration as a STORAGE ENGINE failed");
+call mtr.add_suppression("InnoDB: Tablespace doesn't support raw devices");
+call mtr.add_suppression("InnoDB: Plugin initialization aborted");
+call mtr.add_suppression("innodb_temporary and innodb_system file names seem to be the same");
+call mtr.add_suppression("Could not create the shared innodb_temporary");
+call mtr.add_suppression("InnoDB: syntax error in file path");
+call mtr.add_suppression("InnoDB: Unable to parse innodb_temp_data_file_path=");
+--enable_query_log
+
+let $MYSQL_TMP_DIR = `select @@tmpdir`;
+let $MYSQL_DATA_DIR = `select @@datadir`;
+
+--echo # files in MYSQL_DATA_DIR
+--list_files $MYSQL_DATA_DIR/ ibtmp*
+
+create temporary table t1 (i int, f float, c char(100)) engine=innodb;
+insert into t1 values (100, 1.1, 'pune');
+insert into t1 values (99, 1.2, 'mumbai');
+insert into t1 values (98, 1.3, 'jaipur');
+insert into t1 values (97, 1.4, 'delhi');
+insert into t1 values (96, 1.5, 'ahmedabad');
+select * from t1;
+select * from t1 where i = 98;
+select * from t1 where i < 100;
+
+explain select * from t1 where f > 1.29999;
+alter table t1 add index sec_index(f);
+explain select * from t1 where f > 1.29999;
+select * from t1 where f > 1.29999;
+
+explain select * from t1 where i = 100;
+alter table t1 add unique index pri_index(i);
+explain select * from t1 where i = 100;
+select * from t1 where i = 100;
+
+delete from t1 where i < 97;
+select * from t1;
+insert into t1 values (96, 1.5, 'kolkata');
+select * from t1;
+
+update t1 set f = 1.44 where c = 'delhi';
+select * from t1;
+
+truncate table t1;
+insert into t1 values (100, 1.1, 'pune');
+insert into t1 values (99, 1.2, 'mumbai');
+insert into t1 values (98, 1.3, 'jaipur');
+insert into t1 values (97, 1.4, 'delhi');
+insert into t1 values (96, 1.5, 'ahmedabad');
+select * from t1;
+
+--error ER_CANNOT_DISCARD_TEMPORARY_TABLE
+alter table t1 discard tablespace;
+--error ER_CANNOT_DISCARD_TEMPORARY_TABLE
+alter table t1 import tablespace;
+drop temporary table t1;
+
+create temporary table t1
+ (keyc int, c1 char(100), c2 char(100),
+ primary key(keyc)) engine = innodb;
+delimiter |;
+CREATE PROCEDURE populate_t1()
+BEGIN
+ DECLARE i INT DEFAULT 1;
+ while (i <= 20000) DO
+ insert into t1 values (i, 'a', 'b');
+ SET i = i + 1;
+ END WHILE;
+END|
+delimiter ;|
+set autocommit=0;
+select count(*) from t1;
+call populate_t1();
+select count(*) from t1;
+select * from t1 limit 10;
+set autocommit=1;
+truncate table t1;
+select * from t1;
+#
+
+--echo # test condition of full-temp-tablespace
+--let $restart_parameters= --innodb_temp_data_file_path=ibtmp1:12M
+--source include/restart_mysqld.inc
+
+create temporary table t1
+ (keyc int, c1 char(100), c2 char(100),
+ primary key(keyc)) engine = innodb;
+begin;
+--error ER_RECORD_FILE_FULL
+call populate_t1();
+
+drop procedure populate_t1;
+
+--echo # test read-only mode
+--let $restart_parameters = --innodb-read-only
+--source include/restart_mysqld.inc
+
+--echo # files in MYSQL_DATA_DIR
+--list_files $MYSQL_DATA_DIR/ ibtmp*
+
+--error ER_NO_SUCH_TABLE
+select * from t1;
+show tables;
+--error ER_CANT_CREATE_TABLE
+create temporary table t1 (keyc int, c1 char(100), c2 char(100)) engine = innodb;
+
+SET GLOBAL innodb_encrypt_tables=DEFAULT;
+
+--echo # test various bad start-up parameters
+
+let SEARCH_FILE = $MYSQLTEST_VARDIR/log/mysqld.1.err;
+let SEARCH_ABORT = NOT FOUND;
+let $check_no_innodb=SELECT * FROM INFORMATION_SCHEMA.ENGINES WHERE engine = 'innodb'
+AND support IN ('YES', 'DEFAULT', 'ENABLED');
+
+# We cannot use include/restart_mysqld.inc in this particular test,
+# because SHOW STATUS would fail due to unwritable (nonexistent) tmpdir.
+--source include/shutdown_mysqld.inc
+--exec echo "restart: --tmpdir=/dev/null/$MYSQL_TMP_DIR --skip-innodb-fast-shutdown" > $_expect_file_name
+--enable_reconnect
+--disable_result_log
+--disable_query_log
+let $counter= 5000;
+let $mysql_errno= 9999;
+while ($mysql_errno)
+{
+ --error 0,ER_SERVER_SHUTDOWN,ER_CONNECTION_KILLED,2002,2006,2013,2026
+ select 1;
+
+ dec $counter;
+ if (!$counter)
+ {
+ --die Server failed to restart
+ }
+ --sleep 0.1
+}
+--enable_query_log
+--enable_result_log
+--disable_reconnect
+--let SEARCH_PATTERN= InnoDB: Unable to create temporary file
+--source include/search_pattern_in_file.inc
+
+--let $restart_parameters= --innodb_data_file_path=ibdata1:12M:autoextend --innodb_temp_data_file_path=ibdata1:12M:autoextend
+--source include/restart_mysqld.inc
+--let SEARCH_PATTERN = innodb_temporary and innodb_system file names seem to be the same
+--source include/search_pattern_in_file.inc
+eval $check_no_innodb;
+
+--let $restart_parameters= --innodb_temp_data_file_path=foobar:3Gnewraw
+--source include/restart_mysqld.inc
+--let SEARCH_PATTERN = support raw device
+--source include/search_pattern_in_file.inc
+eval $check_no_innodb;
+
+--let $restart_parameters= --innodb_temp_data_file_path=barbar:3Graw
+--source include/restart_mysqld.inc
+--source include/search_pattern_in_file.inc
+eval $check_no_innodb;
+
+--let $restart_parameters= --innodb_temp_data_file_path=
+--source include/restart_mysqld.inc
+--let SEARCH_PATTERN = InnoDB: syntax error in file path
+--source include/search_pattern_in_file.inc
+eval $check_no_innodb;
+
+--let $restart_parameters=
+--source include/restart_mysqld.inc
+
+--error ER_UNSUPPORTED_COMPRESSED_TABLE
+create temporary table t (
+ i int)
+ engine = innodb row_format = compressed;
+#
+--error ER_UNSUPPORTED_COMPRESSED_TABLE
+create temporary table t (
+ i int)
+ engine = innodb row_format = compressed key_block_size = 8;
+#
+create temporary table t (
+ i int)
+ engine = innodb row_format = dynamic;
+show warnings;
+drop table t;
+#
+create temporary table t (
+ i int)
+ engine = innodb row_format = dynamic;
+show warnings;
+drop table t;
+set innodb_strict_mode = off;
+#
+create temporary table t (
+ i int)
+ engine = innodb row_format = compressed key_block_size = 8;
+show warnings;
+set innodb_strict_mode = default;
+#
+drop table t;
+--error ER_UNSUPPORTED_COMPRESSED_TABLE
+create temporary table t (
+ i int)
+ engine = innodb row_format = compressed;
+--echo #files in MYSQL_TMP_DIR, expecting only default temporary tablespace file
+--list_files $MYSQL_TMP_DIR/ *.ibd
+--list_files $MYSQL_DATA_DIR/ ibtmp*
+#
+create temporary table t (
+ i int)
+ engine = innodb row_format = dynamic;
+show warnings;
+drop table t;
+#
+create temporary table t (
+ i int)
+ engine = innodb row_format = dynamic;
+show warnings;
+drop table t;
+set innodb_strict_mode = off;
+#
+create temporary table t (
+ i int)
+ engine = innodb row_format = dynamic key_block_size = 4;
+show warnings;
+drop table t;
+#
+create temporary table t (
+ i int)
+ engine = innodb row_format = compact;
+show warnings;
+drop table t;
+#
+create temporary table t (
+ i int)
+ engine = innodb key_block_size = 4;
+show warnings;
+drop table t;
+#
+
+CREATE TEMPORARY TABLE t1 (
+ i INT NOT NULL PRIMARY KEY,
+ c CHAR(10) NOT NULL
+) ENGINE = InnoDB KEY_BLOCK_SIZE = 4;
+SHOW WARNINGS;
+SHOW CREATE TABLE t1;
+DROP TABLE t1;
+#
+CREATE TEMPORARY TABLE t1 (
+ i INT NOT NULL PRIMARY KEY,
+ c CHAR(10) NOT NULL
+) ENGINE = InnoDB ROW_FORMAT = REDUNDANT;
+SHOW WARNINGS;
+SHOW CREATE TABLE t1;
+DROP TABLE t1;
+#
+CREATE TEMPORARY TABLE t1 (
+ i INT NOT NULL PRIMARY KEY,
+ c CHAR(10) NOT NULL
+) ENGINE = InnoDB ROW_FORMAT = COMPACT;
+SHOW WARNINGS;
+SHOW CREATE TABLE t1;
+DROP TABLE t1;
+#
+
+CREATE TEMPORARY TABLE t1 (
+ i INT NOT NULL PRIMARY KEY,
+ c CHAR(10) NOT NULL
+) ENGINE = InnoDB KEY_BLOCK_SIZE = 4;
+SHOW WARNINGS;
+SHOW CREATE TABLE t1;
+DROP TABLE t1;
+#
+CREATE TEMPORARY TABLE t1 (
+ i INT NOT NULL PRIMARY KEY,
+ c CHAR(10) NOT NULL
+) ENGINE = InnoDB ROW_FORMAT = COMPRESSED;
+SHOW WARNINGS;
+SHOW CREATE TABLE t1;
+DROP TABLE t1;
+#
+CREATE TEMPORARY TABLE t1 (
+ i INT NOT NULL PRIMARY KEY,
+ c CHAR(10) NOT NULL
+) ENGINE = InnoDB ROW_FORMAT = COMPRESSED KEY_BLOCK_SIZE = 8;
+SHOW WARNINGS;
+SHOW CREATE TABLE t1;
+DROP TABLE t1;
+#
+CREATE TEMPORARY TABLE t1 (
+ i INT NOT NULL PRIMARY KEY,
+ c CHAR(10) NOT NULL
+) ENGINE = InnoDB ROW_FORMAT = DYNAMIC KEY_BLOCK_SIZE = 8;
+SHOW WARNINGS;
+SHOW CREATE TABLE t1;
+DROP TABLE t1;
+#
+CREATE TEMPORARY TABLE t1 (
+ i INT NOT NULL PRIMARY KEY,
+ c CHAR(10) NOT NULL
+) ENGINE = InnoDB ROW_FORMAT = DYNAMIC;
+SHOW WARNINGS;
+SHOW CREATE TABLE t1;
+DROP TABLE t1;
+#
+
+# Test alter table for temporary tables with row format = compressed or
+# key_block_size
+CREATE TEMPORARY TABLE t1 (
+ i INT NOT NULL PRIMARY KEY
+) ENGINE = InnoDB ROW_FORMAT = REDUNDANT;
+
+ALTER TABLE t1 ROW_FORMAT = COMPRESSED;
+SHOW WARNINGS;
+SHOW CREATE TABLE t1;
+ALTER TABLE t1 KEY_BLOCK_SIZE = 4;
+SHOW WARNINGS;
+SHOW CREATE TABLE t1;
+ALTER TABLE t1 KEY_BLOCK_SIZE = 4 ROW_FORMAT = COMPRESSED;
+SHOW WARNINGS;
+SHOW CREATE TABLE t1;
+
+ALTER TABLE t1 ROW_FORMAT = DYNAMIC KEY_BLOCK_SIZE = 4;
+SHOW WARNINGS;
+SHOW CREATE TABLE t1;
+ALTER TABLE t1 ROW_FORMAT = DYNAMIC;
+SHOW WARNINGS;
+SHOW CREATE TABLE t1;
+DROP TABLE t1;
+
+# Set innodb_strict_mode=ON and test compressed temporary tables again.
+set innodb_strict_mode = ON;
+
+--error ER_UNSUPPORTED_COMPRESSED_TABLE
+CREATE TEMPORARY TABLE t1 (
+ i INT NOT NULL PRIMARY KEY,
+ c CHAR(10) NOT NULL
+) ENGINE = InnoDB KEY_BLOCK_SIZE = 4;
+SHOW WARNINGS;
+#
+
+--error ER_UNSUPPORTED_COMPRESSED_TABLE
+CREATE TEMPORARY TABLE t1 (
+ i INT NOT NULL PRIMARY KEY,
+ c CHAR(10) NOT NULL
+) ENGINE = InnoDB KEY_BLOCK_SIZE = 4, ROW_FORMAT = COMPACT;
+SHOW WARNINGS;
+#
+
+CREATE TEMPORARY TABLE t1 (
+ i INT NOT NULL PRIMARY KEY,
+ c CHAR(10) NOT NULL
+) ENGINE = InnoDB ROW_FORMAT = REDUNDANT;
+SHOW WARNINGS;
+SHOW CREATE TABLE t1;
+DROP TABLE t1;
+#
+
+--error ER_UNSUPPORTED_COMPRESSED_TABLE
+CREATE TEMPORARY TABLE t1 (
+ i INT NOT NULL PRIMARY KEY,
+ c CHAR(10) NOT NULL
+) ENGINE = InnoDB KEY_BLOCK_SIZE = 4;
+SHOW WARNINGS;
+#
+
+--error ER_UNSUPPORTED_COMPRESSED_TABLE
+CREATE TEMPORARY TABLE t1 (
+ i INT NOT NULL PRIMARY KEY,
+ c CHAR(10) NOT NULL
+) ENGINE = InnoDB ROW_FORMAT = COMPRESSED;
+SHOW WARNINGS;
+#
+
+--error ER_UNSUPPORTED_COMPRESSED_TABLE
+CREATE TEMPORARY TABLE t1 (
+ i INT NOT NULL PRIMARY KEY,
+ c CHAR(10) NOT NULL
+) ENGINE = InnoDB ROW_FORMAT = COMPRESSED KEY_BLOCK_SIZE = 8;
+SHOW WARNINGS;
+#
+
+--error ER_UNSUPPORTED_COMPRESSED_TABLE
+CREATE TEMPORARY TABLE t1 (
+ i INT NOT NULL PRIMARY KEY,
+ c CHAR(10) NOT NULL
+) ENGINE = InnoDB ROW_FORMAT = COMPRESSED KEY_BLOCK_SIZE = 7;
+SHOW WARNINGS;
+#
+
+CREATE TEMPORARY TABLE t1 (
+ i INT NOT NULL PRIMARY KEY,
+ c CHAR(10) NOT NULL
+) ENGINE = InnoDB ROW_FORMAT = DYNAMIC;
+SHOW WARNINGS;
+SHOW CREATE TABLE t1;
+DROP TABLE t1;
+#
+
+CREATE TEMPORARY TABLE t1 (
+ i INT NOT NULL PRIMARY KEY
+) ENGINE = InnoDB ROW_FORMAT = REDUNDANT;
+
+--error ER_UNSUPPORTED_COMPRESSED_TABLE
+ALTER TABLE t1 ROW_FORMAT = COMPRESSED;
+SHOW WARNINGS;
+
+--error ER_UNSUPPORTED_COMPRESSED_TABLE
+ALTER TABLE t1 KEY_BLOCK_SIZE = 4;
+SHOW WARNINGS;
+
+--error ER_UNSUPPORTED_COMPRESSED_TABLE
+ALTER TABLE t1 ROW_FORMAT = DYNAMIC KEY_BLOCK_SIZE = 4;
+SHOW WARNINGS;
+
+ALTER TABLE t1 ROW_FORMAT = DYNAMIC;
+
+#
+# Some checking for turning innodb_strict_mode ON and OFF.
+set innodb_strict_mode = OFF;
+
+ALTER TABLE t1 ROW_FORMAT = COMPRESSED;
+SHOW WARNINGS;
+
+set innodb_strict_mode = ON;
+
+ALTER TABLE t1 ROW_FORMAT = DYNAMIC;
+SHOW CREATE TABLE t1;
+
+set innodb_strict_mode = OFF;
+
+ALTER TABLE t1 ROW_FORMAT = COMPRESSED;
+SHOW WARNINGS;
+
+ALTER TABLE t1 KEY_BLOCK_SIZE = 8;
+SHOW WARNINGS;
+
+set innodb_strict_mode = ON;
+
+--error ER_UNSUPPORTED_COMPRESSED_TABLE
+ALTER TABLE t1 ADD COLUMN j INT;
+SHOW WARNINGS;
+SHOW CREATE TABLE t1;
+
+set innodb_strict_mode = OFF;
+
+ALTER TABLE t1 KEY_BLOCK_SIZE = 0;
+SHOW CREATE TABLE t1;
+
+ALTER TABLE t1 ROW_FORMAT = DYNAMIC;
+
+set innodb_strict_mode = ON;
+ALTER TABLE t1 ADD COLUMN j INT;
+SHOW CREATE TABLE t1;
+DROP TABLE t1;
+
+CREATE TEMPORARY TABLE t1(f1 INT, KEY(f1)) ENGINE=InnoDB;
+INSERT INTO t1 VALUES(NULL);
+UPDATE t1 SET f1 = 0;
+START TRANSACTION;
+UPDATE t1 SET f1 = 4;
+UPDATE t1 SET f1 = 0;
+ROLLBACK;
+SELECT * FROM t1;
+DROP TABLE t1;
+
+delimiter //;
+create procedure t1_proc()
+begin
+DECLARE var INT UNSIGNED;
+CREATE TEMPORARY TABLE t1(f1 INT UNSIGNED, f2 INT UNSIGNED, KEY( f1, f2 ) )engine=innodb;
+SET TRANSACTION ISOLATION LEVEL READ COMMITTED;
+START TRANSACTION;
+INSERT INTO t1 SET f1 = 1, f2 = 1;
+UPDATE t1 SET f2 = 2;
+SET var = ( SELECT 1 FROM t1 );
+DROP TABLE t1;
+END//
+delimiter ;//
+
+call t1_proc;
+drop procedure t1_proc;
+
+--echo #
+--echo # MDEV-15874 CREATE TABLE creates extra transaction
+--echo #
+call mtr.add_suppression("Warning 150 Create table `mysqld.1`.`t1` with foreign key constraint failed. Temporary tables can't have foreign key constraints.*");
+SET FOREIGN_KEY_CHECKS = 0;
+--error ER_CANT_CREATE_TABLE
+CREATE TEMPORARY TABLE t1(f1 INT NOT NULL,
+ FOREIGN KEY(f1) REFERENCES t0(f1))ENGINE=InnoDB;
+
+CREATE TABLE t (c INT) ENGINE=InnoDB;
+INSERT INTO t VALUES(0);
+CREATE TEMPORARY TABLE t2 (c INT) ENGINE=InnoDB;
+START TRANSACTION READ ONLY;
+INSERT INTO t2 SELECT * FROM t;
+COMMIT;
+DROP TABLE t, t2;
+
+CREATE TEMPORARY TABLE t (c INT,c2 INT) ENGINE=InnoDB;
+START TRANSACTION READ ONLY;
+--error ER_WRONG_VALUE_COUNT_ON_ROW
+INSERT INTO t VALUES(0);
+SAVEPOINT s;
+INSERT INTO t VALUES(0,0);
+COMMIT;
+DROP TABLE t;
+
+CREATE TEMPORARY TABLE t (c INT,c2 INT) ENGINE=InnoDB;
+START TRANSACTION READ ONLY;
+--error ER_WRONG_VALUE_COUNT_ON_ROW
+INSERT INTO t VALUES(0);
+SAVEPOINT s;
+INSERT INTO t VALUES(0,0);
+ROLLBACK;
+DROP TABLE t;
+
+CREATE TEMPORARY TABLE t1 (a INT PRIMARY KEY) ENGINE=InnoDB;
+INSERT INTO t1 VALUES (1);
+START TRANSACTION READ ONLY;
+UPDATE t1 SET a= 2;
+COMMIT;
+DROP TABLE t1;
+
+CREATE TEMPORARY TABLE t(c INT) ENGINE=InnoDB;
+SET SESSION tx_read_only=TRUE;
+LOCK TABLE test.t READ;
+SELECT * FROM t;
+INSERT INTO t VALUES(0xADC3);
+SET SESSION tx_read_only=FALSE;
+DROP TABLE t;
+
+CREATE TEMPORARY TABLE t1 (a INT PRIMARY KEY) ENGINE=InnoDB;
+INSERT INTO t1 VALUES (1);
+START TRANSACTION READ ONLY;
+UPDATE t1 SET a= 2;
+COMMIT;
+DROP TABLE t1;
+
+CREATE TEMPORARY TABLE t1 (a INT PRIMARY KEY, b int) ENGINE=InnoDB;
+INSERT INTO t1 VALUES (1, 1);
+START TRANSACTION READ ONLY;
+UPDATE t1 SET b= 2;
+COMMIT;
+DROP TABLE t1;
+
+CREATE TEMPORARY TABLE t1 (a INT PRIMARY KEY, b int, c varchar(255)) ENGINE=InnoDB;
+INSERT INTO t1 VALUES (1, 1, repeat('a', 200));
+START TRANSACTION READ ONLY;
+UPDATE t1 SET b= 2, c=repeat('a', 250);
+COMMIT;
+DROP TABLE t1;
+
+CREATE TEMPORARY TABLE t1 (a INT PRIMARY KEY) ENGINE=InnoDB;
+INSERT INTO t1 VALUES (1);
+START TRANSACTION READ ONLY;
+UPDATE t1 SET a= 2;
+ROLLBACK;
+DROP TABLE t1;
+
+CREATE TEMPORARY TABLE t1 (a INT PRIMARY KEY) ENGINE=InnoDB;
+INSERT INTO t1 VALUES (1);
+START TRANSACTION READ ONLY;
+DELETE FROM t1 WHERE a= 2;
+COMMIT;
+DROP TABLE t1;
+
+CREATE TEMPORARY TABLE tmp (a INT) ENGINE=InnoDB;
+INSERT INTO tmp () VALUES (),();
+SET TX_READ_ONLY= 1;
+INSERT INTO tmp SELECT * FROM tmp;
+SET TX_READ_ONLY= 0;
+DROP TABLE tmp;
+
+SET sql_mode='';
+SET GLOBAL tx_read_only=TRUE;
+CREATE TEMPORARY TABLE t (c INT);
+SET SESSION tx_read_only=DEFAULT;
+INSERT INTO t VALUES(1);
+INSERT INTO t SELECT * FROM t;
+SET SESSION tx_read_only=FALSE;
+SET GLOBAL tx_read_only=OFF;
+DROP TABLE t;
+
+CREATE TEMPORARY TABLE t(a INT);
+SET SESSION tx_read_only=ON;
+LOCK TABLE t READ;
+SELECT COUNT(*)FROM t;
+INSERT INTO t VALUES (0);
+SET SESSION tx_read_only=OFF;
+DROP TABLE t;
+
+CREATE TEMPORARY TABLE t (a INT) ENGINE=InnoDB;
+INSERT INTO t VALUES (1);
+START TRANSACTION READ ONLY;
+UPDATE t SET a = NULL;
+ROLLBACK;
+DROP TABLE t;
+
+--echo #
+--echo # MDEV-29886 Assertion !index->table->is_temporary() failed
+--echo # in trx_undo_prev_version_build upon CHECK
+--echo #
+CREATE TEMPORARY TABLE t (a INT, KEY(a)) ENGINE=InnoDB SELECT 1;
+UPDATE t SET a=2;
+CHECK TABLE t;
+CHECK TABLE t EXTENDED;
+DROP TEMPORARY TABLE t;
+
+--echo #
+--echo # MDEV-29978 Corruption errors upon CHECK on temporary InnoDB table
+--echo #
+
+CREATE TEMPORARY TABLE t (f INT UNIQUE) ENGINE=InnoDB;
+INSERT INTO t (f) VALUES (1),(2);
+CHECK TABLE t;
+CHECK TABLE t EXTENDED;
+DROP TEMPORARY TABLE t;
+
+--echo # End of 10.6 tests
diff --git a/mysql-test/suite/innodb/t/temporary_table_optimization.opt b/mysql-test/suite/innodb/t/temporary_table_optimization.opt
new file mode 100644
index 00000000..39b93371
--- /dev/null
+++ b/mysql-test/suite/innodb/t/temporary_table_optimization.opt
@@ -0,0 +1 @@
+--loose-innodb-sys-tables
diff --git a/mysql-test/suite/innodb/t/temporary_table_optimization.test b/mysql-test/suite/innodb/t/temporary_table_optimization.test
new file mode 100644
index 00000000..a30f05cb
--- /dev/null
+++ b/mysql-test/suite/innodb/t/temporary_table_optimization.test
@@ -0,0 +1,240 @@
+#
+# WL#6469: Optimizing CREATE/DROP performance for temporary tables
+#
+--source include/no_valgrind_without_big.inc
+--source include/have_innodb.inc
+
+#########################################################################
+# #
+# Will test following scenarios: #
+# 1. Create/Drop of temp-table. (with and w/o explicit pk) #
+# 2. Truncate temp-table (result in table drop and recreate). #
+# 3. Alter of temp-table. #
+# 4. Import/Discard of temp-table (to check blocked action) #
+# 5. Renaming of temp-table #
+# 6. Creating temp-table with large prefix. #
+# 7. Check Temp table info not stored in InnoDB system tables #
+#########################################################################
+
+
+#-------------------------------------------------------------
+#
+# 1. Create/Drop of temp-table. (with and w/o explicit pk) #
+#
+create temporary table t1 (i int) engine = innodb;
+insert into t1 values (1), (2), (3), (4);
+select * from t1;
+select * from t1 where i = 4;
+drop table t1;
+#
+# recreate table wih same name to ensure entries are removed.
+create temporary table t1 (i int) engine = innodb;
+insert into t1 values (1), (2), (3), (4);
+select * from t1;
+select * from t1 where i = 4;
+drop table t1;
+#
+create temporary table t2 (i int) engine = innodb;
+insert into t2 values (1), (2), (3), (4);
+select * from t2;
+select * from t2 where i = 4;
+drop table t2;
+
+#-------------------------------------------------------------
+#
+# 2. Truncate temp-table (result in table drop and recreate). #
+#
+create temporary table t1
+ (keyc int, c1 char(100), c2 char(100),
+ primary key(keyc)) engine = innodb;
+delimiter |;
+create procedure populate_t1()
+begin
+ declare i int default 1;
+ while (i <= 200) DO
+ insert into t1 values (i, 'a', 'b');
+ set i = i + 1;
+ end while;
+end|
+delimiter ;|
+set autocommit=0;
+select count(*) from t1;
+call populate_t1();
+select count(*) from t1;
+select * from t1 limit 10;
+set autocommit=1;
+truncate table t1;
+select count(*) from t1;
+drop table t1;
+#
+# recreate table wih same name to ensure entries are removed.
+create temporary table t1 (i int) engine = innodb;
+insert into t1 values (1), (2), (3), (4);
+select * from t1;
+select * from t1 where i = 4;
+drop table t1;
+#
+create temporary table t1
+ (keyc int, c1 char(100), c2 char(100),
+ primary key(keyc))
+ engine = innodb;
+begin;
+select count(*) from t1;
+call populate_t1();
+select count(*) from t1;
+rollback;
+select count(*) from t1;
+begin;
+call populate_t1();
+commit;
+select count(*) from t1;
+truncate table t1;
+select count(*) from t1;
+drop table t1;
+#
+drop procedure populate_t1;
+
+
+#-------------------------------------------------------------
+#
+# 3. Alter of temp-table.
+#
+create temporary table t1 (t1_i int, t1_f float) engine = innodb;
+insert into t1 values (1, 1.1), (2, 2.5), (3, 2.5), (4, 4.4);
+#
+explain select * from t1 where t1_i = 1;
+alter table t1 add unique index pri_index(t1_i);
+explain select * from t1 where t1_i = 1;
+select * from t1 where t1_i = 1;
+#
+--error ER_DUP_ENTRY
+alter table t1 add unique index sec_index(t1_f);
+alter table t1 add index sec_index(t1_f);
+explain select * from t1 where t1_f >= 2.5;
+select * from t1 where t1_f >= 2.5;
+#
+alter table t1 add column (t1_c char(10));
+select * from t1;
+insert into t1 values (5, 5.5, 'krunal');
+#
+alter table t1 drop column t1_f;
+show create table t1;
+--error ER_BAD_FIELD_ERROR
+select * from t1 where t1_f >= 2.5;
+#
+--error ER_ALTER_OPERATION_NOT_SUPPORTED
+alter table t1 add index sec_index2(t1_c), algorithm=inplace;
+#
+drop table t1;
+
+#-------------------------------------------------------------
+#
+# 4. Import/Discard of temp-table (to check blocked action)
+#
+create temporary table t1 (i int, f float) engine = innodb;
+insert into t1 values (10, 1.1), (20, 2.2);
+select * from t1;
+#
+--error ER_CANNOT_DISCARD_TEMPORARY_TABLE
+alter table t1 discard tablespace;
+--error ER_CANNOT_DISCARD_TEMPORARY_TABLE
+alter table t1 import tablespace;
+drop table t1;
+
+#-------------------------------------------------------------
+#
+# 5. Renaming of temp-table #
+#
+create temporary table t1 (i int) engine=innodb;
+insert into t1 values (1), (2), (3);
+select * from t1;
+#
+alter table t1 rename t2;
+--error ER_NO_SUCH_TABLE
+select * from t1;
+select * from t2;
+insert into t2 values (1), (2), (6), (7);
+select * from t2;
+drop table t2;
+
+
+#-------------------------------------------------------------
+#
+# 6. Creating temp-table with large prefix. #
+#
+SET sql_mode = 'NO_ENGINE_SUBSTITUTION';
+# This will lead to warnings on innodb_page_size=8k or 4k:
+# 8k: Specified key was too long; max key length is 1536 bytes
+# 4k: Specified key was too long; max key length is 768 bytes
+--disable_warnings
+#
+create temporary table t (
+ a int not null,
+ b blob not null,
+ index sk (b(3021))
+ ) row_format = dynamic engine=innodb;
+drop table t;
+#
+create temporary table t (
+ a int not null,
+ b blob not null,
+ index sk (b(3021))
+ ) row_format = dynamic engine=innodb;
+drop table t;
+#
+create temporary table t (
+ a int not null,
+ b blob not null,
+ index sk (b(3021))
+ ) row_format = dynamic engine=innodb;
+drop table t;
+#
+SET innodb_strict_mode=OFF;
+--error ER_INDEX_COLUMN_TOO_LONG
+create temporary table t (
+ a int not null,
+ b blob not null,
+ index sk (b(3021))
+ ) row_format = compact engine=innodb;
+#
+create temporary table t (
+ a int not null,
+ b blob not null,
+ index sk (b(3021))
+ ) row_format = dynamic engine=innodb;
+drop table t;
+#
+create temporary table t (
+ a int not null,
+ b blob not null,
+ index sk (b(3021))
+ ) row_format = compressed engine=innodb;
+drop table t;
+#
+--error ER_INDEX_COLUMN_TOO_LONG
+create temporary table t (
+ a int not null,
+ b blob not null,
+ index sk (b(3021))
+ ) row_format = compact engine=innodb;
+#
+create temporary table t (
+ a int not null,
+ b blob not null,
+ index sk (b(3021))
+ ) row_format = dynamic engine=innodb;
+drop table t;
+--enable_warnings
+#
+
+#-------------------------------------------------------------
+#
+# 7. Temp table info not stored in I_S
+#
+CREATE TABLE t1 ( i INT ) ENGINE = Innodb;
+CREATE TEMPORARY TABLE t2 ( i INT ) ENGINE = Innodb;
+SELECT COUNT(*) FROM information_schema.INNODB_SYS_TABLES WHERE NAME LIKE '%test%t_';
+CREATE TEMPORARY table t3 ( i INT ) ENGINE = Innodb;
+SELECT COUNT(*) FROM information_schema.INNODB_SYS_TABLES WHERE NAME LIKE '%test%t_';
+DROP TABLE t1,t2,t3;
+SELECT COUNT(*) FROM information_schema.INNODB_SYS_TABLES WHERE NAME LIKE '%test%t_';
diff --git a/mysql-test/suite/innodb/t/tmpdir.test b/mysql-test/suite/innodb/t/tmpdir.test
new file mode 100644
index 00000000..b43a0236
--- /dev/null
+++ b/mysql-test/suite/innodb/t/tmpdir.test
@@ -0,0 +1,61 @@
+--source include/have_innodb.inc
+--source include/count_sessions.inc
+
+--echo #
+--echo # Bug #19183565 CREATE DYNAMIC INNODB_TMPDIR VARIABLE TO CONTROL
+--echo # WHERE INNODB WRITES TEMP FILES
+--echo #
+
+--echo # If innodb_tmpdir is NULL or "", temporary file will be created in
+--echo # server configuration variable location(--tmpdir)
+
+create table t1(a int primary key)engine=innodb;
+show session variables like 'innodb_tmpdir';
+alter table t1 add column b int not null;
+set global innodb_tmpdir=NULL;
+connect (con1,localhost,root);
+show session variables like 'innodb_tmpdir';
+alter table t1 add key(b);
+connection default;
+disconnect con1;
+drop table t1;
+
+--echo # innodb_tmpdir with invalid path.
+
+create table t1(a int primary key)engine=innodb;
+--error ER_WRONG_VALUE_FOR_VAR
+set global innodb_tmpdir='wrong_value';
+show warnings;
+drop table t1;
+
+
+--echo # innodb_tmpdir with mysql data directory path.
+
+let $MYSQLD_DATADIR= `select @@datadir`;
+create table t1(a text, b text, fulltext(a,b))engine=innodb;
+insert into t1 values('test1', 'test2');
+insert into t1 values('text1', 'text2');
+--replace_result $MYSQLD_DATADIR MYSQL_DATADIR
+--error ER_WRONG_VALUE_FOR_VAR
+set global innodb_tmpdir = @@global.datadir;
+--replace_regex /.*mysqld.1/DATADIR/
+show warnings;
+drop table t1;
+
+--echo # innodb_tmpdir with valid location.
+let $MYSQL_TMP_DIR= `select @@tmpdir`;
+create table t1(a text, b text, fulltext(a,b))engine=innodb;
+insert into t1 values('test1', 'test2');
+insert into t1 values('text1', 'text2');
+set @tmpdir = @@global.tmpdir;
+set global innodb_tmpdir = @tmpdir;
+show session variables like 'innodb_tmpdir';
+connect (con3,localhost,root);
+# Following alter using innodb_tmpdir as a path to create temporary files
+alter table t1 add fulltext(b);
+disconnect con3;
+connection default;
+set global innodb_tmpdir=NULL;
+drop table t1;
+
+--source include/wait_until_count_sessions.inc
diff --git a/mysql-test/suite/innodb/t/trigger.test b/mysql-test/suite/innodb/t/trigger.test
new file mode 100644
index 00000000..fe0bab21
--- /dev/null
+++ b/mysql-test/suite/innodb/t/trigger.test
@@ -0,0 +1,47 @@
+--source include/have_innodb.inc
+--source include/count_sessions.inc
+
+CREATE TABLE t1 (a INT) ENGINE=InnoDB;
+CREATE TABLE t2 (b INT) ENGINE=InnoDB;
+CREATE TABLE t3 (c INT) ENGINE=InnoDB;
+
+--delimiter $$
+CREATE TRIGGER tr BEFORE INSERT ON t3 FOR EACH ROW BEGIN SAVEPOINT sv; INSERT INTO t2 VALUES (0); END $$
+--delimiter ;
+
+START TRANSACTION;
+DELETE FROM t1;
+
+connect (con1,localhost,root,,test);
+START TRANSACTION;
+INSERT INTO t2 VALUES (2);
+UPDATE t2 SET b = b+1;
+
+--send
+INSERT INTO t1 VALUES (1);
+
+connection default;
+let $wait_condition=
+ select count(*) = 1 from information_schema.processlist
+ where state = 'update' and info = 'INSERT INTO t1 VALUES (1)'
+--source include/wait_condition.inc
+
+--error ER_LOCK_DEADLOCK
+INSERT INTO t3 VALUES (2);
+COMMIT;
+
+connection con1;
+reap;
+COMMIT;
+disconnect con1;
+
+connection default;
+SELECT * FROM t1;
+SELECT * FROM t2;
+SELECT * FROM t3;
+
+DROP TABLE t1, t2, t3;
+--error ER_TRG_DOES_NOT_EXIST
+DROP TRIGGER tr;
+
+--source include/wait_until_count_sessions.inc
diff --git a/mysql-test/suite/innodb/t/trigger_error.test b/mysql-test/suite/innodb/t/trigger_error.test
new file mode 100644
index 00000000..0334f2b3
--- /dev/null
+++ b/mysql-test/suite/innodb/t/trigger_error.test
@@ -0,0 +1,31 @@
+--source include/have_innodb.inc
+
+CREATE TABLE t1 (i INT) ENGINE=InnoDB;
+CREATE TABLE t2 (i INT) ENGINE=InnoDB;
+
+CREATE OR REPLACE TRIGGER tr1
+ AFTER UPDATE ON t2
+ FOR EACH ROW
+ INSERT INTO tlog (i) VALUES (1);
+
+INSERT IGNORE INTO t2 VALUES (1);
+
+CREATE TRIGGER IF NOT EXISTS tr2
+ BEFORE INSERT ON t2
+ FOR EACH ROW
+ INSERT INTO tlog (i) VALUES (2);
+
+START TRANSACTION;
+INSERT INTO t1 VALUES (1);
+--error ER_NO_SUCH_TABLE
+UPDATE t2 SET i = 3;
+INSERT INTO t1 VALUES (2);
+--error ER_NO_SUCH_TABLE
+INSERT INTO t2 VALUES (4);
+UPDATE t1 SET i = 4 LIMIT 1;
+COMMIT;
+
+SELECT * FROM t1;
+SELECT * FROM t2;
+
+DROP TABLE t1,t2;
diff --git a/mysql-test/suite/innodb/t/truncate.test b/mysql-test/suite/innodb/t/truncate.test
new file mode 100644
index 00000000..436fc01b
--- /dev/null
+++ b/mysql-test/suite/innodb/t/truncate.test
@@ -0,0 +1,81 @@
+--source include/have_innodb.inc
+
+CREATE TABLE t (a SERIAL) ENGINE=InnoDB;
+
+connect (dml,localhost,root);
+# At the end of this statement, close_thread_tables()
+# should add the open table handle to the table definition cache (tdc).
+select * from t;
+
+connection default;
+# This should purge the handle from the tdc;
+# otherwise ha_innobase::truncate() would hang,
+# waiting for the reference count to drop to 0.
+TRUNCATE TABLE t;
+disconnect dml;
+
+DROP TABLE t;
+
+--echo #
+--echo # MDEV-17831 TRUNCATE TABLE removes ROW_FORMAT=COMPRESSED
+--echo #
+--disable_query_log
+SET @save_innodb_read_only_compressed=@@GLOBAL.innodb_read_only_compressed;
+SET GLOBAL innodb_read_only_compressed=OFF;
+--enable_query_log
+CREATE TABLE t1 (a SERIAL) ENGINE=InnoDB KEY_BLOCK_SIZE=4;
+TRUNCATE TABLE t1;
+--replace_column 3 # 5 # 6 # 7 # 8 # 9 # 10 # 12 # 13 #
+SHOW TABLE STATUS;
+--disable_query_log
+SET GLOBAL innodb_read_only_compressed=@save_innodb_read_only_compressed;
+--enable_query_log
+DROP TABLE t1;
+
+--echo #
+--echo # MDEV-17859 Operating system errors in file operations
+--echo # after failed CREATE
+--echo #
+let $MYSQLD_DATADIR= `select @@datadir`;
+CREATE TABLE t1 (a INT) ENGINE=InnoDB;
+INSERT INTO t1 VALUES (1);
+call mtr.add_suppression("InnoDB: (Operating system )?[Ee]rror number");
+call mtr.add_suppression("InnoDB: Cannot create file '.*t1\\.ibd");
+FLUSH TABLES;
+--move_file $MYSQLD_DATADIR/test/t1.frm $MYSQLD_DATADIR/test/hidden.frm
+--error ER_TABLE_EXISTS_ERROR
+CREATE TABLE t1 (a INT) ENGINE=InnoDB;
+--move_file $MYSQLD_DATADIR/test/hidden.frm $MYSQLD_DATADIR/test/t1.frm
+SELECT * FROM t1;
+DROP TABLE t1;
+
+--echo #
+--echo # MDEV-17885 TRUNCATE on temporary table causes ER_GET_ERRNO
+--echo #
+CREATE TEMPORARY TABLE t1 (a INT) ENCRYPTED=NO ENGINE=InnoDB;
+INSERT INTO t1 VALUES(1);
+TRUNCATE t1;
+SELECT * FROM t1;
+DROP TEMPORARY TABLE t1;
+
+--echo #
+--echo # MDEV-23705 Assertion 'table->data_dir_path || !space'
+--echo #
+CREATE TABLE t(c INT) ENGINE=InnoDB;
+ALTER TABLE t DISCARD TABLESPACE;
+RENAME TABLE t TO u;
+TRUNCATE u;
+TRUNCATE u;
+DROP TABLE u;
+
+--echo #
+--echo # Test for a regression found during MDEV-25506 rewrite of DROP
+--echo #
+CREATE TEMPORARY TABLE t1 (a INT) ENGINE=InnoDB;
+LOCK TABLE t1 READ;
+TRUNCATE TABLE t1;
+TRUNCATE TABLE t1;
+UNLOCK TABLES;
+DROP TEMPORARY TABLE t1;
+
+--echo # End of 10.6 tests
diff --git a/mysql-test/suite/innodb/t/truncate_crash.test b/mysql-test/suite/innodb/t/truncate_crash.test
new file mode 100644
index 00000000..c5156b4b
--- /dev/null
+++ b/mysql-test/suite/innodb/t/truncate_crash.test
@@ -0,0 +1,26 @@
+--source include/have_innodb.inc
+--source include/have_debug.inc
+--source include/have_debug_sync.inc
+--source include/not_embedded.inc
+
+FLUSH TABLES;
+CREATE TABLE t1 (a INT PRIMARY KEY) ENGINE=InnoDB;
+INSERT INTO t1 VALUES (1),(2);
+
+connect (wait,localhost,root,,test);
+SET DEBUG_SYNC='before_trx_state_committed_in_memory SIGNAL c WAIT_FOR ever';
+send TRUNCATE TABLE t1;
+
+connection default;
+SET DEBUG_SYNC='now WAIT_FOR c';
+--let $shutdown_timeout=0
+--source include/restart_mysqld.inc
+disconnect wait;
+
+--source include/wait_all_purged.inc
+
+--replace_result 2 0
+SELECT COUNT(*) FROM t1;
+TRUNCATE TABLE t1;
+DROP TABLE t1;
+
diff --git a/mysql-test/suite/innodb/t/truncate_foreign.test b/mysql-test/suite/innodb/t/truncate_foreign.test
new file mode 100644
index 00000000..abbe1b3d
--- /dev/null
+++ b/mysql-test/suite/innodb/t/truncate_foreign.test
@@ -0,0 +1,112 @@
+--source include/have_innodb.inc
+--source include/have_debug.inc
+--source include/have_debug_sync.inc
+
+CREATE TABLE parent (a INT PRIMARY KEY) ENGINE=InnoDB;
+INSERT INTO parent SET a=1;
+
+CREATE TABLE child (a INT PRIMARY KEY, FOREIGN KEY (a) REFERENCES parent(a)
+ON UPDATE CASCADE)
+ENGINE=InnoDB;
+INSERT INTO child SET a=1;
+
+--error ER_TRUNCATE_ILLEGAL_FK
+TRUNCATE TABLE parent;
+TRUNCATE TABLE child;
+
+INSERT INTO child SET a=1;
+UPDATE parent SET a=2;
+SELECT * FROM child;
+
+connect (dml,localhost,root);
+SET DEBUG_SYNC='foreign_constraint_update_cascade SIGNAL fk WAIT_FOR go';
+send UPDATE parent SET a=3;
+
+connection default;
+SET DEBUG_SYNC='now WAIT_FOR fk';
+SET lock_wait_timeout=1;
+--error ER_LOCK_WAIT_TIMEOUT
+TRUNCATE TABLE child;
+SET DEBUG_SYNC='now SIGNAL go';
+
+connection dml;
+reap;
+SELECT * FROM child;
+SET DEBUG_SYNC='foreign_constraint_check_for_update SIGNAL fk WAIT_FOR go';
+send DELETE FROM parent;
+
+connection default;
+SET DEBUG_SYNC='now WAIT_FOR fk';
+SET lock_wait_timeout=1;
+--error ER_LOCK_WAIT_TIMEOUT
+TRUNCATE TABLE child;
+SET DEBUG_SYNC='now SIGNAL go';
+
+connection dml;
+--error ER_ROW_IS_REFERENCED_2
+reap;
+SELECT * FROM child;
+INSERT INTO parent SET a=5;
+SET DEBUG_SYNC='foreign_constraint_check_for_ins SIGNAL fk WAIT_FOR go';
+send INSERT INTO child SET a=5;
+
+connection default;
+SET DEBUG_SYNC='now WAIT_FOR fk';
+SET foreign_key_checks=0, innodb_lock_wait_timeout=0;
+--error ER_LOCK_WAIT_TIMEOUT
+TRUNCATE TABLE parent;
+SET DEBUG_SYNC='now SIGNAL go';
+
+connection dml;
+reap;
+SELECT * FROM parent;
+SELECT * FROM child;
+disconnect dml;
+
+connection default;
+SET DEBUG_SYNC = RESET;
+
+DROP TABLE child, parent;
+
+--echo #
+--echo # MDEV-24532 Table corruption ER_NO_SUCH_TABLE_IN_ENGINE or
+--echo # ER_CRASHED_ON_USAGE after ALTER on table with foreign key
+--echo #
+
+CREATE TABLE t1 (a INT, b INT, PRIMARY KEY (a)) ENGINE=InnoDB;
+ALTER TABLE t1 ADD FOREIGN KEY (b) REFERENCES t1 (a) ON UPDATE CASCADE;
+LOCK TABLE t1 WRITE;
+TRUNCATE TABLE t1;
+ALTER TABLE t1 ADD c INT;
+UNLOCK TABLES;
+DROP TABLE t1;
+
+--echo #
+--echo # MDEV-26052 Assertion prebuilt->trx_id < table->def_trx_id failed
+--echo #
+
+call mtr.add_suppression("InnoDB: In ALTER TABLE `test`\\.`t1` has or is");
+
+CREATE TABLE t1 (pk INT, a INT, PRIMARY KEY (pk), KEY (a)) ENGINE=InnoDB;
+SET FOREIGN_KEY_CHECKS=0;
+ALTER TABLE t1 ADD FOREIGN KEY (a) REFERENCES t1 (a), ALGORITHM=COPY;
+INSERT INTO t1 VALUES (1,1);
+LOCK TABLES t1 WRITE;
+SET FOREIGN_KEY_CHECKS=1;
+--error ER_CANNOT_ADD_FOREIGN
+TRUNCATE t1;
+# Whether TRUNCATE succeeds or fails, it will reload FOREIGN KEY constraints.
+# As a result, ha_innobase::referenced_by_foreign_key() will retun TRUE
+# (for the self-referential key), and the statement will fail.
+--error ER_TABLE_NOT_LOCKED
+INSERT INTO t1 VALUES (2,2);
+SELECT * FROM t1;
+UNLOCK TABLES;
+--error ER_NO_REFERENCED_ROW_2
+INSERT INTO t1 VALUES (2,2);
+SET FOREIGN_KEY_CHECKS=0;
+INSERT INTO t1 VALUES (2,2);
+SELECT * FROM t1;
+DROP TABLE t1;
+
+--echo # End of 10.6 tests
diff --git a/mysql-test/suite/innodb/t/truncate_missing.test b/mysql-test/suite/innodb/t/truncate_missing.test
new file mode 100644
index 00000000..d36a2de5
--- /dev/null
+++ b/mysql-test/suite/innodb/t/truncate_missing.test
@@ -0,0 +1,22 @@
+--source include/have_innodb.inc
+--source include/not_embedded.inc
+
+call mtr.add_suppression("InnoDB: Operating system error number ");
+call mtr.add_suppression("InnoDB: (Error number \\d+ means|If you are|Cannot open datafile) ");
+call mtr.add_suppression("InnoDB: Ignoring tablespace for test/t ");
+call mtr.add_suppression("InnoDB: Table test/t .* does not exist");
+
+CREATE TABLE t (a SERIAL) ENGINE=InnoDB;
+INSERT INTO t() VALUES();
+SHOW CREATE TABLE t;
+let $datadir=`select @@datadir`;
+
+--source include/shutdown_mysqld.inc
+--remove_file $datadir/test/t.ibd
+--source include/start_mysqld.inc
+
+--error ER_GET_ERRNO
+SELECT * FROM t;
+--error ER_GET_ERRNO
+TRUNCATE TABLE t;
+DROP TABLE t;
diff --git a/mysql-test/suite/innodb/t/trx_id_future.combinations b/mysql-test/suite/innodb/t/trx_id_future.combinations
new file mode 100644
index 00000000..72938059
--- /dev/null
+++ b/mysql-test/suite/innodb/t/trx_id_future.combinations
@@ -0,0 +1,5 @@
+[strict_crc32]
+--innodb-checksum-algorithm=strict_crc32
+
+[strict_full_crc32]
+--innodb-checksum-algorithm=strict_full_crc32
diff --git a/mysql-test/suite/innodb/t/trx_id_future.test b/mysql-test/suite/innodb/t/trx_id_future.test
new file mode 100644
index 00000000..1aeb1372
--- /dev/null
+++ b/mysql-test/suite/innodb/t/trx_id_future.test
@@ -0,0 +1,66 @@
+--echo #
+--echo # Bug #20445525 ADD A CONSISTENCY CHECK AGAINST DB_TRX_ID BEING
+--echo # IN THE FUTURE
+--echo #
+
+--source include/have_innodb.inc
+--source include/not_embedded.inc
+
+let PAGE_SIZE=`select @@innodb_page_size`;
+
+CREATE TABLE t1(a INT) row_format=redundant engine=innoDB;
+INSERT INTO t1 VALUES(1);
+
+let MYSQLD_DATADIR=`select @@datadir`;
+--source include/wait_all_purged.inc
+let $restart_noprint=2;
+--source include/shutdown_mysqld.inc
+
+perl;
+do "$ENV{MTR_SUITE_DIR}/include/crc32.pl";
+my $file = "$ENV{MYSQLD_DATADIR}/test/t1.ibd";
+open(FILE, "+<", $file) || die "Unable to open $file";
+binmode FILE;
+
+#Seek the the infimum record and get the offset to next record
+#Infimum record exist at offset 101 for redundant format
+#And offset to the next record is present 2 bytes prior to
+#infimum record
+
+my $ps= $ENV{PAGE_SIZE};
+my $page;
+die "Unable to read $file" unless sysread(FILE, $page, $ps) == $ps;
+my $full_crc32 = unpack("N",substr($page,54,4)) & 0x10; # FIL_SPACE_FLAGS
+sysseek(FILE, 3*$ps, 0) || die "Unable to seek $file\n";
+die "Unable to read $file" unless sysread(FILE, $page, $ps) == $ps;
+#In this case the first record should be at offset 135
+die unless unpack("n", substr($page, 99, 2)) == 135;
+
+substr($page,135+6,6) = "\xff" x 6;
+
+my $polynomial = 0x82f63b78; # CRC-32C
+if ($full_crc32)
+{
+ my $ck = mycrc32(substr($page, 0, $ps - 4), 0, $polynomial);
+ substr($page, $ps - 4, 4) = pack("N", $ck);
+}
+else
+{
+ my $ck= pack("N",mycrc32(substr($page, 4, 22), 0, $polynomial) ^
+ mycrc32(substr($page, 38, $ps - 38 - 8), 0, $polynomial));
+ substr($page,0,4)=$ck;
+ substr($page,$ps-8,4)=$ck;
+}
+sysseek(FILE, 3*$ps, 0) || die "Unable to rewind $file\n";
+syswrite(FILE, $page, $ps)==$ps || die "Unable to write $file\n";
+close(FILE) || die "Unable to close $file";
+EOF
+
+--source include/start_mysqld.inc
+call mtr.add_suppression("\\[Warning\\] InnoDB: A transaction id in a record of table `test`\\.`t1` is newer than the system-wide maximum");
+call mtr.add_suppression("\\[ERROR\\] InnoDB: We detected index corruption");
+call mtr.add_suppression("Index for table 't1' is corrupt; try to repair it");
+
+--error ER_NOT_KEYFILE
+SELECT * FROM t1;
+DROP TABLE t1;
diff --git a/mysql-test/suite/innodb/t/trx_sys_t_find_lf_hash_error.test b/mysql-test/suite/innodb/t/trx_sys_t_find_lf_hash_error.test
new file mode 100644
index 00000000..833919f9
--- /dev/null
+++ b/mysql-test/suite/innodb/t/trx_sys_t_find_lf_hash_error.test
@@ -0,0 +1,87 @@
+--source include/have_innodb.inc
+--source include/have_debug.inc
+--source include/have_debug_sync.inc
+--source include/count_sessions.inc
+
+create table t1 (a int) engine=innodb STATS_PERSISTENT=0;
+create table t2 (a int) engine=innodb STATS_PERSISTENT=0;
+
+BEGIN; # trx1
+# register rw-transaction in trx_sys.rw_trx_hash
+insert into t1 values(1);
+
+--connect (con_1, localhost, root,,)
+SET DEBUG_SYNC="before_trx_hash_find_element_mutex_enter SIGNAL before_mutex_enter WAIT_FOR cont1";
+SET DEBUG_SYNC="after_trx_hash_find_element_mutex_enter SIGNAL after_mutex_enter WAIT_FOR cont2";
+
+# trx2 is converting implicit lock of trx1 to explicit one, it's invoking
+# ▾ l_search
+# ▾ lf_hash_search_using_hash_value
+# ▾ lf_hash_search
+# ▾ rw_trx_hash_t::find
+# ▾ trx_sys_t::find
+# ▾ lock_rec_convert_impl_to_expl
+# rw_trx_hash_t::find returns lf_hash element, pin 2 is pinned,
+# but element->mutex has not been acquired yet, what allows trx1 element to be
+# removed from trx_sys.rw_trx_hash at one hand, and at the other hand, the
+# content of the element is still valid as it's pinned.
+#
+# trx2
+--send SELECT * FROM t1 WHERE a = 1 FOR UPDATE
+--connection default
+SET DEBUG_SYNC="now WAIT_FOR before_mutex_enter";
+--disable_query_log
+SET @saved_dbug = @@debug_dbug;
+
+# Usually pinbox purgatory is purged either when the number of elements in
+# purgatory is greater then some limit(see lf_pinbox_free()), or when thread
+# invokes rw_trx_hash_t::put_pins() explicitly. For this test the first
+# variant was choosen. The following option makes lf_pinbox_free() to purge
+# pinbox purgatory on each call, ignoring pins->purgatory_count.
+SET DEBUG_DBUG='+d,unconditional_pinbox_free';
+--enable_query_log
+
+# trx1 is committed and removed from trx_sys.rw_trx_hash. It can be done as
+# trx2 has not been acquired element->mutex yet.
+COMMIT;
+--disable_query_log
+SET DEBUG_DBUG = @saved_dbug;
+--enable_query_log
+
+# Let trx2 to acquire element->mutex and unpin pin 2
+SET DEBUG_SYNC="now SIGNAL cont1";
+SET DEBUG_SYNC="now WAIT_FOR after_mutex_enter";
+
+--disable_query_log
+SET @saved_dbug = @@debug_dbug;
+SET DEBUG_DBUG='+d,unconditional_pinbox_free';
+--enable_query_log
+# trx3 commits and invokes lf_pinbox_free(), which purges pin 2 of trx2 and
+# places its pointer on trx_sys.rw_trx_hash.hash.alloc.top.
+insert into t2 values(1);
+--disable_query_log
+SET DEBUG_DBUG = @saved_dbug;
+--enable_query_log
+
+BEGIN; # trx4
+# trx_sys.rw_trx_hash.hash.alloc.top points to "freed" trx2 lf_hash element,
+# lf_alloc_new() gets the pointer from trx_sys.rw_trx_hash.hash.alloc.top,
+# so the memory for lf_hash element will be reused for trx4 if MDEV-31185 is
+# not fixed
+INSERT INTO t2 VALUES(2);
+
+# let trx2 to invoke DBUG_ASSERT(trx_id == trx->id) and crash if MDEV-31185
+# is not fixed
+SET DEBUG_SYNC="now SIGNAL cont2";
+
+--connection con_1
+# trx 2 assertion failure if MDEV-31185 is not fixed
+--reap
+--disconnect con_1
+--connection default
+DROP TABLE t1;
+DROP TABLE t2;
+
+SET DEBUG_SYNC="reset";
+
+--source include/wait_until_count_sessions.inc
diff --git a/mysql-test/suite/innodb/t/undo_log.test b/mysql-test/suite/innodb/t/undo_log.test
new file mode 100644
index 00000000..2dbc9191
--- /dev/null
+++ b/mysql-test/suite/innodb/t/undo_log.test
@@ -0,0 +1,153 @@
+--source include/have_innodb.inc
+
+SET innodb_strict_mode=OFF;
+CREATE TABLE test_tab (
+a_str_18 mediumtext,
+b_str_3 varchar(32) DEFAULT NULL,
+a_str_13 mediumtext,
+b_str_5 varchar(40) DEFAULT NULL,
+b_str_6 varchar(50) DEFAULT NULL,
+b_str_7 char(32) DEFAULT NULL,
+b_str_8 varchar(32) DEFAULT NULL,
+b_str_9 varchar(255) DEFAULT NULL,
+a_str_28 char(255) DEFAULT NULL,
+a_str_27 varchar(255) DEFAULT NULL,
+b_str_10 varchar(32) DEFAULT NULL,
+a_str_26 varchar(255) DEFAULT NULL,
+a_str_6 varchar(50) DEFAULT NULL,
+b_str_11 varchar(32) DEFAULT NULL,
+b_str_12 varchar(255) DEFAULT NULL,
+b_str_13 char(32) DEFAULT NULL,
+b_str_14 varchar(32) DEFAULT NULL,
+b_str_15 char(32) DEFAULT NULL,
+b_str_16 char(32) DEFAULT NULL,
+b_str_17 varchar(32) DEFAULT NULL,
+b_str_18 varchar(32) DEFAULT NULL,
+a_str_25 varchar(40) DEFAULT NULL,
+b_str_19 varchar(255) DEFAULT NULL,
+a_str_23 varchar(40) DEFAULT NULL,
+b_str_20 varchar(32) DEFAULT NULL,
+a_str_21 varchar(255) DEFAULT NULL,
+a_str_20 varchar(255) DEFAULT NULL,
+a_str_39 varchar(255) DEFAULT NULL,
+a_str_38 varchar(255) DEFAULT NULL,
+a_str_37 varchar(255) DEFAULT NULL,
+b_str_21 char(32) DEFAULT NULL,
+b_str_23 varchar(80) DEFAULT NULL,
+b_str_24 varchar(32) DEFAULT NULL,
+b_str_25 varchar(32) DEFAULT NULL,
+b_str_26 char(32) NOT NULL DEFAULT '',
+b_str_27 varchar(255) DEFAULT NULL,
+a_str_36 varchar(255) DEFAULT NULL,
+a_str_33 varchar(100) DEFAULT NULL,
+a_ref_10 char(32) DEFAULT NULL,
+b_str_28 char(32) DEFAULT NULL,
+b_str_29 char(32) DEFAULT NULL,
+a_ref_6 char(32) DEFAULT NULL,
+a_ref_12 varchar(32) DEFAULT NULL,
+a_ref_11 varchar(32) DEFAULT NULL,
+a_str_49 varchar(40) DEFAULT NULL,
+b_str_30 varchar(32) DEFAULT NULL,
+a_ref_3 varchar(32) DEFAULT NULL,
+a_str_48 varchar(40) DEFAULT NULL,
+a_ref_1 char(32) DEFAULT NULL,
+b_str_31 varchar(32) DEFAULT NULL,
+b_str_32 varchar(255) DEFAULT NULL,
+b_str_33 char(32) DEFAULT NULL,
+b_str_34 varchar(32) DEFAULT NULL,
+a_str_47 varchar(40) DEFAULT NULL,
+b_str_36 varchar(255) DEFAULT NULL,
+a_str_46 varchar(40) DEFAULT NULL,
+a_str_45 varchar(255) DEFAULT NULL,
+b_str_38 varchar(32) DEFAULT NULL,
+b_str_39 char(32) DEFAULT NULL,
+b_str_40 varchar(32) DEFAULT NULL,
+a_str_41 varchar(255) DEFAULT NULL,
+b_str_41 varchar(32) DEFAULT NULL,
+PRIMARY KEY (b_str_26),
+UNIQUE KEY a_str_47 (a_str_47),
+UNIQUE KEY a_str_49 (a_str_49),
+UNIQUE KEY a_str_33 (a_str_33),
+UNIQUE KEY a_str_46 (a_str_46),
+UNIQUE KEY a_str_48 (a_str_48),
+KEY b_str_18 (b_str_18),
+KEY a_str_26 (a_str_26),
+KEY b_str_27 (b_str_27,b_str_19),
+KEY b_str_41 (b_str_41),
+KEY b_str_15 (b_str_15),
+KEY a_str_20 (a_str_20),
+KEY b_str_17 (b_str_17),
+KEY b_str_40 (b_str_40),
+KEY b_str_24 (b_str_24),
+KEY b_str_10 (b_str_10),
+KEY b_str_16 (b_str_16),
+KEY b_str_29 (b_str_29),
+KEY a_str_41 (a_str_41),
+KEY b_str_7 (b_str_7),
+KEY a_str_45 (a_str_45),
+KEY a_str_28 (a_str_28),
+KEY a_str_37 (a_str_37),
+KEY b_str_6 (b_str_6),
+KEY a_ref_6 (a_ref_6),
+KEY b_str_34 (b_str_34),
+KEY b_str_38 (b_str_38),
+KEY a_ref_10 (a_ref_10),
+KEY b_str_21 (b_str_21),
+KEY b_str_23 (b_str_23,b_str_19),
+KEY b_str_33 (b_str_33),
+KEY a_ref_12 (a_ref_12),
+KEY a_str_18 (a_str_18(255)),
+KEY a_str_39 (a_str_39),
+KEY a_str_27 (a_str_27),
+KEY a_str_25 (a_str_25),
+KEY b_str_9 (b_str_9),
+KEY a_str_23 (a_str_23),
+KEY b_str_8 (b_str_8),
+KEY a_str_21 (a_str_21),
+KEY b_str_3 (b_str_3),
+KEY b_str_30 (b_str_30),
+KEY b_str_12 (b_str_12),
+KEY b_str_25 (b_str_25),
+KEY b_str_13 (b_str_13),
+KEY a_str_38 (a_str_38),
+KEY a_str_13 (a_str_13(255)),
+KEY a_str_36 (a_str_36),
+KEY b_str_28 (b_str_28),
+KEY b_str_19 (b_str_19),
+KEY b_str_11 (b_str_11),
+KEY a_ref_1 (a_ref_1),
+KEY b_str_20 (b_str_20),
+KEY b_str_14 (b_str_14),
+KEY a_ref_3 (a_ref_3),
+KEY b_str_39 (b_str_39),
+KEY b_str_32 (b_str_32),
+KEY a_str_6 (a_str_6),
+KEY b_str_5 (b_str_5),
+KEY b_str_31 (b_str_31),
+KEY a_ref_11 (a_ref_11)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8 ROW_FORMAT=COMPACT;
+SET innodb_strict_mode=ON;
+
+BEGIN;
+INSERT INTO test_tab (b_str_26, a_str_13, a_str_18) VALUES
+('a', REPEAT('f',4031), REPEAT('g', 4031));
+
+UPDATE test_tab SET a_str_13=REPEAT('h',4032), a_str_18=REPEAT('i',4032);
+SELECT 'Reducing length to 4030';
+UPDATE test_tab SET a_str_13=REPEAT('j',4030), a_str_18=REPEAT('k',4030);
+UPDATE test_tab SET a_str_13=REPEAT('l',4031), a_str_18=REPEAT('m',4031);
+ROLLBACK;
+SELECT COUNT(*) FROM test_tab;
+CHECK TABLE test_tab;
+DROP TABLE test_tab;
+
+CREATE TEMPORARY TABLE t2(i INT)ENGINE=InnoDB;
+CREATE TABLE t1(i TEXT NOT NULL) ENGINE=INNODB;
+BEGIN;
+INSERT t1 SET i=REPEAT('1234567890',840);
+UPDATE t1 SET i='';
+INSERT INTO t2 VALUES(2);
+ROLLBACK;
+--source include/wait_all_purged.inc
+DROP TABLE t1;
+DROP TABLE t2;
diff --git a/mysql-test/suite/innodb/t/undo_space_dblwr.opt b/mysql-test/suite/innodb/t/undo_space_dblwr.opt
new file mode 100644
index 00000000..0b4f5917
--- /dev/null
+++ b/mysql-test/suite/innodb/t/undo_space_dblwr.opt
@@ -0,0 +1,2 @@
+--innodb_undo_tablespaces=3
+--innodb_sys_tablespaces
diff --git a/mysql-test/suite/innodb/t/undo_space_dblwr.test b/mysql-test/suite/innodb/t/undo_space_dblwr.test
new file mode 100644
index 00000000..b6fd6738
--- /dev/null
+++ b/mysql-test/suite/innodb/t/undo_space_dblwr.test
@@ -0,0 +1,46 @@
+--source include/have_innodb.inc
+--source include/have_debug.inc
+--source include/not_embedded.inc
+call mtr.add_suppression("Checksum mismatch in the first page of file");
+let INNODB_PAGE_SIZE=`select @@innodb_page_size`;
+let MYSQLD_DATADIR=`select @@datadir`;
+
+show variables like 'innodb_doublewrite';
+create table t1(f1 int not null, f2 int not null)engine=innodb;
+insert into t1 values (1, 1);
+
+--source include/wait_all_purged.inc
+
+set GLOBAL innodb_log_checkpoint_now=1;
+--source ../include/no_checkpoint_start.inc
+
+--echo # Make the first page dirty for undo tablespace
+set global innodb_saved_page_number_debug = 0;
+set global innodb_fil_make_page_dirty_debug = 1;
+
+SET GLOBAL innodb_max_dirty_pages_pct_lwm=0.0;
+SET GLOBAL innodb_max_dirty_pages_pct=0.0;
+
+sleep 1;
+--let CLEANUP_IF_CHECKPOINT=drop table t1;
+--source ../include/no_checkpoint_end.inc
+
+perl;
+use IO::Handle;
+my $fname= "$ENV{'MYSQLD_DATADIR'}/undo001";
+my $page_size = $ENV{INNODB_PAGE_SIZE};
+die unless open(FILE, "+<", $fname);
+sysread(FILE, $page, $page_size)==$page_size||die "Unable to read $name\n";
+substr($page, 49, 4) = pack("N", 1000);
+sysseek(FILE, 0, 0)||die "Unable to seek $fname\n";
+die unless syswrite(FILE, $page, $page_size) == $page_size;
+close FILE;
+EOF
+
+--source include/start_mysqld.inc
+let SEARCH_FILE= $MYSQLTEST_VARDIR/log/mysqld.1.err;
+let SEARCH_PATTERN= Checksum mismatch in the first page of file;
+--source include/search_pattern_in_file.inc
+
+check table t1;
+drop table t1;
diff --git a/mysql-test/suite/innodb/t/undo_truncate.opt b/mysql-test/suite/innodb/t/undo_truncate.opt
new file mode 100644
index 00000000..5e331e83
--- /dev/null
+++ b/mysql-test/suite/innodb/t/undo_truncate.opt
@@ -0,0 +1,3 @@
+--innodb-buffer-pool-size=24M
+--innodb-immediate-scrub-data-uncompressed=ON
+--loose-innodb-sys-tablespaces
diff --git a/mysql-test/suite/innodb/t/undo_truncate.test b/mysql-test/suite/innodb/t/undo_truncate.test
new file mode 100644
index 00000000..18cc4f36
--- /dev/null
+++ b/mysql-test/suite/innodb/t/undo_truncate.test
@@ -0,0 +1,72 @@
+--source include/have_innodb.inc
+--source include/innodb_page_size.inc
+--source include/not_embedded.inc
+--source include/have_sequence.inc
+--source include/no_valgrind_without_big.inc
+
+--disable_query_log
+call mtr.add_suppression("InnoDB: Difficult to find free blocks in the buffer pool");
+--disable_query_log
+# This may be triggered on a slow system.
+call mtr.add_suppression("InnoDB: Trying to delete tablespace.*pending operations");
+--enable_query_log
+
+# Re-create the undo log tablespaces after slow shutdown
+SET GLOBAL innodb_fast_shutdown=0;
+let $restart_parameters="--innodb_undo_tablespaces=2";
+--source include/restart_mysqld.inc
+
+SET GLOBAL innodb_undo_log_truncate = 0;
+
+LET $MYSQLD_DATADIR = `select @@datadir`;
+LET $INNODB_PAGE_SIZE = `select @@innodb_page_size`;
+--source suite/innodb/include/show_i_s_tablespaces.inc
+#-----------------------------------------------------------------------------
+#
+# Perform DML action using multiple clients and multiple undo tablespace.
+#
+#
+create table t1(keyc int primary key, c char(100)) engine = innodb;
+create table t2(keyc int primary key, c char(100)) engine = innodb;
+#
+let DATADIR = `select @@datadir`;
+connect (con1,localhost,root,,);
+begin;
+send insert into t1 select seq,'a' from seq_1_to_20000;
+
+connect (con2,localhost,root,,);
+begin;
+send insert into t2 select seq,'a' from seq_1_to_20000;
+
+connection con1; reap; send update t1 set c = 'mysql';
+connection con2; reap; send update t2 set c = 'mysql';
+connection con1; reap; send update t1 set c = 'oracle';
+connection con2; reap; send update t2 set c = 'oracle';
+connection con1; reap; send delete from t1;
+connection con2; reap; delete from t2;
+connection con1; reap;
+
+SET GLOBAL innodb_undo_log_truncate = 1;
+commit; disconnect con1;
+connection con2; commit; disconnect con2;
+
+connection default;
+
+--replace_regex /.*Trx id counter ([0-9]+).*/\1/
+let $trx_before= `SHOW ENGINE INNODB STATUS`;
+let $trx_before= `select substr('$trx_before',9)+2`;
+
+SET GLOBAL innodb_max_purge_lag_wait=0;
+set global innodb_fast_shutdown=0;
+let $restart_parameters=;
+--source include/restart_mysqld.inc
+--replace_regex /.*Trx id counter ([0-9]+).*/\1/
+let $trx_after= `SHOW ENGINE INNODB STATUS`;
+let $trx_after= `select substr('$trx_after',9)`;
+
+drop table t1, t2;
+
+if ($trx_before > $trx_after)
+{
+ echo Transaction sequence mismatch: $trx_before > $trx_after;
+}
diff --git a/mysql-test/suite/innodb/t/undo_truncate_recover.combinations b/mysql-test/suite/innodb/t/undo_truncate_recover.combinations
new file mode 100644
index 00000000..72938059
--- /dev/null
+++ b/mysql-test/suite/innodb/t/undo_truncate_recover.combinations
@@ -0,0 +1,5 @@
+[strict_crc32]
+--innodb-checksum-algorithm=strict_crc32
+
+[strict_full_crc32]
+--innodb-checksum-algorithm=strict_full_crc32
diff --git a/mysql-test/suite/innodb/t/undo_truncate_recover.opt b/mysql-test/suite/innodb/t/undo_truncate_recover.opt
new file mode 100644
index 00000000..a1207721
--- /dev/null
+++ b/mysql-test/suite/innodb/t/undo_truncate_recover.opt
@@ -0,0 +1 @@
+--innodb-purge-threads=1
diff --git a/mysql-test/suite/innodb/t/undo_truncate_recover.test b/mysql-test/suite/innodb/t/undo_truncate_recover.test
new file mode 100644
index 00000000..148c3f93
--- /dev/null
+++ b/mysql-test/suite/innodb/t/undo_truncate_recover.test
@@ -0,0 +1,57 @@
+#
+# WL#6965: Truncate UNDO logs.
+#
+
+--source include/big_test.inc
+--source include/not_valgrind.inc
+# With larger innodb_page_size, the undo log tablespaces do not grow enough.
+--source include/innodb_page_size_small.inc
+--source include/have_innodb.inc
+--source include/have_debug.inc
+# Tests with embedded server do not support restarting
+--source include/not_embedded.inc
+
+# Re-create the undo log tablespaces after slow shutdown
+SET GLOBAL innodb_fast_shutdown=0;
+let $restart_parameters="--innodb_undo_tablespaces=2";
+--source include/restart_mysqld.inc
+
+SET GLOBAL innodb_undo_log_truncate = 1;
+
+let SEARCH_FILE = $MYSQLTEST_VARDIR/log/mysqld.1.err;
+
+create table t1(keyc int primary key, c char(100)) engine = innodb;
+begin;
+--disable_query_log
+let $i=30000;
+while ($i) {
+ eval insert into t1 values(30000-$i, '');
+ dec $i;
+}
+--enable_query_log
+commit;
+
+let $checksum_algorithm = `SELECT @@GLOBAL.innodb_checksum_algorithm`;
+let SEARCH_PATTERN = ib_undo_trunc;
+begin;
+update t1 set c = 'MariaDB';
+update t1 set c = 'InnoDB';
+eval set global debug_dbug = '+d,$SEARCH_PATTERN';
+commit;
+drop table t1;
+call mtr.add_suppression("InnoDB: innodb_undo_tablespaces=0 disables dedicated undo log tablespaces");
+SET GLOBAL innodb_fast_shutdown=0;
+--source include/shutdown_mysqld.inc
+--source include/search_pattern_in_file.inc
+--let $restart_parameters= --innodb-undo-tablespaces=1
+--let $restart_noprint=1
+if ($checksum_algorithm == "strict_full_crc32")
+{
+ let $restart_parameters= $restart_parameters --innodb_checksum_algorithm=strict_crc32;
+}
+
+if ($checksum_algorithm == "strict_crc32")
+{
+ let $restart_parameters= $restart_parameters --innodb_checksum_algorithm=strict_full_crc32;
+}
+--source include/start_mysqld.inc
diff --git a/mysql-test/suite/innodb/t/undo_upgrade.opt b/mysql-test/suite/innodb/t/undo_upgrade.opt
new file mode 100644
index 00000000..87bc4c4d
--- /dev/null
+++ b/mysql-test/suite/innodb/t/undo_upgrade.opt
@@ -0,0 +1,2 @@
+--log-bin=1
+--innodb_undo_tablespaces=4
diff --git a/mysql-test/suite/innodb/t/undo_upgrade.test b/mysql-test/suite/innodb/t/undo_upgrade.test
new file mode 100644
index 00000000..9c0da017
--- /dev/null
+++ b/mysql-test/suite/innodb/t/undo_upgrade.test
@@ -0,0 +1,78 @@
+--source include/have_innodb.inc
+--source include/innodb_page_size.inc
+--source include/not_embedded.inc
+
+--echo #
+--echo # MDEV-19229 Allow innodb_undo_tablespaces to be changed
+--echo # after database creation
+--echo #
+call mtr.add_suppression("Found .* prepared XA transactions");
+call mtr.add_suppression("InnoDB: Plugin initialization aborted");
+call mtr.add_suppression("Plugin 'InnoDB' init function returned error");
+call mtr.add_suppression("Plugin 'InnoDB' registration as a STORAGE ENGINE failed");
+call mtr.add_suppression("InnoDB: Cannot change innodb_undo_tablespaces=\\d+ because previous shutdown was not with innodb_fast_shutdown=0");
+
+let $MYSQLD_DATADIR= `select @@datadir`;
+
+CREATE TABLE t1(f1 INT NOT NULL)ENGINE=InnoDB;
+--echo # case 1: XA transaction alone left
+--source include/wait_all_purged.inc
+XA START 'zombie';
+INSERT INTO t1 VALUES(2);
+XA END 'zombie';
+XA PREPARE 'zombie';
+
+--source include/restart_mysqld.inc
+
+--echo # Display 4 undo tablespaces
+select @@global.innodb_undo_tablespaces;
+
+--echo # Should list 4 undo log tablespaces
+list_files $MYSQLD_DATADIR undo*;
+
+XA COMMIT 'zombie';
+
+--echo # case 2: Successful innodb_undo_tablespace upgrade
+SET GLOBAL innodb_fast_shutdown=0;
+
+let $restart_parameters=--innodb_undo_tablespaces=2;
+--source include/restart_mysqld.inc
+
+--echo # Display 2 undo tablespaces
+SELECT @@global.innodb_undo_tablespaces;
+
+--echo # Should list 2 undo log tablespaces
+list_files $MYSQLD_DATADIR undo*;
+
+DROP TABLE t1;
+--source include/wait_all_purged.inc
+
+--echo # case 3: Reduce the innodb_undo_tablespace to 0
+let $restart_parameters=--innodb_undo_tablespaces=0;
+--source include/restart_mysqld.inc
+
+--echo # Display 0 undo tablespace
+SELECT @@global.innodb_undo_tablespaces;
+
+--echo # Shouldn't list any undo log tablespaces
+list_files $MYSQLD_DATADIR undo*;
+
+--echo # case 4: Change undo tablespace when force_recovery < 5
+let $restart_parameters=--innodb_undo_tablespaces=2 --innodb_force_recovery=4;
+--source include/restart_mysqld.inc
+
+--echo # Display 2 undo tablespace
+SELECT @@global.innodb_undo_tablespaces;
+
+--echo # Should list 2 undo log tablespaces
+list_files $MYSQLD_DATADIR undo*;
+
+--echo # case 5: Fail to change undo tablespace when force_recovery > 4
+let $restart_parameters=--innodb_undo_tablespaces=4 --innodb_force_recovery=5;
+--source include/restart_mysqld.inc
+
+--echo # Display 2 undo tablespace
+SELECT @@global.innodb_undo_tablespaces;
+
+--echo # Should list 2 undo log tablespaces, not 4
+list_files $MYSQLD_DATADIR undo*;
diff --git a/mysql-test/suite/innodb/t/undo_upgrade_debug.test b/mysql-test/suite/innodb/t/undo_upgrade_debug.test
new file mode 100644
index 00000000..e274d6c0
--- /dev/null
+++ b/mysql-test/suite/innodb/t/undo_upgrade_debug.test
@@ -0,0 +1,70 @@
+--source include/have_innodb.inc
+--source include/innodb_page_size.inc
+--source include/have_debug.inc
+--source include/not_embedded.inc
+
+--echo #
+--echo # MDEV-19229 Allow innodb_undo_tablespaces to be changed
+--echo # after database creation
+--echo #
+let $MYSQLD_DATADIR= `select @@datadir`;
+call mtr.add_suppression("InnoDB: Plugin initialization aborted");
+call mtr.add_suppression("Plugin 'InnoDB' init function returned error");
+call mtr.add_suppression("Plugin 'InnoDB' registration as a STORAGE ENGINE failed");
+
+set global innodb_fast_shutdown=0;
+
+--echo # case 1: Abort after resetting TRX_SYS page rollback segments
+let $restart_parameters=--innodb_undo_tablespaces=4 --debug_dbug="+d,after_rseg_reset_abort";
+
+--source include/restart_mysqld.inc
+
+let $restart_parameters=--innodb_undo_tablespaces=4;
+--source include/restart_mysqld.inc
+
+--echo # Should list 4 undo log tablespaces
+list_files $MYSQLD_DATADIR undo*;
+
+--echo # case 2: Abort after deleting the old undo tablespaces
+let $restart_parameters=--innodb_undo_tablespaces=2 --debug_dbug="+d,after_deleting_old_undo_abort";
+
+--source include/restart_mysqld.inc
+
+let $restart_parameters=--innodb_undo_tablespaces=2;
+--source include/restart_mysqld.inc
+
+--echo # Should list 2 undo log tablespaces
+list_files $MYSQLD_DATADIR undo*;
+
+--echo # case 3: Abort after successfully deleting the old undo tablespace
+let $restart_parameters=--innodb_undo_tablespaces=3 --debug_dbug="+d,after_deleting_old_undo_success";
+
+--source include/restart_mysqld.inc
+
+let $restart_parameters=--innodb_undo_tablespaces=3;
+--source include/restart_mysqld.inc
+
+--echo # Should list 3 undo log tablespaces
+list_files $MYSQLD_DATADIR undo*;
+
+--echo # case 4: Abort after re-creating new undo tablespaces
+let $restart_parameters=--innodb_undo_tablespaces=4 --debug_dbug="+d,after_reinit_undo_abort";
+
+--source include/restart_mysqld.inc
+
+let $restart_parameters=--innodb_undo_tablespaces=4;
+--source include/restart_mysqld.inc
+
+--echo # Should list 4 undo log tablespaces
+list_files $MYSQLD_DATADIR undo*;
+
+--echo # case 5: Abort after re-creating new undo tablespaces successfully
+let $restart_parameters=--innodb_undo_tablespaces=2 --debug_dbug="+d,after_reinit_undo_success";
+
+--source include/restart_mysqld.inc
+
+let $restart_parameters=--innodb_undo_tablespaces=2;
+--source include/restart_mysqld.inc
+
+--echo # Should list 2 undo log tablespaces
+list_files $MYSQLD_DATADIR undo*;
diff --git a/mysql-test/suite/innodb/t/update-cascade.test b/mysql-test/suite/innodb/t/update-cascade.test
new file mode 100644
index 00000000..69e81ac4
--- /dev/null
+++ b/mysql-test/suite/innodb/t/update-cascade.test
@@ -0,0 +1,221 @@
+--source include/have_innodb.inc
+--source include/have_debug.inc
+--source include/have_debug_sync.inc
+
+# Save the initial number of concurrent sessions
+--source include/count_sessions.inc
+
+--echo #
+--echo # Bug #18451287 REDUNDANT DELETE MARKING AFTER DB_LOCK_WAIT
+--echo #
+
+create table t1 (f1 int primary key, f2 blob) engine=innodb;
+create table t2 (f1 int primary key, f2 int,
+ foreign key (f2) references t1(f1) on update cascade) engine=innodb;
+
+show create table t1;
+show create table t2;
+insert into t1 values (1, repeat('+', 20000));
+insert into t1 values (2, repeat('-', 20000));
+insert into t1 values (3, repeat('=', 20000));
+insert into t2 values (1, 2);
+
+select f1, right(f2, 20) as p2 from t1;
+select f1, f2 from t2;
+
+connect(con1,localhost,root,,test);
+start transaction;
+select f1, f2 from t2 for update;
+
+connection default;
+set debug_sync='lock_wait_start SIGNAL upd_waiting WAIT_FOR go_upd';
+send update t1 set f1 = 10 where f1 = 2;
+
+connection con1;
+set debug_sync='now WAIT_FOR upd_waiting';
+rollback;
+set debug_sync='now SIGNAL go_upd';
+
+connection default;
+--echo # reap: update t1 set f1 = 10 where f1 = 2;
+reap;
+
+select f1, right(f2, 20) as p2 from t1;
+select f1, f2 from t2;
+
+drop table t2, t1;
+
+set debug_sync = reset;
+
+--echo #
+--echo # Test Scenario: Two tables t1 -> t2 are involved in update cascade.
+--echo # If DB_LOCK_WAIT happens when t1 is being updated and FK constraints
+--echo # are being checked in t2, then retry must happen on t1. The update
+--echo # cascade happens in secondary index. For secondary index testing,
+--echo # blobs are not needed.
+--echo #
+
+create table t1 (f1 int primary key, f2 int, key k1(f2)) engine=innodb;
+create table t2 (f1 int primary key, f2 int,
+ foreign key (f2) references t1(f2) on update cascade) engine=innodb;
+
+show create table t1;
+show create table t2;
+insert into t1 values (1, 91);
+insert into t2 values (1, 91);
+
+select f1, f2 from t1;
+select f1, f2 from t2;
+
+connection con1;
+start transaction;
+select f1, f2 from t2 for update;
+
+connection default;
+set debug_sync='lock_wait_start SIGNAL upd_waiting WAIT_FOR go_upd';
+send update t1 set f2 = 28 where f2 = 91;
+
+connection con1;
+set debug_sync='now WAIT_FOR upd_waiting';
+rollback;
+set debug_sync='now SIGNAL go_upd';
+
+connection default;
+--echo # reap: update t1 set f1 = 10 where f1 = 2;
+--reap
+
+select f1, f2 from t1;
+select f1, f2 from t2;
+
+drop table t2, t1;
+
+set debug_sync = reset;
+
+--echo #
+--echo # Test Scenario: Three tables t1 -> t2 -> t3 are involved in update cascade.
+--echo # If DB_LOCK_WAIT happens when t2 is being updated, then retry must happen
+--echo # on t2.
+--echo #
+
+create table t1 (f1 int primary key, f2 blob) engine=innodb;
+create table t2 (f1 int primary key, f2 blob,
+ foreign key (f1) references t1(f1) on update cascade) engine=innodb;
+create table t3 (f1 int primary key, f2 blob,
+ foreign key (f1) references t2(f1) on update cascade) engine=innodb;
+
+show create table t1;
+show create table t2;
+show create table t3;
+
+insert into t1 values (2, repeat('-', 20000));
+insert into t2 values (2, repeat('%', 20000));
+insert into t3 values (2, repeat('+', 20000));
+
+select f1, right(f2, 20) as p2 from t1;
+select f1, right(f2, 20) as p2 from t2;
+select f1, right(f2, 20) as p2 from t3;
+
+connection con1;
+start transaction;
+select f1 from t3 for update;
+
+connection default;
+set debug_sync='lock_wait_start SIGNAL upd_waiting WAIT_FOR go_upd';
+send update t1 set f1 = 10 where f1 = 2;
+
+connection con1;
+set debug_sync='now WAIT_FOR upd_waiting';
+rollback;
+
+--echo # The table t1 is updated.
+--echo # In t2 delete-mark happened. Retry will happen on t2.
+--echo # In t3 yet to be updated.
+set session transaction isolation level read uncommitted;
+start transaction;
+select f1, right(f2, 20) as p2 from t1;
+select f1, right(f2, 20) as p2 from t2;
+select f1, right(f2, 20) as p2 from t3;
+commit;
+
+set debug_sync='now SIGNAL go_upd';
+
+connection default;
+--echo # reap: update t1 set f1 = 10 where f1 = 2;
+--reap;
+
+start transaction;
+select f1, right(f2, 20) as p2 from t1;
+select f1, right(f2, 20) as p2 from t2;
+select f1, right(f2, 20) as p2 from t3;
+commit;
+
+drop table t3, t2, t1;
+
+set debug_sync = reset;
+
+--echo #
+--echo # Test Scenario: Three tables t1 -> t2 -> t3 are involved in update
+--echo # cascade. If DB_LOCK_WAIT happens when t2 is being updated, then
+--echo # retry must happen on t2. The update cascade is happening via
+--echo # secondary index (hence blobs are not needed).
+--echo #
+
+create table t1 (f1 int primary key, f2 int, key k1(f2)) engine=innodb;
+create table t2 (f1 int primary key, f2 int,
+ foreign key (f2) references t1(f2) on update cascade) engine=innodb;
+create table t3 (f1 int primary key, f2 int,
+ foreign key (f2) references t2(f2) on update cascade) engine=innodb;
+
+show create table t1;
+show create table t2;
+show create table t3;
+
+insert into t1 values (2, 91);
+insert into t2 values (2, 91);
+insert into t3 values (2, 91);
+
+select f1, f2 from t1;
+select f1, f2 from t2;
+select f1, f2 from t3;
+
+connection con1;
+start transaction;
+select f1 from t3 for update;
+
+connection default;
+set debug_sync='lock_wait_start SIGNAL upd_waiting WAIT_FOR go_upd';
+send update t1 set f2 = 28 where f2 = 91;
+
+connection con1;
+set debug_sync='now WAIT_FOR upd_waiting';
+rollback;
+
+--echo # The table t1 is updated.
+--echo # In t2 delete-mark happened. Retry will happen on t2.
+--echo # In t3 yet to be updated.
+set session transaction isolation level read uncommitted;
+start transaction;
+select f1, f2 from t1;
+select f1, f2 from t2;
+select f1, f2 from t3;
+commit;
+
+set debug_sync='now SIGNAL go_upd';
+disconnect con1;
+
+connection default;
+--echo # reap: update t1 set f2 = 28 where f2 = 91;
+--reap;
+
+start transaction;
+select f1, f2 from t1;
+select f1, f2 from t2;
+select f1, f2 from t3;
+commit;
+
+drop table t3, t2, t1;
+
+set debug_sync = reset;
+
+# Wait till all disconnects are completed
+--source include/wait_until_count_sessions.inc
diff --git a/mysql-test/suite/innodb/t/update_time-master.opt b/mysql-test/suite/innodb/t/update_time-master.opt
new file mode 100644
index 00000000..f0fd6475
--- /dev/null
+++ b/mysql-test/suite/innodb/t/update_time-master.opt
@@ -0,0 +1 @@
+--innodb-buffer-pool-size=5M
diff --git a/mysql-test/suite/innodb/t/update_time.test b/mysql-test/suite/innodb/t/update_time.test
new file mode 100644
index 00000000..ce841890
--- /dev/null
+++ b/mysql-test/suite/innodb/t/update_time.test
@@ -0,0 +1,48 @@
+###################################################################
+-- echo #
+-- echo # Test that INFORMATION_SCHEMA.TABLES.UPDATE_TIME is filled
+-- echo # correctly for InnoDB tables.
+-- echo #
+
+-- source include/have_innodb.inc
+# restart does not work with embedded
+-- source include/not_embedded.inc
+
+CREATE TABLE t (a INT) ENGINE=INNODB STATS_PERSISTENT=0;
+
+SELECT update_time FROM information_schema.tables WHERE table_name = 't';
+
+INSERT INTO t VALUES (1);
+
+SELECT COUNT(*) FROM information_schema.tables WHERE table_name = 't'
+AND update_time IS NOT NULL;
+
+-- echo # We cant deterministically check that the saved value is correct, but
+-- echo # at least we check that it is a timestamp not older than 2 minutes.
+-- echo # Usually update_time and NOW() are equal below, but on heavily loaded
+-- echo # machines NOW() could be younger.
+SELECT COUNT(*) FROM information_schema.tables WHERE table_name = 't'
+AND TIMESTAMPDIFF(SECOND, update_time, NOW()) < 120;
+
+-- echo # Test the behavior after restart with a prepared XA transaction
+
+XA START 'xatrx';
+DELETE FROM t;
+XA END 'xatrx';
+XA PREPARE 'xatrx';
+
+CONNECT (con1,localhost,root,,);
+
+call mtr.add_suppression("Found 1 prepared XA transactions");
+FLUSH TABLES;
+
+--let $shutdown_timeout=0
+--source include/restart_mysqld.inc
+
+SELECT update_time FROM information_schema.tables WHERE table_name = 't';
+
+XA COMMIT 'xatrx';
+
+SELECT COUNT(update_time) FROM information_schema.tables WHERE table_name='t';
+
+DROP TABLE t;
diff --git a/mysql-test/suite/innodb/t/update_time_wl6658.test b/mysql-test/suite/innodb/t/update_time_wl6658.test
new file mode 100644
index 00000000..0adc6a86
--- /dev/null
+++ b/mysql-test/suite/innodb/t/update_time_wl6658.test
@@ -0,0 +1,232 @@
+###################################################################
+#Testing functionality of the WL6658
+#case1: begin work with INSERT with Triggers
+#case2: (tab1u) begin transaction with UPDATE
+#case3: (tab1d) begin transaction with DELETE
+#case4: (tab1i) Rollback & INSERT
+#case5: (tab2) partitioned table and procedures
+#case6: (tab2) SAVEPOINT
+#case7: (tab7,tab8) pk-fk with ON DELETE CASCADE
+###################################################################
+--source include/no_valgrind_without_big.inc
+--source include/have_innodb.inc
+--source include/have_partition.inc
+--source include/not_embedded.inc
+
+CREATE TABLE tab1(c1 int,c2 varchar(30), c3 BLOB) ENGINE=InnoDB;
+CREATE TABLE tab1u LIKE tab1;
+CREATE TABLE tab1d LIKE tab1;
+CREATE TABLE tab1i LIKE tab1;
+CREATE TABLE tab3(c1 int,c2 varchar(30)) ENGINE=InnoDB;
+CREATE TABLE tab4(c1 int,c2 varchar(30)) ENGINE=InnoDB;
+CREATE TABLE tab5(c1 int,c2 varchar(30)) ENGINE=InnoDB;
+
+INSERT INTO tab1u VALUES(1,'Testing the wl6658','Testing the wl6658');
+INSERT INTO tab1d VALUES(1,'Updated','Updated');
+INSERT INTO tab4 VALUES(1,'Test for Update');
+INSERT INTO tab5 VALUES(1,'Test for Delete');
+
+delimiter |;
+
+CREATE TRIGGER test_trig BEFORE INSERT ON tab1
+FOR EACH ROW BEGIN
+ INSERT INTO tab3 VALUES(1,'Inserted From Trigger');
+ UPDATE tab4 SET c2='Updated from Trigger' WHERE c1=1;
+ DELETE FROM tab5;
+END |
+
+delimiter ;|
+
+CREATE TABLE tab2(
+ id INT NOT NULL,
+ store_name VARCHAR(30),
+ parts VARCHAR(30),
+ store_id INT
+) ENGINE=InnoDB
+PARTITION BY LIST(store_id) (
+ PARTITION pNorth VALUES IN (10,20,30),
+ PARTITION pEast VALUES IN (40,50,60),
+ PARTITION pWest VALUES IN (70,80,100)
+);
+
+SELECT update_time
+FROM information_schema.tables WHERE table_name='tab2';
+
+delimiter |;
+
+CREATE PROCEDURE proc_wl6658()
+BEGIN
+INSERT INTO tab2 VALUES(1,'ORACLE','NUTT',10);
+INSERT INTO tab2 VALUES(2,'HUAWEI','BOLT',40);
+COMMIT;
+END |
+
+delimiter ;|
+
+CALL proc_wl6658;
+
+SELECT * FROM tab2 ORDER BY id,store_id;
+
+SELECT COUNT(update_time)
+FROM information_schema.tables WHERE table_name='tab2';
+
+TRUNCATE TABLE tab2;
+
+SELECT COUNT(update_time)
+FROM information_schema.tables WHERE table_name='tab2';
+
+CREATE TABLE tab7(c1 INT NOT NULL, PRIMARY KEY (c1)) ENGINE=INNODB;
+
+CREATE TABLE tab8(c1 INT PRIMARY KEY,c2 INT,
+FOREIGN KEY (c2) REFERENCES tab7(c1) ON DELETE CASCADE )
+ENGINE=INNODB;
+
+SELECT table_name,update_time
+FROM information_schema.tables WHERE table_name IN ('tab7','tab8')
+GROUP BY table_name ORDER BY table_name;
+
+INSERT INTO tab7 VALUES(1);
+
+INSERT INTO tab8 VALUES(1,1);
+
+SELECT table_name,COUNT(update_time)
+FROM information_schema.tables WHERE table_name IN ('tab7','tab8')
+GROUP BY table_name ORDER BY table_name;
+
+--echo #restart the server
+--source include/restart_mysqld.inc
+
+SELECT table_name,update_time
+FROM information_schema.tables
+WHERE table_name IN ('tab1','tab2','tab3','tab4','tab5','tab7','tab8')
+ORDER BY table_name;
+
+--echo #case1:
+
+BEGIN WORK;
+
+INSERT INTO tab1
+VALUES(1,'Testing the wl6658', 'Testing the wl6658');
+
+SELECT update_time
+FROM information_schema.tables WHERE table_name='tab1';
+
+COMMIT;
+
+SELECT * FROM tab1;
+SELECT * FROM tab3;
+SELECT * FROM tab4;
+SELECT * FROM tab5;
+
+SELECT table_name,COUNT(update_time)
+FROM information_schema.tables
+WHERE table_name IN ('tab1','tab3','tab4','tab5')
+GROUP BY table_name ORDER BY table_name;
+
+--echo Testcase with UPDATE stmt and transaction
+
+SELECT * FROM tab1u;
+
+SELECT update_time
+FROM information_schema.tables WHERE table_name='tab1u';
+
+--echo #case2:
+START TRANSACTION;
+
+UPDATE tab1u SET c2='Updated',c3='Updated' WHERE c1=1;
+
+SELECT update_time
+FROM information_schema.tables WHERE table_name='tab1u';
+
+COMMIT;
+
+SELECT * FROM tab1u;
+
+SELECT COUNT(update_time)
+FROM information_schema.tables WHERE table_name='tab1u';
+
+SELECT * FROM tab1d;
+
+SELECT update_time
+FROM information_schema.tables WHERE table_name='tab1d';
+
+--echo #case3:
+START TRANSACTION;
+
+DELETE FROM tab1d;
+
+SELECT update_time
+FROM information_schema.tables WHERE table_name='tab1d';
+
+COMMIT;
+
+SELECT * FROM tab1d;
+
+SELECT COUNT(update_time)
+FROM information_schema.tables WHERE table_name='tab1d';
+
+SELECT * FROM tab1i;
+
+SELECT update_time
+FROM information_schema.tables WHERE table_name='tab1i';
+
+--echo #case4:
+START TRANSACTION;
+
+INSERT INTO tab1i
+VALUES(1,'Testing the wl6658', 'Testing the wl6658');
+
+SELECT update_time
+FROM information_schema.tables WHERE table_name='tab1i';
+
+ROLLBACK;
+
+SELECT * FROM tab1i;
+
+SELECT update_time
+FROM information_schema.tables WHERE table_name='tab1i';
+
+BEGIN WORK;
+DELETE FROM tab1i;
+SAVEPOINT A;
+INSERT INTO tab2 VALUES(1,'Oracle','NUTT',10);
+INSERT INTO tab2 VALUES(2,'HUAWEI','BOLT',40);
+SAVEPOINT B;
+INSERT INTO tab2 VALUES(3,'IBM','NAIL',70);
+SAVEPOINT C;
+ROLLBACK to A;
+
+SELECT * FROM tab2;
+
+SELECT update_time
+FROM information_schema.tables WHERE table_name='tab2';
+
+--echo #execute DDL instead of commit
+create table tab6(c1 int);
+
+SELECT update_time
+FROM information_schema.tables WHERE table_name='tab2';
+
+START TRANSACTION;
+DELETE FROM tab7;
+ROLLBACK;
+
+SELECT * FROM tab7;
+SELECT * FROM tab8;
+
+SELECT table_name,update_time
+FROM information_schema.tables WHERE table_name IN ('tab7','tab8')
+GROUP BY table_name ORDER BY table_name;
+
+DELETE FROM tab7;
+SELECT * FROM tab7;
+SELECT * FROM tab8;
+
+SELECT table_name,COUNT(update_time)
+FROM information_schema.tables WHERE table_name IN ('tab7','tab8')
+GROUP BY table_name ORDER BY table_name;
+
+--echo #cleanup
+DROP TRIGGER test_trig;
+DROP TABLE tab1,tab1u,tab1d,tab1i,tab2,tab3,tab4,tab5,tab6,tab8,tab7;
+DROP PROCEDURE proc_wl6658;
diff --git a/mysql-test/suite/innodb/t/xa_debug.test b/mysql-test/suite/innodb/t/xa_debug.test
new file mode 100644
index 00000000..5e38ba11
--- /dev/null
+++ b/mysql-test/suite/innodb/t/xa_debug.test
@@ -0,0 +1,46 @@
+-- source include/have_innodb.inc
+-- source include/have_debug.inc
+-- source include/not_embedded.inc
+
+call mtr.add_suppression("Found 50 prepared XA transactions");
+create table t1 (a int) engine=innodb;
+insert into t1 values(1);
+
+let $trial = 50;
+while ($trial)
+{
+--connect (con$trial, localhost, root,,)
+let $st_pre = `select concat('test', $trial)`;
+eval xa start '$st_pre';
+insert into t1 values(1);
+eval xa end '$st_pre';
+eval xa prepare '$st_pre';
+dec $trial;
+}
+
+connection default;
+# Kill and restart the server.
+FLUSH TABLES;
+-- exec echo "wait" > $MYSQLTEST_VARDIR/tmp/mysqld.1.expect
+-- shutdown_server 0
+-- source include/wait_until_disconnected.inc
+
+-- exec echo "restart:--debug_dbug=+d,min_xa_len" > $MYSQLTEST_VARDIR/tmp/mysqld.1.expect
+-- enable_reconnect
+-- source include/wait_until_connected_again.inc
+-- disable_reconnect
+--sorted_result
+xa recover;
+--sorted_result
+xa recover;
+--disable_query_log
+let $trial = 50;
+while ($trial)
+{
+let $st_pre = `select concat('test', $trial)`;
+eval xa commit '$st_pre';
+dec $trial;
+}
+--enable_query_log
+xa recover;
+drop table t1;
diff --git a/mysql-test/suite/innodb/t/xa_prepare_reset_supremum_lock.test b/mysql-test/suite/innodb/t/xa_prepare_reset_supremum_lock.test
new file mode 100644
index 00000000..180e44d0
--- /dev/null
+++ b/mysql-test/suite/innodb/t/xa_prepare_reset_supremum_lock.test
@@ -0,0 +1,48 @@
+--source include/have_innodb.inc
+--source include/count_sessions.inc
+
+CREATE TABLE t (
+ `a` INT NOT NULL,
+ PRIMARY KEY (`a`)
+) ENGINE=InnoDB;
+
+
+INSERT INTO t VALUES(10);
+INSERT INTO t VALUES(20);
+
+SET TRANSACTION ISOLATION LEVEL REPEATABLE READ;
+XA START '1';
+SELECT * FROM t WHERE a > 20 FOR UPDATE;
+# The following INSERT is necessary because trx_prepare() resets locks
+# only if there were modifications in transaction.
+INSERT INTO t VALUES(40);
+XA END '1';
+XA PREPARE '1';
+
+connect (con1,localhost,root);
+SET innodb_lock_wait_timeout=1;
+# The following INSERT must not be blocked if XA PREPARE released supremum lock
+INSERT INTO t VALUES(50);
+
+--connection default
+XA COMMIT '1';
+
+XA START '1';
+SELECT * FROM t WHERE a > 20 LOCK IN SHARE MODE;
+# The following INSERT is necessary because trx_prepare() resets locks
+# only if there were modifications in transaction.
+INSERT INTO t VALUES (5);
+XA END '1';
+XA PREPARE '1';
+
+--connection con1
+# The following INSERT must not be blocked if XA PREPARE released supremum lock
+INSERT INTO t VALUES (60);
+# The following INSERT must not be blocked if XA PREPARE released shared lock
+INSERT INTO t VALUES (30);
+--disconnect con1
+
+--connection default
+XA COMMIT '1';
+DROP TABLE t;
+--source include/wait_until_count_sessions.inc
diff --git a/mysql-test/suite/innodb/t/xa_recovery.test b/mysql-test/suite/innodb/t/xa_recovery.test
new file mode 100644
index 00000000..547c4eb9
--- /dev/null
+++ b/mysql-test/suite/innodb/t/xa_recovery.test
@@ -0,0 +1,63 @@
+--source include/have_innodb.inc
+# Embedded server does not support restarting.
+--source include/not_embedded.inc
+--source include/no_valgrind_without_big.inc
+
+# MDEV-8841 - close tables opened by previous tests,
+# so they don't get marked crashed when the server gets crashed
+--disable_query_log
+call mtr.add_suppression("Found [12] prepared XA transactions");
+FLUSH TABLES;
+--enable_query_log
+
+CREATE TABLE t1 (a INT) ENGINE=InnoDB;
+INSERT INTO t1 VALUES (1);
+connect (con1,localhost,root);
+XA START 'x'; UPDATE t1 set a=2; XA END 'x'; XA PREPARE 'x';
+connect (con2,localhost,root);
+CREATE TABLE t2 (a INT) ENGINE=InnoDB;
+XA START 'y'; INSERT INTO t2 VALUES (1); XA END 'y'; XA PREPARE 'y';
+connection default;
+
+# innodb_force_recovery=2 prevents the purge and tests that the fix of
+# MDEV-13606 XA PREPARE transactions should survive innodb_force_recovery=1 or 2
+# is present.
+--let $restart_parameters= --innodb-force-recovery=2
+--let $shutdown_timeout=0
+--source include/restart_mysqld.inc
+--let $restart_parameters=
+--let $shutdown_timeout=
+
+disconnect con1;
+disconnect con2;
+connect (con1,localhost,root);
+--send SELECT * FROM t1 LOCK IN SHARE MODE
+
+connection default;
+let $wait_condition=
+ select count(*) = 1 from information_schema.processlist
+ where state = 'Sending data' and
+ info = 'SELECT * FROM t1 LOCK IN SHARE MODE';
+--source include/wait_condition.inc
+
+SET innodb_lock_wait_timeout=1;
+--error ER_LOCK_WAIT_TIMEOUT
+DROP TABLE t2;
+
+disconnect con1;
+
+SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED;
+--disable_ps2_protocol
+SELECT * FROM t1;
+--enable_ps2_protocol
+XA ROLLBACK 'x';
+SELECT * FROM t1;
+
+DROP TABLE t1;
+--error ER_LOCK_WAIT_TIMEOUT
+DROP TABLE t2;
+XA ROLLBACK 'y';
+DROP TABLE t2;
+
+SET GLOBAL innodb_fast_shutdown=0;
+--source include/restart_mysqld.inc
diff --git a/mysql-test/suite/innodb/t/xa_recovery_debug.test b/mysql-test/suite/innodb/t/xa_recovery_debug.test
new file mode 100644
index 00000000..ada2940e
--- /dev/null
+++ b/mysql-test/suite/innodb/t/xa_recovery_debug.test
@@ -0,0 +1,43 @@
+--source include/have_innodb.inc
+--source include/have_debug.inc
+--source include/have_debug_sync.inc
+# Embedded server does not support restarting
+--source include/not_embedded.inc
+
+--disable_query_log
+FLUSH TABLES;
+--enable_query_log
+
+--echo #
+--echo # Bug#20872655 XA ROLLBACK IS NOT CRASH-SAFE
+--echo #
+
+CREATE TABLE t(a INT PRIMARY KEY, b INT UNIQUE) ENGINE=INNODB;
+INSERT INTO t SET a=0;
+connect (con1,localhost,root);
+XA START 'zombie';
+INSERT INTO t SET a=1;
+UPDATE t SET b=1 WHERE a=1;
+SELECT COUNT(*) FROM t;
+XA END 'zombie';
+XA PREPARE 'zombie';
+SET DEBUG_SYNC='trx_after_rollback_row SIGNAL s1 WAIT_FOR s2';
+--send XA ROLLBACK 'zombie'
+connection default;
+SET DEBUG_SYNC='now WAIT_FOR s1';
+# Ensure that the state change from XA PREPARE to ACTIVE gets flushed
+# to the redo log. Without this, it could be that we will recover to
+# a state that precedes the start of the XA ROLLBACK.
+SET GLOBAL innodb_flush_log_at_trx_commit=1;
+DELETE FROM t LIMIT 1;
+let $shutdown_timeout=0;
+--source include/restart_mysqld.inc
+disconnect con1;
+# If the trx_undo_set_state_at_prepare() is omitted at the start of
+# XA ROLLBACK, then the XA COMMIT would succeed and the table would
+# incorrectly show the result of the INSERT but not the UPDATE,
+# because we would commit a partially rolled back transaction.
+--error ER_XAER_NOTA
+XA COMMIT 'zombie';
+SELECT * FROM t;
+DROP TABLE t;
diff --git a/mysql-test/suite/innodb/t/xap_release_locks_on_dict_stats_table.test b/mysql-test/suite/innodb/t/xap_release_locks_on_dict_stats_table.test
new file mode 100644
index 00000000..a02a032e
--- /dev/null
+++ b/mysql-test/suite/innodb/t/xap_release_locks_on_dict_stats_table.test
@@ -0,0 +1,33 @@
+--source include/have_innodb.inc
+--source include/have_debug.inc
+--source include/have_debug_sync.inc
+
+# Some memory is allocated in dict_stats_save() function for additional sync
+# point. The memory is allocated in current_thd->mem_root pool after
+# dict_stats_func() arranged new thd and freed after destroy_background_thd()
+# attached background thread thd to the current_thd. That's there are
+# different thread id's for memory allocation and deallocation, what causes
+# the following warnings. This is not an error because the memory is still
+# allocated and deallocated by the same thread in pool.
+call mtr.add_suppression("bytes freed by");
+
+SET @old_innodb_stats_persistent = @@innodb_stats_persistent;
+SET GLOBAL innodb_stats_persistent=1;
+CREATE TABLE t ENGINE=InnoDB AS SELECT 1;
+
+SET @old_debug_dbug = @@global.debug_dbug;
+
+XA START 'a';
+INSERT INTO mysql.innodb_index_stats SELECT '','' AS table_name,index_name,LAST_UPDATE,stat_name,0 AS stat_value,sample_size,stat_description FROM mysql.innodb_index_stats WHERE table_name='dummy' FOR UPDATE; # Note the SELECT is empty
+SET GLOBAL debug_dbug = "+d,dict_stats_save_exit_notify";
+INSERT INTO t VALUES (1);
+XA END 'a';
+XA PREPARE 'a';
+
+# Locking queue validation will crash the server if the bug is not fixed
+SET DEBUG_SYNC="now WAIT_FOR dict_stats_save_finished";
+SET @@global.debug_dbug = @old_debug_dbug;
+SET DEBUG_SYNC="RESET";
+SET GLOBAL innodb_stats_persistent = @old_innodb_stats_persistent;
+XA COMMIT 'a';
+DROP TABLE t;