diff options
author | konstantin@mysql.com <> | 2006-02-02 18:17:18 +0300 |
---|---|---|
committer | konstantin@mysql.com <> | 2006-02-02 18:17:18 +0300 |
commit | 98091b152a35dc987b9f393ac5737f4fd890aef4 (patch) | |
tree | 336ed0f3ebd53f06d2b14904f4fd937b5fe487c6 /sql/ha_heap.cc | |
parent | c9b7317ff905d5496cbbd4df84f4879c19e27c01 (diff) | |
parent | 736faf473011dffd0fc0905c1d5e7859fa04c5aa (diff) | |
download | mariadb-git-98091b152a35dc987b9f393ac5737f4fd890aef4.tar.gz |
Merge mysql.com:/opt/local/work/mysql-4.1-root
into mysql.com:/opt/local/work/mysql-5.0-root
Diffstat (limited to 'sql/ha_heap.cc')
-rw-r--r-- | sql/ha_heap.cc | 56 |
1 files changed, 45 insertions, 11 deletions
diff --git a/sql/ha_heap.cc b/sql/ha_heap.cc index 98cc96db707..2a989a71edc 100644 --- a/sql/ha_heap.cc +++ b/sql/ha_heap.cc @@ -53,7 +53,7 @@ handlerton heap_hton= { ha_heap::ha_heap(TABLE *table_arg) :handler(&heap_hton, table_arg), file(0), records_changed(0), - key_stats_ok(0) + key_stats_version(0) {} @@ -104,7 +104,7 @@ int ha_heap::open(const char *name, int mode, uint test_if_locked) ha_heap::info(), which is always called before key statistics are used. */ - key_stats_ok= FALSE; + key_stat_version= file->s->key_stat_version-1; } return (file ? 0 : 1); } @@ -151,14 +151,21 @@ void ha_heap::update_key_stats() continue; if (key->algorithm != HA_KEY_ALG_BTREE) { - ha_rows hash_buckets= file->s->keydef[i].hash_buckets; - key->rec_per_key[key->key_parts-1]= - hash_buckets ? file->s->records/hash_buckets : 0; + if (key->flags & HA_NOSAME) + key->rec_per_key[key->key_parts-1]= 1; + else + { + ha_rows hash_buckets= file->s->keydef[i].hash_buckets; + uint no_records= hash_buckets ? file->s->records/hash_buckets : 2; + if (no_records < 2) + no_records= 2; + key->rec_per_key[key->key_parts-1]= no_records; + } } } records_changed= 0; /* At the end of update_key_stats() we can proudly claim they are OK. */ - key_stats_ok= TRUE; + key_stat_version= file->s->key_stat_version; } @@ -173,7 +180,13 @@ int ha_heap::write_row(byte * buf) res= heap_write(file,buf); if (!res && (++records_changed*HEAP_STATS_UPDATE_THRESHOLD > file->s->records)) - key_stats_ok= FALSE; + { + /* + We can perform this safely since only one writer at the time is + allowed on the table. + */ + file->s->key_stat_version++; + } return res; } @@ -186,7 +199,13 @@ int ha_heap::update_row(const byte * old_data, byte * new_data) res= heap_update(file,old_data,new_data); if (!res && ++records_changed*HEAP_STATS_UPDATE_THRESHOLD > file->s->records) - key_stats_ok= FALSE; + { + /* + We can perform this safely since only one writer at the time is + allowed on the table. + */ + file->s->key_stat_version++; + } return res; } @@ -197,7 +216,13 @@ int ha_heap::delete_row(const byte * buf) res= heap_delete(file,buf); if (!res && table->s->tmp_table == NO_TMP_TABLE && ++records_changed*HEAP_STATS_UPDATE_THRESHOLD > file->s->records) - key_stats_ok= FALSE; + { + /* + We can perform this safely since only one writer at the time is + allowed on the table. + */ + file->s->key_stat_version++; + } return res; } @@ -324,7 +349,7 @@ void ha_heap::info(uint flag) have to update the key statistics. Hoping that a table lock is now in place. */ - if (! key_stats_ok) + if (key_stat_version != file->s->key_stat_version) update_key_stats(); } @@ -337,7 +362,13 @@ int ha_heap::delete_all_rows() { heap_clear(file); if (table->s->tmp_table == NO_TMP_TABLE) - key_stats_ok= FALSE; + { + /* + We can perform this safely since only one writer at the time is + allowed on the table. + */ + file->s->key_stat_version++; + } return 0; } @@ -497,6 +528,9 @@ ha_rows ha_heap::records_in_range(uint inx, key_range *min_key, max_key->flag != HA_READ_AFTER_KEY) return HA_POS_ERROR; // Can only use exact keys + if (records <= 1) + return records; + /* Assert that info() did run. We need current statistics here. */ DBUG_ASSERT(key_stats_ok); return key->rec_per_key[key->key_parts-1]; |