开发者

What are the differences between these two queries

The title speaks for itself. The first query -

SELECT    *
FROM      table _t
WHERE     (id1, id2, id3, id4) <> (x1, x2, x3, x4)

The second query -

SELECT    *
FROM      table_t
WHERE     NOT
          (id1 = x1 AND
           id2 = x2 AND
           id3 = x3 AND
           id4 = x4)

What are the differences betw开发者_运维知识库een these two queries (i.e., is there any performance gain/loss or something) ?

Edit

To all those who think I am joking or something, I just want to say that I have used both queries in postgresql 8.4. Both queries work just fine.


User Explain plan to find that out.


I would not expect there to be any difference between the two queries, but it really does depend on the optimizer for you DBMS. It may be that one of these forms prevents the optimizer from "seeing" the opportunity to use an index that the other form doesn't.

As @Jinesh says, you'd be better using whatever facilities are available in your DBMS to examine the plans the optimizer produces in these cases.


The performance will change if you have indexes on ids and x's.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜