如何从巨大的表中快速选择给定范围内的值之和(Derby)
我得到 A 和 B 表,如下所示:
表 A
a b mount
a0 b0 0.0001
a0 b1 0.0002
表 B
c d weight
c0 d0 0.99998
c0 d1 0.99996
每个表都有 10,000 - 100000 条记录。
我想获得 mount+weight >= 0.9998
和 mount+weight <= 0.9999
的所有组合,例如:
a b c d sum
a0 b0 c0 d0 0.9999
a0 b1 c0 d1 0.9998
但是如果我尝试时需要花费很多时间有这些方法:
方法1
SELECT a b c d mount+weight
FROM A,B
WHERE mount+weight >= 0.9998 and mount+weight <= 0.9999
A表有mount索引,B表有weight索引
方法2
创建A+B
表,但是比方法1花费更多时间,
有什么办法改进吗?
I got A and B table like:
Table A
a b mount
a0 b0 0.0001
a0 b1 0.0002
Table B
c d weight
c0 d0 0.99998
c0 d1 0.99996
Each table has 10,000 - 100000 records.
I want to get all combination that mount+weight >= 0.9998
and mount+weight <= 0.9999
, for example:
a b c d sum
a0 b0 c0 d0 0.9999
a0 b1 c0 d1 0.9998
But if takes a lot of time when i try these ways:
Method 1
SELECT a b c d mount+weight
FROM A,B
WHERE mount+weight >= 0.9998 and mount+weight <= 0.9999
A table have index of mount, B table have index of weight
Method 2
Create A+B
table, but it takes more time than method 1.
Is there any ways to improve?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试
这可能会产生略有不同的执行计划
编辑:我刚刚意识到这是针对德比的。甚至不确定 BETWEEN 在德比是否可用
try
This may produce a slightly different execution plan
Edit: I just realised this is for Derby. Not even sure if BETWEEN is available in Derby