Varbinary startswith query using index
So as a matter of fact, starts with is not so hard to write as it would first seem. Given the initial key of 0x000000100004, obviously equals won't work and there is no starts with operation, but we can write ObjectId &gt;= 0x000000100004 AND ObjectId &lt; 0x000000100005.
By forcing the string of long values to VARBINARY conversion to be big-endian the natural form actually works correctly. We want &gt;= (value0 &amp; value1 &amp; ... &amp; lastvalue) AND &lt; (value0 &amp; value1 &amp; ... &amp; (lastvalue + 1)). As far as I know, the conversion to VARBINARY has to be written in application code, which is fine for me.