负(逆)运算符与 NOT(...)

negative (inversed) operator vs NOT(...)

有些运算符有它们的反转选项,例如:

= vs !=
> vs <=
< vs >=
~~ vs !~~
~ vs !~
...

如果我这样写,性能上有什么不同吗

NOT(col ~~ 'some text')

而不是

col !~~ 'some text'

是否有任何运算符的逆运算符比使用 NOT 更快?

postgres@localhost testdb=# create table foo (col varchar(255) not null);    
CREATE TABLE                                                                 
Temps : 8,425 ms                                                             
postgres@localhost testdb=# insert into foo (col) values ('bar');            
INSERT 0 1                                                                   
Temps : 2,286 ms                                                             
postgres@localhost testdb=# select * from foo;                               
 col                                                                         
-----                                                                        
 bar                                                                         
(1 ligne)                                                                    


Temps : 0,934 ms                                                             
postgres@localhost testdb=# select * from foo where not(col ~~ 'some text'); 
 col                                                                         
-----                                                                        
 bar                                                                         
(1 ligne)                                                                    

postgres@localhost testdb=# explain select * from foo where not(col ~~ 'some text'); 
                       QUERY PLAN                                                    
--------------------------------------------------------                             
 Seq Scan on foo  (cost=0.00..11.75 rows=139 width=516)                              
   Filter: ((col)::text !~~ 'some text'::text)                                       
(2 lignes)                                                                           


Temps : 3,011 ms                                                                     
postgres@localhost testdb=# explain select * from foo where col !~~ 'some text';     
                       QUERY PLAN                                                    
--------------------------------------------------------                             
 Seq Scan on foo  (cost=0.00..11.75 rows=139 width=516)                              
   Filter: ((col)::text !~~ 'some text'::text)                                       
(2 lignes)                                                                           

完全一样