#At bzr+ssh://bk-internal.mysql.com/bzrroot/server/mysql-maria/
2669 Michael Widenius 2008-09-26
Fix for Bug #39243 SELECT WHERE does not find row
Symptom was that records_in_range() found 0 matching keys which confused the optimizer to belive that there was no matching rows for the query
modified:
mysql-test/r/maria.result
mysql-test/t/maria.test
storage/maria/ma_search.c
per-file messages:
mysql-test/r/maria.result
New testcase
mysql-test/t/maria.test
New testcase
storage/maria/ma_search.c
Fix bug in skip_key for keys that starts with a CHAR/VARCHAR NULL key.
=== modified file 'mysql-test/r/maria.result'
--- a/mysql-test/r/maria.result 2008-08-28 18:52:23 +0000
+++ b/mysql-test/r/maria.result 2008-09-26 08:16:35 +0000
@@ -2243,3 +2243,35 @@ lock table t1 write concurrent;
delete from t1;
ERROR 42000: The storage engine for the table doesn't support DELETE in WRITE CONCURRENT
drop table t1;
+create table t1 (p int primary key, i int, a char(10), key k1(i), key k2(a))
+engine maria;
+insert into t1 values (1, 1, 'qqqq'), (2, 1, 'pppp'),
+(3, 1, 'yyyy'), (4, 3, 'zzzz');
+insert into t1 values (5, 3, 'yyyy'), (6, 3, 'yyyy'), (7, 0, NULL),
+(8, 0, NULL);
+select * from t1 where a='zzzz';
+p i a
+4 3 zzzz
+select * from t1 where a='yyyy';
+p i a
+3 1 yyyy
+5 3 yyyy
+6 3 yyyy
+select * from t1 where a is NULL;
+p i a
+7 0 NULL
+8 0 NULL
+select * from t1;
+p i a
+1 1 qqqq
+2 1 pppp
+3 1 yyyy
+4 3 zzzz
+5 3 yyyy
+6 3 yyyy
+7 0 NULL
+8 0 NULL
+check table t1;
+Table Op Msg_type Msg_text
+test.t1 check status OK
+drop table t1;
=== modified file 'mysql-test/t/maria.test'
--- a/mysql-test/t/maria.test 2008-08-28 18:52:23 +0000
+++ b/mysql-test/t/maria.test 2008-09-26 08:16:35 +0000
@@ -1542,3 +1542,20 @@ eval set global storage_engine=$default_
--enable_result_log
--enable_query_log
+#
+# Bug#39243 SELECT WHERE does not find row
+# (Problem with skip_row)
+#
+
+create table t1 (p int primary key, i int, a char(10), key k1(i), key k2(a))
+engine maria;
+insert into t1 values (1, 1, 'qqqq'), (2, 1, 'pppp'),
+ (3, 1, 'yyyy'), (4, 3, 'zzzz');
+insert into t1 values (5, 3, 'yyyy'), (6, 3, 'yyyy'), (7, 0, NULL),
+ (8, 0, NULL);
+select * from t1 where a='zzzz';
+select * from t1 where a='yyyy';
+select * from t1 where a is NULL;
+select * from t1;
+check table t1;
+drop table t1;
=== modified file 'storage/maria/ma_search.c'
--- a/storage/maria/ma_search.c 2008-08-24 13:29:34 +0000
+++ b/storage/maria/ma_search.c 2008-09-26 08:16:35 +0000
@@ -931,7 +931,7 @@ uint _ma_get_static_key(MARIA_KEY *key,
/**
Skip over static length key from key-block
- @fn _ma_skip_pack_key()
+ @fn _ma_skip_static_key()
@param key Keyinfo and buffer that can be used
@param nod_flag If nod: Length of node pointer, else zero.
@param key Points at key
@@ -1049,6 +1049,7 @@ uint _ma_get_pack_key(MARIA_KEY *int_key
}
else
{
+ /* Key that is not packed against previous key */
if (keyseg->flag & HA_NULL_PART)
{
if (!length--) /* Null part */
@@ -1121,6 +1122,9 @@ uint _ma_get_pack_key(MARIA_KEY *int_key
@param nod_flag If nod: Length of node pointer, else zero.
@param key Points at key
+ @note
+ This is in principle a simpler version of _ma_get_pack_key()
+
@retval pointer to next key
*/
@@ -1150,6 +1154,14 @@ uchar *_ma_skip_pack_key(MARIA_KEY *key,
page+= length;
continue;
}
+ if ((keyseg->flag & HA_NULL_PART) && length)
+ {
+ /*
+ Keys that can have null use length+1 as the length for date as the
+ number 0 is reserved for keys that have a NULL value
+ */
+ length--;
+ }
page+= length;
}
else
@@ -1846,11 +1858,14 @@ _ma_calc_var_key_length(const MARIA_KEY
prefix byte(s) The high bit is set if this is a prefix for the prev key
length Packed length if the previous was a prefix byte
- [length] data bytes ('length' bytes)
+ [data_length] data bytes ('length' bytes)
next-key-seg Next key segments
If the first segment can have NULL:
- The length is 0 for NULLS and 1+length for not null columns.
+ If key was packed
+ data_length is length of rest of key
+ If key was not packed
+ The data_length is 0 for NULLS and 1+data_length for not null columns
*/
int
| Thread |
|---|
| • bzr commit into MySQL/Maria:mysql-maria branch (monty:2669) Bug#39243 | Michael Widenius | 26 Sep |