Query Optimization Tips

<< Click to Display Table of Contents >>

Navigation:  Apollo VCL Components > Optimizing Performance >

Query Optimization Tips

 

The Query is highly optimized method for allowing the creation of runtime filters on data. Used in conjuction with RYO Filters (Roll-Your-Own), you can achieve amazing performance results unmatched by any other system. The following is an example that demonstrates the power and flexibility of Query. This sample allows end users to enter any part of an expression and filters the data based on what was entered.

If we have a table with the following 3 fields, each field has a corresponding index:

 

e.g.

 

Field Names: FNAME LNAME  ADDRESS

 

Rec #1  John Smith  123 Any Street

Rec #2  Sam  Johnson  555 Last Way

Rec #2  Andy  Dugan   31 Fast Lane

 

 

We want to allow users to filter the table data by entering any of part of the these 3 fields. This is sometimes referred to as a wildcard search. Ie. Show me all records with "John" as the FNAME or show me all records with "D" as part of the LNAME.

 

Using fully optimized queries in conjunction with Apollo's RYO Filters and bitwise operations lets you achieve blazingly fast filter performance - unmatched in performance and flexibility by any other system on the market. The ability to apply multiple filters to existing filtered data, thereby letting data results be narrowed, makes incremental searching instantaneous.

For example:

var

         iFName, iLName : Integer;

Begin

 

 // fully optimised Query Bitmap - very fast filtering

 Table1.Query( 'FNAME=" + edFName.Text + '"' );

 

         // Note: You may optionally test the query using the following:

         // optimizeLevel := Table1.QueryTest('FNAME=" + edFName.Text + '"')

  // This would return the optimization level

 

         // Copies the Query Bitmap for later use

         iFName := Table1.RYOFilterCopy;

 

         // Clears the query

         Table1.Query( #0 );

 

         // Optimized and fast

         Table1.Query( 'LNAME="'+ edLame.Text+'"');

 

         // Not necessary to create another bitmap but

         // this shows you can

         iLName := Table1.RYOFilterCopy;

 

end;

 

The above code creates 2 optimized queries and saves both. The goal is that you want only those

records that match both query statements (i.e. apply and "AND" operation)

 

// Activate the FName RYO Filter

Table1.RYOFilterActivate( iFName, RYOFILTER_NEW );

// Activate the LName RYO Filter

// Note. The result of this LName RYO filter is actually added

// or "AND"ed to the results of the previously set filter.

// In this case, iLName is added to the iFName filter to show

// records that match both queries.

Table1.RYOFilterActivate( iLName, RYOFILTER_AND );

 

RYOFilters is unique to Apollo and this technique of filtering is in class all its own when it comes to performance. The end result of using RYO Filters can be astonishing.

See Also

SetScope, Filtering data