summaryrefslogtreecommitdiff
path: root/sql/sp_cache.cc
diff options
context:
space:
mode:
authorunknown <pem@mysql.comhem.se>2003-10-21 12:08:35 +0200
committerunknown <pem@mysql.comhem.se>2003-10-21 12:08:35 +0200
commit562a04d593ca9a179b851e1d71d30e764e55f7ad (patch)
tree2a69a7aa7527c9093f6156dee7a663e6404c913f /sql/sp_cache.cc
parent2b1dc5f35d5bf773378a36a14399987635be7127 (diff)
downloadmariadb-git-562a04d593ca9a179b851e1d71d30e764e55f7ad.tar.gz
WL#1265: Fix proper ALTER/DROP support in the SP cache.
New sp_cache C API. When an SP is dropped, old caches (in other threads) become invalid and are cleared. Also, the caches in THD are only created on demand. Docs/sp-imp-spec.txt: Brough the SP cache docs up-to-date. sql/mysqld.cc: Initialize SP cache. sql/sp.cc: New C API for SP cache. sql/sp_cache.cc: New C API for sp_cache. The class sp_cache is still used, but not directly. The C functions makes takes care of updating caches when SPs are dropped. (This is done in the simplest possible way, by simply detecting drops and then clear all old caches.) The API is also designed so that the sp_cache is created on demand. sql/sp_cache.h: New C API for sp_cache. The class sp_cache is still used, but not directly. The C functions makes takes care of updating caches when SPs are dropped. The API is also designed so that the sp_cache is created on demand. sql/sql_class.cc: The new sp_cache API creates the caches on demand, to avoid allocating it when it's not needed.
Diffstat (limited to 'sql/sp_cache.cc')
-rw-r--r--sql/sp_cache.cc93
1 files changed, 93 insertions, 0 deletions
diff --git a/sql/sp_cache.cc b/sql/sp_cache.cc
index 1b8816ee0f4..84e3565d543 100644
--- a/sql/sp_cache.cc
+++ b/sql/sp_cache.cc
@@ -22,6 +22,98 @@
#include "sp_cache.h"
#include "sp_head.h"
+static pthread_mutex_t Cversion_lock;
+static ulong Cversion = 0;
+
+void
+sp_cache_init()
+{
+ pthread_mutex_init(&Cversion_lock, MY_MUTEX_INIT_FAST);
+}
+
+void
+sp_cache_clear(sp_cache **cp)
+{
+ sp_cache *c= *cp;
+
+ if (c)
+ {
+ delete c;
+ *cp= NULL;
+ }
+}
+
+void
+sp_cache_insert(sp_cache **cp, sp_head *sp)
+{
+ sp_cache *c= *cp;
+
+ if (! c)
+ c= new sp_cache();
+ if (c)
+ {
+ ulong v;
+
+ pthread_mutex_lock(&Cversion_lock); // LOCK
+ v= Cversion;
+ pthread_mutex_unlock(&Cversion_lock); // UNLOCK
+
+ if (c->version < v)
+ {
+ if (*cp)
+ c->remove_all();
+ c->version= v;
+ }
+ c->insert(sp);
+ if (*cp == NULL)
+ *cp= c;
+ }
+}
+
+sp_head *
+sp_cache_lookup(sp_cache **cp, char *name, uint namelen)
+{
+ ulong v;
+ sp_cache *c= *cp;
+
+ if (! c)
+ return NULL;
+
+ pthread_mutex_lock(&Cversion_lock); // LOCK
+ v= Cversion;
+ pthread_mutex_unlock(&Cversion_lock); // UNLOCK
+
+ if (c->version < v)
+ {
+ c->remove_all();
+ c->version= v;
+ return NULL;
+ }
+ return c->lookup(name, namelen);
+}
+
+void
+sp_cache_remove(sp_cache **cp, sp_head *sp)
+{
+ sp_cache *c= *cp;
+
+ if (c)
+ {
+ ulong v;
+
+ pthread_mutex_lock(&Cversion_lock); // LOCK
+ v= Cversion++;
+ pthread_mutex_unlock(&Cversion_lock); // UNLOCK
+
+ if (c->version < v)
+ c->remove_all();
+ else
+ c->remove(sp);
+ c->version= v+1;
+ }
+}
+
+
static byte *
hash_get_key_for_sp_head(const byte *ptr, uint *plen,
my_bool first)
@@ -44,6 +136,7 @@ sp_cache::init()
{
hash_init(&m_hashtable, system_charset_info, 0, 0, 0,
hash_get_key_for_sp_head, 0, 0);
+ version= 0;
}
void