有些运营商的反转选项如下:
= vs !=
> vs <=
< vs >=
~~ vs !~~
~ vs !~
...
如果我要编写例如
,性能是否有任何差异NOT(col ~~ 'some text')
而不是
col !~~ 'some text'
使用NOT
?
答案 0 :(得分:2)
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)
它完全相同。