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;
301 BDB_IDL_ALL( bdb, ids );
303 bdb_attr_comp_ref ( op->o_bd->be_private, mra->ma_desc, &cr_list );
304 if( !cr_list || !ca->ca_comp_ref )
306 /* find a component reference to be indexed */
307 sat_syntax = ca->ca_ma_rule->smr_syntax;
308 for ( cr = cr_list ; cr ; cr = cr->cr_next ) {
309 if ( cr->cr_string.bv_len == ca->ca_comp_ref->cr_string.bv_len &&
310 strncmp( cr->cr_string.bv_val, ca->ca_comp_ref->cr_string.bv_val,cr->cr_string.bv_len ) == 0 )
317 rc = bdb_index_param( op->o_bd, mra->ma_desc, LDAP_FILTER_EQUALITY,
318 &db, &mask, &prefix );
320 if( rc != LDAP_SUCCESS ) {
331 if( !mr->smr_filter ) {
335 rc = (ca->ca_ma_rule->smr_filter)(
336 LDAP_FILTER_EQUALITY,
342 &keys, op->o_tmpmemctx );
344 if( rc != LDAP_SUCCESS ) {
351 for ( i= 0; keys[i].bv_val != NULL; i++ ) {
352 rc = bdb_key_read( op->o_bd, db, NULL, &keys[i], tmp, NULL, 0 );
354 if( rc == DB_NOTFOUND ) {
358 } else if( rc != LDAP_SUCCESS ) {
362 if( BDB_IDL_IS_ZERO( tmp ) ) {
368 BDB_IDL_CPY( ids, tmp );
370 bdb_idl_intersection( ids, tmp );
373 if( BDB_IDL_IS_ZERO( ids ) )
376 ber_bvarray_free_x( keys, op->o_tmpmemctx );
378 Debug( LDAP_DEBUG_TRACE,
379 "<= comp_equality_candidates: id=%ld, first=%ld, last=%ld\n",
381 (long) BDB_IDL_FIRST(ids),
382 (long) BDB_IDL_LAST(ids) );
387 ava_comp_candidates (
389 AttributeAssertion *ava,
390 AttributeAliasing *aa,
395 MatchingRuleAssertion mra;
397 mra.ma_rule = ava->aa_desc->ad_type->sat_equality;
398 if ( !mra.ma_rule ) {
399 struct bdb_info *bdb = (struct bdb_info *) op->o_bd->be_private;
400 BDB_IDL_ALL( bdb, ids );
403 mra.ma_desc = aa->aa_aliased_ad;
404 mra.ma_rule = ava->aa_desc->ad_type->sat_equality;
406 return comp_candidates ( op, &mra, ava->aa_cf, ids, tmp, stack );
412 MatchingRuleAssertion *mra,
420 if ( !f ) return LDAP_PROTOCOL_ERROR;
422 Debug( LDAP_DEBUG_FILTER, "comp_candidates\n", 0, 0, 0 );
423 switch ( f->cf_choice ) {
424 case SLAPD_FILTER_COMPUTED:
427 case LDAP_COMP_FILTER_AND:
428 rc = comp_list_candidates( op, mra, f->cf_and, LDAP_COMP_FILTER_AND, ids, tmp, stack );
430 case LDAP_COMP_FILTER_OR:
431 rc = comp_list_candidates( op, mra, f->cf_or, LDAP_COMP_FILTER_OR, ids, tmp, stack );
433 case LDAP_COMP_FILTER_NOT:
434 /* No component indexing supported for NOT filter */
435 Debug( LDAP_DEBUG_FILTER, "\tComponent NOT\n", 0, 0, 0 );
437 struct bdb_info *bdb = (struct bdb_info *) op->o_bd->be_private;
438 BDB_IDL_ALL( bdb, ids );
440 rc = LDAP_PROTOCOL_ERROR;
442 case LDAP_COMP_FILTER_ITEM:
443 rc = comp_equality_candidates( op, mra, f->cf_ca, ids, tmp, stack );
447 struct bdb_info *bdb = (struct bdb_info *) op->o_bd->be_private;
448 BDB_IDL_ALL( bdb, ids );
450 rc = LDAP_PROTOCOL_ERROR;
459 MatchingRuleAssertion *mra,
465 * Currently Only Component Indexing for componentFilterMatch is supported
466 * Indexing for an extensible filter is not supported yet
469 struct bdb_info *bdb = (struct bdb_info *) op->o_bd->be_private;
470 BDB_IDL_ALL( bdb, ids );
474 return comp_candidates ( op, mra, mra->ma_cf, ids, tmp, stack);
490 Debug( LDAP_DEBUG_FILTER, "=> bdb_list_candidates 0x%x\n", ftype, 0, 0 );
491 for ( f = flist; f != NULL; f = f->f_next ) {
492 /* ignore precomputed scopes */
493 if ( f->f_choice == SLAPD_FILTER_COMPUTED &&
494 f->f_result == LDAP_SUCCESS ) {
497 BDB_IDL_ZERO( save );
498 rc = bdb_filter_candidates( op, f, save, tmp,
499 save+BDB_IDL_UM_SIZE );
502 if ( ftype == LDAP_FILTER_AND ) {
510 if ( ftype == LDAP_FILTER_AND ) {
512 BDB_IDL_CPY( ids, save );
514 bdb_idl_intersection( ids, save );
516 if( BDB_IDL_IS_ZERO( ids ) )
520 BDB_IDL_CPY( ids, save );
522 bdb_idl_union( ids, save );
527 if( rc == LDAP_SUCCESS ) {
528 Debug( LDAP_DEBUG_FILTER,
529 "<= bdb_list_candidates: id=%ld first=%ld last=%ld\n",
531 (long) BDB_IDL_FIRST(ids),
532 (long) BDB_IDL_LAST(ids) );
535 Debug( LDAP_DEBUG_FILTER,
536 "<= bdb_list_candidates: undefined rc=%d\n",
546 AttributeDescription *desc,
549 struct bdb_info *bdb = (struct bdb_info *) op->o_bd->be_private;
553 struct berval prefix = {0, NULL};
555 Debug( LDAP_DEBUG_TRACE, "=> bdb_presence_candidates (%s)\n",
556 desc->ad_cname.bv_val, 0, 0 );
558 BDB_IDL_ALL( bdb, ids );
560 if( desc == slap_schema.si_ad_objectClass ) {
564 rc = bdb_index_param( op->o_bd, desc, LDAP_FILTER_PRESENT,
565 &db, &mask, &prefix );
567 if( rc != LDAP_SUCCESS ) {
568 Debug( LDAP_DEBUG_TRACE,
569 "<= bdb_presence_candidates: (%s) index_param "
571 desc->ad_cname.bv_val, rc, 0 );
577 Debug( LDAP_DEBUG_TRACE,
578 "<= bdb_presence_candidates: (%s) not indexed\n",
579 desc->ad_cname.bv_val, 0, 0 );
583 if( prefix.bv_val == NULL ) {
584 Debug( LDAP_DEBUG_TRACE,
585 "<= bdb_presence_candidates: (%s) no prefix\n",
586 desc->ad_cname.bv_val, 0, 0 );
590 rc = bdb_key_read( op->o_bd, db, NULL, &prefix, ids, NULL, 0 );
592 if( rc == DB_NOTFOUND ) {
595 } else if( rc != LDAP_SUCCESS ) {
596 Debug( LDAP_DEBUG_TRACE,
597 "<= bdb_presense_candidates: (%s) "
598 "key read failed (%d)\n",
599 desc->ad_cname.bv_val, rc, 0 );
603 Debug(LDAP_DEBUG_TRACE,
604 "<= bdb_presence_candidates: id=%ld first=%ld last=%ld\n",
606 (long) BDB_IDL_FIRST(ids),
607 (long) BDB_IDL_LAST(ids) );
616 AttributeAssertion *ava,
620 struct bdb_info *bdb = (struct bdb_info *) op->o_bd->be_private;
625 struct berval prefix = {0, NULL};
626 struct berval *keys = NULL;
629 Debug( LDAP_DEBUG_TRACE, "=> bdb_equality_candidates (%s)\n",
630 ava->aa_desc->ad_cname.bv_val, 0, 0 );
632 BDB_IDL_ALL( bdb, ids );
634 rc = bdb_index_param( op->o_bd, ava->aa_desc, LDAP_FILTER_EQUALITY,
635 &db, &mask, &prefix );
637 if( rc != LDAP_SUCCESS ) {
638 Debug( LDAP_DEBUG_ANY,
639 "<= bdb_equality_candidates: (%s) "
640 "index_param failed (%d)\n",
641 ava->aa_desc->ad_cname.bv_val, rc, 0 );
646 Debug( LDAP_DEBUG_ANY,
647 "<= bdb_equality_candidates: (%s) not indexed\n",
648 ava->aa_desc->ad_cname.bv_val, 0, 0 );
652 mr = ava->aa_desc->ad_type->sat_equality;
657 if( !mr->smr_filter ) {
661 rc = (mr->smr_filter)(
662 LDAP_FILTER_EQUALITY,
664 ava->aa_desc->ad_type->sat_syntax,
668 &keys, op->o_tmpmemctx );
670 if( rc != LDAP_SUCCESS ) {
671 Debug( LDAP_DEBUG_TRACE,
672 "<= bdb_equality_candidates: (%s, %s) "
673 "MR filter failed (%d)\n",
674 prefix.bv_val, ava->aa_desc->ad_cname.bv_val, rc );
679 Debug( LDAP_DEBUG_TRACE,
680 "<= bdb_equality_candidates: (%s) no keys\n",
681 ava->aa_desc->ad_cname.bv_val, 0, 0 );
685 for ( i= 0; keys[i].bv_val != NULL; i++ ) {
686 rc = bdb_key_read( op->o_bd, db, NULL, &keys[i], tmp, NULL, 0 );
688 if( rc == DB_NOTFOUND ) {
692 } else if( rc != LDAP_SUCCESS ) {
693 Debug( LDAP_DEBUG_TRACE,
694 "<= bdb_equality_candidates: (%s) "
695 "key read failed (%d)\n",
696 ava->aa_desc->ad_cname.bv_val, rc, 0 );
700 if( BDB_IDL_IS_ZERO( tmp ) ) {
701 Debug( LDAP_DEBUG_TRACE,
702 "<= bdb_equality_candidates: (%s) NULL\n",
703 ava->aa_desc->ad_cname.bv_val, 0, 0 );
709 BDB_IDL_CPY( ids, tmp );
711 bdb_idl_intersection( ids, tmp );
714 if( BDB_IDL_IS_ZERO( ids ) )
718 ber_bvarray_free_x( keys, op->o_tmpmemctx );
720 Debug( LDAP_DEBUG_TRACE,
721 "<= bdb_equality_candidates: id=%ld, first=%ld, last=%ld\n",
723 (long) BDB_IDL_FIRST(ids),
724 (long) BDB_IDL_LAST(ids) );
732 AttributeAssertion *ava,
736 struct bdb_info *bdb = (struct bdb_info *) op->o_bd->be_private;
741 struct berval prefix = {0, NULL};
742 struct berval *keys = NULL;
745 Debug( LDAP_DEBUG_TRACE, "=> bdb_approx_candidates (%s)\n",
746 ava->aa_desc->ad_cname.bv_val, 0, 0 );
748 BDB_IDL_ALL( bdb, ids );
750 rc = bdb_index_param( op->o_bd, ava->aa_desc, LDAP_FILTER_APPROX,
751 &db, &mask, &prefix );
753 if( rc != LDAP_SUCCESS ) {
754 Debug( LDAP_DEBUG_ANY,
755 "<= bdb_approx_candidates: (%s) "
756 "index_param failed (%d)\n",
757 ava->aa_desc->ad_cname.bv_val, rc, 0 );
762 Debug( LDAP_DEBUG_ANY,
763 "<= bdb_approx_candidates: (%s) not indexed\n",
764 ava->aa_desc->ad_cname.bv_val, 0, 0 );
768 mr = ava->aa_desc->ad_type->sat_approx;
770 /* no approx matching rule, try equality matching rule */
771 mr = ava->aa_desc->ad_type->sat_equality;
778 if( !mr->smr_filter ) {
782 rc = (mr->smr_filter)(
785 ava->aa_desc->ad_type->sat_syntax,
789 &keys, op->o_tmpmemctx );
791 if( rc != LDAP_SUCCESS ) {
792 Debug( LDAP_DEBUG_TRACE,
793 "<= bdb_approx_candidates: (%s, %s) "
794 "MR filter failed (%d)\n",
795 prefix.bv_val, ava->aa_desc->ad_cname.bv_val, rc );
800 Debug( LDAP_DEBUG_TRACE,
801 "<= bdb_approx_candidates: (%s) no keys (%s)\n",
802 prefix.bv_val, ava->aa_desc->ad_cname.bv_val, 0 );
806 for ( i= 0; keys[i].bv_val != NULL; i++ ) {
807 rc = bdb_key_read( op->o_bd, db, NULL, &keys[i], tmp, NULL, 0 );
809 if( rc == DB_NOTFOUND ) {
813 } else if( rc != LDAP_SUCCESS ) {
814 Debug( LDAP_DEBUG_TRACE,
815 "<= bdb_approx_candidates: (%s) "
816 "key read failed (%d)\n",
817 ava->aa_desc->ad_cname.bv_val, rc, 0 );
821 if( BDB_IDL_IS_ZERO( tmp ) ) {
822 Debug( LDAP_DEBUG_TRACE,
823 "<= bdb_approx_candidates: (%s) NULL\n",
824 ava->aa_desc->ad_cname.bv_val, 0, 0 );
830 BDB_IDL_CPY( ids, tmp );
832 bdb_idl_intersection( ids, tmp );
835 if( BDB_IDL_IS_ZERO( ids ) )
839 ber_bvarray_free_x( keys, op->o_tmpmemctx );
841 Debug( LDAP_DEBUG_TRACE, "<= bdb_approx_candidates %ld, first=%ld, last=%ld\n",
843 (long) BDB_IDL_FIRST(ids),
844 (long) BDB_IDL_LAST(ids) );
849 substring_candidates(
851 SubstringsAssertion *sub,
855 struct bdb_info *bdb = (struct bdb_info *) op->o_bd->be_private;
860 struct berval prefix = {0, NULL};
861 struct berval *keys = NULL;
864 Debug( LDAP_DEBUG_TRACE, "=> bdb_substring_candidates (%s)\n",
865 sub->sa_desc->ad_cname.bv_val, 0, 0 );
867 BDB_IDL_ALL( bdb, ids );
869 rc = bdb_index_param( op->o_bd, sub->sa_desc, LDAP_FILTER_SUBSTRINGS,
870 &db, &mask, &prefix );
872 if( rc != LDAP_SUCCESS ) {
873 Debug( LDAP_DEBUG_ANY,
874 "<= bdb_substring_candidates: (%s) "
875 "index_param failed (%d)\n",
876 sub->sa_desc->ad_cname.bv_val, rc, 0 );
881 Debug( LDAP_DEBUG_ANY,
882 "<= bdb_substring_candidates: (%s) not indexed\n",
883 sub->sa_desc->ad_cname.bv_val, 0, 0 );
887 mr = sub->sa_desc->ad_type->sat_substr;
893 if( !mr->smr_filter ) {
897 rc = (mr->smr_filter)(
898 LDAP_FILTER_SUBSTRINGS,
900 sub->sa_desc->ad_type->sat_syntax,
904 &keys, op->o_tmpmemctx );
906 if( rc != LDAP_SUCCESS ) {
907 Debug( LDAP_DEBUG_TRACE,
908 "<= bdb_substring_candidates: (%s) "
909 "MR filter failed (%d)\n",
910 sub->sa_desc->ad_cname.bv_val, rc, 0 );
915 Debug( LDAP_DEBUG_TRACE,
916 "<= bdb_substring_candidates: (0x%04lx) no keys (%s)\n",
917 mask, sub->sa_desc->ad_cname.bv_val, 0 );
921 for ( i= 0; keys[i].bv_val != NULL; i++ ) {
922 rc = bdb_key_read( op->o_bd, db, NULL, &keys[i], tmp, NULL, 0 );
924 if( rc == DB_NOTFOUND ) {
928 } else if( rc != LDAP_SUCCESS ) {
929 Debug( LDAP_DEBUG_TRACE,
930 "<= bdb_substring_candidates: (%s) "
931 "key read failed (%d)\n",
932 sub->sa_desc->ad_cname.bv_val, rc, 0 );
936 if( BDB_IDL_IS_ZERO( tmp ) ) {
937 Debug( LDAP_DEBUG_TRACE,
938 "<= bdb_substring_candidates: (%s) NULL\n",
939 sub->sa_desc->ad_cname.bv_val, 0, 0 );
945 BDB_IDL_CPY( ids, tmp );
947 bdb_idl_intersection( ids, tmp );
950 if( BDB_IDL_IS_ZERO( ids ) )
954 ber_bvarray_free_x( keys, op->o_tmpmemctx );
956 Debug( LDAP_DEBUG_TRACE, "<= bdb_substring_candidates: %ld, first=%ld, last=%ld\n",
958 (long) BDB_IDL_FIRST(ids),
959 (long) BDB_IDL_LAST(ids) );
964 inequality_candidates(
966 AttributeAssertion *ava,
971 struct bdb_info *bdb = (struct bdb_info *) op->o_bd->be_private;
976 struct berval prefix = {0, NULL};
977 struct berval *keys = NULL;
981 Debug( LDAP_DEBUG_TRACE, "=> bdb_inequality_candidates (%s)\n",
982 ava->aa_desc->ad_cname.bv_val, 0, 0 );
984 BDB_IDL_ALL( bdb, ids );
986 rc = bdb_index_param( op->o_bd, ava->aa_desc, LDAP_FILTER_EQUALITY,
987 &db, &mask, &prefix );
989 if( rc != LDAP_SUCCESS ) {
990 Debug( LDAP_DEBUG_ANY,
991 "<= bdb_inequality_candidates: (%s) "
992 "index_param failed (%d)\n",
993 ava->aa_desc->ad_cname.bv_val, rc, 0 );
998 Debug( LDAP_DEBUG_ANY,
999 "<= bdb_inequality_candidates: (%s) not indexed\n",
1000 ava->aa_desc->ad_cname.bv_val, 0, 0 );
1004 mr = ava->aa_desc->ad_type->sat_equality;
1009 if( !mr->smr_filter ) {
1013 rc = (mr->smr_filter)(
1014 LDAP_FILTER_EQUALITY,
1016 ava->aa_desc->ad_type->sat_syntax,
1020 &keys, op->o_tmpmemctx );
1022 if( rc != LDAP_SUCCESS ) {
1023 Debug( LDAP_DEBUG_TRACE,
1024 "<= bdb_inequality_candidates: (%s, %s) "
1025 "MR filter failed (%d)\n",
1026 prefix.bv_val, ava->aa_desc->ad_cname.bv_val, rc );
1030 if( keys == NULL ) {
1031 Debug( LDAP_DEBUG_TRACE,
1032 "<= bdb_inequality_candidates: (%s) no keys\n",
1033 ava->aa_desc->ad_cname.bv_val, 0, 0 );
1037 BDB_IDL_ZERO( ids );
1039 rc = bdb_key_read( op->o_bd, db, NULL, &keys[0], tmp, &cursor, gtorlt );
1041 if( rc == DB_NOTFOUND ) {
1044 } else if( rc != LDAP_SUCCESS ) {
1045 Debug( LDAP_DEBUG_TRACE,
1046 "<= bdb_inequality_candidates: (%s) "
1047 "key read failed (%d)\n",
1048 ava->aa_desc->ad_cname.bv_val, rc, 0 );
1052 if( BDB_IDL_IS_ZERO( tmp ) ) {
1053 Debug( LDAP_DEBUG_TRACE,
1054 "<= bdb_inequality_candidates: (%s) NULL\n",
1055 ava->aa_desc->ad_cname.bv_val, 0, 0 );
1059 bdb_idl_union( ids, tmp );
1061 if( BDB_IDL_IS_ZERO( ids ) )
1065 ber_bvarray_free_x( keys, op->o_tmpmemctx );
1067 Debug( LDAP_DEBUG_TRACE,
1068 "<= bdb_inequality_candidates: id=%ld, first=%ld, last=%ld\n",
1070 (long) BDB_IDL_FIRST(ids),
1071 (long) BDB_IDL_LAST(ids) );