10.1. About Indexes

10.1. About Indexes

This section provides an overview of indexing in Directory Server. It contains the following topics:

10.1.1. About Index Types

Indexes are stored in files in the directory's databases. The names of the files are based on the indexed attribute, not the type of index contained in the file. Each index file may contain multiple types of indexes if multiple indexes are maintained for the specific attribute. For example, all indexes maintained for the common name attribute are contained in the cn.db4 file.

Directory Server supports the following types of index:

  • Presence index (pres) contains a list of the entries that contain a particular attribute, which is very useful for searched. For example, it makes it easy to examine any entries that contain access control information. Generating an aci.db4 file that includes a presence index efficiently performs the search for ACI=* to generate the access control list for the server.

    The presence index is not used for base object searches.

  • Equality index (eq) improves searches for entries containing a specific attribute value. For example, an equality index on the cn attribute allows a user to perform the search for cn=Babs Jensen far more efficiently.

  • Approximate index (approx) is used for efficient approximate or sounds-like searches. For example, an entry may include the attribute value cn=Robert E Lee. An approximate search would return this value for searches against cn~=Robert Lee, cn~=Robert, or cn~=Lee. Similarly, a search against l~=San Fransisco (note the misspelling) would return entries including l=San Francisco.

  • Substring index (sub) is a costly index to maintain, but it allows efficient searching against substrings within entries. Substring indexes are limited to a minimum of three characters for each entry.

    For example, searches of the form cn=*derson , match the common names containing strings such as Bill Anderson, Jill Henderson, or Steve Sanderson. Similarly, the search for telephonenumber= *555* returns all the entries in the directory with telephone numbers that contain 555.

  • International index speeds up searches for information in international directories. The process for creating an international index is similar to the process for creating regular indexes, except that it applies a matching rule by associating an object identifier (OID) with the attributes to be indexed.

    The supported locales and their associated OIDs are listed in Appendix D, Internationalization. If to configure the Directory Server to accept additional matching rules, contact Red Hat Professional Services.

  • Browsing index, or virtual list view (VLV) index, speeds up the display of entries in the Directory Server Console. This index is particularly useful if a branch of your directory contains hundreds of entries; for example, the ou=people branch. You can create a browsing index on any branch point in the directory tree to improve display performance through the Directory Server Console or by using the vlvindex command-line tool, which is explained in the Directory Server Configuration, Command, and File Reference.

10.1.2. About Default, System, and Standard Indexes

When you install Directory Server, a set of default and system indexes is created per database instance. To maintain these indexes, the directory uses standard indexes.

10.1.2.1. Overview of Default Indexes

The default indexes can be modified depending on the directory indexing needs. Always ensure that no server plug-ins or other servers depend on a default index before removing it.

Table 10.1, “Default Indexes” lists the default indexes installed with the directory.

Attribute Eq Pres Sub Purpose
cn Improves the performance of the most common types of user directory searches.
givenName Improves the performance of the most common types of user directory searches.
mail Improves the performance of the most common types of user directory searches.
mailHost Used by a messaging server.
member Improves Directory Server performance. This index is also used by the Referential Integrity Plug-in. See Section 2.5, “Maintaining Referential Integrity” for more information.
owner Improves Directory Server performance. This index is also used by the Referential Integrity Plug-in. See Section 2.5, “Maintaining Referential Integrity” for more information.
see Also Improves Directory Server performance. This index is also used by the Referential Integrity Plug-in. See Section 2.5, “Maintaining Referential Integrity” for more information.
sn Improves the performance of the most common types of user directory searches.
telephoneNumber Improves the performance of the most common types of user directory searches.
uid Improves Directory Server performance.
unique member Improves Directory Server performance. This index is also used by the Referential Integrity Plug-in. See Section 2.5, “Maintaining Referential Integrity” for more information.
Table 10.1. Default Indexes

10.1.2.2. Overview of System Indexes

System indexes cannot be deleted or modified. They are required by the directory to function properly. Table 10.2, “System Indexes” lists the system indexes included with the directory.

Attribute Eq Pres Purpose
aci Allows the Directory Server to quickly obtain the access control information maintained in the database.
objectClass Used to help accelerate subtree searches in the directory.
entryDN Speeds up entry retrieval based on DN searches.
parentID Enhances directory performance during one-level searches.
numSubordinates Used by the Directory Server Console to enhance display performance on the Directory tab.
nsUniqueID Used to search for specific entries.
Table 10.2. System Indexes

10.1.2.3. Overview of Standard Indexes

Because of the need to maintain default indexes and other internal indexing mechanisms, the Directory Server also maintains certain standard index files. The standard index, id2entry.db4, exists by default in Directory Server; you do not need to generate it.

The id2entry.db4 contains the actual directory database entries. All other database files can be recreated from this one.

10.1.3. Overview of the Searching Algorithm

Indexes are used to speed up searches. To understand how the directory uses indexes, it helps to understand the searching algorithm. Each index contains a list of attributes (such as the cn, common name, attribute) and a pointer to the entries corresponding to each value. Directory Serverprocesses a search request as follows:

  1. An LDAP client application, such as the Directory Server Gateway, sends a search request to the directory.

  2. The directory examines the incoming request to make sure that the specified base DN matches a suffix contained by one or more of its databases or database links.

    • If they do match, the directory processes the request.

    • If they do not match, the directory returns an error to the client indicating that the suffix does not match. If a referral has been specified in the nsslapd-referral attribute under cn=config, the directory also returns the LDAP URL where the client can attempt to pursue the request.

    • If the search request for each database attribute can be satisfied by a single index, then the server reads that index to generate a list of potential matches.

    • If there is no index for the attribute, the directory generates a candidate list that includes all entries in the database, which makes the search considerably slower.

    • If a search request contains multiple attributes, the directory consults multiple indexes and then combines the resulting lists of candidate entries.

    • If there is an index for the attribute, the directory takes the candidate matches from the index files in the form of a series of entry ID numbers.

  3. The directory uses the returned entry ID numbers to read the corresponding entries from the id2entry.db4 file. The Directory Server then examines each of the candidate entries to see if any match the search criteria. The directory returns matching entries to the client as each is found.

    The directory continues until either it has examined all candidate entries or it reaches the limit set in one of the following attributes:

    • nsslapd-sizelimit which specifies the maximum number of entries to return from a search operation. If this limit is reached, the directory returns any entries it has located that match the search request, as well as an exceeded size limit error.

    • nsslapd-timelimit which specifies the maximum number of seconds allocated for a search request. If this limit is reached, the directory returns any entries it has located that match the search request, as well as an exceeded time limit error.

    • nsslapd-lookthroughlimit, which specifies the maximum number of entries that the directory will check when examining candidate entries in response to a search request.

    • nsslapd-idlistscanlimit which specifies the maximum number of entries in an ID list before the list is considered to equal the entire database.

    See Directory Server Configuration, Command, and File Reference for further information about these attributes.

10.1.4. Approximate Searches

In addition, the directory uses a variation of the metaphone phonetic algorithm to perform searches on an approximate index. Each value is treated as a sequence of words, and a phonetic code is generated for each word.

NOTE

The metaphone phonetic algorithm in Directory Server supports only US-ASCII letters. Therefore, use approximate indexing only with English values.

Values entered on an approximate search are similarly translated into a sequence of phonetic codes. An entry is considered to match a query if both of the following are true:

  • All of the query string codes match the codes generated in the entry string.

  • All of the query string codes are in the same order as the entry string codes.

Name in the Directory (Phonetic Code) Query String (Phonetic code) Match Comments
Alice B Sarette (ALS B SRT) Alice Sarette (ALS SRT) Matches. Codes are specified in the correct order.
Alice Sarrette (ALS SRT) Matches. Codes are specified in the correct order, despite the misspelling of Sarette.
Surette (SRT) Matches. The generated code exists in the original name, despite the misspelling of Sarette.
Bertha Sarette (BR0 SRT) No match. The code BR0 does not exist in the original name.
Sarette, Alice (SRT ALS) No match. The codes are not specified in the correct order.

10.1.5. Balancing the Benefits of Indexing

Before creating new indexes, balance the benefits of maintaining indexes against the costs.

  • Approximate indexes are not efficient for attributes commonly containing numbers, such as telephone numbers.

  • Substring indexes do not work for binary attributes.

  • Equality indexes should be avoided if the value is big (such as attributes intended to contain photographs or passwords containing encrypted data).

  • Maintaining indexes for attributes not commonly used in a search increases overhead without improving global searching performance.

  • Attributes that are not indexed can still be specified in search requests, although the search performance may be degraded significantly, depending on the type of search.

  • The more indexes you maintain, the more disk space you require.

Indexes can become very time-consuming. For example:

  1. The Directory Server receives an add or modify operation.

  2. The Directory Server examines the indexing attributes to determine whether an index is maintained for the attribute values.

  3. If the created attribute values are indexed, then the Directory Server generates the new index entries.

  4. Once the server completes the indexing, the actual attribute values are created according to the client request.

For example, the Directory Server adds the entry:

dn: cn=John Doe, ou=People,dc=example,dc=com
objectclass: top
objectClass: person
objectClass: orgperson
objectClass: inetorgperson
cn: John Doe
cn: John
sn: Doe
ou: Manufacturing
ou: people
telephonenumber: 408 555 8834
description: Manufacturing lead for the Z238 line of widgets.

The Directory Server is maintaining the following indexes:

  • Equality, approximate, and substring indexes for cn (common name) and sn (surname) attributes.

  • Equality and substring indexes for the telephone number attribute.

  • Substring indexes for the description attribute.

When adding that entry to the directory, the Directory Server must perform these steps:

  1. Create the cn equality index entry for John and John Doe.

  2. Create the appropriate cn approximate index entries for John and John Doe.

  3. Create the appropriate cn substring index entries for John and John Doe.

  4. Create the sn equality index entry for Doe.

  5. Create the appropriate sn approximate index entry for Doe.

  6. Create the appropriate sn substring index entries for Doe.

  7. Create the telephone number equality index entry for 408 555 8834.

  8. Create the appropriate telephone number substring index entries for 408 555 8834.

  9. Create the appropriate description substring index entries for Manufacturing lead for the Z238 line of widgets. A large number of substring entries are generated for this string.

As this example shows, the number of actions required to create and maintain databases for a large directory can be resource-intensive.


Note: This documentation is provided {and copyrighted} by Red Hat®, Inc. and is released via the Open Publication License. The copyright holder has added the further requirement that Distribution of substantively modified versions of this document is prohibited without the explicit permission of the copyright holder. The CentOS project redistributes these original works (in their unmodified form) as a reference for CentOS-5 because CentOS-5 is built from publicly available, open source SRPMS. The documentation is unmodified to be compliant with upstream distribution policy. Neither CentOS-5 nor the CentOS Project are in any way affiliated with or sponsored by Red Hat®, Inc.