2005-10-27 09:29:40 +02:00
|
|
|
/******************************************************
|
|
|
|
Interface between Innobase row operations and MySQL.
|
|
|
|
Contains also create table and other data dictionary operations.
|
|
|
|
|
|
|
|
(c) 2000 Innobase Oy
|
|
|
|
|
|
|
|
Created 9/17/2000 Heikki Tuuri
|
|
|
|
*******************************************************/
|
|
|
|
|
|
|
|
#include "row0mysql.h"
|
|
|
|
|
|
|
|
#ifdef UNIV_NONINL
|
|
|
|
#include "row0mysql.ic"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "row0ins.h"
|
|
|
|
#include "row0sel.h"
|
|
|
|
#include "row0upd.h"
|
|
|
|
#include "row0row.h"
|
|
|
|
#include "que0que.h"
|
|
|
|
#include "pars0pars.h"
|
|
|
|
#include "dict0dict.h"
|
|
|
|
#include "dict0crea.h"
|
|
|
|
#include "dict0load.h"
|
|
|
|
#include "dict0boot.h"
|
|
|
|
#include "trx0roll.h"
|
|
|
|
#include "trx0purge.h"
|
2007-04-04 13:05:33 +02:00
|
|
|
#include "trx0rec.h"
|
|
|
|
#include "trx0undo.h"
|
2005-10-27 09:29:40 +02:00
|
|
|
#include "lock0lock.h"
|
|
|
|
#include "rem0cmp.h"
|
|
|
|
#include "log0log.h"
|
|
|
|
#include "btr0sea.h"
|
|
|
|
#include "fil0fil.h"
|
|
|
|
#include "ibuf0ibuf.h"
|
|
|
|
|
2007-01-18 13:58:39 +01:00
|
|
|
/* Provide optional 4.x backwards compatibility for 5.0 and above */
|
2008-02-06 15:17:36 +01:00
|
|
|
UNIV_INTERN ibool row_rollback_on_timeout = FALSE;
|
2007-01-18 13:58:39 +01:00
|
|
|
|
2005-10-27 09:29:40 +02:00
|
|
|
/* List of tables we should drop in background. ALTER TABLE in MySQL requires
|
|
|
|
that the table handler can drop the table in background when there are no
|
|
|
|
queries to it any more. Protected by the kernel mutex. */
|
|
|
|
typedef struct row_mysql_drop_struct row_mysql_drop_t;
|
|
|
|
struct row_mysql_drop_struct{
|
|
|
|
char* table_name;
|
|
|
|
UT_LIST_NODE_T(row_mysql_drop_t) row_mysql_drop_list;
|
|
|
|
};
|
|
|
|
|
2008-02-06 15:17:36 +01:00
|
|
|
static UT_LIST_BASE_NODE_T(row_mysql_drop_t) row_mysql_drop_list;
|
|
|
|
static ibool row_mysql_drop_list_inited = FALSE;
|
2005-10-27 09:29:40 +02:00
|
|
|
|
|
|
|
/* Magic table names for invoking various monitor threads */
|
|
|
|
static const char S_innodb_monitor[] = "innodb_monitor";
|
|
|
|
static const char S_innodb_lock_monitor[] = "innodb_lock_monitor";
|
|
|
|
static const char S_innodb_tablespace_monitor[] = "innodb_tablespace_monitor";
|
|
|
|
static const char S_innodb_table_monitor[] = "innodb_table_monitor";
|
|
|
|
static const char S_innodb_mem_validate[] = "innodb_mem_validate";
|
|
|
|
|
2008-02-18 21:09:03 +01:00
|
|
|
/* Evaluates to true if str1 equals str2_onstack, used for comparing
|
|
|
|
the above strings. */
|
|
|
|
#define STR_EQ(str1, str1_len, str2_onstack) \
|
|
|
|
((str1_len) == sizeof(str2_onstack) \
|
|
|
|
&& memcmp(str1, str2_onstack, sizeof(str2_onstack)) == 0)
|
|
|
|
|
2006-11-30 16:25:52 +01:00
|
|
|
#ifndef UNIV_HOTBACKUP
|
2005-10-27 09:29:40 +02:00
|
|
|
/***********************************************************************
|
|
|
|
Determine if the given name is a name reserved for MySQL system tables. */
|
|
|
|
static
|
|
|
|
ibool
|
|
|
|
row_mysql_is_system_table(
|
|
|
|
/*======================*/
|
|
|
|
/* out: TRUE if name is a MySQL
|
|
|
|
system table name */
|
|
|
|
const char* name)
|
|
|
|
{
|
2006-04-12 11:32:17 +02:00
|
|
|
if (strncmp(name, "mysql/", 6) != 0) {
|
|
|
|
|
2005-10-27 09:29:40 +02:00
|
|
|
return(FALSE);
|
|
|
|
}
|
2006-04-12 11:32:17 +02:00
|
|
|
|
2005-10-27 09:29:40 +02:00
|
|
|
return(0 == strcmp(name + 6, "host")
|
2006-08-29 11:30:31 +02:00
|
|
|
|| 0 == strcmp(name + 6, "user")
|
|
|
|
|| 0 == strcmp(name + 6, "db"));
|
2005-10-27 09:29:40 +02:00
|
|
|
}
|
2006-11-30 16:25:52 +01:00
|
|
|
#endif /* !UNIV_HOTBACKUP */
|
2005-10-27 09:29:40 +02:00
|
|
|
|
2007-09-11 07:09:19 +02:00
|
|
|
/*************************************************************************
|
|
|
|
If a table is not yet in the drop list, adds the table to the list of tables
|
|
|
|
which the master thread drops in background. We need this on Unix because in
|
|
|
|
ALTER TABLE MySQL may call drop table even if the table has running queries on
|
|
|
|
it. Also, if there are running foreign key checks on the table, we drop the
|
|
|
|
table lazily. */
|
|
|
|
static
|
|
|
|
ibool
|
|
|
|
row_add_table_to_background_drop_list(
|
|
|
|
/*==================================*/
|
|
|
|
/* out: TRUE if the table was not yet in the
|
|
|
|
drop list, and was added there */
|
|
|
|
const char* name); /* in: table name */
|
2007-04-04 13:05:33 +02:00
|
|
|
|
2005-10-27 09:29:40 +02:00
|
|
|
/***********************************************************************
|
|
|
|
Delays an INSERT, DELETE or UPDATE operation if the purge is lagging. */
|
|
|
|
static
|
|
|
|
void
|
|
|
|
row_mysql_delay_if_needed(void)
|
|
|
|
/*===========================*/
|
|
|
|
{
|
|
|
|
if (srv_dml_needed_delay) {
|
|
|
|
os_thread_sleep(srv_dml_needed_delay);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
Frees the blob heap in prebuilt when no longer needed. */
|
2008-02-06 15:17:36 +01:00
|
|
|
UNIV_INTERN
|
2005-10-27 09:29:40 +02:00
|
|
|
void
|
|
|
|
row_mysql_prebuilt_free_blob_heap(
|
|
|
|
/*==============================*/
|
|
|
|
row_prebuilt_t* prebuilt) /* in: prebuilt struct of a
|
|
|
|
ha_innobase:: table handle */
|
|
|
|
{
|
|
|
|
mem_heap_free(prebuilt->blob_heap);
|
|
|
|
prebuilt->blob_heap = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
Stores a >= 5.0.3 format true VARCHAR length to dest, in the MySQL row
|
|
|
|
format. */
|
2008-02-06 15:17:36 +01:00
|
|
|
UNIV_INTERN
|
2005-10-27 09:29:40 +02:00
|
|
|
byte*
|
|
|
|
row_mysql_store_true_var_len(
|
|
|
|
/*=========================*/
|
|
|
|
/* out: pointer to the data, we skip the 1 or 2 bytes
|
|
|
|
at the start that are used to store the len */
|
|
|
|
byte* dest, /* in: where to store */
|
|
|
|
ulint len, /* in: length, must fit in two bytes */
|
|
|
|
ulint lenlen) /* in: storage length of len: either 1 or 2 bytes */
|
|
|
|
{
|
|
|
|
if (lenlen == 2) {
|
|
|
|
ut_a(len < 256 * 256);
|
|
|
|
|
|
|
|
mach_write_to_2_little_endian(dest, len);
|
|
|
|
|
|
|
|
return(dest + 2);
|
|
|
|
}
|
|
|
|
|
|
|
|
ut_a(lenlen == 1);
|
|
|
|
ut_a(len < 256);
|
|
|
|
|
|
|
|
mach_write_to_1(dest, len);
|
|
|
|
|
|
|
|
return(dest + 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
Reads a >= 5.0.3 format true VARCHAR length, in the MySQL row format, and
|
|
|
|
returns a pointer to the data. */
|
2008-02-06 15:17:36 +01:00
|
|
|
UNIV_INTERN
|
2007-08-03 09:09:29 +02:00
|
|
|
const byte*
|
2005-10-27 09:29:40 +02:00
|
|
|
row_mysql_read_true_varchar(
|
|
|
|
/*========================*/
|
2007-08-03 09:09:29 +02:00
|
|
|
/* out: pointer to the data, we skip
|
|
|
|
the 1 or 2 bytes at the start that are
|
|
|
|
used to store the len */
|
|
|
|
ulint* len, /* out: variable-length field length */
|
|
|
|
const byte* field, /* in: field in the MySQL format */
|
|
|
|
ulint lenlen) /* in: storage length of len: either 1
|
|
|
|
or 2 bytes */
|
2005-10-27 09:29:40 +02:00
|
|
|
{
|
|
|
|
if (lenlen == 2) {
|
|
|
|
*len = mach_read_from_2_little_endian(field);
|
|
|
|
|
|
|
|
return(field + 2);
|
|
|
|
}
|
|
|
|
|
|
|
|
ut_a(lenlen == 1);
|
|
|
|
|
|
|
|
*len = mach_read_from_1(field);
|
|
|
|
|
|
|
|
return(field + 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
Stores a reference to a BLOB in the MySQL format. */
|
2008-02-06 15:17:36 +01:00
|
|
|
UNIV_INTERN
|
2005-10-27 09:29:40 +02:00
|
|
|
void
|
|
|
|
row_mysql_store_blob_ref(
|
|
|
|
/*=====================*/
|
2007-09-27 12:59:54 +02:00
|
|
|
byte* dest, /* in: where to store */
|
|
|
|
ulint col_len,/* in: dest buffer size: determines into
|
2005-10-27 09:29:40 +02:00
|
|
|
how many bytes the BLOB length is stored,
|
|
|
|
the space for the length may vary from 1
|
|
|
|
to 4 bytes */
|
2007-09-27 12:59:54 +02:00
|
|
|
const void* data, /* in: BLOB data; if the value to store
|
2005-10-27 09:29:40 +02:00
|
|
|
is SQL NULL this should be NULL pointer */
|
2007-09-27 12:59:54 +02:00
|
|
|
ulint len) /* in: BLOB length; if the value to store
|
2005-10-27 09:29:40 +02:00
|
|
|
is SQL NULL this should be 0; remember
|
|
|
|
also to set the NULL bit in the MySQL record
|
|
|
|
header! */
|
|
|
|
{
|
|
|
|
/* MySQL might assume the field is set to zero except the length and
|
|
|
|
the pointer fields */
|
|
|
|
|
|
|
|
memset(dest, '\0', col_len);
|
|
|
|
|
|
|
|
/* In dest there are 1 - 4 bytes reserved for the BLOB length,
|
|
|
|
and after that 8 bytes reserved for the pointer to the data.
|
|
|
|
In 32-bit architectures we only use the first 4 bytes of the pointer
|
|
|
|
slot. */
|
|
|
|
|
|
|
|
ut_a(col_len - 8 > 1 || len < 256);
|
|
|
|
ut_a(col_len - 8 > 2 || len < 256 * 256);
|
|
|
|
ut_a(col_len - 8 > 3 || len < 256 * 256 * 256);
|
|
|
|
|
|
|
|
mach_write_to_n_little_endian(dest, col_len - 8, len);
|
|
|
|
|
2007-09-27 12:59:54 +02:00
|
|
|
memcpy(dest + col_len - 8, &data, sizeof data);
|
2005-10-27 09:29:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
Reads a reference to a BLOB in the MySQL format. */
|
2008-02-06 15:17:36 +01:00
|
|
|
UNIV_INTERN
|
2007-08-03 09:09:29 +02:00
|
|
|
const byte*
|
2005-10-27 09:29:40 +02:00
|
|
|
row_mysql_read_blob_ref(
|
|
|
|
/*====================*/
|
2007-08-03 09:09:29 +02:00
|
|
|
/* out: pointer to BLOB data */
|
|
|
|
ulint* len, /* out: BLOB length */
|
|
|
|
const byte* ref, /* in: BLOB reference in the
|
|
|
|
MySQL format */
|
|
|
|
ulint col_len) /* in: BLOB reference length
|
|
|
|
(not BLOB length) */
|
2005-10-27 09:29:40 +02:00
|
|
|
{
|
2008-05-14 17:43:19 +02:00
|
|
|
byte* data;
|
2005-10-27 09:29:40 +02:00
|
|
|
|
|
|
|
*len = mach_read_from_n_little_endian(ref, col_len - 8);
|
|
|
|
|
2007-08-03 09:35:05 +02:00
|
|
|
memcpy(&data, ref + col_len - 8, sizeof data);
|
2005-10-27 09:29:40 +02:00
|
|
|
|
|
|
|
return(data);
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
Stores a non-SQL-NULL field given in the MySQL format in the InnoDB format.
|
|
|
|
The counterpart of this function is row_sel_field_store_in_mysql_format() in
|
|
|
|
row0sel.c. */
|
2008-02-06 15:17:36 +01:00
|
|
|
UNIV_INTERN
|
2005-10-27 09:29:40 +02:00
|
|
|
byte*
|
|
|
|
row_mysql_store_col_in_innobase_format(
|
|
|
|
/*===================================*/
|
|
|
|
/* out: up to which byte we used
|
|
|
|
buf in the conversion */
|
|
|
|
dfield_t* dfield, /* in/out: dfield where dtype
|
|
|
|
information must be already set when
|
|
|
|
this function is called! */
|
|
|
|
byte* buf, /* in/out: buffer for a converted
|
|
|
|
integer value; this must be at least
|
|
|
|
col_len long then! */
|
|
|
|
ibool row_format_col, /* TRUE if the mysql_data is from
|
|
|
|
a MySQL row, FALSE if from a MySQL
|
|
|
|
key value;
|
|
|
|
in MySQL, a true VARCHAR storage
|
|
|
|
format differs in a row and in a
|
|
|
|
key value: in a key value the length
|
|
|
|
is always stored in 2 bytes! */
|
2007-08-03 09:09:29 +02:00
|
|
|
const byte* mysql_data, /* in: MySQL column value, not
|
2005-10-27 09:29:40 +02:00
|
|
|
SQL NULL; NOTE that dfield may also
|
|
|
|
get a pointer to mysql_data,
|
|
|
|
therefore do not discard this as long
|
|
|
|
as dfield is used! */
|
|
|
|
ulint col_len, /* in: MySQL column length; NOTE that
|
|
|
|
this is the storage length of the
|
|
|
|
column in the MySQL format row, not
|
|
|
|
necessarily the length of the actual
|
|
|
|
payload data; if the column is a true
|
|
|
|
VARCHAR then this is irrelevant */
|
|
|
|
ulint comp) /* in: nonzero=compact format */
|
|
|
|
{
|
2007-08-03 09:09:29 +02:00
|
|
|
const byte* ptr = mysql_data;
|
2006-10-17 14:24:13 +02:00
|
|
|
const dtype_t* dtype;
|
2005-10-27 09:29:40 +02:00
|
|
|
ulint type;
|
|
|
|
ulint lenlen;
|
|
|
|
|
|
|
|
dtype = dfield_get_type(dfield);
|
|
|
|
|
|
|
|
type = dtype->mtype;
|
|
|
|
|
|
|
|
if (type == DATA_INT) {
|
|
|
|
/* Store integer data in Innobase in a big-endian format,
|
|
|
|
sign bit negated if the data is a signed integer. In MySQL,
|
|
|
|
integers are stored in a little-endian format. */
|
|
|
|
|
2007-08-03 09:09:29 +02:00
|
|
|
byte* p = buf + col_len;
|
2005-10-27 09:29:40 +02:00
|
|
|
|
|
|
|
for (;;) {
|
2007-08-03 09:09:29 +02:00
|
|
|
p--;
|
|
|
|
*p = *mysql_data;
|
2007-08-03 09:35:05 +02:00
|
|
|
if (p == buf) {
|
2005-10-27 09:29:40 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
mysql_data++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!(dtype->prtype & DATA_UNSIGNED)) {
|
|
|
|
|
2007-08-03 09:35:05 +02:00
|
|
|
*buf ^= 128;
|
2005-10-27 09:29:40 +02:00
|
|
|
}
|
|
|
|
|
2007-08-03 09:35:05 +02:00
|
|
|
ptr = buf;
|
2005-10-27 09:29:40 +02:00
|
|
|
buf += col_len;
|
|
|
|
} else if ((type == DATA_VARCHAR
|
2006-08-29 11:30:31 +02:00
|
|
|
|| type == DATA_VARMYSQL
|
|
|
|
|| type == DATA_BINARY)) {
|
2005-10-27 09:29:40 +02:00
|
|
|
|
|
|
|
if (dtype_get_mysql_type(dtype) == DATA_MYSQL_TRUE_VARCHAR) {
|
|
|
|
/* The length of the actual data is stored to 1 or 2
|
|
|
|
bytes at the start of the field */
|
2006-02-23 20:25:29 +01:00
|
|
|
|
2005-10-27 09:29:40 +02:00
|
|
|
if (row_format_col) {
|
|
|
|
if (dtype->prtype & DATA_LONG_TRUE_VARCHAR) {
|
|
|
|
lenlen = 2;
|
|
|
|
} else {
|
|
|
|
lenlen = 1;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* In a MySQL key value, lenlen is always 2 */
|
|
|
|
lenlen = 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
ptr = row_mysql_read_true_varchar(&col_len, mysql_data,
|
2006-08-29 11:30:31 +02:00
|
|
|
lenlen);
|
2005-10-27 09:29:40 +02:00
|
|
|
} else {
|
|
|
|
/* Remove trailing spaces from old style VARCHAR
|
|
|
|
columns. */
|
|
|
|
|
|
|
|
/* Handle UCS2 strings differently. */
|
|
|
|
ulint mbminlen = dtype_get_mbminlen(dtype);
|
|
|
|
|
|
|
|
ptr = mysql_data;
|
|
|
|
|
|
|
|
if (mbminlen == 2) {
|
|
|
|
/* space=0x0020 */
|
|
|
|
/* Trim "half-chars", just in case. */
|
|
|
|
col_len &= ~1;
|
|
|
|
|
|
|
|
while (col_len >= 2 && ptr[col_len - 2] == 0x00
|
2006-08-29 11:30:31 +02:00
|
|
|
&& ptr[col_len - 1] == 0x20) {
|
2005-10-27 09:29:40 +02:00
|
|
|
col_len -= 2;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
ut_a(mbminlen == 1);
|
|
|
|
/* space=0x20 */
|
|
|
|
while (col_len > 0
|
2006-08-29 11:30:31 +02:00
|
|
|
&& ptr[col_len - 1] == 0x20) {
|
2005-10-27 09:29:40 +02:00
|
|
|
col_len--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (comp && type == DATA_MYSQL
|
2006-08-29 11:30:31 +02:00
|
|
|
&& dtype_get_mbminlen(dtype) == 1
|
|
|
|
&& dtype_get_mbmaxlen(dtype) > 1) {
|
2005-10-27 09:29:40 +02:00
|
|
|
/* In some cases we strip trailing spaces from UTF-8 and other
|
|
|
|
multibyte charsets, from FIXED-length CHAR columns, to save
|
|
|
|
space. UTF-8 would otherwise normally use 3 * the string length
|
|
|
|
bytes to store a latin1 string! */
|
|
|
|
|
|
|
|
/* We assume that this CHAR field is encoded in a
|
|
|
|
variable-length character set where spaces have
|
|
|
|
1:1 correspondence to 0x20 bytes, such as UTF-8.
|
|
|
|
|
|
|
|
Consider a CHAR(n) field, a field of n characters.
|
|
|
|
It will contain between n * mbminlen and n * mbmaxlen bytes.
|
|
|
|
We will try to truncate it to n bytes by stripping
|
2006-02-23 20:25:29 +01:00
|
|
|
space padding. If the field contains single-byte
|
2005-10-27 09:29:40 +02:00
|
|
|
characters only, it will be truncated to n characters.
|
|
|
|
Consider a CHAR(5) field containing the string ".a "
|
|
|
|
where "." denotes a 3-byte character represented by
|
|
|
|
the bytes "$%&". After our stripping, the string will
|
2006-02-23 20:25:29 +01:00
|
|
|
be stored as "$%&a " (5 bytes). The string ".abc "
|
2005-10-27 09:29:40 +02:00
|
|
|
will be stored as "$%&abc" (6 bytes).
|
|
|
|
|
|
|
|
The space padding will be restored in row0sel.c, function
|
|
|
|
row_sel_field_store_in_mysql_format(). */
|
|
|
|
|
|
|
|
ulint n_chars;
|
|
|
|
|
|
|
|
ut_a(!(dtype_get_len(dtype) % dtype_get_mbmaxlen(dtype)));
|
|
|
|
|
|
|
|
n_chars = dtype_get_len(dtype) / dtype_get_mbmaxlen(dtype);
|
|
|
|
|
|
|
|
/* Strip space padding. */
|
|
|
|
while (col_len > n_chars && ptr[col_len - 1] == 0x20) {
|
|
|
|
col_len--;
|
|
|
|
}
|
|
|
|
} else if (type == DATA_BLOB && row_format_col) {
|
|
|
|
|
|
|
|
ptr = row_mysql_read_blob_ref(&col_len, mysql_data, col_len);
|
|
|
|
}
|
|
|
|
|
|
|
|
dfield_set_data(dfield, ptr, col_len);
|
|
|
|
|
|
|
|
return(buf);
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
Convert a row in the MySQL format to a row in the Innobase format. Note that
|
|
|
|
the function to convert a MySQL format key value to an InnoDB dtuple is
|
|
|
|
row_sel_convert_mysql_key_to_innobase() in row0sel.c. */
|
|
|
|
static
|
|
|
|
void
|
|
|
|
row_mysql_convert_row_to_innobase(
|
|
|
|
/*==============================*/
|
|
|
|
dtuple_t* row, /* in/out: Innobase row where the
|
|
|
|
field type information is already
|
|
|
|
copied there! */
|
|
|
|
row_prebuilt_t* prebuilt, /* in: prebuilt struct where template
|
|
|
|
must be of type ROW_MYSQL_WHOLE_ROW */
|
|
|
|
byte* mysql_rec) /* in: row in the MySQL format;
|
|
|
|
NOTE: do not discard as long as
|
|
|
|
row is used, as row may contain
|
|
|
|
pointers to this record! */
|
|
|
|
{
|
2006-02-23 20:25:29 +01:00
|
|
|
mysql_row_templ_t* templ;
|
2005-10-27 09:29:40 +02:00
|
|
|
dfield_t* dfield;
|
|
|
|
ulint i;
|
2006-02-23 20:25:29 +01:00
|
|
|
|
2005-10-27 09:29:40 +02:00
|
|
|
ut_ad(prebuilt->template_type == ROW_MYSQL_WHOLE_ROW);
|
|
|
|
ut_ad(prebuilt->mysql_template);
|
|
|
|
|
|
|
|
for (i = 0; i < prebuilt->n_template; i++) {
|
|
|
|
|
|
|
|
templ = prebuilt->mysql_template + i;
|
2006-10-19 09:27:26 +02:00
|
|
|
dfield = dtuple_get_nth_field(row, i);
|
2005-10-27 09:29:40 +02:00
|
|
|
|
|
|
|
if (templ->mysql_null_bit_mask != 0) {
|
|
|
|
/* Column may be SQL NULL */
|
|
|
|
|
2006-08-29 11:30:31 +02:00
|
|
|
if (mysql_rec[templ->mysql_null_byte_offset]
|
|
|
|
& (byte) (templ->mysql_null_bit_mask)) {
|
2005-10-27 09:29:40 +02:00
|
|
|
|
|
|
|
/* It is SQL NULL */
|
|
|
|
|
branches/zip: Make merge sort handle externally stored columns.
Some things still fail in innodb-index.test, and there seems to be
a race condition (data dictionary lock wait) when running with --valgrind.
dfield_t: Add an "external storage" flag, dfield->ext.
dfield_is_null(), dfield_is_ext(), dfield_set_ext(), dfield_set_null():
New functions.
dfield_copy(), dfield_copy_data(): Add const qualifiers, fix in/out comments.
data_write_sql_null(): Use memset().
big_rec_field_t: Replace byte* data with const void* data.
ut_ulint_sort(): Remove.
upd_field_t: Remove extern_storage.
upd_node_t: Replace ext_vec, n_ext_vec with n_ext.
row_merge_copy_blobs(): New function.
row_ins_index_entry(): Add the parameter "ibool foreign" for suppressing
foreign key checks during fast index creation or when inserting into
secondary indexes.
btr_page_insert_fits(): Add const qualifiers.
btr_cur_add_ext(), upd_ext_vec_contains(): Remove.
dfield_print_also_hex(), dfield_print(): Replace if...else if with switch.
Observe dfield_is_ext().
2007-06-21 11:43:15 +02:00
|
|
|
dfield_set_null(dfield);
|
2005-10-27 09:29:40 +02:00
|
|
|
|
|
|
|
goto next_column;
|
|
|
|
}
|
2006-02-23 20:25:29 +01:00
|
|
|
}
|
|
|
|
|
2006-09-19 12:14:07 +02:00
|
|
|
row_mysql_store_col_in_innobase_format(
|
|
|
|
dfield,
|
|
|
|
prebuilt->ins_upd_rec_buff + templ->mysql_col_offset,
|
|
|
|
TRUE, /* MySQL row format data */
|
|
|
|
mysql_rec + templ->mysql_col_offset,
|
|
|
|
templ->mysql_col_len,
|
|
|
|
dict_table_is_comp(prebuilt->table));
|
2005-10-27 09:29:40 +02:00
|
|
|
next_column:
|
|
|
|
;
|
2006-02-23 20:25:29 +01:00
|
|
|
}
|
2005-10-27 09:29:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/********************************************************************
|
|
|
|
Handles user errors and lock waits detected by the database engine. */
|
2008-02-06 15:17:36 +01:00
|
|
|
UNIV_INTERN
|
2005-10-27 09:29:40 +02:00
|
|
|
ibool
|
|
|
|
row_mysql_handle_errors(
|
|
|
|
/*====================*/
|
|
|
|
/* out: TRUE if it was a lock wait and
|
|
|
|
we should continue running the query thread */
|
|
|
|
ulint* new_err,/* out: possible new error encountered in
|
|
|
|
lock wait, or if no new error, the value
|
|
|
|
of trx->error_state at the entry of this
|
|
|
|
function */
|
|
|
|
trx_t* trx, /* in: transaction */
|
|
|
|
que_thr_t* thr, /* in: query thread */
|
|
|
|
trx_savept_t* savept) /* in: savepoint or NULL */
|
|
|
|
{
|
|
|
|
#ifndef UNIV_HOTBACKUP
|
|
|
|
ulint err;
|
|
|
|
|
|
|
|
handle_new_error:
|
|
|
|
err = trx->error_state;
|
2006-02-23 20:25:29 +01:00
|
|
|
|
2005-10-27 09:29:40 +02:00
|
|
|
ut_a(err != DB_SUCCESS);
|
2006-02-23 20:25:29 +01:00
|
|
|
|
2005-10-27 09:29:40 +02:00
|
|
|
trx->error_state = DB_SUCCESS;
|
2006-02-23 20:25:29 +01:00
|
|
|
|
2007-08-15 17:35:48 +02:00
|
|
|
switch (err) {
|
|
|
|
case DB_LOCK_WAIT_TIMEOUT:
|
|
|
|
if (row_rollback_on_timeout) {
|
|
|
|
trx_general_rollback_for_mysql(trx, FALSE, NULL);
|
|
|
|
break;
|
2005-10-27 09:29:40 +02:00
|
|
|
}
|
2007-08-15 17:35:48 +02:00
|
|
|
/* fall through */
|
|
|
|
case DB_DUPLICATE_KEY:
|
|
|
|
case DB_FOREIGN_DUPLICATE_KEY:
|
|
|
|
case DB_TOO_BIG_RECORD:
|
|
|
|
case DB_ROW_IS_REFERENCED:
|
|
|
|
case DB_NO_REFERENCED_ROW:
|
|
|
|
case DB_CANNOT_ADD_CONSTRAINT:
|
|
|
|
case DB_TOO_MANY_CONCURRENT_TRXS:
|
|
|
|
case DB_OUT_OF_FILE_SPACE:
|
2006-02-23 20:25:29 +01:00
|
|
|
if (savept) {
|
2005-10-27 09:29:40 +02:00
|
|
|
/* Roll back the latest, possibly incomplete
|
|
|
|
insertion or update */
|
|
|
|
|
|
|
|
trx_general_rollback_for_mysql(trx, TRUE, savept);
|
|
|
|
}
|
|
|
|
/* MySQL will roll back the latest SQL statement */
|
2007-08-15 17:35:48 +02:00
|
|
|
break;
|
|
|
|
case DB_LOCK_WAIT:
|
2005-10-27 09:29:40 +02:00
|
|
|
srv_suspend_mysql_thread(thr);
|
|
|
|
|
|
|
|
if (trx->error_state != DB_SUCCESS) {
|
|
|
|
que_thr_stop_for_mysql(thr);
|
|
|
|
|
|
|
|
goto handle_new_error;
|
|
|
|
}
|
|
|
|
|
|
|
|
*new_err = err;
|
|
|
|
|
|
|
|
return(TRUE);
|
|
|
|
|
2007-08-15 17:35:48 +02:00
|
|
|
case DB_DEADLOCK:
|
|
|
|
case DB_LOCK_TABLE_FULL:
|
2005-10-27 09:29:40 +02:00
|
|
|
/* Roll back the whole transaction; this resolution was added
|
|
|
|
to version 3.23.43 */
|
|
|
|
|
|
|
|
trx_general_rollback_for_mysql(trx, FALSE, NULL);
|
2007-08-15 17:35:48 +02:00
|
|
|
break;
|
2006-02-23 20:25:29 +01:00
|
|
|
|
2007-08-15 17:35:48 +02:00
|
|
|
case DB_MUST_GET_MORE_FILE_SPACE:
|
2006-08-29 11:30:31 +02:00
|
|
|
fputs("InnoDB: The database cannot continue"
|
|
|
|
" operation because of\n"
|
|
|
|
"InnoDB: lack of space. You must add"
|
|
|
|
" a new data file to\n"
|
|
|
|
"InnoDB: my.cnf and restart the database.\n", stderr);
|
2006-02-23 20:25:29 +01:00
|
|
|
|
2005-10-27 09:29:40 +02:00
|
|
|
exit(1);
|
|
|
|
|
2007-08-15 17:35:48 +02:00
|
|
|
case DB_CORRUPTION:
|
2006-08-29 11:30:31 +02:00
|
|
|
fputs("InnoDB: We detected index corruption"
|
|
|
|
" in an InnoDB type table.\n"
|
|
|
|
"InnoDB: You have to dump + drop + reimport"
|
|
|
|
" the table or, in\n"
|
|
|
|
"InnoDB: a case of widespread corruption,"
|
|
|
|
" dump all InnoDB\n"
|
|
|
|
"InnoDB: tables and recreate the"
|
|
|
|
" whole InnoDB tablespace.\n"
|
|
|
|
"InnoDB: If the mysqld server crashes"
|
|
|
|
" after the startup or when\n"
|
|
|
|
"InnoDB: you dump the tables, look at\n"
|
|
|
|
"InnoDB: http://dev.mysql.com/doc/refman/5.1/en/"
|
|
|
|
"forcing-recovery.html"
|
|
|
|
" for help.\n", stderr);
|
2007-08-15 17:35:48 +02:00
|
|
|
break;
|
|
|
|
default:
|
2005-10-27 09:29:40 +02:00
|
|
|
fprintf(stderr, "InnoDB: unknown error code %lu\n",
|
|
|
|
(ulong) err);
|
|
|
|
ut_error;
|
2006-02-23 20:25:29 +01:00
|
|
|
}
|
2005-10-27 09:29:40 +02:00
|
|
|
|
|
|
|
if (trx->error_state != DB_SUCCESS) {
|
|
|
|
*new_err = trx->error_state;
|
|
|
|
} else {
|
|
|
|
*new_err = err;
|
|
|
|
}
|
2006-02-23 20:25:29 +01:00
|
|
|
|
2005-10-27 09:29:40 +02:00
|
|
|
trx->error_state = DB_SUCCESS;
|
|
|
|
|
|
|
|
return(FALSE);
|
|
|
|
#else /* UNIV_HOTBACKUP */
|
|
|
|
/* This function depends on MySQL code that is not included in
|
|
|
|
InnoDB Hot Backup builds. Besides, this function should never
|
|
|
|
be called in InnoDB Hot Backup. */
|
|
|
|
ut_error;
|
2006-02-23 20:25:29 +01:00
|
|
|
return(FALSE);
|
2005-10-27 09:29:40 +02:00
|
|
|
#endif /* UNIV_HOTBACKUP */
|
|
|
|
}
|
|
|
|
|
|
|
|
/************************************************************************
|
|
|
|
Create a prebuilt struct for a MySQL table handle. */
|
2008-02-06 15:17:36 +01:00
|
|
|
UNIV_INTERN
|
2005-10-27 09:29:40 +02:00
|
|
|
row_prebuilt_t*
|
|
|
|
row_create_prebuilt(
|
|
|
|
/*================*/
|
|
|
|
/* out, own: a prebuilt struct */
|
|
|
|
dict_table_t* table) /* in: Innobase table handle */
|
|
|
|
{
|
|
|
|
row_prebuilt_t* prebuilt;
|
|
|
|
mem_heap_t* heap;
|
|
|
|
dict_index_t* clust_index;
|
|
|
|
dtuple_t* ref;
|
|
|
|
ulint ref_len;
|
2006-02-23 20:25:29 +01:00
|
|
|
|
2007-06-11 16:39:04 +02:00
|
|
|
heap = mem_heap_create(sizeof *prebuilt + 128);
|
2005-10-27 09:29:40 +02:00
|
|
|
|
2007-08-16 15:25:56 +02:00
|
|
|
prebuilt = mem_heap_zalloc(heap, sizeof *prebuilt);
|
2005-10-27 09:29:40 +02:00
|
|
|
|
|
|
|
prebuilt->magic_n = ROW_PREBUILT_ALLOCATED;
|
|
|
|
prebuilt->magic_n2 = ROW_PREBUILT_ALLOCATED;
|
|
|
|
|
|
|
|
prebuilt->table = table;
|
|
|
|
|
|
|
|
prebuilt->sql_stat_start = TRUE;
|
|
|
|
prebuilt->heap = heap;
|
|
|
|
|
2006-02-23 20:25:29 +01:00
|
|
|
prebuilt->pcur = btr_pcur_create_for_mysql();
|
|
|
|
prebuilt->clust_pcur = btr_pcur_create_for_mysql();
|
2005-10-27 09:29:40 +02:00
|
|
|
|
|
|
|
prebuilt->select_lock_type = LOCK_NONE;
|
|
|
|
prebuilt->stored_select_lock_type = 99999999;
|
|
|
|
|
2006-09-19 12:14:07 +02:00
|
|
|
prebuilt->search_tuple = dtuple_create(
|
|
|
|
heap, 2 * dict_table_get_n_cols(table));
|
2006-02-23 20:25:29 +01:00
|
|
|
|
2005-10-27 09:29:40 +02:00
|
|
|
clust_index = dict_table_get_first_index(table);
|
|
|
|
|
|
|
|
/* Make sure that search_tuple is long enough for clustered index */
|
|
|
|
ut_a(2 * dict_table_get_n_cols(table) >= clust_index->n_fields);
|
|
|
|
|
|
|
|
ref_len = dict_index_get_n_unique(clust_index);
|
|
|
|
|
|
|
|
ref = dtuple_create(heap, ref_len);
|
|
|
|
|
|
|
|
dict_index_copy_types(ref, clust_index, ref_len);
|
|
|
|
|
|
|
|
prebuilt->clust_ref = ref;
|
|
|
|
|
branches/innodb+: Merge revisions 2835:2862 from branches/zip:
------------------------------------------------------------------------
r2838 | vasil | 2008-10-21 12:49:27 +0300 (Tue, 21 Oct 2008) | 61 lines
branches/zip:
Merge 2744:2837 from branches/5.1 (skipping r2782 and r2826):
------------------------------------------------------------------------
r2832 | vasil | 2008-10-21 10:08:30 +0300 (Tue, 21 Oct 2008) | 10 lines
Changed paths:
M /branches/5.1/handler/ha_innodb.cc
branches/5.1:
In ha_innobase::info():
Replace sql_print_warning() which prints to mysqld error log with
push_warning_printf() which sends the error message to the client.
Suggested by: Marko, Sunny, Michael
Objected by: Inaam
------------------------------------------------------------------------
r2837 | vasil | 2008-10-21 12:07:44 +0300 (Tue, 21 Oct 2008) | 32 lines
Changed paths:
M /branches/5.1/mysql-test/innodb-semi-consistent.result
M /branches/5.1/mysql-test/innodb-semi-consistent.test
M /branches/5.1/mysql-test/innodb.result
M /branches/5.1/mysql-test/innodb.test
branches/5.1:
Merge a change from MySQL (this fixes the failing innodb and
innodb-semi-consistent tests):
revno: 2757
committer: Georgi Kodinov <kgeorge@mysql.com>
branch nick: B39812-5.1-5.1.29-rc
timestamp: Fri 2008-10-03 15:24:19 +0300
message:
Bug #39812: Make statement replication default for 5.1 (to match 5.0)
Make STMT replication default for 5.1.
Add a default of MIXED into the config files
Fix the tests that needed MIXED replication mode.
modified:
mysql-test/include/mix1.inc
mysql-test/r/innodb-semi-consistent.result
mysql-test/r/innodb.result
mysql-test/r/innodb_mysql.result
mysql-test/r/tx_isolation_func.result
mysql-test/t/innodb-semi-consistent.test
mysql-test/t/innodb.test
mysql-test/t/tx_isolation_func.test
sql/mysqld.cc
support-files/my-huge.cnf.sh
support-files/my-innodb-heavy-4G.cnf.sh
support-files/my-large.cnf.sh
support-files/my-medium.cnf.sh
support-files/my-small.cnf.sh
------------------------------------------------------------------------
------------------------------------------------------------------------
r2847 | marko | 2008-10-22 10:07:37 +0300 (Wed, 22 Oct 2008) | 6 lines
branches/zip: page_zip_rec_needs_ext(): Fix a bug that was introduced
in the fix of Mantis issue #73. With key_block_size=16, we will also
have to check the available space on the uncompressed page.
Otherwise, the clustered index record can be almost 16 kilobytes in
size, and the undo log record will not fit.
------------------------------------------------------------------------
r2850 | marko | 2008-10-22 13:52:12 +0300 (Wed, 22 Oct 2008) | 2 lines
branches/zip: ibuf_insert_to_index_page(): Discard the local variable block.
page_cur is always positioned on block, the function parameter.
------------------------------------------------------------------------
r2853 | sunny | 2008-10-23 01:52:09 +0300 (Thu, 23 Oct 2008) | 2 lines
branches/zip: Add missing UNIV_INTERN.
------------------------------------------------------------------------
r2855 | sunny | 2008-10-23 09:29:46 +0300 (Thu, 23 Oct 2008) | 36 lines
branches/zip:
Merge revisions 2837:2852 from branches/5.1:
------------------------------------------------------------------------
r2849 | sunny | 2008-10-22 12:01:18 +0300 (Wed, 22 Oct 2008) | 8 lines
Changed paths:
M /branches/5.1/handler/ha_innodb.cc
M /branches/5.1/include/row0mysql.h
M /branches/5.1/row/row0mysql.c
branches/5.1: Return the actual error code encountered when allocating
a new autoinc value. The change in behavior (bug) was introduced in 5.1.22
when we introduced the new AUTOINC locking model.
rb://31
Bug#40224 New AUTOINC changes mask reporting of deadlock/timeout errors
------------------------------------------------------------------------
r2852 | sunny | 2008-10-23 01:42:24 +0300 (Thu, 23 Oct 2008) | 9 lines
Changed paths:
M /branches/5.1/handler/ha_innodb.cc
M /branches/5.1/handler/ha_innodb.h
branches/5.1: Backport r2724 from branches/zip
Check column value against the col max value before updating the table's
global autoinc counter value. This is part of simplifying the AUTOINC
sub-system. We extract the type info from MySQL data structures at runtime.
This fixes Bug#37788 InnoDB Plugin: AUTO_INCREMENT wrong for compressed tables
------------------------------------------------------------------------
------------------------------------------------------------------------
r2856 | sunny | 2008-10-23 10:07:05 +0300 (Thu, 23 Oct 2008) | 1 line
Reverting test file changes from r2855
------------------------------------------------------------------------
r2857 | sunny | 2008-10-23 10:24:33 +0300 (Thu, 23 Oct 2008) | 30 lines
branches/zip:
Merge revisions 2852:2854 from branches/5.1:
------------------------------------------------------------------------
r2854 | sunny | 2008-10-23 08:30:32 +0300 (Thu, 23 Oct 2008) | 13 lines
Changed paths:
M /branches/5.1/dict/dict0dict.c
M /branches/5.1/dict/dict0mem.c
M /branches/5.1/handler/ha_innodb.cc
M /branches/5.1/handler/ha_innodb.h
M /branches/5.1/include/dict0dict.h
M /branches/5.1/include/dict0mem.h
M /branches/5.1/row/row0mysql.c
branches/5.1: Backport changes from branches/zip r2725
Simplify the autoinc initialization code. This removes the
non-determinism related to reading the table's autoinc value for the first
time. This change has also reduced the sizeof dict_table_t by sizeof(ibool)
bytes because we don't need the dict_table_t::autoinc_inited field anymore.
Bug#39830 Table autoinc value not updated on first insert.
Bug#35498 Cannot get table test/table1 auto-inccounter value in ::info
Bug#36411 Failed to read auto-increment value from storage engine" in 5.1.24 auto-inc
rb://16
------------------------------------------------------------------------
------------------------------------------------------------------------
r2858 | vasil | 2008-10-23 11:33:43 +0300 (Thu, 23 Oct 2008) | 4 lines
branches/zip:
Update the ChangeLog
------------------------------------------------------------------------
r2861 | marko | 2008-10-23 12:27:15 +0300 (Thu, 23 Oct 2008) | 24 lines
branches/zip: Clean up the file format stamping.
trx_sys_file_format_max_upgrade(): Rename from
trx_sys_file_format_max_update(). Improve the documentation. Add a
const qualifier to the parameter "name". Replace the parameter
"flags" with "format_id", because this function should deal with file
format identifiers, not with table flags.
trx_sys_file_format_max_write(), trx_sys_file_format_max_set(): Add a
const qualifier to the parameter "name".
ha_innodb.cc: Correct the spelling in some comments: "side effect".
Remove redundant prototypes for some static callback functions.
innodb_file_format_name_update(), innodb_file_format_check_update():
Correct the function signature. Use appropriate pointer type conversions.
MYSQL_SYSVAR_STR(file_format), MYSQL_SYSVAR_STR(file_format_check):
Remove the type conversions from the callback function pointers. When
the function signatures match, no type conversion is needed. The type
conversions would only prevent compilation warnings for any mismatch.
Approved by Sunny in rb://25.
------------------------------------------------------------------------
r2862 | marko | 2008-10-23 12:37:42 +0300 (Thu, 23 Oct 2008) | 8 lines
branches/zip: Non-functional changes:
ibuf_get_volume_buffered(): Declare with static linkage.
This function is private to ibuf0ibuf.c.
btr_cur_pessimistic_delete(): Use the cached result of
btr_cur_get_index(cursor).
------------------------------------------------------------------------
2008-10-23 12:03:20 +02:00
|
|
|
prebuilt->autoinc_error = 0;
|
2008-10-11 21:37:21 +02:00
|
|
|
prebuilt->autoinc_offset = 0;
|
|
|
|
|
|
|
|
/* Default to 1, we will set the actual value later in
|
|
|
|
ha_innobase::get_auto_increment(). */
|
|
|
|
prebuilt->autoinc_increment = 1;
|
|
|
|
|
|
|
|
prebuilt->autoinc_last_value = 0;
|
|
|
|
|
2005-10-27 09:29:40 +02:00
|
|
|
return(prebuilt);
|
|
|
|
}
|
|
|
|
|
|
|
|
/************************************************************************
|
|
|
|
Free a prebuilt struct for a MySQL table handle. */
|
2008-02-06 15:17:36 +01:00
|
|
|
UNIV_INTERN
|
2005-10-27 09:29:40 +02:00
|
|
|
void
|
|
|
|
row_prebuilt_free(
|
|
|
|
/*==============*/
|
2007-08-02 12:55:25 +02:00
|
|
|
row_prebuilt_t* prebuilt, /* in, own: prebuilt struct */
|
|
|
|
ibool dict_locked) /* in: TRUE=data dictionary locked */
|
2005-10-27 09:29:40 +02:00
|
|
|
{
|
|
|
|
ulint i;
|
|
|
|
|
branches/zip: Fast index creation: Remove the ROW_PREBUILT_OBSOLETE nonsense.
Active transactions must not switch table or index definitions on the fly,
for several reasons, including the following:
* copied indexes do not carry any history or locking information;
that is, rollbacks, read views, and record locking would be broken
* huge potential for race conditions, inconsistent reads and writes,
loss of data, and corruption
Instead of trying to track down if the table was changed during a transaction,
acquire appropriate locks that protect the creation and dropping of indexes.
innodb-index.test: Test the locking of CREATE INDEX and DROP INDEX. Test
that consistent reads work across dropped indexes.
lock_rec_insert_check_and_lock(): Relax the lock_table_has() assertion.
When inserting a record into an index, the table must be at least IX-locked.
However, when an index is being created, an IS-lock on the table is
sufficient.
row_merge_lock_table(): Add the parameter enum lock_mode mode, which must
be LOCK_X or LOCK_S.
row_merge_drop_table(): Assert that n_mysql_handles_opened == 0.
Unconditionally drop the table.
ha_innobase::add_index(): Acquire an X or S lock on the table, as appropriate.
After acquiring an X lock, assert that n_mysql_handles_opened == 1.
Remove the comments about dropping tables in the background.
ha_innobase::final_drop_index(): Acquire an X lock on the table.
dict_table_t: Remove version_number, to_be_dropped, and prebuilts.
ins_node_t: Remove table_version_number.
enum lock_mode: Move the definition from lock0lock.h to lock0types.h.
ROW_PREBUILT_OBSOLETE, row_update_prebuilt(), row_prebuilt_table_obsolete():
Remove.
row_prebuilt_t: Remove the declaration from row0types.h.
row_drop_table_for_mysql_no_commit(): Always print a warning if a table
was added to the background drop queue.
2007-12-17 16:49:59 +01:00
|
|
|
if (UNIV_UNLIKELY
|
|
|
|
(prebuilt->magic_n != ROW_PREBUILT_ALLOCATED
|
|
|
|
|| prebuilt->magic_n2 != ROW_PREBUILT_ALLOCATED)) {
|
2007-04-04 13:05:33 +02:00
|
|
|
|
2005-10-27 09:29:40 +02:00
|
|
|
fprintf(stderr,
|
2006-08-29 11:30:31 +02:00
|
|
|
"InnoDB: Error: trying to free a corrupt\n"
|
|
|
|
"InnoDB: table handle. Magic n %lu,"
|
2007-04-04 13:05:33 +02:00
|
|
|
" magic n2 %lu, table name ",
|
2006-08-29 11:30:31 +02:00
|
|
|
(ulong) prebuilt->magic_n,
|
|
|
|
(ulong) prebuilt->magic_n2);
|
2006-06-13 22:23:26 +02:00
|
|
|
ut_print_name(stderr, NULL, TRUE, prebuilt->table->name);
|
2005-10-27 09:29:40 +02:00
|
|
|
putc('\n', stderr);
|
|
|
|
|
2006-04-12 11:32:17 +02:00
|
|
|
mem_analyze_corruption(prebuilt);
|
2005-10-27 09:29:40 +02:00
|
|
|
|
|
|
|
ut_error;
|
|
|
|
}
|
|
|
|
|
|
|
|
prebuilt->magic_n = ROW_PREBUILT_FREED;
|
|
|
|
prebuilt->magic_n2 = ROW_PREBUILT_FREED;
|
|
|
|
|
|
|
|
btr_pcur_free_for_mysql(prebuilt->pcur);
|
|
|
|
btr_pcur_free_for_mysql(prebuilt->clust_pcur);
|
|
|
|
|
|
|
|
if (prebuilt->mysql_template) {
|
|
|
|
mem_free(prebuilt->mysql_template);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (prebuilt->ins_graph) {
|
|
|
|
que_graph_free_recursive(prebuilt->ins_graph);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (prebuilt->sel_graph) {
|
|
|
|
que_graph_free_recursive(prebuilt->sel_graph);
|
|
|
|
}
|
2006-02-23 20:25:29 +01:00
|
|
|
|
2005-10-27 09:29:40 +02:00
|
|
|
if (prebuilt->upd_graph) {
|
|
|
|
que_graph_free_recursive(prebuilt->upd_graph);
|
|
|
|
}
|
2006-02-23 20:25:29 +01:00
|
|
|
|
2005-10-27 09:29:40 +02:00
|
|
|
if (prebuilt->blob_heap) {
|
|
|
|
mem_heap_free(prebuilt->blob_heap);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (prebuilt->old_vers_heap) {
|
|
|
|
mem_heap_free(prebuilt->old_vers_heap);
|
|
|
|
}
|
2006-02-23 20:25:29 +01:00
|
|
|
|
2005-10-27 09:29:40 +02:00
|
|
|
for (i = 0; i < MYSQL_FETCH_CACHE_SIZE; i++) {
|
|
|
|
if (prebuilt->fetch_cache[i] != NULL) {
|
|
|
|
|
2006-09-19 12:14:07 +02:00
|
|
|
if ((ROW_PREBUILT_FETCH_MAGIC_N != mach_read_from_4(
|
|
|
|
(prebuilt->fetch_cache[i]) - 4))
|
|
|
|
|| (ROW_PREBUILT_FETCH_MAGIC_N != mach_read_from_4(
|
|
|
|
(prebuilt->fetch_cache[i])
|
|
|
|
+ prebuilt->mysql_row_len))) {
|
2006-08-29 11:30:31 +02:00
|
|
|
fputs("InnoDB: Error: trying to free"
|
|
|
|
" a corrupt fetch buffer.\n", stderr);
|
2005-10-27 09:29:40 +02:00
|
|
|
|
2006-09-19 12:14:07 +02:00
|
|
|
mem_analyze_corruption(
|
|
|
|
prebuilt->fetch_cache[i]);
|
2005-10-27 09:29:40 +02:00
|
|
|
|
|
|
|
ut_error;
|
|
|
|
}
|
|
|
|
|
|
|
|
mem_free((prebuilt->fetch_cache[i]) - 4);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-08-02 12:55:25 +02:00
|
|
|
dict_table_decrement_handle_count(prebuilt->table, dict_locked);
|
2005-10-27 09:29:40 +02:00
|
|
|
|
|
|
|
mem_heap_free(prebuilt->heap);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
|
|
|
Updates the transaction pointers in query graphs stored in the prebuilt
|
|
|
|
struct. */
|
2008-02-06 15:17:36 +01:00
|
|
|
UNIV_INTERN
|
2005-10-27 09:29:40 +02:00
|
|
|
void
|
|
|
|
row_update_prebuilt_trx(
|
|
|
|
/*====================*/
|
|
|
|
/* out: prebuilt dtuple */
|
|
|
|
row_prebuilt_t* prebuilt, /* in: prebuilt struct in MySQL
|
|
|
|
handle */
|
|
|
|
trx_t* trx) /* in: transaction handle */
|
2006-02-23 20:25:29 +01:00
|
|
|
{
|
2005-10-27 09:29:40 +02:00
|
|
|
if (trx->magic_n != TRX_MAGIC_N) {
|
|
|
|
fprintf(stderr,
|
2006-08-29 11:30:31 +02:00
|
|
|
"InnoDB: Error: trying to use a corrupt\n"
|
|
|
|
"InnoDB: trx handle. Magic n %lu\n",
|
|
|
|
(ulong) trx->magic_n);
|
2005-10-27 09:29:40 +02:00
|
|
|
|
2006-04-12 11:32:17 +02:00
|
|
|
mem_analyze_corruption(trx);
|
2005-10-27 09:29:40 +02:00
|
|
|
|
|
|
|
ut_error;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (prebuilt->magic_n != ROW_PREBUILT_ALLOCATED) {
|
|
|
|
fprintf(stderr,
|
2006-08-29 11:30:31 +02:00
|
|
|
"InnoDB: Error: trying to use a corrupt\n"
|
2007-04-04 13:05:33 +02:00
|
|
|
"InnoDB: table handle. Magic n %lu, table name ",
|
2006-08-29 11:30:31 +02:00
|
|
|
(ulong) prebuilt->magic_n);
|
2007-04-04 13:05:33 +02:00
|
|
|
ut_print_name(stderr, trx, TRUE, prebuilt->table->name);
|
2005-10-27 09:29:40 +02:00
|
|
|
putc('\n', stderr);
|
|
|
|
|
2006-04-12 11:32:17 +02:00
|
|
|
mem_analyze_corruption(prebuilt);
|
2005-10-27 09:29:40 +02:00
|
|
|
|
|
|
|
ut_error;
|
|
|
|
}
|
|
|
|
|
|
|
|
prebuilt->trx = trx;
|
|
|
|
|
|
|
|
if (prebuilt->ins_graph) {
|
|
|
|
prebuilt->ins_graph->trx = trx;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (prebuilt->upd_graph) {
|
|
|
|
prebuilt->upd_graph->trx = trx;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (prebuilt->sel_graph) {
|
|
|
|
prebuilt->sel_graph->trx = trx;
|
2006-02-23 20:25:29 +01:00
|
|
|
}
|
2005-10-27 09:29:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
|
|
|
Gets pointer to a prebuilt dtuple used in insertions. If the insert graph
|
|
|
|
has not yet been built in the prebuilt struct, then this function first
|
|
|
|
builds it. */
|
|
|
|
static
|
|
|
|
dtuple_t*
|
|
|
|
row_get_prebuilt_insert_row(
|
|
|
|
/*========================*/
|
|
|
|
/* out: prebuilt dtuple; the column
|
2006-02-23 20:25:29 +01:00
|
|
|
type information is also set in it */
|
2005-10-27 09:29:40 +02:00
|
|
|
row_prebuilt_t* prebuilt) /* in: prebuilt struct in MySQL
|
|
|
|
handle */
|
|
|
|
{
|
|
|
|
ins_node_t* node;
|
|
|
|
dtuple_t* row;
|
|
|
|
dict_table_t* table = prebuilt->table;
|
|
|
|
|
|
|
|
ut_ad(prebuilt && table && prebuilt->trx);
|
2006-02-23 20:25:29 +01:00
|
|
|
|
2005-10-27 09:29:40 +02:00
|
|
|
if (prebuilt->ins_node == NULL) {
|
|
|
|
|
|
|
|
/* Not called before for this handle: create an insert node
|
|
|
|
and query graph to the prebuilt struct */
|
|
|
|
|
|
|
|
node = ins_node_create(INS_DIRECT, table, prebuilt->heap);
|
2006-02-23 20:25:29 +01:00
|
|
|
|
2005-10-27 09:29:40 +02:00
|
|
|
prebuilt->ins_node = node;
|
|
|
|
|
|
|
|
if (prebuilt->ins_upd_rec_buff == NULL) {
|
2006-09-19 12:14:07 +02:00
|
|
|
prebuilt->ins_upd_rec_buff = mem_heap_alloc(
|
|
|
|
prebuilt->heap, prebuilt->mysql_row_len);
|
2005-10-27 09:29:40 +02:00
|
|
|
}
|
2006-02-23 20:25:29 +01:00
|
|
|
|
2005-10-27 09:29:40 +02:00
|
|
|
row = dtuple_create(prebuilt->heap,
|
2006-08-29 11:30:31 +02:00
|
|
|
dict_table_get_n_cols(table));
|
2005-10-27 09:29:40 +02:00
|
|
|
|
|
|
|
dict_table_copy_types(row, table);
|
|
|
|
|
|
|
|
ins_node_set_new_row(node, row);
|
|
|
|
|
2006-09-19 12:14:07 +02:00
|
|
|
prebuilt->ins_graph = que_node_get_parent(
|
|
|
|
pars_complete_graph_for_exec(node,
|
|
|
|
prebuilt->trx,
|
|
|
|
prebuilt->heap));
|
2005-10-27 09:29:40 +02:00
|
|
|
prebuilt->ins_graph->state = QUE_FORK_ACTIVE;
|
|
|
|
}
|
|
|
|
|
2006-02-23 20:25:29 +01:00
|
|
|
return(prebuilt->ins_node->row);
|
2005-10-27 09:29:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
|
|
|
Updates the table modification counter and calculates new estimates
|
|
|
|
for table and index statistics if necessary. */
|
|
|
|
UNIV_INLINE
|
|
|
|
void
|
|
|
|
row_update_statistics_if_needed(
|
|
|
|
/*============================*/
|
|
|
|
dict_table_t* table) /* in: table */
|
|
|
|
{
|
|
|
|
ulint counter;
|
2006-02-23 20:25:29 +01:00
|
|
|
|
2005-10-27 09:29:40 +02:00
|
|
|
counter = table->stat_modified_counter;
|
|
|
|
|
|
|
|
table->stat_modified_counter = counter + 1;
|
|
|
|
|
|
|
|
/* Calculate new statistics if 1 / 16 of table has been modified
|
|
|
|
since the last time a statistics batch was run, or if
|
|
|
|
stat_modified_counter > 2 000 000 000 (to avoid wrap-around).
|
|
|
|
We calculate statistics at most every 16th round, since we may have
|
|
|
|
a counter table which is very small and updated very often. */
|
|
|
|
|
|
|
|
if (counter > 2000000000
|
2008-05-14 17:43:19 +02:00
|
|
|
|| ((ib_int64_t)counter > 16 + table->stat_n_rows / 16)) {
|
2005-10-27 09:29:40 +02:00
|
|
|
|
|
|
|
dict_update_statistics(table);
|
2006-02-23 20:25:29 +01:00
|
|
|
}
|
2005-10-27 09:29:40 +02:00
|
|
|
}
|
2006-02-23 20:25:29 +01:00
|
|
|
|
2005-10-27 09:29:40 +02:00
|
|
|
/*************************************************************************
|
|
|
|
Unlocks an AUTO_INC type lock possibly reserved by trx. */
|
2008-02-06 15:17:36 +01:00
|
|
|
UNIV_INTERN
|
2006-02-23 20:25:29 +01:00
|
|
|
void
|
2005-10-27 09:29:40 +02:00
|
|
|
row_unlock_table_autoinc_for_mysql(
|
|
|
|
/*===============================*/
|
|
|
|
trx_t* trx) /* in: transaction */
|
|
|
|
{
|
|
|
|
if (!trx->auto_inc_lock) {
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
lock_table_unlock_auto_inc(trx);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
|
|
|
Sets an AUTO_INC type lock on the table mentioned in prebuilt. The
|
|
|
|
AUTO_INC lock gives exclusive access to the auto-inc counter of the
|
|
|
|
table. The lock is reserved only for the duration of an SQL statement.
|
|
|
|
It is not compatible with another AUTO_INC or exclusive lock on the
|
|
|
|
table. */
|
2008-02-06 15:17:36 +01:00
|
|
|
UNIV_INTERN
|
2005-10-27 09:29:40 +02:00
|
|
|
int
|
|
|
|
row_lock_table_autoinc_for_mysql(
|
|
|
|
/*=============================*/
|
|
|
|
/* out: error code or DB_SUCCESS */
|
|
|
|
row_prebuilt_t* prebuilt) /* in: prebuilt struct in the MySQL
|
|
|
|
table handle */
|
|
|
|
{
|
2006-02-23 20:25:29 +01:00
|
|
|
trx_t* trx = prebuilt->trx;
|
2005-10-27 09:29:40 +02:00
|
|
|
ins_node_t* node = prebuilt->ins_node;
|
|
|
|
que_thr_t* thr;
|
|
|
|
ulint err;
|
|
|
|
ibool was_lock_wait;
|
2006-02-23 20:25:29 +01:00
|
|
|
|
2005-10-27 09:29:40 +02:00
|
|
|
ut_ad(trx);
|
|
|
|
ut_ad(trx->mysql_thread_id == os_thread_get_curr_id());
|
2006-02-23 20:25:29 +01:00
|
|
|
|
2005-10-27 09:29:40 +02:00
|
|
|
if (trx->auto_inc_lock) {
|
|
|
|
|
|
|
|
return(DB_SUCCESS);
|
|
|
|
}
|
|
|
|
|
|
|
|
trx->op_info = "setting auto-inc lock";
|
|
|
|
|
|
|
|
if (node == NULL) {
|
|
|
|
row_get_prebuilt_insert_row(prebuilt);
|
|
|
|
node = prebuilt->ins_node;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* We use the insert query graph as the dummy graph needed
|
|
|
|
in the lock module call */
|
|
|
|
|
|
|
|
thr = que_fork_get_first_thr(prebuilt->ins_graph);
|
|
|
|
|
|
|
|
que_thr_move_to_run_state_for_mysql(thr, trx);
|
|
|
|
|
|
|
|
run_again:
|
|
|
|
thr->run_node = node;
|
|
|
|
thr->prev_node = node;
|
|
|
|
|
|
|
|
/* It may be that the current session has not yet started
|
|
|
|
its transaction, or it has been committed: */
|
|
|
|
|
|
|
|
trx_start_if_not_started(trx);
|
|
|
|
|
|
|
|
err = lock_table(0, prebuilt->table, LOCK_AUTO_INC, thr);
|
|
|
|
|
|
|
|
trx->error_state = err;
|
|
|
|
|
|
|
|
if (err != DB_SUCCESS) {
|
|
|
|
que_thr_stop_for_mysql(thr);
|
|
|
|
|
|
|
|
was_lock_wait = row_mysql_handle_errors(&err, trx, thr, NULL);
|
|
|
|
|
|
|
|
if (was_lock_wait) {
|
|
|
|
goto run_again;
|
|
|
|
}
|
|
|
|
|
|
|
|
trx->op_info = "";
|
|
|
|
|
|
|
|
return((int) err);
|
|
|
|
}
|
|
|
|
|
|
|
|
que_thr_stop_for_mysql_no_error(thr, trx);
|
|
|
|
|
|
|
|
trx->op_info = "";
|
|
|
|
|
|
|
|
return((int) err);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
|
|
|
Sets a table lock on the table mentioned in prebuilt. */
|
2008-02-06 15:17:36 +01:00
|
|
|
UNIV_INTERN
|
2005-10-27 09:29:40 +02:00
|
|
|
int
|
|
|
|
row_lock_table_for_mysql(
|
|
|
|
/*=====================*/
|
|
|
|
/* out: error code or DB_SUCCESS */
|
|
|
|
row_prebuilt_t* prebuilt, /* in: prebuilt struct in the MySQL
|
|
|
|
table handle */
|
|
|
|
dict_table_t* table, /* in: table to lock, or NULL
|
|
|
|
if prebuilt->table should be
|
|
|
|
locked as
|
|
|
|
prebuilt->select_lock_type */
|
|
|
|
ulint mode) /* in: lock mode of table
|
|
|
|
(ignored if table==NULL) */
|
|
|
|
{
|
2006-02-23 20:25:29 +01:00
|
|
|
trx_t* trx = prebuilt->trx;
|
2005-10-27 09:29:40 +02:00
|
|
|
que_thr_t* thr;
|
|
|
|
ulint err;
|
|
|
|
ibool was_lock_wait;
|
2006-02-23 20:25:29 +01:00
|
|
|
|
2005-10-27 09:29:40 +02:00
|
|
|
ut_ad(trx);
|
|
|
|
ut_ad(trx->mysql_thread_id == os_thread_get_curr_id());
|
|
|
|
|
|
|
|
trx->op_info = "setting table lock";
|
|
|
|
|
|
|
|
if (prebuilt->sel_graph == NULL) {
|
|
|
|
/* Build a dummy select query graph */
|
|
|
|
row_prebuild_sel_graph(prebuilt);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* We use the select query graph as the dummy graph needed
|
|
|
|
in the lock module call */
|
|
|
|
|
|
|
|
thr = que_fork_get_first_thr(prebuilt->sel_graph);
|
|
|
|
|
|
|
|
que_thr_move_to_run_state_for_mysql(thr, trx);
|
|
|
|
|
|
|
|
run_again:
|
|
|
|
thr->run_node = thr;
|
|
|
|
thr->prev_node = thr->common.parent;
|
|
|
|
|
|
|
|
/* It may be that the current session has not yet started
|
|
|
|
its transaction, or it has been committed: */
|
|
|
|
|
|
|
|
trx_start_if_not_started(trx);
|
|
|
|
|
|
|
|
if (table) {
|
|
|
|
err = lock_table(0, table, mode, thr);
|
|
|
|
} else {
|
|
|
|
err = lock_table(0, prebuilt->table,
|
2006-08-29 11:30:31 +02:00
|
|
|
prebuilt->select_lock_type, thr);
|
2005-10-27 09:29:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
trx->error_state = err;
|
|
|
|
|
|
|
|
if (err != DB_SUCCESS) {
|
|
|
|
que_thr_stop_for_mysql(thr);
|
|
|
|
|
|
|
|
was_lock_wait = row_mysql_handle_errors(&err, trx, thr, NULL);
|
|
|
|
|
|
|
|
if (was_lock_wait) {
|
|
|
|
goto run_again;
|
|
|
|
}
|
|
|
|
|
|
|
|
trx->op_info = "";
|
|
|
|
|
|
|
|
return((int) err);
|
|
|
|
}
|
|
|
|
|
|
|
|
que_thr_stop_for_mysql_no_error(thr, trx);
|
2006-02-23 20:25:29 +01:00
|
|
|
|
2005-10-27 09:29:40 +02:00
|
|
|
trx->op_info = "";
|
|
|
|
|
2006-02-23 20:25:29 +01:00
|
|
|
return((int) err);
|
2005-10-27 09:29:40 +02:00
|
|
|
}
|
2006-02-23 20:25:29 +01:00
|
|
|
|
2005-10-27 09:29:40 +02:00
|
|
|
/*************************************************************************
|
|
|
|
Does an insert for MySQL. */
|
2008-02-06 15:17:36 +01:00
|
|
|
UNIV_INTERN
|
2005-10-27 09:29:40 +02:00
|
|
|
int
|
|
|
|
row_insert_for_mysql(
|
|
|
|
/*=================*/
|
|
|
|
/* out: error code or DB_SUCCESS */
|
|
|
|
byte* mysql_rec, /* in: row in the MySQL format */
|
|
|
|
row_prebuilt_t* prebuilt) /* in: prebuilt struct in MySQL
|
|
|
|
handle */
|
|
|
|
{
|
|
|
|
trx_savept_t savept;
|
|
|
|
que_thr_t* thr;
|
|
|
|
ulint err;
|
|
|
|
ibool was_lock_wait;
|
2006-02-23 20:25:29 +01:00
|
|
|
trx_t* trx = prebuilt->trx;
|
2005-10-27 09:29:40 +02:00
|
|
|
ins_node_t* node = prebuilt->ins_node;
|
2006-02-23 20:25:29 +01:00
|
|
|
|
2005-10-27 09:29:40 +02:00
|
|
|
ut_ad(trx);
|
|
|
|
ut_ad(trx->mysql_thread_id == os_thread_get_curr_id());
|
|
|
|
|
|
|
|
if (prebuilt->table->ibd_file_missing) {
|
2006-02-23 20:25:29 +01:00
|
|
|
ut_print_timestamp(stderr);
|
|
|
|
fprintf(stderr, " InnoDB: Error:\n"
|
2006-08-29 11:30:31 +02:00
|
|
|
"InnoDB: MySQL is trying to use a table handle"
|
|
|
|
" but the .ibd file for\n"
|
|
|
|
"InnoDB: table %s does not exist.\n"
|
|
|
|
"InnoDB: Have you deleted the .ibd file"
|
|
|
|
" from the database directory under\n"
|
|
|
|
"InnoDB: the MySQL datadir, or have you"
|
|
|
|
" used DISCARD TABLESPACE?\n"
|
|
|
|
"InnoDB: Look from\n"
|
|
|
|
"InnoDB: http://dev.mysql.com/doc/refman/5.1/en/"
|
|
|
|
"innodb-troubleshooting.html\n"
|
|
|
|
"InnoDB: how you can resolve the problem.\n",
|
|
|
|
prebuilt->table->name);
|
2005-10-27 09:29:40 +02:00
|
|
|
return(DB_ERROR);
|
|
|
|
}
|
|
|
|
|
branches/zip: Fast index creation: Remove the ROW_PREBUILT_OBSOLETE nonsense.
Active transactions must not switch table or index definitions on the fly,
for several reasons, including the following:
* copied indexes do not carry any history or locking information;
that is, rollbacks, read views, and record locking would be broken
* huge potential for race conditions, inconsistent reads and writes,
loss of data, and corruption
Instead of trying to track down if the table was changed during a transaction,
acquire appropriate locks that protect the creation and dropping of indexes.
innodb-index.test: Test the locking of CREATE INDEX and DROP INDEX. Test
that consistent reads work across dropped indexes.
lock_rec_insert_check_and_lock(): Relax the lock_table_has() assertion.
When inserting a record into an index, the table must be at least IX-locked.
However, when an index is being created, an IS-lock on the table is
sufficient.
row_merge_lock_table(): Add the parameter enum lock_mode mode, which must
be LOCK_X or LOCK_S.
row_merge_drop_table(): Assert that n_mysql_handles_opened == 0.
Unconditionally drop the table.
ha_innobase::add_index(): Acquire an X or S lock on the table, as appropriate.
After acquiring an X lock, assert that n_mysql_handles_opened == 1.
Remove the comments about dropping tables in the background.
ha_innobase::final_drop_index(): Acquire an X lock on the table.
dict_table_t: Remove version_number, to_be_dropped, and prebuilts.
ins_node_t: Remove table_version_number.
enum lock_mode: Move the definition from lock0lock.h to lock0types.h.
ROW_PREBUILT_OBSOLETE, row_update_prebuilt(), row_prebuilt_table_obsolete():
Remove.
row_prebuilt_t: Remove the declaration from row0types.h.
row_drop_table_for_mysql_no_commit(): Always print a warning if a table
was added to the background drop queue.
2007-12-17 16:49:59 +01:00
|
|
|
if (UNIV_UNLIKELY(prebuilt->magic_n != ROW_PREBUILT_ALLOCATED)) {
|
2005-10-27 09:29:40 +02:00
|
|
|
fprintf(stderr,
|
2006-08-29 11:30:31 +02:00
|
|
|
"InnoDB: Error: trying to free a corrupt\n"
|
2007-04-04 13:05:33 +02:00
|
|
|
"InnoDB: table handle. Magic n %lu, table name ",
|
2006-08-29 11:30:31 +02:00
|
|
|
(ulong) prebuilt->magic_n);
|
2007-04-04 13:05:33 +02:00
|
|
|
ut_print_name(stderr, trx, TRUE, prebuilt->table->name);
|
2005-10-27 09:29:40 +02:00
|
|
|
putc('\n', stderr);
|
|
|
|
|
2006-04-12 11:32:17 +02:00
|
|
|
mem_analyze_corruption(prebuilt);
|
2005-10-27 09:29:40 +02:00
|
|
|
|
|
|
|
ut_error;
|
|
|
|
}
|
|
|
|
|
2007-11-07 14:52:52 +01:00
|
|
|
if (UNIV_UNLIKELY(srv_created_new_raw || srv_force_recovery)) {
|
2006-08-29 11:30:31 +02:00
|
|
|
fputs("InnoDB: A new raw disk partition was initialized or\n"
|
|
|
|
"InnoDB: innodb_force_recovery is on: we do not allow\n"
|
|
|
|
"InnoDB: database modifications by the user. Shut down\n"
|
|
|
|
"InnoDB: mysqld and edit my.cnf so that"
|
|
|
|
" newraw is replaced\n"
|
|
|
|
"InnoDB: with raw, and innodb_force_... is removed.\n",
|
|
|
|
stderr);
|
2005-10-27 09:29:40 +02:00
|
|
|
|
|
|
|
return(DB_ERROR);
|
|
|
|
}
|
|
|
|
|
|
|
|
trx->op_info = "inserting";
|
|
|
|
|
|
|
|
row_mysql_delay_if_needed();
|
|
|
|
|
|
|
|
trx_start_if_not_started(trx);
|
|
|
|
|
|
|
|
if (node == NULL) {
|
|
|
|
row_get_prebuilt_insert_row(prebuilt);
|
|
|
|
node = prebuilt->ins_node;
|
|
|
|
}
|
|
|
|
|
|
|
|
row_mysql_convert_row_to_innobase(node->row, prebuilt, mysql_rec);
|
2006-02-23 20:25:29 +01:00
|
|
|
|
2005-10-27 09:29:40 +02:00
|
|
|
savept = trx_savept_take(trx);
|
2006-02-23 20:25:29 +01:00
|
|
|
|
2005-10-27 09:29:40 +02:00
|
|
|
thr = que_fork_get_first_thr(prebuilt->ins_graph);
|
|
|
|
|
|
|
|
if (prebuilt->sql_stat_start) {
|
|
|
|
node->state = INS_NODE_SET_IX_LOCK;
|
|
|
|
prebuilt->sql_stat_start = FALSE;
|
|
|
|
} else {
|
|
|
|
node->state = INS_NODE_ALLOC_ROW_ID;
|
|
|
|
}
|
2006-02-23 20:25:29 +01:00
|
|
|
|
2005-10-27 09:29:40 +02:00
|
|
|
que_thr_move_to_run_state_for_mysql(thr, trx);
|
|
|
|
|
|
|
|
run_again:
|
|
|
|
thr->run_node = node;
|
|
|
|
thr->prev_node = node;
|
|
|
|
|
|
|
|
row_ins_step(thr);
|
2006-02-23 20:25:29 +01:00
|
|
|
|
2005-10-27 09:29:40 +02:00
|
|
|
err = trx->error_state;
|
|
|
|
|
|
|
|
if (err != DB_SUCCESS) {
|
|
|
|
que_thr_stop_for_mysql(thr);
|
|
|
|
|
2006-08-29 11:30:31 +02:00
|
|
|
/* TODO: what is this? */ thr->lock_state= QUE_THR_LOCK_ROW;
|
2005-10-27 09:29:40 +02:00
|
|
|
|
|
|
|
was_lock_wait = row_mysql_handle_errors(&err, trx, thr,
|
2006-08-29 11:30:31 +02:00
|
|
|
&savept);
|
2005-10-27 09:29:40 +02:00
|
|
|
thr->lock_state= QUE_THR_LOCK_NOLOCK;
|
|
|
|
|
|
|
|
if (was_lock_wait) {
|
|
|
|
goto run_again;
|
|
|
|
}
|
|
|
|
|
|
|
|
trx->op_info = "";
|
|
|
|
|
|
|
|
return((int) err);
|
|
|
|
}
|
|
|
|
|
|
|
|
que_thr_stop_for_mysql_no_error(thr, trx);
|
2006-02-23 20:25:29 +01:00
|
|
|
|
2005-10-27 09:29:40 +02:00
|
|
|
prebuilt->table->stat_n_rows++;
|
|
|
|
|
|
|
|
srv_n_rows_inserted++;
|
2006-02-23 20:25:29 +01:00
|
|
|
|
2005-10-27 09:29:40 +02:00
|
|
|
if (prebuilt->table->stat_n_rows == 0) {
|
|
|
|
/* Avoid wrap-over */
|
|
|
|
prebuilt->table->stat_n_rows--;
|
2006-02-23 20:25:29 +01:00
|
|
|
}
|
2005-10-27 09:29:40 +02:00
|
|
|
|
|
|
|
row_update_statistics_if_needed(prebuilt->table);
|
|
|
|
trx->op_info = "";
|
|
|
|
|
|
|
|
return((int) err);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
|
|
|
Builds a dummy query graph used in selects. */
|
2008-02-06 15:17:36 +01:00
|
|
|
UNIV_INTERN
|
2005-10-27 09:29:40 +02:00
|
|
|
void
|
|
|
|
row_prebuild_sel_graph(
|
|
|
|
/*===================*/
|
|
|
|
row_prebuilt_t* prebuilt) /* in: prebuilt struct in MySQL
|
|
|
|
handle */
|
|
|
|
{
|
|
|
|
sel_node_t* node;
|
|
|
|
|
|
|
|
ut_ad(prebuilt && prebuilt->trx);
|
2006-02-23 20:25:29 +01:00
|
|
|
|
2005-10-27 09:29:40 +02:00
|
|
|
if (prebuilt->sel_graph == NULL) {
|
|
|
|
|
|
|
|
node = sel_node_create(prebuilt->heap);
|
2006-02-23 20:25:29 +01:00
|
|
|
|
2006-09-19 12:14:07 +02:00
|
|
|
prebuilt->sel_graph = que_node_get_parent(
|
|
|
|
pars_complete_graph_for_exec(node,
|
|
|
|
prebuilt->trx,
|
|
|
|
prebuilt->heap));
|
2005-10-27 09:29:40 +02:00
|
|
|
|
|
|
|
prebuilt->sel_graph->state = QUE_FORK_ACTIVE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
|
|
|
Creates an query graph node of 'update' type to be used in the MySQL
|
|
|
|
interface. */
|
2008-02-06 15:17:36 +01:00
|
|
|
UNIV_INTERN
|
2005-10-27 09:29:40 +02:00
|
|
|
upd_node_t*
|
|
|
|
row_create_update_node_for_mysql(
|
|
|
|
/*=============================*/
|
|
|
|
/* out, own: update node */
|
|
|
|
dict_table_t* table, /* in: table to update */
|
|
|
|
mem_heap_t* heap) /* in: mem heap from which allocated */
|
|
|
|
{
|
|
|
|
upd_node_t* node;
|
|
|
|
|
|
|
|
node = upd_node_create(heap);
|
2006-02-23 20:25:29 +01:00
|
|
|
|
2005-10-27 09:29:40 +02:00
|
|
|
node->in_mysql_interface = TRUE;
|
|
|
|
node->is_delete = FALSE;
|
|
|
|
node->searched_update = FALSE;
|
|
|
|
node->select_will_do_update = FALSE;
|
|
|
|
node->select = NULL;
|
|
|
|
node->pcur = btr_pcur_create_for_mysql();
|
|
|
|
node->table = table;
|
|
|
|
|
|
|
|
node->update = upd_create(dict_table_get_n_cols(table), heap);
|
|
|
|
|
|
|
|
node->update_n_fields = dict_table_get_n_cols(table);
|
2006-02-23 20:25:29 +01:00
|
|
|
|
2005-10-27 09:29:40 +02:00
|
|
|
UT_LIST_INIT(node->columns);
|
|
|
|
node->has_clust_rec_x_lock = TRUE;
|
|
|
|
node->cmpl_info = 0;
|
|
|
|
|
|
|
|
node->table_sym = NULL;
|
|
|
|
node->col_assign_list = NULL;
|
|
|
|
|
|
|
|
return(node);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
|
|
|
Gets pointer to a prebuilt update vector used in updates. If the update
|
|
|
|
graph has not yet been built in the prebuilt struct, then this function
|
|
|
|
first builds it. */
|
2008-02-06 15:17:36 +01:00
|
|
|
UNIV_INTERN
|
2005-10-27 09:29:40 +02:00
|
|
|
upd_t*
|
|
|
|
row_get_prebuilt_update_vector(
|
|
|
|
/*===========================*/
|
|
|
|
/* out: prebuilt update vector */
|
|
|
|
row_prebuilt_t* prebuilt) /* in: prebuilt struct in MySQL
|
|
|
|
handle */
|
|
|
|
{
|
|
|
|
dict_table_t* table = prebuilt->table;
|
|
|
|
upd_node_t* node;
|
|
|
|
|
|
|
|
ut_ad(prebuilt && table && prebuilt->trx);
|
2006-02-23 20:25:29 +01:00
|
|
|
|
2005-10-27 09:29:40 +02:00
|
|
|
if (prebuilt->upd_node == NULL) {
|
|
|
|
|
|
|
|
/* Not called before for this handle: create an update node
|
|
|
|
and query graph to the prebuilt struct */
|
|
|
|
|
|
|
|
node = row_create_update_node_for_mysql(table, prebuilt->heap);
|
|
|
|
|
|
|
|
prebuilt->upd_node = node;
|
2006-02-23 20:25:29 +01:00
|
|
|
|
2006-09-19 12:14:07 +02:00
|
|
|
prebuilt->upd_graph = que_node_get_parent(
|
|
|
|
pars_complete_graph_for_exec(node,
|
|
|
|
prebuilt->trx,
|
|
|
|
prebuilt->heap));
|
2005-10-27 09:29:40 +02:00
|
|
|
prebuilt->upd_graph->state = QUE_FORK_ACTIVE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return(prebuilt->upd_node->update);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
|
|
|
Does an update or delete of a row for MySQL. */
|
2008-02-06 15:17:36 +01:00
|
|
|
UNIV_INTERN
|
2005-10-27 09:29:40 +02:00
|
|
|
int
|
|
|
|
row_update_for_mysql(
|
|
|
|
/*=================*/
|
|
|
|
/* out: error code or DB_SUCCESS */
|
|
|
|
byte* mysql_rec, /* in: the row to be updated, in
|
|
|
|
the MySQL format */
|
|
|
|
row_prebuilt_t* prebuilt) /* in: prebuilt struct in MySQL
|
|
|
|
handle */
|
|
|
|
{
|
|
|
|
trx_savept_t savept;
|
|
|
|
ulint err;
|
|
|
|
que_thr_t* thr;
|
|
|
|
ibool was_lock_wait;
|
2006-02-23 20:25:29 +01:00
|
|
|
dict_index_t* clust_index;
|
2006-08-29 11:30:31 +02:00
|
|
|
/* ulint ref_len; */
|
2005-10-27 09:29:40 +02:00
|
|
|
upd_node_t* node;
|
|
|
|
dict_table_t* table = prebuilt->table;
|
|
|
|
trx_t* trx = prebuilt->trx;
|
|
|
|
|
|
|
|
ut_ad(prebuilt && trx);
|
|
|
|
ut_ad(trx->mysql_thread_id == os_thread_get_curr_id());
|
|
|
|
UT_NOT_USED(mysql_rec);
|
2006-02-23 20:25:29 +01:00
|
|
|
|
2005-10-27 09:29:40 +02:00
|
|
|
if (prebuilt->table->ibd_file_missing) {
|
2006-02-23 20:25:29 +01:00
|
|
|
ut_print_timestamp(stderr);
|
|
|
|
fprintf(stderr, " InnoDB: Error:\n"
|
2006-08-29 11:30:31 +02:00
|
|
|
"InnoDB: MySQL is trying to use a table handle"
|
|
|
|
" but the .ibd file for\n"
|
|
|
|
"InnoDB: table %s does not exist.\n"
|
|
|
|
"InnoDB: Have you deleted the .ibd file"
|
|
|
|
" from the database directory under\n"
|
|
|
|
"InnoDB: the MySQL datadir, or have you"
|
|
|
|
" used DISCARD TABLESPACE?\n"
|
|
|
|
"InnoDB: Look from\n"
|
|
|
|
"InnoDB: http://dev.mysql.com/doc/refman/5.1/en/"
|
|
|
|
"innodb-troubleshooting.html\n"
|
|
|
|
"InnoDB: how you can resolve the problem.\n",
|
|
|
|
prebuilt->table->name);
|
2005-10-27 09:29:40 +02:00
|
|
|
return(DB_ERROR);
|
|
|
|
}
|
|
|
|
|
branches/zip: Fast index creation: Remove the ROW_PREBUILT_OBSOLETE nonsense.
Active transactions must not switch table or index definitions on the fly,
for several reasons, including the following:
* copied indexes do not carry any history or locking information;
that is, rollbacks, read views, and record locking would be broken
* huge potential for race conditions, inconsistent reads and writes,
loss of data, and corruption
Instead of trying to track down if the table was changed during a transaction,
acquire appropriate locks that protect the creation and dropping of indexes.
innodb-index.test: Test the locking of CREATE INDEX and DROP INDEX. Test
that consistent reads work across dropped indexes.
lock_rec_insert_check_and_lock(): Relax the lock_table_has() assertion.
When inserting a record into an index, the table must be at least IX-locked.
However, when an index is being created, an IS-lock on the table is
sufficient.
row_merge_lock_table(): Add the parameter enum lock_mode mode, which must
be LOCK_X or LOCK_S.
row_merge_drop_table(): Assert that n_mysql_handles_opened == 0.
Unconditionally drop the table.
ha_innobase::add_index(): Acquire an X or S lock on the table, as appropriate.
After acquiring an X lock, assert that n_mysql_handles_opened == 1.
Remove the comments about dropping tables in the background.
ha_innobase::final_drop_index(): Acquire an X lock on the table.
dict_table_t: Remove version_number, to_be_dropped, and prebuilts.
ins_node_t: Remove table_version_number.
enum lock_mode: Move the definition from lock0lock.h to lock0types.h.
ROW_PREBUILT_OBSOLETE, row_update_prebuilt(), row_prebuilt_table_obsolete():
Remove.
row_prebuilt_t: Remove the declaration from row0types.h.
row_drop_table_for_mysql_no_commit(): Always print a warning if a table
was added to the background drop queue.
2007-12-17 16:49:59 +01:00
|
|
|
if (UNIV_UNLIKELY(prebuilt->magic_n != ROW_PREBUILT_ALLOCATED)) {
|
2005-10-27 09:29:40 +02:00
|
|
|
fprintf(stderr,
|
2006-08-29 11:30:31 +02:00
|
|
|
"InnoDB: Error: trying to free a corrupt\n"
|
2007-04-04 13:05:33 +02:00
|
|
|
"InnoDB: table handle. Magic n %lu, table name ",
|
2006-08-29 11:30:31 +02:00
|
|
|
(ulong) prebuilt->magic_n);
|
2007-04-04 13:05:33 +02:00
|
|
|
ut_print_name(stderr, trx, TRUE, prebuilt->table->name);
|
2005-10-27 09:29:40 +02:00
|
|
|
putc('\n', stderr);
|
|
|
|
|
2006-04-12 11:32:17 +02:00
|
|
|
mem_analyze_corruption(prebuilt);
|
2005-10-27 09:29:40 +02:00
|
|
|
|
|
|
|
ut_error;
|
|
|
|
}
|
|
|
|
|
2007-11-07 14:52:52 +01:00
|
|
|
if (UNIV_UNLIKELY(srv_created_new_raw || srv_force_recovery)) {
|
2006-08-29 11:30:31 +02:00
|
|
|
fputs("InnoDB: A new raw disk partition was initialized or\n"
|
|
|
|
"InnoDB: innodb_force_recovery is on: we do not allow\n"
|
|
|
|
"InnoDB: database modifications by the user. Shut down\n"
|
|
|
|
"InnoDB: mysqld and edit my.cnf so that newraw"
|
|
|
|
" is replaced\n"
|
|
|
|
"InnoDB: with raw, and innodb_force_... is removed.\n",
|
|
|
|
stderr);
|
2005-10-27 09:29:40 +02:00
|
|
|
|
|
|
|
return(DB_ERROR);
|
|
|
|
}
|
|
|
|
|
|
|
|
trx->op_info = "updating or deleting";
|
|
|
|
|
|
|
|
row_mysql_delay_if_needed();
|
|
|
|
|
|
|
|
trx_start_if_not_started(trx);
|
|
|
|
|
|
|
|
node = prebuilt->upd_node;
|
|
|
|
|
|
|
|
clust_index = dict_table_get_first_index(table);
|
|
|
|
|
|
|
|
if (prebuilt->pcur->btr_cur.index == clust_index) {
|
|
|
|
btr_pcur_copy_stored_position(node->pcur, prebuilt->pcur);
|
|
|
|
} else {
|
|
|
|
btr_pcur_copy_stored_position(node->pcur,
|
2006-08-29 11:30:31 +02:00
|
|
|
prebuilt->clust_pcur);
|
2005-10-27 09:29:40 +02:00
|
|
|
}
|
2006-02-23 20:25:29 +01:00
|
|
|
|
2005-10-27 09:29:40 +02:00
|
|
|
ut_a(node->pcur->rel_pos == BTR_PCUR_ON);
|
2006-02-23 20:25:29 +01:00
|
|
|
|
2005-10-27 09:29:40 +02:00
|
|
|
/* MySQL seems to call rnd_pos before updating each row it
|
|
|
|
has cached: we can get the correct cursor position from
|
|
|
|
prebuilt->pcur; NOTE that we cannot build the row reference
|
|
|
|
from mysql_rec if the clustered index was automatically
|
|
|
|
generated for the table: MySQL does not know anything about
|
|
|
|
the row id used as the clustered index key */
|
|
|
|
|
|
|
|
savept = trx_savept_take(trx);
|
2006-02-23 20:25:29 +01:00
|
|
|
|
2005-10-27 09:29:40 +02:00
|
|
|
thr = que_fork_get_first_thr(prebuilt->upd_graph);
|
|
|
|
|
|
|
|
node->state = UPD_NODE_UPDATE_CLUSTERED;
|
|
|
|
|
|
|
|
ut_ad(!prebuilt->sql_stat_start);
|
|
|
|
|
|
|
|
que_thr_move_to_run_state_for_mysql(thr, trx);
|
|
|
|
|
|
|
|
run_again:
|
|
|
|
thr->run_node = node;
|
|
|
|
thr->prev_node = node;
|
|
|
|
|
|
|
|
row_upd_step(thr);
|
|
|
|
|
|
|
|
err = trx->error_state;
|
|
|
|
|
|
|
|
if (err != DB_SUCCESS) {
|
|
|
|
que_thr_stop_for_mysql(thr);
|
2006-02-23 20:25:29 +01:00
|
|
|
|
2005-10-27 09:29:40 +02:00
|
|
|
if (err == DB_RECORD_NOT_FOUND) {
|
|
|
|
trx->error_state = DB_SUCCESS;
|
|
|
|
trx->op_info = "";
|
|
|
|
|
|
|
|
return((int) err);
|
|
|
|
}
|
|
|
|
|
2006-02-23 20:25:29 +01:00
|
|
|
thr->lock_state= QUE_THR_LOCK_ROW;
|
2005-10-27 09:29:40 +02:00
|
|
|
was_lock_wait = row_mysql_handle_errors(&err, trx, thr,
|
2006-08-29 11:30:31 +02:00
|
|
|
&savept);
|
2006-02-23 20:25:29 +01:00
|
|
|
thr->lock_state= QUE_THR_LOCK_NOLOCK;
|
|
|
|
|
2005-10-27 09:29:40 +02:00
|
|
|
if (was_lock_wait) {
|
|
|
|
goto run_again;
|
|
|
|
}
|
|
|
|
|
|
|
|
trx->op_info = "";
|
|
|
|
|
|
|
|
return((int) err);
|
|
|
|
}
|
|
|
|
|
|
|
|
que_thr_stop_for_mysql_no_error(thr, trx);
|
|
|
|
|
|
|
|
if (node->is_delete) {
|
|
|
|
if (prebuilt->table->stat_n_rows > 0) {
|
|
|
|
prebuilt->table->stat_n_rows--;
|
|
|
|
}
|
|
|
|
|
|
|
|
srv_n_rows_deleted++;
|
|
|
|
} else {
|
|
|
|
srv_n_rows_updated++;
|
|
|
|
}
|
|
|
|
|
|
|
|
row_update_statistics_if_needed(prebuilt->table);
|
|
|
|
|
|
|
|
trx->op_info = "";
|
|
|
|
|
|
|
|
return((int) err);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
2006-04-12 11:32:17 +02:00
|
|
|
This can only be used when srv_locks_unsafe_for_binlog is TRUE or
|
|
|
|
this session is using a READ COMMITTED isolation level. Before
|
2005-10-27 09:29:40 +02:00
|
|
|
calling this function we must use trx_reset_new_rec_lock_info() and
|
|
|
|
trx_register_new_rec_lock() to store the information which new record locks
|
|
|
|
really were set. This function removes a newly set lock under prebuilt->pcur,
|
|
|
|
and also under prebuilt->clust_pcur. Currently, this is only used and tested
|
|
|
|
in the case of an UPDATE or a DELETE statement, where the row lock is of the
|
|
|
|
LOCK_X type.
|
|
|
|
Thus, this implements a 'mini-rollback' that releases the latest record
|
|
|
|
locks we set. */
|
2008-02-06 15:17:36 +01:00
|
|
|
UNIV_INTERN
|
2005-10-27 09:29:40 +02:00
|
|
|
int
|
|
|
|
row_unlock_for_mysql(
|
|
|
|
/*=================*/
|
|
|
|
/* out: error code or DB_SUCCESS */
|
|
|
|
row_prebuilt_t* prebuilt, /* in: prebuilt struct in MySQL
|
|
|
|
handle */
|
|
|
|
ibool has_latches_on_recs)/* TRUE if called so that we have
|
|
|
|
the latches on the records under pcur
|
|
|
|
and clust_pcur, and we do not need to
|
|
|
|
reposition the cursors. */
|
|
|
|
{
|
|
|
|
dict_index_t* index;
|
|
|
|
btr_pcur_t* pcur = prebuilt->pcur;
|
|
|
|
btr_pcur_t* clust_pcur = prebuilt->clust_pcur;
|
|
|
|
trx_t* trx = prebuilt->trx;
|
|
|
|
rec_t* rec;
|
2006-02-23 20:25:29 +01:00
|
|
|
mtr_t mtr;
|
|
|
|
|
2005-10-27 09:29:40 +02:00
|
|
|
ut_ad(prebuilt && trx);
|
|
|
|
ut_ad(trx->mysql_thread_id == os_thread_get_curr_id());
|
2006-02-23 20:25:29 +01:00
|
|
|
|
2006-04-12 11:32:17 +02:00
|
|
|
if (!(srv_locks_unsafe_for_binlog
|
2006-08-29 11:30:31 +02:00
|
|
|
|| trx->isolation_level == TRX_ISO_READ_COMMITTED)) {
|
2005-10-27 09:29:40 +02:00
|
|
|
|
|
|
|
fprintf(stderr,
|
2006-08-29 11:30:31 +02:00
|
|
|
"InnoDB: Error: calling row_unlock_for_mysql though\n"
|
|
|
|
"InnoDB: srv_locks_unsafe_for_binlog is FALSE and\n"
|
|
|
|
"InnoDB: this session is not using"
|
|
|
|
" READ COMMITTED isolation level.\n");
|
2005-10-27 09:29:40 +02:00
|
|
|
|
|
|
|
return(DB_SUCCESS);
|
|
|
|
}
|
|
|
|
|
|
|
|
trx->op_info = "unlock_row";
|
|
|
|
|
|
|
|
index = btr_pcur_get_btr_cur(pcur)->index;
|
|
|
|
|
|
|
|
if (index != NULL && trx_new_rec_locks_contain(trx, index)) {
|
|
|
|
|
|
|
|
mtr_start(&mtr);
|
2006-02-23 20:25:29 +01:00
|
|
|
|
2005-10-27 09:29:40 +02:00
|
|
|
/* Restore the cursor position and find the record */
|
2006-02-23 20:25:29 +01:00
|
|
|
|
2005-10-27 09:29:40 +02:00
|
|
|
if (!has_latches_on_recs) {
|
|
|
|
btr_pcur_restore_position(BTR_SEARCH_LEAF, pcur, &mtr);
|
|
|
|
}
|
|
|
|
|
|
|
|
rec = btr_pcur_get_rec(pcur);
|
|
|
|
|
2006-10-24 08:45:52 +02:00
|
|
|
lock_rec_unlock(trx, btr_pcur_get_block(pcur),
|
|
|
|
rec, prebuilt->select_lock_type);
|
2005-10-27 09:29:40 +02:00
|
|
|
|
|
|
|
mtr_commit(&mtr);
|
|
|
|
|
|
|
|
/* If the search was done through the clustered index, then
|
|
|
|
we have not used clust_pcur at all, and we must NOT try to
|
|
|
|
reset locks on clust_pcur. The values in clust_pcur may be
|
|
|
|
garbage! */
|
|
|
|
|
2006-03-09 18:26:02 +01:00
|
|
|
if (dict_index_is_clust(index)) {
|
2006-02-23 20:25:29 +01:00
|
|
|
|
2005-10-27 09:29:40 +02:00
|
|
|
goto func_exit;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
index = btr_pcur_get_btr_cur(clust_pcur)->index;
|
|
|
|
|
|
|
|
if (index != NULL && trx_new_rec_locks_contain(trx, index)) {
|
|
|
|
|
|
|
|
mtr_start(&mtr);
|
2006-02-23 20:25:29 +01:00
|
|
|
|
2005-10-27 09:29:40 +02:00
|
|
|
/* Restore the cursor position and find the record */
|
|
|
|
|
|
|
|
if (!has_latches_on_recs) {
|
|
|
|
btr_pcur_restore_position(BTR_SEARCH_LEAF, clust_pcur,
|
2006-08-29 11:30:31 +02:00
|
|
|
&mtr);
|
2005-10-27 09:29:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
rec = btr_pcur_get_rec(clust_pcur);
|
|
|
|
|
2006-10-24 08:45:52 +02:00
|
|
|
lock_rec_unlock(trx, btr_pcur_get_block(clust_pcur),
|
|
|
|
rec, prebuilt->select_lock_type);
|
2005-10-27 09:29:40 +02:00
|
|
|
|
|
|
|
mtr_commit(&mtr);
|
|
|
|
}
|
2006-02-23 20:25:29 +01:00
|
|
|
|
2005-10-27 09:29:40 +02:00
|
|
|
func_exit:
|
|
|
|
trx->op_info = "";
|
2006-02-23 20:25:29 +01:00
|
|
|
|
2005-10-27 09:29:40 +02:00
|
|
|
return(DB_SUCCESS);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
Does a cascaded delete or set null in a foreign key operation. */
|
2008-02-06 15:17:36 +01:00
|
|
|
UNIV_INTERN
|
2005-10-27 09:29:40 +02:00
|
|
|
ulint
|
|
|
|
row_update_cascade_for_mysql(
|
|
|
|
/*=========================*/
|
|
|
|
/* out: error code or DB_SUCCESS */
|
|
|
|
que_thr_t* thr, /* in: query thread */
|
|
|
|
upd_node_t* node, /* in: update node used in the cascade
|
|
|
|
or set null operation */
|
|
|
|
dict_table_t* table) /* in: table where we do the operation */
|
|
|
|
{
|
|
|
|
ulint err;
|
|
|
|
trx_t* trx;
|
|
|
|
|
|
|
|
trx = thr_get_trx(thr);
|
|
|
|
run_again:
|
|
|
|
thr->run_node = node;
|
|
|
|
thr->prev_node = node;
|
|
|
|
|
|
|
|
row_upd_step(thr);
|
|
|
|
|
|
|
|
err = trx->error_state;
|
|
|
|
|
|
|
|
/* Note that the cascade node is a subnode of another InnoDB
|
|
|
|
query graph node. We do a normal lock wait in this node, but
|
|
|
|
all errors are handled by the parent node. */
|
|
|
|
|
|
|
|
if (err == DB_LOCK_WAIT) {
|
|
|
|
/* Handle lock wait here */
|
2006-02-23 20:25:29 +01:00
|
|
|
|
2005-10-27 09:29:40 +02:00
|
|
|
que_thr_stop_for_mysql(thr);
|
|
|
|
|
|
|
|
srv_suspend_mysql_thread(thr);
|
|
|
|
|
|
|
|
/* Note that a lock wait may also end in a lock wait timeout,
|
|
|
|
or this transaction is picked as a victim in selective
|
|
|
|
deadlock resolution */
|
|
|
|
|
|
|
|
if (trx->error_state != DB_SUCCESS) {
|
|
|
|
|
|
|
|
return(trx->error_state);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Retry operation after a normal lock wait */
|
2006-02-23 20:25:29 +01:00
|
|
|
|
2005-10-27 09:29:40 +02:00
|
|
|
goto run_again;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (err != DB_SUCCESS) {
|
|
|
|
|
|
|
|
return(err);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (node->is_delete) {
|
|
|
|
if (table->stat_n_rows > 0) {
|
|
|
|
table->stat_n_rows--;
|
|
|
|
}
|
|
|
|
|
|
|
|
srv_n_rows_deleted++;
|
|
|
|
} else {
|
|
|
|
srv_n_rows_updated++;
|
|
|
|
}
|
|
|
|
|
|
|
|
row_update_statistics_if_needed(table);
|
|
|
|
|
|
|
|
return(err);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
|
|
|
Checks if a table is such that we automatically created a clustered
|
|
|
|
index on it (on row id). */
|
2008-02-06 15:17:36 +01:00
|
|
|
UNIV_INTERN
|
2005-10-27 09:29:40 +02:00
|
|
|
ibool
|
|
|
|
row_table_got_default_clust_index(
|
|
|
|
/*==============================*/
|
2007-08-13 17:57:28 +02:00
|
|
|
const dict_table_t* table)
|
2005-10-27 09:29:40 +02:00
|
|
|
{
|
2006-09-19 12:14:07 +02:00
|
|
|
const dict_index_t* clust_index;
|
2005-10-27 09:29:40 +02:00
|
|
|
|
|
|
|
clust_index = dict_table_get_first_index(table);
|
|
|
|
|
2006-09-19 12:14:07 +02:00
|
|
|
return(dict_index_get_nth_col(clust_index, 0)->mtype == DATA_SYS);
|
2005-10-27 09:29:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
|
|
|
Calculates the key number used inside MySQL for an Innobase index. We have
|
|
|
|
to take into account if we generated a default clustered index for the table */
|
2008-02-06 15:17:36 +01:00
|
|
|
UNIV_INTERN
|
2005-10-27 09:29:40 +02:00
|
|
|
ulint
|
|
|
|
row_get_mysql_key_number_for_index(
|
|
|
|
/*===============================*/
|
2007-08-13 17:57:28 +02:00
|
|
|
const dict_index_t* index)
|
2005-10-27 09:29:40 +02:00
|
|
|
{
|
2007-08-13 17:57:28 +02:00
|
|
|
const dict_index_t* ind;
|
|
|
|
ulint i;
|
2005-10-27 09:29:40 +02:00
|
|
|
|
|
|
|
ut_a(index);
|
|
|
|
|
|
|
|
i = 0;
|
|
|
|
ind = dict_table_get_first_index(index->table);
|
|
|
|
|
|
|
|
while (index != ind) {
|
|
|
|
ind = dict_table_get_next_index(ind);
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (row_table_got_default_clust_index(index->table)) {
|
|
|
|
ut_a(i > 0);
|
|
|
|
i--;
|
|
|
|
}
|
|
|
|
|
|
|
|
return(i);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
|
|
|
Locks the data dictionary in shared mode from modifications, for performing
|
|
|
|
foreign key check, rollback, or other operation invisible to MySQL. */
|
2008-02-06 15:17:36 +01:00
|
|
|
UNIV_INTERN
|
2005-10-27 09:29:40 +02:00
|
|
|
void
|
|
|
|
row_mysql_freeze_data_dictionary(
|
|
|
|
/*=============================*/
|
|
|
|
trx_t* trx) /* in: transaction */
|
|
|
|
{
|
|
|
|
ut_a(trx->dict_operation_lock_mode == 0);
|
2006-02-23 20:25:29 +01:00
|
|
|
|
2005-10-27 09:29:40 +02:00
|
|
|
rw_lock_s_lock(&dict_operation_lock);
|
|
|
|
|
|
|
|
trx->dict_operation_lock_mode = RW_S_LATCH;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
|
|
|
Unlocks the data dictionary shared lock. */
|
2008-02-06 15:17:36 +01:00
|
|
|
UNIV_INTERN
|
2005-10-27 09:29:40 +02:00
|
|
|
void
|
|
|
|
row_mysql_unfreeze_data_dictionary(
|
|
|
|
/*===============================*/
|
|
|
|
trx_t* trx) /* in: transaction */
|
|
|
|
{
|
|
|
|
ut_a(trx->dict_operation_lock_mode == RW_S_LATCH);
|
|
|
|
|
|
|
|
rw_lock_s_unlock(&dict_operation_lock);
|
|
|
|
|
|
|
|
trx->dict_operation_lock_mode = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
|
|
|
Locks the data dictionary exclusively for performing a table create or other
|
|
|
|
data dictionary modification operation. */
|
2008-02-06 15:17:36 +01:00
|
|
|
UNIV_INTERN
|
2005-10-27 09:29:40 +02:00
|
|
|
void
|
|
|
|
row_mysql_lock_data_dictionary(
|
|
|
|
/*===========================*/
|
|
|
|
trx_t* trx) /* in: transaction */
|
|
|
|
{
|
|
|
|
ut_a(trx->dict_operation_lock_mode == 0
|
2006-08-29 11:30:31 +02:00
|
|
|
|| trx->dict_operation_lock_mode == RW_X_LATCH);
|
2006-02-23 20:25:29 +01:00
|
|
|
|
2005-10-27 09:29:40 +02:00
|
|
|
/* Serialize data dictionary operations with dictionary mutex:
|
|
|
|
no deadlocks or lock waits can occur then in these operations */
|
|
|
|
|
|
|
|
rw_lock_x_lock(&dict_operation_lock);
|
|
|
|
trx->dict_operation_lock_mode = RW_X_LATCH;
|
|
|
|
|
|
|
|
mutex_enter(&(dict_sys->mutex));
|
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
|
|
|
Unlocks the data dictionary exclusive lock. */
|
2008-02-06 15:17:36 +01:00
|
|
|
UNIV_INTERN
|
2005-10-27 09:29:40 +02:00
|
|
|
void
|
|
|
|
row_mysql_unlock_data_dictionary(
|
|
|
|
/*=============================*/
|
|
|
|
trx_t* trx) /* in: transaction */
|
|
|
|
{
|
|
|
|
ut_a(trx->dict_operation_lock_mode == RW_X_LATCH);
|
|
|
|
|
|
|
|
/* Serialize data dictionary operations with dictionary mutex:
|
|
|
|
no deadlocks can occur then in these operations */
|
|
|
|
|
|
|
|
mutex_exit(&(dict_sys->mutex));
|
|
|
|
rw_lock_x_unlock(&dict_operation_lock);
|
|
|
|
|
|
|
|
trx->dict_operation_lock_mode = 0;
|
|
|
|
}
|
|
|
|
|
2006-11-30 16:25:52 +01:00
|
|
|
#ifndef UNIV_HOTBACKUP
|
2005-10-27 09:29:40 +02:00
|
|
|
/*************************************************************************
|
2008-02-18 21:09:03 +01:00
|
|
|
Creates a table for MySQL. If the name of the table ends in
|
2007-08-30 11:21:25 +02:00
|
|
|
one of "innodb_monitor", "innodb_lock_monitor", "innodb_tablespace_monitor",
|
|
|
|
"innodb_table_monitor", then this will also start the printing of monitor
|
|
|
|
output by the master thread. If the table name ends in "innodb_mem_validate",
|
|
|
|
InnoDB will try to invoke mem_validate(). */
|
2008-02-06 15:17:36 +01:00
|
|
|
UNIV_INTERN
|
2005-10-27 09:29:40 +02:00
|
|
|
int
|
|
|
|
row_create_table_for_mysql(
|
|
|
|
/*=======================*/
|
|
|
|
/* out: error code or DB_SUCCESS */
|
branches/innodb+: Merge revisions 2774:2799 from branches/zip:
------------------------------------------------------------------------
r2781 | marko | 2008-10-13 13:40:57 +0300 (Mon, 13 Oct 2008) | 1 line
branches/zip: page_cur_delete_rec(): Call page_zip_validate_low().
------------------------------------------------------------------------
r2783 | vasil | 2008-10-13 18:34:34 +0300 (Mon, 13 Oct 2008) | 9 lines
branches/zip:
Remove mysql-test/patches/bug37312.diff because MySQL "fixed"
Bug#37312 by removing the test.
http://bugs.mysql.com/37312
http://lists.mysql.com/commits/54462
------------------------------------------------------------------------
r2784 | marko | 2008-10-13 21:35:30 +0300 (Mon, 13 Oct 2008) | 1 line
branches/zip: Add missing NULL check to the assertion added in r2781.
------------------------------------------------------------------------
r2785 | marko | 2008-10-13 22:29:12 +0300 (Mon, 13 Oct 2008) | 2 lines
branches/zip: page_cur_delete_rec(): Remove the bogus page_zip_validate_low()
assertion that was added in r2781 and explain why it was bogus.
------------------------------------------------------------------------
r2786 | calvin | 2008-10-14 19:14:47 +0300 (Tue, 14 Oct 2008) | 7 lines
branches/zip: fix Mantis issue #96 Problem compiling ha_innodb.cc
on 64-bit Windows
Change the definition of srv_replication_delay from ulint to ulong.
ulint is 64-bit on Win64.
Approved by: Heikki (on IM)
------------------------------------------------------------------------
r2787 | calvin | 2008-10-14 19:19:41 +0300 (Tue, 14 Oct 2008) | 7 lines
branches/zip: fix compiler warning
Change the definition of add_on from ulint to ullint, to eliminate
the warning in .\btr\btr0cur.c:
conversion from 'ullint' to 'ulint', possible loss of data
Approved by: Heikki (on IM)
------------------------------------------------------------------------
r2793 | marko | 2008-10-15 10:00:06 +0300 (Wed, 15 Oct 2008) | 2 lines
branches/zip: row_create_table_for_mysql(), row_create_index_for_mysql():
Note that the dictionary object will be freed.
------------------------------------------------------------------------
r2794 | marko | 2008-10-15 10:32:40 +0300 (Wed, 15 Oct 2008) | 9 lines
branches/zip: When invoking page_zip_copy_recs(), update the lock table
and the adaptive hash index. This should fix Issue #95 and Issue #87.
page_zip_copy_recs(): Copy PAGE_MAX_TRX_ID as well, to have similar behavior
to page_copy_rec_list_start() and page_copy_rec_list_end().
btr_root_raise_and_insert(), btr_page_split_and_insert(), btr_lift_page_up():
Update the lock table and the adaptive hash index.
------------------------------------------------------------------------
r2797 | marko | 2008-10-15 13:21:54 +0300 (Wed, 15 Oct 2008) | 3 lines
branches/zip: Introduce UNIV_ZIP_COPY for invoking page_zip_copy_recs()
more often in B-tree operations.
------------------------------------------------------------------------
r2799 | marko | 2008-10-15 14:27:42 +0300 (Wed, 15 Oct 2008) | 25 lines
branches/zip: When the server crashes while freeing an externally stored
column of a compressed table, the BTR_EXTERN_LEN field in the BLOB pointer
will be written as 0. Tolerate this in the functions that deal with
externally stored columns. This fixes Issue #80 and was posted at rb://26.
Note that the clustered index record is always deleted or purged last,
after any secondary index records referring to it have been deleted.
btr_free_externally_stored_field(): On an uncompressed table, zero out
the BTR_EXTERN_LEN, so that half-deleted BLOBs can be detected after
crash recovery.
btr_copy_externally_stored_field_prefix(): Return 0 if the BLOB has been
half-deleted.
row_upd_ext_fetch(): Assert that the externally stored column exists.
row_ext_cache_fill(): Allow btr_copy_externally_stored_field_prefix()
to return 0.
row_sel_sec_rec_is_for_blob(): Return FALSE if the BLOB has been half-deleted.
This is correct, because the clustered index record would have been deleted
or purged last, after any secondary index records referring to it had been
deleted.
------------------------------------------------------------------------
2008-10-15 14:09:17 +02:00
|
|
|
dict_table_t* table, /* in, own: table definition
|
|
|
|
(will be freed) */
|
2005-10-27 09:29:40 +02:00
|
|
|
trx_t* trx) /* in: transaction handle */
|
|
|
|
{
|
|
|
|
tab_node_t* node;
|
|
|
|
mem_heap_t* heap;
|
|
|
|
que_thr_t* thr;
|
|
|
|
const char* table_name;
|
|
|
|
ulint table_name_len;
|
|
|
|
ulint err;
|
2006-04-12 11:32:17 +02:00
|
|
|
ulint i;
|
2005-10-27 09:29:40 +02:00
|
|
|
|
|
|
|
ut_ad(trx->mysql_thread_id == os_thread_get_curr_id());
|
|
|
|
#ifdef UNIV_SYNC_DEBUG
|
|
|
|
ut_ad(rw_lock_own(&dict_operation_lock, RW_LOCK_EX));
|
|
|
|
#endif /* UNIV_SYNC_DEBUG */
|
2007-01-18 19:29:12 +01:00
|
|
|
ut_ad(mutex_own(&(dict_sys->mutex)));
|
2005-10-27 09:29:40 +02:00
|
|
|
ut_ad(trx->dict_operation_lock_mode == RW_X_LATCH);
|
2006-02-23 20:25:29 +01:00
|
|
|
|
2005-10-27 09:29:40 +02:00
|
|
|
if (srv_created_new_raw) {
|
2007-09-03 10:44:39 +02:00
|
|
|
fputs("InnoDB: A new raw disk partition was initialized:\n"
|
|
|
|
"InnoDB: we do not allow database modifications"
|
|
|
|
" by the user.\n"
|
|
|
|
"InnoDB: Shut down mysqld and edit my.cnf so that newraw"
|
|
|
|
" is replaced with raw.\n", stderr);
|
2008-03-03 11:25:27 +01:00
|
|
|
err_exit:
|
2006-04-12 11:32:17 +02:00
|
|
|
dict_mem_table_free(table);
|
2005-10-27 09:29:40 +02:00
|
|
|
trx_commit_for_mysql(trx);
|
|
|
|
|
|
|
|
return(DB_ERROR);
|
|
|
|
}
|
|
|
|
|
|
|
|
trx->op_info = "creating table";
|
2006-02-23 20:25:29 +01:00
|
|
|
|
2005-10-27 09:29:40 +02:00
|
|
|
if (row_mysql_is_system_table(table->name)) {
|
|
|
|
|
|
|
|
fprintf(stderr,
|
2006-08-29 11:30:31 +02:00
|
|
|
"InnoDB: Error: trying to create a MySQL system"
|
|
|
|
" table %s of type InnoDB.\n"
|
|
|
|
"InnoDB: MySQL system tables must be"
|
|
|
|
" of the MyISAM type!\n",
|
|
|
|
table->name);
|
2008-03-03 11:25:27 +01:00
|
|
|
goto err_exit;
|
2005-10-27 09:29:40 +02:00
|
|
|
}
|
|
|
|
|
2006-04-12 11:32:17 +02:00
|
|
|
/* Check that no reserved column names are used. */
|
|
|
|
for (i = 0; i < dict_table_get_n_user_cols(table); i++) {
|
2006-09-19 12:14:07 +02:00
|
|
|
if (dict_col_name_is_reserved(
|
|
|
|
dict_table_get_col_name(table, i))) {
|
2006-04-12 11:32:17 +02:00
|
|
|
|
2008-03-03 11:25:27 +01:00
|
|
|
goto err_exit;
|
2006-04-12 11:32:17 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-10-27 09:29:40 +02:00
|
|
|
trx_start_if_not_started(trx);
|
|
|
|
|
|
|
|
/* The table name is prefixed with the database name and a '/'.
|
|
|
|
Certain table names starting with 'innodb_' have their special
|
|
|
|
meaning regardless of the database name. Thus, we need to
|
|
|
|
ignore the database name prefix in the comparisons. */
|
|
|
|
table_name = strchr(table->name, '/');
|
|
|
|
ut_a(table_name);
|
|
|
|
table_name++;
|
|
|
|
table_name_len = strlen(table_name) + 1;
|
|
|
|
|
2008-02-18 21:09:03 +01:00
|
|
|
if (STR_EQ(table_name, table_name_len, S_innodb_monitor)) {
|
2005-10-27 09:29:40 +02:00
|
|
|
|
|
|
|
/* Table equals "innodb_monitor":
|
|
|
|
start monitor prints */
|
2006-02-23 20:25:29 +01:00
|
|
|
|
2005-10-27 09:29:40 +02:00
|
|
|
srv_print_innodb_monitor = TRUE;
|
|
|
|
|
|
|
|
/* The lock timeout monitor thread also takes care
|
|
|
|
of InnoDB monitor prints */
|
|
|
|
|
|
|
|
os_event_set(srv_lock_timeout_thread_event);
|
2008-02-18 21:09:03 +01:00
|
|
|
} else if (STR_EQ(table_name, table_name_len,
|
|
|
|
S_innodb_lock_monitor)) {
|
2005-10-27 09:29:40 +02:00
|
|
|
|
|
|
|
srv_print_innodb_monitor = TRUE;
|
|
|
|
srv_print_innodb_lock_monitor = TRUE;
|
|
|
|
os_event_set(srv_lock_timeout_thread_event);
|
2008-02-18 21:09:03 +01:00
|
|
|
} else if (STR_EQ(table_name, table_name_len,
|
|
|
|
S_innodb_tablespace_monitor)) {
|
2005-10-27 09:29:40 +02:00
|
|
|
|
|
|
|
srv_print_innodb_tablespace_monitor = TRUE;
|
|
|
|
os_event_set(srv_lock_timeout_thread_event);
|
2008-02-18 21:09:03 +01:00
|
|
|
} else if (STR_EQ(table_name, table_name_len,
|
|
|
|
S_innodb_table_monitor)) {
|
2005-10-27 09:29:40 +02:00
|
|
|
|
|
|
|
srv_print_innodb_table_monitor = TRUE;
|
|
|
|
os_event_set(srv_lock_timeout_thread_event);
|
2008-02-18 21:09:03 +01:00
|
|
|
} else if (STR_EQ(table_name, table_name_len,
|
|
|
|
S_innodb_mem_validate)) {
|
2006-02-23 20:25:29 +01:00
|
|
|
/* We define here a debugging feature intended for
|
2005-10-27 09:29:40 +02:00
|
|
|
developers */
|
|
|
|
|
|
|
|
fputs("Validating InnoDB memory:\n"
|
2006-08-29 11:30:31 +02:00
|
|
|
"to use this feature you must compile InnoDB with\n"
|
|
|
|
"UNIV_MEM_DEBUG defined in univ.i and"
|
|
|
|
" the server must be\n"
|
|
|
|
"quiet because allocation from a mem heap"
|
|
|
|
" is not protected\n"
|
|
|
|
"by any semaphore.\n", stderr);
|
2005-10-27 09:29:40 +02:00
|
|
|
#ifdef UNIV_MEM_DEBUG
|
|
|
|
ut_a(mem_validate());
|
|
|
|
fputs("Memory validated\n", stderr);
|
|
|
|
#else /* UNIV_MEM_DEBUG */
|
|
|
|
fputs("Memory NOT validated (recompile with UNIV_MEM_DEBUG)\n",
|
2006-08-29 11:30:31 +02:00
|
|
|
stderr);
|
2005-10-27 09:29:40 +02:00
|
|
|
#endif /* UNIV_MEM_DEBUG */
|
|
|
|
}
|
|
|
|
|
|
|
|
heap = mem_heap_create(512);
|
|
|
|
|
2007-10-19 12:52:25 +02:00
|
|
|
trx_set_dict_operation(trx, TRX_DICT_OP_TABLE);
|
2006-02-23 20:25:29 +01:00
|
|
|
|
2005-10-27 09:29:40 +02:00
|
|
|
node = tab_create_graph_create(table, heap);
|
|
|
|
|
|
|
|
thr = pars_complete_graph_for_exec(node, trx, heap);
|
|
|
|
|
|
|
|
ut_a(thr == que_fork_start_command(que_node_get_parent(thr)));
|
|
|
|
que_run_threads(thr);
|
|
|
|
|
|
|
|
err = trx->error_state;
|
|
|
|
|
2008-03-03 11:25:27 +01:00
|
|
|
if (UNIV_UNLIKELY(err != DB_SUCCESS)) {
|
|
|
|
trx->error_state = DB_SUCCESS;
|
2007-08-29 10:45:34 +02:00
|
|
|
trx_general_rollback_for_mysql(trx, FALSE, NULL);
|
2008-03-03 11:25:27 +01:00
|
|
|
}
|
2005-10-27 09:29:40 +02:00
|
|
|
|
2008-03-03 11:25:27 +01:00
|
|
|
switch (err) {
|
|
|
|
case DB_OUT_OF_FILE_SPACE:
|
2007-08-29 10:45:34 +02:00
|
|
|
ut_print_timestamp(stderr);
|
|
|
|
fputs(" InnoDB: Warning: cannot create table ",
|
|
|
|
stderr);
|
|
|
|
ut_print_name(stderr, trx, TRUE, table->name);
|
|
|
|
fputs(" because tablespace full\n", stderr);
|
2005-10-27 09:29:40 +02:00
|
|
|
|
2007-08-29 10:45:34 +02:00
|
|
|
if (dict_table_get_low(table->name)) {
|
2005-10-27 09:29:40 +02:00
|
|
|
|
2007-08-29 10:45:34 +02:00
|
|
|
row_drop_table_for_mysql(table->name, trx, FALSE);
|
2008-10-11 21:37:21 +02:00
|
|
|
trx_commit_for_mysql(trx);
|
2007-08-29 10:45:34 +02:00
|
|
|
}
|
|
|
|
break;
|
2005-10-27 09:29:40 +02:00
|
|
|
|
2007-08-29 10:45:34 +02:00
|
|
|
case DB_DUPLICATE_KEY:
|
|
|
|
ut_print_timestamp(stderr);
|
|
|
|
fputs(" InnoDB: Error: table ", stderr);
|
|
|
|
ut_print_name(stderr, trx, TRUE, table->name);
|
|
|
|
fputs(" already exists in InnoDB internal\n"
|
|
|
|
"InnoDB: data dictionary. Have you deleted"
|
|
|
|
" the .frm file\n"
|
|
|
|
"InnoDB: and not used DROP TABLE?"
|
|
|
|
" Have you used DROP DATABASE\n"
|
|
|
|
"InnoDB: for InnoDB tables in"
|
|
|
|
" MySQL version <= 3.23.43?\n"
|
|
|
|
"InnoDB: See the Restrictions section"
|
|
|
|
" of the InnoDB manual.\n"
|
|
|
|
"InnoDB: You can drop the orphaned table"
|
|
|
|
" inside InnoDB by\n"
|
|
|
|
"InnoDB: creating an InnoDB table with"
|
|
|
|
" the same name in another\n"
|
|
|
|
"InnoDB: database and copying the .frm file"
|
|
|
|
" to the current database.\n"
|
|
|
|
"InnoDB: Then MySQL thinks the table exists,"
|
|
|
|
" and DROP TABLE will\n"
|
|
|
|
"InnoDB: succeed.\n"
|
|
|
|
"InnoDB: You can look for further help from\n"
|
|
|
|
"InnoDB: "
|
|
|
|
"http://dev.mysql.com/doc/refman/5.1/en/"
|
|
|
|
"innodb-troubleshooting.html\n", stderr);
|
2006-02-23 20:25:29 +01:00
|
|
|
|
2005-10-27 09:29:40 +02:00
|
|
|
/* We may also get err == DB_ERROR if the .ibd file for the
|
|
|
|
table already exists */
|
|
|
|
|
2007-08-29 10:45:34 +02:00
|
|
|
break;
|
2005-10-27 09:29:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
que_graph_free((que_t*) que_node_get_parent(thr));
|
|
|
|
|
|
|
|
trx->op_info = "";
|
|
|
|
|
|
|
|
return((int) err);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
|
|
|
Does an index creation operation for MySQL. TODO: currently failure
|
|
|
|
to create an index results in dropping the whole table! This is no problem
|
|
|
|
currently as all indexes must be created at the same time as the table. */
|
2008-02-06 15:17:36 +01:00
|
|
|
UNIV_INTERN
|
2005-10-27 09:29:40 +02:00
|
|
|
int
|
|
|
|
row_create_index_for_mysql(
|
|
|
|
/*=======================*/
|
|
|
|
/* out: error number or DB_SUCCESS */
|
branches/innodb+: Merge revisions 2774:2799 from branches/zip:
------------------------------------------------------------------------
r2781 | marko | 2008-10-13 13:40:57 +0300 (Mon, 13 Oct 2008) | 1 line
branches/zip: page_cur_delete_rec(): Call page_zip_validate_low().
------------------------------------------------------------------------
r2783 | vasil | 2008-10-13 18:34:34 +0300 (Mon, 13 Oct 2008) | 9 lines
branches/zip:
Remove mysql-test/patches/bug37312.diff because MySQL "fixed"
Bug#37312 by removing the test.
http://bugs.mysql.com/37312
http://lists.mysql.com/commits/54462
------------------------------------------------------------------------
r2784 | marko | 2008-10-13 21:35:30 +0300 (Mon, 13 Oct 2008) | 1 line
branches/zip: Add missing NULL check to the assertion added in r2781.
------------------------------------------------------------------------
r2785 | marko | 2008-10-13 22:29:12 +0300 (Mon, 13 Oct 2008) | 2 lines
branches/zip: page_cur_delete_rec(): Remove the bogus page_zip_validate_low()
assertion that was added in r2781 and explain why it was bogus.
------------------------------------------------------------------------
r2786 | calvin | 2008-10-14 19:14:47 +0300 (Tue, 14 Oct 2008) | 7 lines
branches/zip: fix Mantis issue #96 Problem compiling ha_innodb.cc
on 64-bit Windows
Change the definition of srv_replication_delay from ulint to ulong.
ulint is 64-bit on Win64.
Approved by: Heikki (on IM)
------------------------------------------------------------------------
r2787 | calvin | 2008-10-14 19:19:41 +0300 (Tue, 14 Oct 2008) | 7 lines
branches/zip: fix compiler warning
Change the definition of add_on from ulint to ullint, to eliminate
the warning in .\btr\btr0cur.c:
conversion from 'ullint' to 'ulint', possible loss of data
Approved by: Heikki (on IM)
------------------------------------------------------------------------
r2793 | marko | 2008-10-15 10:00:06 +0300 (Wed, 15 Oct 2008) | 2 lines
branches/zip: row_create_table_for_mysql(), row_create_index_for_mysql():
Note that the dictionary object will be freed.
------------------------------------------------------------------------
r2794 | marko | 2008-10-15 10:32:40 +0300 (Wed, 15 Oct 2008) | 9 lines
branches/zip: When invoking page_zip_copy_recs(), update the lock table
and the adaptive hash index. This should fix Issue #95 and Issue #87.
page_zip_copy_recs(): Copy PAGE_MAX_TRX_ID as well, to have similar behavior
to page_copy_rec_list_start() and page_copy_rec_list_end().
btr_root_raise_and_insert(), btr_page_split_and_insert(), btr_lift_page_up():
Update the lock table and the adaptive hash index.
------------------------------------------------------------------------
r2797 | marko | 2008-10-15 13:21:54 +0300 (Wed, 15 Oct 2008) | 3 lines
branches/zip: Introduce UNIV_ZIP_COPY for invoking page_zip_copy_recs()
more often in B-tree operations.
------------------------------------------------------------------------
r2799 | marko | 2008-10-15 14:27:42 +0300 (Wed, 15 Oct 2008) | 25 lines
branches/zip: When the server crashes while freeing an externally stored
column of a compressed table, the BTR_EXTERN_LEN field in the BLOB pointer
will be written as 0. Tolerate this in the functions that deal with
externally stored columns. This fixes Issue #80 and was posted at rb://26.
Note that the clustered index record is always deleted or purged last,
after any secondary index records referring to it have been deleted.
btr_free_externally_stored_field(): On an uncompressed table, zero out
the BTR_EXTERN_LEN, so that half-deleted BLOBs can be detected after
crash recovery.
btr_copy_externally_stored_field_prefix(): Return 0 if the BLOB has been
half-deleted.
row_upd_ext_fetch(): Assert that the externally stored column exists.
row_ext_cache_fill(): Allow btr_copy_externally_stored_field_prefix()
to return 0.
row_sel_sec_rec_is_for_blob(): Return FALSE if the BLOB has been half-deleted.
This is correct, because the clustered index record would have been deleted
or purged last, after any secondary index records referring to it had been
deleted.
------------------------------------------------------------------------
2008-10-15 14:09:17 +02:00
|
|
|
dict_index_t* index, /* in, own: index definition
|
|
|
|
(will be freed) */
|
2005-10-27 09:29:40 +02:00
|
|
|
trx_t* trx, /* in: transaction handle */
|
|
|
|
const ulint* field_lengths) /* in: if not NULL, must contain
|
|
|
|
dict_index_get_n_fields(index)
|
|
|
|
actual field lengths for the
|
|
|
|
index columns, which are
|
|
|
|
then checked for not being too
|
|
|
|
large. */
|
|
|
|
{
|
|
|
|
ind_node_t* node;
|
|
|
|
mem_heap_t* heap;
|
|
|
|
que_thr_t* thr;
|
|
|
|
ulint err;
|
2007-04-04 13:05:33 +02:00
|
|
|
ulint i;
|
2005-10-27 09:29:40 +02:00
|
|
|
ulint len;
|
2008-05-14 17:43:19 +02:00
|
|
|
char* table_name;
|
2006-02-23 20:25:29 +01:00
|
|
|
|
2005-10-27 09:29:40 +02:00
|
|
|
#ifdef UNIV_SYNC_DEBUG
|
|
|
|
ut_ad(rw_lock_own(&dict_operation_lock, RW_LOCK_EX));
|
|
|
|
#endif /* UNIV_SYNC_DEBUG */
|
2007-01-18 19:29:12 +01:00
|
|
|
ut_ad(mutex_own(&(dict_sys->mutex)));
|
2005-10-27 09:29:40 +02:00
|
|
|
ut_ad(trx->mysql_thread_id == os_thread_get_curr_id());
|
2006-02-23 20:25:29 +01:00
|
|
|
|
2005-10-27 09:29:40 +02:00
|
|
|
trx->op_info = "creating index";
|
|
|
|
|
2008-05-14 17:43:19 +02:00
|
|
|
/* Copy the table name because we may want to drop the
|
|
|
|
table later, after the index object is freed (inside
|
|
|
|
que_run_threads()) and thus index->table_name is not available. */
|
|
|
|
table_name = mem_strdup(index->table_name);
|
|
|
|
|
2005-10-27 09:29:40 +02:00
|
|
|
trx_start_if_not_started(trx);
|
|
|
|
|
|
|
|
/* Check that the same column does not appear twice in the index.
|
|
|
|
Starting from 4.0.14, InnoDB should be able to cope with that, but
|
|
|
|
safer not to allow them. */
|
|
|
|
|
|
|
|
for (i = 0; i < dict_index_get_n_fields(index); i++) {
|
2007-04-04 13:05:33 +02:00
|
|
|
ulint j;
|
|
|
|
|
2005-10-27 09:29:40 +02:00
|
|
|
for (j = 0; j < i; j++) {
|
2006-09-19 12:14:07 +02:00
|
|
|
if (0 == ut_strcmp(
|
|
|
|
dict_index_get_nth_field(index, j)->name,
|
|
|
|
dict_index_get_nth_field(index, i)->name)) {
|
2005-10-27 09:29:40 +02:00
|
|
|
ut_print_timestamp(stderr);
|
|
|
|
|
2006-02-27 10:33:26 +01:00
|
|
|
fputs(" InnoDB: Error: column ", stderr);
|
2006-06-13 22:23:26 +02:00
|
|
|
ut_print_name(stderr, trx, FALSE,
|
2006-09-19 12:14:07 +02:00
|
|
|
dict_index_get_nth_field(
|
|
|
|
index, i)->name);
|
2005-10-27 09:29:40 +02:00
|
|
|
fputs(" appears twice in ", stderr);
|
|
|
|
dict_index_name_print(stderr, trx, index);
|
|
|
|
fputs("\n"
|
2006-08-29 11:30:31 +02:00
|
|
|
"InnoDB: This is not allowed"
|
|
|
|
" in InnoDB.\n", stderr);
|
2005-10-27 09:29:40 +02:00
|
|
|
|
|
|
|
err = DB_COL_APPEARS_TWICE_IN_INDEX;
|
|
|
|
|
|
|
|
goto error_handling;
|
|
|
|
}
|
|
|
|
}
|
2006-02-23 20:25:29 +01:00
|
|
|
|
2005-10-27 09:29:40 +02:00
|
|
|
/* Check also that prefix_len and actual length
|
|
|
|
< DICT_MAX_INDEX_COL_LEN */
|
|
|
|
|
|
|
|
len = dict_index_get_nth_field(index, i)->prefix_len;
|
|
|
|
|
|
|
|
if (field_lengths) {
|
|
|
|
len = ut_max(len, field_lengths[i]);
|
|
|
|
}
|
2006-02-23 20:25:29 +01:00
|
|
|
|
2005-10-27 09:29:40 +02:00
|
|
|
if (len >= DICT_MAX_INDEX_COL_LEN) {
|
|
|
|
err = DB_TOO_BIG_RECORD;
|
|
|
|
|
|
|
|
goto error_handling;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
heap = mem_heap_create(512);
|
|
|
|
|
2007-10-19 12:52:25 +02:00
|
|
|
trx_set_dict_operation(trx, TRX_DICT_OP_TABLE);
|
2005-10-27 09:29:40 +02:00
|
|
|
|
|
|
|
/* Note that the space id where we store the index is inherited from
|
|
|
|
the table in dict_build_index_def_step() in dict0crea.c. */
|
|
|
|
|
|
|
|
node = ind_create_graph_create(index, heap);
|
|
|
|
|
|
|
|
thr = pars_complete_graph_for_exec(node, trx, heap);
|
|
|
|
|
|
|
|
ut_a(thr == que_fork_start_command(que_node_get_parent(thr)));
|
|
|
|
que_run_threads(thr);
|
|
|
|
|
2006-02-23 20:25:29 +01:00
|
|
|
err = trx->error_state;
|
2005-10-27 09:29:40 +02:00
|
|
|
|
|
|
|
que_graph_free((que_t*) que_node_get_parent(thr));
|
|
|
|
|
|
|
|
error_handling:
|
|
|
|
if (err != DB_SUCCESS) {
|
|
|
|
/* We have special error handling here */
|
2006-02-23 20:25:29 +01:00
|
|
|
|
2005-10-27 09:29:40 +02:00
|
|
|
trx->error_state = DB_SUCCESS;
|
|
|
|
|
|
|
|
trx_general_rollback_for_mysql(trx, FALSE, NULL);
|
|
|
|
|
2008-05-14 17:43:19 +02:00
|
|
|
row_drop_table_for_mysql(table_name, trx, FALSE);
|
2005-10-27 09:29:40 +02:00
|
|
|
|
2008-10-11 21:37:21 +02:00
|
|
|
trx_commit_for_mysql(trx);
|
|
|
|
|
2005-10-27 09:29:40 +02:00
|
|
|
trx->error_state = DB_SUCCESS;
|
|
|
|
}
|
2006-02-23 20:25:29 +01:00
|
|
|
|
2005-10-27 09:29:40 +02:00
|
|
|
trx->op_info = "";
|
|
|
|
|
2008-05-14 17:43:19 +02:00
|
|
|
mem_free(table_name);
|
|
|
|
|
2005-10-27 09:29:40 +02:00
|
|
|
return((int) err);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
|
|
|
Scans a table create SQL string and adds to the data dictionary
|
|
|
|
the foreign key constraints declared in the string. This function
|
|
|
|
should be called after the indexes for a table have been created.
|
|
|
|
Each foreign key constraint must be accompanied with indexes in
|
|
|
|
bot participating tables. The indexes are allowed to contain more
|
|
|
|
fields than mentioned in the constraint. Check also that foreign key
|
|
|
|
constraints which reference this table are ok. */
|
2008-02-06 15:17:36 +01:00
|
|
|
UNIV_INTERN
|
2005-10-27 09:29:40 +02:00
|
|
|
int
|
|
|
|
row_table_add_foreign_constraints(
|
|
|
|
/*==============================*/
|
|
|
|
/* out: error code or DB_SUCCESS */
|
|
|
|
trx_t* trx, /* in: transaction */
|
|
|
|
const char* sql_string, /* in: table create statement where
|
|
|
|
foreign keys are declared like:
|
|
|
|
FOREIGN KEY (a, b) REFERENCES table2(c, d),
|
|
|
|
table2 can be written also with the
|
|
|
|
database name before it: test.table2 */
|
|
|
|
const char* name, /* in: table full name in the
|
|
|
|
normalized form
|
|
|
|
database_name/table_name */
|
|
|
|
ibool reject_fks) /* in: if TRUE, fail with error
|
|
|
|
code DB_CANNOT_ADD_CONSTRAINT if
|
|
|
|
any foreign keys are found. */
|
|
|
|
{
|
|
|
|
ulint err;
|
|
|
|
|
|
|
|
ut_ad(mutex_own(&(dict_sys->mutex)));
|
2007-01-18 19:29:12 +01:00
|
|
|
#ifdef UNIV_SYNC_DEBUG
|
2005-10-27 09:29:40 +02:00
|
|
|
ut_ad(rw_lock_own(&dict_operation_lock, RW_LOCK_EX));
|
|
|
|
#endif /* UNIV_SYNC_DEBUG */
|
|
|
|
ut_a(sql_string);
|
2006-02-23 20:25:29 +01:00
|
|
|
|
2005-10-27 09:29:40 +02:00
|
|
|
trx->op_info = "adding foreign keys";
|
|
|
|
|
|
|
|
trx_start_if_not_started(trx);
|
|
|
|
|
2007-10-19 12:52:25 +02:00
|
|
|
trx_set_dict_operation(trx, TRX_DICT_OP_TABLE);
|
2005-10-27 09:29:40 +02:00
|
|
|
|
|
|
|
err = dict_create_foreign_constraints(trx, sql_string, name,
|
2006-08-29 11:30:31 +02:00
|
|
|
reject_fks);
|
2006-11-30 16:25:52 +01:00
|
|
|
#ifndef UNIV_HOTBACKUP
|
2005-10-27 09:29:40 +02:00
|
|
|
if (err == DB_SUCCESS) {
|
|
|
|
/* Check that also referencing constraints are ok */
|
2005-11-29 13:30:46 +01:00
|
|
|
err = dict_load_foreigns(name, TRUE);
|
2005-10-27 09:29:40 +02:00
|
|
|
}
|
2006-11-30 16:25:52 +01:00
|
|
|
#endif /* !UNIV_HOTBACKUP */
|
2005-10-27 09:29:40 +02:00
|
|
|
if (err != DB_SUCCESS) {
|
|
|
|
/* We have special error handling here */
|
2006-02-23 20:25:29 +01:00
|
|
|
|
2005-10-27 09:29:40 +02:00
|
|
|
trx->error_state = DB_SUCCESS;
|
|
|
|
|
|
|
|
trx_general_rollback_for_mysql(trx, FALSE, NULL);
|
|
|
|
|
|
|
|
row_drop_table_for_mysql(name, trx, FALSE);
|
|
|
|
|
2008-10-11 21:37:21 +02:00
|
|
|
trx_commit_for_mysql(trx);
|
|
|
|
|
2005-10-27 09:29:40 +02:00
|
|
|
trx->error_state = DB_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
return((int) err);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
|
|
|
Drops a table for MySQL as a background operation. MySQL relies on Unix
|
|
|
|
in ALTER TABLE to the fact that the table handler does not remove the
|
|
|
|
table before all handles to it has been removed. Furhermore, the MySQL's
|
|
|
|
call to drop table must be non-blocking. Therefore we do the drop table
|
|
|
|
as a background operation, which is taken care of by the master thread
|
|
|
|
in srv0srv.c. */
|
|
|
|
static
|
|
|
|
int
|
|
|
|
row_drop_table_for_mysql_in_background(
|
|
|
|
/*===================================*/
|
|
|
|
/* out: error code or DB_SUCCESS */
|
|
|
|
const char* name) /* in: table name */
|
|
|
|
{
|
|
|
|
ulint error;
|
|
|
|
trx_t* trx;
|
|
|
|
|
|
|
|
trx = trx_allocate_for_background();
|
|
|
|
|
|
|
|
/* If the original transaction was dropping a table referenced by
|
|
|
|
foreign keys, we must set the following to be able to drop the
|
|
|
|
table: */
|
|
|
|
|
|
|
|
trx->check_foreigns = FALSE;
|
|
|
|
|
2006-08-29 11:30:31 +02:00
|
|
|
/* fputs("InnoDB: Error: Dropping table ", stderr);
|
2006-06-13 22:23:26 +02:00
|
|
|
ut_print_name(stderr, trx, TRUE, name);
|
2005-10-27 09:29:40 +02:00
|
|
|
fputs(" in background drop list\n", stderr); */
|
|
|
|
|
2006-02-23 20:25:29 +01:00
|
|
|
/* Try to drop the table in InnoDB */
|
|
|
|
|
|
|
|
error = row_drop_table_for_mysql(name, trx, FALSE);
|
2005-10-27 09:29:40 +02:00
|
|
|
|
|
|
|
/* Flush the log to reduce probability that the .frm files and
|
|
|
|
the InnoDB data dictionary get out-of-sync if the user runs
|
|
|
|
with innodb_flush_log_at_trx_commit = 0 */
|
2006-02-23 20:25:29 +01:00
|
|
|
|
2005-10-27 09:29:40 +02:00
|
|
|
log_buffer_flush_to_disk();
|
|
|
|
|
2006-02-23 20:25:29 +01:00
|
|
|
trx_commit_for_mysql(trx);
|
2005-10-27 09:29:40 +02:00
|
|
|
|
2006-02-23 20:25:29 +01:00
|
|
|
trx_free_for_background(trx);
|
2005-10-27 09:29:40 +02:00
|
|
|
|
|
|
|
return((int) error);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
|
|
|
The master thread in srv0srv.c calls this regularly to drop tables which
|
|
|
|
we must drop in background after queries to them have ended. Such lazy
|
|
|
|
dropping of tables is needed in ALTER TABLE on Unix. */
|
2008-02-06 15:17:36 +01:00
|
|
|
UNIV_INTERN
|
2005-10-27 09:29:40 +02:00
|
|
|
ulint
|
|
|
|
row_drop_tables_for_mysql_in_background(void)
|
|
|
|
/*=========================================*/
|
|
|
|
/* out: how many tables dropped
|
|
|
|
+ remaining tables in list */
|
|
|
|
{
|
|
|
|
row_mysql_drop_t* drop;
|
|
|
|
dict_table_t* table;
|
|
|
|
ulint n_tables;
|
|
|
|
ulint n_tables_dropped = 0;
|
2006-02-23 20:25:29 +01:00
|
|
|
loop:
|
2005-10-27 09:29:40 +02:00
|
|
|
mutex_enter(&kernel_mutex);
|
|
|
|
|
|
|
|
if (!row_mysql_drop_list_inited) {
|
|
|
|
|
|
|
|
UT_LIST_INIT(row_mysql_drop_list);
|
|
|
|
row_mysql_drop_list_inited = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
drop = UT_LIST_GET_FIRST(row_mysql_drop_list);
|
2006-02-23 20:25:29 +01:00
|
|
|
|
2005-10-27 09:29:40 +02:00
|
|
|
n_tables = UT_LIST_GET_LEN(row_mysql_drop_list);
|
|
|
|
|
|
|
|
mutex_exit(&kernel_mutex);
|
|
|
|
|
|
|
|
if (drop == NULL) {
|
|
|
|
/* All tables dropped */
|
|
|
|
|
|
|
|
return(n_tables + n_tables_dropped);
|
|
|
|
}
|
|
|
|
|
|
|
|
mutex_enter(&(dict_sys->mutex));
|
|
|
|
table = dict_table_get_low(drop->table_name);
|
|
|
|
mutex_exit(&(dict_sys->mutex));
|
|
|
|
|
|
|
|
if (table == NULL) {
|
2006-02-23 20:25:29 +01:00
|
|
|
/* If for some reason the table has already been dropped
|
2005-10-27 09:29:40 +02:00
|
|
|
through some other mechanism, do not try to drop it */
|
|
|
|
|
2006-02-23 20:25:29 +01:00
|
|
|
goto already_dropped;
|
2005-10-27 09:29:40 +02:00
|
|
|
}
|
2006-02-23 20:25:29 +01:00
|
|
|
|
2006-09-19 12:14:07 +02:00
|
|
|
if (DB_SUCCESS != row_drop_table_for_mysql_in_background(
|
|
|
|
drop->table_name)) {
|
2005-10-27 09:29:40 +02:00
|
|
|
/* If the DROP fails for some table, we return, and let the
|
|
|
|
main thread retry later */
|
|
|
|
|
|
|
|
return(n_tables + n_tables_dropped);
|
|
|
|
}
|
|
|
|
|
|
|
|
n_tables_dropped++;
|
|
|
|
|
|
|
|
already_dropped:
|
|
|
|
mutex_enter(&kernel_mutex);
|
|
|
|
|
|
|
|
UT_LIST_REMOVE(row_mysql_drop_list, row_mysql_drop_list, drop);
|
|
|
|
|
2006-02-23 20:25:29 +01:00
|
|
|
ut_print_timestamp(stderr);
|
2007-06-21 15:25:03 +02:00
|
|
|
fputs(" InnoDB: Dropped table ", stderr);
|
|
|
|
ut_print_name(stderr, NULL, TRUE, drop->table_name);
|
|
|
|
fputs(" in background drop queue.\n", stderr);
|
2005-10-27 09:29:40 +02:00
|
|
|
|
|
|
|
mem_free(drop->table_name);
|
|
|
|
|
|
|
|
mem_free(drop);
|
|
|
|
|
|
|
|
mutex_exit(&kernel_mutex);
|
|
|
|
|
|
|
|
goto loop;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
|
|
|
Get the background drop list length. NOTE: the caller must own the kernel
|
|
|
|
mutex! */
|
2008-02-06 15:17:36 +01:00
|
|
|
UNIV_INTERN
|
2005-10-27 09:29:40 +02:00
|
|
|
ulint
|
|
|
|
row_get_background_drop_list_len_low(void)
|
|
|
|
/*======================================*/
|
|
|
|
/* out: how many tables in list */
|
|
|
|
{
|
|
|
|
ut_ad(mutex_own(&kernel_mutex));
|
|
|
|
|
|
|
|
if (!row_mysql_drop_list_inited) {
|
|
|
|
|
|
|
|
UT_LIST_INIT(row_mysql_drop_list);
|
|
|
|
row_mysql_drop_list_inited = TRUE;
|
|
|
|
}
|
2006-02-23 20:25:29 +01:00
|
|
|
|
2005-10-27 09:29:40 +02:00
|
|
|
return(UT_LIST_GET_LEN(row_mysql_drop_list));
|
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
|
|
|
If a table is not yet in the drop list, adds the table to the list of tables
|
|
|
|
which the master thread drops in background. We need this on Unix because in
|
|
|
|
ALTER TABLE MySQL may call drop table even if the table has running queries on
|
|
|
|
it. Also, if there are running foreign key checks on the table, we drop the
|
|
|
|
table lazily. */
|
|
|
|
static
|
|
|
|
ibool
|
|
|
|
row_add_table_to_background_drop_list(
|
|
|
|
/*==================================*/
|
|
|
|
/* out: TRUE if the table was not yet in the
|
|
|
|
drop list, and was added there */
|
2007-09-11 07:09:19 +02:00
|
|
|
const char* name) /* in: table name */
|
2005-10-27 09:29:40 +02:00
|
|
|
{
|
|
|
|
row_mysql_drop_t* drop;
|
2006-02-23 20:25:29 +01:00
|
|
|
|
2005-10-27 09:29:40 +02:00
|
|
|
mutex_enter(&kernel_mutex);
|
|
|
|
|
|
|
|
if (!row_mysql_drop_list_inited) {
|
|
|
|
|
|
|
|
UT_LIST_INIT(row_mysql_drop_list);
|
|
|
|
row_mysql_drop_list_inited = TRUE;
|
|
|
|
}
|
2006-02-23 20:25:29 +01:00
|
|
|
|
2005-10-27 09:29:40 +02:00
|
|
|
/* Look if the table already is in the drop list */
|
|
|
|
drop = UT_LIST_GET_FIRST(row_mysql_drop_list);
|
|
|
|
|
|
|
|
while (drop != NULL) {
|
2007-09-11 07:09:19 +02:00
|
|
|
if (strcmp(drop->table_name, name) == 0) {
|
2005-10-27 09:29:40 +02:00
|
|
|
/* Already in the list */
|
2006-02-23 20:25:29 +01:00
|
|
|
|
2005-10-27 09:29:40 +02:00
|
|
|
mutex_exit(&kernel_mutex);
|
|
|
|
|
|
|
|
return(FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
drop = UT_LIST_GET_NEXT(row_mysql_drop_list, drop);
|
|
|
|
}
|
|
|
|
|
|
|
|
drop = mem_alloc(sizeof(row_mysql_drop_t));
|
|
|
|
|
2007-09-11 07:09:19 +02:00
|
|
|
drop->table_name = mem_strdup(name);
|
2006-02-23 20:25:29 +01:00
|
|
|
|
2005-10-27 09:29:40 +02:00
|
|
|
UT_LIST_ADD_LAST(row_mysql_drop_list, row_mysql_drop_list, drop);
|
2006-02-23 20:25:29 +01:00
|
|
|
|
2006-08-29 11:30:31 +02:00
|
|
|
/* fputs("InnoDB: Adding table ", stderr);
|
2006-06-13 22:23:26 +02:00
|
|
|
ut_print_name(stderr, trx, TRUE, drop->table_name);
|
2005-10-27 09:29:40 +02:00
|
|
|
fputs(" to background drop list\n", stderr); */
|
|
|
|
|
|
|
|
mutex_exit(&kernel_mutex);
|
|
|
|
|
|
|
|
return(TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
|
|
|
Discards the tablespace of a table which stored in an .ibd file. Discarding
|
|
|
|
means that this function deletes the .ibd file and assigns a new table id for
|
|
|
|
the table. Also the flag table->ibd_file_missing is set TRUE. */
|
2008-02-06 15:17:36 +01:00
|
|
|
UNIV_INTERN
|
2005-10-27 09:29:40 +02:00
|
|
|
int
|
|
|
|
row_discard_tablespace_for_mysql(
|
|
|
|
/*=============================*/
|
|
|
|
/* out: error code or DB_SUCCESS */
|
|
|
|
const char* name, /* in: table name */
|
|
|
|
trx_t* trx) /* in: transaction handle */
|
|
|
|
{
|
|
|
|
dict_foreign_t* foreign;
|
|
|
|
dulint new_id;
|
|
|
|
dict_table_t* table;
|
|
|
|
ibool success;
|
|
|
|
ulint err;
|
2006-05-08 08:18:59 +02:00
|
|
|
pars_info_t* info = NULL;
|
2005-10-27 09:29:40 +02:00
|
|
|
|
2006-08-29 11:30:31 +02:00
|
|
|
/* How do we prevent crashes caused by ongoing operations on
|
|
|
|
the table? Old operations could try to access non-existent
|
|
|
|
pages.
|
|
|
|
|
|
|
|
1) SQL queries, INSERT, SELECT, ...: we must get an exclusive
|
|
|
|
MySQL table lock on the table before we can do DISCARD
|
|
|
|
TABLESPACE. Then there are no running queries on the table.
|
|
|
|
|
|
|
|
2) Purge and rollback: we assign a new table id for the
|
|
|
|
table. Since purge and rollback look for the table based on
|
|
|
|
the table id, they see the table as 'dropped' and discard
|
|
|
|
their operations.
|
|
|
|
|
|
|
|
3) Insert buffer: we remove all entries for the tablespace in
|
|
|
|
the insert buffer tree; as long as the tablespace mem object
|
|
|
|
does not exist, ongoing insert buffer page merges are
|
|
|
|
discarded in buf0rea.c. If we recreate the tablespace mem
|
|
|
|
object with IMPORT TABLESPACE later, then the tablespace will
|
|
|
|
have the same id, but the tablespace_version field in the mem
|
|
|
|
object is different, and ongoing old insert buffer page merges
|
|
|
|
get discarded.
|
|
|
|
|
|
|
|
4) Linear readahead and random readahead: we use the same
|
|
|
|
method as in 3) to discard ongoing operations.
|
|
|
|
|
|
|
|
5) FOREIGN KEY operations: if
|
|
|
|
table->n_foreign_key_checks_running > 0, we do not allow the
|
|
|
|
discard. We also reserve the data dictionary latch. */
|
2005-10-27 09:29:40 +02:00
|
|
|
|
|
|
|
ut_ad(trx->mysql_thread_id == os_thread_get_curr_id());
|
|
|
|
|
|
|
|
trx->op_info = "discarding tablespace";
|
|
|
|
trx_start_if_not_started(trx);
|
|
|
|
|
|
|
|
/* Serialize data dictionary operations with dictionary mutex:
|
|
|
|
no deadlocks can occur then in these operations */
|
|
|
|
|
|
|
|
row_mysql_lock_data_dictionary(trx);
|
|
|
|
|
|
|
|
table = dict_table_get_low(name);
|
|
|
|
|
|
|
|
if (!table) {
|
|
|
|
err = DB_TABLE_NOT_FOUND;
|
|
|
|
|
|
|
|
goto funct_exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (table->space == 0) {
|
|
|
|
ut_print_timestamp(stderr);
|
2006-02-27 10:33:26 +01:00
|
|
|
fputs(" InnoDB: Error: table ", stderr);
|
2006-06-13 22:23:26 +02:00
|
|
|
ut_print_name(stderr, trx, TRUE, name);
|
2005-10-27 09:29:40 +02:00
|
|
|
fputs("\n"
|
2006-08-29 11:30:31 +02:00
|
|
|
"InnoDB: is in the system tablespace 0"
|
|
|
|
" which cannot be discarded\n", stderr);
|
2005-10-27 09:29:40 +02:00
|
|
|
err = DB_ERROR;
|
|
|
|
|
|
|
|
goto funct_exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (table->n_foreign_key_checks_running > 0) {
|
|
|
|
|
2006-02-23 20:25:29 +01:00
|
|
|
ut_print_timestamp(stderr);
|
2006-02-27 10:33:26 +01:00
|
|
|
fputs(" InnoDB: You are trying to DISCARD table ", stderr);
|
2006-06-13 22:23:26 +02:00
|
|
|
ut_print_name(stderr, trx, TRUE, table->name);
|
2005-10-27 09:29:40 +02:00
|
|
|
fputs("\n"
|
2006-08-29 11:30:31 +02:00
|
|
|
"InnoDB: though there is a foreign key check"
|
|
|
|
" running on it.\n"
|
|
|
|
"InnoDB: Cannot discard the table.\n",
|
|
|
|
stderr);
|
2005-10-27 09:29:40 +02:00
|
|
|
|
|
|
|
err = DB_ERROR;
|
|
|
|
|
|
|
|
goto funct_exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check if the table is referenced by foreign key constraints from
|
|
|
|
some other table (not the table itself) */
|
|
|
|
|
|
|
|
foreign = UT_LIST_GET_FIRST(table->referenced_list);
|
2006-02-23 20:25:29 +01:00
|
|
|
|
2005-10-27 09:29:40 +02:00
|
|
|
while (foreign && foreign->foreign_table == table) {
|
|
|
|
foreign = UT_LIST_GET_NEXT(referenced_list, foreign);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (foreign && trx->check_foreigns) {
|
|
|
|
|
|
|
|
FILE* ef = dict_foreign_err_file;
|
|
|
|
|
|
|
|
/* We only allow discarding a referenced table if
|
|
|
|
FOREIGN_KEY_CHECKS is set to 0 */
|
|
|
|
|
|
|
|
err = DB_CANNOT_DROP_CONSTRAINT;
|
|
|
|
|
|
|
|
mutex_enter(&dict_foreign_err_mutex);
|
|
|
|
rewind(ef);
|
|
|
|
ut_print_timestamp(ef);
|
|
|
|
|
2006-02-27 10:33:26 +01:00
|
|
|
fputs(" Cannot DISCARD table ", ef);
|
2007-04-04 13:05:33 +02:00
|
|
|
ut_print_name(stderr, trx, TRUE, name);
|
2005-10-27 09:29:40 +02:00
|
|
|
fputs("\n"
|
2006-08-29 11:30:31 +02:00
|
|
|
"because it is referenced by ", ef);
|
2007-04-04 13:05:33 +02:00
|
|
|
ut_print_name(stderr, trx, TRUE, foreign->foreign_table_name);
|
2005-10-27 09:29:40 +02:00
|
|
|
putc('\n', ef);
|
|
|
|
mutex_exit(&dict_foreign_err_mutex);
|
|
|
|
|
|
|
|
goto funct_exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
new_id = dict_hdr_get_new_id(DICT_HDR_TABLE_ID);
|
|
|
|
|
2008-10-11 21:37:21 +02:00
|
|
|
/* Remove all locks except the table-level S and X locks. */
|
|
|
|
lock_remove_all_on_table(table, FALSE);
|
2005-10-27 09:29:40 +02:00
|
|
|
|
2006-05-08 08:18:59 +02:00
|
|
|
info = pars_info_create();
|
2005-10-27 09:29:40 +02:00
|
|
|
|
2006-05-08 08:18:59 +02:00
|
|
|
pars_info_add_str_literal(info, "table_name", name);
|
|
|
|
pars_info_add_dulint_literal(info, "new_id", new_id);
|
2005-10-27 09:29:40 +02:00
|
|
|
|
2006-05-08 08:18:59 +02:00
|
|
|
err = que_eval_sql(info,
|
2006-08-29 11:30:31 +02:00
|
|
|
"PROCEDURE DISCARD_TABLESPACE_PROC () IS\n"
|
|
|
|
"old_id CHAR;\n"
|
|
|
|
"BEGIN\n"
|
|
|
|
"SELECT ID INTO old_id\n"
|
|
|
|
"FROM SYS_TABLES\n"
|
|
|
|
"WHERE NAME = :table_name\n"
|
|
|
|
"LOCK IN SHARE MODE;\n"
|
|
|
|
"IF (SQL % NOTFOUND) THEN\n"
|
|
|
|
" COMMIT WORK;\n"
|
|
|
|
" RETURN;\n"
|
|
|
|
"END IF;\n"
|
|
|
|
"UPDATE SYS_TABLES SET ID = :new_id\n"
|
|
|
|
" WHERE ID = old_id;\n"
|
|
|
|
"UPDATE SYS_COLUMNS SET TABLE_ID = :new_id\n"
|
|
|
|
" WHERE TABLE_ID = old_id;\n"
|
|
|
|
"UPDATE SYS_INDEXES SET TABLE_ID = :new_id\n"
|
|
|
|
" WHERE TABLE_ID = old_id;\n"
|
|
|
|
"COMMIT WORK;\n"
|
|
|
|
"END;\n"
|
|
|
|
, FALSE, trx);
|
2005-10-27 09:29:40 +02:00
|
|
|
|
|
|
|
if (err != DB_SUCCESS) {
|
|
|
|
trx->error_state = DB_SUCCESS;
|
|
|
|
trx_general_rollback_for_mysql(trx, FALSE, NULL);
|
|
|
|
trx->error_state = DB_SUCCESS;
|
|
|
|
} else {
|
|
|
|
dict_table_change_id_in_cache(table, new_id);
|
|
|
|
|
|
|
|
success = fil_discard_tablespace(table->space);
|
|
|
|
|
|
|
|
if (!success) {
|
|
|
|
trx->error_state = DB_SUCCESS;
|
|
|
|
trx_general_rollback_for_mysql(trx, FALSE, NULL);
|
|
|
|
trx->error_state = DB_SUCCESS;
|
|
|
|
|
|
|
|
err = DB_ERROR;
|
|
|
|
} else {
|
|
|
|
/* Set the flag which tells that now it is legal to
|
|
|
|
IMPORT a tablespace for this table */
|
|
|
|
table->tablespace_discarded = TRUE;
|
|
|
|
table->ibd_file_missing = TRUE;
|
|
|
|
}
|
|
|
|
}
|
2006-05-08 08:18:59 +02:00
|
|
|
|
2006-02-23 20:25:29 +01:00
|
|
|
funct_exit:
|
|
|
|
trx_commit_for_mysql(trx);
|
2005-10-27 09:29:40 +02:00
|
|
|
|
2006-05-22 11:30:34 +02:00
|
|
|
row_mysql_unlock_data_dictionary(trx);
|
|
|
|
|
2005-10-27 09:29:40 +02:00
|
|
|
trx->op_info = "";
|
|
|
|
|
|
|
|
return((int) err);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
Imports a tablespace. The space id in the .ibd file must match the space id
|
|
|
|
of the table in the data dictionary. */
|
2008-02-06 15:17:36 +01:00
|
|
|
UNIV_INTERN
|
2005-10-27 09:29:40 +02:00
|
|
|
int
|
|
|
|
row_import_tablespace_for_mysql(
|
|
|
|
/*============================*/
|
|
|
|
/* out: error code or DB_SUCCESS */
|
|
|
|
const char* name, /* in: table name */
|
|
|
|
trx_t* trx) /* in: transaction handle */
|
|
|
|
{
|
|
|
|
dict_table_t* table;
|
|
|
|
ibool success;
|
2006-11-29 15:52:16 +01:00
|
|
|
ib_uint64_t current_lsn;
|
2005-10-27 09:29:40 +02:00
|
|
|
ulint err = DB_SUCCESS;
|
|
|
|
|
|
|
|
ut_ad(trx->mysql_thread_id == os_thread_get_curr_id());
|
|
|
|
|
|
|
|
trx_start_if_not_started(trx);
|
|
|
|
|
|
|
|
trx->op_info = "importing tablespace";
|
|
|
|
|
|
|
|
current_lsn = log_get_lsn();
|
2006-02-23 20:25:29 +01:00
|
|
|
|
2005-10-27 09:29:40 +02:00
|
|
|
/* It is possible, though very improbable, that the lsn's in the
|
|
|
|
tablespace to be imported have risen above the current system lsn, if
|
|
|
|
a lengthy purge, ibuf merge, or rollback was performed on a backup
|
|
|
|
taken with ibbackup. If that is the case, reset page lsn's in the
|
|
|
|
file. We assume that mysqld was shut down after it performed these
|
|
|
|
cleanup operations on the .ibd file, so that it stamped the latest lsn
|
|
|
|
to the FIL_PAGE_FILE_FLUSH_LSN in the first page of the .ibd file.
|
|
|
|
|
|
|
|
TODO: reset also the trx id's in clustered index records and write
|
|
|
|
a new space id to each data page. That would allow us to import clean
|
|
|
|
.ibd files from another MySQL installation. */
|
|
|
|
|
|
|
|
success = fil_reset_too_high_lsns(name, current_lsn);
|
|
|
|
|
|
|
|
if (!success) {
|
|
|
|
ut_print_timestamp(stderr);
|
2006-02-27 10:33:26 +01:00
|
|
|
fputs(" InnoDB: Error: cannot reset lsn's in table ", stderr);
|
2006-06-13 22:23:26 +02:00
|
|
|
ut_print_name(stderr, trx, TRUE, name);
|
2005-10-27 09:29:40 +02:00
|
|
|
fputs("\n"
|
2006-08-29 11:30:31 +02:00
|
|
|
"InnoDB: in ALTER TABLE ... IMPORT TABLESPACE\n",
|
|
|
|
stderr);
|
2005-10-27 09:29:40 +02:00
|
|
|
|
|
|
|
err = DB_ERROR;
|
|
|
|
|
|
|
|
row_mysql_lock_data_dictionary(trx);
|
|
|
|
|
|
|
|
goto funct_exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Serialize data dictionary operations with dictionary mutex:
|
|
|
|
no deadlocks can occur then in these operations */
|
|
|
|
|
|
|
|
row_mysql_lock_data_dictionary(trx);
|
|
|
|
|
|
|
|
table = dict_table_get_low(name);
|
|
|
|
|
|
|
|
if (!table) {
|
|
|
|
ut_print_timestamp(stderr);
|
2006-02-27 10:33:26 +01:00
|
|
|
fputs(" InnoDB: table ", stderr);
|
2006-06-13 22:23:26 +02:00
|
|
|
ut_print_name(stderr, trx, TRUE, name);
|
2005-10-27 09:29:40 +02:00
|
|
|
fputs("\n"
|
2006-08-29 11:30:31 +02:00
|
|
|
"InnoDB: does not exist in the InnoDB data dictionary\n"
|
|
|
|
"InnoDB: in ALTER TABLE ... IMPORT TABLESPACE\n",
|
|
|
|
stderr);
|
2005-10-27 09:29:40 +02:00
|
|
|
|
|
|
|
err = DB_TABLE_NOT_FOUND;
|
|
|
|
|
|
|
|
goto funct_exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (table->space == 0) {
|
|
|
|
ut_print_timestamp(stderr);
|
2006-02-27 10:33:26 +01:00
|
|
|
fputs(" InnoDB: Error: table ", stderr);
|
2006-06-13 22:23:26 +02:00
|
|
|
ut_print_name(stderr, trx, TRUE, name);
|
2005-10-27 09:29:40 +02:00
|
|
|
fputs("\n"
|
2006-08-29 11:30:31 +02:00
|
|
|
"InnoDB: is in the system tablespace 0"
|
|
|
|
" which cannot be imported\n", stderr);
|
2005-10-27 09:29:40 +02:00
|
|
|
err = DB_ERROR;
|
|
|
|
|
|
|
|
goto funct_exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!table->tablespace_discarded) {
|
|
|
|
ut_print_timestamp(stderr);
|
2006-08-29 11:30:31 +02:00
|
|
|
fputs(" InnoDB: Error: you are trying to"
|
|
|
|
" IMPORT a tablespace\n"
|
|
|
|
"InnoDB: ", stderr);
|
2006-06-13 22:23:26 +02:00
|
|
|
ut_print_name(stderr, trx, TRUE, name);
|
2005-10-27 09:29:40 +02:00
|
|
|
fputs(", though you have not called DISCARD on it yet\n"
|
2006-08-29 11:30:31 +02:00
|
|
|
"InnoDB: during the lifetime of the mysqld process!\n",
|
|
|
|
stderr);
|
2005-10-27 09:29:40 +02:00
|
|
|
|
|
|
|
err = DB_ERROR;
|
|
|
|
|
|
|
|
goto funct_exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Play safe and remove all insert buffer entries, though we should
|
|
|
|
have removed them already when DISCARD TABLESPACE was called */
|
|
|
|
|
|
|
|
ibuf_delete_for_discarded_space(table->space);
|
|
|
|
|
2008-05-14 17:43:19 +02:00
|
|
|
success = fil_open_single_table_tablespace(
|
|
|
|
TRUE, table->space,
|
|
|
|
table->flags == DICT_TF_COMPACT ? 0 : table->flags,
|
|
|
|
table->name);
|
2005-10-27 09:29:40 +02:00
|
|
|
if (success) {
|
|
|
|
table->ibd_file_missing = FALSE;
|
|
|
|
table->tablespace_discarded = FALSE;
|
|
|
|
} else {
|
|
|
|
if (table->ibd_file_missing) {
|
|
|
|
ut_print_timestamp(stderr);
|
2006-08-29 11:30:31 +02:00
|
|
|
fputs(" InnoDB: cannot find or open in the"
|
|
|
|
" database directory the .ibd file of\n"
|
|
|
|
"InnoDB: table ", stderr);
|
2006-06-13 22:23:26 +02:00
|
|
|
ut_print_name(stderr, trx, TRUE, name);
|
2005-10-27 09:29:40 +02:00
|
|
|
fputs("\n"
|
2006-08-29 11:30:31 +02:00
|
|
|
"InnoDB: in ALTER TABLE ... IMPORT TABLESPACE\n",
|
|
|
|
stderr);
|
2005-10-27 09:29:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
err = DB_ERROR;
|
|
|
|
}
|
|
|
|
|
2006-02-23 20:25:29 +01:00
|
|
|
funct_exit:
|
|
|
|
trx_commit_for_mysql(trx);
|
2005-10-27 09:29:40 +02:00
|
|
|
|
2006-05-22 11:30:34 +02:00
|
|
|
row_mysql_unlock_data_dictionary(trx);
|
|
|
|
|
2005-10-27 09:29:40 +02:00
|
|
|
trx->op_info = "";
|
|
|
|
|
|
|
|
return((int) err);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
|
|
|
Truncates a table for MySQL. */
|
2008-02-06 15:17:36 +01:00
|
|
|
UNIV_INTERN
|
2005-10-27 09:29:40 +02:00
|
|
|
int
|
|
|
|
row_truncate_table_for_mysql(
|
|
|
|
/*=========================*/
|
|
|
|
/* out: error code or DB_SUCCESS */
|
|
|
|
dict_table_t* table, /* in: table handle */
|
|
|
|
trx_t* trx) /* in: transaction handle */
|
|
|
|
{
|
|
|
|
dict_foreign_t* foreign;
|
|
|
|
ulint err;
|
|
|
|
mem_heap_t* heap;
|
|
|
|
byte* buf;
|
|
|
|
dtuple_t* tuple;
|
|
|
|
dfield_t* dfield;
|
|
|
|
dict_index_t* sys_index;
|
|
|
|
btr_pcur_t pcur;
|
|
|
|
mtr_t mtr;
|
|
|
|
dulint new_id;
|
2007-03-29 10:51:13 +02:00
|
|
|
ulint recreate_space = 0;
|
2006-05-08 08:18:59 +02:00
|
|
|
pars_info_t* info = NULL;
|
2005-10-27 09:29:40 +02:00
|
|
|
|
2006-08-29 11:30:31 +02:00
|
|
|
/* How do we prevent crashes caused by ongoing operations on
|
|
|
|
the table? Old operations could try to access non-existent
|
|
|
|
pages.
|
|
|
|
|
|
|
|
1) SQL queries, INSERT, SELECT, ...: we must get an exclusive
|
|
|
|
MySQL table lock on the table before we can do TRUNCATE
|
|
|
|
TABLE. Then there are no running queries on the table. This is
|
|
|
|
guaranteed, because in ha_innobase::store_lock(), we do not
|
|
|
|
weaken the TL_WRITE lock requested by MySQL when executing
|
|
|
|
SQLCOM_TRUNCATE.
|
|
|
|
|
|
|
|
2) Purge and rollback: we assign a new table id for the
|
|
|
|
table. Since purge and rollback look for the table based on
|
|
|
|
the table id, they see the table as 'dropped' and discard
|
|
|
|
their operations.
|
|
|
|
|
|
|
|
3) Insert buffer: TRUNCATE TABLE is analogous to DROP TABLE,
|
|
|
|
so we do not have to remove insert buffer records, as the
|
|
|
|
insert buffer works at a low level. If a freed page is later
|
|
|
|
reallocated, the allocator will remove the ibuf entries for
|
|
|
|
it.
|
|
|
|
|
2007-03-29 10:51:13 +02:00
|
|
|
When we truncate *.ibd files by recreating them (analogous to
|
|
|
|
DISCARD TABLESPACE), we remove all entries for the table in the
|
|
|
|
insert buffer tree. This is not strictly necessary, because
|
|
|
|
in 6) we will assign a new tablespace identifier, but we can
|
|
|
|
free up some space in the system tablespace.
|
2006-08-29 11:30:31 +02:00
|
|
|
|
|
|
|
4) Linear readahead and random readahead: we use the same
|
2007-03-29 10:51:13 +02:00
|
|
|
method as in 3) to discard ongoing operations. (This is only
|
|
|
|
relevant for TRUNCATE TABLE by DISCARD TABLESPACE.)
|
2006-08-29 11:30:31 +02:00
|
|
|
|
|
|
|
5) FOREIGN KEY operations: if
|
|
|
|
table->n_foreign_key_checks_running > 0, we do not allow the
|
2007-03-29 10:51:13 +02:00
|
|
|
TRUNCATE. We also reserve the data dictionary latch.
|
|
|
|
|
|
|
|
6) Crash recovery: To prevent the application of pre-truncation
|
|
|
|
redo log records on the truncated tablespace, we will assign
|
|
|
|
a new tablespace identifier to the truncated tablespace. */
|
2005-10-27 09:29:40 +02:00
|
|
|
|
|
|
|
ut_ad(trx->mysql_thread_id == os_thread_get_curr_id());
|
|
|
|
ut_ad(table);
|
|
|
|
|
|
|
|
if (srv_created_new_raw) {
|
2007-09-03 10:44:39 +02:00
|
|
|
fputs("InnoDB: A new raw disk partition was initialized:\n"
|
|
|
|
"InnoDB: we do not allow database modifications"
|
|
|
|
" by the user.\n"
|
|
|
|
"InnoDB: Shut down mysqld and edit my.cnf so that newraw"
|
|
|
|
" is replaced with raw.\n", stderr);
|
2005-10-27 09:29:40 +02:00
|
|
|
|
|
|
|
return(DB_ERROR);
|
|
|
|
}
|
|
|
|
|
|
|
|
trx->op_info = "truncating table";
|
|
|
|
|
|
|
|
trx_start_if_not_started(trx);
|
|
|
|
|
|
|
|
/* Serialize data dictionary operations with dictionary mutex:
|
|
|
|
no deadlocks can occur then in these operations */
|
|
|
|
|
|
|
|
ut_a(trx->dict_operation_lock_mode == 0);
|
|
|
|
/* Prevent foreign key checks etc. while we are truncating the
|
|
|
|
table */
|
|
|
|
|
|
|
|
row_mysql_lock_data_dictionary(trx);
|
|
|
|
|
|
|
|
ut_ad(mutex_own(&(dict_sys->mutex)));
|
2007-01-18 19:29:12 +01:00
|
|
|
#ifdef UNIV_SYNC_DEBUG
|
2005-10-27 09:29:40 +02:00
|
|
|
ut_ad(rw_lock_own(&dict_operation_lock, RW_LOCK_EX));
|
|
|
|
#endif /* UNIV_SYNC_DEBUG */
|
|
|
|
|
|
|
|
/* Check if the table is referenced by foreign key constraints from
|
|
|
|
some other table (not the table itself) */
|
|
|
|
|
|
|
|
foreign = UT_LIST_GET_FIRST(table->referenced_list);
|
|
|
|
|
|
|
|
while (foreign && foreign->foreign_table == table) {
|
|
|
|
foreign = UT_LIST_GET_NEXT(referenced_list, foreign);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (foreign && trx->check_foreigns) {
|
|
|
|
FILE* ef = dict_foreign_err_file;
|
|
|
|
|
|
|
|
/* We only allow truncating a referenced table if
|
|
|
|
FOREIGN_KEY_CHECKS is set to 0 */
|
|
|
|
|
|
|
|
mutex_enter(&dict_foreign_err_mutex);
|
|
|
|
rewind(ef);
|
|
|
|
ut_print_timestamp(ef);
|
|
|
|
|
2006-02-27 10:33:26 +01:00
|
|
|
fputs(" Cannot truncate table ", ef);
|
2007-08-13 19:15:31 +02:00
|
|
|
ut_print_name(ef, trx, TRUE, table->name);
|
2005-10-27 09:29:40 +02:00
|
|
|
fputs(" by DROP+CREATE\n"
|
2006-08-29 11:30:31 +02:00
|
|
|
"InnoDB: because it is referenced by ", ef);
|
2007-08-13 19:15:31 +02:00
|
|
|
ut_print_name(ef, trx, TRUE, foreign->foreign_table_name);
|
2005-10-27 09:29:40 +02:00
|
|
|
putc('\n', ef);
|
|
|
|
mutex_exit(&dict_foreign_err_mutex);
|
|
|
|
|
|
|
|
err = DB_ERROR;
|
|
|
|
goto funct_exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* TODO: could we replace the counter n_foreign_key_checks_running
|
|
|
|
with lock checks on the table? Acquire here an exclusive lock on the
|
|
|
|
table, and rewrite lock0lock.c and the lock wait in srv0srv.c so that
|
|
|
|
they can cope with the table having been truncated here? Foreign key
|
|
|
|
checks take an IS or IX lock on the table. */
|
|
|
|
|
|
|
|
if (table->n_foreign_key_checks_running > 0) {
|
|
|
|
ut_print_timestamp(stderr);
|
2006-02-27 10:33:26 +01:00
|
|
|
fputs(" InnoDB: Cannot truncate table ", stderr);
|
2006-06-13 22:23:26 +02:00
|
|
|
ut_print_name(stderr, trx, TRUE, table->name);
|
2005-10-27 09:29:40 +02:00
|
|
|
fputs(" by DROP+CREATE\n"
|
2006-08-29 11:30:31 +02:00
|
|
|
"InnoDB: because there is a foreign key check"
|
|
|
|
" running on it.\n",
|
|
|
|
stderr);
|
2005-10-27 09:29:40 +02:00
|
|
|
err = DB_ERROR;
|
|
|
|
|
|
|
|
goto funct_exit;
|
|
|
|
}
|
|
|
|
|
2008-10-11 21:37:21 +02:00
|
|
|
/* Remove all locks except the table-level S and X locks. */
|
|
|
|
lock_remove_all_on_table(table, FALSE);
|
2005-10-27 09:29:40 +02:00
|
|
|
|
|
|
|
trx->table_id = table->id;
|
|
|
|
|
2007-03-29 10:51:13 +02:00
|
|
|
if (table->space && !table->dir_path_of_temp_table) {
|
|
|
|
/* Discard and create the single-table tablespace. */
|
|
|
|
ulint space = table->space;
|
2008-05-14 17:43:19 +02:00
|
|
|
ulint flags = fil_space_get_flags(space);
|
2007-03-29 10:51:13 +02:00
|
|
|
|
2008-05-14 17:43:19 +02:00
|
|
|
if (flags != ULINT_UNDEFINED
|
2007-03-29 10:51:13 +02:00
|
|
|
&& fil_discard_tablespace(space)) {
|
|
|
|
|
|
|
|
dict_index_t* index;
|
|
|
|
|
|
|
|
space = 0;
|
|
|
|
|
|
|
|
if (fil_create_new_single_table_tablespace(
|
2008-05-14 17:43:19 +02:00
|
|
|
&space, table->name, FALSE, flags,
|
2007-03-29 10:51:13 +02:00
|
|
|
FIL_IBD_FILE_INITIAL_SIZE) != DB_SUCCESS) {
|
|
|
|
ut_print_timestamp(stderr);
|
|
|
|
fprintf(stderr,
|
|
|
|
" InnoDB: TRUNCATE TABLE %s failed to"
|
|
|
|
" create a new tablespace\n",
|
|
|
|
table->name);
|
|
|
|
table->ibd_file_missing = 1;
|
|
|
|
err = DB_ERROR;
|
|
|
|
goto funct_exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
recreate_space = space;
|
|
|
|
|
|
|
|
/* Replace the space_id in the data dictionary cache.
|
|
|
|
The persisent data dictionary (SYS_TABLES.SPACE
|
|
|
|
and SYS_INDEXES.SPACE) are updated later in this
|
|
|
|
function. */
|
|
|
|
table->space = space;
|
|
|
|
index = dict_table_get_first_index(table);
|
|
|
|
do {
|
|
|
|
index->space = space;
|
|
|
|
index = dict_table_get_next_index(index);
|
|
|
|
} while (index);
|
|
|
|
|
|
|
|
mtr_start(&mtr);
|
|
|
|
fsp_header_init(space,
|
|
|
|
FIL_IBD_FILE_INITIAL_SIZE, &mtr);
|
|
|
|
mtr_commit(&mtr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-10-27 09:29:40 +02:00
|
|
|
/* scan SYS_INDEXES for all indexes of the table */
|
|
|
|
heap = mem_heap_create(800);
|
|
|
|
|
|
|
|
tuple = dtuple_create(heap, 1);
|
2006-10-19 09:27:26 +02:00
|
|
|
dfield = dtuple_get_nth_field(tuple, 0);
|
2005-10-27 09:29:40 +02:00
|
|
|
|
|
|
|
buf = mem_heap_alloc(heap, 8);
|
|
|
|
mach_write_to_8(buf, table->id);
|
|
|
|
|
|
|
|
dfield_set_data(dfield, buf, 8);
|
|
|
|
sys_index = dict_table_get_first_index(dict_sys->sys_indexes);
|
|
|
|
dict_index_copy_types(tuple, sys_index, 1);
|
|
|
|
|
|
|
|
mtr_start(&mtr);
|
|
|
|
btr_pcur_open_on_user_rec(sys_index, tuple, PAGE_CUR_GE,
|
2006-08-29 11:30:31 +02:00
|
|
|
BTR_MODIFY_LEAF, &pcur, &mtr);
|
2005-10-27 09:29:40 +02:00
|
|
|
for (;;) {
|
|
|
|
rec_t* rec;
|
|
|
|
const byte* field;
|
|
|
|
ulint len;
|
|
|
|
ulint root_page_no;
|
|
|
|
|
2007-10-22 10:16:35 +02:00
|
|
|
if (!btr_pcur_is_on_user_rec(&pcur)) {
|
2005-10-27 09:29:40 +02:00
|
|
|
/* The end of SYS_INDEXES has been reached. */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
rec = btr_pcur_get_rec(&pcur);
|
|
|
|
|
|
|
|
field = rec_get_nth_field_old(rec, 0, &len);
|
|
|
|
ut_ad(len == 8);
|
|
|
|
|
|
|
|
if (memcmp(buf, field, len) != 0) {
|
|
|
|
/* End of indexes for the table (TABLE_ID mismatch). */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (rec_get_deleted_flag(rec, FALSE)) {
|
|
|
|
/* The index has been dropped. */
|
|
|
|
goto next_rec;
|
|
|
|
}
|
|
|
|
|
2006-10-30 14:44:00 +01:00
|
|
|
/* This call may commit and restart mtr
|
|
|
|
and reposition pcur. */
|
2007-03-29 10:51:13 +02:00
|
|
|
root_page_no = dict_truncate_index_tree(table, recreate_space,
|
|
|
|
&pcur, &mtr);
|
2005-10-27 09:29:40 +02:00
|
|
|
|
|
|
|
rec = btr_pcur_get_rec(&pcur);
|
|
|
|
|
|
|
|
if (root_page_no != FIL_NULL) {
|
2006-09-19 12:14:07 +02:00
|
|
|
page_rec_write_index_page_no(
|
|
|
|
rec, DICT_SYS_INDEXES_PAGE_NO_FIELD,
|
|
|
|
root_page_no, &mtr);
|
2005-10-27 09:29:40 +02:00
|
|
|
/* We will need to commit and restart the
|
|
|
|
mini-transaction in order to avoid deadlocks.
|
|
|
|
The dict_truncate_index_tree() call has allocated
|
|
|
|
a page in this mini-transaction, and the rest of
|
|
|
|
this loop could latch another index page. */
|
|
|
|
mtr_commit(&mtr);
|
|
|
|
mtr_start(&mtr);
|
|
|
|
btr_pcur_restore_position(BTR_MODIFY_LEAF,
|
2006-08-29 11:30:31 +02:00
|
|
|
&pcur, &mtr);
|
2005-10-27 09:29:40 +02:00
|
|
|
}
|
|
|
|
|
2006-08-29 11:30:31 +02:00
|
|
|
next_rec:
|
2005-10-27 09:29:40 +02:00
|
|
|
btr_pcur_move_to_next_user_rec(&pcur, &mtr);
|
|
|
|
}
|
|
|
|
|
|
|
|
btr_pcur_close(&pcur);
|
|
|
|
mtr_commit(&mtr);
|
|
|
|
|
|
|
|
mem_heap_free(heap);
|
|
|
|
|
2006-05-08 08:18:59 +02:00
|
|
|
new_id = dict_hdr_get_new_id(DICT_HDR_TABLE_ID);
|
2005-10-27 09:29:40 +02:00
|
|
|
|
2006-05-08 08:18:59 +02:00
|
|
|
info = pars_info_create();
|
2005-10-27 09:29:40 +02:00
|
|
|
|
2007-03-29 10:51:13 +02:00
|
|
|
pars_info_add_int4_literal(info, "space", (lint) table->space);
|
2006-05-08 08:18:59 +02:00
|
|
|
pars_info_add_dulint_literal(info, "old_id", table->id);
|
|
|
|
pars_info_add_dulint_literal(info, "new_id", new_id);
|
2005-10-27 09:29:40 +02:00
|
|
|
|
2006-05-08 08:18:59 +02:00
|
|
|
err = que_eval_sql(info,
|
2006-08-29 11:30:31 +02:00
|
|
|
"PROCEDURE RENUMBER_TABLESPACE_PROC () IS\n"
|
|
|
|
"BEGIN\n"
|
2007-03-29 10:51:13 +02:00
|
|
|
"UPDATE SYS_TABLES"
|
|
|
|
" SET ID = :new_id, SPACE = :space\n"
|
2006-08-29 11:30:31 +02:00
|
|
|
" WHERE ID = :old_id;\n"
|
|
|
|
"UPDATE SYS_COLUMNS SET TABLE_ID = :new_id\n"
|
|
|
|
" WHERE TABLE_ID = :old_id;\n"
|
2007-03-29 10:51:13 +02:00
|
|
|
"UPDATE SYS_INDEXES"
|
|
|
|
" SET TABLE_ID = :new_id, SPACE = :space\n"
|
2006-08-29 11:30:31 +02:00
|
|
|
" WHERE TABLE_ID = :old_id;\n"
|
|
|
|
"COMMIT WORK;\n"
|
|
|
|
"END;\n"
|
|
|
|
, FALSE, trx);
|
2005-10-27 09:29:40 +02:00
|
|
|
|
|
|
|
if (err != DB_SUCCESS) {
|
|
|
|
trx->error_state = DB_SUCCESS;
|
|
|
|
trx_general_rollback_for_mysql(trx, FALSE, NULL);
|
|
|
|
trx->error_state = DB_SUCCESS;
|
|
|
|
ut_print_timestamp(stderr);
|
2006-08-29 11:30:31 +02:00
|
|
|
fputs(" InnoDB: Unable to assign a new identifier to table ",
|
|
|
|
stderr);
|
2006-06-13 22:23:26 +02:00
|
|
|
ut_print_name(stderr, trx, TRUE, table->name);
|
2005-10-27 09:29:40 +02:00
|
|
|
fputs("\n"
|
2006-08-29 11:30:31 +02:00
|
|
|
"InnoDB: after truncating it. Background processes"
|
|
|
|
" may corrupt the table!\n", stderr);
|
2005-10-27 09:29:40 +02:00
|
|
|
err = DB_ERROR;
|
|
|
|
} else {
|
|
|
|
dict_table_change_id_in_cache(table, new_id);
|
|
|
|
}
|
|
|
|
|
2007-08-01 13:18:43 +02:00
|
|
|
/* MySQL calls ha_innobase::reset_auto_increment() which does
|
|
|
|
the same thing. */
|
2007-09-27 13:17:45 +02:00
|
|
|
dict_table_autoinc_lock(table);
|
2008-10-11 21:37:21 +02:00
|
|
|
dict_table_autoinc_initialize(table, 1);
|
2007-09-27 13:17:45 +02:00
|
|
|
dict_table_autoinc_unlock(table);
|
2005-10-27 09:29:40 +02:00
|
|
|
dict_update_statistics(table);
|
|
|
|
|
2006-02-23 20:25:29 +01:00
|
|
|
trx_commit_for_mysql(trx);
|
2005-10-27 09:29:40 +02:00
|
|
|
|
|
|
|
funct_exit:
|
|
|
|
|
|
|
|
row_mysql_unlock_data_dictionary(trx);
|
|
|
|
|
|
|
|
trx->op_info = "";
|
|
|
|
|
|
|
|
srv_wake_master_thread();
|
|
|
|
|
|
|
|
return((int) err);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
2008-10-11 21:37:21 +02:00
|
|
|
Drops a table for MySQL. If the name of the dropped table ends in
|
2007-08-30 11:21:25 +02:00
|
|
|
one of "innodb_monitor", "innodb_lock_monitor", "innodb_tablespace_monitor",
|
|
|
|
"innodb_table_monitor", then this will also stop the printing of monitor
|
2008-10-11 21:37:21 +02:00
|
|
|
output by the master thread. If the data dictionary was not already locked
|
|
|
|
by the transaction, the transaction will be committed. Otherwise, the
|
|
|
|
data dictionary will remain locked. */
|
2008-02-06 15:17:36 +01:00
|
|
|
UNIV_INTERN
|
2005-10-27 09:29:40 +02:00
|
|
|
int
|
|
|
|
row_drop_table_for_mysql(
|
|
|
|
/*=====================*/
|
|
|
|
/* out: error code or DB_SUCCESS */
|
|
|
|
const char* name, /* in: table name */
|
|
|
|
trx_t* trx, /* in: transaction handle */
|
|
|
|
ibool drop_db)/* in: TRUE=dropping whole database */
|
|
|
|
{
|
|
|
|
dict_foreign_t* foreign;
|
|
|
|
dict_table_t* table;
|
|
|
|
ulint space_id;
|
|
|
|
ulint err;
|
|
|
|
const char* table_name;
|
|
|
|
ulint namelen;
|
|
|
|
ibool locked_dictionary = FALSE;
|
2006-05-08 08:18:59 +02:00
|
|
|
pars_info_t* info = NULL;
|
2005-10-27 09:29:40 +02:00
|
|
|
|
|
|
|
ut_a(name != NULL);
|
|
|
|
|
|
|
|
if (srv_created_new_raw) {
|
2007-09-03 10:44:39 +02:00
|
|
|
fputs("InnoDB: A new raw disk partition was initialized:\n"
|
|
|
|
"InnoDB: we do not allow database modifications"
|
|
|
|
" by the user.\n"
|
|
|
|
"InnoDB: Shut down mysqld and edit my.cnf so that newraw"
|
|
|
|
" is replaced with raw.\n", stderr);
|
2005-10-27 09:29:40 +02:00
|
|
|
|
|
|
|
return(DB_ERROR);
|
|
|
|
}
|
|
|
|
|
|
|
|
trx->op_info = "dropping table";
|
|
|
|
|
|
|
|
trx_start_if_not_started(trx);
|
|
|
|
|
|
|
|
/* The table name is prefixed with the database name and a '/'.
|
|
|
|
Certain table names starting with 'innodb_' have their special
|
|
|
|
meaning regardless of the database name. Thus, we need to
|
|
|
|
ignore the database name prefix in the comparisons. */
|
|
|
|
table_name = strchr(name, '/');
|
|
|
|
ut_a(table_name);
|
|
|
|
table_name++;
|
|
|
|
namelen = strlen(table_name) + 1;
|
|
|
|
|
|
|
|
if (namelen == sizeof S_innodb_monitor
|
2006-08-29 11:30:31 +02:00
|
|
|
&& !memcmp(table_name, S_innodb_monitor,
|
|
|
|
sizeof S_innodb_monitor)) {
|
2005-10-27 09:29:40 +02:00
|
|
|
|
|
|
|
/* Table name equals "innodb_monitor":
|
|
|
|
stop monitor prints */
|
2006-02-23 20:25:29 +01:00
|
|
|
|
2005-10-27 09:29:40 +02:00
|
|
|
srv_print_innodb_monitor = FALSE;
|
|
|
|
srv_print_innodb_lock_monitor = FALSE;
|
|
|
|
} else if (namelen == sizeof S_innodb_lock_monitor
|
2006-08-29 11:30:31 +02:00
|
|
|
&& !memcmp(table_name, S_innodb_lock_monitor,
|
|
|
|
sizeof S_innodb_lock_monitor)) {
|
2005-10-27 09:29:40 +02:00
|
|
|
srv_print_innodb_monitor = FALSE;
|
|
|
|
srv_print_innodb_lock_monitor = FALSE;
|
|
|
|
} else if (namelen == sizeof S_innodb_tablespace_monitor
|
2006-08-29 11:30:31 +02:00
|
|
|
&& !memcmp(table_name, S_innodb_tablespace_monitor,
|
|
|
|
sizeof S_innodb_tablespace_monitor)) {
|
2005-10-27 09:29:40 +02:00
|
|
|
|
|
|
|
srv_print_innodb_tablespace_monitor = FALSE;
|
|
|
|
} else if (namelen == sizeof S_innodb_table_monitor
|
2006-08-29 11:30:31 +02:00
|
|
|
&& !memcmp(table_name, S_innodb_table_monitor,
|
|
|
|
sizeof S_innodb_table_monitor)) {
|
2005-10-27 09:29:40 +02:00
|
|
|
|
|
|
|
srv_print_innodb_table_monitor = FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Serialize data dictionary operations with dictionary mutex:
|
|
|
|
no deadlocks can occur then in these operations */
|
|
|
|
|
|
|
|
if (trx->dict_operation_lock_mode != RW_X_LATCH) {
|
|
|
|
/* Prevent foreign key checks etc. while we are dropping the
|
|
|
|
table */
|
|
|
|
|
|
|
|
row_mysql_lock_data_dictionary(trx);
|
|
|
|
|
|
|
|
locked_dictionary = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
ut_ad(mutex_own(&(dict_sys->mutex)));
|
2007-01-18 19:29:12 +01:00
|
|
|
#ifdef UNIV_SYNC_DEBUG
|
2005-10-27 09:29:40 +02:00
|
|
|
ut_ad(rw_lock_own(&dict_operation_lock, RW_LOCK_EX));
|
|
|
|
#endif /* UNIV_SYNC_DEBUG */
|
2006-02-23 20:25:29 +01:00
|
|
|
|
2005-10-27 09:29:40 +02:00
|
|
|
table = dict_table_get_low(name);
|
|
|
|
|
|
|
|
if (!table) {
|
|
|
|
err = DB_TABLE_NOT_FOUND;
|
2006-02-23 20:25:29 +01:00
|
|
|
ut_print_timestamp(stderr);
|
2005-10-27 09:29:40 +02:00
|
|
|
|
2006-02-27 10:33:26 +01:00
|
|
|
fputs(" InnoDB: Error: table ", stderr);
|
2006-06-13 22:23:26 +02:00
|
|
|
ut_print_name(stderr, trx, TRUE, name);
|
2005-10-27 09:29:40 +02:00
|
|
|
fputs(" does not exist in the InnoDB internal\n"
|
2006-08-29 11:30:31 +02:00
|
|
|
"InnoDB: data dictionary though MySQL is"
|
|
|
|
" trying to drop it.\n"
|
|
|
|
"InnoDB: Have you copied the .frm file"
|
|
|
|
" of the table to the\n"
|
|
|
|
"InnoDB: MySQL database directory"
|
|
|
|
" from another database?\n"
|
|
|
|
"InnoDB: You can look for further help from\n"
|
|
|
|
"InnoDB: http://dev.mysql.com/doc/refman/5.1/en/"
|
|
|
|
"innodb-troubleshooting.html\n",
|
|
|
|
stderr);
|
2005-10-27 09:29:40 +02:00
|
|
|
goto funct_exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check if the table is referenced by foreign key constraints from
|
|
|
|
some other table (not the table itself) */
|
|
|
|
|
|
|
|
foreign = UT_LIST_GET_FIRST(table->referenced_list);
|
2006-02-23 20:25:29 +01:00
|
|
|
|
2005-10-27 09:29:40 +02:00
|
|
|
while (foreign && foreign->foreign_table == table) {
|
2006-08-29 11:30:31 +02:00
|
|
|
check_next_foreign:
|
2005-10-27 09:29:40 +02:00
|
|
|
foreign = UT_LIST_GET_NEXT(referenced_list, foreign);
|
|
|
|
}
|
|
|
|
|
2006-08-29 11:30:31 +02:00
|
|
|
if (foreign && trx->check_foreigns
|
2006-09-19 12:14:07 +02:00
|
|
|
&& !(drop_db && dict_tables_have_same_db(
|
|
|
|
name, foreign->foreign_table_name))) {
|
2005-10-27 09:29:40 +02:00
|
|
|
FILE* ef = dict_foreign_err_file;
|
|
|
|
|
|
|
|
/* We only allow dropping a referenced table if
|
|
|
|
FOREIGN_KEY_CHECKS is set to 0 */
|
|
|
|
|
|
|
|
err = DB_CANNOT_DROP_CONSTRAINT;
|
|
|
|
|
|
|
|
mutex_enter(&dict_foreign_err_mutex);
|
|
|
|
rewind(ef);
|
|
|
|
ut_print_timestamp(ef);
|
|
|
|
|
2006-02-27 10:33:26 +01:00
|
|
|
fputs(" Cannot drop table ", ef);
|
2007-08-13 19:15:31 +02:00
|
|
|
ut_print_name(ef, trx, TRUE, name);
|
2005-10-27 09:29:40 +02:00
|
|
|
fputs("\n"
|
2006-08-29 11:30:31 +02:00
|
|
|
"because it is referenced by ", ef);
|
2007-08-13 19:15:31 +02:00
|
|
|
ut_print_name(ef, trx, TRUE, foreign->foreign_table_name);
|
2005-10-27 09:29:40 +02:00
|
|
|
putc('\n', ef);
|
|
|
|
mutex_exit(&dict_foreign_err_mutex);
|
|
|
|
|
|
|
|
goto funct_exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (foreign && trx->check_foreigns) {
|
|
|
|
goto check_next_foreign;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (table->n_mysql_handles_opened > 0) {
|
|
|
|
ibool added;
|
|
|
|
|
2007-09-11 07:09:19 +02:00
|
|
|
added = row_add_table_to_background_drop_list(table->name);
|
2005-10-27 09:29:40 +02:00
|
|
|
|
2006-02-23 20:25:29 +01:00
|
|
|
if (added) {
|
branches/zip: Fast index creation: Remove the ROW_PREBUILT_OBSOLETE nonsense.
Active transactions must not switch table or index definitions on the fly,
for several reasons, including the following:
* copied indexes do not carry any history or locking information;
that is, rollbacks, read views, and record locking would be broken
* huge potential for race conditions, inconsistent reads and writes,
loss of data, and corruption
Instead of trying to track down if the table was changed during a transaction,
acquire appropriate locks that protect the creation and dropping of indexes.
innodb-index.test: Test the locking of CREATE INDEX and DROP INDEX. Test
that consistent reads work across dropped indexes.
lock_rec_insert_check_and_lock(): Relax the lock_table_has() assertion.
When inserting a record into an index, the table must be at least IX-locked.
However, when an index is being created, an IS-lock on the table is
sufficient.
row_merge_lock_table(): Add the parameter enum lock_mode mode, which must
be LOCK_X or LOCK_S.
row_merge_drop_table(): Assert that n_mysql_handles_opened == 0.
Unconditionally drop the table.
ha_innobase::add_index(): Acquire an X or S lock on the table, as appropriate.
After acquiring an X lock, assert that n_mysql_handles_opened == 1.
Remove the comments about dropping tables in the background.
ha_innobase::final_drop_index(): Acquire an X lock on the table.
dict_table_t: Remove version_number, to_be_dropped, and prebuilts.
ins_node_t: Remove table_version_number.
enum lock_mode: Move the definition from lock0lock.h to lock0types.h.
ROW_PREBUILT_OBSOLETE, row_update_prebuilt(), row_prebuilt_table_obsolete():
Remove.
row_prebuilt_t: Remove the declaration from row0types.h.
row_drop_table_for_mysql_no_commit(): Always print a warning if a table
was added to the background drop queue.
2007-12-17 16:49:59 +01:00
|
|
|
ut_print_timestamp(stderr);
|
|
|
|
fputs(" InnoDB: Warning: MySQL is"
|
|
|
|
" trying to drop table ", stderr);
|
|
|
|
ut_print_name(stderr, trx, TRUE, table->name);
|
|
|
|
fputs("\n"
|
|
|
|
"InnoDB: though there are still"
|
|
|
|
" open handles to it.\n"
|
|
|
|
"InnoDB: Adding the table to the"
|
|
|
|
" background drop queue.\n",
|
|
|
|
stderr);
|
2006-02-23 20:25:29 +01:00
|
|
|
|
2005-10-27 09:29:40 +02:00
|
|
|
/* We return DB_SUCCESS to MySQL though the drop will
|
|
|
|
happen lazily later */
|
|
|
|
err = DB_SUCCESS;
|
|
|
|
} else {
|
|
|
|
/* The table is already in the background drop list */
|
|
|
|
err = DB_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
goto funct_exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* TODO: could we replace the counter n_foreign_key_checks_running
|
|
|
|
with lock checks on the table? Acquire here an exclusive lock on the
|
|
|
|
table, and rewrite lock0lock.c and the lock wait in srv0srv.c so that
|
|
|
|
they can cope with the table having been dropped here? Foreign key
|
|
|
|
checks take an IS or IX lock on the table. */
|
|
|
|
|
|
|
|
if (table->n_foreign_key_checks_running > 0) {
|
|
|
|
|
2007-09-11 07:09:19 +02:00
|
|
|
const char* table_name = table->name;
|
|
|
|
ibool added;
|
2005-10-27 09:29:40 +02:00
|
|
|
|
2007-09-11 07:09:19 +02:00
|
|
|
added = row_add_table_to_background_drop_list(table_name);
|
2005-10-27 09:29:40 +02:00
|
|
|
|
|
|
|
if (added) {
|
2006-02-23 20:25:29 +01:00
|
|
|
ut_print_timestamp(stderr);
|
2006-08-29 11:30:31 +02:00
|
|
|
fputs(" InnoDB: You are trying to drop table ",
|
|
|
|
stderr);
|
2007-09-11 07:09:19 +02:00
|
|
|
ut_print_name(stderr, trx, TRUE, table_name);
|
2005-10-27 09:29:40 +02:00
|
|
|
fputs("\n"
|
2006-08-29 11:30:31 +02:00
|
|
|
"InnoDB: though there is a"
|
|
|
|
" foreign key check running on it.\n"
|
|
|
|
"InnoDB: Adding the table to"
|
|
|
|
" the background drop queue.\n",
|
|
|
|
stderr);
|
2005-10-27 09:29:40 +02:00
|
|
|
|
|
|
|
/* We return DB_SUCCESS to MySQL though the drop will
|
|
|
|
happen lazily later */
|
|
|
|
|
|
|
|
err = DB_SUCCESS;
|
|
|
|
} else {
|
|
|
|
/* The table is already in the background drop list */
|
|
|
|
err = DB_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
goto funct_exit;
|
|
|
|
}
|
2006-02-23 20:25:29 +01:00
|
|
|
|
2008-10-11 21:37:21 +02:00
|
|
|
/* Remove all locks there are on the table or its records */
|
|
|
|
lock_remove_all_on_table(table, TRUE);
|
2005-10-27 09:29:40 +02:00
|
|
|
|
2007-10-19 12:52:25 +02:00
|
|
|
trx_set_dict_operation(trx, TRX_DICT_OP_TABLE);
|
2005-10-27 09:29:40 +02:00
|
|
|
trx->table_id = table->id;
|
|
|
|
|
2006-05-08 08:18:59 +02:00
|
|
|
/* We use the private SQL parser of Innobase to generate the
|
|
|
|
query graphs needed in deleting the dictionary data from system
|
|
|
|
tables in Innobase. Deleting a row from SYS_INDEXES table also
|
|
|
|
frees the file segments of the B-tree associated with the index. */
|
2005-10-27 09:29:40 +02:00
|
|
|
|
2006-05-08 08:18:59 +02:00
|
|
|
info = pars_info_create();
|
2005-10-27 09:29:40 +02:00
|
|
|
|
2006-05-08 08:18:59 +02:00
|
|
|
pars_info_add_str_literal(info, "table_name", name);
|
|
|
|
|
|
|
|
err = que_eval_sql(info,
|
2006-08-29 11:30:31 +02:00
|
|
|
"PROCEDURE DROP_TABLE_PROC () IS\n"
|
|
|
|
"sys_foreign_id CHAR;\n"
|
|
|
|
"table_id CHAR;\n"
|
|
|
|
"index_id CHAR;\n"
|
|
|
|
"foreign_id CHAR;\n"
|
|
|
|
"found INT;\n"
|
|
|
|
"BEGIN\n"
|
|
|
|
"SELECT ID INTO table_id\n"
|
|
|
|
"FROM SYS_TABLES\n"
|
|
|
|
"WHERE NAME = :table_name\n"
|
|
|
|
"LOCK IN SHARE MODE;\n"
|
|
|
|
"IF (SQL % NOTFOUND) THEN\n"
|
|
|
|
" RETURN;\n"
|
|
|
|
"END IF;\n"
|
|
|
|
"found := 1;\n"
|
|
|
|
"SELECT ID INTO sys_foreign_id\n"
|
|
|
|
"FROM SYS_TABLES\n"
|
|
|
|
"WHERE NAME = 'SYS_FOREIGN'\n"
|
|
|
|
"LOCK IN SHARE MODE;\n"
|
|
|
|
"IF (SQL % NOTFOUND) THEN\n"
|
|
|
|
" found := 0;\n"
|
|
|
|
"END IF;\n"
|
|
|
|
"IF (:table_name = 'SYS_FOREIGN') THEN\n"
|
|
|
|
" found := 0;\n"
|
|
|
|
"END IF;\n"
|
|
|
|
"IF (:table_name = 'SYS_FOREIGN_COLS') THEN\n"
|
|
|
|
" found := 0;\n"
|
|
|
|
"END IF;\n"
|
|
|
|
"WHILE found = 1 LOOP\n"
|
|
|
|
" SELECT ID INTO foreign_id\n"
|
|
|
|
" FROM SYS_FOREIGN\n"
|
|
|
|
" WHERE FOR_NAME = :table_name\n"
|
|
|
|
" AND TO_BINARY(FOR_NAME)\n"
|
|
|
|
" = TO_BINARY(:table_name)\n"
|
|
|
|
" LOCK IN SHARE MODE;\n"
|
|
|
|
" IF (SQL % NOTFOUND) THEN\n"
|
|
|
|
" found := 0;\n"
|
|
|
|
" ELSE\n"
|
|
|
|
" DELETE FROM SYS_FOREIGN_COLS\n"
|
|
|
|
" WHERE ID = foreign_id;\n"
|
|
|
|
" DELETE FROM SYS_FOREIGN\n"
|
|
|
|
" WHERE ID = foreign_id;\n"
|
|
|
|
" END IF;\n"
|
|
|
|
"END LOOP;\n"
|
|
|
|
"found := 1;\n"
|
|
|
|
"WHILE found = 1 LOOP\n"
|
|
|
|
" SELECT ID INTO index_id\n"
|
|
|
|
" FROM SYS_INDEXES\n"
|
|
|
|
" WHERE TABLE_ID = table_id\n"
|
|
|
|
" LOCK IN SHARE MODE;\n"
|
|
|
|
" IF (SQL % NOTFOUND) THEN\n"
|
|
|
|
" found := 0;\n"
|
|
|
|
" ELSE\n"
|
|
|
|
" DELETE FROM SYS_FIELDS\n"
|
|
|
|
" WHERE INDEX_ID = index_id;\n"
|
|
|
|
" DELETE FROM SYS_INDEXES\n"
|
|
|
|
" WHERE ID = index_id\n"
|
|
|
|
" AND TABLE_ID = table_id;\n"
|
|
|
|
" END IF;\n"
|
|
|
|
"END LOOP;\n"
|
|
|
|
"DELETE FROM SYS_COLUMNS\n"
|
|
|
|
"WHERE TABLE_ID = table_id;\n"
|
|
|
|
"DELETE FROM SYS_TABLES\n"
|
|
|
|
"WHERE ID = table_id;\n"
|
|
|
|
"END;\n"
|
|
|
|
, FALSE, trx);
|
2005-10-27 09:29:40 +02:00
|
|
|
|
|
|
|
if (err != DB_SUCCESS) {
|
|
|
|
ut_a(err == DB_OUT_OF_FILE_SPACE);
|
|
|
|
|
|
|
|
err = DB_MUST_GET_MORE_FILE_SPACE;
|
2006-02-23 20:25:29 +01:00
|
|
|
|
2006-05-08 08:18:59 +02:00
|
|
|
row_mysql_handle_errors(&err, trx, NULL, NULL);
|
2005-10-27 09:29:40 +02:00
|
|
|
|
|
|
|
ut_error;
|
|
|
|
} else {
|
|
|
|
ibool is_path;
|
|
|
|
const char* name_or_path;
|
2007-09-03 10:44:39 +02:00
|
|
|
mem_heap_t* heap;
|
2005-10-27 09:29:40 +02:00
|
|
|
|
2007-09-03 10:44:39 +02:00
|
|
|
heap = mem_heap_create(200);
|
|
|
|
|
|
|
|
/* Clone the name, in case it has been allocated
|
|
|
|
from table->heap, which will be freed by
|
|
|
|
dict_table_remove_from_cache(table) below. */
|
|
|
|
name = mem_heap_strdup(heap, name);
|
2005-10-27 09:29:40 +02:00
|
|
|
space_id = table->space;
|
2006-02-23 20:25:29 +01:00
|
|
|
|
2005-10-27 09:29:40 +02:00
|
|
|
if (table->dir_path_of_temp_table != NULL) {
|
|
|
|
is_path = TRUE;
|
2007-09-03 10:44:39 +02:00
|
|
|
name_or_path = mem_heap_strdup(
|
|
|
|
heap, table->dir_path_of_temp_table);
|
2005-10-27 09:29:40 +02:00
|
|
|
} else {
|
|
|
|
is_path = FALSE;
|
|
|
|
name_or_path = name;
|
|
|
|
}
|
|
|
|
|
|
|
|
dict_table_remove_from_cache(table);
|
|
|
|
|
|
|
|
if (dict_load_table(name) != NULL) {
|
|
|
|
ut_print_timestamp(stderr);
|
2006-02-27 10:33:26 +01:00
|
|
|
fputs(" InnoDB: Error: not able to remove table ",
|
2006-08-29 11:30:31 +02:00
|
|
|
stderr);
|
2006-06-13 22:23:26 +02:00
|
|
|
ut_print_name(stderr, trx, TRUE, name);
|
2005-10-27 09:29:40 +02:00
|
|
|
fputs(" from the dictionary cache!\n", stderr);
|
|
|
|
err = DB_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Do not drop possible .ibd tablespace if something went
|
|
|
|
wrong: we do not want to delete valuable data of the user */
|
|
|
|
|
|
|
|
if (err == DB_SUCCESS && space_id > 0) {
|
|
|
|
if (!fil_space_for_table_exists_in_mem(space_id,
|
2006-08-29 11:30:31 +02:00
|
|
|
name_or_path,
|
|
|
|
is_path,
|
|
|
|
FALSE, TRUE)) {
|
2005-10-27 09:29:40 +02:00
|
|
|
err = DB_SUCCESS;
|
|
|
|
|
|
|
|
fprintf(stderr,
|
2006-08-29 11:30:31 +02:00
|
|
|
"InnoDB: We removed now the InnoDB"
|
|
|
|
" internal data dictionary entry\n"
|
|
|
|
"InnoDB: of table ");
|
2006-06-13 22:23:26 +02:00
|
|
|
ut_print_name(stderr, trx, TRUE, name);
|
2005-10-27 09:29:40 +02:00
|
|
|
fprintf(stderr, ".\n");
|
2007-09-03 10:44:39 +02:00
|
|
|
} else if (!fil_delete_tablespace(space_id)) {
|
2005-10-27 09:29:40 +02:00
|
|
|
fprintf(stderr,
|
2006-08-29 11:30:31 +02:00
|
|
|
"InnoDB: We removed now the InnoDB"
|
|
|
|
" internal data dictionary entry\n"
|
|
|
|
"InnoDB: of table ");
|
2006-06-13 22:23:26 +02:00
|
|
|
ut_print_name(stderr, trx, TRUE, name);
|
2005-10-27 09:29:40 +02:00
|
|
|
fprintf(stderr, ".\n");
|
|
|
|
|
|
|
|
ut_print_timestamp(stderr);
|
|
|
|
fprintf(stderr,
|
2006-08-29 11:30:31 +02:00
|
|
|
" InnoDB: Error: not able to"
|
|
|
|
" delete tablespace %lu of table ",
|
2005-10-27 09:29:40 +02:00
|
|
|
(ulong) space_id);
|
2006-06-13 22:23:26 +02:00
|
|
|
ut_print_name(stderr, trx, TRUE, name);
|
2005-10-27 09:29:40 +02:00
|
|
|
fputs("!\n", stderr);
|
|
|
|
err = DB_ERROR;
|
|
|
|
}
|
|
|
|
}
|
2007-09-03 10:44:39 +02:00
|
|
|
|
|
|
|
mem_heap_free(heap);
|
2005-10-27 09:29:40 +02:00
|
|
|
}
|
|
|
|
funct_exit:
|
|
|
|
|
|
|
|
if (locked_dictionary) {
|
2008-10-11 21:37:21 +02:00
|
|
|
trx_commit_for_mysql(trx);
|
|
|
|
|
2006-02-23 20:25:29 +01:00
|
|
|
row_mysql_unlock_data_dictionary(trx);
|
2005-10-27 09:29:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
trx->op_info = "";
|
|
|
|
|
|
|
|
#ifndef UNIV_HOTBACKUP
|
|
|
|
srv_wake_master_thread();
|
|
|
|
#endif /* !UNIV_HOTBACKUP */
|
|
|
|
|
|
|
|
return((int) err);
|
|
|
|
}
|
|
|
|
|
2008-01-07 10:15:25 +01:00
|
|
|
/***********************************************************************
|
|
|
|
Drop all foreign keys in a database, see Bug#18942.
|
|
|
|
Called at the end of row_drop_database_for_mysql(). */
|
|
|
|
static
|
|
|
|
ulint
|
|
|
|
drop_all_foreign_keys_in_db(
|
|
|
|
/*========================*/
|
|
|
|
/* out: error code or DB_SUCCESS */
|
|
|
|
const char* name, /* in: database name which ends to '/' */
|
|
|
|
trx_t* trx) /* in: transaction handle */
|
|
|
|
{
|
|
|
|
pars_info_t* pinfo;
|
|
|
|
ulint err;
|
|
|
|
|
|
|
|
ut_a(name[strlen(name) - 1] == '/');
|
|
|
|
|
|
|
|
pinfo = pars_info_create();
|
|
|
|
|
|
|
|
pars_info_add_str_literal(pinfo, "dbname", name);
|
|
|
|
|
|
|
|
/* true if for_name is not prefixed with dbname */
|
|
|
|
#define TABLE_NOT_IN_THIS_DB \
|
|
|
|
"SUBSTR(for_name, 0, LENGTH(:dbname)) <> :dbname"
|
|
|
|
|
|
|
|
err = que_eval_sql(pinfo,
|
|
|
|
"PROCEDURE DROP_ALL_FOREIGN_KEYS_PROC () IS\n"
|
|
|
|
"foreign_id CHAR;\n"
|
|
|
|
"for_name CHAR;\n"
|
|
|
|
"found INT;\n"
|
|
|
|
"DECLARE CURSOR cur IS\n"
|
|
|
|
"SELECT ID, FOR_NAME FROM SYS_FOREIGN\n"
|
|
|
|
"WHERE FOR_NAME >= :dbname\n"
|
|
|
|
"LOCK IN SHARE MODE\n"
|
|
|
|
"ORDER BY FOR_NAME;\n"
|
|
|
|
"BEGIN\n"
|
|
|
|
"found := 1;\n"
|
|
|
|
"OPEN cur;\n"
|
|
|
|
"WHILE found = 1 LOOP\n"
|
|
|
|
" FETCH cur INTO foreign_id, for_name;\n"
|
|
|
|
" IF (SQL % NOTFOUND) THEN\n"
|
|
|
|
" found := 0;\n"
|
|
|
|
" ELSIF (" TABLE_NOT_IN_THIS_DB ") THEN\n"
|
|
|
|
" found := 0;\n"
|
|
|
|
" ELSIF (1=1) THEN\n"
|
|
|
|
" DELETE FROM SYS_FOREIGN_COLS\n"
|
|
|
|
" WHERE ID = foreign_id;\n"
|
|
|
|
" DELETE FROM SYS_FOREIGN\n"
|
|
|
|
" WHERE ID = foreign_id;\n"
|
|
|
|
" END IF;\n"
|
|
|
|
"END LOOP;\n"
|
|
|
|
"CLOSE cur;\n"
|
|
|
|
"COMMIT WORK;\n"
|
|
|
|
"END;\n",
|
|
|
|
FALSE, /* do not reserve dict mutex,
|
|
|
|
we are already holding it */
|
|
|
|
trx);
|
|
|
|
|
|
|
|
return(err);
|
|
|
|
}
|
|
|
|
|
2005-10-27 09:29:40 +02:00
|
|
|
/*************************************************************************
|
|
|
|
Drops a database for MySQL. */
|
2008-02-06 15:17:36 +01:00
|
|
|
UNIV_INTERN
|
2005-10-27 09:29:40 +02:00
|
|
|
int
|
|
|
|
row_drop_database_for_mysql(
|
|
|
|
/*========================*/
|
|
|
|
/* out: error code or DB_SUCCESS */
|
|
|
|
const char* name, /* in: database name which ends to '/' */
|
|
|
|
trx_t* trx) /* in: transaction handle */
|
|
|
|
{
|
2006-02-23 20:25:29 +01:00
|
|
|
dict_table_t* table;
|
2005-10-27 09:29:40 +02:00
|
|
|
char* table_name;
|
|
|
|
int err = DB_SUCCESS;
|
|
|
|
ulint namelen = strlen(name);
|
2006-02-23 20:25:29 +01:00
|
|
|
|
2005-10-27 09:29:40 +02:00
|
|
|
ut_ad(trx->mysql_thread_id == os_thread_get_curr_id());
|
|
|
|
ut_a(name != NULL);
|
|
|
|
ut_a(name[namelen - 1] == '/');
|
2006-02-23 20:25:29 +01:00
|
|
|
|
2005-10-27 09:29:40 +02:00
|
|
|
trx->op_info = "dropping database";
|
2006-02-23 20:25:29 +01:00
|
|
|
|
2005-10-27 09:29:40 +02:00
|
|
|
trx_start_if_not_started(trx);
|
|
|
|
loop:
|
|
|
|
row_mysql_lock_data_dictionary(trx);
|
|
|
|
|
|
|
|
while ((table_name = dict_get_first_table_name_in_db(name))) {
|
|
|
|
ut_a(memcmp(table_name, name, namelen) == 0);
|
|
|
|
|
|
|
|
table = dict_table_get_low(table_name);
|
|
|
|
|
|
|
|
ut_a(table);
|
|
|
|
|
|
|
|
/* Wait until MySQL does not have any queries running on
|
|
|
|
the table */
|
|
|
|
|
|
|
|
if (table->n_mysql_handles_opened > 0) {
|
|
|
|
row_mysql_unlock_data_dictionary(trx);
|
|
|
|
|
|
|
|
ut_print_timestamp(stderr);
|
2006-08-29 11:30:31 +02:00
|
|
|
fputs(" InnoDB: Warning: MySQL is trying to"
|
|
|
|
" drop database ", stderr);
|
2006-06-13 22:23:26 +02:00
|
|
|
ut_print_name(stderr, trx, TRUE, name);
|
2005-10-27 09:29:40 +02:00
|
|
|
fputs("\n"
|
2006-08-29 11:30:31 +02:00
|
|
|
"InnoDB: though there are still"
|
|
|
|
" open handles to table ", stderr);
|
2006-06-13 22:23:26 +02:00
|
|
|
ut_print_name(stderr, trx, TRUE, table_name);
|
2005-10-27 09:29:40 +02:00
|
|
|
fputs(".\n", stderr);
|
|
|
|
|
2006-02-23 20:25:29 +01:00
|
|
|
os_thread_sleep(1000000);
|
2005-10-27 09:29:40 +02:00
|
|
|
|
2006-02-23 20:25:29 +01:00
|
|
|
mem_free(table_name);
|
2005-10-27 09:29:40 +02:00
|
|
|
|
2006-02-23 20:25:29 +01:00
|
|
|
goto loop;
|
2005-10-27 09:29:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
err = row_drop_table_for_mysql(table_name, trx, TRUE);
|
2008-10-11 21:37:21 +02:00
|
|
|
trx_commit_for_mysql(trx);
|
2005-10-27 09:29:40 +02:00
|
|
|
|
|
|
|
if (err != DB_SUCCESS) {
|
|
|
|
fputs("InnoDB: DROP DATABASE ", stderr);
|
2006-06-13 22:23:26 +02:00
|
|
|
ut_print_name(stderr, trx, TRUE, name);
|
2005-10-27 09:29:40 +02:00
|
|
|
fprintf(stderr, " failed with error %lu for table ",
|
|
|
|
(ulint) err);
|
2006-06-13 22:23:26 +02:00
|
|
|
ut_print_name(stderr, trx, TRUE, table_name);
|
2005-10-27 09:29:40 +02:00
|
|
|
putc('\n', stderr);
|
2008-10-11 21:37:21 +02:00
|
|
|
mem_free(table_name);
|
2005-10-27 09:29:40 +02:00
|
|
|
break;
|
|
|
|
}
|
2008-10-11 21:37:21 +02:00
|
|
|
|
|
|
|
mem_free(table_name);
|
2005-10-27 09:29:40 +02:00
|
|
|
}
|
|
|
|
|
2008-01-07 10:15:25 +01:00
|
|
|
if (err == DB_SUCCESS) {
|
|
|
|
/* after dropping all tables try to drop all leftover
|
|
|
|
foreign keys in case orphaned ones exist */
|
|
|
|
err = (int) drop_all_foreign_keys_in_db(name, trx);
|
|
|
|
|
|
|
|
if (err != DB_SUCCESS) {
|
|
|
|
fputs("InnoDB: DROP DATABASE ", stderr);
|
|
|
|
ut_print_name(stderr, trx, TRUE, name);
|
|
|
|
fprintf(stderr, " failed with error %d while "
|
|
|
|
"dropping all foreign keys", err);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-10-27 09:29:40 +02:00
|
|
|
trx_commit_for_mysql(trx);
|
|
|
|
|
2006-05-22 11:30:34 +02:00
|
|
|
row_mysql_unlock_data_dictionary(trx);
|
|
|
|
|
2005-10-27 09:29:40 +02:00
|
|
|
trx->op_info = "";
|
|
|
|
|
|
|
|
return(err);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
|
|
|
Checks if a table name contains the string "/#sql" which denotes temporary
|
|
|
|
tables in MySQL. */
|
|
|
|
static
|
|
|
|
ibool
|
|
|
|
row_is_mysql_tmp_table_name(
|
|
|
|
/*========================*/
|
|
|
|
/* out: TRUE if temporary table */
|
|
|
|
const char* name) /* in: table name in the form
|
|
|
|
'database/tablename' */
|
|
|
|
{
|
2006-08-15 13:55:06 +02:00
|
|
|
return(strstr(name, "/#sql") != NULL);
|
|
|
|
/* return(strstr(name, "/@0023sql") != NULL); */
|
2005-10-27 09:29:40 +02:00
|
|
|
}
|
|
|
|
|
2006-05-08 08:18:59 +02:00
|
|
|
/********************************************************************
|
|
|
|
Delete a single constraint. */
|
|
|
|
static
|
|
|
|
int
|
|
|
|
row_delete_constraint_low(
|
|
|
|
/*======================*/
|
|
|
|
/* out: error code or DB_SUCCESS */
|
|
|
|
const char* id, /* in: constraint id */
|
|
|
|
trx_t* trx) /* in: transaction handle */
|
|
|
|
{
|
|
|
|
pars_info_t* info = pars_info_create();
|
|
|
|
|
|
|
|
pars_info_add_str_literal(info, "id", id);
|
|
|
|
|
2007-04-02 07:39:41 +02:00
|
|
|
return((int) que_eval_sql(info,
|
2006-08-29 11:30:31 +02:00
|
|
|
"PROCEDURE DELETE_CONSTRAINT () IS\n"
|
|
|
|
"BEGIN\n"
|
|
|
|
"DELETE FROM SYS_FOREIGN_COLS WHERE ID = :id;\n"
|
|
|
|
"DELETE FROM SYS_FOREIGN WHERE ID = :id;\n"
|
|
|
|
"END;\n"
|
|
|
|
, FALSE, trx));
|
2006-05-08 08:18:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/********************************************************************
|
|
|
|
Delete a single constraint. */
|
|
|
|
static
|
|
|
|
int
|
|
|
|
row_delete_constraint(
|
|
|
|
/*==================*/
|
|
|
|
/* out: error code or DB_SUCCESS */
|
|
|
|
const char* id, /* in: constraint id */
|
|
|
|
const char* database_name, /* in: database name, with the
|
|
|
|
trailing '/' */
|
|
|
|
mem_heap_t* heap, /* in: memory heap */
|
|
|
|
trx_t* trx) /* in: transaction handle */
|
|
|
|
{
|
|
|
|
ulint err;
|
|
|
|
|
|
|
|
/* New format constraints have ids <databasename>/<constraintname>. */
|
2006-09-19 12:14:07 +02:00
|
|
|
err = row_delete_constraint_low(
|
|
|
|
mem_heap_strcat(heap, database_name, id), trx);
|
2006-05-08 08:18:59 +02:00
|
|
|
|
|
|
|
if ((err == DB_SUCCESS) && !strchr(id, '/')) {
|
|
|
|
/* Old format < 4.0.18 constraints have constraint ids
|
|
|
|
<number>_<number>. We only try deleting them if the
|
|
|
|
constraint name does not contain a '/' character, otherwise
|
|
|
|
deleting a new format constraint named 'foo/bar' from
|
|
|
|
database 'baz' would remove constraint 'bar' from database
|
|
|
|
'foo', if it existed. */
|
|
|
|
|
|
|
|
err = row_delete_constraint_low(id, trx);
|
|
|
|
}
|
|
|
|
|
2007-04-02 07:39:41 +02:00
|
|
|
return((int) err);
|
2006-05-08 08:18:59 +02:00
|
|
|
}
|
|
|
|
|
2005-10-27 09:29:40 +02:00
|
|
|
/*************************************************************************
|
|
|
|
Renames a table for MySQL. */
|
2008-02-06 15:17:36 +01:00
|
|
|
UNIV_INTERN
|
2007-08-13 14:46:13 +02:00
|
|
|
ulint
|
2005-10-27 09:29:40 +02:00
|
|
|
row_rename_table_for_mysql(
|
|
|
|
/*=======================*/
|
|
|
|
/* out: error code or DB_SUCCESS */
|
|
|
|
const char* old_name, /* in: old table name */
|
|
|
|
const char* new_name, /* in: new table name */
|
2007-04-04 13:05:33 +02:00
|
|
|
trx_t* trx, /* in: transaction handle */
|
|
|
|
ibool commit) /* in: if TRUE then commit trx */
|
2005-10-27 09:29:40 +02:00
|
|
|
{
|
|
|
|
dict_table_t* table;
|
2007-08-13 14:46:13 +02:00
|
|
|
ulint err = DB_ERROR;
|
2005-10-27 09:29:40 +02:00
|
|
|
mem_heap_t* heap = NULL;
|
|
|
|
const char** constraints_to_drop = NULL;
|
|
|
|
ulint n_constraints_to_drop = 0;
|
2005-11-29 13:30:46 +01:00
|
|
|
ibool old_is_tmp, new_is_tmp;
|
2006-05-08 08:18:59 +02:00
|
|
|
pars_info_t* info = NULL;
|
2005-10-27 09:29:40 +02:00
|
|
|
|
|
|
|
ut_ad(trx->mysql_thread_id == os_thread_get_curr_id());
|
|
|
|
ut_a(old_name != NULL);
|
|
|
|
ut_a(new_name != NULL);
|
|
|
|
|
|
|
|
if (srv_created_new_raw || srv_force_recovery) {
|
2006-08-29 11:30:31 +02:00
|
|
|
fputs("InnoDB: A new raw disk partition was initialized or\n"
|
|
|
|
"InnoDB: innodb_force_recovery is on: we do not allow\n"
|
|
|
|
"InnoDB: database modifications by the user. Shut down\n"
|
|
|
|
"InnoDB: mysqld and edit my.cnf so that newraw"
|
|
|
|
" is replaced\n"
|
|
|
|
"InnoDB: with raw, and innodb_force_... is removed.\n",
|
|
|
|
stderr);
|
2005-10-27 09:29:40 +02:00
|
|
|
|
2007-08-13 14:46:13 +02:00
|
|
|
goto funct_exit;
|
2007-04-04 13:05:33 +02:00
|
|
|
} else if (row_mysql_is_system_table(new_name)) {
|
2006-02-23 20:25:29 +01:00
|
|
|
|
2005-10-27 09:29:40 +02:00
|
|
|
fprintf(stderr,
|
2006-08-29 11:30:31 +02:00
|
|
|
"InnoDB: Error: trying to create a MySQL"
|
|
|
|
" system table %s of type InnoDB.\n"
|
|
|
|
"InnoDB: MySQL system tables must be"
|
|
|
|
" of the MyISAM type!\n",
|
|
|
|
new_name);
|
2005-10-27 09:29:40 +02:00
|
|
|
|
2007-08-13 14:46:13 +02:00
|
|
|
goto funct_exit;
|
2005-10-27 09:29:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
trx->op_info = "renaming table";
|
|
|
|
trx_start_if_not_started(trx);
|
|
|
|
|
2005-11-29 13:30:46 +01:00
|
|
|
old_is_tmp = row_is_mysql_tmp_table_name(old_name);
|
|
|
|
new_is_tmp = row_is_mysql_tmp_table_name(new_name);
|
2006-02-23 20:25:29 +01:00
|
|
|
|
2005-10-27 09:29:40 +02:00
|
|
|
table = dict_table_get_low(old_name);
|
|
|
|
|
|
|
|
if (!table) {
|
|
|
|
err = DB_TABLE_NOT_FOUND;
|
2006-02-23 20:25:29 +01:00
|
|
|
ut_print_timestamp(stderr);
|
2005-10-27 09:29:40 +02:00
|
|
|
|
2006-02-27 10:33:26 +01:00
|
|
|
fputs(" InnoDB: Error: table ", stderr);
|
2006-06-13 22:23:26 +02:00
|
|
|
ut_print_name(stderr, trx, TRUE, old_name);
|
2006-02-23 20:25:29 +01:00
|
|
|
fputs(" does not exist in the InnoDB internal\n"
|
2006-08-29 11:30:31 +02:00
|
|
|
"InnoDB: data dictionary though MySQL is"
|
|
|
|
" trying to rename the table.\n"
|
|
|
|
"InnoDB: Have you copied the .frm file"
|
|
|
|
" of the table to the\n"
|
|
|
|
"InnoDB: MySQL database directory"
|
|
|
|
" from another database?\n"
|
|
|
|
"InnoDB: You can look for further help from\n"
|
|
|
|
"InnoDB: http://dev.mysql.com/doc/refman/5.1/en/"
|
|
|
|
"innodb-troubleshooting.html\n",
|
|
|
|
stderr);
|
2005-10-27 09:29:40 +02:00
|
|
|
goto funct_exit;
|
2007-04-04 13:05:33 +02:00
|
|
|
} else if (table->ibd_file_missing) {
|
2005-10-27 09:29:40 +02:00
|
|
|
err = DB_TABLE_NOT_FOUND;
|
2006-02-23 20:25:29 +01:00
|
|
|
ut_print_timestamp(stderr);
|
2005-10-27 09:29:40 +02:00
|
|
|
|
2006-02-27 10:33:26 +01:00
|
|
|
fputs(" InnoDB: Error: table ", stderr);
|
2006-06-13 22:23:26 +02:00
|
|
|
ut_print_name(stderr, trx, TRUE, old_name);
|
2006-08-29 11:30:31 +02:00
|
|
|
fputs(" does not have an .ibd file"
|
|
|
|
" in the database directory.\n"
|
|
|
|
"InnoDB: You can look for further help from\n"
|
|
|
|
"InnoDB: http://dev.mysql.com/doc/refman/5.1/en/"
|
|
|
|
"innodb-troubleshooting.html\n",
|
|
|
|
stderr);
|
2005-10-27 09:29:40 +02:00
|
|
|
goto funct_exit;
|
2007-04-04 13:05:33 +02:00
|
|
|
} else if (new_is_tmp) {
|
2005-10-27 09:29:40 +02:00
|
|
|
/* MySQL is doing an ALTER TABLE command and it renames the
|
|
|
|
original table to a temporary table name. We want to preserve
|
|
|
|
the original foreign key constraint definitions despite the
|
|
|
|
name change. An exception is those constraints for which
|
|
|
|
the ALTER TABLE contained DROP FOREIGN KEY <foreign key id>.*/
|
|
|
|
|
|
|
|
heap = mem_heap_create(100);
|
2006-02-23 20:25:29 +01:00
|
|
|
|
2006-09-19 12:14:07 +02:00
|
|
|
err = dict_foreign_parse_drop_constraints(
|
|
|
|
heap, trx, table, &n_constraints_to_drop,
|
|
|
|
&constraints_to_drop);
|
2006-05-08 08:18:59 +02:00
|
|
|
|
2005-10-27 09:29:40 +02:00
|
|
|
if (err != DB_SUCCESS) {
|
|
|
|
|
|
|
|
goto funct_exit;
|
|
|
|
}
|
2006-05-08 08:18:59 +02:00
|
|
|
}
|
2006-02-23 20:25:29 +01:00
|
|
|
|
2006-05-08 08:18:59 +02:00
|
|
|
/* We use the private SQL parser of Innobase to generate the query
|
2007-08-20 11:45:27 +02:00
|
|
|
graphs needed in updating the dictionary data from system tables. */
|
2005-10-27 09:29:40 +02:00
|
|
|
|
2006-05-08 08:18:59 +02:00
|
|
|
info = pars_info_create();
|
2005-10-27 09:29:40 +02:00
|
|
|
|
2006-05-08 08:18:59 +02:00
|
|
|
pars_info_add_str_literal(info, "new_table_name", new_name);
|
|
|
|
pars_info_add_str_literal(info, "old_table_name", old_name);
|
2005-10-27 09:29:40 +02:00
|
|
|
|
2006-05-08 08:18:59 +02:00
|
|
|
err = que_eval_sql(info,
|
2006-08-29 11:30:31 +02:00
|
|
|
"PROCEDURE RENAME_TABLE () IS\n"
|
|
|
|
"BEGIN\n"
|
|
|
|
"UPDATE SYS_TABLES SET NAME = :new_table_name\n"
|
|
|
|
" WHERE NAME = :old_table_name;\n"
|
|
|
|
"END;\n"
|
|
|
|
, FALSE, trx);
|
2005-10-27 09:29:40 +02:00
|
|
|
|
2006-05-08 08:18:59 +02:00
|
|
|
if (err != DB_SUCCESS) {
|
2005-10-27 09:29:40 +02:00
|
|
|
|
2006-05-08 08:18:59 +02:00
|
|
|
goto end;
|
2007-04-04 13:05:33 +02:00
|
|
|
} else if (!new_is_tmp) {
|
2006-05-08 08:18:59 +02:00
|
|
|
/* Rename all constraints. */
|
2006-02-23 20:25:29 +01:00
|
|
|
|
2006-05-08 08:18:59 +02:00
|
|
|
info = pars_info_create();
|
2005-10-27 09:29:40 +02:00
|
|
|
|
2006-05-08 08:18:59 +02:00
|
|
|
pars_info_add_str_literal(info, "new_table_name", new_name);
|
|
|
|
pars_info_add_str_literal(info, "old_table_name", old_name);
|
2005-10-27 09:29:40 +02:00
|
|
|
|
2006-09-19 12:14:07 +02:00
|
|
|
err = que_eval_sql(
|
|
|
|
info,
|
|
|
|
"PROCEDURE RENAME_CONSTRAINT_IDS () IS\n"
|
|
|
|
"gen_constr_prefix CHAR;\n"
|
|
|
|
"new_db_name CHAR;\n"
|
|
|
|
"foreign_id CHAR;\n"
|
|
|
|
"new_foreign_id CHAR;\n"
|
|
|
|
"old_db_name_len INT;\n"
|
|
|
|
"old_t_name_len INT;\n"
|
|
|
|
"new_db_name_len INT;\n"
|
|
|
|
"id_len INT;\n"
|
|
|
|
"found INT;\n"
|
|
|
|
"BEGIN\n"
|
|
|
|
"found := 1;\n"
|
|
|
|
"old_db_name_len := INSTR(:old_table_name, '/')-1;\n"
|
|
|
|
"new_db_name_len := INSTR(:new_table_name, '/')-1;\n"
|
|
|
|
"new_db_name := SUBSTR(:new_table_name, 0,\n"
|
|
|
|
" new_db_name_len);\n"
|
|
|
|
"old_t_name_len := LENGTH(:old_table_name);\n"
|
|
|
|
"gen_constr_prefix := CONCAT(:old_table_name,\n"
|
|
|
|
" '_ibfk_');\n"
|
|
|
|
"WHILE found = 1 LOOP\n"
|
|
|
|
" SELECT ID INTO foreign_id\n"
|
|
|
|
" FROM SYS_FOREIGN\n"
|
|
|
|
" WHERE FOR_NAME = :old_table_name\n"
|
|
|
|
" AND TO_BINARY(FOR_NAME)\n"
|
|
|
|
" = TO_BINARY(:old_table_name)\n"
|
|
|
|
" LOCK IN SHARE MODE;\n"
|
|
|
|
" IF (SQL % NOTFOUND) THEN\n"
|
|
|
|
" found := 0;\n"
|
|
|
|
" ELSE\n"
|
|
|
|
" UPDATE SYS_FOREIGN\n"
|
|
|
|
" SET FOR_NAME = :new_table_name\n"
|
|
|
|
" WHERE ID = foreign_id;\n"
|
|
|
|
" id_len := LENGTH(foreign_id);\n"
|
|
|
|
" IF (INSTR(foreign_id, '/') > 0) THEN\n"
|
|
|
|
" IF (INSTR(foreign_id,\n"
|
|
|
|
" gen_constr_prefix) > 0)\n"
|
|
|
|
" THEN\n"
|
|
|
|
" new_foreign_id :=\n"
|
|
|
|
" CONCAT(:new_table_name,\n"
|
|
|
|
" SUBSTR(foreign_id, old_t_name_len,\n"
|
|
|
|
" id_len - old_t_name_len));\n"
|
|
|
|
" ELSE\n"
|
|
|
|
" new_foreign_id :=\n"
|
|
|
|
" CONCAT(new_db_name,\n"
|
|
|
|
" SUBSTR(foreign_id,\n"
|
|
|
|
" old_db_name_len,\n"
|
|
|
|
" id_len - old_db_name_len));\n"
|
|
|
|
" END IF;\n"
|
|
|
|
" UPDATE SYS_FOREIGN\n"
|
|
|
|
" SET ID = new_foreign_id\n"
|
|
|
|
" WHERE ID = foreign_id;\n"
|
|
|
|
" UPDATE SYS_FOREIGN_COLS\n"
|
|
|
|
" SET ID = new_foreign_id\n"
|
|
|
|
" WHERE ID = foreign_id;\n"
|
|
|
|
" END IF;\n"
|
|
|
|
" END IF;\n"
|
|
|
|
"END LOOP;\n"
|
|
|
|
"UPDATE SYS_FOREIGN SET REF_NAME = :new_table_name\n"
|
|
|
|
"WHERE REF_NAME = :old_table_name\n"
|
|
|
|
" AND TO_BINARY(REF_NAME)\n"
|
|
|
|
" = TO_BINARY(:old_table_name);\n"
|
|
|
|
"END;\n"
|
|
|
|
, FALSE, trx);
|
2005-10-27 09:29:40 +02:00
|
|
|
|
2006-05-08 08:18:59 +02:00
|
|
|
} else if (n_constraints_to_drop > 0) {
|
|
|
|
/* Drop some constraints of tmp tables. */
|
2005-10-27 09:29:40 +02:00
|
|
|
|
2006-05-08 08:18:59 +02:00
|
|
|
ulint db_name_len = dict_get_db_name_len(old_name) + 1;
|
|
|
|
char* db_name = mem_heap_strdupl(heap, old_name,
|
2006-08-29 11:30:31 +02:00
|
|
|
db_name_len);
|
2006-05-08 08:18:59 +02:00
|
|
|
ulint i;
|
2005-10-27 09:29:40 +02:00
|
|
|
|
2006-05-08 08:18:59 +02:00
|
|
|
for (i = 0; i < n_constraints_to_drop; i++) {
|
|
|
|
err = row_delete_constraint(constraints_to_drop[i],
|
2006-08-29 11:30:31 +02:00
|
|
|
db_name, heap, trx);
|
2005-10-27 09:29:40 +02:00
|
|
|
|
2006-05-08 08:18:59 +02:00
|
|
|
if (err != DB_SUCCESS) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2005-10-27 09:29:40 +02:00
|
|
|
|
2006-05-08 08:18:59 +02:00
|
|
|
end:
|
2005-10-27 09:29:40 +02:00
|
|
|
if (err != DB_SUCCESS) {
|
|
|
|
if (err == DB_DUPLICATE_KEY) {
|
2006-02-23 20:25:29 +01:00
|
|
|
ut_print_timestamp(stderr);
|
2006-08-29 11:30:31 +02:00
|
|
|
fputs(" InnoDB: Error; possible reasons:\n"
|
|
|
|
"InnoDB: 1) Table rename would cause"
|
|
|
|
" two FOREIGN KEY constraints\n"
|
|
|
|
"InnoDB: to have the same internal name"
|
|
|
|
" in case-insensitive comparison.\n"
|
|
|
|
"InnoDB: 2) table ", stderr);
|
|
|
|
ut_print_name(stderr, trx, TRUE, new_name);
|
|
|
|
fputs(" exists in the InnoDB internal data\n"
|
|
|
|
"InnoDB: dictionary though MySQL is"
|
|
|
|
" trying to rename table ", stderr);
|
|
|
|
ut_print_name(stderr, trx, TRUE, old_name);
|
|
|
|
fputs(" to it.\n"
|
|
|
|
"InnoDB: Have you deleted the .frm file"
|
|
|
|
" and not used DROP TABLE?\n"
|
|
|
|
"InnoDB: You can look for further help from\n"
|
|
|
|
"InnoDB: http://dev.mysql.com/doc/refman/5.1/en/"
|
|
|
|
"innodb-troubleshooting.html\n"
|
|
|
|
"InnoDB: If table ", stderr);
|
2006-06-13 22:23:26 +02:00
|
|
|
ut_print_name(stderr, trx, TRUE, new_name);
|
2006-08-29 11:30:31 +02:00
|
|
|
fputs(" is a temporary table #sql..., then"
|
|
|
|
" it can be that\n"
|
|
|
|
"InnoDB: there are still queries running"
|
|
|
|
" on the table, and it will be\n"
|
|
|
|
"InnoDB: dropped automatically when"
|
|
|
|
" the queries end.\n"
|
|
|
|
"InnoDB: You can drop the orphaned table"
|
|
|
|
" inside InnoDB by\n"
|
|
|
|
"InnoDB: creating an InnoDB table with"
|
|
|
|
" the same name in another\n"
|
|
|
|
"InnoDB: database and copying the .frm file"
|
|
|
|
" to the current database.\n"
|
|
|
|
"InnoDB: Then MySQL thinks the table exists,"
|
|
|
|
" and DROP TABLE will\n"
|
|
|
|
"InnoDB: succeed.\n", stderr);
|
2005-10-27 09:29:40 +02:00
|
|
|
}
|
|
|
|
trx->error_state = DB_SUCCESS;
|
|
|
|
trx_general_rollback_for_mysql(trx, FALSE, NULL);
|
|
|
|
trx->error_state = DB_SUCCESS;
|
|
|
|
} else {
|
|
|
|
/* The following call will also rename the .ibd data file if
|
|
|
|
the table is stored in a single-table tablespace */
|
|
|
|
|
2007-08-20 11:45:27 +02:00
|
|
|
if (!dict_table_rename_in_cache(table, new_name,
|
|
|
|
!new_is_tmp)) {
|
2005-10-27 09:29:40 +02:00
|
|
|
trx->error_state = DB_SUCCESS;
|
|
|
|
trx_general_rollback_for_mysql(trx, FALSE, NULL);
|
|
|
|
trx->error_state = DB_SUCCESS;
|
|
|
|
goto funct_exit;
|
|
|
|
}
|
|
|
|
|
2005-11-29 13:30:46 +01:00
|
|
|
/* We only want to switch off some of the type checking in
|
|
|
|
an ALTER, not in a RENAME. */
|
2006-02-23 20:25:29 +01:00
|
|
|
|
2006-09-19 12:14:07 +02:00
|
|
|
err = dict_load_foreigns(
|
2007-08-20 11:45:27 +02:00
|
|
|
new_name, !old_is_tmp || trx->check_foreigns);
|
2005-10-27 09:29:40 +02:00
|
|
|
|
2005-11-29 13:30:46 +01:00
|
|
|
if (err != DB_SUCCESS) {
|
|
|
|
ut_print_timestamp(stderr);
|
2005-10-27 09:29:40 +02:00
|
|
|
|
2005-11-29 13:30:46 +01:00
|
|
|
if (old_is_tmp) {
|
2006-02-27 10:33:26 +01:00
|
|
|
fputs(" InnoDB: Error: in ALTER TABLE ",
|
2006-08-29 11:30:31 +02:00
|
|
|
stderr);
|
2006-06-13 22:23:26 +02:00
|
|
|
ut_print_name(stderr, trx, TRUE, new_name);
|
2005-10-27 09:29:40 +02:00
|
|
|
fputs("\n"
|
2006-08-29 11:30:31 +02:00
|
|
|
"InnoDB: has or is referenced"
|
|
|
|
" in foreign key constraints\n"
|
|
|
|
"InnoDB: which are not compatible"
|
|
|
|
" with the new table definition.\n",
|
|
|
|
stderr);
|
2005-11-29 13:30:46 +01:00
|
|
|
} else {
|
2006-08-29 11:30:31 +02:00
|
|
|
fputs(" InnoDB: Error: in RENAME TABLE"
|
|
|
|
" table ",
|
|
|
|
stderr);
|
2006-06-13 22:23:26 +02:00
|
|
|
ut_print_name(stderr, trx, TRUE, new_name);
|
2005-10-27 09:29:40 +02:00
|
|
|
fputs("\n"
|
2006-08-29 11:30:31 +02:00
|
|
|
"InnoDB: is referenced in"
|
|
|
|
" foreign key constraints\n"
|
|
|
|
"InnoDB: which are not compatible"
|
|
|
|
" with the new table definition.\n",
|
|
|
|
stderr);
|
2005-10-27 09:29:40 +02:00
|
|
|
}
|
2005-11-29 13:30:46 +01:00
|
|
|
|
|
|
|
ut_a(dict_table_rename_in_cache(table,
|
2006-08-29 11:30:31 +02:00
|
|
|
old_name, FALSE));
|
2005-11-29 13:30:46 +01:00
|
|
|
trx->error_state = DB_SUCCESS;
|
2006-05-08 08:18:59 +02:00
|
|
|
trx_general_rollback_for_mysql(trx, FALSE, NULL);
|
2005-11-29 13:30:46 +01:00
|
|
|
trx->error_state = DB_SUCCESS;
|
2005-10-27 09:29:40 +02:00
|
|
|
}
|
|
|
|
}
|
2006-05-08 08:18:59 +02:00
|
|
|
|
2006-02-23 20:25:29 +01:00
|
|
|
funct_exit:
|
2007-04-04 13:05:33 +02:00
|
|
|
|
|
|
|
if (commit) {
|
|
|
|
trx_commit_for_mysql(trx);
|
|
|
|
}
|
2005-10-27 09:29:40 +02:00
|
|
|
|
|
|
|
if (UNIV_LIKELY_NULL(heap)) {
|
|
|
|
mem_heap_free(heap);
|
|
|
|
}
|
2006-02-23 20:25:29 +01:00
|
|
|
|
2005-10-27 09:29:40 +02:00
|
|
|
trx->op_info = "";
|
|
|
|
|
2007-08-13 14:46:13 +02:00
|
|
|
return(err);
|
2005-10-27 09:29:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
|
|
|
Checks that the index contains entries in an ascending order, unique
|
|
|
|
constraint is not broken, and calculates the number of index entries
|
|
|
|
in the read view of the current transaction. */
|
|
|
|
static
|
|
|
|
ibool
|
|
|
|
row_scan_and_check_index(
|
|
|
|
/*=====================*/
|
|
|
|
/* out: TRUE if ok */
|
|
|
|
row_prebuilt_t* prebuilt, /* in: prebuilt struct in MySQL */
|
|
|
|
dict_index_t* index, /* in: index */
|
|
|
|
ulint* n_rows) /* out: number of entries seen in the
|
|
|
|
current consistent read */
|
|
|
|
{
|
|
|
|
dtuple_t* prev_entry = NULL;
|
|
|
|
ulint matched_fields;
|
|
|
|
ulint matched_bytes;
|
|
|
|
byte* buf;
|
|
|
|
ulint ret;
|
|
|
|
rec_t* rec;
|
|
|
|
ibool is_ok = TRUE;
|
|
|
|
int cmp;
|
|
|
|
ibool contains_null;
|
|
|
|
ulint i;
|
|
|
|
ulint cnt;
|
|
|
|
mem_heap_t* heap = NULL;
|
2007-10-17 14:13:29 +02:00
|
|
|
ulint n_ext;
|
2005-10-27 09:29:40 +02:00
|
|
|
ulint offsets_[REC_OFFS_NORMAL_SIZE];
|
2007-10-17 14:13:29 +02:00
|
|
|
ulint* offsets;
|
2007-09-28 09:05:57 +02:00
|
|
|
rec_offs_init(offsets_);
|
2005-10-27 09:29:40 +02:00
|
|
|
|
|
|
|
*n_rows = 0;
|
2006-02-23 20:25:29 +01:00
|
|
|
|
2005-10-27 09:29:40 +02:00
|
|
|
buf = mem_alloc(UNIV_PAGE_SIZE);
|
|
|
|
heap = mem_heap_create(100);
|
2006-02-23 20:25:29 +01:00
|
|
|
|
2005-10-27 09:29:40 +02:00
|
|
|
/* Make a dummy template in prebuilt, which we will use
|
|
|
|
in scanning the index entries */
|
|
|
|
|
|
|
|
prebuilt->index = index;
|
|
|
|
prebuilt->sql_stat_start = TRUE;
|
|
|
|
prebuilt->template_type = ROW_MYSQL_DUMMY_TEMPLATE;
|
|
|
|
prebuilt->n_template = 0;
|
|
|
|
prebuilt->need_to_access_clustered = FALSE;
|
|
|
|
|
2006-02-23 20:25:29 +01:00
|
|
|
dtuple_set_n_fields(prebuilt->search_tuple, 0);
|
2005-10-27 09:29:40 +02:00
|
|
|
|
|
|
|
prebuilt->select_lock_type = LOCK_NONE;
|
|
|
|
cnt = 1000;
|
|
|
|
|
|
|
|
ret = row_search_for_mysql(buf, PAGE_CUR_G, prebuilt, 0, 0);
|
|
|
|
loop:
|
|
|
|
/* Check thd->killed every 1,000 scanned rows */
|
|
|
|
if (--cnt == 0) {
|
|
|
|
if (trx_is_interrupted(prebuilt->trx)) {
|
|
|
|
goto func_exit;
|
|
|
|
}
|
|
|
|
cnt = 1000;
|
|
|
|
}
|
|
|
|
if (ret != DB_SUCCESS) {
|
2006-08-29 11:30:31 +02:00
|
|
|
func_exit:
|
2005-10-27 09:29:40 +02:00
|
|
|
mem_free(buf);
|
|
|
|
mem_heap_free(heap);
|
|
|
|
|
|
|
|
return(is_ok);
|
|
|
|
}
|
|
|
|
|
|
|
|
*n_rows = *n_rows + 1;
|
2006-02-23 20:25:29 +01:00
|
|
|
|
2005-10-27 09:29:40 +02:00
|
|
|
/* row_search... returns the index record in buf, record origin offset
|
|
|
|
within buf stored in the first 4 bytes, because we have built a dummy
|
|
|
|
template */
|
2006-02-23 20:25:29 +01:00
|
|
|
|
2005-10-27 09:29:40 +02:00
|
|
|
rec = buf + mach_read_from_4(buf);
|
|
|
|
|
2007-10-17 14:13:29 +02:00
|
|
|
offsets = rec_get_offsets(rec, index, offsets_,
|
|
|
|
ULINT_UNDEFINED, &heap);
|
|
|
|
|
2005-10-27 09:29:40 +02:00
|
|
|
if (prev_entry != NULL) {
|
|
|
|
matched_fields = 0;
|
|
|
|
matched_bytes = 0;
|
|
|
|
|
|
|
|
cmp = cmp_dtuple_rec_with_match(prev_entry, rec, offsets,
|
|
|
|
&matched_fields,
|
|
|
|
&matched_bytes);
|
|
|
|
contains_null = FALSE;
|
|
|
|
|
|
|
|
/* In a unique secondary index we allow equal key values if
|
|
|
|
they contain SQL NULLs */
|
|
|
|
|
2006-02-23 20:25:29 +01:00
|
|
|
for (i = 0;
|
|
|
|
i < dict_index_get_n_ordering_defined_by_user(index);
|
2005-10-27 09:29:40 +02:00
|
|
|
i++) {
|
2006-09-19 12:14:07 +02:00
|
|
|
if (UNIV_SQL_NULL == dfield_get_len(
|
|
|
|
dtuple_get_nth_field(prev_entry, i))) {
|
2005-10-27 09:29:40 +02:00
|
|
|
|
2006-02-23 20:25:29 +01:00
|
|
|
contains_null = TRUE;
|
|
|
|
}
|
|
|
|
}
|
2005-10-27 09:29:40 +02:00
|
|
|
|
|
|
|
if (cmp > 0) {
|
|
|
|
fputs("InnoDB: index records in a wrong order in ",
|
2006-08-29 11:30:31 +02:00
|
|
|
stderr);
|
|
|
|
not_ok:
|
2005-10-27 09:29:40 +02:00
|
|
|
dict_index_name_print(stderr,
|
2006-08-29 11:30:31 +02:00
|
|
|
prebuilt->trx, index);
|
2005-10-27 09:29:40 +02:00
|
|
|
fputs("\n"
|
2006-08-29 11:30:31 +02:00
|
|
|
"InnoDB: prev record ", stderr);
|
2005-10-27 09:29:40 +02:00
|
|
|
dtuple_print(stderr, prev_entry);
|
|
|
|
fputs("\n"
|
2006-08-29 11:30:31 +02:00
|
|
|
"InnoDB: record ", stderr);
|
2005-10-27 09:29:40 +02:00
|
|
|
rec_print_new(stderr, rec, offsets);
|
|
|
|
putc('\n', stderr);
|
|
|
|
is_ok = FALSE;
|
2007-04-16 11:21:39 +02:00
|
|
|
} else if (dict_index_is_unique(index)
|
2005-10-27 09:29:40 +02:00
|
|
|
&& !contains_null
|
2006-08-29 11:30:31 +02:00
|
|
|
&& matched_fields
|
2006-09-19 12:14:07 +02:00
|
|
|
>= dict_index_get_n_ordering_defined_by_user(
|
|
|
|
index)) {
|
2005-10-27 09:29:40 +02:00
|
|
|
|
|
|
|
fputs("InnoDB: duplicate key in ", stderr);
|
|
|
|
goto not_ok;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-10-17 14:19:35 +02:00
|
|
|
{
|
|
|
|
mem_heap_t* tmp_heap = NULL;
|
2007-10-17 14:13:29 +02:00
|
|
|
|
2007-10-17 14:19:35 +02:00
|
|
|
/* Empty the heap on each round. But preserve offsets[]
|
|
|
|
for the row_rec_to_index_entry() call, by copying them
|
|
|
|
into a separate memory heap when needed. */
|
|
|
|
if (UNIV_UNLIKELY(offsets != offsets_)) {
|
|
|
|
ulint size = rec_offs_get_n_alloc(offsets)
|
|
|
|
* sizeof *offsets;
|
|
|
|
|
|
|
|
tmp_heap = mem_heap_create(size);
|
|
|
|
offsets = mem_heap_dup(tmp_heap, offsets, size);
|
|
|
|
}
|
2007-10-17 14:13:29 +02:00
|
|
|
|
2007-10-17 14:19:35 +02:00
|
|
|
mem_heap_empty(heap);
|
2006-02-23 20:25:29 +01:00
|
|
|
|
2007-10-17 14:19:35 +02:00
|
|
|
prev_entry = row_rec_to_index_entry(ROW_COPY_DATA, rec,
|
|
|
|
index, offsets,
|
|
|
|
&n_ext, heap);
|
2007-10-17 14:13:29 +02:00
|
|
|
|
2007-10-17 14:19:35 +02:00
|
|
|
if (UNIV_LIKELY_NULL(tmp_heap)) {
|
|
|
|
mem_heap_free(tmp_heap);
|
|
|
|
}
|
2007-10-17 14:13:29 +02:00
|
|
|
}
|
2005-10-27 09:29:40 +02:00
|
|
|
|
|
|
|
ret = row_search_for_mysql(buf, PAGE_CUR_G, prebuilt, 0, ROW_SEL_NEXT);
|
|
|
|
|
2006-02-23 20:25:29 +01:00
|
|
|
goto loop;
|
2005-10-27 09:29:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
|
|
|
Checks a table for corruption. */
|
2008-02-06 15:17:36 +01:00
|
|
|
UNIV_INTERN
|
2005-10-27 09:29:40 +02:00
|
|
|
ulint
|
|
|
|
row_check_table_for_mysql(
|
|
|
|
/*======================*/
|
|
|
|
/* out: DB_ERROR or DB_SUCCESS */
|
|
|
|
row_prebuilt_t* prebuilt) /* in: prebuilt struct in MySQL
|
|
|
|
handle */
|
|
|
|
{
|
|
|
|
dict_table_t* table = prebuilt->table;
|
|
|
|
dict_index_t* index;
|
|
|
|
ulint n_rows;
|
|
|
|
ulint n_rows_in_table = ULINT_UNDEFINED;
|
2006-02-23 20:25:29 +01:00
|
|
|
ulint ret = DB_SUCCESS;
|
2005-10-27 09:29:40 +02:00
|
|
|
ulint old_isolation_level;
|
|
|
|
|
2007-09-11 07:09:19 +02:00
|
|
|
if (table->ibd_file_missing) {
|
2006-02-23 20:25:29 +01:00
|
|
|
ut_print_timestamp(stderr);
|
|
|
|
fprintf(stderr, " InnoDB: Error:\n"
|
2006-08-29 11:30:31 +02:00
|
|
|
"InnoDB: MySQL is trying to use a table handle"
|
|
|
|
" but the .ibd file for\n"
|
|
|
|
"InnoDB: table %s does not exist.\n"
|
|
|
|
"InnoDB: Have you deleted the .ibd file"
|
|
|
|
" from the database directory under\n"
|
|
|
|
"InnoDB: the MySQL datadir, or have you"
|
|
|
|
" used DISCARD TABLESPACE?\n"
|
|
|
|
"InnoDB: Look from\n"
|
|
|
|
"InnoDB: http://dev.mysql.com/doc/refman/5.1/en/"
|
|
|
|
"innodb-troubleshooting.html\n"
|
|
|
|
"InnoDB: how you can resolve the problem.\n",
|
2007-09-11 07:09:19 +02:00
|
|
|
table->name);
|
2005-10-27 09:29:40 +02:00
|
|
|
return(DB_ERROR);
|
|
|
|
}
|
|
|
|
|
|
|
|
prebuilt->trx->op_info = "checking table";
|
|
|
|
|
|
|
|
old_isolation_level = prebuilt->trx->isolation_level;
|
|
|
|
|
|
|
|
/* We must run the index record counts at an isolation level
|
|
|
|
>= READ COMMITTED, because a dirty read can see a wrong number
|
|
|
|
of records in some index; to play safe, we use always
|
|
|
|
REPEATABLE READ here */
|
|
|
|
|
|
|
|
prebuilt->trx->isolation_level = TRX_ISO_REPEATABLE_READ;
|
|
|
|
|
|
|
|
/* Enlarge the fatal lock wait timeout during CHECK TABLE. */
|
|
|
|
mutex_enter(&kernel_mutex);
|
|
|
|
srv_fatal_semaphore_wait_threshold += 7200; /* 2 hours */
|
|
|
|
mutex_exit(&kernel_mutex);
|
|
|
|
|
|
|
|
index = dict_table_get_first_index(table);
|
|
|
|
|
|
|
|
while (index != NULL) {
|
|
|
|
/* fputs("Validating index ", stderr);
|
2006-06-13 22:23:26 +02:00
|
|
|
ut_print_name(stderr, trx, FALSE, index->name);
|
2005-10-27 09:29:40 +02:00
|
|
|
putc('\n', stderr); */
|
2006-02-23 20:25:29 +01:00
|
|
|
|
2006-09-19 12:14:07 +02:00
|
|
|
if (!btr_validate_index(index, prebuilt->trx)) {
|
2005-10-27 09:29:40 +02:00
|
|
|
ret = DB_ERROR;
|
|
|
|
} else {
|
2007-04-04 13:05:33 +02:00
|
|
|
if (!row_scan_and_check_index(prebuilt,index, &n_rows)){
|
2005-10-27 09:29:40 +02:00
|
|
|
ret = DB_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (trx_is_interrupted(prebuilt->trx)) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* fprintf(stderr, "%lu entries in index %s\n", n_rows,
|
2006-08-29 11:30:31 +02:00
|
|
|
index->name); */
|
2005-10-27 09:29:40 +02:00
|
|
|
|
|
|
|
if (index == dict_table_get_first_index(table)) {
|
|
|
|
n_rows_in_table = n_rows;
|
|
|
|
} else if (n_rows != n_rows_in_table) {
|
|
|
|
|
|
|
|
ret = DB_ERROR;
|
2006-02-23 20:25:29 +01:00
|
|
|
|
2005-10-27 09:29:40 +02:00
|
|
|
fputs("Error: ", stderr);
|
|
|
|
dict_index_name_print(stderr,
|
2006-08-29 11:30:31 +02:00
|
|
|
prebuilt->trx, index);
|
2005-10-27 09:29:40 +02:00
|
|
|
fprintf(stderr,
|
2006-08-29 11:30:31 +02:00
|
|
|
" contains %lu entries,"
|
|
|
|
" should be %lu\n",
|
2005-10-27 09:29:40 +02:00
|
|
|
(ulong) n_rows,
|
|
|
|
(ulong) n_rows_in_table);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
index = dict_table_get_next_index(index);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Restore the original isolation level */
|
|
|
|
prebuilt->trx->isolation_level = old_isolation_level;
|
2006-02-23 20:25:29 +01:00
|
|
|
|
2005-10-27 09:29:40 +02:00
|
|
|
/* We validate also the whole adaptive hash index for all tables
|
|
|
|
at every CHECK TABLE */
|
|
|
|
|
|
|
|
if (!btr_search_validate()) {
|
|
|
|
|
|
|
|
ret = DB_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Restore the fatal lock wait timeout after CHECK TABLE. */
|
|
|
|
mutex_enter(&kernel_mutex);
|
|
|
|
srv_fatal_semaphore_wait_threshold -= 7200; /* 2 hours */
|
|
|
|
mutex_exit(&kernel_mutex);
|
|
|
|
|
|
|
|
prebuilt->trx->op_info = "";
|
|
|
|
|
|
|
|
return(ret);
|
|
|
|
}
|
2006-11-30 16:25:52 +01:00
|
|
|
#endif /* !UNIV_HOTBACKUP */
|
2008-02-18 21:09:03 +01:00
|
|
|
|
|
|
|
/*************************************************************************
|
|
|
|
Determines if a table is a magic monitor table. */
|
|
|
|
UNIV_INTERN
|
|
|
|
ibool
|
|
|
|
row_is_magic_monitor_table(
|
|
|
|
/*=======================*/
|
|
|
|
/* out: TRUE if monitor table */
|
|
|
|
const char* table_name) /* in: name of the table, in the
|
|
|
|
form database/table_name */
|
|
|
|
{
|
|
|
|
const char* name; /* table_name without database/ */
|
|
|
|
ulint len;
|
|
|
|
|
|
|
|
name = strchr(table_name, '/');
|
|
|
|
ut_a(name != NULL);
|
|
|
|
name++;
|
|
|
|
len = strlen(name) + 1;
|
|
|
|
|
|
|
|
if (STR_EQ(name, len, S_innodb_monitor)
|
|
|
|
|| STR_EQ(name, len, S_innodb_lock_monitor)
|
|
|
|
|| STR_EQ(name, len, S_innodb_tablespace_monitor)
|
|
|
|
|| STR_EQ(name, len, S_innodb_table_monitor)
|
|
|
|
|| STR_EQ(name, len, S_innodb_mem_validate)) {
|
|
|
|
|
|
|
|
return(TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
return(FALSE);
|
|
|
|
}
|