Bug #83907 | A where condition on a function behaves different than inlining the function | ||
---|---|---|---|
Submitted: | 21 Nov 2016 11:17 | Modified: | 23 Nov 2016 0:14 |
Reporter: | Jesper Kristensen | Email Updates: | |
Status: | Verified | Impact on me: | |
Category: | MySQL Server: User-defined functions ( UDF ) | Severity: | S2 (Serious) |
Version: | 5.7.16 | OS: | Debian (Using official Docker images) |
Assigned to: | CPU Architecture: | Any |
[21 Nov 2016 11:17]
Jesper Kristensen
[22 Nov 2016 23:50]
MySQL Verification Team
Please print here the output of your test case; It fails for me: SELECT n, b, f(b) FROM t1 LEFT JOIN t2 USING (n) WHERE IF(b, FALSE, TRUE); ERROR 1305 (42000): FUNCTION test.f does not exist. Thanks in advance.
[23 Nov 2016 0:05]
MySQL Verification Team
mysql> select * from t1; +---+ | n | +---+ | 0 | | 1 | | 2 | +---+ 3 rows in set (0.00 sec) mysql> select * from t2; +---+------+ | n | b | +---+------+ | 0 | 0 | | 1 | 1 | +---+------+ 2 rows in set (0.00 sec) mysql> SELECT n, b, neg(b) FROM t1 LEFT JOIN t2 USING (n) WHERE IF(b, FALSE, TRUE); +---+------+--------+ | n | b | neg(b) | +---+------+--------+ | 0 | 0 | 1 | | 2 | NULL | 1 | +---+------+--------+ 2 rows in set (0.05 sec) mysql> SELECT n, b, neg(b) FROM t1 LEFT JOIN t2 USING (n) WHERE neg(b); +---+------+--------+ | n | b | neg(b) | +---+------+--------+ | 0 | 0 | 1 | +---+------+--------+ 1 row in set (0.00 sec) mysql> SELECT n, b, neg(b) FROM t1 LEFT JOIN t2 USING (n) HAVING IF(b, FALSE, TRUE); +---+------+--------+ | n | b | neg(b) | +---+------+--------+ | 0 | 0 | 1 | | 2 | NULL | 1 | +---+------+--------+ 2 rows in set (0.00 sec) mysql> SELECT n, b, neg(b) FROM t1 LEFT JOIN t2 USING (n) HAVING neg(b); +---+------+--------+ | n | b | neg(b) | +---+------+--------+ | 0 | 0 | 1 | | 2 | NULL | 1 | +---+------+--------+ 2 rows in set (0.00 sec)
[23 Nov 2016 0:14]
MySQL Verification Team
Hi, Thanks for the report, yes select neg(null) behaves differently then select where neg(null) but only in join where that null was "calculated" .. as for e.g. mysql> insert into t2 values (2,null); Query OK, 1 row affected (0.00 sec) mysql> select * from t2; +---+------+ | n | b | +---+------+ | 0 | 0 | | 1 | 1 | | 2 | NULL | +---+------+ 3 rows in set (0.00 sec) mysql> select b,neg(B) from t2; -- this is ok +------+--------+ | b | neg(B) | +------+--------+ | 0 | 1 | | 1 | 0 | | NULL | 1 | +------+--------+ 3 rows in set (0.00 sec) mysql> select b,neg(b) from t2 where b; -- this is ok +------+--------+ | b | neg(b) | +------+--------+ | 1 | 0 | +------+--------+ 1 row in set (0.00 sec) mysql> select b,neg(b) from t2 where neg(b); -- this is ok +------+--------+ | b | neg(b) | +------+--------+ | 0 | 1 | | NULL | 1 | +------+--------+ 2 rows in set (0.00 sec) so it's only not ok with left join when you are missing the value mysql> insert into t1 values (3); Query OK, 1 row affected (0.00 sec) mysql> SELECT n, b, neg(b) FROM t1 LEFT JOIN t2 USING (n) WHERE neg(b); +---+------+--------+ | n | b | neg(b) | +---+------+--------+ | 0 | 0 | 1 | | 2 | NULL | 1 | +---+------+--------+ 2 rows in set (0.00 sec) mysql> the 2,null,1 row is here (null from t2 not from "missing" value) I'm verifying this, thanks for the report Bogdan Kecman