diff options
author | unknown <serg@serg.mylan> | 2003-10-30 19:17:57 +0100 |
---|---|---|
committer | unknown <serg@serg.mylan> | 2003-10-30 19:17:57 +0100 |
commit | 372e949242e637d0d80a694132a221e3842acdbd (patch) | |
tree | e29f3d04a40a0f1438871abcf54eceb9de6a07e4 /sql | |
parent | a8b7edda5123969c62101a65aac33b4b0d173e44 (diff) | |
download | mariadb-git-372e949242e637d0d80a694132a221e3842acdbd.tar.gz |
Bitmap post-review fixes
Diffstat (limited to 'sql')
-rw-r--r-- | sql/ha_berkeley.cc | 28 | ||||
-rw-r--r-- | sql/ha_berkeley.h | 4 | ||||
-rw-r--r-- | sql/item_func.h | 4 | ||||
-rw-r--r-- | sql/opt_range.cc | 36 | ||||
-rw-r--r-- | sql/sql_bitmap.h | 2 | ||||
-rw-r--r-- | sql/sql_select.cc | 11 | ||||
-rw-r--r-- | sql/table.cc | 6 | ||||
-rw-r--r-- | sql/unireg.cc | 7 |
8 files changed, 55 insertions, 43 deletions
diff --git a/sql/ha_berkeley.cc b/sql/ha_berkeley.cc index 3e5dc38e864..e87e31708f3 100644 --- a/sql/ha_berkeley.cc +++ b/sql/ha_berkeley.cc @@ -844,7 +844,7 @@ int ha_berkeley::write_row(byte * record) ulong thd_options = table->in_use ? table->in_use->options : 0; for (uint retry=0 ; retry < berkeley_trans_retry ; retry++) { - key_map changed_keys; + key_map changed_keys(0); if (using_ignore && (thd_options & OPTION_INTERNAL_SUBTRANSACTIONS)) { if ((error=txn_begin(db_env, transaction, &sub_trans, 0))) /* purecov: deadcode */ @@ -888,7 +888,8 @@ int ha_berkeley::write_row(byte * record) else if (!changed_keys.is_clear_all()) { new_error = 0; - for (uint keynr=0; keynr < changed_keys.length(); keynr++) + for (uint keynr=0 ; keynr < table->keys+test(hidden_primary_key) ; + keynr++) { if (changed_keys.is_set(keynr)) { @@ -1012,7 +1013,7 @@ int ha_berkeley::update_primary_key(DB_TXN *trans, bool primary_key_changed, Clobbers keybuff2 */ -int ha_berkeley::restore_keys(DB_TXN *trans, key_map changed_keys, +int ha_berkeley::restore_keys(DB_TXN *trans, key_map *changed_keys, uint primary_key, const byte *old_row, DBT *old_key, const byte *new_row, DBT *new_key, @@ -1034,14 +1035,13 @@ 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. */ - if (!changed_keys.is_clear_all()) + if (!changed_keys->is_clear_all()) { - key_map map1(1); - for (keynr=0; keynr < changed_keys.length(); keynr++) + for (keynr=0 ; keynr < table->keys+test(hidden_primary_key) ; keynr++) { - if (changed_keys.is_set(keynr)) + if (changed_keys->is_set(keynr)) { - if (changed_keys.is_subset(map1) && + if (changed_keys->is_prefix(1) && (error = remove_key(trans, keynr, new_row, new_key))) break; /* purecov: inspected */ if ((error = key_file[keynr]->put(key_file[keynr], trans, @@ -1094,7 +1094,7 @@ int ha_berkeley::update_row(const byte * old_row, byte * new_row) sub_trans = transaction; for (uint retry=0 ; retry < berkeley_trans_retry ; retry++) { - key_map changed_keys; + key_map changed_keys(0); if (using_ignore && (thd_options & OPTION_INTERNAL_SUBTRANSACTIONS)) { if ((error=txn_begin(db_env, transaction, &sub_trans, 0))) /* purecov: deadcode */ @@ -1152,7 +1152,7 @@ int ha_berkeley::update_row(const byte * old_row, byte * new_row) new_error=txn_abort(sub_trans); /* purecov: deadcode */ } else if (!changed_keys.is_clear_all()) - new_error=restore_keys(transaction, changed_keys, primary_key, + new_error=restore_keys(transaction, &changed_keys, primary_key, old_row, &old_prim_key, new_row, &prim_key, thd_options); if (new_error) @@ -1233,12 +1233,12 @@ int ha_berkeley::remove_key(DB_TXN *trans, uint keynr, const byte *record, /* Delete all keys for new_record */ int ha_berkeley::remove_keys(DB_TXN *trans, const byte *record, - DBT *new_record, DBT *prim_key, key_map keys) + DBT *new_record, DBT *prim_key, key_map *keys) { int result = 0; - for (uint keynr=0; keynr < keys.length(); keynr++) + for (uint keynr=0 ; keynr < table->keys+test(hidden_primary_key) ; keynr++) { - if (keys.is_set(keynr)) + if (keys->is_set(keynr)) { int new_error=remove_key(trans, keynr, record, prim_key); if (new_error) @@ -1278,7 +1278,7 @@ int ha_berkeley::delete_row(const byte * record) break; /* purecov: deadcode */ DBUG_PRINT("trans",("starting sub transaction")); /* purecov: deadcode */ } - error=remove_keys(sub_trans, record, &row, &prim_key, keys); + error=remove_keys(sub_trans, record, &row, &prim_key, &keys); if (!error && (thd_options & OPTION_INTERNAL_SUBTRANSACTIONS)) { DBUG_PRINT("trans",("ending sub transaction")); /* purecov: deadcode */ diff --git a/sql/ha_berkeley.h b/sql/ha_berkeley.h index 79e52ea71af..39293717c27 100644 --- a/sql/ha_berkeley.h +++ b/sql/ha_berkeley.h @@ -72,8 +72,8 @@ class ha_berkeley: public handler uint key_length); int remove_key(DB_TXN *trans, uint keynr, const byte *record, DBT *prim_key); int remove_keys(DB_TXN *trans,const byte *record, DBT *new_record, - DBT *prim_key, key_map keys); - int restore_keys(DB_TXN *trans, key_map changed_keys, uint primary_key, + DBT *prim_key, key_map *keys); + int restore_keys(DB_TXN *trans, key_map *changed_keys, uint primary_key, const byte *old_row, DBT *old_key, const byte *new_row, DBT *new_key, ulong thd_options); diff --git a/sql/item_func.h b/sql/item_func.h index 0ba4445def2..9a6e2a71f64 100644 --- a/sql/item_func.h +++ b/sql/item_func.h @@ -981,8 +981,8 @@ public: String value; // value of concat String search_value; // key_item()'s value converted to cmp_collation - Item_func_match(List<Item> &a, uint b): Item_real_func(a), flags(b), - table(0), master(0), ft_handler(0), concat(0), key(0), join_key(0) { } + Item_func_match(List<Item> &a, uint b): Item_real_func(a), key(0), flags(b), + join_key(0), ft_handler(0), table(0), master(0), concat(0) { } ~Item_func_match() { if (!master && ft_handler) diff --git a/sql/opt_range.cc b/sql/opt_range.cc index da6ede8586f..aa216849d76 100644 --- a/sql/opt_range.cc +++ b/sql/opt_range.cc @@ -567,19 +567,29 @@ SEL_ARG *SEL_ARG::clone_tree() return root; } -/***************************************************************************** -** Test if a key can be used in different ranges -** Returns: -** -1 if impossible select -** 0 if can't use quick_select -** 1 if found usable range -** Updates the following in the select parameter: -** needed_reg ; Bits for keys with may be used if all prev regs are read -** quick ; Parameter to use when reading records. -** In the table struct the following information is updated: -** quick_keys ; Which keys can be used -** quick_rows ; How many rows the key matches -*****************************************************************************/ +/* + Test if a key can be used in different ranges + + SYNOPSIS + SQL_SELECT::test_quick_select(thd,keys_to_use, prev_tables, + limit, force_quick_range) + + Updates the following in the select parameter: + needed_reg - Bits for keys with may be used if all prev regs are read + quick - Parameter to use when reading records. + In the table struct the following information is updated: + quick_keys - Which keys can be used + quick_rows - How many rows the key matches + + RETURN VALUES + -1 if impossible select + 0 if can't use quick_select + 1 if found usable range + + TODO + check if the function really needs to modify keys_to_use, and change the + code to pass it by reference if not +*/ int SQL_SELECT::test_quick_select(THD *thd, key_map keys_to_use, table_map prev_tables, diff --git a/sql/sql_bitmap.h b/sql/sql_bitmap.h index b8e163ce24a..53293e39591 100644 --- a/sql/sql_bitmap.h +++ b/sql/sql_bitmap.h @@ -16,6 +16,7 @@ template <uint default_width> class Bitmap uchar buffer[(default_width+7)/8]; public: Bitmap() { init(); } + Bitmap(Bitmap& from) { *this=from; } Bitmap(uint prefix_to_set) { init(prefix_to_set); } void init() { bitmap_init(&map, buffer, default_width, 0); } void init(uint prefix_to_set) { init(); set_prefix(prefix_to_set); } @@ -24,6 +25,7 @@ public: { init(); memcpy(buffer, map2.buffer, sizeof(buffer)); + return *this; } void set_bit(uint n) { bitmap_set_bit(&map, n); } void clear_bit(uint n) { bitmap_clear_bit(&map, n); } diff --git a/sql/sql_select.cc b/sql/sql_select.cc index 5c784422bc4..59d3242ff37 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -1579,7 +1579,7 @@ err: static ha_rows get_quick_record_count(THD *thd, SQL_SELECT *select, TABLE *table, - const key_map& keys,ha_rows limit) + const key_map *keys,ha_rows limit) { int error; DBUG_ENTER("get_quick_record_count"); @@ -1587,7 +1587,7 @@ static ha_rows get_quick_record_count(THD *thd, SQL_SELECT *select, { select->head=table; table->reginfo.impossible_range=0; - if ((error=select->test_quick_select(thd, keys,(table_map) 0,limit)) + if ((error=select->test_quick_select(thd, *(key_map *)keys,(table_map) 0,limit)) == 1) DBUG_RETURN(select->quick->records); if (error == -1) @@ -1876,7 +1876,7 @@ make_join_statistics(JOIN *join,TABLE_LIST *tables,COND *conds, s->on_expr ? s->on_expr : conds, &error); records= get_quick_record_count(join->thd, select, s->table, - s->const_keys, join->row_limit); + &s->const_keys, join->row_limit); s->quick=select->quick; s->needed_reg=select->needed_reg; select->quick=0; @@ -2104,8 +2104,7 @@ add_key_field(KEY_FIELD **key_fields,uint and_level, else { JOIN_TAB *stat=field->table->reginfo.join_tab; - key_map possible_keys; - possible_keys=field->key_start; + key_map possible_keys=field->key_start; possible_keys.intersect(field->table->keys_in_use_for_query); stat[0].keys.merge(possible_keys); // Add possible keys @@ -8777,7 +8776,7 @@ static void select_describe(JOIN *join, bool need_tmp_table, bool need_order, uint j; if (!tab->keys.is_clear_all()) { - for (j=0 ; j < tab->keys.length() ; j++) + for (j=0 ; j < table->keys ; j++) { if (tab->keys.is_set(j)) { diff --git a/sql/table.cc b/sql/table.cc index ebe1b51248e..14853011510 100644 --- a/sql/table.cc +++ b/sql/table.cc @@ -156,9 +156,9 @@ int openfrm(const char *name, const char *alias, uint db_stat, uint prgflag, VOID(my_seek(file,(ulong) uint2korr(head+6),MY_SEEK_SET,MYF(0))); if (read_string(file,(gptr*) &disk_buff,key_info_length)) goto err_not_open; /* purecov: inspected */ - if (disk_buff[1] & 0x80) + if (disk_buff[0] & 0x80) { - outparam->keys= keys= uint2korr(disk_buff) & 0x7fff; + outparam->keys= keys= (disk_buff[1] << 7) | (disk_buff[0] & 0x7f); outparam->key_parts= key_parts= uint2korr(disk_buff+2); } else @@ -279,7 +279,7 @@ int openfrm(const char *name, const char *alias, uint db_stat, uint prgflag, if (my_pread(file,(byte*) record,(uint) outparam->reclength, (ulong) (uint2korr(head+6)+ ((uint2korr(head+14) == 0xffff ? - uint4korr(head+10) : uint2korr(head+14)))), + uint4korr(head+47) : uint2korr(head+14)))), MYF(MY_NABP))) goto err_not_open; /* purecov: inspected */ /* HACK: table->record[2] is used instead of table->default_values here */ diff --git a/sql/unireg.cc b/sql/unireg.cc index d95aba97424..8606830e450 100644 --- a/sql/unireg.cc +++ b/sql/unireg.cc @@ -100,7 +100,8 @@ int rea_create_table(THD *thd, my_string file_name, goto err; maxlength=(uint) next_io_size((ulong) (uint2korr(forminfo)+1000)); int2store(forminfo+2,maxlength); - int4store(fileinfo+10,key_buff_length); + int4store(fileinfo+10,(ulong) (filepos+maxlength)); + int4store(fileinfo+47,key_buff_length); fileinfo[26]= (uchar) test((create_info->max_rows == 1) && (create_info->min_rows == 1) && (keys == 0)); int2store(fileinfo+28,key_info_length); @@ -293,8 +294,8 @@ static uint pack_keys(uchar *keybuff,uint key_count,KEY *keyinfo) if (key_count > 127 || key_parts > 127) { - key_count|=0x8000; - int2store(keybuff,key_count); + keybuff[0]= (key_count & 0x7f) | 0x80; + keybuff[1]= key_count >> 7; int2store(keybuff+2,key_parts); } else |