1 = 1上的加入与交叉加入 [英] Join on 1=1 versus cross join

查看:85
本文介绍了1 = 1上的加入与交叉加入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将postgresql中的一个大表连接到其中有1行的表.是的,我知道我可以只从这个单行表中获取值,然后将它们写到我的查询中,但是有210列.

I am joining a large table in postgresql to a table with 1 row in it. Yes, I know I could just take the values from this single row table and put them in my query written out, but there's 210 columns.

所以我的问题是这样的:我应该使用交叉连接还是在重言式上使用常规连接(1 = 1或类似的东西)将单行表连接到所有内容.这些方法中的任何一种注定会变慢吗?

So my question is this: should I join up the single row table to everything using a cross join or using a regular join on a tautology (1 = 1 or something). Is either of those ways bound to be slower?

还是有第三种更快的方法?

Or is there a third faster way?

推荐答案

要注意的一件事是,如果其中一个表为空,则交叉联接将导致表为空.如果您的一个表可能是空的并且您仍需要记录,则可能希望在1 = 1上进行外部联接(例如,左,右或全联接).

One thing to note is a cross join will result in an empty table if one of the tables is empty. If one of your tables might be empty and you still want records, you may want an outer join (e.g. left, right, or full) on 1=1.

这篇关于1 = 1上的加入与交叉加入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆