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-2008 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, rtxn, 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, rtxn, f->f_ava, aa, ids, tmp, stack );
154 rc = equality_candidates( op, rtxn, 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, rtxn, 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, rtxn, 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, rtxn, f->f_ava, ids, tmp, LDAP_FILTER_GE );
175 rc = presence_candidates( op, rtxn, 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, rtxn, f->f_ava, ids, tmp, LDAP_FILTER_LE );
185 rc = presence_candidates( op, rtxn, 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, rtxn,
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, rtxn,
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, rtxn, 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, rtxn, 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 ) {
352 if( !mr->smr_filter ) {
356 rc = (ca->ca_ma_rule->smr_filter)(
357 LDAP_FILTER_EQUALITY,
363 &keys, op->o_tmpmemctx );
365 if( rc != LDAP_SUCCESS ) {
372 for ( i= 0; keys[i].bv_val != NULL; i++ ) {
373 rc = bdb_key_read( op->o_bd, db, rtxn, &keys[i], tmp, NULL, 0 );
375 if( rc == DB_NOTFOUND ) {
379 } else if( rc != LDAP_SUCCESS ) {
383 if( BDB_IDL_IS_ZERO( tmp ) ) {
389 BDB_IDL_CPY( ids, tmp );
391 bdb_idl_intersection( ids, tmp );
394 if( BDB_IDL_IS_ZERO( ids ) )
397 ber_bvarray_free_x( keys, op->o_tmpmemctx );
399 Debug( LDAP_DEBUG_TRACE,
400 "<= comp_equality_candidates: id=%ld, first=%ld, last=%ld\n",
402 (long) BDB_IDL_FIRST(ids),
403 (long) BDB_IDL_LAST(ids) );
408 ava_comp_candidates (
411 AttributeAssertion *ava,
412 AttributeAliasing *aa,
417 MatchingRuleAssertion mra;
419 mra.ma_rule = ava->aa_desc->ad_type->sat_equality;
420 if ( !mra.ma_rule ) {
421 struct bdb_info *bdb = (struct bdb_info *) op->o_bd->be_private;
422 BDB_IDL_ALL( bdb, ids );
425 mra.ma_desc = aa->aa_aliased_ad;
426 mra.ma_rule = ava->aa_desc->ad_type->sat_equality;
428 return comp_candidates ( op, rtxn, &mra, ava->aa_cf, ids, tmp, stack );
435 MatchingRuleAssertion *mra,
443 if ( !f ) return LDAP_PROTOCOL_ERROR;
445 Debug( LDAP_DEBUG_FILTER, "comp_candidates\n", 0, 0, 0 );
446 switch ( f->cf_choice ) {
447 case SLAPD_FILTER_COMPUTED:
450 case LDAP_COMP_FILTER_AND:
451 rc = comp_list_candidates( op, rtxn, mra, f->cf_and, LDAP_COMP_FILTER_AND, ids, tmp, stack );
453 case LDAP_COMP_FILTER_OR:
454 rc = comp_list_candidates( op, rtxn, mra, f->cf_or, LDAP_COMP_FILTER_OR, ids, tmp, stack );
456 case LDAP_COMP_FILTER_NOT:
457 /* No component indexing supported for NOT filter */
458 Debug( LDAP_DEBUG_FILTER, "\tComponent NOT\n", 0, 0, 0 );
460 struct bdb_info *bdb = (struct bdb_info *) op->o_bd->be_private;
461 BDB_IDL_ALL( bdb, ids );
463 rc = LDAP_PROTOCOL_ERROR;
465 case LDAP_COMP_FILTER_ITEM:
466 rc = comp_equality_candidates( op, rtxn, mra, f->cf_ca, ids, tmp, stack );
470 struct bdb_info *bdb = (struct bdb_info *) op->o_bd->be_private;
471 BDB_IDL_ALL( bdb, ids );
473 rc = LDAP_PROTOCOL_ERROR;
484 MatchingRuleAssertion *mra,
489 struct bdb_info *bdb = (struct bdb_info *) op->o_bd->be_private;
491 #ifdef LDAP_COMP_MATCH
493 * Currently Only Component Indexing for componentFilterMatch is supported
494 * Indexing for an extensible filter is not supported yet
497 return comp_candidates ( op, rtxn, mra, mra->ma_cf, ids, tmp, stack);
500 if ( mra->ma_desc == slap_schema.si_ad_entryDN ) {
505 if ( mra->ma_rule == slap_schema.si_mr_distinguishedNameMatch ) {
507 rc = bdb_cache_find_ndn( op, rtxn, &mra->ma_value, &ei );
508 if ( rc == LDAP_SUCCESS )
509 bdb_idl_insert( ids, ei->bei_id );
511 bdb_cache_entryinfo_unlock( ei );
513 } else if ( mra->ma_rule && mra->ma_rule->smr_match ==
514 dnRelativeMatch && dnIsSuffix( &mra->ma_value,
515 op->o_bd->be_nsuffix )) {
517 if ( mra->ma_rule == slap_schema.si_mr_dnSuperiorMatch ) {
520 dnParent( &mra->ma_value, &pdn );
521 bdb_cache_find_ndn( op, rtxn, &pdn, &ei );
523 bdb_cache_entryinfo_unlock( ei );
524 while ( ei && ei->bei_id ) {
525 bdb_idl_insert( ids, ei->bei_id );
531 if ( mra->ma_rule == slap_schema.si_mr_dnSubtreeMatch )
532 scope = LDAP_SCOPE_SUBTREE;
533 else if ( mra->ma_rule == slap_schema.si_mr_dnOneLevelMatch )
534 scope = LDAP_SCOPE_ONELEVEL;
535 else if ( mra->ma_rule == slap_schema.si_mr_dnSubordinateMatch )
536 scope = LDAP_SCOPE_SUBORDINATE;
538 scope = LDAP_SCOPE_BASE;
539 if ( scope > LDAP_SCOPE_BASE ) {
541 rc = bdb_cache_find_ndn( op, rtxn, &mra->ma_value, &ei );
543 bdb_cache_entryinfo_unlock( ei );
544 if ( rc == LDAP_SUCCESS ) {
545 int sc = op->ors_scope;
546 op->ors_scope = scope;
547 rc = bdb_dn2idl( op, rtxn, &mra->ma_value, ei, ids,
556 BDB_IDL_ALL( bdb, ids );
573 Debug( LDAP_DEBUG_FILTER, "=> bdb_list_candidates 0x%x\n", ftype, 0, 0 );
574 for ( f = flist; f != NULL; f = f->f_next ) {
575 /* ignore precomputed scopes */
576 if ( f->f_choice == SLAPD_FILTER_COMPUTED &&
577 f->f_result == LDAP_SUCCESS ) {
580 BDB_IDL_ZERO( save );
581 rc = bdb_filter_candidates( op, rtxn, f, save, tmp,
582 save+BDB_IDL_UM_SIZE );
585 if ( rc == DB_LOCK_DEADLOCK )
588 if ( ftype == LDAP_FILTER_AND ) {
596 if ( ftype == LDAP_FILTER_AND ) {
598 BDB_IDL_CPY( ids, save );
600 bdb_idl_intersection( ids, save );
602 if( BDB_IDL_IS_ZERO( ids ) )
606 BDB_IDL_CPY( ids, save );
608 bdb_idl_union( ids, save );
613 if( rc == LDAP_SUCCESS ) {
614 Debug( LDAP_DEBUG_FILTER,
615 "<= bdb_list_candidates: id=%ld first=%ld last=%ld\n",
617 (long) BDB_IDL_FIRST(ids),
618 (long) BDB_IDL_LAST(ids) );
621 Debug( LDAP_DEBUG_FILTER,
622 "<= bdb_list_candidates: undefined rc=%d\n",
633 AttributeDescription *desc,
636 struct bdb_info *bdb = (struct bdb_info *) op->o_bd->be_private;
640 struct berval prefix = {0, NULL};
642 Debug( LDAP_DEBUG_TRACE, "=> bdb_presence_candidates (%s)\n",
643 desc->ad_cname.bv_val, 0, 0 );
645 BDB_IDL_ALL( bdb, ids );
647 if( desc == slap_schema.si_ad_objectClass ) {
651 rc = bdb_index_param( op->o_bd, desc, LDAP_FILTER_PRESENT,
652 &db, &mask, &prefix );
654 if( rc == LDAP_INAPPROPRIATE_MATCHING ) {
656 Debug( LDAP_DEBUG_TRACE,
657 "<= bdb_presence_candidates: (%s) not indexed\n",
658 desc->ad_cname.bv_val, 0, 0 );
662 if( rc != LDAP_SUCCESS ) {
663 Debug( LDAP_DEBUG_TRACE,
664 "<= bdb_presence_candidates: (%s) index_param "
666 desc->ad_cname.bv_val, rc, 0 );
670 if( prefix.bv_val == NULL ) {
671 Debug( LDAP_DEBUG_TRACE,
672 "<= bdb_presence_candidates: (%s) no prefix\n",
673 desc->ad_cname.bv_val, 0, 0 );
677 rc = bdb_key_read( op->o_bd, db, rtxn, &prefix, ids, NULL, 0 );
679 if( rc == DB_NOTFOUND ) {
682 } else if( rc != LDAP_SUCCESS ) {
683 Debug( LDAP_DEBUG_TRACE,
684 "<= bdb_presense_candidates: (%s) "
685 "key read failed (%d)\n",
686 desc->ad_cname.bv_val, rc, 0 );
690 Debug(LDAP_DEBUG_TRACE,
691 "<= bdb_presence_candidates: id=%ld first=%ld last=%ld\n",
693 (long) BDB_IDL_FIRST(ids),
694 (long) BDB_IDL_LAST(ids) );
704 AttributeAssertion *ava,
708 struct bdb_info *bdb = (struct bdb_info *) op->o_bd->be_private;
713 struct berval prefix = {0, NULL};
714 struct berval *keys = NULL;
717 Debug( LDAP_DEBUG_TRACE, "=> bdb_equality_candidates (%s)\n",
718 ava->aa_desc->ad_cname.bv_val, 0, 0 );
720 BDB_IDL_ALL( bdb, ids );
722 rc = bdb_index_param( op->o_bd, ava->aa_desc, LDAP_FILTER_EQUALITY,
723 &db, &mask, &prefix );
725 if ( rc == LDAP_INAPPROPRIATE_MATCHING ) {
726 Debug( LDAP_DEBUG_ANY,
727 "<= bdb_equality_candidates: (%s) not indexed\n",
728 ava->aa_desc->ad_cname.bv_val, 0, 0 );
732 if( rc != LDAP_SUCCESS ) {
733 Debug( LDAP_DEBUG_ANY,
734 "<= bdb_equality_candidates: (%s) "
735 "index_param failed (%d)\n",
736 ava->aa_desc->ad_cname.bv_val, rc, 0 );
740 mr = ava->aa_desc->ad_type->sat_equality;
745 if( !mr->smr_filter ) {
749 rc = (mr->smr_filter)(
750 LDAP_FILTER_EQUALITY,
752 ava->aa_desc->ad_type->sat_syntax,
756 &keys, op->o_tmpmemctx );
758 if( rc != LDAP_SUCCESS ) {
759 Debug( LDAP_DEBUG_TRACE,
760 "<= bdb_equality_candidates: (%s, %s) "
761 "MR filter failed (%d)\n",
762 prefix.bv_val, ava->aa_desc->ad_cname.bv_val, rc );
767 Debug( LDAP_DEBUG_TRACE,
768 "<= bdb_equality_candidates: (%s) no keys\n",
769 ava->aa_desc->ad_cname.bv_val, 0, 0 );
773 for ( i= 0; keys[i].bv_val != NULL; i++ ) {
774 rc = bdb_key_read( op->o_bd, db, rtxn, &keys[i], tmp, NULL, 0 );
776 if( rc == DB_NOTFOUND ) {
780 } else if( rc != LDAP_SUCCESS ) {
781 Debug( LDAP_DEBUG_TRACE,
782 "<= bdb_equality_candidates: (%s) "
783 "key read failed (%d)\n",
784 ava->aa_desc->ad_cname.bv_val, rc, 0 );
788 if( BDB_IDL_IS_ZERO( tmp ) ) {
789 Debug( LDAP_DEBUG_TRACE,
790 "<= bdb_equality_candidates: (%s) NULL\n",
791 ava->aa_desc->ad_cname.bv_val, 0, 0 );
797 BDB_IDL_CPY( ids, tmp );
799 bdb_idl_intersection( ids, tmp );
802 if( BDB_IDL_IS_ZERO( ids ) )
806 ber_bvarray_free_x( keys, op->o_tmpmemctx );
808 Debug( LDAP_DEBUG_TRACE,
809 "<= bdb_equality_candidates: id=%ld, first=%ld, last=%ld\n",
811 (long) BDB_IDL_FIRST(ids),
812 (long) BDB_IDL_LAST(ids) );
821 AttributeAssertion *ava,
825 struct bdb_info *bdb = (struct bdb_info *) op->o_bd->be_private;
830 struct berval prefix = {0, NULL};
831 struct berval *keys = NULL;
834 Debug( LDAP_DEBUG_TRACE, "=> bdb_approx_candidates (%s)\n",
835 ava->aa_desc->ad_cname.bv_val, 0, 0 );
837 BDB_IDL_ALL( bdb, ids );
839 rc = bdb_index_param( op->o_bd, ava->aa_desc, LDAP_FILTER_APPROX,
840 &db, &mask, &prefix );
842 if ( rc == LDAP_INAPPROPRIATE_MATCHING ) {
843 Debug( LDAP_DEBUG_ANY,
844 "<= bdb_approx_candidates: (%s) not indexed\n",
845 ava->aa_desc->ad_cname.bv_val, 0, 0 );
849 if( rc != LDAP_SUCCESS ) {
850 Debug( LDAP_DEBUG_ANY,
851 "<= bdb_approx_candidates: (%s) "
852 "index_param failed (%d)\n",
853 ava->aa_desc->ad_cname.bv_val, rc, 0 );
857 mr = ava->aa_desc->ad_type->sat_approx;
859 /* no approx matching rule, try equality matching rule */
860 mr = ava->aa_desc->ad_type->sat_equality;
867 if( !mr->smr_filter ) {
871 rc = (mr->smr_filter)(
874 ava->aa_desc->ad_type->sat_syntax,
878 &keys, op->o_tmpmemctx );
880 if( rc != LDAP_SUCCESS ) {
881 Debug( LDAP_DEBUG_TRACE,
882 "<= bdb_approx_candidates: (%s, %s) "
883 "MR filter failed (%d)\n",
884 prefix.bv_val, ava->aa_desc->ad_cname.bv_val, rc );
889 Debug( LDAP_DEBUG_TRACE,
890 "<= bdb_approx_candidates: (%s) no keys (%s)\n",
891 prefix.bv_val, ava->aa_desc->ad_cname.bv_val, 0 );
895 for ( i= 0; keys[i].bv_val != NULL; i++ ) {
896 rc = bdb_key_read( op->o_bd, db, rtxn, &keys[i], tmp, NULL, 0 );
898 if( rc == DB_NOTFOUND ) {
902 } else if( rc != LDAP_SUCCESS ) {
903 Debug( LDAP_DEBUG_TRACE,
904 "<= bdb_approx_candidates: (%s) "
905 "key read failed (%d)\n",
906 ava->aa_desc->ad_cname.bv_val, rc, 0 );
910 if( BDB_IDL_IS_ZERO( tmp ) ) {
911 Debug( LDAP_DEBUG_TRACE,
912 "<= bdb_approx_candidates: (%s) NULL\n",
913 ava->aa_desc->ad_cname.bv_val, 0, 0 );
919 BDB_IDL_CPY( ids, tmp );
921 bdb_idl_intersection( ids, tmp );
924 if( BDB_IDL_IS_ZERO( ids ) )
928 ber_bvarray_free_x( keys, op->o_tmpmemctx );
930 Debug( LDAP_DEBUG_TRACE, "<= bdb_approx_candidates %ld, first=%ld, last=%ld\n",
932 (long) BDB_IDL_FIRST(ids),
933 (long) BDB_IDL_LAST(ids) );
938 substring_candidates(
941 SubstringsAssertion *sub,
945 struct bdb_info *bdb = (struct bdb_info *) op->o_bd->be_private;
950 struct berval prefix = {0, NULL};
951 struct berval *keys = NULL;
954 Debug( LDAP_DEBUG_TRACE, "=> bdb_substring_candidates (%s)\n",
955 sub->sa_desc->ad_cname.bv_val, 0, 0 );
957 BDB_IDL_ALL( bdb, ids );
959 rc = bdb_index_param( op->o_bd, sub->sa_desc, LDAP_FILTER_SUBSTRINGS,
960 &db, &mask, &prefix );
962 if ( rc == LDAP_INAPPROPRIATE_MATCHING ) {
963 Debug( LDAP_DEBUG_ANY,
964 "<= bdb_substring_candidates: (%s) not indexed\n",
965 sub->sa_desc->ad_cname.bv_val, 0, 0 );
969 if( rc != LDAP_SUCCESS ) {
970 Debug( LDAP_DEBUG_ANY,
971 "<= bdb_substring_candidates: (%s) "
972 "index_param failed (%d)\n",
973 sub->sa_desc->ad_cname.bv_val, rc, 0 );
977 mr = sub->sa_desc->ad_type->sat_substr;
983 if( !mr->smr_filter ) {
987 rc = (mr->smr_filter)(
988 LDAP_FILTER_SUBSTRINGS,
990 sub->sa_desc->ad_type->sat_syntax,
994 &keys, op->o_tmpmemctx );
996 if( rc != LDAP_SUCCESS ) {
997 Debug( LDAP_DEBUG_TRACE,
998 "<= bdb_substring_candidates: (%s) "
999 "MR filter failed (%d)\n",
1000 sub->sa_desc->ad_cname.bv_val, rc, 0 );
1004 if( keys == NULL ) {
1005 Debug( LDAP_DEBUG_TRACE,
1006 "<= bdb_substring_candidates: (0x%04lx) no keys (%s)\n",
1007 mask, sub->sa_desc->ad_cname.bv_val, 0 );
1011 for ( i= 0; keys[i].bv_val != NULL; i++ ) {
1012 rc = bdb_key_read( op->o_bd, db, rtxn, &keys[i], tmp, NULL, 0 );
1014 if( rc == DB_NOTFOUND ) {
1015 BDB_IDL_ZERO( ids );
1018 } else if( rc != LDAP_SUCCESS ) {
1019 Debug( LDAP_DEBUG_TRACE,
1020 "<= bdb_substring_candidates: (%s) "
1021 "key read failed (%d)\n",
1022 sub->sa_desc->ad_cname.bv_val, rc, 0 );
1026 if( BDB_IDL_IS_ZERO( tmp ) ) {
1027 Debug( LDAP_DEBUG_TRACE,
1028 "<= bdb_substring_candidates: (%s) NULL\n",
1029 sub->sa_desc->ad_cname.bv_val, 0, 0 );
1030 BDB_IDL_ZERO( ids );
1035 BDB_IDL_CPY( ids, tmp );
1037 bdb_idl_intersection( ids, tmp );
1040 if( BDB_IDL_IS_ZERO( ids ) )
1044 ber_bvarray_free_x( keys, op->o_tmpmemctx );
1046 Debug( LDAP_DEBUG_TRACE, "<= bdb_substring_candidates: %ld, first=%ld, last=%ld\n",
1048 (long) BDB_IDL_FIRST(ids),
1049 (long) BDB_IDL_LAST(ids) );
1054 inequality_candidates(
1057 AttributeAssertion *ava,
1062 struct bdb_info *bdb = (struct bdb_info *) op->o_bd->be_private;
1066 struct berval prefix = {0, NULL};
1067 struct berval *keys = NULL;
1069 DBC * cursor = NULL;
1071 Debug( LDAP_DEBUG_TRACE, "=> bdb_inequality_candidates (%s)\n",
1072 ava->aa_desc->ad_cname.bv_val, 0, 0 );
1074 BDB_IDL_ALL( bdb, ids );
1076 rc = bdb_index_param( op->o_bd, ava->aa_desc, LDAP_FILTER_EQUALITY,
1077 &db, &mask, &prefix );
1079 if ( rc == LDAP_INAPPROPRIATE_MATCHING ) {
1080 Debug( LDAP_DEBUG_ANY,
1081 "<= bdb_inequality_candidates: (%s) not indexed\n",
1082 ava->aa_desc->ad_cname.bv_val, 0, 0 );
1086 if( rc != LDAP_SUCCESS ) {
1087 Debug( LDAP_DEBUG_ANY,
1088 "<= bdb_inequality_candidates: (%s) "
1089 "index_param failed (%d)\n",
1090 ava->aa_desc->ad_cname.bv_val, rc, 0 );
1094 mr = ava->aa_desc->ad_type->sat_equality;
1099 if( !mr->smr_filter ) {
1103 rc = (mr->smr_filter)(
1104 LDAP_FILTER_EQUALITY,
1106 ava->aa_desc->ad_type->sat_syntax,
1110 &keys, op->o_tmpmemctx );
1112 if( rc != LDAP_SUCCESS ) {
1113 Debug( LDAP_DEBUG_TRACE,
1114 "<= bdb_inequality_candidates: (%s, %s) "
1115 "MR filter failed (%d)\n",
1116 prefix.bv_val, ava->aa_desc->ad_cname.bv_val, rc );
1120 if( keys == NULL ) {
1121 Debug( LDAP_DEBUG_TRACE,
1122 "<= bdb_inequality_candidates: (%s) no keys\n",
1123 ava->aa_desc->ad_cname.bv_val, 0, 0 );
1127 BDB_IDL_ZERO( ids );
1129 rc = bdb_key_read( op->o_bd, db, rtxn, &keys[0], tmp, &cursor, gtorlt );
1131 if( rc == DB_NOTFOUND ) {
1134 } else if( rc != LDAP_SUCCESS ) {
1135 Debug( LDAP_DEBUG_TRACE,
1136 "<= bdb_inequality_candidates: (%s) "
1137 "key read failed (%d)\n",
1138 ava->aa_desc->ad_cname.bv_val, rc, 0 );
1142 if( BDB_IDL_IS_ZERO( tmp ) ) {
1143 Debug( LDAP_DEBUG_TRACE,
1144 "<= bdb_inequality_candidates: (%s) NULL\n",
1145 ava->aa_desc->ad_cname.bv_val, 0, 0 );
1149 bdb_idl_union( ids, tmp );
1151 if( op->ors_limit && op->ors_limit->lms_s_unchecked != -1 &&
1152 BDB_IDL_N( ids ) >= (unsigned) op->ors_limit->lms_s_unchecked ) {
1153 cursor->c_close( cursor );
1157 ber_bvarray_free_x( keys, op->o_tmpmemctx );
1159 Debug( LDAP_DEBUG_TRACE,
1160 "<= bdb_inequality_candidates: id=%ld, first=%ld, last=%ld\n",
1162 (long) BDB_IDL_FIRST(ids),
1163 (long) BDB_IDL_LAST(ids) );