This post is part of a series of posts that aims to capture a number of emerging design patterns for the Windows Azure Platform. This series will begin by tackling emerging design patterns for Windows Azure Table storage.
The Starts With Query Pattern enables performance optimised begins with partial match operations.
Provide a fast search for articles that begins with the term “Metabolis” from a list of article titles, such as those found on Wikipedia. A subset is shown below:
Metabolife, Metabolise, Metabolised, Metabolism, Metabolite
Using LINQ to return the titles that start with e.g. “Metabolis” the following query might be tried:
var titles =
from titlesearch in
However, this is not supported by Windows Azure Table storage (http://blogs.southworks.net/fboerr/2010/04/22/compsition-in-windows-azure-table-storage-choosing-the-row-key-and-simulating-startswith/).
The entities within a partition in a table are returned in the lexicographical order of the row key. To take advantage of this, storing all the article titles in the same partition and capitalising the title, to provide case insensitive search (if required).
|Partition Key||Row Key||Title|
Then using a LINQ query with a set of statements to constrain the results in 3 ways. First, constrain to a single partition “M”. Second, constrain to records from and including “METABOLIS” (lexicographically) . Third, by replacing the last character “S” with the next character “T”, constrain to records before “METABOLIT” (lexicographically).
var titles =
(from t in
where t.RowKey.CompareTo(“METABOLIS”) >= 0
&& t.RowKey.CompareTo(“METABOLIT”) < 0
&& t.PartitionKey == “M”
Additionally, the Take operator can be used to limit the number of results returned (http://msdn.microsoft.com/en-us/library/dd135725.aspx). This query will return “Metabolise” and “Metabolised” as the top 2 results from the example list shown.
Enable performance optimised begins with partial match operations.
The value to be queried stored as the row key and lower and upper bound constraints applied to the query.
Where multiple row need to be returned from a begins with partial word match search.
Windows Azure Table (Tips and Tricks Section)