表中不同键的相同数据需要花费大量时间

发布于 2024-10-26 14:21:34 字数 416 浏览 4 评论 0原文

我有一个表...

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

梦里兽 2024-11-02 14:21:35

连接可能正在使用表扫描。检查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.

燕归巢 2024-11-02 14:21:35

 


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.

哇,说的太少了。

答案取决于三件事。

  1. 你的表是如何定义的?
    • 你有主键吗?哪些列是键?
      如果上表中只有两个“FactorID”值,那么对于主键来说这将是一个糟糕的选择。
    • 是否还有其他列已编入索引?
    • 您实际上有名为“col1”和“col2”的列吗?或者你只是说,“名字并不重要”?

    如何定义其他表也很重要。他们有钥匙吗?

     

  2. 表中的数据是什么类型?有多少行?

     
  3. 最重要的是:“当我将表与其他表连接时”是什么意思?有多少张表正在连接?你如何进行连接?

另外,你说你的查询“永远不会结束”——你等了多久?

抱歉,我们需要更多信息才能给出有意义的答案。

 


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.

  1. How are your tables defined?
    • Do you have primary keys? Which columns are keys?
      If there are only two "FactorID" values in the table shown above, that would be a poor choice for a primary key.
    • Are any other columns indexed?
    • Do you actually have columns named "col1" and "col2"? Or are you just saying, "the names don't matter"?

    It matters how the OTHER tables are defined too. Do they have any keys?

     

  2. What type of data is in the tables? How many rows?

     
  3. The most important thing: What do you mean by "when I join table with some other tables"? How many tables are being joined? How are you doing the joins?

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文