mirror of
https://github.com/MariaDB/server.git
synced 2025-01-20 14:02:32 +01:00
eff3780dd8
Backport of: ------------------------------------------------------------ revno: 2630.4.1 committer: Dmitry Lenev <dlenev@mysql.com> branch nick: mysql-6.0-3726-w timestamp: Fri 2008-05-23 17:54:03 +0400 message: WL#3726 "DDL locking for all metadata objects". After review fixes in progress. ------------------------------------------------------------ This is the first patch in series. It transforms the metadata locking subsystem to use a dedicated module (mdl.h,cc). No significant changes in the locking protocol. The import passes the test suite with the exception of deprecated/removed 6.0 features, and MERGE tables. The latter are subject to a fix by WL#4144. Unfortunately, the original changeset comments got lost in a merge, thus this import has its own (largely insufficient) comments. This patch fixes Bug#25144 "replication / binlog with view breaks". Warning: this patch introduces an incompatible change: Under LOCK TABLES, it's no longer possible to FLUSH a table that was not locked for WRITE. Under LOCK TABLES, it's no longer possible to DROP a table or VIEW that was not locked for WRITE. ****** Backport of: ------------------------------------------------------------ revno: 2630.4.2 committer: Dmitry Lenev <dlenev@mysql.com> branch nick: mysql-6.0-3726-w timestamp: Sat 2008-05-24 14:03:45 +0400 message: WL#3726 "DDL locking for all metadata objects". After review fixes in progress. ****** Backport of: ------------------------------------------------------------ revno: 2630.4.3 committer: Dmitry Lenev <dlenev@mysql.com> branch nick: mysql-6.0-3726-w timestamp: Sat 2008-05-24 14:08:51 +0400 message: WL#3726 "DDL locking for all metadata objects" Fixed failing Windows builds by adding mdl.cc to the lists of files needed to build server/libmysqld on Windows. ****** Backport of: ------------------------------------------------------------ revno: 2630.4.4 committer: Dmitry Lenev <dlenev@mysql.com> branch nick: mysql-6.0-3726-w timestamp: Sat 2008-05-24 21:57:58 +0400 message: WL#3726 "DDL locking for all metadata objects". Fix for assert failures in kill.test which occured when one tried to kill ALTER TABLE statement on merge table while it was waiting in wait_while_table_is_used() for other connections to close this table. These assert failures stemmed from the fact that cleanup code in this case assumed that temporary table representing new version of table was open with adding to THD::temporary_tables list while code which were opening this temporary table wasn't always fulfilling this. This patch changes code that opens new version of table to always do this linking in. It also streamlines cleanup process for cases when error occurs while we have new version of table open. ****** WL#3726 "DDL locking for all metadata objects" Add libmysqld/mdl.cc to .bzrignore. ****** Backport of: ------------------------------------------------------------ revno: 2630.4.6 committer: Dmitry Lenev <dlenev@mysql.com> branch nick: mysql-6.0-3726-w timestamp: Sun 2008-05-25 00:33:22 +0400 message: WL#3726 "DDL locking for all metadata objects". Addition to the fix of assert failures in kill.test caused by changes for this worklog. Make sure we close the new table only once. .bzrignore: Add libmysqld/mdl.cc libmysqld/CMakeLists.txt: Added mdl.cc to the list of files needed for building of libmysqld. libmysqld/Makefile.am: Added files implementing new meta-data locking subsystem to the server. mysql-test/include/handler.inc: Use separate connection for waiting while threads performing DDL operations conflicting with open HANDLER tables reach blocked state. This is required because now we check and close tables open by HANDLER statements in this connection conflicting with DDL in another each time open_tables() is called and thus select from I_S which is used for waiting will unblock DDL operations if issued from connection with open HANDLERs. mysql-test/r/create.result: Adjusted test case after change in implementation of CREATE TABLE ... SELECT. We no longer have special check in open_table() which catches the case when we select from the table created. Instead we rely on unique_table() call which happens after opening and locking all tables. mysql-test/r/flush.result: FLUSH TABLES WITH READ LOCK can no longer happen under LOCK TABLES. Updated test accordingly. mysql-test/r/flush_table.result: Under LOCK TABLES we no longer allow to do FLUSH TABLES for tables locked for read. Updated test accordingly. mysql-test/r/handler_innodb.result: Use separate connection for waiting while threads performing DDL operations conflicting with open HANDLER tables reach blocked state. This is required because now we check and close tables open by HANDLER statements in this connection conflicting with DDL in another each time open_tables() is called and thus select from I_S which is used for waiting will unblock DDL operations if issued from connection with open HANDLERs. mysql-test/r/handler_myisam.result: Use separate connection for waiting while threads performing DDL operations conflicting with open HANDLER tables reach blocked state. This is required because now we check and close tables open by HANDLER statements in this connection conflicting with DDL in another each time open_tables() is called and thus select from I_S which is used for waiting will unblock DDL operations if issued from connection with open HANDLERs. mysql-test/r/information_schema.result: Additional test for WL#3726 "DDL locking for all metadata objects". Check that we use high-priority metadata lock requests when filling I_S tables. Rearrange tests to match 6.0 better (fewer merge conflicts). mysql-test/r/kill.result: Added tests checking that DDL and DML statements waiting for metadata locks can be interrupted by KILL command. mysql-test/r/lock.result: One no longer is allowed to do DROP VIEW under LOCK TABLES even if this view is locked by LOCK TABLES. The problem is that in such situation write locks on view are not mutually exclusive so upgrading metadata lock which is required for dropping of view will lead to deadlock. mysql-test/r/partition_column_prune.result: Update results (same results in 6.0), WL#3726 mysql-test/r/partition_pruning.result: Update results (same results in 6.0), WL#3726 mysql-test/r/ps_ddl.result: We no longer invalidate prepared CREATE TABLE ... SELECT statement if target table changes. This is OK since it is not strictly necessary. The first change is wrong, is caused by FLUSH TABLE now flushing all unused tables. This is a regression that Dmitri fixed in 6.0 in a follow up patch. mysql-test/r/sp.result: Under LOCK TABLES we no longer allow accessing views which were not explicitly locked. To access view we need to obtain metadata lock on it and doing this under LOCK TABLES may lead to deadlocks. mysql-test/r/view.result: One no longer is allowed to do DROP VIEW under LOCK TABLES even if this view is locked by LOCK TABLES. The problem is that in such situation even "write locks" on view are not mutually exclusive so upgrading metadata lock which is required for dropping of view will lead to deadlock mysql-test/r/view_grant.result: ALTER VIEW implementation was changed to open a view only after checking that user which does alter has appropriate privileges on it. This means that in case when user's privileges are insufficient for this we won't check that new view definer is the same as original one or user performing alter has SUPER privilege. Adjusted test case accordingly. mysql-test/r/view_multi.result: Added test case for bug#25144 "replication / binlog with view breaks". mysql-test/suite/rpl/t/disabled.def: Disable test for deprecated features (they don't work with new MDL). mysql-test/t/create.test: Adjusted test case after change in implementation of CREATE TABLE ... SELECT. We no longer have special check in open_table() which catches the case when we select from the table created. Instead we rely on unique_table() call which happens after opening and locking all tables. mysql-test/t/disabled.def: Disable merge.test, subject of WL#4144 mysql-test/t/flush.test: FLUSH TABLES WITH READ LOCK can no longer happen under LOCK TABLES. Updated test accordingly. mysql-test/t/flush_table.test: Under LOCK TABLES we no longer allow to do FLUSH TABLES for tables locked for read. Updated test accordingly. mysql-test/t/information_schema.test: Additional test for WL#3726 "DDL locking for all metadata objects". Check that we use high-priority metadata lock requests when filling I_S tables. Rearrange the results for easier merges with 6.0. mysql-test/t/kill.test: Added tests checking that DDL and DML statements waiting for metadata locks can be interrupted by KILL command. mysql-test/t/lock.test: One no longer is allowed to do DROP VIEW under LOCK TABLES even if this view is locked by LOCK TABLES. The problem is that in such situation write locks on view are not mutually exclusive so upgrading metadata lock which is required for dropping of view will lead to deadlock. mysql-test/t/lock_multi.test: Adjusted test case to the changes of status in various places caused by change in implementation FLUSH TABLES WITH READ LOCK, which is now takes global metadata lock before flushing tables and therefore waits on at these places. mysql-test/t/ps_ddl.test: We no longer invalidate prepared CREATE TABLE ... SELECT statement if target table changes. This is OK since it is not strictly necessary. The first change is wrong, is caused by FLUSH TABLE now flushing all unused tables. This is a regression that Dmitri fixed in 6.0 in a follow up patch. mysql-test/t/sp.test: Under LOCK TABLES we no longer allow accessing views which were not explicitly locked. To access view we need to obtain metadata lock on it and doing this under LOCK TABLES may lead to deadlocks. mysql-test/t/trigger_notembedded.test: Adjusted test case to the changes of status in various places caused by change in implementation FLUSH TABLES WITH READ LOCK, which is now takes global metadata lock before flushing tables and therefore waits on at these places. mysql-test/t/view.test: One no longer is allowed to do DROP VIEW under LOCK TABLES even if this view is locked by LOCK TABLES. The problem is that in such situation even "write locks" on view are not mutually exclusive so upgrading metadata lock which is required for dropping of view will lead to deadlock. mysql-test/t/view_grant.test: ALTER VIEW implementation was changed to open a view only after checking that user which does alter has appropriate privileges on it. This means that in case when user's privileges are insufficient for this we won't check that new view definer is the same as original one or user performing alter has SUPER privilege. Adjusted test case accordingly. mysql-test/t/view_multi.test: Added test case for bug#25144 "replication / binlog with view breaks". sql/CMakeLists.txt: Added mdl.cc to the list of files needed for building of server. sql/Makefile.am: Added files implementing new meta-data locking subsystem to the server. sql/event_db_repository.cc: Allocate metadata lock requests objects (MDL_LOCK) on execution memory root in cases when TABLE_LIST objects is also allocated there or on stack. sql/ha_ndbcluster.cc: Adjusted code to work nicely with new metadata locking subsystem. close_cached_tables() no longer has wait_for_placeholder argument. Instead of relying on this parameter and related behavior FLUSH TABLES WITH READ LOCK now takes global shared metadata lock. sql/ha_ndbcluster_binlog.cc: Adjusted code to work with new metadata locking subsystem. close_cached_tables() no longer has wait_for_placeholder argument. Instead of relying on this parameter and related behavior FLUSH TABLES WITH READ LOCK now takes global shared metadata lock. sql/handler.cc: update_frm_version(): Directly update TABLE_SHARE::mysql_version member instead of going through all TABLE instances for this table (old code was a legacy from pre-table-definition-cache days). sql/lock.cc: Use new metadata locking subsystem. Threw away most of functions related to name locking as now one is supposed to use metadata locking API instead. In lock_global_read_lock() and unlock_global_read_lock() in order to avoid problems with global read lock sneaking in at the moment when we perform FLUSH TABLES or ALTER TABLE under LOCK TABLES and when tables being reopened are protected only by metadata locks we also have to take global shared meta data lock. sql/log_event.cc: Adjusted code to work with new metadata locking subsystem. For tables open by slave thread for applying RBR events allocate memory for lock request object in the same chunk of memory as TABLE_LIST objects for them. In order to ensure that we keep these objects around until tables are open always close tables before calling Relay_log_info::clear_tables_to_lock(). Use new auxiliary Relay_log_info::slave_close_thread_tables() method to enforce this. sql/log_event_old.cc: Adjusted code to work with new metadata locking subsystem. Since for tables open by slave thread for applying RBR events memory for lock request object is allocated in the same chunk of memory as TABLE_LIST objects for them we have to ensure that we keep these objects around until tables are open. To ensure this we always close tables before calling Relay_log_info::clear_tables_to_lock(). To enfore this we use new auxiliary Relay_log_info::slave_close_thread_tables() method. sql/mdl.cc: Implemented new metadata locking subsystem and API described in WL3726 "DDL locking for all metadata objects". sql/mdl.h: Implemented new metadata locking subsystem and API described in WL3726 "DDL locking for all metadata objects". sql/mysql_priv.h: - close_thread_tables()/close_tables_for_reopen() now has one more argument which indicates that metadata locks should be released but not removed from the context in order to be used later in mdl_wait_for_locks() and tdc_wait_for_old_version(). - close_cached_table() routine is no longer public. - Thread waiting in wait_while_table_is_used() can be now killed so this function returns boolean to make caller aware of such situation. - We no longer have table cache as separate entity instead used and unused TABLE instances are linked to TABLE_SHARE objects in table definition cache. - Now third argument of open_table() is also used for requesting table repair or auto-discovery of table's new definition. So its type was changed from bool to enum. - Added tdc_open_view() function for opening view by getting its definition from disk (and table cache in future). - reopen_name_locked_table() no longer needs "link_in" argument as now we have exclusive metadata locks instead of dummy TABLE instances when this function is called. - find_locked_table() now takes head of list of TABLE instances instead of always scanning through THD::open_tables list. Also added find_write_locked_table() auxiliary. - reopen_tables(), close_cached_tables() no longer have mark_share_as_old and wait_for_placeholder arguments. Instead of relying on this parameters and related behavior FLUSH TABLES WITH READ LOCK now takes global shared metadata lock. - We no longer need drop_locked_tables() and abort_locked_tables(). - mysql_ha_rm_tables() now always assume that LOCK_open is not acquired by caller. - Added notify_thread_having_shared_lock() callback invoked by metadata locking subsystem when acquiring an exclusive lock, for each thread that has a conflicting shared metadata lock. - Introduced expel_table_from_cache() as replacement for remove_table_from_cache() (the main difference is that this new function assumes that caller follows metadata locking protocol and never waits). - Threw away most of functions related to name locking. One should use new metadata locking subsystem and API instead. sql/mysqld.cc: Got rid of call initializing/deinitializing table cache since now it is embedded into table definition cache. Added calls for initializing/ deinitializing metadata locking subsystem. sql/rpl_rli.cc: Introduced auxiliary Relay_log_info::slave_close_thread_tables() method which is used for enforcing that we always close tables open for RBR before deallocating TABLE_LIST elements and MDL_LOCK objects for them. sql/rpl_rli.h: Introduced auxiliary Relay_log_info::slave_close_thread_tables() method which is used for enforcing that we always close tables open for RBR before deallocating TABLE_LIST elements and MDL_LOCK objects for them. sql/set_var.cc: close_cached_tables() no longer has wait_for_placeholder argument. Instead of relying on this parameter and related behavior FLUSH TABLES WITH READ LOCK now takes global shared metadata lock. sql/sp_head.cc: For tables added to the statement's table list by prelocking algorithm we allocate these objects either on the same memory as corresponding table list elements or on THD::locked_tables_root (if we are building table list for LOCK TABLES). sql/sql_acl.cc: Allocate metadata lock requests objects (MDL_LOCK) on execution memory root in cases when we use stack TABLE_LIST objects to open tables. Got rid of redundant code by using unlock_locked_tables() function. sql/sql_base.cc: Changed code to use new MDL subsystem. Got rid of separate table cache. Now used and unused TABLE instances are linked to the TABLE_SHAREs in table definition cache. check_unused(): Adjusted code to the fact that we no longer have separate table cache. Removed dead code. table_def_free(): Free TABLE instances referenced from TABLE_SHARE objects before destroying table definition cache. get_table_share(): Added assert which ensures that noone will be able to access table (and its share) without acquiring some kind of metadata lock first. close_handle_and_leave_table_as_lock(): Adjusted code to the fact that TABLE instances now are linked to list in TABLE_SHARE. list_open_tables(): Changed this function to use table definition cache instead of table cache. free_cache_entry(): Unlink freed TABLE elements from the list of all TABLE instances for the table in TABLE_SHARE. kill_delayed_thread_for_table(): Added auxiliary for killing delayed insert threads for particular table. close_cached_tables(): Got rid of wait_for_refresh argument as we now rely on global shared metadata lock to prevent FLUSH WITH READ LOCK sneaking in when we are reopening tables. Heavily reworked this function to use new MDL code and not to rely on separate table cache entity. close_open_tables(): We no longer have separate table cache. close_thread_tables(): Release metadata locks after closing all tables. Added skip_mdl argument which allows us not to remove metadata lock requests from the context in case when we are going to use this requests later in mdl_wait_for_locks() and tdc_wait_for_old_versions(). close_thread_table()/close_table_for_reopen(): Since we no longer have separate table cache and all TABLE instances are linked to TABLE_SHARE objects in table definition cache we have to link/unlink TABLE object to/from appropriate lists in the share. name_lock_locked_table(): Moved redundant code to find_write_locked_table() function and adjusted code to the fact that wait_while_table_is_used() can now return with an error if our thread is killed. reopen_table_entry(): We no longer need "link_in" argument as with MDL we no longer call this function with dummy TABLE object pre-allocated and added to the THD::open_tables. Also now we add newly-open TABLE instance to the list of share's used TABLE instances. table_cache_insert_placeholder(): Got rid of name-locking legacy. lock_table_name_if_not_cached(): Moved to sql_table.cc the only place where it is used. It was also reimplemented using new MDL API. open_table(): - Reworked this function to use new MDL subsystem. - Changed code to deal with table definition cache directly instead of going through separate table cache. - Now third argument is also used for requesting table repair or auto-discovery of table's new definition. So its type was changed from bool to enum. find_locked_table()/find_write_locked_table(): Accept head of list of TABLE objects as first argument and use this list instead of always searching in THD::open_tables list. Also added auxiliary for finding write-locked locked tables. reopen_table(): Adjusted function to work with new MDL subsystem and to properly manuipulate with lists of used/unused TABLE instaces in TABLE_SHARE. reopen_tables(): Removed mark_share_as_old parameter. Instead of relying on it and related behavior FLUSH TABLES WITH READ LOCK now takes global shared metadata lock. Changed code after removing separate table cache. drop_locked_tables()/abort_locked_tables(): Got rid of functions which are no longer needed. unlock_locked_tables(): Moved this function from sql_parse.cc and changed it to release memory which was used for allocating metadata lock requests for tables open and locked by LOCK TABLES. tdc_open_view(): Intoduced function for opening a view by getting its definition from disk (and table cache in future). reopen_table_entry(): Introduced function for opening table definitions while holding exclusive metatadata lock on it. open_unireg_entry(): Got rid of this function. Most of its functionality is relocated to open_table() and open_table_fini() functions, and some of it to reopen_table_entry() and tdc_open_view(). Also code resposible for auto-repair and auto-discovery of tables was moved to separate function. open_table_entry_fini(): Introduced function which contains common actions which finalize process of TABLE object creation. auto_repair_table(): Moved code responsible for auto-repair of table being opened here. handle_failed_open_table_attempt() Moved code responsible for handling failing attempt to open table to one place (retry due to lock conflict/old version, auto-discovery and repair). open_tables(): - Flush open HANDLER tables if they have old version of if there is conflicting metadata lock against them (before this moment we had this code in open_table()). - When we open view which should be processed via derived table on the second execution of prepared statement or stored routine we still should call open_table() for it in order to obtain metadata lock on it and prepare its security context. - In cases when we discover that some special handling of failure to open table is needed call handle_failed_open_table_attempt() which handles all such scenarios. open_ltable(): Handling of various special scenarios of failure to open a table was moved to separate handle_failed_open_table_attempt() function. remove_db_from_cache(): Removed this function as it is no longer used. notify_thread_having_shared_lock(): Added callback which is invoked by MDL subsystem when acquiring an exclusive lock, for each thread that has a conflicting shared metadata lock. expel_table_from_cache(): Introduced function for removing unused TABLE instances. Unlike remove_table_from_cache() it relies on caller following MDL protocol and having appropriate locks when calling it and thus does not do any waiting if table is still in use. tdc_wait_for_old_version(): Added function which allows open_tables() to wait in cases when we discover that we should back-off due to presence of old version of table. abort_and_upgrade_lock(): Use new MDL calls. mysql_wait_completed_table(): Got rid of unused function. open_system_tables_for_read/for_update()/performance_schema_table(): Allocate MDL_LOCK objects on execution memory root in cases when TABLE_LIST objects for corresponding tables is allocated on stack. close_performance_schema_table(): Release metadata locks after closing tables. ****** Use I_P_List for free/used tables list in the table share. sql/sql_binlog.cc: Use Relay_log_info::slave_close_thread_tables() method to enforce that we always close tables open for RBR before deallocating TABLE_LIST elements and MDL_LOCK objects for them. sql/sql_class.cc: Added meta-data locking contexts as part of Open_tables_state context. Also introduced THD::locked_tables_root memory root which is to be used for allocating MDL_LOCK objects for tables in LOCK TABLES statement (end of lifetime for such objects is UNLOCK TABLES so we can't use statement or execution root for them). sql/sql_class.h: Added meta-data locking contexts as part of Open_tables_state context. Also introduced THD::locked_tables_root memory root which is to be used for allocating MDL_LOCK objects for tables in LOCK TABLES statement (end of lifetime for such objects is UNLOCK TABLES so we can't use statement or execution root for them). Note: handler_mdl_context and locked_tables_root and mdl_el_root will be removed by subsequent patches. sql/sql_db.cc: mysql_rm_db() does not really need to call remove_db_from_cache() as it drops each table in the database using mysql_rm_table_part2(), which performs all necessary operations on table (definition) cache. sql/sql_delete.cc: Use the new metadata locking API for TRUNCATE. sql/sql_handler.cc: Changed HANDLER implementation to use new metadata locking subsystem. Note that MDL_LOCK objects for HANDLER tables are allocated in the same chunk of heap memory as TABLE_LIST object for those tables. sql/sql_insert.cc: mysql_insert(): find_locked_table() now takes head of list of TABLE object as its argument instead of always scanning through THD::open_tables list. handle_delayed_insert(): Allocate metadata lock request object for table open by delayed insert thread on execution memroot. create_table_from_items(): We no longer allocate dummy TABLE objects for tables being created if they don't exist. As consequence reopen_name_locked_table() no longer has link_in argument. open_table() now has one more argument which is not relevant for temporary tables. sql/sql_parse.cc: - Moved unlock_locked_tables() routine to sql_base.cc and made available it in other files. Got rid of some redundant code by using this function. - Replaced boolean TABLE_LIST::create member with enum open_table_type member. - Use special memory root for allocating MDL_LOCK objects for tables open and locked by LOCK TABLES (these object should live till UNLOCK TABLES so we can't allocate them on statement nor execution memory root). Also properly set metadata lock upgradability attribure for those tables. - Under LOCK TABLES it is no longer allowed to flush tables which are not write-locked as this breaks metadata locking protocol and thus potentially might lead to deadlock. - Added auxiliary adjust_mdl_locks_upgradability() function. sql/sql_partition.cc: Adjusted code to the fact that reopen_tables() no longer has "mark_share_as_old" argument. Got rid of comments which are no longer true. sql/sql_plist.h: Added I_P_List template class for parametrized intrusive doubly linked lists and I_P_List_iterator for corresponding iterator. Unlike for I_List<> list elements of such list can participate in several lists. Unlike List<> such lists are doubly-linked and intrusive. sql/sql_plugin.cc: Allocate metadata lock requests objects (MDL_LOCK) on execution memory root in cases when we use stack TABLE_LIST objects to open tables. sql/sql_prepare.cc: Replaced boolean TABLE_LIST::create member with enum open_table_type member. This allows easily handle situation in which instead of opening the table we want only to take exclusive metadata lock on it. sql/sql_rename.cc: Use new metadata locking subsystem in implementation of RENAME TABLE. sql/sql_servers.cc: Allocate metadata lock requests objects (MDL_LOCK) on execution memory root in cases when we use stack TABLE_LIST objects to open tables. Got rid of redundant code by using unlock_locked_tables() function. sql/sql_show.cc: Acquire shared metadata lock when we are getting information for I_S table directly from TABLE_SHARE without doing full-blown table open. We use high priority lock request in this situation in order to avoid deadlocks. Also allocate metadata lock requests objects (MDL_LOCK) on execution memory root in cases when TABLE_LIST objects are also allocated there sql/sql_table.cc: mysql_rm_table(): Removed comment which is no longer relevant. mysql_rm_table_part2(): Now caller of mysql_ha_rm_tables() should not own LOCK_open. Adjusted code to use new metadata locking subsystem instead of name-locks. lock_table_name_if_not_cached(): Moved this function from sql_base.cc to this file and reimplemented it using metadata locking API. mysql_create_table(): Adjusted code to use new MDL API. wait_while_table_is_used(): Changed function to use new MDL subsystem. Made thread waiting in it killable (this also led to introduction of return value so caller can distinguish successful executions from situations when waiting was aborted). close_cached_tables(): Thread waiting in this function is killable now. As result it has return value for distinguishing between succes and failure. Got rid of redundant boradcast_refresh() call. prepare_for_repair(): Use MDL subsystem instead of name-locks. mysql_admin_table(): mysql_ha_rm_tables() now always assumes that caller doesn't own LOCK_open. mysql_repair_table(): We should mark all elements of table list as requiring upgradable metadata locks. mysql_create_table_like(): Use new MDL subsystem instead of name-locks. create_temporary_tables(): We don't need to obtain metadata locks when creating temporary table. mysql_fast_or_online_alter_table(): Thread waiting in wait_while_table_is_used() is now killable. mysql_alter_table(): Adjusted code to work with new MDL subsystem and to the fact that threads waiting in what_while_table_is_used() and close_cached_table() are now killable. sql/sql_test.cc: We no longer have separate table cache. TABLE instances are now associated with/linked to TABLE_SHARE objects in table definition cache. sql/sql_trigger.cc: Adjusted code to work with new metadata locking subsystem. Also reopen_tables() no longer has mark_share_as_old argument (Instead of relying on this parameter and related behavior FLUSH TABLES WITH READ LOCK now takes global shared metadata lock). sql/sql_udf.cc: Allocate metadata lock requests objects (MDL_LOCK) on execution memory root in cases when we use stack TABLE_LIST objects to open tables. sql/sql_update.cc: Adjusted code to work with new meta-data locking subsystem. sql/sql_view.cc: Added proper meta-data locking to implementations of CREATE/ALTER/DROP VIEW statements. Now we obtain exclusive meta-data lock on a view before creating/ changing/dropping it. This ensures that all concurrent statements that use this view will finish before our statement will proceed and therefore we will get correct order of statements in the binary log. Also ensure that TABLE_LIST::mdl_upgradable attribute is properly propagated for underlying tables of view. sql/table.cc: Added auxiliary alloc_mdl_locks() function for allocating metadata lock request objects for all elements of table list. sql/table.h: TABLE_SHARE: Got rid of unused members. Introduced members for storing lists of used and unused TABLE objects for this share. TABLE: Added members for linking TABLE objects into per-share lists of used and unused TABLE instances. Added member for holding pointer to metadata lock for this table. TABLE_LIST: Replaced boolean TABLE_LIST::create member with enum open_table_type member. This allows easily handle situation in which instead of opening the table we want only to take exclusive meta-data lock on it (we need this in order to handle ALTER VIEW and CREATE VIEW statements). Introduced new mdl_upgradable member for marking elements of table list for which we need to take upgradable shared metadata lock instead of plain shared metadata lock. Added pointer for holding pointer to MDL_LOCK for the table. Added auxiliary alloc_mdl_locks() function for allocating metadata lock requests objects for all elements of table list. Added auxiliary set_all_mdl_upgradable() function for marking all elements in table list as requiring upgradable metadata locks. storage/myisammrg/ha_myisammrg.cc: Allocate MDL_LOCK objects for underlying tables of MERGE table. To be reworked once Ingo pushes his patch for WL4144.
1504 lines
46 KiB
Text
1504 lines
46 KiB
Text
# This test uses grants, which can't get tested for embedded server
|
|
-- source include/not_embedded.inc
|
|
|
|
# check that CSV engine was compiled in, as the result of the test depends
|
|
# on the presence of the log tables (which are CSV-based).
|
|
--source include/have_csv.inc
|
|
|
|
# Save the initial number of concurrent sessions
|
|
--source include/count_sessions.inc
|
|
|
|
|
|
# Test for information_schema.schemata &
|
|
# show databases
|
|
|
|
--disable_warnings
|
|
DROP TABLE IF EXISTS t0,t1,t2,t3,t4,t5;
|
|
DROP VIEW IF EXISTS v1;
|
|
--enable_warnings
|
|
|
|
|
|
show variables where variable_name like "skip_show_database";
|
|
grant select, update, execute on test.* to mysqltest_2@localhost;
|
|
grant select, update on test.* to mysqltest_1@localhost;
|
|
create user mysqltest_3@localhost;
|
|
create user mysqltest_3;
|
|
|
|
|
|
select * from information_schema.SCHEMATA where schema_name > 'm';
|
|
select schema_name from information_schema.schemata;
|
|
show databases like 't%';
|
|
show databases;
|
|
show databases where `database` = 't%';
|
|
|
|
# Test for information_schema.tables &
|
|
# show tables
|
|
|
|
create database mysqltest;
|
|
create table mysqltest.t1(a int, b VARCHAR(30), KEY string_data (b));
|
|
create table test.t2(a int);
|
|
create table t3(a int, KEY a_data (a));
|
|
create table mysqltest.t4(a int);
|
|
create table t5 (id int auto_increment primary key);
|
|
insert into t5 values (10);
|
|
create view v1 (c) as
|
|
SELECT table_name FROM information_schema.TABLES
|
|
WHERE table_schema IN ('mysql', 'INFORMATION_SCHEMA', 'test', 'mysqltest') AND
|
|
table_name not like 'ndb_%' AND table_name not like 'innodb_%';
|
|
select * from v1;
|
|
|
|
select c,table_name from v1
|
|
inner join information_schema.TABLES v2 on (v1.c=v2.table_name)
|
|
where v1.c like "t%";
|
|
|
|
select c,table_name from v1
|
|
left join information_schema.TABLES v2 on (v1.c=v2.table_name)
|
|
where v1.c like "t%";
|
|
|
|
select c, v2.table_name from v1
|
|
right join information_schema.TABLES v2 on (v1.c=v2.table_name)
|
|
where v1.c like "t%";
|
|
|
|
select table_name from information_schema.TABLES
|
|
where table_schema = "mysqltest" and table_name like "t%";
|
|
|
|
select * from information_schema.STATISTICS where TABLE_SCHEMA = "mysqltest";
|
|
show keys from t3 where Key_name = "a_data";
|
|
|
|
show tables like 't%';
|
|
--replace_column 8 # 12 # 13 #
|
|
show table status;
|
|
show full columns from t3 like "a%";
|
|
show full columns from mysql.db like "Insert%";
|
|
show full columns from v1;
|
|
select * from information_schema.COLUMNS where table_name="t1"
|
|
and column_name= "a";
|
|
show columns from mysqltest.t1 where field like "%a%";
|
|
|
|
create view mysqltest.v1 (c) as select a from mysqltest.t1;
|
|
grant select (a) on mysqltest.t1 to mysqltest_2@localhost;
|
|
grant select on mysqltest.v1 to mysqltest_3;
|
|
connect (user3,localhost,mysqltest_2,,);
|
|
connection user3;
|
|
select table_name, column_name, privileges from information_schema.columns
|
|
where table_schema = 'mysqltest' and table_name = 't1';
|
|
show columns from mysqltest.t1;
|
|
connect (user4,localhost,mysqltest_3,,mysqltest);
|
|
connection user4;
|
|
select table_name, column_name, privileges from information_schema.columns
|
|
where table_schema = 'mysqltest' and table_name = 'v1';
|
|
--error ER_VIEW_NO_EXPLAIN
|
|
explain select * from v1;
|
|
connection default;
|
|
disconnect user4;
|
|
|
|
drop view v1, mysqltest.v1;
|
|
drop tables mysqltest.t4, mysqltest.t1, t2, t3, t5;
|
|
drop database mysqltest;
|
|
|
|
# Test for information_schema.CHARACTER_SETS &
|
|
# SHOW CHARACTER SET
|
|
|
|
select * from information_schema.CHARACTER_SETS
|
|
where CHARACTER_SET_NAME like 'latin1%';
|
|
SHOW CHARACTER SET LIKE 'latin1%';
|
|
SHOW CHARACTER SET WHERE charset like 'latin1%';
|
|
|
|
# Test for information_schema.COLLATIONS &
|
|
# SHOW COLLATION
|
|
|
|
--replace_column 5 #
|
|
select * from information_schema.COLLATIONS
|
|
where COLLATION_NAME like 'latin1%';
|
|
--replace_column 5 #
|
|
SHOW COLLATION LIKE 'latin1%';
|
|
--replace_column 5 #
|
|
SHOW COLLATION WHERE collation like 'latin1%';
|
|
|
|
select * from information_schema.COLLATION_CHARACTER_SET_APPLICABILITY
|
|
where COLLATION_NAME like 'latin1%';
|
|
|
|
# Test for information_schema.ROUTINES &
|
|
#
|
|
|
|
--disable_warnings
|
|
drop procedure if exists sel2;
|
|
drop function if exists sub1;
|
|
drop function if exists sub2;
|
|
--enable_warnings
|
|
|
|
create function sub1(i int) returns int
|
|
return i+1;
|
|
delimiter |;
|
|
create procedure sel2()
|
|
begin
|
|
select * from t1;
|
|
select * from t2;
|
|
end|
|
|
delimiter ;|
|
|
|
|
#
|
|
# Bug#7222 information_schema: errors in "routines"
|
|
#
|
|
select parameter_style, sql_data_access, dtd_identifier
|
|
from information_schema.routines where routine_schema='test';
|
|
|
|
--replace_column 5 # 6 #
|
|
show procedure status where db='test';
|
|
--replace_column 5 # 6 #
|
|
show function status where db='test';
|
|
select a.ROUTINE_NAME from information_schema.ROUTINES a,
|
|
information_schema.SCHEMATA b where
|
|
a.ROUTINE_SCHEMA = b.SCHEMA_NAME AND b.SCHEMA_NAME='test';
|
|
--replace_column 3 #
|
|
explain select a.ROUTINE_NAME from information_schema.ROUTINES a,
|
|
information_schema.SCHEMATA b where
|
|
a.ROUTINE_SCHEMA = b.SCHEMA_NAME;
|
|
|
|
select a.ROUTINE_NAME, b.name from information_schema.ROUTINES a,
|
|
mysql.proc b where a.ROUTINE_NAME = convert(b.name using utf8) AND a.ROUTINE_SCHEMA='test' order by 1;
|
|
select count(*) from information_schema.ROUTINES where routine_schema='test';
|
|
|
|
create view v1 as select routine_schema, routine_name from information_schema.routines where routine_schema='test'
|
|
order by routine_schema, routine_name;
|
|
select * from v1;
|
|
drop view v1;
|
|
|
|
connect (user1,localhost,mysqltest_1,,);
|
|
connection user1;
|
|
select ROUTINE_NAME, ROUTINE_DEFINITION from information_schema.ROUTINES;
|
|
--error ER_SP_DOES_NOT_EXIST
|
|
show create function sub1;
|
|
connection user3;
|
|
select ROUTINE_NAME, ROUTINE_DEFINITION from information_schema.ROUTINES;
|
|
connection default;
|
|
grant all privileges on test.* to mysqltest_1@localhost;
|
|
connect (user2,localhost,mysqltest_1,,);
|
|
connection user2;
|
|
select ROUTINE_NAME, ROUTINE_DEFINITION from information_schema.ROUTINES;
|
|
create function sub2(i int) returns int
|
|
return i+1;
|
|
select ROUTINE_NAME, ROUTINE_DEFINITION from information_schema.ROUTINES;
|
|
show create procedure sel2;
|
|
show create function sub1;
|
|
show create function sub2;
|
|
--replace_column 5 # 6 #
|
|
show function status like "sub2";
|
|
connection default;
|
|
disconnect user1;
|
|
disconnect user3;
|
|
drop function sub2;
|
|
show create procedure sel2;
|
|
|
|
#
|
|
# Test for views
|
|
#
|
|
create view v0 (c) as select schema_name from information_schema.schemata;
|
|
select * from v0;
|
|
--replace_column 3 #
|
|
explain select * from v0;
|
|
create view v1 (c) as select table_name from information_schema.tables
|
|
where table_name="v1";
|
|
select * from v1;
|
|
create view v2 (c) as select column_name from information_schema.columns
|
|
where table_name="v2";
|
|
select * from v2;
|
|
create view v3 (c) as select CHARACTER_SET_NAME from information_schema.character_sets
|
|
where CHARACTER_SET_NAME like "latin1%";
|
|
select * from v3;
|
|
create view v4 (c) as select COLLATION_NAME from information_schema.collations
|
|
where COLLATION_NAME like "latin1%";
|
|
select * from v4;
|
|
show keys from v4;
|
|
select * from information_schema.views where TABLE_NAME like "v%";
|
|
drop view v0, v1, v2, v3, v4;
|
|
|
|
#
|
|
# Test for privileges tables
|
|
#
|
|
create table t1 (a int);
|
|
grant select,update,insert on t1 to mysqltest_1@localhost;
|
|
grant select (a), update (a),insert(a), references(a) on t1 to mysqltest_1@localhost;
|
|
grant all on test.* to mysqltest_1@localhost with grant option;
|
|
select * from information_schema.USER_PRIVILEGES where grantee like '%mysqltest_1%';
|
|
select * from information_schema.SCHEMA_PRIVILEGES where grantee like '%mysqltest_1%';
|
|
select * from information_schema.TABLE_PRIVILEGES where grantee like '%mysqltest_1%';
|
|
select * from information_schema.COLUMN_PRIVILEGES where grantee like '%mysqltest_1%';
|
|
delete from mysql.user where user like 'mysqltest%';
|
|
delete from mysql.db where user like 'mysqltest%';
|
|
delete from mysql.tables_priv where user like 'mysqltest%';
|
|
delete from mysql.columns_priv where user like 'mysqltest%';
|
|
flush privileges;
|
|
drop table t1;
|
|
|
|
|
|
#
|
|
# Test for KEY_COLUMN_USAGE & TABLE_CONSTRAINTS tables
|
|
#
|
|
|
|
create table t1 (a int null, primary key(a));
|
|
alter table t1 add constraint constraint_1 unique (a);
|
|
alter table t1 add constraint unique key_1(a);
|
|
alter table t1 add constraint constraint_2 unique key_2(a);
|
|
show create table t1;
|
|
select * from information_schema.TABLE_CONSTRAINTS where
|
|
TABLE_SCHEMA= "test";
|
|
select * from information_schema.KEY_COLUMN_USAGE where
|
|
TABLE_SCHEMA= "test";
|
|
|
|
connection user2;
|
|
select table_name from information_schema.TABLES where table_schema like "test%";
|
|
select table_name,column_name from information_schema.COLUMNS where table_schema like "test%";
|
|
select ROUTINE_NAME from information_schema.ROUTINES;
|
|
disconnect user2;
|
|
connection default;
|
|
delete from mysql.user where user='mysqltest_1';
|
|
drop table t1;
|
|
drop procedure sel2;
|
|
drop function sub1;
|
|
|
|
create table t1(a int);
|
|
create view v1 (c) as select a from t1 with check option;
|
|
create view v2 (c) as select a from t1 WITH LOCAL CHECK OPTION;
|
|
create view v3 (c) as select a from t1 WITH CASCADED CHECK OPTION;
|
|
select * from information_schema.views;
|
|
grant select (a) on test.t1 to joe@localhost with grant option;
|
|
select * from INFORMATION_SCHEMA.COLUMN_PRIVILEGES;
|
|
select * from INFORMATION_SCHEMA.TABLE_PRIVILEGES;
|
|
drop view v1, v2, v3;
|
|
drop table t1;
|
|
delete from mysql.user where user='joe';
|
|
delete from mysql.db where user='joe';
|
|
delete from mysql.tables_priv where user='joe';
|
|
delete from mysql.columns_priv where user='joe';
|
|
flush privileges;
|
|
|
|
# QQ This results in NULLs instead of the version numbers when
|
|
# QQ a LOCK TABLES is in effect when selecting from
|
|
# QQ information_schema.tables.
|
|
|
|
--disable_parsing # until bug is fixed
|
|
delimiter //;
|
|
create procedure px5 ()
|
|
begin
|
|
declare v int;
|
|
declare c cursor for select version from
|
|
information_schema.tables where table_schema <> 'information_schema';
|
|
open c;
|
|
fetch c into v;
|
|
select v;
|
|
close c;
|
|
end;//
|
|
|
|
call px5()//
|
|
call px5()//
|
|
delimiter ;//
|
|
select sql_mode from information_schema.ROUTINES;
|
|
drop procedure px5;
|
|
--enable_parsing
|
|
|
|
create table t1 (a int not null auto_increment,b int, primary key (a));
|
|
insert into t1 values (1,1),(NULL,3),(NULL,4);
|
|
select AUTO_INCREMENT from information_schema.tables where table_name = 't1';
|
|
drop table t1;
|
|
|
|
create table t1 (s1 int);
|
|
insert into t1 values (0),(9),(0);
|
|
select s1 from t1 where s1 in (select version from
|
|
information_schema.tables) union select version from
|
|
information_schema.tables;
|
|
drop table t1;
|
|
|
|
SHOW CREATE TABLE INFORMATION_SCHEMA.character_sets;
|
|
set names latin2;
|
|
SHOW CREATE TABLE INFORMATION_SCHEMA.character_sets;
|
|
set names latin1;
|
|
|
|
create table t1 select * from information_schema.CHARACTER_SETS
|
|
where CHARACTER_SET_NAME like "latin1";
|
|
select * from t1;
|
|
alter table t1 default character set utf8;
|
|
show create table t1;
|
|
drop table t1;
|
|
|
|
create view v1 as select * from information_schema.TABLES;
|
|
drop view v1;
|
|
create table t1(a NUMERIC(5,3), b NUMERIC(5,1), c float(5,2),
|
|
d NUMERIC(6,4), e float, f DECIMAL(6,3), g int(11), h DOUBLE(10,3),
|
|
i DOUBLE);
|
|
select COLUMN_NAME,COLUMN_TYPE, CHARACTER_MAXIMUM_LENGTH,
|
|
CHARACTER_OCTET_LENGTH, NUMERIC_PRECISION, NUMERIC_SCALE
|
|
from information_schema.columns where table_name= 't1';
|
|
drop table t1;
|
|
|
|
create table t115 as select table_name, column_name, column_type
|
|
from information_schema.columns where table_name = 'proc';
|
|
select * from t115;
|
|
drop table t115;
|
|
|
|
delimiter //;
|
|
create procedure p108 () begin declare c cursor for select data_type
|
|
from information_schema.columns; open c; open c; end;//
|
|
--error ER_SP_CURSOR_ALREADY_OPEN
|
|
call p108()//
|
|
delimiter ;//
|
|
drop procedure p108;
|
|
|
|
create view v1 as select A1.table_name from information_schema.TABLES A1
|
|
where table_name= "user";
|
|
select * from v1;
|
|
drop view v1;
|
|
|
|
create view vo as select 'a' union select 'a';
|
|
show index from vo;
|
|
select * from information_schema.TABLE_CONSTRAINTS where
|
|
TABLE_NAME= "vo";
|
|
select * from information_schema.KEY_COLUMN_USAGE where
|
|
TABLE_NAME= "vo";
|
|
drop view vo;
|
|
|
|
select TABLE_NAME,TABLE_TYPE,ENGINE
|
|
from information_schema.tables
|
|
where table_schema='information_schema' limit 2;
|
|
show tables from information_schema like "T%";
|
|
|
|
--error ER_DBACCESS_DENIED_ERROR
|
|
create database information_schema;
|
|
use information_schema;
|
|
show full tables like "T%";
|
|
--error ER_DBACCESS_DENIED_ERROR
|
|
create table t1(a int);
|
|
use test;
|
|
show tables;
|
|
use information_schema;
|
|
show tables like "T%";
|
|
|
|
#
|
|
# Bug#7210 information_schema: can't access when table-name = reserved word
|
|
#
|
|
select table_name from tables where table_name='user';
|
|
select column_name, privileges from columns
|
|
where table_name='user' and column_name like '%o%';
|
|
|
|
#
|
|
# Bug#7212 information_schema: "Can't find file" errors if storage engine gone
|
|
# Bug#7211 information_schema: crash if bad view
|
|
#
|
|
use test;
|
|
create function sub1(i int) returns int
|
|
return i+1;
|
|
create table t1(f1 int);
|
|
create view v2 (c) as select f1 from t1;
|
|
create view v3 (c) as select sub1(1);
|
|
create table t4(f1 int, KEY f1_key (f1));
|
|
drop table t1;
|
|
drop function sub1;
|
|
select table_name from information_schema.views
|
|
where table_schema='test';
|
|
select table_name from information_schema.views
|
|
where table_schema='test';
|
|
select column_name from information_schema.columns
|
|
where table_schema='test';
|
|
select index_name from information_schema.statistics where table_schema='test';
|
|
select constraint_name from information_schema.table_constraints
|
|
where table_schema='test';
|
|
show create view v2;
|
|
show create table v3;
|
|
drop view v2;
|
|
drop view v3;
|
|
drop table t4;
|
|
|
|
#
|
|
# Bug#7213 information_schema: redundant non-standard TABLE_NAMES table
|
|
#
|
|
--error ER_UNKNOWN_TABLE
|
|
select * from information_schema.table_names;
|
|
|
|
#
|
|
# Bug#2719 information_schema: errors in "columns"
|
|
#
|
|
select column_type from information_schema.columns
|
|
where table_schema="information_schema" and table_name="COLUMNS" and
|
|
(column_name="character_set_name" or column_name="collation_name");
|
|
|
|
#
|
|
# Bug#2718 information_schema: errors in "tables"
|
|
#
|
|
select TABLE_ROWS from information_schema.tables where
|
|
table_schema="information_schema" and table_name="COLUMNS";
|
|
select table_type from information_schema.tables
|
|
where table_schema="mysql" and table_name="user";
|
|
|
|
# test for 'show open tables ... where'
|
|
show open tables where `table` like "user";
|
|
# test for 'show status ... where'
|
|
show status where variable_name like "%database%";
|
|
# test for 'show variables ... where'
|
|
show variables where variable_name like "skip_show_databas";
|
|
|
|
#
|
|
# Bug#7981 SHOW GLOBAL STATUS crashes server
|
|
#
|
|
# We don't actually care about the value, just that it doesn't crash.
|
|
--replace_column 2 #
|
|
show global status like "Threads_running";
|
|
|
|
#
|
|
# Bug#7915 crash,JOIN VIEW, subquery,
|
|
# SELECT .. FROM INFORMATION_SCHEMA.COLUMNS
|
|
#
|
|
create table t1(f1 int);
|
|
create table t2(f2 int);
|
|
create view v1 as select * from t1, t2;
|
|
set @got_val= (select count(*) from information_schema.columns);
|
|
drop view v1;
|
|
drop table t1, t2;
|
|
|
|
#
|
|
# Bug#7476 crash on SELECT * FROM INFORMATION_SCHEMA.TABLES
|
|
#
|
|
use test;
|
|
CREATE TABLE t_crashme ( f1 BIGINT);
|
|
CREATE VIEW a1 (t_CRASHME) AS SELECT f1 FROM t_crashme GROUP BY f1;
|
|
CREATE VIEW a2 AS SELECT t_CRASHME FROM a1;
|
|
let $tab_count= 65;
|
|
--disable_query_log
|
|
while ($tab_count)
|
|
{
|
|
EVAL CREATE TABLE t_$tab_count (f1 BIGINT);
|
|
dec $tab_count ;
|
|
}
|
|
--disable_result_log
|
|
SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES;
|
|
--enable_result_log
|
|
SELECT count(*) FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA='test';
|
|
let $tab_count= 65;
|
|
while ($tab_count)
|
|
{
|
|
EVAL DROP TABLE t_$tab_count;
|
|
dec $tab_count ;
|
|
}
|
|
--enable_query_log
|
|
drop view a2, a1;
|
|
drop table t_crashme;
|
|
|
|
#
|
|
# Bug#7215 information_schema: columns are longtext instead of varchar
|
|
# Bug#7217 information_schema: columns are varbinary() instead of timestamp
|
|
#
|
|
select table_schema,table_name, column_name from
|
|
information_schema.columns
|
|
where data_type = 'longtext';
|
|
select table_name, column_name, data_type from information_schema.columns
|
|
where data_type = 'datetime' and table_name not like 'innodb_%';
|
|
|
|
#
|
|
# Bug#8164 subquery with INFORMATION_SCHEMA.COLUMNS, 100 % CPU
|
|
#
|
|
SELECT COUNT(*) FROM INFORMATION_SCHEMA.TABLES A
|
|
WHERE NOT EXISTS
|
|
(SELECT * FROM INFORMATION_SCHEMA.COLUMNS B
|
|
WHERE A.TABLE_SCHEMA = B.TABLE_SCHEMA
|
|
AND A.TABLE_NAME = B.TABLE_NAME);
|
|
|
|
#
|
|
# Bug#9344 INFORMATION_SCHEMA, wrong content, numeric columns
|
|
#
|
|
|
|
create table t1
|
|
( x_bigint BIGINT,
|
|
x_integer INTEGER,
|
|
x_smallint SMALLINT,
|
|
x_decimal DECIMAL(5,3),
|
|
x_numeric NUMERIC(5,3),
|
|
x_real REAL,
|
|
x_float FLOAT,
|
|
x_double_precision DOUBLE PRECISION );
|
|
SELECT COLUMN_NAME, CHARACTER_MAXIMUM_LENGTH, CHARACTER_OCTET_LENGTH
|
|
FROM INFORMATION_SCHEMA.COLUMNS
|
|
WHERE TABLE_NAME= 't1';
|
|
drop table t1;
|
|
|
|
#
|
|
# Bug#10261 INFORMATION_SCHEMA.COLUMNS, incomplete result for non root user
|
|
#
|
|
|
|
grant select on test.* to mysqltest_4@localhost;
|
|
connect (user10261,localhost,mysqltest_4,,);
|
|
connection user10261;
|
|
SELECT TABLE_NAME, COLUMN_NAME, PRIVILEGES FROM INFORMATION_SCHEMA.COLUMNS
|
|
where COLUMN_NAME='TABLE_NAME';
|
|
connection default;
|
|
disconnect user10261;
|
|
delete from mysql.user where user='mysqltest_4';
|
|
delete from mysql.db where user='mysqltest_4';
|
|
flush privileges;
|
|
|
|
#
|
|
# Bug#9404 information_schema: Weird error messages
|
|
# with SELECT SUM() ... GROUP BY queries
|
|
#
|
|
SELECT table_schema, count(*) FROM information_schema.TABLES WHERE
|
|
table_schema IN ('mysql', 'INFORMATION_SCHEMA', 'test', 'mysqltest')
|
|
AND table_name not like 'ndb%' AND table_name not like 'innodb_%'
|
|
GROUP BY TABLE_SCHEMA;
|
|
|
|
|
|
|
|
#
|
|
# TRIGGERS table test
|
|
#
|
|
create table t1 (i int, j int);
|
|
|
|
delimiter |;
|
|
create trigger trg1 before insert on t1 for each row
|
|
begin
|
|
if new.j > 10 then
|
|
set new.j := 10;
|
|
end if;
|
|
end|
|
|
create trigger trg2 before update on t1 for each row
|
|
begin
|
|
if old.i % 2 = 0 then
|
|
set new.j := -1;
|
|
end if;
|
|
end|
|
|
create trigger trg3 after update on t1 for each row
|
|
begin
|
|
if new.j = -1 then
|
|
set @fired:= "Yes";
|
|
end if;
|
|
end|
|
|
delimiter ;|
|
|
show triggers;
|
|
select * from information_schema.triggers where trigger_schema in ('mysql', 'information_schema', 'test', 'mysqltest');
|
|
|
|
drop trigger trg1;
|
|
drop trigger trg2;
|
|
drop trigger trg3;
|
|
drop table t1;
|
|
|
|
|
|
#
|
|
# Bug#10964 Information Schema:Authorization check on privilege tables is improper
|
|
#
|
|
|
|
create database mysqltest;
|
|
create table mysqltest.t1 (f1 int, f2 int);
|
|
create table mysqltest.t2 (f1 int);
|
|
grant select (f1) on mysqltest.t1 to user1@localhost;
|
|
grant select on mysqltest.t2 to user2@localhost;
|
|
grant select on mysqltest.* to user3@localhost;
|
|
grant select on *.* to user4@localhost;
|
|
|
|
connect (con1,localhost,user1,,mysqltest);
|
|
connect (con2,localhost,user2,,mysqltest);
|
|
connect (con3,localhost,user3,,mysqltest);
|
|
connect (con4,localhost,user4,,);
|
|
connection con1;
|
|
select * from information_schema.column_privileges order by grantee;
|
|
select * from information_schema.table_privileges order by grantee;
|
|
select * from information_schema.schema_privileges order by grantee;
|
|
select * from information_schema.user_privileges order by grantee;
|
|
show grants;
|
|
connection con2;
|
|
select * from information_schema.column_privileges order by grantee;
|
|
select * from information_schema.table_privileges order by grantee;
|
|
select * from information_schema.schema_privileges order by grantee;
|
|
select * from information_schema.user_privileges order by grantee;
|
|
show grants;
|
|
connection con3;
|
|
select * from information_schema.column_privileges order by grantee;
|
|
select * from information_schema.table_privileges order by grantee;
|
|
select * from information_schema.schema_privileges order by grantee;
|
|
select * from information_schema.user_privileges order by grantee;
|
|
show grants;
|
|
connection con4;
|
|
select * from information_schema.column_privileges where grantee like '%user%'
|
|
order by grantee;
|
|
select * from information_schema.table_privileges where grantee like '%user%'
|
|
order by grantee;
|
|
select * from information_schema.schema_privileges where grantee like '%user%'
|
|
order by grantee;
|
|
select * from information_schema.user_privileges where grantee like '%user%'
|
|
order by grantee;
|
|
show grants;
|
|
connection default;
|
|
disconnect con1;
|
|
disconnect con2;
|
|
disconnect con3;
|
|
disconnect con4;
|
|
drop user user1@localhost, user2@localhost, user3@localhost, user4@localhost;
|
|
use test;
|
|
drop database mysqltest;
|
|
|
|
#
|
|
# Bug#11055 information_schema: routines.sql_data_access has wrong value
|
|
#
|
|
--disable_warnings
|
|
drop procedure if exists p1;
|
|
drop procedure if exists p2;
|
|
--enable_warnings
|
|
|
|
create procedure p1 () modifies sql data set @a = 5;
|
|
create procedure p2 () set @a = 5;
|
|
select sql_data_access from information_schema.routines
|
|
where specific_name like 'p%';
|
|
drop procedure p1;
|
|
drop procedure p2;
|
|
|
|
#
|
|
# Bug#9434 SHOW CREATE DATABASE information_schema;
|
|
#
|
|
show create database information_schema;
|
|
|
|
#
|
|
# Bug#11057 information_schema: columns table has some questionable contents
|
|
# Bug#12301 information_schema: NUMERIC_SCALE must be 0 for integer columns
|
|
#
|
|
create table t1(f1 LONGBLOB, f2 LONGTEXT);
|
|
select column_name,data_type,CHARACTER_OCTET_LENGTH,
|
|
CHARACTER_MAXIMUM_LENGTH
|
|
from information_schema.columns
|
|
where table_name='t1';
|
|
drop table t1;
|
|
create table t1(f1 tinyint, f2 SMALLINT, f3 mediumint, f4 int,
|
|
f5 BIGINT, f6 BIT, f7 bit(64));
|
|
select column_name, NUMERIC_PRECISION, NUMERIC_SCALE
|
|
from information_schema.columns
|
|
where table_name='t1';
|
|
drop table t1;
|
|
|
|
#
|
|
# Bug#12127 triggers do not show in info_schema before they are used if set to the database
|
|
#
|
|
create table t1 (f1 integer);
|
|
create trigger tr1 after insert on t1 for each row set @test_var=42;
|
|
use information_schema;
|
|
select trigger_schema, trigger_name from triggers where
|
|
trigger_name='tr1';
|
|
use test;
|
|
drop table t1;
|
|
|
|
#
|
|
# Bug#12518 COLUMN_DEFAULT has wrong value if NOT NULL is set
|
|
#
|
|
create table t1 (a int not null, b int);
|
|
use information_schema;
|
|
select column_name, column_default from columns
|
|
where table_schema='test' and table_name='t1';
|
|
use test;
|
|
show columns from t1;
|
|
drop table t1;
|
|
|
|
#
|
|
# Bug#12636 SHOW TABLE STATUS with where condition containing a subquery
|
|
# over information schema
|
|
#
|
|
|
|
CREATE TABLE t1 (a int);
|
|
CREATE TABLE t2 (b int);
|
|
|
|
--replace_column 8 # 12 # 13 #
|
|
SHOW TABLE STATUS FROM test
|
|
WHERE name IN ( SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES
|
|
WHERE TABLE_SCHEMA='test' AND TABLE_TYPE='BASE TABLE');
|
|
|
|
DROP TABLE t1,t2;
|
|
|
|
#
|
|
# Bug#12905 show fields from view behaving erratically with current database
|
|
#
|
|
create table t1(f1 int);
|
|
create view v1 (c) as select f1 from t1;
|
|
connect (con5,localhost,root,,*NO-ONE*);
|
|
select database();
|
|
show fields from test.v1;
|
|
connection default;
|
|
disconnect con5;
|
|
drop view v1;
|
|
drop table t1;
|
|
|
|
#
|
|
# Bug#9846 Inappropriate error displayed while dropping table from 'INFORMATION_SCHEMA'
|
|
#
|
|
--error ER_PARSE_ERROR
|
|
alter database information_schema;
|
|
--error ER_DBACCESS_DENIED_ERROR
|
|
drop database information_schema;
|
|
--error ER_DBACCESS_DENIED_ERROR
|
|
drop table information_schema.tables;
|
|
--error ER_DBACCESS_DENIED_ERROR
|
|
alter table information_schema.tables;
|
|
#
|
|
# Bug#9683 INFORMATION_SCH: Creation of temporary table allowed in Information_schema DB
|
|
#
|
|
use information_schema;
|
|
--error ER_DBACCESS_DENIED_ERROR
|
|
create temporary table schemata(f1 char(10));
|
|
#
|
|
# Bug#10708 SP's can use INFORMATION_SCHEMA as ROUTINE_SCHEMA
|
|
#
|
|
delimiter |;
|
|
--error ER_BAD_DB_ERROR
|
|
CREATE PROCEDURE p1 ()
|
|
BEGIN
|
|
SELECT 'foo' FROM DUAL;
|
|
END |
|
|
delimiter ;|
|
|
select ROUTINE_NAME from routines where ROUTINE_SCHEMA='information_schema';
|
|
#
|
|
# Bug#10734 Grant of privileges other than 'select' and 'create view' should fail on schema
|
|
#
|
|
--error ER_DBACCESS_DENIED_ERROR
|
|
grant all on information_schema.* to 'user1'@'localhost';
|
|
--error ER_DBACCESS_DENIED_ERROR
|
|
grant select on information_schema.* to 'user1'@'localhost';
|
|
|
|
#
|
|
# Bug#14089 FROM list subquery always fails when information_schema is current database
|
|
#
|
|
use test;
|
|
create table t1(id int);
|
|
insert into t1(id) values (1);
|
|
select 1 from (select 1 from test.t1) a;
|
|
use information_schema;
|
|
select 1 from (select 1 from test.t1) a;
|
|
use test;
|
|
drop table t1;
|
|
|
|
#
|
|
# Bug#14476 `information_schema`.`TABLES`.`TABLE_TYPE` with empty value
|
|
#
|
|
create table t1 (f1 int(11));
|
|
create view v1 as select * from t1;
|
|
drop table t1;
|
|
select table_type from information_schema.tables
|
|
where table_name="v1";
|
|
drop view v1;
|
|
|
|
#
|
|
# Bug#14387 SHOW COLUMNS doesn't work on temporary tables
|
|
# Bug#15224 SHOW INDEX from temporary table doesn't work
|
|
# Bug#12770 DESC cannot display the info. about temporary table
|
|
#
|
|
create temporary table t1(f1 int, index(f1));
|
|
show columns from t1;
|
|
describe t1;
|
|
show indexes from t1;
|
|
drop table t1;
|
|
|
|
#
|
|
# Bug#14271 I_S: columns has no size for (var)binary columns
|
|
#
|
|
create table t1(f1 binary(32), f2 varbinary(64));
|
|
select character_maximum_length, character_octet_length
|
|
from information_schema.columns where table_name='t1';
|
|
drop table t1;
|
|
|
|
#
|
|
# Bug#15533 crash, information_schema, function, view
|
|
#
|
|
CREATE TABLE t1 (f1 BIGINT, f2 VARCHAR(20), f3 BIGINT);
|
|
INSERT INTO t1 SET f1 = 1, f2 = 'Schoenenbourg', f3 = 1;
|
|
|
|
CREATE FUNCTION func2() RETURNS BIGINT RETURN 1;
|
|
|
|
delimiter //;
|
|
CREATE FUNCTION func1() RETURNS BIGINT
|
|
BEGIN
|
|
RETURN ( SELECT COUNT(*) FROM INFORMATION_SCHEMA.VIEWS);
|
|
END//
|
|
delimiter ;//
|
|
|
|
CREATE VIEW v1 AS SELECT 1 FROM t1
|
|
WHERE f3 = (SELECT func2 ());
|
|
SELECT func1();
|
|
DROP TABLE t1;
|
|
DROP VIEW v1;
|
|
DROP FUNCTION func1;
|
|
DROP FUNCTION func2;
|
|
|
|
|
|
#
|
|
# Bug#15307 GROUP_CONCAT() with ORDER BY returns empty set on information_schema
|
|
#
|
|
select column_type, group_concat(table_schema, '.', table_name), count(*) as num
|
|
from information_schema.columns where
|
|
table_schema='information_schema' and
|
|
(column_type = 'varchar(7)' or column_type = 'varchar(20)'
|
|
or column_type = 'varchar(27)')
|
|
group by column_type order by num;
|
|
|
|
#
|
|
# Bug#19236 bad COLUMNS.CHARACTER_MAXIMUM_LENGHT and CHARACTER_OCTET_LENGTH
|
|
#
|
|
create table t1(f1 char(1) not null, f2 char(9) not null)
|
|
default character set utf8;
|
|
select CHARACTER_MAXIMUM_LENGTH, CHARACTER_OCTET_LENGTH from
|
|
information_schema.columns where table_schema='test' and table_name = 't1';
|
|
drop table t1;
|
|
|
|
#
|
|
# Bug#18177 any access to INFORMATION_SCHEMA.ROUTINES crashes
|
|
#
|
|
use mysql;
|
|
INSERT INTO `proc` VALUES ('test','','PROCEDURE','','SQL','CONTAINS_SQL',
|
|
'NO','DEFINER','','','BEGIN\r\n \r\nEND','root@%','2006-03-02 18:40:03',
|
|
'2006-03-02 18:40:03','','','utf8','utf8_general_ci','utf8_general_ci','n/a');
|
|
select routine_name from information_schema.routines where ROUTINE_SCHEMA='test';
|
|
delete from proc where name='';
|
|
use test;
|
|
|
|
#
|
|
# Bug#16681 information_schema shows forbidden VIEW details
|
|
#
|
|
grant select on test.* to mysqltest_1@localhost;
|
|
create table t1 (id int);
|
|
create view v1 as select * from t1;
|
|
create definer = mysqltest_1@localhost
|
|
sql security definer view v2 as select 1;
|
|
|
|
connect (con16681,localhost,mysqltest_1,,test);
|
|
connection con16681;
|
|
|
|
select * from information_schema.views
|
|
where table_name='v1' or table_name='v2';
|
|
connection default;
|
|
disconnect con16681;
|
|
drop view v1, v2;
|
|
drop table t1;
|
|
drop user mysqltest_1@localhost;
|
|
|
|
#
|
|
# Bug#19599 duplication of information_schema column value in a CONCAT expr with user var
|
|
#
|
|
set @a:= '.';
|
|
create table t1(f1 char(5));
|
|
create table t2(f1 char(5));
|
|
select concat(@a, table_name), @a, table_name
|
|
from information_schema.tables where table_schema = 'test';
|
|
drop table t1,t2;
|
|
|
|
|
|
#
|
|
# Bug#20230 routine_definition is not null
|
|
#
|
|
--disable_warnings
|
|
DROP PROCEDURE IF EXISTS p1;
|
|
DROP FUNCTION IF EXISTS f1;
|
|
--enable_warnings
|
|
|
|
CREATE PROCEDURE p1() SET @a= 1;
|
|
CREATE FUNCTION f1() RETURNS INT RETURN @a + 1;
|
|
CREATE USER mysql_bug20230@localhost;
|
|
GRANT EXECUTE ON PROCEDURE p1 TO mysql_bug20230@localhost;
|
|
GRANT EXECUTE ON FUNCTION f1 TO mysql_bug20230@localhost;
|
|
|
|
SELECT ROUTINE_NAME, ROUTINE_DEFINITION FROM INFORMATION_SCHEMA.ROUTINES WHERE ROUTINE_SCHEMA='test';
|
|
SHOW CREATE PROCEDURE p1;
|
|
SHOW CREATE FUNCTION f1;
|
|
|
|
connect (conn1, localhost, mysql_bug20230,,);
|
|
|
|
SELECT ROUTINE_NAME, ROUTINE_DEFINITION FROM INFORMATION_SCHEMA.ROUTINES WHERE ROUTINE_SCHEMA='test';
|
|
SHOW CREATE PROCEDURE p1;
|
|
SHOW CREATE FUNCTION f1;
|
|
CALL p1();
|
|
SELECT f1();
|
|
|
|
disconnect conn1;
|
|
connection default;
|
|
|
|
DROP FUNCTION f1;
|
|
DROP PROCEDURE p1;
|
|
DROP USER mysql_bug20230@localhost;
|
|
|
|
#
|
|
# Bug#21231 query with a simple non-correlated subquery over
|
|
# INFORMARTION_SCHEMA.TABLES
|
|
#
|
|
|
|
SELECT MAX(table_name) FROM information_schema.tables WHERE table_schema IN ('mysql', 'INFORMATION_SCHEMA', 'test');
|
|
SELECT table_name from information_schema.tables
|
|
WHERE table_name=(SELECT MAX(table_name)
|
|
FROM information_schema.tables WHERE table_schema IN ('mysql', 'INFORMATION_SCHEMA', 'test'));
|
|
#
|
|
# Bug#23037 Bug in field "Default" of query "SHOW COLUMNS FROM table"
|
|
#
|
|
# Note, MyISAM/InnoDB can't take more that 65532 chars, because the row
|
|
# size is limited to 65535 bytes (BLOBs not counted)
|
|
#
|
|
--disable_warnings
|
|
DROP TABLE IF EXISTS bug23037;
|
|
DROP FUNCTION IF EXISTS get_value;
|
|
--enable_warnings
|
|
--disable_query_log
|
|
DELIMITER |;
|
|
CREATE FUNCTION get_value()
|
|
RETURNS TEXT
|
|
DETERMINISTIC
|
|
BEGIN
|
|
DECLARE col1, col2, col3, col4, col6 CHAR(255);
|
|
DECLARE default_val VARCHAR(65532);
|
|
DECLARE done INT DEFAULT 0;
|
|
DECLARE cur1 CURSOR FOR SELECT COLUMN_NAME, COLUMN_TYPE, IS_NULLABLE, COLUMN_KEY, COLUMN_DEFAULT, EXTRA FROM INFORMATION_SCHEMA.COLUMNS where TABLE_NAME='bug23037';
|
|
DECLARE CONTINUE HANDLER FOR SQLSTATE '02000' SET done = 1;
|
|
OPEN cur1;
|
|
FETCH cur1 INTO col1, col2, col3, col4, default_val, col6;
|
|
CLOSE cur1;
|
|
RETURN default_val;
|
|
end|
|
|
DELIMITER ;|
|
|
|
|
let $body=`SELECT REPEAT('A', 65532)`;
|
|
eval CREATE TABLE bug23037(fld1 VARCHAR(65532) CHARACTER SET latin1 DEFAULT "$body");
|
|
--enable_query_log
|
|
|
|
SELECT COLUMN_NAME, MD5(COLUMN_DEFAULT), LENGTH(COLUMN_DEFAULT) FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME='bug23037';
|
|
|
|
SELECT MD5(get_value());
|
|
|
|
SELECT COLUMN_NAME, MD5(COLUMN_DEFAULT), LENGTH(COLUMN_DEFAULT), COLUMN_DEFAULT=get_value() FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME='bug23037';
|
|
|
|
DROP TABLE bug23037;
|
|
DROP FUNCTION get_value;
|
|
|
|
#
|
|
# Bug#22413 EXPLAIN SELECT FROM view with ORDER BY yield server crash
|
|
#
|
|
create view v1 as
|
|
select table_schema as object_schema,
|
|
table_name as object_name,
|
|
table_type as object_type
|
|
from information_schema.tables
|
|
order by object_schema;
|
|
explain select * from v1;
|
|
explain select * from (select table_name from information_schema.tables) as a;
|
|
drop view v1;
|
|
|
|
#
|
|
# Bug#23299 Some queries against INFORMATION_SCHEMA with subqueries fail
|
|
#
|
|
create table t1 (f1 int(11));
|
|
create table t2 (f1 int(11), f2 int(11));
|
|
|
|
select table_name from information_schema.tables
|
|
where table_schema = 'test' and table_name not in
|
|
(select table_name from information_schema.columns
|
|
where table_schema = 'test' and column_name = 'f3');
|
|
drop table t1,t2;
|
|
|
|
|
|
#
|
|
# Bug#24630 Subselect query crashes mysqld
|
|
#
|
|
select 1 as f1 from information_schema.tables where "CHARACTER_SETS"=
|
|
(select cast(table_name as char) from information_schema.tables
|
|
order by table_name limit 1) limit 1;
|
|
|
|
select t.table_name, group_concat(t.table_schema, '.', t.table_name),
|
|
count(*) as num1
|
|
from information_schema.tables t
|
|
inner join information_schema.columns c1
|
|
on t.table_schema = c1.table_schema AND t.table_name = c1.table_name
|
|
where t.table_schema = 'information_schema' and
|
|
c1.ordinal_position =
|
|
(select isnull(c2.column_type) -
|
|
isnull(group_concat(c2.table_schema, '.', c2.table_name)) +
|
|
count(*) as num
|
|
from information_schema.columns c2 where
|
|
c2.table_schema='information_schema' and
|
|
(c2.column_type = 'varchar(7)' or c2.column_type = 'varchar(20)')
|
|
group by c2.column_type order by num limit 1)
|
|
and t.table_name not like 'innodb_%'
|
|
group by t.table_name order by num1, t.table_name;
|
|
|
|
#
|
|
# Bug#28266 IS_UPDATABLE field on VIEWS table in I_S database is wrong
|
|
#
|
|
create table t1(f1 int);
|
|
create view v1 as select f1+1 as a from t1;
|
|
create table t2 (f1 int, f2 int);
|
|
create view v2 as select f1+1 as a, f2 as b from t2;
|
|
select table_name, is_updatable from information_schema.views;
|
|
#
|
|
# Note: we can perform 'delete' for non updatable view.
|
|
#
|
|
delete from v1;
|
|
drop view v1,v2;
|
|
drop table t1,t2;
|
|
|
|
#
|
|
# Bug#25859 ALTER DATABASE works w/o parameters
|
|
#
|
|
--error ER_PARSE_ERROR
|
|
alter database;
|
|
--error ER_PARSE_ERROR
|
|
alter database test;
|
|
|
|
#
|
|
# Bug#27629 Possible security flaw in INFORMATION_SCHEMA and SHOW statements
|
|
#
|
|
|
|
create database mysqltest;
|
|
create table mysqltest.t1(a int, b int, c int);
|
|
create trigger mysqltest.t1_ai after insert on mysqltest.t1
|
|
for each row set @a = new.a + new.b + new.c;
|
|
grant select(b) on mysqltest.t1 to mysqltest_1@localhost;
|
|
|
|
select trigger_name from information_schema.triggers
|
|
where event_object_table='t1';
|
|
show triggers from mysqltest;
|
|
|
|
connect (con27629,localhost,mysqltest_1,,mysqltest);
|
|
show columns from t1;
|
|
select column_name from information_schema.columns where table_name='t1';
|
|
|
|
show triggers;
|
|
select trigger_name from information_schema.triggers
|
|
where event_object_table='t1';
|
|
connection default;
|
|
disconnect con27629;
|
|
drop user mysqltest_1@localhost;
|
|
drop database mysqltest;
|
|
|
|
#
|
|
# Bug#27747 database metadata doesn't return sufficient column default info
|
|
#
|
|
create table t1 (
|
|
f1 varchar(50),
|
|
f2 varchar(50) not null,
|
|
f3 varchar(50) default '',
|
|
f4 varchar(50) default NULL,
|
|
f5 bigint not null,
|
|
f6 bigint not null default 10,
|
|
f7 datetime not null,
|
|
f8 datetime default '2006-01-01'
|
|
);
|
|
select column_default from information_schema.columns where table_name= 't1';
|
|
show columns from t1;
|
|
drop table t1;
|
|
|
|
#
|
|
# Bug#30079 A check for "hidden" I_S tables is flawed
|
|
#
|
|
--error ER_UNKNOWN_TABLE
|
|
show fields from information_schema.table_names;
|
|
--error ER_UNKNOWN_TABLE
|
|
show keys from information_schema.table_names;
|
|
|
|
#
|
|
# Bug#34529 Crash on complex Falcon I_S select after ALTER .. PARTITION BY
|
|
#
|
|
USE information_schema;
|
|
SET max_heap_table_size = 16384;
|
|
|
|
CREATE TABLE test.t1( a INT );
|
|
|
|
# What we need to create here is a bit of a corner case:
|
|
# We need a star query with information_schema tables, where the first
|
|
# branch of the star join produces zero rows, so that reading of the
|
|
# second branch never happens. At the same time we have to make sure
|
|
# that data for at least the last table is swapped from MEMORY/HEAP to
|
|
# MyISAM. This and only this triggers the bug.
|
|
SELECT *
|
|
FROM tables ta
|
|
JOIN collations co ON ( co.collation_name = ta.table_catalog )
|
|
JOIN character_sets cs ON ( cs.character_set_name = ta.table_catalog );
|
|
|
|
DROP TABLE test.t1;
|
|
SET max_heap_table_size = DEFAULT;
|
|
USE test;
|
|
|
|
--echo End of 5.0 tests.
|
|
|
|
#
|
|
# Show engines
|
|
#
|
|
|
|
select * from information_schema.engines WHERE ENGINE="MyISAM";
|
|
|
|
#
|
|
# INFORMATION_SCHEMA.PROCESSLIST
|
|
#
|
|
|
|
grant select on *.* to user3148@localhost;
|
|
connect (con3148,localhost,user3148,,test);
|
|
connection con3148;
|
|
select user,db from information_schema.processlist;
|
|
connection default;
|
|
disconnect con3148;
|
|
drop user user3148@localhost;
|
|
|
|
#
|
|
# Bug#26174 Server Crash: INSERT ... SELECT ... FROM I_S.GLOBAL_STATUS
|
|
# in Event (see also openssl_1.test)
|
|
#
|
|
--disable_warnings
|
|
DROP TABLE IF EXISTS server_status;
|
|
DROP EVENT IF EXISTS event_status;
|
|
--enable_warnings
|
|
|
|
SET GLOBAL event_scheduler=1;
|
|
|
|
DELIMITER $$;
|
|
|
|
CREATE EVENT event_status
|
|
ON SCHEDULE AT NOW()
|
|
ON COMPLETION NOT PRESERVE
|
|
DO
|
|
BEGIN
|
|
CREATE TABLE server_status
|
|
SELECT variable_name
|
|
FROM information_schema.global_status
|
|
WHERE variable_name LIKE 'ABORTED_CONNECTS' OR
|
|
variable_name LIKE 'BINLOG_CACHE_DISK_USE';
|
|
END$$
|
|
|
|
DELIMITER ;$$
|
|
|
|
let $wait_timeout= 300;
|
|
let $wait_condition=select count(*) = 0 from information_schema.events where event_name='event_status';
|
|
--source include/wait_condition.inc
|
|
|
|
SELECT variable_name FROM server_status;
|
|
|
|
DROP TABLE server_status;
|
|
SET GLOBAL event_scheduler=0;
|
|
|
|
|
|
#
|
|
# WL#3732 Information schema optimization
|
|
#
|
|
|
|
explain select table_name from information_schema.views where
|
|
table_schema='test' and table_name='v1';
|
|
|
|
explain select * from information_schema.tables;
|
|
explain select * from information_schema.collations;
|
|
|
|
explain select * from information_schema.tables where
|
|
table_schema='test' and table_name= 't1';
|
|
explain select table_name, table_type from information_schema.tables
|
|
where table_schema='test';
|
|
|
|
explain select b.table_name
|
|
from information_schema.tables a, information_schema.columns b
|
|
where a.table_name='t1' and a.table_schema='test' and b.table_name=a.table_name;
|
|
|
|
#
|
|
# Bug#30310 wrong result on SELECT * FROM INFORMATION_SCHEMA.SCHEMATA WHERE ..
|
|
#
|
|
SELECT * FROM INFORMATION_SCHEMA.SCHEMATA
|
|
WHERE SCHEMA_NAME = 'mysqltest';
|
|
|
|
SELECT * FROM INFORMATION_SCHEMA.SCHEMATA
|
|
WHERE SCHEMA_NAME = '';
|
|
|
|
SELECT * FROM INFORMATION_SCHEMA.SCHEMATA
|
|
WHERE SCHEMA_NAME = 'test';
|
|
|
|
select count(*) from INFORMATION_SCHEMA.TABLES where TABLE_SCHEMA='mysql' AND TABLE_NAME='nonexisting';
|
|
select count(*) from INFORMATION_SCHEMA.TABLES where TABLE_SCHEMA='mysql' AND TABLE_NAME='';
|
|
select count(*) from INFORMATION_SCHEMA.TABLES where TABLE_SCHEMA='' AND TABLE_NAME='';
|
|
select count(*) from INFORMATION_SCHEMA.TABLES where TABLE_SCHEMA='' AND TABLE_NAME='nonexisting';
|
|
|
|
#
|
|
# Bug#30689 Wrong content in I_S.VIEWS.VIEW_DEFINITION if VIEW is based on I_S
|
|
#
|
|
CREATE VIEW v1
|
|
AS SELECT *
|
|
FROM information_schema.tables;
|
|
SELECT VIEW_DEFINITION FROM INFORMATION_SCHEMA.VIEWS where TABLE_NAME = 'v1';
|
|
DROP VIEW v1;
|
|
|
|
#
|
|
# Bug#30795 Query on INFORMATION_SCHEMA.SCHEMATA, wrong result
|
|
#
|
|
SELECT SCHEMA_NAME FROM INFORMATION_SCHEMA.SCHEMATA
|
|
WHERE SCHEMA_NAME ='information_schema';
|
|
|
|
#
|
|
# Bug#31381 Error in retrieving Data from INFORMATION_SCHEMA
|
|
#
|
|
SELECT TABLE_COLLATION FROM INFORMATION_SCHEMA.TABLES
|
|
WHERE TABLE_SCHEMA='mysql' and TABLE_NAME= 'db';
|
|
|
|
#
|
|
# Bug#31633 Information schema = NULL queries crash the server
|
|
#
|
|
select * from information_schema.columns where table_schema = NULL;
|
|
select * from `information_schema`.`COLUMNS` where `TABLE_NAME` = NULL;
|
|
select * from `information_schema`.`KEY_COLUMN_USAGE` where `TABLE_SCHEMA` = NULL;
|
|
select * from `information_schema`.`KEY_COLUMN_USAGE` where `TABLE_NAME` = NULL;
|
|
select * from `information_schema`.`PARTITIONS` where `TABLE_SCHEMA` = NULL;
|
|
select * from `information_schema`.`PARTITIONS` where `TABLE_NAME` = NULL;
|
|
select * from `information_schema`.`REFERENTIAL_CONSTRAINTS` where `CONSTRAINT_SCHEMA` = NULL;
|
|
select * from `information_schema`.`REFERENTIAL_CONSTRAINTS` where `TABLE_NAME` = NULL;
|
|
select * from information_schema.schemata where schema_name = NULL;
|
|
select * from `information_schema`.`STATISTICS` where `TABLE_SCHEMA` = NULL;
|
|
select * from `information_schema`.`STATISTICS` where `TABLE_NAME` = NULL;
|
|
select * from information_schema.tables where table_schema = NULL;
|
|
select * from information_schema.tables where table_catalog = NULL;
|
|
select * from information_schema.tables where table_name = NULL;
|
|
select * from `information_schema`.`TABLE_CONSTRAINTS` where `TABLE_SCHEMA` = NULL;
|
|
select * from `information_schema`.`TABLE_CONSTRAINTS` where `TABLE_NAME` = NULL;
|
|
select * from `information_schema`.`TRIGGERS` where `EVENT_OBJECT_SCHEMA` = NULL;
|
|
select * from `information_schema`.`TRIGGERS` where `EVENT_OBJECT_TABLE` = NULL;
|
|
select * from `information_schema`.`VIEWS` where `TABLE_SCHEMA` = NULL;
|
|
select * from `information_schema`.`VIEWS` where `TABLE_NAME` = NULL;
|
|
|
|
#
|
|
# Bug#31630 debug assert with explain extended select ... from i_s
|
|
#
|
|
explain extended select 1 from information_schema.tables;
|
|
|
|
#
|
|
# Bug#32775 problems with SHOW EVENTS and Information_Schema
|
|
#
|
|
use information_schema;
|
|
show events;
|
|
show events from information_schema;
|
|
show events where Db= 'information_schema';
|
|
use test;
|
|
|
|
--echo #
|
|
--echo # Bug#34166 Server crash in SHOW OPEN TABLES and prelocking
|
|
--echo #
|
|
--disable_warnings
|
|
drop table if exists t1;
|
|
drop function if exists f1;
|
|
--enable_warnings
|
|
create table t1 (a int);
|
|
delimiter |;
|
|
create function f1() returns int
|
|
begin
|
|
insert into t1 (a) values (1);
|
|
return 0;
|
|
end|
|
|
delimiter ;|
|
|
--disable_result_log
|
|
show open tables where f1()=0;
|
|
show open tables where f1()=0;
|
|
--enable_result_log
|
|
drop table t1;
|
|
drop function f1;
|
|
|
|
#
|
|
# Bug#34656 KILL a query = Assertion failed: m_status == DA_ERROR ||
|
|
# m_status == DA_OK
|
|
#
|
|
connect (conn1, localhost, root,,);
|
|
connection conn1;
|
|
let $ID= `select connection_id()`;
|
|
send select * from information_schema.tables where 1=sleep(100000);
|
|
connection default;
|
|
let $wait_timeout= 10;
|
|
let $wait_condition=select count(*)=1 from information_schema.processlist
|
|
where state='User sleep' and
|
|
info='select * from information_schema.tables where 1=sleep(100000)';
|
|
--source include/wait_condition.inc
|
|
disable_query_log;
|
|
eval kill $ID;
|
|
enable_query_log;
|
|
disconnect conn1;
|
|
let $wait_timeout= 10;
|
|
let $wait_condition=select count(*)=0 from information_schema.processlist
|
|
where state='User sleep' and
|
|
info='select * from information_schema.tables where 1=sleep(100000)';
|
|
--source include/wait_condition.inc
|
|
|
|
connect (conn1, localhost, root,,);
|
|
connection conn1;
|
|
let $ID= `select connection_id()`;
|
|
send select * from information_schema.columns where 1=sleep(100000);
|
|
connection default;
|
|
let $wait_timeout= 10;
|
|
let $wait_condition=select count(*)=1 from information_schema.processlist
|
|
where state='User sleep' and
|
|
info='select * from information_schema.columns where 1=sleep(100000)';
|
|
--source include/wait_condition.inc
|
|
disable_query_log;
|
|
eval kill $ID;
|
|
enable_query_log;
|
|
disconnect conn1;
|
|
let $wait_timeout= 10;
|
|
let $wait_condition=select count(*)=0 from information_schema.processlist
|
|
where state='User sleep' and
|
|
info='select * from information_schema.columns where 1=sleep(100000)';
|
|
--source include/wait_condition.inc
|
|
|
|
|
|
#
|
|
# Bug#38918 selecting from information_schema.columns is disproportionately slow
|
|
#
|
|
explain select count(*) from information_schema.tables;
|
|
explain select count(*) from information_schema.columns;
|
|
explain select count(*) from information_schema.views;
|
|
|
|
#
|
|
# Bug#39955 SELECT on INFORMATION_SCHEMA.GLOBAL_VARIABLES takes too long
|
|
#
|
|
set global init_connect="drop table if exists t1;drop table if exists t1;\
|
|
drop table if exists t1;drop table if exists t1;\
|
|
drop table if exists t1;drop table if exists t1;\
|
|
drop table if exists t1;drop table if exists t1;\
|
|
drop table if exists t1;drop table if exists t1;\
|
|
drop table if exists t1;drop table if exists t1;\
|
|
drop table if exists t1;drop table if exists t1;\
|
|
drop table if exists t1;drop table if exists t1;\
|
|
drop table if exists t1;drop table if exists t1;\
|
|
drop table if exists t1;drop table if exists t1;\
|
|
drop table if exists t1;drop table if exists t1;\
|
|
drop table if exists t1;drop table if exists t1;\
|
|
drop table if exists t1;drop table if exists t1;\
|
|
drop table if exists t1;drop table if exists t1;\
|
|
drop table if exists t1;drop table if exists t1;\
|
|
drop table if exists t1;drop table if exists t1;\
|
|
drop table if exists t1;drop table if exists t1;\
|
|
drop table if exists t1;drop table if exists t1;\
|
|
drop table if exists t1;drop table if exists t1;\
|
|
drop table if exists t1;drop table if exists t1;\
|
|
drop table if exists t1;drop table if exists t1;";
|
|
select * from information_schema.global_variables where variable_name='init_connect';
|
|
set global init_connect="";
|
|
|
|
#
|
|
# Bug#34517 SHOW GLOBAL STATUS does not work properly in embedded server.
|
|
#
|
|
|
|
create table t0 select * from information_schema.global_status where VARIABLE_NAME='COM_SELECT';
|
|
SELECT 1;
|
|
select a.VARIABLE_VALUE - b.VARIABLE_VALUE from t0 b, information_schema.global_status a
|
|
where a.VARIABLE_NAME = b.VARIABLE_NAME;
|
|
drop table t0;
|
|
|
|
#
|
|
# Bug#35275 INFORMATION_SCHEMA.TABLES.CREATE_OPTIONS omits KEY_BLOCK_SIZE
|
|
#
|
|
CREATE TABLE t1(a INT) KEY_BLOCK_SIZE=1;
|
|
SELECT CREATE_OPTIONS FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME='t1';
|
|
DROP TABLE t1;
|
|
|
|
#
|
|
# Bug #22047: Time in SHOW PROCESSLIST for SQL thread in replication seems
|
|
# to become negative
|
|
#
|
|
|
|
SET TIMESTAMP=@@TIMESTAMP + 10000000;
|
|
SELECT 'OK' AS TEST_RESULT FROM INFORMATION_SCHEMA.PROCESSLIST WHERE time < 0;
|
|
SET TIMESTAMP=DEFAULT;
|
|
|
|
--echo End of 5.1 tests.
|
|
|
|
--echo #
|
|
--echo # Additional test for WL#3726 "DDL locking for all metadata objects"
|
|
--echo # To avoid possible deadlocks process of filling of I_S tables should
|
|
--echo # use high-priority metadata lock requests when opening tables.
|
|
--echo # Below we just test that we really use high-priority lock request
|
|
--echo # since reproducing a deadlock will require much more complex test.
|
|
--echo #
|
|
--disable_warnings
|
|
drop tables if exists t1, t2, t3;
|
|
--enable_warnings
|
|
create table t1 (i int);
|
|
create table t2 (j int primary key auto_increment);
|
|
connect (con3726_1,localhost,root,,test);
|
|
--echo # Switching to connection 'con3726_1'
|
|
connection con3726_1;
|
|
lock table t2 read;
|
|
connect (con3726_2,localhost,root,,test);
|
|
--echo # Switching to connection 'con3726_2'
|
|
connection con3726_2;
|
|
--echo # RENAME below will be blocked by 'lock table t2 read' above but
|
|
--echo # will add two pending requests for exclusive metadata locks.
|
|
--send rename table t2 to t3
|
|
--echo # Switching to connection 'default'
|
|
connection default;
|
|
let $wait_condition=
|
|
select count(*) = 1 from information_schema.processlist
|
|
where state = "Waiting for table" and info like "rename table t2 to t3";
|
|
--source include/wait_condition.inc
|
|
--echo # These statements should not be blocked by pending lock requests
|
|
select table_name, column_name, data_type from information_schema.columns
|
|
where table_schema = 'test' and table_name in ('t1', 't2');
|
|
select table_name, auto_increment from information_schema.tables
|
|
where table_schema = 'test' and table_name in ('t1', 't2');
|
|
--echo # Switching to connection 'con3726_1'
|
|
connection con3726_1;
|
|
unlock tables;
|
|
--echo # Switching to connection 'con3726_2'
|
|
connection con3726_2;
|
|
--reap
|
|
--echo # Switching to connection 'default'
|
|
connection default;
|
|
disconnect con3726_1;
|
|
disconnect con3726_2;
|
|
drop tables t1, t3;
|
|
|
|
#
|
|
# Bug#39270 I_S optimization algorithm does not work properly in some cases
|
|
#
|
|
EXPLAIN SELECT * FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE;
|
|
EXPLAIN SELECT * FROM INFORMATION_SCHEMA.PARTITIONS WHERE TABLE_NAME='t1';
|
|
EXPLAIN SELECT * FROM INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS
|
|
WHERE CONSTRAINT_SCHEMA='test';
|
|
EXPLAIN SELECT * FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS
|
|
WHERE TABLE_NAME='t1' and TABLE_SCHEMA='test';
|
|
EXPLAIN SELECT * FROM INFORMATION_SCHEMA.TRIGGERS
|
|
WHERE EVENT_OBJECT_SCHEMA='test';
|
|
|
|
#
|
|
# Bug#24062 Incorrect error msg after execute DROP TABLE IF EXISTS on information_schema
|
|
#
|
|
--error ER_DBACCESS_DENIED_ERROR
|
|
create table information_schema.t1 (f1 INT);
|
|
--error ER_DBACCESS_DENIED_ERROR
|
|
drop table information_schema.t1;
|
|
--error ER_DBACCESS_DENIED_ERROR
|
|
drop temporary table if exists information_schema.t1;
|
|
--error ER_DBACCESS_DENIED_ERROR
|
|
create temporary table information_schema.t1 (f1 INT);
|
|
--error ER_DBACCESS_DENIED_ERROR
|
|
drop view information_schema.v1;
|
|
--error ER_DBACCESS_DENIED_ERROR
|
|
create view information_schema.v1;
|
|
--error ER_DBACCESS_DENIED_ERROR
|
|
create trigger mysql.trg1 after insert on information_schema.t1 for each row set @a=1;
|
|
--error 1109
|
|
create table t1 select * from information_schema.t1;
|
|
|
|
CREATE TABLE t1(f1 char(100));
|
|
--error ER_DBACCESS_DENIED_ERROR
|
|
REPAIR TABLE t1, information_schema.tables;
|
|
CHECKSUM TABLE t1, information_schema.tables;
|
|
--error ER_DBACCESS_DENIED_ERROR
|
|
ANALYZE TABLE t1, information_schema.tables;
|
|
CHECK TABLE t1, information_schema.tables;
|
|
--error ER_DBACCESS_DENIED_ERROR
|
|
OPTIMIZE TABLE t1, information_schema.tables;
|
|
--error ER_DBACCESS_DENIED_ERROR
|
|
RENAME TABLE v1 to v2, information_schema.tables to t2;
|
|
--error ER_DBACCESS_DENIED_ERROR
|
|
DROP TABLE t1, information_schema.tables;
|
|
|
|
--error ER_DBACCESS_DENIED_ERROR
|
|
LOCK TABLES t1 READ, information_schema.tables READ;
|
|
DROP TABLE t1;
|
|
|
|
# Wait till all disconnects are completed
|
|
--source include/wait_until_count_sessions.inc
|
|
|
|
#
|
|
# Bug #43834 Assertion in Natural_join_column::db_name() on an I_S query
|
|
#
|
|
|
|
SELECT *
|
|
FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE
|
|
LEFT JOIN INFORMATION_SCHEMA.COLUMNS
|
|
USING (TABLE_SCHEMA, TABLE_NAME, COLUMN_NAME)
|
|
WHERE COLUMNS.TABLE_SCHEMA = 'test'
|
|
AND COLUMNS.TABLE_NAME = 't1';
|
|
|
|
|