indexing descending

I have a query that is being sorted descending. I am trying to index that following JA documentation: and it is not working. Any help would be appreciated! :slight_smile:

Hi Paula

You can specify the order of the index by adding a - before the name of the field you want to put the index on. For example

<model name="customer" label="Customer">
    <field name="name" label="Name" type="text:name" />
    <field name="date" label="Date" type="date" />
    <field name="is_deleted" label="Is Deleted" type="boolean" />

    <has-many model="ticket" name="tickets" />
    <index on="name" /> <!-- asc index -->
    <index on="-date" /> <!-- desc index -->
    <index on="name,-date" /> <!-- index on name(asc)+date(desc) -->

Please share your findings in terms of performance improvement before and after specifying the sort order of the index - we are very curious to see the results. From our experience indexes are mostly useful for reducing the results set that needs to be evaluated into memory, and for that the order of the index will probably have a negligible impact. But it’s possible that the order of the index could have an impact for large results set using compound queries, something like make,model,-year for vehicles.