Hi!
I've written a custom collator for index that effectively compares only suffixes of the keys.
The problem is that now
::search()
in index returns
for key that is equal according to the collator, but has different prefix.
Minimized test:
include <assert.h>
include <stdio.h>
include <stdlib.h>
include <string.h>
include <wiredtiger.h>
define WT_HOME "index_suff_collator.db"
define WT_CALL(call) \
do { \
const int __rc = call; \
if (__rc != 0)
\
} while (0)
static int
compare_int(int a, int b)
{
return (a < b ? -1 : (a > b ? 1 : 0));
}
static int
compare_ikey(const WT_ITEM _a, const WT_ITEM _b)
{
assert(a->size == 2);
assert(b->size == 2);
int av = ((char*)a->data)[1],
bv = ((char*)b->data)[1];
return compare_int(av, bv);
}
static int
compare_pkey(const WT_ITEM _a, const WT_ITEM _b)
{
assert(a->size == 1);
assert(b->size == 1);
int av = ((char*)a->data)[0],
bv = ((char*)b->data)[0];
return compare_int(av, bv);
}
static int
main_compare(WT_COLLATOR _collator, WT_SESSION _session, const WT_ITEM *key1, const WT_ITEM _key2, int _cmp)
{
*cmp = compare_pkey(key1, key2);
return 0;
}
static int
index_compare(WT_COLLATOR _collator, WT_SESSION _session, const WT_ITEM *key1, const WT_ITEM _key2, int _cmp)
{
WT_ITEM ikey1, pkey1, ikey2, pkey2;
WT_CALL(wiredtiger_struct_unpack(session, key1->data, key1->size, "uu", &ikey1, &pkey1));
WT_CALL(wiredtiger_struct_unpack(session, key2->data, key2->size, "uu", &ikey2, &pkey2));
if ((*cmp = compare_ikey(&ikey1, &ikey2)) != 0)
return 0;
if ((pkey1.size > 0) && (pkey2.size > 0))
*cmp = compare_pkey(&pkey1, &pkey2);
return 0;
}
static WT_COLLATOR main_coll =
{ main_compare, NULL, NULL };
static WT_COLLATOR index_coll =
;
int
main(void)
When running it I get:
$ ./index_suff_collator
cursor->search(cursor) at (index_suff_collator.c:116) failed: WT_NOTFOUND: item not found [-31803]
`
Please advise!
Thanks!
- related to
-
WT-1714 broken search in index with custom collator
- Closed