1) TimesTen索引目前分两种:
Ø Hash索引做等值匹配查询具有较大的优势,但占用空间较大;只能出现在primary key上。
Ø T-tree索引则适宜做范围、排序等查询(Order By,Group By,Distinct),当然它也可做等值查询,占用空间较小。语法create index test_idx on test(a,b);
2) 主键缺省具有Hash索引。
3) 建Hash 索引时必须定义Pages值(Rows/256),以避免Hash冲突。
4) 全表扫描时候,如果被扫描的表具有T-tree索引(不管这个索引的列是否被用到),则性能会有较大的提升。
5) 组合索引时,Hash 索引需要列的完全匹配,而T-tree索引只需要前置匹配。如:
SELECT … FROM T1 WHERE COL1 = ? AND COL2 = ?
|
索引 |
Hash |
T-Tree |
| Hash index: (COL1, COL2)
T-tree index: (COL1, COL2, COL3) |
是
可能会选择Hash,如果Hash索引较快的话 |
是 |
| Hash index: (COL1, COL2, COL3)
T-tree index: (COL1, COL2) |
否 |
是 |
| Hash index: (COL1)
T-tree index: (COL3, COL1, COL2) |
是 |
否(不能前置匹配) |
| Hash index: (COL1, COL2, COL3)
T-tree index: (COL3, COL1, COL2) |
否 |
否(会做全表扫描,但由于有T-tree索引,所以会比普通的全表扫描要快) |
6) 对下列语句
WHERE c1+10 < c2+20写成WHERE c1 < c2+10在C1上创建索引
7) 如果表的空间无法预测,即不能定义Pages的值,或者索引的列中包含 大的Char/Binary 以及组合列时,建议使用unique index
用如下两个存储过程进行表的分析,以提高执行的效率
Ø ttOptUpdateStats (全表)
Ø ttOptEstimateStats (抽取部分)
9) 执行计划会一直使用,直到碰到下列情形:
Ø A table it uses is dropped
Ø A table it uses is altered
Ø An index on a table it references is dropped
Ø An index is created on a table it references
Ø Statistics are recomputed
10) 执行计划:
Command> autocommit 0;
Command> showplan 1;
Command> prepare SELECT * from test;
或:
Command> autocommit 0;
Command> call ttOptSetFlag(’GenPlan’,1);
Command> prepare SELECT * from test;
Command> SELECT * FROM plan;
11) 有时候系统也会创建临时索引以加快查询速度,但如果临时索引创建地过于频繁,就要考虑手工建相应的索引,这可以通过系统表 MONITOR 的列 CMD_TEMP_INDEXES来监测。
文章 (RSS)