Slow Azure Table query with range filter on the RowKey -


i upgraded azure sdk 1 sdk 2 , converted following code:

public ienumerable<anonymoussessionentity> getanonymoussessions(guid visitorid, guid customerid, int connectionid, mergeoption mergeoption = mergeoption.appendonly) {     try     {         var partitionkey = azureutil.combinetokey(customerid, connectionid);          _tablestorageservicecontext.mergeoption = mergeoption;         _tablestorageservicecontext.resolvetype = (unused) => typeof(anonymoussessionentity);          var query = s in _tablestorageservicecontext.createquery<anonymoussessionentity>(tablestorageservicecontext.anonymoussessionentityname)                          .where(s => s.partitionkey == partitionkey && s.rowkey.compareto(azureutil.getrowkeytimelimit(90)) <= 0 && s.visitorid == visitorid)                     select s;          cloudtablequery<anonymoussessionentity> cloudtablequery = query.astableservicequery<anonymoussessionentity>();         ienumerable<anonymoussessionentity> anonymoussessions = cloudtablequery.execute();          return anonymoussessions;     }     catch (dataservicequeryexception e)     {         if (e.response.statuscode == (int)httpstatuscode.notfound) return null;         else throw;     } } 

into following:

public ienumerable<anonymoussessionentity> getanonymoussessions(guid visitorid, guid customerid, int connectionid) {     var partitionkey = azureutil.combinetokey(customerid, connectionid);     var pkfilter = tablequery.generatefiltercondition("partitionkey", querycomparisons.equal, partitionkey);     var rkfilter = tablequery.generatefiltercondition("rowkey", querycomparisons.lessthan, azureutil.getrowkeytimelimit(90));     var visitoridfilter = tablequery.generatefilterconditionforguid("visitorid", querycomparisons.equal, visitorid);     var combinedfilter = string.format("({0}) {1} ({2}) {3} ({4})", pkfilter, tableoperators.and, rkfilter, tableoperators.and, visitoridfilter);      var table = getcloudtable(tablestoragedatasource.anonymoussessionentityname);     var rangequery = new tablequery<anonymoussessionentity>().where(combinedfilter);      var result = table.executequery<anonymoussessionentity>(rangequery);     return result; } 

as can see, have filter on partitionkey , on rowkey , on custom field (called "visitorid"). query worked great sdk 1 new version slow. in fact, it's slow leads me believe azure full table scan (i stopped counting after more minute). have few million rows in table absolutely have avoid table scans.

for testing purposes, removed filter on "visitorid" field in v2 query , performs fast: 2-3 seconds.

is there way build fast query following criteria:

  1. exact match on partitionkey
  2. range filter on rowkey
  3. exact match on custom field


Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -