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(
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 );
314 /* find a component reference to be indexed */
315 sat_syntax = ca->ca_ma_rule->smr_syntax;
316 for ( cr = cr_list ; cr ; cr = cr->cr_next ) {
317 if ( cr->cr_string.bv_len == ca->ca_comp_ref->cr_string.bv_len &&
318 strncmp( cr->cr_string.bv_val, ca->ca_comp_ref->cr_string.bv_val,cr->cr_string.bv_len ) == 0 )
325 rc = bdb_index_param( op->o_bd, mra->ma_desc, LDAP_FILTER_EQUALITY,
326 &db, &mask, &prefix );
328 if( rc != LDAP_SUCCESS ) {
339 if( !mr->smr_filter ) {
343 rc = (ca->ca_ma_rule->smr_filter)(
344 LDAP_FILTER_EQUALITY,
350 &keys, op->o_tmpmemctx );
352 if( rc != LDAP_SUCCESS ) {
359 for ( i= 0; keys[i].bv_val != NULL; i++ ) {
360 rc = bdb_key_read( op->o_bd, db, NULL, &keys[i], tmp, NULL, 0 );
362 if( rc == DB_NOTFOUND ) {
366 } else if( rc != LDAP_SUCCESS ) {
370 if( BDB_IDL_IS_ZERO( tmp ) ) {
376 BDB_IDL_CPY( ids, tmp );
378 bdb_idl_intersection( ids, tmp );
381 if( BDB_IDL_IS_ZERO( ids ) )
384 ber_bvarray_free_x( keys, op->o_tmpmemctx );
386 Debug( LDAP_DEBUG_TRACE,
387 "<= comp_equality_candidates: id=%ld, first=%ld, last=%ld\n",
389 (long) BDB_IDL_FIRST(ids),
390 (long) BDB_IDL_LAST(ids) );
395 ava_comp_candidates (
397 AttributeAssertion *ava,
398 AttributeAliasing *aa,
403 MatchingRuleAssertion mra;
405 mra.ma_rule = ava->aa_desc->ad_type->sat_equality;
406 if ( !mra.ma_rule ) {
407 struct bdb_info *bdb = (struct bdb_info *) op->o_bd->be_private;
408 BDB_IDL_ALL( bdb, ids );
411 mra.ma_desc = aa->aa_aliased_ad;
412 mra.ma_rule = ava->aa_desc->ad_type->sat_equality;
414 return comp_candidates ( op, &mra, ava->aa_cf, ids, tmp, stack );
420 MatchingRuleAssertion *mra,
428 if ( !f ) return LDAP_PROTOCOL_ERROR;
430 Debug( LDAP_DEBUG_FILTER, "comp_candidates\n", 0, 0, 0 );
431 switch ( f->cf_choice ) {
432 case SLAPD_FILTER_COMPUTED:
435 case LDAP_COMP_FILTER_AND:
436 rc = comp_list_candidates( op, mra, f->cf_and, LDAP_COMP_FILTER_AND, ids, tmp, stack );
438 case LDAP_COMP_FILTER_OR:
439 rc = comp_list_candidates( op, mra, f->cf_or, LDAP_COMP_FILTER_OR, ids, tmp, stack );
441 case LDAP_COMP_FILTER_NOT:
442 /* No component indexing supported for NOT filter */
443 Debug( LDAP_DEBUG_FILTER, "\tComponent NOT\n", 0, 0, 0 );
445 struct bdb_info *bdb = (struct bdb_info *) op->o_bd->be_private;
446 BDB_IDL_ALL( bdb, ids );
448 rc = LDAP_PROTOCOL_ERROR;
450 case LDAP_COMP_FILTER_ITEM:
451 rc = comp_equality_candidates( op, mra, f->cf_ca, ids, tmp, stack );
455 struct bdb_info *bdb = (struct bdb_info *) op->o_bd->be_private;
456 BDB_IDL_ALL( bdb, ids );
458 rc = LDAP_PROTOCOL_ERROR;
467 MatchingRuleAssertion *mra,
473 * Currently Only Component Indexing for componentFilterMatch is supported
474 * Indexing for an extensible filter is not supported yet
477 struct bdb_info *bdb = (struct bdb_info *) op->o_bd->be_private;
478 BDB_IDL_ALL( bdb, ids );
482 return comp_candidates ( op, mra, mra->ma_cf, ids, tmp, stack);
498 Debug( LDAP_DEBUG_FILTER, "=> bdb_list_candidates 0x%x\n", ftype, 0, 0 );
499 for ( f = flist; f != NULL; f = f->f_next ) {
500 /* ignore precomputed scopes */
501 if ( f->f_choice == SLAPD_FILTER_COMPUTED &&
502 f->f_result == LDAP_SUCCESS ) {
505 BDB_IDL_ZERO( save );
506 rc = bdb_filter_candidates( op, f, save, tmp,
507 save+BDB_IDL_UM_SIZE );
510 if ( ftype == LDAP_FILTER_AND ) {
518 if ( ftype == LDAP_FILTER_AND ) {
520 BDB_IDL_CPY( ids, save );
522 bdb_idl_intersection( ids, save );
524 if( BDB_IDL_IS_ZERO( ids ) )
528 BDB_IDL_CPY( ids, save );
530 bdb_idl_union( ids, save );
535 if( rc == LDAP_SUCCESS ) {
536 Debug( LDAP_DEBUG_FILTER,
537 "<= bdb_list_candidates: id=%ld first=%ld last=%ld\n",
539 (long) BDB_IDL_FIRST(ids),
540 (long) BDB_IDL_LAST(ids) );
543 Debug( LDAP_DEBUG_FILTER,
544 "<= bdb_list_candidates: undefined rc=%d\n",
554 AttributeDescription *desc,
557 struct bdb_info *bdb = (struct bdb_info *) op->o_bd->be_private;
561 struct berval prefix = {0, NULL};
563 Debug( LDAP_DEBUG_TRACE, "=> bdb_presence_candidates (%s)\n",
564 desc->ad_cname.bv_val, 0, 0 );
566 BDB_IDL_ALL( bdb, ids );
568 if( desc == slap_schema.si_ad_objectClass ) {
572 rc = bdb_index_param( op->o_bd, desc, LDAP_FILTER_PRESENT,
573 &db, &mask, &prefix );
575 if( rc != LDAP_SUCCESS ) {
576 Debug( LDAP_DEBUG_TRACE,
577 "<= bdb_presence_candidates: (%s) index_param "
579 desc->ad_cname.bv_val, rc, 0 );
585 Debug( LDAP_DEBUG_TRACE,
586 "<= bdb_presence_candidates: (%s) not indexed\n",
587 desc->ad_cname.bv_val, 0, 0 );
591 if( prefix.bv_val == NULL ) {
592 Debug( LDAP_DEBUG_TRACE,
593 "<= bdb_presence_candidates: (%s) no prefix\n",
594 desc->ad_cname.bv_val, 0, 0 );
598 rc = bdb_key_read( op->o_bd, db, NULL, &prefix, ids, NULL, 0 );
600 if( rc == DB_NOTFOUND ) {
603 } else if( rc != LDAP_SUCCESS ) {
604 Debug( LDAP_DEBUG_TRACE,
605 "<= bdb_presense_candidates: (%s) "
606 "key read failed (%d)\n",
607 desc->ad_cname.bv_val, rc, 0 );
611 Debug(LDAP_DEBUG_TRACE,
612 "<= bdb_presence_candidates: id=%ld first=%ld last=%ld\n",
614 (long) BDB_IDL_FIRST(ids),
615 (long) BDB_IDL_LAST(ids) );
624 AttributeAssertion *ava,
628 struct bdb_info *bdb = (struct bdb_info *) op->o_bd->be_private;
633 struct berval prefix = {0, NULL};
634 struct berval *keys = NULL;
637 Debug( LDAP_DEBUG_TRACE, "=> bdb_equality_candidates (%s)\n",
638 ava->aa_desc->ad_cname.bv_val, 0, 0 );
640 BDB_IDL_ALL( bdb, ids );
642 rc = bdb_index_param( op->o_bd, ava->aa_desc, LDAP_FILTER_EQUALITY,
643 &db, &mask, &prefix );
645 if( rc != LDAP_SUCCESS ) {
646 Debug( LDAP_DEBUG_ANY,
647 "<= bdb_equality_candidates: (%s) "
648 "index_param failed (%d)\n",
649 ava->aa_desc->ad_cname.bv_val, rc, 0 );
654 Debug( LDAP_DEBUG_ANY,
655 "<= bdb_equality_candidates: (%s) not indexed\n",
656 ava->aa_desc->ad_cname.bv_val, 0, 0 );
660 mr = ava->aa_desc->ad_type->sat_equality;
665 if( !mr->smr_filter ) {
669 rc = (mr->smr_filter)(
670 LDAP_FILTER_EQUALITY,
672 ava->aa_desc->ad_type->sat_syntax,
676 &keys, op->o_tmpmemctx );
678 if( rc != LDAP_SUCCESS ) {
679 Debug( LDAP_DEBUG_TRACE,
680 "<= bdb_equality_candidates: (%s, %s) "
681 "MR filter failed (%d)\n",
682 prefix.bv_val, ava->aa_desc->ad_cname.bv_val, rc );
687 Debug( LDAP_DEBUG_TRACE,
688 "<= bdb_equality_candidates: (%s) no keys\n",
689 ava->aa_desc->ad_cname.bv_val, 0, 0 );
693 for ( i= 0; keys[i].bv_val != NULL; i++ ) {
694 rc = bdb_key_read( op->o_bd, db, NULL, &keys[i], tmp, NULL, 0 );
696 if( rc == DB_NOTFOUND ) {
700 } else if( rc != LDAP_SUCCESS ) {
701 Debug( LDAP_DEBUG_TRACE,
702 "<= bdb_equality_candidates: (%s) "
703 "key read failed (%d)\n",
704 ava->aa_desc->ad_cname.bv_val, rc, 0 );
708 if( BDB_IDL_IS_ZERO( tmp ) ) {
709 Debug( LDAP_DEBUG_TRACE,
710 "<= bdb_equality_candidates: (%s) NULL\n",
711 ava->aa_desc->ad_cname.bv_val, 0, 0 );
717 BDB_IDL_CPY( ids, tmp );
719 bdb_idl_intersection( ids, tmp );
722 if( BDB_IDL_IS_ZERO( ids ) )
726 ber_bvarray_free_x( keys, op->o_tmpmemctx );
728 Debug( LDAP_DEBUG_TRACE,
729 "<= bdb_equality_candidates: id=%ld, first=%ld, last=%ld\n",
731 (long) BDB_IDL_FIRST(ids),
732 (long) BDB_IDL_LAST(ids) );
740 AttributeAssertion *ava,
744 struct bdb_info *bdb = (struct bdb_info *) op->o_bd->be_private;
749 struct berval prefix = {0, NULL};
750 struct berval *keys = NULL;
753 Debug( LDAP_DEBUG_TRACE, "=> bdb_approx_candidates (%s)\n",
754 ava->aa_desc->ad_cname.bv_val, 0, 0 );
756 BDB_IDL_ALL( bdb, ids );
758 rc = bdb_index_param( op->o_bd, ava->aa_desc, LDAP_FILTER_APPROX,
759 &db, &mask, &prefix );
761 if( rc != LDAP_SUCCESS ) {
762 Debug( LDAP_DEBUG_ANY,
763 "<= bdb_approx_candidates: (%s) "
764 "index_param failed (%d)\n",
765 ava->aa_desc->ad_cname.bv_val, rc, 0 );
770 Debug( LDAP_DEBUG_ANY,
771 "<= bdb_approx_candidates: (%s) not indexed\n",
772 ava->aa_desc->ad_cname.bv_val, 0, 0 );
776 mr = ava->aa_desc->ad_type->sat_approx;
778 /* no approx matching rule, try equality matching rule */
779 mr = ava->aa_desc->ad_type->sat_equality;
786 if( !mr->smr_filter ) {
790 rc = (mr->smr_filter)(
793 ava->aa_desc->ad_type->sat_syntax,
797 &keys, op->o_tmpmemctx );
799 if( rc != LDAP_SUCCESS ) {
800 Debug( LDAP_DEBUG_TRACE,
801 "<= bdb_approx_candidates: (%s, %s) "
802 "MR filter failed (%d)\n",
803 prefix.bv_val, ava->aa_desc->ad_cname.bv_val, rc );
808 Debug( LDAP_DEBUG_TRACE,
809 "<= bdb_approx_candidates: (%s) no keys (%s)\n",
810 prefix.bv_val, ava->aa_desc->ad_cname.bv_val, 0 );
814 for ( i= 0; keys[i].bv_val != NULL; i++ ) {
815 rc = bdb_key_read( op->o_bd, db, NULL, &keys[i], tmp, NULL, 0 );
817 if( rc == DB_NOTFOUND ) {
821 } else if( rc != LDAP_SUCCESS ) {
822 Debug( LDAP_DEBUG_TRACE,
823 "<= bdb_approx_candidates: (%s) "
824 "key read failed (%d)\n",
825 ava->aa_desc->ad_cname.bv_val, rc, 0 );
829 if( BDB_IDL_IS_ZERO( tmp ) ) {
830 Debug( LDAP_DEBUG_TRACE,
831 "<= bdb_approx_candidates: (%s) NULL\n",
832 ava->aa_desc->ad_cname.bv_val, 0, 0 );
838 BDB_IDL_CPY( ids, tmp );
840 bdb_idl_intersection( ids, tmp );
843 if( BDB_IDL_IS_ZERO( ids ) )
847 ber_bvarray_free_x( keys, op->o_tmpmemctx );
849 Debug( LDAP_DEBUG_TRACE, "<= bdb_approx_candidates %ld, first=%ld, last=%ld\n",
851 (long) BDB_IDL_FIRST(ids),
852 (long) BDB_IDL_LAST(ids) );
857 substring_candidates(
859 SubstringsAssertion *sub,
863 struct bdb_info *bdb = (struct bdb_info *) op->o_bd->be_private;
868 struct berval prefix = {0, NULL};
869 struct berval *keys = NULL;
872 Debug( LDAP_DEBUG_TRACE, "=> bdb_substring_candidates (%s)\n",
873 sub->sa_desc->ad_cname.bv_val, 0, 0 );
875 BDB_IDL_ALL( bdb, ids );
877 rc = bdb_index_param( op->o_bd, sub->sa_desc, LDAP_FILTER_SUBSTRINGS,
878 &db, &mask, &prefix );
880 if( rc != LDAP_SUCCESS ) {
881 Debug( LDAP_DEBUG_ANY,
882 "<= bdb_substring_candidates: (%s) "
883 "index_param failed (%d)\n",
884 sub->sa_desc->ad_cname.bv_val, rc, 0 );
889 Debug( LDAP_DEBUG_ANY,
890 "<= bdb_substring_candidates: (%s) not indexed\n",
891 sub->sa_desc->ad_cname.bv_val, 0, 0 );
895 mr = sub->sa_desc->ad_type->sat_substr;
901 if( !mr->smr_filter ) {
905 rc = (mr->smr_filter)(
906 LDAP_FILTER_SUBSTRINGS,
908 sub->sa_desc->ad_type->sat_syntax,
912 &keys, op->o_tmpmemctx );
914 if( rc != LDAP_SUCCESS ) {
915 Debug( LDAP_DEBUG_TRACE,
916 "<= bdb_substring_candidates: (%s) "
917 "MR filter failed (%d)\n",
918 sub->sa_desc->ad_cname.bv_val, rc, 0 );
923 Debug( LDAP_DEBUG_TRACE,
924 "<= bdb_substring_candidates: (0x%04lx) no keys (%s)\n",
925 mask, sub->sa_desc->ad_cname.bv_val, 0 );
929 for ( i= 0; keys[i].bv_val != NULL; i++ ) {
930 rc = bdb_key_read( op->o_bd, db, NULL, &keys[i], tmp, NULL, 0 );
932 if( rc == DB_NOTFOUND ) {
936 } else if( rc != LDAP_SUCCESS ) {
937 Debug( LDAP_DEBUG_TRACE,
938 "<= bdb_substring_candidates: (%s) "
939 "key read failed (%d)\n",
940 sub->sa_desc->ad_cname.bv_val, rc, 0 );
944 if( BDB_IDL_IS_ZERO( tmp ) ) {
945 Debug( LDAP_DEBUG_TRACE,
946 "<= bdb_substring_candidates: (%s) NULL\n",
947 sub->sa_desc->ad_cname.bv_val, 0, 0 );
953 BDB_IDL_CPY( ids, tmp );
955 bdb_idl_intersection( ids, tmp );
958 if( BDB_IDL_IS_ZERO( ids ) )
962 ber_bvarray_free_x( keys, op->o_tmpmemctx );
964 Debug( LDAP_DEBUG_TRACE, "<= bdb_substring_candidates: %ld, first=%ld, last=%ld\n",
966 (long) BDB_IDL_FIRST(ids),
967 (long) BDB_IDL_LAST(ids) );
972 inequality_candidates(
974 AttributeAssertion *ava,
979 struct bdb_info *bdb = (struct bdb_info *) op->o_bd->be_private;
983 struct berval prefix = {0, NULL};
984 struct berval *keys = NULL;
988 Debug( LDAP_DEBUG_TRACE, "=> bdb_inequality_candidates (%s)\n",
989 ava->aa_desc->ad_cname.bv_val, 0, 0 );
991 BDB_IDL_ALL( bdb, ids );
993 rc = bdb_index_param( op->o_bd, ava->aa_desc, LDAP_FILTER_EQUALITY,
994 &db, &mask, &prefix );
996 if( rc != LDAP_SUCCESS ) {
997 Debug( LDAP_DEBUG_ANY,
998 "<= bdb_inequality_candidates: (%s) "
999 "index_param failed (%d)\n",
1000 ava->aa_desc->ad_cname.bv_val, rc, 0 );
1005 Debug( LDAP_DEBUG_ANY,
1006 "<= bdb_inequality_candidates: (%s) not indexed\n",
1007 ava->aa_desc->ad_cname.bv_val, 0, 0 );
1011 mr = ava->aa_desc->ad_type->sat_equality;
1016 if( !mr->smr_filter ) {
1020 rc = (mr->smr_filter)(
1021 LDAP_FILTER_EQUALITY,
1023 ava->aa_desc->ad_type->sat_syntax,
1027 &keys, op->o_tmpmemctx );
1029 if( rc != LDAP_SUCCESS ) {
1030 Debug( LDAP_DEBUG_TRACE,
1031 "<= bdb_inequality_candidates: (%s, %s) "
1032 "MR filter failed (%d)\n",
1033 prefix.bv_val, ava->aa_desc->ad_cname.bv_val, rc );
1037 if( keys == NULL ) {
1038 Debug( LDAP_DEBUG_TRACE,
1039 "<= bdb_inequality_candidates: (%s) no keys\n",
1040 ava->aa_desc->ad_cname.bv_val, 0, 0 );
1044 BDB_IDL_ZERO( ids );
1046 rc = bdb_key_read( op->o_bd, db, NULL, &keys[0], tmp, &cursor, gtorlt );
1048 if( rc == DB_NOTFOUND ) {
1051 } else if( rc != LDAP_SUCCESS ) {
1052 Debug( LDAP_DEBUG_TRACE,
1053 "<= bdb_inequality_candidates: (%s) "
1054 "key read failed (%d)\n",
1055 ava->aa_desc->ad_cname.bv_val, rc, 0 );
1059 if( BDB_IDL_IS_ZERO( tmp ) ) {
1060 Debug( LDAP_DEBUG_TRACE,
1061 "<= bdb_inequality_candidates: (%s) NULL\n",
1062 ava->aa_desc->ad_cname.bv_val, 0, 0 );
1066 bdb_idl_union( ids, tmp );
1068 if( op->ors_limit && op->ors_limit->lms_s_unchecked != -1 &&
1069 BDB_IDL_N( ids ) >= (unsigned) op->ors_limit->lms_s_unchecked ) {
1070 cursor->c_close( cursor );
1074 ber_bvarray_free_x( keys, op->o_tmpmemctx );
1076 Debug( LDAP_DEBUG_TRACE,
1077 "<= bdb_inequality_candidates: id=%ld, first=%ld, last=%ld\n",
1079 (long) BDB_IDL_FIRST(ids),
1080 (long) BDB_IDL_LAST(ids) );