连接多个大表
我有三个表
Table T1: Columns {a,b,c}, combination {a,b} is unique in Table T1
Table T2: Columns {a,c,d}, combination {a,c} is unique in Table T2
Table T3: Columns {a,c,e}, combination {a,c} is unique in Table T3
,其中 {a,b,c} 是字符串,{d,e} 是数字
我希望我的输出是
Table T4: Columns {a,b} where e/d < x.
表 T1,T2,T3 都非常大(数百万行),所以我实现这个的方式是通过对表 T1 T2 进行左联接并将结果保存到临时表,然后对表 T1 T3 进行左联接并保存结果,然后对结果进行左联接,最后将这些临时表合并为 1 个最终表桌子。
我的问题是,有没有更好/更有效的方法来做到这一点而不破坏数据库?
I have three tables
Table T1: Columns {a,b,c}, combination {a,b} is unique in Table T1
Table T2: Columns {a,c,d}, combination {a,c} is unique in Table T2
Table T3: Columns {a,c,e}, combination {a,c} is unique in Table T3
where {a,b,c} are strings and {d,e} are numbers
I want my output to be
Table T4: Columns {a,b} where e/d < x.
Tables T1,T2,T3 are all very large (millions of rows), so the way I implemented this is by doing an left join on table T1 T2 and saving the results to a temp table, then doing an left join on tables T1 T3 and saving the results, then doing an left join of the results and finally combining these temp tables into 1 final table.
My question is, is there a better/more efficient way to do this without blowing up the database?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您是否尝试过直接这样做?
在临时表中存储数百万条记录对于性能或存储都没有好处......
Have you tried just doing this the straight-forward way?
Storing millions of records in temp tables isn't good for performance or storage...