Database mapping database-mapping

This page describes how to declare indexes on the fields of a schema.

As part of the transition from Campaign v7 to v8, the Campaign Classic documentation set has been streamlined and reorganized. Common features are now available exclusively in the Campaign v8 documentation set. To learn more about the SQL mapping of schemas, refer to the Campaign v8 documentation.

image

Indexed fields indexed-fields

Indexes let you optimize the performance of the SQL queries used in the application.

An index is declared from the main element of the data schema.

<dbindex name="name_of_index" unique="true/false">
  <keyfield xpath="xpath_of_field1"/>
  <keyfield xpath="xpath_of_field2"/>
  ...
</key>

Indexes obey the following rules:

  • An index can reference one or more fields in the table
  • An index can be unique (to avoid duplicates) in all of the fields if the unique attribute contains the value “true”
  • The SQL name of the index is determined from the SQL name of the table and the name of the index
NOTE
  • As a standard, indexes are the first elements declared from the main element of the schema.

  • Indexes are created automatically during table mapping (standard or FDA).

Example:

  • Adding an index to the email address and city:

    code language-sql
    <srcSchema name="recipient" namespace="cus">
      <element name="recipient">
        <dbindex name="email">
          <keyfield xpath="@email"/>
          <keyfield xpath="location/@city"/>
        </dbindex>
    
        <attribute name="email" type="string" length="80" label="Email" desc="Email address of recipient"/>
        <element name="location" label="Location">
          <attribute name="city" type="string" length="50" label="City" userEnum="city"/>
        </element>
      </element>
    </srcSchema>
    
  • Adding a unique index to the “id” name field:

    code language-sql
    <srcSchema name="recipient" namespace="cus">
      <element name="recipient">
        <dbindex name="id" unique="true">
          <keyfield xpath="@id"/>
        </dbindex>
    
        <dbindex name="email">
          <keyfield xpath="@email"/>
        </dbindex>
    
        <attribute name="id" type="long" label="Identifier"/>
        <attribute name="email" type="string" length="80" label="Email" desc="Email address of recipient"/>
      </element>
    </srcSchema>
    

Learn more

Browse the following links to learn more:

recommendation-more-help
campaign-classic-help