Extensible Indexing
可扩展索引框架是一个基于sql的接口,允许您定义特定于域的操作符和索引模式,并将它们集成到Oracle服务器中。
可扩展索引框架由以下组件组成:
-
Indextypes: indextype模式对象指定管理特定于应用程序索引的定义、维护和扫描操作的例程。索引类型告诉Oracle服务器如何在表的列或对象的属性上建立用户定义的索引。
-
Domain Indexes: 使用索引类型创建的特定于应用程序的索引称为域索引,因为它在特定于应用程序的域中对数据进行索引。域索引是由索引类型指定的例程创建、管理和访问的索引的实例。
-
Operators: 查询和数据操作语句可以使用特定于应用程序的操作符,例如空间域中的Overlaps操作符。用户定义的操作符绑定到函数。还可以使用索引对它们进行评估。例如,可以使用哈希索引计算等式运算符。索引类型为它定义的操作符提供基于索引的实现。
See Also:
Chapter 9, "Defining Operators" for detailed information on user-defined operators -
Index-Organized Tables: 使用索引组织的表,应用程序可以使用表隐喻为复杂对象定义、构建、维护和访问索引。对于应用程序,索引被建模为一个表,其中每一行都是一个索引条目。索引组织的表处理重复的索引项,这对于复杂类型的数据非常重要。
See Also:
Oracle Database Administrator's Guide for detailed information on index-organized tables
可扩展索引框架让您:
-
将特定于应用程序的索引管理例程封装为索引类型模式对象
-
在表列上定义域索引
-
有效地处理特定于应用程序的操作符
使用可扩展索引框架,您可以构建一个域索引,其操作方式与任何其他Oracle索引都非常相似。用户使用定义的操作符编写标准查询。要创建、删除、截断、修改和搜索域索引,Oracle服务器将调用作为索引类型的一部分指定的应用程序代码。
Using the Text Indextype
本节通过一个骨架示例演示了可扩展索引框架,该示例使用Textindextype定义了一个新的文本索引方案,并使用文本索引类型对文本数据进行索引和操作。
Defining the Indextype
创建索引类型组件的顺序取决于是否创建基于索引的功能实现。
Non-Index-Based功能实现
要定义文本索引类型,索引类型设计器必须遵循以下步骤:
-
Define and code the functional implementation for the supported operator
The
Text
indextype supports an operator calledContains
, which accepts a text value and a key, and returns a number indicating whether the text contains the key. The functional implementation of this operator is a regular function defined as:CREATE FUNCTION TextContains(Text IN VARCHAR2, Key IN VARCHAR2) RETURN NUMBER AS BEGIN ....... END TextContains;
-
Create the new operator and bind it to the functional implementation
CREATE OPERATOR Contains BINDING (VARCHAR2, VARCHAR2) RETURN NUMBER USING TextContains;
-
Define a type that implements the index interface
ODCIIndex
This involves implementing routines for index definition, index maintenance, and index scan operations. Oracle calls:
-
The index definition routines ODCIIndexCreate(), ODCIIndexAlter(), and ODCIIndexDrop() to perform the appropriate operations when the index is created, altered, or dropped, or the base table is truncated
-
The index maintenance routines ODCIIndexInsert(), ODCIIndexDelete(), and ODCIIndexUpdate() to maintain the text index when table rows are inserted, deleted, or updated
-
The index scan routines ODCIIndexStart(), ODCIIndexFetch(), and ODCIIndexClose() to scan the text index and retrieve rows of the base table that satisfy the operator predicate
CREATE TYPE TextIndexMethods ( STATIC FUNCTION ODCIIndexCreate(...) ... ); CREATE TYPE BODY TextIndexMethods ( ... );
-
-
Create the
Text
indextype schema objectThe indextype definition specifies the operators supported by the new indextype and the type that implements the index interface.
CREATE INDEXTYPE TextIndexType FOR Contains(VARCHAR2, VARCHAR2) USING TextIndexMethods WITH SYSTEM MANAGED STORAGE TABLES;
Index-Based Functional Implementations
If you are creating an index-based functional implementation, you perform the same operations as for non-index-based functional implementations, but in a different order:
-
Define the implementation type
-
Define and code the functional implementation
-
Create the operator
-
Create the indextype
This order is required because definition of an index-based functional implementation requires the implementation type as a parameter.
Using the Indextype
When the Text
indextype presented in the previous section has been defined, users can define text indexes on text columns and use the Contains
operator to query text data.
Suppose the MyEmployees
table is defined by the statement in Example 7-1:
Example 7-1 Declaring a New Table
CREATE TABLE MyEmployees (employee_id NUMBER(6), first_name VARCHAR2(20), last_name VARCHAR2(25), salary NUMBER(8,2), resume VARCHAR2(2000), location VARCHAR2(200), department_id NUMBER(4));
To build a text domain index on the resume
column, a user issues the statement in Example 7-2:
Example 7-2 Building a Text Domain Index
CREATE INDEX ResumeIndex ON MyEmployees(resume) INDEXTYPE IS TextIndexType;
To query the text data in the resume
column, users issue statements like the one in Example 7-3:
Example 7-3 Using the Contains() Operator
SELECT * FROM MyEmployees WHERE Contains(resume, 'Oracle') =1;
The query execution uses the text index on resume
to evaluate the Contains
predicate.