准备:
sql语句为:
create table a1 (a int);
create table a2 (a int);
create table a3 (a int,b int);
create table a4 (a int,b int);
insert into a1 values (0),(1);//(被除数)(除数)
insert into a2 values (0),(0);//
(被除数)(除数)
insert into a3 values (0,0),(1,1);//
(被除数,测试数)(除数,测试数)
insert into a4 values (0,1),0);//
(被除数,测试数)(除数,测试数)
需要知道的:
select 4/0;
ERROR: division by zero
select * from a1 where (4 / a > 2) and (a > 0);//
(4 / a > 2) a有可能为0
返回1;
select * from a1 where (4 / a > 2) and (a > a-1);
ERROR: division by zero
select * from a2 where (4 / a > 2) and (a > 0);
无返回;
select * from a3 where (4 / a > 2) and (b > 0);
返回1;
select * from a4 where (4 / a > 2) and (b > 0);
ERROR: division by zero
当没有and时,执行计划会根据通过语法解析的节点复杂度进行重新排序,而有or的时候,就会按照手写的顺序。