Home Database Mysql Tutorial 使用Oracle函数索引简单介绍(一般)

使用Oracle函数索引简单介绍(一般)

Jun 07, 2016 pm 03:45 PM
oracle generally introduce use function Simple index

如果一个函数(function)或表达式(expression)使用了一个表的一列或多 列,则用户可以依据这些函数或表达式为表建立索引,这样的索引被称为函 数索引(Function-Based Index)。函数索引能够计算出函数或表达式的, 并将其保存在索引中。用户创建的函数索

如果一个函数(function)或表达式(expression)使用了一个表的一列或多
列,则用户可以依据这些函数或表达式为表建立索引,这样的索引被称为函
数索引(Function-Based Index)。函数索引能够计算出函数或表达式的值,
并将其保存在索引中。用户创建的函数索引既可以是平衡树类型(B-tree
index)的,也可以是位图类型(bitmap index)的。

用于创建索引的函数可以是一个数学表达式(arithmetic expression),也可以
是使用了 PL/SQL 函数(PL/SQL function),包函数(package function),C
外部调用(C callout),或 SQL 函数(SQL function)的表达式。用于创建索
引的函数不能包含任何聚合函数(ggregate function),如果为用户自定义函
数,则在声明中必须使用 DETERMINISTIC 关键字。例如,

  1. create or replace function f_david(p_value varchar2) return varchar2  
  2.  deterministic is  
  3.  begin  
  4.  return p_value;  
  5.  end;  

如果在一个使用对象类型(object type)的列上建立函数索引,则可以使用此对象的方法(method)
作为函数,例如此对象的 map 方法。用户不能在数据类型为 LOB,REF,或嵌套表(nested table)的列上

建立函数索引,也不能在包含 LOB,REF,或嵌

套表等数据类型的对象类型列上建立函数索引。

使用函数索引

如果一个 SQL 语句的 WHERE 子句中使用了函数,那么建立相应的函数索引
(function-based index)是提高数据访问性能的有效机制。表达式
(expression)的结果经过计算后将被存储在索引中。但是当执行 INSERT 和
UPDATE 语句时,Oracle 需要进行函数运算以便维护索引。

例如,如果用户创建了以下函数索引:
CREATE INDEX idx ON table_1 (a + b * (c - 1), a, b);

当 Oracle 处理如下查询时就可以使用之前建立的索引:
SELECT a FROM table_1 WHERE a + b * (c - 1)

使用 UPPER(column_name) 或 LOWER(column_name) 函数建立函数索引
(function-based index)有助于与大小写无关(case-insensitive)的查询。例如
创建以下函数索引:

CREATE INDEX uppercase_idx ON employees (UPPER
(first_name));

有助于提高以下查询的性能:
SELECT * FROM employees WHERE UPPER(first_name) =
'RICHARD';

函数索引的依赖性

函数索引(function-based index)依赖于索引定义表达式中使用的函数。如果
此函数为 PL/SQL 函数(PL/SQL function)或包函数(package function),当
函数声明(function specification)发生变化时,索引将失效(disabled)。

用户需要被授予(grant)CREATE INDEX 或 CREATE ANY INDEX 权限才能
创建函数索引(function-based index)。

要想使用函数索引(function-based index):
● 建立索引后,表必须经过分析(analyze)。
● 必须保证查询的条件表达式不是 NULL 值, 因为 NULL 值不会被存储到
索引中。

以下各节将讲述使用函数索引的其他需求。

定义函数的权限

函数索引(function-based index)的所有者(owner)必须具备此索引定义中
使用的函数的 EXECUTE 权限。当 EXECUTE 权限被收回(revoke)后,
Oracle 则将索引标识为 DISABLED。索引的所有者无须具备此函数的
EXECUTE WITH GRANT OPTION 权限,即可将索引所在表的 SELECT 权限
授予(grant)其他用户。

解决函数索引的依赖性问题

函数索引(function-based index)依赖于她使用的所有函数。如果函数或函数
所在包的声明(specification)被修改过(或索引所有者对函数的 EXECUTE
权限被收回),将会出现以下情况:
● 索引被标记为 DISABLED。
● 如果优化器(optimizer)选择了在标记为 DISABLED 的索引上执行查
询,那么此查询将失败
● 使用标记为 DISABLED 的索引而执行的 DML 操作将失败,除非此索引
同时被标记为 UNUSABLE 且初始化参数(initialization parameter)
SKIP_UNUSABLE_INDEXES 被设为 TRUE。

函数被修改之后,用户可以使用 ALTER INDEX ... ENABLE 语句将索引重新置
为 ENABLE 状态。


Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

What to do if the oracle can't be opened What to do if the oracle can't be opened Apr 11, 2025 pm 10:06 PM

Solutions to Oracle cannot be opened include: 1. Start the database service; 2. Start the listener; 3. Check port conflicts; 4. Set environment variables correctly; 5. Make sure the firewall or antivirus software does not block the connection; 6. Check whether the server is closed; 7. Use RMAN to recover corrupt files; 8. Check whether the TNS service name is correct; 9. Check network connection; 10. Reinstall Oracle software.

How to solve the problem of closing oracle cursor How to solve the problem of closing oracle cursor Apr 11, 2025 pm 10:18 PM

The method to solve the Oracle cursor closure problem includes: explicitly closing the cursor using the CLOSE statement. Declare the cursor in the FOR UPDATE clause so that it automatically closes after the scope is ended. Declare the cursor in the USING clause so that it automatically closes when the associated PL/SQL variable is closed. Use exception handling to ensure that the cursor is closed in any exception situation. Use the connection pool to automatically close the cursor. Disable automatic submission and delay cursor closing.

How to delete all data from oracle How to delete all data from oracle Apr 11, 2025 pm 08:36 PM

Deleting all data in Oracle requires the following steps: 1. Establish a connection; 2. Disable foreign key constraints; 3. Delete table data; 4. Submit transactions; 5. Enable foreign key constraints (optional). Be sure to back up the database before execution to prevent data loss.

How to paginate oracle database How to paginate oracle database Apr 11, 2025 pm 08:42 PM

Oracle database paging uses ROWNUM pseudo-columns or FETCH statements to implement: ROWNUM pseudo-columns are used to filter results by row numbers and are suitable for complex queries. The FETCH statement is used to get the specified number of first rows and is suitable for simple queries.

How to create cursors in oracle loop How to create cursors in oracle loop Apr 12, 2025 am 06:18 AM

In Oracle, the FOR LOOP loop can create cursors dynamically. The steps are: 1. Define the cursor type; 2. Create the loop; 3. Create the cursor dynamically; 4. Execute the cursor; 5. Close the cursor. Example: A cursor can be created cycle-by-circuit to display the names and salaries of the top 10 employees.

How to stop oracle database How to stop oracle database Apr 12, 2025 am 06:12 AM

To stop an Oracle database, perform the following steps: 1. Connect to the database; 2. Shutdown immediately; 3. Shutdown abort completely.

How to create oracle dynamic sql How to create oracle dynamic sql Apr 12, 2025 am 06:06 AM

SQL statements can be created and executed based on runtime input by using Oracle's dynamic SQL. The steps include: preparing an empty string variable to store dynamically generated SQL statements. Use the EXECUTE IMMEDIATE or PREPARE statement to compile and execute dynamic SQL statements. Use bind variable to pass user input or other dynamic values ​​to dynamic SQL. Use EXECUTE IMMEDIATE or EXECUTE to execute dynamic SQL statements.

What steps are required to configure CentOS in HDFS What steps are required to configure CentOS in HDFS Apr 14, 2025 pm 06:42 PM

Building a Hadoop Distributed File System (HDFS) on a CentOS system requires multiple steps. This article provides a brief configuration guide. 1. Prepare to install JDK in the early stage: Install JavaDevelopmentKit (JDK) on all nodes, and the version must be compatible with Hadoop. The installation package can be downloaded from the Oracle official website. Environment variable configuration: Edit /etc/profile file, set Java and Hadoop environment variables, so that the system can find the installation path of JDK and Hadoop. 2. Security configuration: SSH password-free login to generate SSH key: Use the ssh-keygen command on each node

See all articles