Lightning Query Optimization


Lightning Query Optimization is a feature that Alpha Anywhere activates to increase the speed at which queries are run against DBF tables. By using information contained in the indexes you have created, Alpha Anywhere can dramatically speed up queries. To take advantage of this time-saving feature, both the query you design and the pre-existing indexes must be compatible with Lightning Query Optimization. The following sections explain this compatibility.

 Building Compatible Indexes

For Lightning Query Optimization to use a pre-existing index, the index must:

  • Use at least one of the same fields used in the query.

  • If you use multiple fields with different data types, the first field used must be type character,

  • The data type of the data in the index key must match the data type of the field you are searching.

  • Use an order expression that contains either a single field, or two fields concatenated using the plus operator (+), such as in the expression Lname+Fname.

  • Not use the Unique Only option

  • Not use a filter expression

 Building Compatible Queries

For a Query to work with Lightning Query Optimization, at least one of the condition expressions in the query must compare a field used in one of your indexes with a constant. For example, State = "MA", is suitable, provided you have a pre-existing index which sorts records using the State field. The condition expression must use operators that are compatible with Lightning Query Optimization. These include:

  • Equals (=)

  • Exactly equals (==)

  • Greater than or equal to (>=)

  • Greater than (>)

  • Less than or equal to (<=)

  • Less than (<)

  • Not equal to (<>)

  • BETWEEN(..)

  • SMATCH()- see note below

  • Wildcards (* and ?) - see note below

  • .NOT.

  • .AND.

  • .OR.

The SMATCH() function and the wildcards * and ? can only be used with Lightning Query Optimization if they appear at the end of the expression. For example, a search for McC* can be optimized since the wildcard operator appears at the end, while a search for *stein cannot be optimized, since the wildcard operator begins at the beginning.

 Partial Compatibility

In some cases, only part of your query's selection expression can be used with Lightning Query Optimization. In this case, Alpha Anywhere applies the optimization algorithm to the compatible part, and uses Alpha Anywhere's standard query algorithm to evaluate the rest. For example, you have a table of customers for which you have created an index that sorts records by the field City. You then create a query which uses the following selection expression:

(CITY = "BOSTON").AND.("Commonwealth" $ ADDRESS1)

Because the second half of the expression uses an operator that is not compatible with Lightning Query Optimization and a field which is not used in a pre-existing index (ADDRESS1), Alpha Anywhere applies Lightning Query Optimization to only the first part of the expression. Furthermore, in cases where the selection expression evaluates to TRUE for most of the records in the table or set, Alpha Anywhere will analyze the query and might determine that the standard query algorithm is more suitable. In this case, Lightning Query Optimization is not used.

See Also