summaryrefslogtreecommitdiff
path: root/sql
diff options
context:
space:
mode:
authorunknown <monty@mashka.mysql.fi>2003-01-18 03:13:37 +0200
committerunknown <monty@mashka.mysql.fi>2003-01-18 03:13:37 +0200
commit76c8b9becec0438562882f591529190564a2d82f (patch)
treeb24bce166fd5affbcc506bbc7d70c2c7ef00f561 /sql
parent0ee64eb3d2daccd29478832ef9ce86f0ea086e9d (diff)
parentaec8aeaab869e8553123ad1aefd8a5ab2c5f3ea7 (diff)
downloadmariadb-git-76c8b9becec0438562882f591529190564a2d82f.tar.gz
Merge with 4.0.9
BitKeeper/etc/ignore: auto-union client/mysqltest.c: Auto merged configure.in: Auto merged BitKeeper/deleted/.del-mutex.h~d3ae7a2977a68137: Auto merged BitKeeper/deleted/.del-mutex.m4~a13383cde18a64e1: Auto merged innobase/btr/btr0cur.c: Auto merged innobase/btr/btr0pcur.c: Auto merged innobase/log/log0log.c: Auto merged innobase/srv/srv0srv.c: Auto merged innobase/trx/trx0trx.c: Auto merged myisam/mi_create.c: Auto merged myisam/mi_unique.c: Auto merged myisam/myisamchk.c: Auto merged mysql-test/mysql-test-run.sh: Auto merged mysql-test/r/group_by.result: Auto merged mysql-test/r/merge.result: Auto merged mysql-test/r/null.result: Auto merged mysql-test/t/group_by.test: Auto merged mysql-test/t/merge.test: Auto merged mysql-test/t/null.test: Auto merged scripts/mysql_fix_privilege_tables.sh: Auto merged sql/field_conv.cc: Auto merged sql/ha_myisammrg.cc: Auto merged sql/mysqld.cc: Auto merged sql/net_serv.cc: Auto merged sql/opt_sum.cc: Auto merged sql/protocol.cc: Auto merged sql/sql_db.cc: Auto merged sql/sql_load.cc: Auto merged sql/sql_table.cc: Auto merged strings/Makefile.am: Auto merged libmysql/Makefile.shared: merge libmysql/libmysql.def: merge sql/ha_innodb.cc: merge sql/item_cmpfunc.cc: merge sql/log_event.cc: merge sql/sql_handler.cc: merge
Diffstat (limited to 'sql')
-rw-r--r--sql/field_conv.cc9
-rw-r--r--sql/ha_innodb.cc196
-rw-r--r--sql/ha_myisammrg.cc2
-rw-r--r--sql/item_cmpfunc.cc38
-rw-r--r--sql/log_event.cc2
-rw-r--r--sql/mysqld.cc2
-rw-r--r--sql/opt_sum.cc7
-rw-r--r--sql/sql_load.cc40
-rw-r--r--sql/sql_table.cc9
9 files changed, 223 insertions, 82 deletions
diff --git a/sql/field_conv.cc b/sql/field_conv.cc
index 95d06176cd2..47996606638 100644
--- a/sql/field_conv.cc
+++ b/sql/field_conv.cc
@@ -118,6 +118,15 @@ set_field_to_null(Field *field)
field->reset();
return 0;
}
+ field->reset();
+ if (current_thd->count_cuted_fields)
+ {
+ current_thd->cuted_fields++; // Increment error counter
+ return 0;
+ }
+ if (!current_thd->no_errors)
+ my_printf_error(ER_BAD_NULL_ERROR,ER(ER_BAD_NULL_ERROR),MYF(0),
+ field->field_name);
return 1;
}
diff --git a/sql/ha_innodb.cc b/sql/ha_innodb.cc
index cb012d33572..86544542613 100644
--- a/sql/ha_innodb.cc
+++ b/sql/ha_innodb.cc
@@ -2272,19 +2272,7 @@ convert_search_mode_to_innobase(
case HA_READ_AFTER_KEY: return(PAGE_CUR_G);
case HA_READ_BEFORE_KEY: return(PAGE_CUR_L);
case HA_READ_PREFIX: return(PAGE_CUR_GE);
- case HA_READ_PREFIX_LAST:
- /* ut_print_timestamp(stderr);
- fprintf(stderr,
- " InnoDB: Warning: Using HA_READ_PREFIX_LAST\n"); */
- return(PAGE_CUR_LE);
-
- /* InnoDB does not yet support ..PREFIX_LAST!
- We have to add a new search flag
- PAGE_CUR_LE_OR_PREFIX to InnoDB. */
-
- /* the above PREFIX flags mean that the last
- field in the key value may just be a prefix
- of the complete fixed length field */
+ case HA_READ_PREFIX_LAST: return(PAGE_CUR_LE_OR_EXTENDS);
default: assert(0);
}
@@ -2489,6 +2477,9 @@ ha_innobase::change_active_index(
(trx_t*) current_thd->transaction.all.innobase_tid);
ut_a(user_thd == current_thd);
+ ut_a(prebuilt->trx ==
+ (trx_t*) current_thd->transaction.all.innobase_tid);
+
active_index = keynr;
if (keynr != MAX_KEY && table->keys > 0) {
@@ -2520,6 +2511,11 @@ ha_innobase::change_active_index(
the flag ROW_MYSQL_WHOLE_ROW below, but that caused unnecessary
copying. Starting from MySQL-4.1 we use a more efficient flag here. */
+ /*
+ TODO: In 4.0 the below user_thd was changed to NULL.
+ Heikki, please delete this comment after you have read this and may
+ acted upon it.
+ */
build_template(prebuilt, user_thd, table, ROW_MYSQL_REC_FIELDS);
DBUG_RETURN(0);
@@ -3025,6 +3021,7 @@ ha_innobase::create(
{
int error;
dict_table_t* innobase_table;
+ trx_t* parent_trx;
trx_t* trx;
int primary_key_no;
uint i;
@@ -3036,6 +3033,16 @@ ha_innobase::create(
DBUG_ASSERT(thd != NULL);
+ /* Get the transaction associated with the current thd, or create one
+ if not yet created */
+
+ parent_trx = check_trx_exists(current_thd);
+
+ /* In case MySQL calls this in the middle of a SELECT query, release
+ possible adaptive hash latch to avoid deadlocks of threads */
+
+ trx_search_latch_release_if_reserved(parent_trx);
+
trx = trx_allocate_for_mysql();
if (thd->options & OPTION_NO_FOREIGN_KEY_CHECKS) {
@@ -3196,11 +3203,22 @@ ha_innobase::delete_table(
{
ulint name_len;
int error;
+ trx_t* parent_trx;
trx_t* trx;
char norm_name[1000];
DBUG_ENTER("ha_innobase::delete_table");
+ /* Get the transaction associated with the current thd, or create one
+ if not yet created */
+
+ parent_trx = check_trx_exists(current_thd);
+
+ /* In case MySQL calls this in the middle of a SELECT query, release
+ possible adaptive hash latch to avoid deadlocks of threads */
+
+ trx_search_latch_release_if_reserved(parent_trx);
+
if (lower_case_table_names) {
srv_lower_case_table_names = TRUE;
} else {
@@ -3255,11 +3273,22 @@ innobase_drop_database(
the database name is 'test' */
{
ulint len = 0;
+ trx_t* parent_trx;
trx_t* trx;
char* ptr;
int error;
char namebuf[10000];
+ /* Get the transaction associated with the current thd, or create one
+ if not yet created */
+
+ parent_trx = check_trx_exists(current_thd);
+
+ /* In case MySQL calls this in the middle of a SELECT query, release
+ possible adaptive hash latch to avoid deadlocks of threads */
+
+ trx_search_latch_release_if_reserved(parent_trx);
+
ptr = strend(path) - 2;
while (ptr >= path && *ptr != '\\' && *ptr != '/') {
@@ -3311,12 +3340,23 @@ ha_innobase::rename_table(
ulint name_len1;
ulint name_len2;
int error;
+ trx_t* parent_trx;
trx_t* trx;
char norm_from[1000];
char norm_to[1000];
DBUG_ENTER("ha_innobase::rename_table");
+ /* Get the transaction associated with the current thd, or create one
+ if not yet created */
+
+ parent_trx = check_trx_exists(current_thd);
+
+ /* In case MySQL calls this in the middle of a SELECT query, release
+ possible adaptive hash latch to avoid deadlocks of threads */
+
+ trx_search_latch_release_if_reserved(parent_trx);
+
if (lower_case_table_names) {
srv_lower_case_table_names = TRUE;
} else {
@@ -3363,8 +3403,8 @@ Estimates the number of index records in a range. */
ha_rows
ha_innobase::records_in_range(
/*==========================*/
- /* out: estimated number of rows,
- currently 32-bit int or uint */
+ /* out: estimated number of
+ rows */
int keynr, /* in: index number */
const mysql_byte* start_key, /* in: start key value of the
range, may also be empty */
@@ -3395,9 +3435,18 @@ ha_innobase::records_in_range(
DBUG_ENTER("records_in_range");
- /* Warning: since it is not sure that MySQL calls external_lock
- before calling this function, the trx field in prebuilt can be
- obsolete! */
+ /* We do not know if MySQL can call this function before calling
+ external_lock(). To be safe, update the thd of the current table
+ handle. */
+
+ update_thd(current_thd);
+
+ prebuilt->trx->op_info = (char*)"estimating records in index range";
+
+ /* In case MySQL calls this in the middle of a SELECT query, release
+ possible adaptive hash latch to avoid deadlocks of threads */
+
+ trx_search_latch_release_if_reserved(prebuilt->trx);
active_index = keynr;
@@ -3431,6 +3480,8 @@ ha_innobase::records_in_range(
my_free((char*) key_val_buff2, MYF(0));
+ prebuilt->trx->op_info = (char*)"";
+
DBUG_RETURN((ha_rows) n_rows);
}
@@ -3451,11 +3502,21 @@ ha_innobase::estimate_number_of_rows(void)
ulonglong estimate;
ulonglong local_data_file_length;
- /* Warning: since it is not sure that MySQL calls external_lock
- before calling this function, the trx field in prebuilt can be
- obsolete! */
+ DBUG_ENTER("estimate_number_of_rows");
- DBUG_ENTER("info");
+ /* We do not know if MySQL can call this function before calling
+ external_lock(). To be safe, update the thd of the current table
+ handle. */
+
+ update_thd(current_thd);
+
+ prebuilt->trx->op_info = (char*)
+ "calculating upper bound for table rows";
+
+ /* In case MySQL calls this in the middle of a SELECT query, release
+ possible adaptive hash latch to avoid deadlocks of threads */
+
+ trx_search_latch_release_if_reserved(prebuilt->trx);
index = dict_table_get_first_index_noninline(prebuilt->table);
@@ -3470,6 +3531,8 @@ ha_innobase::estimate_number_of_rows(void)
estimate = 2 * local_data_file_length / dict_index_calc_min_rec_len(index);
+ prebuilt->trx->op_info = (char*)"";
+
DBUG_RETURN((ha_rows) estimate);
}
@@ -3520,9 +3583,18 @@ ha_innobase::info(
return;
}
- /* Warning: since it is not sure that MySQL calls external_lock
- before calling this function, the trx field in prebuilt can be
- obsolete! */
+ /* We do not know if MySQL can call this function before calling
+ external_lock(). To be safe, update the thd of the current table
+ handle. */
+
+ update_thd(current_thd);
+
+ /* In case MySQL calls this in the middle of a SELECT query, release
+ possible adaptive hash latch to avoid deadlocks of threads */
+
+ prebuilt->trx->op_info = (char*)"returning various info to MySQL";
+
+ trx_search_latch_release_if_reserved(prebuilt->trx);
ib_table = prebuilt->table;
@@ -3530,7 +3602,12 @@ ha_innobase::info(
/* In sql_show we call with this flag: update then statistics
so that they are up-to-date */
+ prebuilt->trx->op_info = (char*)"updating table statistics";
+
dict_update_statistics(ib_table);
+
+ prebuilt->trx->op_info = (char*)
+ "returning various info to MySQL";
}
if (flag & HA_STATUS_VARIABLE) {
@@ -3590,12 +3667,6 @@ ha_innobase::info(
}
}
- /* The trx struct in InnoDB contains a pthread mutex embedded:
- in the debug version of MySQL that it replaced by a 'safe mutex'
- which is of a different size. We have to use a function to access
- trx fields. Otherwise trx->error_info will be a random
- pointer and cause a seg fault. */
-
if (flag & HA_STATUS_ERRKEY) {
ut_a(prebuilt->trx && prebuilt->trx->magic_n == TRX_MAGIC_N);
@@ -3604,6 +3675,8 @@ ha_innobase::info(
trx_get_error_info(prebuilt->trx));
}
+ prebuilt->trx->op_info = (char*)"";
+
DBUG_VOID_RETURN;
}
@@ -3661,11 +3734,22 @@ ha_innobase::update_table_comment(
char* str = my_malloc(length + 16500, MYF(0));
char* pos;
- /* Warning: since it is not sure that MySQL calls external_lock
- before calling this function, the trx field in prebuilt can be
- obsolete! */
+ /* We do not know if MySQL can call this function before calling
+ external_lock(). To be safe, update the thd of the current table
+ handle. */
+
+ update_thd(current_thd);
+
+ prebuilt->trx->op_info = (char*)"returning table comment";
+
+ /* In case MySQL calls this in the middle of a SELECT query, release
+ possible adaptive hash latch to avoid deadlocks of threads */
+
+ trx_search_latch_release_if_reserved(prebuilt->trx);
if (!str) {
+ prebuilt->trx->op_info = (char*)"";
+
return((char*)comment);
}
@@ -3689,6 +3773,8 @@ ha_innobase::update_table_comment(
prebuilt->table);
}
+ prebuilt->trx->op_info = (char*)"";
+
return(str);
}
@@ -3704,20 +3790,30 @@ ha_innobase::get_foreign_key_create_info(void)
{
row_prebuilt_t* prebuilt = (row_prebuilt_t*)innobase_prebuilt;
char* str;
-
- if (prebuilt == NULL) {
- fprintf(stderr,
-"InnoDB: Error: cannot get create info for foreign keys\n");
- return(NULL);
- }
+ ut_a(prebuilt != NULL);
+ /* We do not know if MySQL can call this function before calling
+ external_lock(). To be safe, update the thd of the current table
+ handle. */
+
+ update_thd(current_thd);
+
+ prebuilt->trx->op_info = (char*)"getting info on foreign keys";
+
+ /* In case MySQL calls this in the middle of a SELECT query, release
+ possible adaptive hash latch to avoid deadlocks of threads */
+
+ trx_search_latch_release_if_reserved(prebuilt->trx);
+
str = (char*)ut_malloc(10000);
str[0] = '\0';
dict_print_info_on_foreign_keys(TRUE, str, 9000, prebuilt->table);
+ prebuilt->trx->op_info = (char*)"";
+
return(str);
}
@@ -3793,9 +3889,10 @@ ha_innobase::reset(void)
}
/**********************************************************************
-When we create a temporary table inside MySQL LOCK TABLES, MySQL will
-not call external_lock for the temporary table when it uses it. Instead,
-it will call this function. */
+Inside LOCK TABLES MySQL will not call external_lock() between SQL
+statements. It will call this function at the start of each SQL statement.
+Note also a spacial case: if a temporary table is created inside LOCK
+TABLES, MySQL has not called external_lock() at all on that table. */
int
ha_innobase::start_stmt(
@@ -3933,8 +4030,8 @@ ha_innobase::external_lock(
trx->mysql_n_tables_locked = 0;
- /* Here we release the search latch, auto_inc_lock,
- and InnoDB thread FIFO ticket if they were reserved. */
+ /* Here we release the search latch and InnoDB
+ thread FIFO ticket if they were reserved. */
innobase_release_stat_resources(trx);
@@ -3978,12 +4075,12 @@ innodb_show_status(
DBUG_RETURN(-1);
}
- /* We let the InnoDB Monitor to output at most 100 kB of text, add
+ /* We let the InnoDB Monitor to output at most 200 kB of text, add
a safety margin of 10 kB for buffer overruns */
- buf = (char*)ut_malloc(110 * 1024);
+ buf = (char*)ut_malloc(210 * 1024);
- srv_sprintf_innodb_monitor(buf, 100 * 1024);
+ srv_sprintf_innodb_monitor(buf, 200 * 1024);
List<Item> field_list;
@@ -3991,6 +4088,7 @@ innodb_show_status(
if (protocol->send_fields(&field_list, 1))
{
+ ut_free(buf);
DBUG_RETURN(-1);
}
@@ -4241,4 +4339,4 @@ ha_innobase::get_auto_increment()
}
#endif /* HAVE_INNOBASE_DB */
-
+
diff --git a/sql/ha_myisammrg.cc b/sql/ha_myisammrg.cc
index 3bd812821f6..00052239f0b 100644
--- a/sql/ha_myisammrg.cc
+++ b/sql/ha_myisammrg.cc
@@ -241,7 +241,7 @@ void ha_myisammrg::info(uint flag)
#endif
if (flag & HA_STATUS_CONST)
{
- if (table->key_parts)
+ if (table->key_parts && info.rec_per_key)
memcpy((char*) table->key_info[0].rec_per_key,
(char*) info.rec_per_key,
sizeof(table->key_info[0].rec_per_key)*table->key_parts);
diff --git a/sql/item_cmpfunc.cc b/sql/item_cmpfunc.cc
index 3d65c05b9cf..79807653317 100644
--- a/sql/item_cmpfunc.cc
+++ b/sql/item_cmpfunc.cc
@@ -1898,7 +1898,7 @@ Item_func_regex::~Item_func_regex()
Precomputation dependent only on pattern_len.
**********************************************************************/
-void Item_func_like::turboBM_compute_suffixes(int* suff)
+void Item_func_like::turboBM_compute_suffixes(int *suff)
{
const int plm1 = pattern_len - 1;
int f = 0;
@@ -1940,8 +1940,8 @@ void Item_func_like::turboBM_compute_suffixes(int* suff)
if (i < g)
g = i; // g = min(i, g)
f = i;
- while (g >= 0 && likeconv(cs, pattern[g]) ==
- likeconv(cs, pattern[g + plm1 - f]))
+ while (g >= 0 &&
+ likeconv(cs, pattern[g]) == likeconv(cs, pattern[g + plm1 - f]))
g--;
suff[i] = f - g;
}
@@ -1955,12 +1955,12 @@ void Item_func_like::turboBM_compute_suffixes(int* suff)
Precomputation dependent only on pattern_len.
**********************************************************************/
-void Item_func_like::turboBM_compute_good_suffix_shifts(int* suff)
+void Item_func_like::turboBM_compute_good_suffix_shifts(int *suff)
{
turboBM_compute_suffixes(suff);
- int* end = bmGs + pattern_len;
- int* k;
+ int *end = bmGs + pattern_len;
+ int *k;
for (k = bmGs; k < end; k++)
*k = pattern_len;
@@ -1974,14 +1974,14 @@ void Item_func_like::turboBM_compute_good_suffix_shifts(int* suff)
{
for (tmp = plm1 - i; j < tmp; j++)
{
- int* tmp2 = bmGs + j;
+ int *tmp2 = bmGs + j;
if (*tmp2 == pattern_len)
*tmp2 = tmp;
}
}
}
- int* tmp2;
+ int *tmp2;
for (tmp = plm1 - i; j < tmp; j++)
{
tmp2 = bmGs + j;
@@ -2014,12 +2014,12 @@ void Item_func_like::turboBM_compute_bad_character_shifts()
if (binary())
{
for (j = 0; j < plm1; j++)
- bmBc[pattern[j]] = plm1 - j;
+ bmBc[(uint) (uchar) pattern[j]] = plm1 - j;
}
else
{
for (j = 0; j < plm1; j++)
- bmBc[likeconv(cs,pattern[j])] = plm1 - j;
+ bmBc[(uint) likeconv(cs,pattern[j])] = plm1 - j;
}
}
@@ -2038,27 +2038,27 @@ bool Item_func_like::turboBM_matches(const char* text, int text_len) const
int u = 0;
CHARSET_INFO *cs=system_charset_info; // QQ Needs to be fixed
- const int plm1 = pattern_len - 1;
- const int tlmpl = text_len - pattern_len;
+ const int plm1= pattern_len - 1;
+ const int tlmpl= text_len - pattern_len;
/* Searching */
if (binary())
{
while (j <= tlmpl)
{
- register int i = plm1;
+ register int i= plm1;
while (i >= 0 && pattern[i] == text[i + j])
{
i--;
if (i == plm1 - shift)
- i -= u;
+ i-= u;
}
if (i < 0)
return 1;
register const int v = plm1 - i;
turboShift = u - v;
- bcShift = bmBc[text[i + j]] - plm1 + i;
+ bcShift = bmBc[(uint) (uchar) text[i + j]] - plm1 + i;
shift = max(turboShift, bcShift);
shift = max(shift, bmGs[i]);
if (shift == bmGs[i])
@@ -2069,7 +2069,7 @@ bool Item_func_like::turboBM_matches(const char* text, int text_len) const
shift = max(shift, u + 1);
u = 0;
}
- j += shift;
+ j+= shift;
}
return 0;
}
@@ -2082,14 +2082,14 @@ bool Item_func_like::turboBM_matches(const char* text, int text_len) const
{
i--;
if (i == plm1 - shift)
- i -= u;
+ i-= u;
}
if (i < 0)
return 1;
register const int v = plm1 - i;
turboShift = u - v;
- bcShift = bmBc[likeconv(cs, text[i + j])] - plm1 + i;
+ bcShift = bmBc[(uint) likeconv(cs, text[i + j])] - plm1 + i;
shift = max(turboShift, bcShift);
shift = max(shift, bmGs[i]);
if (shift == bmGs[i])
@@ -2100,7 +2100,7 @@ bool Item_func_like::turboBM_matches(const char* text, int text_len) const
shift = max(shift, u + 1);
u = 0;
}
- j += shift;
+ j+= shift;
}
return 0;
}
diff --git a/sql/log_event.cc b/sql/log_event.cc
index 4ce491d7cc5..1d27e48f14f 100644
--- a/sql/log_event.cc
+++ b/sql/log_event.cc
@@ -1331,8 +1331,8 @@ int Load_log_event::copy_log_event(const char *buf, ulong event_len,
bool old_format)
{
uint data_len;
- uint header_len= old_format ? OLD_HEADER_LEN : LOG_EVENT_HEADER_LEN;
char* buf_end = (char*)buf + event_len;
+ uint header_len= old_format ? OLD_HEADER_LEN : LOG_EVENT_HEADER_LEN;
const char* data_head = buf + header_len;
thread_id = uint4korr(data_head + L_THREAD_ID_OFFSET);
exec_time = uint4korr(data_head + L_EXEC_TIME_OFFSET);
diff --git a/sql/mysqld.cc b/sql/mysqld.cc
index f30034049f0..1ed33d5c9db 100644
--- a/sql/mysqld.cc
+++ b/sql/mysqld.cc
@@ -770,7 +770,7 @@ static void *kill_server(void *sig_ptr)
#define RETURN_FROM_KILL_SERVER DBUG_RETURN(0)
#else
static void __cdecl kill_server(int sig_ptr)
-#define RETURN_FROM_KILL_SERVER DBUG_RETURN
+#define RETURN_FROM_KILL_SERVER DBUG_VOID_RETURN
#endif
{
int sig=(int) (long) sig_ptr; // This is passed a int
diff --git a/sql/opt_sum.cc b/sql/opt_sum.cc
index b1bb36353bf..492834b5bb9 100644
--- a/sql/opt_sum.cc
+++ b/sql/opt_sum.cc
@@ -38,7 +38,7 @@ int opt_sum_query(TABLE_LIST *tables, List<Item> &all_fields,COND *conds)
table_map removed_tables=0;
Item *item;
COND *org_conds= conds;
-
+
/* Add all ON conditions to WHERE condition */
for (TABLE_LIST *tl=tables; tl ; tl= tl->next)
{
@@ -165,10 +165,9 @@ int opt_sum_query(TABLE_LIST *tables, List<Item> &all_fields,COND *conds)
error=table->file->index_last(table->record[0]) !=0;
else
{
- (void)table->file->index_read(table->record[0], key_buff,
+ error = table->file->index_read(table->record[0], key_buff,
ref.key_length,
- HA_READ_AFTER_KEY);
- error=table->file->index_prev(table->record[0]) ||
+ HA_READ_PREFIX_LAST) ||
key_cmp(table,key_buff,ref.key,ref.key_length);
}
if (table->key_read)
diff --git a/sql/sql_load.cc b/sql/sql_load.cc
index 96ff33774ac..8fca6300992 100644
--- a/sql/sql_load.cc
+++ b/sql/sql_load.cc
@@ -283,6 +283,20 @@ int mysql_load(THD *thd,sql_exchange *ex,TABLE_LIST *table_list,
{
if (lf_info.wrote_create_file)
{
+ /*
+ Make sure last block (the one which caused the error) gets logged.
+ This is needed because otherwise after write of
+ (to the binlog, not to read_info (which is a cache))
+ Delete_file_log_event the bad block will remain in read_info.
+ At the end of mysql_load(), the destructor of read_info will call
+ end_io_cache() which will flush read_info, so we will finally have
+ this in the binlog:
+ Append_block # The last successfull block
+ Delete_file
+ Append_block # The failing block
+ which is nonsense.
+ */
+ read_info.end_io_cache();
Delete_file_log_event d(thd, log_delayed);
mysql_bin_log.write(&d);
}
@@ -343,8 +357,10 @@ read_fixed_length(THD *thd,COPY_INFO &info,TABLE *table,List<Item> &fields,
{
List_iterator_fast<Item> it(fields);
Item_field *sql_field;
+ ulonglong id;
DBUG_ENTER("read_fixed_length");
+ id=0;
/* No fields can be null in this format. mark all fields as not null */
while ((sql_field= (Item_field*) it++))
sql_field->field->set_notnull();
@@ -387,6 +403,14 @@ read_fixed_length(THD *thd,COPY_INFO &info,TABLE *table,List<Item> &fields,
thd->cuted_fields++; /* To long row */
if (write_record(table,&info))
DBUG_RETURN(1);
+ /*
+ If auto_increment values are used, save the first one
+ for LAST_INSERT_ID() and for the binary/update log.
+ We can't use insert_id() as we don't want to touch the
+ last_insert_id_used flag.
+ */
+ if (!id && thd->insert_id_used)
+ id= thd->last_insert_id;
if (table->next_number_field)
table->next_number_field->reset(); // Clear for next record
if (read_info.next_line()) // Skip to next line
@@ -394,6 +418,8 @@ read_fixed_length(THD *thd,COPY_INFO &info,TABLE *table,List<Item> &fields,
if (read_info.line_cuted)
thd->cuted_fields++; /* To long row */
}
+ if (id && !read_info.error)
+ thd->insert_id(id); // For binary/update log
DBUG_RETURN(test(read_info.error));
}
@@ -407,10 +433,12 @@ read_sep_field(THD *thd,COPY_INFO &info,TABLE *table,
List_iterator_fast<Item> it(fields);
Item_field *sql_field;
uint enclosed_length;
+ ulonglong id;
DBUG_ENTER("read_sep_field");
enclosed_length=enclosed.length();
-
+ id=0;
+
for (;;it.rewind())
{
if (thd->killed)
@@ -463,6 +491,14 @@ read_sep_field(THD *thd,COPY_INFO &info,TABLE *table,
}
if (write_record(table,&info))
DBUG_RETURN(1);
+ /*
+ If auto_increment values are used, save the first one
+ for LAST_INSERT_ID() and for the binary/update log.
+ We can't use insert_id() as we don't want to touch the
+ last_insert_id_used flag.
+ */
+ if (!id && thd->insert_id_used)
+ id= thd->last_insert_id;
if (table->next_number_field)
table->next_number_field->reset(); // Clear for next record
if (read_info.next_line()) // Skip to next line
@@ -470,6 +506,8 @@ read_sep_field(THD *thd,COPY_INFO &info,TABLE *table,
if (read_info.line_cuted)
thd->cuted_fields++; /* To long row */
}
+ if (id && !read_info.error)
+ thd->insert_id(id); // For binary/update log
DBUG_RETURN(test(read_info.error));
}
diff --git a/sql/sql_table.cc b/sql/sql_table.cc
index 7f46311cd85..686db8736af 100644
--- a/sql/sql_table.cc
+++ b/sql/sql_table.cc
@@ -2030,12 +2030,9 @@ int mysql_alter_table(THD *thd,char *new_db, char *new_name,
/* We changed a temporary table */
if (error)
{
- /*
- * The following function call will also free a
- * new_table pointer.
- * Therefore, here new_table pointer is not free'd as it is
- * free'd in close_temporary() which is called by by the
- * close_temporary_table() function.
+ /*
+ The following function call will free the new_table pointer,
+ in close_temporary_table(), so we can safely directly jump to err
*/
close_temporary_table(thd,new_db,tmp_name);
goto err;