diff options
Diffstat (limited to 'sql/sql_handler.cc')
-rw-r--r-- | sql/sql_handler.cc | 73 |
1 files changed, 42 insertions, 31 deletions
diff --git a/sql/sql_handler.cc b/sql/sql_handler.cc index 89090c9fa63..bced29e1e81 100644 --- a/sql/sql_handler.cc +++ b/sql/sql_handler.cc @@ -87,7 +87,7 @@ static int mysql_ha_flush_table(THD *thd, TABLE **table_ptr, uint mode_flags); Pointer to the TABLE_LIST struct. */ -static char *mysql_ha_hash_get_key(TABLE_LIST *tables, uint *key_len_p, +static char *mysql_ha_hash_get_key(TABLE_LIST *tables, size_t *key_len_p, my_bool first __attribute__((unused))) { *key_len_p= strlen(tables->alias) + 1 ; /* include '\0' in comparisons */ @@ -201,7 +201,7 @@ bool mysql_ha_open(THD *thd, TABLE_LIST *tables, bool reopen) } else if (! reopen) /* Otherwise we have 'tables' already. */ { - if (hash_search(&thd->handler_tables_hash, (byte*) tables->alias, + if (hash_search(&thd->handler_tables_hash, (uchar*) tables->alias, strlen(tables->alias) + 1)) { DBUG_PRINT("info",("duplicate '%s'", tables->alias)); @@ -229,7 +229,6 @@ bool mysql_ha_open(THD *thd, TABLE_LIST *tables, bool reopen) /* for now HANDLER can be used only for real TABLES */ tables->required_type= FRMTYPE_TABLE; error= open_tables(thd, &tables, &counter, 0); - /* restore the state and merge the opened table into handler_tables list */ thd->handler_tables= thd->open_tables ? thd->open_tables->next= backup_handler_tables, @@ -240,7 +239,7 @@ bool mysql_ha_open(THD *thd, TABLE_LIST *tables, bool reopen) goto err; /* There can be only one table in '*tables'. */ - if (! (tables->table->file->table_flags() & HA_CAN_SQL_HANDLER)) + if (! (tables->table->file->ha_table_flags() & HA_CAN_SQL_HANDLER)) { if (! reopen) my_error(ER_ILLEGAL_HA, MYF(0), tables->alias); @@ -254,10 +253,10 @@ bool mysql_ha_open(THD *thd, TABLE_LIST *tables, bool reopen) namelen= strlen(tables->table_name) + 1; aliaslen= strlen(tables->alias) + 1; if (!(my_multi_malloc(MYF(MY_WME), - &hash_tables, sizeof(*hash_tables), - &db, dblen, - &name, namelen, - &alias, aliaslen, + &hash_tables, (uint) sizeof(*hash_tables), + &db, (uint) dblen, + &name, (uint) namelen, + &alias, (uint) aliaslen, NullS))) goto err; /* structure copy */ @@ -270,7 +269,7 @@ bool mysql_ha_open(THD *thd, TABLE_LIST *tables, bool reopen) memcpy(hash_tables->alias, tables->alias, aliaslen); /* add to hash */ - if (my_hash_insert(&thd->handler_tables_hash, (byte*) hash_tables)) + if (my_hash_insert(&thd->handler_tables_hash, (uchar*) hash_tables)) goto err; } @@ -314,11 +313,11 @@ bool mysql_ha_close(THD *thd, TABLE_LIST *tables) tables->db, tables->table_name, tables->alias)); if ((hash_tables= (TABLE_LIST*) hash_search(&thd->handler_tables_hash, - (byte*) tables->alias, + (uchar*) tables->alias, strlen(tables->alias) + 1))) { mysql_ha_close_table(thd, hash_tables); - hash_delete(&thd->handler_tables_hash, (byte*) hash_tables); + hash_delete(&thd->handler_tables_hash, (uchar*) hash_tables); } else { @@ -368,7 +367,7 @@ bool mysql_ha_read(THD *thd, TABLE_LIST *tables, String buffer(buff, sizeof(buff), system_charset_info); int error, keyno= -1; uint num_rows; - byte *key; + uchar *key; uint key_len; bool need_reopen; DBUG_ENTER("mysql_ha_read"); @@ -386,13 +385,13 @@ bool mysql_ha_read(THD *thd, TABLE_LIST *tables, retry: if ((hash_tables= (TABLE_LIST*) hash_search(&thd->handler_tables_hash, - (byte*) tables->alias, + (uchar*) tables->alias, strlen(tables->alias) + 1))) { table= hash_tables->table; - DBUG_PRINT("info-in-hash",("'%s'.'%s' as '%s' tab %p", + DBUG_PRINT("info-in-hash",("'%s'.'%s' as '%s' table: 0x%lx", hash_tables->db, hash_tables->table_name, - hash_tables->alias, table)); + hash_tables->alias, (long) table)); if (!table) { /* @@ -426,7 +425,8 @@ retry: #if MYSQL_VERSION_ID < 40100 char buff[MAX_DBKEY_LENGTH]; if (*tables->db) - strxnmov(buff, sizeof(buff), tables->db, ".", tables->table_name, NullS); + strxnmov(buff, sizeof(buff)-1, tables->db, ".", tables->table_name, + NullS); else strncpy(buff, tables->alias, sizeof(buff)); my_error(ER_UNKNOWN_TABLE, MYF(0), buff, "HANDLER"); @@ -463,6 +463,9 @@ retry: if (!lock) goto err0; // mysql_lock_tables() printed error message already + // Always read all columns + tables->table->read_set= &tables->table->s->all_set; + if (cond) { if (table->query_id != thd->query_id) @@ -511,7 +514,7 @@ retry: if (keyname) { table->file->ha_index_or_rnd_end(); - table->file->ha_index_init(keyno); + table->file->ha_index_init(keyno, 1); error= table->file->index_first(table->record[0]); } else @@ -533,7 +536,7 @@ retry: case RLAST: DBUG_ASSERT(keyname != 0); table->file->ha_index_or_rnd_end(); - table->file->ha_index_init(keyno); + table->file->ha_index_init(keyno, 1); error= table->file->index_last(table->record[0]); mode=RPREV; break; @@ -554,8 +557,10 @@ retry: } List_iterator<Item> it_ke(*key_expr); Item *item; - for (key_len=0 ; (item=it_ke++) ; key_part++) + key_part_map keypart_map; + for (keypart_map= key_len=0 ; (item=it_ke++) ; key_part++) { + my_bitmap_map *old_map; // 'item' can be changed by fix_fields() call if ((!item->fixed && item->fix_fields(thd, it_ke.ref())) || @@ -566,16 +571,20 @@ retry: my_error(ER_WRONG_ARGUMENTS,MYF(0),"HANDLER ... READ"); goto err; } + old_map= dbug_tmp_use_all_columns(table, table->write_set); (void) item->save_in_field(key_part->field, 1); + dbug_tmp_restore_column_map(table->write_set, old_map); key_len+=key_part->store_length; + keypart_map= (keypart_map << 1) | 1; } - if (!(key= (byte*) thd->calloc(ALIGN_SIZE(key_len)))) + + if (!(key= (uchar*) thd->calloc(ALIGN_SIZE(key_len)))) goto err; table->file->ha_index_or_rnd_end(); - table->file->ha_index_init(keyno); + table->file->ha_index_init(keyno, 1); key_copy(key, table->record[0], table->key_info + keyno, key_len); - error= table->file->index_read(table->record[0], - key,key_len,ha_rkey_mode); + error= table->file->index_read_map(table->record[0], + key, keypart_map, ha_rkey_mode); mode=rkey_to_rnext[(int)ha_rkey_mode]; break; } @@ -667,7 +676,8 @@ int mysql_ha_flush(THD *thd, TABLE_LIST *tables, uint mode_flags, TABLE **table_ptr; bool did_lock= FALSE; DBUG_ENTER("mysql_ha_flush"); - DBUG_PRINT("enter", ("tables: %p mode_flags: 0x%02x", tables, mode_flags)); + DBUG_PRINT("enter", ("tables: 0x%lx mode_flags: 0x%02x", + (long) tables, mode_flags)); if (tables) { @@ -682,14 +692,15 @@ int mysql_ha_flush(THD *thd, TABLE_LIST *tables, uint mode_flags, while (*table_ptr) { if ((!*tmp_tables->db || - !my_strcasecmp(&my_charset_latin1, (*table_ptr)->s->db, + !my_strcasecmp(&my_charset_latin1, (*table_ptr)->s->db.str, tmp_tables->db)) && - ! my_strcasecmp(&my_charset_latin1, (*table_ptr)->s->table_name, + ! my_strcasecmp(&my_charset_latin1, + (*table_ptr)->s->table_name.str, tmp_tables->table_name)) { DBUG_PRINT("info",("*table_ptr '%s'.'%s' as '%s'", - (*table_ptr)->s->db, - (*table_ptr)->s->table_name, + (*table_ptr)->s->db.str, + (*table_ptr)->s->table_name.str, (*table_ptr)->alias)); /* The first time it is required, lock for close_thread_table(). */ if (! did_lock && ! is_locked) @@ -759,17 +770,17 @@ static int mysql_ha_flush_table(THD *thd, TABLE **table_ptr, uint mode_flags) TABLE *table= *table_ptr; DBUG_ENTER("mysql_ha_flush_table"); DBUG_PRINT("enter",("'%s'.'%s' as '%s' flags: 0x%02x", - table->s->db, table->s->table_name, + table->s->db.str, table->s->table_name.str, table->alias, mode_flags)); if ((hash_tables= (TABLE_LIST*) hash_search(&thd->handler_tables_hash, - (byte*) table->alias, + (uchar*) table->alias, strlen(table->alias) + 1))) { if (! (mode_flags & MYSQL_HA_REOPEN_ON_USAGE)) { /* This is a final close. Remove from hash. */ - hash_delete(&thd->handler_tables_hash, (byte*) hash_tables); + hash_delete(&thd->handler_tables_hash, (uchar*) hash_tables); } else { |