870 likes | 1.01k Vues
Indexes and Performance. Supercharging Your Progress Applications. Paul Guggenheim. About Paul Guggenheim & Associates. Working in Progress since 1984 and training Progress programmers since 1986 Designed seven comprehensive Progress courses covering all levels of expertise
E N D
Indexes and Performance Supercharging Your Progress Applications Paul Guggenheim
About Paul Guggenheim & Associates • Working in Progress since 1984 and training Progress programmers since 1986 • Designed seven comprehensive Progress courses covering all levels of expertise • The Keys to OpenEdge Training Course released in 2007. • White Star Software Principal • TailorPro Consultant and Reseller • Tools4Progress Partner • Major consulting clients include Acument Global Technologies, American Academy of Orthopaedic Surgeons, Berlin Industries, Foxwoods Casino, Sterling Machine and US Tsubaki. http://www.pgasmarts.com
Goals of this Presentation • Educate the audience on how Progress treats indexes • Suggest ways to take advantage of the index rules and ways to avoid the pitfalls.
Index Benefits 1.Rapid record retrieval 2. Specified record order 3.Enforced uniqueness
Index Costs 1.Index maintenance overhead occurs during an add or delete of a record or modification of an index component. 2. Additional disk space
General Indexing Properties • Bracketing affects rapid record retrieval • Sorting affects specified record order
Bracketing • Using an index to read a subset of records from a table based upon conditions specified in WHERE,OF and USING clauses.
Sorting • Reading records in a specified order may be accomplished by using an index. However, if it cannot be accomplished by using an index, then a sort table is built.
Manual Index Selection • If USE-INDEX is used in the Record Phrase, the requested index is always used, regardless of its efficiency. • If a RECID or ROWID is used in the WHERE clause, the record is always retrieved using the RECID or ROWID, unless USE-INDEX is used.
Index Rules Overview • Factors Progress considers when deciding which index(es) to use are: • Unique indexes • Equality matches • Range matches • Sort matches • Primary indexes • Word indexes
Equality Matches • An equality match occurs whenever a field is equal to (=, EQ) an expression in an OF, WHERE, or USING clause. • If the expression includes a reference to any fields in the same record buffer, then the equality match is not active.
Range Matches • A range match occurs when a field is compared with an expression in a WHERE clause using either: • Greater than (>, GT) • Greater than or equal to (>=, GE) • Less than (<, LT) • Less than or equal to (<=, LE) • Begins with (BEGINS)
Range Matches • BEGINS counts as two range matches. • Why? • Because BEGINS is essentially a GE valueANDLT next-value. For example, BEGINS “B” is treated as GE “B” AND LT “C”.
Range Matches • Not equals (<>, NE) does not count as a range match. Even though x<> 4 is logically the same as x<4 OR x>4, Progress treats it differently. • If the expression includes a reference to any fields in the same buffer, then the range match is not active.
Range Matches • A CONTAINS is neither an equality nor a range match. It is a word index operator.
Active Equality & Range Matches • An active match is one that can be used by Progress to select an index, and select a bracket on that index. • AEM is an acronym for Active Equality Match. • ARM is an acronym for Active Range Match.
Active Equality & Range Matches • Beginning with Version 7, an equality or range match is considered active if no conditions exist that either standalone or connected with the OR operator use: 1.A non-leading component 2.Any field in the same record buffer 3.The NOT operator or not equal (<>, NE)
Bracketing Rules • If a leading component of an index has an active equality match, then it can be bracketed and the next component of that index is examined for bracketing. • If a leading component of an index has an active range match, then it can be bracketed but remaining components of that index cannot be bracketed.
Sort Matches • A sort match is present whenever a field and not an expression appears in a BY phrase. • You can have multiple BY phrases; each counts as one sort match as long as they are sorted in the same order as they are in the index.
Multiple Index Rules • Since a word index is such a powerful search mechanism, it is always used if a CONTAINS is found in the WHERE clause. • Next, Progress determines whether the AND or OR connectors are used and applies the appropriate set of rules, if any.
Multiple Index Rules – Word Index • When at least one criteria utilizes a word index, at least the word index will be used, and other indexes are used if Rule 2 and Rule 3 are met.
Multiple Index Rules – AND • More than one index can be used with AND when: • All components of each index are involved in an active equality match. • None of the indexes involved in the active equality match are unique.
Multiple Index Rules – AND • When multiple indexes are used with anAND, the final results list is an intersection of the results list for each index.
Multiple Indexes – AND • Why such strict AND rules? • The shaded area in the diagram is relatively small, normally reflecting a relatively small number of records returned. Therefore, it is usually more efficient to use a single index, rather than pull records efficiently from multiple indexes only to discard them.
Multiple Index Rules – OR • More than one index can be used with OR when both criteria utilize at least the leading component of an index. Unlike AND: • Only the leading components of any index must be used. • Range matches as well as equality matches may be used.
Multiple Index Rules – OR • When multiple indexes are used with anOR, the final results list is a union of the results lists of the indexes, with duplicates discarded.
Multiple Index Rules – OR • Why are OR rules not as strict as AND? • Because OR is a union and not an intersection, fewer records will tend to be discarded. Therefore, the efficiency of reading records based on leading components has a much greater positive affect on performance.
Single Index Rules 1. Unique index with fewest components where all components are used in active equality matches 2. More active equality matches 3. More active range matches 4. All components used in an active equality match 5. More sort matches 6. The primary index 7. The first index alphabetically
Single Index Rules – Rule 1 • A unique index with all of its components used in active equality matches (AEMs) will be chosen, even if another index has more active equality matches, since using all components of a unique index in AEMs means there’s a direct hit on a single record.
Single Index Rules – Rules 2 to 7 • Rules 1 to 4 are designed to choose the smallest bracket of records. • After bracketing, Progress looks for the minimal amount of sorting needed, or arbitrarily selects the primary index, or first index alphabetically. (Single Index Rules 5, 6 and 7)
Counting AEMs and ARMs • When counting AEMs and ARMs (active range matches), remember to apply bracketing rules for counting. • If the comparison is an AEM, then the next component comparison may be counted for either an AEM or an ARM.
Counting AEMs and ARMs • When counting AEMs and ARMs (active range matches), remember to apply bracketing rules for counting. • If the comparison is an ARM, then no subsequent component comparison may be counted as either an AEM or ARM.
Single Index Rules – Rule 4 • Rule 4 tells Progress that if two possible indexes have the same number of AEMs, then look to see if all components are used in AEMs for any of the indexes.
Single Index Rules – Rule 4 • Progress assumes that an index with all components chosen will be a smaller bracket than an index where not all the components are chosen.
Single Index Rules – Rules 5 to 7 • Rule 5 – Sort Matches • Progress tries to minimize sorting • Rule 6 – Primary Index • If nothing is better and it is still available, Progress will use the primary index
Single Index Rules – Rules 5 to 7 • Rule 7 – First Index Alphabetically • If the primary index has been disqualified when compared to other indexes, Progress chooses the first index alphabetically of the indexes remaining.
Counting Records • A quick and easy way to count records is to use the SQLSELECT statement with the COUNT(*) function.
Counting Records /*cntsql.p */ form with frame a. select count(*) column-label ‘Last Name!Begins C’ from student where slastname begins ‘C’ with frame a. select count(*) label ‘State = CA’ from student where stcode = ‘CA’ with frame a.
Compiling with XREF • You can use the XREF option of the COMPILE statement to check which indexes you are using. • Look for lines in the cross-reference file containing the word “SEARCH”.
Compiling with XREF /* oneidx.p */ for each student where slast-name = "Kramer": display student-id slast-name sfirst-name. end. XREF reference ...SEARCH school.student name