如何加快简单加入 [英] How to Speed Up Simple Join

查看:111
本文介绍了如何加快简单加入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不擅长SQL.

我正在寻找一种加快像这样的简单连接的方法:

I am looking for a way to speed up a simple join like this:

SELECT
    E.expressionID,
    A.attributeName,
    A.attributeValue
FROM 
    attributes A
JOIN
    expressions E
ON 
    E.attributeId = A.attributeId

我做了数十万次,并且随着桌子的变大,它的消耗越来越大.

I am doing this dozens of thousands times and it's taking more and more as the table gets bigger.

我在考虑索引-如果要加快单个表上的选择的速度,我可能会在表达式表的expressionID上放置非聚集索引,在属性表的另一个属性上(attributeName,attributeValue)放置非聚集索引-但我不这样做知道如何将其应用于联接.

I am thinking indexes - If I was to speed up selects on the single tables I'd probably put nonclustered indexes on expressionID for the expressions table and another on (attributeName, attributeValue) for the attributes table - but I don't know how this could apply to the join.

编辑:我已经在expressions表上具有expressionId(PK),attributeId(PK,FK)上的聚簇索引,并且在属性表上具有attributeId(PK)的另一个聚簇索引

EDIT: I already have a clustered index on expressionId (PK), attributeId (PK, FK) on the expressions table and another clustered index on attributeId (PK) on the attributes table

我见过这个问题,但我要问的是更一般的东西,可能还很远更简单.

I've seen this question but I am asking for something more general and probably far simpler.

任何帮助表示赞赏!

推荐答案

您肯定希望在attributesexpressions表的attributeID上都具有索引.如果您目前没有这些索引,那么我认为您会看到很大的加速.

You definitely want to have indexes on attributeID on both the attributes and expressions table. If you don't currently have those indexes in place, I think you'll see a big speedup.

这篇关于如何加快简单加入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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