This shows you the differences between two versions of the page.
| Next revision | Previous revision | ||
|
admin:indexing:strategies:aggregations [2011/03/02 18:32] 127.0.0.1 external edit |
admin:indexing:strategies:aggregations [2012/10/26 14:57] (current) |
||
|---|---|---|---|
| Line 1: | Line 1: | ||
| ~~NOTOC~~ | ~~NOTOC~~ | ||
| + | |||
| {{page>:top_add&nofooter&noeditbtn}} | {{page>:top_add&nofooter&noeditbtn}} | ||
| Line 29: | Line 30: | ||
| <code sql> | <code sql> | ||
| + | |||
| select count(*) | select count(*) | ||
| from INDIVIDUALS | from INDIVIDUALS | ||
| where GENDER = 'M' and NAME = 'John'; | where GENDER = 'M' and NAME = 'John'; | ||
| </code> | </code> | ||
| + | |||
| The GENDER and NAME indexes which were created to satisfy the criteria will also satisfy the requested count. | The GENDER and NAME indexes which were created to satisfy the criteria will also satisfy the requested count. | ||
| Line 41: | Line 44: | ||
| <code sql> | <code sql> | ||
| + | |||
| select GENDER, count(*) | select GENDER, count(*) | ||
| from INDIVIDUALS | from INDIVIDUALS | ||
| Line 46: | Line 50: | ||
| group by GENDER; | group by GENDER; | ||
| </code> | </code> | ||
| + | |||
| The BIRTHDATE and NAME columns must be indexed to satisfy the criteria and the GENDER column must be indexed to satisfy the GROUP BY clause. As discussed earlier, GENDER is a low-cardinality column and can be an Omnidex Bitmap index. | The BIRTHDATE and NAME columns must be indexed to satisfy the criteria and the GENDER column must be indexed to satisfy the GROUP BY clause. As discussed earlier, GENDER is a low-cardinality column and can be an Omnidex Bitmap index. | ||
| Line 54: | Line 59: | ||
| <code sql> | <code sql> | ||
| + | |||
| select C.DESCRIPTION, S.DESCRIPTION, H.CITY, count(DISTINCT H.ZIP) | select C.DESCRIPTION, S.DESCRIPTION, H.CITY, count(DISTINCT H.ZIP) | ||
| from HOUSEHOLDS H join COUNTRIES C on H.COUNTRY = C.COUNTRY | from HOUSEHOLDS H join COUNTRIES C on H.COUNTRY = C.COUNTRY | ||
| Line 59: | Line 65: | ||
| group by C.DESCRIPTION, S.DESCRIPTION, H.CITY; | group by C.DESCRIPTION, S.DESCRIPTION, H.CITY; | ||
| </code> | </code> | ||
| + | |||
| This statement is indexed by creating a multi-column Omnidex index on the COUNTRY, STATE, CITY and ZIP columns in HOUSEHOLDS. The COUNTRY and STATE columns are included because they are foreign keys that correlate to the COUNTRIES.DESCRIPTION and STATES.DESCRIPTION columns. The CITY column is included because it is also in the GROUP BY clause. The ZIP column is included because it is referenced in an aggregation. | This statement is indexed by creating a multi-column Omnidex index on the COUNTRY, STATE, CITY and ZIP columns in HOUSEHOLDS. The COUNTRY and STATE columns are included because they are foreign keys that correlate to the COUNTRIES.DESCRIPTION and STATES.DESCRIPTION columns. The CITY column is included because it is also in the GROUP BY clause. The ZIP column is included because it is referenced in an aggregation. | ||
| Line 66: | Line 73: | ||
| == Example 4. Multiple aggregations satisfied by one index == | == Example 4. Multiple aggregations satisfied by one index == | ||
| - | In this example, the both SQL statements can be satisfied by one Omnidex index. | + | In this example, both SQL statements can be satisfied by one Omnidex index. |
| <code sql> | <code sql> | ||
| + | |||
| select GENDER, BIRTHDATE, count(DISTINCT HOUSEHOLD) | select GENDER, BIRTHDATE, count(DISTINCT HOUSEHOLD) | ||
| from INDIVIDUALS | from INDIVIDUALS | ||
| group by GENDER, BIRTHDATE; | group by GENDER, BIRTHDATE; | ||
| </code> | </code> | ||
| + | |||
| <code sql> | <code sql> | ||
| + | |||
| select HOUSEHOLD, GENDER, count(*) | select HOUSEHOLD, GENDER, count(*) | ||
| from INDIVIDUALS | from INDIVIDUALS | ||
| group by HOUSEHOLD, GENDER; | group by HOUSEHOLD, GENDER; | ||
| </code> | </code> | ||
| + | |||
| A multi-column Omnidex index containing GENDER, BIRTHDATE and HOUSEHOLD would satisfy both of these statements because all GROUP BY columns and all aggregated columns can be found in this index. | A multi-column Omnidex index containing GENDER, BIRTHDATE and HOUSEHOLD would satisfy both of these statements because all GROUP BY columns and all aggregated columns can be found in this index. | ||
| Line 92: | Line 103: | ||
| create database "SIMPLE" | create database "SIMPLE" | ||
| - | type FLATFILE | + | type FILE |
| index_directory "idx" | index_directory "idx" | ||
| in "simple.xml"; | in "simple.xml"; | ||
| create table "COUNTRIES" | create table "COUNTRIES" | ||
| - | physical "dat\cnt.dat" | + | physical "dat/cnt.dat" |
| ( | ( | ||
| "COUNTRY" CHARACTER(2) omnidex, | "COUNTRY" CHARACTER(2) omnidex, | ||
| Line 111: | Line 122: | ||
| create table "STATES" | create table "STATES" | ||
| - | physical "dat\sta.dat" | + | physical "dat/sta.dat" |
| ( | ( | ||
| "STATE" CHARACTER(2) omnidex, | "STATE" CHARACTER(2) omnidex, | ||
| Line 125: | Line 136: | ||
| create table "HOUSEHOLDS" | create table "HOUSEHOLDS" | ||
| - | physical "dat\households.dat" | + | physical "dat/households.dat" |
| ( | ( | ||
| "HOUSEHOLD" CHARACTER(12), | "HOUSEHOLD" CHARACTER(12), | ||
| Line 141: | Line 152: | ||
| create table "INDIVIDUALS" | create table "INDIVIDUALS" | ||
| - | physical "dat\individuals.dat" | + | physical "dat/individuals.dat" |
| ( | ( | ||
| "INDIVIDUAL" CHARACTER(12), | "INDIVIDUAL" CHARACTER(12), | ||