Fast Query is an exciting Crestone feature that is usually off the marketing radar. It is a subset of Sitecore Query that executes with SQL speed, meaning fast.
While it's not as expressive as Sitecore Query, you can still retrieve items using item paths, IDs or names, field values and parent/child relationships, which is what people need 80% of the time. The performance gain is outstanding - think writing an SQL query instead of going through all the items using the Sitecore API.
How to Use the Fast Query?
Much like standard Sitecore Query before, you can use Fast Query either in field sources or in the API. To indicate that that your query must be executed in the "fast" mode, prefix it with "fast:" :
The API way:
Sitecore.Context.ContentDatabase.SelectItems("fast:/sitecore/content/home/*");
Note that relative queries starting from a specific item are not supported, you cannot use fast query in item.Axes.SelectItems.
So What Queries are Supported?
- Only child and descendant axes are supported. For example you cannot search for a parent of a specific item or following-sibling.
- The following special attributes are supported: @@id, @@name, @@templateid, @@masterid and @@parentid.
- String comparison is converted to SQL LIKE operator.
- Functions are not supported, contains() is replaced by string comparison which behaves like SQL LIKE.
- Subqueries are not supported. i.e. the following query won't work: //*[../@name='Home']
- It is not possible to query from a context item, only the whole database.
(More on query syntax in the original Crestone beta forum post by Dmitry Kostenko)
How to Test?
The XPath Builder works great with Fast Query. Open Developer Center, select Tools menu and then XPath Builder. Remember to prefix your queries with "fast:":
Performance
XPath Builder actually shows how much time it spent executing the query, so we can see the difference the fast query makes:
Switch the XPath Builder to the core database (it's much bigger than the master in a clean Sitecore installation).
fast://*[@@name = 'Home'] takes 1-2ms.
//*[@@name = 'Home'] takes 350-500ms after the first couple of runs.
New Usage Scenarios
Fast Query enables scenarios that weren't possible before because of the query speed:
In Sitecore 5 we have a shared source "My Locked Items" module that has to use caching and subsequently cache invalidation to get a list of items locked by the user with a decent performance.
In Crestone we have a built-in Locked Items application, that does pretty much the same but was trivial to make, because all it has to do to get the list of items locked by the user is to run the following query:
Database.SelectItems("fast://*[@__lock='%sitecore\\Admin%']"
The Crestone version of the RSS module will also use the fast query to retrieve items while building the feed, which will hopefully make generating feeds per-demand more feasible.
Summary
It doesn't get much simpler: the new query is fast, use it to make your sites more responsive or to provide better features which you couldn't implement before.
Update: As of June 14th, 2008, the fast query is considered an experimental feature in Sitecore 6.0. It's recommended that you test the results of the query first - in some situations it's possible that queries relying on parent-child relationships can return results that are slightly out of date. This is likely to be fixed in the following versions of Sitecore.