This is an old revision of the document!


DRAFT

Omnidex SQL Examples

  • Select Statements
  • Qualify Statements
  • Export Statements
  • Extract Statements
  • Debugging Statements
  • Update Indexes Statements
  • Select Specials (SAMPLE, RANDOM, EVERY)

Extract Omnidex DDL from existing Omnidex Environment

  os> odxsql
  odxsql> connect myenv.xml;
  odxsql> EXTRACT DDL to myfile.sql;

Export using Oracle NLS date

Oracle has a setting called NLS_DATE_FORMAT that controls what default date and time format to use in SQL statements. We use that setting to pass criteria to Oracle. We have a default setting, but you can control it yourself through an environment variable. If you set that environment variable, we’ll do an ALTER SESSION with Oracle to pass on your new values. Set the environment variable as follows:

export DA_ORA_DATE_FMT=’format’

where ‘format’ is any valid NLS_DATE_FORMAT.

In my example, I set it as follows:

export DA_ORA_DATE_FMT=’MON DD, YYYY HH24:MI:SS’

Here is an example of sending SQL statements through Omnidex using this technique. Note that I’m using the EXTRACT function format a date to see the seconds and so forth.

 
> select extract ('MMM D, YYYY  HH:0N:0S.0F' from created) from mytable;
 
EXTRACT('MMM D, YYYY  HH:0N:0S.0
--------------------------------
July 27, 2010  15:26:04.00
July 27, 2010  15:26:05.00
July 27, 2010  15:26:06.00
 
3 rows returned
> select extract ('MMM D, YYYY  HH:0N:0S.0F' from created) from mytable where created > 'Jul 27, 2010 15:26:04';
 
EXTRACT('MMM D, YYYY  HH:0N:0S.0
--------------------------------
July 27, 2010  15:26:05.00
July 27, 2010  15:26:06.00
 
 
2 rows returned
> 
 

Updates Indexes

update indexes with MAXTHREADS=2;
update indexes with max_threads=2;

Specifies a directory where several indexing logs are written as well as some internal logs such as dbinstal.log.

update indexes with log=odxlogs;

$CONTAIN Function

SELECT FIRST_NAME FROM CUSTOMERS WHERE $CONTAINS(FIRST_NAME,'fred,'SYNONYMS=ALL_GIVEN_NAMES');
SELECT FIRST_NAME FROM CUSTOMERS WHERE 
    $CONTAINS(FIRST_NAME,'fred,'SYNONYMS','LIST=ALL_GIVEN_NAMES');
SELECT FIRST_NAME FROM CUSTOMERS WHERE $CONTAINS(FIRST_NAME, 
   '(SYNONYMS(fred,"ALL_GIVEN_NAMES"))'); 

Qualify Statement

QUALIFY CUSTOMERS WHERE FIRST_NAME = 'SYNONYMS(fred,"ALL_GIVEN_NAMES")'
QUALIFY CUSTOMERS WHERE FIRST_NAME = 'SYNONYMS(fred,,"LIST=ALL_GIVEN_NAMES")'

Searches

Example 1: Basic search

select        TOP 20 PRO.COMPANY, \
              PRO.CONTACT, \
              PRD.DESCRIPTION, \
              ORD.ORDER_DATE, \
              ORD.QUANTITY, \
              ORD.AMOUNT, \
              ORD.TOTAL \
  from        ORDERS_SVW ORD \
  join        PROSPECTS PRO on ORD.ACCT = PRO.ACCT \
  join        PRODUCTS PRD on ORD.PRODUCT_NO = PRD.PRODUCT_NO \
  where       ORD.ORDER_DATE BETWEEN 'Jan 1 2000' and 'Mar 31 2000' and \
              PRO.STATE = 'CO' and \
              PRO.CUST_SINCE = '1996'

Example 2: Same select list, but use $contains to allow synonyms

select        TOP 20 PRO.COMPANY, \
              PRO.CONTACT, \
              PRD.DESCRIPTION, \
              ORD.ORDER_DATE, \
              ORD.QUANTITY, \
              ORD.AMOUNT, \
              ORD.TOTAL \
  from        ORDERS_SVW ORD \
  join        PROSPECTS PRO on ORD.ACCT = PRO.ACCT \
  join        PRODUCTS PRD on ORD.PRODUCT_NO = PRD.PRODUCT_NO \
  where       $contains(ORD.ORDER_DATE, '1ST_QTR_2000', 'synonyms=time_periods, exclusive') and \
              $contains(PRO.STATE, 'COLORADO', 'synonyms=state_codes') and \
              $contains(PRO.CUST_SINCE, '1996')

Example 3: Same select list, but use joins to more dimensions to allow description fields from other dimensions and snowflakes.

select        TOP 20 PRO.COMPANY, \
              PRO.CONTACT, \
              PRD.DESCRIPTION, \
              ORD.ORDER_DATE, \
              ORD.QUANTITY, \
              ORD.AMOUNT, \
              ORD.TOTAL \
  from        ORDERS_SVW ORD \
  join        PROSPECTS PRO on ORD.ACCT = PRO.ACCT \
  join        PRODUCTS PRD on ORD.PRODUCT_NO = PRD.PRODUCT_NO \
  join        INCOMES INC on PRO.INCOME = INC.INCOME \
  join        MFRS on PRD.MFR = MFRS.MFR \
  where       $contains(ORD.ORDER_DATE, '1ST_QTR_2000', 'synonyms=time_periods, exclusive') and \
              $contains(MFRS.DESCRIPTION, 'Dell') and \
              $contains(INC.DESCRIPTION, '$50,000-$59,999') 

Crosstab

<code>
select        CAT.DESCRIPTION, \
              ORD.OR_FQTR, \
              COUNT(ORD.TOTAL) \
  from        ORDERS_SVW ORD \
  join        PROSPECTS PRO on ORD.ACCT = PROSPECTS.ACCT \
  join        CATEGORIES CAT on ORD.CATEGORY = CAT.CATEGORY \
  where       ORD.ORDER_DATE BETWEEN 'Jan 1 2000' and 'Mar 31 2000' and \
              PRO.STATE = 'CO' and \
              PRO.CUST_SINCE = '1996' \
  group by    CAT.DESCRIPTION, \
              ORD.OR_FQTR

Example 2: List View Example #2 criteria shown with a crosstab of totals by income and profession

select        INC.DESCRIPTION, \
              PRF.DESCRIPTION, \
              SUM(ORD.TOTAL) \
  from        ORDERS_SVW ORD \
  join        PROSPECTS PRO on ORD.ACCT = PRO.ACCT \
  join        INCOMES INC on ORD.INCOME = INC.INCOME \
  join        PROFESSIONS PRF on ORD.PROFESSION = PRF.PROFESSION \
  where       $contains(ORD.ORDER_DATE, '1ST_QTR_2000', 'synonyms=time_periods, exclusive') and \
              $contains(PRO.STATE, 'COLORADO', 'synonyms=state_codes') and \
              $contains(PRO.CUST_SINCE, '1996') \
  group by    INC.DESCRIPTION, \
              PRF.DESCRIPTION

criteria shown with a crosstab of counts by cust_since and region

select        ORD.CUST_SINCE, \
              ORD.REGION, \
              COUNT(ORD.TOTAL) \
  from        ORDERS_SVW ORD \
  join        PROSPECTS PRO on ORD.ACCT = PRO.ACCT \
  join        PRODUCTS PRD on ORD.PRODUCT_NO = PRD.PRODUCT_NO \
  join        INCOMES INC on PRO.INCOME = INC.INCOME \
  join        MFRS on PRD.MFR = MFRS.MFR \
  where       $contains(ORD.ORDER_DATE, '1ST_QTR_2000', 'synonyms=time_periods, exclusive') and \
              $contains(MFRS.DESCRIPTION, 'Dell') and \
              $contains(INC.DESCRIPTION, '$50,000-$59,999') \
  group by    ORD.CUST_SINCE, \
              ORD.REGION

Force a system segmentation violation to test abnormal terminations

select * from $abort;

For example, “select count(*) from events where userid = 1 with optimization=none” will send it to Oracle and Oracle will use its index. “select count(*) from events where userid = <expression> with opt=none” will be processed with a full table scan, but with us processing the expression ourselves.

Yes, that’s correct. We do not support the arithmetic expression below, partly because people want different units of measure. In the example you use, I assume you mean “current_date minus 90 days”, but it could also mean “90 hours” or something different. Since there was no SQL standard, we used our $calc_date or $compare_date functions to be explicit.

 
Back to top
dev/sql/examples/home.1303490075.txt.gz · Last modified: 2012/10/26 14:52 (external edit)