mirror of
https://git.openldap.org/openldap/openldap.git
synced 2025-01-12 10:54:48 +08:00
substring indexing optimization
This commit is contained in:
parent
34e154e28b
commit
8f5ea1f1d2
@ -169,16 +169,13 @@ octetStringOrderingMatch(
|
|||||||
return LDAP_SUCCESS;
|
return LDAP_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
static void
|
||||||
hashDigestify(
|
hashPreset(
|
||||||
HASH_CONTEXT *HASHcontext,
|
HASH_CONTEXT *HASHcontext,
|
||||||
unsigned char *HASHdigest,
|
|
||||||
struct berval *prefix,
|
struct berval *prefix,
|
||||||
char pre,
|
char pre,
|
||||||
Syntax *syntax,
|
Syntax *syntax,
|
||||||
MatchingRule *mr,
|
MatchingRule *mr)
|
||||||
unsigned char *value,
|
|
||||||
int value_len)
|
|
||||||
{
|
{
|
||||||
HASH_Init(HASHcontext);
|
HASH_Init(HASHcontext);
|
||||||
if(prefix && prefix->bv_len > 0) {
|
if(prefix && prefix->bv_len > 0) {
|
||||||
@ -188,11 +185,21 @@ hashDigestify(
|
|||||||
if(pre) HASH_Update(HASHcontext, (unsigned char*)&pre, sizeof(pre));
|
if(pre) HASH_Update(HASHcontext, (unsigned char*)&pre, sizeof(pre));
|
||||||
HASH_Update(HASHcontext, (unsigned char*)syntax->ssyn_oid, syntax->ssyn_oidlen);
|
HASH_Update(HASHcontext, (unsigned char*)syntax->ssyn_oid, syntax->ssyn_oidlen);
|
||||||
HASH_Update(HASHcontext, (unsigned char*)mr->smr_oid, mr->smr_oidlen);
|
HASH_Update(HASHcontext, (unsigned char*)mr->smr_oid, mr->smr_oidlen);
|
||||||
HASH_Update(HASHcontext, value, value_len);
|
|
||||||
HASH_Final(HASHdigest, HASHcontext);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
hashIter(
|
||||||
|
HASH_CONTEXT *HASHcontext,
|
||||||
|
unsigned char *HASHdigest,
|
||||||
|
unsigned char *value,
|
||||||
|
int len)
|
||||||
|
{
|
||||||
|
HASH_CONTEXT ctx = *HASHcontext;
|
||||||
|
HASH_Update( &ctx, value, len );
|
||||||
|
HASH_Final( HASHdigest, &ctx );
|
||||||
|
}
|
||||||
|
|
||||||
/* Index generation function */
|
/* Index generation function */
|
||||||
int octetStringIndexer(
|
int octetStringIndexer(
|
||||||
slap_mask_t use,
|
slap_mask_t use,
|
||||||
@ -225,9 +232,10 @@ int octetStringIndexer(
|
|||||||
slen = syntax->ssyn_oidlen;
|
slen = syntax->ssyn_oidlen;
|
||||||
mlen = mr->smr_oidlen;
|
mlen = mr->smr_oidlen;
|
||||||
|
|
||||||
|
hashPreset( &HASHcontext, prefix, 0, syntax, mr);
|
||||||
for( i=0; !BER_BVISNULL( &values[i] ); i++ ) {
|
for( i=0; !BER_BVISNULL( &values[i] ); i++ ) {
|
||||||
hashDigestify( &HASHcontext, HASHdigest, prefix, 0,
|
hashIter( &HASHcontext, HASHdigest,
|
||||||
syntax, mr, (unsigned char *)values[i].bv_val, values[i].bv_len );
|
(unsigned char *)values[i].bv_val, values[i].bv_len );
|
||||||
ber_dupbv_x( &keys[i], &digest, ctx );
|
ber_dupbv_x( &keys[i], &digest, ctx );
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -263,8 +271,9 @@ int octetStringFilter(
|
|||||||
|
|
||||||
keys = slap_sl_malloc( sizeof( struct berval ) * 2, ctx );
|
keys = slap_sl_malloc( sizeof( struct berval ) * 2, ctx );
|
||||||
|
|
||||||
hashDigestify( &HASHcontext, HASHdigest, prefix, 0,
|
hashPreset( &HASHcontext, prefix, 0, syntax, mr );
|
||||||
syntax, mr, (unsigned char *)value->bv_val, value->bv_len );
|
hashIter( &HASHcontext, HASHdigest,
|
||||||
|
(unsigned char *)value->bv_val, value->bv_len );
|
||||||
|
|
||||||
ber_dupbv_x( keys, &digest, ctx );
|
ber_dupbv_x( keys, &digest, ctx );
|
||||||
BER_BVZERO( &keys[1] );
|
BER_BVZERO( &keys[1] );
|
||||||
@ -414,7 +423,7 @@ octetStringSubstringsIndexer(
|
|||||||
size_t slen, mlen;
|
size_t slen, mlen;
|
||||||
BerVarray keys;
|
BerVarray keys;
|
||||||
|
|
||||||
HASH_CONTEXT HASHcontext;
|
HASH_CONTEXT HCany, HCini, HCfin;
|
||||||
unsigned char HASHdigest[HASH_BYTES];
|
unsigned char HASHdigest[HASH_BYTES];
|
||||||
struct berval digest;
|
struct berval digest;
|
||||||
digest.bv_val = (char *)HASHdigest;
|
digest.bv_val = (char *)HASHdigest;
|
||||||
@ -460,6 +469,13 @@ octetStringSubstringsIndexer(
|
|||||||
slen = syntax->ssyn_oidlen;
|
slen = syntax->ssyn_oidlen;
|
||||||
mlen = mr->smr_oidlen;
|
mlen = mr->smr_oidlen;
|
||||||
|
|
||||||
|
if ( flags & SLAP_INDEX_SUBSTR_ANY )
|
||||||
|
hashPreset( &HCany, prefix, SLAP_INDEX_SUBSTR_PREFIX, syntax, mr );
|
||||||
|
if( flags & SLAP_INDEX_SUBSTR_INITIAL )
|
||||||
|
hashPreset( &HCini, prefix, SLAP_INDEX_SUBSTR_INITIAL_PREFIX, syntax, mr );
|
||||||
|
if( flags & SLAP_INDEX_SUBSTR_FINAL )
|
||||||
|
hashPreset( &HCfin, prefix, SLAP_INDEX_SUBSTR_FINAL_PREFIX, syntax, mr );
|
||||||
|
|
||||||
nkeys = 0;
|
nkeys = 0;
|
||||||
for ( i = 0; !BER_BVISNULL( &values[i] ); i++ ) {
|
for ( i = 0; !BER_BVISNULL( &values[i] ); i++ ) {
|
||||||
ber_len_t j,max;
|
ber_len_t j,max;
|
||||||
@ -467,12 +483,12 @@ octetStringSubstringsIndexer(
|
|||||||
if( ( flags & SLAP_INDEX_SUBSTR_ANY ) &&
|
if( ( flags & SLAP_INDEX_SUBSTR_ANY ) &&
|
||||||
( values[i].bv_len >= index_substr_any_len ) )
|
( values[i].bv_len >= index_substr_any_len ) )
|
||||||
{
|
{
|
||||||
char pre = SLAP_INDEX_SUBSTR_PREFIX;
|
|
||||||
max = values[i].bv_len - (index_substr_any_len - 1);
|
max = values[i].bv_len - (index_substr_any_len - 1);
|
||||||
|
|
||||||
for( j=0; j<max; j++ ) {
|
for( j=0; j<max; j++ ) {
|
||||||
hashDigestify( &HASHcontext, HASHdigest, prefix, pre,
|
hashIter( &HCany, HASHdigest,
|
||||||
syntax, mr, (unsigned char *)&values[i].bv_val[j], index_substr_any_len);
|
(unsigned char *)&values[i].bv_val[j],
|
||||||
|
index_substr_any_len );
|
||||||
ber_dupbv_x( &keys[nkeys++], &digest, ctx );
|
ber_dupbv_x( &keys[nkeys++], &digest, ctx );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -484,19 +500,16 @@ octetStringSubstringsIndexer(
|
|||||||
? index_substr_if_maxlen : values[i].bv_len;
|
? index_substr_if_maxlen : values[i].bv_len;
|
||||||
|
|
||||||
for( j=index_substr_if_minlen; j<=max; j++ ) {
|
for( j=index_substr_if_minlen; j<=max; j++ ) {
|
||||||
char pre;
|
|
||||||
|
|
||||||
if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
|
if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
|
||||||
pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
|
hashIter( &HCini, HASHdigest,
|
||||||
hashDigestify( &HASHcontext, HASHdigest, prefix, pre,
|
(unsigned char *)values[i].bv_val, j );
|
||||||
syntax, mr, (unsigned char *)values[i].bv_val, j );
|
|
||||||
ber_dupbv_x( &keys[nkeys++], &digest, ctx );
|
ber_dupbv_x( &keys[nkeys++], &digest, ctx );
|
||||||
}
|
}
|
||||||
|
|
||||||
if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
|
if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
|
||||||
pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
|
hashIter( &HCfin, HASHdigest,
|
||||||
hashDigestify( &HASHcontext, HASHdigest, prefix, pre,
|
(unsigned char *)&values[i].bv_val[values[i].bv_len-j], j );
|
||||||
syntax, mr, (unsigned char *)&values[i].bv_val[values[i].bv_len-j], j );
|
|
||||||
ber_dupbv_x( &keys[nkeys++], &digest, ctx );
|
ber_dupbv_x( &keys[nkeys++], &digest, ctx );
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -596,8 +609,9 @@ octetStringSubstringsFilter (
|
|||||||
klen = index_substr_if_maxlen < value->bv_len
|
klen = index_substr_if_maxlen < value->bv_len
|
||||||
? index_substr_if_maxlen : value->bv_len;
|
? index_substr_if_maxlen : value->bv_len;
|
||||||
|
|
||||||
hashDigestify( &HASHcontext, HASHdigest, prefix, pre,
|
hashPreset( &HASHcontext, prefix, pre, syntax, mr );
|
||||||
syntax, mr, (unsigned char *)value->bv_val, klen );
|
hashIter( &HASHcontext, HASHdigest,
|
||||||
|
(unsigned char *)value->bv_val, klen );
|
||||||
ber_dupbv_x( &keys[nkeys++], &digest, ctx );
|
ber_dupbv_x( &keys[nkeys++], &digest, ctx );
|
||||||
|
|
||||||
/* If initial is too long and we have subany indexed, use it
|
/* If initial is too long and we have subany indexed, use it
|
||||||
@ -607,10 +621,11 @@ octetStringSubstringsFilter (
|
|||||||
{
|
{
|
||||||
ber_len_t j;
|
ber_len_t j;
|
||||||
pre = SLAP_INDEX_SUBSTR_PREFIX;
|
pre = SLAP_INDEX_SUBSTR_PREFIX;
|
||||||
|
hashPreset( &HASHcontext, prefix, pre, syntax, mr);
|
||||||
for ( j=index_substr_if_maxlen-1; j <= value->bv_len - index_substr_any_len; j+=index_substr_any_step )
|
for ( j=index_substr_if_maxlen-1; j <= value->bv_len - index_substr_any_len; j+=index_substr_any_step )
|
||||||
{
|
{
|
||||||
hashDigestify( &HASHcontext, HASHdigest, prefix, pre,
|
hashIter( &HASHcontext, HASHdigest,
|
||||||
syntax, mr, (unsigned char *)&value->bv_val[j], index_substr_any_len );
|
(unsigned char *)&value->bv_val[j], index_substr_any_len );
|
||||||
ber_dupbv_x( &keys[nkeys++], &digest, ctx );
|
ber_dupbv_x( &keys[nkeys++], &digest, ctx );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -628,12 +643,13 @@ octetStringSubstringsFilter (
|
|||||||
|
|
||||||
value = &sa->sa_any[i];
|
value = &sa->sa_any[i];
|
||||||
|
|
||||||
|
hashPreset( &HASHcontext, prefix, pre, syntax, mr);
|
||||||
for(j=0;
|
for(j=0;
|
||||||
j <= value->bv_len - index_substr_any_len;
|
j <= value->bv_len - index_substr_any_len;
|
||||||
j += index_substr_any_step )
|
j += index_substr_any_step )
|
||||||
{
|
{
|
||||||
hashDigestify( &HASHcontext, HASHdigest, prefix, pre,
|
hashIter( &HASHcontext, HASHdigest,
|
||||||
syntax, mr, (unsigned char *)&value->bv_val[j], klen );
|
(unsigned char *)&value->bv_val[j], klen );
|
||||||
ber_dupbv_x( &keys[nkeys++], &digest, ctx );
|
ber_dupbv_x( &keys[nkeys++], &digest, ctx );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -649,8 +665,9 @@ octetStringSubstringsFilter (
|
|||||||
klen = index_substr_if_maxlen < value->bv_len
|
klen = index_substr_if_maxlen < value->bv_len
|
||||||
? index_substr_if_maxlen : value->bv_len;
|
? index_substr_if_maxlen : value->bv_len;
|
||||||
|
|
||||||
hashDigestify( &HASHcontext, HASHdigest, prefix, pre,
|
hashPreset( &HASHcontext, prefix, pre, syntax, mr );
|
||||||
syntax, mr, (unsigned char *)&value->bv_val[value->bv_len-klen], klen );
|
hashIter( &HASHcontext, HASHdigest,
|
||||||
|
(unsigned char *)&value->bv_val[value->bv_len-klen], klen );
|
||||||
ber_dupbv_x( &keys[nkeys++], &digest, ctx );
|
ber_dupbv_x( &keys[nkeys++], &digest, ctx );
|
||||||
|
|
||||||
/* If final is too long and we have subany indexed, use it
|
/* If final is too long and we have subany indexed, use it
|
||||||
@ -660,10 +677,11 @@ octetStringSubstringsFilter (
|
|||||||
{
|
{
|
||||||
ber_len_t j;
|
ber_len_t j;
|
||||||
pre = SLAP_INDEX_SUBSTR_PREFIX;
|
pre = SLAP_INDEX_SUBSTR_PREFIX;
|
||||||
|
hashPreset( &HASHcontext, prefix, pre, syntax, mr);
|
||||||
for ( j=0; j <= value->bv_len - index_substr_if_maxlen; j+=index_substr_any_step )
|
for ( j=0; j <= value->bv_len - index_substr_if_maxlen; j+=index_substr_any_step )
|
||||||
{
|
{
|
||||||
hashDigestify( &HASHcontext, HASHdigest, prefix, pre,
|
hashIter( &HASHcontext, HASHdigest,
|
||||||
syntax, mr, (unsigned char *)&value->bv_val[j], index_substr_any_len );
|
(unsigned char *)&value->bv_val[j], index_substr_any_len );
|
||||||
ber_dupbv_x( &keys[nkeys++], &digest, ctx );
|
ber_dupbv_x( &keys[nkeys++], &digest, ctx );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user