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-2006 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(
30 AttributeDescription *desc,
33 static int equality_candidates(
35 AttributeAssertion *ava,
38 static int inequality_candidates(
40 AttributeAssertion *ava,
44 static int approx_candidates(
46 AttributeAssertion *ava,
49 static int substring_candidates(
51 SubstringsAssertion *sub,
55 static int list_candidates(
63 #ifdef LDAP_COMP_MATCH
67 MatchingRuleAssertion *mra,
75 MatchingRuleAssertion *mra,
84 AttributeAssertion *ava,
85 AttributeAliasing *aa,
92 bdb_filter_candidates(
100 #ifdef LDAP_COMP_MATCH
101 AttributeAliasing *aa;
103 Debug( LDAP_DEBUG_FILTER, "=> bdb_filter_candidates\n", 0, 0, 0 );
105 if ( f->f_choice & SLAPD_FILTER_UNDEFINED ) {
110 switch ( f->f_choice ) {
111 case SLAPD_FILTER_COMPUTED:
112 switch( f->f_result ) {
113 case SLAPD_COMPARE_UNDEFINED:
114 /* This technically is not the same as FALSE, but it
115 * certainly will produce no matches.
118 case LDAP_COMPARE_FALSE:
121 case LDAP_COMPARE_TRUE: {
122 struct bdb_info *bdb = (struct bdb_info *)op->o_bd->be_private;
123 BDB_IDL_ALL( bdb, ids );
126 /* this is a pre-computed scope, leave it alone */
130 case LDAP_FILTER_PRESENT:
131 Debug( LDAP_DEBUG_FILTER, "\tPRESENT\n", 0, 0, 0 );
132 rc = presence_candidates( op, f->f_desc, ids );
135 case LDAP_FILTER_EQUALITY:
136 Debug( LDAP_DEBUG_FILTER, "\tEQUALITY\n", 0, 0, 0 );
137 #ifdef LDAP_COMP_MATCH
138 if ( is_aliased_attribute && ( aa = is_aliased_attribute ( f->f_ava->aa_desc ) ) ) {
139 rc = ava_comp_candidates ( op, f->f_ava, aa, ids, tmp, stack );
144 rc = equality_candidates( op, f->f_ava, ids, tmp );
148 case LDAP_FILTER_APPROX:
149 Debug( LDAP_DEBUG_FILTER, "\tAPPROX\n", 0, 0, 0 );
150 rc = approx_candidates( op, f->f_ava, ids, tmp );
153 case LDAP_FILTER_SUBSTRINGS:
154 Debug( LDAP_DEBUG_FILTER, "\tSUBSTRINGS\n", 0, 0, 0 );
155 rc = substring_candidates( op, f->f_sub, ids, tmp );
159 /* if no GE index, use pres */
160 Debug( LDAP_DEBUG_FILTER, "\tGE\n", 0, 0, 0 );
161 if( f->f_ava->aa_desc->ad_type->sat_ordering &&
162 ( f->f_ava->aa_desc->ad_type->sat_ordering->smr_usage & SLAP_MR_ORDERED_INDEX ) )
163 rc = inequality_candidates( op, f->f_ava, ids, tmp, LDAP_FILTER_GE );
165 rc = presence_candidates( op, f->f_ava->aa_desc, ids );
169 /* if no LE index, use pres */
170 Debug( LDAP_DEBUG_FILTER, "\tLE\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, f->f_ava, ids, tmp, LDAP_FILTER_LE );
175 rc = presence_candidates( op, f->f_ava->aa_desc, ids );
178 case LDAP_FILTER_NOT:
179 /* no indexing to support NOT filters */
180 Debug( LDAP_DEBUG_FILTER, "\tNOT\n", 0, 0, 0 );
181 { struct bdb_info *bdb = (struct bdb_info *) op->o_bd->be_private;
182 BDB_IDL_ALL( bdb, ids );
186 case LDAP_FILTER_AND:
187 Debug( LDAP_DEBUG_FILTER, "\tAND\n", 0, 0, 0 );
188 rc = list_candidates( op,
189 f->f_and, LDAP_FILTER_AND, ids, tmp, stack );
193 Debug( LDAP_DEBUG_FILTER, "\tOR\n", 0, 0, 0 );
194 rc = list_candidates( op,
195 f->f_or, LDAP_FILTER_OR, ids, tmp, stack );
197 #ifdef LDAP_COMP_MATCH
198 case LDAP_FILTER_EXT:
199 Debug( LDAP_DEBUG_FILTER, "\tEXT\n", 0, 0, 0 );
200 rc = ext_candidates( op, f->f_mra, ids, tmp, stack );
204 Debug( LDAP_DEBUG_FILTER, "\tUNKNOWN %lu\n",
205 (unsigned long) f->f_choice, 0, 0 );
206 /* Must not return NULL, otherwise extended filters break */
207 { struct bdb_info *bdb = (struct bdb_info *) op->o_bd->be_private;
208 BDB_IDL_ALL( bdb, ids );
213 Debug( LDAP_DEBUG_FILTER,
214 "<= bdb_filter_candidates: id=%ld first=%ld last=%ld\n",
216 (long) BDB_IDL_FIRST( ids ),
217 (long) BDB_IDL_LAST( ids ) );
222 #ifdef LDAP_COMP_MATCH
224 comp_list_candidates(
226 MatchingRuleAssertion* mra,
227 ComponentFilter *flist,
236 Debug( LDAP_DEBUG_FILTER, "=> comp_list_candidates 0x%x\n", ftype, 0, 0 );
237 for ( f = flist; f != NULL; f = f->cf_next ) {
238 /* ignore precomputed scopes */
239 if ( f->cf_choice == SLAPD_FILTER_COMPUTED &&
240 f->cf_result == LDAP_SUCCESS ) {
243 BDB_IDL_ZERO( save );
244 rc = comp_candidates( op, mra, f, save, tmp, save+BDB_IDL_UM_SIZE );
247 if ( ftype == LDAP_COMP_FILTER_AND ) {
254 if ( ftype == LDAP_COMP_FILTER_AND ) {
256 BDB_IDL_CPY( ids, save );
258 bdb_idl_intersection( ids, save );
260 if( BDB_IDL_IS_ZERO( ids ) )
264 BDB_IDL_CPY( ids, save );
266 bdb_idl_union( ids, save );
271 if( rc == LDAP_SUCCESS ) {
272 Debug( LDAP_DEBUG_FILTER,
273 "<= comp_list_candidates: id=%ld first=%ld last=%ld\n",
275 (long) BDB_IDL_FIRST(ids),
276 (long) BDB_IDL_LAST(ids) );
279 Debug( LDAP_DEBUG_FILTER,
280 "<= comp_list_candidates: undefined rc=%d\n",
288 comp_equality_candidates (
290 MatchingRuleAssertion *mra,
291 ComponentAssertion *ca,
296 struct bdb_info *bdb = (struct bdb_info *) op->o_bd->be_private;
301 struct berval prefix = {0, NULL};
302 struct berval *keys = NULL;
303 MatchingRule *mr = mra->ma_rule;
305 ComponentReference* cr_list, *cr;
308 BDB_IDL_ALL( bdb, ids );
310 if ( !ca->ca_comp_ref )
313 ai = bdb_attr_mask( op->o_bd->be_private, mra->ma_desc );
320 /* find a component reference to be indexed */
321 sat_syntax = ca->ca_ma_rule->smr_syntax;
322 for ( cr = cr_list ; cr ; cr = cr->cr_next ) {
323 if ( cr->cr_string.bv_len == ca->ca_comp_ref->cr_string.bv_len &&
324 strncmp( cr->cr_string.bv_val, ca->ca_comp_ref->cr_string.bv_val,cr->cr_string.bv_len ) == 0 )
331 rc = bdb_index_param( op->o_bd, mra->ma_desc, LDAP_FILTER_EQUALITY,
332 &db, &mask, &prefix );
334 if( rc != LDAP_SUCCESS ) {
345 if( !mr->smr_filter ) {
349 rc = (ca->ca_ma_rule->smr_filter)(
350 LDAP_FILTER_EQUALITY,
356 &keys, op->o_tmpmemctx );
358 if( rc != LDAP_SUCCESS ) {
365 for ( i= 0; keys[i].bv_val != NULL; i++ ) {
366 rc = bdb_key_read( op->o_bd, db, NULL, &keys[i], tmp, NULL, 0 );
368 if( rc == DB_NOTFOUND ) {
372 } else if( rc != LDAP_SUCCESS ) {
376 if( BDB_IDL_IS_ZERO( tmp ) ) {
382 BDB_IDL_CPY( ids, tmp );
384 bdb_idl_intersection( ids, tmp );
387 if( BDB_IDL_IS_ZERO( ids ) )
390 ber_bvarray_free_x( keys, op->o_tmpmemctx );
392 Debug( LDAP_DEBUG_TRACE,
393 "<= comp_equality_candidates: id=%ld, first=%ld, last=%ld\n",
395 (long) BDB_IDL_FIRST(ids),
396 (long) BDB_IDL_LAST(ids) );
401 ava_comp_candidates (
403 AttributeAssertion *ava,
404 AttributeAliasing *aa,
409 MatchingRuleAssertion mra;
411 mra.ma_rule = ava->aa_desc->ad_type->sat_equality;
412 if ( !mra.ma_rule ) {
413 struct bdb_info *bdb = (struct bdb_info *) op->o_bd->be_private;
414 BDB_IDL_ALL( bdb, ids );
417 mra.ma_desc = aa->aa_aliased_ad;
418 mra.ma_rule = ava->aa_desc->ad_type->sat_equality;
420 return comp_candidates ( op, &mra, ava->aa_cf, ids, tmp, stack );
426 MatchingRuleAssertion *mra,
434 if ( !f ) return LDAP_PROTOCOL_ERROR;
436 Debug( LDAP_DEBUG_FILTER, "comp_candidates\n", 0, 0, 0 );
437 switch ( f->cf_choice ) {
438 case SLAPD_FILTER_COMPUTED:
441 case LDAP_COMP_FILTER_AND:
442 rc = comp_list_candidates( op, mra, f->cf_and, LDAP_COMP_FILTER_AND, ids, tmp, stack );
444 case LDAP_COMP_FILTER_OR:
445 rc = comp_list_candidates( op, mra, f->cf_or, LDAP_COMP_FILTER_OR, ids, tmp, stack );
447 case LDAP_COMP_FILTER_NOT:
448 /* No component indexing supported for NOT filter */
449 Debug( LDAP_DEBUG_FILTER, "\tComponent NOT\n", 0, 0, 0 );
451 struct bdb_info *bdb = (struct bdb_info *) op->o_bd->be_private;
452 BDB_IDL_ALL( bdb, ids );
454 rc = LDAP_PROTOCOL_ERROR;
456 case LDAP_COMP_FILTER_ITEM:
457 rc = comp_equality_candidates( op, mra, f->cf_ca, ids, tmp, stack );
461 struct bdb_info *bdb = (struct bdb_info *) op->o_bd->be_private;
462 BDB_IDL_ALL( bdb, ids );
464 rc = LDAP_PROTOCOL_ERROR;
473 MatchingRuleAssertion *mra,
479 * Currently Only Component Indexing for componentFilterMatch is supported
480 * Indexing for an extensible filter is not supported yet
483 struct bdb_info *bdb = (struct bdb_info *) op->o_bd->be_private;
484 BDB_IDL_ALL( bdb, ids );
488 return comp_candidates ( op, mra, mra->ma_cf, ids, tmp, stack);
504 Debug( LDAP_DEBUG_FILTER, "=> bdb_list_candidates 0x%x\n", ftype, 0, 0 );
505 for ( f = flist; f != NULL; f = f->f_next ) {
506 /* ignore precomputed scopes */
507 if ( f->f_choice == SLAPD_FILTER_COMPUTED &&
508 f->f_result == LDAP_SUCCESS ) {
511 BDB_IDL_ZERO( save );
512 rc = bdb_filter_candidates( op, f, save, tmp,
513 save+BDB_IDL_UM_SIZE );
516 if ( ftype == LDAP_FILTER_AND ) {
524 if ( ftype == LDAP_FILTER_AND ) {
526 BDB_IDL_CPY( ids, save );
528 bdb_idl_intersection( ids, save );
530 if( BDB_IDL_IS_ZERO( ids ) )
534 BDB_IDL_CPY( ids, save );
536 bdb_idl_union( ids, save );
541 if( rc == LDAP_SUCCESS ) {
542 Debug( LDAP_DEBUG_FILTER,
543 "<= bdb_list_candidates: id=%ld first=%ld last=%ld\n",
545 (long) BDB_IDL_FIRST(ids),
546 (long) BDB_IDL_LAST(ids) );
549 Debug( LDAP_DEBUG_FILTER,
550 "<= bdb_list_candidates: undefined rc=%d\n",
560 AttributeDescription *desc,
563 struct bdb_info *bdb = (struct bdb_info *) op->o_bd->be_private;
567 struct berval prefix = {0, NULL};
569 Debug( LDAP_DEBUG_TRACE, "=> bdb_presence_candidates (%s)\n",
570 desc->ad_cname.bv_val, 0, 0 );
572 BDB_IDL_ALL( bdb, ids );
574 if( desc == slap_schema.si_ad_objectClass ) {
578 rc = bdb_index_param( op->o_bd, desc, LDAP_FILTER_PRESENT,
579 &db, &mask, &prefix );
581 if( rc != LDAP_SUCCESS ) {
582 Debug( LDAP_DEBUG_TRACE,
583 "<= bdb_presence_candidates: (%s) index_param "
585 desc->ad_cname.bv_val, rc, 0 );
591 Debug( LDAP_DEBUG_TRACE,
592 "<= bdb_presence_candidates: (%s) not indexed\n",
593 desc->ad_cname.bv_val, 0, 0 );
597 if( prefix.bv_val == NULL ) {
598 Debug( LDAP_DEBUG_TRACE,
599 "<= bdb_presence_candidates: (%s) no prefix\n",
600 desc->ad_cname.bv_val, 0, 0 );
604 rc = bdb_key_read( op->o_bd, db, NULL, &prefix, ids, NULL, 0 );
606 if( rc == DB_NOTFOUND ) {
609 } else if( rc != LDAP_SUCCESS ) {
610 Debug( LDAP_DEBUG_TRACE,
611 "<= bdb_presense_candidates: (%s) "
612 "key read failed (%d)\n",
613 desc->ad_cname.bv_val, rc, 0 );
617 Debug(LDAP_DEBUG_TRACE,
618 "<= bdb_presence_candidates: id=%ld first=%ld last=%ld\n",
620 (long) BDB_IDL_FIRST(ids),
621 (long) BDB_IDL_LAST(ids) );
630 AttributeAssertion *ava,
634 struct bdb_info *bdb = (struct bdb_info *) op->o_bd->be_private;
639 struct berval prefix = {0, NULL};
640 struct berval *keys = NULL;
643 Debug( LDAP_DEBUG_TRACE, "=> bdb_equality_candidates (%s)\n",
644 ava->aa_desc->ad_cname.bv_val, 0, 0 );
646 BDB_IDL_ALL( bdb, ids );
648 rc = bdb_index_param( op->o_bd, ava->aa_desc, LDAP_FILTER_EQUALITY,
649 &db, &mask, &prefix );
651 if( rc != LDAP_SUCCESS ) {
652 Debug( LDAP_DEBUG_ANY,
653 "<= bdb_equality_candidates: (%s) "
654 "index_param failed (%d)\n",
655 ava->aa_desc->ad_cname.bv_val, rc, 0 );
660 Debug( LDAP_DEBUG_ANY,
661 "<= bdb_equality_candidates: (%s) not indexed\n",
662 ava->aa_desc->ad_cname.bv_val, 0, 0 );
666 mr = ava->aa_desc->ad_type->sat_equality;
671 if( !mr->smr_filter ) {
675 rc = (mr->smr_filter)(
676 LDAP_FILTER_EQUALITY,
678 ava->aa_desc->ad_type->sat_syntax,
682 &keys, op->o_tmpmemctx );
684 if( rc != LDAP_SUCCESS ) {
685 Debug( LDAP_DEBUG_TRACE,
686 "<= bdb_equality_candidates: (%s, %s) "
687 "MR filter failed (%d)\n",
688 prefix.bv_val, ava->aa_desc->ad_cname.bv_val, rc );
693 Debug( LDAP_DEBUG_TRACE,
694 "<= bdb_equality_candidates: (%s) no keys\n",
695 ava->aa_desc->ad_cname.bv_val, 0, 0 );
699 for ( i= 0; keys[i].bv_val != NULL; i++ ) {
700 rc = bdb_key_read( op->o_bd, db, NULL, &keys[i], tmp, NULL, 0 );
702 if( rc == DB_NOTFOUND ) {
706 } else if( rc != LDAP_SUCCESS ) {
707 Debug( LDAP_DEBUG_TRACE,
708 "<= bdb_equality_candidates: (%s) "
709 "key read failed (%d)\n",
710 ava->aa_desc->ad_cname.bv_val, rc, 0 );
714 if( BDB_IDL_IS_ZERO( tmp ) ) {
715 Debug( LDAP_DEBUG_TRACE,
716 "<= bdb_equality_candidates: (%s) NULL\n",
717 ava->aa_desc->ad_cname.bv_val, 0, 0 );
723 BDB_IDL_CPY( ids, tmp );
725 bdb_idl_intersection( ids, tmp );
728 if( BDB_IDL_IS_ZERO( ids ) )
732 ber_bvarray_free_x( keys, op->o_tmpmemctx );
734 Debug( LDAP_DEBUG_TRACE,
735 "<= bdb_equality_candidates: id=%ld, first=%ld, last=%ld\n",
737 (long) BDB_IDL_FIRST(ids),
738 (long) BDB_IDL_LAST(ids) );
746 AttributeAssertion *ava,
750 struct bdb_info *bdb = (struct bdb_info *) op->o_bd->be_private;
755 struct berval prefix = {0, NULL};
756 struct berval *keys = NULL;
759 Debug( LDAP_DEBUG_TRACE, "=> bdb_approx_candidates (%s)\n",
760 ava->aa_desc->ad_cname.bv_val, 0, 0 );
762 BDB_IDL_ALL( bdb, ids );
764 rc = bdb_index_param( op->o_bd, ava->aa_desc, LDAP_FILTER_APPROX,
765 &db, &mask, &prefix );
767 if( rc != LDAP_SUCCESS ) {
768 Debug( LDAP_DEBUG_ANY,
769 "<= bdb_approx_candidates: (%s) "
770 "index_param failed (%d)\n",
771 ava->aa_desc->ad_cname.bv_val, rc, 0 );
776 Debug( LDAP_DEBUG_ANY,
777 "<= bdb_approx_candidates: (%s) not indexed\n",
778 ava->aa_desc->ad_cname.bv_val, 0, 0 );
782 mr = ava->aa_desc->ad_type->sat_approx;
784 /* no approx matching rule, try equality matching rule */
785 mr = ava->aa_desc->ad_type->sat_equality;
792 if( !mr->smr_filter ) {
796 rc = (mr->smr_filter)(
799 ava->aa_desc->ad_type->sat_syntax,
803 &keys, op->o_tmpmemctx );
805 if( rc != LDAP_SUCCESS ) {
806 Debug( LDAP_DEBUG_TRACE,
807 "<= bdb_approx_candidates: (%s, %s) "
808 "MR filter failed (%d)\n",
809 prefix.bv_val, ava->aa_desc->ad_cname.bv_val, rc );
814 Debug( LDAP_DEBUG_TRACE,
815 "<= bdb_approx_candidates: (%s) no keys (%s)\n",
816 prefix.bv_val, ava->aa_desc->ad_cname.bv_val, 0 );
820 for ( i= 0; keys[i].bv_val != NULL; i++ ) {
821 rc = bdb_key_read( op->o_bd, db, NULL, &keys[i], tmp, NULL, 0 );
823 if( rc == DB_NOTFOUND ) {
827 } else if( rc != LDAP_SUCCESS ) {
828 Debug( LDAP_DEBUG_TRACE,
829 "<= bdb_approx_candidates: (%s) "
830 "key read failed (%d)\n",
831 ava->aa_desc->ad_cname.bv_val, rc, 0 );
835 if( BDB_IDL_IS_ZERO( tmp ) ) {
836 Debug( LDAP_DEBUG_TRACE,
837 "<= bdb_approx_candidates: (%s) NULL\n",
838 ava->aa_desc->ad_cname.bv_val, 0, 0 );
844 BDB_IDL_CPY( ids, tmp );
846 bdb_idl_intersection( ids, tmp );
849 if( BDB_IDL_IS_ZERO( ids ) )
853 ber_bvarray_free_x( keys, op->o_tmpmemctx );
855 Debug( LDAP_DEBUG_TRACE, "<= bdb_approx_candidates %ld, first=%ld, last=%ld\n",
857 (long) BDB_IDL_FIRST(ids),
858 (long) BDB_IDL_LAST(ids) );
863 substring_candidates(
865 SubstringsAssertion *sub,
869 struct bdb_info *bdb = (struct bdb_info *) op->o_bd->be_private;
874 struct berval prefix = {0, NULL};
875 struct berval *keys = NULL;
878 Debug( LDAP_DEBUG_TRACE, "=> bdb_substring_candidates (%s)\n",
879 sub->sa_desc->ad_cname.bv_val, 0, 0 );
881 BDB_IDL_ALL( bdb, ids );
883 rc = bdb_index_param( op->o_bd, sub->sa_desc, LDAP_FILTER_SUBSTRINGS,
884 &db, &mask, &prefix );
886 if( rc != LDAP_SUCCESS ) {
887 Debug( LDAP_DEBUG_ANY,
888 "<= bdb_substring_candidates: (%s) "
889 "index_param failed (%d)\n",
890 sub->sa_desc->ad_cname.bv_val, rc, 0 );
895 Debug( LDAP_DEBUG_ANY,
896 "<= bdb_substring_candidates: (%s) not indexed\n",
897 sub->sa_desc->ad_cname.bv_val, 0, 0 );
901 mr = sub->sa_desc->ad_type->sat_substr;
907 if( !mr->smr_filter ) {
911 rc = (mr->smr_filter)(
912 LDAP_FILTER_SUBSTRINGS,
914 sub->sa_desc->ad_type->sat_syntax,
918 &keys, op->o_tmpmemctx );
920 if( rc != LDAP_SUCCESS ) {
921 Debug( LDAP_DEBUG_TRACE,
922 "<= bdb_substring_candidates: (%s) "
923 "MR filter failed (%d)\n",
924 sub->sa_desc->ad_cname.bv_val, rc, 0 );
929 Debug( LDAP_DEBUG_TRACE,
930 "<= bdb_substring_candidates: (0x%04lx) no keys (%s)\n",
931 mask, sub->sa_desc->ad_cname.bv_val, 0 );
935 for ( i= 0; keys[i].bv_val != NULL; i++ ) {
936 rc = bdb_key_read( op->o_bd, db, NULL, &keys[i], tmp, NULL, 0 );
938 if( rc == DB_NOTFOUND ) {
942 } else if( rc != LDAP_SUCCESS ) {
943 Debug( LDAP_DEBUG_TRACE,
944 "<= bdb_substring_candidates: (%s) "
945 "key read failed (%d)\n",
946 sub->sa_desc->ad_cname.bv_val, rc, 0 );
950 if( BDB_IDL_IS_ZERO( tmp ) ) {
951 Debug( LDAP_DEBUG_TRACE,
952 "<= bdb_substring_candidates: (%s) NULL\n",
953 sub->sa_desc->ad_cname.bv_val, 0, 0 );
959 BDB_IDL_CPY( ids, tmp );
961 bdb_idl_intersection( ids, tmp );
964 if( BDB_IDL_IS_ZERO( ids ) )
968 ber_bvarray_free_x( keys, op->o_tmpmemctx );
970 Debug( LDAP_DEBUG_TRACE, "<= bdb_substring_candidates: %ld, first=%ld, last=%ld\n",
972 (long) BDB_IDL_FIRST(ids),
973 (long) BDB_IDL_LAST(ids) );
978 inequality_candidates(
980 AttributeAssertion *ava,
985 struct bdb_info *bdb = (struct bdb_info *) op->o_bd->be_private;
989 struct berval prefix = {0, NULL};
990 struct berval *keys = NULL;
994 Debug( LDAP_DEBUG_TRACE, "=> bdb_inequality_candidates (%s)\n",
995 ava->aa_desc->ad_cname.bv_val, 0, 0 );
997 BDB_IDL_ALL( bdb, ids );
999 rc = bdb_index_param( op->o_bd, ava->aa_desc, LDAP_FILTER_EQUALITY,
1000 &db, &mask, &prefix );
1002 if( rc != LDAP_SUCCESS ) {
1003 Debug( LDAP_DEBUG_ANY,
1004 "<= bdb_inequality_candidates: (%s) "
1005 "index_param failed (%d)\n",
1006 ava->aa_desc->ad_cname.bv_val, rc, 0 );
1011 Debug( LDAP_DEBUG_ANY,
1012 "<= bdb_inequality_candidates: (%s) not indexed\n",
1013 ava->aa_desc->ad_cname.bv_val, 0, 0 );
1017 mr = ava->aa_desc->ad_type->sat_equality;
1022 if( !mr->smr_filter ) {
1026 rc = (mr->smr_filter)(
1027 LDAP_FILTER_EQUALITY,
1029 ava->aa_desc->ad_type->sat_syntax,
1033 &keys, op->o_tmpmemctx );
1035 if( rc != LDAP_SUCCESS ) {
1036 Debug( LDAP_DEBUG_TRACE,
1037 "<= bdb_inequality_candidates: (%s, %s) "
1038 "MR filter failed (%d)\n",
1039 prefix.bv_val, ava->aa_desc->ad_cname.bv_val, rc );
1043 if( keys == NULL ) {
1044 Debug( LDAP_DEBUG_TRACE,
1045 "<= bdb_inequality_candidates: (%s) no keys\n",
1046 ava->aa_desc->ad_cname.bv_val, 0, 0 );
1050 BDB_IDL_ZERO( ids );
1052 rc = bdb_key_read( op->o_bd, db, NULL, &keys[0], tmp, &cursor, gtorlt );
1054 if( rc == DB_NOTFOUND ) {
1057 } else if( rc != LDAP_SUCCESS ) {
1058 Debug( LDAP_DEBUG_TRACE,
1059 "<= bdb_inequality_candidates: (%s) "
1060 "key read failed (%d)\n",
1061 ava->aa_desc->ad_cname.bv_val, rc, 0 );
1065 if( BDB_IDL_IS_ZERO( tmp ) ) {
1066 Debug( LDAP_DEBUG_TRACE,
1067 "<= bdb_inequality_candidates: (%s) NULL\n",
1068 ava->aa_desc->ad_cname.bv_val, 0, 0 );
1072 bdb_idl_union( ids, tmp );
1074 if( op->ors_limit && op->ors_limit->lms_s_unchecked != -1 &&
1075 BDB_IDL_N( ids ) >= (unsigned) op->ors_limit->lms_s_unchecked ) {
1076 cursor->c_close( cursor );
1080 ber_bvarray_free_x( keys, op->o_tmpmemctx );
1082 Debug( LDAP_DEBUG_TRACE,
1083 "<= bdb_inequality_candidates: id=%ld, first=%ld, last=%ld\n",
1085 (long) BDB_IDL_FIRST(ids),
1086 (long) BDB_IDL_LAST(ids) );