summaryrefslogtreecommitdiff
path: root/sql/ha_innodb.cc
diff options
context:
space:
mode:
authorunknown <monty@mishka.local>2004-04-26 15:53:31 +0300
committerunknown <monty@mishka.local>2004-04-26 15:53:31 +0300
commit1065f2bbd66ac4b1161f5c188171a54cbad5b422 (patch)
tree25e3315af05fa92d20d2ad1d812882957c400337 /sql/ha_innodb.cc
parent0ba6cb48d84f1ff951d09871a96be6cdef3f2c3c (diff)
parent6366a9090c7fc24f0e13b5b9d73d6777dcda9d9e (diff)
downloadmariadb-git-1065f2bbd66ac4b1161f5c188171a54cbad5b422.tar.gz
Merge with 4.0
innobase/dict/dict0boot.c: Auto merged innobase/dict/dict0load.c: Auto merged innobase/dict/dict0mem.c: Auto merged innobase/fut/fut0lst.c: Auto merged innobase/include/buf0lru.h: Auto merged innobase/include/dict0mem.h: Auto merged innobase/include/fsp0fsp.h: Auto merged innobase/include/ha0ha.h: Auto merged innobase/include/ibuf0ibuf.h: Auto merged innobase/include/lock0lock.h: Auto merged innobase/include/log0log.h: Auto merged innobase/include/mem0pool.h: Auto merged innobase/include/mtr0mtr.h: Auto merged innobase/include/os0file.h: Auto merged innobase/include/rem0rec.h: Auto merged innobase/include/rem0rec.ic: Auto merged innobase/include/srv0srv.h: Auto merged innobase/include/sync0sync.h: Auto merged innobase/include/trx0sys.h: Auto merged innobase/include/ut0byte.h: Auto merged innobase/include/ut0ut.h: Auto merged innobase/mem/mem0pool.c: Auto merged innobase/mtr/mtr0mtr.c: Auto merged innobase/os/os0proc.c: Auto merged innobase/pars/lexyy.c: Auto merged innobase/pars/pars0opt.c: Auto merged innobase/row/row0ins.c: Auto merged innobase/row/row0purge.c: Auto merged innobase/row/row0uins.c: Auto merged innobase/row/row0umod.c: Auto merged innobase/row/row0undo.c: Auto merged innobase/row/row0upd.c: Auto merged innobase/trx/trx0purge.c: Auto merged innobase/trx/trx0roll.c: Auto merged innobase/trx/trx0sys.c: Auto merged innobase/trx/trx0undo.c: Auto merged innobase/ut/ut0byte.c: Auto merged pstack/bucomm.h: Auto merged pstack/budbg.h: Auto merged sql/item_sum.h: Auto merged sql/slave.cc: Auto merged sql/sql_db.cc: Auto merged support-files/mysql.spec.sh: Auto merged tests/insert_test.c: Auto merged mysql-test/t/func_group.test: Merge with 4.0 Put 4.1 tests lasts sql/ha_innodb.cc: Merge with 4.0 Added checking of results from my_malloc() BitKeeper/etc/logging_ok: Logging to logging@openlogging.org accepted
Diffstat (limited to 'sql/ha_innodb.cc')
-rw-r--r--sql/ha_innodb.cc294
1 files changed, 170 insertions, 124 deletions
diff --git a/sql/ha_innodb.cc b/sql/ha_innodb.cc
index a5dc6719182..b6b2123fd66 100644
--- a/sql/ha_innodb.cc
+++ b/sql/ha_innodb.cc
@@ -15,7 +15,9 @@
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
/* This file defines the InnoDB handler: the interface between MySQL and
-InnoDB */
+InnoDB
+NOTE: You can only use noninlined InnoDB functions in this file, because we
+have disables the InnoDB inlining in this file. */
/* TODO list for the InnoDB handler in 4.1:
- Check if the query_id is now right also in prepared and executed stats
@@ -74,6 +76,7 @@ extern "C" {
#include "../innobase/include/btr0cur.h"
#include "../innobase/include/btr0btr.h"
#include "../innobase/include/fsp0fsp.h"
+#include "../innobase/include/sync0sync.h"
#include "../innobase/include/fil0fil.h"
}
@@ -321,70 +324,49 @@ convert_error_code_to_mysql(
}
}
-extern "C" {
/*****************************************************************
Prints info of a THD object (== user session thread) to the
standard output. NOTE that /mysql/innobase/trx/trx0trx.c must contain
the prototype for this function! */
-
+extern "C"
void
innobase_mysql_print_thd(
/*=====================*/
- char* buf, /* in/out: buffer where to print, must be at least
- 400 bytes */
+ FILE* f, /* in: output stream */
void* input_thd)/* in: pointer to a MySQL THD object */
{
THD* thd;
- char* old_buf = buf;
thd = (THD*) input_thd;
- /* We cannot use the return value of normal sprintf() as this is
- not portable to some old non-Posix Unixes, e.g., some old SCO
- Unixes */
-
- buf += my_sprintf(buf,
- (buf, "MySQL thread id %lu, query id %lu",
- thd->thread_id, thd->query_id));
- if (thd->host) {
- *buf = ' ';
- buf++;
- buf = strnmov(buf, thd->host, 30);
- }
+ fprintf(f, "MySQL thread id %lu, query id %lu",
+ thd->thread_id, thd->query_id);
+ if (thd->host) {
+ putc(' ', f);
+ fputs(thd->host, f);
+ }
- if (thd->ip) {
- *buf = ' ';
- buf++;
- buf=strnmov(buf, thd->ip, 20);
- }
+ if (thd->ip) {
+ putc(' ', f);
+ fputs(thd->ip, f);
+ }
if (thd->user) {
- *buf = ' ';
- buf++;
- buf=strnmov(buf, thd->user, 20);
- }
-
- if (thd->proc_info) {
- *buf = ' ';
- buf++;
- buf=strnmov(buf, thd->proc_info, 50);
+ putc(' ', f);
+ fputs(thd->user, f);
}
- if (thd->query) {
- *buf = '\n';
- buf++;
- buf=strnmov(buf, thd->query, 150);
- }
-
- buf[0] = '\n';
- buf[1] = '\0'; /* Note that we must put a null character here to end
- the printed string */
+ if (thd->proc_info) {
+ putc(' ', f);
+ fputs(thd->proc_info, f);
+ }
- /* We test the printed length did not overrun the buffer length of
- 400 bytes */
+ if (thd->query) {
+ putc(' ', f);
+ fputs(thd->query, f);
+ }
- ut_a(strlen(old_buf) < 400);
-}
+ putc('\n', f);
}
/*************************************************************************
@@ -627,12 +609,11 @@ innobase_query_caching_of_table_permitted(
return((my_bool)FALSE);
}
-extern "C" {
/*********************************************************************
Invalidates the MySQL query cache for the table.
NOTE that the exact prototype of this function has to be in
/innobase/row/row0ins.c! */
-
+extern "C"
void
innobase_invalidate_query_cache(
/*============================*/
@@ -652,6 +633,17 @@ innobase_invalidate_query_cache(
TRUE);
#endif
}
+
+/*********************************************************************
+Get the quote character to be used in SQL identifiers. */
+extern "C"
+char
+mysql_get_identifier_quote_char(void)
+/*=================================*/
+ /* out: quote character to be
+ used in SQL identifiers */
+{
+ return '`';
}
/*********************************************************************
@@ -2102,24 +2094,20 @@ ha_innobase::write_row(
if (prebuilt->trx !=
(trx_t*) current_thd->transaction.all.innobase_tid) {
- char err_buf[2000];
-
fprintf(stderr,
"InnoDB: Error: the transaction object for the table handle is at\n"
-"InnoDB: %lx, but for the current thread it is at %lx\n",
- (ulong)prebuilt->trx,
- (ulong)current_thd->transaction.all.innobase_tid);
-
- ut_sprintf_buf(err_buf, ((byte*)prebuilt) - 100, 200);
- fprintf(stderr,
-"InnoDB: Dump of 200 bytes around prebuilt: %.1000s\n", err_buf);
-
- ut_sprintf_buf(err_buf,
+"InnoDB: %p, but for the current thread it is at %p\n",
+ prebuilt->trx,
+ current_thd->transaction.all.innobase_tid);
+ fputs("InnoDB: Dump of 200 bytes around prebuilt: ", stderr);
+ ut_print_buf(stderr, ((const byte*)prebuilt) - 100, 200);
+ fputs("\n"
+ "InnoDB: Dump of 200 bytes around transaction.all: ",
+ stderr);
+ ut_print_buf(stderr,
((byte*)(&(current_thd->transaction.all))) - 100, 200);
- fprintf(stderr,
-"InnoDB: Dump of 200 bytes around transaction.all: %.1000s\n", err_buf);
-
- ut_a(0);
+ putc('\n', stderr);
+ ut_error;
}
statistic_increment(ha_write_count, &LOCK_status);
@@ -3390,12 +3378,9 @@ create_index(
field = form->field[j];
- if (strlen(field->field_name)
- == strlen(key_part->field->field_name)
- && 0 == ut_cmp_in_lower_case(
+ if (0 == ut_cmp_in_lower_case(
(char*)field->field_name,
- (char*)key_part->field->field_name,
- strlen(field->field_name))) {
+ (char*)key_part->field->field_name)) {
/* Found the corresponding column */
break;
@@ -3762,7 +3747,8 @@ ha_innobase::delete_table(
/* Drop the table in InnoDB */
- error = row_drop_table_for_mysql(norm_name, trx);
+ error = row_drop_table_for_mysql(norm_name, trx,
+ thd->lex.sql_command == SQLCOM_DROP_DB);
/* Flush the log to reduce probability that the .frm files and
the InnoDB data dictionary get out-of-sync if the user runs
@@ -3801,7 +3787,7 @@ innobase_drop_database(
trx_t* trx;
char* ptr;
int error;
- char namebuf[10000];
+ char* namebuf;
/* Get the transaction associated with the current thd, or create one
if not yet created */
@@ -3821,6 +3807,7 @@ innobase_drop_database(
}
ptr++;
+ namebuf = my_malloc(len + 2, MYF(0));
memcpy(namebuf, ptr, len);
namebuf[len] = '/';
@@ -3837,6 +3824,7 @@ innobase_drop_database(
}
error = row_drop_database_for_mysql(namebuf, trx);
+ my_free(namebuf, MYF(0));
/* Flush the log to reduce probability that the .frm files and
the InnoDB data dictionary get out-of-sync if the user runs
@@ -4361,15 +4349,18 @@ ha_innobase::update_table_comment(
info on foreign keys */
const char* comment)/* in: table comment defined by user */
{
- row_prebuilt_t* prebuilt = (row_prebuilt_t*)innobase_prebuilt;
- uint length = strlen(comment);
- char* str = my_malloc(length + 16500, MYF(0));
- char* pos;
+ uint length = strlen(comment);
+ char* str;
+ row_prebuilt_t* prebuilt = (row_prebuilt_t*)innobase_prebuilt;
/* We do not know if MySQL can call this function before calling
external_lock(). To be safe, update the thd of the current table
handle. */
+ if(length > 64000 - 3) {
+ return((char*)comment); /* string too long */
+ }
+
update_thd(current_thd);
prebuilt->trx->op_info = (char*)"returning table comment";
@@ -4378,37 +4369,47 @@ ha_innobase::update_table_comment(
possible adaptive hash latch to avoid deadlocks of threads */
trx_search_latch_release_if_reserved(prebuilt->trx);
-
- if (!str) {
- prebuilt->trx->op_info = (char*)"";
+ str = NULL;
- return((char*)comment);
- }
+ if (FILE* file = tmpfile()) {
+ long flen;
- pos = str;
- if (length) {
- pos=strmov(str, comment);
- *pos++=';';
- *pos++=' ';
- }
+ /* output the data to a temporary file */
+ fprintf(file, "InnoDB free: %lu kB",
+ (ulong) fsp_get_available_space_in_free_extents(
+ prebuilt->table->space));
+
+ dict_print_info_on_foreign_keys(FALSE, file, prebuilt->table);
+ flen = ftell(file);
+ if(length + flen + 3 > 64000) {
+ flen = 64000 - 3 - length;
+ }
- pos += my_sprintf(pos,
- (pos,"InnoDB free: %lu kB",
- (ulong) fsp_get_available_space_in_free_extents(
- prebuilt->table->space)));
+ ut_ad(flen > 0);
- /* We assume 16000 - length bytes of space to print info; the limit
- 16000 bytes is arbitrary, and MySQL could handle at least 64000
- bytes */
-
- if (length < 16000) {
- dict_print_info_on_foreign_keys(FALSE, pos, 16000 - length,
- prebuilt->table);
+ /* allocate buffer for the full string, and
+ read the contents of the temporary file */
+
+ str = my_malloc(length + flen + 3, MYF(0));
+
+ if (str) {
+ char* pos = str + length;
+ if(length) {
+ memcpy(str, comment, length);
+ *pos++ = ';';
+ *pos++ = ' ';
+ }
+ rewind(file);
+ flen = fread(pos, 1, flen, file);
+ pos[flen] = 0;
+ }
+
+ fclose(file);
}
prebuilt->trx->op_info = (char*)"";
- return(str);
+ return(str ? str : (char*) comment);
}
/***********************************************************************
@@ -4422,7 +4423,7 @@ ha_innobase::get_foreign_key_create_info(void)
MUST be freed with ::free_foreign_key_create_info */
{
row_prebuilt_t* prebuilt = (row_prebuilt_t*)innobase_prebuilt;
- char* str;
+ char* str = 0;
ut_a(prebuilt != NULL);
@@ -4432,23 +4433,47 @@ ha_innobase::get_foreign_key_create_info(void)
update_thd(current_thd);
- prebuilt->trx->op_info = (char*)"getting info on foreign keys";
+ if (FILE* file = tmpfile()) {
+ long flen;
- /* In case MySQL calls this in the middle of a SELECT query, release
- possible adaptive hash latch to avoid deadlocks of threads */
+ prebuilt->trx->op_info = (char*)"getting info on foreign keys";
- trx_search_latch_release_if_reserved(prebuilt->trx);
-
- str = (char*)ut_malloc(10000);
+ /* In case MySQL calls this in the middle of a SELECT query,
+ release possible adaptive hash latch to avoid
+ deadlocks of threads */
- str[0] = '\0';
-
- dict_print_info_on_foreign_keys(TRUE, str, 9000, prebuilt->table);
+ trx_search_latch_release_if_reserved(prebuilt->trx);
- prebuilt->trx->op_info = (char*)"";
+ /* output the data to a temporary file */
+ dict_print_info_on_foreign_keys(TRUE, file, prebuilt->table);
+ prebuilt->trx->op_info = (char*)"";
+
+ flen = ftell(file);
+ if(flen > 64000 - 1) {
+ flen = 64000 - 1;
+ }
+
+ ut_ad(flen >= 0);
+
+ /* allocate buffer for the string, and
+ read the contents of the temporary file */
+
+ str = my_malloc(flen + 1, MYF(0));
+
+ if (str) {
+ rewind(file);
+ flen = fread(str, 1, flen, file);
+ str[flen] = 0;
+ }
+
+ fclose(file);
+ } else {
+ /* unable to create temporary file */
+ str = my_malloc(1, MYF(MY_ZEROFILL));
+ }
return(str);
-}
+}
/***********************************************************************
Checks if a table is referenced by a foreign key. The MySQL manual states that
@@ -4481,7 +4506,7 @@ ha_innobase::free_foreign_key_create_info(
char* str) /* in, own: create info string to free */
{
if (str) {
- ut_free(str);
+ my_free(str, MYF(0));
}
}
@@ -4772,34 +4797,55 @@ innodb_show_status(
innobase_release_stat_resources(trx);
- /* We let the InnoDB Monitor to output at most 60 kB of text, add
- a safety margin of 100 kB for buffer overruns */
+ /* We let the InnoDB Monitor to output at most 64000 bytes of text. */
- buf = (char*)ut_malloc(160 * 1024);
+ long flen;
+ char* str;
- srv_sprintf_innodb_monitor(buf, 60 * 1024);
+ mutex_enter_noninline(&srv_monitor_file_mutex);
+ rewind(srv_monitor_file);
+ srv_printf_innodb_monitor(srv_monitor_file);
+ flen = ftell(srv_monitor_file);
+ if(flen > 64000 - 1) {
+ flen = 64000 - 1;
+ }
- List<Item> field_list;
+ ut_ad(flen > 0);
- field_list.push_back(new Item_empty_string("Status", strlen(buf)));
+ /* allocate buffer for the string, and
+ read the contents of the temporary file */
- if (protocol->send_fields(&field_list, 1))
+ if (!(str = my_malloc(flen + 1, MYF(0))))
{
- ut_free(buf);
- DBUG_RETURN(-1);
+ mutex_exit_noninline(&srv_monitor_file_mutex);
+ DBUG_RETURN(-1);
}
- protocol->prepare_for_resend();
- protocol->store(buf, strlen(buf), system_charset_info);
+ rewind(srv_monitor_file);
+ flen = fread(str, 1, flen, srv_monitor_file);
+
+ mutex_exit_noninline(&srv_monitor_file_mutex);
+
+ List<Item> field_list;
- ut_free(buf);
+ field_list.push_back(new Item_empty_string("Status", flen));
+
+ if (protocol->send_fields(field_list, 1)) {
+
+ my_free(str, MYF(0));
+
+ DBUG_RETURN(-1);
+ }
+
+ protocol->prepare_for_resend();
+ protocol->store(str, flen, system_charset_info);
+ my_free(str, MYF(0));
if (protocol->write())
DBUG_RETURN(-1);
- send_eof(thd);
-
- DBUG_RETURN(0);
+ send_eof(&thd->net);
+ DBUG_RETURN(0);
}
/****************************************************************************