From 6850c17f94e8f3c7a29eab75df643a7e96c8ba29 Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 22 Feb 2005 21:58:10 +0300 Subject: [PATCH 1/2] Fix for BUG#8397 (second commit after review): In Item_cache_decimal::store(item) the call item->val_decimal_result() returns NULL if the passed item has an SQL null value. Don't try copying NULL into Item_cache_decimal::val in this case. mysql-test/r/type_decimal.result: Test for BUG#8397 mysql-test/t/type_decimal.test: Test for BUG#8397 sql/item.cc: Fix for BUG#8397: In Item_cache_decimal::store(item) the call item->val_decimal_result() returns NULL if the passed item has an SQL null value. Don't try copying NULL into Item_cache_decimal::val in this case. --- mysql-test/r/type_decimal.result | 18 +++++++++++++++++- mysql-test/t/type_decimal.test | 19 ++++++++++++++++++- sql/item.cc | 2 +- 3 files changed, 36 insertions(+), 3 deletions(-) diff --git a/mysql-test/r/type_decimal.result b/mysql-test/r/type_decimal.result index 6c4a1fab857..2d5c2d2ac97 100644 --- a/mysql-test/r/type_decimal.result +++ b/mysql-test/r/type_decimal.result @@ -1,4 +1,4 @@ -DROP TABLE IF EXISTS t1; +DROP TABLE IF EXISTS t1, t2; SET SQL_WARNINGS=1; CREATE TABLE t1 ( id int(11) NOT NULL auto_increment, @@ -677,3 +677,19 @@ a 9999.999 0000.000 drop table t1; +CREATE TABLE t1 +(EMPNUM CHAR(3) NOT NULL, +HOURS DECIMAL(5)); +CREATE TABLE t2 +(EMPNUM CHAR(3) NOT NULL, +HOURS BIGINT); +INSERT INTO t1 VALUES ('E1',40); +INSERT INTO t1 VALUES ('E8',NULL); +INSERT INTO t2 VALUES ('E1',40); +SELECT EMPNUM FROM t1 WHERE HOURS IN (SELECT HOURS FROM t2); +EMPNUM +E1 +SELECT EMPNUM FROM t1 WHERE HOURS IN (SELECT HOURS FROM t1); +EMPNUM +E1 +DROP TABLE t1,t2; diff --git a/mysql-test/t/type_decimal.test b/mysql-test/t/type_decimal.test index 6f170a52700..18ac5d1e467 100644 --- a/mysql-test/t/type_decimal.test +++ b/mysql-test/t/type_decimal.test @@ -1,7 +1,7 @@ # bug in decimal() with negative numbers by kaido@tradenet.ee --disable_warnings -DROP TABLE IF EXISTS t1; +DROP TABLE IF EXISTS t1, t2; --enable_warnings SET SQL_WARNINGS=1; @@ -268,3 +268,20 @@ insert into t1 values ('1'),('+1'),('-1'),('0000000001'),('+0000000001'),('-0000 --enable_warnings select * from t1; drop table t1; + +# Test for BUG#8397: decimal type in subselects (Item_cache_decimal) +CREATE TABLE t1 +(EMPNUM CHAR(3) NOT NULL, +HOURS DECIMAL(5)); +CREATE TABLE t2 +(EMPNUM CHAR(3) NOT NULL, +HOURS BIGINT); + +INSERT INTO t1 VALUES ('E1',40); +INSERT INTO t1 VALUES ('E8',NULL); +INSERT INTO t2 VALUES ('E1',40); + +SELECT EMPNUM FROM t1 WHERE HOURS IN (SELECT HOURS FROM t2); +SELECT EMPNUM FROM t1 WHERE HOURS IN (SELECT HOURS FROM t1); + +DROP TABLE t1,t2; diff --git a/sql/item.cc b/sql/item.cc index 33e6d7cfc42..da9c98862b7 100644 --- a/sql/item.cc +++ b/sql/item.cc @@ -4349,7 +4349,7 @@ my_decimal *Item_cache_real::val_decimal(my_decimal *decimal_val) void Item_cache_decimal::store(Item *item) { my_decimal *val= item->val_decimal_result(&decimal_value); - if (val != &decimal_value) + if (val != &decimal_value && !item->null_value) my_decimal2decimal(val, &decimal_value); null_value= item->null_value; } From eec458e2c59be4daf11c4b3d6094a3fbd681d31d Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 22 Feb 2005 21:59:02 +0300 Subject: [PATCH 2/2] Coding style fixes according to Sergei's feedback --- sql/opt_range.cc | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/sql/opt_range.cc b/sql/opt_range.cc index 2f93da28395..66d9da10334 100644 --- a/sql/opt_range.cc +++ b/sql/opt_range.cc @@ -2562,8 +2562,8 @@ static double ror_scan_selectivity(const ROR_INTERSECT_INFO *info, char *key_ptr= (char*) key_val; SEL_ARG *sel_arg, *tuple_arg= NULL; bool cur_covered; - bool prev_covered= (bitmap_is_set(&info->covered_fields, - key_part->fieldnr))? 1 : 0; + bool prev_covered= test(bitmap_is_set(&info->covered_fields, + key_part->fieldnr)); key_range min_range; key_range max_range; min_range.key= (byte*) key_val; @@ -2577,8 +2577,8 @@ static double ror_scan_selectivity(const ROR_INTERSECT_INFO *info, i++, sel_arg= sel_arg->next_key_part) { DBUG_PRINT("info",("sel_arg step")); - cur_covered= (bitmap_is_set(&info->covered_fields, - (key_part + i)->fieldnr))? 1 : 0; + cur_covered= test(bitmap_is_set(&info->covered_fields, + (key_part + i)->fieldnr)); if (cur_covered != prev_covered) { /* create (part1val, ..., part{n-1}val) tuple. */