繁体   English   中英

如何在sybase ase 15.4中创建查询索引以提高性能?

[英]How to create indexes for query for better performance in sybase ase 15.4?

我有3个大表:tab1,tab2,tab3,tab4。 我有一个SQL查询,如:

select * from tab1 a, tab2 b, tab3 c, tab4 d
where 
    a.c1 = b.c1
and b.c2 = c.c2
and c.c3 = d.c3

and a.c4 = c.c4

and a.c3 = @var3
and a.c4 = @var4
and b.date >= @d1 and b.date <=@d2
and b.c5 =@var5
group by d.c6, a.c4, c.c7
order by d.c6, a.c4, c.c7

索引创建为:where条件中的每一列都创建了一个索引。 例如,以上查询中使用的tab1中有3列:c1,c3,c4。 创建了3个索引:c1上的索引,c3上的索引,onc4上的索引。

其他所有表相同。

问题:1.如何为出现在何处的那些列创建索引? 单列索引还是组合索引? 例如,对于tab1,每个索引的一个索引包括3列c1,c3,c4或3个索引?
2.是否还要为group by中的列创建索引?
3.顺序在哪里重要? 例如,以下3对性能有何影响?

where 
    a.c1 = b.c1
and b.c2 = c.c2
and c.c3 = d.c3

and a.c4 = c.c4  ----duplicate join???

and a.c3 = @var3
and a.c4 = @var4
and b.date >= @d1 and b.date <=@d2
and b.c5 =@var5

要么

where 
a.c3 = @var3
and a.c4 = @var4
and b.date >= @d1 and b.date <=@d2
and b.c5 =@var5

and a.c1 = b.c1
and b.c2 = c.c2
and c.c3 = d.c3
and a.c4 = c.c4  --duplicate join???

要么

where 
a.c3 = @var3
and a.c4 = @var4
and b.date >= @d1 and b.date <=@d2
and b.c5 =@var5

and a.c1 = b.c1
and b.c2 = c.c2
and c.c3 = d.c3

桌子多大? 遵循哪种锁定方案表?

通常,在远程查询的情况下,聚簇索引会更好地工作,但是如果表遵循DOL方案,那就不好了。

不用看表就很难确定应该创建哪些索引,但是我最初会像

  • Tab1:C3和C4上的2个不同的非聚集索引
  • Tab2:日期上的聚集索引,C5上的非聚集索引
  • Tab3:C2,C3和C4中的唯一聚集索引

我也将查询细分成小块:

  • 一个用于取出所有行(将它们放入#temp1中)
  • 在#temp1的C6,C4,C7上创建聚簇索引
  • 使用group by子句编写最终查询,其中只有#temp1会参与group by子句。 您可以跳过order by子句,因为我们已经在这些列上进行了聚类

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM