Postgresql 负(逆)运算符vs NOT(…)
某些运算符有其反转选项,如:Postgresql 负(逆)运算符vs NOT(…),postgresql,postgresql-9.4,Postgresql,Postgresql 9.4,某些运算符有其反转选项,如: = vs != > vs <= < vs >= ~~ vs !~~ ~ vs !~ ... 而不是 col !~~ 'some text' 是否有任何运算符的反转运算符比使用而不是更快 postgres@localhost testdb=# create table foo (col varchar(255) not null); CREATE TABLE
= vs !=
> vs <=
< vs >=
~~ vs !~~
~ vs !~
...
而不是
col !~~ 'some text'
是否有任何运算符的反转运算符比使用而不是更快
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)
完全一样
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)