mirror of
https://github.com/MariaDB/server.git
synced 2025-02-01 11:31:51 +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.
3908 lines
97 KiB
Text
3908 lines
97 KiB
Text
--disable_warnings
|
|
drop table if exists t1,t2,t3,t4,t9,`t1a``b`,v1,v2,v3,v4,v5,v6;
|
|
drop view if exists t1,t2,`t1a``b`,v1,v2,v3,v4,v5,v6;
|
|
drop database if exists mysqltest;
|
|
--enable_warnings
|
|
use test;
|
|
|
|
#
|
|
# some basic test of views and its functionality
|
|
#
|
|
|
|
# create view on nonexistent table
|
|
-- error ER_NO_SUCH_TABLE
|
|
create view v1 (c,d) as select a,b from t1;
|
|
|
|
create temporary table t1 (a int, b int);
|
|
# view on temporary table
|
|
-- error ER_VIEW_SELECT_TMPTABLE
|
|
create view v1 (c) as select b+1 from t1;
|
|
drop table t1;
|
|
|
|
create table t1 (a int, b int);
|
|
insert into t1 values (1,2), (1,3), (2,4), (2,5), (3,10);
|
|
|
|
# view with variable
|
|
-- error ER_VIEW_SELECT_VARIABLE
|
|
create view v1 (c,d) as select a,b+@@global.max_user_connections from t1;
|
|
-- error ER_VIEW_SELECT_VARIABLE
|
|
create view v1 (c,d) as select a,b from t1
|
|
where a = @@global.max_user_connections;
|
|
|
|
# simple view
|
|
create view v1 (c) as select b+1 from t1;
|
|
select c from v1;
|
|
select is_updatable from information_schema.views where table_name='v1';
|
|
|
|
# temporary table should not hide table of view
|
|
create temporary table t1 (a int, b int);
|
|
# this is empty
|
|
select * from t1;
|
|
# but this based on normal t1
|
|
select c from v1;
|
|
show create table v1;
|
|
show create view v1;
|
|
-- error ER_WRONG_OBJECT
|
|
show create view t1;
|
|
drop table t1;
|
|
|
|
# try to use fields from underlying table
|
|
-- error ER_BAD_FIELD_ERROR
|
|
select a from v1;
|
|
-- error ER_BAD_FIELD_ERROR
|
|
select v1.a from v1;
|
|
-- error ER_BAD_FIELD_ERROR
|
|
select b from v1;
|
|
-- error ER_BAD_FIELD_ERROR
|
|
select v1.b from v1;
|
|
|
|
# view with different algorithms (explain output differs)
|
|
explain extended select c from v1;
|
|
create algorithm=temptable view v2 (c) as select b+1 from t1;
|
|
show create view v2;
|
|
select c from v2;
|
|
explain extended select c from v2;
|
|
|
|
# try to use underlying table fields in VIEW creation process
|
|
-- error ER_BAD_FIELD_ERROR
|
|
create view v3 (c) as select a+1 from v1;
|
|
-- error ER_BAD_FIELD_ERROR
|
|
create view v3 (c) as select b+1 from v1;
|
|
|
|
|
|
# VIEW on VIEW test with mixing different algorithms on different order
|
|
create view v3 (c) as select c+1 from v1;
|
|
select c from v3;
|
|
explain extended select c from v3;
|
|
create algorithm=temptable view v4 (c) as select c+1 from v2;
|
|
select c from v4;
|
|
explain extended select c from v4;
|
|
create view v5 (c) as select c+1 from v2;
|
|
select c from v5;
|
|
explain extended select c from v5;
|
|
create algorithm=temptable view v6 (c) as select c+1 from v1;
|
|
select c from v6;
|
|
explain extended select c from v6;
|
|
|
|
# show table/table status test
|
|
show tables;
|
|
show full tables;
|
|
--replace_column 8 # 12 # 13 #
|
|
show table status;
|
|
|
|
drop view v1,v2,v3,v4,v5,v6;
|
|
|
|
#
|
|
# alter/create view test
|
|
#
|
|
|
|
# view with subqueries of different types
|
|
create view v1 (c,d,e,f) as select a,b,
|
|
a in (select a+2 from t1), a = all (select a from t1) from t1;
|
|
create view v2 as select c, d from v1;
|
|
select * from v1;
|
|
select * from v2;
|
|
|
|
# try to create VIEW with name of existing VIEW
|
|
-- error ER_TABLE_EXISTS_ERROR
|
|
create view v1 (c,d,e,f) as select a,b, a in (select a+2 from t1), a = all (select a from t1) from t1;
|
|
|
|
# 'or replace' should work in this case
|
|
create or replace view v1 (c,d,e,f) as select a,b, a in (select a+2 from t1), a = all (select a from t1) from t1;
|
|
|
|
# try to ALTER unexisting VIEW
|
|
drop view v2;
|
|
-- error ER_NO_SUCH_TABLE
|
|
alter view v2 as select c, d from v1;
|
|
|
|
# 'or replace' on unexisting view
|
|
create or replace view v2 as select c, d from v1;
|
|
|
|
# alter view on existing view
|
|
alter view v1 (c,d) as select a,max(b) from t1 group by a;
|
|
|
|
# check that created view works
|
|
select * from v1;
|
|
select * from v2;
|
|
|
|
# try to drop nonexistent VIEW
|
|
-- error ER_BAD_TABLE_ERROR
|
|
drop view v100;
|
|
|
|
# try to drop table with DROP VIEW
|
|
-- error ER_WRONG_OBJECT
|
|
drop view t1;
|
|
|
|
# try to drop VIEW with DROP TABLE
|
|
-- error ER_BAD_TABLE_ERROR
|
|
drop table v1;
|
|
|
|
# try to drop table with DROP VIEW
|
|
|
|
drop view v1,v2;
|
|
drop table t1;
|
|
|
|
#
|
|
# outer left join with merged views
|
|
#
|
|
create table t1 (a int);
|
|
insert into t1 values (1), (2), (3);
|
|
|
|
create view v1 (a) as select a+1 from t1;
|
|
create view v2 (a) as select a-1 from t1;
|
|
|
|
select * from t1 natural left join v1;
|
|
select * from v2 natural left join t1;
|
|
select * from v2 natural left join v1;
|
|
|
|
drop view v1, v2;
|
|
drop table t1;
|
|
|
|
|
|
#
|
|
# DISTINCT option for VIEW
|
|
#
|
|
create table t1 (a int);
|
|
insert into t1 values (1), (2), (3), (1), (2), (3);
|
|
create view v1 as select distinct a from t1;
|
|
select * from v1;
|
|
explain select * from v1;
|
|
select * from t1;
|
|
drop view v1;
|
|
drop table t1;
|
|
|
|
#
|
|
# syntax compatibility
|
|
#
|
|
create table t1 (a int);
|
|
-- error ER_VIEW_NONUPD_CHECK
|
|
create view v1 as select distinct a from t1 WITH CHECK OPTION;
|
|
create view v1 as select a from t1 WITH CHECK OPTION;
|
|
create view v2 as select a from t1 WITH CASCADED CHECK OPTION;
|
|
create view v3 as select a from t1 WITH LOCAL CHECK OPTION;
|
|
drop view v3 RESTRICT;
|
|
drop view v2 CASCADE;
|
|
drop view v1;
|
|
drop table t1;
|
|
|
|
#
|
|
# aliases
|
|
#
|
|
create table t1 (a int, b int);
|
|
insert into t1 values (1,2), (1,3), (2,4), (2,5), (3,10);
|
|
create view v1 (c) as select b+1 from t1;
|
|
select test.c from v1 test;
|
|
create algorithm=temptable view v2 (c) as select b+1 from t1;
|
|
select test.c from v2 test;
|
|
select test1.* from v1 test1, v2 test2 where test1.c=test2.c;
|
|
select test2.* from v1 test1, v2 test2 where test1.c=test2.c;
|
|
drop table t1;
|
|
drop view v1,v2;
|
|
|
|
#
|
|
# LIMIT clause test
|
|
#
|
|
create table t1 (a int);
|
|
insert into t1 values (1), (2), (3), (4);
|
|
create view v1 as select a+1 from t1 order by 1 desc limit 2;
|
|
select * from v1;
|
|
explain select * from v1;
|
|
drop view v1;
|
|
drop table t1;
|
|
|
|
#
|
|
# CREATE ... SELECT view test
|
|
#
|
|
create table t1 (a int);
|
|
insert into t1 values (1), (2), (3), (4);
|
|
create view v1 as select a+1 from t1;
|
|
create table t2 select * from v1;
|
|
show columns from t2;
|
|
select * from t2;
|
|
drop view v1;
|
|
drop table t1,t2;
|
|
|
|
#
|
|
# simple view + simple update
|
|
#
|
|
create table t1 (a int, b int, primary key(a));
|
|
insert into t1 values (10,2), (20,3), (30,4), (40,5), (50,10);
|
|
create view v1 (a,c) as select a, b+1 from t1;
|
|
create algorithm=temptable view v2 (a,c) as select a, b+1 from t1;
|
|
select is_updatable from information_schema.views where table_name='v2';
|
|
select is_updatable from information_schema.views where table_name='v1';
|
|
# try to update expression
|
|
-- error ER_NONUPDATEABLE_COLUMN
|
|
update v1 set c=a+c;
|
|
# try to update VIEW with forced TEMPORARY TABLE algorithm
|
|
-- error ER_NON_UPDATABLE_TABLE
|
|
update v2 set a=a+c;
|
|
# updatable field of updateable view
|
|
update v1 set a=a+c;
|
|
select * from v1;
|
|
select * from t1;
|
|
drop table t1;
|
|
drop view v1,v2;
|
|
|
|
#
|
|
# simple view + simple multi-update
|
|
#
|
|
create table t1 (a int, b int, primary key(a));
|
|
insert into t1 values (10,2), (20,3), (30,4), (40,5), (50,10);
|
|
create table t2 (x int);
|
|
insert into t2 values (10), (20);
|
|
create view v1 (a,c) as select a, b+1 from t1;
|
|
create algorithm=temptable view v2 (a,c) as select a, b+1 from t1;
|
|
# try to update expression
|
|
-- error ER_NONUPDATEABLE_COLUMN
|
|
update t2,v1 set v1.c=v1.a+v1.c where t2.x=v1.a;
|
|
# try to update VIEW with forced TEMPORARY TABLE algorithm
|
|
-- error ER_NON_UPDATABLE_TABLE
|
|
update t2,v2 set v2.a=v2.v2.a+c where t2.x=v2.a;
|
|
# updatable field of updateable view
|
|
update t2,v1 set v1.a=v1.a+v1.c where t2.x=v1.a;
|
|
select * from v1;
|
|
select * from t1;
|
|
drop table t1,t2;
|
|
drop view v1,v2;
|
|
|
|
#
|
|
# MERGE VIEW with WHERE clause
|
|
#
|
|
create table t1 (a int, b int, primary key(b));
|
|
insert into t1 values (1,20), (2,30), (3,40), (4,50), (5,100);
|
|
create view v1 (c) as select b from t1 where a<3;
|
|
# simple select and explaint to be sure that it is MERGE
|
|
select * from v1;
|
|
explain extended select * from v1;
|
|
# update test
|
|
update v1 set c=c+1;
|
|
select * from t1;
|
|
# join of such VIEWs test
|
|
create view v2 (c) as select b from t1 where a>=3;
|
|
select * from v1, v2;
|
|
drop view v1, v2;
|
|
drop table t1;
|
|
|
|
#
|
|
# simple view + simple delete
|
|
#
|
|
create table t1 (a int, b int, primary key(a));
|
|
insert into t1 values (1,2), (2,3), (3,4), (4,5), (5,10);
|
|
create view v1 (a,c) as select a, b+1 from t1;
|
|
create algorithm=temptable view v2 (a,c) as select a, b+1 from t1;
|
|
# try to update VIEW with forced TEMPORARY TABLE algorithm
|
|
-- error ER_NON_UPDATABLE_TABLE
|
|
delete from v2 where c < 4;
|
|
# updatable field of updateable view
|
|
delete from v1 where c < 4;
|
|
select * from v1;
|
|
select * from t1;
|
|
drop table t1;
|
|
drop view v1,v2;
|
|
|
|
#
|
|
# simple view + simple multi-delete
|
|
#
|
|
create table t1 (a int, b int, primary key(a));
|
|
insert into t1 values (1,2), (2,3), (3,4), (4,5), (5,10);
|
|
create table t2 (x int);
|
|
insert into t2 values (1), (2), (3), (4);
|
|
create view v1 (a,c) as select a, b+1 from t1;
|
|
create algorithm=temptable view v2 (a,c) as select a, b+1 from t1;
|
|
# try to update VIEW with forced TEMPORARY TABLE algorithm
|
|
-- error ER_NON_UPDATABLE_TABLE
|
|
delete v2 from t2,v2 where t2.x=v2.a;
|
|
# updatable field of updateable view
|
|
delete v1 from t2,v1 where t2.x=v1.a;
|
|
select * from v1;
|
|
select * from t1;
|
|
drop table t1,t2;
|
|
drop view v1,v2;
|
|
|
|
#
|
|
# key presence check
|
|
#
|
|
create table t1 (a int, b int, c int, primary key(a,b));
|
|
insert into t1 values (10,2,-1), (20,3,-2), (30,4,-3), (40,5,-4), (50,10,-5);
|
|
create view v1 (x,y) as select a, b from t1;
|
|
create view v2 (x,y) as select a, c from t1;
|
|
set updatable_views_with_limit=NO;
|
|
update v1 set x=x+1;
|
|
update v2 set x=x+1;
|
|
update v1 set x=x+1 limit 1;
|
|
-- error ER_NON_UPDATABLE_TABLE
|
|
update v2 set x=x+1 limit 1;
|
|
set updatable_views_with_limit=YES;
|
|
update v1 set x=x+1 limit 1;
|
|
update v2 set x=x+1 limit 1;
|
|
set updatable_views_with_limit=DEFAULT;
|
|
show variables like "updatable_views_with_limit";
|
|
select * from t1;
|
|
drop table t1;
|
|
drop view v1,v2;
|
|
|
|
#
|
|
# simple insert
|
|
#
|
|
create table t1 (a int, b int, c int, primary key(a,b));
|
|
insert into t1 values (10,2,-1), (20,3,-2);
|
|
create view v1 (x,y,z) as select c, b, a from t1;
|
|
create view v2 (x,y) as select b, a from t1;
|
|
create view v3 (x,y,z) as select b, a, b from t1;
|
|
create view v4 (x,y,z) as select c+1, b, a from t1;
|
|
create algorithm=temptable view v5 (x,y,z) as select c, b, a from t1;
|
|
# try insert to VIEW with fields duplicate
|
|
-- error ER_NON_INSERTABLE_TABLE
|
|
insert into v3 values (-60,4,30);
|
|
# try insert to VIEW with expression in SELECT list
|
|
-- error ER_NON_INSERTABLE_TABLE
|
|
insert into v4 values (-60,4,30);
|
|
# try insert to VIEW using temporary table algorithm
|
|
-- error ER_NON_INSERTABLE_TABLE
|
|
insert into v5 values (-60,4,30);
|
|
insert into v1 values (-60,4,30);
|
|
insert into v1 (z,y,x) values (50,6,-100);
|
|
insert into v2 values (5,40);
|
|
select * from t1;
|
|
drop table t1;
|
|
drop view v1,v2,v3,v4,v5;
|
|
|
|
#
|
|
# insert ... select
|
|
#
|
|
create table t1 (a int, b int, c int, primary key(a,b));
|
|
insert into t1 values (10,2,-1), (20,3,-2);
|
|
create table t2 (a int, b int, c int, primary key(a,b));
|
|
insert into t2 values (30,4,-60);
|
|
create view v1 (x,y,z) as select c, b, a from t1;
|
|
create view v2 (x,y) as select b, a from t1;
|
|
create view v3 (x,y,z) as select b, a, b from t1;
|
|
create view v4 (x,y,z) as select c+1, b, a from t1;
|
|
create algorithm=temptable view v5 (x,y,z) as select c, b, a from t1;
|
|
# try insert to VIEW with fields duplicate
|
|
-- error ER_NON_INSERTABLE_TABLE
|
|
insert into v3 select c, b, a from t2;
|
|
# try insert to VIEW with expression in SELECT list
|
|
-- error ER_NON_INSERTABLE_TABLE
|
|
insert into v4 select c, b, a from t2;
|
|
# try insert to VIEW using temporary table algorithm
|
|
-- error ER_NON_INSERTABLE_TABLE
|
|
insert into v5 select c, b, a from t2;
|
|
insert into v1 select c, b, a from t2;
|
|
insert into v1 (z,y,x) select a+20,b+2,-100 from t2;
|
|
insert into v2 select b+1, a+10 from t2;
|
|
select * from t1;
|
|
drop table t1, t2;
|
|
drop view v1,v2,v3,v4,v5;
|
|
|
|
#
|
|
# outer join based on VIEW with WHERE clause
|
|
#
|
|
create table t1 (a int, primary key(a));
|
|
insert into t1 values (1), (2), (3);
|
|
create view v1 (x) as select a from t1 where a > 1;
|
|
select t1.a, v1.x from t1 left join v1 on (t1.a= v1.x);
|
|
drop table t1;
|
|
drop view v1;
|
|
|
|
#
|
|
# merging WHERE condition on VIEW on VIEW
|
|
#
|
|
create table t1 (a int, primary key(a));
|
|
insert into t1 values (1), (2), (3), (200);
|
|
create view v1 (x) as select a from t1 where a > 1;
|
|
create view v2 (y) as select x from v1 where x < 100;
|
|
select * from v2;
|
|
drop table t1;
|
|
drop view v1,v2;
|
|
|
|
#
|
|
# VIEW on non-updatable view
|
|
#
|
|
create table t1 (a int, primary key(a));
|
|
insert into t1 values (1), (2), (3), (200);
|
|
create ALGORITHM=TEMPTABLE view v1 (x) as select a from t1;
|
|
create view v2 (y) as select x from v1;
|
|
-- error ER_NON_UPDATABLE_TABLE
|
|
update v2 set y=10 where y=2;
|
|
drop table t1;
|
|
drop view v1,v2;
|
|
|
|
#
|
|
# auto_increment field out of VIEW
|
|
#
|
|
create table t1 (a int not null auto_increment, b int not null, primary key(a), unique(b));
|
|
create view v1 (x) as select b from t1;
|
|
insert into v1 values (1);
|
|
select last_insert_id();
|
|
insert into t1 (b) values (2);
|
|
select last_insert_id();
|
|
select * from t1;
|
|
drop view v1;
|
|
drop table t1;
|
|
|
|
#
|
|
# VIEW fields quoting
|
|
#
|
|
set sql_mode='ansi';
|
|
create table t1 ("a*b" int);
|
|
create view v1 as select "a*b" from t1;
|
|
show create view v1;
|
|
drop view v1;
|
|
drop table t1;
|
|
set sql_mode=default;
|
|
|
|
#
|
|
# VIEW without tables
|
|
#
|
|
create table t1 (t_column int);
|
|
create view v1 as select 'a';
|
|
select * from v1, t1;
|
|
drop view v1;
|
|
drop table t1;
|
|
|
|
#
|
|
# quote mark inside table name
|
|
#
|
|
create table `t1a``b` (col1 char(2));
|
|
create view v1 as select * from `t1a``b`;
|
|
select * from v1;
|
|
describe v1;
|
|
drop view v1;
|
|
drop table `t1a``b`;
|
|
|
|
#
|
|
# Changing of underlying table
|
|
#
|
|
create table t1 (col1 char(5),col2 char(5));
|
|
create view v1 as select * from t1;
|
|
drop table t1;
|
|
create table t1 (col1 char(5),newcol2 char(5));
|
|
-- error ER_VIEW_INVALID
|
|
insert into v1 values('a','aa');
|
|
drop table t1;
|
|
-- error ER_VIEW_INVALID
|
|
select * from v1;
|
|
drop view v1;
|
|
|
|
#
|
|
# check of duplication of column names
|
|
#
|
|
-- error ER_DUP_FIELDNAME
|
|
create view v1 (a,a) as select 'a','a';
|
|
|
|
#
|
|
# updatablity should be transitive
|
|
#
|
|
create table t1 (col1 int,col2 char(22));
|
|
insert into t1 values(5,'Hello, world of views');
|
|
create view v1 as select * from t1;
|
|
create view v2 as select * from v1;
|
|
update v2 set col2='Hello, view world';
|
|
select is_updatable from information_schema.views;
|
|
select * from t1;
|
|
drop view v2, v1;
|
|
drop table t1;
|
|
|
|
#
|
|
# check 'use index' on view with temporary table
|
|
#
|
|
create table t1 (a int, b int);
|
|
create view v1 as select a, sum(b) from t1 group by a;
|
|
--error ER_KEY_DOES_NOT_EXITS
|
|
select b from v1 use index (some_index) where b=1;
|
|
drop view v1;
|
|
drop table t1;
|
|
|
|
#
|
|
# using VIEW fields several times in query resolved via temporary tables
|
|
#
|
|
create table t1 (col1 char(5),col2 char(5));
|
|
create view v1 (col1,col2) as select col1,col2 from t1;
|
|
insert into v1 values('s1','p1'),('s1','p2'),('s1','p3'),('s1','p4'),('s2','p1'),('s3','p2'),('s4','p4');
|
|
select distinct first.col2 from t1 first where first.col2 in (select second.col2 from t1 second where second.col1<>first.col1);
|
|
select distinct first.col2 from v1 first where first.col2 in (select second.col2 from t1 second where second.col1<>first.col1);
|
|
drop view v1;
|
|
drop table t1;
|
|
|
|
#
|
|
# Test of view updatability in prepared statement
|
|
#
|
|
create table t1 (a int);
|
|
create view v1 as select a from t1;
|
|
insert into t1 values (1);
|
|
|
|
#update
|
|
SET @v0 = '2';
|
|
PREPARE stmt FROM 'UPDATE v1 SET a = ?';
|
|
EXECUTE stmt USING @v0;
|
|
DEALLOCATE PREPARE stmt;
|
|
|
|
#insert without field list
|
|
SET @v0 = '3';
|
|
PREPARE stmt FROM 'insert into v1 values (?)';
|
|
EXECUTE stmt USING @v0;
|
|
DEALLOCATE PREPARE stmt;
|
|
|
|
#insert with field list
|
|
SET @v0 = '4';
|
|
PREPARE stmt FROM 'insert into v1 (a) values (?)';
|
|
EXECUTE stmt USING @v0;
|
|
DEALLOCATE PREPARE stmt;
|
|
|
|
select * from t1;
|
|
|
|
drop view v1;
|
|
drop table t1;
|
|
|
|
#
|
|
# error on preparation
|
|
#
|
|
-- error ER_NO_TABLES_USED
|
|
CREATE VIEW v02 AS SELECT * FROM DUAL;
|
|
SHOW TABLES;
|
|
|
|
#
|
|
# EXISTS with UNION VIEW
|
|
#
|
|
CREATE VIEW v1 AS SELECT EXISTS (SELECT 1 UNION SELECT 2);
|
|
select * from v1;
|
|
drop view v1;
|
|
|
|
#
|
|
# using VIEW where table is required
|
|
#
|
|
create table t1 (col1 int,col2 char(22));
|
|
create view v1 as select * from t1;
|
|
-- error ER_WRONG_OBJECT
|
|
create index i1 on v1 (col1);
|
|
drop view v1;
|
|
drop table t1;
|
|
|
|
#
|
|
# connection_id(), pi(), current_user(), version() representation test
|
|
#
|
|
CREATE VIEW v1 (f1,f2,f3,f4) AS SELECT connection_id(), pi(), current_user(), version();
|
|
SHOW CREATE VIEW v1;
|
|
drop view v1;
|
|
|
|
#
|
|
# VIEW built over UNION
|
|
#
|
|
create table t1 (s1 int);
|
|
create table t2 (s2 int);
|
|
insert into t1 values (1), (2);
|
|
insert into t2 values (2), (3);
|
|
create view v1 as select * from t1,t2 union all select * from t1,t2;
|
|
select * from v1;
|
|
drop view v1;
|
|
drop tables t1, t2;
|
|
|
|
#
|
|
# Aggregate functions in view list
|
|
#
|
|
create table t1 (col1 int);
|
|
insert into t1 values (1);
|
|
create view v1 as select count(*) from t1;
|
|
insert into t1 values (null);
|
|
select * from v1;
|
|
drop view v1;
|
|
drop table t1;
|
|
|
|
#
|
|
# Showing VIEW with VIEWs in subquery
|
|
#
|
|
create table t1 (a int);
|
|
create table t2 (a int);
|
|
create view v1 as select a from t1;
|
|
create view v2 as select a from t2 where a in (select a from v1);
|
|
show create view v2;
|
|
drop view v2, v1;
|
|
drop table t1, t2;
|
|
|
|
#
|
|
# SHOW VIEW view with name with spaces
|
|
#
|
|
CREATE VIEW `v 1` AS select 5 AS `5`;
|
|
show create view `v 1`;
|
|
drop view `v 1`;
|
|
|
|
#
|
|
# Removing database with .frm archives
|
|
#
|
|
create database mysqltest;
|
|
create table mysqltest.t1 (a int, b int);
|
|
create view mysqltest.v1 as select a from mysqltest.t1;
|
|
alter view mysqltest.v1 as select b from mysqltest.t1;
|
|
alter view mysqltest.v1 as select a from mysqltest.t1;
|
|
drop database mysqltest;
|
|
|
|
#
|
|
# VIEW with full text
|
|
#
|
|
CREATE TABLE t1 (c1 int not null auto_increment primary key, c2 varchar(20), fulltext(c2));
|
|
insert into t1 (c2) VALUES ('real Beer'),('Water'),('Kossu'),('Coca-Cola'),('Vodka'),('Wine'),('almost real Beer');
|
|
select * from t1 WHERE match (c2) against ('Beer');
|
|
CREATE VIEW v1 AS SELECT * from t1 WHERE match (c2) against ('Beer');
|
|
select * from v1;
|
|
drop view v1;
|
|
drop table t1;
|
|
|
|
#
|
|
# distinct in temporary table with a VIEW
|
|
#
|
|
create table t1 (a int);
|
|
insert into t1 values (1),(1),(2),(2),(3),(3);
|
|
create view v1 as select a from t1;
|
|
select distinct a from v1;
|
|
select distinct a from v1 limit 2;
|
|
select distinct a from t1 limit 2;
|
|
prepare stmt1 from "select distinct a from v1 limit 2";
|
|
execute stmt1;
|
|
execute stmt1;
|
|
deallocate prepare stmt1;
|
|
drop view v1;
|
|
drop table t1;
|
|
|
|
#
|
|
# aggregate function of aggregate function
|
|
#
|
|
create table t1 (tg_column bigint);
|
|
create view v1 as select count(tg_column) as vg_column from t1;
|
|
select avg(vg_column) from v1;
|
|
drop view v1;
|
|
drop table t1;
|
|
|
|
#
|
|
# VIEW of VIEW with column renaming
|
|
#
|
|
create table t1 (col1 bigint not null, primary key (col1));
|
|
create table t2 (col1 bigint not null, key (col1));
|
|
create view v1 as select * from t1;
|
|
create view v2 as select * from t2;
|
|
insert into v1 values (1);
|
|
insert into v2 values (1);
|
|
create view v3 (a,b) as select v1.col1 as a, v2.col1 as b from v1, v2 where v1.col1 = v2.col1;
|
|
select * from v3;
|
|
show create view v3;
|
|
drop view v3, v2, v1;
|
|
drop table t2, t1;
|
|
|
|
#
|
|
# VIEW based on functions with complex names
|
|
#
|
|
create function `f``1` () returns int return 5;
|
|
create view v1 as select test.`f``1` ();
|
|
show create view v1;
|
|
select * from v1;
|
|
drop view v1;
|
|
drop function `f``1`;
|
|
|
|
#
|
|
# tested problem when function name length close to ALIGN_SIZE
|
|
#
|
|
create function a() returns int return 5;
|
|
create view v1 as select a();
|
|
select * from v1;
|
|
drop view v1;
|
|
drop function a;
|
|
|
|
#
|
|
# VIEW with collation
|
|
#
|
|
create table t2 (col1 char collate latin1_german2_ci);
|
|
create view v2 as select col1 collate latin1_german1_ci from t2;
|
|
show create view v2;
|
|
show create view v2;
|
|
drop view v2;
|
|
drop table t2;
|
|
|
|
#
|
|
# order by refers on integer field
|
|
#
|
|
create table t1 (a int);
|
|
insert into t1 values (1), (2);
|
|
create view v1 as select 5 from t1 order by 1;
|
|
select * from v1;
|
|
drop view v1;
|
|
drop table t1;
|
|
|
|
#
|
|
# VIEW over dropped function
|
|
#
|
|
create function x1 () returns int return 5;
|
|
create table t1 (s1 int);
|
|
create view v1 as select x1() from t1;
|
|
drop function x1;
|
|
-- error ER_VIEW_INVALID
|
|
select * from v1;
|
|
--replace_column 8 # 12 # 13 #
|
|
show table status;
|
|
drop view v1;
|
|
drop table t1;
|
|
|
|
#
|
|
# VIEW with floating point (long number) as column
|
|
#
|
|
create view v1 as select 99999999999999999999999999999999999999999999999999999 as col1;
|
|
show create view v1;
|
|
drop view v1;
|
|
|
|
#
|
|
# VIEWs with national characters
|
|
#
|
|
|
|
SET @old_cs_client = @@character_set_client;
|
|
SET @old_cs_results = @@character_set_results;
|
|
SET @old_cs_connection = @@character_set_connection;
|
|
|
|
set names utf8;
|
|
create table tü (cü char);
|
|
create view vü as select cü from tü;
|
|
insert into vü values ('ü');
|
|
select * from vü;
|
|
drop view vü;
|
|
drop table tü;
|
|
|
|
SET character_set_client = @old_cs_client;
|
|
SET character_set_results = @old_cs_results;
|
|
SET character_set_connection = @old_cs_connection;
|
|
|
|
#
|
|
# problem with used_tables() of outer reference resolved in VIEW
|
|
#
|
|
create table t1 (a int, b int);
|
|
insert into t1 values (1,2), (1,3), (2,4), (2,5), (3,10);
|
|
create view v1(c) as select a+1 from t1 where b >= 4;
|
|
select c from v1 where exists (select * from t1 where a=2 and b=c);
|
|
drop view v1;
|
|
drop table t1;
|
|
|
|
#
|
|
# view with cast operation
|
|
#
|
|
create view v1 as select cast(1 as char(3));
|
|
show create view v1;
|
|
select * from v1;
|
|
drop view v1;
|
|
|
|
#
|
|
# renaming views
|
|
#
|
|
create table t1 (a int);
|
|
create view v1 as select a from t1;
|
|
create view v3 as select a from t1;
|
|
create database mysqltest;
|
|
-- error ER_FORBID_SCHEMA_CHANGE
|
|
rename table v1 to mysqltest.v1;
|
|
rename table v1 to v2;
|
|
--error ER_TABLE_EXISTS_ERROR
|
|
rename table v3 to v1, v2 to t1;
|
|
drop table t1;
|
|
drop view v2,v3;
|
|
drop database mysqltest;
|
|
|
|
#
|
|
# bug handling from VIEWs
|
|
#
|
|
create view v1 as select 'a',1;
|
|
create view v2 as select * from v1 union all select * from v1;
|
|
create view v3 as select * from v2 where 1 = (select `1` from v2);
|
|
create view v4 as select * from v3;
|
|
-- error ER_SUBQUERY_NO_1_ROW
|
|
select * from v4;
|
|
drop view v4, v3, v2, v1;
|
|
|
|
#
|
|
# VIEW over SELECT with prohibited clauses
|
|
#
|
|
-- error ER_VIEW_SELECT_CLAUSE
|
|
create view v1 as select 5 into @w;
|
|
-- error ER_VIEW_SELECT_CLAUSE
|
|
create view v1 as select 5 into outfile 'ttt';
|
|
create table t1 (a int);
|
|
-- error ER_VIEW_SELECT_CLAUSE
|
|
create view v1 as select a from t1 procedure analyse();
|
|
-- error ER_VIEW_SELECT_DERIVED
|
|
create view v1 as select 1 from (select 1) as d1;
|
|
drop table t1;
|
|
|
|
#
|
|
# INSERT into VIEW with ON DUPLICATE
|
|
#
|
|
create table t1 (s1 int, primary key (s1));
|
|
create view v1 as select * from t1;
|
|
insert into v1 values (1) on duplicate key update s1 = 7;
|
|
insert into v1 values (1) on duplicate key update s1 = 7;
|
|
select * from t1;
|
|
drop view v1;
|
|
drop table t1;
|
|
|
|
#
|
|
# test of updating and fetching from the same table check
|
|
#
|
|
create table t1 (col1 int);
|
|
create table t2 (col1 int);
|
|
create table t3 (col1 datetime not null);
|
|
create view v1 as select * from t1;
|
|
create view v2 as select * from v1;
|
|
create view v3 as select v2.col1 from v2,t2 where v2.col1 = t2.col1;
|
|
-- error ER_VIEW_PREVENT_UPDATE
|
|
update v2 set col1 = (select max(col1) from v1);
|
|
-- error ER_VIEW_PREVENT_UPDATE
|
|
update v2 set col1 = (select max(col1) from t1);
|
|
-- error ER_UPDATE_TABLE_USED
|
|
update v2 set col1 = (select max(col1) from v2);
|
|
-- error ER_VIEW_PREVENT_UPDATE
|
|
update v2,t2 set v2.col1 = (select max(col1) from v1) where v2.col1 = t2.col1;
|
|
-- error ER_VIEW_PREVENT_UPDATE
|
|
update t1,t2 set t1.col1 = (select max(col1) from v1) where t1.col1 = t2.col1;
|
|
-- error ER_UPDATE_TABLE_USED
|
|
update v1,t2 set v1.col1 = (select max(col1) from v1) where v1.col1 = t2.col1;
|
|
-- error ER_VIEW_PREVENT_UPDATE
|
|
update t2,v2 set v2.col1 = (select max(col1) from v1) where v2.col1 = t2.col1;
|
|
-- error ER_VIEW_PREVENT_UPDATE
|
|
update t2,t1 set t1.col1 = (select max(col1) from v1) where t1.col1 = t2.col1;
|
|
-- error ER_VIEW_PREVENT_UPDATE
|
|
update t2,v1 set v1.col1 = (select max(col1) from v1) where v1.col1 = t2.col1;
|
|
-- error ER_VIEW_PREVENT_UPDATE
|
|
update v2,t2 set v2.col1 = (select max(col1) from t1) where v2.col1 = t2.col1;
|
|
-- error ER_UPDATE_TABLE_USED
|
|
update t1,t2 set t1.col1 = (select max(col1) from t1) where t1.col1 = t2.col1;
|
|
-- error ER_VIEW_PREVENT_UPDATE
|
|
update v1,t2 set v1.col1 = (select max(col1) from t1) where v1.col1 = t2.col1;
|
|
-- error ER_UPDATE_TABLE_USED
|
|
update t2,v2 set v2.col1 = (select max(col1) from t1) where v2.col1 = t2.col1;
|
|
-- error ER_UPDATE_TABLE_USED
|
|
update t2,t1 set t1.col1 = (select max(col1) from t1) where t1.col1 = t2.col1;
|
|
-- error ER_UPDATE_TABLE_USED
|
|
update t2,v1 set v1.col1 = (select max(col1) from t1) where v1.col1 = t2.col1;
|
|
-- error ER_UPDATE_TABLE_USED
|
|
update v2,t2 set v2.col1 = (select max(col1) from v2) where v2.col1 = t2.col1;
|
|
-- error ER_VIEW_PREVENT_UPDATE
|
|
update t1,t2 set t1.col1 = (select max(col1) from v2) where t1.col1 = t2.col1;
|
|
-- error ER_VIEW_PREVENT_UPDATE
|
|
update v1,t2 set v1.col1 = (select max(col1) from v2) where v1.col1 = t2.col1;
|
|
-- error ER_VIEW_PREVENT_UPDATE
|
|
update t2,v2 set v2.col1 = (select max(col1) from v2) where v2.col1 = t2.col1;
|
|
-- error ER_VIEW_PREVENT_UPDATE
|
|
update t2,t1 set t1.col1 = (select max(col1) from v2) where t1.col1 = t2.col1;
|
|
-- error ER_VIEW_PREVENT_UPDATE
|
|
update t2,v1 set v1.col1 = (select max(col1) from v2) where v1.col1 = t2.col1;
|
|
-- error ER_VIEW_PREVENT_UPDATE
|
|
update v3 set v3.col1 = (select max(col1) from v1);
|
|
-- error ER_VIEW_PREVENT_UPDATE
|
|
update v3 set v3.col1 = (select max(col1) from t1);
|
|
-- error ER_VIEW_PREVENT_UPDATE
|
|
update v3 set v3.col1 = (select max(col1) from v2);
|
|
-- error ER_UPDATE_TABLE_USED
|
|
update v3 set v3.col1 = (select max(col1) from v3);
|
|
-- error ER_VIEW_PREVENT_UPDATE
|
|
delete from v2 where col1 = (select max(col1) from v1);
|
|
-- error ER_VIEW_PREVENT_UPDATE
|
|
delete from v2 where col1 = (select max(col1) from t1);
|
|
-- error ER_UPDATE_TABLE_USED
|
|
delete from v2 where col1 = (select max(col1) from v2);
|
|
-- error ER_VIEW_PREVENT_UPDATE
|
|
delete v2 from v2,t2 where (select max(col1) from v1) > 0 and v2.col1 = t2.col1;
|
|
-- error ER_VIEW_PREVENT_UPDATE
|
|
delete t1 from t1,t2 where (select max(col1) from v1) > 0 and t1.col1 = t2.col1;
|
|
-- error ER_UPDATE_TABLE_USED
|
|
delete v1 from v1,t2 where (select max(col1) from v1) > 0 and v1.col1 = t2.col1;
|
|
-- error ER_VIEW_PREVENT_UPDATE
|
|
delete v2 from v2,t2 where (select max(col1) from t1) > 0 and v2.col1 = t2.col1;
|
|
-- error ER_UPDATE_TABLE_USED
|
|
delete t1 from t1,t2 where (select max(col1) from t1) > 0 and t1.col1 = t2.col1;
|
|
-- error ER_VIEW_PREVENT_UPDATE
|
|
delete v1 from v1,t2 where (select max(col1) from t1) > 0 and v1.col1 = t2.col1;
|
|
-- error ER_UPDATE_TABLE_USED
|
|
delete v2 from v2,t2 where (select max(col1) from v2) > 0 and v2.col1 = t2.col1;
|
|
-- error ER_VIEW_PREVENT_UPDATE
|
|
delete t1 from t1,t2 where (select max(col1) from v2) > 0 and t1.col1 = t2.col1;
|
|
-- error ER_VIEW_PREVENT_UPDATE
|
|
delete v1 from v1,t2 where (select max(col1) from v2) > 0 and v1.col1 = t2.col1;
|
|
-- error ER_VIEW_PREVENT_UPDATE
|
|
insert into v2 values ((select max(col1) from v1));
|
|
-- error ER_VIEW_PREVENT_UPDATE
|
|
insert into t1 values ((select max(col1) from v1));
|
|
-- error ER_VIEW_PREVENT_UPDATE
|
|
insert into v2 values ((select max(col1) from v1));
|
|
-- error ER_VIEW_PREVENT_UPDATE
|
|
insert into v2 values ((select max(col1) from t1));
|
|
-- error ER_UPDATE_TABLE_USED
|
|
insert into t1 values ((select max(col1) from t1));
|
|
-- error ER_VIEW_PREVENT_UPDATE
|
|
insert into v2 values ((select max(col1) from t1));
|
|
-- error ER_UPDATE_TABLE_USED
|
|
insert into v2 values ((select max(col1) from v2));
|
|
-- error ER_VIEW_PREVENT_UPDATE
|
|
insert into t1 values ((select max(col1) from v2));
|
|
-- error ER_UPDATE_TABLE_USED
|
|
insert into v2 values ((select max(col1) from v2));
|
|
-- error ER_VIEW_PREVENT_UPDATE
|
|
insert into v3 (col1) values ((select max(col1) from v1));
|
|
-- error ER_VIEW_PREVENT_UPDATE
|
|
insert into v3 (col1) values ((select max(col1) from t1));
|
|
-- error ER_VIEW_PREVENT_UPDATE
|
|
insert into v3 (col1) values ((select max(col1) from v2));
|
|
# check with TZ tables in list
|
|
-- error ER_VIEW_PREVENT_UPDATE
|
|
insert into v3 (col1) values ((select CONVERT_TZ('20050101000000','UTC','MET') from v2));
|
|
insert into v3 (col1) values ((select CONVERT_TZ('20050101000000','UTC','MET') from t2));
|
|
-- error ER_BAD_NULL_ERROR
|
|
insert into t3 values ((select CONVERT_TZ('20050101000000','UTC','MET') from t2));
|
|
# temporary table algorithm view should be equal to subquery in the from clause
|
|
create algorithm=temptable view v4 as select * from t1;
|
|
insert into t1 values (1),(2),(3);
|
|
insert into t1 (col1) values ((select max(col1) from v4));
|
|
select * from t1;
|
|
|
|
drop view v4,v3,v2,v1;
|
|
drop table t1,t2,t3;
|
|
|
|
#
|
|
# HANDLER with VIEW
|
|
#
|
|
create table t1 (s1 int);
|
|
create view v1 as select * from t1;
|
|
-- error ER_WRONG_OBJECT
|
|
handler v1 open as xx;
|
|
drop view v1;
|
|
drop table t1;
|
|
|
|
#
|
|
# view with WHERE in nested join
|
|
#
|
|
create table t1(a int);
|
|
insert into t1 values (0), (1), (2), (3);
|
|
create table t2 (a int);
|
|
insert into t2 select a from t1 where a > 1;
|
|
create view v1 as select a from t1 where a > 1;
|
|
select * from t1 left join (t2 as t, v1) on v1.a=t1.a;
|
|
select * from t1 left join (t2 as t, t2) on t2.a=t1.a;
|
|
drop view v1;
|
|
drop table t1, t2;
|
|
|
|
#
|
|
# Collation with view update
|
|
#
|
|
create table t1 (s1 char);
|
|
create view v1 as select s1 collate latin1_german1_ci as s1 from t1;
|
|
insert into v1 values ('a');
|
|
select * from v1;
|
|
update v1 set s1='b';
|
|
select * from v1;
|
|
update v1,t1 set v1.s1='c' where t1.s1=v1.s1;
|
|
select * from v1;
|
|
prepare stmt1 from "update v1,t1 set v1.s1=? where t1.s1=v1.s1";
|
|
set @arg='d';
|
|
execute stmt1 using @arg;
|
|
select * from v1;
|
|
set @arg='e';
|
|
execute stmt1 using @arg;
|
|
select * from v1;
|
|
deallocate prepare stmt1;
|
|
drop view v1;
|
|
drop table t1;
|
|
|
|
#
|
|
# test view with LOCK TABLES (work around)
|
|
#
|
|
create table t1 (a int);
|
|
create table t2 (a int);
|
|
create view v1 as select * from t1;
|
|
lock tables t1 read, v1 read;
|
|
select * from v1;
|
|
-- error ER_TABLE_NOT_LOCKED
|
|
select * from t2;
|
|
unlock tables;
|
|
drop view v1;
|
|
drop table t1, t2;
|
|
|
|
#
|
|
# WITH CHECK OPTION insert/update test
|
|
#
|
|
create table t1 (a int);
|
|
create view v1 as select * from t1 where a < 2 with check option;
|
|
# simple insert
|
|
insert into v1 values(1);
|
|
-- error ER_VIEW_CHECK_FAILED
|
|
insert into v1 values(3);
|
|
# simple insert with ignore
|
|
insert ignore into v1 values (2),(3),(0);
|
|
select * from t1;
|
|
# prepare data for next check
|
|
delete from t1;
|
|
# INSERT SELECT test
|
|
insert into v1 SELECT 1;
|
|
-- error ER_VIEW_CHECK_FAILED
|
|
insert into v1 SELECT 3;
|
|
# prepare data for next check
|
|
create table t2 (a int);
|
|
insert into t2 values (2),(3),(0);
|
|
# INSERT SELECT with ignore test
|
|
insert ignore into v1 SELECT a from t2;
|
|
select * from t1 order by a desc;
|
|
# simple UPDATE test
|
|
update v1 set a=-1 where a=0;
|
|
-- error ER_VIEW_CHECK_FAILED
|
|
update v1 set a=2 where a=1;
|
|
select * from t1 order by a desc;
|
|
# prepare data for next check
|
|
update v1 set a=0 where a=0;
|
|
insert into t2 values (1);
|
|
# multiupdate test
|
|
update v1,t2 set v1.a=v1.a-1 where v1.a=t2.a;
|
|
select * from t1 order by a desc;
|
|
# prepare data for next check
|
|
update v1 set a=a+1;
|
|
# multiupdate with ignore test
|
|
update ignore v1,t2 set v1.a=v1.a+1 where v1.a=t2.a;
|
|
select * from t1;
|
|
|
|
drop view v1;
|
|
drop table t1, t2;
|
|
|
|
#
|
|
# CASCADED/LOCAL CHECK OPTION test
|
|
#
|
|
create table t1 (a int);
|
|
create view v1 as select * from t1 where a < 2 with check option;
|
|
create view v2 as select * from v1 where a > 0 with local check option;
|
|
create view v3 as select * from v1 where a > 0 with cascaded check option;
|
|
insert into v2 values (1);
|
|
insert into v3 values (1);
|
|
-- error ER_VIEW_CHECK_FAILED
|
|
insert into v2 values (0);
|
|
-- error ER_VIEW_CHECK_FAILED
|
|
insert into v3 values (0);
|
|
insert into v2 values (2);
|
|
-- error ER_VIEW_CHECK_FAILED
|
|
insert into v3 values (2);
|
|
select * from t1;
|
|
drop view v3,v2,v1;
|
|
drop table t1;
|
|
|
|
#
|
|
# CHECK OPTION with INSERT ... ON DUPLICATE KEY UPDATE
|
|
#
|
|
create table t1 (a int, primary key (a));
|
|
create view v1 as select * from t1 where a < 2 with check option;
|
|
insert into v1 values (1) on duplicate key update a=2;
|
|
-- error ER_VIEW_CHECK_FAILED
|
|
insert into v1 values (1) on duplicate key update a=2;
|
|
insert ignore into v1 values (1) on duplicate key update a=2;
|
|
select * from t1;
|
|
drop view v1;
|
|
drop table t1;
|
|
|
|
#
|
|
# check cyclic referencing protection on altering view
|
|
#
|
|
create table t1 (s1 int);
|
|
create view v1 as select * from t1;
|
|
create view v2 as select * from v1;
|
|
-- error ER_NO_SUCH_TABLE
|
|
alter view v1 as select * from v2;
|
|
-- error ER_NO_SUCH_TABLE
|
|
alter view v1 as select * from v1;
|
|
-- error ER_NO_SUCH_TABLE
|
|
create or replace view v1 as select * from v2;
|
|
-- error ER_NO_SUCH_TABLE
|
|
create or replace view v1 as select * from v1;
|
|
drop view v2,v1;
|
|
drop table t1;
|
|
|
|
#
|
|
# check altering differ options
|
|
#
|
|
create table t1 (a int);
|
|
create view v1 as select * from t1;
|
|
show create view v1;
|
|
alter algorithm=undefined view v1 as select * from t1 with check option;
|
|
show create view v1;
|
|
alter algorithm=merge view v1 as select * from t1 with cascaded check option;
|
|
show create view v1;
|
|
alter algorithm=temptable view v1 as select * from t1;
|
|
show create view v1;
|
|
drop view v1;
|
|
drop table t1;
|
|
|
|
#
|
|
# updating view with subquery in the WHERE clause
|
|
#
|
|
create table t1 (s1 int);
|
|
create table t2 (s1 int);
|
|
create view v2 as select * from t2 where s1 in (select s1 from t1);
|
|
insert into v2 values (5);
|
|
insert into t1 values (5);
|
|
select * from v2;
|
|
update v2 set s1 = 0;
|
|
select * from v2;
|
|
select * from t2;
|
|
# check it with check option
|
|
alter view v2 as select * from t2 where s1 in (select s1 from t1) with check option;
|
|
insert into v2 values (5);
|
|
-- error ER_VIEW_CHECK_FAILED
|
|
update v2 set s1 = 1;
|
|
insert into t1 values (1);
|
|
update v2 set s1 = 1;
|
|
select * from v2;
|
|
select * from t2;
|
|
# scheck how VIEWs with subqueries work with prepared statements
|
|
prepare stmt1 from "select * from v2;";
|
|
execute stmt1;
|
|
insert into t1 values (0);
|
|
execute stmt1;
|
|
deallocate prepare stmt1;
|
|
drop view v2;
|
|
drop table t1, t2;
|
|
|
|
#
|
|
# test of substring_index with view
|
|
#
|
|
create table t1 (t time);
|
|
create view v1 as select substring_index(t,':',2) as t from t1;
|
|
insert into t1 (t) values ('12:24:10');
|
|
select substring_index(t,':',2) from t1;
|
|
select substring_index(t,':',2) from v1;
|
|
drop view v1;
|
|
drop table t1;
|
|
|
|
#
|
|
# test of cascaded check option for whiew without WHERE clause
|
|
#
|
|
create table t1 (s1 tinyint);
|
|
create view v1 as select * from t1 where s1 <> 0 with local check option;
|
|
create view v2 as select * from v1 with cascaded check option;
|
|
-- error ER_VIEW_CHECK_FAILED
|
|
insert into v2 values (0);
|
|
drop view v2, v1;
|
|
drop table t1;
|
|
|
|
#
|
|
# inserting single value with check option failed always get error
|
|
#
|
|
create table t1 (s1 int);
|
|
create view v1 as select * from t1 where s1 < 5 with check option;
|
|
#single value
|
|
-- error ER_VIEW_CHECK_FAILED
|
|
insert ignore into v1 values (6);
|
|
#several values
|
|
insert ignore into v1 values (6),(3);
|
|
select * from t1;
|
|
drop view v1;
|
|
drop table t1;
|
|
|
|
#
|
|
# changing value by trigger and CHECK OPTION
|
|
#
|
|
create table t1 (s1 tinyint);
|
|
create trigger t1_bi before insert on t1 for each row set new.s1 = 500;
|
|
create view v1 as select * from t1 where s1 <> 127 with check option;
|
|
-- error ER_VIEW_CHECK_FAILED
|
|
insert into v1 values (0);
|
|
select * from v1;
|
|
select * from t1;
|
|
drop trigger t1_bi;
|
|
drop view v1;
|
|
drop table t1;
|
|
|
|
#
|
|
# CASCADED should be used for all underlaying VIEWs
|
|
#
|
|
create table t1 (s1 tinyint);
|
|
create view v1 as select * from t1 where s1 <> 0;
|
|
create view v2 as select * from v1 where s1 <> 1 with cascaded check option;
|
|
-- error ER_VIEW_CHECK_FAILED
|
|
insert into v2 values (0);
|
|
select * from v2;
|
|
select * from t1;
|
|
drop view v2, v1;
|
|
drop table t1;
|
|
|
|
#
|
|
# LOAD DATA with view and CHECK OPTION
|
|
#
|
|
# fixed length fields
|
|
create table t1 (a int, b char(10));
|
|
create view v1 as select * from t1 where a != 0 with check option;
|
|
-- error ER_VIEW_CHECK_FAILED
|
|
load data infile '../../std_data/loaddata3.dat' into table v1 fields terminated by '' enclosed by '' ignore 1 lines;
|
|
select * from t1;
|
|
select * from v1;
|
|
delete from t1;
|
|
load data infile '../../std_data/loaddata3.dat' ignore into table v1 fields terminated by '' enclosed by '' ignore 1 lines;
|
|
select * from t1 order by a,b;
|
|
select * from v1 order by a,b;
|
|
drop view v1;
|
|
drop table t1;
|
|
# variable length fields
|
|
create table t1 (a text, b text);
|
|
create view v1 as select * from t1 where a <> 'Field A' with check option;
|
|
-- error ER_VIEW_CHECK_FAILED
|
|
load data infile '../../std_data/loaddata2.dat' into table v1 fields terminated by ',' enclosed by '''';
|
|
select concat('|',a,'|'), concat('|',b,'|') from t1;
|
|
select concat('|',a,'|'), concat('|',b,'|') from v1;
|
|
delete from t1;
|
|
load data infile '../../std_data/loaddata2.dat' ignore into table v1 fields terminated by ',' enclosed by '''';
|
|
select concat('|',a,'|'), concat('|',b,'|') from t1;
|
|
select concat('|',a,'|'), concat('|',b,'|') from v1;
|
|
drop view v1;
|
|
drop table t1;
|
|
|
|
#
|
|
# Trys update table from which we select using views and subqueries
|
|
#
|
|
create table t1 (s1 smallint);
|
|
create view v1 as select * from t1 where 20 < (select (s1) from t1);
|
|
-- error ER_NON_INSERTABLE_TABLE
|
|
insert into v1 values (30);
|
|
create view v2 as select * from t1;
|
|
create view v3 as select * from t1 where 20 < (select (s1) from v2);
|
|
-- error ER_NON_INSERTABLE_TABLE
|
|
insert into v3 values (30);
|
|
create view v4 as select * from v2 where 20 < (select (s1) from t1);
|
|
-- error ER_NON_INSERTABLE_TABLE
|
|
insert into v4 values (30);
|
|
drop view v4, v3, v2, v1;
|
|
drop table t1;
|
|
|
|
#
|
|
# CHECK TABLE with VIEW
|
|
#
|
|
create table t1 (a int);
|
|
create view v1 as select * from t1;
|
|
check table t1,v1;
|
|
check table v1,t1;
|
|
drop table t1;
|
|
check table v1;
|
|
drop view v1;
|
|
|
|
#
|
|
# merge of VIEW with several tables
|
|
#
|
|
create table t1 (a int);
|
|
create table t2 (a int);
|
|
create table t3 (a int);
|
|
insert into t1 values (1), (2), (3);
|
|
insert into t2 values (1), (3);
|
|
insert into t3 values (1), (2), (4);
|
|
# view over tables
|
|
create view v3 (a,b) as select t1.a as a, t2.a as b from t1 left join t2 on (t1.a=t2.a);
|
|
select * from t3 left join v3 on (t3.a = v3.a);
|
|
explain extended select * from t3 left join v3 on (t3.a = v3.a);
|
|
# view over views
|
|
create view v1 (a) as select a from t1;
|
|
create view v2 (a) as select a from t2;
|
|
create view v4 (a,b) as select v1.a as a, v2.a as b from v1 left join v2 on (v1.a=v2.a);
|
|
select * from t3 left join v4 on (t3.a = v4.a);
|
|
explain extended select * from t3 left join v4 on (t3.a = v4.a);
|
|
# PS with view over views
|
|
prepare stmt1 from "select * from t3 left join v4 on (t3.a = v4.a);";
|
|
execute stmt1;
|
|
execute stmt1;
|
|
deallocate prepare stmt1;
|
|
drop view v4,v3,v2,v1;
|
|
drop tables t1,t2,t3;
|
|
|
|
#
|
|
# updating of join view
|
|
#
|
|
create table t1 (a int, primary key (a), b int);
|
|
create table t2 (a int, primary key (a));
|
|
insert into t1 values (1,100), (2,200);
|
|
insert into t2 values (1), (3);
|
|
# legal view for update
|
|
create view v3 (a,b) as select t1.a as a, t2.a as b from t1, t2;
|
|
update v3 set a= 10 where a=1;
|
|
select * from t1;
|
|
select * from t2;
|
|
# view without primary key
|
|
create view v2 (a,b) as select t1.b as a, t2.a as b from t1, t2;
|
|
set updatable_views_with_limit=NO;
|
|
-- error ER_NON_UPDATABLE_TABLE
|
|
update v2 set a= 10 where a=200 limit 1;
|
|
set updatable_views_with_limit=DEFAULT;
|
|
# just view selects
|
|
select * from v3;
|
|
select * from v2;
|
|
# prepare statement with updating join view
|
|
set @a= 10;
|
|
set @b= 100;
|
|
prepare stmt1 from "update v3 set a= ? where a=?";
|
|
execute stmt1 using @a,@b;
|
|
select * from v3;
|
|
set @a= 300;
|
|
set @b= 10;
|
|
execute stmt1 using @a,@b;
|
|
select * from v3;
|
|
deallocate prepare stmt1;
|
|
drop view v3,v2;
|
|
drop tables t1,t2;
|
|
|
|
#
|
|
# inserting/deleting join view
|
|
#
|
|
create table t1 (a int, primary key (a), b int);
|
|
create table t2 (a int, primary key (a), b int);
|
|
insert into t2 values (1000, 2000);
|
|
create view v3 (a,b) as select t1.a as a, t2.a as b from t1, t2;
|
|
# inserting into join view without field list
|
|
-- error ER_VIEW_NO_INSERT_FIELD_LIST
|
|
insert into v3 values (1,2);
|
|
-- error ER_VIEW_NO_INSERT_FIELD_LIST
|
|
insert into v3 select * from t2;
|
|
# inserting in several tables of join view
|
|
-- error ER_VIEW_MULTIUPDATE
|
|
insert into v3(a,b) values (1,2);
|
|
-- error ER_VIEW_MULTIUPDATE
|
|
insert into v3(a,b) select * from t2;
|
|
# correct inserts into join view
|
|
insert into v3(a) values (1);
|
|
insert into v3(b) values (10);
|
|
insert into v3(a) select a from t2;
|
|
insert into v3(b) select b from t2;
|
|
insert into v3(a) values (1) on duplicate key update a=a+10000+VALUES(a);
|
|
select * from t1;
|
|
select * from t2;
|
|
# try delete from join view
|
|
-- error ER_VIEW_DELETE_MERGE_VIEW
|
|
delete from v3;
|
|
-- error ER_VIEW_DELETE_MERGE_VIEW
|
|
delete v3,t1 from v3,t1;
|
|
-- error ER_VIEW_DELETE_MERGE_VIEW
|
|
delete t1,v3 from t1,v3;
|
|
# delete from t1 just to reduce result set size
|
|
delete from t1;
|
|
# prepare statement with insert join view
|
|
prepare stmt1 from "insert into v3(a) values (?);";
|
|
set @a= 100;
|
|
execute stmt1 using @a;
|
|
set @a= 300;
|
|
execute stmt1 using @a;
|
|
deallocate prepare stmt1;
|
|
prepare stmt1 from "insert into v3(a) select ?;";
|
|
set @a= 101;
|
|
execute stmt1 using @a;
|
|
set @a= 301;
|
|
execute stmt1 using @a;
|
|
deallocate prepare stmt1;
|
|
select * from v3;
|
|
|
|
drop view v3;
|
|
drop tables t1,t2;
|
|
|
|
#
|
|
# View field names should be case insensitive
|
|
#
|
|
create table t1(f1 int);
|
|
create view v1 as select f1 from t1;
|
|
select * from v1 where F1 = 1;
|
|
drop view v1;
|
|
drop table t1;
|
|
|
|
#
|
|
# Resolving view fields in subqueries in VIEW (Bug#6394)
|
|
#
|
|
create table t1(c1 int);
|
|
create table t2(c2 int);
|
|
insert into t1 values (1),(2),(3);
|
|
insert into t2 values (1);
|
|
SELECT c1 FROM t1 WHERE c1 IN (SELECT c2 FROM t2);
|
|
SELECT c1 FROM t1 WHERE EXISTS (SELECT c2 FROM t2 WHERE c2 = c1);
|
|
create view v1 as SELECT c1 FROM t1 WHERE c1 IN (SELECT c2 FROM t2);
|
|
create view v2 as SELECT c1 FROM t1 WHERE EXISTS (SELECT c2 FROM t2 WHERE c2 = c1);
|
|
select * from v1;
|
|
select * from v2;
|
|
select * from (select c1 from v2) X;
|
|
drop view v2, v1;
|
|
drop table t1, t2;
|
|
|
|
#
|
|
# view over other view setup (Bug#7433)
|
|
#
|
|
CREATE TABLE t1 (C1 INT, C2 INT);
|
|
CREATE TABLE t2 (C2 INT);
|
|
CREATE VIEW v1 AS SELECT C2 FROM t2;
|
|
CREATE VIEW v2 AS SELECT C1 FROM t1 LEFT OUTER JOIN v1 USING (C2);
|
|
SELECT * FROM v2;
|
|
drop view v2, v1;
|
|
drop table t1, t2;
|
|
|
|
#
|
|
# view and group_concat() (Bug#7116)
|
|
#
|
|
create table t1 (col1 char(5),col2 int,col3 int);
|
|
insert into t1 values ('one',10,25), ('two',10,50), ('two',10,50), ('one',20,25), ('one',30,25);
|
|
create view v1 as select * from t1;
|
|
select col1,group_concat(col2,col3) from t1 group by col1;
|
|
select col1,group_concat(col2,col3) from v1 group by col1;
|
|
drop view v1;
|
|
drop table t1;
|
|
|
|
#
|
|
# Item_ref resolved as view field (Bug#6894)
|
|
#
|
|
create table t1 (s1 int, s2 char);
|
|
create view v1 as select s1, s2 from t1;
|
|
-- error ER_BAD_FIELD_ERROR
|
|
select s2 from v1 vq1 where 2 = (select count(*) from v1 vq2 having vq1.s2 = vq2.s2);
|
|
select s2 from v1 vq1 where 2 = (select count(*) aa from v1 vq2 having vq1.s2 = aa);
|
|
drop view v1;
|
|
drop table t1;
|
|
|
|
#
|
|
# Test case for Bug#9398 CREATE TABLE with SELECT from a multi-table view
|
|
#
|
|
CREATE TABLE t1 (a1 int);
|
|
CREATE TABLE t2 (a2 int);
|
|
INSERT INTO t1 VALUES (1), (2), (3), (4);
|
|
INSERT INTO t2 VALUES (1), (2), (3);
|
|
CREATE VIEW v1(a,b) AS SELECT a1,a2 FROM t1 JOIN t2 ON a1=a2 WHERE a1>1;
|
|
|
|
SELECT * FROM v1;
|
|
CREATE TABLE t3 SELECT * FROM v1;
|
|
SELECT * FROM t3;
|
|
|
|
DROP VIEW v1;
|
|
DROP TABLE t1,t2,t3;
|
|
|
|
#
|
|
# Test for Bug#8703 insert into table select from view crashes
|
|
#
|
|
create table t1 (a int);
|
|
create table t2 like t1;
|
|
create table t3 like t1;
|
|
create view v1 as select t1.a x, t2.a y from t1 join t2 where t1.a=t2.a;
|
|
insert into t3 select x from v1;
|
|
insert into t2 select x from v1;
|
|
drop view v1;
|
|
drop table t1,t2,t3;
|
|
|
|
#
|
|
# Test for Bug#6106 query over a view using subquery for the underlying table
|
|
#
|
|
|
|
CREATE TABLE t1 (col1 int PRIMARY KEY, col2 varchar(10));
|
|
INSERT INTO t1 VALUES(1,'trudy');
|
|
INSERT INTO t1 VALUES(2,'peter');
|
|
INSERT INTO t1 VALUES(3,'sanja');
|
|
INSERT INTO t1 VALUES(4,'monty');
|
|
INSERT INTO t1 VALUES(5,'david');
|
|
INSERT INTO t1 VALUES(6,'kent');
|
|
INSERT INTO t1 VALUES(7,'carsten');
|
|
INSERT INTO t1 VALUES(8,'ranger');
|
|
INSERT INTO t1 VALUES(10,'matt');
|
|
CREATE TABLE t2 (col1 int, col2 int, col3 char(1));
|
|
INSERT INTO t2 VALUES (1,1,'y');
|
|
INSERT INTO t2 VALUES (1,2,'y');
|
|
INSERT INTO t2 VALUES (2,1,'n');
|
|
INSERT INTO t2 VALUES (3,1,'n');
|
|
INSERT INTO t2 VALUES (4,1,'y');
|
|
INSERT INTO t2 VALUES (4,2,'n');
|
|
INSERT INTO t2 VALUES (4,3,'n');
|
|
INSERT INTO t2 VALUES (6,1,'n');
|
|
INSERT INTO t2 VALUES (8,1,'y');
|
|
|
|
CREATE VIEW v1 AS SELECT * FROM t1;
|
|
|
|
SELECT a.col1,a.col2,b.col2,b.col3
|
|
FROM t1 a LEFT JOIN t2 b ON a.col1=b.col1
|
|
WHERE b.col2 IS NULL OR
|
|
b.col2=(SELECT MAX(col2) FROM t2 b WHERE b.col1=a.col1);
|
|
|
|
SELECT a.col1,a.col2,b.col2,b.col3
|
|
FROM v1 a LEFT JOIN t2 b ON a.col1=b.col1
|
|
WHERE b.col2 IS NULL OR
|
|
b.col2=(SELECT MAX(col2) FROM t2 b WHERE b.col1=a.col1);
|
|
|
|
CREATE VIEW v2 AS SELECT * FROM t2;
|
|
|
|
SELECT a.col1,a.col2,b.col2,b.col3
|
|
FROM v2 b RIGHT JOIN v1 a ON a.col1=b.col1
|
|
WHERE b.col2 IS NULL OR
|
|
b.col2=(SELECT MAX(col2) FROM v2 b WHERE b.col1=a.col1);
|
|
|
|
# Tests from the report for Bug#6107
|
|
|
|
SELECT a.col1,a.col2,b.col2,b.col3
|
|
FROM v2 b RIGHT JOIN v1 a ON a.col1=b.col1
|
|
WHERE a.col1 IN (1,5,9) AND
|
|
(b.col2 IS NULL OR
|
|
b.col2=(SELECT MAX(col2) FROM v2 b WHERE b.col1=a.col1));
|
|
|
|
CREATE VIEW v3 AS SELECT * FROM t1 WHERE col1 IN (1,5,9);
|
|
|
|
SELECT a.col1,a.col2,b.col2,b.col3
|
|
FROM v2 b RIGHT JOIN v3 a ON a.col1=b.col1
|
|
WHERE b.col2 IS NULL OR
|
|
b.col2=(SELECT MAX(col2) FROM v2 b WHERE b.col1=a.col1);
|
|
|
|
DROP VIEW v1,v2,v3;
|
|
DROP TABLE t1,t2;
|
|
|
|
#
|
|
# Bug#8490 Select from views containing subqueries causes server to hang
|
|
# forever.
|
|
#
|
|
create table t1 as select 1 A union select 2 union select 3;
|
|
create table t2 as select * from t1;
|
|
create view v1 as select * from t1 where a in (select * from t2);
|
|
select * from v1 A, v1 B where A.a = B.a;
|
|
create table t3 as select a a,a b from t2;
|
|
create view v2 as select * from t3 where
|
|
a in (select * from t1) or b in (select * from t2);
|
|
select * from v2 A, v2 B where A.a = B.b;
|
|
drop view v1, v2;
|
|
drop table t1, t2, t3;
|
|
|
|
#
|
|
# Test case for Bug#8528 select from view over multi-table view
|
|
#
|
|
CREATE TABLE t1 (a int);
|
|
CREATE TABLE t2 (b int);
|
|
INSERT INTO t1 VALUES (1), (2), (3), (4);
|
|
INSERT INTO t2 VALUES (4), (2);
|
|
|
|
CREATE VIEW v1 AS SELECT * FROM t1,t2 WHERE t1.a=t2.b;
|
|
SELECT * FROM v1;
|
|
CREATE VIEW v2 AS SELECT * FROM v1;
|
|
SELECT * FROM v2;
|
|
|
|
DROP VIEW v2,v1;
|
|
|
|
DROP TABLE t1, t2;
|
|
#
|
|
# Correct restoring view name in SP table locking Bug#9758
|
|
#
|
|
create table t1 (a int);
|
|
create view v1 as select sum(a) from t1 group by a;
|
|
delimiter //;
|
|
create procedure p1()
|
|
begin
|
|
select * from v1;
|
|
end//
|
|
delimiter ;//
|
|
call p1();
|
|
call p1();
|
|
drop procedure p1;
|
|
drop view v1;
|
|
drop table t1;
|
|
|
|
#
|
|
# Bug#7422 "order by" doesn't work
|
|
#
|
|
CREATE TABLE t1(a char(2) primary key, b char(2));
|
|
CREATE TABLE t2(a char(2), b char(2), index i(a));
|
|
INSERT INTO t1 VALUES ('a','1'), ('b','2');
|
|
INSERT INTO t2 VALUES ('a','5'), ('a','6'), ('b','5'), ('b','6');
|
|
CREATE VIEW v1 AS
|
|
SELECT t1.b as c, t2.b as d FROM t1,t2 WHERE t1.a=t2.a;
|
|
SELECT d, c FROM v1 ORDER BY d,c;
|
|
DROP VIEW v1;
|
|
DROP TABLE t1, t2;
|
|
#
|
|
# using sum(distinct ) & avg(distinct ) in views (Bug#7015)
|
|
#
|
|
create table t1 (s1 int);
|
|
create view v1 as select sum(distinct s1) from t1;
|
|
select * from v1;
|
|
drop view v1;
|
|
create view v1 as select avg(distinct s1) from t1;
|
|
select * from v1;
|
|
drop view v1;
|
|
drop table t1;
|
|
|
|
#
|
|
# using cast(... as decimal) in views (Bug#11387);
|
|
#
|
|
create view v1 as select cast(1 as decimal);
|
|
select * from v1;
|
|
drop view v1;
|
|
|
|
#
|
|
# Bug#11298 insert into select from VIEW produces incorrect result when
|
|
# using ORDER BY
|
|
create table t1(f1 int);
|
|
create table t2(f2 int);
|
|
insert into t1 values(1),(2),(3);
|
|
insert into t2 values(1),(2),(3);
|
|
create view v1 as select * from t1,t2 where f1=f2;
|
|
create table t3 (f1 int, f2 int);
|
|
insert into t3 select * from v1 order by 1;
|
|
select * from t3;
|
|
drop view v1;
|
|
drop table t1,t2,t3;
|
|
|
|
#
|
|
# Generation unique names for columns, and correct names check (Bug#7448)
|
|
#
|
|
# names with ' and \
|
|
create view v1 as select '\\','\\shazam';
|
|
select * from v1;
|
|
drop view v1;
|
|
create view v1 as select '\'','\shazam';
|
|
select * from v1;
|
|
drop view v1;
|
|
# autogenerated names differ by case only
|
|
create view v1 as select 'k','K';
|
|
select * from v1;
|
|
drop view v1;
|
|
create table t1 (s1 int);
|
|
# same autogenerated names
|
|
create view v1 as select s1, 's1' from t1;
|
|
select * from v1;
|
|
drop view v1;
|
|
create view v1 as select 's1', s1 from t1;
|
|
select * from v1;
|
|
drop view v1;
|
|
# set name as one of expected autogenerated
|
|
create view v1 as select 's1', s1, 1 as My_exp_s1 from t1;
|
|
select * from v1;
|
|
drop view v1;
|
|
create view v1 as select 1 as My_exp_s1, 's1', s1 from t1;
|
|
select * from v1;
|
|
drop view v1;
|
|
# set name conflict with autogenerated names
|
|
create view v1 as select 1 as s1, 's1', 's1' from t1;
|
|
select * from v1;
|
|
drop view v1;
|
|
create view v1 as select 's1', 's1', 1 as s1 from t1;
|
|
select * from v1;
|
|
drop view v1;
|
|
# underlying field name conflict with autogenerated names
|
|
create view v1 as select s1, 's1', 's1' from t1;
|
|
select * from v1;
|
|
drop view v1;
|
|
create view v1 as select 's1', 's1', s1 from t1;
|
|
select * from v1;
|
|
drop view v1;
|
|
# underlying field name conflict with set name
|
|
-- error ER_DUP_FIELDNAME
|
|
create view v1 as select 1 as s1, 's1', s1 from t1;
|
|
-- error ER_DUP_FIELDNAME
|
|
create view v1 as select 's1', s1, 1 as s1 from t1;
|
|
drop table t1;
|
|
# set names differ by case only
|
|
-- error ER_DUP_FIELDNAME
|
|
create view v1(k, K) as select 1,2;
|
|
|
|
#
|
|
# using time_format in view (Bug#7521)
|
|
#
|
|
create view v1 as SELECT TIME_FORMAT(SEC_TO_TIME(3600),'%H:%i') as t;
|
|
select * from v1;
|
|
drop view v1;
|
|
|
|
#
|
|
# evaluation constant functions in WHERE (Bug#4663)
|
|
#
|
|
create table t1 (a timestamp default now());
|
|
create table t2 (b timestamp default now());
|
|
create view v1 as select a,b,t1.a < now() from t1,t2 where t1.a < now();
|
|
SHOW CREATE VIEW v1;
|
|
drop view v1;
|
|
drop table t1, t2;
|
|
CREATE TABLE t1 ( a varchar(50) );
|
|
CREATE VIEW v1 AS SELECT * FROM t1 WHERE a = CURRENT_USER();
|
|
SHOW CREATE VIEW v1;
|
|
DROP VIEW v1;
|
|
CREATE VIEW v1 AS SELECT * FROM t1 WHERE a = VERSION();
|
|
SHOW CREATE VIEW v1;
|
|
DROP VIEW v1;
|
|
CREATE VIEW v1 AS SELECT * FROM t1 WHERE a = DATABASE();
|
|
SHOW CREATE VIEW v1;
|
|
DROP VIEW v1;
|
|
DROP TABLE t1;
|
|
|
|
#
|
|
# checking views after some view with error (Bug#11337)
|
|
#
|
|
CREATE TABLE t1 (col1 time);
|
|
CREATE TABLE t2 (col1 time);
|
|
CREATE VIEW v1 AS SELECT CONVERT_TZ(col1,'GMT','MET') FROM t1;
|
|
CREATE VIEW v2 AS SELECT CONVERT_TZ(col1,'GMT','MET') FROM t2;
|
|
CREATE VIEW v3 AS SELECT CONVERT_TZ(col1,'GMT','MET') FROM t1;
|
|
CREATE VIEW v4 AS SELECT CONVERT_TZ(col1,'GMT','MET') FROM t2;
|
|
CREATE VIEW v5 AS SELECT CONVERT_TZ(col1,'GMT','MET') FROM t1;
|
|
CREATE VIEW v6 AS SELECT CONVERT_TZ(col1,'GMT','MET') FROM t2;
|
|
DROP TABLE t1;
|
|
CHECK TABLE v1, v2, v3, v4, v5, v6;
|
|
drop view v1, v2, v3, v4, v5, v6;
|
|
drop table t2;
|
|
|
|
--disable_warnings
|
|
drop function if exists f1;
|
|
drop function if exists f2;
|
|
--enable_warnings
|
|
CREATE TABLE t1 (col1 time);
|
|
CREATE TABLE t2 (col1 time);
|
|
CREATE TABLE t3 (col1 time);
|
|
create function f1 () returns int return (select max(col1) from t1);
|
|
create function f2 () returns int return (select max(col1) from t2);
|
|
CREATE VIEW v1 AS SELECT f1() FROM t3;
|
|
CREATE VIEW v2 AS SELECT f2() FROM t3;
|
|
CREATE VIEW v3 AS SELECT f1() FROM t3;
|
|
CREATE VIEW v4 AS SELECT f2() FROM t3;
|
|
CREATE VIEW v5 AS SELECT f1() FROM t3;
|
|
CREATE VIEW v6 AS SELECT f2() FROM t3;
|
|
drop function f1;
|
|
CHECK TABLE v1, v2, v3, v4, v5, v6;
|
|
create function f1 () returns int return (select max(col1) from t1);
|
|
DROP TABLE t1;
|
|
CHECK TABLE v1, v2, v3, v4, v5, v6;
|
|
drop function f1;
|
|
drop function f2;
|
|
drop view v1, v2, v3, v4, v5, v6;
|
|
drop table t2,t3;
|
|
|
|
#
|
|
# Bug#11325 Wrong date comparison in views
|
|
#
|
|
create table t1 (f1 date);
|
|
insert into t1 values ('2005-01-01'),('2005-02-02');
|
|
create view v1 as select * from t1;
|
|
select * from v1 where f1='2005.02.02';
|
|
select * from v1 where '2005.02.02'=f1;
|
|
drop view v1;
|
|
drop table t1;
|
|
|
|
#
|
|
# using encrypt & substring_index in view (Bug#7024)
|
|
#
|
|
CREATE VIEW v1 AS SELECT ENCRYPT("dhgdhgd");
|
|
disable_result_log;
|
|
SELECT * FROM v1;
|
|
enable_result_log;
|
|
drop view v1;
|
|
CREATE VIEW v1 AS SELECT SUBSTRING_INDEX("dkjhgd:kjhdjh", ":", 1);
|
|
SELECT * FROM v1;
|
|
drop view v1;
|
|
|
|
#
|
|
# hide underlying tables names in case of imposibility to update (Bug#10773)
|
|
#
|
|
create table t1 (f59 int, f60 int, f61 int);
|
|
insert into t1 values (19,41,32);
|
|
create view v1 as select f59, f60 from t1 where f59 in
|
|
(select f59 from t1);
|
|
-- error ER_NON_UPDATABLE_TABLE
|
|
update v1 set f60=2345;
|
|
-- error ER_VIEW_PREVENT_UPDATE
|
|
update t1 set f60=(select max(f60) from v1);
|
|
drop view v1;
|
|
drop table t1;
|
|
|
|
#
|
|
# Using var_samp with view (Bug#10651)
|
|
#
|
|
create table t1 (s1 int);
|
|
create view v1 as select var_samp(s1) from t1;
|
|
show create view v1;
|
|
drop view v1;
|
|
drop table t1;
|
|
|
|
|
|
#
|
|
# Correct inserting data check (absence of default value) for view
|
|
# underlying tables (Bug#6443)
|
|
#
|
|
set sql_mode='strict_all_tables';
|
|
CREATE TABLE t1 (col1 INT NOT NULL, col2 INT NOT NULL);
|
|
CREATE VIEW v1 (vcol1) AS SELECT col1 FROM t1;
|
|
CREATE VIEW v2 (vcol1) AS SELECT col1 FROM t1 WHERE col2 > 2;
|
|
-- error ER_NO_DEFAULT_FOR_FIELD
|
|
INSERT INTO t1 (col1) VALUES(12);
|
|
-- error ER_NO_DEFAULT_FOR_VIEW_FIELD
|
|
INSERT INTO v1 (vcol1) VALUES(12);
|
|
-- error ER_NO_DEFAULT_FOR_VIEW_FIELD
|
|
INSERT INTO v2 (vcol1) VALUES(12);
|
|
set sql_mode=default;
|
|
drop view v2,v1;
|
|
drop table t1;
|
|
|
|
|
|
#
|
|
# Bug#11399 Use an alias in a select statement on a view
|
|
#
|
|
create table t1 (f1 int);
|
|
insert into t1 values (1);
|
|
create view v1 as select f1 from t1;
|
|
select f1 as alias from v1;
|
|
drop view v1;
|
|
drop table t1;
|
|
|
|
|
|
#
|
|
# Test for Bug#6120 SP cache to be invalidated when altering a view
|
|
#
|
|
|
|
CREATE TABLE t1 (s1 int, s2 int);
|
|
INSERT INTO t1 VALUES (1,2);
|
|
CREATE VIEW v1 AS SELECT s2 AS s1, s1 AS s2 FROM t1;
|
|
SELECT * FROM v1;
|
|
CREATE PROCEDURE p1 () SELECT * FROM v1;
|
|
CALL p1();
|
|
ALTER VIEW v1 AS SELECT s1 AS s1, s2 AS s2 FROM t1;
|
|
CALL p1();
|
|
DROP VIEW v1;
|
|
CREATE VIEW v1 AS SELECT s2 AS s1, s1 AS s2 FROM t1;
|
|
CALL p1();
|
|
|
|
DROP PROCEDURE p1;
|
|
DROP VIEW v1;
|
|
DROP TABLE t1;
|
|
|
|
|
|
#
|
|
# Test for Bug#11709 View was ordered by wrong column
|
|
#
|
|
create table t1 (f1 int, f2 int);
|
|
create view v1 as select f1 as f3, f2 as f1 from t1;
|
|
insert into t1 values (1,3),(2,1),(3,2);
|
|
select * from v1 order by f1;
|
|
drop view v1;
|
|
drop table t1;
|
|
|
|
|
|
#
|
|
# Test for Bug#11771 wrong query_id in SELECT * FROM <view>
|
|
#
|
|
CREATE TABLE t1 (f1 char);
|
|
INSERT INTO t1 VALUES ('A');
|
|
CREATE VIEW v1 AS SELECT * FROM t1;
|
|
|
|
INSERT INTO t1 VALUES('B');
|
|
SELECT * FROM v1;
|
|
SELECT * FROM t1;
|
|
|
|
DROP VIEW v1;
|
|
DROP TABLE t1;
|
|
|
|
|
|
#
|
|
# opening table in correct locking mode (Bug#9597)
|
|
#
|
|
CREATE TABLE t1 ( bug_table_seq INTEGER NOT NULL);
|
|
CREATE OR REPLACE VIEW v1 AS SELECT * from t1;
|
|
DROP PROCEDURE IF EXISTS p1;
|
|
delimiter //;
|
|
CREATE PROCEDURE p1 ( )
|
|
BEGIN
|
|
DO (SELECT @next := IFNULL(max(bug_table_seq),0) + 1 FROM v1);
|
|
INSERT INTO t1 VALUES (1);
|
|
END //
|
|
delimiter ;//
|
|
CALL p1();
|
|
DROP PROCEDURE p1;
|
|
DROP VIEW v1;
|
|
DROP TABLE t1;
|
|
|
|
|
|
#
|
|
# Bug#11760 Typo in Item_func_add_time::print() results in NULLs returned
|
|
# subtime() in view
|
|
create table t1(f1 datetime);
|
|
insert into t1 values('2005.01.01 12:0:0');
|
|
create view v1 as select f1, subtime(f1, '1:1:1') as sb from t1;
|
|
select * from v1;
|
|
drop view v1;
|
|
drop table t1;
|
|
|
|
|
|
#
|
|
# Test for Bug#11412 query over a multitable view with GROUP_CONCAT
|
|
#
|
|
CREATE TABLE t1 (
|
|
aid int PRIMARY KEY,
|
|
fn varchar(20) NOT NULL,
|
|
ln varchar(20) NOT NULL
|
|
);
|
|
CREATE TABLE t2 (
|
|
aid int NOT NULL,
|
|
pid int NOT NULL
|
|
);
|
|
INSERT INTO t1 VALUES(1,'a','b'), (2,'c','d');
|
|
INSERT INTO t2 values (1,1), (2,1), (2,2);
|
|
|
|
CREATE VIEW v1 AS SELECT t1.*,t2.pid FROM t1,t2 WHERE t1.aid = t2.aid;
|
|
|
|
SELECT pid,GROUP_CONCAT(CONCAT(fn,' ',ln) ORDER BY 1) FROM t1,t2
|
|
WHERE t1.aid = t2.aid GROUP BY pid;
|
|
SELECT pid,GROUP_CONCAT(CONCAT(fn,' ',ln) ORDER BY 1) FROM v1 GROUP BY pid;
|
|
|
|
DROP VIEW v1;
|
|
DROP TABLE t1,t2;
|
|
|
|
|
|
#
|
|
# Test for Bug#12382 SELECT * FROM view after INSERT command
|
|
#
|
|
|
|
CREATE TABLE t1 (id int PRIMARY KEY, f varchar(255));
|
|
CREATE VIEW v1 AS SELECT id, f FROM t1 WHERE id <= 2;
|
|
INSERT INTO t1 VALUES (2, 'foo2');
|
|
INSERT INTO t1 VALUES (1, 'foo1');
|
|
|
|
SELECT * FROM v1;
|
|
SELECT * FROM v1;
|
|
|
|
DROP VIEW v1;
|
|
DROP TABLE t1;
|
|
|
|
|
|
#
|
|
# Test for Bug#12470 crash for a simple select from a view defined
|
|
# as a join over 5 tables
|
|
|
|
CREATE TABLE t1 (pk int PRIMARY KEY, b int);
|
|
CREATE TABLE t2 (pk int PRIMARY KEY, fk int, INDEX idx(fk));
|
|
CREATE TABLE t3 (pk int PRIMARY KEY, fk int, INDEX idx(fk));
|
|
CREATE TABLE t4 (pk int PRIMARY KEY, fk int, INDEX idx(fk));
|
|
CREATE TABLE t5 (pk int PRIMARY KEY, fk int, INDEX idx(fk));
|
|
CREATE VIEW v1 AS
|
|
SELECT t1.pk as a FROM t1,t2,t3,t4,t5
|
|
WHERE t1.b IS NULL AND
|
|
t1.pk=t2.fk AND t2.pk=t3.fk AND t3.pk=t4.fk AND t4.pk=t5.fk;
|
|
|
|
SELECT a FROM v1;
|
|
|
|
DROP VIEW v1;
|
|
DROP TABLE t1,t2,t3,t4,t5;
|
|
|
|
|
|
#
|
|
# Bug#12298 Typo in function name results in erroneous view being created.
|
|
#
|
|
create view v1 as select timestampdiff(day,'1997-01-01 00:00:00','1997-01-02 00:00:00') as f1;
|
|
select * from v1;
|
|
drop view v1;
|
|
|
|
#
|
|
# repeatable CREATE VIEW statement Bug#12468
|
|
#
|
|
create table t1(a int);
|
|
create procedure p1() create view v1 as select * from t1;
|
|
drop table t1;
|
|
-- error ER_NO_SUCH_TABLE
|
|
call p1();
|
|
-- error ER_NO_SUCH_TABLE
|
|
call p1();
|
|
drop procedure p1;
|
|
|
|
|
|
#
|
|
# Bug#10624 Views with multiple UNION and UNION ALL produce incorrect results
|
|
#
|
|
create table t1 (f1 int);
|
|
create table t2 (f1 int);
|
|
insert into t1 values (1);
|
|
insert into t2 values (2);
|
|
create view v1 as select * from t1 union select * from t2 union all select * from t2;
|
|
select * from v1;
|
|
drop view v1;
|
|
drop table t1,t2;
|
|
|
|
|
|
#
|
|
# Test for Bug#10970 view referring a temporary table indirectly
|
|
#
|
|
|
|
CREATE TEMPORARY TABLE t1 (a int);
|
|
CREATE FUNCTION f1 () RETURNS int RETURN (SELECT COUNT(*) FROM t1);
|
|
-- error ER_VIEW_SELECT_TMPTABLE
|
|
CREATE VIEW v1 AS SELECT f1();
|
|
|
|
DROP FUNCTION f1;
|
|
DROP TABLE t1;
|
|
|
|
|
|
#
|
|
# Bug#12533 (crash on DESCRIBE <view> after renaming base table column)
|
|
#
|
|
--disable_warnings
|
|
DROP TABLE IF EXISTS t1;
|
|
DROP VIEW IF EXISTS v1;
|
|
--enable_warnings
|
|
|
|
CREATE TABLE t1 (f4 CHAR(5));
|
|
CREATE VIEW v1 AS SELECT * FROM t1;
|
|
DESCRIBE v1;
|
|
|
|
ALTER TABLE t1 CHANGE COLUMN f4 f4x CHAR(5);
|
|
--error ER_VIEW_INVALID
|
|
DESCRIBE v1;
|
|
DROP TABLE t1;
|
|
DROP VIEW v1;
|
|
|
|
|
|
#
|
|
# Bug#12489 wrongly printed strcmp() function results in creation of broken
|
|
# view
|
|
create table t1 (f1 char);
|
|
create view v1 as select strcmp(f1,'a') from t1;
|
|
select * from v1;
|
|
drop view v1;
|
|
drop table t1;
|
|
|
|
|
|
#
|
|
# Bug#12922 if(sum(),...) with group from view returns wrong results
|
|
#
|
|
create table t1 (f1 int, f2 int,f3 int);
|
|
insert into t1 values (1,10,20),(2,0,0);
|
|
create view v1 as select * from t1;
|
|
select if(sum(f1)>1,f2,f3) from v1 group by f1;
|
|
drop view v1;
|
|
drop table t1;
|
|
|
|
|
|
# Bug#12941
|
|
#
|
|
--disable_warnings
|
|
create table t1 (
|
|
r_object_id char(16) NOT NULL,
|
|
group_name varchar(32) NOT NULL
|
|
) engine = InnoDB;
|
|
|
|
create table t2 (
|
|
r_object_id char(16) NOT NULL,
|
|
i_position int(11) NOT NULL,
|
|
users_names varchar(32) default NULL
|
|
) Engine = InnoDB;
|
|
--enable_warnings
|
|
|
|
create view v1 as select r_object_id, group_name from t1;
|
|
create view v2 as select r_object_id, i_position, users_names from t2;
|
|
|
|
create unique index r_object_id on t1(r_object_id);
|
|
create index group_name on t1(group_name);
|
|
create unique index r_object_id_i_position on t2(r_object_id,i_position);
|
|
create index users_names on t2(users_names);
|
|
|
|
insert into t1 values('120001a080000542','tstgroup1');
|
|
insert into t2 values('120001a080000542',-1, 'guser01');
|
|
insert into t2 values('120001a080000542',-2, 'guser02');
|
|
|
|
select v1.r_object_id, v2.users_names from v1, v2
|
|
where (v1.group_name='tstgroup1') and v2.r_object_id=v1.r_object_id
|
|
order by users_names;
|
|
|
|
drop view v1, v2;
|
|
drop table t1, t2;
|
|
|
|
|
|
#
|
|
# Bug#6808 Views: CREATE VIEW v ... FROM t AS v fails
|
|
#
|
|
|
|
create table t1 (s1 int);
|
|
create view abc as select * from t1 as abc;
|
|
drop table t1;
|
|
drop view abc;
|
|
|
|
|
|
#
|
|
# Bug#12993 View column rename broken in subselect
|
|
#
|
|
create table t1(f1 char(1));
|
|
create view v1 as select * from t1;
|
|
select * from (select f1 as f2 from v1) v where v.f2='a';
|
|
drop view v1;
|
|
drop table t1;
|
|
|
|
|
|
#
|
|
# Bug#11416 Server crash if using a view that uses function convert_tz
|
|
#
|
|
create view v1 as SELECT CONVERT_TZ('2004-01-01 12:00:00','GMT','MET');
|
|
select * from v1;
|
|
drop view v1;
|
|
|
|
|
|
#
|
|
# Bugs#12963, #13000 wrong creation of VIEW with DAYNAME, DAYOFWEEK, and WEEKDAY
|
|
#
|
|
|
|
CREATE TABLE t1 (date DATE NOT NULL);
|
|
INSERT INTO t1 VALUES ('2005-09-06');
|
|
|
|
CREATE VIEW v1 AS SELECT DAYNAME(date) FROM t1;
|
|
SHOW CREATE VIEW v1;
|
|
|
|
CREATE VIEW v2 AS SELECT DAYOFWEEK(date) FROM t1;
|
|
SHOW CREATE VIEW v2;
|
|
|
|
CREATE VIEW v3 AS SELECT WEEKDAY(date) FROM t1;
|
|
SHOW CREATE VIEW v3;
|
|
|
|
SELECT DAYNAME('2005-09-06');
|
|
SELECT DAYNAME(date) FROM t1;
|
|
SELECT * FROM v1;
|
|
|
|
SELECT DAYOFWEEK('2005-09-06');
|
|
SELECT DAYOFWEEK(date) FROM t1;
|
|
SELECT * FROM v2;
|
|
|
|
SELECT WEEKDAY('2005-09-06');
|
|
SELECT WEEKDAY(date) FROM t1;
|
|
SELECT * FROM v3;
|
|
|
|
DROP TABLE t1;
|
|
DROP VIEW v1, v2, v3;
|
|
|
|
|
|
#
|
|
# Bug#13411 crash when using non-qualified view column in HAVING clause
|
|
#
|
|
|
|
CREATE TABLE t1 ( a int, b int );
|
|
INSERT INTO t1 VALUES (1,1),(2,2),(3,3);
|
|
CREATE VIEW v1 AS SELECT a,b FROM t1;
|
|
SELECT t1.a FROM t1 GROUP BY t1.a HAVING a > 1;
|
|
SELECT v1.a FROM v1 GROUP BY v1.a HAVING a > 1;
|
|
|
|
DROP VIEW v1;
|
|
DROP TABLE t1;
|
|
|
|
|
|
#
|
|
# Bug#13410 failed name resolution for qualified view column in HAVING
|
|
#
|
|
|
|
CREATE TABLE t1 ( a int, b int );
|
|
INSERT INTO t1 VALUES (1,1),(2,2),(3,3);
|
|
CREATE VIEW v1 AS SELECT a,b FROM t1;
|
|
SELECT t1.a FROM t1 GROUP BY t1.a HAVING t1.a > 1;
|
|
SELECT v1.a FROM v1 GROUP BY v1.a HAVING v1.a > 1;
|
|
SELECT t_1.a FROM t1 AS t_1 GROUP BY t_1.a HAVING t_1.a IN (1,2,3);
|
|
SELECT v_1.a FROM v1 AS v_1 GROUP BY v_1.a HAVING v_1.a IN (1,2,3);
|
|
|
|
DROP VIEW v1;
|
|
DROP TABLE t1;
|
|
|
|
|
|
#
|
|
# Bug#13327 view wasn't using index for const condition
|
|
#
|
|
|
|
CREATE TABLE t1 (a INT, b INT, INDEX(a,b));
|
|
CREATE TABLE t2 LIKE t1;
|
|
CREATE TABLE t3 (a INT);
|
|
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),(2),(3);
|
|
CREATE VIEW v1 AS SELECT t1.* FROM t1,t2 WHERE t1.a=t2.a AND t1.b=t2.b;
|
|
CREATE VIEW v2 AS SELECT t3.* FROM t1,t3 WHERE t1.a=t3.a;
|
|
EXPLAIN SELECT t1.* FROM t1 JOIN t2 WHERE t1.a=t2.a AND t1.b=t2.b AND t1.a=1;
|
|
EXPLAIN SELECT * FROM v1 WHERE a=1;
|
|
EXPLAIN SELECT * FROM v2 WHERE a=1;
|
|
DROP VIEW v1,v2;
|
|
DROP TABLE t1,t2,t3;
|
|
|
|
|
|
#
|
|
# Bug#13622 Wrong view .frm created if some field's alias contain \n
|
|
#
|
|
create table t1 (f1 int);
|
|
create view v1 as select t1.f1 as '123
|
|
456' from t1;
|
|
select * from v1;
|
|
drop view v1;
|
|
drop table t1;
|
|
|
|
|
|
# Bug#14466 lost sort order in GROUP_CONCAT() in a view
|
|
#
|
|
create table t1 (f1 int, f2 int);
|
|
insert into t1 values(1,1),(1,2),(1,3);
|
|
create view v1 as select f1 ,group_concat(f2 order by f2 asc) from t1 group by f1;
|
|
create view v2 as select f1 ,group_concat(f2 order by f2 desc) from t1 group by f1;
|
|
select * from v1;
|
|
select * from v2;
|
|
drop view v1,v2;
|
|
drop table t1;
|
|
|
|
|
|
#
|
|
# Bug#14026 Crash on second PS execution when using views
|
|
#
|
|
create table t1 (x int, y int);
|
|
create table t2 (x int, y int, z int);
|
|
create table t3 (x int, y int, z int);
|
|
create table t4 (x int, y int, z int);
|
|
|
|
create view v1 as
|
|
select t1.x
|
|
from (
|
|
(t1 join t2 on ((t1.y = t2.y)))
|
|
join
|
|
(t3 left join t4 on (t3.y = t4.y) and (t3.z = t4.z))
|
|
);
|
|
|
|
prepare stmt1 from "select count(*) from v1 where x = ?";
|
|
set @parm1=1;
|
|
|
|
execute stmt1 using @parm1;
|
|
execute stmt1 using @parm1;
|
|
drop view v1;
|
|
drop table t1,t2,t3,t4;
|
|
|
|
|
|
#
|
|
# Bug#14540 OPTIMIZE, ANALYZE, REPAIR applied to not a view
|
|
#
|
|
|
|
CREATE TABLE t1(id INT);
|
|
CREATE VIEW v1 AS SELECT id FROM t1;
|
|
|
|
OPTIMIZE TABLE v1;
|
|
ANALYZE TABLE v1;
|
|
REPAIR TABLE v1;
|
|
|
|
DROP TABLE t1;
|
|
OPTIMIZE TABLE v1;
|
|
ANALYZE TABLE v1;
|
|
REPAIR TABLE v1;
|
|
|
|
DROP VIEW v1;
|
|
|
|
|
|
#
|
|
# Bug#14719 Views DEFINER grammar is incorrect
|
|
#
|
|
|
|
create definer = current_user() sql security invoker view v1 as select 1;
|
|
show create view v1;
|
|
drop view v1;
|
|
|
|
create definer = current_user sql security invoker view v1 as select 1;
|
|
show create view v1;
|
|
drop view v1;
|
|
|
|
|
|
#
|
|
# Bug#14816 test_if_order_by_key() expected only Item_fields.
|
|
#
|
|
create table t1 (id INT, primary key(id));
|
|
insert into t1 values (1),(2);
|
|
create view v1 as select * from t1;
|
|
explain select id from v1 order by id;
|
|
drop view v1;
|
|
drop table t1;
|
|
|
|
|
|
#
|
|
# Bug#14850 Item_ref's values wasn't updated
|
|
#
|
|
create table t1(f1 int, f2 int);
|
|
insert into t1 values (null, 10), (null,2);
|
|
select f1, sum(f2) from t1 group by f1;
|
|
create view v1 as select * from t1;
|
|
select f1, sum(f2) from v1 group by f1;
|
|
drop view v1;
|
|
drop table t1;
|
|
|
|
|
|
#
|
|
# Bug#14885 incorrect SOURCE in view created in a procedure
|
|
# TODO: here SOURCE string must be shown when it will be possible
|
|
#
|
|
--disable_warnings
|
|
drop procedure if exists p1;
|
|
--enable_warnings
|
|
delimiter //;
|
|
create procedure p1 () deterministic
|
|
begin
|
|
create view v1 as select 1;
|
|
end;
|
|
//
|
|
delimiter ;//
|
|
call p1();
|
|
show create view v1;
|
|
drop view v1;
|
|
drop procedure p1;
|
|
|
|
|
|
#
|
|
# Bug#15096 using function with view for view creation
|
|
#
|
|
CREATE VIEW v1 AS SELECT 42 AS Meaning;
|
|
--disable_warnings
|
|
DROP FUNCTION IF EXISTS f1;
|
|
--enable_warnings
|
|
DELIMITER //;
|
|
CREATE FUNCTION f1() RETURNS INTEGER
|
|
BEGIN
|
|
DECLARE retn INTEGER;
|
|
SELECT Meaning FROM v1 INTO retn;
|
|
RETURN retn;
|
|
END
|
|
//
|
|
DELIMITER ;//
|
|
CREATE VIEW v2 AS SELECT f1();
|
|
select * from v2;
|
|
drop view v2,v1;
|
|
drop function f1;
|
|
|
|
|
|
#
|
|
# Bug#14861 aliased column names are not preserved.
|
|
#
|
|
create table t1 (id numeric, warehouse_id numeric);
|
|
create view v1 as select id from t1;
|
|
create view v2 as
|
|
select t1.warehouse_id, v1.id as receipt_id
|
|
from t1, v1 where t1.id = v1.id;
|
|
|
|
insert into t1 (id, warehouse_id) values(3, 2);
|
|
insert into t1 (id, warehouse_id) values(4, 2);
|
|
insert into t1 (id, warehouse_id) values(5, 1);
|
|
|
|
select v2.receipt_id as alias1, v2.receipt_id as alias2 from v2
|
|
order by v2.receipt_id;
|
|
|
|
drop view v2, v1;
|
|
drop table t1;
|
|
|
|
|
|
#
|
|
# Bug#16016 MIN/MAX optimization for views
|
|
#
|
|
|
|
CREATE TABLE t1 (a int PRIMARY KEY, b int);
|
|
INSERT INTO t1 VALUES (2,20), (3,10), (1,10), (0,30), (5,10);
|
|
|
|
CREATE VIEW v1 AS SELECT * FROM t1;
|
|
|
|
SELECT MAX(a) FROM t1;
|
|
SELECT MAX(a) FROM v1;
|
|
|
|
EXPLAIN SELECT MAX(a) FROM t1;
|
|
EXPLAIN SELECT MAX(a) FROM v1;
|
|
|
|
SELECT MIN(a) FROM t1;
|
|
SELECT MIN(a) FROM v1;
|
|
|
|
EXPLAIN SELECT MIN(a) FROM t1;
|
|
EXPLAIN SELECT MIN(a) FROM v1;
|
|
|
|
DROP VIEW v1;
|
|
DROP TABLE t1;
|
|
|
|
|
|
#
|
|
# Bug#16382 grouping name is resolved against a view column name
|
|
# which coincides with a select column name
|
|
|
|
CREATE TABLE t1 (x varchar(10));
|
|
INSERT INTO t1 VALUES (null), ('foo'), ('bar'), (null);
|
|
CREATE VIEW v1 AS SELECT * FROM t1;
|
|
|
|
SELECT IF(x IS NULL, 'blank', 'not blank') FROM v1 GROUP BY x;
|
|
SELECT IF(x IS NULL, 'blank', 'not blank') AS x FROM t1 GROUP BY x;
|
|
SELECT IF(x IS NULL, 'blank', 'not blank') AS x FROM v1;
|
|
SELECT IF(x IS NULL, 'blank', 'not blank') AS y FROM v1 GROUP BY y;
|
|
SELECT IF(x IS NULL, 'blank', 'not blank') AS x FROM v1 GROUP BY x;
|
|
|
|
DROP VIEW v1;
|
|
DROP TABLE t1;
|
|
|
|
|
|
#
|
|
# Bug#15943 mysql_next_result hangs on invalid SHOW CREATE VIEW
|
|
#
|
|
|
|
delimiter //;
|
|
drop table if exists t1;
|
|
drop view if exists v1;
|
|
create table t1 (id int);
|
|
create view v1 as select * from t1;
|
|
drop table t1;
|
|
show create view v1;
|
|
drop view v1;
|
|
//
|
|
delimiter ;//
|
|
|
|
|
|
#
|
|
# Bug#17726 Not checked empty list caused endless loop
|
|
#
|
|
create table t1(f1 int, f2 int);
|
|
create view v1 as select ta.f1 as a, tb.f1 as b from t1 ta, t1 tb where ta.f1=tb
|
|
.f1 and ta.f2=tb.f2;
|
|
insert into t1 values(1,1),(2,2);
|
|
create view v2 as select * from v1 where a > 1 with local check option;
|
|
select * from v2;
|
|
update v2 set b=3 where a=2;
|
|
select * from v2;
|
|
drop view v2, v1;
|
|
drop table t1;
|
|
|
|
|
|
#
|
|
# Bug#18386 select from view over a table with ORDER BY view_col clause
|
|
# given view_col is not an image of any column from the base table
|
|
|
|
CREATE TABLE t1 (a int);
|
|
INSERT INTO t1 VALUES (1), (2);
|
|
|
|
CREATE VIEW v1 AS SELECT SQRT(a) my_sqrt FROM t1;
|
|
|
|
SELECT my_sqrt FROM v1 ORDER BY my_sqrt;
|
|
|
|
DROP VIEW v1;
|
|
DROP TABLE t1;
|
|
|
|
|
|
#
|
|
# Bug#18237 invalid count optimization applied to an outer join with a view
|
|
#
|
|
|
|
CREATE TABLE t1 (id int PRIMARY KEY);
|
|
CREATE TABLE t2 (id int PRIMARY KEY);
|
|
|
|
INSERT INTO t1 VALUES (1), (3);
|
|
INSERT INTO t2 VALUES (1), (2), (3);
|
|
|
|
CREATE VIEW v2 AS SELECT * FROM t2;
|
|
|
|
SELECT COUNT(*) FROM t1 LEFT JOIN t2 ON t1.id=t2.id;
|
|
SELECT * FROM t1 LEFT JOIN t2 ON t1.id=t2.id;
|
|
|
|
SELECT COUNT(*) FROM t1 LEFT JOIN v2 ON t1.id=v2.id;
|
|
|
|
DROP VIEW v2;
|
|
|
|
DROP TABLE t1, t2;
|
|
|
|
|
|
#
|
|
# Bug#16069 VIEW does return the same results as underlying SELECT
|
|
# with WHERE condition containing BETWEEN over dates
|
|
# Dates as strings should be casted to date type
|
|
|
|
CREATE TABLE t1 (id int NOT NULL PRIMARY KEY,
|
|
td date DEFAULT NULL, KEY idx(td));
|
|
|
|
INSERT INTO t1 VALUES
|
|
(1, '2005-01-01'), (2, '2005-01-02'), (3, '2005-01-02'),
|
|
(4, '2005-01-03'), (5, '2005-01-04'), (6, '2005-01-05'),
|
|
(7, '2005-01-05'), (8, '2005-01-05'), (9, '2005-01-06');
|
|
|
|
CREATE VIEW v1 AS SELECT * FROM t1;
|
|
|
|
SELECT * FROM t1 WHERE td BETWEEN CAST('2005.01.02' AS DATE) AND CAST('2005.01.04' AS DATE);
|
|
SELECT * FROM v1 WHERE td BETWEEN CAST('2005.01.02' AS DATE) AND CAST('2005.01.04' AS DATE);
|
|
|
|
DROP VIEW v1;
|
|
DROP TABLE t1;
|
|
|
|
|
|
#
|
|
# Bug#14308 Recursive view definitions
|
|
#
|
|
# using view only
|
|
create table t1 (a int);
|
|
create view v1 as select * from t1;
|
|
create view v2 as select * from v1;
|
|
drop table t1;
|
|
rename table v2 to t1;
|
|
-- error ER_VIEW_RECURSIVE
|
|
select * from v1;
|
|
drop view t1, v1;
|
|
# using SP function
|
|
create table t1 (a int);
|
|
delimiter //;
|
|
create function f1() returns int
|
|
begin
|
|
declare mx int;
|
|
select max(a) from t1 into mx;
|
|
return mx;
|
|
end//
|
|
delimiter ;//
|
|
create view v1 as select f1() as a;
|
|
create view v2 as select * from v1;
|
|
drop table t1;
|
|
rename table v2 to t1;
|
|
-- error ER_SP_NO_RECURSION
|
|
select * from v1;
|
|
drop function f1;
|
|
drop view t1, v1;
|
|
|
|
|
|
#
|
|
# Bug#15153 CONVERT_TZ() is not allowed in all places in VIEWs
|
|
#
|
|
# Error was reported when one tried to use CONVERT_TZ() function
|
|
# select list of view which was processed using MERGE algorithm.
|
|
# (Also see additional test in timezone_grant.test)
|
|
create table t1 (dt datetime);
|
|
insert into t1 values (20040101000000), (20050101000000), (20060101000000);
|
|
# Let us test that convert_tz() can be used in view's select list
|
|
create view v1 as select convert_tz(dt, 'UTC', 'Europe/Moscow') as ldt from t1;
|
|
select * from v1;
|
|
drop view v1;
|
|
# And in its where part
|
|
create view v1 as select * from t1 where convert_tz(dt, 'UTC', 'Europe/Moscow') >= 20050101000000;
|
|
select * from v1;
|
|
# Other interesting case - a view which uses convert_tz() function
|
|
# through other view.
|
|
create view v2 as select * from v1 where dt < 20060101000000;
|
|
select * from v2;
|
|
drop view v2;
|
|
# And even more interesting case when view uses convert_tz() both
|
|
# directly and indirectly
|
|
create view v2 as select convert_tz(dt, 'UTC', 'Europe/Moscow') as ldt from v1;
|
|
select * from v2;
|
|
drop view v1, v2;
|
|
drop table t1;
|
|
|
|
|
|
#
|
|
# Bug#19490 usage of view specified by a query with GROUP BY
|
|
# an expression containing non-constant interval
|
|
|
|
CREATE TABLE t1 (id int NOT NULL PRIMARY KEY, d datetime);
|
|
|
|
CREATE VIEW v1 AS
|
|
SELECT id, date(d) + INTERVAL TIME_TO_SEC(d) SECOND AS t, COUNT(*)
|
|
FROM t1 GROUP BY id, t;
|
|
|
|
SHOW CREATE VIEW v1;
|
|
SELECT * FROM v1;
|
|
|
|
DROP VIEW v1;
|
|
DROP TABLE t1;
|
|
|
|
|
|
#
|
|
# Bug#19077 A nested materialized view is used before being populated.
|
|
#
|
|
CREATE TABLE t1 (i INT, j BIGINT);
|
|
INSERT INTO t1 VALUES (1, 2), (2, 2), (3, 2);
|
|
CREATE VIEW v1 AS SELECT MIN(j) AS j FROM t1;
|
|
CREATE VIEW v2 AS SELECT MIN(i) FROM t1 WHERE j = ( SELECT * FROM v1 );
|
|
SELECT * FROM v2;
|
|
DROP VIEW v2, v1;
|
|
DROP TABLE t1;
|
|
|
|
|
|
#
|
|
# Bug#19573 VIEW with HAVING that refers an alias name
|
|
#
|
|
|
|
CREATE TABLE t1(
|
|
fName varchar(25) NOT NULL,
|
|
lName varchar(25) NOT NULL,
|
|
DOB date NOT NULL,
|
|
test_date date NOT NULL,
|
|
uID int unsigned NOT NULL AUTO_INCREMENT PRIMARY KEY);
|
|
|
|
INSERT INTO t1(fName, lName, DOB, test_date) VALUES
|
|
('Hank', 'Hill', '1964-09-29', '2007-01-01'),
|
|
('Tom', 'Adams', '1908-02-14', '2007-01-01'),
|
|
('Homer', 'Simpson', '1968-03-05', '2007-01-01');
|
|
|
|
CREATE VIEW v1 AS
|
|
SELECT (year(test_date)-year(DOB)) AS Age
|
|
FROM t1 HAVING Age < 75;
|
|
SHOW CREATE VIEW v1;
|
|
|
|
SELECT (year(test_date)-year(DOB)) AS Age FROM t1 HAVING Age < 75;
|
|
SELECT * FROM v1;
|
|
|
|
DROP VIEW v1;
|
|
DROP TABLE t1;
|
|
|
|
|
|
#
|
|
# Bug#19089 wrong inherited dafault values in temp table views
|
|
#
|
|
|
|
CREATE TABLE t1 (id int NOT NULL PRIMARY KEY, a char(6) DEFAULT 'xxx');
|
|
INSERT INTO t1(id) VALUES (1), (2), (3), (4);
|
|
INSERT INTO t1 VALUES (5,'yyy'), (6,'yyy');
|
|
SELECT * FROM t1;
|
|
|
|
CREATE VIEW v1(a, m) AS SELECT a, MIN(id) FROM t1 GROUP BY a;
|
|
SELECT * FROM v1;
|
|
|
|
CREATE TABLE t2 SELECT * FROM v1;
|
|
INSERT INTO t2(m) VALUES (0);
|
|
SELECT * FROM t2;
|
|
|
|
DROP VIEW v1;
|
|
DROP TABLE t1,t2;
|
|
|
|
CREATE TABLE t1 (id int PRIMARY KEY, e ENUM('a','b') NOT NULL DEFAULT 'b');
|
|
INSERT INTO t1(id) VALUES (1), (2), (3);
|
|
INSERT INTO t1 VALUES (4,'a');
|
|
SELECT * FROM t1;
|
|
|
|
CREATE VIEW v1(m, e) AS SELECT MIN(id), e FROM t1 GROUP BY e;
|
|
CREATE TABLE t2 SELECT * FROM v1;
|
|
SELECT * FROM t2;
|
|
|
|
DROP VIEW v1;
|
|
DROP TABLE t1,t2;
|
|
|
|
|
|
#
|
|
# Bug#16110 insert permitted into view col w/o default value
|
|
#
|
|
CREATE TABLE t1 (a INT NOT NULL, b INT NULL DEFAULT NULL);
|
|
CREATE VIEW v1 AS SELECT a, b FROM t1;
|
|
|
|
INSERT INTO v1 (b) VALUES (2);
|
|
|
|
SET SQL_MODE = STRICT_ALL_TABLES;
|
|
--error ER_NO_DEFAULT_FOR_VIEW_FIELD
|
|
INSERT INTO v1 (b) VALUES (4);
|
|
SET SQL_MODE = '';
|
|
|
|
SELECT * FROM t1;
|
|
|
|
DROP VIEW v1;
|
|
DROP TABLE t1;
|
|
|
|
|
|
#
|
|
# Bug#18243 expression over a view column that with the REVERSE function
|
|
#
|
|
|
|
CREATE TABLE t1 (firstname text, surname text);
|
|
INSERT INTO t1 VALUES
|
|
("Bart","Simpson"),("Milhouse","van Houten"),("Montgomery","Burns");
|
|
|
|
CREATE VIEW v1 AS SELECT CONCAT(firstname," ",surname) AS name FROM t1;
|
|
SELECT CONCAT(LEFT(name,LENGTH(name)-INSTR(REVERSE(name)," ")),
|
|
LEFT(name,LENGTH(name)-INSTR(REVERSE(name)," "))) AS f1
|
|
FROM v1;
|
|
|
|
DROP VIEW v1;
|
|
DROP TABLE t1;
|
|
|
|
|
|
#
|
|
# Bug#19714 wrong type of a view column specified by an expressions over ints
|
|
#
|
|
|
|
CREATE TABLE t1 (i int, j int);
|
|
CREATE VIEW v1 AS SELECT COALESCE(i,j) FROM t1;
|
|
DESCRIBE v1;
|
|
CREATE TABLE t2 SELECT COALESCE(i,j) FROM t1;
|
|
DESCRIBE t2;
|
|
|
|
DROP VIEW v1;
|
|
DROP TABLE t1,t2;
|
|
|
|
|
|
#
|
|
# Bug#17526 views with TRIM functions
|
|
#
|
|
|
|
CREATE TABLE t1 (s varchar(10));
|
|
INSERT INTO t1 VALUES ('yadda'), ('yady');
|
|
|
|
SELECT TRIM(BOTH 'y' FROM s) FROM t1;
|
|
CREATE VIEW v1 AS SELECT TRIM(BOTH 'y' FROM s) FROM t1;
|
|
SELECT * FROM v1;
|
|
DROP VIEW v1;
|
|
|
|
SELECT TRIM(LEADING 'y' FROM s) FROM t1;
|
|
CREATE VIEW v1 AS SELECT TRIM(LEADING 'y' FROM s) FROM t1;
|
|
SELECT * FROM v1;
|
|
DROP VIEW v1;
|
|
|
|
SELECT TRIM(TRAILING 'y' FROM s) FROM t1;
|
|
CREATE VIEW v1 AS SELECT TRIM(TRAILING 'y' FROM s) FROM t1;
|
|
SELECT * FROM v1;
|
|
DROP VIEW v1;
|
|
|
|
DROP TABLE t1;
|
|
|
|
|
|
#
|
|
# Bug#21080 ALTER VIEW makes user restate SQL SECURITY mode, and ALGORITHM
|
|
#
|
|
CREATE TABLE t1 (x INT, y INT);
|
|
CREATE ALGORITHM=TEMPTABLE SQL SECURITY INVOKER VIEW v1 AS SELECT x FROM t1;
|
|
SHOW CREATE VIEW v1;
|
|
|
|
ALTER VIEW v1 AS SELECT x, y FROM t1;
|
|
SHOW CREATE VIEW v1;
|
|
|
|
DROP VIEW v1;
|
|
DROP TABLE t1;
|
|
|
|
|
|
# Bug#21086 server crashes when VIEW defined with a SELECT with COLLATE
|
|
# clause is called
|
|
#
|
|
CREATE TABLE t1 (s1 char);
|
|
INSERT INTO t1 VALUES ('Z');
|
|
|
|
CREATE VIEW v1 AS SELECT s1 collate latin1_german1_ci AS col FROM t1;
|
|
|
|
CREATE VIEW v2 (col) AS SELECT s1 collate latin1_german1_ci FROM t1;
|
|
|
|
# either of these statements will cause crash
|
|
INSERT INTO v1 (col) VALUES ('b');
|
|
INSERT INTO v2 (col) VALUES ('c');
|
|
|
|
SELECT s1 FROM t1;
|
|
DROP VIEW v1, v2;
|
|
DROP TABLE t1;
|
|
|
|
|
|
#
|
|
# Bug#11551 Asymmetric + undocumented behaviour of DROP VIEW and DROP TABLE
|
|
#
|
|
CREATE TABLE t1 (id INT);
|
|
CREATE VIEW v1 AS SELECT id FROM t1;
|
|
SHOW TABLES;
|
|
|
|
--error ER_BAD_TABLE_ERROR
|
|
DROP VIEW v2,v1;
|
|
SHOW TABLES;
|
|
|
|
CREATE VIEW v1 AS SELECT id FROM t1;
|
|
--error ER_WRONG_OBJECT
|
|
DROP VIEW t1,v1;
|
|
SHOW TABLES;
|
|
|
|
DROP TABLE t1;
|
|
--disable_warnings
|
|
DROP VIEW IF EXISTS v1;
|
|
--enable_warnings
|
|
|
|
|
|
#
|
|
# Bug#21261 Wrong access rights was required for an insert to a view
|
|
#
|
|
CREATE DATABASE bug21261DB;
|
|
USE bug21261DB;
|
|
connect (root,localhost,root,,bug21261DB);
|
|
connection root;
|
|
|
|
CREATE TABLE t1 (x INT);
|
|
CREATE SQL SECURITY INVOKER VIEW v1 AS SELECT x FROM t1;
|
|
GRANT INSERT, UPDATE ON v1 TO 'user21261'@'localhost';
|
|
GRANT INSERT, UPDATE ON t1 TO 'user21261'@'localhost';
|
|
CREATE TABLE t2 (y INT);
|
|
GRANT SELECT ON t2 TO 'user21261'@'localhost';
|
|
|
|
connect (user21261, localhost, user21261,, bug21261DB);
|
|
connection user21261;
|
|
INSERT INTO v1 (x) VALUES (5);
|
|
UPDATE v1 SET x=1;
|
|
connection root;
|
|
GRANT SELECT ON v1 TO 'user21261'@'localhost';
|
|
GRANT SELECT ON t1 TO 'user21261'@'localhost';
|
|
connection user21261;
|
|
UPDATE v1,t2 SET x=1 WHERE x=y;
|
|
connection root;
|
|
SELECT * FROM t1;
|
|
REVOKE ALL PRIVILEGES, GRANT OPTION FROM 'user21261'@'localhost';
|
|
DROP USER 'user21261'@'localhost';
|
|
DROP VIEW v1;
|
|
DROP TABLE t1;
|
|
DROP DATABASE bug21261DB;
|
|
|
|
connection default;
|
|
USE test;
|
|
disconnect root;
|
|
disconnect user21261;
|
|
|
|
|
|
#
|
|
# Bug#15950 NOW() optimized away in VIEWs
|
|
#
|
|
create table t1 (f1 datetime);
|
|
create view v1 as select * from t1 where f1 between now() and now() + interval 1 minute;
|
|
show create view v1;
|
|
drop view v1;
|
|
drop table t1;
|
|
|
|
|
|
#
|
|
# Test for Bug#16899 Possible buffer overflow in handling of DEFINER-clause.
|
|
#
|
|
|
|
# Prepare.
|
|
|
|
--disable_warnings
|
|
DROP TABLE IF EXISTS t1;
|
|
DROP VIEW IF EXISTS v1;
|
|
DROP VIEW IF EXISTS v2;
|
|
--enable_warnings
|
|
|
|
CREATE TABLE t1(a INT, b INT);
|
|
|
|
--error ER_WRONG_STRING_LENGTH
|
|
CREATE DEFINER=1234567890abcdefGHIKL@localhost
|
|
VIEW v1 AS SELECT a FROM t1;
|
|
|
|
--error ER_WRONG_STRING_LENGTH
|
|
CREATE DEFINER=some_user_name@1234567890abcdefghij1234567890abcdefghij1234567890abcdefghijQWERTY
|
|
VIEW v2 AS SELECT b FROM t1;
|
|
|
|
# Cleanup.
|
|
|
|
DROP TABLE t1;
|
|
|
|
|
|
#
|
|
# Bug#17591 Updatable view not possible with trigger or stored function
|
|
#
|
|
# During prelocking phase we didn't update lock type of view tables,
|
|
# hence READ lock was always requested.
|
|
#
|
|
--disable_warnings
|
|
DROP FUNCTION IF EXISTS f1;
|
|
DROP FUNCTION IF EXISTS f2;
|
|
DROP VIEW IF EXISTS v1, v2;
|
|
DROP TABLE IF EXISTS t1;
|
|
--enable_warnings
|
|
|
|
CREATE TABLE t1 (i INT);
|
|
|
|
CREATE VIEW v1 AS SELECT * FROM t1;
|
|
|
|
delimiter |;
|
|
CREATE FUNCTION f1() RETURNS INT
|
|
BEGIN
|
|
INSERT INTO v1 VALUES (0);
|
|
RETURN 0;
|
|
END |
|
|
delimiter ;|
|
|
|
|
SELECT f1();
|
|
|
|
CREATE ALGORITHM=TEMPTABLE VIEW v2 AS SELECT * FROM t1;
|
|
|
|
delimiter |;
|
|
CREATE FUNCTION f2() RETURNS INT
|
|
BEGIN
|
|
INSERT INTO v2 VALUES (0);
|
|
RETURN 0;
|
|
END |
|
|
delimiter ;|
|
|
|
|
--error ER_NON_INSERTABLE_TABLE
|
|
SELECT f2();
|
|
|
|
DROP FUNCTION f1;
|
|
DROP FUNCTION f2;
|
|
DROP VIEW v1, v2;
|
|
DROP TABLE t1;
|
|
|
|
|
|
#
|
|
# Bug#5500 wrong select_type in EXPLAIN output for queries over views
|
|
#
|
|
|
|
CREATE TABLE t1 (s1 int);
|
|
CREATE VIEW v1 AS SELECT * FROM t1;
|
|
|
|
EXPLAIN SELECT * FROM t1;
|
|
EXPLAIN SELECT * FROM v1;
|
|
|
|
INSERT INTO t1 VALUES (1), (3), (2);
|
|
|
|
EXPLAIN SELECT * FROM t1 t WHERE t.s1+1 < (SELECT MAX(t1.s1) FROM t1);
|
|
EXPLAIN SELECT * FROM v1 t WHERE t.s1+1 < (SELECT MAX(t1.s1) FROM t1);
|
|
|
|
DROP VIEW v1;
|
|
DROP TABLE t1;
|
|
|
|
|
|
#
|
|
# Bug#5505 Wrong error message on INSERT into a view
|
|
#
|
|
create table t1 (s1 int);
|
|
create view v1 as select s1 as a, s1 as b from t1;
|
|
--error ER_NON_INSERTABLE_TABLE
|
|
insert into v1 values (1,1);
|
|
update v1 set a = 5;
|
|
drop view v1;
|
|
drop table t1;
|
|
|
|
|
|
#
|
|
# Bug#21646 view qith a subquery in ON expression
|
|
#
|
|
|
|
CREATE TABLE t1(pk int PRIMARY KEY);
|
|
CREATE TABLE t2(pk int PRIMARY KEY, fk int, ver int, org int);
|
|
|
|
CREATE ALGORITHM=MERGE VIEW v1 AS
|
|
SELECT t1.*
|
|
FROM t1 JOIN t2
|
|
ON t2.fk = t1.pk AND
|
|
t2.ver = (SELECT MAX(t.ver) FROM t2 t WHERE t.org = t2.org);
|
|
SHOW WARNINGS;
|
|
SHOW CREATE VIEW v1;
|
|
|
|
DROP VIEW v1;
|
|
DROP TABLE t1, t2;
|
|
|
|
|
|
#
|
|
# Bug#19111 TRIGGERs selecting from a VIEW on the firing base table fail
|
|
#
|
|
# Allow to select from a view on a table being modified in a trigger
|
|
# and stored function, since plain select is allowed there.
|
|
#
|
|
--disable_warnings
|
|
DROP FUNCTION IF EXISTS f1;
|
|
DROP VIEW IF EXISTS v1;
|
|
DROP TABLE IF EXISTS t1;
|
|
--enable_warnings
|
|
|
|
CREATE TABLE t1 (i INT);
|
|
INSERT INTO t1 VALUES (1);
|
|
|
|
CREATE VIEW v1 AS SELECT MAX(i) FROM t1;
|
|
|
|
# Plain 'SET NEW.i = (SELECT MAX(i) FROM t1) + 1' works, so select
|
|
# from a view should work too.
|
|
CREATE TRIGGER t1_bi BEFORE INSERT ON t1 FOR EACH ROW
|
|
SET NEW.i = (SELECT * FROM v1) + 1;
|
|
INSERT INTO t1 VALUES (1);
|
|
|
|
# Plain 'RETURN (SELECT MAX(i) FROM t1)' works in INSERT, so select
|
|
# from a view should work too.
|
|
CREATE FUNCTION f1() RETURNS INT RETURN (SELECT * FROM v1);
|
|
UPDATE t1 SET i= f1();
|
|
|
|
DROP FUNCTION f1;
|
|
DROP VIEW v1;
|
|
DROP TABLE t1;
|
|
|
|
|
|
#
|
|
# Bug#16813 (WITH CHECK OPTION doesn't work with UPDATE)
|
|
#
|
|
CREATE TABLE t1(id INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, val INT UNSIGNED NOT NULL);
|
|
CREATE VIEW v1 AS SELECT id, val FROM t1 WHERE val >= 1 AND val <= 5 WITH CHECK OPTION;
|
|
INSERT INTO v1 (val) VALUES (2);
|
|
INSERT INTO v1 (val) VALUES (4);
|
|
-- error ER_VIEW_CHECK_FAILED
|
|
INSERT INTO v1 (val) VALUES (6);
|
|
-- error ER_VIEW_CHECK_FAILED
|
|
UPDATE v1 SET val=6 WHERE id=2;
|
|
DROP VIEW v1;
|
|
DROP TABLE t1;
|
|
|
|
|
|
#
|
|
# Bug#22584 last_insert_id not updated after inserting a record
|
|
# through a updatable view
|
|
#
|
|
# We still do not update LAST_INSERT_ID if AUTO_INCREMENT column is
|
|
# not accessible through a view. However, we do not reset the value
|
|
# of LAST_INSERT_ID, but keep it unchanged.
|
|
#
|
|
--disable_warnings
|
|
DROP VIEW IF EXISTS v1, v2;
|
|
DROP TABLE IF EXISTS t1;
|
|
--enable_warnings
|
|
|
|
CREATE TABLE t1 (i INT AUTO_INCREMENT PRIMARY KEY, j INT);
|
|
CREATE VIEW v1 AS SELECT j FROM t1;
|
|
CREATE VIEW v2 AS SELECT * FROM t1;
|
|
|
|
INSERT INTO t1 (j) VALUES (1);
|
|
SELECT LAST_INSERT_ID();
|
|
|
|
INSERT INTO v1 (j) VALUES (2);
|
|
--echo # LAST_INSERT_ID() should not change.
|
|
SELECT LAST_INSERT_ID();
|
|
|
|
INSERT INTO v2 (j) VALUES (3);
|
|
--echo # LAST_INSERT_ID() should be updated.
|
|
SELECT LAST_INSERT_ID();
|
|
|
|
INSERT INTO v1 (j) SELECT j FROM t1;
|
|
--echo # LAST_INSERT_ID() should not change.
|
|
SELECT LAST_INSERT_ID();
|
|
|
|
SELECT * FROM t1;
|
|
|
|
DROP VIEW v1, v2;
|
|
DROP TABLE t1;
|
|
|
|
|
|
#
|
|
# Bug#25580 !0 as an operand in a select expression of a view
|
|
#
|
|
|
|
CREATE VIEW v AS SELECT !0 * 5 AS x FROM DUAL;
|
|
SHOW CREATE VIEW v;
|
|
|
|
SELECT !0 * 5 AS x FROM DUAL;
|
|
SELECT * FROM v;
|
|
|
|
DROP VIEW v;
|
|
|
|
|
|
#
|
|
# Bug#24293 '\Z' token is not handled correctly in views
|
|
#
|
|
|
|
--disable_warnings
|
|
DROP VIEW IF EXISTS v1;
|
|
--enable_warnings
|
|
|
|
CREATE VIEW v1 AS SELECT 'The\ZEnd';
|
|
SELECT * FROM v1;
|
|
|
|
SHOW CREATE VIEW v1;
|
|
|
|
DROP VIEW v1;
|
|
|
|
|
|
#
|
|
# Bug#26124 BETWEEN over a view column of the DATETIME type
|
|
#
|
|
|
|
CREATE TABLE t1 (mydate DATETIME);
|
|
INSERT INTO t1 VALUES
|
|
('2007-01-01'), ('2007-01-02'), ('2007-01-30'), ('2007-01-31');
|
|
|
|
CREATE VIEW v1 AS SELECT mydate from t1;
|
|
|
|
SELECT * FROM t1 WHERE mydate BETWEEN '2007-01-01' AND '2007-01-31';
|
|
SELECT * FROM v1 WHERE mydate BETWEEN '2007-01-01' AND '2007-01-31';
|
|
|
|
DROP VIEW v1;
|
|
DROP TABLE t1;
|
|
|
|
|
|
#
|
|
# Bug#25931 update of a multi-table view with check option
|
|
#
|
|
|
|
CREATE TABLE t1 (a int);
|
|
CREATE TABLE t2 (b int);
|
|
INSERT INTO t1 VALUES (1), (2);
|
|
INSERT INTO t2 VALUES (1), (2);
|
|
|
|
CREATE VIEW v1 AS
|
|
SELECT t2.b FROM t1,t2 WHERE t1.a = t2.b WITH CHECK OPTION;
|
|
|
|
SELECT * FROM v1;
|
|
--error ER_VIEW_CHECK_FAILED
|
|
UPDATE v1 SET b=3;
|
|
SELECT * FROM v1;
|
|
SELECT * FROM t1;
|
|
SELECT * FROM t2;
|
|
|
|
DROP VIEW v1;
|
|
DROP TABLE t1,t2;
|
|
|
|
|
|
#
|
|
# Bug#12122 Views with ORDER BY can't be resolved using MERGE algorithm.
|
|
#
|
|
create table t1(f1 int, f2 int);
|
|
insert into t1 values(1,2),(1,3),(1,1),(2,3),(2,1),(2,2);
|
|
select * from t1;
|
|
create view v1 as select * from t1 order by f2;
|
|
select * from v1;
|
|
explain extended select * from v1;
|
|
select * from v1 order by f1;
|
|
explain extended select * from v1 order by f1;
|
|
drop view v1;
|
|
drop table t1;
|
|
|
|
#
|
|
# Bug#26209 queries with GROUP BY and ORDER BY using views
|
|
#
|
|
|
|
CREATE TABLE t1 (
|
|
id int(11) NOT NULL PRIMARY KEY,
|
|
country varchar(32),
|
|
code int(11) default NULL
|
|
);
|
|
INSERT INTO t1 VALUES
|
|
(1,'ITALY',100),(2,'ITALY',200),(3,'FRANCE',100), (4,'ITALY',100);
|
|
|
|
CREATE VIEW v1 AS SELECT * FROM t1;
|
|
|
|
SELECT code, COUNT(DISTINCT country) FROM t1 GROUP BY code ORDER BY MAX(id);
|
|
SELECT code, COUNT(DISTINCT country) FROM v1 GROUP BY code ORDER BY MAX(id);
|
|
|
|
DROP VIEW v1;
|
|
DROP TABLE t1;
|
|
|
|
|
|
#
|
|
# Bug#25897 Some queries are no longer possible after a CREATE VIEW fails
|
|
#
|
|
--disable_warnings
|
|
DROP VIEW IF EXISTS v1;
|
|
--enable_warnings
|
|
|
|
let $query = SELECT * FROM (SELECT 1) AS t;
|
|
|
|
eval $query;
|
|
--error ER_VIEW_SELECT_DERIVED
|
|
eval CREATE VIEW v1 AS $query;
|
|
--echo # Previously the following would fail.
|
|
eval $query;
|
|
|
|
|
|
#
|
|
# Bug#24532 The return data type of IS TRUE is different from similar operations
|
|
#
|
|
|
|
--disable_warnings
|
|
drop view if exists view_24532_a;
|
|
drop view if exists view_24532_b;
|
|
drop table if exists table_24532;
|
|
--enable_warnings
|
|
|
|
create table table_24532 (
|
|
a int,
|
|
b bigint,
|
|
c int(4),
|
|
d bigint(48)
|
|
);
|
|
|
|
create view view_24532_a as
|
|
select
|
|
a IS TRUE,
|
|
a IS NOT TRUE,
|
|
a IS FALSE,
|
|
a IS NOT FALSE,
|
|
a IS UNKNOWN,
|
|
a IS NOT UNKNOWN,
|
|
a is NULL,
|
|
a IS NOT NULL,
|
|
ISNULL(a),
|
|
b IS TRUE,
|
|
b IS NOT TRUE,
|
|
b IS FALSE,
|
|
b IS NOT FALSE,
|
|
b IS UNKNOWN,
|
|
b IS NOT UNKNOWN,
|
|
b is NULL,
|
|
b IS NOT NULL,
|
|
ISNULL(b),
|
|
c IS TRUE,
|
|
c IS NOT TRUE,
|
|
c IS FALSE,
|
|
c IS NOT FALSE,
|
|
c IS UNKNOWN,
|
|
c IS NOT UNKNOWN,
|
|
c is NULL,
|
|
c IS NOT NULL,
|
|
ISNULL(c),
|
|
d IS TRUE,
|
|
d IS NOT TRUE,
|
|
d IS FALSE,
|
|
d IS NOT FALSE,
|
|
d IS UNKNOWN,
|
|
d IS NOT UNKNOWN,
|
|
d is NULL,
|
|
d IS NOT NULL,
|
|
ISNULL(d)
|
|
from table_24532;
|
|
|
|
describe view_24532_a;
|
|
|
|
create view view_24532_b as
|
|
select
|
|
a IS TRUE,
|
|
if(ifnull(a, 0), 1, 0) as old_istrue,
|
|
a IS NOT TRUE,
|
|
if(ifnull(a, 0), 0, 1) as old_isnottrue,
|
|
a IS FALSE,
|
|
if(ifnull(a, 1), 0, 1) as old_isfalse,
|
|
a IS NOT FALSE,
|
|
if(ifnull(a, 1), 1, 0) as old_isnotfalse
|
|
from table_24532;
|
|
|
|
describe view_24532_b;
|
|
|
|
show create view view_24532_b;
|
|
|
|
insert into table_24532 values (0, 0, 0, 0);
|
|
select * from view_24532_b;
|
|
update table_24532 set a=1;
|
|
select * from view_24532_b;
|
|
update table_24532 set a=NULL;
|
|
select * from view_24532_b;
|
|
|
|
drop view view_24532_a;
|
|
drop view view_24532_b;
|
|
drop table table_24532;
|
|
|
|
|
|
#
|
|
# Bug#26560 view using subquery with a reference to an outer alias
|
|
#
|
|
|
|
CREATE TABLE t1 (
|
|
lid int NOT NULL PRIMARY KEY,
|
|
name char(10) NOT NULL
|
|
);
|
|
INSERT INTO t1 (lid, name) VALUES
|
|
(1, 'YES'), (2, 'NO');
|
|
|
|
CREATE TABLE t2 (
|
|
id int NOT NULL PRIMARY KEY,
|
|
gid int NOT NULL,
|
|
lid int NOT NULL,
|
|
dt date
|
|
);
|
|
INSERT INTO t2 (id, gid, lid, dt) VALUES
|
|
(1, 1, 1, '2007-01-01'),(2, 1, 2, '2007-01-02'),
|
|
(3, 2, 2, '2007-02-01'),(4, 2, 1, '2007-02-02');
|
|
|
|
SELECT DISTINCT t2.gid AS lgid,
|
|
(SELECT t1.name FROM t1, t2
|
|
WHERE t1.lid = t2.lid AND t2.gid = lgid
|
|
ORDER BY t2.dt DESC LIMIT 1
|
|
) as clid
|
|
FROM t2;
|
|
|
|
CREATE VIEW v1 AS
|
|
SELECT DISTINCT t2.gid AS lgid,
|
|
(SELECT t1.name FROM t1, t2
|
|
WHERE t1.lid = t2.lid AND t2.gid = lgid
|
|
ORDER BY t2.dt DESC LIMIT 1
|
|
) as clid
|
|
FROM t2;
|
|
SELECT * FROM v1;
|
|
|
|
DROP VIEW v1;
|
|
DROP table t1,t2;
|
|
|
|
|
|
#
|
|
# Bug#27786 Inconsistent Operation Performing UNION On View With ORDER BY
|
|
#
|
|
CREATE TABLE t1 (a INT); INSERT INTO t1 VALUES (1),(2),(3);
|
|
CREATE VIEW v1 AS SELECT a FROM t1 ORDER BY a;
|
|
|
|
SELECT * FROM t1 UNION SELECT * FROM v1;
|
|
EXPLAIN SELECT * FROM t1 UNION SELECT * FROM v1;
|
|
SELECT * FROM v1 UNION SELECT * FROM t1;
|
|
EXPLAIN SELECT * FROM v1 UNION SELECT * FROM t1;
|
|
SELECT * FROM t1 UNION SELECT * FROM v1 ORDER BY a;
|
|
EXPLAIN SELECT * FROM t1 UNION SELECT * FROM v1 ORDER BY a;
|
|
|
|
DROP VIEW v1;
|
|
DROP TABLE t1;
|
|
|
|
|
|
#
|
|
# Bug#27921 View ignores precision for CAST()
|
|
#
|
|
CREATE VIEW v1 AS SELECT CAST( 1.23456789 AS DECIMAL( 7,5 ) ) AS col;
|
|
SELECT * FROM v1;
|
|
DESCRIBE v1;
|
|
DROP VIEW v1;
|
|
|
|
CREATE VIEW v1 AS SELECT CAST(1.23456789 AS DECIMAL(8,0)) AS col;
|
|
SHOW CREATE VIEW v1;
|
|
DROP VIEW v1;
|
|
|
|
|
|
#
|
|
# Bug#28716 CHECK OPTION expression is evaluated over expired record buffers
|
|
# when VIEW is updated via temporary tables
|
|
#
|
|
CREATE TABLE t1 (a INT);
|
|
CREATE TABLE t2 (b INT, c INT DEFAULT 0);
|
|
INSERT INTO t1 (a) VALUES (1), (2);
|
|
INSERT INTO t2 (b) VALUES (1), (2);
|
|
CREATE VIEW v1 AS SELECT t2.b,t2.c FROM t1, t2
|
|
WHERE t1.a=t2.b AND t2.b < 3 WITH CHECK OPTION;
|
|
SELECT * FROM v1;
|
|
UPDATE v1 SET c=1 WHERE b=1;
|
|
SELECT * FROM v1;
|
|
DROP VIEW v1;
|
|
DROP TABLE t1,t2;
|
|
|
|
|
|
#
|
|
# Bug#28561 update on multi-table view with CHECK OPTION and a subquery
|
|
# in WHERE condition
|
|
#
|
|
|
|
CREATE TABLE t1 (id int);
|
|
CREATE TABLE t2 (id int, c int DEFAULT 0);
|
|
INSERT INTO t1 (id) VALUES (1);
|
|
INSERT INTO t2 (id) VALUES (1);
|
|
|
|
CREATE VIEW v1 AS
|
|
SELECT t2.c FROM t1, t2
|
|
WHERE t1.id=t2.id AND 1 IN (SELECT id FROM t1) WITH CHECK OPTION;
|
|
|
|
UPDATE v1 SET c=1;
|
|
|
|
DROP VIEW v1;
|
|
DROP TABLE t1,t2;
|
|
|
|
|
|
#
|
|
# Bug#27827 CHECK OPTION ignores ON conditions when updating
|
|
# a multi-table view with CHECK OPTION.
|
|
#
|
|
|
|
CREATE TABLE t1 (a1 INT, c INT DEFAULT 0);
|
|
CREATE TABLE t2 (a2 INT);
|
|
CREATE TABLE t3 (a3 INT);
|
|
CREATE TABLE t4 (a4 INT);
|
|
INSERT INTO t1 (a1) VALUES (1),(2);
|
|
INSERT INTO t2 (a2) VALUES (1),(2);
|
|
INSERT INTO t3 (a3) VALUES (1),(2);
|
|
INSERT INTO t4 (a4) VALUES (1),(2);
|
|
|
|
CREATE VIEW v1 AS
|
|
SELECT t1.a1, t1.c FROM t1 JOIN t2 ON t1.a1=t2.a2 AND t1.c < 3
|
|
WITH CHECK OPTION;
|
|
SELECT * FROM v1;
|
|
--error ER_VIEW_CHECK_FAILED
|
|
UPDATE v1 SET c=3;
|
|
PREPARE t FROM 'UPDATE v1 SET c=3';
|
|
--error ER_VIEW_CHECK_FAILED
|
|
EXECUTE t;
|
|
--error ER_VIEW_CHECK_FAILED
|
|
EXECUTE t;
|
|
--error ER_VIEW_CHECK_FAILED
|
|
INSERT INTO v1(a1, c) VALUES (3, 3);
|
|
UPDATE v1 SET c=1 WHERE a1=1;
|
|
SELECT * FROM v1;
|
|
SELECT * FROM t1;
|
|
|
|
CREATE VIEW v2 AS SELECT t1.a1, t1.c
|
|
FROM (t1 JOIN t2 ON t1.a1=t2.a2 AND t1.c < 3)
|
|
JOIN (t3 JOIN t4 ON t3.a3=t4.a4)
|
|
ON t2.a2=t3.a3 WITH CHECK OPTION;
|
|
SELECT * FROM v2;
|
|
--error ER_VIEW_CHECK_FAILED
|
|
UPDATE v2 SET c=3;
|
|
PREPARE t FROM 'UPDATE v2 SET c=3';
|
|
--error ER_VIEW_CHECK_FAILED
|
|
EXECUTE t;
|
|
--error ER_VIEW_CHECK_FAILED
|
|
EXECUTE t;
|
|
--error ER_VIEW_CHECK_FAILED
|
|
INSERT INTO v2(a1, c) VALUES (3, 3);
|
|
UPDATE v2 SET c=2 WHERE a1=1;
|
|
SELECT * FROM v2;
|
|
SELECT * FROM t1;
|
|
|
|
DROP VIEW v1,v2;
|
|
DROP TABLE t1,t2,t3,t4;
|
|
|
|
|
|
#
|
|
# Bug#29104 assertion abort for a query with a view column reference
|
|
# in the GROUP BY list and a condition requiring the value
|
|
# of another view column to be equal to a constant
|
|
#
|
|
|
|
CREATE TABLE t1 (a int, b int);
|
|
INSERT INTO t1 VALUES (1,2), (2,2), (1,3), (1,2);
|
|
|
|
CREATE VIEW v1 AS SELECT a, b+1 as b FROM t1;
|
|
|
|
|
|
SELECT b, SUM(a) FROM v1 WHERE b=3 GROUP BY b;
|
|
EXPLAIN SELECT b, SUM(a) FROM v1 WHERE b=3 GROUP BY b;
|
|
|
|
SELECT a, SUM(b) FROM v1 WHERE b=3 GROUP BY a;
|
|
EXPLAIN SELECT a, SUM(b) FROM v1 WHERE b=3 GROUP BY a;
|
|
|
|
SELECT a, SUM(b) FROM v1 WHERE a=1 GROUP BY a;
|
|
EXPLAIN SELECT a, SUM(b) FROM v1 WHERE a=1 GROUP BY a;
|
|
|
|
DROP VIEW v1;
|
|
DROP TABLE t1;
|
|
|
|
|
|
#
|
|
# Bug#29392 SELECT over a multi-table view with ORDER BY
|
|
# selecting the same view column with two different aliases
|
|
#
|
|
|
|
CREATE TABLE t1 (
|
|
person_id int NOT NULL PRIMARY KEY,
|
|
username varchar(40) default NULL,
|
|
status_flg char(1) NOT NULL default 'A'
|
|
);
|
|
|
|
CREATE TABLE t2 (
|
|
person_role_id int NOT NULL auto_increment PRIMARY KEY,
|
|
role_id int NOT NULL,
|
|
person_id int NOT NULL,
|
|
INDEX idx_person_id (person_id),
|
|
INDEX idx_role_id (role_id)
|
|
);
|
|
|
|
CREATE TABLE t3 (
|
|
role_id int NOT NULL auto_increment PRIMARY KEY,
|
|
role_name varchar(100) default NULL,
|
|
app_name varchar(40) NOT NULL,
|
|
INDEX idx_app_name(app_name)
|
|
);
|
|
|
|
CREATE VIEW v1 AS
|
|
SELECT profile.person_id AS person_id
|
|
FROM t1 profile, t2 userrole, t3 role
|
|
WHERE userrole.person_id = profile.person_id AND
|
|
role.role_id = userrole.role_id AND
|
|
profile.status_flg = 'A'
|
|
ORDER BY profile.person_id,role.app_name,role.role_name;
|
|
|
|
INSERT INTO t1 VALUES
|
|
(6,'Sw','A'), (-1136332546,'ols','e'), (0,' *\n','0'),
|
|
(-717462680,'ENTS Ta','0'), (-904346964,'ndard SQL\n','0');
|
|
INSERT INTO t2 VALUES
|
|
(1,3,6),(2,4,7),(3,5,8),(4,6,9),(5,1,6),(6,1,7),(7,1,8),(8,1,9),(9,1,10);
|
|
|
|
INSERT INTO t3 VALUES
|
|
(1,'NUCANS_APP_USER','NUCANSAPP'),(2,'NUCANS_TRGAPP_USER','NUCANSAPP'),
|
|
(3,'IA_INTAKE_COORDINATOR','IACANS'),(4,'IA_SCREENER','IACANS'),
|
|
(5,'IA_SUPERVISOR','IACANS'),(6,'IA_READONLY','IACANS'),
|
|
(7,'SOC_USER','SOCCANS'),(8,'CAYIT_USER','CAYITCANS'),
|
|
(9,'RTOS_DCFSPOS_SUPERVISOR','RTOS');
|
|
|
|
EXPLAIN SELECT t.person_id AS a, t.person_id AS b FROM v1 t WHERE t.person_id=6;
|
|
SELECT t.person_id AS a, t.person_id AS b FROM v1 t WHERE t.person_id=6;
|
|
|
|
DROP VIEW v1;
|
|
DROP TABLE t1,t2,t3;
|
|
|
|
|
|
#
|
|
# Bug#30020 Insufficient check led to a wrong info provided by the
|
|
# information schema table.
|
|
#
|
|
create table t1 (i int);
|
|
insert into t1 values (1), (2), (1), (3), (2), (4);
|
|
create view v1 as select distinct i from t1;
|
|
select * from v1;
|
|
select table_name, is_updatable from information_schema.views
|
|
where table_name = 'v1';
|
|
drop view v1;
|
|
drop table t1;
|
|
|
|
|
|
#
|
|
# Bug#28701 SELECTs from VIEWs completely ignore USE/FORCE KEY, allowing
|
|
# invalid statements
|
|
#
|
|
|
|
CREATE TABLE t1 (a INT);
|
|
INSERT INTO t1 VALUES (1),(2);
|
|
CREATE VIEW v1 AS SELECT * FROM t1;
|
|
--error ER_KEY_DOES_NOT_EXITS
|
|
SELECT * FROM v1 USE KEY(non_existant);
|
|
--error ER_KEY_DOES_NOT_EXITS
|
|
SELECT * FROM v1 FORCE KEY(non_existant);
|
|
--error ER_KEY_DOES_NOT_EXITS
|
|
SELECT * FROM v1 IGNORE KEY(non_existant);
|
|
|
|
DROP VIEW v1;
|
|
DROP TABLE t1;
|
|
|
|
|
|
#
|
|
# Bug#28702 VIEWs defined with USE/FORCE KEY ignore that request
|
|
#
|
|
CREATE TABLE t1 (a INT NOT NULL AUTO_INCREMENT, b INT NOT NULL DEFAULT 0,
|
|
PRIMARY KEY(a), KEY (b));
|
|
INSERT INTO t1 VALUES (),(),(),(),(),(),(),(),(),(),(),(),(),(),();
|
|
CREATE VIEW v1 AS SELECT * FROM t1 FORCE KEY (PRIMARY,b) ORDER BY a;
|
|
SHOW CREATE VIEW v1;
|
|
EXPLAIN SELECT * FROM v1;
|
|
CREATE VIEW v2 AS SELECT * FROM t1 USE KEY () ORDER BY a;
|
|
SHOW CREATE VIEW v2;
|
|
EXPLAIN SELECT * FROM v2;
|
|
CREATE VIEW v3 AS SELECT * FROM t1 IGNORE KEY (b) ORDER BY a;
|
|
SHOW CREATE VIEW v3;
|
|
EXPLAIN SELECT * FROM v3;
|
|
|
|
DROP VIEW v1;
|
|
DROP VIEW v2;
|
|
DROP VIEW v3;
|
|
DROP TABLE t1;
|
|
|
|
|
|
--echo #
|
|
--echo # Bug#29477 Not all fields of the target table were checked to have
|
|
--echo # a default value when inserting into a view.
|
|
--echo #
|
|
create table t1(f1 int, f2 int not null);
|
|
create view v1 as select f1 from t1;
|
|
insert into v1 values(1);
|
|
set @old_mode=@@sql_mode;
|
|
set @@sql_mode=traditional;
|
|
--error ER_NO_DEFAULT_FOR_VIEW_FIELD
|
|
insert into v1 values(1);
|
|
set @@sql_mode=@old_mode;
|
|
drop view v1;
|
|
drop table t1;
|
|
|
|
|
|
#
|
|
# Bug#33389 Selecting from a view into a table from within SP or trigger
|
|
# crashes server
|
|
#
|
|
|
|
create table t1 (a int, key(a));
|
|
create table t2 (c int);
|
|
|
|
create view v1 as select a b from t1;
|
|
create view v2 as select 1 a from t2, v1 where c in
|
|
(select 1 from t1 where b = a);
|
|
|
|
insert into t1 values (1), (1);
|
|
insert into t2 values (1), (1);
|
|
|
|
prepare stmt from "select * from v2 where a = 1";
|
|
execute stmt;
|
|
|
|
drop view v1, v2;
|
|
drop table t1, t2;
|
|
|
|
|
|
#
|
|
# Bug#33049 Assert while running test-as3ap test(mysql-bench suite)
|
|
#
|
|
|
|
CREATE TABLE t1 (a INT);
|
|
CREATE VIEW v1 AS SELECT p.a AS a FROM t1 p, t1 q;
|
|
|
|
INSERT INTO t1 VALUES (1), (1);
|
|
SELECT MAX(a), COUNT(DISTINCT a) FROM v1 GROUP BY a;
|
|
|
|
DROP VIEW v1;
|
|
DROP TABLE t1;
|
|
|
|
###########################################################################
|
|
|
|
--echo # -----------------------------------------------------------------
|
|
--echo # -- Bug#34337 Server crash when Altering a view using a table name.
|
|
--echo # -----------------------------------------------------------------
|
|
--echo
|
|
|
|
--disable_warnings
|
|
DROP TABLE IF EXISTS t1;
|
|
--enable_warnings
|
|
|
|
--echo
|
|
|
|
CREATE TABLE t1(c1 INT);
|
|
|
|
--echo
|
|
|
|
SELECT * FROM t1;
|
|
|
|
--error ER_WRONG_OBJECT
|
|
ALTER ALGORITHM=TEMPTABLE SQL SECURITY INVOKER VIEW t1 (c2) AS SELECT (1);
|
|
|
|
--echo
|
|
|
|
DROP TABLE t1;
|
|
|
|
--echo
|
|
--echo # -- End of test case for Bug#34337.
|
|
--echo
|
|
|
|
###########################################################################
|
|
|
|
--echo # -----------------------------------------------------------------
|
|
--echo # -- Bug#35193 VIEW query is rewritten without "FROM DUAL",
|
|
--echo # -- causing syntax error
|
|
--echo # -----------------------------------------------------------------
|
|
--echo
|
|
|
|
CREATE VIEW v1 AS SELECT 1 FROM DUAL WHERE 1;
|
|
|
|
--echo
|
|
|
|
SELECT * FROM v1;
|
|
SHOW CREATE TABLE v1;
|
|
|
|
--echo
|
|
|
|
DROP VIEW v1;
|
|
|
|
--echo
|
|
--echo # -- End of test case for Bug#35193.
|
|
--echo
|
|
|
|
###########################################################################
|
|
|
|
#
|
|
# Bug#39040 valgrind errors/crash when creating views with binlog logging
|
|
# enabled
|
|
#
|
|
# Bug is visible only when running in valgrind with binary logging.
|
|
CREATE VIEW v1 AS SELECT 1;
|
|
DROP VIEW v1;
|
|
|
|
|
|
#
|
|
# Bug#33461 SELECT ... FROM <view> USE INDEX (...) throws an error
|
|
#
|
|
|
|
CREATE TABLE t1 (c1 INT PRIMARY KEY, c2 INT, INDEX (c2));
|
|
INSERT INTO t1 VALUES (1,1), (2,2), (3,3);
|
|
SELECT * FROM t1 USE INDEX (PRIMARY) WHERE c1=2;
|
|
SELECT * FROM t1 USE INDEX (c2) WHERE c2=2;
|
|
|
|
CREATE VIEW v1 AS SELECT c1, c2 FROM t1;
|
|
SHOW INDEX FROM v1;
|
|
--error ER_KEY_DOES_NOT_EXITS
|
|
SELECT * FROM v1 USE INDEX (PRIMARY) WHERE c1=2;
|
|
--error ER_KEY_DOES_NOT_EXITS
|
|
SELECT * FROM v1 FORCE INDEX (PRIMARY) WHERE c1=2;
|
|
--error ER_KEY_DOES_NOT_EXITS
|
|
SELECT * FROM v1 IGNORE INDEX (PRIMARY) WHERE c1=2;
|
|
--error ER_KEY_DOES_NOT_EXITS
|
|
SELECT * FROM v1 USE INDEX (c2) WHERE c2=2;
|
|
--error ER_KEY_DOES_NOT_EXITS
|
|
SELECT * FROM v1 FORCE INDEX (c2) WHERE c2=2;
|
|
--error ER_KEY_DOES_NOT_EXITS
|
|
SELECT * FROM v1 IGNORE INDEX (c2) WHERE c2=2;
|
|
|
|
DROP VIEW v1;
|
|
DROP TABLE t1;
|
|
|
|
--echo #
|
|
--echo # Bug #45806 crash when replacing into a view with a join!
|
|
--echo #
|
|
CREATE TABLE t1(a INT UNIQUE);
|
|
CREATE VIEW v1 AS SELECT t1.a FROM t1, t1 AS a;
|
|
INSERT INTO t1 VALUES (1), (2);
|
|
|
|
REPLACE INTO v1(a) SELECT 1 FROM t1,t1 AS c;
|
|
SELECT * FROM v1;
|
|
REPLACE INTO v1(a) SELECT 3 FROM t1,t1 AS c;
|
|
SELECT * FROM v1;
|
|
DELETE FROM t1 WHERE a=3;
|
|
INSERT INTO v1(a) SELECT 1 FROM t1,t1 AS c
|
|
ON DUPLICATE KEY UPDATE `v1`.`a`= 1;
|
|
SELECT * FROM v1;
|
|
|
|
CREATE VIEW v2 AS SELECT t1.a FROM t1, v1 AS a;
|
|
|
|
REPLACE INTO v2(a) SELECT 1 FROM t1,t1 AS c;
|
|
SELECT * FROM v2;
|
|
REPLACE INTO v2(a) SELECT 3 FROM t1,t1 AS c;
|
|
SELECT * FROM v2;
|
|
INSERT INTO v2(a) SELECT 1 FROM t1,t1 AS c
|
|
ON DUPLICATE KEY UPDATE `v2`.`a`= 1;
|
|
SELECT * FROM v2;
|
|
|
|
DROP VIEW v1;
|
|
DROP VIEW v2;
|
|
DROP TABLE t1;
|
|
|
|
--echo # -- End of test case for Bug#45806
|
|
|
|
--echo # -----------------------------------------------------------------
|
|
--echo # -- Bug#40825: Error 1356 while selecting from a view
|
|
--echo # -- with a "HAVING" clause though query works
|
|
--echo # -----------------------------------------------------------------
|
|
--echo
|
|
|
|
CREATE TABLE t1 (c INT);
|
|
|
|
--echo
|
|
|
|
CREATE VIEW v1 (view_column) AS SELECT c AS alias FROM t1 HAVING alias;
|
|
SHOW CREATE VIEW v1;
|
|
SELECT * FROM v1;
|
|
|
|
--echo
|
|
|
|
DROP VIEW v1;
|
|
DROP TABLE t1;
|
|
|
|
--echo
|
|
--echo # -- End of test case for Bug#40825
|
|
--echo
|
|
|
|
--echo # -----------------------------------------------------------------
|
|
--echo # -- End of 5.0 tests.
|
|
--echo # -----------------------------------------------------------------
|
|
|
|
#
|
|
# Bug#21370 View renaming lacks tablename_to_filename encoding
|
|
#
|
|
--disable_warnings
|
|
DROP DATABASE IF EXISTS `d-1`;
|
|
--enable_warnings
|
|
CREATE DATABASE `d-1`;
|
|
USE `d-1`;
|
|
CREATE TABLE `t-1` (c1 INT);
|
|
CREATE VIEW `v-1` AS SELECT c1 FROM `t-1`;
|
|
SHOW TABLES;
|
|
RENAME TABLE `t-1` TO `t-2`;
|
|
RENAME TABLE `v-1` TO `v-2`;
|
|
SHOW TABLES;
|
|
DROP TABLE `t-2`;
|
|
DROP VIEW `v-2`;
|
|
DROP DATABASE `d-1`;
|
|
USE test;
|
|
|
|
--echo
|
|
--echo #
|
|
--echo # Bug#26676 VIEW using old table schema in a session.
|
|
--echo #
|
|
--echo
|
|
|
|
--disable_warnings
|
|
DROP VIEW IF EXISTS v1;
|
|
DROP TABLE IF EXISTS t1;
|
|
--enable_warnings
|
|
|
|
CREATE TABLE t1(c1 INT, c2 INT);
|
|
INSERT INTO t1 VALUES (1, 2), (3, 4);
|
|
|
|
--echo
|
|
|
|
SELECT * FROM t1;
|
|
|
|
--echo
|
|
|
|
CREATE VIEW v1 AS SELECT * FROM t1;
|
|
|
|
--echo
|
|
|
|
SELECT * FROM v1;
|
|
|
|
--echo
|
|
|
|
ALTER TABLE t1 ADD COLUMN c3 INT AFTER c2;
|
|
|
|
--echo
|
|
|
|
SELECT * FROM t1;
|
|
|
|
--echo
|
|
|
|
SELECT * FROM v1;
|
|
|
|
--echo
|
|
|
|
SHOW CREATE VIEW v1;
|
|
|
|
--echo
|
|
|
|
DROP VIEW v1;
|
|
DROP TABLE t1;
|
|
|
|
--echo
|
|
--echo # End of test case for Bug#26676.
|
|
--echo
|
|
|
|
###########################################################################
|
|
|
|
--echo # -----------------------------------------------------------------
|
|
--echo # -- Bug#32538 View definition picks up character set, but not collation
|
|
--echo # -----------------------------------------------------------------
|
|
--echo
|
|
|
|
--disable_warnings
|
|
DROP VIEW IF EXISTS v1;
|
|
--enable_warnings
|
|
|
|
--echo
|
|
|
|
SET collation_connection = latin1_general_ci;
|
|
CREATE VIEW v1 AS SELECT _latin1 'text1' AS c1, 'text2' AS c2;
|
|
|
|
--echo
|
|
|
|
SELECT COLLATION(c1), COLLATION(c2) FROM v1;
|
|
|
|
--echo
|
|
|
|
SHOW CREATE VIEW v1;
|
|
|
|
--echo
|
|
|
|
--error ER_CANT_AGGREGATE_2COLLATIONS
|
|
SELECT * FROM v1 WHERE c1 = 'text1';
|
|
|
|
--echo
|
|
|
|
SELECT * FROM v1 WHERE c2 = 'text2';
|
|
|
|
--echo
|
|
|
|
use test;
|
|
SET names latin1;
|
|
|
|
--echo
|
|
|
|
SELECT COLLATION(c1), COLLATION(c2) FROM v1;
|
|
|
|
--echo
|
|
|
|
SELECT * FROM v1 WHERE c1 = 'text1';
|
|
|
|
--echo
|
|
|
|
--error ER_CANT_AGGREGATE_2COLLATIONS
|
|
SELECT * FROM v1 WHERE c2 = 'text2';
|
|
|
|
--echo
|
|
|
|
DROP VIEW v1;
|
|
|
|
--echo
|
|
--echo # -- End of test case for Bug#32538.
|
|
--echo
|
|
|
|
#
|
|
# Bug#34587 Creating a view inside a stored procedure leads to a server crash
|
|
#
|
|
|
|
--disable_warnings
|
|
drop view if exists a;
|
|
drop procedure if exists p;
|
|
--enable_warnings
|
|
|
|
delimiter |;
|
|
create procedure p()
|
|
begin
|
|
declare continue handler for sqlexception begin end;
|
|
create view a as select 1;
|
|
end|
|
|
delimiter ;|
|
|
call p();
|
|
call p();
|
|
drop view a;
|
|
drop procedure p;
|
|
|
|
###########################################################################
|
|
|
|
|
|
--echo #
|
|
--echo # Bug #44860: ALTER TABLE on view crashes server
|
|
--echo #
|
|
CREATE TABLE t1 (a INT);
|
|
CREATE VIEW v1 AS SELECT a FROM t1;
|
|
ALTER TABLE v1;
|
|
DROP VIEW v1;
|
|
DROP TABLE t1;
|
|
|
|
|
|
--echo # -----------------------------------------------------------------
|
|
--echo # -- End of 5.1 tests.
|
|
--echo # -----------------------------------------------------------------
|