Salesforce

Multiple Index Selection Explained

« Go Back

Information

 
TitleMultiple Index Selection Explained
URL Name21099
Article Number000149305
EnvironmentProduct: Progress
Version: 9.x
Product: OpenEdge
Version: 10.x, 11.x, 12.x
OS: All Supported Platforms
Question/Problem Description
How multiple index selection occurs in Progress, explained.
How multiple index selection occurs?
What is multiple index selection?
Steps to Reproduce
Clarifying Information
The Sports2000 example database is included with OpenEdge installations.
The examples below use the sports2000.customer table which has the following indexes:

Index Name   Index     Columns             Unique
------------ --------- ------------------- ----------
Cust-Num     (Primary) CustNum             Yes
Name                   Name                No
Sales-Rep              Sales-Rep           No
Country-Post           Country,Postal-code No
Comments    Word Index  Comments
Error Message
Defect Number
Enhancement Number
Cause
Resolution
When the WHERE clause uses AND or OR clauses and indexes are available for both sides of the AND or OR, more than one index can be used.  Multiple indexes are not used for queries using FIND.  FIND statements can only use one index.The following examples describe how the compiler uses multiple indexes:
  1. WHERE clauses using AND,
  2. WHERE clauses using OR, and
  3. WHERE clauses using CONTAINS.

1.  WHERE using AND

When the selection criteria includes the use of AND, more than one index will be used when all the components of each index are involved in equality matches, and the indexes are not unique.

Example 1:  Index Used: Name, SalesRep
Two indexes are used, because both indexes are non-unique and all components are involved in equality matches.
FOR EACH customer WHERE name = "Peter" AND salesrep = "Jim":

Example 2:  Index Used: Name
Only one index is used, because the match is not an equality match. 
FOR EACH customer WHERE name > "Martin" AND salesrep > "Jim":

Example 3: Index Used: CountryPost, SalesRep
Two indexes are used, because both indexes are non-unique and all components are involved in equality matches.
FOR EACH customer WHERE country = "USA" AND postalcode = "21000" AND salesrep = "Jim":

Example 4: Index Used: SalesRep
Only one index is used, since not all the components of CountryPost are involved in the equality match.
FOR EACH customer WHERE country = "USA" AND salesrep = "Jim":

Example 5: Index Used: Custnum
Only one index is used, because Custnum is unique.
FOR EACH customer WHERE custnum = 65 AND salesrep = "Jim":

2. WHERE using OR

When an OR is used in the WHERE clause and both the left and right side of the OR contain at least the lead component of an index using either the equality or range matches, then multiple indexes are used.

Example 1: Index Used: CountryPost, SalesRep
Two indexes are used, since the selection criteria on both sides of OR use at least the leading components of both indexes.
FOR EACH customer WHERE (country = "USA" AND postalcode = "21000") OR (salesrep = "Jim"):

Example 2:  Index Used: CountryPost, SalesRep
Two indexes are used, since the selection criteria on both sides of OR use at least the leading components o.f both indexes.
FOR EACH customer WHERE (country = "USA" AND postalcode = "21000") OR (salesrep > "Jim"):

Example 3:  Index Used: CountryPost, SalesRep
Two indexes are used, since the selection criteria on both sides of OR use at least the leading components of both indexes.
FOR EACH customer WHERE (country = "USA") OR (salesrep = "Jim"):

Example 4:  Index Used: Custnum
Since the postalcode is not the leading component, two indexes are not selected.  In addition, since an OR is used, Progress selects the primary index in this case.
FOR EACH customer WHERE (postalcode = "21000") OR (salesrep =Jim"):

Example 5:  Index Used: Name, Countrypost
Two indexes are used, since both the matches are on the leading components of the index. 
FOR EACH customer WHERE (name begins "J") OR (country = "USA"):

Example 6:  Index Used: Custnum, Custnum 
One index and two brackets used
FOR EACH customer WHERE (custnum = 99) OR (custnum = 187):
Example 7:  Index Used: Custnum, Name, Name
Two indexes and three brackets used.
FOR EACH customer WHERE (custnum < 99) OR (name = "John") OR (name = "Scott"):
3. WHERE using CONTAINS

When a CONTAINS clause with a column that has a word index is used in the WHERE clause, the word index, as well as other indexes, will be used.

Example 1:  Index Used: Comments, Salesrep
Comments is word indexed, therefore it is selected.  
Also AND is used with the equality match, therefore salesrep is also selected.
FOR EACH customer WHERE (comments CONTAINS "amount") AND (salesrep = "Jim"):

Example 2:  Index Used: Comments, Name, CountryPost
Comments index is word indexed, therefore it is selected.  
The AND after the comments contains an equality match, therefore it's selected and the selection on the right of OR uses the lead components of the index, therefore it is selected.
FOR EACH customer WHERE (comments CONTAINS "amount" AND name = "John") OR (country = "USA" AND postalcode = "21000"):

 
Workaround
Notes
Keyword Phrase
Last Modified Date9/15/2020 8:48 PM

Powered by