mirror of
https://github.com/MariaDB/server.git
synced 2025-12-24 11:21:21 +03:00
Bug#20086: Can't get data from key partitioned tables with VARCHAR key
The problem appeared because the same values produced different hash during INSERT and SELECT for VARCHAR data type. Fix: VARCHAR required special treatment to avoid hashing of length bytes (leftmost one or two bytes) as well as trailing bytes beyond real length, which could contain garbage. Fix is done by introducing hash() - new method in the Field class. mysql-test/r/partition_innodb.result: Adding test case mysql-test/r/partition_pruning.result: Fixing test results (results differ due to changes in hash function) mysql-test/t/partition_innodb.test: Adding test case sql/field.cc: Adding generic hash() method, and a special method for VARCHAR. sql/field.h: Adding prototypes for new methods sql/key.cc: Mark columns for write before executinf of set_key_image(). Thanks for Mikael for suggesting this fix. sql/sql_partition.cc: Removing old hash code. Using new methid field->hash() instead.
This commit is contained in:
@@ -2103,26 +2103,15 @@ static inline longlong part_val_int(Item *item_expr)
|
||||
|
||||
static uint32 calculate_key_value(Field **field_array)
|
||||
{
|
||||
uint32 hashnr= 0;
|
||||
ulong nr1= 1;
|
||||
ulong nr2= 4;
|
||||
|
||||
do
|
||||
{
|
||||
Field *field= *field_array;
|
||||
if (field->is_null())
|
||||
{
|
||||
hashnr^= (hashnr << 1) | 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
uint len= field->pack_length();
|
||||
ulong nr1= 1;
|
||||
CHARSET_INFO *cs= field->charset();
|
||||
cs->coll->hash_sort(cs, (uchar*)field->ptr, len, &nr1, &nr2);
|
||||
hashnr^= (uint32)nr1;
|
||||
}
|
||||
field->hash(&nr1, &nr2);
|
||||
} while (*(++field_array));
|
||||
return hashnr;
|
||||
return (uint32) nr1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user