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(
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->hint_need_to_fetch_extra_cols = 0;
reset_template(prebuilt);
......@@ -7339,6 +7342,11 @@ ha_innobase::innobase_get_auto_increment(
{
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 {
error = innobase_autoinc_lock();
......@@ -7403,6 +7411,7 @@ ha_innobase::get_auto_increment(
ulonglong *first_value, /* out: the autoinc value */
ulonglong *nb_reserved_values) /* out: count of reserved values */
{
trx_t* trx;
ulint error;
ulonglong autoinc = 0;
......@@ -7429,37 +7438,34 @@ ha_innobase::get_auto_increment(
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
called and count down from that as rows are written (see write_row()).
*/
We make one exception, if the *first_value is precomputed by MySQL
we use that value. And set the number of reserved values to 1 if
this is the first time we were called for the SQL statement, this
will force MySQL to call us for the next value. If we are in the
middle of a multi-row insert we preserve the existing counter.*/
if (*first_value == 0) {
trx = prebuilt->trx;
/* Called for the first time ? */
if (prebuilt->trx->n_autoinc_rows == 0) {
/* Note: We can't rely on *first_value since some MySQL engines,
in particular the partition engine, don't initialize it to 0 when
invoking this method. So we are not sure if it's guaranteed to
be 0 or not. */
prebuilt->trx->n_autoinc_rows = nb_desired_values;
/* Called for the first time ? */
if (trx->n_autoinc_rows == 0) {
/* It's possible for nb_desired_values to be 0:
e.g., INSERT INTO T1(C) SELECT C FROM T2; */
if (nb_desired_values == 0) {
trx->n_autoinc_rows = nb_desired_values;
++prebuilt->trx->n_autoinc_rows;
}
/* It's possible for nb_desired_values to be 0:
e.g., INSERT INTO T1(C) SELECT C FROM T2; */
if (nb_desired_values == 0) {
trx->n_autoinc_rows = 1;
}
*first_value = autoinc;
} else if (prebuilt->trx->n_autoinc_rows == 0) {
prebuilt->trx->n_autoinc_rows = 1;
/* Not in the middle of a mult-row INSERT. */
} else if (prebuilt->last_value == 0) {
*first_value = autoinc;
}
ut_a(prebuilt->trx->n_autoinc_rows > 0);
*nb_reserved_values = prebuilt->trx->n_autoinc_rows;
*nb_reserved_values = trx->n_autoinc_rows;
/* With old style AUTOINC locking we only update the table's
AUTOINC counter after attempting to insert the row. */
......
......@@ -60,6 +60,14 @@ mem_heap_validate_or_print(
ulint* n_blocks); /* out: number of blocks in the heap,
if a NULL pointer is passed as this
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 */
#ifdef UNIV_DEBUG
/******************************************************************
......@@ -71,14 +79,6 @@ mem_heap_check(
/* out: TRUE if ok */
mem_heap_t* heap); /* in: memory heap */
#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
/*********************************************************************
TRUE if no memory is currently allocated. */
......
......@@ -292,8 +292,9 @@ mem_heap_free_heap_top(
mem_current_allocated_memory -= (total_size - size);
mutex_exit(&mem_hash_mutex);
#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 */
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
one */
......
......@@ -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_DESC(addr, size, b) VALGRIND_CREATE_BLOCK(addr, size, b)
# define UNIV_MEM_UNDESC(b) VALGRIND_DISCARD(b)
# define UNIV_MEM_ASSERT_RW(addr, size) \
VALGRIND_CHECK_MEM_IS_DEFINED(addr, size)
# define UNIV_MEM_ASSERT_W(addr, size) \
VALGRIND_CHECK_MEM_IS_ADDRESSABLE(addr, size)
# define UNIV_MEM_ASSERT_RW(addr, size) do { \
const void* _p = (const void*) \
VALGRIND_CHECK_MEM_IS_DEFINED(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
# define UNIV_MEM_VALID(addr, size) do {} while(0)
# define UNIV_MEM_INVALID(addr, size) do {} while(0)
......
......@@ -554,9 +554,7 @@ completed:
}
*error = FALSE;
}
#endif /* UNIV_MEM_DEBUG || UNIV_DEBUG */
#ifdef UNIV_DEBUG
/******************************************************************
Prints the contents of a memory heap. */
static
......@@ -582,20 +580,6 @@ mem_heap_print(
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. */
......@@ -622,6 +606,22 @@ mem_heap_validate(
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 */
#ifdef UNIV_MEM_DEBUG
......
......@@ -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 #
explain select * from t1 order by b;
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;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL # Using filesort
......
......@@ -598,12 +598,13 @@ row_sel_build_prev_vers(
/*====================*/
/* out: DB_SUCCESS or error code */
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 */
ulint** offsets, /* in/out: offsets returned by
rec_get_offsets(rec, plan->index) */
mem_heap_t** offset_heap, /* in/out: memory heap from which
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
record does not exist in the view:
i.e., it was freshly inserted
......@@ -612,15 +613,15 @@ row_sel_build_prev_vers(
{
ulint err;
if (plan->old_vers_heap) {
mem_heap_empty(plan->old_vers_heap);
if (*old_vers_heap) {
mem_heap_empty(*old_vers_heap);
} else {
plan->old_vers_heap = mem_heap_create(512);
*old_vers_heap = mem_heap_create(512);
}
err = row_vers_build_for_consistent_read(
rec, mtr, plan->index, offsets, read_view, offset_heap,
plan->old_vers_heap, old_vers);
rec, mtr, index, offsets, read_view, offset_heap,
*old_vers_heap, old_vers);
return(err);
}
......@@ -833,9 +834,11 @@ row_sel_get_clust_rec(
if (!lock_clust_rec_cons_read_sees(clust_rec, index, offsets,
node->read_view)) {
err = row_sel_build_prev_vers(node->read_view, plan,
clust_rec, &offsets,
&heap, &old_vers, mtr);
err = row_sel_build_prev_vers(
node->read_view, index, clust_rec,
&offsets, &heap, &plan->old_vers_heap,
&old_vers, mtr);
if (err != DB_SUCCESS) {
goto err_exit;
......@@ -1561,10 +1564,11 @@ skip_lock:
if (!lock_clust_rec_cons_read_sees(rec, index, offsets,
node->read_view)) {
err = row_sel_build_prev_vers(node->read_view,
plan, rec,
&offsets, &heap,
&old_vers, &mtr);
err = row_sel_build_prev_vers(
node->read_view, index, rec,
&offsets, &heap, &plan->old_vers_heap,
&old_vers, &mtr);
if (err != DB_SUCCESS) {
goto lock_wait_or_error;
......@@ -4626,6 +4630,11 @@ row_search_autoinc_read_column(
value = *(ib_uint32_t*) dest;
break;
case 3:
value = *(ib_uint32_t*) dest;
value &= 0xFFFFFF;
break;
case 2:
value = *(uint16 *) dest;
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