Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
admin:indexing:basic [2009/12/10 16:36]
els
— (current)
Line 1: Line 1:
-{{page>:​top_add&​nofooter&​noeditbtn}} 
-<​html><​div align="​center"><​span style="​color:​red">​DRAFT</​span></​div></​html>​ 
  
-====== Omnidex Indexing ====== 
- 
-[[admin:​indexing:​home|Overview]] -> [[admin:​indexing:​indexes|Indexes]] -> **[[admin:​indexing:​basic|Strategies]]** -> [[admin:​indexing:​advanced|Advanced]] -> [[admin:​indexing:​installation|Installation]] -> [[admin:​indexing:​maintenance|Maintenance]] 
- 
- 
-===== Basic Indexing Strategies ===== 
- 
-The basic strategy for creating indexes is to index all of the columns that are used in criteria, table joins, aggregations and ordering. ​ This is a different approach than is taken with relational databases. ​ Database administrators are usually trained to identify selected columns that are most frequently used and create indexes only on those columns. ​ Their general expectation is that the relational database will choose an index to access a table and will process the rest of the statement by directly evaluating the data.  ​ 
- 
-Omnidex approaches indexing differently. ​ Omnidex indexes all of the columns and then coordinates use of all of the indexes to fulfill the different aspects of a query. ​ Some indexes will be used to satisfy table joins or criteria. ​ Other indexes will be used to fulfill aggregations or ordering. ​ Most database administrators are surprised to learn that complex SQL statements which join many tables and contain intricate criteria can often be fulfilled without ever accessing the underlying data.  This approach allows Omnidex to process queries very quickly. ​ It also reduces the load on the servers since accessing the data is a common cause of performance problems. ​   
- 
-Most indexing strategies are developed by analyzing the queries. ​ Queries usually follow patterns and these patterns give clues to the best indexing approach. ​ Analyze the queries to determine which columns are criteria in the WHERE clause, which tables are joined together in the FROM clause, which columns are aggregated or used in GROUP BY clauses, and which columns are used in the ORDER BY clause. ​ Use the discussions below to create indexes for these columns and then run sample queries to assess their performance. ​ Query plans will show how the indexes were used, and if the query is not fully optimized, revisit the indexing strategy as needed. ​ You can also read about [[admin:​indexing:​advanced|Advanced Indexing Strategies]] for special optimization techniques. 
- 
-  - [[#​Optimizing_criteria|Optimizing Criteria]] 
-  - [[#​Optimizing_table_joins|Optimizing Table Joins]] 
-  - [[#​Optimizing_aggregations|Optimizing Aggregations]] 
-  - [[#​Optimizing_ordering|Optimizing Ordering]] 
- 
-==== Optimizing Criteria ==== 
- 
-Criteria is usually optimized by creating indexes on each column. ​ This is true regardless of the use of Boolean operators or parentheses. ​ As you consider the query patterns, look for opportunities to use QuickText indexes or indexing options. 
- 
-== Example 1. Basic Criteria == 
- 
-In the following statement, look for the columns used as criteria in the WHERE clause 
- 
-  select ​    NAME, ADDRESS1, ADDRESS2, PHONE 
-    from     ​INDIVIDUALS 
-    where    ((STATE = '​CO'​ and CITY = '​Boulder'​) or  
-              (STATE = '​IL'​ and CITY = '​Chicago'​)) 
- 
-The STATE and CITY columns should be Omnidex indexes. 
- 
-== Example 2. Textual Criteria == 
- 
-In this example, you might want to use QuickText indexes. 
- 
-  select ​    NAME, ADDRESS1, ADDRESS2, PHONE 
-    from     ​INDIVIDUALS 
-    where    STATE = '​CO'​ and NAME = '​John'​ 
- 
-The STATE column should be an Omnidex index and the NAME column should be a Quicktext index. 
- 
-== Example 3. Case Sensitivity == 
- 
-In this same example, we might want to allow case insensitivity.  ​ 
- 
-  select ​    NAME, ADDRESS1, ADDRESS2, PHONE 
-    from     ​INDIVIDUALS 
-    where    STATE = '​co'​ and NAME = '​john'​ 
- 
-The STATE column should be an Omnidex index with the Case Insensitive option, and the NAME column should be a QuickText index. ​ QuickText indexes are automatically case insensitive. 
- 
-==== ==== 
-[[#​Omnidex_Indexing|top of page]] 
- 
- 
-==== Optimizing Table Joins ==== 
- 
-Tables joins are usually optimized by creating indexes on the table constraints. ​ For relational databases, it is only necessary to index the foreign keys since the relational database'​s indexes on the primary keys will suffice. ​ For raw data files, both the primary and foreign keys should be indexed. 
- 
-Multi-column constraints should be indexed using multi-column Omnidex indexes. ​ These are custom indexes that combine multiple columns into an index. ​ The order of the columns in the indexes should match the order of the columns in the constraint. 
- 
-Not all joins follow actual constraints. ​ Sometimes there is a parent-child relationship between tables but no formal constraint is declared. ​ In these cases, create Omnidex indexes as though a constraint was declared. ​ 
- 
- 
-== Example 1.  Table joins on primary and foreign constraints == 
- 
-In this example, the HOUSEHOLD column is a primary constraint in HOUSEHOLDS and a foreign constraint in INDIVIDUALS. 
- 
-  select ​    ​INDIVIDUALS.NAME,​ HOUSEHOLDS.ADDRESS1,​ HOUSEHOLDS.ADDRESS2,​ INDIVIDUALS.PHONE 
-    from     ​INDIVIDUALS join HOUSEHOLDS on INDIVIDUALS.HOUSEHOLD = HOUSEHOLDS.HOUSEHOLD 
-   ​where ​    ​HOUSEHOLDS.STATE = '​CO'​ and INDIVIDUALS.NAME = '​John' ​ 
- 
-For relational databases, the HOUSEHOLD column in INDIVIDUALS should be an Omnidex index since it is a foreign key.  For raw data files, the HOUSEHOLD column in HOUSEHOLDS should also be an Omnidex index since it is a primary key. 
- 
-== Example 2.  Table joins along multi-column constraints == 
- 
-In this example, the HOUSEHOLD column is a primary constraint in HOUSEHOLDS and a foreign constraint in INDIVIDUALS. 
- 
-  select ​    ​HOUSEHOLDS.NAME,​ COUNTIES.COUNTY 
-    from     ​HOUSEHOLDS join COUNTIES on HOUSEHOLDS.STATE = COUNTIES.STATE and 
-                                         ​HOUSEHOLDS.COUNTY_CODE = COUNTIES.COUNTY_CODE ​ 
- 
-For relational databases, the STATE and COUNTY_CODE columns of HOUSEHOLD should be indexed using a multi-column Omnidex index. ​ For raw data files, the STATE and COUNTY_CODE columns of COUNTIES should also be a multi-column Omnidex index. 
- 
-==== ==== 
-[[#​Omnidex_Indexing|top of page]] 
- 
- 
-==== Optimizing Aggregations ==== 
- 
-Aggregations are usually optimized by creating an index containing all of the columns in the GROUP BY clause and all of the columns referenced in COUNT, SUM, MIN, MAX and AVERAGE functions. ​ It is preferable to have the columns in the GROUP BY clause precede the columns being aggregated.  ​ 
- 
-The COUNT(*) aggregation is treated uniquely. ​ The use of the asterisk does not equate to an individual column and does not expand the side of the index. ​ In fact, Omnidex maintains counts at each step of the search, so simple COUNT(*) aggregations no not need specialized indexing. 
- 
-Some applications will use GROUP BY clauses that consist of columns from a child table and columns from parent or grandparent tables. ​ In these cases, the Omnidex index in the child should include all columns from the child table as well as the foreign keys that point to the parent table. 
- 
-It is fine for one index to service multiple aggregations be containing a superset of all of the columns. ​ For example, an index on columns A, B, C and D would allow sums of D grouped by A, and also averages of D and C grouped by B and A.  The performance of these aggregations degrades as the index width increases, so indexes should not contain an excessive number of columns. 
- 
-== Example 1.  Ungrouped COUNT(*) aggregations == 
- 
-In this example, the COUNT(*) does not require any additional indexes. 
- 
-  select ​    ​count(*) 
-    from     ​INDIVIDUALS 
-    where    STATE = '​CO'​ and NAME = '​John'​ 
- 
-The STATE and NAME indexes which were created to satisfy the criteria will also satisfy the requested count. 
- 
-== Example 2.  Grouped COUNT(*) aggregations == 
- 
-In this example, the COUNT(*) does not require any additional indexes, but the GROUP BY clause requires an index. 
- 
-  select ​    ​GENDER,​ count(*) 
-    from     ​INDIVIDUALS 
-    where    STATE = '​CO'​ and NAME = '​John'​ 
-    group by GENDER 
- 
-The STATE and NAME columns must be indexed to satisfy the criteria and the GENDER column must be indexed to satisfy the GROUP BY clause. 
- 
-== Example 3.  Aggregations between a child and multiple parents == 
- 
-In this example, the GROUP BY clause contains columns from multiple parents. 
- 
-  select ​    ​STATES.DESCRIPTION,​ INDIVIDUALS.ZIP,​ GENDERS.DESCRIPTION,​ max(INDIVIDUALS.AGE) 
-    from     ​INDIVIDUALS join STATES.STATE = INDIVIDUALS.STATE ​ 
-                         join GENDERS on INDIVIDUALS.GENDER = GENDERS.GENDER ​ 
-    group by STATES.DESCRIPTION,​ INDIVIDUALS.ZIP,​ GENDERS.DESCRIPTION 
- 
-This statement is indexed by creating a multi-column Omnidex index on the STATE, ZIP, GENDER and AGE columns in INDIVIDUALS. ​ The STATE and GENDER columns are foreign keys that correlate to the STATES.DESCRIPTION and GENDERS.DESCRIPTION columns.  ​ 
- 
-== Example 4.  Multiple aggregations satisfied by one index == 
- 
-In this example, the both SQL statements can be satisfied by one Omnidex index. 
- 
-  select ​    ​GENDER,​ INCOME, count(*), count(DISTINCT HOUSEHOLD) 
-    from     ​INDIVIDUALS 
-    group by GENDER, INCOME 
- 
-  select ​    ​GENDER,​ EDUCATION, MAX(AGE), MIN(AGE), ​ 
-    from     ​INDIVIDUALS 
-    group by GENDER, EDUCATION 
- 
-A multi-column Omnidex index containing GENDER, INCOME, EDUCATION, AGE and HOUSEHOLD would satisfy both of these statements because all GROUP BY columns and all aggregated columns can be found in this index. 
- 
-==== ==== 
-[[#​Omnidex_Indexing|top of page]] 
- 
- 
-==== Optimizing Ordering ==== 
- 
-Ordering is usually optimized by creating an index containing all of the columns in the ORDER BY clause. ​ The order of the column in the index must match the order of the columns in the ORDER BY clause. At present, only ascending ORDER BY clauses are optimized.  ​ 
- 
- 
-== Example 1.  Single-column ORDER BY clauses == 
- 
-In this example, the ORDER BY clause is optimized using the same index used for processing criteria. 
- 
-  select ​    NAME, ADDRESS1, ADDRESS2, PHONE  
-    from     ​INDIVIDUALS 
-    where    STATE in ('​CA','​CO'​) and NAME = '​John'​ 
-    order by STATE 
- 
-The STATE index will be used to satisfy both the criteria and the ORDER BY clause. 
- 
- 
-== Example 2.  Multi-column ORDER BY clauses == 
- 
-In this example, the ORDER BY clause will be optimized with a multi-column index. 
- 
-  select ​    NAME, ADDRESS1, ADDRESS2, PHONE  
-    from     ​INDIVIDUALS 
-    where    STATE in ('​CA','​CO'​) and NAME = '​John'​ 
-    order by STATE, CITY 
- 
-A multi-column Omnidex index containing STATE and CITY, in that order, will optimize this ORDER BY clause. 
- 
-==== ==== 
-[[#​Omnidex_Indexing|top of page]] 
- 
- 
-===== Validating the Indexing Strategy ===== 
- 
-These basic indexing strategies will handle the majority of queries in most applications;​ however, queries can also be deceivingly unique. ​ After using these strategies, review the query plans from sample queries to insure they are being properly optimized.  ​ 
- 
----- 
-\\  ​ 
- 
-The next section on Omnidex Indexing is [[admin:​indexing:​advanced|Advanced Indexing Strategies]]. 
- 
- 
-{{page>:​bottom_add&​nofooter&​noeditbtn}} 
 
Back to top
admin/indexing/basic.1260463003.txt.gz ยท Last modified: 2012/10/26 14:46 (external edit)