This project has moved and is read-only. For the latest updates, please go here.

Using SeekEQ with partial keys

Mar 19, 2014 at 7:27 AM
Is it possible to seek with SeekEQ using a partial key?

Let's say I have an index on columns A, B and C. I want to seek to the first row that matches A==42, B==13 and then iterate through the rows in ascending values of C.

I know I can seek using SeekGE, but then I have to read the first row to see if A==42 and B==13 before I know if there are any matches.

If I was seeking with a full key, then I know SeekEQ would work fine and return false when there's no match. I just want the same behaviour for partial keys.

Heads up, my next question will probably be about index ranges using partial keys. But I'm trying to figure out seeks first.
Mar 20, 2014 at 8:18 AM
After thinking/reading about this a bit, I think I understand why it works the way it does.

It's still a shame that I need to compare the values of the row I end up seeking to. Especially since my key might be on multi-valued columns, which means I'll have to compare my key with each of the multi-values to see if it matches any of them.
Mar 20, 2014 at 8:39 PM
Correct, a SeekEQ won't work the way you want.

You were right that you want an index range. Here's some untested pseudo-code.
Api.MakeKey( 42, NewKey );
Api.MakeKey( 13, FullColumnStartLimit ); // This fills in 0x0's for the remaining columns
Api.TrySeek( GE );
Api.MakeKey( 42 );
Api.MakeKey( 13, FullColumnEndLimit ); // This fills in 0xff's for the remaining columns.
Api.TrySetIndexRange( ..., SetIndexRangeGrbit.RangeInclusive | SetIndexRangeGrbit.RangeUpperLimit );
Marked as answer by ptousig on 3/20/2014 at 11:59 PM
Mar 20, 2014 at 8:46 PM
Even with the index range, I will still need to verify that after the Api.TrySeek(GE) call I am on a row where A==42 and B==13. That's the part I was trying to avoid.
Mar 20, 2014 at 8:58 PM
No, because setting the index range would fail.
Mar 21, 2014 at 7:58 AM
You're right, that worked. Thanks.