Sorting Queries in Browsers

ActiveSpaces provides the ability to sort queries that are made using browsers. The sorting feature is implemented in the filter that is used for specifying a browser query. The filter can now use order by statements.

The order by clause is a part of the filter. It is similar to the method used with SQL. There is no change in the API.

The following are examples of order by statements in filters:

  • order by key
  • id < 100 order by id
  • id = 5 and key < 100 order by key
  • id < 10 order by id, key

Note the following points:

Syntax

<query> order by <field1>, <field2>, . . . needs to be added to the end of the filter.

There is no limit on the number of fields you can have.

Requirements

A TREE index with fields is used in the order bysection. The index can be a, b, c and where the order by is performed on a, b.

If the index has more than one field and order by is executed only on one field, the sorting will work only if the field name is the first entry in the index.

CURRENT time scope.

If the order by cannot be satisfied due to requirements 1 or 2 as stated above, then an exception is thrown.

Change in Behavior

Index selection for queries is dictated by the use of order by in the filter. The use of order by in a query filter can override the indices that would normally be used by the query.

Consider the following query:

key<10 order by id

If the user has an index on “key” and another index on “id,” ActiveSpaces will pick the index on “id” over the index on “key” and perform a table scan to validate “key<10."