diff options
author | unknown <gkodinov/kgeorge@macbook.gmz> | 2007-01-23 19:45:58 +0200 |
---|---|---|
committer | unknown <gkodinov/kgeorge@macbook.gmz> | 2007-01-23 19:45:58 +0200 |
commit | d74a7b9def7a9fdbfe72325a4ba05f8647e252e4 (patch) | |
tree | 9b9ca4040693883a9177bf4489f327106dd22c98 /mysql-test/t/func_math.test | |
parent | 9af4bbc7b038a89e60bced7bd97cc1165525a020 (diff) | |
download | mariadb-git-d74a7b9def7a9fdbfe72325a4ba05f8647e252e4.tar.gz |
Bug #6172: RAND(a) should only accept constant values as arguments
RAND() must accept scalar expressions regardless of their kind.
That includes both constant expressions and expressions that
depend on column values.
When the expression is constant the random seed can be initialized
at compile time.
However when the expression is not constant the random seed must be
initialized at each invocation (while it still can be allocated at
compile time).
Implemented the above rules by extending Item_func_rand::val_real()
to initialize the random seed at the correct place.
mysql-test/r/func_math.result:
Bug #6172: RAND(a) should only accept constant values as arguments
- extened the test case
mysql-test/t/func_math.test:
Bug #6172: RAND(a) should only accept constant values as arguments
- extened the test case
sql/item_func.cc:
Bug #6172: RAND(a) should only accept constant values as arguments
- allow specifying non-const expressions as RAND() arguments
sql/item_func.h:
Bug #6172: RAND(a) should only accept constant values as arguments
- allow specifying non-const expressions as RAND() arguments
Diffstat (limited to 'mysql-test/t/func_math.test')
-rw-r--r-- | mysql-test/t/func_math.test | 24 |
1 files changed, 19 insertions, 5 deletions
diff --git a/mysql-test/t/func_math.test b/mysql-test/t/func_math.test index 09aa5751301..639ced6a1c0 100644 --- a/mysql-test/t/func_math.test +++ b/mysql-test/t/func_math.test @@ -115,11 +115,25 @@ select abs(-2) * -2; # # Bug #6172 RAND(a) should only accept constant values as arguments # -create table t1 (i int); -insert into t1 values (1); ---error 1210 -select rand(i) from t1; -drop table t1; +CREATE TABLE t1 (a INT); + +INSERT INTO t1 VALUES (1),(1),(1),(2); +SELECT CAST(RAND(2) * 1000 AS UNSIGNED), CAST(RAND(a) * 1000 AS UNSIGNED) + FROM t1; +SELECT CAST(RAND(2) * 1000 AS UNSIGNED), CAST(RAND(a) * 1000 AS UNSIGNED) + FROM t1 WHERE a = 1; +INSERT INTO t1 VALUES (3); +SELECT CAST(RAND(2) * 1000 AS UNSIGNED), CAST(RAND(a) * 1000 AS UNSIGNED) + FROM t1; +SELECT CAST(RAND(2) * 1000 AS UNSIGNED), CAST(RAND(a) * 1000 AS UNSIGNED) + FROM t1 WHERE a = 1; +PREPARE stmt FROM + "SELECT CAST(RAND(2) * 1000 AS UNSIGNED), CAST(RAND(?) * 1000 AS UNSIGNED) + FROM t1 WHERE a = 1"; +set @var=2; +EXECUTE stmt USING @var; + +DROP TABLE t1; # # Bug #14009: use of abs() on null value causes problems with filesort |