Below is the list of changes that have just been committed into a local
4.1 repository of mikron. When mikron does a push these changes will
be propagated to the main repository and, within 24 hours after the
push, to the public repository.
For information on how to access the public repository
see http://dev.mysql.com/doc/mysql/en/installing-source-tree.html
ChangeSet
1.2470 05/11/22 12:31:54 mikron@stripped +8
-0
Bug #12796: key on HEAP with hash fails to find row
Statistics could become corrupted in certain cases,
unqiue key statistics wasn't properly handled and
numbers 0 and 1 not properly handled in HEAP using HASH
for records_in_range
sql/ha_heap.h
1.34 05/11/22 12:31:38 mikron@stripped +2
-2
Local variable to keep track of key_stat_version
sql/ha_heap.cc
1.58 05/11/22 12:31:38 mikron@stripped +25
-13
Update statistics flag moved to share object
Also proper handling of unique keys
Also return 2 and not 1 since 1 must be exactly 1 and not an
estimate
mysql-test/t/heap.test
1.23 05/11/22 12:31:37 mikron@stripped +11
-0
New test case results
Return 2 instead of 1 in records_in_range in certain situations since
1 is interpreted as == 1 and not as an estimate.
mysql-test/r/myisam.result
1.58 05/11/22 12:31:37 mikron@stripped +1
-1
New test case results
Return 2 instead of 1 in records_in_range in certain situations since
1 is interpreted as == 1 and not as an estimate.
mysql-test/r/heap_hash.result
1.14 05/11/22 12:31:37 mikron@stripped +10
-10
New test case results
Return 2 instead of 1 in records_in_range in certain situations since
1 is interpreted as == 1 and not as an estimate.
mysql-test/r/heap.result
1.30 05/11/22 12:31:37 mikron@stripped +11
-1
New test case results
Return 2 instead of 1 in records_in_range in certain situations since
1 is interpreted as == 1 and not as an estimate.
include/heap.h
1.25 05/11/22 12:31:37 mikron@stripped +1
-0
Introduced key_stat_version on share object to ensure we recalculate
statistics properly.
heap/hp_create.c
1.19 05/11/22 12:31:36 mikron@stripped +1
-0
Introduced key_stat_version on share object to ensure we recalculate
statistics properly.
# This is a BitKeeper patch. What follows are the unified diffs for the
# set of deltas contained in the patch. The rest of the patch, the part
# that BitKeeper cares about, is below these diffs.
# User: mikron
# Host: c-5f08e253.1238-1-64736c10.cust.bredbandsbolaget.se
# Root: /Users/mikron/mysql-4.1
--- 1.18/heap/hp_create.c 2005-10-25 01:27:29 +02:00
+++ 1.19/heap/hp_create.c 2005-11-22 12:31:36 +01:00
@@ -104,6 +104,7 @@
DBUG_RETURN(1);
}
share->keydef= (HP_KEYDEF*) (share + 1);
+ share->key_stat_version= 1;
keyseg= (HA_KEYSEG*) (share->keydef + keys);
init_block(&share->block, reclength + 1, min_records, max_records);
/* Fix keys */
--- 1.24/include/heap.h 2005-03-16 00:15:42 +01:00
+++ 1.25/include/heap.h 2005-11-22 12:31:37 +01:00
@@ -136,6 +136,7 @@
HP_KEYDEF *keydef;
ulong min_records,max_records; /* Params to open */
ulong data_length,index_length,max_table_size;
+ uint key_stat_version; /* version to indicate insert/delete */
uint records; /* records */
uint blength; /* records rounded up to 2^n */
uint deleted; /* Deleted records in database */
--- 1.57/sql/ha_heap.cc 2005-06-24 17:47:04 +02:00
+++ 1.58/sql/ha_heap.cc 2005-11-22 12:31:38 +01:00
@@ -68,7 +68,7 @@
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);
}
@@ -114,14 +114,21 @@
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;
}
int ha_heap::write_row(byte * buf)
@@ -135,7 +142,7 @@
res= heap_write(file,buf);
if (!res && ++records_changed*HEAP_STATS_UPDATE_THRESHOLD >
file->s->records)
- key_stats_ok= FALSE;
+ file->s->key_stat_version++;
return res;
}
@@ -148,7 +155,7 @@
res= heap_update(file,old_data,new_data);
if (!res && ++records_changed*HEAP_STATS_UPDATE_THRESHOLD >
file->s->records)
- key_stats_ok= FALSE;
+ file->s->key_stat_version++;
return res;
}
@@ -159,7 +166,7 @@
res= heap_delete(file,buf);
if (!res && table->tmp_table == NO_TMP_TABLE &&
++records_changed*HEAP_STATS_UPDATE_THRESHOLD > file->s->records)
- key_stats_ok= FALSE;
+ file->s->key_stat_version++;
return res;
}
@@ -277,7 +284,7 @@
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();
}
@@ -290,7 +297,7 @@
{
heap_clear(file);
if (table->tmp_table == NO_TMP_TABLE)
- key_stats_ok= FALSE;
+ file->s->key_stat_version++;
return 0;
}
@@ -451,9 +458,14 @@
return HA_POS_ERROR; // Can only use exact keys
else
{
- /* Assert that info() did run. We need current statistics here. */
- DBUG_ASSERT(key_stats_ok);
- return key->rec_per_key[key->key_parts-1];
+ if (records <= 1)
+ return records;
+ else
+ {
+ /* Assert that info() did run. We need current statistics here. */
+ DBUG_ASSERT(key_stat_version == file->s->key_stat_version);
+ return key->rec_per_key[key->key_parts-1];
+ }
}
}
--- 1.33/sql/ha_heap.h 2005-06-24 17:47:04 +02:00
+++ 1.34/sql/ha_heap.h 2005-11-22 12:31:38 +01:00
@@ -29,10 +29,10 @@
key_map btree_keys;
/* number of records changed since last statistics update */
uint records_changed;
- bool key_stats_ok;
+ uint key_stat_version;
public:
ha_heap(TABLE *table): handler(table), file(0), records_changed(0),
- key_stats_ok(0) {}
+ key_stat_version(0) {}
~ha_heap() {}
const char *table_type() const { return "HEAP"; }
const char *index_type(uint inx)
--- 1.13/mysql-test/r/heap_hash.result 2005-06-24 17:47:04 +02:00
+++ 1.14/mysql-test/r/heap_hash.result 2005-11-22 12:31:37 +01:00
@@ -182,7 +182,7 @@
a b
explain SELECT * FROM t1 WHERE a IS NULL;
id select_type table type possible_keys key key_len ref rows Extra
-1 SIMPLE t1 ref a a 5 const 1 Using where
+1 SIMPLE t1 ref a a 5 const 2 Using where
SELECT * FROM t1 WHERE a<=>NULL;
a b
NULL 99
@@ -220,16 +220,16 @@
insert into t1 values ('aaah', 'prefill-hash=6',0);
explain select * from t1 where a='aaaa';
id select_type table type possible_keys key key_len ref rows Extra
-1 SIMPLE t1 ref a a 8 const 1 Using where
+1 SIMPLE t1 ref a a 8 const 2 Using where
explain select * from t1 where a='aaab';
id select_type table type possible_keys key key_len ref rows Extra
-1 SIMPLE t1 ref a a 8 const 1 Using where
+1 SIMPLE t1 ref a a 8 const 2 Using where
explain select * from t1 where a='aaac';
id select_type table type possible_keys key key_len ref rows Extra
-1 SIMPLE t1 ref a a 8 const 1 Using where
+1 SIMPLE t1 ref a a 8 const 2 Using where
explain select * from t1 where a='aaad';
id select_type table type possible_keys key key_len ref rows Extra
-1 SIMPLE t1 ref a a 8 const 1 Using where
+1 SIMPLE t1 ref a a 8 const 2 Using where
insert into t1 select * from t1;
flush tables;
explain select * from t1 where a='aaaa';
@@ -291,25 +291,25 @@
insert into t2 select * from t1;
explain select * from t1 where name='matt';
id select_type table type possible_keys key key_len ref rows Extra
-1 SIMPLE t1 ref heap_idx,btree_idx heap_idx 20 const 1 Using where
+1 SIMPLE t1 ref heap_idx,btree_idx btree_idx 20 const 1 Using where
explain select * from t2 where name='matt';
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t2 ref btree_idx,heap_idx btree_idx 20 const 1 Using where
explain select * from t1 where name='Lilu';
id select_type table type possible_keys key key_len ref rows Extra
-1 SIMPLE t1 ref heap_idx,btree_idx heap_idx 20 const 1 Using where
+1 SIMPLE t1 ref heap_idx,btree_idx btree_idx 20 const 1 Using where
explain select * from t2 where name='Lilu';
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t2 ref btree_idx,heap_idx btree_idx 20 const 1 Using where
explain select * from t1 where name='Phil';
id select_type table type possible_keys key key_len ref rows Extra
-1 SIMPLE t1 ref heap_idx,btree_idx heap_idx 20 const 1 Using where
+1 SIMPLE t1 ref heap_idx,btree_idx btree_idx 20 const 1 Using where
explain select * from t2 where name='Phil';
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t2 ref btree_idx,heap_idx btree_idx 20 const 1 Using where
explain select * from t1 where name='Lilu';
id select_type table type possible_keys key key_len ref rows Extra
-1 SIMPLE t1 ref heap_idx,btree_idx heap_idx 20 const 1 Using where
+1 SIMPLE t1 ref heap_idx,btree_idx btree_idx 20 const 1 Using where
explain select * from t2 where name='Lilu';
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t2 ref btree_idx,heap_idx btree_idx 20 const 1 Using where
@@ -364,5 +364,5 @@
3
explain select a from t1 where a in (1,3);
id select_type table type possible_keys key key_len ref rows Extra
-1 SIMPLE t1 range a a 5 NULL 2 Using where
+1 SIMPLE t1 range a a 5 NULL 4 Using where
drop table t1;
--- 1.29/mysql-test/r/heap.result 2005-05-24 21:21:11 +02:00
+++ 1.30/mysql-test/r/heap.result 2005-11-22 12:31:37 +01:00
@@ -182,7 +182,7 @@
a b
explain SELECT * FROM t1 WHERE a IS NULL;
id select_type table type possible_keys key key_len ref rows Extra
-1 SIMPLE t1 ref a a 5 const 1 Using where
+1 SIMPLE t1 ref a a 5 const 2 Using where
SELECT * FROM t1 WHERE a<=>NULL;
a b
NULL 99
@@ -295,4 +295,14 @@
insert into t1 values
("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz");
insert into t1 values
("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz");
ERROR 23000: Duplicate entry
'abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijkl'
for key 1
+drop table t1;
+CREATE TABLE t1 (a int, key(a)) engine=heap;
+insert delayed into t1 values (0);
+delete from t1;
+select * from t1;
+a
+insert delayed into t1 values (0), (1);
+select * from t1 where a = 0;
+a
+0
drop table t1;
--- 1.22/mysql-test/t/heap.test 2005-07-28 02:21:43 +02:00
+++ 1.23/mysql-test/t/heap.test 2005-11-22 12:31:37 +01:00
@@ -234,4 +234,15 @@
insert into t1 values
("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz");
drop table t1;
+#
+# Bug 12796: Record doesn't show when selecting through index
+#
+CREATE TABLE t1 (a int, key(a)) engine=heap;
+insert delayed into t1 values (0);
+delete from t1;
+select * from t1;
+insert delayed into t1 values (0), (1);
+select * from t1 where a = 0;
+drop table t1;
+
# End of 4.1 tests
--- 1.57/mysql-test/r/myisam.result 2005-11-15 18:01:26 +01:00
+++ 1.58/mysql-test/r/myisam.result 2005-11-22 12:31:37 +01:00
@@ -554,7 +554,7 @@
Note 1031 Table storage engine for 't1' doesn't have this option
show keys from t1;
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment
-t1 1 a 1 a NULL 1000 NULL NULL YES HASH
+t1 1 a 1 a NULL 500 NULL NULL YES HASH
drop table t1,t2;
create table t1 ( a tinytext, b char(1), index idx (a(1),b) );
insert into t1 values (null,''), (null,'');
| Thread |
|---|
| • bk commit into 4.1 tree (mikron:1.2470) BUG#12796 | mikael | 24 Nov |