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-2005 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 switch ( f->f_choice ) {
106 case SLAPD_FILTER_COMPUTED:
107 switch( f->f_result ) {
108 case SLAPD_COMPARE_UNDEFINED:
109 /* This technically is not the same as FALSE, but it
110 * certainly will produce no matches.
113 case LDAP_COMPARE_FALSE:
116 case LDAP_COMPARE_TRUE: {
117 struct bdb_info *bdb = (struct bdb_info *)op->o_bd->be_private;
118 BDB_IDL_ALL( bdb, ids );
121 /* this is a pre-computed scope, leave it alone */
125 case LDAP_FILTER_PRESENT:
126 Debug( LDAP_DEBUG_FILTER, "\tPRESENT\n", 0, 0, 0 );
127 rc = presence_candidates( op, f->f_desc, ids );
130 case LDAP_FILTER_EQUALITY:
131 Debug( LDAP_DEBUG_FILTER, "\tEQUALITY\n", 0, 0, 0 );
132 #ifdef LDAP_COMP_MATCH
133 if ( is_aliased_attribute && ( aa = is_aliased_attribute ( f->f_ava->aa_desc ) ) ) {
134 rc = ava_comp_candidates ( op, f->f_ava, aa, ids, tmp, stack );
139 rc = equality_candidates( op, f->f_ava, ids, tmp );
143 case LDAP_FILTER_APPROX:
144 Debug( LDAP_DEBUG_FILTER, "\tAPPROX\n", 0, 0, 0 );
145 rc = approx_candidates( op, f->f_ava, ids, tmp );
148 case LDAP_FILTER_SUBSTRINGS:
149 Debug( LDAP_DEBUG_FILTER, "\tSUBSTRINGS\n", 0, 0, 0 );
150 rc = substring_candidates( op, f->f_sub, ids, tmp );
154 /* if no GE index, use pres */
155 Debug( LDAP_DEBUG_FILTER, "\tGE\n", 0, 0, 0 );
156 if( f->f_ava->aa_desc->ad_type->sat_ordering &&
157 ( f->f_ava->aa_desc->ad_type->sat_ordering->smr_usage && SLAP_MR_ORDERED_INDEX ) )
158 rc = inequality_candidates( op, f->f_ava, ids, tmp, LDAP_FILTER_GE );
160 rc = presence_candidates( op, f->f_ava->aa_desc, ids );
164 /* if no LE index, use pres */
165 Debug( LDAP_DEBUG_FILTER, "\tLE\n", 0, 0, 0 );
166 if( f->f_ava->aa_desc->ad_type->sat_ordering &&
167 ( f->f_ava->aa_desc->ad_type->sat_ordering->smr_usage && SLAP_MR_ORDERED_INDEX ) )
168 rc = inequality_candidates( op, f->f_ava, ids, tmp, LDAP_FILTER_LE );
170 rc = presence_candidates( op, f->f_ava->aa_desc, ids );
173 case LDAP_FILTER_NOT:
174 /* no indexing to support NOT filters */
175 Debug( LDAP_DEBUG_FILTER, "\tNOT\n", 0, 0, 0 );
176 { struct bdb_info *bdb = (struct bdb_info *) op->o_bd->be_private;
177 BDB_IDL_ALL( bdb, ids );
181 case LDAP_FILTER_AND:
182 Debug( LDAP_DEBUG_FILTER, "\tAND\n", 0, 0, 0 );
183 rc = list_candidates( op,
184 f->f_and, LDAP_FILTER_AND, ids, tmp, stack );
188 Debug( LDAP_DEBUG_FILTER, "\tOR\n", 0, 0, 0 );
189 rc = list_candidates( op,
190 f->f_or, LDAP_FILTER_OR, ids, tmp, stack );
192 #ifdef LDAP_COMP_MATCH
193 case LDAP_FILTER_EXT:
194 Debug( LDAP_DEBUG_FILTER, "\tEXT\n", 0, 0, 0 );
195 rc = ext_candidates( op, f->f_mra, ids, tmp, stack );
199 Debug( LDAP_DEBUG_FILTER, "\tUNKNOWN %lu\n",
200 (unsigned long) f->f_choice, 0, 0 );
201 /* Must not return NULL, otherwise extended filters break */
202 { struct bdb_info *bdb = (struct bdb_info *) op->o_bd->be_private;
203 BDB_IDL_ALL( bdb, ids );
207 Debug( LDAP_DEBUG_FILTER,
208 "<= bdb_filter_candidates: id=%ld first=%ld last=%ld\n",
210 (long) BDB_IDL_FIRST( ids ),
211 (long) BDB_IDL_LAST( ids ) );
216 #ifdef LDAP_COMP_MATCH
218 comp_list_candidates(
220 MatchingRuleAssertion* mra,
221 ComponentFilter *flist,
230 Debug( LDAP_DEBUG_FILTER, "=> comp_list_candidates 0x%x\n", ftype, 0, 0 );
231 for ( f = flist; f != NULL; f = f->cf_next ) {
232 /* ignore precomputed scopes */
233 if ( f->cf_choice == SLAPD_FILTER_COMPUTED &&
234 f->cf_result == LDAP_SUCCESS ) {
237 BDB_IDL_ZERO( save );
238 rc = comp_candidates( op, mra, f, save, tmp, save+BDB_IDL_UM_SIZE );
241 if ( ftype == LDAP_COMP_FILTER_AND ) {
248 if ( ftype == LDAP_COMP_FILTER_AND ) {
250 BDB_IDL_CPY( ids, save );
252 bdb_idl_intersection( ids, save );
254 if( BDB_IDL_IS_ZERO( ids ) )
258 BDB_IDL_CPY( ids, save );
260 bdb_idl_union( ids, save );
265 if( rc == LDAP_SUCCESS ) {
266 Debug( LDAP_DEBUG_FILTER,
267 "<= comp_list_candidates: id=%ld first=%ld last=%ld\n",
269 (long) BDB_IDL_FIRST(ids),
270 (long) BDB_IDL_LAST(ids) );
273 Debug( LDAP_DEBUG_FILTER,
274 "<= comp_list_candidates: undefined rc=%d\n",
282 comp_equality_candidates (
284 MatchingRuleAssertion *mra,
285 ComponentAssertion *ca,
290 struct bdb_info *bdb = (struct bdb_info *) op->o_bd->be_private;
295 struct berval prefix = {0, NULL};
296 struct berval *keys = NULL;
297 MatchingRule *mr = mra->ma_rule;
299 ComponentReference* cr_list, *cr;
302 BDB_IDL_ALL( bdb, ids );
304 if ( !ca->ca_comp_ref )
307 ai = bdb_attr_mask( op->o_bd->be_private, mra->ma_desc );
310 /* find a component reference to be indexed */
311 sat_syntax = ca->ca_ma_rule->smr_syntax;
312 for ( cr = cr_list ; cr ; cr = cr->cr_next ) {
313 if ( cr->cr_string.bv_len == ca->ca_comp_ref->cr_string.bv_len &&
314 strncmp( cr->cr_string.bv_val, ca->ca_comp_ref->cr_string.bv_val,cr->cr_string.bv_len ) == 0 )
321 rc = bdb_index_param( op->o_bd, mra->ma_desc, LDAP_FILTER_EQUALITY,
322 &db, &mask, &prefix );
324 if( rc != LDAP_SUCCESS ) {
335 if( !mr->smr_filter ) {
339 rc = (ca->ca_ma_rule->smr_filter)(
340 LDAP_FILTER_EQUALITY,
346 &keys, op->o_tmpmemctx );
348 if( rc != LDAP_SUCCESS ) {
355 for ( i= 0; keys[i].bv_val != NULL; i++ ) {
356 rc = bdb_key_read( op->o_bd, db, NULL, &keys[i], tmp, NULL, 0 );
358 if( rc == DB_NOTFOUND ) {
362 } else if( rc != LDAP_SUCCESS ) {
366 if( BDB_IDL_IS_ZERO( tmp ) ) {
372 BDB_IDL_CPY( ids, tmp );
374 bdb_idl_intersection( ids, tmp );
377 if( BDB_IDL_IS_ZERO( ids ) )
380 ber_bvarray_free_x( keys, op->o_tmpmemctx );
382 Debug( LDAP_DEBUG_TRACE,
383 "<= comp_equality_candidates: id=%ld, first=%ld, last=%ld\n",
385 (long) BDB_IDL_FIRST(ids),
386 (long) BDB_IDL_LAST(ids) );
391 ava_comp_candidates (
393 AttributeAssertion *ava,
394 AttributeAliasing *aa,
399 MatchingRuleAssertion mra;
401 mra.ma_rule = ava->aa_desc->ad_type->sat_equality;
402 if ( !mra.ma_rule ) {
403 struct bdb_info *bdb = (struct bdb_info *) op->o_bd->be_private;
404 BDB_IDL_ALL( bdb, ids );
407 mra.ma_desc = aa->aa_aliased_ad;
408 mra.ma_rule = ava->aa_desc->ad_type->sat_equality;
410 return comp_candidates ( op, &mra, ava->aa_cf, ids, tmp, stack );
416 MatchingRuleAssertion *mra,
424 if ( !f ) return LDAP_PROTOCOL_ERROR;
426 Debug( LDAP_DEBUG_FILTER, "comp_candidates\n", 0, 0, 0 );
427 switch ( f->cf_choice ) {
428 case SLAPD_FILTER_COMPUTED:
431 case LDAP_COMP_FILTER_AND:
432 rc = comp_list_candidates( op, mra, f->cf_and, LDAP_COMP_FILTER_AND, ids, tmp, stack );
434 case LDAP_COMP_FILTER_OR:
435 rc = comp_list_candidates( op, mra, f->cf_or, LDAP_COMP_FILTER_OR, ids, tmp, stack );
437 case LDAP_COMP_FILTER_NOT:
438 /* No component indexing supported for NOT filter */
439 Debug( LDAP_DEBUG_FILTER, "\tComponent NOT\n", 0, 0, 0 );
441 struct bdb_info *bdb = (struct bdb_info *) op->o_bd->be_private;
442 BDB_IDL_ALL( bdb, ids );
444 rc = LDAP_PROTOCOL_ERROR;
446 case LDAP_COMP_FILTER_ITEM:
447 rc = comp_equality_candidates( op, mra, f->cf_ca, ids, tmp, stack );
451 struct bdb_info *bdb = (struct bdb_info *) op->o_bd->be_private;
452 BDB_IDL_ALL( bdb, ids );
454 rc = LDAP_PROTOCOL_ERROR;
463 MatchingRuleAssertion *mra,
469 * Currently Only Component Indexing for componentFilterMatch is supported
470 * Indexing for an extensible filter is not supported yet
473 struct bdb_info *bdb = (struct bdb_info *) op->o_bd->be_private;
474 BDB_IDL_ALL( bdb, ids );
478 return comp_candidates ( op, mra, mra->ma_cf, ids, tmp, stack);
494 Debug( LDAP_DEBUG_FILTER, "=> bdb_list_candidates 0x%x\n", ftype, 0, 0 );
495 for ( f = flist; f != NULL; f = f->f_next ) {
496 /* ignore precomputed scopes */
497 if ( f->f_choice == SLAPD_FILTER_COMPUTED &&
498 f->f_result == LDAP_SUCCESS ) {
501 BDB_IDL_ZERO( save );
502 rc = bdb_filter_candidates( op, f, save, tmp,
503 save+BDB_IDL_UM_SIZE );
506 if ( ftype == LDAP_FILTER_AND ) {
514 if ( ftype == LDAP_FILTER_AND ) {
516 BDB_IDL_CPY( ids, save );
518 bdb_idl_intersection( ids, save );
520 if( BDB_IDL_IS_ZERO( ids ) )
524 BDB_IDL_CPY( ids, save );
526 bdb_idl_union( ids, save );
531 if( rc == LDAP_SUCCESS ) {
532 Debug( LDAP_DEBUG_FILTER,
533 "<= bdb_list_candidates: id=%ld first=%ld last=%ld\n",
535 (long) BDB_IDL_FIRST(ids),
536 (long) BDB_IDL_LAST(ids) );
539 Debug( LDAP_DEBUG_FILTER,
540 "<= bdb_list_candidates: undefined rc=%d\n",
550 AttributeDescription *desc,
553 struct bdb_info *bdb = (struct bdb_info *) op->o_bd->be_private;
557 struct berval prefix = {0, NULL};
559 Debug( LDAP_DEBUG_TRACE, "=> bdb_presence_candidates (%s)\n",
560 desc->ad_cname.bv_val, 0, 0 );
562 BDB_IDL_ALL( bdb, ids );
564 if( desc == slap_schema.si_ad_objectClass ) {
568 rc = bdb_index_param( op->o_bd, desc, LDAP_FILTER_PRESENT,
569 &db, &mask, &prefix );
571 if( rc != LDAP_SUCCESS ) {
572 Debug( LDAP_DEBUG_TRACE,
573 "<= bdb_presence_candidates: (%s) index_param "
575 desc->ad_cname.bv_val, rc, 0 );
581 Debug( LDAP_DEBUG_TRACE,
582 "<= bdb_presence_candidates: (%s) not indexed\n",
583 desc->ad_cname.bv_val, 0, 0 );
587 if( prefix.bv_val == NULL ) {
588 Debug( LDAP_DEBUG_TRACE,
589 "<= bdb_presence_candidates: (%s) no prefix\n",
590 desc->ad_cname.bv_val, 0, 0 );
594 rc = bdb_key_read( op->o_bd, db, NULL, &prefix, ids, NULL, 0 );
596 if( rc == DB_NOTFOUND ) {
599 } else if( rc != LDAP_SUCCESS ) {
600 Debug( LDAP_DEBUG_TRACE,
601 "<= bdb_presense_candidates: (%s) "
602 "key read failed (%d)\n",
603 desc->ad_cname.bv_val, rc, 0 );
607 Debug(LDAP_DEBUG_TRACE,
608 "<= bdb_presence_candidates: id=%ld first=%ld last=%ld\n",
610 (long) BDB_IDL_FIRST(ids),
611 (long) BDB_IDL_LAST(ids) );
620 AttributeAssertion *ava,
624 struct bdb_info *bdb = (struct bdb_info *) op->o_bd->be_private;
629 struct berval prefix = {0, NULL};
630 struct berval *keys = NULL;
633 Debug( LDAP_DEBUG_TRACE, "=> bdb_equality_candidates (%s)\n",
634 ava->aa_desc->ad_cname.bv_val, 0, 0 );
636 BDB_IDL_ALL( bdb, ids );
638 rc = bdb_index_param( op->o_bd, ava->aa_desc, LDAP_FILTER_EQUALITY,
639 &db, &mask, &prefix );
641 if( rc != LDAP_SUCCESS ) {
642 Debug( LDAP_DEBUG_ANY,
643 "<= bdb_equality_candidates: (%s) "
644 "index_param failed (%d)\n",
645 ava->aa_desc->ad_cname.bv_val, rc, 0 );
650 Debug( LDAP_DEBUG_ANY,
651 "<= bdb_equality_candidates: (%s) not indexed\n",
652 ava->aa_desc->ad_cname.bv_val, 0, 0 );
656 mr = ava->aa_desc->ad_type->sat_equality;
661 if( !mr->smr_filter ) {
665 rc = (mr->smr_filter)(
666 LDAP_FILTER_EQUALITY,
668 ava->aa_desc->ad_type->sat_syntax,
672 &keys, op->o_tmpmemctx );
674 if( rc != LDAP_SUCCESS ) {
675 Debug( LDAP_DEBUG_TRACE,
676 "<= bdb_equality_candidates: (%s, %s) "
677 "MR filter failed (%d)\n",
678 prefix.bv_val, ava->aa_desc->ad_cname.bv_val, rc );
683 Debug( LDAP_DEBUG_TRACE,
684 "<= bdb_equality_candidates: (%s) no keys\n",
685 ava->aa_desc->ad_cname.bv_val, 0, 0 );
689 for ( i= 0; keys[i].bv_val != NULL; i++ ) {
690 rc = bdb_key_read( op->o_bd, db, NULL, &keys[i], tmp, NULL, 0 );
692 if( rc == DB_NOTFOUND ) {
696 } else if( rc != LDAP_SUCCESS ) {
697 Debug( LDAP_DEBUG_TRACE,
698 "<= bdb_equality_candidates: (%s) "
699 "key read failed (%d)\n",
700 ava->aa_desc->ad_cname.bv_val, rc, 0 );
704 if( BDB_IDL_IS_ZERO( tmp ) ) {
705 Debug( LDAP_DEBUG_TRACE,
706 "<= bdb_equality_candidates: (%s) NULL\n",
707 ava->aa_desc->ad_cname.bv_val, 0, 0 );
713 BDB_IDL_CPY( ids, tmp );
715 bdb_idl_intersection( ids, tmp );
718 if( BDB_IDL_IS_ZERO( ids ) )
722 ber_bvarray_free_x( keys, op->o_tmpmemctx );
724 Debug( LDAP_DEBUG_TRACE,
725 "<= bdb_equality_candidates: id=%ld, first=%ld, last=%ld\n",
727 (long) BDB_IDL_FIRST(ids),
728 (long) BDB_IDL_LAST(ids) );
736 AttributeAssertion *ava,
740 struct bdb_info *bdb = (struct bdb_info *) op->o_bd->be_private;
745 struct berval prefix = {0, NULL};
746 struct berval *keys = NULL;
749 Debug( LDAP_DEBUG_TRACE, "=> bdb_approx_candidates (%s)\n",
750 ava->aa_desc->ad_cname.bv_val, 0, 0 );
752 BDB_IDL_ALL( bdb, ids );
754 rc = bdb_index_param( op->o_bd, ava->aa_desc, LDAP_FILTER_APPROX,
755 &db, &mask, &prefix );
757 if( rc != LDAP_SUCCESS ) {
758 Debug( LDAP_DEBUG_ANY,
759 "<= bdb_approx_candidates: (%s) "
760 "index_param failed (%d)\n",
761 ava->aa_desc->ad_cname.bv_val, rc, 0 );
766 Debug( LDAP_DEBUG_ANY,
767 "<= bdb_approx_candidates: (%s) not indexed\n",
768 ava->aa_desc->ad_cname.bv_val, 0, 0 );
772 mr = ava->aa_desc->ad_type->sat_approx;
774 /* no approx matching rule, try equality matching rule */
775 mr = ava->aa_desc->ad_type->sat_equality;
782 if( !mr->smr_filter ) {
786 rc = (mr->smr_filter)(
789 ava->aa_desc->ad_type->sat_syntax,
793 &keys, op->o_tmpmemctx );
795 if( rc != LDAP_SUCCESS ) {
796 Debug( LDAP_DEBUG_TRACE,
797 "<= bdb_approx_candidates: (%s, %s) "
798 "MR filter failed (%d)\n",
799 prefix.bv_val, ava->aa_desc->ad_cname.bv_val, rc );
804 Debug( LDAP_DEBUG_TRACE,
805 "<= bdb_approx_candidates: (%s) no keys (%s)\n",
806 prefix.bv_val, ava->aa_desc->ad_cname.bv_val, 0 );
810 for ( i= 0; keys[i].bv_val != NULL; i++ ) {
811 rc = bdb_key_read( op->o_bd, db, NULL, &keys[i], tmp, NULL, 0 );
813 if( rc == DB_NOTFOUND ) {
817 } else if( rc != LDAP_SUCCESS ) {
818 Debug( LDAP_DEBUG_TRACE,
819 "<= bdb_approx_candidates: (%s) "
820 "key read failed (%d)\n",
821 ava->aa_desc->ad_cname.bv_val, rc, 0 );
825 if( BDB_IDL_IS_ZERO( tmp ) ) {
826 Debug( LDAP_DEBUG_TRACE,
827 "<= bdb_approx_candidates: (%s) NULL\n",
828 ava->aa_desc->ad_cname.bv_val, 0, 0 );
834 BDB_IDL_CPY( ids, tmp );
836 bdb_idl_intersection( ids, tmp );
839 if( BDB_IDL_IS_ZERO( ids ) )
843 ber_bvarray_free_x( keys, op->o_tmpmemctx );
845 Debug( LDAP_DEBUG_TRACE, "<= bdb_approx_candidates %ld, first=%ld, last=%ld\n",
847 (long) BDB_IDL_FIRST(ids),
848 (long) BDB_IDL_LAST(ids) );
853 substring_candidates(
855 SubstringsAssertion *sub,
859 struct bdb_info *bdb = (struct bdb_info *) op->o_bd->be_private;
864 struct berval prefix = {0, NULL};
865 struct berval *keys = NULL;
868 Debug( LDAP_DEBUG_TRACE, "=> bdb_substring_candidates (%s)\n",
869 sub->sa_desc->ad_cname.bv_val, 0, 0 );
871 BDB_IDL_ALL( bdb, ids );
873 rc = bdb_index_param( op->o_bd, sub->sa_desc, LDAP_FILTER_SUBSTRINGS,
874 &db, &mask, &prefix );
876 if( rc != LDAP_SUCCESS ) {
877 Debug( LDAP_DEBUG_ANY,
878 "<= bdb_substring_candidates: (%s) "
879 "index_param failed (%d)\n",
880 sub->sa_desc->ad_cname.bv_val, rc, 0 );
885 Debug( LDAP_DEBUG_ANY,
886 "<= bdb_substring_candidates: (%s) not indexed\n",
887 sub->sa_desc->ad_cname.bv_val, 0, 0 );
891 mr = sub->sa_desc->ad_type->sat_substr;
897 if( !mr->smr_filter ) {
901 rc = (mr->smr_filter)(
902 LDAP_FILTER_SUBSTRINGS,
904 sub->sa_desc->ad_type->sat_syntax,
908 &keys, op->o_tmpmemctx );
910 if( rc != LDAP_SUCCESS ) {
911 Debug( LDAP_DEBUG_TRACE,
912 "<= bdb_substring_candidates: (%s) "
913 "MR filter failed (%d)\n",
914 sub->sa_desc->ad_cname.bv_val, rc, 0 );
919 Debug( LDAP_DEBUG_TRACE,
920 "<= bdb_substring_candidates: (0x%04lx) no keys (%s)\n",
921 mask, sub->sa_desc->ad_cname.bv_val, 0 );
925 for ( i= 0; keys[i].bv_val != NULL; i++ ) {
926 rc = bdb_key_read( op->o_bd, db, NULL, &keys[i], tmp, NULL, 0 );
928 if( rc == DB_NOTFOUND ) {
932 } else if( rc != LDAP_SUCCESS ) {
933 Debug( LDAP_DEBUG_TRACE,
934 "<= bdb_substring_candidates: (%s) "
935 "key read failed (%d)\n",
936 sub->sa_desc->ad_cname.bv_val, rc, 0 );
940 if( BDB_IDL_IS_ZERO( tmp ) ) {
941 Debug( LDAP_DEBUG_TRACE,
942 "<= bdb_substring_candidates: (%s) NULL\n",
943 sub->sa_desc->ad_cname.bv_val, 0, 0 );
949 BDB_IDL_CPY( ids, tmp );
951 bdb_idl_intersection( ids, tmp );
954 if( BDB_IDL_IS_ZERO( ids ) )
958 ber_bvarray_free_x( keys, op->o_tmpmemctx );
960 Debug( LDAP_DEBUG_TRACE, "<= bdb_substring_candidates: %ld, first=%ld, last=%ld\n",
962 (long) BDB_IDL_FIRST(ids),
963 (long) BDB_IDL_LAST(ids) );
968 inequality_candidates(
970 AttributeAssertion *ava,
975 struct bdb_info *bdb = (struct bdb_info *) op->o_bd->be_private;
980 struct berval prefix = {0, NULL};
981 struct berval *keys = NULL;
985 Debug( LDAP_DEBUG_TRACE, "=> bdb_inequality_candidates (%s)\n",
986 ava->aa_desc->ad_cname.bv_val, 0, 0 );
988 BDB_IDL_ALL( bdb, ids );
990 rc = bdb_index_param( op->o_bd, ava->aa_desc, LDAP_FILTER_EQUALITY,
991 &db, &mask, &prefix );
993 if( rc != LDAP_SUCCESS ) {
994 Debug( LDAP_DEBUG_ANY,
995 "<= bdb_inequality_candidates: (%s) "
996 "index_param failed (%d)\n",
997 ava->aa_desc->ad_cname.bv_val, rc, 0 );
1002 Debug( LDAP_DEBUG_ANY,
1003 "<= bdb_inequality_candidates: (%s) not indexed\n",
1004 ava->aa_desc->ad_cname.bv_val, 0, 0 );
1008 mr = ava->aa_desc->ad_type->sat_equality;
1013 if( !mr->smr_filter ) {
1017 rc = (mr->smr_filter)(
1018 LDAP_FILTER_EQUALITY,
1020 ava->aa_desc->ad_type->sat_syntax,
1024 &keys, op->o_tmpmemctx );
1026 if( rc != LDAP_SUCCESS ) {
1027 Debug( LDAP_DEBUG_TRACE,
1028 "<= bdb_inequality_candidates: (%s, %s) "
1029 "MR filter failed (%d)\n",
1030 prefix.bv_val, ava->aa_desc->ad_cname.bv_val, rc );
1034 if( keys == NULL ) {
1035 Debug( LDAP_DEBUG_TRACE,
1036 "<= bdb_inequality_candidates: (%s) no keys\n",
1037 ava->aa_desc->ad_cname.bv_val, 0, 0 );
1041 BDB_IDL_ZERO( ids );
1043 rc = bdb_key_read( op->o_bd, db, NULL, &keys[0], tmp, &cursor, gtorlt );
1045 if( rc == DB_NOTFOUND ) {
1048 } else if( rc != LDAP_SUCCESS ) {
1049 Debug( LDAP_DEBUG_TRACE,
1050 "<= bdb_inequality_candidates: (%s) "
1051 "key read failed (%d)\n",
1052 ava->aa_desc->ad_cname.bv_val, rc, 0 );
1056 if( BDB_IDL_IS_ZERO( tmp ) ) {
1057 Debug( LDAP_DEBUG_TRACE,
1058 "<= bdb_inequality_candidates: (%s) NULL\n",
1059 ava->aa_desc->ad_cname.bv_val, 0, 0 );
1063 bdb_idl_union( ids, tmp );
1065 if( BDB_IDL_IS_ZERO( ids ) )
1069 ber_bvarray_free_x( keys, op->o_tmpmemctx );
1071 Debug( LDAP_DEBUG_TRACE,
1072 "<= bdb_inequality_candidates: id=%ld, first=%ld, last=%ld\n",
1074 (long) BDB_IDL_FIRST(ids),
1075 (long) BDB_IDL_LAST(ids) );