Indexes and Index-Organized Tables (2024)

Oracle Database can use prefix compression, also known as key compression, to compress portions of the primary key column values in a B-tree index or an index-organized table. Prefix compression can greatly reduce the space consumed by the index.

An uncompressed index entry has one piece. An index entry using prefix compression has two pieces: a prefix entry, which is the grouping piece, and a suffix entry, which is the unique or nearly unique piece. The database achieves compression by sharing the prefix entries among the suffix entries in an index block.

Note:

If a key is not defined to have a unique piece, then the database provides one by appending a rowid to the grouping piece.

By default, the prefix of a unique index consists of all key columns excluding the last one, whereas the prefix of a nonunique index consists of all key columns. Suppose you create a composite, unique index on two columns of the oe.orders table as follows:

CREATE UNIQUE INDEX orders_mod_stat_ix ON orders ( order_mode, order_status );

In the preceding example, an index key might be online,0. The rowid is stored in the key data portion of the entry, and is not part of the key itself.

Note:

If you create a unique index on a single column, then Oracle Database cannot use prefix key compression because no common prefixes exist.

Alternatively, suppose you create a nonunique index on the same columns:

CREATE INDEX orders_mod_stat_ix ON orders ( order_mode, order_status );

Also assume that repeated values occur in the order_mode and order_status columns. An index block could have entries as shown in the follow example:

online,0,AAAPvCAAFAAAAFaAAaonline,0,AAAPvCAAFAAAAFaAAgonline,0,AAAPvCAAFAAAAFaAAlonline,2,AAAPvCAAFAAAAFaAAmonline,3,AAAPvCAAFAAAAFaAAqonline,3,AAAPvCAAFAAAAFaAAt

In the preceding example, the key prefix would consist of a concatenation of the order_mode and order_status values, as in online,0. The suffix consists in the rowid, as in AAAPvCAAFAAAAFaAAa. The rowid makes the whole index entry unique because a rowid is itself unique in the database.

If the index in the preceding example were created with default prefix compression (specified by the COMPRESS keyword), then duplicate key prefixes such as online,0 and online,3 would be compressed. Conceptually, the database achieves compression as follows:

online,0AAAPvCAAFAAAAFaAAaAAAPvCAAFAAAAFaAAgAAAPvCAAFAAAAFaAAlonline,2AAAPvCAAFAAAAFaAAmonline,3AAAPvCAAFAAAAFaAAqAAAPvCAAFAAAAFaAAt

Suffix entries (the rowids) form the compressed version of index rows. Each suffix entry references a prefix entry, which is stored in the same index block as the suffix.

Alternatively, you could specify a prefix length when creating an index that uses prefix compression. For example, if you specified COMPRESS 1, then the prefix would be order_mode and the suffix would be order_status,rowid. For the values in the index block example, the index would factor out duplicate occurrences of the prefix online, which can be represented conceptually as follows:

online0,AAAPvCAAFAAAAFaAAa0,AAAPvCAAFAAAAFaAAg0,AAAPvCAAFAAAAFaAAl2,AAAPvCAAFAAAAFaAAm3,AAAPvCAAFAAAAFaAAq3,AAAPvCAAFAAAAFaAAt

The index stores a specific prefix once per leaf block at most. Only keys in the leaf blocks of a B-tree index are compressed. In the branch blocks the key suffix can be truncated, but the key is not compressed.

See Also:

Indexes and Index-Organized Tables (2024)

FAQs

How to check if a table is index-organized? ›

1 Answer. The IOT_TYPE column. If the table is an index-organized table, then IOT_TYPE is IOT , IOT_OVERFLOW , or IOT_MAPPING . If the table is not an index-organized table, then IOT_TYPE is NULL .

What is the difference between index table and index-organized table? ›

An index in an ordinary table stores both the column data and the rowid. A row in an index-organized table does not have a stable physical location. It keeps data in sorted order, in the leaves of a B*-tree index built on the table's primary key. These rows can move around to preserve the sorted order.

Is it good to have multiple indexes on a table? ›

But this is not always a good idea, as there can be drawbacks to adding too many secondary indexes. You should always include a primary index on every table in your database. However, too many secondary indexes can begin to cause issues in some instances.

What is the difference between index-organized tables and heap tables? ›

An index-organized table differs from a heap-organized because the data is itself the index. In this type of index, the bytes of the index key are reversed, for example, 103 is stored as 301. The reversal of bytes spreads out inserts into the index over many blocks.

How do you check if a table is indexed? ›

Answer: Yes, you can check if a table has any indexes in Oracle by running the following query: SELECT COUNT(*) FROM all_indexes WHERE table_name = 'your_table_name';

How do you organize an index? ›

Summary of how to index (if not using Word index functionality at manuscript preparation stage)
  1. Make a list of terms to appear.
  2. Separate these terms into main entries and subentries.
  3. Add the page numbers for every meaningful reference to a selected term.
  4. Alphabetize all main entries and main words of subentries.
Sep 23, 2021

What is the difference between partitioned tables and index organized tables? ›

Generally used to improve SELECT query performance, indices can hurt UPDATE and DELETE performance and should be avoided on tables with frequently changing data. Partitions refer to the arrangement of data in a database to be accessed more efficiently. Partitioning makes it easier to add new data.

How many indexes should a table have? ›

There is not an "optimal" number of indexes for a table. The number of indexes completely depends on how you query the table. Having unused indexes wastes disks space and resources to maintain the index. As well as user time during insert/update/deletes.

What is the difference between database index and table index? ›

An index is a database structure that you can use to improve the performance of database activity. A database table can have one or more indexes associated with it. An index is defined by a field expression that you specify when you create the index. Typically, the field expression is a single field name, like EMP_ID.

What is the problem with too many indexes on a table? ›

More indexes may mean that more different queries will run fast but inserts, updates, and deletes will be slower. So, depends on the workload mix. Slower inserts/updates/deletes as the indexes have to be updated as well as the table. Wasted disk/memory space as well.

What is one major problem of creating indexes in SQL? ›

We should also be careful to not make an index for each query as creating indexes also take storage and when the amount of data is huge it will create a problem. Therefore, it's important to carefully consider which columns to index based on the needs of your application.

Does indexing increase database size? ›

The time at which the indexing is set will have no influence on the resulting database size. The internal effort of indexing depends on the data managed. But it makes a difference in terms of speed. If you first fill the non-indexed table with data and then set the indexing, it is a little faster.

When to use index organized table? ›

An index-organized table is appropriate if you will always be accessing the TROUBLE data by the CITY and SAMPLE_DATE columns (in the WHERE clauses of your queries). To minimize the amount of active management required for the index, you should use an index-organized table only if the table's data is very static.

How does an index organized table differ from a standard table and a typical index? ›

Index Organized Tables (IOTs) are tables stored in an index structure. Whereas a table stored in a heap is unorganized, data in an IOT is stored and sorted by primary key (the data is the index). IOTs behave just like “regular” tables, and you use the same SQL to access them.

How does table indexing work? ›

Indexing is the way to get an unordered table into an order that will maximize the query's efficiency while searching. When a table is unindexed, the order of the rows will likely not be discernible by the query as optimized in any way, and your query will therefore have to search through the rows linearly.

How can you see all indexes defined for a table? ›

To get indexes of a table in MySQL database using the MySQL command line, you can use the SHOW INDEXES command line as follow: Command: SHOW INDEXES FROM table_name; Specify the name of the table and it will return all indexes for that table.

How is an index organized in a document? ›

Document indexing is the process of organizing documents with proper tags or labels to improve visibility when searching or retrieving documents from large databases or indexes. This approach enables swift and effective searching of documents at all times.

How are indexes arranged? ›

An Index may be arranged either chronologically, alphabetically, or according to classes, but great confusion will be caused by uniting the three.

How would you decide whether an index should be created for a table? ›

There is no simple formula to determine whether or not an index should be created. You must consider the trade-off of the benefits of indexed retrieval versus the maintenance overhead of that index.

Top Articles
Latest Posts
Article information

Author: Sen. Ignacio Ratke

Last Updated:

Views: 6748

Rating: 4.6 / 5 (56 voted)

Reviews: 95% of readers found this page helpful

Author information

Name: Sen. Ignacio Ratke

Birthday: 1999-05-27

Address: Apt. 171 8116 Bailey Via, Roberthaven, GA 58289

Phone: +2585395768220

Job: Lead Liaison

Hobby: Lockpicking, LARPing, Lego building, Lapidary, Macrame, Book restoration, Bodybuilding

Introduction: My name is Sen. Ignacio Ratke, I am a adventurous, zealous, outstanding, agreeable, precious, excited, gifted person who loves writing and wants to share my knowledge and understanding with you.