一些运营商有他们的反转选项,如:
= vs !=
> vs <=
< vs >=
~~ vs !~~
~ vs !~
...
例如,如果我要写的话,性能有什么不同吗
NOT(col ~~ 'some text')
代替
col !~~ 'some text'
是否有任何运算符的倒数运算符会比使用更快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)
它完全一样。