summaryrefslogtreecommitdiff
path: root/sql/sql_class.cc
diff options
context:
space:
mode:
authorunknown <bell@sanja.is.com.ua>2002-03-15 23:57:31 +0200
committerunknown <bell@sanja.is.com.ua>2002-03-15 23:57:31 +0200
commit0510e98e11666728d21ae29621adbe134454dc71 (patch)
tree691610fcbd4313eb2d79af0b91394cb2b9410f21 /sql/sql_class.cc
parent75a268a65be94b15b1651b2dab1c969d24238f48 (diff)
downloadmariadb-git-0510e98e11666728d21ae29621adbe134454dc71.tar.gz
processing trunsactional tables in query cache
mysql-test/r/innodb_cache.result: new test for query cache with transactions mysql-test/t/innodb_cache.test: new test for query cache with transactions sql/sql_cache.cc: processing trunsactional tables in query cache & removing strlen sql/sql_class.cc: processing trunsactional tables in query cache & added transaction-live memory sql/sql_class.h: processing trunsactional tables in query cache & added transaction-live memory sql/sql_parse.cc: processing trunsactional tables in query cache & added transaction-live memory sql/table.h: removing strlen operation from query cache
Diffstat (limited to 'sql/sql_class.cc')
-rw-r--r--sql/sql_class.cc87
1 files changed, 87 insertions, 0 deletions
diff --git a/sql/sql_class.cc b/sql/sql_class.cc
index f6f66b0b7da..810342c2bc3 100644
--- a/sql/sql_class.cc
+++ b/sql/sql_class.cc
@@ -34,6 +34,8 @@
#ifdef __WIN__
#include <io.h>
#endif
+#include <mysys_err.h>
+#include <assert.h>
/*****************************************************************************
** Instansiate templates
@@ -105,6 +107,7 @@ THD::THD():user_time(0),fatal_error(0),last_insert_id_used(0),
net.vio=0;
ull=0;
system_thread=cleanup_done=0;
+ transaction.changed_tables = 0;
#ifdef __WIN__
real_id = 0;
#endif
@@ -136,6 +139,7 @@ THD::THD():user_time(0),fatal_error(0),last_insert_id_used(0),
/* Initialize sub structures */
bzero((char*) &mem_root,sizeof(mem_root));
+ bzero((char*) &transaction.mem_root,sizeof(transaction.mem_root));
user_connect=(UC *)0;
hash_init(&user_vars, USER_VARS_HASH_SIZE, 0, 0,
(hash_get_key) get_var_key,
@@ -211,6 +215,7 @@ THD::~THD()
safeFree(db);
safeFree(ip);
free_root(&mem_root,MYF(0));
+ free_root(&transaction.mem_root,MYF(0));
mysys_var=0; // Safety (shouldn't be needed)
#ifdef SIGNAL_WITH_VIO_CLOSE
pthread_mutex_destroy(&active_vio_lock);
@@ -255,6 +260,88 @@ bool THD::store_globals()
my_pthread_setspecific_ptr(THR_NET, &net));
}
+/* routings to adding tables to list of changed in transaction tables */
+
+inline static void list_include(CHANGED_TABLE_LIST** prev,
+ CHANGED_TABLE_LIST* curr,
+ CHANGED_TABLE_LIST* new_table)
+{
+ if (new_table)
+ {
+ *prev = new_table;
+ (*prev)->next = curr;
+ }
+}
+
+/* add table to list of changed in transaction tables */
+void THD::add_changed_table(TABLE *table)
+{
+ DBUG_ENTER("THD::add_changed_table (table)");
+
+ DBUG_ASSERT((options & (OPTION_NOT_AUTO_COMMIT | OPTION_BEGIN)) &&
+ table->file->has_transactions());
+
+ CHANGED_TABLE_LIST** prev = &transaction.changed_tables;
+ CHANGED_TABLE_LIST* curr = transaction.changed_tables;
+
+ for(; curr; prev = &(curr->next), curr = curr->next)
+ {
+ int cmp = (long)curr->key_length - (long)table->key_length;
+ if (cmp < 0)
+ {
+ list_include(prev, curr, changed_table_dup(table));
+ DBUG_PRINT("info",
+ ("key_length %u %u", table->key_length, (*prev)->key_length));
+ DBUG_VOID_RETURN;
+ }
+ else if (cmp == 0)
+ {
+ cmp = memcmp(curr->key ,table->table_cache_key, curr->key_length);
+ if (cmp < 0)
+ {
+ list_include(prev, curr, changed_table_dup(table));
+ DBUG_PRINT("info",
+ ("key_length %u %u", table->key_length, (*prev)->key_length));
+ DBUG_VOID_RETURN;
+ }
+ else if (cmp == 0)
+ {
+ DBUG_PRINT("info", ("already in list"));
+ DBUG_VOID_RETURN;
+ }
+ }
+ }
+ *prev = changed_table_dup(table);
+ DBUG_PRINT("info", ("key_length %u %u", table->key_length, (*prev)->key_length));
+ DBUG_VOID_RETURN;
+}
+
+CHANGED_TABLE_LIST* THD::changed_table_dup(TABLE *table)
+{
+ CHANGED_TABLE_LIST* new_table =
+ (CHANGED_TABLE_LIST*) trans_alloc(ALIGN_SIZE(sizeof(CHANGED_TABLE_LIST))+
+ table->key_length + 1);
+ if (!new_table)
+ {
+ my_error(EE_OUTOFMEMORY, MYF(ME_BELL),
+ ALIGN_SIZE(sizeof(TABLE_LIST)) + table->key_length + 1);
+ killed= 1;
+ return 0;
+ }
+
+ new_table->key = (char *) (((byte*)new_table)+
+ ALIGN_SIZE(sizeof(CHANGED_TABLE_LIST)));
+ new_table->next = 0;
+ new_table->key_length = table->key_length;
+ uint32 db_len = ((new_table->table_name =
+ ::strmake(new_table->key, table->table_cache_key,
+ table->key_length) + 1) - new_table->key);
+ ::memcpy(new_table->key + db_len, table->table_cache_key + db_len,
+ table->key_length - db_len);
+ return new_table;
+}
+
+
/*****************************************************************************
** Functions to provide a interface to select results
*****************************************************************************/