From e2ab8558e899716d653d994af1a1e86c54e90bf9 Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 12 Jan 2004 16:25:13 +0200 Subject: [PATCH] opt_sum.cc: A fix for a bug #3189, pertaining to crashing MySQL server when a query with MIN / MAX on the BLOB column is to be optimised sql/opt_sum.cc: A fix for a bug #3189, pertaining to crashing MySQL server when a query with MIN / MAX on the BLOB column is to be optimised --- mysql-test/r/type_blob.result | 6 ++++++ mysql-test/t/type_blob.test | 6 ++++++ sql/opt_sum.cc | 4 +++- 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/mysql-test/r/type_blob.result b/mysql-test/r/type_blob.result index 0bb9146fafc..685301f3639 100644 --- a/mysql-test/r/type_blob.result +++ b/mysql-test/r/type_blob.result @@ -601,3 +601,9 @@ id txt 2 Chevy 4 Ford drop table t1; +CREATE TABLE t1 ( i int(11) NOT NULL default '0', c text NOT NULL, PRIMARY KEY (i), KEY (c(1),c(1))); +INSERT t1 VALUES (1,''),(2,''),(3,'asdfh'),(4,''); +select max(i) from t1 where c = ''; +max(i) +4 +drop table t1; diff --git a/mysql-test/t/type_blob.test b/mysql-test/t/type_blob.test index cf5c0d6e581..928f79a661e 100644 --- a/mysql-test/t/type_blob.test +++ b/mysql-test/t/type_blob.test @@ -312,3 +312,9 @@ select * from t1 where txt <= 'Chevy'; select * from t1 where txt > 'Chevy'; select * from t1 where txt >= 'Chevy'; drop table t1; +CREATE TABLE t1 ( i int(11) NOT NULL default '0', c text NOT NULL, PRIMARY KEY (i), KEY (c(1),c(1))); +INSERT t1 VALUES (1,''),(2,''),(3,'asdfh'),(4,''); +select max(i) from t1 where c = ''; +drop table t1; + + diff --git a/sql/opt_sum.cc b/sql/opt_sum.cc index 855813f1140..abf04cf5517 100644 --- a/sql/opt_sum.cc +++ b/sql/opt_sum.cc @@ -443,7 +443,9 @@ static bool find_range_key(TABLE_REF *ref, Field* field, COND *cond) // Save found constant if (part->null_bit) *key_ptr++= (byte) test(part->field->is_null()); - part->field->get_key_image((char*) key_ptr,part->length); + part->field->get_key_image((char*) key_ptr, + (part->field->type() == FIELD_TYPE_BLOB) ? + part->length + HA_KEY_BLOB_LENGTH : part->length); key_ptr+=part->store_length - test(part->null_bit); left_length-=part->store_length; }