1661
Implementation of FLUSH TABLES <table_list> WITH READ LOCK.
1663
In brief: take exclusive locks, expel tables from the table
1664
cache, reopen the tables, enter the 'LOCKED TABLES' mode,
1665
downgrade the locks.
1669
Since the statement implicitly enters LOCK TABLES mode,
1670
it requires LOCK TABLES privilege on every table.
1671
But since the rest of FLUSH commands require
1672
the global RELOAD_ACL, it also requires RELOAD_ACL.
1674
Compatibility with the global read lock
1675
---------------------------------------
1676
We don't wait for the GRL, since neither the
1677
5.1 combination that this new statement is intended to
1678
replace (LOCK TABLE <list> WRITE; FLUSH TABLES;),
1679
nor FLUSH TABLES WITH READ LOCK do.
1680
@todo: this is not implemented, Dmitry disagrees.
1681
Currently we wait for GRL in another connection,
1682
but are compatible with a GRL in our own connection.
1684
Behaviour under LOCK TABLES
1685
---------------------------
1686
Bail out: i.e. don't perform an implicit UNLOCK TABLES.
1687
This is not consistent with LOCK TABLES statement, but is
1688
in line with behaviour of FLUSH TABLES WITH READ LOCK, and we
1689
try to not introduce any new statements with implicit
1692
Compatibility with parallel updates
1693
-----------------------------------
1694
As a result, we will wait for all open transactions
1695
against the tables to complete. After the lock downgrade,
1696
new transactions will be able to read the tables, but not
1699
Differences from FLUSH TABLES <list>
1700
-------------------------------------
1701
- you can't flush WITH READ LOCK a non-existent table
1702
- you can't flush WITH READ LOCK under LOCK TABLES
1703
- currently incompatible with the GRL (@todo: fix)
1706
static bool flush_tables_with_read_lock(THD *thd, TABLE_LIST *all_tables)
1708
Lock_tables_prelocking_strategy lock_tables_prelocking_strategy;
1709
TABLE_LIST *table_list;
1712
This is called from SQLCOM_FLUSH, the transaction has
1713
been committed implicitly.
1716
/* RELOAD_ACL is checked by the caller. Check table-level privileges. */
1717
if (check_table_access(thd, LOCK_TABLES_ACL | SELECT_ACL, all_tables,
1718
FALSE, FALSE, UINT_MAX))
1721
if (thd->locked_tables_mode)
1723
my_error(ER_LOCK_OR_ACTIVE_TRANSACTION, MYF(0));
1728
@todo: Since lock_table_names() acquires a global IX
1729
lock, this actually waits for a GRL in another connection.
1730
We are thus introducing an incompatibility.
1731
Do nothing for now, since not taking a global IX violates
1732
current internal MDL asserts, fix after discussing with
1735
if (lock_table_names(thd, all_tables))
1738
if (open_and_lock_tables(thd, all_tables, FALSE,
1739
MYSQL_OPEN_HAS_MDL_LOCK,
1740
&lock_tables_prelocking_strategy) ||
1741
thd->locked_tables_list.init_locked_tables(thd))
1743
close_thread_tables(thd);
1748
Downgrade the exclusive locks.
1749
Use MDL_SHARED_NO_WRITE as the intended
1750
post effect of this call is identical
1751
to LOCK TABLES <...> READ, and we didn't use
1752
thd->in_lock_talbes and thd->sql_command= SQLCOM_LOCK_TABLES
1753
hacks to enter the LTM.
1754
@todo: release the global IX lock here!!!
1756
for (table_list= all_tables; table_list;
1757
table_list= table_list->next_global)
1758
table_list->mdl_request.ticket->downgrade_exclusive_lock(MDL_SHARED_NO_WRITE);
1660
1768
Read query from packet and store in thd->query.
1661
1769
Used in COM_QUERY and COM_STMT_PREPARE.
4530
4647
close_thread_tables(thd);
4531
4648
thd->mdl_context.release_transactional_locks();
4533
if (sp_automatic_privileges && !opt_noacl &&
4534
sp_revoke_privileges(thd, db, name,
4650
if (sp_automatic_privileges && !opt_noacl &&
4651
sp_revoke_privileges(thd, db, name,
4535
4652
lex->sql_command == SQLCOM_DROP_PROCEDURE))
4537
push_warning(thd, MYSQL_ERROR::WARN_LEVEL_WARN,
4538
ER_PROC_AUTO_REVOKE_FAIL,
4539
ER(ER_PROC_AUTO_REVOKE_FAIL));
4654
push_warning(thd, MYSQL_ERROR::WARN_LEVEL_WARN,
4655
ER_PROC_AUTO_REVOKE_FAIL,
4656
ER(ER_PROC_AUTO_REVOKE_FAIL));
4657
/* If this happens, an error should have been reported. */
4543
4662
res= sp_result;