数据库中处理最常见的表之外,就是索引了,显然和Oracle数据库中不一样,同一个字段上可以重复索引多次。
除了常规的索引外,还可以建立唯一索引和BITMAP索引:
SQL>CREATE UNIQUE INDEX IND_T_ID ON T(ID);
CREATE UNIQUE INDEX IND_T_ID ON T(ID);
time used: 48.352(ms) clock tick:80826160.
SQL>CREATE BITMAP INDEX IND_T_DATE
2 ON T(CREATE_DATE);
CREATE BITMAP INDEX IND_T_DATE
ON T(CREATE_DATE);
time used: 1.051(ms) clock tick:1554330.
CREATE UNIQUE INDEX IND_T_ID ON T(ID);
time used: 48.352(ms) clock tick:80826160.
SQL>CREATE BITMAP INDEX IND_T_DATE
2 ON T(CREATE_DATE);
CREATE BITMAP INDEX IND_T_DATE
ON T(CREATE_DATE);
time used: 1.051(ms) clock tick:1554330.
达梦数据库还支持CLUSTER索引:
SQL>CREATE CLUSTER INDEX IND_T_C_NAME
2 ON T(NAME);
CREATE CLUSTER INDEX IND_T_C_NAME
ON T(NAME);
time used: 1573.010(ms) clock tick:1245465460.
2 ON T(NAME);
CREATE CLUSTER INDEX IND_T_C_NAME
ON T(NAME);
time used: 1573.010(ms) clock tick:1245465460.
创建CLUSTER索引的时间要明显长于普通索引,而且这里的CLUSTER和Oracle中的CLUSTER以及CLUSTER INDEX并不相同,这里的CLUSTER索引类似SQLSERVER中的CLUSTER索引。
函数索引也是支持的:
SQL>CREATE INDEX IND_UPP_NAME
2 ON T(UPPER(NAME));
CREATE INDEX IND_UPP_NAME
ON T(UPPER(NAME));
time used: 46.564(ms) clock tick:77264470.
2 ON T(UPPER(NAME));
CREATE INDEX IND_UPP_NAME
ON T(UPPER(NAME));
time used: 46.564(ms) clock tick:77264470.
甚至连全文索引都是支持的:
SQL>CREATE TABLE T_LOB
2 (ID NUMBER,
3 CONTENTS CLOB);
CREATE TABLE T_LOB
(ID NUMBER,
CONTENTS CLOB);
time used: 12.018(ms) clock tick:19830720.
SQL>INSERT INTO T_LOB
2 VALUES (1, '用户可以在指定的表的文本列上建立全文索引');
INSERT INTO T_LOB
VALUES (1, '用户可以在指定的表的文本列上建立全文索引')
1 rows affected
time used: 0.390(ms) clock tick:639420.
SQL>CREATE CONTEXT INDEX T_CONTEXT_LOB
2 ON T_LOB(CONTENTS);
CREATE CONTEXT INDEX T_CONTEXT_LOB
ON T_LOB(CONTENTS);
time used: 553.896(ms) clock tick:633347730.
SQL>SELECT * FROM T_LOB
2 WHERE CONTAINS(CONTENTS, '索引');
SELECT * FROM T_LOB
WHERE CONTAINS(CONTENTS, '索引');
全文索引 'T_CONTEXT_LOB' 无效,需要重新填充.error code = -1453
SQL>ALTER CONTEXT INDEX T_CONTEXT_LOB ON T_LOB REBUILD;
ALTER CONTEXT INDEX T_CONTEXT_LOB ON T_LOB REBUILD
time used: 1087.051(ms) clock tick:1746940440.
SQL>SELECT * FROM T_LOB
2 WHERE CONTAINS(CONTENTS, '索引');
SELECT * FROM T_LOB
WHERE CONTAINS(CONTENTS, '索引');
ID CONTENTS
1 1 用户可以在指定的表的文本列上建立全文索引
1 rows got
time used: 0.734(ms) clock tick:1213930.
SQL>SELECT * FROM T_LOB
2 WHERE CONTAINS(CONTENTS, '索引' AND '文本');
SELECT * FROM T_LOB
WHERE CONTAINS(CONTENTS, '索引' AND '文本');
ID CONTENTS
1 1 用户可以在指定的表的文本列上建立全文索引
1 rows got
time used: 1.117(ms) clock tick:1853100.
2 (ID NUMBER,
3 CONTENTS CLOB);
CREATE TABLE T_LOB
(ID NUMBER,
CONTENTS CLOB);
time used: 12.018(ms) clock tick:19830720.
SQL>INSERT INTO T_LOB
2 VALUES (1, '用户可以在指定的表的文本列上建立全文索引');
INSERT INTO T_LOB
VALUES (1, '用户可以在指定的表的文本列上建立全文索引')
1 rows affected
time used: 0.390(ms) clock tick:639420.
SQL>CREATE CONTEXT INDEX T_CONTEXT_LOB
2 ON T_LOB(CONTENTS);
CREATE CONTEXT INDEX T_CONTEXT_LOB
ON T_LOB(CONTENTS);
time used: 553.896(ms) clock tick:633347730.
SQL>SELECT * FROM T_LOB
2 WHERE CONTAINS(CONTENTS, '索引');
SELECT * FROM T_LOB
WHERE CONTAINS(CONTENTS, '索引');
全文索引 'T_CONTEXT_LOB' 无效,需要重新填充.error code = -1453
SQL>ALTER CONTEXT INDEX T_CONTEXT_LOB ON T_LOB REBUILD;
ALTER CONTEXT INDEX T_CONTEXT_LOB ON T_LOB REBUILD
time used: 1087.051(ms) clock tick:1746940440.
SQL>SELECT * FROM T_LOB
2 WHERE CONTAINS(CONTENTS, '索引');
SELECT * FROM T_LOB
WHERE CONTAINS(CONTENTS, '索引');
ID CONTENTS
1 1 用户可以在指定的表的文本列上建立全文索引
1 rows got
time used: 0.734(ms) clock tick:1213930.
SQL>SELECT * FROM T_LOB
2 WHERE CONTAINS(CONTENTS, '索引' AND '文本');
SELECT * FROM T_LOB
WHERE CONTAINS(CONTENTS, '索引' AND '文本');
ID CONTENTS
1 1 用户可以在指定的表的文本列上建立全文索引
1 rows got
time used: 1.117(ms) clock tick:1853100.