C:\Program Files (x86)\MariaDB 10.1\bin>mysql -uroot -proot -P3316 test
|
Welcome to the MariaDB monitor. Commands end with ; or \g.
|
Your MariaDB connection id is 2
|
Server version: 10.1.13-MariaDB mariadb.org binary distribution
|
|
Copyright (c) 2000, 2016, Oracle, MariaDB Corporation Ab and others.
|
|
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
|
|
MariaDB [test]> drop table t1;
|
Query OK, 0 rows affected (0.47 sec)
|
|
MariaDB [test]> create table t1(c1 int);
|
Query OK, 0 rows affected (0.19 sec)
|
|
MariaDB [test]> insert into t1 values(1);
|
Query OK, 1 row affected (0.14 sec)
|
|
MariaDB [test]> select * from t1 where ( (c1 is not null) >= (not true) ) is not
|
null;
|
Empty set (0.08 sec)
|
|
MariaDB [test]> select c1, c1 is not null, not true, ((c1 is not null) >= (not true)) as a from t1;
|
+------+----------------+----------+---+
|
| c1 | c1 is not null | not true | a |
|
+------+----------------+----------+---+
|
| 1 | 1 | 0 | 1 |
|
+------+----------------+----------+---+
|
1 row in set (0.00 sec)
|
|
MariaDB [test]> select c1, c1 is not null, not true, ((c1 is not null) >= (not true)) is not null as a from t1;
|
+------+----------------+----------+---+
|
| c1 | c1 is not null | not true | a |
|
+------+----------------+----------+---+
|
| 1 | 1 | 0 | 1 |
|
+------+----------------+----------+---+
|
1 row in set (0.00 sec)
|
|
MariaDB [test]> select c1, c1 is not null, (((c1 is not null) >= (not true)) is
|
not null) as a from t1 where ( (c1 is not null) >= (not true) ) is not null;
|
Empty set (0.00 sec)
|
|
MariaDB [test]> explain extended select c1, c1 is not null, (((c1 is not null) >
|
= (not true)) is not null) as a from t1 where ( (c1 is not null) >= (not true) )
|
is not null;
|
+------+-------------+-------+------+---------------+------+---------+------+---
|
---+----------+-------------+
|
| id | select_type | table | type | possible_keys | key | key_len | ref | ro
|
ws | filtered | Extra |
|
+------+-------------+-------+------+---------------+------+---------+------+---
|
---+----------+-------------+
|
| 1 | SIMPLE | t1 | ALL | NULL | NULL | NULL | NULL |
|
1 | 100.00 | Using where |
|
+------+-------------+-------+------+---------------+------+---------+------+---
|
---+----------+-------------+
|
1 row in set, 1 warning (0.06 sec)
|
|
MariaDB [test]> show warnings\G
|
*************************** 1. row ***************************
|
Level: Note
|
Code: 1003
|
Message: select `test`.`t1`.`c1` AS `c1`,(`test`.`t1`.`c1` is not null) AS `c1 i
|
s not null`,(((`test`.`t1`.`c1` is not null) >= (not(1))) is not null) AS `a` fr
|
om `test`.`t1` where (((`test`.`t1`.`c1` is not null) >= <cache>((not(1)))) is n
|
ot null)
|
1 row in set (0.00 sec)
|
|
MariaDB [test]> select 1 is not null;
|
+---------------+
|
| 1 is not null |
|
+---------------+
|
| 1 |
|
+---------------+
|
1 row in set (0.00 sec)
|
|
I can reproduce this with 10.1.13 also:
C:\Program Files (x86)\MariaDB 10.1\bin>mysql -uroot -proot -P3316 test
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 2
Server version: 10.1.13-MariaDB mariadb.org binary distribution
Copyright (c) 2000, 2016, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [test]> drop table t1;
Query OK, 0 rows affected (0.47 sec)
MariaDB [test]> create table t1(c1 int);
Query OK, 0 rows affected (0.19 sec)
MariaDB [test]> insert into t1 values(1);
Query OK, 1 row affected (0.14 sec)
MariaDB [test]> select * from t1 where ( (c1 is not null) >= (not true) ) is not
null;
Empty set (0.08 sec)
MariaDB [test]> select c1, c1 is not null, not true, ((c1 is not null) >= (not true)) as a from t1;
+------+----------------+----------+---+
| c1 | c1 is not null | not true | a |
+------+----------------+----------+---+
| 1 | 1 | 0 | 1 |
+------+----------------+----------+---+
1 row in set (0.00 sec)
MariaDB [test]> select c1, c1 is not null, not true, ((c1 is not null) >= (not true)) is not null as a from t1;
+------+----------------+----------+---+
| c1 | c1 is not null | not true | a |
+------+----------------+----------+---+
| 1 | 1 | 0 | 1 |
+------+----------------+----------+---+
1 row in set (0.00 sec)
MariaDB [test]> select c1, c1 is not null, (((c1 is not null) >= (not true)) is
not null) as a from t1 where ( (c1 is not null) >= (not true) ) is not null;
Empty set (0.00 sec)
MariaDB [test]> explain extended select c1, c1 is not null, (((c1 is not null) >
= (not true)) is not null) as a from t1 where ( (c1 is not null) >= (not true) )
is not null;
+------+-------------+-------+------+---------------+------+---------+------+---
---+----------+-------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | ro
ws | filtered | Extra |
+------+-------------+-------+------+---------------+------+---------+------+---
---+----------+-------------+
| 1 | SIMPLE | t1 | ALL | NULL | NULL | NULL | NULL |
1 | 100.00 | Using where |
+------+-------------+-------+------+---------------+------+---------+------+---
---+----------+-------------+
1 row in set, 1 warning (0.06 sec)
MariaDB [test]> show warnings\G
*************************** 1. row ***************************
Level: Note
Code: 1003
Message: select `test`.`t1`.`c1` AS `c1`,(`test`.`t1`.`c1` is not null) AS `c1 i
s not null`,(((`test`.`t1`.`c1` is not null) >= (not(1))) is not null) AS `a` fr
om `test`.`t1` where (((`test`.`t1`.`c1` is not null) >= <cache>((not(1)))) is n
ot null)
1 row in set (0.00 sec)
MariaDB [test]> select 1 is not null;
+---------------+
| 1 is not null |
+---------------+
| 1 |
+---------------+
1 row in set (0.00 sec)
So, it seems expression is evaluated differently somehow when it's in WHERE clause comparing to it's value in SELECT clause.