1 /* filterindex.c - generate the list of candidate entries from a filter */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 2000-2007 The OpenLDAP Foundation.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted only as authorized by the OpenLDAP
12 * A copy of this license is available in the file LICENSE in the
13 * top-level directory of the distribution or, alternatively, at
14 * <http://www.OpenLDAP.org/license.html>.
20 #include <ac/string.h>
24 #ifdef LDAP_COMP_MATCH
25 #include <component.h>
28 static int presence_candidates(
31 AttributeDescription *desc,
34 static int equality_candidates(
37 AttributeAssertion *ava,
40 static int inequality_candidates(
43 AttributeAssertion *ava,
47 static int approx_candidates(
50 AttributeAssertion *ava,
53 static int substring_candidates(
56 SubstringsAssertion *sub,
60 static int list_candidates(
73 MatchingRuleAssertion *mra,
78 #ifdef LDAP_COMP_MATCH
83 MatchingRuleAssertion *mra,
93 AttributeAssertion *ava,
94 AttributeAliasing *aa,
101 bdb_filter_candidates(
110 #ifdef LDAP_COMP_MATCH
111 AttributeAliasing *aa;
113 Debug( LDAP_DEBUG_FILTER, "=> bdb_filter_candidates\n", 0, 0, 0 );
115 if ( f->f_choice & SLAPD_FILTER_UNDEFINED ) {
120 switch ( f->f_choice ) {
121 case SLAPD_FILTER_COMPUTED:
122 switch( f->f_result ) {
123 case SLAPD_COMPARE_UNDEFINED:
124 /* This technically is not the same as FALSE, but it
125 * certainly will produce no matches.
128 case LDAP_COMPARE_FALSE:
131 case LDAP_COMPARE_TRUE: {
132 struct bdb_info *bdb = (struct bdb_info *)op->o_bd->be_private;
133 BDB_IDL_ALL( bdb, ids );
136 /* this is a pre-computed scope, leave it alone */
140 case LDAP_FILTER_PRESENT:
141 Debug( LDAP_DEBUG_FILTER, "\tPRESENT\n", 0, 0, 0 );
142 rc = presence_candidates( op, locker, f->f_desc, ids );
145 case LDAP_FILTER_EQUALITY:
146 Debug( LDAP_DEBUG_FILTER, "\tEQUALITY\n", 0, 0, 0 );
147 #ifdef LDAP_COMP_MATCH
148 if ( is_aliased_attribute && ( aa = is_aliased_attribute ( f->f_ava->aa_desc ) ) ) {
149 rc = ava_comp_candidates ( op, locker, f->f_ava, aa, ids, tmp, stack );
154 rc = equality_candidates( op, locker, f->f_ava, ids, tmp );
158 case LDAP_FILTER_APPROX:
159 Debug( LDAP_DEBUG_FILTER, "\tAPPROX\n", 0, 0, 0 );
160 rc = approx_candidates( op, locker, f->f_ava, ids, tmp );
163 case LDAP_FILTER_SUBSTRINGS:
164 Debug( LDAP_DEBUG_FILTER, "\tSUBSTRINGS\n", 0, 0, 0 );
165 rc = substring_candidates( op, locker, f->f_sub, ids, tmp );
169 /* if no GE index, use pres */
170 Debug( LDAP_DEBUG_FILTER, "\tGE\n", 0, 0, 0 );
171 if( f->f_ava->aa_desc->ad_type->sat_ordering &&
172 ( f->f_ava->aa_desc->ad_type->sat_ordering->smr_usage & SLAP_MR_ORDERED_INDEX ) )
173 rc = inequality_candidates( op, locker, f->f_ava, ids, tmp, LDAP_FILTER_GE );
175 rc = presence_candidates( op, locker, f->f_ava->aa_desc, ids );
179 /* if no LE index, use pres */
180 Debug( LDAP_DEBUG_FILTER, "\tLE\n", 0, 0, 0 );
181 if( f->f_ava->aa_desc->ad_type->sat_ordering &&
182 ( f->f_ava->aa_desc->ad_type->sat_ordering->smr_usage & SLAP_MR_ORDERED_INDEX ) )
183 rc = inequality_candidates( op, locker, f->f_ava, ids, tmp, LDAP_FILTER_LE );
185 rc = presence_candidates( op, locker, f->f_ava->aa_desc, ids );
188 case LDAP_FILTER_NOT:
189 /* no indexing to support NOT filters */
190 Debug( LDAP_DEBUG_FILTER, "\tNOT\n", 0, 0, 0 );
191 { struct bdb_info *bdb = (struct bdb_info *) op->o_bd->be_private;
192 BDB_IDL_ALL( bdb, ids );
196 case LDAP_FILTER_AND:
197 Debug( LDAP_DEBUG_FILTER, "\tAND\n", 0, 0, 0 );
198 rc = list_candidates( op, locker,
199 f->f_and, LDAP_FILTER_AND, ids, tmp, stack );
203 Debug( LDAP_DEBUG_FILTER, "\tOR\n", 0, 0, 0 );
204 rc = list_candidates( op, locker,
205 f->f_or, LDAP_FILTER_OR, ids, tmp, stack );
207 case LDAP_FILTER_EXT:
208 Debug( LDAP_DEBUG_FILTER, "\tEXT\n", 0, 0, 0 );
209 rc = ext_candidates( op, locker, f->f_mra, ids, tmp, stack );
212 Debug( LDAP_DEBUG_FILTER, "\tUNKNOWN %lu\n",
213 (unsigned long) f->f_choice, 0, 0 );
214 /* Must not return NULL, otherwise extended filters break */
215 { struct bdb_info *bdb = (struct bdb_info *) op->o_bd->be_private;
216 BDB_IDL_ALL( bdb, ids );
221 Debug( LDAP_DEBUG_FILTER,
222 "<= bdb_filter_candidates: id=%ld first=%ld last=%ld\n",
224 (long) BDB_IDL_FIRST( ids ),
225 (long) BDB_IDL_LAST( ids ) );
230 #ifdef LDAP_COMP_MATCH
232 comp_list_candidates(
235 MatchingRuleAssertion* mra,
236 ComponentFilter *flist,
245 Debug( LDAP_DEBUG_FILTER, "=> comp_list_candidates 0x%x\n", ftype, 0, 0 );
246 for ( f = flist; f != NULL; f = f->cf_next ) {
247 /* ignore precomputed scopes */
248 if ( f->cf_choice == SLAPD_FILTER_COMPUTED &&
249 f->cf_result == LDAP_SUCCESS ) {
252 BDB_IDL_ZERO( save );
253 rc = comp_candidates( op, locker, mra, f, save, tmp, save+BDB_IDL_UM_SIZE );
256 if ( ftype == LDAP_COMP_FILTER_AND ) {
263 if ( ftype == LDAP_COMP_FILTER_AND ) {
265 BDB_IDL_CPY( ids, save );
267 bdb_idl_intersection( ids, save );
269 if( BDB_IDL_IS_ZERO( ids ) )
273 BDB_IDL_CPY( ids, save );
275 bdb_idl_union( ids, save );
280 if( rc == LDAP_SUCCESS ) {
281 Debug( LDAP_DEBUG_FILTER,
282 "<= comp_list_candidates: id=%ld first=%ld last=%ld\n",
284 (long) BDB_IDL_FIRST(ids),
285 (long) BDB_IDL_LAST(ids) );
288 Debug( LDAP_DEBUG_FILTER,
289 "<= comp_list_candidates: undefined rc=%d\n",
297 comp_equality_candidates (
300 MatchingRuleAssertion *mra,
301 ComponentAssertion *ca,
306 struct bdb_info *bdb = (struct bdb_info *) op->o_bd->be_private;
311 struct berval prefix = {0, NULL};
312 struct berval *keys = NULL;
313 MatchingRule *mr = mra->ma_rule;
315 ComponentReference* cr_list, *cr;
318 BDB_IDL_ALL( bdb, ids );
320 if ( !ca->ca_comp_ref )
323 ai = bdb_attr_mask( op->o_bd->be_private, mra->ma_desc );
330 /* find a component reference to be indexed */
331 sat_syntax = ca->ca_ma_rule->smr_syntax;
332 for ( cr = cr_list ; cr ; cr = cr->cr_next ) {
333 if ( cr->cr_string.bv_len == ca->ca_comp_ref->cr_string.bv_len &&
334 strncmp( cr->cr_string.bv_val, ca->ca_comp_ref->cr_string.bv_val,cr->cr_string.bv_len ) == 0 )
341 rc = bdb_index_param( op->o_bd, mra->ma_desc, LDAP_FILTER_EQUALITY,
342 &db, &mask, &prefix );
344 if( rc != LDAP_SUCCESS ) {
355 if( !mr->smr_filter ) {
359 rc = (ca->ca_ma_rule->smr_filter)(
360 LDAP_FILTER_EQUALITY,
366 &keys, op->o_tmpmemctx );
368 if( rc != LDAP_SUCCESS ) {
375 for ( i= 0; keys[i].bv_val != NULL; i++ ) {
376 rc = bdb_key_read( op->o_bd, db, locker, &keys[i], tmp, NULL, 0 );
378 if( rc == DB_NOTFOUND ) {
382 } else if( rc != LDAP_SUCCESS ) {
386 if( BDB_IDL_IS_ZERO( tmp ) ) {
392 BDB_IDL_CPY( ids, tmp );
394 bdb_idl_intersection( ids, tmp );
397 if( BDB_IDL_IS_ZERO( ids ) )
400 ber_bvarray_free_x( keys, op->o_tmpmemctx );
402 Debug( LDAP_DEBUG_TRACE,
403 "<= comp_equality_candidates: id=%ld, first=%ld, last=%ld\n",
405 (long) BDB_IDL_FIRST(ids),
406 (long) BDB_IDL_LAST(ids) );
411 ava_comp_candidates (
414 AttributeAssertion *ava,
415 AttributeAliasing *aa,
420 MatchingRuleAssertion mra;
422 mra.ma_rule = ava->aa_desc->ad_type->sat_equality;
423 if ( !mra.ma_rule ) {
424 struct bdb_info *bdb = (struct bdb_info *) op->o_bd->be_private;
425 BDB_IDL_ALL( bdb, ids );
428 mra.ma_desc = aa->aa_aliased_ad;
429 mra.ma_rule = ava->aa_desc->ad_type->sat_equality;
431 return comp_candidates ( op, locker, &mra, ava->aa_cf, ids, tmp, stack );
438 MatchingRuleAssertion *mra,
446 if ( !f ) return LDAP_PROTOCOL_ERROR;
448 Debug( LDAP_DEBUG_FILTER, "comp_candidates\n", 0, 0, 0 );
449 switch ( f->cf_choice ) {
450 case SLAPD_FILTER_COMPUTED:
453 case LDAP_COMP_FILTER_AND:
454 rc = comp_list_candidates( op, locker, mra, f->cf_and, LDAP_COMP_FILTER_AND, ids, tmp, stack );
456 case LDAP_COMP_FILTER_OR:
457 rc = comp_list_candidates( op, locker, mra, f->cf_or, LDAP_COMP_FILTER_OR, ids, tmp, stack );
459 case LDAP_COMP_FILTER_NOT:
460 /* No component indexing supported for NOT filter */
461 Debug( LDAP_DEBUG_FILTER, "\tComponent NOT\n", 0, 0, 0 );
463 struct bdb_info *bdb = (struct bdb_info *) op->o_bd->be_private;
464 BDB_IDL_ALL( bdb, ids );
466 rc = LDAP_PROTOCOL_ERROR;
468 case LDAP_COMP_FILTER_ITEM:
469 rc = comp_equality_candidates( op, locker, mra, f->cf_ca, ids, tmp, stack );
473 struct bdb_info *bdb = (struct bdb_info *) op->o_bd->be_private;
474 BDB_IDL_ALL( bdb, ids );
476 rc = LDAP_PROTOCOL_ERROR;
487 MatchingRuleAssertion *mra,
492 struct bdb_info *bdb = (struct bdb_info *) op->o_bd->be_private;
494 #ifdef LDAP_COMP_MATCH
496 * Currently Only Component Indexing for componentFilterMatch is supported
497 * Indexing for an extensible filter is not supported yet
500 return comp_candidates ( op, locker, mra, mra->ma_cf, ids, tmp, stack);
503 if ( mra->ma_desc == slap_schema.si_ad_entryDN ) {
508 if ( mra->ma_rule == slap_schema.si_mr_distinguishedNameMatch ) {
510 rc = bdb_cache_find_ndn( op, NULL, &mra->ma_value, &ei );
511 if ( rc == LDAP_SUCCESS )
512 bdb_idl_insert( ids, ei->bei_id );
514 bdb_cache_entryinfo_unlock( ei );
516 } else if ( mra->ma_rule && mra->ma_rule->smr_match ==
517 dnRelativeMatch && dnIsSuffix( &mra->ma_value,
518 op->o_bd->be_nsuffix )) {
520 if ( mra->ma_rule == slap_schema.si_mr_dnSuperiorMatch ) {
523 dnParent( &mra->ma_value, &pdn );
524 bdb_cache_find_ndn( op, NULL, &pdn, &ei );
526 bdb_cache_entryinfo_unlock( ei );
527 while ( ei && ei->bei_id ) {
528 bdb_idl_insert( ids, ei->bei_id );
534 if ( mra->ma_rule == slap_schema.si_mr_dnSubtreeMatch )
535 scope = LDAP_SCOPE_SUBTREE;
536 else if ( mra->ma_rule == slap_schema.si_mr_dnOneLevelMatch )
537 scope = LDAP_SCOPE_ONELEVEL;
538 else if ( mra->ma_rule == slap_schema.si_mr_dnSubordinateMatch )
539 scope = LDAP_SCOPE_SUBORDINATE;
541 scope = LDAP_SCOPE_BASE;
542 if ( scope > LDAP_SCOPE_BASE ) {
544 rc = bdb_cache_find_ndn( op, NULL, &mra->ma_value, &ei );
546 bdb_cache_entryinfo_unlock( ei );
547 if ( rc == LDAP_SUCCESS ) {
548 int sc = op->ors_scope;
549 op->ors_scope = scope;
550 rc = bdb_dn2idl( op, locker, &mra->ma_value, ei, ids,
558 BDB_IDL_ALL( bdb, ids );
575 Debug( LDAP_DEBUG_FILTER, "=> bdb_list_candidates 0x%x\n", ftype, 0, 0 );
576 for ( f = flist; f != NULL; f = f->f_next ) {
577 /* ignore precomputed scopes */
578 if ( f->f_choice == SLAPD_FILTER_COMPUTED &&
579 f->f_result == LDAP_SUCCESS ) {
582 BDB_IDL_ZERO( save );
583 rc = bdb_filter_candidates( op, locker, f, save, tmp,
584 save+BDB_IDL_UM_SIZE );
587 if ( ftype == LDAP_FILTER_AND ) {
595 if ( ftype == LDAP_FILTER_AND ) {
597 BDB_IDL_CPY( ids, save );
599 bdb_idl_intersection( ids, save );
601 if( BDB_IDL_IS_ZERO( ids ) )
605 BDB_IDL_CPY( ids, save );
607 bdb_idl_union( ids, save );
612 if( rc == LDAP_SUCCESS ) {
613 Debug( LDAP_DEBUG_FILTER,
614 "<= bdb_list_candidates: id=%ld first=%ld last=%ld\n",
616 (long) BDB_IDL_FIRST(ids),
617 (long) BDB_IDL_LAST(ids) );
620 Debug( LDAP_DEBUG_FILTER,
621 "<= bdb_list_candidates: undefined rc=%d\n",
632 AttributeDescription *desc,
635 struct bdb_info *bdb = (struct bdb_info *) op->o_bd->be_private;
639 struct berval prefix = {0, NULL};
641 Debug( LDAP_DEBUG_TRACE, "=> bdb_presence_candidates (%s)\n",
642 desc->ad_cname.bv_val, 0, 0 );
644 BDB_IDL_ALL( bdb, ids );
646 if( desc == slap_schema.si_ad_objectClass ) {
650 rc = bdb_index_param( op->o_bd, desc, LDAP_FILTER_PRESENT,
651 &db, &mask, &prefix );
653 if( rc != LDAP_SUCCESS ) {
654 Debug( LDAP_DEBUG_TRACE,
655 "<= bdb_presence_candidates: (%s) index_param "
657 desc->ad_cname.bv_val, rc, 0 );
663 Debug( LDAP_DEBUG_TRACE,
664 "<= bdb_presence_candidates: (%s) not indexed\n",
665 desc->ad_cname.bv_val, 0, 0 );
669 if( prefix.bv_val == NULL ) {
670 Debug( LDAP_DEBUG_TRACE,
671 "<= bdb_presence_candidates: (%s) no prefix\n",
672 desc->ad_cname.bv_val, 0, 0 );
676 rc = bdb_key_read( op->o_bd, db, locker, &prefix, ids, NULL, 0 );
678 if( rc == DB_NOTFOUND ) {
681 } else if( rc != LDAP_SUCCESS ) {
682 Debug( LDAP_DEBUG_TRACE,
683 "<= bdb_presense_candidates: (%s) "
684 "key read failed (%d)\n",
685 desc->ad_cname.bv_val, rc, 0 );
689 Debug(LDAP_DEBUG_TRACE,
690 "<= bdb_presence_candidates: id=%ld first=%ld last=%ld\n",
692 (long) BDB_IDL_FIRST(ids),
693 (long) BDB_IDL_LAST(ids) );
703 AttributeAssertion *ava,
707 struct bdb_info *bdb = (struct bdb_info *) op->o_bd->be_private;
712 struct berval prefix = {0, NULL};
713 struct berval *keys = NULL;
716 Debug( LDAP_DEBUG_TRACE, "=> bdb_equality_candidates (%s)\n",
717 ava->aa_desc->ad_cname.bv_val, 0, 0 );
719 BDB_IDL_ALL( bdb, ids );
721 rc = bdb_index_param( op->o_bd, ava->aa_desc, LDAP_FILTER_EQUALITY,
722 &db, &mask, &prefix );
724 if( rc != LDAP_SUCCESS ) {
725 Debug( LDAP_DEBUG_ANY,
726 "<= bdb_equality_candidates: (%s) "
727 "index_param failed (%d)\n",
728 ava->aa_desc->ad_cname.bv_val, rc, 0 );
733 Debug( LDAP_DEBUG_ANY,
734 "<= bdb_equality_candidates: (%s) not indexed\n",
735 ava->aa_desc->ad_cname.bv_val, 0, 0 );
739 mr = ava->aa_desc->ad_type->sat_equality;
744 if( !mr->smr_filter ) {
748 rc = (mr->smr_filter)(
749 LDAP_FILTER_EQUALITY,
751 ava->aa_desc->ad_type->sat_syntax,
755 &keys, op->o_tmpmemctx );
757 if( rc != LDAP_SUCCESS ) {
758 Debug( LDAP_DEBUG_TRACE,
759 "<= bdb_equality_candidates: (%s, %s) "
760 "MR filter failed (%d)\n",
761 prefix.bv_val, ava->aa_desc->ad_cname.bv_val, rc );
766 Debug( LDAP_DEBUG_TRACE,
767 "<= bdb_equality_candidates: (%s) no keys\n",
768 ava->aa_desc->ad_cname.bv_val, 0, 0 );
772 for ( i= 0; keys[i].bv_val != NULL; i++ ) {
773 rc = bdb_key_read( op->o_bd, db, locker, &keys[i], tmp, NULL, 0 );
775 if( rc == DB_NOTFOUND ) {
779 } else if( rc != LDAP_SUCCESS ) {
780 Debug( LDAP_DEBUG_TRACE,
781 "<= bdb_equality_candidates: (%s) "
782 "key read failed (%d)\n",
783 ava->aa_desc->ad_cname.bv_val, rc, 0 );
787 if( BDB_IDL_IS_ZERO( tmp ) ) {
788 Debug( LDAP_DEBUG_TRACE,
789 "<= bdb_equality_candidates: (%s) NULL\n",
790 ava->aa_desc->ad_cname.bv_val, 0, 0 );
796 BDB_IDL_CPY( ids, tmp );
798 bdb_idl_intersection( ids, tmp );
801 if( BDB_IDL_IS_ZERO( ids ) )
805 ber_bvarray_free_x( keys, op->o_tmpmemctx );
807 Debug( LDAP_DEBUG_TRACE,
808 "<= bdb_equality_candidates: id=%ld, first=%ld, last=%ld\n",
810 (long) BDB_IDL_FIRST(ids),
811 (long) BDB_IDL_LAST(ids) );
820 AttributeAssertion *ava,
824 struct bdb_info *bdb = (struct bdb_info *) op->o_bd->be_private;
829 struct berval prefix = {0, NULL};
830 struct berval *keys = NULL;
833 Debug( LDAP_DEBUG_TRACE, "=> bdb_approx_candidates (%s)\n",
834 ava->aa_desc->ad_cname.bv_val, 0, 0 );
836 BDB_IDL_ALL( bdb, ids );
838 rc = bdb_index_param( op->o_bd, ava->aa_desc, LDAP_FILTER_APPROX,
839 &db, &mask, &prefix );
841 if( rc != LDAP_SUCCESS ) {
842 Debug( LDAP_DEBUG_ANY,
843 "<= bdb_approx_candidates: (%s) "
844 "index_param failed (%d)\n",
845 ava->aa_desc->ad_cname.bv_val, rc, 0 );
850 Debug( LDAP_DEBUG_ANY,
851 "<= bdb_approx_candidates: (%s) not indexed\n",
852 ava->aa_desc->ad_cname.bv_val, 0, 0 );
856 mr = ava->aa_desc->ad_type->sat_approx;
858 /* no approx matching rule, try equality matching rule */
859 mr = ava->aa_desc->ad_type->sat_equality;
866 if( !mr->smr_filter ) {
870 rc = (mr->smr_filter)(
873 ava->aa_desc->ad_type->sat_syntax,
877 &keys, op->o_tmpmemctx );
879 if( rc != LDAP_SUCCESS ) {
880 Debug( LDAP_DEBUG_TRACE,
881 "<= bdb_approx_candidates: (%s, %s) "
882 "MR filter failed (%d)\n",
883 prefix.bv_val, ava->aa_desc->ad_cname.bv_val, rc );
888 Debug( LDAP_DEBUG_TRACE,
889 "<= bdb_approx_candidates: (%s) no keys (%s)\n",
890 prefix.bv_val, ava->aa_desc->ad_cname.bv_val, 0 );
894 for ( i= 0; keys[i].bv_val != NULL; i++ ) {
895 rc = bdb_key_read( op->o_bd, db, locker, &keys[i], tmp, NULL, 0 );
897 if( rc == DB_NOTFOUND ) {
901 } else if( rc != LDAP_SUCCESS ) {
902 Debug( LDAP_DEBUG_TRACE,
903 "<= bdb_approx_candidates: (%s) "
904 "key read failed (%d)\n",
905 ava->aa_desc->ad_cname.bv_val, rc, 0 );
909 if( BDB_IDL_IS_ZERO( tmp ) ) {
910 Debug( LDAP_DEBUG_TRACE,
911 "<= bdb_approx_candidates: (%s) NULL\n",
912 ava->aa_desc->ad_cname.bv_val, 0, 0 );
918 BDB_IDL_CPY( ids, tmp );
920 bdb_idl_intersection( ids, tmp );
923 if( BDB_IDL_IS_ZERO( ids ) )
927 ber_bvarray_free_x( keys, op->o_tmpmemctx );
929 Debug( LDAP_DEBUG_TRACE, "<= bdb_approx_candidates %ld, first=%ld, last=%ld\n",
931 (long) BDB_IDL_FIRST(ids),
932 (long) BDB_IDL_LAST(ids) );
937 substring_candidates(
940 SubstringsAssertion *sub,
944 struct bdb_info *bdb = (struct bdb_info *) op->o_bd->be_private;
949 struct berval prefix = {0, NULL};
950 struct berval *keys = NULL;
953 Debug( LDAP_DEBUG_TRACE, "=> bdb_substring_candidates (%s)\n",
954 sub->sa_desc->ad_cname.bv_val, 0, 0 );
956 BDB_IDL_ALL( bdb, ids );
958 rc = bdb_index_param( op->o_bd, sub->sa_desc, LDAP_FILTER_SUBSTRINGS,
959 &db, &mask, &prefix );
961 if( rc != LDAP_SUCCESS ) {
962 Debug( LDAP_DEBUG_ANY,
963 "<= bdb_substring_candidates: (%s) "
964 "index_param failed (%d)\n",
965 sub->sa_desc->ad_cname.bv_val, rc, 0 );
970 Debug( LDAP_DEBUG_ANY,
971 "<= bdb_substring_candidates: (%s) not indexed\n",
972 sub->sa_desc->ad_cname.bv_val, 0, 0 );
976 mr = sub->sa_desc->ad_type->sat_substr;
982 if( !mr->smr_filter ) {
986 rc = (mr->smr_filter)(
987 LDAP_FILTER_SUBSTRINGS,
989 sub->sa_desc->ad_type->sat_syntax,
993 &keys, op->o_tmpmemctx );
995 if( rc != LDAP_SUCCESS ) {
996 Debug( LDAP_DEBUG_TRACE,
997 "<= bdb_substring_candidates: (%s) "
998 "MR filter failed (%d)\n",
999 sub->sa_desc->ad_cname.bv_val, rc, 0 );
1003 if( keys == NULL ) {
1004 Debug( LDAP_DEBUG_TRACE,
1005 "<= bdb_substring_candidates: (0x%04lx) no keys (%s)\n",
1006 mask, sub->sa_desc->ad_cname.bv_val, 0 );
1010 for ( i= 0; keys[i].bv_val != NULL; i++ ) {
1011 rc = bdb_key_read( op->o_bd, db, locker, &keys[i], tmp, NULL, 0 );
1013 if( rc == DB_NOTFOUND ) {
1014 BDB_IDL_ZERO( ids );
1017 } else if( rc != LDAP_SUCCESS ) {
1018 Debug( LDAP_DEBUG_TRACE,
1019 "<= bdb_substring_candidates: (%s) "
1020 "key read failed (%d)\n",
1021 sub->sa_desc->ad_cname.bv_val, rc, 0 );
1025 if( BDB_IDL_IS_ZERO( tmp ) ) {
1026 Debug( LDAP_DEBUG_TRACE,
1027 "<= bdb_substring_candidates: (%s) NULL\n",
1028 sub->sa_desc->ad_cname.bv_val, 0, 0 );
1029 BDB_IDL_ZERO( ids );
1034 BDB_IDL_CPY( ids, tmp );
1036 bdb_idl_intersection( ids, tmp );
1039 if( BDB_IDL_IS_ZERO( ids ) )
1043 ber_bvarray_free_x( keys, op->o_tmpmemctx );
1045 Debug( LDAP_DEBUG_TRACE, "<= bdb_substring_candidates: %ld, first=%ld, last=%ld\n",
1047 (long) BDB_IDL_FIRST(ids),
1048 (long) BDB_IDL_LAST(ids) );
1053 inequality_candidates(
1056 AttributeAssertion *ava,
1061 struct bdb_info *bdb = (struct bdb_info *) op->o_bd->be_private;
1065 struct berval prefix = {0, NULL};
1066 struct berval *keys = NULL;
1068 DBC * cursor = NULL;
1070 Debug( LDAP_DEBUG_TRACE, "=> bdb_inequality_candidates (%s)\n",
1071 ava->aa_desc->ad_cname.bv_val, 0, 0 );
1073 BDB_IDL_ALL( bdb, ids );
1075 rc = bdb_index_param( op->o_bd, ava->aa_desc, LDAP_FILTER_EQUALITY,
1076 &db, &mask, &prefix );
1078 if( rc != LDAP_SUCCESS ) {
1079 Debug( LDAP_DEBUG_ANY,
1080 "<= bdb_inequality_candidates: (%s) "
1081 "index_param failed (%d)\n",
1082 ava->aa_desc->ad_cname.bv_val, rc, 0 );
1087 Debug( LDAP_DEBUG_ANY,
1088 "<= bdb_inequality_candidates: (%s) not indexed\n",
1089 ava->aa_desc->ad_cname.bv_val, 0, 0 );
1093 mr = ava->aa_desc->ad_type->sat_equality;
1098 if( !mr->smr_filter ) {
1102 rc = (mr->smr_filter)(
1103 LDAP_FILTER_EQUALITY,
1105 ava->aa_desc->ad_type->sat_syntax,
1109 &keys, op->o_tmpmemctx );
1111 if( rc != LDAP_SUCCESS ) {
1112 Debug( LDAP_DEBUG_TRACE,
1113 "<= bdb_inequality_candidates: (%s, %s) "
1114 "MR filter failed (%d)\n",
1115 prefix.bv_val, ava->aa_desc->ad_cname.bv_val, rc );
1119 if( keys == NULL ) {
1120 Debug( LDAP_DEBUG_TRACE,
1121 "<= bdb_inequality_candidates: (%s) no keys\n",
1122 ava->aa_desc->ad_cname.bv_val, 0, 0 );
1126 BDB_IDL_ZERO( ids );
1128 rc = bdb_key_read( op->o_bd, db, locker, &keys[0], tmp, &cursor, gtorlt );
1130 if( rc == DB_NOTFOUND ) {
1133 } else if( rc != LDAP_SUCCESS ) {
1134 Debug( LDAP_DEBUG_TRACE,
1135 "<= bdb_inequality_candidates: (%s) "
1136 "key read failed (%d)\n",
1137 ava->aa_desc->ad_cname.bv_val, rc, 0 );
1141 if( BDB_IDL_IS_ZERO( tmp ) ) {
1142 Debug( LDAP_DEBUG_TRACE,
1143 "<= bdb_inequality_candidates: (%s) NULL\n",
1144 ava->aa_desc->ad_cname.bv_val, 0, 0 );
1148 bdb_idl_union( ids, tmp );
1150 if( op->ors_limit && op->ors_limit->lms_s_unchecked != -1 &&
1151 BDB_IDL_N( ids ) >= (unsigned) op->ors_limit->lms_s_unchecked ) {
1152 cursor->c_close( cursor );
1156 ber_bvarray_free_x( keys, op->o_tmpmemctx );
1158 Debug( LDAP_DEBUG_TRACE,
1159 "<= bdb_inequality_candidates: id=%ld, first=%ld, last=%ld\n",
1161 (long) BDB_IDL_FIRST(ids),
1162 (long) BDB_IDL_LAST(ids) );