Differences

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

Link to this comparison view

Next revision
Previous revision
admin:features:segments:index [2012/03/06 21:47]
doc created
admin:features:segments:index [2016/06/28 22:38] (current)
Line 9: Line 9:
 [[admin:​features:​segments:​home|Overview]] | [[admin:​features:​segments:​home|Overview]] |
 **[[admin:​features:​segments:​index|Index Segments]]** | **[[admin:​features:​segments:​index|Index Segments]]** |
 +[[admin:​features:​segments:​data|Data Segments]] |
 [[admin:​features:​segments:​creating|Creating Segments]] | [[admin:​features:​segments:​creating|Creating Segments]] |
 [[admin:​features:​segments:​querying|Querying Segments]] | [[admin:​features:​segments:​querying|Querying Segments]] |
Line 14: Line 15:
 ---- ----
  
-==== Overview ​====+==== Index Segments ​====
  
 +=== Overview ===
 Some applications process their queries in multiple steps. ​ The first step isolates some rows based on a first group of criteria. ​ The second step either refines those rows, or isolates a new set of rows based on a second group of criteria. ​ At the end of the query, all of the steps are combined to produce a final result set. Some applications process their queries in multiple steps. ​ The first step isolates some rows based on a first group of criteria. ​ The second step either refines those rows, or isolates a new set of rows based on a second group of criteria. ​ At the end of the query, all of the steps are combined to produce a final result set.
  
Line 22: Line 24:
 Omnidex Segments provide a higher-speed approach to multi-step queries. ​ Instead of writing and rewriting temporary tables, Omnidex Segments will record the index pointers for each step into temporary objects and allow those segments to be reused in future queries. ​ These index segments are much more efficient than temporary tables, and can be directly applied against Omnidex indexes in future queries. ​ This greatly improves the performance of multi-step queries. Omnidex Segments provide a higher-speed approach to multi-step queries. ​ Instead of writing and rewriting temporary tables, Omnidex Segments will record the index pointers for each step into temporary objects and allow those segments to be reused in future queries. ​ These index segments are much more efficient than temporary tables, and can be directly applied against Omnidex indexes in future queries. ​ This greatly improves the performance of multi-step queries.
  
 +=== Creating Segments ===
 +
 +Segments are easily creating using the [[dev:​sql:​statements:​create_segment:​home|CREATE SEGMENT]] statement. ​ The following example shows a series of segments being created in a multi-step query.
 +
 +<​code>​
 +> ; Create an index segment for Individuals in Denver, CO
 +> create index segment PART_1
 +>> ​ as (select ​       INDIVIDUALS.$UNIQUEKEY
 +>> ​       from        INDIVIDUALS
 +>> ​       join        HOUSEHOLDS on INDIVIDUALS.HOUSEHOLD = HOUSEHOLDS.HOUSEHOLD
 +>> ​       where       STATE = '​CO'​ and
 +>> ​                   CITY = '​Denver'​);​
 +Segment PART_1 created with 37 rows
 +
 +> ; Create an index segment for Individuals in Phoenix, AZ;
 +-> create index segment PART_2
 +>> ​ as (select ​       INDIVIDUALS.$UNIQUEKEY
 +>> ​       from        INDIVIDUALS
 +>> ​       join        HOUSEHOLDS on INDIVIDUALS.HOUSEHOLD = HOUSEHOLDS.HOUSEHOLD
 +>> ​       where       STATE = '​AZ'​ and
 +>> ​                   CITY = '​Phoenix'​);​
 +Segment PART_2 created with 27 rows
 +
 +> ; Create an index segment for Individuals born since 1990;
 +> create index segment PART_3
 +>> ​ as (select ​       INDIVIDUALS.$UNIQUEKEY
 +>> ​       from        INDIVIDUALS
 +>> ​       where       ​BIRTHDATE >= '​January 1, 1990'​);​
 +Segment PART_3 created with 1,198 rows
 +</​code>​
 +
 +=== Using Index Segments in Queries ===
 +
 +Omnidex Segments can be referenced as criteria in a future query  using the [[dev:​sql:​functions:​segment:​home|$SEGMENT]] function. ​ The $SEGMENT function references the object name for any segment previously created in the same connection. ​ Since Omnidex Segments already contain index pointers, they are incorporated into a search with very high performance.
 +
 +The following example shows several segments that were above being referenced in a query using the $SEGMENT function:
 +
 +<​code>​
 +> ; Fulfill the query based on the final segment;
 +> select ​       INDIVIDUAL,
 +>> ​              ​BIRTHDATE,​
 +>> ​              CITY,
 +>> ​              STATE
 +>> ​  ​from ​       INDIVIDUALS
 +>> ​  ​join ​       HOUSEHOLDS on INDIVIDUALS.HOUSEHOLD = HOUSEHOLDS.HOUSEHOLD
 +>> ​  ​where ​      ​INDIVIDUAL in ($segment(PART_1),​ $segment(PART_2)) and
 +>> ​              ​INDIVIDUAL = $segment(PART_3);​
 +
 +INDIVIDUAL ​   BIRTHDATE ​    ​CITY ​                         ST
 +------------ ​ ------------ ​ ---------------------------- ​ --
 +000400191550 ​ 1996-04-26 ​   PHOENIX ​                      AZ
 +000400575367 ​ 1996-11-19 ​   PHOENIX ​                      AZ
 +000400575366 ​ 1995-09-26 ​   PHOENIX ​                      AZ
 +000400575369 ​ 2005-06-29 ​   PHOENIX ​                      AZ
 +000400575368 ​ 2004-07-30 ​   PHOENIX ​                      AZ
 +000403467439 ​ 1994-08-28 ​   PHOENIX ​                      AZ
 +000403467441 ​ 2003-04-19 ​   PHOENIX ​                      AZ
 +000403467440 ​ 1997-02-28 ​   PHOENIX ​                      AZ
 +000800345452 ​ 1998-08-31 ​   DENVER ​                       CO
 +000800345453 ​ 2003-12-25 ​   DENVER ​                       CO
 +000801610627 ​ 2004-03-17 ​   DENVER ​                       CO
 +000802420583 ​ 1990-03-18 ​   DENVER ​                       CO
 +000802420584 ​ 1993-10-06 ​   DENVER ​                       CO
 +000803400688 ​ 1990-06-16 ​   DENVER ​                       CO
 +000803400689 ​ 1990-10-25 ​   DENVER ​                       CO
 +000803760388 ​ 2006-07-30 ​   DENVER ​                       CO
 +000803760386 ​ 1995-12-09 ​   DENVER ​                       CO
 +000803760387 ​ 1997-09-24 ​   DENVER ​                       CO
 +
 +18 rows returned
 +</​code>​
 +
 +
 +=== Dropping Segments ===
 +
 +Omnidex Segments can be dropped, resulting in the removal of the object from the connection, and also the removal of the underlying data.  It is not required to drop segments, as they will be automatically dropped when the connection ends.  Dropping segments is required when reusing the same connection name within the same connection.
 +
 +Omnidex Segments are dropped using the [[dev:​sql:​statements:​drop_segment:​home|DROP SEGMENT]] statement, as shown in the example below:
 +
 +<​code>​
 +> drop segment ​                  ​PART_1;​
 +Segment PART_1 dropped
 +> drop segment ​                  ​PART_2;​
 +Segment PART_2 dropped
 +> drop segment ​                  ​PART_3;​
 +Segment PART_3 dropped
 +</​code>​
  
 ====  ==== ====  ====
 
Back to top
admin/features/segments/index.1331070432.txt.gz ยท Last modified: 2016/06/28 22:38 (external edit)