diff options
Diffstat (limited to 'storage/innobase/api/api0api.cc')
-rw-r--r-- | storage/innobase/api/api0api.cc | 137 |
1 files changed, 113 insertions, 24 deletions
diff --git a/storage/innobase/api/api0api.cc b/storage/innobase/api/api0api.cc index 5f9762a1846..647ebcde6f0 100644 --- a/storage/innobase/api/api0api.cc +++ b/storage/innobase/api/api0api.cc @@ -1,6 +1,6 @@ /***************************************************************************** -Copyright (c) 2008, 2012, Oracle and/or its affiliates. All Rights Reserved. +Copyright (c) 2008, 2013, Oracle and/or its affiliates. All Rights Reserved. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software @@ -245,7 +245,7 @@ ib_open_table_by_id( dict_mutex_enter_for_mysql(); } - table = dict_table_open_on_id(table_id, FALSE, FALSE); + table = dict_table_open_on_id(table_id, FALSE, DICT_TABLE_OP_NORMAL); if (table != NULL && table->ibd_file_missing) { table = NULL; @@ -1183,7 +1183,7 @@ ib_cursor_open_index_using_name( /* We want to increment the ref count, so we do a redundant search. */ table = dict_table_open_on_id(cursor->prebuilt->table->id, - FALSE, FALSE); + FALSE, DICT_TABLE_OP_NORMAL); ut_a(table != NULL); /* The first index is always the cluster index. */ @@ -1630,6 +1630,8 @@ ib_cursor_insert_row( src_tuple->index->table, q_proc->grph.ins, node->ins); } + srv_active_wake_master_thread(); + return(err); } @@ -1914,6 +1916,8 @@ ib_cursor_update_row( err = ib_execute_update_query_graph(cursor, pcur); } + srv_active_wake_master_thread(); + return(err); } @@ -2039,6 +2043,8 @@ ib_cursor_delete_row( err = DB_RECORD_NOT_FOUND; } + srv_active_wake_master_thread(); + return(err); } @@ -2296,12 +2302,14 @@ ib_col_set_value( ib_tpl_t ib_tpl, /*!< in: tuple instance */ ib_ulint_t col_no, /*!< in: column index in tuple */ const void* src, /*!< in: data value */ - ib_ulint_t len) /*!< in: data value len */ + ib_ulint_t len, /*!< in: data value len */ + ib_bool_t need_cpy) /*!< in: if need memcpy */ { const dtype_t* dtype; dfield_t* dfield; void* dst = NULL; ib_tuple_t* tuple = (ib_tuple_t*) ib_tpl; + ulint col_len; dfield = ib_col_get_dfield(tuple, col_no); @@ -2312,6 +2320,7 @@ ib_col_set_value( } dtype = dfield_get_type(dfield); + col_len = dtype_get_len(dtype); /* Not allowed to update system columns. */ if (dtype_get_mtype(dtype) == DATA_SYS) { @@ -2325,10 +2334,10 @@ ib_col_set_value( for that. */ if (ib_col_is_capped(dtype)) { - len = ut_min(len, dtype_get_len(dtype)); + len = ut_min(len, col_len); if (dst == NULL || len > dfield_get_len(dfield)) { - dst = mem_heap_alloc(tuple->heap, dtype_get_len(dtype)); + dst = mem_heap_alloc(tuple->heap, col_len); ut_a(dst != NULL); } } else if (dst == NULL || len > dfield_get_len(dfield)) { @@ -2342,7 +2351,7 @@ ib_col_set_value( switch (dtype_get_mtype(dtype)) { case DATA_INT: { - if (dtype_get_len(dtype) == len) { + if (col_len == len) { ibool usign; usign = dtype_get_prtype(dtype) & DATA_UNSIGNED; @@ -2387,22 +2396,96 @@ ib_col_set_value( memset((byte*) dst + len, pad_char, - dtype_get_len(dtype) - len); + col_len - len); memcpy(dst, src, len); - len = dtype_get_len(dtype); + len = col_len; break; } case DATA_BLOB: case DATA_BINARY: - case DATA_MYSQL: case DATA_DECIMAL: case DATA_VARCHAR: - case DATA_VARMYSQL: case DATA_FIXBINARY: + if (need_cpy) { + memcpy(dst, src, len); + } else { + dfield_set_data(dfield, src, len); + dst = dfield_get_data(dfield); + } + break; + + case DATA_MYSQL: + case DATA_VARMYSQL: { + ulint cset; + CHARSET_INFO* cs; + int error = 0; + ulint true_len = len; + + /* For multi byte character sets we need to + calculate the true length of the data. */ + cset = dtype_get_charset_coll( + dtype_get_prtype(dtype)); + cs = all_charsets[cset]; + if (cs) { + uint pos = (uint)(col_len / cs->mbmaxlen); + + if (len > 0 && cs->mbmaxlen > 1) { + true_len = (ulint) + cs->cset->well_formed_len( + cs, + (const char*)src, + (const char*)src + len, + pos, + &error); + + if (true_len < len) { + len = true_len; + } + } + } + + /* All invalid bytes in data need be truncated. + If len == 0, means all bytes of the data is invalid. + In this case, the data will be truncated to empty.*/ memcpy(dst, src, len); + + /* For DATA_MYSQL, need to pad the unused + space with spaces. */ + if (dtype_get_mtype(dtype) == DATA_MYSQL) { + ulint n_chars; + + if (len < col_len) { + ulint pad_len = col_len - len; + + ut_a(cs != NULL); + ut_a(!(pad_len % cs->mbminlen)); + + cs->cset->fill(cs, (char*)dst + len, + pad_len, + 0x20 /* space */); + } + + /* Why we should do below? See function + row_mysql_store_col_in_innobase_format */ + + 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 + && ((char*)dst)[col_len - 1] == 0x20) { + col_len--; + } + + len = col_len; + } break; + } default: ut_error; @@ -2476,7 +2559,9 @@ ib_col_copy_value_low( data_len, usign); if (usign) { - if (len == 2) { + if (len == 1) { + *(ib_i8_t*)dst = (ib_i8_t)ret; + } else if (len == 2) { *(ib_i16_t*)dst = (ib_i16_t)ret; } else if (len == 4) { *(ib_i32_t*)dst = (ib_i32_t)ret; @@ -2484,7 +2569,9 @@ ib_col_copy_value_low( *(ib_i64_t*)dst = (ib_i64_t)ret; } } else { - if (len == 2) { + if (len == 1) { + *(ib_u8_t*)dst = (ib_i8_t)ret; + } else if (len == 2) { *(ib_u16_t*)dst = (ib_i16_t)ret; } else if (len == 4) { *(ib_u32_t*)dst = (ib_i32_t)ret; @@ -3450,7 +3537,7 @@ ib_tuple_write_int( return(DB_DATA_MISMATCH); } - return(ib_col_set_value(ib_tpl, col_no, value, type_len)); + return(ib_col_set_value(ib_tpl, col_no, value, type_len, true)); } /*****************************************************************//** @@ -3465,7 +3552,7 @@ ib_tuple_write_i8( int col_no, /*!< in: column number */ ib_i8_t val) /*!< in: value to write */ { - return(ib_col_set_value(ib_tpl, col_no, &val, sizeof(val))); + return(ib_col_set_value(ib_tpl, col_no, &val, sizeof(val), true)); } /*****************************************************************//** @@ -3480,7 +3567,7 @@ ib_tuple_write_i16( int col_no, /*!< in: column number */ ib_i16_t val) /*!< in: value to write */ { - return(ib_col_set_value(ib_tpl, col_no, &val, sizeof(val))); + return(ib_col_set_value(ib_tpl, col_no, &val, sizeof(val), true)); } /*****************************************************************//** @@ -3495,7 +3582,7 @@ ib_tuple_write_i32( int col_no, /*!< in: column number */ ib_i32_t val) /*!< in: value to write */ { - return(ib_col_set_value(ib_tpl, col_no, &val, sizeof(val))); + return(ib_col_set_value(ib_tpl, col_no, &val, sizeof(val), true)); } /*****************************************************************//** @@ -3510,7 +3597,7 @@ ib_tuple_write_i64( int col_no, /*!< in: column number */ ib_i64_t val) /*!< in: value to write */ { - return(ib_col_set_value(ib_tpl, col_no, &val, sizeof(val))); + return(ib_col_set_value(ib_tpl, col_no, &val, sizeof(val), true)); } /*****************************************************************//** @@ -3525,7 +3612,7 @@ ib_tuple_write_u8( int col_no, /*!< in: column number */ ib_u8_t val) /*!< in: value to write */ { - return(ib_col_set_value(ib_tpl, col_no, &val, sizeof(val))); + return(ib_col_set_value(ib_tpl, col_no, &val, sizeof(val), true)); } /*****************************************************************//** @@ -3540,7 +3627,7 @@ ib_tuple_write_u16( int col_no, /*!< in: column number */ ib_u16_t val) /*!< in: value to write */ { - return(ib_col_set_value(ib_tpl, col_no, &val, sizeof(val))); + return(ib_col_set_value(ib_tpl, col_no, &val, sizeof(val), true)); } /*****************************************************************//** @@ -3555,7 +3642,7 @@ ib_tuple_write_u32( int col_no, /*!< in: column number */ ib_u32_t val) /*!< in: value to write */ { - return(ib_col_set_value(ib_tpl, col_no, &val, sizeof(val))); + return(ib_col_set_value(ib_tpl, col_no, &val, sizeof(val), true)); } /*****************************************************************//** @@ -3570,7 +3657,7 @@ ib_tuple_write_u64( int col_no, /*!< in: column number */ ib_u64_t val) /*!< in: value to write */ { - return(ib_col_set_value(ib_tpl, col_no, &val, sizeof(val))); + return(ib_col_set_value(ib_tpl, col_no, &val, sizeof(val), true)); } /*****************************************************************//** @@ -3603,7 +3690,8 @@ ib_tuple_write_double( dfield = ib_col_get_dfield(tuple, col_no); if (dtype_get_mtype(dfield_get_type(dfield)) == DATA_DOUBLE) { - return(ib_col_set_value(ib_tpl, col_no, &val, sizeof(val))); + return(ib_col_set_value(ib_tpl, col_no, + &val, sizeof(val), true)); } else { return(DB_DATA_MISMATCH); } @@ -3653,7 +3741,8 @@ ib_tuple_write_float( dfield = ib_col_get_dfield(tuple, col_no); if (dtype_get_mtype(dfield_get_type(dfield)) == DATA_FLOAT) { - return(ib_col_set_value(ib_tpl, col_no, &val, sizeof(val))); + return(ib_col_set_value(ib_tpl, col_no, + &val, sizeof(val), true)); } else { return(DB_DATA_MISMATCH); } |