diff options
author | unknown <monty@donna.mysql.fi> | 2001-03-06 15:26:13 +0200 |
---|---|---|
committer | unknown <monty@donna.mysql.fi> | 2001-03-06 15:26:13 +0200 |
commit | a9c60a41feb2189e270c41def107d40c1f00b8b5 (patch) | |
tree | ac4bcd8007addf9ae2a4501364bc413b0e1667b8 /sql | |
parent | 277d59b86e14fc5443bc5a87fc399ee2d5491069 (diff) | |
parent | 869c89feaaf82d0f44b2a48db0099aae87b4732f (diff) | |
download | mariadb-git-a9c60a41feb2189e270c41def107d40c1f00b8b5.tar.gz |
Merge work:/my/mysql into donna.mysql.fi:/home/my/bk/mysql
Docs/manual.texi:
Auto merged
sql/ha_innobase.cc:
Auto merged
sql/sql_select.cc:
Auto merged
Diffstat (limited to 'sql')
-rw-r--r-- | sql/field.h | 2 | ||||
-rw-r--r-- | sql/ha_berkeley.cc | 68 | ||||
-rw-r--r-- | sql/ha_innobase.cc | 6 | ||||
-rw-r--r-- | sql/ha_myisammrg.cc | 31 | ||||
-rw-r--r-- | sql/ha_myisammrg.h | 1 | ||||
-rw-r--r-- | sql/handler.cc | 112 | ||||
-rw-r--r-- | sql/handler.h | 6 | ||||
-rw-r--r-- | sql/key.cc | 4 | ||||
-rw-r--r-- | sql/mysql_priv.h | 8 | ||||
-rw-r--r-- | sql/mysqld.cc | 1 | ||||
-rw-r--r-- | sql/opt_range.cc | 6 | ||||
-rw-r--r-- | sql/opt_sum.cc | 11 | ||||
-rw-r--r-- | sql/sql_class.cc | 24 | ||||
-rw-r--r-- | sql/sql_insert.cc | 8 | ||||
-rw-r--r-- | sql/sql_parse.cc | 94 | ||||
-rw-r--r-- | sql/sql_select.cc | 8 | ||||
-rw-r--r-- | sql/sql_yacc.yy | 6 | ||||
-rw-r--r-- | sql/table.cc | 19 |
18 files changed, 259 insertions, 156 deletions
diff --git a/sql/field.h b/sql/field.h index 09ce80db615..30b2945d006 100644 --- a/sql/field.h +++ b/sql/field.h @@ -45,7 +45,7 @@ public: uint8 null_bit; // And position to it struct st_table *table; // Pointer for table ulong query_id; // For quick test of used fields - key_map key_start,part_of_key; // Key is part of these keys. + key_map key_start,part_of_key,part_of_sortkey;// Field is part of these keys. const char *table_name,*field_name; utype unireg_check; uint32 field_length; // Length of field diff --git a/sql/ha_berkeley.cc b/sql/ha_berkeley.cc index ea9f492a9c8..af66f9ebf96 100644 --- a/sql/ha_berkeley.cc +++ b/sql/ha_berkeley.cc @@ -459,7 +459,7 @@ int ha_berkeley::open(const char *name, int mode, uint test_if_locked) key_used_on_scan=primary_key; /* Need some extra memory in case of packed keys */ - uint max_key_length= table->max_key_length + MAX_REF_PARTS*2; + uint max_key_length= table->max_key_length + MAX_REF_PARTS*3; if (!(alloc_ptr= my_multi_malloc(MYF(MY_WME), &key_buff, max_key_length, @@ -469,8 +469,9 @@ int ha_berkeley::open(const char *name, int mode, uint test_if_locked) table->key_info[table->primary_key].key_length), NullS))) DBUG_RETURN(1); /* purecov: inspected */ - if (!(rec_buff=my_malloc((alloced_rec_buff_length=table->rec_buff_length), - MYF(MY_WME)))) + if (!(rec_buff= (byte*) my_malloc((alloced_rec_buff_length= + table->rec_buff_length), + MYF(MY_WME)))) { my_free(alloc_ptr,MYF(0)); /* purecov: inspected */ DBUG_RETURN(1); /* purecov: inspected */ @@ -479,7 +480,7 @@ int ha_berkeley::open(const char *name, int mode, uint test_if_locked) /* Init shared structure */ if (!(share=get_share(name,table))) { - my_free(rec_buff,MYF(0)); /* purecov: inspected */ + my_free((char*) rec_buff,MYF(0)); /* purecov: inspected */ my_free(alloc_ptr,MYF(0)); /* purecov: inspected */ DBUG_RETURN(1); /* purecov: inspected */ } @@ -496,7 +497,7 @@ int ha_berkeley::open(const char *name, int mode, uint test_if_locked) if ((error=db_create(&file, db_env, 0))) { free_share(share,table, hidden_primary_key,1); /* purecov: inspected */ - my_free(rec_buff,MYF(0)); /* purecov: inspected */ + my_free((char*) rec_buff,MYF(0)); /* purecov: inspected */ my_free(alloc_ptr,MYF(0)); /* purecov: inspected */ my_errno=error; /* purecov: inspected */ DBUG_RETURN(1); /* purecov: inspected */ @@ -513,7 +514,7 @@ int ha_berkeley::open(const char *name, int mode, uint test_if_locked) "main", DB_BTREE, open_mode,0)))) { free_share(share,table, hidden_primary_key,1); /* purecov: inspected */ - my_free(rec_buff,MYF(0)); /* purecov: inspected */ + my_free((char*) rec_buff,MYF(0)); /* purecov: inspected */ my_free(alloc_ptr,MYF(0)); /* purecov: inspected */ my_errno=error; /* purecov: inspected */ DBUG_RETURN(1); /* purecov: inspected */ @@ -583,7 +584,7 @@ int ha_berkeley::close(void) { DBUG_ENTER("ha_berkeley::close"); - my_free(rec_buff,MYF(MY_ALLOW_ZERO_PTR)); + my_free((char*) rec_buff,MYF(MY_ALLOW_ZERO_PTR)); my_free(alloc_ptr,MYF(MY_ALLOW_ZERO_PTR)); ha_berkeley::extra(HA_EXTRA_RESET); // current_row buffer DBUG_RETURN(free_share(share,table, hidden_primary_key,0)); @@ -613,7 +614,7 @@ ulong ha_berkeley::max_row_length(const byte *buf) { ulong length=table->reclength + table->fields*2; for (Field_blob **ptr=table->blob_field ; *ptr ; ptr++) - length+= (*ptr)->get_length(buf+(*ptr)->offset())+2; + length+= (*ptr)->get_length((char*) buf+(*ptr)->offset())+2; return length; } @@ -654,7 +655,8 @@ int ha_berkeley::pack_row(DBT *row, const byte *record, bool new_row) byte *ptr=rec_buff + table->null_bytes; for (Field **field=table->field ; *field ; field++) - ptr=(byte*) (*field)->pack((char*) ptr,record + (*field)->offset()); + ptr=(byte*) (*field)->pack((char*) ptr, + (char*) record + (*field)->offset()); if (hidden_primary_key) { @@ -753,7 +755,7 @@ DBT *ha_berkeley::create_key(DBT *key, uint keynr, char *buff, } *buff++ = 1; // Store NOT NULL marker } - buff=key_part->field->pack_key(buff,record + key_part->offset, + buff=key_part->field->pack_key(buff,(char*) (record + key_part->offset), key_part->length); key_length-=key_part->length; } @@ -792,7 +794,7 @@ DBT *ha_berkeley::pack_key(DBT *key, uint keynr, char *buff, } offset=1; // Data is at key_ptr+1 } - buff=key_part->field->pack_key_from_key_image(buff,key_ptr+offset, + buff=key_part->field->pack_key_from_key_image(buff,(char*) key_ptr+offset, key_part->length); key_ptr+=key_part->store_length; key_length-=key_part->store_length; @@ -928,8 +930,8 @@ int ha_berkeley::key_cmp(uint keynr, const byte * old_row, if (key_part->key_part_flag & (HA_BLOB_PART | HA_VAR_LENGTH)) { - if (key_part->field->cmp_binary(old_row + key_part->offset, - new_row + key_part->offset, + if (key_part->field->cmp_binary((char*) (old_row + key_part->offset), + (char*) (new_row + key_part->offset), (ulong) key_part->length)) return 1; } @@ -1007,6 +1009,7 @@ int ha_berkeley::restore_keys(DB_TXN *trans, key_map changed_keys, { int error; DBT tmp_key; + uint keynr; DBUG_ENTER("restore_keys"); /* Restore the old primary key, and the old row, but don't ignore @@ -1020,7 +1023,7 @@ int ha_berkeley::restore_keys(DB_TXN *trans, key_map changed_keys, rolled back. The last key set in changed_keys is the one that triggered the duplicate key error (it wasn't inserted), so for that one just put back the old value. */ - for (uint keynr=0; changed_keys; keynr++, changed_keys >>= 1) + for (keynr=0; changed_keys; keynr++, changed_keys >>= 1) { if (changed_keys & 1) { @@ -1387,7 +1390,7 @@ int ha_berkeley::index_read_idx(byte * buf, uint keynr, const byte * key, pack_key(&last_key, keynr, key_buff, key, key_len), ¤t_row,0), - buf, keynr, ¤t_row, &last_key, 0)); + (char*) buf, keynr, ¤t_row, &last_key, 0)); } @@ -1401,7 +1404,7 @@ int ha_berkeley::index_read(byte * buf, const byte * key, statistic_increment(ha_read_key_count,&LOCK_status); bzero((char*) &row,sizeof(row)); - if (key_len == key_info->key_length + key_info->extra_length) + if (key_len == key_info->key_length) { error=read_row(cursor->c_get(cursor, pack_key(&last_key, active_index, @@ -1410,7 +1413,7 @@ int ha_berkeley::index_read(byte * buf, const byte * key, &row, (find_flag == HA_READ_KEY_EXACT ? DB_SET : DB_SET_RANGE)), - buf, active_index, &row, (DBT*) 0, 0); + (char*) buf, active_index, &row, (DBT*) 0, 0); } else { @@ -1420,7 +1423,7 @@ int ha_berkeley::index_read(byte * buf, const byte * key, memcpy(key_buff2, key_buff, (key_len=last_key.size)); key_info->handler.bdb_return_if_eq= -1; error=read_row(cursor->c_get(cursor, &last_key, &row, DB_SET_RANGE), - buf, active_index, &row, (DBT*) 0, 0); + (char*) buf, active_index, &row, (DBT*) 0, 0); key_info->handler.bdb_return_if_eq= 0; if (!error && find_flag == HA_READ_KEY_EXACT) { @@ -1440,7 +1443,7 @@ int ha_berkeley::index_next(byte * buf) statistic_increment(ha_read_next_count,&LOCK_status); bzero((char*) &row,sizeof(row)); DBUG_RETURN(read_row(cursor->c_get(cursor, &last_key, &row, DB_NEXT), - buf, active_index, &row, &last_key, 1)); + (char*) buf, active_index, &row, &last_key, 1)); } int ha_berkeley::index_next_same(byte * buf, const byte *key, uint keylen) @@ -1452,11 +1455,11 @@ int ha_berkeley::index_next_same(byte * buf, const byte *key, uint keylen) bzero((char*) &row,sizeof(row)); if (keylen == table->key_info[active_index].key_length) error=read_row(cursor->c_get(cursor, &last_key, &row, DB_NEXT_DUP), - buf, active_index, &row, &last_key, 1); + (char*) buf, active_index, &row, &last_key, 1); else { error=read_row(cursor->c_get(cursor, &last_key, &row, DB_NEXT), - buf, active_index, &row, &last_key, 1); + (char*) buf, active_index, &row, &last_key, 1); if (!error && ::key_cmp(table, key, active_index, keylen)) error=HA_ERR_END_OF_FILE; } @@ -1471,7 +1474,7 @@ int ha_berkeley::index_prev(byte * buf) statistic_increment(ha_read_prev_count,&LOCK_status); bzero((char*) &row,sizeof(row)); DBUG_RETURN(read_row(cursor->c_get(cursor, &last_key, &row, DB_PREV), - buf, active_index, &row, &last_key, 1)); + (char*) buf, active_index, &row, &last_key, 1)); } @@ -1482,7 +1485,7 @@ int ha_berkeley::index_first(byte * buf) statistic_increment(ha_read_first_count,&LOCK_status); bzero((char*) &row,sizeof(row)); DBUG_RETURN(read_row(cursor->c_get(cursor, &last_key, &row, DB_FIRST), - buf, active_index, &row, &last_key, 0)); + (char*) buf, active_index, &row, &last_key, 0)); } int ha_berkeley::index_last(byte * buf) @@ -1492,7 +1495,7 @@ int ha_berkeley::index_last(byte * buf) statistic_increment(ha_read_last_count,&LOCK_status); bzero((char*) &row,sizeof(row)); DBUG_RETURN(read_row(cursor->c_get(cursor, &last_key, &row, DB_LAST), - buf, active_index, &row, &last_key, 0)); + (char*) buf, active_index, &row, &last_key, 0)); } int ha_berkeley::rnd_init(bool scan) @@ -1513,7 +1516,7 @@ int ha_berkeley::rnd_next(byte *buf) statistic_increment(ha_read_rnd_next_count,&LOCK_status); bzero((char*) &row,sizeof(row)); DBUG_RETURN(read_row(cursor->c_get(cursor, &last_key, &row, DB_NEXT), - buf, active_index, &row, &last_key, 1)); + (char*) buf, active_index, &row, &last_key, 1)); } @@ -1530,7 +1533,7 @@ DBT *ha_berkeley::get_pos(DBT *to, byte *pos) KEY_PART_INFO *end=key_part+table->key_info[primary_key].key_parts; for ( ; key_part != end ; key_part++) - pos+=key_part->field->packed_col_length(pos); + pos+=key_part->field->packed_col_length((char*) pos); to->size= (uint) (pos- (byte*) to->data); } return to; @@ -1545,7 +1548,7 @@ int ha_berkeley::rnd_pos(byte * buf, byte *pos) return read_row(file->get(file, transaction, get_pos(&db_pos, pos), ¤t_row, 0), - buf, active_index, ¤t_row, (DBT*) 0, 0); + (char*) buf, active_index, ¤t_row, (DBT*) 0, 0); } void ha_berkeley::position(const byte *record) @@ -1554,7 +1557,7 @@ void ha_berkeley::position(const byte *record) if (hidden_primary_key) memcpy_fixed(ref, (char*) current_ident, BDB_HIDDEN_PRIMARY_KEY_LENGTH); else - create_key(&key, primary_key, ref, record); + create_key(&key, primary_key, (char*) ref, record); } @@ -1928,7 +1931,7 @@ longlong ha_berkeley::get_auto_increment() &last_key)) { error=0; // Found value - unpack_key(table->record[1], &last_key, active_index); + unpack_key((char*) table->record[1], &last_key, active_index); } } } @@ -2105,7 +2108,8 @@ static BDB_SHARE *get_share(const char *table_name, TABLE *table) BDB_SHARE *share; pthread_mutex_lock(&bdb_mutex); uint length=(uint) strlen(table_name); - if (!(share=(BDB_SHARE*) hash_search(&bdb_open_tables, table_name, length))) + if (!(share=(BDB_SHARE*) hash_search(&bdb_open_tables, (byte*) table_name, + length))) { ha_rows *rec_per_key; char *tmp_name; @@ -2127,7 +2131,7 @@ static BDB_SHARE *get_share(const char *table_name, TABLE *table) strmov(share->table_name,table_name); share->key_file = key_file; share->key_type = key_type; - if (hash_insert(&bdb_open_tables, (char*) share)) + if (hash_insert(&bdb_open_tables, (byte*) share)) { pthread_mutex_unlock(&bdb_mutex); /* purecov: inspected */ my_free((gptr) share,0); /* purecov: inspected */ @@ -2162,7 +2166,7 @@ static int free_share(BDB_SHARE *share, TABLE *table, uint hidden_primary_key, if (share->status_block && (error = share->status_block->close(share->status_block,0))) result = error; /* purecov: inspected */ - hash_delete(&bdb_open_tables, (gptr) share); + hash_delete(&bdb_open_tables, (byte*) share); thr_lock_delete(&share->lock); pthread_mutex_destroy(&share->mutex); my_free((gptr) share, MYF(0)); diff --git a/sql/ha_innobase.cc b/sql/ha_innobase.cc index e3f3d19f865..372b4df09b7 100644 --- a/sql/ha_innobase.cc +++ b/sql/ha_innobase.cc @@ -736,7 +736,7 @@ ha_innobase::open( stored the string length as the first byte. */ buff_len = table->reclength + table->max_key_length - + MAX_REF_PARTS * 2; + + MAX_REF_PARTS * 3; if (!(mysql_byte*) my_multi_malloc(MYF(MY_WME), &upd_buff, buff_len, &key_val_buff, buff_len, @@ -2594,10 +2594,10 @@ ha_innobase::update_table_comment( return (char*)comment; sprintf(str, - "%s; (See manual about Innobase stats); Innobase free: %lu kB", + "%s; Innobase free: %lu kB", comment, (ulong) innobase_get_free_space()); - return((char*) str); + return(str); } diff --git a/sql/ha_myisammrg.cc b/sql/ha_myisammrg.cc index 181ae724cd8..b842c15cce0 100644 --- a/sql/ha_myisammrg.cc +++ b/sql/ha_myisammrg.cc @@ -221,6 +221,37 @@ THR_LOCK_DATA **ha_myisammrg::store_lock(THD *thd, return to; } +void ha_myisammrg::update_create_info(HA_CREATE_INFO *create_info) +{ + DBUG_ENTER("ha_myisammrg::update_create_info"); + if (!(create_info->used_fields & HA_CREATE_USED_UNION)) + { + MYRG_TABLE *table; + THD *thd=current_thd; + create_info->merge_list.next= &create_info->merge_list.first; + + for (table=file->open_tables ; table != file->end_table ; table++) + { + char *name=table->table->s->filename; + char buff[FN_REFLEN]; + TABLE_LIST *ptr; + if (!(ptr = (TABLE_LIST *) thd->calloc(sizeof(TABLE_LIST)))) + goto err; + fn_format(buff,name,"","",3); + if (!(ptr->real_name=thd->strdup(buff))) + goto err; + (*create_info->merge_list.next) = (byte*) ptr; + create_info->merge_list.next= (byte**) &ptr->next; + } + *create_info->merge_list.next=0; + } + DBUG_VOID_RETURN; + +err: + create_info->merge_list.elements=0; + create_info->merge_list.first=0; + DBUG_VOID_RETURN; +} int ha_myisammrg::create(const char *name, register TABLE *form, HA_CREATE_INFO *create_info) diff --git a/sql/ha_myisammrg.h b/sql/ha_myisammrg.h index 4b43ea0eab3..089d9ca5107 100644 --- a/sql/ha_myisammrg.h +++ b/sql/ha_myisammrg.h @@ -72,5 +72,6 @@ class ha_myisammrg: public handler int create(const char *name, TABLE *form, HA_CREATE_INFO *create_info); THR_LOCK_DATA **store_lock(THD *thd, THR_LOCK_DATA **to, enum thr_lock_type lock_type); + void update_create_info(HA_CREATE_INFO *create_info); void append_create_info(String *packet); }; diff --git a/sql/handler.cc b/sql/handler.cc index 240b1ded5e7..96c19c904fe 100644 --- a/sql/handler.cc +++ b/sql/handler.cc @@ -133,6 +133,8 @@ int ha_init() int error; if ((error=berkeley_init())) return error; + if (!berkeley_skip) // If we couldn't use handler + opt_using_transactions=1; } #endif #ifdef HAVE_INNOBASE_DB @@ -140,6 +142,8 @@ int ha_init() { if (innobase_init()) return -1; + if (!innobase_skip) // If we couldn't use handler + opt_using_transactions=1; } #endif return 0; @@ -190,13 +194,16 @@ int ha_autocommit_or_rollback(THD *thd, int error) { DBUG_ENTER("ha_autocommit_or_rollback"); #ifdef USING_TRANSACTIONS - if (!error) + if (opt_using_transactions) { - if (ha_commit_stmt(thd)) - error=1; + if (!error) + { + if (ha_commit_stmt(thd)) + error=1; + } + else + (void) ha_rollback_stmt(thd); } - else - (void) ha_rollback_stmt(thd); #endif DBUG_RETURN(error); } @@ -207,73 +214,80 @@ int ha_commit_trans(THD *thd, THD_TRANS* trans) int error=0; DBUG_ENTER("ha_commit"); #ifdef USING_TRANSACTIONS - /* Update the binary log if we have cached some queries */ - if (trans == &thd->transaction.all && mysql_bin_log.is_open() && - my_b_tell(&thd->transaction.trans_log)) + if (opt_using_transactions) { - mysql_bin_log.write(&thd->transaction.trans_log); - reinit_io_cache(&thd->transaction.trans_log, - WRITE_CACHE, (my_off_t) 0, 0, 1); - thd->transaction.trans_log.end_of_file= max_binlog_cache_size; - } + /* Update the binary log if we have cached some queries */ + if (trans == &thd->transaction.all && mysql_bin_log.is_open() && + my_b_tell(&thd->transaction.trans_log)) + { + mysql_bin_log.write(&thd->transaction.trans_log); + reinit_io_cache(&thd->transaction.trans_log, + WRITE_CACHE, (my_off_t) 0, 0, 1); + thd->transaction.trans_log.end_of_file= max_binlog_cache_size; + } #ifdef HAVE_BERKELEY_DB - if (trans->bdb_tid) - { - if ((error=berkeley_commit(thd,trans->bdb_tid))) + if (trans->bdb_tid) { - my_error(ER_ERROR_DURING_COMMIT, MYF(0), error); - error=1; + if ((error=berkeley_commit(thd,trans->bdb_tid))) + { + my_error(ER_ERROR_DURING_COMMIT, MYF(0), error); + error=1; + } + trans->bdb_tid=0; } - trans->bdb_tid=0; - } #endif #ifdef HAVE_INNOBASE_DB - if (trans->innobase_tid) - { - if ((error=innobase_commit(thd,trans->innobase_tid))) + if (trans->innobase_tid) { - my_error(ER_ERROR_DURING_COMMIT, MYF(0), error); - error=1; + if ((error=innobase_commit(thd,trans->innobase_tid))) + { + my_error(ER_ERROR_DURING_COMMIT, MYF(0), error); + error=1; + } } - } #endif - if (error && trans == &thd->transaction.all && mysql_bin_log.is_open()) - sql_print_error("Error: Got error during commit; Binlog is not up to date!"); + if (error && trans == &thd->transaction.all && mysql_bin_log.is_open()) + sql_print_error("Error: Got error during commit; Binlog is not up to date!"); + } #endif // using transactions DBUG_RETURN(error); } + int ha_rollback_trans(THD *thd, THD_TRANS *trans) { int error=0; DBUG_ENTER("ha_rollback"); -#ifdef HAVE_BERKELEY_DB - if (trans->bdb_tid) +#ifdef USING_TRANSACTIONS + if (opt_using_transactions) { - if ((error=berkeley_rollback(thd, trans->bdb_tid))) +#ifdef HAVE_BERKELEY_DB + if (trans->bdb_tid) { - my_error(ER_ERROR_DURING_ROLLBACK, MYF(0), error); - error=1; + if ((error=berkeley_rollback(thd, trans->bdb_tid))) + { + my_error(ER_ERROR_DURING_ROLLBACK, MYF(0), error); + error=1; + } + trans->bdb_tid=0; } - trans->bdb_tid=0; - } #endif #ifdef HAVE_INNOBASE_DB - if (trans->innobase_tid) - { - if ((error=innobase_rollback(thd, trans->innobase_tid))) + if (trans->innobase_tid) { - my_error(ER_ERROR_DURING_ROLLBACK, MYF(0), error); - error=1; + if ((error=innobase_rollback(thd, trans->innobase_tid))) + { + my_error(ER_ERROR_DURING_ROLLBACK, MYF(0), error); + error=1; + } } - } -#endif -#ifdef USING_TRANSACTIONS - if (trans == &thd->transaction.all) - reinit_io_cache(&thd->transaction.trans_log, - WRITE_CACHE, (my_off_t) 0, 0, 1); - thd->transaction.trans_log.end_of_file= max_binlog_cache_size; #endif + if (trans == &thd->transaction.all) + reinit_io_cache(&thd->transaction.trans_log, + WRITE_CACHE, (my_off_t) 0, 0, 1); + thd->transaction.trans_log.end_of_file= max_binlog_cache_size; + } +#endif /* USING_TRANSACTIONS */ DBUG_RETURN(error); } @@ -493,7 +507,10 @@ void handler::update_auto_increment() THD *thd; DBUG_ENTER("update_auto_increment"); if (table->next_number_field->val_int() != 0) + { + auto_increment_column_changed=0; DBUG_VOID_RETURN; + } thd=current_thd; if ((nr=thd->next_insert_id)) thd->next_insert_id=0; // Clear after use @@ -501,6 +518,7 @@ void handler::update_auto_increment() nr=get_auto_increment(); thd->insert_id((ulonglong) nr); table->next_number_field->store(nr); + auto_increment_column_changed=1; DBUG_VOID_RETURN; } diff --git a/sql/handler.h b/sql/handler.h index ed3683acbd2..8cecd1fe171 100644 --- a/sql/handler.h +++ b/sql/handler.h @@ -115,8 +115,9 @@ enum row_type { ROW_TYPE_DEFAULT, ROW_TYPE_FIXED, ROW_TYPE_DYNAMIC, /* struct to hold information about the table that should be created */ /* Bits in used_fields */ -#define HA_CREATE_USED_AUTO 1 -#define HA_CREATE_USED_RAID 2 +#define HA_CREATE_USED_AUTO 1 +#define HA_CREATE_USED_RAID 2 +#define HA_CREATE_USED_UNION 4 typedef struct st_thd_trans { void *bdb_tid; @@ -191,6 +192,7 @@ public: time_t update_time; ulong mean_rec_length; /* physical reclength */ void *ft_handler; + bool auto_increment_column_changed; handler(TABLE *table_arg) : table(table_arg),active_index(MAX_REF_PARTS), ref(0),ref_length(sizeof(my_off_t)), block_size(0),records(0),deleted(0), diff --git a/sql/key.cc b/sql/key.cc index 87595fda06d..80a33bc45d3 100644 --- a/sql/key.cc +++ b/sql/key.cc @@ -76,7 +76,7 @@ void key_copy(byte *key,TABLE *table,uint idx,uint key_length) KEY_PART_INFO *key_part; if (key_length == 0) - key_length=key_info->key_length+key_info->extra_length; + key_length=key_info->key_length; for (key_part=key_info->key_part; (int) key_length > 0 ; key_part++) @@ -122,7 +122,7 @@ void key_restore(TABLE *table,byte *key,uint idx,uint key_length) { if (idx == (uint) -1) return; - key_length=key_info->key_length+key_info->extra_length; + key_length=key_info->key_length; } for (key_part=key_info->key_part; (int) key_length > 0 ; diff --git a/sql/mysql_priv.h b/sql/mysql_priv.h index 352cdcee6f6..ea2e1460e50 100644 --- a/sql/mysql_priv.h +++ b/sql/mysql_priv.h @@ -504,16 +504,16 @@ extern pthread_mutex_t LOCK_mysql_create_db,LOCK_Acl,LOCK_open, LOCK_delayed_status, LOCK_delayed_create, LOCK_crypt, LOCK_timezone, LOCK_binlog_update, LOCK_slave, LOCK_server_id; extern pthread_cond_t COND_refresh,COND_thread_count, COND_binlog_update, - COND_slave_stopped, COND_slave_start; + COND_slave_stopped, COND_slave_start; extern pthread_attr_t connection_attrib; -extern bool opt_endinfo,using_udf_functions, locked_in_memory; +extern bool opt_endinfo, using_udf_functions, locked_in_memory, + opt_using_transactions, use_temp_pool; +extern char f_fyllchar; extern ulong ha_read_count, ha_write_count, ha_delete_count, ha_update_count, ha_read_key_count, ha_read_next_count, ha_read_prev_count, ha_read_first_count, ha_read_last_count, ha_read_rnd_count, ha_read_rnd_next_count; extern MY_BITMAP temp_pool; -extern bool use_temp_pool; -extern char f_fyllchar; extern uchar *days_in_month; extern DATE_FORMAT dayord; extern double log_10[32]; diff --git a/sql/mysqld.cc b/sql/mysqld.cc index 9798783c9f6..d3d343fe4e5 100644 --- a/sql/mysqld.cc +++ b/sql/mysqld.cc @@ -249,6 +249,7 @@ ulong max_tmp_tables,max_heap_table_size; ulong bytes_sent = 0L, bytes_received = 0L; bool opt_endinfo,using_udf_functions,low_priority_updates, locked_in_memory; +bool opt_using_transactions; bool volatile abort_loop,select_thread_in_use,grant_option; bool volatile ready_to_exit,shutdown_in_progress; ulong refresh_version=1L,flush_version=1L; /* Increments on each reload */ diff --git a/sql/opt_range.cc b/sql/opt_range.cc index d8cd49685ee..92dca25c3c5 100644 --- a/sql/opt_range.cc +++ b/sql/opt_range.cc @@ -2500,14 +2500,16 @@ print_key(KEY_PART *key_part,const char *key,uint used_length) fputc('/',DBUG_FILE); if (field->real_maybe_null()) { - length++; + length++; // null byte is not in part_length if (*key++) { fwrite("NULL",sizeof(char),4,DBUG_FILE); continue; } } - field->set_key_image((char*) key,key_part->part_length); + field->set_key_image((char*) key,key_part->part_length - + ((field->type() == FIELD_TYPE_BLOB) ? + HA_KEY_BLOB_LENGTH : 0)); field->val_str(&tmp,&tmp); fwrite(tmp.ptr(),sizeof(char),tmp.length(),DBUG_FILE); } diff --git a/sql/opt_sum.cc b/sql/opt_sum.cc index beac829bb74..d56bf68db62 100644 --- a/sql/opt_sum.cc +++ b/sql/opt_sum.cc @@ -331,16 +331,15 @@ static bool find_range_key(TABLE_REF *ref, Field* field, COND *cond) part != part_end ; part++) { - if (!part_of_cond(cond,part->field)) + if (!part_of_cond(cond,part->field) || + left_length < part->store_length) break; // Save found constant if (part->null_bit) *key_ptr++= (byte) test(part->field->is_null()); - if (left_length - part->length < 0) - break; // Can't use this key - part->field->get_image((char*) key_ptr,part->length); - key_ptr+=part->length; - left_length-=part->length; + part->field->get_key_image((char*) key_ptr,part->length); + key_ptr+=part->store_length - test(part->null_bit); + left_length-=part->store_length; } if (part == part_end && part->field == field) { diff --git a/sql/sql_class.cc b/sql/sql_class.cc index e9f696fedab..abe7fad822c 100644 --- a/sql/sql_class.cc +++ b/sql/sql_class.cc @@ -91,7 +91,7 @@ THD::THD():user_time(0),fatal_error(0),last_insert_id_used(0), tmp_table=0; lock=locked_tables=0; used_tables=0; - cuted_fields=0L; + cuted_fields=sent_row_count=0L; options=thd_startup_options; update_lock_default= low_priority_updates ? TL_WRITE_LOW_PRIORITY : TL_WRITE; start_time=(time_t) 0; @@ -118,12 +118,15 @@ THD::THD():user_time(0),fatal_error(0),last_insert_id_used(0), system_thread=0; bzero((char*) &mem_root,sizeof(mem_root)); #ifdef USING_TRANSACTIONS - bzero((char*) &transaction,sizeof(transaction)); - if (open_cached_file(&transaction.trans_log, - mysql_tmpdir, LOG_PREFIX, binlog_cache_size, - MYF(MY_WME))) - killed=1; - transaction.trans_log.end_of_file= max_binlog_cache_size; + if (opt_using_transactions) + { + bzero((char*) &transaction,sizeof(transaction)); + if (open_cached_file(&transaction.trans_log, + mysql_tmpdir, LOG_PREFIX, binlog_cache_size, + MYF(MY_WME))) + killed=1; + transaction.trans_log.end_of_file= max_binlog_cache_size; + } #endif #ifdef __WIN__ @@ -148,8 +151,11 @@ THD::~THD() } close_temporary_tables(this); #ifdef USING_TRANSACTIONS - close_cached_file(&transaction.trans_log); - ha_close_connection(this); + if (opt_using_transactions) + { + close_cached_file(&transaction.trans_log); + ha_close_connection(this); + } #endif if (global_read_lock) { diff --git a/sql/sql_insert.cc b/sql/sql_insert.cc index bc67a7f261f..21827d17573 100644 --- a/sql/sql_insert.cc +++ b/sql/sql_insert.cc @@ -346,6 +346,14 @@ int write_record(TABLE *table,COPY_INFO *info) error=HA_WRITE_SKIPP; /* Database can't find key */ goto err; } + /* + Don't allow REPLACE to replace a row when a auto_increment column + was used. This ensures that we don't get a problem when the + whole range of the key has been used. + */ + if (table->next_number_field && key_nr == table->next_number_index && + table->file->auto_increment_column_changed) + goto err; if (table->file->option_flag() & HA_DUPP_POS) { if (table->file->rnd_pos(table->record[1],table->file->dupp_ref)) diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc index fb3bba722de..0cf18edc4dc 100644 --- a/sql/sql_parse.cc +++ b/sql/sql_parse.cc @@ -156,7 +156,7 @@ static bool check_user(THD *thd,enum_server_command command, const char *user, { bool error=test(mysql_change_db(thd,db)); if (error) - decrease_user_connections(user,thd->host); + decrease_user_connections(thd->user,thd->host); return error; } else @@ -175,8 +175,8 @@ static DYNAMIC_ARRAY user_conn_array; extern pthread_mutex_t LOCK_user_conn; struct user_conn { - char user[USERNAME_LENGTH+HOSTNAME_LENGTH+2]; - int connections, len; + char *user; + uint len, connections; }; static byte* get_key_conn(user_conn *buff, uint *length, @@ -188,18 +188,23 @@ static byte* get_key_conn(user_conn *buff, uint *length, #define DEF_USER_COUNT 50 +static void free_user(struct user_conn *uc) +{ + my_free((char*) uc,MYF(0)); +} + void init_max_user_conn(void) { (void) hash_init(&hash_user_connections,DEF_USER_COUNT,0,0, - (hash_get_key) get_key_conn,0, 0); - (void) init_dynamic_array(&user_conn_array,sizeof(user_conn), - DEF_USER_COUNT, DEF_USER_COUNT); + (hash_get_key) get_key_conn, (void (*)(void*)) free_user, + 0); } static int check_for_max_user_connections(const char *user, int u_length, const char *host) { + int error=1; uint temp_len; char temp_user[USERNAME_LENGTH+HOSTNAME_LENGTH+2]; struct user_conn *uc; @@ -207,6 +212,9 @@ static int check_for_max_user_connections(const char *user, int u_length, user=""; if (!host) host=""; + DBUG_ENTER("check_for_max_user_connections"); + DBUG_PRINT("enter",("user: '%s' host: '%s'", user, host)); + temp_len= (uint) (strxnmov(temp_user, sizeof(temp_user), user, "@", host, NullS) - temp_user); (void) pthread_mutex_lock(&LOCK_user_conn); @@ -214,30 +222,40 @@ static int check_for_max_user_connections(const char *user, int u_length, (byte*) temp_user, temp_len); if (uc) /* user found ; check for no. of connections */ { - if ((uint) max_user_connections == uc->connections) + if (max_user_connections == (uint) uc->connections) { net_printf(&(current_thd->net),ER_TOO_MANY_USER_CONNECTIONS, temp_user); - pthread_mutex_unlock(&LOCK_user_conn); - return 1; + goto end; } uc->connections++; } else { /* the user is not found in the cache; Insert it */ - struct user_conn uc; - memcpy(uc.user,temp_user,temp_len+1); - uc.len = temp_len; - uc.connections = 1; - if (!insert_dynamic(&user_conn_array, (char *) &uc)) - { - hash_insert(&hash_user_connections, - (byte *) dynamic_array_ptr(&user_conn_array, - user_conn_array.elements - 1)); + struct user_conn *uc= ((struct user_conn*) + my_malloc(sizeof(struct user_conn) + temp_len+1, + MYF(MY_WME))); + if (!uc) + { + send_error(¤t_thd->net, 0, NullS); // Out of memory + goto end; + } + uc->user=(char*) (uc+1); + memcpy(uc->user,temp_user,temp_len+1); + uc->len = temp_len; + uc->connections = 1; + if (hash_insert(&hash_user_connections, (byte*) uc)) + { + my_free((char*) uc,0); + send_error(¤t_thd->net, 0, NullS); // Out of memory + goto end; } } + error=0; + +end: (void) pthread_mutex_unlock(&LOCK_user_conn); - return 0; + DBUG_RETURN(error); } @@ -246,10 +264,15 @@ static void decrease_user_connections(const char *user, const char *host) char temp_user[USERNAME_LENGTH+HOSTNAME_LENGTH+2]; int temp_len; struct user_conn uucc, *uc; + if (!max_user_connections) + return; if (!user) user=""; if (!host) host=""; + DBUG_ENTER("decrease_user_connections"); + DBUG_PRINT("enter",("user: '%s' host: '%s'", user, host)); + temp_len= (uint) (strxnmov(temp_user, sizeof(temp_user), user, "@", host, NullS) - temp_user); (void) pthread_mutex_lock(&LOCK_user_conn); @@ -263,17 +286,15 @@ static void decrease_user_connections(const char *user, const char *host) { /* Last connection for user; Delete it */ (void) hash_delete(&hash_user_connections,(char *) uc); - uint element= ((uint) ((byte*) uc - (byte*) user_conn_array.buffer) / - user_conn_array.size_of_element); - delete_dynamic_element(&user_conn_array,element); } end: (void) pthread_mutex_unlock(&LOCK_user_conn); + DBUG_VOID_RETURN; } + void free_max_user_conn(void) { - delete_dynamic(&user_conn_array); hash_free(&hash_user_connections); } @@ -336,20 +357,20 @@ check_connections(THD *thd) { /* buff[] needs to big enough to hold the server_version variable */ char buff[SERVER_VERSION_LENGTH + SCRAMBLE_LENGTH+32],*end; - int client_flags = CLIENT_LONG_FLAG | CLIENT_CONNECT_WITH_DB | - CLIENT_TRANSACTIONS; - LINT_INIT(pkt_len); + int client_flags = CLIENT_LONG_FLAG | CLIENT_CONNECT_WITH_DB; + if (opt_using_transactions) + client_flags|=CLIENT_TRANSACTIONS; +#ifdef HAVE_COMPRESS + client_flags |= CLIENT_COMPRESS; +#endif /* HAVE_COMPRESS */ end=strmov(buff,server_version)+1; int4store((uchar*) end,thd->thread_id); end+=4; memcpy(end,thd->scramble,SCRAMBLE_LENGTH+1); end+=SCRAMBLE_LENGTH +1; -#ifdef HAVE_COMPRESS - client_flags |= CLIENT_COMPRESS; -#endif /* HAVE_COMPRESS */ #ifdef HAVE_OPENSSL - if (ssl_acceptor_fd!=0) + if (ssl_acceptor_fd) client_flags |= CLIENT_SSL; /* Wow, SSL is avalaible! */ /* * Without SSL the handshake consists of one packet. This packet @@ -542,8 +563,7 @@ pthread_handler_decl(handle_one_connection,arg) thread_safe_increment(aborted_threads,&LOCK_thread_count); } - if (max_user_connections) - decrease_user_connections(thd->user,thd->host); + decrease_user_connections(thd->user,thd->host); end_thread: close_connection(net); end_thread(thd,1); @@ -567,17 +587,18 @@ pthread_handler_decl(handle_bootstrap,arg) THD *thd=(THD*) arg; FILE *file=bootstrap_file; char *buff; - DBUG_ENTER("handle_bootstrap"); - - pthread_detach_this_thread(); - thd->thread_stack= (char*) &thd; + /* The following must be called before DBUG_ENTER */ if (my_thread_init() || thd->store_globals()) { close_connection(&thd->net,ER_OUT_OF_RESOURCES); thd->fatal_error=1; goto end; } + DBUG_ENTER("handle_bootstrap"); + + pthread_detach_this_thread(); + thd->thread_stack= (char*) &thd; thd->mysys_var=my_thread_var; thd->dbug_thread_id=my_thread_id(); #ifndef __WIN__ @@ -2800,4 +2821,3 @@ static void refresh_status(void) pthread_mutex_unlock(&LOCK_status); pthread_mutex_unlock(&THR_LOCK_keycache); } - diff --git a/sql/sql_select.cc b/sql/sql_select.cc index 9f051448bd2..9359b40849c 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -2040,8 +2040,7 @@ get_best_combination(JOIN *join) if (keyparts == keyuse->keypart) { keyparts++; - length+=keyinfo->key_part[keyuse->keypart].length + - test(keyinfo->key_part[keyuse->keypart].null_bit); + length+=keyinfo->key_part[keyuse->keypart].store_length; } } keyuse++; @@ -2241,7 +2240,10 @@ make_join_select(JOIN *join,SQL_SELECT *select,COND *cond) make_cond_for_table(cond,join->const_table_map,(table_map) 0); DBUG_EXECUTE("where",print_where(const_cond,"constants");); if (const_cond && !const_cond->val_int()) + { + DBUG_PRINT("info",("Found impossible WHERE condition")); DBUG_RETURN(1); // Impossible const condition + } } used_tables=(select->const_tables=join->const_table_map) | RAND_TABLE_BIT; for (uint i=join->const_tables ; i < join->tables ; i++) @@ -5134,7 +5136,7 @@ test_if_skip_sort_order(JOIN_TAB *tab,ORDER *order,ha_rows select_limit) usable_keys=0; break; } - usable_keys&=((Item_field*) (*tmp_order->item))->field->part_of_key; + usable_keys&=((Item_field*) (*tmp_order->item))->field->part_of_sortkey; } ref_key= -1; diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy index 922d90103f1..fa44e7799fa 100644 --- a/sql/sql_yacc.yy +++ b/sql/sql_yacc.yy @@ -740,6 +740,7 @@ create_table_option: lex->table_list.elements=1; lex->table_list.next= (byte**) &(table_list->next); table_list->next=0; + lex->create_info.used_fields|= HA_CREATE_USED_UNION; } table_types: @@ -2666,8 +2667,11 @@ option_value: { Item_func_set_user_var *item = new Item_func_set_user_var($2,$4); if (item->fix_fields(current_thd,0) || item->update()) + { send_error(¤t_thd->net, ER_SET_CONSTANTS_ONLY); - } + YYABORT; + } + } | SQL_SLAVE_SKIP_COUNTER equal ULONG_NUM { pthread_mutex_lock(&LOCK_slave); diff --git a/sql/table.cc b/sql/table.cc index b6fde659cd9..a6d524840d9 100644 --- a/sql/table.cc +++ b/sql/table.cc @@ -153,7 +153,6 @@ int openfrm(const char *name, const char *alias, uint db_stat, uint prgflag, for (i=0 ; i < keys ; i++, keyinfo++) { - uint null_parts=0; keyinfo->flags= ((uint) strpos[0]) ^ HA_NOSAME; keyinfo->key_length= (uint) uint2korr(strpos+1); keyinfo->key_parts= (uint) strpos[3]; strpos+=4; @@ -185,7 +184,6 @@ int openfrm(const char *name, const char *alias, uint db_stat, uint prgflag, } key_part->store_length=key_part->length; } - keyinfo->key_length+=null_parts; set_if_bigger(outparam->max_key_length,keyinfo->key_length+ keyinfo->key_parts); if (keyinfo->flags & HA_NOSAME) @@ -420,6 +418,7 @@ int openfrm(const char *name, const char *alias, uint db_stat, uint prgflag, key_part->store_length+=HA_KEY_NULL_LENGTH; keyinfo->flags|=HA_NULL_PART_KEY; keyinfo->extra_length+= HA_KEY_NULL_LENGTH; + keyinfo->key_length+= HA_KEY_NULL_LENGTH; } if (field->type() == FIELD_TYPE_BLOB || field->real_type() == FIELD_TYPE_VAR_STRING) @@ -428,6 +427,7 @@ int openfrm(const char *name, const char *alias, uint db_stat, uint prgflag, key_part->key_part_flag|= HA_BLOB_PART; keyinfo->extra_length+=HA_KEY_BLOB_LENGTH; key_part->store_length+=HA_KEY_BLOB_LENGTH; + keyinfo->key_length+= HA_KEY_BLOB_LENGTH; } if (i == 0 && key != primary_key) field->flags |= @@ -438,11 +438,16 @@ int openfrm(const char *name, const char *alias, uint db_stat, uint prgflag, field->key_start|= ((key_map) 1 << key); if ((ha_option & HA_HAVE_KEY_READ_ONLY) && field->key_length() == key_part->length && - field->type() != FIELD_TYPE_BLOB && - (field->key_type() != HA_KEYTYPE_TEXT || - (!(ha_option & HA_KEY_READ_WRONG_STR) && - !(keyinfo->flags & HA_FULLTEXT)))) - field->part_of_key|= ((key_map) 1 << key); + field->type() != FIELD_TYPE_BLOB) + { + if (field->key_type() != HA_KEYTYPE_TEXT || + (!(ha_option & HA_KEY_READ_WRONG_STR) && + !(keyinfo->flags & HA_FULLTEXT))) + field->part_of_key|= ((key_map) 1 << key); + if (field->key_type() != HA_KEYTYPE_TEXT || + !(keyinfo->flags & HA_FULLTEXT)) + field->part_of_sortkey|= ((key_map) 1 << key); + } if (!(key_part->key_part_flag & HA_REVERSE_SORT) && usable_parts == i) usable_parts++; // For FILESORT |