表中不同键的相同数据需要花费大量时间
我有一个表...
FactorID, col1 col2 Factor Value
1 a 2 1231
1 b 3 2342
2 a 2 1233
2 b 3 2344
这意味着...对于因素 Id 1,我有 1500 条记录...而因素 Id 2 我有相同数量的记录。
对于因子 ID 1 和 2,除了“因子值”之外,每个值都相同。
当我将上面的表与其他一些表连接起来以获取数据时...... FactorID 1 给了我快速结果...但是当我查询“2”时...执行永远不会结束。
这对我来说似乎是一个奇怪的错误。与行锁有关吗? 请帮我。
I have a table...
FactorID, col1 col2 Factor Value
1 a 2 1231
1 b 3 2342
2 a 2 1233
2 b 3 2344
That mean ... For factor Id 1, I have 1500 records...and factor Id 2 I have same number of records.
For Factor Ids 1 &2 every values are same except "Factor Value".
When I join above table with some other tables to fetch data...
FactorID 1 gives me quick results...but when I query for "2" ...the execution never ends.
This seems to be weird eror to me. Is it something related to row-lock ?
Please helpme.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
连接可能正在使用表扫描。检查FactorID是否有索引。您看到的结果可能是因为 FactorID 1 记录位于表中的第一个,而当涉及到 FactorID 2 时,它会继续一条一条地跳过 FactorID1 的记录,直到到达 FactorID 2。
It could be that the join is using a table scan. Check whether FactorID has got an index. The results you are seeing might be because FactorID 1 records are first in the table and when it comes to FactorID 2, it goes on skipping records for FactorID1 one by one until it comes to FactorID 2.
When I join above table with some other tables to fetch data...
FactorID 1 gives me quick results...
but when I query for "2" ...the execution never ends.
哇,说的太少了。
答案取决于三件事。
如果上表中只有两个“FactorID”值,那么对于主键来说这将是一个糟糕的选择。
如何定义其他表也很重要。他们有钥匙吗?
另外,你说你的查询“永远不会结束”——你等了多久?
抱歉,我们需要更多信息才能给出有意义的答案。
When I join above table with some other tables to fetch data...
FactorID 1 gives me quick results...
but when I query for "2" ...the execution never ends.
Wow, that's saying very little.
The answer depends on three things.
If there are only two "FactorID" values in the table shown above, that would be a poor choice for a primary key.
It matters how the OTHER tables are defined too. Do they have any keys?
Plus, you say that your query "never ends" - how long did you wait?
Sorry, but we need a LOT more information before a meaningful answer can be given.