TimesTen中的索引和其它数据库一样,都是为了加速查询

Indexes are auxiliary data structures that greatly improve the performance of table searches.
Indexes are used automatically by the query optimizer to speed up the execution of a query.

演示环境准备

create table test(a int, b timestamp, primary key(a));declare a number := 1;
begin
for i in 1..100000 loop  a := a+1;insert into test values(a, sysdate);commit;
end loop;
end;
/

索引类型和查看

TimesTen支持三种索引类型,这比Oracle要简单得多,内存数据库的性能使其没有必要支持那么多类型的索引。

  • Range Index(T-tree Index)
    适合于范围匹配,如where a between c and d, 或where a > value

    Range indexes are useful for finding rows with column values within a certain range.
    但没有指定Index类型时,Range Index为缺省类型。

  • Hash Index
    适合于完全匹配, 如where a=value

    are useful for equality searches

  • Bitmap Index

    Bitmap indexes are useful when searching and retrieving data from columns with low cardinality
    low cardinality指列具有较少的唯一值,如性别。bitmap中的每一个bit表示一行。
    Bitmap Index占用空间较少。

三者的比较如下:

Hash indexes are faster than range indexes for exact match lookups, but they require more space than range indexes. Hash indexes cannot be used for lookups involving ranges.
Range indexes are optimized for in-memory data management and provide efficient sorting by column value.
TimesTen may create temporary hash and range indexes automatically during query processing to speed up query execution.

查看索引类型可以使用indexes命令或查询系统表:
indexes命令

Command> indexesIndexes on table ORACLE.A:No indexes found.Indexes on table ORACLE.TEST:TEST: unique range index on columns:AHASHIDX: non-unique hash index on columns: A2 indexes found.Indexes on table ORACLE.TEST1:TEST1: unique range index on columns:A1 index found.3 indexes found on 3 tables.
Command> indexes testIndexes on table ORACLE.TEST:TEST: unique range index on columns:AHASHIDX: non-unique hash index on columns: A2 indexes found.2 indexes found on 1 table.

查询系统表

select t.tblname, i.ixname, i.ixtype,
(case i.ixtype when 0 then 'HASH'
when 1 then 'T-TREE'
when 2 then 'BITMAP'
when 3 then 'B+TREE'
else 'WeirdTypeFound' end)
from tables t, indexes i
where t.tblowner = current_user
and t.tblid = i.tblid
order by t.tblname, i.ixtype;< TEST                           , HASHIDX                        , 0, HASH >
< TEST                           , TEST                           , 1, T-TREE >
< TEST1                          , TEST1                          , 1, T-TREE >
3 rows found.

创建索引

每一个index都有属主,即创建表的属主
LOB列不能有索引
例:

CREATE HASH INDEX custname_idx ON customer(cust_name);

HASH索引的特殊考虑

为避免hash冲突,创建hash索引时需指定hash index pages参数,算法是表中估计的行数除以256,如果表的行数变化很大,就建议用range index。例如:

Command> select count(*) from test;
< 100000 >
1 row found.
Command> create hash index hashidx on test(a) pages = 390;

其中390=100000/256

修改索引

唯一可改的是使用range index还是hash index。

You can use the ALTER TABLE statement to add (or change) a primary key constraint to use either a range or hash index.

Command> alter table test1 add constraint test1 primary key(a);
Command> indexes test1Indexes on table ORACLE.TEST1:TEST1: unique range index on columns:A1 index found.1 index found on 1 table.
Command> alter table test1 use hash index pages = current;Command> alter table test1 use range index;
Command> indexes test1Indexes on table ORACLE.TEST1:TEST1: unique range index on columns:A1 index found.1 index found on 1 table.

删除索引

语法:DROP INDEX [Owner.]IndexName [FROM [Owner.]TableName]
以下演示Drop index无法删除primary key,Primary key不允许删除。

Command> indexesIndexes on table ORACLE.A:IDX1: non-unique range index on columns: A1 index found.Indexes on table ORACLE.TEST:TEST: unique range index on columns:A1 index found.Indexes on table ORACLE.TEST1:No indexes found.2 indexes found on 3 tables.
Command> drop index idx1;
Command> drop index test;2215: Attempt to drop a primary key index
The command failed.

以下演示index重名时需指定表名

Command> create index idx1 on a(a);
Command> create index idx1 on test1(a);
Command> indexesIndexes on table ORACLE.A:IDX1: non-unique range index on columns: A1 index found.Indexes on table ORACLE.TEST:TEST: unique range index on columns:A1 index found.Indexes on table ORACLE.TEST1:IDX1: non-unique range index on columns: A1 index found.3 indexes found on 3 tables.
Command> drop index idx1;2222: Index name is not unique. More than one table has an index with this name.
The command failed.
Command> drop index idx1 from test1;
Command> drop index idx1 from a;

估算/计算索引空间

使用ttSize,如下:

[oracle@tt12c ~]$ ttsize -tbl test sampledb_1122Rows = 100000Total in-line row bytes = 6040494Indexes:Range index ORACLE.TEST adds 2035434 bytesTotal index bytes = 2035434Total = 8075928[oracle@tt12c ~]$ ttsize -tbl test -rows 11111111 sampledb_1122Rows = 11111111Total in-line row bytes = 669500798Indexes:Range index ORACLE.TEST adds 225752554 bytesTotal index bytes = 225752554Total = 895253352

dsmap不能估算,但可以监控当前索引占用空间:

“`
[oracle@tt12c support]$ ./dsmap -dsname /home/oracle/TimesTen/tt1122/info/DemoDataStore/sampledb_1122.ds0 -tblsize oracle.test
2016-05-03 18:58:55.799
/home/oracle/TimesTen/tt1122/info/DemoDataStore/sampledb_1122.ds0
TimesTen Release 11.2.2.8.11

* WARNING - Checkpoint file is not for a sync checkpoint!

DSN = sampledb_1122
filesize = 61048560 (58.22m)
maxid_file = 41941112
maxid_ds = 41943040

Size information for ORACLE.TEST

Total logical pages = 391
Logical page space used = 1807984

In-line information

Total physical pages = 391
Used rows = 100000
Free rows = 96
Total in-line size = 4210288

Space usage information for index ORACLE.TEST

Index type is T-Tree

Hdr size = 1440
Node size = 672
Nodes = 3076

Total index usage = 2068512

System usage = 18416

Total usage for ORACLE.TEST= 8105200
“`

使用Index Advisor作出索引建议

选择正确的索引对性能影响很大,Index Advisor可以针对特定的SQL工作负载提出索引建议。一般用于读密集型工作负载,对于写密集型的工作负载不建议使用。
后续会做详细介绍,这里就不赘述了。

参考

  • Oracle® TimesTen In-Memory Database Operations Guide |8 Working with Data in a TimesTen Database| Understanding indexes
  • How do I check whether B+Tree or T-Tree indexes are being created on a TimesTen datastore? (文档 ID 1504280.1)

TimesTen索引的概念与日常操作相关推荐

  1. Oracle 数据库简单日常操作

    Oracle 数据库简单日常操作 目录 Oracle 数据库简单日常操作 SQL基础部分 1.简介 2.安装好之后可以登录系统账户 3.用户与表空间 4.数据字典 5.如何启用scott用户 6.表空 ...

  2. Mysql索引基本概念及案例总结(含索引的使用注意事项)

    Mysql索引基本概念及案例总结 键(Key)与索引(Index)关键字的区别 索引是键的列表,当我们定义一个key(外键除外,一般是PRIMARY KEY或者KEY形式)时就会产生对应的索引.一般情 ...

  3. Linux上的gitlab日常操作

    Linux上的gitlab日常操作 一.本地创建系统用户 1.创建zhangsan用户 2.创建数据存放目录 二.git用户信息配置 1.git信息配置 2.查看git信息状态 三.下载代码版本库 1 ...

  4. 理解SQL Server中索引的概念,原理以及其他

    简介 在SQL Server中,索引是一种增强式的存在,这意味着,即使没有索引,SQL Server仍然可以实现应有的功能.但索引可以在大多数情况下大大提升查询性能,在OLAP中尤其明显.要完全理解索 ...

  5. OCM备考 三. Managing Database Availability 之RMAN日常操作

    10 OCM考试大纲关于RMAN的考点: 三 Managing Database Availability ﹡ Create a recovery catalog database ﹡ Configu ...

  6. 索引的概念和创建索引例子

    1 索引的概念 索引是一个单独的.物理的数据库结构,它是某个表中一列或若干列值的集合和相应的指向表中物理标识这些值的数据页的逻辑指针清单.表的存储由两部分组成,一部分用来存放数据页面,另一部分存放索引 ...

  7. T-SQL查询进阶--理解SQL Server中索引的概念,原理以及其他(看了两次了,转了)

    简介 在SQL Server中,索引是一种增强式的存在,这意味着,即使没有索引,SQL Server仍然可以实现应有的功能.但索引可以在大多数情况下大大提升查询性能,在OLAP中尤其明显.要完全理解索 ...

  8. postgreSQL源码分析——索引的建立与使用——各种索引类型的管理和操作(2)

    2021SC@SDUSC 目录 上层操作函数 index_open index_beginscan() index_create() indexcmd.c 下层接口函数 IndexScanDescDa ...

  9. postgreSQL源码分析——索引的建立与使用——各种索引类型的管理和操作(1)

    2021SC@SDUSC 目录 概述 管理索引的系统表 记录索引相关的系统表 与索引系统表相关的后端源码 索引的操作函数 上层操作函数 下层接口函数 概述 索引是指按表中某些关键属性或表达式建立元组的 ...

  10. OpenShift 4 之 Image Registry、Image 和 ImageStream 概念和相关操作

    <OpenShift 4.x HOL教程汇总> OpenShift 4 之 Image Registry.Image 和 ImageStream 概念和相关操作 概念篇 1. Contai ...

最新文章

  1. 解决:sql中将日期字符串当做日期类型处理
  2. 受益匪浅:十个哲理寓言,十个成功秘诀
  3. Tungsten Fabric SDN — 与 OpenStack 的集成部署
  4. python中定制类_python定制类__str__(实例详解)
  5. 真香定律!Android动态换肤实现原理解析,吐血整理
  6. 从没想过会有一个这样的机会|大疆招聘
  7. CentOs基础操作指令(压缩、定时任务调度)
  8. 【转】windows多线程CreateThread与_beginthreadex本质区别
  9. 深入浅出MFC学习笔记:MFC六大关键技术仿真之RTTI运行时类型识别
  10. linux 快速合并文本文件,Linux-Linux中高效合并文本文件的方法
  11. pycharm设置python环境_pycharm怎么配置python环境
  12. 安装sql2000提示html,安装sql2000数据库提示:command line option syntax error
  13. python dbf导入到sql_python读写dbf数据库
  14. C++下caffe使用教程
  15. android 摄像头同时打开方式,Android,同时打开前置和后置摄像头
  16. 智能卡CPU卡开卡指令
  17. 公交线路管理 数据结构课程设计
  18. 贴片功率电感封装尺寸与性能
  19. bugku 细心的大象
  20. 永远的谭嗣同--2005年四川高考满分作文

热门文章

  1. 航拍地形图转换成地形图_无人机航测生成地形图技术流程(Pix4D+ArcGIS+CASS)...
  2. 【T+】畅捷通T+认证报错,提示:“当前加密狗信息无效,无法进行企业认证”
  3. CADD课程学习(10)-- 模拟不同体系与小分子相互作用(MOE)
  4. BAT文件中如何注释:
  5. 二、建模及画网格软件推荐
  6. 如何防御xss?HTML编码和JS编码
  7. 关于阿里云,有什么故事?
  8. React Native踩坑新建的RN0.64项目无法在xcode 12.5上打开
  9. VirtualBox上安装WindowsXP的完整教程
  10. Cadence每日一学_01| Cadence、Allegro、OrCAD都是什么东东?