Overview | Environments | Databases | Tables | Constraints | Datatypes | Queries | Updates | Example
Oracle table constraints and indexes should be declared in the Omnidex Environment File. Omnidex uses primary and foreign key table constraints to understand the nature of the data and to optimize table joins. Declaring primary keys for a table also allows Omnidex to fulfill more queries solely in the indexes without having to access the database. Omnidex uses an understanding of the Oracle indexes to insure that the queries it submits to Oracle will be well optimized.
The table declarations in the Omnidex Environment File should include primary and foreign key constraints that establish parent-child relationships between the tables. While Omnidex does not validate or enforce these constraints; they are heavily used when optimizing queries. Omnidex does not need to know about column constraints that exist in Oracle, such as NULL, NOT NULL, CHECK or DEFAULT constraints.
In most situations, the constraints declared in Omnidex should match those declared in the Oracle database; however, administrators may alter these if they wish. At times, a parent-child relationship may exist between tables in Oracle even though a constraint is not formally declared. These can be declared in Omnidex, allowing more advanced optimization of multi-table queries.
Omnidex requires that the datatype of a foreign key constraint match the datatype of the referencing constraint. If this is not the case within the Oracle database, it may be possible to remap the datatype in Omnidex so that they do match. Consult the documentation on datatypes to see the options for remapping datatypes.
Omnidex is tolerant of violations of foreign key constraints, such as foreign keys for which there are no primary keys in the corresponding tables. Omnidex is not tolerant of violations of primary key constraints, as these can lead to incorrect results returned from queries.
The following examples show constraints being declared in Oracle and Omnidex CREATE TABLE statements:
Oracle CREATE TABLE Statement
create table STATES (STATE_CD CHAR(2), DESCRIPTION VARCHAR2(31), STATE_NUM CHAR(2), REGION_CD CHAR(2), COUNTRY_CD CHAR(2), TAX_RATE NUMBER(16,6), constraint STATES_STATE_CD_PK primary key (STATE_CD) using index, constraint STATES_COUNTRY_CD_FK foreign key (COUNTRY_CD) references COUNTRIES(COUNTRY_CD));
Omnidex CREATE TABLE Statement
create table "STATES" physical "SIMPLE.STATES" ( "STATE" CHARACTER(2) physical "STATE_CD", "DESCRIPTION" STRING(31), "STATE_CODE" CHARACTER(2) physical "STATE_NUM", "REGION" CHARACTER(2) physical "REGION_CD", "COUNTRY" CHARACTER(2) physical "COUNTRY_CD", "TAX_RATE" FLOAT, constraint STATES_STATE_PK primary ("STATE"), constraint STATES_COUNTRY_FK foreign ("COUNTRY") references "COUNTRIES" ) in "simple.xml";
Oracle indexes that exist on primary and foreign key constraints should be declared as NATIVE indexes in the Omnidex Environment File. This is true whether the Oracle index was created using Oracle's CREATE INDEX statement or whether the Oracle constraint was created using the “USING INDEX” clause. It can be beneficial to declare other Oracle indexes as well.
The Omnidex SQL Engine will evaluate the presence of native Oracle indexes when deciding how to process a statement. At times, it may be faster to rely on the native Oracle indexes than to use Omnidex indexes. This is especially true for searches on unique values, such as primary keys.
Oracle indexes are declared in the Omnidex Environment File using the CREATE TABLE or CREATE INDEX statements. The following example shows native indexes being declared for a table.
Declaring Native Indexes
create table "STATES" physical "SIMPLE.STATES" ( "STATE" CHARACTER(2) physical "STATE_CD", "DESCRIPTION" STRING(31), "STATE_CODE" CHARACTER(2) physical "STATE_NUM", "REGION" CHARACTER(2) physical "REGION_CD", "COUNTRY" CHARACTER(2) physical "COUNTRY_CD", "TAX_RATE" FLOAT, constraint STATES_STATE_PK primary ("STATE"), constraint STATES_COUNTRY_FK foreign ("COUNTRY") references "COUNTRIES", native index STATE_IDX ("STATE"), native index COUNTRY_IDX ("COUNTRY") ) in "simple.xml";
See also: