Commit 57afe1d5 authored by marko's avatar marko

branches/zip: Merge 1809:1830 from trunk.

parent 313dabb9
...@@ -6427,6 +6427,9 @@ ha_innobase::start_stmt( ...@@ -6427,6 +6427,9 @@ ha_innobase::start_stmt(
innobase_release_stat_resources(trx); innobase_release_stat_resources(trx);
/* Reset the AUTOINC statement level counter for multi-row INSERTs. */
trx->n_autoinc_rows = 0;
prebuilt->sql_stat_start = TRUE; prebuilt->sql_stat_start = TRUE;
prebuilt->hint_need_to_fetch_extra_cols = 0; prebuilt->hint_need_to_fetch_extra_cols = 0;
reset_template(prebuilt); reset_template(prebuilt);
...@@ -7339,6 +7342,11 @@ ha_innobase::innobase_get_auto_increment( ...@@ -7339,6 +7342,11 @@ ha_innobase::innobase_get_auto_increment(
{ {
ulint error; ulint error;
ut_a(*value == 0);
/* Note: If the table is not initialized when we attempt the
read below. We initialize the table's auto-inc counter and
always do a reread of the AUTOINC value. */
do { do {
error = innobase_autoinc_lock(); error = innobase_autoinc_lock();
...@@ -7403,6 +7411,7 @@ ha_innobase::get_auto_increment( ...@@ -7403,6 +7411,7 @@ ha_innobase::get_auto_increment(
ulonglong *first_value, /* out: the autoinc value */ ulonglong *first_value, /* out: the autoinc value */
ulonglong *nb_reserved_values) /* out: count of reserved values */ ulonglong *nb_reserved_values) /* out: count of reserved values */
{ {
trx_t* trx;
ulint error; ulint error;
ulonglong autoinc = 0; ulonglong autoinc = 0;
...@@ -7429,37 +7438,34 @@ ha_innobase::get_auto_increment( ...@@ -7429,37 +7438,34 @@ ha_innobase::get_auto_increment(
this method for the same statement results in different values which this method for the same statement results in different values which
don't make sense. Therefore we store the value the first time we are don't make sense. Therefore we store the value the first time we are
called and count down from that as rows are written (see write_row()). called and count down from that as rows are written (see write_row()).
*/
trx = prebuilt->trx;
We make one exception, if the *first_value is precomputed by MySQL /* Note: We can't rely on *first_value since some MySQL engines,
we use that value. And set the number of reserved values to 1 if in particular the partition engine, don't initialize it to 0 when
this is the first time we were called for the SQL statement, this invoking this method. So we are not sure if it's guaranteed to
will force MySQL to call us for the next value. If we are in the be 0 or not. */
middle of a multi-row insert we preserve the existing counter.*/
if (*first_value == 0) {
/* Called for the first time ? */ /* Called for the first time ? */
if (prebuilt->trx->n_autoinc_rows == 0) { if (trx->n_autoinc_rows == 0) {
prebuilt->trx->n_autoinc_rows = nb_desired_values; trx->n_autoinc_rows = nb_desired_values;
/* It's possible for nb_desired_values to be 0: /* It's possible for nb_desired_values to be 0:
e.g., INSERT INTO T1(C) SELECT C FROM T2; */ e.g., INSERT INTO T1(C) SELECT C FROM T2; */
if (nb_desired_values == 0) { if (nb_desired_values == 0) {
++prebuilt->trx->n_autoinc_rows; trx->n_autoinc_rows = 1;
}
} }
*first_value = autoinc; *first_value = autoinc;
/* Not in the middle of a mult-row INSERT. */
} else if (prebuilt->trx->n_autoinc_rows == 0) { } else if (prebuilt->last_value == 0) {
*first_value = autoinc;
prebuilt->trx->n_autoinc_rows = 1;
} }
ut_a(prebuilt->trx->n_autoinc_rows > 0); *nb_reserved_values = trx->n_autoinc_rows;
*nb_reserved_values = prebuilt->trx->n_autoinc_rows;
/* With old style AUTOINC locking we only update the table's /* With old style AUTOINC locking we only update the table's
AUTOINC counter after attempting to insert the row. */ AUTOINC counter after attempting to insert the row. */
......
...@@ -60,6 +60,14 @@ mem_heap_validate_or_print( ...@@ -60,6 +60,14 @@ mem_heap_validate_or_print(
ulint* n_blocks); /* out: number of blocks in the heap, ulint* n_blocks); /* out: number of blocks in the heap,
if a NULL pointer is passed as this if a NULL pointer is passed as this
argument, it is ignored */ argument, it is ignored */
/******************************************************************
Validates the contents of a memory heap. */
ibool
mem_heap_validate(
/*==============*/
/* out: TRUE if ok */
mem_heap_t* heap); /* in: memory heap */
#endif /* UNIV_MEM_DEBUG || UNIV_DEBUG */ #endif /* UNIV_MEM_DEBUG || UNIV_DEBUG */
#ifdef UNIV_DEBUG #ifdef UNIV_DEBUG
/****************************************************************** /******************************************************************
...@@ -71,14 +79,6 @@ mem_heap_check( ...@@ -71,14 +79,6 @@ mem_heap_check(
/* out: TRUE if ok */ /* out: TRUE if ok */
mem_heap_t* heap); /* in: memory heap */ mem_heap_t* heap); /* in: memory heap */
#endif /* UNIV_DEBUG */ #endif /* UNIV_DEBUG */
/******************************************************************
Validates the contents of a memory heap. */
ibool
mem_heap_validate(
/*==============*/
/* out: TRUE if ok */
mem_heap_t* heap); /* in: memory heap */
#ifdef UNIV_MEM_DEBUG #ifdef UNIV_MEM_DEBUG
/********************************************************************* /*********************************************************************
TRUE if no memory is currently allocated. */ TRUE if no memory is currently allocated. */
......
...@@ -292,8 +292,9 @@ mem_heap_free_heap_top( ...@@ -292,8 +292,9 @@ mem_heap_free_heap_top(
mem_current_allocated_memory -= (total_size - size); mem_current_allocated_memory -= (total_size - size);
mutex_exit(&mem_hash_mutex); mutex_exit(&mem_hash_mutex);
#else /* UNIV_MEM_DEBUG */ #else /* UNIV_MEM_DEBUG */
UNIV_MEM_ASSERT_AND_FREE(old_top, (byte*)block + block->len - old_top); UNIV_MEM_ASSERT_W(old_top, (byte*)block + block->len - old_top);
#endif /* UNIV_MEM_DEBUG */ #endif /* UNIV_MEM_DEBUG */
UNIV_MEM_ALLOC(old_top, (byte*)block + block->len - old_top);
/* If free == start, we may free the block if it is not the first /* If free == start, we may free the block if it is not the first
one */ one */
......
...@@ -328,10 +328,22 @@ typedef void* os_thread_ret_t; ...@@ -328,10 +328,22 @@ typedef void* os_thread_ret_t;
# define UNIV_MEM_ALLOC(addr, size) VALGRIND_MAKE_MEM_UNDEFINED(addr, size) # define UNIV_MEM_ALLOC(addr, size) VALGRIND_MAKE_MEM_UNDEFINED(addr, size)
# define UNIV_MEM_DESC(addr, size, b) VALGRIND_CREATE_BLOCK(addr, size, b) # define UNIV_MEM_DESC(addr, size, b) VALGRIND_CREATE_BLOCK(addr, size, b)
# define UNIV_MEM_UNDESC(b) VALGRIND_DISCARD(b) # define UNIV_MEM_UNDESC(b) VALGRIND_DISCARD(b)
# define UNIV_MEM_ASSERT_RW(addr, size) \ # define UNIV_MEM_ASSERT_RW(addr, size) do { \
VALGRIND_CHECK_MEM_IS_DEFINED(addr, size) const void* _p = (const void*) \
# define UNIV_MEM_ASSERT_W(addr, size) \ VALGRIND_CHECK_MEM_IS_DEFINED(addr, size); \
VALGRIND_CHECK_MEM_IS_ADDRESSABLE(addr, size) if (UNIV_LIKELY_NULL(_p)) \
fprintf(stderr, "%p[%u] undefined at %d\n", \
(const void*) (addr), (unsigned) (size), \
((const char*) _p) - ((const char*) (addr))); \
} while (0)
# define UNIV_MEM_ASSERT_W(addr, size) do { \
const void* _p = (const void*) \
VALGRIND_CHECK_MEM_IS_ADDRESSABLE(addr, size); \
if (UNIV_LIKELY_NULL(_p)) \
fprintf(stderr, "%p[%u] unwritable at %d\n", \
(const void*) (addr), (unsigned) (size), \
((const char*) _p) - ((const char*) (addr))); \
} while (0)
#else #else
# define UNIV_MEM_VALID(addr, size) do {} while(0) # define UNIV_MEM_VALID(addr, size) do {} while(0)
# define UNIV_MEM_INVALID(addr, size) do {} while(0) # define UNIV_MEM_INVALID(addr, size) do {} while(0)
......
...@@ -554,9 +554,7 @@ completed: ...@@ -554,9 +554,7 @@ completed:
} }
*error = FALSE; *error = FALSE;
} }
#endif /* UNIV_MEM_DEBUG || UNIV_DEBUG */
#ifdef UNIV_DEBUG
/****************************************************************** /******************************************************************
Prints the contents of a memory heap. */ Prints the contents of a memory heap. */
static static
...@@ -582,20 +580,6 @@ mem_heap_print( ...@@ -582,20 +580,6 @@ mem_heap_print(
ut_a(!error); ut_a(!error);
} }
/******************************************************************
Checks that an object is a memory heap (or a block of it). */
ibool
mem_heap_check(
/*===========*/
/* out: TRUE if ok */
mem_heap_t* heap) /* in: memory heap */
{
ut_a(heap->magic_n == MEM_BLOCK_MAGIC_N);
return(TRUE);
}
/****************************************************************** /******************************************************************
Validates the contents of a memory heap. */ Validates the contents of a memory heap. */
...@@ -622,6 +606,22 @@ mem_heap_validate( ...@@ -622,6 +606,22 @@ mem_heap_validate(
return(TRUE); return(TRUE);
} }
#endif /* UNIV_MEM_DEBUG || UNIV_DEBUG */
#ifdef UNIV_DEBUG
/******************************************************************
Checks that an object is a memory heap (or a block of it). */
ibool
mem_heap_check(
/*===========*/
/* out: TRUE if ok */
mem_heap_t* heap) /* in: memory heap */
{
ut_a(heap->magic_n == MEM_BLOCK_MAGIC_N);
return(TRUE);
}
#endif /* UNIV_DEBUG */ #endif /* UNIV_DEBUG */
#ifdef UNIV_MEM_DEBUG #ifdef UNIV_MEM_DEBUG
......
...@@ -948,7 +948,7 @@ id select_type table type possible_keys key key_len ref rows Extra ...@@ -948,7 +948,7 @@ id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 index NULL PRIMARY 4 NULL # 1 SIMPLE t1 index NULL PRIMARY 4 NULL #
explain select * from t1 order by b; explain select * from t1 order by b;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 index NULL b 4 NULL # 1 SIMPLE t1 ALL NULL NULL NULL NULL # Using filesort
explain select * from t1 order by c; explain select * from t1 order by c;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL # Using filesort 1 SIMPLE t1 ALL NULL NULL NULL NULL # Using filesort
......
...@@ -598,12 +598,13 @@ row_sel_build_prev_vers( ...@@ -598,12 +598,13 @@ row_sel_build_prev_vers(
/*====================*/ /*====================*/
/* out: DB_SUCCESS or error code */ /* out: DB_SUCCESS or error code */
read_view_t* read_view, /* in: read view */ read_view_t* read_view, /* in: read view */
plan_t* plan, /* in: plan node for table */ dict_index_t* index, /* in: plan node for table */
rec_t* rec, /* in: record in a clustered index */ rec_t* rec, /* in: record in a clustered index */
ulint** offsets, /* in/out: offsets returned by ulint** offsets, /* in/out: offsets returned by
rec_get_offsets(rec, plan->index) */ rec_get_offsets(rec, plan->index) */
mem_heap_t** offset_heap, /* in/out: memory heap from which mem_heap_t** offset_heap, /* in/out: memory heap from which
the offsets are allocated */ the offsets are allocated */
mem_heap_t** old_vers_heap, /* out: old version heap to use */
rec_t** old_vers, /* out: old version, or NULL if the rec_t** old_vers, /* out: old version, or NULL if the
record does not exist in the view: record does not exist in the view:
i.e., it was freshly inserted i.e., it was freshly inserted
...@@ -612,15 +613,15 @@ row_sel_build_prev_vers( ...@@ -612,15 +613,15 @@ row_sel_build_prev_vers(
{ {
ulint err; ulint err;
if (plan->old_vers_heap) { if (*old_vers_heap) {
mem_heap_empty(plan->old_vers_heap); mem_heap_empty(*old_vers_heap);
} else { } else {
plan->old_vers_heap = mem_heap_create(512); *old_vers_heap = mem_heap_create(512);
} }
err = row_vers_build_for_consistent_read( err = row_vers_build_for_consistent_read(
rec, mtr, plan->index, offsets, read_view, offset_heap, rec, mtr, index, offsets, read_view, offset_heap,
plan->old_vers_heap, old_vers); *old_vers_heap, old_vers);
return(err); return(err);
} }
...@@ -833,9 +834,11 @@ row_sel_get_clust_rec( ...@@ -833,9 +834,11 @@ row_sel_get_clust_rec(
if (!lock_clust_rec_cons_read_sees(clust_rec, index, offsets, if (!lock_clust_rec_cons_read_sees(clust_rec, index, offsets,
node->read_view)) { node->read_view)) {
err = row_sel_build_prev_vers(node->read_view, plan, err = row_sel_build_prev_vers(
clust_rec, &offsets, node->read_view, index, clust_rec,
&heap, &old_vers, mtr); &offsets, &heap, &plan->old_vers_heap,
&old_vers, mtr);
if (err != DB_SUCCESS) { if (err != DB_SUCCESS) {
goto err_exit; goto err_exit;
...@@ -1561,10 +1564,11 @@ skip_lock: ...@@ -1561,10 +1564,11 @@ skip_lock:
if (!lock_clust_rec_cons_read_sees(rec, index, offsets, if (!lock_clust_rec_cons_read_sees(rec, index, offsets,
node->read_view)) { node->read_view)) {
err = row_sel_build_prev_vers(node->read_view, err = row_sel_build_prev_vers(
plan, rec, node->read_view, index, rec,
&offsets, &heap, &offsets, &heap, &plan->old_vers_heap,
&old_vers, &mtr); &old_vers, &mtr);
if (err != DB_SUCCESS) { if (err != DB_SUCCESS) {
goto lock_wait_or_error; goto lock_wait_or_error;
...@@ -4626,6 +4630,11 @@ row_search_autoinc_read_column( ...@@ -4626,6 +4630,11 @@ row_search_autoinc_read_column(
value = *(ib_uint32_t*) dest; value = *(ib_uint32_t*) dest;
break; break;
case 3:
value = *(ib_uint32_t*) dest;
value &= 0xFFFFFF;
break;
case 2: case 2:
value = *(uint16 *) dest; value = *(uint16 *) dest;
break; break;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment