这两个查询有什么区别
标题不言而喻。第一个查询 -
SELECT *
FROM table _t
WHERE (id1, id2, id3, id4) <> (x1, x2, x3, x4)
第二个查询 -
SELECT *
FROM table_t
WHERE NOT
(id1 = x1 AND
id2 = x2 AND
id3 = x3 AND
id4 = x4)
这两个查询之间有什么区别(即是否有任何性能增益/损失或其他)?
编辑
对于所有认为我在开玩笑或其他什么的人,我只想说我在 postgresql 8.4 中使用了这两个查询。 两个查询都运行良好。
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 between 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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
用户解释计划来找出答案。
User Explain plan to find that out.
我不希望这两个查询之间有任何差异,但它确实取决于 DBMS 的优化器。其中一种形式可能会阻止优化器“看到”使用另一种形式没有看到的索引的机会。
正如@Jinesh 所说,您最好使用 DBMS 中可用的任何工具来检查优化器在这些情况下生成的计划。
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.
如果您在
id
和x
上有索引,性能将会改变。The performance will change if you have indexes on
id
s andx
's.