mirror of
https://github.com/MariaDB/server.git
synced 2025-07-29 05:21:33 +03:00
Speed up connection time:
-Change my_rnd() slightly to make it safer if two threads use it at the same time. -Avoid some sprintf and strmov in vio. -Changed thread_count to be automaticly incremented (instead of under LOCK_thread_count). -Thread cache now uses LOCK_thread_cache instead of LOCK_thread_count. -Moved delete thd out from LOCK_thread_count. -Save some mysql_cond_broadcast(&COND_thread_count) calls. -Removed call to getsockname() during connect. -Initialize random generator without locks. Other things: -Fixed test cases that depends on changes for LOCK_grant -Added thread_safe_decrement32() and thread_safe_increment32() -Removed sql_rnd_with_mutex() and get_thread_running() -In check_table_access() don't lock LOCK_grant if we can resolve the grant with user or db level grants (the normal case). -Don't use a lock for setting THD->query_id. -Fixed bug where thd->set_query_id() could be set to same value by multiple threads. Thanks to Yoshinori Matsunobu for the benchmark of connection speed and to Domas Mituzas for the inspiration for many of the fixes. include/violite.h: Change desc to a string pointer mysql-test/suite/perfschema/r/all_instances.result: Added new mutex mysql-test/suite/perfschema/t/func_mutex.test: Test for LOCK_system_variables_hash instead of LOCK_grant, as LOCK_grant is not anymore always taken for SELECT's. mysys/my_gethwaddr.c: More DBUG mysys/my_rnd.c: Change my_rnd() slightly to make it safer if two threads use it at the same time. sql/event_scheduler.cc: Changed thread_count to be automically incremented Moved some safe things out from LOCK_thread_count. Simplify deleting of THD for running thread. sql/mysqld.cc: Changed thread_count to be automically incremented Thread cache now uses LOCK_thread_cache instead of LOCK_thread_count Added delete_running_thd() Moved delete thd out from LOCK_thread_count More DBUG Only call mysql_cond_broadcast(&COND_thread_count) if thread_count is 0 Removed call to getsockname() (old not anymore needed check) sql/mysqld.h: Removed sql_rnd_with_mutex() (not needed anymore) Removed not used function get_thread_running() Added thread_safe_decrement32() and thread_safe_increment32() Simplified dec_thread_running() and inc_thread_running() next_query_id() should return the original value for global_query_id, not the next one. (Bug introduced with MySQL 5.5 merge). sql/sql_acl.cc: In check_table_access() don't lock LOCK_grant if we can resolve the grant with user or db level grants (the normal case). sql/sql_class.cc: Removed thd_lock_thread_count() and thd_unlock_thread_count() Initialize random generator without locks Don't use a lock for setting THD->query_id. (This is only accessed by thread owning the THD) sql/sql_class.h: Don't use a lock for setting THD->query_id. sql/sql_insert.cc: Changed thread_count to be automically incremented sql/sql_parse.cc: Changed thread_count to be automically incremented Fixed bug where thd->set_query_id() could be set to same value by multiple threads. vio/vio.c: Don't generate 'desc' with sprintf/strmov. Assign a pointer instead. (Good enough as this is just for debugging)
This commit is contained in:
@ -4530,12 +4530,16 @@ end:
|
||||
@see check_access
|
||||
@see check_table_access
|
||||
|
||||
@note This functions assumes that either number of tables to be inspected
|
||||
@note
|
||||
This functions assumes that either number of tables to be inspected
|
||||
by it is limited explicitly (i.e. is is not UINT_MAX) or table list
|
||||
used and thd->lex->query_tables_own_last value correspond to each
|
||||
other (the latter should be either 0 or point to next_global member
|
||||
of one of elements of this table list).
|
||||
|
||||
We delay locking of LOCK_grant until we really need it as we assume that
|
||||
most privileges be resolved with user or db level accesses.
|
||||
|
||||
@return Access status
|
||||
@retval FALSE Access granted; But column privileges might need to be
|
||||
checked.
|
||||
@ -4552,6 +4556,8 @@ bool check_grant(THD *thd, ulong want_access, TABLE_LIST *tables,
|
||||
Security_context *sctx= thd->security_ctx;
|
||||
uint i;
|
||||
ulong orig_want_access= want_access;
|
||||
my_bool locked= 0;
|
||||
GRANT_TABLE *grant_table;
|
||||
DBUG_ENTER("check_grant");
|
||||
DBUG_ASSERT(number > 0);
|
||||
|
||||
@ -4575,11 +4581,9 @@ bool check_grant(THD *thd, ulong want_access, TABLE_LIST *tables,
|
||||
*/
|
||||
tl->grant.orig_want_privilege= (want_access & ~SHOW_VIEW_ACL);
|
||||
}
|
||||
number= i;
|
||||
|
||||
mysql_rwlock_rdlock(&LOCK_grant);
|
||||
for (tl= tables;
|
||||
tl && number-- && tl != first_not_own_table;
|
||||
tl= tl->next_global)
|
||||
for (tl= tables; number-- ; tl= tl->next_global)
|
||||
{
|
||||
sctx = test(tl->security_ctx) ? tl->security_ctx : thd->security_ctx;
|
||||
|
||||
@ -4632,13 +4636,18 @@ bool check_grant(THD *thd, ulong want_access, TABLE_LIST *tables,
|
||||
}
|
||||
continue;
|
||||
}
|
||||
GRANT_TABLE *grant_table= table_hash_search(sctx->host, sctx->ip,
|
||||
tl->get_db_name(),
|
||||
sctx->priv_user,
|
||||
tl->get_table_name(),
|
||||
FALSE);
|
||||
|
||||
if (!grant_table)
|
||||
if (!locked)
|
||||
{
|
||||
locked= 1;
|
||||
mysql_rwlock_rdlock(&LOCK_grant);
|
||||
}
|
||||
|
||||
if (!(grant_table= table_hash_search(sctx->host, sctx->ip,
|
||||
tl->get_db_name(),
|
||||
sctx->priv_user,
|
||||
tl->get_table_name(),
|
||||
FALSE)))
|
||||
{
|
||||
want_access &= ~tl->grant.privilege;
|
||||
goto err; // No grants
|
||||
@ -4665,11 +4674,13 @@ bool check_grant(THD *thd, ulong want_access, TABLE_LIST *tables,
|
||||
goto err; // impossible
|
||||
}
|
||||
}
|
||||
mysql_rwlock_unlock(&LOCK_grant);
|
||||
if (locked)
|
||||
mysql_rwlock_unlock(&LOCK_grant);
|
||||
DBUG_RETURN(FALSE);
|
||||
|
||||
err:
|
||||
mysql_rwlock_unlock(&LOCK_grant);
|
||||
if (locked)
|
||||
mysql_rwlock_unlock(&LOCK_grant);
|
||||
if (!no_errors) // Not a silent skip of table
|
||||
{
|
||||
char command[128];
|
||||
|
Reference in New Issue
Block a user